[ 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 class PriceBooks_Relation_Model extends Vtiger_Relation_Model{ 12 13 /** 14 * Function returns the Query for the relationhips 15 * @param <Vtiger_Record_Model> $recordModel 16 * @param type $actions 17 * @return <String> 18 */ 19 public function getQuery($recordModel, $actions=false){ 20 $parentModuleModel = $this->getParentModuleModel(); 21 $relatedModuleModel = $this->getRelationModuleModel(); 22 $relatedModuleName = $relatedModuleModel->get('name'); 23 $parentModuleName = $parentModuleModel->get('name'); 24 $functionName = $this->get('name'); 25 $focus = CRMEntity::getInstance($parentModuleName); 26 $focus->id = $recordModel->getId(); 27 if(method_exists($parentModuleModel, $functionName)) { 28 $query = $parentModuleModel->$functionName($recordModel, $relatedModuleModel); 29 } else { 30 $result = $focus->$functionName($recordModel->getId(), $parentModuleModel->getId(), 31 $relatedModuleModel->getId(), $actions); 32 $query = $result['query']; 33 } 34 35 //modify query if any module has summary fields, those fields we are displayed in related list of that module 36 $relatedListFields = $relatedModuleModel->getConfigureRelatedListFields(); 37 if(count($relatedListFields) > 0) { 38 $currentUser = Users_Record_Model::getCurrentUserModel(); 39 $queryGenerator = new QueryGenerator($relatedModuleName, $currentUser); 40 $queryGenerator->setFields($relatedListFields); 41 $selectColumnSql = $queryGenerator->getSelectClauseColumnSQL(); 42 $newQuery = spliti('FROM', $query); 43 $selectColumnSql = 'SELECT DISTINCT vtiger_crmentity.crmid,'.$selectColumnSql; 44 } 45 if($functionName == ('get_pricebook_products' || 'get_pricebook_services')){ 46 $selectColumnSql = $selectColumnSql.', vtiger_pricebookproductrel.listprice'; 47 } 48 $query = $selectColumnSql.' FROM '.$newQuery[1]; 49 return $query; 50 } 51 52 /** 53 * Function to add PriceBook-Products/Services Relation 54 * @param <Integer> $sourceRecordId 55 * @param <Integer> $destinationRecordId 56 * @param <Integer> $listPrice 57 */ 58 public function addListPrice($sourceRecordId, $destinationRecordId, $listPrice) { 59 $sourceModuleName = $this->getParentModuleModel()->get('name'); 60 61 $priceBookModel = Vtiger_Record_Model::getInstanceById($sourceRecordId, $sourceModuleName); 62 $priceBookModel->updateListPrice($destinationRecordId, $listPrice); 63 } 64 65 /** 66 * Function that deletes PriceBooks related records information 67 * @param <Integer> $sourceRecordId - PriceBook Id 68 * @param <Integer> $relatedRecordId - Related Record Id 69 */ 70 public function deleteRelation($sourceRecordId, $relatedRecordId){ 71 $sourceModuleName = $this->getParentModuleModel()->get('name'); 72 $destinationModuleName = $this->getRelationModuleModel()->get('name'); 73 if($sourceModuleName == 'PriceBooks' && ($destinationModuleName == 'Products' || $destinationModuleName == 'Services')) { 74 $priceBookModel = Vtiger_Record_Model::getInstanceById($sourceRecordId, $sourceModuleName); 75 $priceBookModel->deleteListPrice($relatedRecordId); 76 } else { 77 parent::deleteRelation($sourceRecordId, $relatedRecordId); 78 } 79 } 80 }
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 |