Пример #1
0
 /**
  * Handle response from a request
  *
  * Method will handle the response from a request
  *
  * @access protected
  * @return bool true if the response was successful and handled correctly, FALSE otherwise
  */
 protected function response()
 {
     /**
      * This service is kind of private and so we don't need to worry about creating children services and so forth. Just parse and return true
      * as this will always be a child service itself and will then get deleted automatically
      */
     parent::handleResponse();
     return true;
 }
 /**
  * Handle response from a request
  *
  * Method will handle the response from a request
  *
  * @access protected
  * @return bool true if the response was successful and handled correctly, FALSE otherwise
  */
 protected function response()
 {
     /**
      * If we failed to insert this record, then check the response status code. If there is an error code then just die as each sales order should
      * be unique
      */
     if (($code = parent::handleResponse()) !== true) {
         throw new Exception('An error occured when trying to handle the response from the InventoryAdjustmentAdd spool ' . $this->data->spoolID);
     }
     return true;
 }
Пример #3
0
 /**
  * Handle response from a request
  *
  * Method will handle the response from a request
  *
  * @access protected
  * @return bool true if the response was successful and handled correctly, FALSE otherwise
  */
 protected function response()
 {
     /**
      * If we failed to insert this record, then check the response status code. If the code is 3100 'Name is not unique' then we execute the required
      * services to 'edit' this account
      */
     if (($code = parent::handleResponse()) !== true) {
         if ($code == 3100) {
             /**
              * Just quickly check to see if we already have the ListID for this account first. If we do then we just saved a 'accountmod' SOAP call.
              */
             $reference = $this->getAccountingReference($this->spoolData['accountingspoolnode'], 'account');
             if ($reference) {
                 /**
                  * Only call the AccountMod if we have version 6.0 or above! If so then forcefully set this service as executed
                  */
                 if (!$this->quickbooks->compareClientVersion('6.0')) {
                     $this->quickbooks->setSpoolAsExecuted($this->spoolId, true);
                     return true;
                 }
                 /**
                  * Run our 'accountmod' service with this information. Add this job as a child
                  */
                 $editSpoolId = $this->createChildSpool('account', 'edit', $reference);
                 if (isId($editSpoolId)) {
                     return true;
                 }
                 throw new Exception('Cannot initiate an "AccountMod" override service for the AccountAdd spool ' . $this->spoolId);
             }
             /**
              * Ok, we didn't find a match. Run the "accountquery" service and associate it with this service
              */
             $querySpoolId = $this->createChildSpool('account', 'query', $this->spoolData['accountingspoolnode']);
             if (isId($querySpoolId)) {
                 return true;
             }
             throw new Exception('Cannot initiate an "AccountQuery" override service for the AccountAdd spool ' . $this->spoolId);
         }
         throw new Exception('An error occured when trying to handle the response from the AccountAdd spool ' . $this->spoolId);
     }
     /**
      * Account was successfully added, now all we need to do is to store the association information for this account
      */
     $listid = trim(@(string) $this->data->info->AccountRet->ListID);
     $sequence = trim(@(string) $this->data->info->AccountRet->EditSequence);
     if ($listid !== '' && $sequence !== '') {
         $reference = array('ListID' => $listid, 'EditSequence' => $sequence, 'Name' => $this->spoolData['accountingspoolnode']['Name'], 'AccountType' => $this->spoolData['accountingspoolnode']['AccountType']);
         $this->quickbooks->setAccountingReference($this->spoolData['accountingspoolnode'], 'account', $reference);
         return true;
     }
     throw new Exception('Cannot insert the account using the information in the AccountAdd spool ' . $this->spoolId);
 }
 /**
  * Handle response from a request
  *
  * Method will handle the response from a request
  *
  * @access protected
  * @return bool true if the response was successful and handled correctly, FALSE otherwise
  */
 protected function response()
 {
     /**
      * If we failed to insert this record, then check the response status code. If the code is 3100 'Name is not unique' then we execute the required
      * services to 'edit' this customer
      */
     if (($code = parent::handleResponse()) !== true) {
         if ($code == 3100) {
             /**
              * Just quickly check to see if we already have the ListID for this customer group first. If we do then we just saved a 'pricelevelquery' SOAP call
              */
             $reference = $this->getAccountingReference($this->spoolData['accountingspoolnodeid'], 'customergroup');
             if ($reference) {
                 /**
                  * Run our 'pricelevelmod' service with this information. Add this job as a child
                  */
                 $editSpoolId = $this->createChildSpool('customergroup', 'edit', $this->spoolData['accountingspoolnode']);
                 if (isId($editSpoolId)) {
                     return true;
                 }
                 throw new Exception('Cannot initiate an "PriceLEvelMod" override service for the PriceLevelAdd spool ' . $this->spoolId);
             }
             $servicedata = array('info' => $object);
             /**
              * Ok, we didn't find a match. Run the "pricelevelquery" service and associate it with this service
              */
             $querySpoolId = $this->createChildSpool('customergroup', 'query', $this->spoolData['accountingspoolnode']);
             if (isId($querySpoolId)) {
                 return true;
             }
             throw new Exception('Cannot initiate an "PriceLevelQuery" override service for the PriceLevelAdd spool ' . $this->spoolId);
         }
         throw new Exception('An error occured when trying to handle the response from the PriceLevelAdd spool ' . $this->spoolId);
     }
     /**
      * Customer group was successfully added, now all we need to do is to store the association information for this customer group
      */
     $listid = trim(@(string) $this->data->info->PriceLevelRet->ListID);
     $sequence = trim(@(string) $this->data->info->PriceLevelRet->EditSequence);
     if ($listid !== '' && $sequence !== '') {
         $reference = array('ListID' => $listid, 'EditSequence' => $sequence);
         $this->setAccountingReference($this->spoolData['accountingspoolnodeid'], 'customergroup', $reference);
         return true;
     }
     throw new Exception('Cannot insert the customer group using the information in the PriceLEvelAdd spool ' . $this->spoolId);
 }
