QuickBooks/QBXML/Object.php
public function asQBXML($request, $version = null, $locale = null, $root = null)
	{
		$todo_for_empty_elements = QuickBooks_XML::XML_DROP;
		$indent = "\t";
		
		// Call any cleanup routines
		$this->_cleanup();
		
		// 
		if (strtolower(substr($request, -2, 2)) != 'rq')
		{
			$request .= 'Rq';
		}
		
		$Request = new QuickBooks_XML_Node($request);
		
		if ($schema = $this->_schema($request))
		{
			$tmp = array();
			
			// Restrict it to a specific qbXML version?
			if ($version)
			{
				
			}
			
			// Restrict it to a specific qbXML locale?
			if ($locale)
			{
				// List of fields which are not supported for some versions of qbXML
				
				if (strlen($locale) == 2)
				{
					// The OSR lists locales as 'QBOE', 'QBUK', 'QBCA', etc. vs. our QUICKBOOKS_LOCALE_* constants of just 'OE', 'UK', 'CA', etc.
					$locale = 'QB' . $locale;
				}
				
				$locales = $schema->localePaths();
			}

			$thelist = $this->asList($request);
			$reordered = $schema->reorderPaths(array_keys($thelist));

			foreach ($reordered as $key => $path)
			{
				$value = $this->_object[$path];
				
				if (is_array($value))
				{	
					$tmp[$path] = array();
					
					foreach ($value as $arr)
					{
						$tmp2 = array();
						
						foreach ($arr->asList('') as $inkey => $invalue)
						{
							$arr->set($path . ' ' . $inkey, $invalue);
						}
						
						foreach ($schema->reorderPaths(array_keys($arr->asList(''))) as $subkey => $subpath)
						{
							// We need this later, so store it
							$fullpath = $subpath;
							
							if ($locale and 
								isset($locales[$subpath]))
							{
								if (in_array($locale, $locales[$subpath]))
								{
									// 
									//print('found: ' . $subpath . ' (' . $locale . ') so skipping!' . "\n");
								}
								else
								{
									$subpath = substr($subpath, strlen($path) + 1);
									$tmp2[$subpath] = $arr->get($subpath);									
								}
							}
							else
							{
								$subpath = substr($subpath, strlen($path) + 1);
								$tmp2[$subpath] = $arr->get($subpath);								
							}
							
							if ($schema->dataType($fullpath) == QUICKBOOKS_QBXML_SCHEMA_TYPE_AMTTYPE and 
								isset($tmp2[$subpath]))
							{
								$tmp2[$subpath] = sprintf('%01.2f', $tmp2[$subpath]);
							}
						}
						
						$tmp2 = new QuickBooks_QBXML_Object_Generic($tmp2, $arr->object());
						
						$tmp[$path][] = $tmp2;
					}
				}
				else
				{
					// Do some simple data type casting... 
					if ($schema->dataType($path) == QUICKBOOKS_QBXML_SCHEMA_TYPE_AMTTYPE)
					{
						$this->_object[$path] = sprintf('%01.2f', $this->_object[$path]);
					}
					
					if ($locale and 				// If a locale is specified...
						isset($locales[$path]))		// ... and this path is set in the locales restriction array
					{
						// Check to see if it's supported by the given locale
						
						if (in_array($locale, $locales[$path]))
						{
							// It's not supported by this locale, don't show add it
						}
						else
						{
							$tmp[$path] = $this->_object[$path];
						}
					}
					else
					{
						// If we don't know whether or not it's supported, return it!
							
						$tmp[$path] = $this->_object[$path];
					}
				}
			}
			
			// *DO NOT* change the source values of the original object! 
			//$this->_object = $tmp;
			
			if ($wrapper = $schema->qbxmlWrapper())
			{
				
				$Node = $this->asXML($wrapper, null, $tmp);
				$Request->addChild($Node);
				
				return $Request->asXML($todo_for_empty_elements, $indent);
			}
			else if (count($this->_object) == 0)
			{
				// This catches the cases where we just want to get *all* objects 
				//	back (no filters) and thus the root level qbXML element is *empty* 
				//	and we need to *preserve* this empty element rather than just 
				//	drop it (which results in an empty string, and thus invalid query)
				
				$Node = $this->asXML($request, null, $tmp);
				
				return $Node->asXML(QuickBooks_XML::XML_PRESERVE, $indent);
			}
			else
			{
				$Node = $this->asXML($request, null, $tmp);
				
				return $Node->asXML($todo_for_empty_elements, $indent);
			}
		}
		
		return '';
	}
