protected static function _ChildObjectsToXML($type, $action, $children, $parentPath = '') { $Driver = QuickBooks_Driver_Singleton::getInstance(); $nodes = array(); $file = '/QuickBooks/QBXML/Schema/Object/' . QuickBooks_Utilities::actionToRequest($action) . '.php'; $class = 'QuickBooks_QBXML_Schema_Object_' . QuickBooks_Utilities::actionToRequest($action); QuickBooks_Loader::load($file); $schema_object = new $class(); $usePath = ''; if ($parentPath != '') { $usePath .= $parentPath . ' '; } foreach ($children as $child) { // Figure out which LinkedTxn method should be used... if (strpos($child['table'], "linkedtxn") !== false) { if (stripos($action, "add") !== false) { $part = preg_replace("/add/i", "", $action); $part .= "LineAdd"; } else { if (stripos($action, 'mod') !== false) { $part = preg_replace("/mod/i", "", $action); $part .= "LineMod"; } } if ($schema_object->exists($usePath . 'LinkToTxnID')) { $Node = new QuickBooks_XML_Node("LinkToTxnID", $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { if ($schema_object->exists($action . ' ' . $part . ' ' . 'LinkToTxn')) { $Node = new QuickBooks_XML_Node("LinkToTxnID", $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { if ($schema_object->exists($usePath . 'LinkedTxn')) { $Node = new QuickBooks_XML_Node("LinkToTxnID", $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { if ($schema_object->exists($action . ' ' . $part . ' ' . 'LinkedTxn')) { $Node = new QuickBooks_XML_Node("LinkToTxnID", $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { if ($schema_object->exists($usePath . 'ApplyCheckToTxnAdd')) { $Node = new QuickBooks_XML_Node("ApplyCheckToTxnAdd"); $Node->setChildDataAt($Node->name() . ' ' . 'TxnID', $child['data']->get("ToTxnID")); $Node->setChildDataAt($Node->name() . ' ' . 'Amount', $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { if ($schema_object->exists($usePath . 'ApplyCheckToTxnMod')) { $Node = new QuickBooks_XML_Node("ApplyCheckToTxnMod"); $Node->setChildDataAt($Node->name() . ' ' . 'TxnID', $child['data']->get("ToTxnID")); $Node->setChildDataAt($Node->name() . ' ' . 'Amount', $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { continue; } } } } } } } else { if (strpos($child['table'], "dataext") !== false) { continue; } } $map = ''; $others = array(); QuickBooks_SQL_Schema::mapToSchema($child['table'] . '.*', QUICKBOOKS_SQL_SCHEMA_MAP_TO_XML, $map, $others); $map = str_replace(' *', '', $map); $explode = explode(' ', $map); $first = trim(current($explode)); $map = trim(implode(' ', array_slice($explode, 1))); if (stripos($action, 'add') !== false) { $map = str_replace('Ret', 'Add', $map); } else { $map = str_replace('Ret', 'Mod', $map); } // Journal entries have an unusual JournalEntryMod syntax. Instead of // the typical CreditLineMod and DebitLineMod entries, they instead // have just a single combined entry, JournalLineMod. if ($action == QUICKBOOKS_MOD_JOURNALENTRY) { if ($child['table'] == 'journalentry_journaldebitline' or $child['table'] == 'journalentry_journalcreditline') { $map = 'JournalLineMod'; } } $Node = new QuickBooks_XML_Node($map); /* $retArr[$index]["table"] = $table; $retArr[$index]["data"] = QuickBooks_SQL_Object($table, null, $arr); $retArr[$index]["children"] */ foreach ($child['data']->asArray() as $field => $value) { $map = ''; $others = array(); QuickBooks_SQL_Schema::mapToSchema($child['table'] . '.' . $field, QUICKBOOKS_SQL_SCHEMA_MAP_TO_XML, $map, $others); if ($Driver->foldsToLower()) { $retpos = strpos($map, 'Ret '); $retval = substr($map, 0, $retpos + 4); $map = substr($map, $retpos + 4); if (stripos($action, 'add') !== false) { $map = str_replace('Ret ', 'Add ', $map); } else { $map = str_replace('Ret ', 'Mod ', $map); } //print('unfolding: {' . $map . '}' . "\n"); $map = $schema_object->unfold($map); //print(' unfolded to: [' . $map . ']' . "\n"); } //print($field . ' => ' . $value . "\n"); //print_r($map); //print("\n\n"); if (!$map or !strlen($value)) { continue; } // OK, the paths look like this: // CustomerRet FirstName // // We don't need the 'CustomerRet' part of it, that's actually incorrect, so we'll strip it off $explode = explode(' ', $map); $first = trim(current($explode)); $map = trim(implode(' ', array_slice($explode, 1))); if (stripos($action, "add") !== false) { $map = str_replace("Ret", "Add", $map); } else { $map = str_replace("Ret", "Mod", $map); } $map = preg_replace("/.*" . $Node->name() . " /", "", $map); /* if (strtolower($Node->name()) == "estimatelinemod" and strpos($map, 'TxnLineID') !== false ) { $value = -1; } */ if (false === strpos($map, ' ')) { if ($schema_object->exists($usePath . $Node->name() . ' ' . $map)) { $use_in_request = true; switch ($schema_object->dataType($usePath . $Node->name() . ' ' . $map)) { case 'AMTTYPE': $value = str_replace(',', '', number_format($value, 2)); break; case 'BOOLTYPE': if ($value == 1) { $value = 'true'; } else { if ($value == 0) { $value = 'false'; } else { $use_in_request = false; } } break; default: break; } if ($use_in_request) { $Child = new QuickBooks_XML_Node($map); $Child->setData($value); $Node->addChild($Child); } } else { // ignore it } } else { // Please see comments about JournalEntries above! if ($action == QUICKBOOKS_MOD_JOURNALENTRY) { $map = str_replace(array('JournalCreditLine ', 'JournalDebitLine '), '', $map); } if ($schema_object->exists($usePath . $Node->name() . ' ' . $map)) { $use_in_request = true; switch ($schema_object->dataType($usePath . $Node->name() . ' ' . $map)) { case 'AMTTYPE': $value = str_replace(',', '', number_format($value, 2)); break; case 'BOOLTYPE': if ($value == 1) { $value = 'true'; } else { if ($value == 0) { $value = 'false'; } else { $use_in_request = false; } } break; default: break; } if ($use_in_request) { $Node->setChildDataAt($Node->name() . ' ' . $map, $value, true); } } } } $tNodes = QuickBooks_Callbacks_SQL_Callbacks::_ChildObjectsToXML(strtolower($child['table']), $action, $child['children'], $usePath . $Node->name()); foreach ($tNodes as $tn) { $Node->addChild($tn); } $nodes[count($nodes)] = $Node; } return $nodes; }
protected static function _ChildObjectsToXML($type, $action, $children, $parentPath = '') { $nodes = array(); $file = 'QuickBooks/QBXML/Schema/Object/' . QuickBooks_Utilities::actionToRequest($action) . '.php'; $class = 'QuickBooks_QBXML_Schema_Object_' . QuickBooks_Utilities::actionToRequest($action); require_once $file; $schema_object = new $class(); $usePath = ''; if ($parentPath != "") { $usePath .= $parentPath . ' '; } foreach ($children as $child) { // Figure out which LinkedTxn method should be used... if (strpos($child['table'], "linkedtxn") !== false) { if (stripos($action, "add") !== false) { $part = preg_replace("/add/i", "", $action); $part .= "LineAdd"; } else { if (stripos($action, "mod") !== false) { $part = preg_replace("/mod/i", "", $action); $part .= "LineMod"; } } if ($schema_object->exists($usePath . 'LinkToTxnID')) { $Node = new QuickBooks_XML_Node("LinkToTxnID", $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { if ($schema_object->exists($action . ' ' . $part . ' ' . 'LinkToTxn')) { $Node = new QuickBooks_XML_Node("LinkToTxnID", $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { if ($schema_object->exists($usePath . 'LinkedTxn')) { $Node = new QuickBooks_XML_Node("LinkToTxnID", $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { if ($schema_object->exists($action . ' ' . $part . ' ' . 'LinkedTxn')) { $Node = new QuickBooks_XML_Node("LinkToTxnID", $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { if ($schema_object->exists($usePath . 'ApplyCheckToTxnAdd')) { $Node = new QuickBooks_XML_Node("ApplyCheckToTxnAdd"); $Node->setChildDataAt($Node->name() . ' ' . 'TxnID', $child['data']->get("ToTxnID")); $Node->setChildDataAt($Node->name() . ' ' . 'Amount', $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { if ($schema_object->exists($usePath . 'ApplyCheckToTxnMod')) { $Node = new QuickBooks_XML_Node("ApplyCheckToTxnMod"); $Node->setChildDataAt($Node->name() . ' ' . 'TxnID', $child['data']->get("ToTxnID")); $Node->setChildDataAt($Node->name() . ' ' . 'Amount', $child['data']->get("ToTxnID")); $nodes[count($nodes)] = $Node; continue; } else { continue; } } } } } } } else { if (strpos($child['table'], "dataext") !== false) { continue; } } $map = ''; $others = array(); QuickBooks_SQL_Schema::mapToSchema($child['table'] . ".*", QUICKBOOKS_SQL_SCHEMA_MAP_TO_XML, $map, $others); $map = str_replace(" *", "", $map); $explode = explode(' ', $map); $first = trim(current($explode)); $map = trim(implode(' ', array_slice($explode, 1))); if (stripos($action, "add") !== false) { $map = str_replace("Ret", "Add", $map); } else { $map = str_replace("Ret", "Mod", $map); } $Node = new QuickBooks_XML_Node($map); /* $retArr[$index]["table"] = $table; $retArr[$index]["data"] = QuickBooks_SQL_Object($table, null, $arr); $retArr[$index]["children"] */ foreach ($child['data']->asArray() as $field => $value) { $map = ''; $others = array(); QuickBooks_SQL_Schema::mapToSchema($child['table'] . '.' . $field, QUICKBOOKS_SQL_SCHEMA_MAP_TO_XML, $map, $others); /* print($field . ' => ' . $value . "\n"); print_r($map); print("\n\n"); */ if (!$map or !strlen($value)) { continue; } // OK, the paths look like this: // CustomerRet FirstName // // We don't need the 'CustomerRet' part of it, that's actually incorrect, so we'll strip it off $explode = explode(' ', $map); $first = trim(current($explode)); $map = trim(implode(' ', array_slice($explode, 1))); if (stripos($action, "add") !== false) { $map = str_replace("Ret", "Add", $map); } else { $map = str_replace("Ret", "Mod", $map); } $map = preg_replace("/.*" . $Node->name() . " /", "", $map); if (strtolower($Node->name()) == "estimatelinemod" and strpos($map, 'TxnLineID') !== false) { $value = -1; } if (false === strpos($map, ' ')) { if ($schema_object->exists($usePath . $Node->name() . ' ' . $map)) { $use_in_request = true; switch ($schema_object->dataType($usePath . $Node->name() . ' ' . $map)) { case 'AMTTYPE': $value = str_replace(",", "", number_format($value, 2)); break; case 'BOOLTYPE': if ($value == 1) { $value = 'true'; } else { if ($value == 0) { $value = 'false'; } else { $use_in_request = false; } } break; default: break; } if ($use_in_request) { $Child = new QuickBooks_XML_Node($map); $Child->setData($value); $Node->addChild($Child); } } else { //ignore it } } else { if ($schema_object->exists($usePath . $Node->name() . ' ' . $map)) { $use_in_request = true; switch ($schema_object->dataType($usePath . $Node->name() . ' ' . $map)) { case 'AMTTYPE': $value = str_replace(",", "", number_format($value, 2)); break; case 'BOOLTYPE': if ($value == 1) { $value = 'true'; } else { if ($value == 0) { $value = 'false'; } else { $use_in_request = false; } } break; default: break; } if ($use_in_request) { $Node->setChildDataAt($Node->name() . ' ' . $map, $value, true); } } } } $tNodes = QuickBooks_Server_SQL_Callbacks::_ChildObjectsToXML(strtolower($child['table']), $action, $child['children'], $usePath . $Node->name()); foreach ($tNodes as $tn) { $Node->addChild($tn); } $nodes[count($nodes)] = $Node; } return $nodes; }