示例#1
0
 protected static function _getData()
 {
     if (count(self::$_dateRange) === 0) {
         $yesterdayLocal = new UDate('now', 'Australia/Melbourne');
         $yesterdayLocal->modify('-1 day');
         $fromDate = new UDate($yesterdayLocal->format('Y-m-d') . ' 00:00:00', 'Australia/Melbourne');
         $fromDate->setTimeZone('UTC');
         $toDate = new UDate($yesterdayLocal->format('Y-m-d') . ' 23:59:59', 'Australia/Melbourne');
         $toDate->setTimeZone('UTC');
     } else {
         $fromDate = self::$_dateRange['start'];
         $toDate = self::$_dateRange['end'];
     }
     $dataType = 'created';
     $receivingItems = ReceivingItem::getAllByCriteria($dataType . ' >= :fromDate and ' . $dataType . ' < :toDate', array('fromDate' => trim($fromDate), 'toDate' => trim($toDate)));
     $now = new UDate();
     $now->setTimeZone('Australia/Melbourne');
     $formatArray = array();
     foreach ($receivingItems as $receivingItem) {
         $product = $receivingItem->getProduct();
         if (!$product instanceof Product) {
             continue;
         }
         if (!array_key_exists($key = trim($receivingItem->getPurchaseOrder()->getId() . '|' . $product->getId() . '|' . $receivingItem->getInvoiceNo()), $formatArray)) {
             $formatArray[$key] = $receivingItem;
         }
         if ($formatArray[$key]->getId() !== $receivingItem->getId()) {
             $formatArray[$key]->setQty($formatArray[$key]->getQty() + $receivingItem->getQty());
         }
     }
     $return = array();
     foreach ($formatArray as $key => $receivingItem) {
         $product = $receivingItem->getProduct();
         $purchaseOrder = $receivingItem->getPurchaseOrder();
         $supplier = $purchaseOrder->getSupplier();
         $return[] = array('ContactName' => $supplier->getName(), 'EmailAddress' => $supplier->getEmail(), 'POAddressLine1' => '', 'POAddressLine2' => '', 'POAddressLine3' => '', 'POAddressLine4' => '', 'POCity' => '', 'PORegion' => '', 'POPostalCode' => '', 'POCountry' => '', 'InvoiceNumber' => $receivingItem->getInvoiceNo(), 'InvoiceDate' => '', 'DueDate' => trim($now->modify(self::DEFAULT_DUE_DELAY)), 'InventoryItemCode' => $product->getSku(), 'Description' => ($description = trim($product->getShortDescription())) === '' ? $product->getName() : $description, 'Quantity' => $receivingItem->getQty(), 'UnitAmount' => $receivingItem->getUnitPrice(), 'AccountCode' => $product->getAssetAccNo(), 'TaxType' => "GST on Expenses", 'TrackingName1' => '', 'TrackingOption1' => '', 'TrackingName2' => '', 'TrackingOption2' => '', 'Currency' => '');
     }
     return $return;
 }
示例#2
0
    /**
     * Getting the items
     *
     * @param unknown $sender
     * @param unknown $param
     * @throws Exception
     *
     */
    public function getItems($sender, $param)
    {
        $results = $errors = array();
        try {
            if (!isset($param->CallbackParameter->searchCriteria->supplierId) || !($supplier = Supplier::get(trim($param->CallbackParameter->searchCriteria->supplierId))) instanceof Supplier) {
                throw new Exception('Invalid Supplier provided');
            }
            if (!isset($param->CallbackParameter->searchCriteria->invoiceNo) || ($invoiceNo = trim($param->CallbackParameter->searchCriteria->invoiceNo)) === '') {
                throw new Exception('Invalid Invoice number provided');
            }
            ReceivingItem::getQuery()->eagerLoad('ReceivingItem.purchaseOrder', 'inner join', 'rec_item_po', 'rec_item_po.id = rec_item.purchaseOrderId');
            if (ReceivingItem::countByCriteria('rec_item_po.supplierId = ? and rec_item.invoiceNo = ?', array($supplier->getId(), $invoiceNo)) === 0) {
                throw new Exception('There is no such a invoice(invoice No=' . $invoiceNo . ') for supplier:' . $supplier->getName());
            }
            $sql = 'select ri.productId,
						ri.unitPrice `unitPrice`,
						sum(ri.qty) `qty`,
						group_concat(distinct ri.id) `itemIds`,
						group_concat(distinct po.id) `poIds`
					from receivingitem ri
					inner join purchaseorder po on (po.id = ri.purchaseOrderId)
					where ri.active = 1 and ri.invoiceNo = ? and po.supplierId = ?
					group by ri.productId,  ri.unitPrice';
            $params = array($invoiceNo, $supplier->getId());
            $rows = Dao::getResultsNative($sql, $params);
            $results['supplier'] = $supplier->getJson();
            $results['items'] = array();
            foreach ($rows as $row) {
                $items = count($itemIds = explode(',', $row['itemIds'])) === 0 ? array() : ReceivingItem::getAllByCriteria('id in (' . implode(',', array_fill(0, count($itemIds), '?')) . ')', $itemIds);
                $pos = count($poIds = explode(',', $row['poIds'])) === 0 ? array() : PurchaseOrder::getAllByCriteria('id in (' . implode(',', array_fill(0, count($poIds), '?')) . ')', $poIds);
                $results['items'][] = array('product' => Product::get($row['productId'])->getJson(), 'totalQty' => $row['qty'], 'totalPrice' => $row['unitPrice'] * $row['qty'], 'items' => array_map(create_function('$a', 'return $a->getJson();'), $items), 'purchaseOrders' => array_map(create_function('$a', 'return $a->getJson();'), $pos));
            }
        } catch (Exception $ex) {
            $errors[] = $ex->getMessage();
        }
        $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
    }
