Example #1
0
 function processOrder()
 {
     global $db, $messageStack;
     define('JOURNAL_ID', 10);
     // make them all sales orders for now
     define('GL_TYPE', 'soo');
     $this->msgDebug("\njournal_id = " . JOURNAL_ID . " and function = " . $this->function);
     $tax_rates = ord_calculate_tax_drop_down('c');
     $order = json_decode($_POST['Order'], true);
     // Here we map the received xml array to the pre-defined generic structure (application specific format later)
     if ($order['ReceivablesGLAccount'] != '') {
         // see if requestor specifies a AR account else use default
         define('DEF_GL_ACCT', $order['ReceivablesGLAccount']);
     } else {
         define('DEF_GL_ACCT', AR_DEFAULT_GL_ACCT);
     }
     $this->order = array('order_id' => $order['General']['OrderID'], 'purch_order_id' => $order['General']['PurchaseOrderID'], 'post_date' => $order['General']['OrderDate'], 'order_total' => $order['General']['OrderTotal'], 'tax_total' => $order['General']['TaxTotal'], 'freight_total' => $order['General']['ShippingTotal'], 'freight_carrier' => $order['General']['ShippingCarrier'], 'freight_method' => $order['General']['ShippingMethod'], 'rep_id' => $order['General']['SalesRepID'], 'payment' => array('holder_name' => $order['Payment']['CardHolderName'], 'method' => $order['Payment']['Method'], 'type' => $order['Payment']['CardType'], 'card_number' => $order['Payment']['CardNumber'], 'exp_date' => $order['Payment']['ExpirationDate'], 'cvv2' => $order['Payment']['CVV2Number']));
     // Billing and Shipping
     $types = array('billing' => 'Billing', 'shipping' => 'Shipping');
     foreach ($types as $key => $entry) {
         $this->order[$key] = array('primary_name' => $order[$entry]['CompanyName'], 'contact' => $order[$entry]['Contact'], 'address1' => $order[$entry]['Address1'], 'address2' => $order[$entry]['Address2'], 'city_town' => $order[$entry]['City'], 'state_province' => $order[$entry]['State'], 'postal_code' => $order[$entry]['PostalCode'], 'country_code' => $order[$entry]['Country'], 'telephone' => $order[$entry]['Telephone'], 'email' => $order[$entry]['Email']);
         if ($key == 'billing') {
             // additional information for the customer record
             $this->order[$key]['customer_id'] = $order[$entry]['CustomerID'];
         }
     }
     // if billing or shipping is blank, use customer address
     if ($this->order['billing']['primary_name'] == '' && $this->order['billing']['contact'] == '') {
         $this->order['billing'] = $this->order['customer'];
     }
     if ($this->order['shipping']['primary_name'] == '' && $this->order['shipping']['contact'] == '') {
         $this->order['shipping'] = $this->order['customer'];
     }
     // <LineItems>
     $this->order['items'] = array();
     foreach ($order['Item'] as $entry) {
         $item = array();
         $sku = $entry['ItemID'];
         // try to match sku and get the sales gl account
         $result = $db->Execute("SELECT account_sales_income FROM " . TABLE_INVENTORY . " WHERE sku='{$sku}'");
         if ($result->RecordCount() > 0) {
             $item['sku'] = $sku;
             $item['gl_acct'] = $result->fields['account_sales_income'];
         } else {
             $result = $db->Execute("SELECT sku, account_sales_income FROM " . TABLE_INVENTORY . " WHERE description_short='{$sku}'");
             $item['sku'] = $result->fields['sku'];
             $item['gl_acct'] = $result->fields['account_sales_income'];
         }
         $item['description'] = $entry['Description'];
         $item['quantity'] = $entry['Quantity'];
         $item['unit_price'] = $entry['UnitPrice'];
         $item['tax_percent'] = $entry['SalesTaxPercent'];
         //		$item['sales_tax']   = $entry['SalesTax']; // sales tax will be calculated
         $item['taxable'] = $this->guess_tax_id($tax_rates, $item['tax_percent']);
         $item['total_price'] = $entry['TotalPrice'];
         $this->order['items'][] = $item;
     }
     if (function_exists('xtra_order_data')) {
         xtra_order_data($this->order, $order);
     }
     $this->buildJournalEntry();
 }
