[ 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 SalesOrder extends CRMEntity { 24 var $log; 25 var $db; 26 27 var $table_name = "vtiger_salesorder"; 28 var $table_index= 'salesorderid'; 29 var $tab_name = Array('vtiger_crmentity','vtiger_salesorder','vtiger_sobillads','vtiger_soshipads','vtiger_salesordercf','vtiger_invoice_recurring_info','vtiger_inventoryproductrel'); 30 var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_salesorder'=>'salesorderid','vtiger_sobillads'=>'sobilladdressid','vtiger_soshipads'=>'soshipaddressid','vtiger_salesordercf'=>'salesorderid','vtiger_invoice_recurring_info'=>'salesorderid','vtiger_inventoryproductrel'=>'id'); 31 /** 32 * Mandatory table for supporting custom fields. 33 */ 34 var $customFieldTable = Array('vtiger_salesordercf', 'salesorderid'); 35 var $entity_table = "vtiger_crmentity"; 36 37 var $billadr_table = "vtiger_sobillads"; 38 39 var $object_name = "SalesOrder"; 40 41 var $new_schema = true; 42 43 var $update_product_array = Array(); 44 45 var $column_fields = Array(); 46 47 var $sortby_fields = Array('subject','smownerid','accountname','lastname'); 48 49 // This is used to retrieve related vtiger_fields from form posts. 50 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' ); 51 52 // This is the list of vtiger_fields that are in the lists. 53 var $list_fields = Array( 54 // Module Sequence Numbering 55 //'Order No'=>Array('crmentity'=>'crmid'), 56 'Order No'=>Array('salesorder','salesorder_no'), 57 // END 58 'Subject'=>Array('salesorder'=>'subject'), 59 'Account Name'=>Array('account'=>'accountid'), 60 'Quote Name'=>Array('quotes'=>'quoteid'), 61 'Total'=>Array('salesorder'=>'total'), 62 'Assigned To'=>Array('crmentity'=>'smownerid') 63 ); 64 65 var $list_fields_name = Array( 66 'Order No'=>'salesorder_no', 67 'Subject'=>'subject', 68 'Account Name'=>'account_id', 69 'Quote Name'=>'quote_id', 70 'Total'=>'hdnGrandTotal', 71 'Assigned To'=>'assigned_user_id' 72 ); 73 var $list_link_field= 'subject'; 74 75 var $search_fields = Array( 76 'Order No'=>Array('salesorder'=>'salesorder_no'), 77 'Subject'=>Array('salesorder'=>'subject'), 78 'Account Name'=>Array('account'=>'accountid'), 79 'Quote Name'=>Array('salesorder'=>'quoteid') 80 ); 81 82 var $search_fields_name = Array( 83 'Order No'=>'salesorder_no', 84 'Subject'=>'subject', 85 'Account Name'=>'account_id', 86 'Quote Name'=>'quote_id' 87 ); 88 89 // This is the list of vtiger_fields that are required. 90 var $required_fields = array("accountname"=>1); 91 92 //Added these variables which are used as default order by and sortorder in ListView 93 var $default_order_by = 'subject'; 94 var $default_sort_order = 'ASC'; 95 //var $groupTable = Array('vtiger_sogrouprelation','salesorderid'); 96 97 var $mandatory_fields = Array('subject','createdtime' ,'modifiedtime', 'assigned_user_id'); 98 99 // For Alphabetical search 100 var $def_basicsearch_col = 'subject'; 101 102 // For workflows update field tasks is deleted all the lineitems. 103 var $isLineItemUpdate = true; 104 105 /** Constructor Function for SalesOrder class 106 * This function creates an instance of LoggerManager class using getLogger method 107 * creates an instance for PearDatabase class and get values for column_fields array of SalesOrder class. 108 */ 109 function SalesOrder() { 110 $this->log =LoggerManager::getLogger('SalesOrder'); 111 $this->db = PearDatabase::getInstance(); 112 $this->column_fields = getColumnFields('SalesOrder'); 113 } 114 115 function save_module($module) 116 { 117 118 //Checking if quote_id is present and updating the quote status 119 if($this->column_fields["quote_id"] != '') 120 { 121 $qt_id = $this->column_fields["quote_id"]; 122 $query1 = "update vtiger_quotes set quotestage='Accepted' where quoteid=?"; 123 $this->db->pquery($query1, array($qt_id)); 124 } 125 126 //in ajax save we should not call this function, because this will delete all the existing product values 127 if($_REQUEST['action'] != 'SalesOrderAjax' && $_REQUEST['ajxaction'] != 'DETAILVIEW' 128 && $_REQUEST['action'] != 'MassEditSave' && $_REQUEST['action'] != 'ProcessDuplicates' 129 && $_REQUEST['action'] != 'SaveAjax' && $this->isLineItemUpdate != false) { 130 //Based on the total Number of rows we will save the product relationship with this entity 131 saveInventoryProductDetails($this, 'SalesOrder'); 132 } 133 134 // Update the currency id and the conversion rate for the sales order 135 $update_query = "update vtiger_salesorder set currency_id=?, conversion_rate=? where salesorderid=?"; 136 $update_params = array($this->column_fields['currency_id'], $this->column_fields['conversion_rate'], $this->id); 137 $this->db->pquery($update_query, $update_params); 138 } 139 140 /** Function to get activities associated with the Sales Order 141 * This function accepts the id as arguments and execute the MySQL query using the id 142 * and sends the query and the id as arguments to renderRelatedActivities() method 143 */ 144 function get_activities($id, $cur_tab_id, $rel_tab_id, $actions=false) { 145 global $log, $singlepane_view,$currentModule,$current_user; 146 $log->debug("Entering get_activities(".$id.") method ..."); 147 $this_module = $currentModule; 148 149 $related_module = vtlib_getModuleNameById($rel_tab_id); 150 require_once("modules/$related_module/Activity.php"); 151 $other = new Activity(); 152 vtlib_setup_modulevars($related_module, $other); 153 $singular_modname = vtlib_toSingular($related_module); 154 155 $parenttab = getParentTab(); 156 157 if($singlepane_view == 'true') 158 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 159 else 160 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 161 162 $button = ''; 163 164 $button .= '<input type="hidden" name="activity_mode">'; 165 166 if($actions) { 167 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 168 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 169 if(getFieldVisibilityPermission('Calendar',$current_user->id,'parent_id', 'readwrite') == '0') { 170 $button .= "<input title='".getTranslatedString('LBL_NEW'). " ". getTranslatedString('LBL_TODO', $related_module) ."' class='crmbutton small create'" . 171 " 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'" . 172 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString('LBL_TODO', $related_module) ."'> "; 173 } 174 } 175 } 176 177 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 178 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 179 $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 and vtiger_activity.status != 'Completed') and (vtiger_activity.status is not NULL and vtiger_activity.status !='Deferred')"; 180 181 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 182 183 if($return_value == null) $return_value = Array(); 184 $return_value['CUSTOM_BUTTON'] = $button; 185 186 $log->debug("Exiting get_activities method ..."); 187 return $return_value; 188 } 189 190 /** Function to get the activities history associated with the Sales Order 191 * This function accepts the id as arguments and execute the MySQL query using the id 192 * and sends the query and the id as arguments to renderRelatedHistory() method 193 */ 194 function get_history($id) 195 { 196 global $log; 197 $log->debug("Entering get_history(".$id.") method ..."); 198 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 199 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 200 $query = "SELECT vtiger_contactdetails.lastname, vtiger_contactdetails.firstname, 201 vtiger_contactdetails.contactid,vtiger_activity.*, vtiger_seactivityrel.*, 202 vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime, 203 vtiger_crmentity.createdtime, vtiger_crmentity.description, case when 204 (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname 205 end as user_name from vtiger_activity 206 inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid 207 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid 208 left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid 209 left join vtiger_contactdetails on vtiger_contactdetails.contactid = vtiger_cntactivityrel.contactid 210 left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid 211 left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 212 where activitytype='Task' 213 and (vtiger_activity.status = 'Completed' or vtiger_activity.status = 'Deferred') 214 and vtiger_seactivityrel.crmid=".$id." 215 and vtiger_crmentity.deleted = 0"; 216 //Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php 217 218 $log->debug("Exiting get_history method ..."); 219 return getHistory('SalesOrder',$query,$id); 220 } 221 222 223 224 /** Function to get the invoices associated with the Sales Order 225 * This function accepts the id as arguments and execute the MySQL query using the id 226 * and sends the query and the id as arguments to renderRelatedInvoices() method. 227 */ 228 function get_invoices($id) 229 { 230 global $log,$singlepane_view; 231 $log->debug("Entering get_invoices(".$id.") method ..."); 232 require_once ('modules/Invoice/Invoice.php'); 233 234 $focus = new Invoice(); 235 236 $button = ''; 237 if($singlepane_view == 'true') 238 $returnset = '&return_module=SalesOrder&return_action=DetailView&return_id='.$id; 239 else 240 $returnset = '&return_module=SalesOrder&return_action=CallRelatedList&return_id='.$id; 241 242 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 243 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 244 $query = "select vtiger_crmentity.*, vtiger_invoice.*, vtiger_account.accountname, 245 vtiger_salesorder.subject as salessubject, case when 246 (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname 247 end as user_name from vtiger_invoice 248 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_invoice.invoiceid 249 left outer join vtiger_account on vtiger_account.accountid=vtiger_invoice.accountid 250 inner join vtiger_salesorder on vtiger_salesorder.salesorderid=vtiger_invoice.salesorderid 251 LEFT JOIN vtiger_invoicecf ON vtiger_invoicecf.invoiceid = vtiger_invoice.invoiceid 252 LEFT JOIN vtiger_invoicebillads ON vtiger_invoicebillads.invoicebilladdressid = vtiger_invoice.invoiceid 253 LEFT JOIN vtiger_invoiceshipads ON vtiger_invoiceshipads.invoiceshipaddressid = vtiger_invoice.invoiceid 254 left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 255 left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid 256 where vtiger_crmentity.deleted=0 and vtiger_salesorder.salesorderid=".$id; 257 258 $log->debug("Exiting get_invoices method ..."); 259 return GetRelatedList('SalesOrder','Invoice',$focus,$query,$button,$returnset); 260 261 } 262 263 /** Function used to get the Status history of the Sales Order 264 * @param $id - salesorder id 265 * @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 266 */ 267 function get_sostatushistory($id) 268 { 269 global $log; 270 $log->debug("Entering get_sostatushistory(".$id.") method ..."); 271 272 global $adb; 273 global $mod_strings; 274 global $app_strings; 275 276 $query = 'select vtiger_sostatushistory.*, vtiger_salesorder.salesorder_no from vtiger_sostatushistory inner join vtiger_salesorder on vtiger_salesorder.salesorderid = vtiger_sostatushistory.salesorderid inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_salesorder.salesorderid where vtiger_crmentity.deleted = 0 and vtiger_salesorder.salesorderid = ?'; 277 $result=$adb->pquery($query, array($id)); 278 $noofrows = $adb->num_rows($result); 279 280 $header[] = $app_strings['Order No']; 281 $header[] = $app_strings['LBL_ACCOUNT_NAME']; 282 $header[] = $app_strings['LBL_AMOUNT']; 283 $header[] = $app_strings['LBL_SO_STATUS']; 284 $header[] = $app_strings['LBL_LAST_MODIFIED']; 285 286 //Getting the field permission for the current user. 1 - Not Accessible, 0 - Accessible 287 //Account Name , Total are mandatory fields. So no need to do security check to these fields. 288 global $current_user; 289 290 //If field is accessible then getFieldVisibilityPermission function will return 0 else return 1 291 $sostatus_access = (getFieldVisibilityPermission('SalesOrder', $current_user->id, 'sostatus') != '0')? 1 : 0; 292 $picklistarray = getAccessPickListValues('SalesOrder'); 293 294 $sostatus_array = ($sostatus_access != 1)? $picklistarray['sostatus']: array(); 295 //- ==> picklist field is not permitted in profile 296 //Not Accessible - picklist is permitted in profile but picklist value is not permitted 297 $error_msg = ($sostatus_access != 1)? 'Not Accessible': '-'; 298 299 while($row = $adb->fetch_array($result)) 300 { 301 $entries = Array(); 302 303 // Module Sequence Numbering 304 //$entries[] = $row['salesorderid']; 305 $entries[] = $row['salesorder_no']; 306 // END 307 $entries[] = $row['accountname']; 308 $entries[] = $row['total']; 309 $entries[] = (in_array($row['sostatus'], $sostatus_array))? $row['sostatus']: $error_msg; 310 $date = new DateTimeField($row['lastmodified']); 311 $entries[] = $date->getDisplayDateTimeValue(); 312 313 $entries_list[] = $entries; 314 } 315 316 $return_data = Array('header'=>$header,'entries'=>$entries_list); 317 318 $log->debug("Exiting get_sostatushistory method ..."); 319 320 return $return_data; 321 } 322 323 /* 324 * Function to get the secondary query part of a report 325 * @param - $module primary module name 326 * @param - $secmodule secondary module name 327 * returns the query string formed on fetching the related data for report for secondary module 328 */ 329 function generateReportsSecQuery($module,$secmodule,$queryPlanner){ 330 $matrix = $queryPlanner->newDependencyMatrix(); 331 $matrix->setDependency('vtiger_crmentitySalesOrder', array('vtiger_usersSalesOrder', 'vtiger_groupsSalesOrder', 'vtiger_lastModifiedBySalesOrder')); 332 $matrix->setDependency('vtiger_inventoryproductrelSalesOrder', array('vtiger_productsSalesOrder', 'vtiger_serviceSalesOrder')); 333 $matrix->setDependency('vtiger_salesorder',array('vtiger_crmentitySalesOrder', "vtiger_currency_info$secmodule", 334 'vtiger_salesordercf', 'vtiger_potentialRelSalesOrder', 'vtiger_sobillads','vtiger_soshipads', 335 'vtiger_inventoryproductrelSalesOrder', 'vtiger_contactdetailsSalesOrder', 'vtiger_accountSalesOrder', 336 'vtiger_invoice_recurring_info','vtiger_quotesSalesOrder')); 337 338 if (!$queryPlanner->requireTable('vtiger_salesorder', $matrix)) { 339 return ''; 340 } 341 342 $query = $this->getRelationQuery($module,$secmodule,"vtiger_salesorder","salesorderid", $queryPlanner); 343 if ($queryPlanner->requireTable("vtiger_crmentitySalesOrder",$matrix)){ 344 $query .= " left join vtiger_crmentity as vtiger_crmentitySalesOrder on vtiger_crmentitySalesOrder.crmid=vtiger_salesorder.salesorderid and vtiger_crmentitySalesOrder.deleted=0"; 345 } 346 if ($queryPlanner->requireTable("vtiger_salesordercf")){ 347 $query .= " left join vtiger_salesordercf on vtiger_salesorder.salesorderid = vtiger_salesordercf.salesorderid"; 348 } 349 if ($queryPlanner->requireTable("vtiger_sobillads")){ 350 $query .= " left join vtiger_sobillads on vtiger_salesorder.salesorderid=vtiger_sobillads.sobilladdressid"; 351 } 352 if ($queryPlanner->requireTable("vtiger_soshipads")){ 353 $query .= " left join vtiger_soshipads on vtiger_salesorder.salesorderid=vtiger_soshipads.soshipaddressid"; 354 } 355 if ($queryPlanner->requireTable("vtiger_currency_info$secmodule")){ 356 $query .= " left join vtiger_currency_info as vtiger_currency_info$secmodule on vtiger_currency_info$secmodule.id = vtiger_salesorder.currency_id"; 357 } 358 if ($queryPlanner->requireTable("vtiger_inventoryproductrelSalesOrder", $matrix)){ 359 $query .= " left join vtiger_inventoryproductrel as vtiger_inventoryproductrelSalesOrder on vtiger_salesorder.salesorderid = vtiger_inventoryproductrelSalesOrder.id"; 360 // To Eliminate duplicates in reports 361 if(($module == 'Products' || $module == 'Services') && $secmodule == "SalesOrder"){ 362 if($module == 'Products'){ 363 $query .= " and vtiger_inventoryproductrelSalesOrder.productid = vtiger_products.productid "; 364 }else if($module == 'Services'){ 365 $query .= " and vtiger_inventoryproductrelSalesOrder.productid = vtiger_service.serviceid "; 366 } 367 } 368 } 369 if ($queryPlanner->requireTable("vtiger_productsSalesOrder")){ 370 $query .= " left join vtiger_products as vtiger_productsSalesOrder on vtiger_productsSalesOrder.productid = vtiger_inventoryproductrelSalesOrder.productid"; 371 } 372 if ($queryPlanner->requireTable("vtiger_serviceSalesOrder")){ 373 $query .= " left join vtiger_service as vtiger_serviceSalesOrder on vtiger_serviceSalesOrder.serviceid = vtiger_inventoryproductrelSalesOrder.productid"; 374 } 375 if ($queryPlanner->requireTable("vtiger_groupsSalesOrder")){ 376 $query .= " left join vtiger_groups as vtiger_groupsSalesOrder on vtiger_groupsSalesOrder.groupid = vtiger_crmentitySalesOrder.smownerid"; 377 } 378 if ($queryPlanner->requireTable("vtiger_usersSalesOrder")){ 379 $query .= " left join vtiger_users as vtiger_usersSalesOrder on vtiger_usersSalesOrder.id = vtiger_crmentitySalesOrder.smownerid"; 380 } 381 if ($queryPlanner->requireTable("vtiger_potentialRelSalesOrder")){ 382 $query .= " left join vtiger_potential as vtiger_potentialRelSalesOrder on vtiger_potentialRelSalesOrder.potentialid = vtiger_salesorder.potentialid"; 383 } 384 if ($queryPlanner->requireTable("vtiger_contactdetailsSalesOrder")){ 385 $query .= " left join vtiger_contactdetails as vtiger_contactdetailsSalesOrder on vtiger_salesorder.contactid = vtiger_contactdetailsSalesOrder.contactid"; 386 } 387 if ($queryPlanner->requireTable("vtiger_invoice_recurring_info")){ 388 $query .= " left join vtiger_invoice_recurring_info on vtiger_salesorder.salesorderid = vtiger_invoice_recurring_info.salesorderid"; 389 } 390 if ($queryPlanner->requireTable("vtiger_quotesSalesOrder")){ 391 $query .= " left join vtiger_quotes as vtiger_quotesSalesOrder on vtiger_salesorder.quoteid = vtiger_quotesSalesOrder.quoteid"; 392 } 393 if ($queryPlanner->requireTable("vtiger_accountSalesOrder")){ 394 $query .= " left join vtiger_account as vtiger_accountSalesOrder on vtiger_accountSalesOrder.accountid = vtiger_salesorder.accountid"; 395 } 396 if ($queryPlanner->requireTable("vtiger_lastModifiedBySalesOrder")){ 397 $query .= " left join vtiger_users as vtiger_lastModifiedBySalesOrder on vtiger_lastModifiedBySalesOrder.id = vtiger_crmentitySalesOrder.modifiedby "; 398 } 399 if ($queryPlanner->requireTable("vtiger_createdbySalesOrder")){ 400 $query .= " left join vtiger_users as vtiger_createdbySalesOrder on vtiger_createdbySalesOrder.id = vtiger_crmentitySalesOrder.smcreatorid "; 401 } 402 return $query; 403 } 404 405 /* 406 * Function to get the relation tables for related modules 407 * @param - $secmodule secondary module name 408 * returns the array with table names and fieldnames storing relations between module and this module 409 */ 410 function setRelationTables($secmodule){ 411 $rel_tables = array ( 412 "Calendar" =>array("vtiger_seactivityrel"=>array("crmid","activityid"),"vtiger_salesorder"=>"salesorderid"), 413 "Invoice" =>array("vtiger_invoice"=>array("salesorderid","invoiceid"),"vtiger_salesorder"=>"salesorderid"), 414 "Documents" => array("vtiger_senotesrel"=>array("crmid","notesid"),"vtiger_salesorder"=>"salesorderid"), 415 ); 416 return $rel_tables[$secmodule]; 417 } 418 419 // Function to unlink an entity with given Id from another entity 420 function unlinkRelationship($id, $return_module, $return_id) { 421 global $log; 422 if(empty($return_module) || empty($return_id)) return; 423 424 if($return_module == 'Accounts') { 425 $this->trash('SalesOrder',$id); 426 } 427 elseif($return_module == 'Quotes') { 428 $relation_query = 'UPDATE vtiger_salesorder SET quoteid=? WHERE salesorderid=?'; 429 $this->db->pquery($relation_query, array(null, $id)); 430 } 431 elseif($return_module == 'Potentials') { 432 $relation_query = 'UPDATE vtiger_salesorder SET potentialid=? WHERE salesorderid=?'; 433 $this->db->pquery($relation_query, array(null, $id)); 434 } 435 elseif($return_module == 'Contacts') { 436 $relation_query = 'UPDATE vtiger_salesorder SET contactid=? WHERE salesorderid=?'; 437 $this->db->pquery($relation_query, array(null, $id)); 438 } else { 439 $sql = 'DELETE FROM vtiger_crmentityrel WHERE (crmid=? AND relmodule=? AND relcrmid=?) OR (relcrmid=? AND module=? AND crmid=?)'; 440 $params = array($id, $return_module, $return_id, $id, $return_module, $return_id); 441 $this->db->pquery($sql, $params); 442 } 443 } 444 445 public function getJoinClause($tableName) { 446 if ($tableName == 'vtiger_invoice_recurring_info') { 447 return 'LEFT JOIN'; 448 } 449 return parent::getJoinClause($tableName); 450 } 451 452 function insertIntoEntityTable($table_name, $module, $fileid = '') { 453 //Ignore relation table insertions while saving of the record 454 if($table_name == 'vtiger_inventoryproductrel') { 455 return; 456 } 457 parent::insertIntoEntityTable($table_name, $module, $fileid); 458 } 459 460 /*Function to create records in current module. 461 **This function called while importing records to this module*/ 462 function createRecords($obj) { 463 $createRecords = createRecords($obj); 464 return $createRecords; 465 } 466 467 /*Function returns the record information which means whether the record is imported or not 468 **This function called while importing records to this module*/ 469 function importRecord($obj, $inventoryFieldData, $lineItemDetails) { 470 $entityInfo = importRecord($obj, $inventoryFieldData, $lineItemDetails); 471 return $entityInfo; 472 } 473 474 /*Function to return the status count of imported records in current module. 475 **This function called while importing records to this module*/ 476 function getImportStatusCount($obj) { 477 $statusCount = getImportStatusCount($obj); 478 return $statusCount; 479 } 480 481 function undoLastImport($obj, $user) { 482 $undoLastImport = undoLastImport($obj, $user); 483 } 484 485 /** Function to export the lead records in CSV Format 486 * @param reference variable - where condition is passed when the query is executed 487 * Returns Export SalesOrder Query. 488 */ 489 function create_export_query($where) 490 { 491 global $log; 492 global $current_user; 493 $log->debug("Entering create_export_query(".$where.") method ..."); 494 495 include ("include/utils/ExportUtils.php"); 496 497 //To get the Permitted fields query and the permitted fields list 498 $sql = getPermittedFieldsQuery("SalesOrder", "detail_view"); 499 $fields_list = getFieldsListFromQuery($sql); 500 $fields_list .= getInventoryFieldsForExport($this->table_name); 501 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=>'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 502 503 $query = "SELECT $fields_list FROM ".$this->entity_table." 504 INNER JOIN vtiger_salesorder ON vtiger_salesorder.salesorderid = vtiger_crmentity.crmid 505 LEFT JOIN vtiger_salesordercf ON vtiger_salesordercf.salesorderid = vtiger_salesorder.salesorderid 506 LEFT JOIN vtiger_sobillads ON vtiger_sobillads.sobilladdressid = vtiger_salesorder.salesorderid 507 LEFT JOIN vtiger_soshipads ON vtiger_soshipads.soshipaddressid = vtiger_salesorder.salesorderid 508 LEFT JOIN vtiger_inventoryproductrel ON vtiger_inventoryproductrel.id = vtiger_salesorder.salesorderid 509 LEFT JOIN vtiger_products ON vtiger_products.productid = vtiger_inventoryproductrel.productid 510 LEFT JOIN vtiger_service ON vtiger_service.serviceid = vtiger_inventoryproductrel.productid 511 LEFT JOIN vtiger_contactdetails ON vtiger_contactdetails.contactid = vtiger_salesorder.contactid 512 LEFT JOIN vtiger_invoice_recurring_info ON vtiger_invoice_recurring_info.salesorderid = vtiger_salesorder.salesorderid 513 LEFT JOIN vtiger_potential ON vtiger_potential.potentialid = vtiger_salesorder.potentialid 514 LEFT JOIN vtiger_account ON vtiger_account.accountid = vtiger_salesorder.accountid 515 LEFT JOIN vtiger_currency_info ON vtiger_currency_info.id = vtiger_salesorder.currency_id 516 LEFT JOIN vtiger_quotes ON vtiger_quotes.quoteid = vtiger_salesorder.quoteid 517 LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid 518 LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid"; 519 520 $query .= $this->getNonAdminAccessControlQuery('SalesOrder',$current_user); 521 $where_auto = " vtiger_crmentity.deleted=0"; 522 523 if($where != "") { 524 $query .= " where ($where) AND ".$where_auto; 525 } else { 526 $query .= " where ".$where_auto; 527 } 528 529 $log->debug("Exiting create_export_query method ..."); 530 return $query; 531 } 532 533 /** 534 * Function which will give the basic query to find duplicates 535 * @param <String> $module 536 * @param <String> $tableColumns 537 * @param <String> $selectedColumns 538 * @param <Boolean> $ignoreEmpty 539 * @return string 540 */ 541 // Note : remove getDuplicatesQuery API once vtiger5 code is removed 542 function getQueryForDuplicates($module, $tableColumns, $selectedColumns = '', $ignoreEmpty = false) { 543 if(is_array($tableColumns)) { 544 $tableColumnsString = implode(',', $tableColumns); 545 } 546 $selectClause = "SELECT " . $this->table_name . "." . $this->table_index . " AS recordid," . $tableColumnsString; 547 548 // Select Custom Field Table Columns if present 549 if (isset($this->customFieldTable)) 550 $query .= ", " . $this->customFieldTable[0] . ".* "; 551 552 $fromClause = " FROM $this->table_name"; 553 554 $fromClause .= " INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = $this->table_name.$this->table_index"; 555 556 if($this->tab_name) { 557 foreach($this->tab_name as $tableName) { 558 if($tableName != 'vtiger_crmentity' && $tableName != $this->table_name && $tableName != 'vtiger_inventoryproductrel') { 559 if($tableName == 'vtiger_invoice_recurring_info') { 560 $fromClause .= " LEFT JOIN " . $tableName . " ON " . $tableName . '.' . $this->tab_name_index[$tableName] . 561 " = $this->table_name.$this->table_index"; 562 }elseif($this->tab_name_index[$tableName]) { 563 $fromClause .= " INNER JOIN " . $tableName . " ON " . $tableName . '.' . $this->tab_name_index[$tableName] . 564 " = $this->table_name.$this->table_index"; 565 } 566 } 567 } 568 } 569 $fromClause .= " LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid 570 LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid"; 571 572 $whereClause = " WHERE vtiger_crmentity.deleted = 0"; 573 $whereClause .= $this->getListViewSecurityParameter($module); 574 575 if($ignoreEmpty) { 576 foreach($tableColumns as $tableColumn){ 577 $whereClause .= " AND ($tableColumn IS NOT NULL AND $tableColumn != '') "; 578 } 579 } 580 581 if (isset($selectedColumns) && trim($selectedColumns) != '') { 582 $sub_query = "SELECT $selectedColumns FROM $this->table_name AS t " . 583 " INNER JOIN vtiger_crmentity AS crm ON crm.crmid = t." . $this->table_index; 584 // Consider custom table join as well. 585 if (isset($this->customFieldTable)) { 586 $sub_query .= " LEFT JOIN " . $this->customFieldTable[0] . " tcf ON tcf." . $this->customFieldTable[1] . " = t.$this->table_index"; 587 } 588 $sub_query .= " WHERE crm.deleted=0 GROUP BY $selectedColumns HAVING COUNT(*)>1"; 589 } else { 590 $sub_query = "SELECT $tableColumnsString $fromClause $whereClause GROUP BY $tableColumnsString HAVING COUNT(*)>1"; 591 } 592 593 $i = 1; 594 foreach($tableColumns as $tableColumn){ 595 $tableInfo = explode('.', $tableColumn); 596 $duplicateCheckClause .= " ifnull($tableColumn,'null') = ifnull(temp.$tableInfo[1],'null')"; 597 if (count($tableColumns) != $i++) $duplicateCheckClause .= " AND "; 598 } 599 600 $query = $selectClause . $fromClause . 601 " LEFT JOIN vtiger_users_last_import ON vtiger_users_last_import.bean_id=" . $this->table_name . "." . $this->table_index . 602 " INNER JOIN (" . $sub_query . ") AS temp ON " . $duplicateCheckClause . 603 $whereClause . 604 " ORDER BY $tableColumnsString," . $this->table_name . "." . $this->table_index . " ASC"; 605 return $query; 606 } 607 608 } 609 610 ?>
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 |