示例#1
0
 /**
  * Get the price of the product
  * 
  * If there's a refund subtrack to the price (20130409)
  * @param integer $productid
  * @param float   $refund
  */
 public static function getPrices($productid, $refund = false)
 {
     $prices = array();
     if (is_numeric($productid)) {
         $product = self::getAllInfo($productid);
         // Get the tax percentage
         $tax = Taxes::getTaxbyProductID($productid);
         if (!empty($product)) {
             if (!empty($product['price_1']) && $product['price_1'] > 0) {
                 if ($refund !== false) {
                     $priceToPayWithRefund = $product['price_1'] - $refund;
                     if ($priceToPayWithRefund < 0) {
                         $product['price_1'] = $priceToPayWithRefund;
                     }
                 }
                 // Taxes calculation
                 if (!empty($tax['percentage']) && is_numeric($tax['percentage'])) {
                     $taxincluded = $product['price_1'] * ($tax['percentage'] + 100) / 100;
                 } else {
                     $taxincluded = $product['price_1'];
                 }
                 return array('type' => 'flat', 'value' => $product['price_1'], 'taxincluded' => $taxincluded, 'taxes' => $tax);
             } else {
                 // Get the price min & max interval tranches
                 $tranches = ProductsTranches::getMinMaxTranches($productid);
                 if (!empty($tranches[1])) {
                     // Refund calculation price
                     if ($refund !== false) {
                         $idBillingCircle = $tranches[0]['BillingCycle']['billing_cycle_id'];
                         $monthBilling = BillingCycle::getMonthsNumber($idBillingCircle);
                         if ($monthBilling > 0) {
                             $priceToPay = $tranches[0]['price'] * $monthBilling;
                             $priceToPayWithRefund = $priceToPay - $refund;
                             if ($priceToPayWithRefund < 0) {
                                 $priceToPayWithRefund = $priceToPay;
                             }
                             $tranches[0]['price'] = round($priceToPayWithRefund / $monthBilling, 2);
                         } else {
                             $priceToPayWithRefund = $tranches[0]['price'] - $refund;
                             if ($priceToPayWithRefund > 0) {
                                 $tranches[0]['price'] = $priceToPayWithRefund;
                             }
                         }
                         $idBillingCircle = $tranches[1]['BillingCycle']['billing_cycle_id'];
                         $monthBilling = BillingCycle::getMonthsNumber($idBillingCircle);
                         if ($monthBilling > 0) {
                             $priceToPay = $tranches[1]['price'] * $monthBilling;
                             $priceToPayWithRefund = $priceToPay - $refund;
                             if ($priceToPayWithRefund < 0) {
                                 $priceToPayWithRefund = $priceToPay;
                             }
                             $tranches[1]['price'] = round($priceToPayWithRefund / $monthBilling, 2);
                         } else {
                             $priceToPayWithRefund = $tranches[1]['price'] - $refund;
                             if ($priceToPayWithRefund > 0) {
                                 $tranches[1]['price'] = $priceToPayWithRefund;
                             }
                         }
                     }
                     // Taxes calculation
                     if (!empty($tax['percentage']) && is_numeric($tax['percentage'])) {
                         $minvaluewithtaxes = $tranches[0]['price'] * ($tax['percentage'] + 100) / 100;
                         $maxvaluewithtaxes = $tranches[1]['price'] * ($tax['percentage'] + 100) / 100;
                     } else {
                         $minvaluewithtaxes = $tranches[0]['price'];
                         $maxvaluewithtaxes = $tranches[1]['price'];
                     }
                     $discount = floatval($tranches[1]['price']) - floatval($tranches[0]['price']);
                     $minvalue = $tranches[0]['price'];
                     $maxvalue = $tranches[1]['price'];
                     $data = array('type' => 'multiple', 'measurement' => $tranches[0]['measurement'], 'tranches' => $tranches, 'minvalue' => $minvalue, 'maxvalue' => $maxvalue, 'minvaluewithtaxes' => $minvaluewithtaxes, 'maxvaluewithtaxes' => $maxvaluewithtaxes, 'discount' => $discount, 'taxes' => $tax);
                     return $data;
                 } elseif (!empty($tranches['price'])) {
                     // Taxes calculation
                     if ($refund !== false) {
                         $priceToPayWithRefund = $tranches['price'] - $refund;
                         if ($priceToPayWithRefund < 0) {
                             $tranches['price'] = $priceToPayWithRefund;
                         }
                     }
                     if (!empty($tax['percentage']) && is_numeric($tax['percentage'])) {
                         $minvaluewithtaxes = $tranches['price'] * ($tax['percentage'] + 100) / 100;
                     } else {
                         $minvaluewithtaxes = $tranches['price'];
                     }
                     $price = $tranches['price'];
                     $data = array('type' => 'multiple', 'measurement' => $tranches['measurement'], 'minvalue' => $price, 'maxvalue' => $price, 'taxes' => $tax, 'minvaluewithtaxes' => $minvaluewithtaxes, 'maxvaluewithtaxes' => 0, 'discount' => 0);
                     return $data;
                 }
             }
         }
     }
     return array('type' => 'flat', 'value' => 0, 'taxincluded' => 0, 'taxes' => 0);
 }