Example #2
0
 function processOrder($objXML)
 {
     global $db, $messageStack;
     // build the tax table to set the tax rates
     switch ($this->function) {
         case 'SalesInvoice':
             define('JOURNAL_ID', 12);
             define('GL_TYPE', 'sos');
             break;
         case 'SalesOrder':
         default:
             define('JOURNAL_ID', 10);
             define('GL_TYPE', 'soo');
     }
     $messageStack->debug("\njournal_id = " . JOURNAL_ID . " and function = " . $this->function);
     $tax_rates = ord_calculate_tax_drop_down('c');
     // Here we map the received xml array to the pre-defined generic structure (application specific format later)
     if (!is_array($objXML->Request->Order)) {
         $objXML->Request->Order = array($objXML->Request->Order);
     }
     foreach ($objXML->Request->Order as $order) {
         if ($order->ReceivablesGLAccount != '') {
             // see if requestor specifies a AR account else use default
             define('DEF_GL_ACCT', $order->ReceivablesGLAccount);
         } else {
             define('DEF_GL_ACCT', AR_DEFAULT_GL_ACCT);
         }
         $this->order = array();
         $this->order['reference'] = $order->Reference;
         $this->order['store_id'] = $order->StoreID;
         $this->order['sales_gl_account'] = $order->SalesGLAccount;
         $this->order['receivables_gl_acct'] = $order->ReceivablesGLAccount;
         $this->order['order_id'] = $order->OrderID;
         $this->order['purch_order_id'] = $order->PurchaseOrderID;
         $this->order['post_date'] = $order->OrderDate;
         $this->order['order_total'] = $order->OrderTotal;
         $this->order['tax_total'] = $order->TaxTotal;
         $this->order['freight_total'] = $order->ShippingTotal;
         $this->order['freight_carrier'] = $order->ShippingCarrier;
         $this->order['freight_method'] = $order->ShippingMethod;
         $this->order['rep_id'] = $order->SalesRepID;
         //	  $this->order['discount_total']         = $order->DiscountTotal;
         // <Payment>
         $this->order['payment']['holder_name'] = $order->Payment->CardHolderName;
         $this->order['payment']['method'] = $order->Payment->Method;
         $this->order['payment']['type'] = $order->Payment->CardType;
         $this->order['payment']['card_number'] = $order->Payment->CardNumber;
         $this->order['payment']['exp_date'] = $order->Payment->ExpirationDate;
         $this->order['payment']['cvv2'] = $order->Payment->CVV2Number;
         // <Customer> and <Billing> and <Shipping>
         $types = array('customer', 'billing', 'shipping');
         foreach ($types as $value) {
             $entry = ucfirst($value);
             $this->order[$value]['primary_name'] = $order->{$entry}->CompanyName;
             $this->order[$value]['contact'] = $order->{$entry}->Contact;
             $this->order[$value]['address1'] = $order->{$entry}->Address1;
             $this->order[$value]['address2'] = $order->{$entry}->Address2;
             $this->order[$value]['city_town'] = $order->{$entry}->CityTown;
             $this->order[$value]['state_province'] = $order->{$entry}->StateProvince;
             $this->order[$value]['postal_code'] = $order->{$entry}->PostalCode;
             $this->order[$value]['country_code'] = $order->{$entry}->CountryCode;
             $this->order[$value]['telephone'] = $order->{$entry}->Telephone;
             $this->order[$value]['email'] = $order->{$entry}->Email;
             if ($value == 'customer') {
                 // additional information for the customer record
                 $this->order[$value]['customer_id'] = $order->{$entry}->CustomerID;
             }
         }
         // if billing or shipping is blank, use customer address
         if ($this->order['billing']['primary_name'] == '' && $this->order['billing']['contact'] == '') {
             $this->order['billing'] = $this->order['customer'];
         }
         if ($this->order['shipping']['primary_name'] == '' && $this->order['shipping']['contact'] == '') {
             $this->order['shipping'] = $this->order['customer'];
         }
         // <LineItems>
         $this->order['items'] = array();
         if (!is_array($order->Item)) {
             $order->Item = array($order->Item);
         }
         foreach ($order->Item as $entry) {
             $item = array();
             $sku = $entry->ItemID;
             // try to match sku and get the sales gl account
             $result = $db->Execute("select account_sales_income from " . TABLE_INVENTORY . " where sku = '" . $sku . "'");
             if ($result->RecordCount() > 0) {
                 $item['sku'] = $sku;
                 $item['gl_acct'] = $result->fields['account_sales_income'];
             } else {
                 $result = $db->Execute("select sku, account_sales_income from " . TABLE_INVENTORY . " where description_short = '" . $sku . "'");
                 $item['sku'] = $result->fields['sku'];
                 $item['gl_acct'] = $result->fields['account_sales_income'];
             }
             $item['description'] = $entry->Description;
             $item['quantity'] = $entry->Quantity;
             $item['unit_price'] = $entry->UnitPrice;
             $item['tax_percent'] = $entry->SalesTaxPercent;
             //		$item['sales_tax']   = $entry->SalesTax; // sales tax will be calculated
             $item['taxable'] = $this->guess_tax_id($tax_rates, $item['tax_percent']);
             $item['total_price'] = $entry->TotalPrice;
             $this->order['items'][] = $item;
         }
         if (function_exists('xtra_order_data')) {
             xtra_order_data($this->order, $order);
         }
         $this->buildJournalEntry();
         $this->buildJournalResponse();
     }
     return true;
 }