Пример #1
0
 public function getLatestETAs($sender, $param)
 {
     $result = $error = array();
     try {
         $pageNo = $this->pageNumber;
         $pageSize = $this->pageSize;
         if (isset($param->CallbackParameter->pagination)) {
             $pageNo = $param->CallbackParameter->pagination->pageNo;
             $pageSize = $param->CallbackParameter->pagination->pageSize;
         }
         $notSearchStatusIds = array(OrderStatus::ID_CANCELLED, OrderStatus::ID_PICKED, OrderStatus::ID_SHIPPED);
         OrderItem::getQuery()->eagerLoad('OrderItem.order', 'inner join', 'ord', 'ord.id = ord_item.orderId and ord.active = 1');
         $stats = array();
         $oiArray = OrderItem::getAllByCriteria("(eta != '' and eta IS NOT NULL and eta != ? and ord.statusId not in (" . implode(',', $notSearchStatusIds) . "))", array(trim(UDate::zeroDate())), true, $pageNo, $pageSize, array("ord_item.eta" => "ASC", "ord_item.orderId" => "DESC"), $stats);
         $result['pagination'] = $stats;
         $result['items'] = array();
         foreach ($oiArray as $oi) {
             if (!$oi->getProduct() instanceof product) {
                 continue;
             }
             $tmp['eta'] = trim($oi->getEta());
             $tmp['orderNo'] = $oi->getOrder()->getOrderNo();
             $tmp['sku'] = $oi->getProduct() instanceof Product ? $oi->getProduct()->getSku() : '';
             $tmp['productName'] = $oi->getProduct()->getName();
             $tmp['id'] = $oi->getId();
             $tmp['orderId'] = $oi->getOrder()->getId();
             $result['items'][] = $tmp;
         }
     } catch (Exception $ex) {
         $error[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($result, $error);
 }
Пример #2
0
 private function _getInsufficientStockOrders($params)
 {
     $pageNo = isset($params['pageNo']) ? trim($params['pageNo']) : 1;
     $pageSize = isset($params['pageSize']) ? trim($params['pageSize']) : DaoQuery::DEFAUTL_PAGE_SIZE;
     $sql = "select distinct pro.id, sum(ord_item.qtyOrdered) `orderedQty`, pro.stockOnHand, pro.stockOnPO\r\n  \t\t\t\tfrom product pro\r\n  \t\t\t\tinner join orderitem ord_item on (ord_item.productId = pro.id and ord_item.active = 1)\r\n  \t\t\t\tinner join `order` ord on (ord.id = ord_item.orderId and ord.active = 1 and ord.type in (:ordType1, :ordType2) and ord.statusId in (:ordStatusId1, :ordStatusId2))\r\n  \t\t\t\twhere pro.active = 1\r\n  \t\t\t\tgroup by pro.id\r\n  \t\t\t\thaving `orderedQty` > (pro.stockOnHand + pro.stockOnPO)\r\n  \t\t\t\torder by ord.id";
     $result = Dao::getResultsNative($sql, array('ordType1' => Order::TYPE_ORDER, 'ordType2' => Order::TYPE_INVOICE, 'ordStatusId1' => OrderStatus::ID_NEW, 'ordStatusId2' => OrderStatus::ID_INSUFFICIENT_STOCK), PDO::FETCH_ASSOC);
     if (count($result) === 0) {
         return array();
     }
     $productMap = array();
     foreach ($result as $row) {
         $productMap[$row['id']] = $row;
     }
     OrderItem::getQuery()->eagerLoad('OrderItem.order', 'inner join', 'ord', 'ord.id = ord_item.orderId and ord.active = 1 and ord.type in (?,?) and ord.statusId in (?,?)');
     $sqlParams = array(Order::TYPE_ORDER, Order::TYPE_INVOICE, OrderStatus::ID_NEW, OrderStatus::ID_INSUFFICIENT_STOCK);
     $where = 'ord_item.active = 1 and ord_item.productId in (' . implode(', ', array_fill(0, count(array_keys($productMap)), '?')) . ')';
     $sqlParams = array_merge($sqlParams, array_keys($productMap));
     $items = OrderItem::getAllByCriteria($where, $sqlParams, true, $pageNo, $pageSize, array('ord_item.id' => 'desc'));
     $return = array();
     foreach ($items as $item) {
         $extra = array('totalOrderedQty' => isset($productMap[$item->getProduct()->getId()]) ? $productMap[$item->getProduct()->getId()]['orderedQty'] : 0);
         $return[] = $item->getJson($extra);
     }
     return array('items' => $return);
 }
Пример #3
0
 /**
  * Getting the orders
  * 
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  * 
  */
 public function getOrderItems($sender, $param)
 {
     $results = $errors = array();
     try {
         if (!isset($param->CallbackParameter->searchCriteria) || count($serachCriteria = json_decode(json_encode($param->CallbackParameter->searchCriteria), true)) === 0) {
             throw new Exception('System Error: search criteria not provided!');
         }
         $pageNo = 1;
         $pageSize = DaoQuery::DEFAUTL_PAGE_SIZE;
         if (isset($param->CallbackParameter->pagination)) {
             $pageNo = $param->CallbackParameter->pagination->pageNo;
             $pageSize = $param->CallbackParameter->pagination->pageSize;
         }
         $noSearch = true;
         $where = array(1);
         $params = array();
         foreach ($serachCriteria as $field => $value) {
             if (is_array($value) && count($value) === 0 || is_string($value) && ($value = trim($value)) === '') {
                 continue;
             }
             OrderItem::getQuery()->eagerLoad("OrderItem.order", 'inner join', 'ord', 'ord.id = ord_item.orderId');
             switch ($field) {
                 case 'ord.orderNo':
                 case 'ord.invNo':
                     $where[] = $field . " like ? ";
                     $params[] = $value . '%';
                     break;
                 case 'ord_item.isOrdered':
                     $where[] = $field . " = ? ";
                     $params[] = $value;
                     break;
                 case 'ord_item.eta.from':
                     $where[] = 'ord_item.eta >= ?';
                     $params[] = $value;
                     break;
                 case 'ord_item.eta.to':
                     $where[] = 'ord_item.eta <= ?';
                     $params[] = $value;
                     break;
             }
             $noSearch = false;
         }
         if ($noSearch === true) {
             throw new Exception("Nothing to search!");
         }
         $stats = array();
         $orderItems = OrderItem::getAllByCriteria(implode(' AND ', $where), $params, true, $pageNo, $pageSize, array('ord_item.eta' => 'asc', 'ord.orderNo' => 'asc'), $stats);
         $results['pageStats'] = $stats;
         $results['items'] = array();
         foreach ($orderItems as $item) {
             $orderItemArray = $item->getJson();
             $comments = Comments::getAllByCriteria('entityName = ? and entityId = ?', array('OrderItem', $item->getId()), true, null, DaoQuery::DEFAUTL_PAGE_SIZE, array('created' => 'desc'));
             $orderItemArray['comments'] = array_map(create_function('$a', 'return $a->getJson();'), $comments);
             $results['items'][] = $orderItemArray;
         }
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Пример #4
0
 /**
  * saveOrder
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  *
  */
 public function saveOrder($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         $customer = Customer::get(trim($param->CallbackParameter->customer->id));
         if (!$customer instanceof Customer) {
             throw new Exception('Invalid Customer passed in!');
         }
         if (!isset($param->CallbackParameter->applyTo) || ($applyTo = trim($param->CallbackParameter->applyTo)) === '' || !in_array($applyTo, CreditNote::getApplyToTypes())) {
             throw new Exception('Invalid Apply To passed in!');
         }
         if (isset($param->CallbackParameter->creditNoteId) && ($creditNote = CreditNote::get(trim($param->CallbackParameter->creditNoteId))) instanceof CreditNote) {
             $creditNote = $creditNote;
         } else {
             if (isset($param->CallbackParameter->orderId) && ($order = Order::get(trim($param->CallbackParameter->orderId))) instanceof Order) {
                 $creditNote = CreditNote::createFromOrder($order, $customer, trim($param->CallbackParameter->description));
             } else {
                 $creditNote = CreditNote::create($customer, trim($param->CallbackParameter->description));
             }
         }
         $creditNote->setShippingValue(isset($param->CallbackParameter->totalShippingCost) ? StringUtilsAbstract::getValueFromCurrency($param->CallbackParameter->totalShippingCost) : 0);
         if (isset($param->CallbackParameter->shippingAddr)) {
             $shippAddress = Address::create($param->CallbackParameter->shippingAddr->street, $param->CallbackParameter->shippingAddr->city, $param->CallbackParameter->shippingAddr->region, $param->CallbackParameter->shippingAddr->country, $param->CallbackParameter->shippingAddr->postCode, $param->CallbackParameter->shippingAddr->contactName, $param->CallbackParameter->shippingAddr->contactNo);
             $customer->setShippingAddress($shippAddress);
         }
         $printItAfterSave = false;
         if (isset($param->CallbackParameter->printIt)) {
             $printItAfterSave = intval($param->CallbackParameter->printIt) === 1 ? true : false;
         }
         if (isset($param->CallbackParameter->comments)) {
             $comments = trim($param->CallbackParameter->comments);
             $creditNote->addComment($comments, Comments::TYPE_SALES);
         }
         $totalPaymentDue = $creditNote->getShippingValue();
         $hasShipped = $creditNote->getOrder() instanceof Order && Shippment::countByCriteria('orderId = ?', array($creditNote->getOrder()->getId())) > 0;
         $creditNoteItemsMap = array();
         foreach ($param->CallbackParameter->items as $item) {
             if (!($product = Product::get(trim($item->product->id))) instanceof Product) {
                 throw new Exception('Invalid Product passed in!');
             }
             $unitPrice = StringUtilsAbstract::getValueFromCurrency(trim($item->unitPrice));
             $qtyOrdered = trim($item->qtyOrdered);
             $totalPrice = StringUtilsAbstract::getValueFromCurrency(trim($item->totalPrice));
             $itemDescription = trim($item->itemDescription);
             $active = trim($item->valid);
             $totalPaymentDue += $totalPrice;
             if (is_numeric($item->creditNoteItemId) && !CreditNoteItem::get(trim($item->creditNoteItemId)) instanceof CreditNoteItem) {
                 throw new Exception('Invalid Credit Note Item passed in');
             }
             $unitCost = $product->getUnitCost();
             $orderItem = null;
             if (isset($item->orderItemId) && ($orderItem = OrderItem::get(trim($item->orderItemId))) instanceof OrderItem) {
                 $unitCost = $orderItem->getUnitCost();
             }
             $creditNoteItem = is_numeric($item->creditNoteItemId) ? CreditNoteItem::get(trim($item->creditNoteItemId))->setActive($active)->setProduct($product)->setQty($qtyOrdered)->setUnitPrice($unitPrice)->setItemDescription($itemDescription)->setUnitCost($unitCost)->setTotalPrice($totalPrice)->save() : ($orderItem instanceof OrderItem ? CreditNoteItem::createFromOrderItem($creditNote, $orderItem, $qtyOrdered, $unitPrice, $itemDescription, $unitCost, $totalPrice) : CreditNoteItem::create($creditNote, $product, $qtyOrdered, $unitPrice, $itemDescription, $unitCost, $totalPrice));
             if (intval($creditNoteItem->getActive()) === 1) {
                 if (!isset($creditNoteItemsMap[$product->getId()])) {
                     $creditNoteItemsMap[$product->getId()] = 0;
                 }
                 $creditNoteItemsMap[$product->getId()] += $qtyOrdered;
             }
             //if we are not creating from a order, or there are shippments for this order then
             if (!$creditNote->getOrder() instanceof Order || $hasShipped === true) {
                 switch (trim($item->stockData)) {
                     case 'StockOnHand':
                         $product->returnedIntoSOH($qtyOrdered, $creditNoteItem->getUnitCost(), '', $creditNoteItem);
                         break;
                     case 'StockOnRMA':
                         $product->returnedIntoRMA($qtyOrdered, $creditNoteItem->getUnitCost(), '', $creditNoteItem);
                         break;
                     default:
                         throw new Exception('System Error: NO where to transfer the stock: ' . trim($item->stockData) . ' for product(SKU=' . $product->getSku() . ').');
                 }
             } else {
                 //revert all the shipped stock
                 foreach (OrderItem::getAllByCriteria('ord_item.orderId = ? and ord_item.isShipped = 1', array($creditNote->getOrder()->getId())) as $orderItem) {
                     $orderItem->setIsShipped(false)->save();
                 }
                 //revert all the picked stock
                 foreach (OrderItem::getAllByCriteria('ord_item.orderId = ? and ord_item.isPicked = 1', array($creditNote->getOrder()->getId())) as $orderItem) {
                     $orderItem->setIsPicked(false)->save();
                 }
             }
         }
         if (($paymentMethod = PaymentMethod::get(trim($param->CallbackParameter->paymentMethodId))) instanceof PaymentMethod) {
             $creditNote->setTotalPaid($totalPaidAmount = $param->CallbackParameter->totalPaidAmount)->addPayment($paymentMethod, $totalPaidAmount);
         }
         $creditNote->setTotalValue($totalPaymentDue)->setApplyTo($applyTo)->save();
         //if need to check half credited orders
         if ($creditNote->getOrder() instanceof Order && $hasShipped === false) {
             $orderItemMap = array();
             foreach ($order->getOrderItems() as $orderItem) {
                 $productId = $orderItem->getProduct()->getId();
                 if (!isset($orderItemMap[$productId])) {
                     $orderItemMap[$productId] = 0;
                 }
                 $orderItemMap[$productId] += $orderItem->getQtyOrdered();
             }
             //figure out the difference
             foreach ($creditNoteItemsMap as $productId => $qty) {
                 if (isset($orderItemMap[$productId])) {
                     if ($orderItemMap[$productId] <= $qty) {
                         //credited more than orderred
                         unset($orderItemMap[$productId]);
                     } else {
                         //credited less then ordered
                         $orderItemMap[$productId] = $orderItemMap[$productId] - $qty;
                     }
                 }
             }
             $orderItemMap = array_filter($orderItemMap);
             if (count($orderItemMap) > 0) {
                 //there are difference
                 $creditNote->creditFullOrder();
                 $newOrder = Order::create($creditNote->getOrder()->getCustomer(), $creditNote->getOrder()->getType() === 'INVOICE' ? Order::TYPE_ORDER : $creditNote->getOrder()->getType(), null, 'Spliting order because of partial credit note(CreditNoteNo:.' . $creditNote->getCreditNoteNo() . ') created', null, $creditNote->getOrder()->getOrderDate(), false, $creditNote->getOrder()->getShippingAddr(), $creditNote->getOrder()->getBillingAddr(), $creditNote->getOrder()->getPassPaymentCheck(), $creditNote->getOrder()->getPONo(), $creditNote->getOrder())->addComment('Created because of partial credit from ');
                 $totalAmount = 0;
                 foreach ($orderItemMap as $productId => $qty) {
                     $orderItems = OrderItem::getAllByCriteria('productId = ? and orderId = ?', array($productId, $creditNote->getOrder()->getId()), true, 1, 1);
                     if (count($orderItems) > 0) {
                         $totalAmount += $orderItems[0]->getUnitPrice() * $qty;
                     }
                     $newOrder->addItem($orderItems[0]->getProduct(), $orderItems[0]->getUnitPrice(), $qty, $orderItems[0]->getTotalPrice(), $orderItems[0]->getMageOrderId(), $orderItems[0]->getEta(), $orderItems[0]->getItemDescription());
                 }
                 if (count($shippingMethods = $creditNote->getOrder()->getInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_METHOD)) > 0) {
                     $newOrder->addInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_METHOD, $shippingMethods[0], true);
                 }
                 if (count($shippingCost = $creditNote->getOrder()->getInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_COST)) > 0) {
                     $newOrder->addInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_COST, $shippingCost[0], true);
                     $totalAmount += StringUtilsAbstract::getValueFromCurrency($shippingCost[0]);
                 }
                 $results['newOrder'] = $newOrder->setTotalAmount($totalAmount)->save()->getJson();
                 $creditNote->getOrder()->setStatus(OrderStatus::get(OrderStatus::ID_CANCELLED))->save()->addComment('This ' . $creditNote->getOrder()->getType() . ' is CANCELED, because of partial credit (CreditNoteNo:<a href="/creditnote/' . $creditNote->getId() . '.html" target="_BLANK">' . $creditNote->getCreditNoteNo() . '</a>) is created and a new ' . $newOrder->getType() . ' (<a href="/orderdetails/' . $newOrder->getId() . '.html?blanklayout=1">' . $newOrder->getOrderNo() . '</a>) is created for the diference.', Comments::TYPE_MEMO);
             } else {
                 $creditNote->getOrder()->setStatus(OrderStatus::get(OrderStatus::ID_CANCELLED))->save()->addComment('This ' . $creditNote->getOrder()->getType() . ' is CANCELED, because of full credit (CreditNoteNo:<a href="/creditnote/' . $creditNote->getId() . '.html" target="_BLANK">' . $creditNote->getCreditNoteNo() . '</a>) is created.', Comments::TYPE_MEMO);
             }
         }
         $results['item'] = $creditNote->getJson();
         $results['redirectURL'] = '/creditnote/' . $creditNote->getId() . '.html?' . $_SERVER['QUERY_STRING'];
         if ($printItAfterSave === true) {
             $results['printURL'] = '/print/creditnote/' . $creditNote->getId() . '.html?pdf=1';
         }
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage() . '<pre>' . $ex->getTraceAsString() . '</pre>';
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Пример #5
0
 /**
  * Searching searchProduct
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  *
  */
 public function searchProduct($sender, $param)
 {
     $results = $errors = array();
     try {
         $items = array();
         $searchTxt = isset($param->CallbackParameter->searchTxt) ? trim($param->CallbackParameter->searchTxt) : '';
         $customer = isset($param->CallbackParameter->customerId) ? Customer::get(trim($param->CallbackParameter->customerId)) : null;
         $where = 'pro_pro_code.code = :searchExact or pro.name like :searchTxt OR sku like :searchTxt';
         $params = array('searchExact' => $searchTxt, 'searchTxt' => '%' . $searchTxt . '%');
         $pageNo = isset($param->CallbackParameter->pageNo) ? trim($param->CallbackParameter->pageNo) : '1';
         $searchTxtArray = StringUtilsAbstract::getAllPossibleCombo(StringUtilsAbstract::tokenize($searchTxt));
         if (count($searchTxtArray) > 1) {
             foreach ($searchTxtArray as $index => $comboArray) {
                 $key = 'combo' . $index;
                 $where .= ' OR pro.name like :' . $key;
                 $params[$key] = '%' . implode('%', $comboArray) . '%';
             }
         }
         $supplierID = isset($param->CallbackParameter->supplierID) ? trim($param->CallbackParameter->supplierID) : '';
         Product::getQuery()->eagerLoad('Product.codes', 'left join');
         $stats = array();
         $products = Product::getAllByCriteria($where, $params, true, $pageNo, DaoQuery::DEFAUTL_PAGE_SIZE, array('pro.sku' => 'asc'), $stats);
         foreach ($products as $product) {
             $jsonArray = $product->getJson();
             $jsonArray['lastOrderItemFromCustomer'] = array();
             if ($customer instanceof Customer) {
                 $query = OrderItem::getQuery()->eagerLoad('OrderItem.order', 'inner join', 'ord', 'ord_item.orderId = ord.id and ord_item.active = 1 and ord.customerId = :custId and ord.type = :ordType');
                 $orderItems = OrderItem::getAllByCriteria('productId = :prodId', array('custId' => $customer->getId(), 'prodId' => $product->getId(), 'ordType' => Order::TYPE_INVOICE), true, 1, 1, array('ord_item.id' => 'desc'));
                 $jsonArray['lastOrderItemFromCustomer'] = count($orderItems) > 0 ? $orderItems[0]->getJson() : array();
             }
             $items[] = $jsonArray;
         }
         $results['items'] = $items;
         $results['pagination'] = $stats;
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Пример #6
0
 /**
  * saveOrder
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  *
  */
 public function saveOrder($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         $items = array();
         $purchaseOrder = PurchaseOrder::get(trim($param->CallbackParameter->purchaseOrder->id));
         if (!$purchaseOrder instanceof PurchaseOrder) {
             throw new Exception('Invalid PurchaseOrder passed in!');
         }
         $comment = trim($param->CallbackParameter->comments);
         $purchaseOrder->addComment(Comments::TYPE_WAREHOUSE, $comment);
         $products = $param->CallbackParameter->products;
         $outStandingOrders = array();
         $invoiceNos = array();
         foreach ($products->matched as $item) {
             $product = Product::get(trim($item->product->id));
             if (!$product instanceof Product) {
                 throw new Exception('Invalid Product passed in!');
             }
             if (isset($item->product->EANcode)) {
                 $EANcode = trim($item->product->EANcode);
                 $productcodes = ProductCode::getAllByCriteria('pro_code.productId = :productId and pro_code.typeId = :typeId', array('productId' => $product->getId(), 'typeId' => ProductCodeType::ID_EAN), true, 1, 1);
                 if (count($productcodes) > 0) {
                     $productcodes[0]->setCode($EANcode)->save();
                 } else {
                     ProductCode::create($product, ProductCodeType::get(ProductCodeType::ID_EAN), $EANcode);
                 }
             }
             if (isset($item->product->UPCcode)) {
                 $UPCcode = trim($item->product->UPCcode);
                 $productcodes = ProductCode::getAllByCriteria('pro_code.productId = :productId and pro_code.typeId = :typeId', array('productId' => $product->getId(), 'typeId' => ProductCodeType::ID_UPC), true, 1, 1);
                 if (sizeof($productcodes)) {
                     $productcodes[0]->setCode($UPCcode)->save();
                 } else {
                     ProductCode::create($product, ProductCodeType::get(ProductCodeType::ID_UPC), $UPCcode);
                 }
             }
             if (isset($item->product->warehouseLocation) && ($locationName = trim($item->product->warehouseLocation)) !== '') {
                 $locs = Location::getAllByCriteria('name = ?', array($locationName), true, 1, 1);
                 $loc = count($locs) > 0 ? $locs[0] : Location::create($locationName, $locationName);
                 $product->addLocation(PreferredLocationType::get(PreferredLocationType::ID_WAREHOUSE), $loc);
             }
             $serials = $item->serial;
             $totalQty = 0;
             foreach ($serials as $serial) {
                 $qty = trim($serial->qty);
                 $totalQty += intval($qty);
                 $serialNo = trim($serial->serialNo);
                 $unitPrice = trim($serial->unitPrice);
                 $invoiceNo = trim($serial->invoiceNo);
                 $invoiceNos[] = $invoiceNo;
                 $comments = trim($serial->comments);
                 ReceivingItem::create($purchaseOrder, $product, $unitPrice, $qty, $serialNo, $invoiceNo, $comments);
             }
             OrderItem::getQuery()->eagerLoad('OrderItem.order', 'inner join', 'ord', 'ord.id = ord_item.orderId and ord.active = 1 and ord.type = :ordType and ord_item.productId = :productId and ord.statusId in ( :statusId1, :statusId2, :statusId3)');
             $orderItems = OrderItem::getAllByCriteria('ord_item.active = 1', array('ordType' => Order::TYPE_INVOICE, 'productId' => $product->getId(), 'statusId1' => OrderStatus::ID_INSUFFICIENT_STOCK, 'statusId2' => OrderStatus::ID_ETA, 'statusId3' => OrderStatus::ID_STOCK_CHECKED_BY_PURCHASING));
             if (count($orderItems) > 0) {
                 $orders = array();
                 foreach ($orderItems as $orderItem) {
                     if (!array_key_exists($orderItem->getOrder()->getId(), $orders)) {
                         $orders[$orderItem->getOrder()->getId()] = $orderItem->getOrder()->getJson();
                     }
                 }
                 $outStandingOrders[$product->getId()] = array('product' => $product->getJson(), 'recievedQty' => $totalQty, 'outStandingOrders' => array_values($orders));
             }
         }
         $results['outStandingOrders'] = count($outStandingOrders) > 0 ? array_values($outStandingOrders) : array();
         $results['item'] = PurchaseOrder::get($purchaseOrder->getId())->getJson();
         $invoiceNos = array_unique($invoiceNos);
         $results['invoiceNos'] = $invoiceNos;
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Пример #7
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::postSave()
  */
 public function postSave()
 {
     if (trim($this->getOrderNo()) === '') {
         $this->setOrderNo('BPCM' . str_pad($this->getId(), 8, '0', STR_PAD_LEFT))->setMargin($this->getCalculatedTotalMargin())->save();
     }
     if (trim($this->getType()) === trim(self::TYPE_INVOICE)) {
         $this->_changeToInvoice();
     }
     //if the order is now SHIPPED
     if (trim($this->getStatus()->getId()) === trim(OrderStatus::ID_SHIPPED)) {
         $items = OrderItem::getAllByCriteria('orderId = ? and isPicked = 1', array($this->getId()));
         foreach ($items as $item) {
             $item->setIsShipped(true)->save();
         }
         $this->_changeToInvoice();
     } elseif (trim($this->getStatus()->getId()) === trim(OrderStatus::ID_CANCELLED)) {
         //if the order is now cancelled
         //we need to unlink all the kits that were provided in this order item for sale.
         SellingItem::getQuery()->eagerLoad('SellingItem.orderItem', 'inner join', 'rec_item_oi', 'rec_item_oi.id = sell_item.orderItemId and sell_item.active = 1 and sell_item.kitId is not null');
         $items = SellingItem::getAllByCriteria('rec_item_oi.orderId = ? and rec_item_oi.isShipped = 0', array($this->getId()));
         foreach ($items as $item) {
             $item->setActive(false)->save();
         }
     }
 }