private function _getXnames()
 {
     $names = array();
     $_12mthAgo = new UDate();
     $_12mthAgo->modify('-12 month');
     for ($i = 0; $i < 12; $i++) {
         $from = new UDate(trim($_12mthAgo->format('Y-m-01 00:00:00')));
         $to = new UDate(trim($_12mthAgo->modify('+1 month')->format('Y-m-01 00:00:00')));
         $names[trim($from->format('M/Y'))] = array('from' => trim($from), 'to' => trim($to));
     }
     return $names;
 }
 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;
 }
 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'];
     }
     $orders = Order::getAllByCriteria('invDate >= :fromDate and invDate < :toDate and statusId != :cancelStatusId', array('fromDate' => trim($fromDate), 'toDate' => trim($toDate), 'cancelStatusId' => trim(OrderStatus::ID_CANCELLED)));
     $return = array();
     foreach ($orders as $order) {
         //common fields
         $customer = $order->getCustomer();
         $row = array('ContactName' => $customer->getName(), 'EmailAddress' => $customer->getEmail(), 'POAddressLine1' => '', 'POAddressLine2' => '', 'POAddressLine3' => '', 'POAddressLine4' => '', 'POCity' => '', 'PORegion' => '', 'POPostalCode' => '', 'POCountry' => '', 'InvoiceNumber' => $order->getInvNo(), 'Reference' => intval($order->getIsFromB2B()) === 1 ? $order->getOrderNo() : $order->getPONo(), 'InvoiceDate' => $order->getInvDate()->setTimeZone('Australia/Melbourne')->__toString(), 'DueDate' => $order->getInvDate()->modify('+' . self::getTerms($customer) . ' day')->setTimeZone('Australia/Melbourne')->__toString());
         foreach ($order->getOrderItems() as $orderItem) {
             $product = $orderItem->getProduct();
             if (!$product instanceof Product) {
                 continue;
             }
             $shouldTotal = $orderItem->getUnitPrice() * $orderItem->getQtyOrdered();
             $return[] = array_merge($row, array('InventoryItemCode' => $product->getSku(), 'Description' => $product->getShortDescription(), 'Quantity' => $orderItem->getQtyOrdered(), 'UnitAmount' => $orderItem->getUnitPrice(), 'Discount' => (floatval($shouldTotal) === 0.0 ? 0 : round(($shouldTotal - $orderItem->getTotalPrice()) * 100 / $shouldTotal, 2)) . '%', 'AccountCode' => $product->getRevenueAccNo(), 'TaxType' => "GST on Income", 'TrackingName1' => '', 'TrackingOption1' => '', 'TrackingName2' => '', 'TrackingOption2' => '', 'Currency' => '', 'BrandingTheme' => ''));
         }
         if (($shippingMethod = trim(implode(',', $order->getInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_METHOD)))) !== '') {
             $shippingCost = $order->getInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_COST);
             $return[] = array_merge($row, array('InventoryItemCode' => $shippingMethod, 'Description' => $shippingMethod, 'Quantity' => 1, 'UnitAmount' => StringUtilsAbstract::getCurrency(count($shippingCost) > 0 ? StringUtilsAbstract::getValueFromCurrency($shippingCost[0]) : 0), 'Discount' => '', 'AccountCode' => '43300', 'TaxType' => "GST on Income", 'TrackingName1' => '', 'TrackingOption1' => '', 'TrackingName2' => '', 'TrackingOption2' => '', 'Currency' => '', 'BrandingTheme' => ''));
         }
     }
     return $return;
 }
 /**
  * 
  * @param Product $product
  * @param unknown $cronStartDateTime
  * @param string $syncType
  */
 private function _handle_failed_product(Product $product, $cronStartDateTime, $syncType = "insert")
 {
     $date = new UDate(trim($cronStartDateTime));
     $date->modify('+1 second');
     $product->setUpdated($date)->save();
     Log::LogEntity($product, 'Product Sync failed with Magento. ' . $syncType . ' operation failed', Log::TYPE_SYSTEM);
 }
 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'];
     }
     $productPrices = ProductPrice::getAllByCriteria('updated >= :fromDate and updated < :toDate', array('fromDate' => trim($fromDate), 'toDate' => trim($toDate)));
     $return = array();
     foreach ($productPrices as $productPrice) {
         if (!($product = $productPrice->getProduct()) instanceof Product) {
             continue;
         }
         if (!isset($return[trim($product->getSku())])) {
             $return[trim($product->getSku())] = self::_getDefaultData($product);
         }
         if (trim($productPrice->getType()->getId()) === trim(ProductPriceType::ID_RRP)) {
             $return[trim($product->getSku())]['price'] = $productPrice->getPrice();
         } else {
             if (trim($productPrice->getType()->getId()) === trim(ProductPriceType::ID_CASUAL_SPECIAL)) {
                 $return[trim($product->getSku())]['special_price'] = $productPrice->getPrice();
                 $return[trim($product->getSku())]['special_from_date'] = trim($productPrice->getStart());
                 $return[trim($product->getSku())]['special_to_date'] = trim($productPrice->getEnd());
             }
         }
     }
     return $return;
 }
 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;
 }
 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';
     $receivingItems = ReceivingItem::getAllByCriteria($dataType . ' >= :fromDate and ' . $dataType . ' < :toDate', array('fromDate' => trim($fromDate), 'toDate' => trim($toDate)));
     $now = new UDate();
     $now->setTimeZone('Australia/Melbourne');
     $formatArray = array();
     foreach ($receivingItems as $receivingItem) {
         $product = $receivingItem->getProduct();
         if (!$product instanceof Product) {
             continue;
         }
         if (!array_key_exists($key = trim($receivingItem->getPurchaseOrder()->getId() . '|' . $product->getId() . '|' . $receivingItem->getInvoiceNo()), $formatArray)) {
             $formatArray[$key] = $receivingItem;
         }
         if ($formatArray[$key]->getId() !== $receivingItem->getId()) {
             $formatArray[$key]->setQty($formatArray[$key]->getQty() + $receivingItem->getQty());
         }
     }
     $return = array();
     foreach ($formatArray as $key => $receivingItem) {
         $product = $receivingItem->getProduct();
         $purchaseOrder = $receivingItem->getPurchaseOrder();
         $supplier = $purchaseOrder->getSupplier();
         $return[] = array('ContactName' => $supplier->getName(), 'EmailAddress' => $supplier->getEmail(), 'POAddressLine1' => '', 'POAddressLine2' => '', 'POAddressLine3' => '', 'POAddressLine4' => '', 'POCity' => '', 'PORegion' => '', 'POPostalCode' => '', 'POCountry' => '', 'InvoiceNumber' => $receivingItem->getInvoiceNo(), 'InvoiceDate' => '', 'DueDate' => trim($now->modify(self::DEFAULT_DUE_DELAY)), 'InventoryItemCode' => $product->getSku(), 'Description' => ($description = trim($product->getShortDescription())) === '' ? $product->getName() : $description, 'Quantity' => $receivingItem->getQty(), 'UnitAmount' => $receivingItem->getUnitPrice(), 'AccountCode' => $product->getAssetAccNo(), 'TaxType' => "GST on Expenses", 'TrackingName1' => '', 'TrackingOption1' => '', 'TrackingName2' => '', 'TrackingOption2' => '', 'Currency' => '');
     }
     return $return;
 }
 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;
 }
 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 = Payment::getAllByCriteria($dataType . ' >= :fromDate and ' . $dataType . ' < :toDate', array('fromDate' => trim($fromDate), 'toDate' => trim($toDate)));
     $now = new UDate();
     $now->setTimeZone('Australia/Melbourne');
     $return = array();
     foreach ($items as $item) {
         $return[] = array('Type' => $item->getOrder() instanceof Order ? 'Payment' : 'Credit', 'InvNo' => $item->getOrder() instanceof Order ? trim($item->getOrder()->getInvNo()) === '' ? '' : $item->getOrder()->getInvNo() : '', 'Payment Date' => $item->getPaymentDate()->setTimeZone('Australia/Melbourne')->format('Y-m-d'), 'Customer Name' => $item->getOrder() instanceof Order ? $item->getOrder()->getCustomer() instanceof Customer ? $item->getOrder()->getCustomer()->getName() : '' : '', 'Order No.' => $item->getOrder() instanceof Order ? $item->getOrder()->getOrderNo() : '', 'CreditNote No' => $item->getCreditNote() instanceof CreditNote ? $item->getCreditNote()->getCreditNoteNo() : '', 'Processed Date' => trim($item->getCreated()->setTimeZone('Australia/Melbourne')), 'Processed By' => $item->getCreatedBy() instanceof UserAccount ? $item->getCreatedBy()->getPerson()->getFullName() : '', 'Method' => $item->getMethod() instanceof PaymentMethod ? trim($item->getMethod()->getName()) : '', 'Amount' => StringUtilsAbstract::getCurrency($item->getCreditNote() instanceof CreditNote ? 0 - $item->getValue() : $item->getValue()), 'Comments' => trim(implode(',', array_map(create_function('$a', 'return $a->getComments();'), Comments::getAllByCriteria('entityName = ? and entityId = ?', array(get_class($item), $item->getId()))))));
     }
     return $return;
 }
Exemple #10
0
 /**
  * delete all sessions that has been timed out
  *
  * @param int $maxTimeOut The number of seconds for the session's life time
  *
  * @return SessionService
  */
 public static function cleanUp($maxTimeOut)
 {
     $now = new UDate();
     $now->modify('-' . $maxTimeOut . ' second');
     return self::deleteByCriteria('`active` = 0 and `updated` < ?', array($now->__toString()));
 }