Files
crm.twinpol.com/modules/EcmProductB2Bs/ListViewAddToPriceBook.php
2025-05-12 15:44:39 +00:00

295 lines
15 KiB
PHP
Executable File

<?php
/*****************************************************************************
* The contents of this file are subject to the RECIPROCAL PUBLIC LICENSE
* Version 1.1 ("License"); You may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/rpl.php. Software distributed under the
* License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
* either express or implied.
*
* You may:
* a) Use and distribute this code exactly as you received without payment or
* a royalty or other fee.
* b) Create extensions for this code, provided that you make the extensions
* publicly available and document your modifications clearly.
* c) Charge for a fee for warranty or support or for accepting liability
* obligations for your customers.
*
* You may NOT:
* a) Charge for the use of the original code or extensions, including in
* electronic distribution models, such as ASP (Application Service
* Provider).
* b) Charge for the original source code or your extensions other than a
* nominal fee to cover distribution costs where such distribution
* involves PHYSICAL media.
* c) Modify or delete any pre-existing copyright notices, change notices,
* or License text in the Licensed Software
* d) Assert any patent claims against the Licensor or Contributors, or
* which would in any way restrict the ability of any third party to use the
* Licensed Software.
*
* You must:
* a) Document any modifications you make to this code including the nature of
* the change, the authors of the change, and the date of the change.
* b) Make the source code for any extensions you deploy available via an
* Electronic Distribution Mechanism such as FTP or HTTP download.
* c) Notify the licensor of the availability of source code to your extensions
* and include instructions on how to acquire the source code and updates.
* d) Grant Licensor a world-wide, non-exclusive, royalty-free license to use,
* reproduce, perform, modify, sublicense, and distribute your extensions.
*
* The Original Code is: CommuniCore
* Olavo Farias
* 2006-04-7 olavo.farias@gmail.com
*
* The Initial Developer of the Original Code is CommuniCore.
* Portions created by CommuniCore are Copyright (C) 2005 CommuniCore Ltda
* All Rights Reserved.
********************************************************************************/
if($_GET['end_of_line_advanced']==0 && $_GET['end_of_line_advanced']!="")$_GET['end_of_line_advanced']="no";
if($_GET['production_advanced']==0 && $_GET['production_advanced']!="")$_GET['production_advanced']="no";
if($_GET['flag_advanced']==0 && $_GET['flag_advanced']!="")$_GET['flag_advanced']="no";
if($_GET['end_of_line_basic']==0 && $_GET['end_of_line_basic']!="")$_GET['end_of_line_basic']="no";
if($_GET['production_basic']==0 && $_GET['production_basic']!="")$_GET['production_basic']="no";
if($_GET['flag_basic']==0 && $_GET['flag_basic']!="")$_GET['flag_basic']="no";
$_REQUEST['clear_query']=true;
$_GET['clear_query']=true;
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select user_name from users where id='".$_SESSION['authenticated_user_id']."'"));
$user_name=$r['user_name'];
$arr_fields=array("name","code","product_category_name","product_category_id","flag","manufacturer_name","manufacturer_id","product_active","commission_rate","qty_per_unit","purchase_price","sales_start_date","sales_end_date","end_of_line","production");
/*if(!$_REQUEST['EcmProductB2Bs_ECMPRODUCT_offset'] && !$_REQUEST['EcmProductB2Bs_ECMPRODUCT_ORDER_BY']){
foreach($arr_fields as $a){
if($_REQUEST['searchFormTab']=="advanced_search")$_SESSION[$user_name."_PREFERENCES"]['global']['EcmProductB2BsQ'][$a.'_advanced']=$_REQUEST[$a.'_advanced']=$_GET[$a.'_advanced'];
if($_REQUEST['searchFormTab']=="basic_search")$_SESSION[$user_name."_PREFERENCES"]['global']['EcmProductB2BsQ'][$a.'_basic']=$_REQUEST[$a.'_basic']=$_GET[$a.'_basic'];
}
}
else{
foreach($arr_fields as $a){
if($_REQUEST['searchFormTab']=="advanced_search"){
$_REQUEST[$a.'_advanced']=$_SESSION[$user_name."_PREFERENCES"]['global']['EcmProductB2BsQ'][$a.'_advanced'];
$_GET[$a.'_advanced']=$_SESSION[$user_name."_PREFERENCES"]['global']['EcmProductB2BsQ'][$a.'_advanced'];
}
if($_REQUEST['searchFormTab']=="basic_search"){
$_REQUEST[$a.'_basic']=$_SESSION[$user_name."_PREFERENCES"]['global']['EcmProductB2BsQ'][$a.'_basic'];
$_GET[$a.'_basic']=$_SESSION[$user_name."_PREFERENCES"]['global']['EcmProductB2BsQ'][$a.'_basic'];
}
}
}*/
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
if($_REQUEST['pricebook_id'])$_SESSION['add_to_pricebook_id']=$_REQUEST['pricebook_id'];
require_once ('XTemplate/xtpl.php');
require_once ("data/Tracker.php");
require_once ('modules/EcmProductB2Bs/EcmProductB2B.php');
require_once ('themes/'.$theme.'/layout_utils.php');
require_once ('log4php/LoggerManager.php');
require_once('include/ListView/ListViewSmarty.php');
require_once('include/ListView/ListView.php');
require_once('modules/Currencies/Currency.php');
if(file_exists('custom/modules/EcmProductB2Bs/metadata/listviewdefs.php')){
require_once('custom/modules/EcmProductB2Bs/metadata/listviewdefs.php');
}
else{
require_once('modules/EcmProductB2Bs/metadata/listviewdefs.php');
}
require_once('modules/SavedSearch/SavedSearch.php');
require_once('include/SearchForm/SearchForm.php');
$header_text = '';
global $app_strings;
global $mod_strings;
global $app_list_strings;
global $current_language;
$current_module_strings = return_module_language($current_language, 'EcmProductB2Bs');
global $urlPrefix;
global $currentModule;
global $theme;
global $current_user;
global $focus_list;
require_once('include/QuickSearchDefaults.php');
$qsd = new QuickSearchDefaults();
$currentModule="EcmProductB2Bs";
echo "\n<p>\n";
echo get_module_title($mod_strings['LBL_MODULE_ID'], $mod_strings['LBL_MODULE_NAME'], true);
echo "\n</p>\n";
if(!empty($_REQUEST['clear_query']) && $_REQUEST['clear_query'] == 'true')$current_user->setPreference('ListViewDisplayColumns', array(), 0, $currentModule);
$savedDisplayColumns = $current_user->getPreference('ListViewDisplayColumns', $currentModule);
$json = getJSONobj();
$seedEcmProductB2B = new EcmProductB2B();
$searchForm = new SearchForm('EcmProductB2Bs', $seedEcmProductB2B,"ListViewAddToPricebook");
$lv = new ListViewSmarty();
$displayColumns = array();
foreach($listViewDefs['EcmProductB2Bs'] as $col => $params) {
if(!empty($params['default']) && $params['default'])$displayColumns[$col] = $params;
}
$params = array('massupdate' => true);
$params['action']="ListViewAddToPriceBook";
if(!empty($_REQUEST['orderBy'])) {
$params['orderBy'] = $_REQUEST['orderBy'];
$params['overrideOrder'] = true;
if(!empty($_REQUEST['sortOrder'])) $params['sortOrder'] = $_REQUEST['sortOrder'];
}
$lv->displayColumns = $displayColumns;
if (!isset($where)) $where = "";
require_once('modules/MySettings/StoreQuery.php');
$storeQuery = new StoreQuery();
if(!isset($_REQUEST['query'])){
$storeQuery->loadQuery($currentModule);
$storeQuery->populateRequest();
}
else{
$storeQuery->saveFromRequest($currentModule);
}
if(isset($_REQUEST['query'])){
$current_user->setPreference('ListViewDisplayColumns', $displayColumns, 0, $currentModule);
$searchForm->populateFromRequest();
foreach($searchForm->searchFields as $k=>$v){
$searchForm->searchFields[$k]['value']=$_SESSION[$user_name."_PREFERENCES"]['global']['EcmProductB2BsQ'][$k.'_advanced'];
}
$where_clauses = $searchForm->generateSearchWhere(true, "EcmProductB2B");
if (count($where_clauses) > 0 ){
foreach($where_clauses as $wh){
if(!eregi("ecmproducts.assigned_user_id",$wh) && !eregi("ecmproducts.product_category_name",$wh) && !eregi("ecmproducts.product_active",$wh) && !eregi("ecmproducts.end_of_line",$wh))$wwh[]=$wh;
}
$where_clauses=array();
$where_clauses=$wwh;
}
if(count($searchForm->searchFields['assigned_user_id']['value'])>0){
$w_clauses=array();
foreach($searchForm->searchFields['assigned_user_id']['value'] as $auid){
$w_clauses[]="ecmproducts.assigned_user_id='".$auid."'";
}
$where_clauses[]="(".implode(" or ",$w_clauses).")";
}
if($_REQUEST['searchFormTab']=="advanced_search"){
if($_GET['end_of_line_advanced']!="" && ($_GET['end_of_line_advanced']==1 || $_GET['end_of_line_advanced']=="no")){
if($_GET['end_of_line_advanced']=="no")$where_clauses[]="ecmproducts.end_of_line='0'";
else $where_clauses[]="ecmproducts.end_of_line='1'";
}
if($_GET['flag_advanced']!="" && ($_GET['flag_advanced']==1 || $_GET['flag_advanced']=="no")){
if($_GET['flag_advanced']=="no")$where_clauses[]="ecmproducts.flag='0'";
else $where_clauses[]="ecmproducts.flag='1'";
}
if($_GET['production_advanced']!="" && ($_GET['production_advanced']==1 || $_GET['production_advanced']=="no")){
if($_GET['production_advanced']=="no")$where_clauses[]="ecmproducts.production='0'";
else $where_clauses[]="ecmproducts.production='1'";
}
if($_GET['manufacturer_id_advanced'])$where_clauses[]="ecmproducts.manufacturer_id='".$_GET['manufacturer_id_advanced']."'";
if($_GET['product_category_id_advanced'])$where_clauses[]="ecmproducts.product_category_id='".$_GET['product_category_id_advanced']."'";
if($_GET['product_category_name_advanced'])$where_clauses[]="ecmproducts.product_category_name like '".$_GET['product_category_name_advanced']."%'";
if($_GET['product_active_advanced']==0 && $_GET['product_active_advanced']!="")$where_clauses[]="ecmproducts.product_active='0'";
if($_GET['product_active_advanced']==1 && $_GET['product_active_advanced']!="")$where_clauses[]="ecmproducts.product_active='1'";
if($_GET['code_advanced'])$where_clauses[]="ecmproducts.code like '%".$_GET['code_advanced']."%'";
if($_GET['name_advanced'])$where_clauses[]="ecmproducts.name like '%".$_GET['name_advanced']."%'";
}
if($_REQUEST['searchFormTab']=="basic_search"){
if($_GET['flag_basic']!="" && ($_GET['flag_basic']==1 || $_GET['flag_basic']=="no")){
if($_GET['flag_basic']=="no")$where_clauses[]="ecmproducts.flag='0'";
else $where_clauses[]="ecmproducts.flag='1'";
}
if($_GET['production_basic']!="" && ($_GET['production_basic']==1 || $_GET['production_basic']==0))$where_clauses[]="ecmproducts.production='".$_GET['production_basic']."'";
if($_GET['manufacturer_id_basic'])$where_clauses[]="ecmproducts.manufacturer_id='".$_GET['manufacturer_id_basic']."'";
if($_GET['product_category_id_basic'])$where_clauses[]="ecmproducts.product_category_id='".$_GET['product_category_id_basic']."'";
if($_GET['product_category_name_basic'])$where_clauses[]="ecmproducts.product_category_name like '".$_GET['product_category_name_basic']."%'";
if($_GET['product_active_basic']==0 && $_GET['product_active_basic']!="")$where_clauses[]="ecmproducts.product_active='0'";
if($_GET['product_active_basic']==1 && $_GET['product_active_basic']!="")$where_clauses[]="ecmproducts.product_active='1'";
if($_GET['code_basic'])$where_clauses[]="ecmproducts.code like '%".$_GET['code_basic']."%'";
if($_GET['name_basic'])$where_clauses[]="ecmproducts.name like '%".$_GET['name_basic']."%'";
}
if($_SESSION['add_to_pricebook_id']){
$w=$GLOBALS['db']->query("select ecmproduct_id from ecmpricebooks_ecmproducts where ecmpricebook_id='".$_SESSION['add_to_pricebook_id']."' and deleted='0'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$where_clauses[]="ecmproducts.id!='".$r['ecmproduct_id']."'";
}
}
if (count($where_clauses) > 0 )$where = implode(' and ', $where_clauses);
$GLOBALS['log']->info("Here is the where clause for the list view: $where");
}
$searchForm->lv=$lv;
if(!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
$searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl', "advanced", $listViewDefs);
if(isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') {
$searchForm->displayAdvanced(true);
}
elseif(isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'saved_views'){
$searchForm->displaySavedViews($listViewDefs, $lv);
}
else {
$searchForm->displayBasic(true);
}
}
//print_r($searchForm->searchFields);
echo $qsd->GetQSScripts();
$ListView = new ListView();
$ListView->show_mass_update = false;
$ListView->show_mass_update_form = false;
$ListView->multiSelect=false;
$ListView->show_export_button = false;
$ListView->show_delete_button = false;
$ListView->show_select_menu = false;
$ListView->initNewXTemplate('modules/EcmProductB2Bs/ListView1.html',$current_module_strings);
$ListView->setHeaderTitle($current_module_strings['LBL_LIST_FORM_TITLE']);
$ListView->setQuery($where, "", "ecmproducts.name asc", "ECMPRODUCT");
$ListView->processListView($seedEcmProductB2B, "main", "ECMPRODUCT");
$savedSearch = new SavedSearch();
$json = getJSONobj();
$savedSearchSelects = $json->encode(array($GLOBALS['app_strings']['LBL_SAVED_SEARCH_SHORTCUT'] . '<br>' . $savedSearch->getSelect('EcmProductB2Bs')));
$str = "<script>YAHOO.util.Event.addListener(window, 'load', SUGAR.util.fillShortcuts, $savedSearchSelects);</script>";
echo '<input type="hidden" name="pricebook_id" value="'.$_REQUEST['pricebook_id'].'">';
echo '</form>';
if(!$_REQUEST['searchFormTab'])$sft="basic_search";
else $sft=$_REQUEST['searchFormTab'];
echo '<script language="javascript">selectTabCSS(\'EcmProductB2Bs|'.$sft.'\');';echo '</script>';
echo '<script>setTimeout(function(){';
foreach($arr_fields as $v){
if($_REQUEST['searchFormTab']=="advanced_search"){
if(!in_array($v,array("end_of_line","product_active","flag","production")))echo 'if(document.getElementById("'.$v.'_advanced"))document.getElementById("'.$v.'_advanced").value="'.$_REQUEST[$v.'_advanced'].'";
';
elseif(in_array($v,array("end_of_line","product_active","flag","production")) && $_GET[$v.'_advanced']=="no")echo 'if(document.getElementById("'.$v.'_advanced"))document.getElementById("'.$v.'_advanced")[1].selected="1";
';
elseif(in_array($v,array("end_of_line","product_active","flag","production")) && $_REQUEST[$v.'_advanced']==1)echo 'if(document.getElementById("'.$v.'_advanced"))document.getElementById("'.$v.'_advanced")[2].selected="1";
';
//else echo 'if(document.getElementById("'.$v.'_advanced"))document.getElementById("'.$v.'_advanced").value="'.$_REQUEST[$v.'_advanced'].'";';
}
if($_REQUEST['searchFormTab']=="basic_search"){
if(!in_array($v,array("end_of_line","product_active","flag","production")))echo 'if(document.getElementById("'.$v.'_basic"))document.getElementById("'.$v.'_basic").value="'.$_REQUEST[$v.'_basic'].'";
';
if(in_array($v,array("end_of_line","product_active","flag","production")) && $_GET[$v.'_basic']=="no")echo 'if(document.getElementById("'.$v.'_basic"))document.getElementById("'.$v.'_basic")[1].selected="1";
';
if(in_array($v,array("end_of_line","product_active","flag","production")) && $_REQUEST[$v.'_basic']==1)echo 'if(document.getElementById("'.$v.'_basic"))document.getElementById("'.$v.'_basic")[2].selected="1";
';
//else echo 'if(document.getElementById("'.$v.'_basic"))document.getElementById("'.$v.'_basic").value="'.$_REQUEST[$v.'_basic'].'";';
}
}
echo '},1700);</script>';
echo $str;
?>