public function run() { spl_autoload_register(function ($sClass) { $sClass = str_replace("_", "/", $sClass); include $sClass . '.php'; }); $fDiscountTotal = 0; $errors = array(); $this->worker->addData(array('receiptId' => $this->receiptId)); try { switch ($this->orderType) { case null: // Error $this->worker->addData(array('ignore' => true)); $errors[] = 'Order Type was NULL'; break; case 999: // Error $this->worker->addData(array('ignore' => true)); $errors[] = 'Error Code 999'; break; case 2: // EXCHANGE - Swap for Different Item $this->worker->addData(array('ignore' => true)); $errors[] = 'Exchange'; break; case 3: // EXCHANGE - One for One Exchange $this->worker->addData(array('ignore' => true)); $errors[] = 'Exchange'; break; case 1: // REFUND $items = LivePos_Maps_MapFactory::create('itemlist', $this->_raworder['enumProductsSold'], $this->_locationData); $refund = LivePos_Maps_MapFactory::create('refund', $this->_raworder, $this->_locationData, $items); $this->worker->addData(array('encrypted' => $this->_getEncryptedRefundJson($refund))); $this->worker->addData(array('entityId' => $this->_locationData['location_entity'])); $this->worker->addData(array('order_id' => $this->_orderId)); break; case 0: // Sale $items = LivePos_Maps_MapFactory::create('itemlist', $this->_raworder['enumProductsSold'], $this->_locationData); $customer = LivePos_Maps_MapFactory::create('customer', $this->_raworder, $this->_locationData); $order = LivePos_Maps_MapFactory::create('order', $this->_raworder, $this->_locationData, $this->_orderId); $discounts = LivePos_Maps_MapFactory::create('discountlist', $this->_raworder['enumCouponDiscounts']); $payments = LivePos_Maps_MapFactory::create('paymentlist', $this->_raworder['enumPayments']); $this->_processPayments($order, $payments, $discounts); if ($discounts->hasDiscounts()) { $items->popPreDiscountPrices(); } // Process InStore/Shipped Orders if ($this->_orderToMerge != null) { $sPosOriginalId = $this->_orderId; $aOrderToMerge = json_decode($this->_orderToMerge, true); $order->setMultiShipTo(true); $customer->mergeCustomer($aOrderToMerge['customer']); // Reset ID to Activa ID, TEMP until exposeure in receipt $order->setOrderId($aOrderToMerge['order']['custbody_order_source_id']); $this->_orderId = $aOrderToMerge['order']['custbody_order_source_id']; array_walk($aOrderToMerge['order']['item'], function ($aItem, $sKey) use(&$items) { $item = LivePos_Maps_MapFactory::create('item', $aItem, $this->_locationData, true); switch ($items->isOldStyle()) { case true: // OLD STYLE WEBORDER ENTRY $items->addItem($item); break; case false: // New Style... replace item with web order item $items->mergeItem($item); break; } }); // Catch Non Payed For Items per George 3/15/15 if ($items->hasMergerErrors()) { $mergerErrorItems = $items->getNonMergedItems(); $order->setFulFillmentTo('A'); Utils_Email::sendMergeEmail($this->_orderId, $sPosOriginalId, $mergerErrorItems); } } $order->addItems($items->getItemsArray()); $order->setShippedTax($items->getShippingTax()); $order->setShippingCharge($items->getShippingCharge()); $this->_processDiscounts($order, $items, $discounts); $this->worker->addData(array('order_id' => $this->_orderId)); // DEBUG STUFF $this->worker->addData(array('posTotal' => $order->getPosTotal())); $this->worker->addData(array('orderTotal' => $order->getTotal())); $this->worker->addData(array('webItems' => $items->getWebItemsTotal())); $this->worker->addData(array('invoiceId' => $order->getInvoiceId())); // END DEBUG $this->worker->addData(array('encrypted' => $this->_getEncryptedJson($customer, $order))); $this->worker->addData(array('entityId' => $this->_locationData['location_entity'])); $this->worker->addData(array('web_items' => $items->hasWebItems)); break; default: $errors[] = 'Did Not Recognize Transaction Type: ' . $this->orderType; break; } $sFlatErrors = implode(',', $errors); $this->worker->addData(array('error' => $sFlatErrors)); } catch (Exception $e) { LivePos_Db_Model::logError($e); $this->worker->addData(array('error' => $e->getMessage())); $this->worker->addData(array('ignore' => true)); } }