[ 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 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$ 17 * Description: Defines the Account SugarBean Account entity with the necessary 18 * methods and variables. 19 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 20 * All Rights Reserved. 21 * Contributor(s): ______________________________________.. 22 ********************************************************************************/ 23 class PurchaseOrder extends CRMEntity { 24 var $log; 25 var $db; 26 27 var $table_name = "vtiger_purchaseorder"; 28 var $table_index= 'purchaseorderid'; 29 var $tab_name = Array('vtiger_crmentity','vtiger_purchaseorder','vtiger_pobillads','vtiger_poshipads','vtiger_purchaseordercf','vtiger_inventoryproductrel'); 30 var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_purchaseorder'=>'purchaseorderid','vtiger_pobillads'=>'pobilladdressid','vtiger_poshipads'=>'poshipaddressid','vtiger_purchaseordercf'=>'purchaseorderid','vtiger_inventoryproductrel'=>'id'); 31 /** 32 * Mandatory table for supporting custom fields. 33 */ 34 var $customFieldTable = Array('vtiger_purchaseordercf', 'purchaseorderid'); 35 var $entity_table = "vtiger_crmentity"; 36 37 var $billadr_table = "vtiger_pobillads"; 38 39 var $column_fields = Array(); 40 41 var $sortby_fields = Array('subject','tracking_no','smownerid','lastname'); 42 43 // This is used to retrieve related vtiger_fields from form posts. 44 var $additional_column_fields = Array('assigned_user_name', 'smownerid', 'opportunity_id', 'case_id', 'contact_id', 'task_id', 'note_id', 'meeting_id', 'call_id', 'email_id', 'parent_name', 'member_id' ); 45 46 // This is the list of vtiger_fields that are in the lists. 47 var $list_fields = Array( 48 // Module Sequence Numbering 49 //'Order No'=>Array('crmentity'=>'crmid'), 50 'Order No'=>Array('purchaseorder'=>'purchaseorder_no'), 51 // END 52 'Subject'=>Array('purchaseorder'=>'subject'), 53 'Vendor Name'=>Array('purchaseorder'=>'vendorid'), 54 'Tracking Number'=>Array('purchaseorder'=> 'tracking_no'), 55 'Total'=>Array('purchaseorder'=>'total'), 56 'Assigned To'=>Array('crmentity'=>'smownerid') 57 ); 58 59 var $list_fields_name = Array( 60 'Order No'=>'purchaseorder_no', 61 'Subject'=>'subject', 62 'Vendor Name'=>'vendor_id', 63 'Tracking Number'=>'tracking_no', 64 'Total'=>'hdnGrandTotal', 65 'Assigned To'=>'assigned_user_id' 66 ); 67 var $list_link_field= 'subject'; 68 69 var $search_fields = Array( 70 'Order No'=>Array('purchaseorder'=>'purchaseorder_no'), 71 'Subject'=>Array('purchaseorder'=>'subject'), 72 ); 73 74 var $search_fields_name = Array( 75 'Order No'=>'purchaseorder_no', 76 'Subject'=>'subject', 77 ); 78 // Used when enabling/disabling the mandatory fields for the module. 79 // Refers to vtiger_field.fieldname values. 80 var $mandatory_fields = Array('subject', 'vendor_id','createdtime' ,'modifiedtime', 'assigned_user_id'); 81 82 // This is the list of vtiger_fields that are required. 83 var $required_fields = array("accountname"=>1); 84 85 //Added these variables which are used as default order by and sortorder in ListView 86 var $default_order_by = 'subject'; 87 var $default_sort_order = 'ASC'; 88 89 // For Alphabetical search 90 var $def_basicsearch_col = 'subject'; 91 92 // For workflows update field tasks is deleted all the lineitems. 93 var $isLineItemUpdate = true; 94 95 //var $groupTable = Array('vtiger_pogrouprelation','purchaseorderid'); 96 /** Constructor Function for Order class 97 * This function creates an instance of LoggerManager class using getLogger method 98 * creates an instance for PearDatabase class and get values for column_fields array of Order class. 99 */ 100 function PurchaseOrder() { 101 $this->log =LoggerManager::getLogger('PurchaseOrder'); 102 $this->db = PearDatabase::getInstance(); 103 $this->column_fields = getColumnFields('PurchaseOrder'); 104 } 105 106 function save_module($module) 107 { 108 global $adb, $updateInventoryProductRel_deduct_stock; 109 $updateInventoryProductRel_deduct_stock = false; 110 //in ajax save we should not call this function, because this will delete all the existing product values 111 if($_REQUEST['action'] != 'PurchaseOrderAjax' && $_REQUEST['ajxaction'] != 'DETAILVIEW' 112 && $_REQUEST['action'] != 'MassEditSave' && $_REQUEST['action'] != 'ProcessDuplicates' 113 && $_REQUEST['action'] != 'SaveAjax' && $this->isLineItemUpdate != false && $_REQUEST['action'] != 'FROM_WS') { 114 115 $requestProductIdsList = $requestQuantitiesList = array(); 116 $totalNoOfProducts = $_REQUEST['totalProductCount']; 117 for($i=1; $i<=$totalNoOfProducts; $i++) { 118 $productId = $_REQUEST['hdnProductId'.$i]; 119 $requestProductIdsList[$productId] = $productId; 120 if(array_key_exists($productId, $requestQuantitiesList)){ 121 $requestQuantitiesList[$productId] = $requestQuantitiesList[$productId] + $_REQUEST['qty'.$i]; 122 continue; 123 } 124 $requestQuantitiesList[$productId] = $_REQUEST['qty'.$i]; 125 } 126 127 if($this->mode == '' && $this->column_fields['postatus'] === 'Received Shipment') { //Updating Product stock quantity during create mode 128 foreach ($requestProductIdsList as $productId) { 129 addToProductStock($productId, $requestQuantitiesList[$productId]); 130 } 131 } else if ($this->column_fields['postatus'] === 'Received Shipment' && $this->mode != '') { //Updating Product stock quantity during edit mode 132 $recordId = $this->id; 133 $result = $adb->pquery("SELECT productid, quantity FROM vtiger_inventoryproductrel WHERE id = ?", array($recordId)); 134 $numOfRows = $adb->num_rows($result); 135 for ($i=0; $i<$numOfRows; $i++) { 136 $productId = $adb->query_result($result, $i, 'productid'); 137 $productIdsList[$productId] = $productId; 138 $quantitiesList[$productId] = $adb->query_result($result, $i, 'quantity'); 139 } 140 141 $newProductIds = array_diff($requestProductIdsList, $productIdsList); 142 if ($newProductIds) { 143 foreach ($newProductIds as $productId) { 144 addToProductStock($productId, $requestQuantitiesList[$productId]); 145 } 146 } 147 148 $deletedProductIds = array_diff($productIdsList, $requestProductIdsList); 149 if ($deletedProductIds) { 150 foreach ($deletedProductIds as $productId) { 151 $productStock= getPrdQtyInStck($productId); 152 $quantity = $productStock - $quantitiesList[$productId]; 153 updateProductQty($productId, $quantity); 154 } 155 } 156 157 $updatedProductIds = array_intersect($productIdsList, $requestProductIdsList); 158 if ($updatedProductIds) { 159 foreach ($updatedProductIds as $productId) { 160 $quantityDiff = $quantitiesList[$productId] - $requestQuantitiesList[$productId]; 161 if ($quantityDiff < 0) { 162 $quantityDiff = -($quantityDiff); 163 addToProductStock($productId, $quantityDiff); 164 } elseif ($quantityDiff > 0) { 165 $productStock= getPrdQtyInStck($productId); 166 $quantity = $productStock - $quantityDiff; 167 updateProductQty($productId, $quantity); 168 } 169 } 170 } 171 } 172 173 //Based on the total Number of rows we will save the product relationship with this entity 174 saveInventoryProductDetails($this, 'PurchaseOrder', $this->update_prod_stock); 175 176 if ($this->mode != '') { 177 $updateInventoryProductRel_deduct_stock = true; 178 } 179 } 180 181 // Update the currency id and the conversion rate for the purchase order 182 $update_query = "update vtiger_purchaseorder set currency_id=?, conversion_rate=? where purchaseorderid=?"; 183 $update_params = array($this->column_fields['currency_id'], $this->column_fields['conversion_rate'], $this->id); 184 $adb->pquery($update_query, $update_params); 185 } 186 187 /** Function to get activities associated with the Purchase Order 188 * This function accepts the id as arguments and execute the MySQL query using the id 189 * and sends the query and the id as arguments to renderRelatedActivities() method 190 */ 191 function get_activities($id, $cur_tab_id, $rel_tab_id, $actions=false) { 192 global $log, $singlepane_view,$currentModule,$current_user; 193 $log->debug("Entering get_activities(".$id.") method ..."); 194 $this_module = $currentModule; 195 196 $related_module = vtlib_getModuleNameById($rel_tab_id); 197 require_once("modules/$related_module/Activity.php"); 198 $other = new Activity(); 199 vtlib_setup_modulevars($related_module, $other); 200 $singular_modname = vtlib_toSingular($related_module); 201 202 $parenttab = getParentTab(); 203 204 if($singlepane_view == 'true') 205 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 206 else 207 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 208 209 $button = ''; 210 211 $button .= '<input type="hidden" name="activity_mode">'; 212 213 if($actions) { 214 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 215 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 216 if(getFieldVisibilityPermission('Calendar',$current_user->id,'parent_id', 'readwrite') == '0') { 217 $button .= "<input title='".getTranslatedString('LBL_NEW'). " ". getTranslatedString('LBL_TODO', $related_module) ."' class='crmbutton small create'" . 218 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\";this.form.return_module.value=\"$this_module\";this.form.activity_mode.value=\"Task\";' type='submit' name='button'" . 219 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString('LBL_TODO', $related_module) ."'> "; 220 } 221 } 222 } 223 224 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 225 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 226 $query = "SELECT case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name,vtiger_contactdetails.lastname, vtiger_contactdetails.firstname, vtiger_contactdetails.contactid,vtiger_activity.*,vtiger_seactivityrel.crmid as parent_id,vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime from vtiger_activity inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid left join vtiger_contactdetails on vtiger_contactdetails.contactid = vtiger_cntactivityrel.contactid left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid where vtiger_seactivityrel.crmid=".$id." and activitytype='Task' and vtiger_crmentity.deleted=0 and (vtiger_activity.status is not NULL && vtiger_activity.status != 'Completed') and (vtiger_activity.status is not NULL and vtiger_activity.status != 'Deferred') "; 227 228 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 229 230 if($return_value == null) $return_value = Array(); 231 $return_value['CUSTOM_BUTTON'] = $button; 232 233 $log->debug("Exiting get_activities method ..."); 234 return $return_value; 235 } 236 237 /** Function to get the activities history associated with the Purchase Order 238 * This function accepts the id as arguments and execute the MySQL query using the id 239 * and sends the query and the id as arguments to renderRelatedHistory() method 240 */ 241 function get_history($id) 242 { 243 global $log; 244 $log->debug("Entering get_history(".$id.") method ..."); 245 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 246 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 247 $query = "SELECT vtiger_contactdetails.lastname, vtiger_contactdetails.firstname, 248 vtiger_contactdetails.contactid,vtiger_activity.* ,vtiger_seactivityrel.*, 249 vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime, 250 vtiger_crmentity.createdtime, vtiger_crmentity.description,case when 251 (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end 252 as user_name from vtiger_activity 253 inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid 254 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid 255 left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid 256 left join vtiger_contactdetails on vtiger_contactdetails.contactid = vtiger_cntactivityrel.contactid 257 left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid 258 left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 259 where vtiger_activity.activitytype='Task' 260 and (vtiger_activity.status = 'Completed' or vtiger_activity.status = 'Deferred') 261 and vtiger_seactivityrel.crmid=".$id." 262 and vtiger_crmentity.deleted = 0"; 263 //Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php 264 265 $returnValue = getHistory('PurchaseOrder',$query,$id); 266 $log->debug("Exiting get_history method ..."); 267 return $returnValue; 268 } 269 270 271 /** Function used to get the Status history of the Purchase Order 272 * @param $id - purchaseorder id 273 * @return $return_data - array with header and the entries in format Array('header'=>$header,'entries'=>$entries_list) where as $header and $entries_list are arrays which contains header values and all column values of all entries 274 */ 275 function get_postatushistory($id) 276 { 277 global $log; 278 $log->debug("Entering get_postatushistory(".$id.") method ..."); 279 280 global $adb; 281 global $mod_strings; 282 global $app_strings; 283 284 $query = 'select vtiger_postatushistory.*, vtiger_purchaseorder.purchaseorder_no from vtiger_postatushistory inner join vtiger_purchaseorder on vtiger_purchaseorder.purchaseorderid = vtiger_postatushistory.purchaseorderid inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_purchaseorder.purchaseorderid where vtiger_crmentity.deleted = 0 and vtiger_purchaseorder.purchaseorderid = ?'; 285 $result=$adb->pquery($query, array($id)); 286 $noofrows = $adb->num_rows($result); 287 288 $header[] = $app_strings['Order No']; 289 $header[] = $app_strings['Vendor Name']; 290 $header[] = $app_strings['LBL_AMOUNT']; 291 $header[] = $app_strings['LBL_PO_STATUS']; 292 $header[] = $app_strings['LBL_LAST_MODIFIED']; 293 294 //Getting the field permission for the current user. 1 - Not Accessible, 0 - Accessible 295 //Vendor, Total are mandatory fields. So no need to do security check to these fields. 296 global $current_user; 297 298 //If field is accessible then getFieldVisibilityPermission function will return 0 else return 1 299 $postatus_access = (getFieldVisibilityPermission('PurchaseOrder', $current_user->id, 'postatus') != '0')? 1 : 0; 300 $picklistarray = getAccessPickListValues('PurchaseOrder'); 301 302 $postatus_array = ($postatus_access != 1)? $picklistarray['postatus']: array(); 303 //- ==> picklist field is not permitted in profile 304 //Not Accessible - picklist is permitted in profile but picklist value is not permitted 305 $error_msg = ($postatus_access != 1)? 'Not Accessible': '-'; 306 307 while($row = $adb->fetch_array($result)) 308 { 309 $entries = Array(); 310 311 //Module Sequence Numbering 312 //$entries[] = $row['purchaseorderid']; 313 $entries[] = $row['purchaseorder_no']; 314 // END 315 $entries[] = $row['vendorname']; 316 $entries[] = $row['total']; 317 $entries[] = (in_array($row['postatus'], $postatus_array))? $row['postatus']: $error_msg; 318 $date = new DateTimeField($row['lastmodified']); 319 $entries[] = $date->getDisplayDateTimeValue(); 320 321 $entries_list[] = $entries; 322 } 323 324 $return_data = Array('header'=>$header,'entries'=>$entries_list); 325 326 $log->debug("Exiting get_postatushistory method ..."); 327 328 return $return_data; 329 } 330 /* 331 * Function to get the secondary query part of a report 332 * @param - $module primary module name 333 * @param - $secmodule secondary module name 334 * returns the query string formed on fetching the related data for report for secondary module 335 */ 336 function generateReportsSecQuery($module,$secmodule,$queryPlanner){ 337 338 $matrix = $queryPlanner->newDependencyMatrix(); 339 $matrix->setDependency('vtiger_crmentityPurchaseOrder', array('vtiger_usersPurchaseOrder', 'vtiger_groupsPurchaseOrder', 'vtiger_lastModifiedByPurchaseOrder')); 340 $matrix->setDependency('vtiger_inventoryproductrelPurchaseOrder', array('vtiger_productsPurchaseOrder', 'vtiger_servicePurchaseOrder')); 341 $matrix->setDependency('vtiger_purchaseorder',array('vtiger_crmentityPurchaseOrder', "vtiger_currency_info$secmodule", 342 'vtiger_purchaseordercf', 'vtiger_vendorRelPurchaseOrder', 'vtiger_pobillads', 343 'vtiger_poshipads', 'vtiger_inventoryproductrelPurchaseOrder', 'vtiger_contactdetailsPurchaseOrder')); 344 345 if (!$queryPlanner->requireTable('vtiger_purchaseorder', $matrix)) { 346 return ''; 347 } 348 349 $query = $this->getRelationQuery($module,$secmodule,"vtiger_purchaseorder","purchaseorderid",$queryPlanner); 350 if ($queryPlanner->requireTable("vtiger_crmentityPurchaseOrder", $matrix)){ 351 $query .= " left join vtiger_crmentity as vtiger_crmentityPurchaseOrder on vtiger_crmentityPurchaseOrder.crmid=vtiger_purchaseorder.purchaseorderid and vtiger_crmentityPurchaseOrder.deleted=0"; 352 } 353 if ($queryPlanner->requireTable("vtiger_purchaseordercf")){ 354 $query .= " left join vtiger_purchaseordercf on vtiger_purchaseorder.purchaseorderid = vtiger_purchaseordercf.purchaseorderid"; 355 } 356 if ($queryPlanner->requireTable("vtiger_pobillads")){ 357 $query .= " left join vtiger_pobillads on vtiger_purchaseorder.purchaseorderid=vtiger_pobillads.pobilladdressid"; 358 } 359 if ($queryPlanner->requireTable("vtiger_poshipads")){ 360 $query .= " left join vtiger_poshipads on vtiger_purchaseorder.purchaseorderid=vtiger_poshipads.poshipaddressid"; 361 } 362 if ($queryPlanner->requireTable("vtiger_currency_info$secmodule")){ 363 $query .= " left join vtiger_currency_info as vtiger_currency_info$secmodule on vtiger_currency_info$secmodule.id = vtiger_purchaseorder.currency_id"; 364 } 365 if ($queryPlanner->requireTable("vtiger_inventoryproductrelPurchaseOrder", $matrix)){ 366 $query .= " left join vtiger_inventoryproductrel as vtiger_inventoryproductrelPurchaseOrder on vtiger_purchaseorder.purchaseorderid = vtiger_inventoryproductrelPurchaseOrder.id"; 367 // To Eliminate duplicates in reports 368 if(($module == 'Products' || $module == 'Services') && $secmodule == "PurchaseOrder"){ 369 if($module == 'Products'){ 370 $query .= " and vtiger_inventoryproductrelPurchaseOrder.productid = vtiger_products.productid "; 371 }else if($module == 'Services'){ 372 $query .= " and vtiger_inventoryproductrelPurchaseOrder.productid = vtiger_service.serviceid "; 373 } 374 } 375 } 376 if ($queryPlanner->requireTable("vtiger_productsPurchaseOrder")){ 377 $query .= " left join vtiger_products as vtiger_productsPurchaseOrder on vtiger_productsPurchaseOrder.productid = vtiger_inventoryproductrelPurchaseOrder.productid"; 378 } 379 if ($queryPlanner->requireTable("vtiger_servicePurchaseOrder")){ 380 $query .= " left join vtiger_service as vtiger_servicePurchaseOrder on vtiger_servicePurchaseOrder.serviceid = vtiger_inventoryproductrelPurchaseOrder.productid"; 381 } 382 if ($queryPlanner->requireTable("vtiger_usersPurchaseOrder")){ 383 $query .= " left join vtiger_users as vtiger_usersPurchaseOrder on vtiger_usersPurchaseOrder.id = vtiger_crmentityPurchaseOrder.smownerid"; 384 } 385 if ($queryPlanner->requireTable("vtiger_groupsPurchaseOrder")){ 386 $query .= " left join vtiger_groups as vtiger_groupsPurchaseOrder on vtiger_groupsPurchaseOrder.groupid = vtiger_crmentityPurchaseOrder.smownerid"; 387 } 388 if ($queryPlanner->requireTable("vtiger_vendorRelPurchaseOrder")){ 389 $query .= " left join vtiger_vendor as vtiger_vendorRelPurchaseOrder on vtiger_vendorRelPurchaseOrder.vendorid = vtiger_purchaseorder.vendorid"; 390 } 391 if ($queryPlanner->requireTable("vtiger_contactdetailsPurchaseOrder")){ 392 $query .= " left join vtiger_contactdetails as vtiger_contactdetailsPurchaseOrder on vtiger_contactdetailsPurchaseOrder.contactid = vtiger_purchaseorder.contactid"; 393 } 394 if ($queryPlanner->requireTable("vtiger_lastModifiedByPurchaseOrder")){ 395 $query .= " left join vtiger_users as vtiger_lastModifiedByPurchaseOrder on vtiger_lastModifiedByPurchaseOrder.id = vtiger_crmentityPurchaseOrder.modifiedby "; 396 } 397 if ($queryPlanner->requireTable("vtiger_createdbyPurchaseOrder")){ 398 $query .= " left join vtiger_users as vtiger_createdbyPurchaseOrder on vtiger_createdbyPurchaseOrder.id = vtiger_crmentityPurchaseOrder.smcreatorid "; 399 } 400 return $query; 401 } 402 403 /* 404 * Function to get the relation tables for related modules 405 * @param - $secmodule secondary module name 406 * returns the array with table names and fieldnames storing relations between module and this module 407 */ 408 function setRelationTables($secmodule){ 409 $rel_tables = array ( 410 "Calendar" =>array("vtiger_seactivityrel"=>array("crmid","activityid"),"vtiger_purchaseorder"=>"purchaseorderid"), 411 "Documents" => array("vtiger_senotesrel"=>array("crmid","notesid"),"vtiger_purchaseorder"=>"purchaseorderid"), 412 "Contacts" => array("vtiger_purchaseorder"=>array("purchaseorderid","contactid")), 413 ); 414 return $rel_tables[$secmodule]; 415 } 416 417 // Function to unlink an entity with given Id from another entity 418 function unlinkRelationship($id, $return_module, $return_id) { 419 global $log; 420 if(empty($return_module) || empty($return_id)) return; 421 422 if($return_module == 'Vendors') { 423 $sql_req ='UPDATE vtiger_crmentity SET deleted = 1 WHERE crmid= ?'; 424 $this->db->pquery($sql_req, array($id)); 425 } elseif($return_module == 'Contacts') { 426 $sql_req ='UPDATE vtiger_purchaseorder SET contactid=? WHERE purchaseorderid = ?'; 427 $this->db->pquery($sql_req, array(null, $id)); 428 } else { 429 $sql = 'DELETE FROM vtiger_crmentityrel WHERE (crmid=? AND relmodule=? AND relcrmid=?) OR (relcrmid=? AND module=? AND crmid=?)'; 430 $params = array($id, $return_module, $return_id, $id, $return_module, $return_id); 431 $this->db->pquery($sql, $params); 432 } 433 } 434 435 function insertIntoEntityTable($table_name, $module, $fileid = '') { 436 //Ignore relation table insertions while saving of the record 437 if($table_name == 'vtiger_inventoryproductrel') { 438 return; 439 } 440 parent::insertIntoEntityTable($table_name, $module, $fileid); 441 } 442 443 /*Function to create records in current module. 444 **This function called while importing records to this module*/ 445 function createRecords($obj) { 446 $createRecords = createRecords($obj); 447 return $createRecords; 448 } 449 450 /*Function returns the record information which means whether the record is imported or not 451 **This function called while importing records to this module*/ 452 function importRecord($obj, $inventoryFieldData, $lineItemDetails) { 453 $entityInfo = importRecord($obj, $inventoryFieldData, $lineItemDetails); 454 return $entityInfo; 455 } 456 457 /*Function to return the status count of imported records in current module. 458 **This function called while importing records to this module*/ 459 function getImportStatusCount($obj) { 460 $statusCount = getImportStatusCount($obj); 461 return $statusCount; 462 } 463 464 function undoLastImport($obj, $user) { 465 $undoLastImport = undoLastImport($obj, $user); 466 } 467 468 /** Function to export the lead records in CSV Format 469 * @param reference variable - where condition is passed when the query is executed 470 * Returns Export PurchaseOrder Query. 471 */ 472 function create_export_query($where) 473 { 474 global $log; 475 global $current_user; 476 $log->debug("Entering create_export_query(".$where.") method ..."); 477 478 include ("include/utils/ExportUtils.php"); 479 480 //To get the Permitted fields query and the permitted fields list 481 $sql = getPermittedFieldsQuery("PurchaseOrder", "detail_view"); 482 $fields_list = getFieldsListFromQuery($sql); 483 $fields_list .= getInventoryFieldsForExport($this->table_name); 484 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=>'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 485 486 $query = "SELECT $fields_list FROM ".$this->entity_table." 487 INNER JOIN vtiger_purchaseorder ON vtiger_purchaseorder.purchaseorderid = vtiger_crmentity.crmid 488 LEFT JOIN vtiger_purchaseordercf ON vtiger_purchaseordercf.purchaseorderid = vtiger_purchaseorder.purchaseorderid 489 LEFT JOIN vtiger_pobillads ON vtiger_pobillads.pobilladdressid = vtiger_purchaseorder.purchaseorderid 490 LEFT JOIN vtiger_poshipads ON vtiger_poshipads.poshipaddressid = vtiger_purchaseorder.purchaseorderid 491 LEFT JOIN vtiger_inventoryproductrel ON vtiger_inventoryproductrel.id = vtiger_purchaseorder.purchaseorderid 492 LEFT JOIN vtiger_products ON vtiger_products.productid = vtiger_inventoryproductrel.productid 493 LEFT JOIN vtiger_service ON vtiger_service.serviceid = vtiger_inventoryproductrel.productid 494 LEFT JOIN vtiger_contactdetails ON vtiger_contactdetails.contactid = vtiger_purchaseorder.contactid 495 LEFT JOIN vtiger_vendor ON vtiger_vendor.vendorid = vtiger_purchaseorder.vendorid 496 LEFT JOIN vtiger_currency_info ON vtiger_currency_info.id = vtiger_purchaseorder.currency_id 497 LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid 498 LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid"; 499 500 $query .= $this->getNonAdminAccessControlQuery('PurchaseOrder',$current_user); 501 $where_auto = " vtiger_crmentity.deleted=0"; 502 503 if($where != "") { 504 $query .= " where ($where) AND ".$where_auto; 505 } else { 506 $query .= " where ".$where_auto; 507 } 508 509 $log->debug("Exiting create_export_query method ..."); 510 return $query; 511 } 512 513 } 514 515 ?>
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 |