function buildSummaryModel() { if (isset($this->focus->column_fields['currency_id'])) { $currencyInfo = getCurrencyInfo($this->focus->column_fields['currency_id']); $currency = $currencyInfo['code']; } else { $currency = 'RUB'; } $associated_products = $this->associated_products; $final_details = $associated_products[1]['final_details']; $summaryModel = new Vtiger_PDF_Model(); $netTotal = $netTotalGoods = $netTotalServices = $discount = $handlingCharges = $handlingTaxes = 0; $adjustment = $grandTotal = 0; $productLineItemIndex = 0; $sh_tax_percent = 0; foreach ($associated_products as $productLineItem) { ++$productLineItemIndex; $netTotal += $productLineItem["netPrice{$productLineItemIndex}"]; if ($productLineItem["entityType{$productLineItemIndex}"] == 'Products') { $netTotalGoods += $productLineItem["netPrice{$productLineItemIndex}"]; } if ($productLineItem["entityType{$productLineItemIndex}"] == 'Services') { $netTotalServices += $productLineItem["netPrice{$productLineItemIndex}"]; } } $summaryModel->set("summaryNetTotal", $this->formatPrice($netTotal)); $summaryModel->set("summaryNetTotalGoods", $this->formatPrice($netTotalGoods)); $summaryModel->set("summaryNetTotalServices", $this->formatPrice($netTotalServices)); $discount_amount = $final_details["discount_amount_final"]; $discount_percent = $final_details["discount_percentage_final"]; $discount = 0.0; $discountGoods = 0.0; $discountServices = 0.0; if (!empty($discount_amount)) { $discount = $discount_amount; $discountGoods = $discount_amount; $discountServices = $discount_amount; } if (!empty($discount_percent)) { $discount = $discount_percent * $final_details["hdnSubTotal"] / 100; $discountGoods = $discount_percent * $netTotalGoods / 100; $discountServices = $discount_percent * $netTotalServices / 100; } $summaryModel->set("summaryDiscount", $this->formatPrice($discount)); $summaryModel->set("summaryDiscountGoods", $this->formatPrice($discountGoods)); $summaryModel->set("summaryDiscountServices", $this->formatPrice($discountServices)); $group_total_tax_percent = '0.00'; $overall_tax = 0; $overall_tax_goods = 0; $overall_tax_services = 0; //To calculate the group tax amount if ($final_details['taxtype'] == 'group') { $group_tax_details = $final_details['taxes']; for ($i = 0; $i < count($group_tax_details); $i++) { $group_total_tax_percent += $group_tax_details[$i]['percentage']; } $summaryModel->set("summaryTax", $this->formatPrice($final_details['tax_totalamount'])); $summaryModel->set("summaryTaxLiteral", $this->num2str($final_details['tax_totalamount'], false, $currency)); $summaryModel->set("summaryTaxPercent", $group_total_tax_percent); $overall_tax += $final_details['tax_totalamount']; $summaryModel->set("summaryTaxGoods", $this->formatPrice(($netTotalGoods - $discountGoods) * $group_total_tax_percent / 100.0)); $summaryModel->set("summaryTaxGoodsLiteral", $this->num2str(($netTotalGoods - $discountGoods) * $group_total_tax_percent / 100.0, false, $currency)); $summaryModel->set("summaryTaxGoodsPercent", $group_total_tax_percent); $overall_tax_goods += ($netTotalGoods - $discountGoods) * $group_total_tax_percent / 100.0; $summaryModel->set("summaryTaxServices", $this->formatPrice(($netTotalServices - $discountServices) * $group_total_tax_percent / 100.0)); $summaryModel->set("summaryTaxServicesLiteral", $this->num2str(($netTotalServices - $discountServices) * $group_total_tax_percent / 100.0, false, $currency)); $summaryModel->set("summaryTaxServicesPercent", $group_total_tax_percent); $overall_tax_services += ($netTotalServices - $discountServices) * $group_total_tax_percent / 100.0; } else { if ($final_details['taxtype'] == 'group_tax_inc') { $group_tax_details = $final_details['taxes']; for ($i = 0; $i < count($group_tax_details); $i++) { $group_total_tax_percent += $group_tax_details[$i]['percentage']; } $summaryModel->set("summaryTax", $this->formatPrice($final_details['tax_totalamount'])); $summaryModel->set("summaryTaxLiteral", $this->num2str($final_details['tax_totalamount'], false, $currency)); $summaryModel->set("summaryTaxPercent", $group_total_tax_percent); $overall_tax += $final_details['tax_totalamount']; $summaryModel->set("summaryNetTotal", $this->formatPrice($netTotal - $final_details['tax_totalamount'])); $summaryModel->set("summaryTaxGoods", $this->formatPrice(($netTotalGoods - $discountGoods) * $group_total_tax_percent / (100.0 + $group_total_tax_percent))); $summaryModel->set("summaryTaxGoodsLiteral", $this->num2str(($netTotalGoods - $discountGoods) * $group_total_tax_percent / (100.0 + $group_total_tax_percent), false, $currency)); $summaryModel->set("summaryTaxGoodsPercent", $group_total_tax_percent); $overall_tax_goods += ($netTotalGoods - $discountGoods) * $group_total_tax_percent / (100.0 + $group_total_tax_percent); $summaryModel->set("summaryNetTotalGoods", $this->formatPrice($netTotalGoods - ($netTotalGoods - $discountGoods) * $group_total_tax_percent / (100.0 + $group_total_tax_percent))); $summaryModel->set("summaryTaxServices", $this->formatPrice(($netTotalServices - $discountServices) * $group_total_tax_percent / (100.0 + $group_total_tax_percent))); $summaryModel->set("summaryTaxServicesLiteral", $this->num2str(($netTotalServices - $discountServices) * $group_total_tax_percent / (100.0 + $group_total_tax_percent), false, $currency)); $summaryModel->set("summaryTaxServicesPercent", $group_total_tax_percent); $overall_tax_services += ($netTotalServices - $discountServices) * $group_total_tax_percent / (100.0 + $group_total_tax_percent); $summaryModel->set("summaryNetTotalServices", $this->formatPrice($netTotalServices - ($netTotalServices - $discountServices) * $group_total_tax_percent / (100.0 + $group_total_tax_percent))); } else { $summaryModel->set("summaryTax", $this->formatPrice($this->totaltaxes)); $summaryModel->set("summaryTaxLiteral", $this->num2str($this->totaltaxes, false, $currency)); if ($netTotal > 0) { $summaryModel->set("summaryTaxPercent", $this->totaltaxes / $netTotal * 100); } else { $summaryModel->set("summaryTaxPercent", 0); } $overall_tax += $this->totaltaxes; $summaryModel->set("summaryTaxGoods", $this->formatPrice($this->totaltaxesGoods)); $summaryModel->set("summaryTaxGoodsLiteral", $this->num2str($this->totaltaxesGoods, false, $currency)); if ($netTotalGoods > 0) { $summaryModel->set("summaryTaxGoodsPercent", $this->totaltaxesGoods / $netTotalGoods * 100); } else { $summaryModel->set("summaryTaxGoodsPercent", 0); } $overall_tax_goods += $this->totaltaxesGoods; $summaryModel->set("summaryTaxServices", $this->formatPrice($this->totaltaxesServices)); $summaryModel->set("summaryTaxServicesLiteral", $this->num2str($this->totaltaxesServices, false, $currency)); if ($netTotalServices > 0) { $summaryModel->set("summaryTaxServicesPercent", $this->totaltaxesServices / $netTotalServices * 100); } else { $summaryModel->set("summaryTaxServicesPercent", 0); } $overall_tax_services += $this->totaltaxesServices; } } //Shipping & Handling taxes $sh_tax_details = $final_details['sh_taxes']; for ($i = 0; $i < count($sh_tax_details); $i++) { $sh_tax_percent = $sh_tax_percent + $sh_tax_details[$i]['percentage']; } //obtain the Currency Symbol $currencySymbol = $this->buildCurrencySymbol(); $summaryModel->set("summaryShipping", $this->formatPrice($final_details['shipping_handling_charge'])); $summaryModel->set("summaryShippingTax", $this->formatPrice($final_details['shtax_totalamount'])); $summaryModel->set("summaryShippingTaxPercent", $sh_tax_percent); $summaryModel->set("summaryAdjustment", $this->formatPrice($final_details['adjustment'])); $summaryModel->set("summaryGrandTotal", $this->formatPrice($final_details['grandTotal'])); // TODO add currency string $summaryModel->set("summaryGrandTotalLiteral", $this->num2str($final_details['grandTotal'], false, $currency)); $overall_tax += $final_details['shtax_totalamount']; $overall_tax_goods += $final_details['shtax_totalamount']; $summaryModel->set("summaryOverallTax", $this->formatPrice(round($overall_tax))); $summaryModel->set("summaryOverallTaxLiteral", $this->num2str(round($overall_tax), false, $currency)); $summaryModel->set("summaryOverallTaxGoods", $this->formatPrice(round($overall_tax_goods))); $summaryModel->set("summaryOverallTaxGoodsLiteral", $this->num2str(round($overall_tax_goods), false, $currency)); $summaryModel->set("summaryOverallTaxServices", $this->formatPrice(round($overall_tax_services))); $summaryModel->set("summaryOverallTaxServicesLiteral", $this->num2str(round($overall_tax_services), false, $currency)); if ($final_details['taxtype'] == 'group_tax_inc') { $summaryModel->set("summaryGrandTotalGoods", $this->formatPrice($netTotalGoods - $discountGoods + $final_details['shipping_handling_charge'] + $final_details['adjustment'])); $summaryModel->set("summaryGrandTotalGoodsLiteral", $this->num2str($netTotalGoods - $discountGoods + $final_details['shipping_handling_charge'] + $final_details['adjustment'], false, $currency)); $summaryModel->set("summaryGrandTotalServices", $this->formatPrice($netTotalServices - $discountServices + $final_details['adjustment'])); $summaryModel->set("summaryGrandTotalServicesLiteral", $this->num2str($netTotalServices - $discountServices + $final_details['adjustment'], false, $currency)); } else { $summaryModel->set("summaryGrandTotalGoods", $this->formatPrice($netTotalGoods - $discountGoods + $overall_tax_goods + $final_details['shipping_handling_charge'] + $final_details['adjustment'])); $summaryModel->set("summaryGrandTotalGoodsLiteral", $this->num2str($netTotalGoods - $discountGoods + $overall_tax_goods + $final_details['shipping_handling_charge'] + $final_details['adjustment'], false, $currency)); $summaryModel->set("summaryGrandTotalServices", $this->formatPrice($netTotalServices - $discountServices + $overall_tax_services + $final_details['adjustment'])); $summaryModel->set("summaryGrandTotalServicesLiteral", $this->num2str($netTotalServices - $discountServices + $overall_tax_services + $final_details['adjustment'], false, $currency)); } return $summaryModel; }
protected function generateEntityModel($entity, $module, $prefix, $model) { // Get only active field information $cachedModuleFields = VTCacheUtils::lookupFieldInfo_Module($module); if (isset($this->focus->column_fields['currency_id'])) { $currencyInfo = getCurrencyInfo($this->focus->column_fields['currency_id']); $currency = $currencyInfo['code']; } else { $currency = 'RUB'; } if ($cachedModuleFields) { foreach ($cachedModuleFields as $fieldname => $fieldinfo) { $fieldname = $fieldinfo['fieldname']; $type = explode('~', $fieldinfo['typeofdata']); $uitype = $fieldinfo['uitype']; if ($uitype == 10 && !empty($entity->column_fields[$fieldname])) { $entityid = $entity->column_fields[$fieldname]; $entityType = getSalesEntityType($entityid); $recordName = array_values(getEntityName($entityType, $entityid)); $recordName = $recordName[0]; $model->set($prefix . $fieldname, $recordName); } else { if ($uitype == 117) { $currencyInfo = getCurrencyInfo($entity->column_fields[$fieldname]); $model->set($prefix . $fieldname, getTranslatedString($currencyInfo['name'], $module)); } else { switch ($type[0]) { case 'N': case 'NN': $model->set($prefix . $fieldname, $this->formatPrice($entity->column_fields[$fieldname])); $model->set($prefix . $fieldname . '_literal', $this->num2str($entity->column_fields[$fieldname], false, $currency)); $model->set(strtoupper($prefix) . strtoupper(str_replace(" ", "", $fieldinfo['fieldlabel'])) . '_LITERAL', $model->get($prefix . $fieldname . '_literal')); $model->set(getTranslatedString(strtoupper($prefix), $module) . str_replace(" ", "", getTranslatedString($fieldinfo['fieldlabel'], $module)) . getTranslatedString('_literal'), $model->get($prefix . $fieldname . '_literal')); break; case 'D': $model->set($prefix . $fieldname, $this->literalDate($entity->column_fields[$fieldname])); $model->set($prefix . $fieldname . '_short', $this->shortDate($entity->column_fields[$fieldname])); $model->set($prefix . $fieldname . '_mmyyyy', $this->mmyyyyDate($entity->column_fields[$fieldname])); $model->set(strtoupper($prefix) . strtoupper(str_replace(" ", "", $fieldinfo['fieldlabel'])) . '_SHORT', $model->get($prefix . $fieldname . '_short')); $model->set(getTranslatedString(strtoupper($prefix), $module) . str_replace(" ", "", getTranslatedString($fieldinfo['fieldlabel'], $module)) . getTranslatedString('_short'), $model->get($prefix . $fieldname . '_short')); break; case 'C': if ($entity->column_fields[$fieldname] == 0) { $model->set($prefix . $fieldname, 'Нет'); } else { $model->set($prefix . $fieldname, 'Да'); } break; case 'V': $model->set($prefix . $fieldname, nl2br($entity->column_fields[$fieldname])); $model->set($prefix . $fieldname . '_translated', nl2br(getTranslatedString($entity->column_fields[$fieldname], $module))); break; default: $model->set($prefix . $fieldname, $entity->column_fields[$fieldname]); break; } } } // Add human-readable variables $model->set(strtoupper($prefix) . strtoupper(str_replace(" ", "", $fieldinfo['fieldlabel'])), $model->get($prefix . $fieldname)); $model->set(getTranslatedString(strtoupper($prefix), $module) . str_replace(" ", "", getTranslatedString($fieldinfo['fieldlabel'], $module)), $model->get($prefix . $fieldname)); } } }
require_once BASE_PATH . '/assets/includes/language.inc.php'; require_once BASE_PATH . '/assets/includes/cart.inc.php'; require_once BASE_PATH . '/assets/includes/affiliate.inc.php'; require_once BASE_PATH . '/assets/includes/header.inc.php'; require_once BASE_PATH . '/assets/includes/errors.php'; require_once BASE_PATH . '/assets/classes/invoicetools.php'; require_once BASE_PATH . '/assets/includes/errors.php'; if (!$billID) { // Make sure this exists before going on die('No billID was passed. Cannot proceed.'); } $gatewayMode = "publicForm"; /* * Get currency info from db */ $currency = getCurrencyInfo($config['settings']['defaultcur']); $invoice = new invoiceTools(); $billInfo = $invoice->getBillDetails($billID); // Get the bill info using the passed bill ID $invoiceInfo = $invoice->getInvoiceDetailsViaBillDBID($billInfo['bill_id']); // Get invoice details // xxxxxx Check if this is a membership and if so then check to see if tax needs to be added $parms['noDefault'] = true; // Do not allow defaults just in case $cartInfo['orderNumber'] = $invoiceInfo['invoice_number']; $uniqueOrderID = "bill-{$billID}"; $cartTotals['subtotalMinusDiscounts'] = $invoiceInfo['total'] * 1; // Round it $cartTotals['taxTotal'] = 0; $cartTotals['shippingTotal'] = 0; $cartTotals['cartGrandTotal'] = $invoiceInfo['total'] * 1;
// Add updated local tax b to session $_SESSION['cartTotalsSession']['taxCLocal'] = getCorrectedPrice($recalcTaxC, $parms); // Add updated local tax c to session $_SESSION['cartTotalsSession']['shippingTotal'] = $shippingDetails['total']; // Add shipping total to cartTotalsSession $_SESSION['cartTotalsSession']['cartGrandTotalLocal'] = getCorrectedPrice($cartGrandTotal, $parms); $_SESSION['cartTotalsSession']['shippingTotalLocal']['display'] = $shippingDetails['price']['display']; //$_SESSION['cartTotalsSession']['shippingTotalLocal'] = getCorrectedPrice($shippingDetails['price']['raw'],$parms); //echo $shippingDetails['price']['display']; if ($_SESSION['cartTotalsSession']['shippingRequired']) { // Create step numbers depending on if shipping is needed or not $stepNumber = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4); } else { $stepNumber = array('a' => 1, 'b' => 0, 'c' => 2, 'd' => 3); } $currency = getCurrencyInfo($_SESSION['selectedCurrencySession']); // Get the details of the currently selected currency //echo 'name: '.$_SESSION['shippingAddressSession']['name']; exit; // Update invoice with shipping and billing info if known mysqli_query($db, "\r\n\t\tUPDATE {$dbinfo[pre]}invoices SET \r\n\t\tinvoice_mem_id='{$_SESSION[member][mem_id]}',\r\n\t\texchange_rate='{$currency[exchange_rate]}',\r\n\t\ttotal='{$cartGrandTotal}',\r\n\t\tsubtotal='{$_SESSION[cartTotalsSession][priceSubTotal]}',\r\n\t\ttaxa_cost='{$recalcTaxA}',\r\n\t\ttaxb_cost='{$recalcTaxB}',\r\n\t\ttaxc_cost='{$recalcTaxC}',\r\n\t\ttax_ratea='{$_SESSION[tax][tax_a_default]}',\r\n\t\ttax_rateb='{$_SESSION[tax][tax_b_default]}',\r\n\t\ttax_ratec='{$_SESSION[tax][tax_c_default]}',\r\n\t\tship_id='{$_SESSION[cartInfoSession][selectedShippingMethodID]}',\r\n\t\tshipping_cost='{$shippingDetails[total]}',\r\n\t\tship_name='{$_SESSION[shippingAddressSession][name]}',\r\n\t\tship_address='{$_SESSION[shippingAddressSession][address]}',\r\n\t\tship_address2='{$_SESSION[shippingAddressSession][address2]}',\r\n\t\tship_city='{$_SESSION[shippingAddressSession][city]}',\r\n\t\tship_state='{$_SESSION[shippingAddressSession][stateID]}',\r\n\t\tship_country='{$_SESSION[shippingAddressSession][countryID]}',\r\n\t\tship_zip='{$_SESSION[shippingAddressSession][postalCode]}',\r\n\t\tship_phone='{$_SESSION[shippingAddressSession][phone]}',\r\n\t\tship_email='{$_SESSION[shippingAddressSession][email]}',\r\n\t\tbill_name='{$_SESSION[billingAddressSession][name]}',\r\n\t\tbill_address='{$_SESSION[billingAddressSession][address]}',\r\n\t\tbill_address2='{$_SESSION[billingAddressSession][address2]}',\r\n\t\tbill_city='{$_SESSION[billingAddressSession][city]}',\r\n\t\tbill_state='{$_SESSION[billingAddressSession][stateID]}',\r\n\t\tbill_country='{$_SESSION[billingAddressSession][countryID]}',\r\n\t\tbill_zip='{$_SESSION[billingAddressSession][postalCode]}',\r\n\t\tbill_phone='{$_SESSION[billingAddressSession][phone]}',\r\n\t\tbill_email='{$_SESSION[billingAddressSession][email]}',\r\n\t\tshippable='{$_SESSION[cartTotalsSession][shippingRequired]}',\r\n\t\tshipping_summary='{$_SESSION[cartTotalsSession][shippingSummary]}'\r\n\t\tWHERE invoice_id = '{$_SESSION[cartInfoSession][invoiceID]}'\r\n\t"); mysqli_query($db, "UPDATE {$dbinfo[pre]}orders SET member_id='{$_SESSION[member][mem_id]}',checkout_lang='{$_SESSION[member][language]}' WHERE uorder_id = '{$_SESSION[uniqueOrderID]}'"); // Upade orders db try { $invoice = new invoiceTools(); $invoice->setInvoiceID($_SESSION['cartInfoSession']['invoiceID']); $invoiceItemsCount = $invoice->queryInvoiceItems(); // Number of invoice items total $digitalInvoiceItems = $invoice->getDigitalItems(); $physicalInvoiceItems = $invoice->getPhysicalItems(); } catch (Exception $e) { echo $e->getMessage();