Beispiel #1
0
 protected static function _getData()
 {
     $return = array();
     $myobCodeType = ProductCodeType::get(ProductCodeType::ID_MYOB);
     foreach (Product::getAllByCriteria('updated <= 2015-12-06 04:00:00', array(), false) as $product) {
         $logs = ProductQtyLog::getAllByCriteria('productId = ? and created <= ?', array($product->getId(), trim($toDate)), true, 1, 1, array('id' => 'desc'));
         $log = count($logs) > 0 ? $logs[0] : null;
         $myobCodes = ProductCode::getCodes($product, $myobCodeType, true, 1, 1);
         $return[] = array('sku' => $product->getSku(), 'name' => $product->getName(), 'short description' => $product->getShortDescription(), 'category' => join(', ', array_map(create_function('$a', 'return $a->getCategory()->getName();'), $product->getCategories())), 'assetAccNo' => $product->getAssetAccNo(), 'revenueAccNo' => $product->getRevenueAccNo(), 'costAccNo' => $product->getCostAccNo(), 'Stock On PO' => $log instanceof ProductQtyLog ? $log->getStockOnPO() : $product->getStockOnPO(), 'Stock On Order' => $log instanceof ProductQtyLog ? $log->getStockOnOrder() : $product->getStockOnOrder(), 'Stock On Hand' => $log instanceof ProductQtyLog ? $log->getStockOnHand() : $product->getStockOnHand(), 'Total On Hand Value' => $log instanceof ProductQtyLog ? $log->getTotalOnHandValue() : $product->getTotalOnHandValue(), 'Stock In Parts' => $log instanceof ProductQtyLog ? $log->getStockInParts() : $product->getStockInParts(), 'Total In Parts Value' => $log instanceof ProductQtyLog ? $log->getTotalInPartsValue() : $product->getTotalInPartsValue(), 'Stock In RMA' => $log instanceof ProductQtyLog ? $log->getStockInRMA() : $product->getStockInRMA(), 'Total RMA Value' => $log instanceof ProductQtyLog ? $log->getTotalRMAValue() : $product->getTotalRMAValue(), 'active' => intval($product->getActive()) === 1 ? 'Y' : 'N', 'MYOB' => count($myobCodes) > 0 ? $myobCodes[0]->getCode() : '');
     }
     return $return;
 }
