コード例 #1
0
ファイル: Orders.php プロジェクト: kokkez/shineisp
 /**
  * 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;
 }
コード例 #2
0
ファイル: CartController.php プロジェクト: kokkez/shineisp
 public function summaryAction()
 {
     $session = new Zend_Session_Namespace('Default');
     $request = $this->getRequest();
     $this->getHelper('layout')->setLayout('1column');
     if (empty($session->cart) || $session->cart->isEmpty()) {
         $this->_helper->redirector('index', 'index', 'default', array('mex' => "Cart is empty"));
     }
     if (!$session->cart->getCustomer()) {
         $this->_helper->redirector('contacts');
     }
     // Get the heading of the cart
     $cart_heading = $session->cart->getHeading();
     // Check if the user is VAT free
     $this->view->isVATFree = Customers::isVATFree($cart_heading['customer']['id']);
     // Update the cart totals
     $session->cart->update();
     // Send the cart information to the view
     $this->view->lastproduct = $session->lastproduct;
     $this->view->cart = $session->cart;
 }
コード例 #3
0
ファイル: Orders.php プロジェクト: kokkez/shineisp
 public function create($params)
 {
     $this->authenticate();
     $uuid = $params['uuid'];
     $customers = Customers::find($uuid);
     if (empty($customers)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'uuid' not valid");
         exit;
     }
     $trancheid = intval($params['trancheid']);
     $tranche = ProductsTranches::getTranchebyId($trancheid);
     if (empty($tranche)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'trancheid' not valid");
         exit;
     }
     #Check Products
     if (empty($params['products']) && !is_array($params['products'])) {
         throw new Shineisp_Api_Exceptions(400006, ":: not 'products' choose");
         exit;
     }
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $ttry = ProductsTranches::getTranchesBy_ProductId_BillingId($productid, $billingid);
         if (empty($ttry)) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'productid' or 'bilingid' not valid");
             exit;
         }
         $ttry = array_shift($ttry);
         if ($ttry['tranche_id'] != $trancheid) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'bilingid' not valid");
             exit;
         }
     }
     $id = $customers['customer_id'];
     $isVATFree = Customers::isVATFree($id);
     if ($params['status'] == "complete") {
         $status = Statuses::id('complete', 'orders');
     } else {
         $status = Statuses::id('tobepaid', 'orders');
     }
     $theOrder = Orders::create($customers['customer_id'], $status, $params['note']);
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $quantity = intval($product['quantity']);
         $p = Products::getAllInfo($productid);
         Orders::addItem($productid, $quantity, $billingid, $trancheid, $p['ProductsData'][0]['name'], array());
     }
     $orderID = $theOrder['order_id'];
     if ($params['sendemail'] == 1) {
         Orders::sendOrder($orderID);
     }
     $banks = Banks::find($params['payment'], "*", true);
     if (!empty($banks[0]['classname'])) {
         $class = $banks[0]['classname'];
         if (class_exists($class)) {
             // Get the payment form object
             $banks = Banks::findbyClassname($class);
             $gateway = new $class($orderID);
             $gateway->setFormHidden(true);
             $gateway->setRedirect(true);
             $gateway->setUrlOk($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($banks['classname']));
             $gateway->setUrlKo($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($banks['classname']));
             $gateway->setUrlCallback($_SERVER['HTTP_HOST'] . "/common/callback/gateway/" . md5($banks['classname']));
             return $gateway->CreateForm();
         }
     }
     throw new Shineisp_Api_Exceptions(400006, ":: bad request");
     exit;
 }
コード例 #4
0
ファイル: Cart.php プロジェクト: kokkez/shineisp
 /**
  * Get all the product data information from the database
  *
  * @return array
  */
 public function update()
 {
     if (!empty($this->items) && is_array($this->items)) {
         // Reset the subtotal
         $this->setGrandtotal(0);
         $this->setTaxes(0);
         $this->setSubtotal(0);
         $this->setSetupfee(0);
         if ($this->getCustomerId()) {
             $isVATFree = Customers::isVATFree($this->getCustomerId());
         } else {
             $isVATFree = false;
         }
         foreach ($this->items as $item) {
             $this->calcSubtotal($item, $isVATFree);
             $subtotals = $this->getSubtotal();
             $grandtotal = $this->getGrandtotal();
             $subtaxes = $this->getTaxes();
             $setupfee = $this->getSetupfee();
             $itemsubtot = $item->getSubtotals();
             $this->setSubtotal($subtotals + $itemsubtot['subtotal']);
             $this->setTaxes($subtaxes + $itemsubtot['taxes']);
             $this->setSetupfee($setupfee + $itemsubtot['setupfee']);
             $this->setGrandtotal($grandtotal + $itemsubtot['price'] + $itemsubtot['taxes']);
         }
     }
     return $this->items;
 }