function toDecimal($amount, $ISOCode = NULL)
 {
     if (is_float($amount)) {
         return $amount;
     }
     if (strrpos($amount, '.') > strrpos($amount, ',')) {
         $amount = str_replace(',', '', $amount);
         $amount = str_replace('.', ',', $amount);
     }
     if (is_null($ISOCode)) {
         $ISOCode = $this->defaultISOCode;
     }
     return parent::toDecimal($amount, $ISOCode);
 }
Exemple #2
0
 public function printAcknowledgement($status = 'generate')
 {
     // set the models
     $order = $this->_uses[$this->modeltype];
     $order->load($this->_data['id']);
     // set type / name depending on the order type
     if ($order->type == 'Q') {
         $document_type = 'Quote';
         $document_name = 'SQ';
         $report_definition = 'SOQuote';
     } else {
         $document_type = 'Order Acknowledgement';
         $document_name = 'SOack';
         $report_definition = 'SOacknowledgement';
     }
     // build options array
     $options = array('type' => array('pdf' => '', 'xml' => ''), 'output' => array('print' => '', 'save' => '', 'email' => '', 'view' => ''), 'filename' => $document_name . $order->order_number, 'report' => $report_definition);
     if (strtolower($status) == 'dialog') {
         // show the main dialog
         // pick up the options from above, use these to shape the dialog
         return $options;
     }
     /* generate document */
     // set the extra array
     $extra = array();
     // get the title
     $extra['title'] = 'SALES ' . strtoupper($document_type);
     // get company_address address
     $company_address = array('name' => $this->getCompanyName());
     $company_address += $this->formatAddress($this->getCompanyAddress());
     $extra['company_address'] = $company_address;
     // get the company details
     $extra['company_details'] = $this->getCompanyDetails();
     // get customer address
     $customer_address = array('title' => 'Customer Address:', 'customer' => $order->customer);
     $customer = $this->getCustomer($order->slmaster_id);
     $tax_status = DataObjectFactory::Factory('TaxStatus');
     $tax_status->load($customer->tax_status_id);
     $extra['show_vat'] = $tax_status->apply_tax;
     if (!is_null($order->person_id)) {
         $names = explode(',', $order->person);
         $customer_address += array('person' => $names[1] . ' ' . $names[0]);
     }
     $customer_address += $this->formatAddress($order->getInvoiceAddress());
     $extra['customer_address'] = $customer_address;
     $extra['customer_number'] = $customer->accountnumber();
     $extra['price_type'] = $order->customer->so_price_type;
     // get delivery address
     $delivery_address = array('title' => 'Delivery Address:', 'customer' => $order->customer);
     $delivery_address += $this->formatAddress($order->getDeliveryAddress());
     $extra['delivery_address'] = $delivery_address;
     // get order details
     $order_details = array();
     $order_details[]['line'] = array('label' => 'Your Reference:', 'value' => $order->ext_reference);
     $order_details[]['line'] = array('label' => 'Order Date:', 'value' => un_fix_date($order->order_date));
     $order_details[]['line'] = array('label' => 'Our Order Number: ', 'value' => $order->order_number);
     $order_details[]['line'] = array('label' => 'Due Date: ', 'value' => un_fix_date($order->due_date));
     $extra['order_details'] = $order_details;
     // Set variables for invoice values
     $vat_total = 0;
     $gross_total = 0;
     // Calculate net + vat for each item on order
     $payment_term = DataObjectFactory::Factory('PaymentTerm');
     $payment_term->load($order->customer->payment_term_id);
     foreach ($order->lines as $orderlines) {
         // tax (in the UK at least) is dependent on the tax_rate of the item, and the tax status of the customer.
         // this function is a wrapper to a call to a config-dependent method
         // $tax_percentage=calc_tax_percentage($orderlines->tax_rate_id,$customer->tax_status_id,$orderlines->net_value);
         // tax_value is the tax percentage of the net value
         // $tax_total=trunc(bcmul($orderlines->net_value,$tax_percentage,4),2);
         $tax_total = $orderlines->calcTax($order->customer->tax_status_id, $payment_term);
         // Construct totals for generic info
         $vat_total = bcadd($vat_total, $tax_total);
         $line_gross = bcadd($orderlines->net_value, $tax_total);
         $gross_total = bcadd($line_gross, $gross_total);
         $orderlines->setAdditional('vat_value', 'numeric');
         $orderlines->vat_value = $tax_total;
         $orderlines->setAdditional('gross_value', 'numeric');
         $orderlines->gross_value = $line_gross;
         // $extra['lines'][] = $orderlines;
     }
     $currency = new CurrencyFormatter($order->currency_id);
     $extra['order_totals']['VAT'] = $currency->format($vat_total);
     $extra['order_totals']['gross'] = $currency->format($gross_total);
     // generate the xml and add it to the options array
     $options['xmlSource'] = $this->generateXML(array('model' => $order, 'relationship_whitelist' => array('lines'), 'extra' => $extra));
     // execute the print output function, echo the returned json for jquery
     echo $this->constructOutput($this->_data['print'], $options);
     exit;
 }