Пример #1
0
 /**
  * Event Manager Registration
  * @return mixed
  */
 public function events()
 {
     $em = Shineisp_Registry::get('em');
     if (!self::$events && is_object($em)) {
         self::$events = Shineisp_Registry::get('em');
     }
     return self::$events;
 }
Пример #2
0
 /**
  * print the credit note
  * @param integer $creditnoteId
  */
 public static function PrintPDF($creditnoteId, $show = true)
 {
     $currency = Shineisp_Registry::getInstance()->Zend_Currency;
     $pdf = new Shineisp_Commons_PdfOrder();
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     $creditnote = Doctrine_Query::create()->from('CreditNotes cn')->leftJoin('cn.CreditNotesItems cni')->leftJoin('cn.Invoices i')->leftJoin('i.Customers c')->leftJoin('c.Addresses a')->leftJoin('a.Countries co')->leftJoin('i.Orders o')->leftJoin('o.OrdersItems oi')->leftJoin('o.Isp isp')->leftJoin('o.Payments p')->leftJoin('p.Banks b')->leftJoin('o.Statuses s')->leftJoin('o.Customers oc')->where("cn.creditnote_id = ?", $creditnoteId)->execute(array(), Doctrine::HYDRATE_ARRAY);
     if (empty($creditnote)) {
         return false;
     }
     $invoice = $creditnote[0]['Invoices'];
     $customer = $creditnote[0]['Invoices']['Customers'];
     $payments = $creditnote[0]['Invoices']['Orders']['Payments'];
     $order = $creditnote[0]['Invoices']['Orders'];
     $items = $creditnote[0]['CreditNotesItems'];
     $database['header']['label'] = $translator->translate('Credit Note No.') . " " . sprintf("%03d", $creditnote[0]['number']) . " - " . Shineisp_Commons_Utilities::formatDateOut($creditnote[0]['creationdate']);
     $database['columns'][] = array("value" => "Description");
     $database['columns'][] = array("value" => "Qty", "size" => 30, "align" => "center");
     $database['columns'][] = array("value" => "Unit", "size" => 30);
     $database['columns'][] = array("value" => "Tax Free Price", "size" => 60, "align" => "right");
     $database['columns'][] = array("value" => "VAT", "size" => 40, "align" => "right");
     $database['columns'][] = array("value" => "Total", "size" => 50, "align" => "right");
     if (isset($order)) {
         $info['order_number'] = $order['order_id'];
         $info['invoice_number'] = $invoice['number'];
         $info['date'] = Shineisp_Commons_Utilities::formatDateOut($invoice['invoice_date']);
         //if customer comes from reseller
         if ($order['Customers']['parent_id']) {
             $reseller = Customers::getAllInfo($order['Customers']['parent_id']);
             $info['customer']['customer_id'] = $reseller['customer_id'];
             $info['customer']['company'] = $reseller['company'];
             $info['customer']['firstname'] = $reseller['firstname'];
             $info['customer']['lastname'] = $reseller['lastname'];
             $info['customer']['vat'] = $reseller['vat'];
             $info['customer']['email'] = $reseller['email'];
             if (isset($reseller['Addresses'][0])) {
                 $info['customer']['address'] = $reseller['Addresses'][0]['address'];
                 $info['customer']['city'] = $reseller['Addresses'][0]['city'];
                 $info['customer']['code'] = $reseller['Addresses'][0]['code'];
                 $info['customer']['country'] = !empty($reseller['Addresses'][0]['Countries']['name']) ? $reseller['Addresses'][0]['Countries']['name'] : "";
             }
         } else {
             $info['customer']['customer_id'] = $customer['customer_id'];
             $info['customer']['company'] = $customer['company'];
             $info['customer']['firstname'] = $customer['firstname'];
             $info['customer']['lastname'] = $customer['lastname'];
             $info['customer']['vat'] = $customer['vat'];
             $info['customer']['email'] = $customer['email'];
             if (isset($customer['Addresses'][0])) {
                 $info['customer']['address'] = $customer['Addresses'][0]['address'];
                 $info['customer']['city'] = $customer['Addresses'][0]['city'];
                 $info['customer']['code'] = $customer['Addresses'][0]['code'];
                 $info['customer']['country'] = $customer['Addresses'][0]['Countries']['name'];
             }
         }
         if (count($payments) > 0) {
             $info['payment_date'] = Shineisp_Commons_Utilities::formatDateOut($payments[0]['paymentdate']);
             $info['payment_mode'] = $payments[0]['Banks']['name'];
             $info['payment_description'] = $payments[0]['description'];
             $info['payment_transaction_id'] = $payments[0]['reference'];
         }
         $info['invoice_id'] = $invoice['number'];
         $info['company']['name'] = $order['Isp']['company'];
         $info['company']['vat'] = $order['Isp']['vatnumber'];
         $info['company']['bankname'] = $order['Isp']['bankname'];
         $info['company']['iban'] = $order['Isp']['iban'];
         $info['company']['bic'] = $order['Isp']['bic'];
         $info['company']['address'] = $order['Isp']['address'];
         $info['company']['zip'] = $order['Isp']['zip'];
         $info['company']['city'] = $order['Isp']['city'];
         $info['company']['country'] = $order['Isp']['country'];
         $info['company']['telephone'] = $order['Isp']['telephone'];
         $info['company']['fax'] = $order['Isp']['fax'];
         $info['company']['website'] = $order['Isp']['website'];
         $info['company']['email'] = $order['Isp']['email'];
         $info['company']['slogan'] = $order['Isp']['slogan'];
         $info['subtotal'] = $currency->toCurrency($creditnote[0]['total_net'], array('currency' => Settings::findbyParam('currency')));
         $info['grandtotal'] = $currency->toCurrency($creditnote[0]['total'], array('currency' => Settings::findbyParam('currency')));
         $info['vat'] = $currency->toCurrency($creditnote[0]['vat'], array('currency' => Settings::findbyParam('currency')));
         $info['delivery'] = 0;
         $database['records'] = $info;
         //				Zend_Debug::dump($creditnote);
         //				die;
         foreach ($items as $item) {
             $item['price'] = $currency->toCurrency($item['price'], array('currency' => Settings::findbyParam('currency')));
             $item['vat'] = $currency->toCurrency($item['vat'], array('currency' => Settings::findbyParam('currency')));
             $item['total'] = $currency->toCurrency($item['total'], array('currency' => Settings::findbyParam('currency')));
             $database['records'][] = array($item['description'], $item['quantity'], 'nr', $item['price'], $item['vat'], $item['total']);
         }
         if (isset($order)) {
             $pdf->CreatePDF($database, $creditnote[0]['creationdate'] . " - " . $creditnote[0]['number'] . ".pdf", $show, "/documents/creditnotes", true);
         }
     }
 }
