Example #1
0
 /**
  *
  * @return string
  */
 public function showProducts()
 {
     $html = '';
     $purchaseOrderItems = PurchaseOrderItem::getAllByCriteria('purchaseOrderId = ?', array($this->order->getId()));
     foreach ($purchaseOrderItems as $index => $orderItem) {
         $uPrice = '$' . number_format($orderItem->getUnitPrice(), 2, '.', ',');
         $tPrice = '$' . number_format($orderItem->getTotalPrice(), 2, '.', ',');
         $html .= $this->getRow($orderItem->getQty(), $orderItem->getProduct()->getSku(), $orderItem->getProduct()->getname(), $uPrice, $tPrice, 'itemRow');
     }
     for ($i = 12; $i > $index; $i--) {
         $html .= $this->getRow(' ', ' ', ' ', ' ', ' ', 'itemRow');
     }
     return $html;
 }
Example #2
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) : '';
         $pageNo = isset($param->CallbackParameter->pageNo) ? trim($param->CallbackParameter->pageNo) : '1';
         $where = 'pro_pro_code.code = :searchExact or pro.name like :searchTxt OR sku like :searchTxt';
         $params = array('searchExact' => $searchTxt, 'searchTxt' => '%' . $searchTxt . '%');
         $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) . '%';
             }
         }
         $stats = array();
         $supplierID = isset($param->CallbackParameter->supplierID) ? trim($param->CallbackParameter->supplierID) : '';
         Product::getQuery()->eagerLoad('Product.codes', 'left join');
         $products = Product::getAllByCriteria($where, $params, true, $pageNo, DaoQuery::DEFAUTL_PAGE_SIZE, array('pro.sku' => 'asc'), $stats);
         foreach ($products as $product) {
             $array = $product->getJson();
             $array['minProductPrice'] = 0;
             $array['lastSupplierPrice'] = 0;
             $array['minSupplierPrice'] = 0;
             $minProductPriceProduct = PurchaseOrderItem::getAllByCriteria('productId = ?', array($product->getId()), true, 1, 1, array('unitPrice' => 'asc'));
             $minProductPrice = sizeof($minProductPriceProduct) ? $minProductPriceProduct[0]->getUnitPrice() : 0;
             $minProductPriceId = sizeof($minProductPriceProduct) ? $minProductPriceProduct[0]->getPurchaseOrder()->getId() : '';
             PurchaseOrderItem::getQuery()->eagerLoad('PurchaseOrderItem.purchaseOrder');
             $lastSupplierPriceProduct = PurchaseOrderItem::getAllByCriteria('po_item.productId = ? and po_item_po.supplierId = ?', array($product->getId(), $supplierID), true, 1, 1, array('po_item.id' => 'desc'));
             $lastSupplierPrice = sizeof($lastSupplierPriceProduct) ? $lastSupplierPriceProduct[0]->getUnitPrice() : 0;
             $lastSupplierPriceId = sizeof($lastSupplierPriceProduct) ? $lastSupplierPriceProduct[0]->getPurchaseOrder()->getId() : '';
             PurchaseOrderItem::getQuery()->eagerLoad('PurchaseOrderItem.purchaseOrder');
             $minSupplierPriceProduct = PurchaseOrderItem::getAllByCriteria('po_item.productId = ? and po_item_po.supplierId = ?', array($product->getId(), $supplierID), true, 1, 1, array('po_item.unitPrice' => 'asc'));
             $minSupplierPrice = sizeof($minSupplierPriceProduct) ? $minSupplierPriceProduct[0]->getUnitPrice() : 0;
             $minSupplierPriceId = sizeof($minSupplierPriceProduct) ? $minSupplierPriceProduct[0]->getPurchaseOrder()->getId() : '';
             $array['minProductPrice'] = $minProductPrice;
             $array['minProductPriceId'] = $minProductPriceId;
             $array['lastSupplierPrice'] = $lastSupplierPrice;
             $array['lastSupplierPriceId'] = $lastSupplierPriceId;
             $array['minSupplierPrice'] = $minSupplierPrice;
             $array['minSupplierPriceId'] = $minSupplierPriceId;
             $items[] = $array;
         }
         $results['items'] = $items;
         $results['pagination'] = $stats;
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Example #3
0
 /**
  * get all purchase order items under this PO
  *
  * @return array
  */
 public function getPurchaseOrderItems()
 {
     return PurchaseOrderItem::getAllByCriteria('po_item.purchaseOrderId = ?', array($this->getId()));
 }