public function asQBXML($request, $version = null, $locale = null, $root = null)
	{
		$todo_for_empty_elements = QuickBooks_XML::XML_DROP;
		$indent = "\t";
		
		// Call any cleanup routines
		$this->_cleanup();
		
		// 
		if (strtolower(substr($request, -2, 2)) != 'rq')
		{
			$request .= 'Rq';
		}
		
		$Request = new QuickBooks_XML_Node($request);
		
		if ($schema = $this->_schema($request))
		{
			$tmp = array();
			
			// Restrict it to a specific qbXML version?
			if ($version)
			{
				
			}
			
			// Restrict it to a specific qbXML locale?
			if ($locale)
			{
				// List of fields which are not supported for some versions of qbXML
				
				if (strlen($locale) == 2)
				{
					// The OSR lists locales as 'QBOE', 'QBUK', 'QBCA', etc. vs. our QUICKBOOKS_LOCALE_* constants of just 'OE', 'UK', 'CA', etc.
					$locale = 'QB' . $locale;
				}
				
				$locales = $schema->localePaths();
			}

			$thelist = $this->asList($request);
			$reordered = $schema->reorderPaths(array_keys($thelist));

			foreach ($reordered as $key => $path)
			{
				$value = $this->_object[$path];
				
				if (is_array($value))
				{	
					$tmp[$path] = array();
					
					foreach ($value as $arr)
					{
						$tmp2 = array();
						
						foreach ($arr->asList('') as $inkey => $invalue)
						{
							$arr->set($path . ' ' . $inkey, $invalue);
						}
						
						foreach ($schema->reorderPaths(array_keys($arr->asList(''))) as $subkey => $subpath)
						{
							// We need this later, so store it
							$fullpath = $subpath;
							
							if ($locale and 
								isset($locales[$subpath]))
							{
								if (in_array($locale, $locales[$subpath]))
								{
									// 
									//print('found: ' . $subpath . ' (' . $locale . ') so skipping!' . "\n");
								}
								else
								{
									$subpath = substr($subpath, strlen($path) + 1);
									$tmp2[$subpath] = $arr->get($subpath);									
								}
							}
							else
							{
								$subpath = substr($subpath, strlen($path) + 1);
								$tmp2[$subpath] = $arr->get($subpath);								
							}
							
							if ($schema->dataType($fullpath) == QUICKBOOKS_QBXML_SCHEMA_TYPE_AMTTYPE and 
								isset($tmp2[$subpath]))
							{
								$tmp2[$subpath] = sprintf('%01.2f', $tmp2[$subpath]);
							}
						}
						
						$tmp2 = new QuickBooks_QBXML_Object_Generic($tmp2, $arr->object());
						
						$tmp[$path][] = $tmp2;
					}
				}
				else
				{
					// Do some simple data type casting... 
					if ($schema->dataType($path) == QUICKBOOKS_QBXML_SCHEMA_TYPE_AMTTYPE)
					{
						$this->_object[$path] = sprintf('%01.2f', $this->_object[$path]);
					}
					
					if ($locale and 				// If a locale is specified...
						isset($locales[$path]))		// ... and this path is set in the locales restriction array
					{
						// Check to see if it's supported by the given locale
						
						if (in_array($locale, $locales[$path]))
						{
							// It's not supported by this locale, don't show add it
						}
						else
						{
							$tmp[$path] = $this->_object[$path];
						}
					}
					else
					{
						// If we don't know whether or not it's supported, return it!
							
						$tmp[$path] = $this->_object[$path];
					}
				}
			}
			
			// *DO NOT* change the source values of the original object! 
			//$this->_object = $tmp;
			
			if ($wrapper = $schema->qbxmlWrapper())
			{
				
				$Node = $this->asXML($wrapper, null, $tmp);
				$Request->addChild($Node);
				
				return $Request->asXML($todo_for_empty_elements, $indent);
			}
			else if (count($this->_object) == 0)
			{
				// This catches the cases where we just want to get *all* objects 
				//	back (no filters) and thus the root level qbXML element is *empty* 
				//	and we need to *preserve* this empty element rather than just 
				//	drop it (which results in an empty string, and thus invalid query)
				
				$Node = $this->asXML($request, null, $tmp);
				
				return $Node->asXML(QuickBooks_XML::XML_PRESERVE, $indent);
			}
			else
			{
				$Node = $this->asXML($request, null, $tmp);
				
				return $Node->asXML($todo_for_empty_elements, $indent);
			}
		}
		
		return '';
	}
public function asQBXML($request, $todo_for_empty_elements = QUICKBOOKS_XML_XML_DROP, $indent = "\t", $root = null)