예제 #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'];
     }
     self::$_fromDate = $fromDate;
     self::$_toDate = $toDate;
     $orders = Order::getAllByCriteria('invDate >= :fromDate and invDate <= :toDate', array('fromDate' => trim($fromDate), 'toDate' => trim($toDate)));
     $return = array();
     foreach ($orders as $order) {
         //common fields
         $customer = $order->getCustomer();
         $creditNotes = CreditNote::getAllByCriteria('orderId = ?', array($order->getId()));
         $row = array('Invoice No.' => $order->getInvNo(), 'Invoice Date' => $order->getInvDate()->setTimeZone('Australia/Melbourne')->__toString(), 'Order No.' => $order->getOrderNo(), 'Order Date' => $order->getOrderDate()->setTimeZone('Australia/Melbourne')->__toString(), 'PO No.' => $order->getPONo(), 'Customer Name' => $customer->getName(), 'Customer Ph.' => $customer->getContactNo(), 'Customer Email' => $customer->getEmail(), 'Status' => $order->getStatus()->getName(), 'Total Amt.' => StringUtilsAbstract::getCurrency($order->getTotalAmount()), 'Total Paid' => StringUtilsAbstract::getCurrency($order->getTotalPaid()), 'Total Credited' => StringUtilsAbstract::getCurrency($order->getTotalCreditNoteValue()), 'Total Due' => StringUtilsAbstract::getCurrency($order->getTotalAmount() - $order->getTotalPaid() - $order->getTotalCreditNoteValue()), 'CreditNote Nos.' => implode(', ', array_map(create_function('$a', 'return $a->getCreditNoteNo();'), $creditNotes)));
         $return[] = $row;
     }
     return $return;
 }
예제 #2
0
 /**
  * Getting The end javascript
  *
  * @return string
  */
 protected function _getEndJs()
 {
     if (!($order = Order::get($this->Request['orderId'])) instanceof Order) {
         die('Invalid Order!');
     }
     if (trim($order->getType()) !== Order::TYPE_INVOICE) {
         header('Location: /order/' . $order->getId() . '.html?' . $_SERVER['QUERY_STRING']);
         die;
     }
     $js = parent::_getEndJs();
     $orderItems = $courierArray = array();
     foreach ($order->getOrderItems() as $orderItem) {
         $orderItems[] = $orderItem->getJson();
     }
     $purchaseEdit = $warehouseEdit = $accounEdit = $statusEdit = 'false';
     if ($order->canEditBy(Core::getRole())) {
         $statusEdit = $order->canEditBy(Core::getRole()) && Core::getRole()->getId() === trim(Role::ID_SYSTEM_ADMIN) ? 'true' : 'false';
         if (in_array(intval(Core::getRole()->getId()), array(Role::ID_SYSTEM_ADMIN, Role::ID_STORE_MANAGER, Role::ID_SALES))) {
             $purchaseEdit = $warehouseEdit = $accounEdit = 'true';
         } else {
             if (trim(Core::getRole()->getId()) === trim(Role::ID_PURCHASING)) {
                 $purchaseEdit = 'true';
             } else {
                 if (trim(Core::getRole()->getId()) === trim(Role::ID_WAREHOUSE)) {
                     $purchaseEdit = 'false';
                     $warehouseEdit = 'true';
                     $statusEdit = 'false';
                 }
             }
         }
     }
     if (in_array(intval(Core::getRole()->getId()), array(Role::ID_SYSTEM_ADMIN, Role::ID_STORE_MANAGER, Role::ID_ACCOUNTING, Role::ID_SALES))) {
         $accounEdit = 'true';
     }
     $orderArray = $order->getJson();
     $orderArray['childrenOrders'] = array_map(create_function('$a', 'return $a->getOrder()->getJson();'), OrderInfo::getAllByCriteria('typeId = ? and value = ?', array(OrderInfoType::ID_CLONED_FROM_ORDER_NO, trim($order->getOrderNo()))));
     $orderArray['creditNotes'] = array_map(create_function('$a', 'return $a->getJson();'), CreditNote::getAllByCriteria('orderId = ?', array(trim($order->getId()))));
     $orderStatuses = array_map(create_function('$a', 'return $a->getJson();'), OrderStatus::findAll());
     $courierArray = array_map(create_function('$a', 'return $a->getJson();'), Courier::findAll());
     $js .= 'pageJs';
     $js .= '.setCallbackId("updateOrder", "' . $this->updateOrderBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("changeOrderStatus", "' . $this->changeOrderStatusBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("updateOIForWH", "' . $this->updateOIForWHBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("updateShippingInfo", "' . $this->updateShippingInfoBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("clearETA", "' . $this->clearETABtn->getUniqueID() . '")';
     $js .= '.setCallbackId("changeIsOrdered", "' . $this->changeIsOrderedBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("updateAddress", "' . $this->updateAddressBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("updatePONo", "' . $this->updatePONoBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("changeShippingMethod", "' . $this->changeShippingMethodBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("updateSerials", "' . $this->updateSerialsBtn->getUniqueID() . '")';
     $js .= '.setEditMode(' . $purchaseEdit . ', ' . $warehouseEdit . ', ' . $accounEdit . ', ' . $statusEdit . ')';
     $js .= '.setOrder(' . json_encode($orderArray) . ', ' . json_encode($orderItems) . ', ' . json_encode($orderStatuses) . ', ' . OrderStatus::ID_SHIPPED . ')';
     $js .= '.setCourier(' . json_encode($courierArray) . ', ' . Courier::ID_LOCAL_PICKUP . ')';
     $js .= '.setCommentType("' . Comments::TYPE_PURCHASING . '", "' . Comments::TYPE_WAREHOUSE . '")';
     $js .= '.setOrderStatusIds([' . OrderStatus::ID_NEW . ', ' . OrderStatus::ID_INSUFFICIENT_STOCK . '], [' . OrderStatus::ID_ETA . ', ' . OrderStatus::ID_STOCK_CHECKED_BY_PURCHASING . ', ' . OrderStatus::ID_INSUFFICIENT_STOCK . '], [' . OrderStatus::ID_PICKED . '])';
     $js .= '.init("detailswrapper")';
     $js .= '.load();';
     return $js;
 }
예제 #3
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'];
     }
     $creditNotes = CreditNote::getAllByCriteria('applyDate >= :fromDate and applyDate < :toDate', array('fromDate' => trim($fromDate), 'toDate' => trim($toDate)));
     $return = array();
     foreach ($creditNotes as $creditNote) {
         $orderStatus = $creditNote->getOrder()->getStatus()->getId();
         $orderType = $creditNote->getOrder()->getType();
         //file_put_contents('/tmp/datafeed/web.log', __FILE__ .':' . __FUNCTION__ . ':' . __LINE__ . ':' . $orderType .  ":" . $orderStatus . PHP_EOL, FILE_APPEND | LOCK_EX);
         if ($orderType == Order::TYPE_INVOICE && $orderStatus == OrderStatus::ID_CANCELLED) {
             continue;
         }
         //common fields
         $customer = $creditNote->getCustomer();
         $row = array('ContactName' => $customer->getName(), 'EmailAddress' => $customer->getEmail(), 'POAddressLine1' => '', 'POAddressLine2' => '', 'POAddressLine3' => '', 'POAddressLine4' => '', 'POCity' => '', 'PORegion' => '', 'POPostalCode' => '', 'POCountry' => '', 'InvoiceNumber' => $creditNote->getCreditNoteNo(), 'Reference' => $creditNote->getOrder() instanceof Order ? $creditNote->getOrder()->getInvNo() : '', 'InvoiceDate' => $creditNote->getApplyDate()->setTimeZone('Australia/Melbourne')->__toString(), 'DueDate' => '');
         foreach ($creditNote->getCreditNoteItems() as $item) {
             $product = $item->getProduct();
             if (!$product instanceof Product) {
                 continue;
             }
             $shouldTotal = $item->getUnitPrice() * $item->getQty();
             $return[] = array_merge($row, array('InventoryItemCode' => $product->getSku(), 'Description' => $product->getShortDescription(), 'Quantity' => 0 - $item->getQty(), 'UnitAmount' => $item->getUnitPrice(), 'Discount' => (floatval($shouldTotal) === 0.0 ? 0 : round(($shouldTotal - $item->getTotalPrice()) * 100 / $shouldTotal, 2)) . '%', 'AccountCode' => $product->getRevenueAccNo(), 'TaxType' => "GST on Income", 'TrackingName1' => '', 'TrackingOption1' => '', 'TrackingName2' => '', 'TrackingOption2' => '', 'Currency' => '', 'BrandingTheme' => ''));
         }
         if (($shippingValue = $creditNote->getShippingValue()) > 0) {
             $return[] = array_merge($row, array('InventoryItemCode' => 'Credit Note Shipping', 'Description' => 'Credit Note Shipping', 'Quantity' => 0 - 1, 'UnitAmount' => StringUtilsAbstract::getCurrency($shippingValue), 'Discount' => '', 'AccountCode' => '43300', 'TaxType' => "GST on Income", 'TrackingName1' => '', 'TrackingOption1' => '', 'TrackingName2' => '', 'TrackingOption2' => '', 'Currency' => '', 'BrandingTheme' => ''));
         }
     }
     return $return;
 }
