[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+*********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 *************************************************************************************/ 10 11 /** 12 * Inventory Record Model Class 13 */ 14 class Inventory_Record_Model extends Vtiger_Record_Model { 15 16 function getCurrencyInfo() { 17 $moduleName = $this->getModuleName(); 18 $currencyInfo = getInventoryCurrencyInfo($moduleName, $this->getId()); 19 return $currencyInfo; 20 } 21 22 function getProductTaxes() { 23 $taxDetails = $this->get('taxDetails'); 24 if ($taxDetails) { 25 return $taxDetails; 26 } 27 28 $record = $this->getId(); 29 if ($record) { 30 $relatedProducts = getAssociatedProducts($this->getModuleName(), $this->getEntity()); 31 $taxDetails = $relatedProducts[1]['final_details']['taxes']; 32 } else { 33 $taxDetails = getAllTaxes('available', '', $this->getEntity()->mode, $this->getId()); 34 } 35 36 $this->set('taxDetails', $taxDetails); 37 return $taxDetails; 38 } 39 40 function getShippingTaxes() { 41 $shippingTaxDetails = $this->get('shippingTaxDetails'); 42 if ($shippingTaxDetails) { 43 return $shippingTaxDetails; 44 } 45 46 $record = $this->getId(); 47 if ($record) { 48 $relatedProducts = getAssociatedProducts($this->getModuleName(), $this->getEntity()); 49 $shippingTaxDetails = $relatedProducts[1]['final_details']['sh_taxes']; 50 } else { 51 $shippingTaxDetails = getAllTaxes('available', 'sh', 'edit', $this->getId()); 52 } 53 54 $this->set('shippingTaxDetails', $shippingTaxDetails); 55 return $shippingTaxDetails; 56 } 57 58 function getProducts() { 59 $relatedProducts = getAssociatedProducts($this->getModuleName(), $this->getEntity()); 60 $productsCount = count($relatedProducts); 61 62 //Updating Pre tax total 63 $preTaxTotal = (float)$relatedProducts[1]['final_details']['hdnSubTotal'] 64 + (float)$relatedProducts[1]['final_details']['shipping_handling_charge'] 65 - (float)$relatedProducts[1]['final_details']['discountTotal_final']; 66 67 $relatedProducts[1]['final_details']['preTaxTotal'] = number_format($preTaxTotal, getCurrencyDecimalPlaces(),'.',''); 68 69 //Updating Total After Discount 70 $totalAfterDiscount = (float)$relatedProducts[1]['final_details']['hdnSubTotal'] 71 - (float)$relatedProducts[1]['final_details']['discountTotal_final']; 72 73 $relatedProducts[1]['final_details']['totalAfterDiscount'] = number_format($totalAfterDiscount, getCurrencyDecimalPlaces(),'.',''); 74 75 //Updating Tax details 76 $taxtype = $relatedProducts[1]['final_details']['taxtype']; 77 78 for ($i=1;$i<=$productsCount; $i++) { 79 $product = $relatedProducts[$i]; 80 $productId = $product['hdnProductId'.$i]; 81 $totalAfterDiscount = $product['totalAfterDiscount'.$i]; 82 83 if ($taxtype == 'individual') { 84 $taxDetails = getTaxDetailsForProduct($productId, 'all'); 85 $taxCount = count($taxDetails); 86 $taxTotal = '0.00'; 87 88 for($j=0; $j<$taxCount; $j++) { 89 $taxValue = $product['taxes'][$j]['percentage']; 90 91 $taxAmount = $totalAfterDiscount * $taxValue / 100; 92 $taxTotal = $taxTotal + $taxAmount; 93 94 $relatedProducts[$i]['taxes'][$j]['amount'] = $taxAmount; 95 $relatedProducts[$i]['taxTotal'.$i] = $taxTotal; 96 } 97 $netPrice = $totalAfterDiscount + $taxTotal; 98 $relatedProducts[$i]['netPrice'.$i] = $netPrice; 99 } 100 } 101 return $relatedProducts; 102 } 103 104 /** 105 * Function to set record module field values 106 * @param parent record model 107 * @return <Model> returns Vtiger_Record_Model 108 */ 109 function setRecordFieldValues($parentRecordModel) { 110 $currentUser = Users_Record_Model::getCurrentUserModel(); 111 112 $fieldsList = array_keys($this->getModule()->getFields()); 113 $parentFieldsList = array_keys($parentRecordModel->getModule()->getFields()); 114 115 $commonFields = array_intersect($fieldsList, $parentFieldsList); 116 foreach ($commonFields as $fieldName) { 117 if (getFieldVisibilityPermission($parentRecordModel->getModuleName(), $currentUser->getId(), $fieldName) == 0) { 118 $this->set($fieldName, $parentRecordModel->get($fieldName)); 119 } 120 } 121 122 return $recordModel; 123 } 124 125 /** 126 * Function to get inventoy terms and conditions 127 * @return <String> 128 */ 129 function getInventoryTermsandConditions() { 130 return getTermsandConditions(); 131 } 132 133 /** 134 * Function to set data of parent record model to this record 135 * @param Vtiger_Record_Model $parentRecordModel 136 * @return Inventory_Record_Model 137 */ 138 public function setParentRecordData(Vtiger_Record_Model $parentRecordModel) { 139 $userModel = Users_Privileges_Model::getCurrentUserPrivilegesModel(); 140 $moduleName = $parentRecordModel->getModuleName(); 141 142 $data = array(); 143 $fieldMappingList = $parentRecordModel->getInventoryMappingFields(); 144 145 foreach ($fieldMappingList as $fieldMapping) { 146 $parentField = $fieldMapping['parentField']; 147 $inventoryField = $fieldMapping['inventoryField']; 148 $fieldModel = Vtiger_Field_Model::getInstance($parentField, Vtiger_Module_Model::getInstance($moduleName)); 149 if ($fieldModel->getPermissions()) { 150 $data[$inventoryField] = $parentRecordModel->get($parentField); 151 } else { 152 $data[$inventoryField] = $fieldMapping['defaultValue']; 153 } 154 } 155 return $this->setData($data); 156 } 157 158 /** 159 * Function to get URL for Export the record as PDF 160 * @return <type> 161 */ 162 public function getExportPDFUrl() { 163 return "index.php?module=".$this->getModuleName()."&action=ExportPDF&record=".$this->getId(); 164 } 165 166 /** 167 * Function to get the send email pdf url 168 * @return <string> 169 */ 170 public function getSendEmailPDFUrl() { 171 return 'module='.$this->getModuleName().'&view=SendEmail&mode=composeMailData&record='.$this->getId(); 172 } 173 174 /** 175 * Function to get this record and details as PDF 176 */ 177 public function getPDF() { 178 $recordId = $this->getId(); 179 $moduleName = $this->getModuleName(); 180 181 $controllerClassName = "Vtiger_". $moduleName ."PDFController"; 182 183 $controller = new $controllerClassName($moduleName); 184 $controller->loadRecord($recordId); 185 186 $fileName = $moduleName.'_'.getModuleSequenceNumber($moduleName, $recordId); 187 $controller->Output($fileName.'.pdf', 'D'); 188 } 189 190 /** 191 * Function to get the pdf file name . This will conver the invoice in to pdf and saves the file 192 * @return <String> 193 * 194 */ 195 public function getPDFFileName() { 196 $moduleName = $this->getModuleName(); 197 if ($moduleName == 'Quotes') { 198 vimport("~~/modules/$moduleName/QuotePDFController.php"); 199 $controllerClassName = "Vtiger_QuotePDFController"; 200 } else { 201 vimport("~~/modules/$moduleName/$moduleName" . "PDFController.php"); 202 $controllerClassName = "Vtiger_" . $moduleName . "PDFController"; 203 } 204 205 $recordId = $this->getId(); 206 $controller = new $controllerClassName($moduleName); 207 $controller->loadRecord($recordId); 208 209 $sequenceNo = getModuleSequenceNumber($moduleName,$recordId); 210 $translatedName = vtranslate($moduleName, $moduleName); 211 $filePath = "storage/$translatedName"."_".$sequenceNo.".pdf"; 212 //added file name to make it work in IE, also forces the download giving the user the option to save 213 $controller->Output($filePath,'F'); 214 return $filePath; 215 } 216 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |