function getProducts() { $numOfCurrencyDecimalPlaces = getCurrencyDecimalPlaces(); $relatedProducts = getAssociatedProducts($this->getModuleName(), $this->getEntity()); $productsCount = count($relatedProducts); //Updating Pre tax total $preTaxTotal = (double) $relatedProducts[1]['final_details']['hdnSubTotal'] + (double) $relatedProducts[1]['final_details']['shipping_handling_charge'] - (double) $relatedProducts[1]['final_details']['discountTotal_final']; $relatedProducts[1]['final_details']['preTaxTotal'] = number_format($preTaxTotal, $numOfCurrencyDecimalPlaces, '.', ''); //Updating Total After Discount $totalAfterDiscount = (double) $relatedProducts[1]['final_details']['hdnSubTotal'] - (double) $relatedProducts[1]['final_details']['discountTotal_final']; $relatedProducts[1]['final_details']['totalAfterDiscount'] = number_format($totalAfterDiscount, $numOfCurrencyDecimalPlaces, '.', ''); //Updating Tax details $taxtype = $relatedProducts[1]['final_details']['taxtype']; for ($i = 1; $i <= $productsCount; $i++) { $product = $relatedProducts[$i]; $productId = $product['hdnProductId' . $i]; $totalAfterDiscount = $product['totalAfterDiscount' . $i]; if ($taxtype == 'individual') { $taxDetails = getTaxDetailsForProduct($productId, 'all'); $taxCount = count($taxDetails); $taxTotal = '0'; for ($j = 0; $j < $taxCount; $j++) { $taxValue = $product['taxes'][$j]['percentage']; $taxAmount = $totalAfterDiscount * $taxValue / 100; $taxTotal = $taxTotal + $taxAmount; $relatedProducts[$i]['taxes'][$j]['amount'] = $taxAmount; $relatedProducts[$i]['taxTotal' . $i] = $taxTotal; } $netPrice = $totalAfterDiscount + $taxTotal; $relatedProducts[$i]['netPrice' . $i] = $netPrice; } } return $relatedProducts; }
function getProducts() { $relatedProducts = getAssociatedProducts($this->getModuleName(), $this->getEntity()); $relatedProducts[1]['final_details']['grandTotal'] = number_format($this->get('hdnGrandTotal'), getCurrencyDecimalPlaces(), '.', ''); $relatedProducts[1]['final_details']['total_purchase'] = number_format($this->get('total_purchase'), getCurrencyDecimalPlaces(), '.', ''); $relatedProducts[1]['final_details']['total_margin'] = number_format($this->get('total_margin'), getCurrencyDecimalPlaces(), '.', ''); $relatedProducts[1]['final_details']['total_marginp'] = number_format($this->get('total_marginp'), getCurrencyDecimalPlaces(), '.', ''); //Updating Pre tax total $preTaxTotal = (double) $relatedProducts[1]['final_details']['hdnSubTotal'] - (double) $relatedProducts[1]['final_details']['discountTotal_final']; $relatedProducts[1]['final_details']['preTaxTotal'] = number_format($preTaxTotal, getCurrencyDecimalPlaces(), '.', ''); //Updating Total After Discount $totalAfterDiscount = (double) $relatedProducts[1]['final_details']['hdnSubTotal'] - (double) $relatedProducts[1]['final_details']['discountTotal_final']; $relatedProducts[1]['final_details']['totalAfterDiscount'] = number_format($totalAfterDiscount, getCurrencyDecimalPlaces(), '.', ''); return $relatedProducts; }
/** Function to display the Products which are related to the PriceBook * @param string $query - query to get the list of products which are related to the current PriceBook * @param object $focus - PriceBook object which contains all the information of the current PriceBook * @param string $returnset - return_module, return_action and return_id which are sequenced with & to pass to the URL which is optional * return array $return_data which will be formed like array('header'=>$header,'entries'=>$entries_list) where as $header contains all the header columns and $entries_list will contain all the Product entries */ function getPriceBookRelatedProducts($query, $focus, $returnset = '') { global $log; $log->debug("Entering getPriceBookRelatedProducts(" . $query . "," . get_class($focus) . "," . $returnset . ") method ..."); global $adb; global $app_strings; global $mod_strings; global $current_language, $current_user; $current_module_strings = return_module_language($current_language, 'PriceBook'); $no_of_decimal_places = getCurrencyDecimalPlaces(); global $list_max_entries_per_page; global $urlPrefix; global $theme; $pricebook_id = vtlib_purify($_REQUEST['record']); $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $computeCount = $_REQUEST['withCount']; if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true || (bool) $computeCount == true) { $noofrows = $adb->query_result($adb->query(Vtiger_Functions::mkCountQuery($query)), 0, 'count'); } else { $noofrows = null; } $module = 'PriceBooks'; $relatedmodule = 'Products'; if (!$_SESSION['rlvs'][$module][$relatedmodule]) { $modObj = new ListViewSession(); $modObj->sortby = $focus->default_order_by; $modObj->sorder = $focus->default_sort_order; $_SESSION['rlvs'][$module][$relatedmodule] = get_object_vars($modObj); } if (isset($_REQUEST['relmodule']) && $_REQUEST['relmodule'] != '' && $_REQUEST['relmodule'] == $relatedmodule) { $relmodule = vtlib_purify($_REQUEST['relmodule']); if ($_SESSION['rlvs'][$module][$relmodule]) { setSessionVar($_SESSION['rlvs'][$module][$relmodule], $noofrows, $list_max_entries_per_page, $module, $relmodule); } } global $relationId; $start = RelatedListViewSession::getRequestCurrentPage($relationId, $query); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limit_start_rec = ($start - 1) * $list_max_entries_per_page; if ($adb->dbType == "pgsql") { $list_result = $adb->pquery($query . " OFFSET {$limit_start_rec} LIMIT {$list_max_entries_per_page}", array()); } else { $list_result = $adb->pquery($query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array()); } $header = array(); $header[] = $mod_strings['LBL_LIST_PRODUCT_NAME']; if (getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0') { $header[] = $mod_strings['LBL_PRODUCT_CODE']; } if (getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0') { $header[] = $mod_strings['LBL_PRODUCT_UNIT_PRICE']; } $header[] = $mod_strings['LBL_PB_LIST_PRICE']; if (isPermitted("PriceBooks", "EditView", "") == 'yes' || isPermitted("PriceBooks", "Delete", "") == 'yes') { $header[] = $mod_strings['LBL_ACTION']; } $currency_id = $focus->column_fields['currency_id']; $numRows = $adb->num_rows($list_result); for ($i = 0; $i < $numRows; $i++) { $entity_id = $adb->query_result($list_result, $i, "crmid"); $unit_price = $adb->query_result($list_result, $i, "unit_price"); if ($currency_id != null) { $prod_prices = getPricesForProducts($currency_id, array($entity_id)); $unit_price = $prod_prices[$entity_id]; } $listprice = $adb->query_result($list_result, $i, "listprice"); $field_name = $entity_id . "_listprice"; $entries = array(); $entries[] = textlength_check($adb->query_result($list_result, $i, "productname")); if (getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0') { $entries[] = $adb->query_result($list_result, $i, "productcode"); } if (getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0') { $entries[] = CurrencyField::convertToUserFormat($unit_price, null, true); } $entries[] = CurrencyField::convertToUserFormat($listprice, null, true); $action = ""; if (isPermitted("PriceBooks", "EditView", "") == 'yes' && isPermitted('Products', 'EditView', $entity_id) == 'yes') { $action .= '<img style="cursor:pointer;" src="' . vtiger_imageurl('editfield.gif', $theme) . '" border="0" onClick="fnvshobj(this,\'editlistprice\'),editProductListPrice(\'' . $entity_id . '\',\'' . $pricebook_id . '\',\'' . number_format($listprice, $no_of_decimal_places, '.', '') . '\')" alt="' . $app_strings["LBL_EDIT_BUTTON"] . '" title="' . $app_strings["LBL_EDIT_BUTTON"] . '"/>'; } else { $action .= '<img src="' . vtiger_imageurl('blank.gif', $theme) . '" border="0" />'; } if (isPermitted("PriceBooks", "Delete", "") == 'yes' && isPermitted('Products', 'Delete', $entity_id) == 'yes') { if ($action != "") { $action .= ' | '; } $action .= '<img src="' . vtiger_imageurl('delete.gif', $theme) . '" onclick="if(confirm(\'' . $app_strings['ARE_YOU_SURE'] . '\')) deletePriceBookProductRel(' . $entity_id . ',' . $pricebook_id . ');" alt="' . $app_strings["LBL_DELETE"] . '" title="' . $app_strings["LBL_DELETE"] . '" style="cursor:pointer;" border="0">'; } if ($action != "") { $entries[] = $action; } $entries_list[] = $entries; } $navigationOutput[] = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows); $navigationOutput[] = getRelatedTableHeaderNavigation($navigation_array, '', $module, $relatedmodule, $focus->id); $return_data = array('header' => $header, 'entries' => $entries_list, 'navigation' => $navigationOutput); $log->debug("Exiting getPriceBookRelatedProducts method ..."); return $return_data; }
/** Function to retreive the user info of the specifed user id The user info will be available in $this->column_fields array * @param $record -- record id:: Type integer * @param $module -- module:: Type varchar */ function retrieve_entity_info($record, $module) { $adb = PearDatabase::getInstance(); $log = vglobal('log'); $log->debug("Entering into retrieve_entity_info({$record}, {$module}) method."); if ($record == '') { $log->debug("record is empty. returning null"); return null; } $result = array(); foreach ($this->tab_name_index as $table_name => $index) { $result[$table_name] = $adb->pquery("select * from " . $table_name . " where " . $index . "=?", array($record)); } $tabid = getTabid($module); $sql1 = "select * from vtiger_field where tabid=? and vtiger_field.presence in (0,2)"; $result1 = $adb->pquery($sql1, array($tabid)); $noofrows = $adb->num_rows($result1); for ($i = 0; $i < $noofrows; $i++) { $fieldcolname = $adb->query_result($result1, $i, "columnname"); $tablename = $adb->query_result($result1, $i, "tablename"); $fieldname = $adb->query_result($result1, $i, "fieldname"); $fld_value = $adb->query_result($result[$tablename], 0, $fieldcolname); $this->column_fields[$fieldname] = $fld_value; $this->{$fieldname} = $fld_value; } $this->column_fields["record_id"] = $record; $this->column_fields["record_module"] = $module; $currency_query = "select * from vtiger_currency_info where id=? and currency_status='Active' and deleted=0"; $currency_result = $adb->pquery($currency_query, array($this->column_fields["currency_id"])); if ($adb->num_rows($currency_result) == 0) { $currency_query = "select * from vtiger_currency_info where id =1"; $currency_result = $adb->pquery($currency_query, array()); } $currency_array = array("\$" => "$", "€" => "€", "£" => "£", "¥" => "¥"); $ui_curr = $currency_array[$adb->query_result($currency_result, 0, "currency_symbol")]; if ($ui_curr == "") { $ui_curr = $adb->query_result($currency_result, 0, "currency_symbol"); } $this->column_fields["currency_name"] = $this->currency_name = $adb->query_result($currency_result, 0, "currency_name"); $this->column_fields["currency_code"] = $this->currency_code = $adb->query_result($currency_result, 0, "currency_code"); $this->column_fields["currency_symbol"] = $this->currency_symbol = $ui_curr; $this->column_fields["conv_rate"] = $this->conv_rate = $adb->query_result($currency_result, 0, "conversion_rate"); if ($this->column_fields['no_of_currency_decimals'] == '') { $this->column_fields['no_of_currency_decimals'] = $this->no_of_currency_decimals = getCurrencyDecimalPlaces(); } // TODO - This needs to be cleaned up once default values for fields are picked up in a cleaner way. // This is just a quick fix to ensure things doesn't start breaking when the user currency configuration is missing if ($this->column_fields['currency_grouping_pattern'] == '' && $this->column_fields['currency_symbol_placement'] == '') { $this->column_fields['currency_grouping_pattern'] = $this->currency_grouping_pattern = '123,456,789'; $this->column_fields['currency_decimal_separator'] = $this->currency_decimal_separator = '.'; $this->column_fields['currency_grouping_separator'] = $this->currency_grouping_separator = ','; $this->column_fields['currency_symbol_placement'] = $this->currency_symbol_placement = '$1.0'; } // TODO - This needs to be cleaned up once default values for fields are picked up in a cleaner way. // This is just a quick fix to ensure things doesn't start breaking when the user currency configuration is missing if ($this->column_fields['currency_grouping_pattern'] == '' && $this->column_fields['currency_symbol_placement'] == '') { $this->column_fields['currency_grouping_pattern'] = $this->currency_grouping_pattern = '123,456,789'; $this->column_fields['currency_decimal_separator'] = $this->currency_decimal_separator = '.'; $this->column_fields['currency_grouping_separator'] = $this->currency_grouping_separator = ','; $this->column_fields['currency_symbol_placement'] = $this->currency_symbol_placement = '$1.0'; } $this->id = $record; $log->debug("Exit from retrieve_entity_info({$record}, {$module}) method."); return $this; }
function getAssociatedProducts($module, $focus, $seid = '') { $log = vglobal('log'); $log->debug("Entering Calculations_Record_Model getAssociatedProducts(" . $module . "," . get_class($focus) . "," . $seid . "='') method ..."); $adb = PearDatabase::getInstance(); $output = ''; global $theme; $no_of_decimal_places = getCurrencyDecimalPlaces(); $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $product_Detail = array(); if ($module == 'Calculations') { $query = "SELECT\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productcode else vtiger_service.service_no end as productcode,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype,\n\t\t\t\t\t\t\t\t\tvtiger_calculationsproductrel.listprice,\n\t\t\t\t\t\t\t\t\tvtiger_calculationsproductrel.description AS product_description,\n\t\t\t\t\t\t\t\t\tvtiger_calculationsproductrel.*,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_products.usageunit,\n\t\t\t\t\t\t\t\t\tvtiger_service.service_usageunit\n\t\t\t\t\t\t\t\t\tFROM vtiger_calculationsproductrel\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_calculationsproductrel.productid\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_products\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_products.productid=vtiger_calculationsproductrel.productid\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_service\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_service.serviceid=vtiger_calculationsproductrel.productid\n\t\t\t\t\t\t\t\t\tWHERE id=?\n\t\t\t\t\t\t\t\t\tORDER BY sequence_no"; $params = array($focus->id); } elseif ($module == 'Products') { $query = "SELECT\n\t\t\t\t\t\t\t\t\tvtiger_products.productid,\n\t\t\t\t\t\t\t\t\tvtiger_products.productcode,\n\t\t\t\t\t\t\t\t\tvtiger_products.productname,\n\t\t\t\t\t\t\t\t\tvtiger_products.unit_price,\n\t\t\t\t\t\t\t\t\tvtiger_products.usageunit,\n\t\t\t\t\t\t\t\t\tvtiger_products.qtyinstock,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_crmentity.description AS product_description,\n\t\t\t\t\t\t\t\t\t'Products' AS entitytype\n\t\t\t\t\t\t\t\t\tFROM vtiger_products\n\t\t\t\t\t\t\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_crmentity.crmid=vtiger_products.productid\n\t\t\t\t\t\t\t\t\tWHERE vtiger_crmentity.deleted=0\n\t\t\t\t\t\t\t\t\t\t\tAND productid=?"; $params = array($seid); } elseif ($module == 'Services') { $query = "SELECT\n\t\t\t\t\t\t\t\t\tvtiger_service.serviceid AS productid,\n\t\t\t\t\t\t\t\t\t'NA' AS productcode,\n\t\t\t\t\t\t\t\t\tvtiger_service.servicename AS productname,\n\t\t\t\t\t\t\t\t\tvtiger_service.unit_price AS unit_price,\n\t\t\t\t\t\t\t\t\tvtiger_service.service_usageunit AS usageunit,\n\t\t\t\t\t\t\t\t\t'NA' AS qtyinstock,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_crmentity.description AS product_description,\n\t\t\t\t\t\t\t\t\t'Services' AS entitytype\n\t\t\t\t\t\t\t\t\tFROM vtiger_service\n\t\t\t\t\t\t\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_crmentity.crmid=vtiger_service.serviceid\n\t\t\t\t\t\t\t\t\tWHERE vtiger_crmentity.deleted=0\n\t\t\t\t\t\t\t\t\t\t\tAND serviceid=?"; $params = array($seid); } $result = $adb->pquery($query, $params); $num_rows = $adb->num_rows($result); for ($i = 1; $i <= $num_rows; $i++) { $deleted = $adb->query_result($result, $i - 1, 'deleted'); $hdnProductId = $adb->query_result($result, $i - 1, 'productid'); $hdnProductcode = $adb->query_result($result, $i - 1, 'productcode'); $productname = $adb->query_result($result, $i - 1, 'productname'); $productdescription = $adb->query_result($result, $i - 1, 'product_description'); $comment = decode_html($adb->query_result($result, $i - 1, 'comment')); $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock'); $qty = $adb->query_result($result, $i - 1, 'quantity'); $unitprice = $adb->query_result($result, $i - 1, 'unit_price'); $listprice = $adb->query_result($result, $i - 1, 'listprice'); $entitytype = $adb->query_result($result, $i - 1, 'entitytype'); if ($entitytype == 'Services') { $usageunit = vtranslate($adb->query_result($result, $i - 1, 'service_usageunit'), $entitytype); } else { $usageunit = vtranslate($adb->query_result($result, $i - 1, 'usageunit'), $entitytype); } $rbh = $adb->query_result($result, $i - 1, 'rbh'); $purchase = $adb->query_result($result, $i - 1, 'purchase'); $margin = $adb->query_result($result, $i - 1, 'margin'); $marginp = $adb->query_result($result, $i - 1, 'marginp'); if ($deleted || !isset($deleted)) { $product_Detail[$i]['productDeleted' . $i] = true; } elseif (!$deleted) { $product_Detail[$i]['productDeleted' . $i] = false; } if (!empty($entitytype)) { $product_Detail[$i]['entityType' . $i] = $entitytype; } if ($listprice == '') { $listprice = $unitprice; } if ($qty == '') { $qty = 1; } //calculate productTotal $productTotal = $qty * $listprice; //Delete link in First column if ($i != 1) { $product_Detail[$i]['delRow' . $i] = "Del"; } if (empty($focus->mode) && $seid != '') { $sub_prod_query = $adb->pquery("SELECT crmid as prod_id from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($seid)); } else { $sub_prod_query = $adb->pquery("SELECT productid as prod_id from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i)); } $subprodid_str = ''; $subprodname_str = ''; $subProductArray = array(); if ($adb->num_rows($sub_prod_query) > 0) { for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) { $sprod_id = $adb->query_result($sub_prod_query, $j, 'prod_id'); $sprod_name = $subProductArray[] = getProductName($sprod_id); $str_sep = ""; if ($j > 0) { $str_sep = ":"; } $subprodid_str .= $str_sep . $sprod_id; $subprodname_str .= $str_sep . " - " . $sprod_name; } } $subprodname_str = str_replace(":", "<br>", $subprodname_str); $product_Detail[$i]['subProductArray' . $i] = $subProductArray; $product_Detail[$i]['hdnProductId' . $i] = $hdnProductId; $product_Detail[$i]['productName' . $i] = from_html($productname); /* Added to fix the issue Product Pop-up name display*/ if ($_REQUEST['action'] == 'CreateSOPDF' || $_REQUEST['action'] == 'CreatePDF' || $_REQUEST['action'] == 'SendPDFMail') { $product_Detail[$i]['productName' . $i] = htmlspecialchars($product_Detail[$i]['productName' . $i]); } $product_Detail[$i]['hdnProductcode' . $i] = $hdnProductcode; $product_Detail[$i]['productDescription' . $i] = from_html($productdescription); if ($module == 'Potentials' || $module == 'Products' || $module == 'Services') { $product_Detail[$i]['comment' . $i] = $productdescription; } else { $product_Detail[$i]['comment' . $i] = $comment; } $listprice = number_format($listprice, $no_of_decimal_places, '.', ''); $product_Detail[$i]['qty' . $i] = decimalFormat($qty); $product_Detail[$i]['listPrice' . $i] = $listprice; $product_Detail[$i]['unitPrice' . $i] = number_format($unitprice, $no_of_decimal_places, '.', ''); $product_Detail[$i]['usageUnit' . $i] = $usageunit; $product_Detail[$i]['productTotal' . $i] = number_format($productTotal, $no_of_decimal_places, '.', ''); $product_Detail[$i]['subproduct_ids' . $i] = $subprodid_str; $product_Detail[$i]['subprod_names' . $i] = $subprodname_str; $product_Detail[$i]['rbh' . $i] = number_format($rbh, $no_of_decimal_places, '.', ''); $product_Detail[$i]['purchase' . $i] = number_format($purchase, $no_of_decimal_places, '.', ''); $product_Detail[$i]['margin' . $i] = number_format($margin, $no_of_decimal_places, '.', ''); $product_Detail[$i]['marginp' . $i] = number_format($marginp, $no_of_decimal_places, '.', ''); } $log->debug("Exiting Calculations_Record_Model getAssociatedProducts method ..."); return $product_Detail; }
/** * Initializes the User's Currency Details * @global Users $current_user * @param Users $user */ public function initialize($user = null) { global $current_user, $default_charset; if (empty($user)) { $user = $current_user; } if (!empty($user->currency_grouping_pattern)) { $this->currencyFormat = html_entity_decode($user->currency_grouping_pattern, ENT_QUOTES, $default_charset); $this->currencySeparator = str_replace(" ", ' ', html_entity_decode($user->currency_grouping_separator, ENT_QUOTES, $default_charset)); $this->decimalSeparator = str_replace(" ", ' ', html_entity_decode($user->currency_decimal_separator, ENT_QUOTES, $default_charset)); } if (!empty($user->currency_id)) { $this->currencyId = $user->currency_id; } else { $this->currencyId = self::getDBCurrencyId(); } $currencyRateAndSymbol = getCurrencySymbolandCRate($this->currencyId); $this->currencySymbol = $currencyRateAndSymbol['symbol']; $this->conversionRate = $currencyRateAndSymbol['rate']; $this->currencySymbolPlacement = $user->currency_symbol_placement; $this->numberOfDecimal = getCurrencyDecimalPlaces(); }
function buildSummaryModel() { $associated_products = $this->associated_products; $final_details = $associated_products[1]['final_details']; $summaryModel = new Vtiger_PDF_Model(); $netTotal = $discount = $handlingCharges = $handlingTaxes = 0; $adjustment = $grandTotal = 0; $productLineItemIndex = 0; $sh_tax_percent = 0; foreach ($associated_products as $productLineItem) { ++$productLineItemIndex; $netTotal += $productLineItem["netPrice{$productLineItemIndex}"]; } $netTotal = number_format($netTotal + $this->totaltaxes, getCurrencyDecimalPlaces(), '.', ''); $summaryModel->set(getTranslatedString("Net Total", $this->moduleName), $this->formatPrice($netTotal)); $discount_amount = $final_details["discount_amount_final"]; $discount_percent = $final_details["discount_percentage_final"]; $discount = 0.0; $discount_final_percent = '0.00'; if ($final_details['discount_type_final'] == 'amount') { $discount = $discount_amount; } else { if ($final_details['discount_type_final'] == 'percentage') { $discount_final_percent = $discount_percent; $discount = $discount_percent * $final_details["hdnSubTotal"] / 100; } } $summaryModel->set(getTranslatedString("Discount", $this->moduleName) . "({$discount_final_percent}%)", $this->formatPrice($discount)); $group_total_tax_percent = '0.00'; //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(getTranslatedString("Tax:", $this->moduleName) . "({$group_total_tax_percent}%)", $this->formatPrice($final_details['tax_totalamount'])); } //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(getTranslatedString("Shipping & Handling Charges", $this->moduleName), $this->formatPrice($final_details['shipping_handling_charge'])); $summaryModel->set(getTranslatedString("Shipping & Handling Tax:", $this->moduleName) . "({$sh_tax_percent}%)", $this->formatPrice($final_details['shtax_totalamount'])); $summaryModel->set(getTranslatedString("Adjustment", $this->moduleName), $this->formatPrice($final_details['adjustment'])); $summaryModel->set(getTranslatedString("Grand Total:", $this->moduleName) . "(in {$currencySymbol})", $this->formatPrice($final_details['grandTotal'])); // TODO add currency string if ($this->moduleName == 'Invoice') { $receivedVal = $this->focusColumnValue("received"); if (!$receivedVal) { $this->focus->column_fields["received"] = 0; } //If Received value is exist then only Recieved, Balance details should present in PDF if ($this->formatPrice($this->focusColumnValue("received")) > 0) { $summaryModel->set(getTranslatedString("Received", $this->moduleName), $this->formatPrice($this->focusColumnValue("received"))); $summaryModel->set(getTranslatedString("Balance", $this->moduleName), $this->formatPrice($this->focusColumnValue("balance"))); } } return $summaryModel; }
function getAssociatedProducts($module, $focus, $seid = '') { $adb = PearDatabase::getInstance(); $current_user = vglobal('current_user'); $log = vglobal('log'); $theme = vglobal('theme'); $log->debug("Entering OSSCosts_Record_Model getAssociatedProducts(" . $module . "," . get_class($focus) . "," . $seid . "='') method ..."); $output = ''; $no_of_decimal_places = getCurrencyDecimalPlaces(); $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $product_Detail = array(); if ($module == 'OSSCosts') { $query = "SELECT\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productcode else vtiger_service.service_no end as productcode,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype,\n\t\t\t\t\t\t\t\t\tvtiger_inventoryproductrel.listprice,\n\t\t\t\t\t\t\t\t\tvtiger_inventoryproductrel.description AS product_description,\n\t\t\t\t\t\t\t\t\tvtiger_inventoryproductrel.*,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_products.usageunit,\n\t\t\t\t\t\t\t\t\tvtiger_service.service_usageunit\n\t\t\t\t\t\t\t\t\tFROM vtiger_inventoryproductrel\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_inventoryproductrel.productid\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_products\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_products.productid=vtiger_inventoryproductrel.productid\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_service\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_service.serviceid=vtiger_inventoryproductrel.productid\n\t\t\t\t\t\t\t\t\tWHERE id=?\n\t\t\t\t\t\t\t\t\tORDER BY sequence_no"; $params = array($focus->id); } elseif ($module == 'Products') { $query = "SELECT\n\t\t\t\t\t\t\t\t\tvtiger_products.productid,\n\t\t\t\t\t\t\t\t\tvtiger_products.productcode,\n\t\t\t\t\t\t\t\t\tvtiger_products.productname,\n\t\t\t\t\t\t\t\t\tvtiger_products.unit_price,\n\t\t\t\t\t\t\t\t\tvtiger_products.usageunit,\n\t\t\t\t\t\t\t\t\tvtiger_products.qtyinstock,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_crmentity.description AS product_description,\n\t\t\t\t\t\t\t\t\t'Products' AS entitytype\n\t\t\t\t\t\t\t\t\tFROM vtiger_products\n\t\t\t\t\t\t\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_crmentity.crmid=vtiger_products.productid\n\t\t\t\t\t\t\t\t\tWHERE vtiger_crmentity.deleted=0\n\t\t\t\t\t\t\t\t\t\t\tAND productid=?"; $params = array($seid); } elseif ($module == 'Services') { $query = "SELECT\n\t\t\t\t\t\t\t\t\tvtiger_service.serviceid AS productid,\n\t\t\t\t\t\t\t\t\t'NA' AS productcode,\n\t\t\t\t\t\t\t\t\tvtiger_service.servicename AS productname,\n\t\t\t\t\t\t\t\t\tvtiger_service.unit_price AS unit_price,\n\t\t\t\t\t\t\t\t\tvtiger_service.service_usageunit AS usageunit,\n\t\t\t\t\t\t\t\t\t'NA' AS qtyinstock,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_crmentity.description AS product_description,\n\t\t\t\t\t\t\t\t\t'Services' AS entitytype\n\t\t\t\t\t\t\t\t\tFROM vtiger_service\n\t\t\t\t\t\t\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_crmentity.crmid=vtiger_service.serviceid\n\t\t\t\t\t\t\t\t\tWHERE vtiger_crmentity.deleted=0\n\t\t\t\t\t\t\t\t\t\t\tAND serviceid=?"; $params = array($seid); } $result = $adb->pquery($query, $params); $num_rows = $adb->num_rows($result); $finalTaxTotal = '0.00'; for ($i = 1; $i <= $num_rows; $i++) { $deleted = $adb->query_result($result, $i - 1, 'deleted'); $hdnProductId = $adb->query_result($result, $i - 1, 'productid'); $hdnProductcode = $adb->query_result($result, $i - 1, 'productcode'); $productname = $adb->query_result($result, $i - 1, 'productname'); $productdescription = $adb->query_result($result, $i - 1, 'product_description'); $comment = $adb->query_result($result, $i - 1, 'comment'); $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock'); $qty = $adb->query_result($result, $i - 1, 'quantity'); $unitprice = $adb->query_result($result, $i - 1, 'unit_price'); $listprice = $adb->query_result($result, $i - 1, 'listprice'); $entitytype = $adb->query_result($result, $i - 1, 'entitytype'); if ($entitytype == 'Services') { $usageunit = vtranslate($adb->query_result($result, $i - 1, 'service_usageunit'), $entitytype); } else { $usageunit = vtranslate($adb->query_result($result, $i - 1, 'usageunit'), $entitytype); } $tax = $adb->query_result($result, $i - 1, 'tax'); if ($deleted || !isset($deleted)) { $product_Detail[$i]['productDeleted' . $i] = true; } elseif (!$deleted) { $product_Detail[$i]['productDeleted' . $i] = false; } if (!empty($entitytype)) { $product_Detail[$i]['entityType' . $i] = $entitytype; } if ($listprice == '') { $listprice = $unitprice; } if ($qty == '') { $qty = 1; } //calculate productTotal $productTotal = $qty * $listprice; //Delete link in First column if ($i != 1) { $product_Detail[$i]['delRow' . $i] = "Del"; } if (empty($focus->mode) && $seid != '') { $sub_prod_query = $adb->pquery("SELECT crmid as prod_id from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($seid)); } else { $sub_prod_query = $adb->pquery("SELECT productid as prod_id from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i)); } $subprodid_str = ''; $subprodname_str = ''; $subProductArray = array(); if ($adb->num_rows($sub_prod_query) > 0) { for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) { $sprod_id = $adb->query_result($sub_prod_query, $j, 'prod_id'); $sprod_name = $subProductArray[] = getProductName($sprod_id); $str_sep = ""; if ($j > 0) { $str_sep = ":"; } $subprodid_str .= $str_sep . $sprod_id; $subprodname_str .= $str_sep . " - " . $sprod_name; } } $subprodname_str = str_replace(":", "<br>", $subprodname_str); $product_Detail[$i]['subProductArray' . $i] = $subProductArray; $product_Detail[$i]['hdnProductId' . $i] = $hdnProductId; $product_Detail[$i]['productName' . $i] = from_html($productname); /* Added to fix the issue Product Pop-up name display*/ if ($_REQUEST['action'] == 'CreateSOPDF' || $_REQUEST['action'] == 'CreatePDF' || $_REQUEST['action'] == 'SendPDFMail') { $product_Detail[$i]['productName' . $i] = htmlspecialchars($product_Detail[$i]['productName' . $i]); } $product_Detail[$i]['hdnProductcode' . $i] = $hdnProductcode; $product_Detail[$i]['productDescription' . $i] = from_html($productdescription); if ($module == 'Potentials' || $module == 'Products' || $module == 'Services') { $product_Detail[$i]['comment' . $i] = $productdescription; } else { $product_Detail[$i]['comment' . $i] = $comment; } if ($module != 'PurchaseOrder' && $focus->object_name != 'Order') { $product_Detail[$i]['qtyInStock' . $i] = decimalFormat($qtyinstock); } $listprice = number_format($listprice, $no_of_decimal_places, '.', ''); $product_Detail[$i]['qty' . $i] = decimalFormat($qty); $product_Detail[$i]['listPrice' . $i] = $listprice; $product_Detail[$i]['unitPrice' . $i] = number_format($unitprice, $no_of_decimal_places, '.', ''); $product_Detail[$i]['usageUnit' . $i] = $usageunit; $product_Detail[$i]['productTotal' . $i] = $productTotal; $product_Detail[$i]['subproduct_ids' . $i] = $subprodid_str; $product_Detail[$i]['subprod_names' . $i] = $subprodname_str; $product_Detail[$i]['tax' . $i] = $tax; $discount_percent = decimalFormat($adb->query_result($result, $i - 1, 'discount_percent')); $discount_amount = $adb->query_result($result, $i - 1, 'discount_amount'); $discount_amount = decimalFormat(number_format($discount_amount, $no_of_decimal_places, '.', '')); $discountTotal = '0.00'; //Based on the discount percent or amount we will show the discount details //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(for Each Product) $product_Detail[$i]['discount_percent' . $i] = 0; $product_Detail[$i]['discount_amount' . $i] = 0; if ($discount_percent != 'NULL' && $discount_percent != '') { $product_Detail[$i]['discount_type' . $i] = "percentage"; $product_Detail[$i]['discount_percent' . $i] = $discount_percent; $product_Detail[$i]['checked_discount_percent' . $i] = ' checked'; $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:visible"'; $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:hidden"'; $discountTotal = $productTotal * $discount_percent / 100; } elseif ($discount_amount != 'NULL' && $discount_amount != '') { $product_Detail[$i]['discount_type' . $i] = "amount"; $product_Detail[$i]['discount_amount' . $i] = $discount_amount; $product_Detail[$i]['checked_discount_amount' . $i] = ' checked'; $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:visible"'; $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:hidden"'; $discountTotal = $discount_amount; } else { $product_Detail[$i]['checked_discount_zero' . $i] = ' checked'; } $totalAfterDiscount = $productTotal - $discountTotal; $totalAfterDiscount = number_format($totalAfterDiscount, $no_of_decimal_places, '.', ''); $discountTotal = number_format($discountTotal, $no_of_decimal_places, '.', ''); $product_Detail[$i]['discountTotal' . $i] = $discountTotal; $product_Detail[$i]['totalAfterDiscount' . $i] = $totalAfterDiscount; $amount = '0.00'; $tax_details = getTaxDetailsForProduct($hdnProductId, 'all'); //First we should get all available taxes and then retrieve the corresponding tax values $allTaxes = getAllTaxes('available', '', 'edit', $focus->id); $taxtype = $this->getInventoryTaxType($module, $focus->id); for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) { $tax_name = $tax_details[$tax_count]['taxname']; $tax_label = $tax_details[$tax_count]['taxlabel']; $tax_value = '0.00'; //condition to avoid this function call when create new PO/SO/Quotes/Invoice from Product module if ($focus->id != '') { if ($taxtype == 'individual') { //if individual then show the entered tax percentage $tax_value = getInventoryProductTaxValue($focus->id, $hdnProductId, $tax_name); } else { //if group tax then we have to show the default value when change to individual tax $tax_value = $tax_details[$tax_count]['percentage']; } } else { //if the above function not called then assign the default associated value of the product $tax_value = $tax_details[$tax_count]['percentage']; } $product_Detail[$i]['taxes'][$tax_count]['taxname'] = $tax_name; $product_Detail[$i]['taxes'][$tax_count]['taxlabel'] = $tax_label; $product_Detail[$i]['taxes'][$tax_count]['percentage'] = $tax_value; $amount = $totalAfterDiscount * $tax_value / 100; $amount = number_format($amount, $no_of_decimal_places, '.', ''); $product_Detail[$i]['taxes'][$tax_count]['amount'] = $amount; if ($tax == $tax_name) { $finalTaxTotal += $amount; $product_Detail[$i]['taxTotal' . $i] = $amount; } } if ($taxtype == 'group') { foreach ($allTaxes as $key => $value) { if ($tax == $value['taxname']) { $amount = $totalAfterDiscount * $value['percentage'] / 100; $amount = number_format($amount, $no_of_decimal_places, '.', ''); $product_Detail[$i]['taxes'][$tax]['amount'] = $amount; $finalTaxTotal += $amount; $product_Detail[$i]['taxTotal' . $i] = $amount; } } } //Calculate netprice $netPrice = $totalAfterDiscount + number_format($product_Detail[$i]['taxTotal' . $i], $no_of_decimal_places, '.', ''); //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module $product_Detail[$i]['netPrice' . $i] = $netPrice; } //set the taxtype $product_Detail[1]['final_details']['taxtype'] = $taxtype; //Get the Final Discount, S&H charge, Tax for S&H values //To set the Final Discount details $finalDiscount = '0.00'; $product_Detail[1]['final_details']['discount_type_final'] = 'zero'; $subTotal = $focus->column_fields['hdnSubTotal'] != '' ? $focus->column_fields['hdnSubTotal'] : '0.00'; $subTotal = number_format($subTotal, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['hdnSubTotal'] = $subTotal; $discountPercent = $focus->column_fields['hdnDiscountPercent'] != '' ? $focus->column_fields['hdnDiscountPercent'] : '0.00'; $discountAmount = $focus->column_fields['hdnDiscountAmount'] != '' ? $focus->column_fields['hdnDiscountAmount'] : '0.00'; if ($discountPercent != '0') { $discountAmount = $product_Detail[1]['final_details']['hdnSubTotal'] * $discountPercent / 100; } //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(For Final Discount) $discount_amount_final = '0.00'; $discount_amount_final = number_format($discount_amount_final, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['discount_percentage_final'] = 0; $product_Detail[1]['final_details']['discount_amount_final'] = $discount_amount_final; if ($focus->column_fields['hdnDiscountPercent'] != '0') { $finalDiscount = $subTotal * $discountPercent / 100; $product_Detail[1]['final_details']['discount_type_final'] = 'percentage'; $product_Detail[1]['final_details']['discount_percentage_final'] = $discountPercent; $product_Detail[1]['final_details']['checked_discount_percentage_final'] = ' checked'; $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:visible"'; $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:hidden"'; } elseif ($focus->column_fields['hdnDiscountAmount'] != '0' && $focus->column_fields['hdnDiscountAmount'] != '') { $finalDiscount = $focus->column_fields['hdnDiscountAmount']; $product_Detail[1]['final_details']['discount_type_final'] = 'amount'; $product_Detail[1]['final_details']['discount_amount_final'] = $discountAmount; $product_Detail[1]['final_details']['checked_discount_amount_final'] = ' checked'; $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:visible"'; $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:hidden"'; } $finalDiscount = number_format($finalDiscount, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['discountTotal_final'] = $finalDiscount; //To set the Final Tax values //we will get all taxes. if individual then show the product related taxes only else show all taxes //suppose user want to change individual to group or vice versa in edit time the we have to show all taxes. so that here we will store all the taxes and based on need we will show the corresponding taxes for ($tax_count = 0; $tax_count < count($allTaxes); $tax_count++) { $tax_name = $allTaxes[$tax_count]['taxname']; $tax_label = $allTaxes[$tax_count]['taxlabel']; //if taxtype is individual and want to change to group during edit time then we have to show the all available taxes and their default values //Also taxtype is group and want to change to individual during edit time then we have to provide the asspciated taxes and their default tax values for individual products if ($taxtype == 'group') { $tax_percent = $adb->query_result($result, 0, $tax_name); } else { $tax_percent = $allTaxes[$tax_count]['percentage']; } //$adb->query_result($result,0,$tax_name); if ($tax_percent == '' || $tax_percent == 'NULL') { $tax_percent = '0.00'; } $taxamount = ($subTotal - $finalDiscount) * $tax_percent / 100; $taxamount = number_format($taxamount, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['taxes'][$tax_count]['taxname'] = $tax_name; $product_Detail[1]['final_details']['taxes'][$tax_count]['taxlabel'] = $tax_label; $product_Detail[1]['final_details']['taxes'][$tax_count]['percentage'] = $tax_percent; $product_Detail[1]['final_details']['taxes'][$tax_count]['amount'] = $taxamount; } $product_Detail[1]['final_details']['tax_totalamount'] = $finalTaxTotal; $product_Detail[1]['final_details']['tax'] = $tax; //To set the grand total $grandTotal = $focus->column_fields['hdnGrandTotal'] != '' ? $focus->column_fields['hdnGrandTotal'] : '0.00'; $grandTotal = number_format($grandTotal, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['grandTotal'] = $grandTotal; $log->debug("Exiting OSSCosts_Record_Model getAssociatedProducts method ..."); return $product_Detail; }
public function setTableDefinition() { parent::setTableDefinition(); $this->setTableName('company'); # override the not null and not blank properties for the createdby column in the BaseEntity $this->hasColumn('createdby', 'integer', 11, array('default' => NULL)); $this->hasColumn('refno', 'string', 15); $this->hasColumn('name', 'string', 255, array('notblank' => true)); $this->hasColumn('appname', 'string', 255); $this->hasColumn('headertype', 'integer', null, array('default' => 0)); $this->hasColumn('slogan', 'string', 255); $this->hasColumn('username', 'string', 255); $this->hasColumn('abbrv', 'string', 255); $this->hasColumn('status', 'integer', null, array('default' => NULL)); $this->hasColumn('contactperson', 'string', 255); $this->hasColumn('email', 'string', 255); $this->hasColumn('phone', 'string', 15); $this->hasColumn('country', 'string', 2, array('default' => 'UG')); $this->hasColumn('addressline1', 'string', 255); $this->hasColumn('addressline2', 'string', 255); $this->hasColumn('city', 'string', 255); $this->hasColumn('postalcode', 'string', 10); $this->hasColumn('industrycode', 'string', 15); $this->hasColumn('description', 'string', 1000); $this->hasColumn('remarks', 'string', 255); $this->hasColumn('yearstart', 'date', null, array('default' => getFirstDayOfMonth(1, date('Y')))); $this->hasColumn('yearend', 'date', null, array('default' => getLastDayOfMonth(12, date('Y')))); $this->hasColumn('ipsubnets', 'string', 255); $this->hasColumn('hoursinday', 'string', 50, array('default' => HOURS_IN_DAY)); $this->hasColumn('openinghour', 'string', 50, array('default' => '08:00 AM')); $this->hasColumn('closinghour', 'string', 50, array('default' => '05:00 PM')); $this->hasColumn('lunchduration', 'string', 50, array('default' => DEFAULT_LUNCH_DURATION)); $this->hasColumn('payspaye', 'string', 50, array('default' => 1)); $this->hasColumn('paysnssf', 'string', 50, array('default' => 1)); $this->hasColumn('nssfemployeerate', 'string', 50, array('default' => DEFAULT_NSSF_EMP)); $this->hasColumn('nssfcompanyrate', 'string', 50, array('default' => DEFAULT_NSSF_COM)); $this->hasColumn('workingdays', 'string', 50); $this->hasColumn('maxhoursperday', 'string', 50, array('default' => HOURS_IN_DAY)); $this->hasColumn('maxhoursperweek', 'string', 50, array('default' => HOURS_IN_WEEK)); $this->hasColumn('defaultuserid', 'integer', null, array('default' => NULL)); $this->hasColumn('dateapproved', 'date', null, array('default' => NULL)); $this->hasColumn('approvedbyid', 'integer', null, array('default' => NULL)); $this->hasColumn('isinvited', 'integer', null, array('default' => NULL)); $this->hasColumn('invitedbyid', 'integer', null); $this->hasColumn('hasacceptedinvite', 'integer', null, array('default' => 0)); $this->hasColumn('dateinvited', 'date'); $this->hasColumn('startdate', 'date', null, array('default' => NULL)); $this->hasColumn('enddate', 'date', null, array('default' => NULL)); $this->hasColumn('layout', 'string', 25, array('default' => getDefaultLayout())); $this->hasColumn('topbar', 'string', 25, array('default' => getDefaultTopBar())); $this->hasColumn('sidebar', 'string', 25, array('default' => getDefaultSideBar())); $this->hasColumn('colortheme', 'string', 25, array('default' => getDefaultTheme())); $this->hasColumn('showsidebar', 'string', 25, array('default' => getDefaultShowSideBar())); $this->hasColumn('logo', 'string', 255); $this->hasColumn('defaultadminname', 'string', 255, array('default' => getDefaultAdminName())); $this->hasColumn('defaultadminemail', 'string', 255, array('default' => getDefaultAdminEmail())); $this->hasColumn('currencysymbol', 'string', 15, array('default' => getCountryCurrencySymbol())); $this->hasColumn('currencycode', 'string', 15, array('default' => getCountryCurrencyCode())); $this->hasColumn('currencydecimalplaces', 'string', 15, array('default' => getCurrencyDecimalPlaces())); $this->hasColumn('numberdecimalplaces', 'string', 15, array('default' => getNumberDecimalPlaces())); $this->hasColumn('countryisocode', 'string', 15, array('default' => getCountryCode())); $this->hasColumn('phonemaxlength', 'string', 15, array('default' => getMaxPhoneLength())); $this->hasColumn('phoneminlength', 'string', 15, array('default' => getMinPhoneLength())); $this->hasColumn('nationalidminlength', 'string', 15, array('default' => getNationalIDMaxLength())); $this->hasColumn('nationalidmaxlength', 'string', 15, array('default' => getNationalIDMinLength())); $this->hasColumn('countryphonecode', 'string', 15, array('default' => getDefaultPhoneCode())); $this->hasColumn('timezone', 'string', 255, array('default' => getTimeZine())); }
function buildSummaryModel() { $associated_products = $this->associated_products; $final_details = $associated_products[1]['final_details']; $summaryModel = new Vtiger_PDF_Model(); $netTotal = $discount = $handlingCharges = $handlingTaxes = 0; $grandTotal = 0; $productLineItemIndex = 0; foreach ($associated_products as $productLineItem) { ++$productLineItemIndex; $netTotal += $productLineItem["netPrice{$productLineItemIndex}"]; } $netTotal = number_format($netTotal + $this->totaltaxes, getCurrencyDecimalPlaces(), '.', ''); $summaryModel->set(getTranslatedString("Net Total", $this->moduleName), $this->formatPrice($netTotal)); $discount_amount = $final_details["discount_amount_final"]; $discount_percent = $final_details["discount_percentage_final"]; $discount = 0.0; $discount_final_percent = '0.00'; if ($final_details['discount_type_final'] == 'amount') { $discount = $discount_amount; } else { if ($final_details['discount_type_final'] == 'percentage') { $discount_final_percent = $discount_percent; $discount = $discount_percent * $final_details["hdnSubTotal"] / 100; } } $summaryModel->set(getTranslatedString("Discount", $this->moduleName) . "({$discount_final_percent}%)", $this->formatPrice($discount)); $group_total_tax_percent = '0.00'; //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(getTranslatedString("Tax:", $this->moduleName) . "({$group_total_tax_percent}%)", $this->formatPrice($final_details['tax_totalamount'])); } //obtain the Currency Symbol $currencySymbol = $this->buildCurrencySymbol(); $summaryModel->set(getTranslatedString("Grand Total:", $this->moduleName) . "(in {$currencySymbol})", $this->formatPrice($final_details['grandTotal'])); // TODO add currency string return $summaryModel; }
/** This function returns the detailed list of vtiger_products associated to a given entity or a record. * Param $module - module name * Param $focus - module object * Param $seid - sales entity id * Return type is an object array */ function getAssociatedProducts($module, $focus, $seid = '') { global $log; $log->debug("Entering getAssociatedProducts(" . $module . "," . get_class($focus) . "," . $seid . "='') method ..."); global $adb; $output = ''; global $theme, $current_user; $no_of_decimal_places = getCurrencyDecimalPlaces(); $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $product_Detail = array(); // DG 15 Aug 2006 // Add "ORDER BY sequence_no" to retain add order on all inventoryproductrel items // SalesPlatform.ru begin Add Act and Consignment modules if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') { // SalesPlatform.ru begin $query = "SELECT \n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname,\n \t\t case when vtiger_products.productid != '' then vtiger_products.productcode else vtiger_service.service_no end as productcode, \n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.usageunit else vtiger_service.service_usageunit end as usageunit,\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.unit_code else vtiger_service.unit_code end as unit_code,\n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price,\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.manuf_country else '--' end as manuf_country,\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.manuf_country_code else '--' end as manuf_country_code,\n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.customs_id else '--' end as customs_id,\t\t\t\t\t\t\t\t\t\n \t\t case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock,\n \t\t case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype,\n \t\t vtiger_inventoryproductrel.listprice, \n \t\t vtiger_crmentity.description AS product_description, \n \t\t vtiger_inventoryproductrel.* , vtiger_crmentity.deleted\n , attachments.attachment_id, attachments.attachment_name, attachments.attachment_path\n \t FROM vtiger_inventoryproductrel \n LEFT JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_inventoryproductrel.productid\n \t\t LEFT JOIN vtiger_products \n \t\t ON vtiger_products.productid=vtiger_inventoryproductrel.productid \n \t\t LEFT JOIN vtiger_service \n \t\t ON vtiger_service.serviceid=vtiger_inventoryproductrel.productid \n LEFT JOIN (\n SELECT vtiger_attachments.attachmentsid AS attachment_id,\n vtiger_seattachmentsrel.crmid AS attachment_crmid, \n vtiger_attachments.name AS attachment_name, \n vtiger_attachments.path AS attachment_path \n FROM vtiger_seattachmentsrel, vtiger_attachments, vtiger_inventoryproductrel \n WHERE vtiger_seattachmentsrel.crmid=vtiger_inventoryproductrel.productid AND \n vtiger_attachments.attachmentsid=vtiger_seattachmentsrel.attachmentsid \n GROUP BY attachment_crmid DESC\n ) attachments\n ON attachments.attachment_crmid=vtiger_inventoryproductrel.productid \n \t\t WHERE id=?\n \t\t ORDER BY sequence_no"; /* $query="SELECT case when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname, case when vtiger_products.productid != '' then vtiger_products.productcode else vtiger_service.service_no end as productcode, case when vtiger_products.productid != '' then vtiger_products.usageunit else vtiger_service.service_usageunit end as usageunit, case when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price, case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock, case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype, vtiger_inventoryproductrel.listprice, vtiger_inventoryproductrel.description AS product_description, vtiger_inventoryproductrel.* FROM vtiger_inventoryproductrel LEFT JOIN vtiger_products ON vtiger_products.productid=vtiger_inventoryproductrel.productid LEFT JOIN vtiger_service ON vtiger_service.serviceid=vtiger_inventoryproductrel.productid WHERE id=? ORDER BY sequence_no"; */ // SalesPlatform.ru end $params = array($focus->id); } elseif ($module == 'Potentials') { $query = "SELECT\n \t\t vtiger_products.productname,\n \t\t vtiger_products.productcode,\n \t\t vtiger_products.unit_price,\n \t\t vtiger_products.qtyinstock,\n \t\t vtiger_seproductsrel.*,vtiger_crmentity.deleted,\n \t\t vtiger_crmentity.description AS product_description\n \t\t FROM vtiger_products\n \t\t INNER JOIN vtiger_crmentity\n \t\t ON vtiger_crmentity.crmid=vtiger_products.productid\n \t\t INNER JOIN vtiger_seproductsrel\n \t\t ON vtiger_seproductsrel.productid=vtiger_products.productid\n \t\t WHERE vtiger_seproductsrel.crmid=?"; $params = array($seid); } elseif ($module == 'Products') { $query = "SELECT\n \t\t vtiger_products.productid,\n \t\t vtiger_products.productcode,\n \t\t vtiger_products.productname,\n \t\t vtiger_products.unit_price,\n \t\t vtiger_products.qtyinstock,vtiger_crmentity.deleted,\n \t\t vtiger_crmentity.description AS product_description,\n \t\t 'Products' AS entitytype\n \t\t FROM vtiger_products\n \t\t INNER JOIN vtiger_crmentity\n \t\t ON vtiger_crmentity.crmid=vtiger_products.productid\n \t\t WHERE vtiger_crmentity.deleted=0\n \t\t AND productid=?"; $params = array($seid); } elseif ($module == 'Services') { $query = "SELECT\n \t\t vtiger_service.serviceid AS productid,\n \t\t 'NA' AS productcode,\n \t\t vtiger_service.servicename AS productname,\n \t\t vtiger_service.unit_price AS unit_price,\n \t\t 'NA' AS qtyinstock,vtiger_crmentity.deleted,\n \t\t vtiger_crmentity.description AS product_description,\n \t\t \t'Services' AS entitytype\n \t\t\t\t\t\t\t\tFROM vtiger_service\n \t\t INNER JOIN vtiger_crmentity\n \t\t ON vtiger_crmentity.crmid=vtiger_service.serviceid\n \t\t WHERE vtiger_crmentity.deleted=0\n \t\t AND serviceid=?"; $params = array($seid); } $result = $adb->pquery($query, $params); $num_rows = $adb->num_rows($result); for ($i = 1; $i <= $num_rows; $i++) { $deleted = $adb->query_result($result, $i - 1, 'deleted'); $hdnProductId = $adb->query_result($result, $i - 1, 'productid'); $hdnProductcode = $adb->query_result($result, $i - 1, 'productcode'); $productname = $adb->query_result($result, $i - 1, 'productname'); $productdescription = $adb->query_result($result, $i - 1, 'product_description'); $comment = $adb->query_result($result, $i - 1, 'comment'); $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock'); $qty = $adb->query_result($result, $i - 1, 'quantity'); $unitprice = $adb->query_result($result, $i - 1, 'unit_price'); $listprice = $adb->query_result($result, $i - 1, 'listprice'); $entitytype = $adb->query_result($result, $i - 1, 'entitytype'); // SalesPlatform.ru begin if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') { $manuf_country = $adb->query_result($result, $i - 1, 'manuf_country'); $customs_id = $adb->query_result($result, $i - 1, 'customs_id'); $manuf_country_code = $adb->query_result($result, $i - 1, 'manuf_country_code'); $unit_code = $adb->query_result($result, $i - 1, 'unit_code'); $usageunit = $adb->query_result($result, $i - 1, 'usageunit'); $attachment_id = $adb->query_result($result, $i - 1, 'attachment_id'); $attachment_name = $adb->query_result($result, $i - 1, 'attachment_name'); $attachment_path = $adb->query_result($result, $i - 1, 'attachment_path'); } // SalesPlatform.ru end if ($deleted || !isset($deleted)) { $product_Detail[$i]['productDeleted' . $i] = true; } elseif (!$deleted) { $product_Detail[$i]['productDeleted' . $i] = false; } if (!empty($entitytype)) { $product_Detail[$i]['entityType' . $i] = $entitytype; } if ($listprice == '') { $listprice = $unitprice; } if ($qty == '') { $qty = 1; } //calculate productTotal $productTotal = $qty * $listprice; //Delete link in First column if ($i != 1) { $product_Detail[$i]['delRow' . $i] = "Del"; } if (empty($focus->mode) && $seid != '') { $sub_prod_query = $adb->pquery("SELECT crmid as prod_id from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($seid)); } else { $sub_prod_query = $adb->pquery("SELECT productid as prod_id from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i)); } $subprodid_str = ''; $subprodname_str = ''; $subProductArray = array(); if ($adb->num_rows($sub_prod_query) > 0) { for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) { $sprod_id = $adb->query_result($sub_prod_query, $j, 'prod_id'); $sprod_name = $subProductArray[] = getProductName($sprod_id); $str_sep = ""; if ($j > 0) { $str_sep = ":"; } $subprodid_str .= $str_sep . $sprod_id; if (isset($sprod_name)) { $subprodname_str .= $str_sep . " - " . $sprod_name; } } } $subprodname_str = str_replace(":", "<br>", $subprodname_str); $product_Detail[$i]['subProductArray' . $i] = $subProductArray; $product_Detail[$i]['hdnProductId' . $i] = $hdnProductId; $product_Detail[$i]['productName' . $i] = from_html($productname); /* Added to fix the issue Product Pop-up name display*/ if ($_REQUEST['action'] == 'CreateSOPDF' || $_REQUEST['action'] == 'CreatePDF' || $_REQUEST['action'] == 'SendPDFMail') { $product_Detail[$i]['productName' . $i] = htmlspecialchars($product_Detail[$i]['productName' . $i]); } $product_Detail[$i]['hdnProductcode' . $i] = $hdnProductcode; $product_Detail[$i]['productDescription' . $i] = from_html($productdescription); if ($module == 'Potentials' || $module == 'Products' || $module == 'Services') { $product_Detail[$i]['comment' . $i] = $productdescription; } else { $product_Detail[$i]['comment' . $i] = $comment; } // SalesPlatform.ru begin Added acts and consignments if ($module != 'PurchaseOrder' && $focus->object_name != 'Order' && $module != 'Act' && $module != 'Consignment') { $product_Detail[$i]['qtyInStock' . $i] = decimalFormat($qtyinstock); } $listprice = number_format($listprice, $no_of_decimal_places, '.', ''); $product_Detail[$i]['qty' . $i] = decimalFormat($qty); $product_Detail[$i]['listPrice' . $i] = $listprice; $product_Detail[$i]['unitPrice' . $i] = number_format($unitprice, $no_of_decimal_places, '.', ''); $product_Detail[$i]['productTotal' . $i] = $productTotal; $product_Detail[$i]['subproduct_ids' . $i] = $subprodid_str; $product_Detail[$i]['subprod_names' . $i] = $subprodname_str; $discount_percent = decimalFormat($adb->query_result($result, $i - 1, 'discount_percent')); $discount_amount = $adb->query_result($result, $i - 1, 'discount_amount'); $discount_amount = decimalFormat(number_format($discount_amount, $no_of_decimal_places, '.', '')); $discountTotal = '0'; //Based on the discount percent or amount we will show the discount details //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(for Each Product) $product_Detail[$i]['discount_percent' . $i] = 0; $product_Detail[$i]['discount_amount' . $i] = 0; if (!empty($discount_percent)) { $product_Detail[$i]['discount_type' . $i] = "percentage"; $product_Detail[$i]['discount_percent' . $i] = $discount_percent; $product_Detail[$i]['checked_discount_percent' . $i] = ' checked'; $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:visible"'; $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:hidden"'; $discountTotal = $productTotal * $discount_percent / 100; } elseif (!empty($discount_amount)) { $product_Detail[$i]['discount_type' . $i] = "amount"; $product_Detail[$i]['discount_amount' . $i] = $discount_amount; $product_Detail[$i]['checked_discount_amount' . $i] = ' checked'; $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:visible"'; $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:hidden"'; $discountTotal = $discount_amount; } else { $product_Detail[$i]['checked_discount_zero' . $i] = ' checked'; } $totalAfterDiscount = $productTotal - $discountTotal; $totalAfterDiscount = number_format($totalAfterDiscount, $no_of_decimal_places, '.', ''); $discountTotal = number_format($discountTotal, $no_of_decimal_places, '.', ''); $product_Detail[$i]['discountTotal' . $i] = $discountTotal; $product_Detail[$i]['totalAfterDiscount' . $i] = $totalAfterDiscount; // SalesPlatform.ru begin if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') { $product_Detail[$i]['manufCountry' . $i] = $manuf_country; $product_Detail[$i]['customsId' . $i] = $customs_id; $product_Detail[$i]['manufCountryCode' . $i] = $manuf_country_code; $product_Detail[$i]['unitCode' . $i] = $unit_code; $product_Detail[$i]['usageunit' . $i] = $usageunit; $product_Detail[$i]['attachmentId' . $i] = $attachment_id; $product_Detail[$i]['attachmentName' . $i] = $attachment_name; $product_Detail[$i]['attachmentPath' . $i] = $attachment_path; } // SalesPlatform.ru end $taxTotal = '0.00'; $taxTotal = number_format($taxTotal, $no_of_decimal_places, '.', ''); $product_Detail[$i]['taxTotal' . $i] = $taxTotal; //Calculate netprice $netPrice = $totalAfterDiscount + $taxTotal; //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module // SalesPlatform.ru begin Added acts and consignments if ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') { $taxtype = getInventoryTaxType($module, $focus->id); if ($taxtype == 'individual') { //Add the tax with product total and assign to netprice $netPrice = $netPrice + $taxTotal; } } $product_Detail[$i]['netPrice' . $i] = $netPrice; //First we will get all associated taxes as array $tax_details = getTaxDetailsForProduct($hdnProductId, 'all'); //Now retrieve the tax values from the current query with the name for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) { $tax_name = $tax_details[$tax_count]['taxname']; $tax_label = $tax_details[$tax_count]['taxlabel']; $tax_value = '0'; //condition to avoid this function call when create new PO/SO/Quotes/Invoice from Product module if ($focus->id != '') { if ($taxtype == 'individual') { //if individual then show the entered tax percentage $tax_value = getInventoryProductTaxValue($focus->id, $hdnProductId, $tax_name); } else { //if group tax then we have to show the default value when change to individual tax $tax_value = $tax_details[$tax_count]['percentage']; } } else { //if the above function not called then assign the default associated value of the product $tax_value = $tax_details[$tax_count]['percentage']; } $product_Detail[$i]['taxes'][$tax_count]['taxname'] = $tax_name; $product_Detail[$i]['taxes'][$tax_count]['taxlabel'] = $tax_label; $product_Detail[$i]['taxes'][$tax_count]['percentage'] = $tax_value; } } //set the taxtype $product_Detail[1]['final_details']['taxtype'] = $taxtype; //Get the Final Discount, S&H charge, Tax for S&H and Adjustment values //To set the Final Discount details $finalDiscount = '0'; $product_Detail[1]['final_details']['discount_type_final'] = 'zero'; $subTotal = $focus->column_fields['hdnSubTotal'] != '' ? $focus->column_fields['hdnSubTotal'] : '0'; $subTotal = number_format($subTotal, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['hdnSubTotal'] = $subTotal; $discountPercent = $focus->column_fields['hdnDiscountPercent'] != '' ? $focus->column_fields['hdnDiscountPercent'] : '0'; $discountAmount = $focus->column_fields['hdnDiscountAmount'] != '' ? $focus->column_fields['hdnDiscountAmount'] : '0'; if ($discountPercent != '0') { $discountAmount = $product_Detail[1]['final_details']['hdnSubTotal'] * $discountPercent / 100; } //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(For Final Discount) $discount_amount_final = '0'; $discount_amount_final = number_format($discount_amount_final, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['discount_percentage_final'] = 0; $product_Detail[1]['final_details']['discount_amount_final'] = $discount_amount_final; //fix for opensource issue not saving invoice data properly if (!empty($focus->column_fields['hdnDiscountPercent'])) { $finalDiscount = $subTotal * $discountPercent / 100; $product_Detail[1]['final_details']['discount_type_final'] = 'percentage'; $product_Detail[1]['final_details']['discount_percentage_final'] = $discountPercent; $product_Detail[1]['final_details']['checked_discount_percentage_final'] = ' checked'; $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:visible"'; $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:hidden"'; } elseif (!empty($focus->column_fields['hdnDiscountAmount'])) { $finalDiscount = $focus->column_fields['hdnDiscountAmount']; $product_Detail[1]['final_details']['discount_type_final'] = 'amount'; $product_Detail[1]['final_details']['discount_amount_final'] = $discountAmount; $product_Detail[1]['final_details']['checked_discount_amount_final'] = ' checked'; $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:visible"'; $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:hidden"'; } $finalDiscount = number_format($finalDiscount, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['discountTotal_final'] = $finalDiscount; //To set the Final Tax values //we will get all taxes. if individual then show the product related taxes only else show all taxes //suppose user want to change individual to group or vice versa in edit time the we have to show all taxes. so that here we will store all the taxes and based on need we will show the corresponding taxes $taxtotal = '0'; //First we should get all available taxes and then retrieve the corresponding tax values $tax_details = getAllTaxes('available', '', 'edit', $focus->id); for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) { $tax_name = $tax_details[$tax_count]['taxname']; $tax_label = $tax_details[$tax_count]['taxlabel']; //if taxtype is individual and want to change to group during edit time then we have to show the all available taxes and their default values //Also taxtype is group and want to change to individual during edit time then we have to provide the asspciated taxes and their default tax values for individual products // SalesPlatform.ru begin if ($taxtype == 'group' || $taxtype == 'group_tax_inc') { //if($taxtype == 'group') // SalesPlatform.ru end $tax_percent = $adb->query_result($result, 0, $tax_name); } else { $tax_percent = $tax_details[$tax_count]['percentage']; } //$adb->query_result($result,0,$tax_name); if ($tax_percent == '' || $tax_percent == 'NULL') { $tax_percent = '0.00'; } // SalesPlatform.ru begin if ($taxtype == 'group_tax_inc') { $taxamount = ($subTotal - $finalDiscount) * $tax_percent / (100.0 + $tax_percent); } else { // SalesPlatform.ru end $taxamount = ($subTotal - $finalDiscount) * $tax_percent / 100; } $taxamount = number_format($taxamount, $no_of_decimal_places, '.', ''); $taxtotal = $taxtotal + $taxamount; $product_Detail[1]['final_details']['taxes'][$tax_count]['taxname'] = $tax_name; $product_Detail[1]['final_details']['taxes'][$tax_count]['taxlabel'] = $tax_label; $product_Detail[1]['final_details']['taxes'][$tax_count]['percentage'] = $tax_percent; $product_Detail[1]['final_details']['taxes'][$tax_count]['amount'] = $taxamount; } $product_Detail[1]['final_details']['tax_totalamount'] = $taxtotal; //To set the Shipping & Handling charge $shCharge = $focus->column_fields['hdnS_H_Amount'] != '' ? $focus->column_fields['hdnS_H_Amount'] : '0 '; $shCharge = number_format($shCharge, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['shipping_handling_charge'] = $shCharge; //To set the Shipping & Handling tax values //calculate S&H tax $shtaxtotal = '0'; //First we should get all available taxes and then retrieve the corresponding tax values $shtax_details = getAllTaxes('available', 'sh', 'edit', $focus->id); //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table for ($shtax_count = 0; $shtax_count < count($shtax_details); $shtax_count++) { $shtax_name = $shtax_details[$shtax_count]['taxname']; $shtax_label = $shtax_details[$shtax_count]['taxlabel']; $shtax_percent = '0'; //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module // SalesPlatform.ru begin Added acts and consignments if ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') { $shtax_percent = getInventorySHTaxPercent($focus->id, $shtax_name); } // SalesPlatform.ru begin if ($taxtype == 'group_tax_inc') { $shtaxamount = $shCharge * $shtax_percent / (100 + $shtax_percent); } else { // SalesPlatform.ru end $shtaxamount = $shCharge * $shtax_percent / 100; } $shtaxtotal = $shtaxtotal + $shtaxamount; $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['taxname'] = $shtax_name; $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['taxlabel'] = $shtax_label; $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['percentage'] = $shtax_percent; $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['amount'] = $shtaxamount; } $shtaxtotal = number_format($shtaxtotal, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['shtax_totalamount'] = $shtaxtotal; //To set the Adjustment value $adjustment = $focus->column_fields['txtAdjustment'] != '' ? $focus->column_fields['txtAdjustment'] : '0'; $adjustment = number_format($adjustment, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['adjustment'] = $adjustment; //To set the grand total $grandTotal = $focus->column_fields['hdnGrandTotal'] != '' ? $focus->column_fields['hdnGrandTotal'] : '0'; $grandTotal = number_format($grandTotal, $no_of_decimal_places, '.', ''); $product_Detail[1]['final_details']['grandTotal'] = $grandTotal; $log->debug("Exiting getAssociatedProducts method ..."); return $product_Detail; }