예제 #4
0
 /**
  * get Credit Note Items by credit note
  * 
  * @param CreditNote|string $creditNote
  * @return Ambigous <NULL, unknown>
  */
 public static function getByCreditNote($creditNote)
 {
     $creditNote = $creditNote instanceof CreditNote ? $creditNote : CreditNote::get(trim($creditNote));
     $creditNote = $creditNote instanceof CreditNote ? $creditNote : (count($creditNotes = CreditNote::getAllByCriteria('creditNoteNo = ?', array(trim($creditNote)), true, 1, 1)) > 0 ? $creditNotes[0] : null);
     return $creditNote instanceof CreditNote ? count($items = self::getAllByCriteria('creditNoteId = ?', array($creditNote->getId()), true)) > 0 ? $items : null : null;
 }
예제 #5
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::postSave()
  */
 public function postSave()
 {
     if (trim($this->getCreditNoteNo()) === '') {
         $this->setCreditNoteNo('BPCC' . str_pad($this->getId(), 8, '0', STR_PAD_LEFT))->save();
         if ($this->getOrder() instanceof Order) {
             $msg = "An Credit Note(" . $this->getCreditNoteNo() . ") has created for this order";
             $this->getOrder()->addComment($msg, Comments::TYPE_SYSTEM)->addLog($msg, Log::TYPE_SYSTEM, 'AUTO', __CLASS__ . '::' . __FUNCTION__);
         }
     }
     if ($this->getOrder() instanceof Order) {
         $totalCreditNoteValue = 0;
         foreach (CreditNote::getAllByCriteria('cn.orderId = ?', array($this->getOrder()->getId())) as $creditNote) {
             $totalCreditNoteValue += $creditNote->getTotalValue();
         }
         $this->getOrder()->setTotalCreditNoteValue($totalCreditNoteValue)->setMargin($this->getOrder()->getCalculatedTotalMargin() - $totalCreditNoteValue)->save();
     }
 }