示例#3
0
 /**
  * Getting the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function getItems($sender, $param)
 {
     $results = $errors = array();
     try {
         $serachCriteria = isset($param->CallbackParameter->searchCriteria) ? json_decode(json_encode($param->CallbackParameter->searchCriteria), true) : array();
         $pageNo = 1;
         $pageSize = DaoQuery::DEFAUTL_PAGE_SIZE;
         if (isset($param->CallbackParameter->pagination)) {
             $pageNo = $param->CallbackParameter->pagination->pageNo;
             $pageSize = $param->CallbackParameter->pagination->pageSize;
         }
         $where = $params = $stats = array();
         if (isset($serachCriteria['serialno']) && ($serialno = trim($serachCriteria['serialno'])) !== '') {
             $where[] = 'serialNo like ?';
             $params[] = '%' . trim($serialno) . '%';
         }
         if (isset($serachCriteria['productid']) && ($productid = trim($serachCriteria['productid'])) !== '') {
             $where[] = 'productId = ?';
             $params[] = trim($productid);
         }
         if (isset($serachCriteria['purchaseorderid']) && ($purchaseorderid = trim($serachCriteria['purchaseorderid'])) !== '') {
             $where[] = 'purchaseorderid = ?';
             $params[] = trim($purchaseorderid);
         }
         if (isset($serachCriteria['pro.ids']) && ($productids = trim($serachCriteria['pro.ids'])) !== '' && count($productids = trim($serachCriteria['pro.ids'])) > 0) {
             $value = explode(',', $productids);
             $where[] = 'productId in (' . implode(", ", array_fill(0, count($value), "?")) . ')';
             $params = array_merge($params, $value);
         }
         if (isset($serachCriteria['purchaseorderids']) && ($purchaseorderids = trim($serachCriteria['purchaseorderids'])) !== '') {
             $value = explode(',', $purchaseorderids);
             $where[] = 'purchaseOrderId in (' . implode(", ", array_fill(0, count($value), "?")) . ')';
             $params = array_merge($params, $value);
         }
         $objects = array();
         if (count($where) > 0) {
             $objects = ReceivingItem::getAllByCriteria(implode(' AND ', $where), $params, true, $pageNo, $pageSize, array('rec_item.productId' => 'desc'), $stats);
         }
         $results['pageStats'] = $stats;
         $results['items'] = array();
         foreach ($objects as $obj) {
             $results['items'][] = $obj->getJson();
         }
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
示例#4
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::postSave()
  */
 public function postSave()
 {
     if (trim($this->getPurchaseOrderNo()) === '') {
         $this->setPurchaseOrderNo(self::PO_NO_PRE . str_pad($this->getId(), 6, '0', STR_PAD_LEFT))->save();
     }
     //if the order status is ordered, then calculated the
     if (intval($this->getActive()) === 0 || trim($this->getStatus()) === PurchaseOrder::STATUS_CANCELED) {
         $items = PurchaseOrderItem::getAllByCriteria('purchaseOrderId = ? and stockCalculated = 1', array($this->getId()));
         foreach ($items as $item) {
             $item->getProduct()->ordered(0 - $item->getQty(), 'PO(' . $this->getPurchaseOrderNo() . ') is CANCELLED or Deactivated', $item);
             $item->setStockCalculated(false)->save()->addLog('UNMarked this item for StockOnPO and stockCalculated', Log::TYPE_SYSTEM, 'STOCK_QTY_CHG', __CLASS__ . '::' . __FUNCTION__);
         }
         $this->addComment(count($items) . ' POItem(s) are reverted, as this PO is now deactivated or CANCELLED');
         $receivedItems = ReceivingItem::getAllByCriteria('purchaseOrderId = ?', array($this->getId()));
         foreach ($receivedItems as $item) {
             $item->setActive(false)->save();
         }
     } else {
         if (trim($this->getStatus()) === PurchaseOrder::STATUS_ORDERED) {
             $items = PurchaseOrderItem::getAllByCriteria('purchaseOrderId = ? and stockCalculated = 0', array($this->getId()));
             foreach ($items as $item) {
                 $item->getProduct()->ordered($item->getQty(), 'PO(' . $this->getPurchaseOrderNo() . ') is ordered now.', $item);
                 $item->setStockCalculated(true)->save()->addLog('Marked this item for StockOnPO and stockCalculated', Log::TYPE_SYSTEM, 'STOCK_QTY_CHG', __CLASS__ . '::' . __FUNCTION__);
             }
         }
     }
 }