[ 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 Products_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_product_pricebooks'){ 46 $selectColumnSql = $selectColumnSql.' ,vtiger_pricebookproductrel.listprice, vtiger_pricebook.currency_id, vtiger_products.unit_price'; 47 } 48 if($functionName == 'get_service_pricebooks'){ 49 $selectColumnSql = $selectColumnSql.' ,vtiger_pricebookproductrel.listprice, vtiger_pricebook.currency_id, vtiger_service.unit_price'; 50 } 51 $query = $selectColumnSql.' FROM '.$newQuery[1]; 52 return $query; 53 } 54 55 /** 56 * Function that deletes PriceBooks related records information 57 * @param <Integer> $sourceRecordId - Product/Service Id 58 * @param <Integer> $relatedRecordId - Related Record Id 59 */ 60 public function deleteRelation($sourceRecordId, $relatedRecordId) { 61 $sourceModuleName = $this->getParentModuleModel()->get('name'); 62 $relatedModuleName = $this->getRelationModuleModel()->get('name'); 63 if(($sourceModuleName == 'Products' || $sourceModuleName == 'Services') && $relatedModuleName == 'PriceBooks') { 64 //Description: deleteListPrice function is deleting the relation between Pricebook and Product/Service 65 $priceBookModel = Vtiger_Record_Model::getInstanceById($relatedRecordId, $relatedModuleName); 66 $priceBookModel->deleteListPrice($sourceRecordId); 67 } else if($sourceModuleName == $relatedModuleName){ 68 $this->deleteProductToProductRelation($sourceRecordId, $relatedRecordId); 69 } else { 70 parent::deleteRelation($sourceRecordId, $relatedRecordId); 71 } 72 } 73 74 /** 75 * Function to delete the product to product relation(product bundles) 76 * @param type $sourceRecordId 77 * @param type $relatedRecordId true / false 78 * @return <boolean> 79 */ 80 public function deleteProductToProductRelation($sourceRecordId, $relatedRecordId) { 81 $db = PearDatabase::getInstance(); 82 if(!empty($sourceRecordId) && !empty($relatedRecordId)){ 83 $db->pquery('DELETE FROM vtiger_seproductsrel WHERE crmid = ? AND productid = ?', array($relatedRecordId, $sourceRecordId)); 84 return true; 85 } 86 } 87 88 /** 89 * Function which will specify whether the relation is deletable 90 * @return <Boolean> 91 */ 92 public function isDeletable() { 93 $relatedModuleModel = $this->getRelationModuleModel(); 94 $relatedModuleName = $relatedModuleModel->get('name'); 95 $inventoryModulesList = array('Invoice','Quotes','PurchaseOrder','SalesOrder'); 96 97 //Inventoty relationship cannot be deleted from the related list 98 if(in_array($relatedModuleName, $inventoryModulesList)){ 99 return false; 100 } 101 return parent::isDeletable(); 102 } 103 104 105 public function isSubProduct($subProductId){ 106 if(!empty($subProductId)){ 107 $db = PearDatabase::getInstance(); 108 $result = $db->pquery('SELECT crmid FROM vtiger_seproductsrel WHERE crmid = ?', array($subProductId)); 109 if($db->num_rows($result) > 0){ 110 return true; 111 } 112 } 113 } 114 115 /** 116 * Function to add Products/Services-PriceBooks Relation 117 * @param <Integer> $sourceRecordId 118 * @param <Integer> $destinationRecordId 119 * @param <Integer> $listPrice 120 */ 121 public function addListPrice($sourceRecordId, $destinationRecordId, $listPrice) { 122 $sourceModuleName = $this->getParentModuleModel()->get('name'); 123 $relatedModuleName = $this->getRelationModuleModel()->get('name'); 124 $relationModuleModel = Vtiger_Record_Model::getInstanceById($destinationRecordId, $relatedModuleName); 125 126 $productModel = Vtiger_Record_Model::getInstanceById($sourceRecordId, $sourceModuleName); 127 $productModel->updateListPrice($destinationRecordId, $listPrice, $relationModuleModel->get('currency_id')); 128 } 129 130 }
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 |