[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/include/utils/ -> EditViewUtils.php (source)

   1  <?php
   2  /*********************************************************************************
   3   * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
   4   * ("License"); You may not use this file except in compliance with the
   5   * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
   6   * Software distributed under the License is distributed on an  "AS IS"  basis,
   7   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
   8   * the specific language governing rights and limitations under the License.
   9   * The Original Code is:  SugarCRM Open Source
  10   * The Initial Developer of the Original Code is SugarCRM, Inc.
  11   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12   * All Rights Reserved.
  13   * Contributor(s): ______________________________________.
  14   ********************************************************************************/
  15  /*********************************************************************************
  16   * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/include/utils/EditViewUtils.php,v 1.188 2005/04/29 05:5 * 4:39 rank Exp
  17   * Description:  Includes generic helper functions used throughout the application.
  18   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  19   * All Rights Reserved.
  20   * Contributor(s): ______________________________________..
  21   ********************************************************************************/
  22  
  23  require_once ('include/database/PearDatabase.php');
  24  require_once ('include/ComboUtil.php'); //new
  25  require_once ('include/utils/CommonUtils.php'); //new
  26  require_once  'modules/PickList/DependentPickListUtils.php';
  27  
  28  /** This function returns the vtiger_invoice object populated with the details from sales order object.
  29  * Param $focus - Invoice object
  30  * Param $so_focus - Sales order focus
  31  * Param $soid - sales order id
  32  * Return type is an object array
  33  */
  34  
  35  function getConvertSoToInvoice($focus,$so_focus,$soid)
  36  {
  37      global $log,$current_user;
  38      $log->debug("Entering getConvertSoToInvoice(".get_class($focus).",".get_class($so_focus).",".$soid.") method ...");
  39      $log->info("in getConvertSoToInvoice ".$soid);
  40      $xyz=array('bill_street','bill_city','bill_code','bill_pobox','bill_country','bill_state','ship_street','ship_city','ship_code','ship_pobox','ship_country','ship_state');
  41      for($i=0;$i<count($xyz);$i++){
  42          if (getFieldVisibilityPermission('SalesOrder', $current_user->id,$xyz[$i]) == '0'){
  43              $so_focus->column_fields[$xyz[$i]] = $so_focus->column_fields[$xyz[$i]];
  44          }
  45          else
  46              $so_focus->column_fields[$xyz[$i]] = '';
  47      }
  48      $focus->column_fields['salesorder_id'] = $soid;
  49      $focus->column_fields['subject'] = $so_focus->column_fields['subject'];
  50      $focus->column_fields['customerno'] = $so_focus->column_fields['customerno'];
  51      $focus->column_fields['duedate'] = $so_focus->column_fields['duedate'];
  52      $focus->column_fields['contact_id'] = $so_focus->column_fields['contact_id'];//to include contact name in Invoice
  53      $focus->column_fields['account_id'] = $so_focus->column_fields['account_id'];
  54      $focus->column_fields['exciseduty'] = $so_focus->column_fields['exciseduty'];
  55      $focus->column_fields['salescommission'] = $so_focus->column_fields['salescommission'];
  56      $focus->column_fields['purchaseorder'] = $so_focus->column_fields['purchaseorder'];
  57      $focus->column_fields['bill_street'] = $so_focus->column_fields['bill_street'];
  58      $focus->column_fields['ship_street'] = $so_focus->column_fields['ship_street'];
  59      $focus->column_fields['bill_city'] = $so_focus->column_fields['bill_city'];
  60      $focus->column_fields['ship_city'] = $so_focus->column_fields['ship_city'];
  61      $focus->column_fields['bill_state'] = $so_focus->column_fields['bill_state'];
  62      $focus->column_fields['ship_state'] = $so_focus->column_fields['ship_state'];
  63      $focus->column_fields['bill_code'] = $so_focus->column_fields['bill_code'];
  64      $focus->column_fields['ship_code'] = $so_focus->column_fields['ship_code'];
  65      $focus->column_fields['bill_country'] = $so_focus->column_fields['bill_country'];
  66      $focus->column_fields['ship_country'] = $so_focus->column_fields['ship_country'];
  67      $focus->column_fields['bill_pobox'] = $so_focus->column_fields['bill_pobox'];
  68      $focus->column_fields['ship_pobox'] = $so_focus->column_fields['ship_pobox'];
  69      $focus->column_fields['description'] = $so_focus->column_fields['description'];
  70      $focus->column_fields['terms_conditions'] = $so_focus->column_fields['terms_conditions'];
  71      $focus->column_fields['currency_id'] = $so_focus->column_fields['currency_id'];
  72      $focus->column_fields['conversion_rate'] = $so_focus->column_fields['conversion_rate'];
  73  
  74      $log->debug("Exiting getConvertSoToInvoice method ...");
  75      return $focus;
  76  
  77  }
  78  
  79  /** This function returns the detailed list of vtiger_products associated to a given entity or a record.
  80  * Param $module - module name
  81  * Param $focus - module object
  82  * Param $seid - sales entity id
  83  * Return type is an object array
  84  */
  85  
  86  
  87  function getAssociatedProducts($module,$focus,$seid='')
  88  {
  89      global $log;
  90      $log->debug("Entering getAssociatedProducts(".$module.",".get_class($focus).",".$seid."='') method ...");
  91      global $adb;
  92      $output = '';
  93      global $theme,$current_user;
  94  
  95      $no_of_decimal_places = getCurrencyDecimalPlaces();
  96      $theme_path="themes/".$theme."/";
  97      $image_path=$theme_path."images/";
  98      $product_Detail = Array();
  99  
 100      // DG 15 Aug 2006
 101      // Add "ORDER BY sequence_no" to retain add order on all inventoryproductrel items
 102  
 103      if($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice')
 104      {
 105          $query="SELECT
 106                      case when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname,
 107                       case when vtiger_products.productid != '' then vtiger_products.product_no else vtiger_service.service_no end as productcode,
 108                      case when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price,
 109                       case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock,
 110                       case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype,
 111                                   vtiger_inventoryproductrel.listprice,
 112                                   vtiger_inventoryproductrel.description AS product_description,
 113                                   vtiger_inventoryproductrel.*,vtiger_crmentity.deleted
 114                                   FROM vtiger_inventoryproductrel
 115                                  LEFT JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_inventoryproductrel.productid
 116                                   LEFT JOIN vtiger_products
 117                                           ON vtiger_products.productid=vtiger_inventoryproductrel.productid
 118                                   LEFT JOIN vtiger_service
 119                                           ON vtiger_service.serviceid=vtiger_inventoryproductrel.productid
 120                                   WHERE id=?
 121                                   ORDER BY sequence_no";
 122              $params = array($focus->id);
 123      }
 124      elseif($module == 'Potentials')
 125      {
 126          $query="SELECT
 127                                   vtiger_products.productname,
 128                                   vtiger_products.productcode,
 129                                   vtiger_products.unit_price,
 130                                   vtiger_products.qtyinstock,
 131                                   vtiger_seproductsrel.*,vtiger_crmentity.deleted,
 132                                   vtiger_crmentity.description AS product_description
 133                                   FROM vtiger_products
 134                                   INNER JOIN vtiger_crmentity
 135                                           ON vtiger_crmentity.crmid=vtiger_products.productid
 136                                   INNER JOIN vtiger_seproductsrel
 137                                           ON vtiger_seproductsrel.productid=vtiger_products.productid
 138                                   WHERE vtiger_seproductsrel.crmid=?";
 139              $params = array($seid);
 140      }
 141      elseif($module == 'Products')
 142      {
 143          $query="SELECT
 144                                   vtiger_products.productid,
 145                                   vtiger_products.productcode,
 146                                   vtiger_products.productname,
 147                                   vtiger_products.unit_price,
 148                                   vtiger_products.qtyinstock,vtiger_crmentity.deleted,
 149                                   vtiger_crmentity.description AS product_description,
 150                                   'Products' AS entitytype
 151                                   FROM vtiger_products
 152                                   INNER JOIN vtiger_crmentity
 153                                           ON vtiger_crmentity.crmid=vtiger_products.productid
 154                                   WHERE vtiger_crmentity.deleted=0
 155                                           AND productid=?";
 156              $params = array($seid);
 157      }
 158      elseif($module == 'Services')
 159      {
 160          $query="SELECT
 161                                   vtiger_service.serviceid AS productid,
 162                                   'NA' AS productcode,
 163                                   vtiger_service.servicename AS productname,
 164                                   vtiger_service.unit_price AS unit_price,
 165                                   'NA' AS qtyinstock,vtiger_crmentity.deleted,
 166                                   vtiger_crmentity.description AS product_description,
 167                                      'Services' AS entitytype
 168                                   FROM vtiger_service
 169                                   INNER JOIN vtiger_crmentity
 170                                           ON vtiger_crmentity.crmid=vtiger_service.serviceid
 171                                   WHERE vtiger_crmentity.deleted=0
 172                                           AND serviceid=?";
 173              $params = array($seid);
 174      }
 175  
 176      $result = $adb->pquery($query, $params);
 177      $num_rows=$adb->num_rows($result);
 178      for($i=1;$i<=$num_rows;$i++)
 179      {
 180          $deleted = $adb->query_result($result,$i-1,'deleted');
 181          $hdnProductId = $adb->query_result($result,$i-1,'productid');
 182          $hdnProductcode = $adb->query_result($result,$i-1,'productcode');
 183          $productname=$adb->query_result($result,$i-1,'productname');
 184          $productdescription=$adb->query_result($result,$i-1,'product_description');
 185          $comment=$adb->query_result($result,$i-1,'comment');
 186          $qtyinstock=$adb->query_result($result,$i-1,'qtyinstock');
 187          $qty=$adb->query_result($result,$i-1,'quantity');
 188          $unitprice=$adb->query_result($result,$i-1,'unit_price');
 189          $listprice=$adb->query_result($result,$i-1,'listprice');
 190          $entitytype=$adb->query_result($result,$i-1,'entitytype');
 191  
 192          if(($deleted) || (!isset($deleted))){
 193              $product_Detail[$i]['productDeleted'.$i] = true;
 194          }elseif(!$deleted){
 195              $product_Detail[$i]['productDeleted'.$i] = false;
 196          }
 197  
 198          if (!empty($entitytype)) {
 199              $product_Detail[$i]['entityType'.$i]=$entitytype;
 200          }
 201  
 202          if($listprice == '')
 203              $listprice = $unitprice;
 204          if($qty =='')
 205              $qty = 1;
 206  
 207          //calculate productTotal
 208          $productTotal = $qty*$listprice;
 209  
 210          //Delete link in First column
 211          if($i != 1)
 212          {
 213              $product_Detail[$i]['delRow'.$i]="Del";
 214          }
 215          if(empty($focus->mode) && $seid!=''){
 216              $sub_prod_query = $adb->pquery("SELECT crmid as prod_id from vtiger_seproductsrel WHERE productid=? AND setype='Products'",array($seid));
 217          } else {
 218              $sub_prod_query = $adb->pquery("SELECT productid as prod_id from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?",array($focus->id,$i));
 219          }
 220          $subprodid_str='';
 221          $subprodname_str='';
 222          $subProductArray = array();
 223          if($adb->num_rows($sub_prod_query)>0){
 224              for($j=0;$j<$adb->num_rows($sub_prod_query);$j++){
 225                  $sprod_id = $adb->query_result($sub_prod_query,$j,'prod_id');
 226                  $sprod_name = $subProductArray[] = getProductName($sprod_id);
 227                  $str_sep = "";
 228                  if($j>0) $str_sep = ":";
 229                  $subprodid_str .= $str_sep.$sprod_id;
 230                  if(isset($sprod_name)){
 231                      $subprodname_str .= $str_sep." - ".$sprod_name;
 232                  }
 233              }
 234          }
 235  
 236          $subprodname_str = str_replace(":","<br>",$subprodname_str);
 237  
 238          $product_Detail[$i]['subProductArray'.$i] = $subProductArray;
 239          $product_Detail[$i]['hdnProductId'.$i] = $hdnProductId;
 240          $product_Detail[$i]['productName'.$i]= from_html($productname);
 241          /* Added to fix the issue Product Pop-up name display*/
 242          if($_REQUEST['action'] == 'CreateSOPDF' || $_REQUEST['action'] == 'CreatePDF' || $_REQUEST['action'] == 'SendPDFMail')
 243              $product_Detail[$i]['productName'.$i]= htmlspecialchars($product_Detail[$i]['productName'.$i]);
 244          $product_Detail[$i]['hdnProductcode'.$i] = $hdnProductcode;
 245          $product_Detail[$i]['productDescription'.$i]= from_html($productdescription);
 246          if($module == 'Potentials' || $module == 'Products' || $module == 'Services') {
 247              $product_Detail[$i]['comment'.$i]= $productdescription;
 248          }else {
 249              $product_Detail[$i]['comment'.$i]= $comment;
 250          }
 251  
 252          if($module != 'PurchaseOrder' && $focus->object_name != 'Order') {
 253              $product_Detail[$i]['qtyInStock'.$i]=decimalFormat($qtyinstock);
 254          }
 255          $listprice = number_format($listprice, $no_of_decimal_places,'.','');
 256          $product_Detail[$i]['qty'.$i]=decimalFormat($qty);
 257          $product_Detail[$i]['listPrice'.$i]=$listprice;
 258          $product_Detail[$i]['unitPrice'.$i]=number_format($unitprice, $no_of_decimal_places,'.','');
 259          $product_Detail[$i]['productTotal'.$i]=$productTotal;
 260          $product_Detail[$i]['subproduct_ids'.$i]=$subprodid_str;
 261          $product_Detail[$i]['subprod_names'.$i]=$subprodname_str;
 262          $discount_percent = decimalFormat($adb->query_result($result,$i-1,'discount_percent'));
 263          $discount_amount = $adb->query_result($result,$i-1,'discount_amount');
 264          $discount_amount = decimalFormat(number_format($discount_amount, $no_of_decimal_places,'.',''));
 265          $discountTotal = '0.00';
 266          //Based on the discount percent or amount we will show the discount details
 267  
 268          //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(for Each Product)
 269          $product_Detail[$i]['discount_percent'.$i] = 0;
 270          $product_Detail[$i]['discount_amount'.$i] = 0;
 271  
 272          if(!empty($discount_percent)) {
 273              $product_Detail[$i]['discount_type'.$i] = "percentage";
 274              $product_Detail[$i]['discount_percent'.$i] = $discount_percent;
 275              $product_Detail[$i]['checked_discount_percent'.$i] = ' checked';
 276              $product_Detail[$i]['style_discount_percent'.$i] = ' style="visibility:visible"';
 277              $product_Detail[$i]['style_discount_amount'.$i] = ' style="visibility:hidden"';
 278              $discountTotal = $productTotal*$discount_percent/100;
 279          } elseif(!empty($discount_amount)) {
 280              $product_Detail[$i]['discount_type'.$i] = "amount";
 281              $product_Detail[$i]['discount_amount'.$i] = $discount_amount;
 282              $product_Detail[$i]['checked_discount_amount'.$i] = ' checked';
 283              $product_Detail[$i]['style_discount_amount'.$i] = ' style="visibility:visible"';
 284              $product_Detail[$i]['style_discount_percent'.$i] = ' style="visibility:hidden"';
 285              $discountTotal = $discount_amount;
 286          }
 287          else
 288          {
 289              $product_Detail[$i]['checked_discount_zero'.$i] = ' checked';
 290          }
 291          $totalAfterDiscount = $productTotal-$discountTotal;
 292          $totalAfterDiscount = number_format($totalAfterDiscount, $no_of_decimal_places,'.','');
 293          $discountTotal = number_format($discountTotal, $no_of_decimal_places,'.','');
 294          $product_Detail[$i]['discountTotal'.$i] = $discountTotal;
 295          $product_Detail[$i]['totalAfterDiscount'.$i] = $totalAfterDiscount;
 296  
 297          $taxTotal = '0.00';
 298          $taxTotal = number_format($taxTotal, $no_of_decimal_places,'.','');
 299          $product_Detail[$i]['taxTotal'.$i] = $taxTotal;
 300  
 301          //Calculate netprice
 302          $netPrice = $totalAfterDiscount+$taxTotal;
 303          //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module
 304          if($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice')
 305          {
 306              $taxtype = getInventoryTaxType($module,$focus->id);
 307              if($taxtype == 'individual')
 308              {
 309                  //Add the tax with product total and assign to netprice
 310                  $netPrice = $netPrice+$taxTotal;
 311              }
 312          }
 313          $product_Detail[$i]['netPrice'.$i] = $netPrice;
 314  
 315          //First we will get all associated taxes as array
 316          $tax_details = getTaxDetailsForProduct($hdnProductId,'all');
 317          //Now retrieve the tax values from the current query with the name
 318          for($tax_count=0;$tax_count<count($tax_details);$tax_count++)
 319          {
 320              $tax_name = $tax_details[$tax_count]['taxname'];
 321              $tax_label = $tax_details[$tax_count]['taxlabel'];
 322              $tax_value = '0.00';
 323  
 324              //condition to avoid this function call when create new PO/SO/Quotes/Invoice from Product module
 325              if($focus->id != '')
 326              {
 327                  if($taxtype == 'individual')//if individual then show the entered tax percentage
 328                      $tax_value = getInventoryProductTaxValue($focus->id, $hdnProductId, $tax_name);
 329                  else//if group tax then we have to show the default value when change to individual tax
 330                      $tax_value = $tax_details[$tax_count]['percentage'];
 331              }
 332              else//if the above function not called then assign the default associated value of the product
 333                  $tax_value = $tax_details[$tax_count]['percentage'];
 334  
 335              $product_Detail[$i]['taxes'][$tax_count]['taxname'] = $tax_name;
 336              $product_Detail[$i]['taxes'][$tax_count]['taxlabel'] = $tax_label;
 337              $product_Detail[$i]['taxes'][$tax_count]['percentage'] = $tax_value;
 338          }
 339  
 340      }
 341  
 342      //set the taxtype
 343      $product_Detail[1]['final_details']['taxtype'] = $taxtype;
 344  
 345      //Get the Final Discount, S&H charge, Tax for S&H and Adjustment values
 346      //To set the Final Discount details
 347      $finalDiscount = '0.00';
 348      $product_Detail[1]['final_details']['discount_type_final'] = 'zero';
 349  
 350      $subTotal = ($focus->column_fields['hdnSubTotal'] != '')?$focus->column_fields['hdnSubTotal']:'0.00';
 351      $subTotal = number_format($subTotal, $no_of_decimal_places,'.','');
 352  
 353      $product_Detail[1]['final_details']['hdnSubTotal'] = $subTotal;
 354      $discountPercent = ($focus->column_fields['hdnDiscountPercent'] != '')?$focus->column_fields['hdnDiscountPercent']:'0.00';
 355      $discountAmount = ($focus->column_fields['hdnDiscountAmount'] != '')?$focus->column_fields['hdnDiscountAmount']:'0.00';
 356      if($discountPercent != '0'){
 357          $discountAmount = ($product_Detail[1]['final_details']['hdnSubTotal'] * $discountPercent / 100);
 358      }
 359  
 360      //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(For Final Discount)
 361      $discount_amount_final = '0.00';
 362      $discount_amount_final = number_format($discount_amount_final, $no_of_decimal_places,'.','');
 363      $product_Detail[1]['final_details']['discount_percentage_final'] = 0;
 364      $product_Detail[1]['final_details']['discount_amount_final'] = $discount_amount_final;
 365  
 366      //fix for opensource issue not saving invoice data properly
 367      if(!empty($focus->column_fields['hdnDiscountPercent']))
 368      {
 369          $finalDiscount = ($subTotal*$discountPercent/100);
 370          $product_Detail[1]['final_details']['discount_type_final'] = 'percentage';
 371          $product_Detail[1]['final_details']['discount_percentage_final'] = $discountPercent;
 372          $product_Detail[1]['final_details']['checked_discount_percentage_final'] = ' checked';
 373          $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:visible"';
 374          $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:hidden"';
 375      }
 376      //fix for opensource issue not saving invoice data properly
 377      elseif(!empty($focus->column_fields['hdnDiscountAmount']))
 378      {
 379          $finalDiscount = $focus->column_fields['hdnDiscountAmount'];
 380          $product_Detail[1]['final_details']['discount_type_final'] = 'amount';
 381          $product_Detail[1]['final_details']['discount_amount_final'] = $discountAmount;
 382          $product_Detail[1]['final_details']['checked_discount_amount_final'] = ' checked';
 383          $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:visible"';
 384          $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:hidden"';
 385      }
 386      $finalDiscount = number_format($finalDiscount, $no_of_decimal_places,'.','');
 387      $product_Detail[1]['final_details']['discountTotal_final'] = $finalDiscount;
 388  
 389      //To set the Final Tax values
 390      //we will get all taxes. if individual then show the product related taxes only else show all taxes
 391      //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
 392  
 393      $taxtotal = '0.00';
 394      //First we should get all available taxes and then retrieve the corresponding tax values
 395      $tax_details = getAllTaxes('available','','edit',$focus->id);
 396  
 397      for($tax_count=0;$tax_count<count($tax_details);$tax_count++)
 398      {
 399          $tax_name = $tax_details[$tax_count]['taxname'];
 400          $tax_label = $tax_details[$tax_count]['taxlabel'];
 401  
 402          //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
 403          //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
 404          if($taxtype == 'group')
 405              $tax_percent = $adb->query_result($result,0,$tax_name);
 406          else
 407              $tax_percent = $tax_details[$tax_count]['percentage'];//$adb->query_result($result,0,$tax_name);
 408  
 409          if($tax_percent == '' || $tax_percent == 'NULL')
 410              $tax_percent = '0.00';
 411          $taxamount = ($subTotal-$finalDiscount)*$tax_percent/100;
 412          $taxamount = number_format($taxamount, $no_of_decimal_places,'.','');
 413          $taxtotal = $taxtotal + $taxamount;
 414          $product_Detail[1]['final_details']['taxes'][$tax_count]['taxname'] = $tax_name;
 415          $product_Detail[1]['final_details']['taxes'][$tax_count]['taxlabel'] = $tax_label;
 416          $product_Detail[1]['final_details']['taxes'][$tax_count]['percentage'] = $tax_percent;
 417          $product_Detail[1]['final_details']['taxes'][$tax_count]['amount'] = $taxamount;
 418      }
 419      $product_Detail[1]['final_details']['tax_totalamount'] = $taxtotal;
 420  
 421      //To set the Shipping & Handling charge
 422      $shCharge = ($focus->column_fields['hdnS_H_Amount'] != '')?$focus->column_fields['hdnS_H_Amount']:'0.00';
 423      $shCharge = number_format($shCharge, $no_of_decimal_places,'.','');
 424      $product_Detail[1]['final_details']['shipping_handling_charge'] = $shCharge;
 425  
 426      //To set the Shipping & Handling tax values
 427      //calculate S&H tax
 428      $shtaxtotal = '0.00';
 429      //First we should get all available taxes and then retrieve the corresponding tax values
 430      $shtax_details = getAllTaxes('available','sh','edit',$focus->id);
 431  
 432      //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
 433      for($shtax_count=0;$shtax_count<count($shtax_details);$shtax_count++)
 434      {
 435          $shtax_name = $shtax_details[$shtax_count]['taxname'];
 436          $shtax_label = $shtax_details[$shtax_count]['taxlabel'];
 437          $shtax_percent = '0.00';
 438          //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module
 439          if($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice')
 440          {
 441              $shtax_percent = getInventorySHTaxPercent($focus->id,$shtax_name);
 442          }
 443          $shtaxamount = $shCharge*$shtax_percent/100;
 444          $shtaxtotal = $shtaxtotal + $shtaxamount;
 445          $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['taxname'] = $shtax_name;
 446          $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['taxlabel'] = $shtax_label;
 447          $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['percentage'] = $shtax_percent;
 448          $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['amount'] = $shtaxamount;
 449      }
 450      $shtaxtotal = number_format($shtaxtotal, $no_of_decimal_places,'.','');
 451      $product_Detail[1]['final_details']['shtax_totalamount'] = $shtaxtotal;
 452  
 453      //To set the Adjustment value
 454      $adjustment = ($focus->column_fields['txtAdjustment'] != '')?$focus->column_fields['txtAdjustment']:'0.00';
 455      $adjustment = number_format($adjustment, $no_of_decimal_places,'.','');
 456      $product_Detail[1]['final_details']['adjustment'] = $adjustment;
 457  
 458      //To set the grand total
 459      $grandTotal = ($focus->column_fields['hdnGrandTotal'] != '')?$focus->column_fields['hdnGrandTotal']:'0.00';
 460      $grandTotal = number_format($grandTotal, $no_of_decimal_places,'.','');
 461      $product_Detail[1]['final_details']['grandTotal'] = $grandTotal;
 462  
 463      $log->debug("Exiting getAssociatedProducts method ...");
 464  
 465      return $product_Detail;
 466  
 467  }
 468  
 469  /** This function returns the data type of the vtiger_fields, with vtiger_field label, which is used for javascript validation.
 470  * Param $validationData - array of vtiger_fieldnames with datatype
 471  * Return type array
 472  */
 473  
 474  function split_validationdataArray($validationData)
 475  {
 476      global $log;
 477      $log->debug("Entering split_validationdataArray(".$validationData.") method ...");
 478      $fieldName = '';
 479      $fieldLabel = '';
 480      $fldDataType = '';
 481      $rows = count($validationData);
 482      foreach($validationData as $fldName => $fldLabel_array)
 483      {
 484          if($fieldName == '')
 485          {
 486              $fieldName="'".$fldName."'";
 487          }
 488          else
 489          {
 490              $fieldName .= ",'".$fldName ."'";
 491          }
 492          foreach($fldLabel_array as $fldLabel => $datatype)
 493          {
 494              if($fieldLabel == '')
 495              {
 496                  $fieldLabel = "'".addslashes($fldLabel)."'";
 497              }
 498              else
 499              {
 500                  $fieldLabel .= ",'".addslashes($fldLabel)."'";
 501              }
 502              if($fldDataType == '')
 503              {
 504                  $fldDataType = "'".$datatype ."'";
 505              }
 506              else
 507              {
 508                  $fldDataType .= ",'".$datatype ."'";
 509              }
 510          }
 511      }
 512      $data['fieldname'] = $fieldName;
 513      $data['fieldlabel'] = $fieldLabel;
 514      $data['datatype'] = $fldDataType;
 515      $log->debug("Exiting split_validationdataArray method ...");
 516      return $data;
 517  }
 518  
 519  
 520  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1