Пример #5
0
 /**
  * Handle response from a request
  *
  * Method will handle the response from a request
  *
  * @access protected
  * @return bool true if the response was successful and handled correctly, FALSE otherwise
  */
 protected function response()
 {
     /**
      * If QuickBooks cannot find our account then query it for the proper information with the 'accountquery' service
      */
     if (($code = parent::handleResponse()) !== true) {
         /**
          * 3120 means the record cannot be found and 3200 means that the EditSequence is out of sync. Either way the reference data is stale
          */
         if ($code == 3120 || $code == 3200) {
             /**
              * Ok, we didn't find a match. Run the "accountquery" service and associate it with this service
              */
             $querySpoolId = $this->createChildSpool('account', 'query', $this->spoolData['accountingspoolnode']);
             if (isId($querySpoolId)) {
                 return true;
             }
             throw new Exception('Cannot initiate an "AccountQuery" override service for the AccountMod spool ' . $this->spoolId);
         }
         throw new Exception('An error occured when trying to handle the response from the AccountMod spool ' . $this->spoolId);
     }
     /**
      * Save the ref id if we can. Find the account first using the name and then associate the ref id with that account. This should not determine
      * the outcome of this mehtod as the account has already been inserted into QuickBooks by now
      */
     $listid = trim(@(string) $this->data->info->AccountRet->ListID);
     $sequence = trim(@(string) $this->data->info->AccountRet->EditSequence);
     if ($listid !== '' && $sequence !== '') {
         $reference = array('ListID' => $listid, 'EditSequence' => $sequence, 'Name' => $this->spoolData['accountingspoolnode']['Name'], 'AccountType' => $this->spoolData['accountingspoolnode']['AccountType']);
         $this->quickbooks->setAccountingReference($this->spoolData['accountingspoolnode'], 'account', $reference);
         return true;
     }
     throw new Exception('Cannot insert the account using the information in the AccountMod spool ' . $this->spoolId);
 }
 /**
  * Handle response from a request
  *
  * Method will handle the response from a request
  *
  * @access protected
  * @return bool true if the response was successful and handled correctly, FALSE otherwise
  */
 protected function response()
 {
     /**
      * If we failed to insert this record, then check the response status code. If there is an error code then just die as each sales order should
      * be unique
      */
     if (($code = parent::handleResponse()) !== true) {
         throw new Exception('An error occured when trying to handle the response from the SalesOrderEdit spool ' . $this->spoolId);
     }
     /**
      * SalesOrder was successfully added, now all we need to do is to store the association information for this order and decerement the stock on hand levels
      */
     $txnid = trim(@(string) $this->data->info->SalesOrderRet->TxnID);
     $sequence = trim(@(string) $this->data->info->SalesOrderRet->EditSequence);
     if ($txnid !== '' && $sequence !== '') {
         $reference = array('TnxID' => $txnid, 'EditSequence' => $sequence);
         $this->quickbooks->setAccountingReference($this->spoolData['accountingspoolnodeid'], 'order', $reference);
         /**
          * Next we need to save the order - product association id that QuickBooks use
          */
         foreach ($this->data->info->SalesOrderRet->SalesOrderLineRet as $lineItem) {
             $productId = null;
             foreach ($this->spoolData['accountingspoolnode']['products'] as $key => $product) {
                 if ($product['prodname'] == $lineItem->Desc) {
                     $productId = $product['productid'];
                 }
             }
             if (!isId($productId)) {
                 continue;
             }
             $itemID = array('TnxID' => $txnid, 'EditSequence' => $sequence, 'ProductID' => $productId);
             $itemReference = array('TnxID' => $txnid, 'EditSequence' => $sequence, 'ProductID' => $productId, 'TxnLineID' => (string) $lineItem->TxnLineID);
             $this->quickbooks->setAccountingReference($itemID, 'orderlineitem', $itemReference);
         }
         /**
          * Now assign a child spool to adjust all the product quantity levels but only if we have version 4.0 or above
          */
         if ($this->quickbooks->compareClientVersion('4.0')) {
             $products = array();
             $prevProds = array();
             $prevSpoolId = null;
             /**
              * Run through the previous ordered products so we can deduct them first. These need to be in a separate sppol as QuickBooks can't handle
              * 2 or more of the same items in the one transaction
              */
             if (isset($this->spoolData['accountingspoolnode']['previous'])) {
                 foreach ($this->spoolData['accountingspoolnode']['previous']['products'] as $key => $product) {
                     $reference = $this->quickbooks->getAccountingReference($product['productid'], 'product');
                     if (!$reference) {
                         throw new Exception('Cannot find the product account reference data (Prod# ' . $product['productid'] . ') for the SalesOrderEdit spool ' . $this->spoolId);
                     }
                     $prevProds[] = array('ListID' => $reference['ListID'], 'QuantityDifference' => $product['prodorderquantity']);
                 }
                 if (!empty($prevProds)) {
                     $prevSpoolId = $this->createChildSpool('inventorylevel', 'add', $prevProds);
                 }
             }
             /**
              * Now for the current ordered products
              */
             foreach ($this->spoolData['accountingspoolnode']['products'] as $key => $product) {
                 $reference = $this->quickbooks->getAccountingReference($product['productid'], 'product');
                 if (!$reference) {
                     throw new Exception('Cannot find the product account reference data (Prod# ' . $product['productid'] . ') for the SalesOrderEdit spool ' . $this->spoolId);
                 }
                 $products[] = array('ListID' => $reference['ListID'], 'QuantityDifference' => $product['prodorderquantity'] * -1);
             }
             if (empty($products)) {
                 throw new Exception('Cannot load any products for the "InventoryAdjustmentAdd" child service for the SalesOrderEdit spool ' . $this->spoolId);
             }
             /**
              * Leave the previous child spool as the current one FI htere is one
              */
             if (isId($prevSpoolId)) {
                 $setAsCurrent = false;
             } else {
                 $setAsCurrent = true;
             }
             $adjustSpoolId = $this->createChildSpool('inventorylevel', 'add', $products, $setAsCurrent);
             if (isId($adjustSpoolId)) {
                 return true;
             }
             throw new Exception('Cannot initiate an "InventoryAdjustmentAdd" child service for the SalesOrderEdit spool ' . $this->spoolId);
         }
         return true;
     }
     throw new Exception('Cannot insert the order using the information in the SalesOrderEdit spool ' . $this->spoolId);
 }