Example #4
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::postSave()
  */
 public function postSave()
 {
     if (trim($this->getId()) !== '') {
         //if a receiving item gets deactivate, then stockonHand needs to be changed
         if (intval($this->getActive()) === 0) {
             $msg = 'ReceivedItem for Product(SKU=' . $this->getProduct() . '), unitPrice=' . $this->getUnitPrice() . ', serialNo=' . $this->getSerialNo() . ', invoiceNo=' . $this->getInvoiceNo() . ', qty=' . $this->getQty() . ' has now been deactivated.';
             $log_Comments = get_class($this) . '_DEACTIVATION';
             $qty = 0 - intval($this->getQty());
         } else {
             $msg = 'Received a Product(SKU=' . $this->getProduct() . ') with unitPrice=' . $this->getUnitPrice() . ', serialNo=' . $this->getSerialNo() . ', invoiceNo=' . $this->getInvoiceNo() . ', qty=' . $this->getQty() . '';
             $log_Comments = 'Auto Log';
             $qty = intval($this->getQty());
         }
         $this->getPurchaseOrder()->addLog($msg, Log::TYPE_SYSTEM, Log::TYPE_SYSTEM, $log_Comments, __CLASS__ . '::' . __FUNCTION__)->addComment($msg, Comments::TYPE_WAREHOUSE);
         $this->getProduct()->received($qty, $this->getUnitPrice(), $msg, $this);
         $nofullReceivedItems = PurchaseOrderItem::getAllByCriteria('productId = ? and purchaseOrderId = ?', array($this->getProduct()->getId(), $this->getPurchaseOrder()->getId()), true, 1, 1, array('po_item.receivedQty' => 'asc'));
         if (count($nofullReceivedItems) > 0) {
             $nofullReceivedItems[0]->setReceivedQty($nofullReceivedItems[0]->getReceivedQty() + $qty)->save()->addLog(Log::TYPE_SYSTEM, $msg, $log_Comments, __CLASS__ . '::' . __FUNCTION__)->addComment($msg, Comments::TYPE_WAREHOUSE);
         }
         $totalCount = PurchaseOrderItem::countByCriteria('active = 1 and purchaseOrderId = ? and receivedQty < qty', array($this->getPurchaseOrder()->getId()));
         $this->getPurchaseOrder()->setStatus($totalCount > 0 ? PurchaseOrder::STATUS_RECEIVING : PurchaseOrder::STATUS_RECEIVED)->save()->addComment($msg, Comments::TYPE_WAREHOUSE);
     }
 }
 /**
  * Getting the JSon for PurchaseOrder
  *
  * @param PurchaseOrder $po
  *
  * @return Ambigous <multitype:, multitype:multitype:string  NULL >
  */
 private function _getPOJson(PurchaseOrder $po)
 {
     $array = $po->getJson();
     $array['totalProductCount'] = $po->getTotalProductCount();
     $array['totalReceivedValue'] = $po->getTotalRecievedValue();
     $array['purchaseOrderItem'] = array();
     foreach (PurchaseOrderItem::getAllByCriteria('po_item.purchaseOrderId = :purchaseOrderId', array('purchaseOrderId' => $po->getId())) as $purchaseOrderItem) {
         $product = $purchaseOrderItem->getProduct();
         $EANcodes = ProductCode::getAllByCriteria('pro_code.productId = :productId and pro_code.typeId = :typeId', array('productId' => $product->getId(), 'typeId' => ProductCodeType::ID_EAN), true, 1, 1);
         $EANcodes = count($EANcodes) ? $EANcodes[0]->getCode() : '';
         $UPCcodes = ProductCode::getAllByCriteria('pro_code.productId = :productId and pro_code.typeId = :typeId', array('productId' => $product->getId(), 'typeId' => ProductCodeType::ID_UPC), true, 1, 1);
         $UPCcodes = count($UPCcodes) ? $UPCcodes[0]->getCode() : '';
         $warehouseLocations = PreferredLocation::getAllByCriteria('productId = :productId and typeId = :typeId', array('productId' => $product->getId(), 'typeId' => PreferredLocationType::ID_WAREHOUSE), true, 1, 1);
         $warehouseLocation = count($warehouseLocations) > 0 && $warehouseLocations[0]->getLocation() instanceof Location ? $warehouseLocations[0]->getLocation()->getName() : '';
         $productArray = $product->getJson();
         $productArray['codes'] = array('EAN' => $EANcodes, 'UPC' => $UPCcodes);
         $productArray['warehouseLocation'] = $warehouseLocation;
         $array['purchaseOrderItem'][] = array('purchaseOrderItem' => $purchaseOrderItem->getJson(), 'product' => $productArray);
     }
     return $array;
 }