Beispiel #2
0
 /**
  * Getting the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function getItems($sender, $param)
 {
     $results = $errors = array();
     try {
         $class = trim($this->_focusEntity);
         $pageNo = 1;
         $pageSize = DaoQuery::DEFAUTL_PAGE_SIZE;
         if (isset($param->CallbackParameter->pagination)) {
             $pageNo = $param->CallbackParameter->pagination->pageNo;
             $pageSize = $param->CallbackParameter->pagination->pageSize;
         }
         $serachCriteria = isset($param->CallbackParameter->searchCriteria) ? json_decode(json_encode($param->CallbackParameter->searchCriteria), true) : array();
         $where = array(1);
         $params = array();
         if (isset($serachCriteria['pql.product']) && ($skuORid = trim($serachCriteria['pql.product'])) !== '') {
             ProductQtyLog::getQuery()->eagerLoad('ProductQtyLog.product', 'inner join', 'pql_pro');
             $where[] = '(pql_pro.sku = ? or pql_pro.id = ?)';
             $params[] = $skuORid;
             $params[] = $skuORid;
         }
         if (isset($serachCriteria['pro.id']) && ($productId = trim($serachCriteria['pro.id'])) !== '') {
             ProductQtyLog::getQuery()->eagerLoad('ProductQtyLog.product', 'inner join', 'pql_pro');
             $where[] = '(pql_pro.id = ? )';
             $params[] = $productId;
         }
         if (isset($serachCriteria['pql.createdDate_from']) && ($from = trim($serachCriteria['pql.createdDate_from'])) !== '') {
             $where[] = 'pql.created >= ?';
             $params[] = $from;
         }
         if (isset($serachCriteria['pql.createdDate_to']) && ($to = trim($serachCriteria['pql.createdDate_to'])) !== '') {
             $where[] = 'pql.created <= ?';
             $params[] = str_replace(' 00:00:00', ' 23:59:59', $to);
         }
         $stats = array();
         $objects = $class::getAllByCriteria(implode(' AND ', $where), $params, false, $pageNo, $pageSize, array('pql.id' => 'desc'), $stats);
         $results['pageStats'] = $stats;
         $results['items'] = array();
         foreach ($objects as $obj) {
             $order = $obj->getEntity() instanceof OrderItem ? $obj->getEntity()->getOrder() : ($obj->getEntity() instanceof Order ? $obj->getEntity() : null);
             $purchaseOrder = $obj->getEntity() instanceof PurchaseOrderItem ? $obj->getEntity()->getPurchaseOrder() : ($obj->getEntity() instanceof PurchaseOrder ? $obj->getEntity() : null);
             $extra = array('product' => $obj->getproduct()->getJson(), 'order' => $order instanceof Order ? $order->getJson() : null, 'purchaseOrder' => $purchaseOrder instanceof PurchaseOrder ? $purchaseOrder->getJson() : null);
             $results['items'][] = $obj->getJson($extra);
         }
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
 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';
     $items = ProductQtyLog::getAllByCriteria($dataType . ' >= :fromDate and ' . $dataType . ' < :toDate and type in (:type1, :type2)', array('fromDate' => trim($fromDate), 'toDate' => trim($toDate), 'type1' => ProductQtyLog::TYPE_SALES_ORDER, 'type2' => ProductQtyLog::TYPE_STOCK_ADJ));
     $now = new UDate();
     $now->setTimeZone('Australia/Melbourne');
     $return = array();
     foreach ($items as $item) {
         if (!($product = $item->getProduct()) instanceof Product) {
             continue;
         }
         $narration = '';
         if ($item->getEntity() instanceof BaseEntityAbstract) {
             if ($item->getEntity() instanceof PurchaseOrderItem) {
                 $narration = $item->getEntity()->getPurchaseOrder() instanceof PurchaseOrder ? $item->getEntity()->getPurchaseOrder()->getPurchaseOrderNo() : '';
             } else {
                 if ($item->getEntity() instanceof PurchaseOrder) {
                     $narration = $item->getEntity()->getPurchaseOrderNo();
                 } else {
                     if ($item->getEntity() instanceof OrderItem) {
                         $narration = $item->getEntity()->getOrder() instanceof Order ? ($invoiceNo = trim($item->getEntity()->getOrder()->getInvNo())) === '' ? $item->getEntity()->getOrder()->getOrderNo() : $invoiceNo : '';
                     } else {
                         if ($item->getEntity() instanceof Order) {
                             $narration = ($invoiceNo = trim($item->getEntity()->getInvNo())) === '' ? $item->getEntity()->getOrderNo() : $invoiceNo;
                         }
                     }
                 }
             }
         }
         $comments = $item->getComments();
         $return[] = array('Narration' => $narration, 'Date' => trim($item->getCreated()->setTimeZone('Australia/Melbourne')), 'Description' => $product->getSku(), 'AccountCode' => $product->getAssetAccNo(), 'TaxRate' => 'BAS Excluded', 'Amount' => $item->getTotalOnHandValueVar(), 'TrackingName1' => $item->getType(), 'TrackingOption1' => '', 'TrackingName2' => '', 'TrackingOption2' => '', 'Comments' => $comments);
         $return[] = array('Narration' => $narration, 'Date' => trim($item->getCreated()->setTimeZone('Australia/Melbourne')), 'Description' => $product->getSku(), 'AccountCode' => $product->getCostAccNo(), 'TaxRate' => 'BAS Excluded', 'Amount' => 0 - $item->getTotalOnHandValueVar(), 'TrackingName1' => $item->getType(), 'TrackingOption1' => '', 'TrackingName2' => '', 'TrackingOption2' => '', 'Comments' => $comments);
     }
     return $return;
 }
 private static function _getProductQtyLogs(Product $product, $pageNumber, $pageSize = self::PAGE_SIZE)
 {
     return ProductQtyLog::getAllByCriteria('pql.active = 1 and pql.productId = ? and pql.stockOnHandVar > 0 and pql.type in (?, ?, ?)', array($product->getId(), ProductQtyLog::TYPE_PO, ProductQtyLog::TYPE_STOCK_MOVE_INTERNAL, ProductQtyLog::TYPE_STOCK_ADJ), true, $pageNumber, $pageSize, array('id' => 'desc'));
 }
Beispiel #5
0
 /**
  *
  * @param Product $product
  * @param BaseEntityAbstract $entity
  * @param string $comments
  * @return Ambigous <BaseEntityAbstract, GenericDAO>
  */
 public static function create(Product $product, $type = '', BaseEntityAbstract $entity = null, $comments = '')
 {
     $log = new ProductQtyLog();
     $log->setProduct($product)->setType($type)->setStockOnHand($product->getStockOnHand())->setTotalOnHandValue($product->getTotalOnHandValue())->setStockOnOrder($product->getStockOnOrder())->setStockOnPO($product->getstockOnPO())->setStockInParts($product->getStockInParts())->setTotalInPartsValue($product->getTotalInPartsValue())->setStockInRMA($product->getStockInRMA())->setTotalRMAValue($product->getTotalRMAValue())->setComments($comments);
     if ($entity instanceof BaseEntityAbstract) {
         $log->setEntityName(get_class($entity))->setEntityId($entity->getId());
     }
     return $log->save();
 }
Beispiel #6
0
 /**
  * snapshot of the product qty
  *
  * @param BaseEntityAbstract $entity
  * @param string             $type
  * @param string             $comments
  *
  * @return Product
  */
 public function snapshotQty(BaseEntityAbstract $entity = null, $type = '', $comments = '')
 {
     ProductQtyLog::create($this, $type, $entity, trim($comments));
     return $this;
 }