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); }
/** * Magic toString function * @return string */ public function __toString() { try { $dt = $this->getDateTimeString("Y-m-d H:i:s"); if ($dt === "0000-00-00 00:00:00") { $dt = (string) UDate::zeroDate(); } } catch (Exception $ex) { $dt = (string) UDate::zeroDate(); } return $dt; }
/** * The runner * * @param string $preFix * @param string $debug */ public static function run($outputFileDir, $preFix = '', $debug = false) { $start = self::_log('## START ##############################', __CLASS__ . '::' . __FUNCTION__, $preFix); self::$_outputFileDir = trim($outputFileDir); self::_log('GEN FILE TO: ' . self::$_outputFileDir, '', $preFix . self::TAB); self::$_imageDirName = self::$_imageDirName . '_' . UDate::now()->format('Y_m_d_H_i_s'); Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT)); $now = UDate::now(); $settings = self::_getSettings($preFix . self::TAB, $debug); $lastUpdatedTime = UDate::zeroDate(); if (isset($settings['lastUpdatedTime']) && trim($settings['lastUpdatedTime']) !== '') { $lastUpdatedTime = new UDate(trim($settings['lastUpdatedTime'])); } self::_log('GOT LAST SYNC TIME: ' . trim($lastUpdatedTime), '', $preFix); $products = self::_getData($lastUpdatedTime, $preFix . self::TAB, $debug); if (count($products) > 0) { $files = self::_genCSV($lastUpdatedTime, array_values($products), $preFix . self::TAB, $debug); self::_zipFile($files, $preFix, $debug); self::_setSettings('lastUpdatedTime', trim($now), $preFix, $debug); } else { self::_log('NO changed products found after: "' . trim($lastUpdatedTime) . '".', '', $preFix); } self::_log('## FINISH ##############################', __CLASS__ . '::' . __FUNCTION__, $preFix, $start); }
/** * (non-PHPdoc) * @see BaseEntity::__loadDaoMap() */ public function __loadDaoMap() { DaoMap::begin($this, 'pro_price'); DaoMap::setManyToOne('product', 'Product', 'pro_price_pro'); DaoMap::setManyToOne('type', 'ProductPriceType', 'pro_price_type'); DaoMap::setIntType('price', 'double', '10,4'); DaoMap::setDateType('start', 'datetime', false, trim(UDate::zeroDate())); DaoMap::setDateType('end', 'datetime', false, trim(UDate::maxDate())); parent::__loadDaoMap(); DaoMap::createIndex('price'); DaoMap::createIndex('start'); DaoMap::createIndex('end'); DaoMap::commit(); }
public function clearETA($sender, $param) { $results = $errors = array(); try { if (!isset($param->CallbackParameter->item_id) || !($item = OrderItem::get($param->CallbackParameter->item_id)) instanceof OrderItem) { throw new Exception('System Error: invalid order item provided!'); } if (!isset($param->CallbackParameter->comments) || ($comments = trim($param->CallbackParameter->comments)) === '') { $comments = ''; } Dao::beginTransaction(); //saving the order item $item->setETA(UDate::zeroDate())->addComment('Clearing the ETA: ' . $comments); $order = $item->getOrder(); $sku = $item->getProduct()->getSku(); $order->addComment('Clearing the ETA for product (' . $sku . '): ' . $comments, Comments::TYPE_PURCHASING); $item->save(); //check to see whether we need to update the order as well $allChecked = true; foreach ($order->getOrderItems() as $orderItems) { if (trim($orderItems->getETA()) !== trim(UDate::zeroDate())) { $allChecked = false; } } if ($allChecked === true) { $order->addComment('Auto Push this order status from [' . $order->getStatus() . '] to [' . OrderStatus::ID_ETA . '], as the last ETA cleared', Comments::TYPE_SYSTEM); $order->setStatus(OrderStatus::get(OrderStatus::ID_STOCK_CHECKED_BY_PURCHASING)); } $order->save(); $results = $item->getJson(); Dao::commitTransaction(); } catch (Exception $ex) { Dao::rollbackTransaction(); $errors[] = $ex->getMessage(); } $param->ResponseData = StringUtilsAbstract::getJson($results, $errors); }
private static function _orderItems(Order $order) { $msg = "<div>"; $msg .= "<div>Thank you for your support, we have received your following order, and it is currently in processing.</div>"; $msg .= "<div>Here are the item information/status on your order, our logistics will have them shipped out as soon as possible.</div>"; $msg .= "<div>If you have any item with long ETA waiting time and you want to ship part of your order first, please email <a href='mailto:sales@budgetpc.com.au'>sales@budgetpc.com.au</a> and quote your order number when you call.</div>"; $msg .= "<div style='margin: 10px 0 10px 0'>"; $msg .= '<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">'; $msg .= "<thead>"; $msg .= "<tr style='background:#eeeeee; height:23px;'>"; $msg .= "<td width='*'>Item</td>"; $msg .= "<td width='30%'>SKU</td>"; $msg .= "<td width='10%' style='text-align:center;'>Qty</td>"; $msg .= "<td width='20%'>Status</td>"; $msg .= "</tr>"; $msg .= "</thead>"; $msg .= "<tbody>"; foreach ($order->getOrderItems() as $item) { $msg .= "<tr style='height:18px; border-bottom: 1px #cccccc solid;'>"; $msg .= "<td>" . $item->getProduct()->getName() . "</td>"; $msg .= "<td>" . $item->getProduct()->getSku() . "</td>"; $msg .= "<td style='text-align:center;'>" . $item->getQtyOrdered() . "</td>"; $msg .= "<td>" . (trim($item->getEta()) === trim(UDate::zeroDate()) ? 'In Stock' : 'ETA: ' . $item->getEta()->format('d F Y')) . "</td>"; $msg .= "</tr>"; } $msg .= "</tbody>"; $msg .= "</table>"; $msg .= "</div>"; $msg .= "</div>"; return $msg; }
public function getInvDate() { return $this->order->getInvDate() == UDate::zeroDate() ? '' : $this->order->getInvDate()->format('d/M/Y'); }
/** * (non-PHPdoc) * @see BaseEntityAbstract::postSave() */ public function postSave() { if (trim($this->getReceivedDate()) !== trim(UDate::zeroDate())) { if (self::countByCriteria('RMAId = ? and receivedDate = ?', array($this->getRMA()->getId(), trim(UDate::zeroDate()))) > 0) { $this->getRMA()->setStatus(RMA::STATUS_RECEIVING)->save()->addComment('Setting Status to "' . RMA::STATUS_RECEIVING . '", as received one of items'); } else { $this->getRMA()->setStatus(RMA::STATUS_RECEIVED)->save()->addComment('Setting Status to "' . RMA::STATUS_RECEIVED . '", as no more item to receive'); } } }
/** * (non-PHPdoc) * @see TreeEntityAbstract::preSave() */ public function preSave() { if (!$this->getProduct() instanceof Product) { throw new EntityException('A product needed to create a kit!'); } if (trim($this->soldDate) === '') { $this->setSoldDate(UDate::zeroDate()); } if ($this->getProduct()->getIsKit() !== true) { throw new EntityException('The product of the kit needs to have the flag IsKit ticked.'); } if (trim($this->getId()) !== '') { if (self::countByCriteria('id = ? and productId != ?', array($this->getId(), $this->getProduct()->getId())) > 0) { throw new EntityException('You can NOT change the product of the KIT[' . $this->getBarcode() . '] once it is created.'); } $origKit = self::get($this->getId()); $this->_changeLog('soldToCustomer', 'getName', $origKit, 'Customer')->_changeLog('soldDate', '__toString', $origKit, '')->_changeLog('soldOnOrder', 'getOrderNo', $origKit, 'Order')->_changeLog('shippment', 'getId', $origKit, 'Shippment'); } }
/** * (non-PHPdoc) * @see BaseEntityAbstract::postSave() */ public function postSave() { if ($this->getOrderItem() instanceof OrderItem) { if (count($serialItems = self::getAllByCriteria('orderItemId = ?', array($this->getOrderItem()->getId()))) > 0) { $totalUnitCostForOrderItem = 0; $totalNoOfKits = 0; foreach ($serialItems as $serialItem) { if (($kit = $serialItem->getKit()) instanceof Kit) { $totalUnitCostForOrderItem = $totalUnitCostForOrderItem + $kit->getCost(); $totalNoOfKits = $totalNoOfKits + 1; if (!$kit->getSoldOnOrder() instanceof Order) { $kit->setSoldOnOrder($this->getOrderItem()->getOrder()); } if (!$kit->getSoldToCustomer() instanceof Customer) { $kit->setSoldToCustomer($this->getOrderItem()->getOrder()->getCustomer()); } if (trim($kit->getSoldDate()) === trim(UDate::zeroDate())) { $kit->setSoldDate(new UDate()); } if (!$kit->getShippment() instanceof Shippment && count($shippments = $this->getOrderItem()->getOrder()->getShippments()) > 0) { $kit->setShippment($shippments[0]); } $kit->save(); } } $this->getOrderItem()->setUnitCost(intval($totalNoOfKits) === 0 ? 0 : $totalUnitCostForOrderItem / $totalNoOfKits)->reCalMargin(); } } }
/** * recalculating the stockOnHand and stockOnHandValue of this product, if it's a kit */ public function reCalKitsValue() { if ($this->getIsKit() !== true || trim($this->getId()) === '') { return $this; } $sql = 'select sum(kit.cost) `totalValue`, count(distinct kit.id) `totalCount` from kit kit where kit.active = 1 and kit.soldDate = ? and kit.productId = ?'; $result = Dao::getResultsNative($sql, array(trim(UDate::zeroDate()), $this->getId())); if (count($result) > 0) { $totalValue = trim($result[0]['totalValue']) === '' ? '0.0000' : trim($result[0]['totalValue']); $totalCount = trim($result[0]['totalCount']) === '' ? '0' : trim($result[0]['totalCount']); if (($originalTotalOnHandValue = trim($this->getTotalInPartsValue())) !== $totalValue || ($originalStockOnHand = trim($this->getStockOnHand())) !== $totalCount) { //if not matched, then we need to adjust the qty $this->setStockOnHand($totalCount)->setTotalOnHandValue($totalValue)->snapshotQty($this, ProductQtyLog::TYPE_STOCK_ADJ, 'Realigning the TotalInPartsValue to ' . StringUtilsAbstract::getCurrency($totalValue) . ' and StockOnHand to ' . $totalCount)->save()->addLog('StockOnHand(' . $originalStockOnHand . ' => ' . $this->getStockOnHand() . ')', Log::TYPE_SYSTEM, 'STOCK_QTY_CHG', __CLASS__ . '::' . __FUNCTION__)->addLog('TotalOnHandValue(' . $originalTotalOnHandValue . ' => ' . $this->getTotalOnHandValue() . ')', Log::TYPE_SYSTEM, 'STOCK_VALUE_CHG', __CLASS__ . '::' . __FUNCTION__); } } }
/** * (non-PHPdoc) * @see BaseEntityAbstract::preSave() */ public function preSave() { if (trim($this->getId()) === '') { if (!$this->status instanceof TaskStatus) { $this->setStatus(TaskStatus::get(TaskStatus::ID_NEW)); } if (trim($this->getDueDate()) === trim(UDate::zeroDate())) { $this->setDueDate(UDate::now()->modify(self::DUE_DATE_PERIOD)); } } else { $changed = array(); $origTech = $origCustomer = $origOrder = $origStatus = null; $origTask = Task::get($this->getId()); if (($customer = $this->getCustomer()) instanceof Customer && !($origCustomer = $origTask->getCustomer()) instanceof Customer || !$customer instanceof Customer && $origCustomer instanceof Customer || $customer instanceof Customer && $origCustomer instanceof Customer && $customer->getId() !== $origCustomer->getId()) { $changed[] = 'Customer Changed["' . ($origCustomer instanceof Customer ? $origCustomer->getName() : '') . '" => "' . ($customer instanceof Customer ? $customer->getName() : '') . '"]'; } if (($tech = $this->getTechnician()) instanceof UserAccount && !($origTech = $origTask->getTechnician()) instanceof UserAccount || !$tech instanceof UserAccount && $origTech instanceof UserAccount || $tech instanceof UserAccount && $origTech instanceof UserAccount && $tech->getId() !== $origTech->getId()) { $changed[] = 'Technician Changed["' . ($origTech instanceof UserAccount ? $origTech->getPerson()->getFullName() : '') . '" => "' . ($tech instanceof UserAccount ? $tech->getPerson()->getFullName() : '') . '"]'; } if (($order = $this->getFromEntity()) instanceof Order && !($origOrder = $origTask->getFromEntity()) instanceof Order || !$order instanceof Order && $origOrder instanceof Order || $order instanceof Order && $origOrder instanceof Order && $order->getId() !== $origOrder->getId()) { $changed[] = 'Order Changed["' . ($origOrder instanceof Order ? $origOrder->getOrderNo() : '') . '" => "' . ($order instanceof Order ? $order->getOrderNo() : '') . '"]'; } if (($status = $this->getStatus()) instanceof TaskStatus && !($origStatus = $origTask->getStatus()) instanceof TaskStatus || !$status instanceof TaskStatus && $origStatus instanceof TaskStatus || $status instanceof TaskStatus && $origStatus instanceof TaskStatus && $status->getId() !== $origStatus->getId()) { $changed[] = 'Status Changed["' . ($origStatus instanceof TaskStatus ? $origStatus->getName() : '') . '" => "' . ($status instanceof TaskStatus ? $status->getName() : '') . '"]'; } if (count($changed) > 0) { $this->addComment(implode(', ', $changed), Comments::TYPE_SYSTEM); } } }