public function execRequest()
	{
		if (is_array($this->spool["children"]) && !empty($this->spool["children"])) {
			$lastKid = end($this->spool["children"]);

			switch (isc_strtolower($lastKid["service"])) {
				case "query":

					/**
					 * If we have an error here then that would mean that adding created a duplicate error
					 * but querying for it return nothing. Bad news
					 */
					if ($lastKid["errNo"] > 0) {
						throw new QBException("Caught a QBJD error when adding a prerequisite record", $lastKid);
					}

					/**
					 * Our query kid was successfully so we need to create the reference data from the
					 * response. If we can't create the reference then we need to error out
					 */
					$queryResponse = $lastKid["response"];
					$queryResponse += $lastKid["nodeData"];

					if (!$this->setReferenceData($queryResponse, '*')) {
						throw new QBException("Cannot create reference data from prerequisite query response", $queryResponse);
					}

					return $this->execNextService();
					break;
			}
		}

		return parent::execRequest();
	}
Example #2
0
	public function execRequest()
	{
		if (array_key_exists("modifiedDate", $this->spool["nodeData"])) {
			$entity = $this->entityObjectFactory();
			return $entity->buildQuerySyncXML();
		} else {
			return parent::execRequest();
		}
	}
Example #3
0
	public function execRequest()
	{
		if (is_array($this->spool["children"]) && !empty($this->spool["children"])) {
			$lastKid = end($this->spool["children"]);

			switch (isc_strtolower($lastKid["service"])) {
				case "query":

					/**
					 * If we have an error here then that would mean that adding created a duplicate error
					 * but querying for it return nothing. Bad news
					 */
					if ($lastKid["errNo"] > 0) {
						throw new QBException("Caught a QBJD error when adding a customer record", $lastKid);
					}

					/**
					 * Our query kid was successfully so we need to create the reference data from the
					 * response. If we can't create the reference then we need to error out
					 */
					if (!$this->setReferenceData($lastKid["response"])) {
						throw new QBException("Cannot create reference data from customer query response", $queryResponse);
					}

					return $this->execChildService("customer", "edit", $this->spool["nodeData"]);
					break;

				case "edit":

					/**
					 * If we have an error here then that would mean that adding created a duplicate error,
					 * querying for it return a record but editing that record returned an error. Bad news
					 */
					if ($lastKid["errNo"] > 0) {
						throw new QBException("Caught a QBJD error when editing a customer record (from customeradd)", $lastKid);
					}

					/**
					 * OK, the account was added (edited) successfully, so mark this as successful and esacpe this service
					 */
					return $this->execNextService();
					break;
			}
		}

		return parent::execRequest();
	}
	public function execRequest()
	{
		if (is_array($this->spool["children"]) && !empty($this->spool["children"])) {
			$lastKid = end($this->spool["children"]);

			switch (isc_strtolower($lastKid["service"])) {
				case "add":

					/**
					 * Adding will handle both adding a new product OR editing an existing product with a
					 * bad reference, so either way just escape it here
					 */
					return $this->execNextService();
					break;
			}
		}

		return parent::execRequest();
	}
Example #5
0
	/**
	 * Handle the order response
	 *
	 * Method will handle all the order responses. Mainly it is used for recording the "orderitem" references
	 *
	 * @access public
	 * @return bool The output of the parent execResponse method on success, throw an error on failure
	 */
	public function execResponse()
	{
		$output = parent::execResponse();

		if (isc_strtolower(trim($this->spool["service"])) == "query") {
			return $output;
		}

		/**
		 * If we died at the parent then there is no point in continuing
		 */
		if (!$output) {
			return $output;
		}

		if ($this->accounting->getValue("orderoption") == "order") {
			$salesLineRetTag = "SalesOrderLineRet";
		} else {
			$salesLineRetTag = "SalesReceiptLineRet";
		}

		/**
		 * Record the TxnLineID's for all the products
		 */
		if (!isset($this->spool["response"][$salesLineRetTag]) || !is_array($this->spool["response"][$salesLineRetTag])) {
			throw new QBException("Unable to find the " . $salesLineRetTag . " records for order ID: " . $this->spool["nodeId"], array("Tag" => $salesLineRetTag, " response" => $this->spool["response"]));
		}

		/**
		 * Remove all the TxnListID records for this order first as QB will change the TxnListID records EVERYTIME
		 * you add/edit an order (fun times)
		 */
		$searchData = array(
			"OrderID" => $this->spool["nodeId"]
		);

		$orderItemRef = $this->accounting->getReference("orderitem", $searchData, '', '', false);

		while (is_array($orderItemRef)) {
			$this->accounting->unsetReference("orderitem", $orderItemRef["accountingrefid"]);
			$orderItemRef = $this->accounting->getReference("orderitem", $searchData, '', '', false);
		}

		foreach ($this->spool["response"][$salesLineRetTag] as $productData) {

			if (!array_key_exists("TxnLineID", $productData)) {
				throw new QBException("Unable to find product TxnLineID for order ID: " . $this->spool["nodeId"], array("order" => $this->spool["nodeData"], "product" => $productData));
			}

			if (!array_key_exists("ItemRef", $productData) || !is_array($productData["ItemRef"]) || !array_key_exists("ListID", $productData["ItemRef"])) {
				throw new QBException("Unable to find product ListID for order ID: " . $this->spool["nodeId"], array("order" => $this->spool["nodeData"], "product" => $productData));
			}

			/**
			 * OK, recird the TxnListID. Unfortunately we do not know if this product is a normal one, a variation, a shipping cost
			 * or a tax component, so check for all
			 */
			$checkTypes = array("product", "productvariation", "prerequisite");
			$productType = "";

			foreach ($checkTypes as $checkType) {
				if ($this->accounting->getReference($checkType, '', $productData["ItemRef"]["ListID"], '', false)) {
					$productType = $checkType;
					break;
				}
			}

			/**
			 * If no reference then something is wrong
			 */
			if (trim($productType) == '') {
				throw new QBException("Unable to find product reference for order ID: " . $this->spool["nodeId"], array("order" => $this->spool["nodeData"], "product" => $productData));
			}

			/**
			 * OK, we've got the "product" reference data, now create the orderitem reference
			 */
			$referenceData = array(
				"TxnLineID" => $productData["TxnLineID"],
				"ListID" => $productData["ItemRef"]["ListID"],
				"OrderID" => $this->spool["nodeId"],
				"Type" => $productType
			);
			/**
			 * This one is setting up the orderitem (product) in the database in the accountingref table
			 */
			$refId = $this->accounting->setReference("orderitem", $referenceData, '', $productData["TxnLineID"], $prodRef["accountingrefnodeid"]);

			if (!isId($refId)) {
				throw new QBException("Unable to create product reference for order ID: " . $this->spool["nodeId"], array("order" => $this->spool["nodeData"], "product" => $productData));
			}
		}

		return $output;
	}