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; }
public function genReport($sender, $param) { $results = $errors = array(); try { Dao::beginTransaction(); if (isset($param->CallbackParameter->type) && ($type = trim($param->CallbackParameter->type)) === '') { throw new Exception('SYSTEM ERROR: invalid type passed in.'); } $asset = null; switch (strtolower($type)) { case 'sales_daily': SalesExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to))); $asset = SalesExport_Xero::run(false, false); break; case 'creditnotes_daily': CreditNoteExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to))); $asset = CreditNoteExport_Xero::run(false, false); break; case 'supplier_bill_daily': BillExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to))); $asset = BillExport_Xero::run(false, false); break; case 'manual_journal': ManualJournalExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to))); $asset = ManualJournalExport_Xero::run(false, false); break; case 'payments_daily': PaymentExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to))); $asset = PaymentExport_Xero::run(false, false); break; case 'inventory_list': ItemExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to))); $asset = ItemExport_Xero::run(false, true); break; case 'magento_price': ItemExport_Magento::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to))); $asset = ItemExport_Magento::run(false, false); break; case 'accounting_code': AccoutingCodeExport::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to))); $asset = AccoutingCodeExport::run(false, false); break; case 'open_inv': OpenInvoiceExport::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to))); $asset = OpenInvoiceExport::run(false, false); break; default: throw new Exception('SYSTEM ERROR: invalid type passed in: ' . $type); } if ($asset instanceof Asset) { $results['item'] = $asset->getJson(); } Dao::commitTransaction(); } catch (Exception $ex) { Dao::rollbackTransaction(); $error[] = $ex->getMessage(); } $param->ResponseData = StringUtilsAbstract::getJson($results, $errors); }