示例#2
0
 /**
  * saveAll
  * Save all the data 
  * @param $params
  * @return Boolean
  */
 public static function saveAll($id, $params)
 {
     $date_end = null;
     if (!is_array($params)) {
         return false;
     }
     $details = Doctrine::getTable('OrdersItems')->find($id);
     // Generic price setting
     $rowtotal = $params['price'];
     $vat = null;
     $percentage = null;
     // Get the taxes applied
     $tax = Taxes::getTaxbyProductID($params['product_id']);
     if ($tax['percentage'] > 0) {
         $rowtotal = $params['price'] * (100 + $tax['percentage']) / 100;
         $vat = $params['price'] * $tax['percentage'] / 100;
         $percentage = $tax['percentage'];
     } else {
         if (!empty($params['parameters'])) {
             // it is a domain
             $domainparams = json_decode($params['parameters'], true);
             if (!empty($domainparams['domain']['tld'])) {
                 $tax = Taxes::getTaxbyTldID($domainparams['domain']['tld']);
                 if ($tax['percentage'] > 0) {
                     $vat = $params['price'] * $tax['percentage'] / 100;
                     $percentage = $tax['percentage'];
                     $rowtotal = $params['price'] * (100 + $tax['percentage']) / 100;
                 }
             }
         }
     }
     if (!empty($params['billing_cycle_id'])) {
         $months = BillingCycle::getMonthsNumber($params['billing_cycle_id']);
     }
     if ($months > 0 && is_numeric($params['product_id']) && $params['product_id'] > 0) {
         // only for the product and services. Domains excluded
         $rowtotal = $rowtotal * $months;
     }
     $params['date_end'] = Shineisp_Commons_Utilities::add_date($params['date_start'], null, $months);
     $details->quantity = $params['quantity'];
     $details->date_start = Shineisp_Commons_Utilities::formatDateIn($params['date_start']);
     $details->date_end = Shineisp_Commons_Utilities::formatDateIn($params['date_end']);
     $details->billing_cycle_id = !empty($params['billing_cycle_id']) ? $params['billing_cycle_id'] : null;
     $details->price = $params['price'];
     $details->vat = $vat;
     $details->percentage = $percentage;
     $details->cost = $params['cost'];
     $details->product_id = is_numeric($params['product_id']) && $params['product_id'] > 0 ? $params['product_id'] : NULL;
     $details->setupfee = $params['setupfee'];
     $details->discount = $params['discount'];
     $details->subtotal = $rowtotal * $params['quantity'];
     $details->status_id = $params['status_id'];
     $details->description = $params['description'];
     $details->parameters = $params['parameters'];
     if ($details->trySave()) {
         OrdersItems::setAutorenew($id, $params['autorenew']);
         // Remove all domains
         OrdersItemsDomains::removeAllDomains($id);
         if ($params['domains_selected']) {
             foreach ($params['domains_selected'] as $domain) {
                 OrdersItemsDomains::addDomain($details['order_id'], $domain);
             }
         }
         return true;
     }
     return false;
 }
示例#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;
 }