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;
 }
 /**
  * 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;
 }
 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;
 }
Beispiel #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;
 }
Beispiel #5
0
 /**
  * save the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function deactivateItems($sender, $param)
 {
     $results = $errors = array();
     try {
         $class = trim($this->_focusEntity);
         $id = isset($param->CallbackParameter->item_id) ? $param->CallbackParameter->item_id : array();
         $creditNote = CreditNote::get($id);
         if (!$creditNote instanceof CreditNote) {
             throw new Exception('Invalid Credit Note passed in');
         }
         $creditNote->setActive(false)->save();
         $results['item'] = $creditNote->getJson(array('order' => $creditNote->getOrder() instanceof Order ? '' : $creditNote->getOrder()->getJson(), 'customer' => $creditNote->getCustomer()->getJson()));
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage() . $ex->getTraceAsString();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Beispiel #6
0
 /**
  * Creating a payment for creditNote
  *
  * @param CreditNote    $creditNote
  * @param PaymentMethod $method
  * @param string        $value
  * @param string        $comments
  *
  * @return Ambigous <BaseEntityAbstract, GenericDAO>
  */
 public static function createFromCreditNote(CreditNote &$creditNote, PaymentMethod $method, $value, $comments = '', $paymentDate = '')
 {
     $payment = new Payment();
     $message = 'A ' . StringUtilsAbstract::getCurrency($value) . ' Credit Payment is made via ' . $method->getName() . ' for CreditNote(CreditNoteNo.=' . $creditNote->getCreditNoteNo() . ')' . (trim($comments) !== '' ? ': ' . $comments : '.');
     $payment = $payment->setCreditNote($creditNote)->setMethod($method)->setValue($value)->setPaymentDate(new UDate(trim($paymentDate) === '' ? 'now' : trim($paymentDate)))->save()->addComment($message, Comments::TYPE_ACCOUNTING)->addLog($message, Log::TYPE_SYSTEM, get_class($payment) . '_CREATION', __CLASS__ . '::' . __FUNCTION__);
     $creditNote->addComment($message, Comments::TYPE_ACCOUNTING)->addLog($message, Log::TYPE_SYSTEM, 'Auto Log', __CLASS__ . '::' . __FUNCTION__);
     return $payment;
 }
 /**
  *
  * @param unknown $sender
  * @param unknown $params
  */
 public function addComments($sender, $params)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($params->CallbackParameter->creditNote) || !($creditNote = CreditNote::get($params->CallbackParameter->creditNote->id)) instanceof CreditNote) {
             throw new Exception('System Error: invalid CreditNote passed in!');
         }
         if (!isset($params->CallbackParameter->comments) || ($comments = trim($params->CallbackParameter->comments)) === '') {
             throw new Exception('System Error: invalid comments passed in!');
         }
         $comment = Comments::addComments($creditNote, $comments, Comments::TYPE_NORMAL);
         $results = $comment->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $params->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Beispiel #8
0
         echo "ko";
         exit;
     }
 } else {
     if ($credit_amount > 0) {
         $credit_note_desc = 'Refund of balance for Invoice: ' . pad($previous_invoice, 11, '0');
         $filename = generate_random_string_of(8) . '.' . generate_random_string_of(8);
         $issued_on = today();
         $expire_on = sql_date_add($issued_on, 30, 'day');
         Invoice::accompany_credit_note_with($previous_invoice, $invoice, $issued_on, $credit_amount);
         $branch = $employer->get_branch();
         $sales = 'sales.' . strtolower($branch[0]['country']) . '@yellowelevator.com';
         $branch[0]['address'] = str_replace(array("\r\n", "\r"), "\n", $branch[0]['address']);
         $branch['address_lines'] = explode("\n", $branch[0]['address']);
         $currency = Currency::getSymbolFromCountryCode($branch[0]['country']);
         $pdf = new CreditNote();
         $pdf->AliasNbPages();
         $pdf->SetAuthor('Yellow Elevator. This credit note was automatically generated. Signature is not required.');
         $pdf->SetTitle($GLOBALS['COMPANYNAME'] . ' - Credit Note ' . pad($invoice, 11, '0'));
         $pdf->SetRefundAmount($credit_amount);
         $pdf->SetDescription($credit_note_desc);
         $pdf->SetCurrency($currency);
         $pdf->SetBranch($branch);
         $pdf->AddPage();
         $pdf->SetFont('Arial', '', 10);
         $pdf->SetTextColor(255, 255, 255);
         $pdf->SetFillColor(54, 54, 54);
         $pdf->Cell(60, 5, "Credit Note Number", 1, 0, 'C', 1);
         $pdf->Cell(1);
         $pdf->Cell(33, 5, "Issuance Date", 1, 0, 'C', 1);
         $pdf->Cell(1);
Beispiel #9
0
 public static function GenerateCashCreditNote($clientid, $invoice, $credit, $description)
 {
     $client = Client::GetClient($clientid);
     $description = 'Credit Note (Inv: ' . $invoice . ') - ' . $description;
     $inv = SalesInvoice::GetInvoice($invoice);
     if ($inv->total->amount < $inv->credit->amount + $credit) {
         return false;
     }
     $crnote = CreditNote::CreateCashCreditNote($client, $invoice, $credit, $description);
     if ($crnote->generate()) {
         return new SalesTX($crnote, 'Credit Note');
     } else {
         Logger::Log('SalesTX', 'Failed', 'Credit Note transaction with id:' . $crnote->id . ' and tx id:' . $this->transactionId . ' could not be completed');
         return false;
     }
 }
Beispiel #10
0
 /**
  * Creating a CreditNote
  *
  * @param Customer $customer
  *
  * @return CreditNote
  */
 public static function create(Customer $customer, $description = '')
 {
     $creditNote = new CreditNote();
     return $creditNote->setCustomer($customer)->setDescription(trim($description))->save();
 }