public static function makeLine($data, $do, &$errors) { //net value is unit-price * quantity if (!isset($data['tax_value'])) { //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 $data['tax_percentage'] = calc_tax_percentage($data['tax_rate_id'], $data['tax_status_id'], $data['net_value']); $data['tax_value'] = round(bcmul($data['net_value'], $data['tax_percentage'], 4), 2); $data['tax_rate_percent'] = bcmul($data['tax_percentage'], 100); } else { $tax_rate = DataObjectFactory::Factory('TaxRate'); $tax_rate->load($data['tax_rate_id']); $data['tax_rate_percent'] = $tax_rate->percentage; } //gross value is net + tax; use bcadd to format the data $data['tax_value'] = bcadd($data['tax_value'], 0); $data['gross_value'] = bcadd($data['net_value'], $data['tax_value']); //then convert to the base currency if ($data['rate'] == 1) { $data['base_net_value'] = $data['net_value']; $data['base_tax_value'] = $data['tax_value']; $data['base_gross_value'] = $data['gross_value']; } else { $data['base_net_value'] = round(bcdiv($data['net_value'], $data['rate'], 4), 2); $data['base_tax_value'] = round(bcdiv($data['tax_value'], $data['rate'], 4), 2); $data['base_gross_value'] = round(bcadd($data['base_tax_value'], $data['base_net_value']), 2); } //and to the twin-currency $data['twin_net_value'] = round(bcmul($data['base_net_value'], $data['twin_rate'], 4), 2); $data['twin_tax_value'] = round(bcmul($data['base_tax_value'], $data['twin_rate'], 4), 2); $data['twin_gross_value'] = round(bcadd($data['twin_tax_value'], $data['twin_net_value']), 2); return DataObject::Factory($data, $errors, $do); }
public function sortOutValues($data) { //net value is unit-price * quantity $this->net_value = round(bcmul($this->sales_qty, $this->sales_price, 4), 2); //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($data['tax_rate_id'], $data['tax_status_id'], $this->net_value); $this->tax_percentage = $tax_percentage; //tax_value is the tax percentage of the net value $this->tax_value = trunc(bcmul($this->net_value, $tax_percentage), 2); }
public function calcTax($tax_status_id, $payment_term) { //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($this->tax_rate_id, $tax_status_id, $this->net_value); $settlement_discount = $payment_term->calcSettlementDiscount($this->net_value); $net_value = bcsub($this->net_value, $settlement_discount); //tax_value is the tax percentage of the net value return round(bcmul($net_value, $tax_percentage, 4), 2); }
function get_price($_productline_id = '', $_slmaster_id = '') { if (isset($this->_data['ajax'])) { if (!empty($this->_data['productline_id'])) { $_productline_id = $this->_data['productline_id']; } if (!empty($this->_data['slmaster_id'])) { $_slmaster_id = $this->_data['slmaster_id']; } } if (empty($_productline_id)) { $currency = ''; $product_price = ''; $discount_percent = ''; $discount_value = ''; $net_price = ''; $vat = ''; $gross = ''; } else { $productline = DataObjectFactory::Factory('SOProductline'); $productline->load($_productline_id); if ($productline->isLoaded()) { $currency = $productline->currency; $product_price = $productline->getGrossPrice(); $discount_percent = $productline->getPriceDiscount('', $_slmaster_id); $net_price = $productline->getPrice('', '', $_slmaster_id); $discount_value = bcsub($product_price, $net_price); if (empty($_slmaster_id)) { $_slmaster_id = $productline->slmaster_id; } if (!empty($_slmaster_id)) { $customer = DataObjectFactory::Factory('SLCustomer'); $customer->load($_slmaster_id); $tax_status_id = $customer->tax_status_id; } else { $tax_status_id = ''; } $tax_percentage = calc_tax_percentage($productline->product_detail->tax_rate_id, $tax_status_id, $net_price); $vat = bcadd(round($net_price * $tax_percentage, 2), 0); $gross = bcadd($net_price, $vat); } else { $net_price = 'Not Found'; } } $output['currency'] = array('data' => $currency, 'is_array' => false); $output['product_price'] = array('data' => $product_price, 'is_array' => false); $output['discount_percent'] = array('data' => $discount_percent, 'is_array' => false); $output['discount_value'] = array('data' => $discount_value, 'is_array' => false); $output['net_price'] = array('data' => $net_price, 'is_array' => false); $output['vat'] = array('data' => $vat, 'is_array' => false); $output['gross'] = array('data' => $gross, 'is_array' => false); if (isset($this->_data['ajax'])) { $this->view->set('data', $output); $this->setTemplateName('ajax_multiple'); } else { return $output; } }