Пример #3
0
 /**
  * print the order
  *
  * @param unknown_type $invoiceid
  */
 public static function pdf($order_id, $show = true, $force = false, $path = "/documents/orders/")
 {
     $taxpercent = "";
     $currency = Shineisp_Registry::getInstance()->Zend_Currency;
     if (!is_numeric($order_id)) {
         return false;
     }
     $pdf = new Shineisp_Commons_PdfOrder();
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     $payments = Payments::findbyorderid($order_id, null, true);
     $order = self::getAllInfo($order_id, null, true);
     // Set the name of the file
     $filename = $order[0]['order_date'] . " - " . $order[0]['order_id'] . ".pdf";
     $database['header']['label'] = $translator->translate('Order No.') . " " . $order[0]['order_number'] . " - " . Shineisp_Commons_Utilities::formatDateOut($order[0]['order_date']);
     $database['columns'][] = array("value" => $translator->translate("SKU"), "size" => 40);
     $database['columns'][] = array("value" => $translator->translate("Description"));
     $database['columns'][] = array("value" => $translator->translate("Qty"), "size" => 30, "align" => "center");
     $database['columns'][] = array("value" => $translator->translate("Unit"), "size" => 30);
     $database['columns'][] = array("value" => $translator->translate("Tax Free Price"), "size" => 60, "align" => "right");
     $database['columns'][] = array("value" => $translator->translate("Discount"), "size" => 60, "align" => "right");
     $database['columns'][] = array("value" => $translator->translate("Setup fee"), "size" => 60, "align" => "right");
     $database['columns'][] = array("value" => $translator->translate("Tax %"), "size" => 40, "align" => "center");
     $database['columns'][] = array("value" => $translator->translate("Total"), "size" => 50, "align" => "right");
     if (isset($order[0])) {
         $orderinfo['order_number'] = !empty($order[0]['order_number']) ? $order[0]['order_number'] : self::formatOrderId($order[0]['order_id']);
         $orderinfo['invoice_id'] = "";
         $orderinfo['date'] = Shineisp_Commons_Utilities::formatDateOut($order[0]['order_date']);
         //if customer comes from reseller
         if ($order[0]['Customers']['parent_id']) {
             $isTaxFree = Customers::isTaxFree($order[0]['Customers']['parent_id']);
             $isVATFree = Customers::isVATFree($order[0]['Customers']['parent_id']);
             $invoice_dest = Customers::getAllInfo($order[0]['Customers']['parent_id'], 'c.*, a.*');
             $orderinfo['customer']['customer_id'] = $invoice_dest['customer_id'];
             $orderinfo['customer']['company'] = $invoice_dest['company'];
             $orderinfo['customer']['firstname'] = $invoice_dest['firstname'];
             $orderinfo['customer']['lastname'] = $invoice_dest['lastname'];
             $orderinfo['customer']['vat'] = $invoice_dest['vat'];
             $orderinfo['customer']['taxpayernumber'] = $invoice_dest['taxpayernumber'];
             $orderinfo['customer']['email'] = $invoice_dest['email'];
             if (isset($invoice_dest['Addresses'][0])) {
                 $orderinfo['customer']['address'] = $invoice_dest['Addresses'][0]['address'];
                 $orderinfo['customer']['city'] = $invoice_dest['Addresses'][0]['city'];
                 $orderinfo['customer']['code'] = $invoice_dest['Addresses'][0]['code'];
                 $orderinfo['customer']['country'] = !empty($invoice_dest['Addresses'][0]['Countries']['name']) ? $invoice_dest['Addresses'][0]['Countries']['name'] : "";
             }
         } else {
             $isTaxFree = Customers::isTaxFree($order[0]['Customers']['customer_id']);
             $isVATFree = Customers::isVATFree($order[0]['Customers']['customer_id']);
             $orderinfo['customer']['customer_id'] = $order[0]['Customers']['customer_id'];
             $orderinfo['customer']['company'] = $order[0]['Customers']['company'];
             $orderinfo['customer']['firstname'] = $order[0]['Customers']['firstname'];
             $orderinfo['customer']['lastname'] = $order[0]['Customers']['lastname'];
             $orderinfo['customer']['vat'] = $order[0]['Customers']['vat'];
             $orderinfo['customer']['taxpayernumber'] = $order[0]['Customers']['taxpayernumber'];
             $orderinfo['customer']['email'] = $order[0]['Customers']['email'];
             if (isset($order[0]['Customers']['Addresses'][0])) {
                 $orderinfo['customer']['address'] = $order[0]['Customers']['Addresses'][0]['address'];
                 $orderinfo['customer']['city'] = $order[0]['Customers']['Addresses'][0]['city'];
                 $orderinfo['customer']['code'] = $order[0]['Customers']['Addresses'][0]['code'];
                 $orderinfo['customer']['country'] = $order[0]['Customers']['Addresses'][0]['Countries']['name'];
             }
         }
         if (count($payments) > 0) {
             $orderinfo['payment_date'] = Shineisp_Commons_Utilities::formatDateOut($payments[0]['paymentdate']);
             $orderinfo['payment_mode'] = $payments[0]['Banks']['name'];
             $orderinfo['payment_description'] = $payments[0]['description'];
             $orderinfo['payment_transaction_id'] = $payments[0]['reference'];
         }
         $orderinfo['invoice_id'] = "";
         $orderinfo['company']['name'] = $order[0]['Isp']['company'];
         $orderinfo['company']['manager'] = $order[0]['Isp']['manager'];
         $orderinfo['company']['vat'] = $order[0]['Isp']['vatnumber'];
         $orderinfo['company']['bankname'] = $order[0]['Isp']['bankname'];
         $orderinfo['company']['iban'] = $order[0]['Isp']['iban'];
         $orderinfo['company']['bic'] = $order[0]['Isp']['bic'];
         $orderinfo['company']['address'] = $order[0]['Isp']['address'];
         $orderinfo['company']['zip'] = $order[0]['Isp']['zip'];
         $orderinfo['company']['city'] = $order[0]['Isp']['city'];
         $orderinfo['company']['country'] = $order[0]['Isp']['country'];
         $orderinfo['company']['telephone'] = $order[0]['Isp']['telephone'];
         $orderinfo['company']['fax'] = $order[0]['Isp']['fax'];
         $orderinfo['company']['website'] = $order[0]['Isp']['website'];
         $orderinfo['company']['email'] = $order[0]['Isp']['email'];
         $orderinfo['company']['slogan'] = $order[0]['Isp']['slogan'];
         $orderinfo['company']['custom1'] = $order[0]['Isp']['custom1'];
         $orderinfo['company']['custom2'] = $order[0]['Isp']['custom2'];
         $orderinfo['company']['custom3'] = $order[0]['Isp']['custom3'];
         if ($order[0]['status_id'] == Statuses::id("tobepaid", "orders")) {
             // To be payed
             $orderinfo['ribbon']['text'] = $translator->translate("To be Paid");
             $orderinfo['ribbon']['color'] = "#D60000";
             $orderinfo['ribbon']['border-color'] = "#BD0000";
         } elseif ($order[0]['status_id'] == Statuses::id("complete", "orders")) {
             // Complete
             $orderinfo['ribbon']['text'] = $translator->translate("Paid");
             $orderinfo['ribbon']['color'] = "#009926";
             $orderinfo['ribbon']['border-color'] = "#00661A";
         } else {
             $orderinfo['ribbon']['text'] = $translator->translate(Statuses::getLabel($order[0]['status_id']));
             $orderinfo['ribbon']['color'] = "#FFCC33";
             $orderinfo['ribbon']['border-color'] = "#E6AC00";
         }
         $orderinfo['subtotal'] = $order[0]['total'];
         $orderinfo['grandtotal'] = $order[0]['grandtotal'];
         $orderinfo['vat'] = $order[0]['vat'];
         $orderinfo['delivery'] = 0;
         $database['records'] = $orderinfo;
         foreach ($order[0]['OrdersItems'] as $item) {
             $price = $item['price'] * $item['quantity'] + $item['setupfee'];
             $tax = Taxes::getTaxbyProductID($item['product_id']);
             if ($tax['percentage'] > 0) {
                 $rowtotal = $price * (100 + $tax['percentage']) / 100;
             } else {
                 $rowtotal = $price;
             }
             if (!$isTaxFree && !$isVATFree) {
                 $taxes = Taxes::getTaxbyProductID($item['product_id']);
                 if (!empty($taxes['percentage'])) {
                     $taxpercent = $taxes['percentage'];
                 }
             }
             if (!empty($item['discount'])) {
                 $item['discount'] = $item['discount'] . "%";
             }
             $database['records'][] = array($item['Products']['sku'], $item['description'], $item['quantity'], $translator->translate('nr'), $item['price'], $item['discount'], $item['setupfee'], $taxpercent, $rowtotal);
         }
         if (isset($order[0])) {
             $pdf->CreatePDF($database, $filename, $show, $path, $force);
             // Execute a custom event
             self::events()->trigger('orders_pdf_created', "Orders", array('file' => "{$path}/{$filename}"));
             return $path . $filename;
         }
     }
     return false;
 }