Files
crm.twinpol.com/modules/EcmInsideOrders.cp/EditView.php
2025-05-12 15:44:39 +00:00

359 lines
13 KiB
PHP
Executable File

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
//require_once('modules/EcmGroupSales/HeaderMenu.php');
global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings, $current_user, $app_list_strings;
require_once('modules/EcmInsideOrders/EcmInsideOrder.php');
require_once('modules/EcmInsideOrders/Forms.php');
require_once ('include/time.php');
require_once('include/json_config.php');
require_once('include/Upload.php');
$json_config = new json_config();
$file = 'modules/EcmGroupSales/EcmGroupSale.php';
if(file_exists($file)) {
$cc = array();
require_once($file);
$cc = EcmGroupSale::loadSettings();
}
$OPT = array();
$OPT['row_item_height'] = $cc['row_item_height'];
$OPT['row_item_height_selected'] = $cc['row_item_height_selected'];
$OPT['rows_on_item_list'] = $cc['rows_on_item_list'];
$OPT['position_table_height'] = $OPT['row_item_height']*$OPT['rows_on_item_list']+40+$OPT['rows_on_item_list']*4;
$OPT['quick_product_item_adding'] = $cc['quick_product_item_adding'];
if($cc['checkbox_demo'] == 1) {
$query = "SELECT COUNT(id) as count FROM ecminsideorders WHERE deleted='0'";
$result = $GLOBALS['db']->query($query);
if(is_resource($result)) {
$row = $GLOBALS['db']->fetchByAssoc($result);
if(isset($row['count']) && is_numeric($row['count']=intval($row['count'])) && $row['count'] >= 10) $OPT['checkbox_demo'] = 1;
}
}
//$OPT['default_manager_role_id'] = $cc['default_manager_role_id'];
//$OPT['default_representative_role_id'] = $cc['default_representative_role_id'];
//$OPT['default_representative_extra_role_id'] = $cc['default_representative_extra_role_id'];
$OPT['check_parent_id'] = true;
$cq = $current_user->getPreference('confirm_quotes');
$OPT['user']['confirm_quotes'] = ((isset($cq) && $cq)?1:0);
$focus = new EcmInsideOrder();
$OPT['auto_commiting'] = $focus->ACLAccess('auto_commiting');
if(isset($_REQUEST['record'])) {
$focus->retrieve($_REQUEST['record']);
if(isset($focus->id) && $focus->id != '') {
if($focus->accepted == 1) {
echo 'You cannot edit this quote. This quote is accepted. <a href="index.php?module='.$_REQUEST['return_module'].'&action='.$_REQUEST['return_action'].'&record='.$_REQUEST['return_id'].'">return</a>';
return;
}
$focus->format_all_fields();
$focus->position_list = str_replace('&quot;','\"',$focus->getPositionList());
}
} else {
if(isset($_REQUEST['contact_id']) && $_REQUEST['contact_id'] != '' && isset($_REQUEST['contact_name']) && $_REQUEST['contact_name'] != '') {
$_REQUEST['parent_type'] = 'Contacts';
$_REQUEST['parent_name'] = $_REQUEST['contact_name'];
$_REQUEST['parent_id'] = $_REQUEST['contact_id'];
$OPT['check_parent_id'] = false;
}
if(isset($_REQUEST['account_id']) && $_REQUEST['account_id'] != '' && isset($_REQUEST['account_name']) && $_REQUEST['account_name'] != '') {
$_REQUEST['parent_type'] = 'Accounts';
$_REQUEST['parent_name'] = $_REQUEST['account_name'];
$_REQUEST['parent_id'] = $_REQUEST['account_id'];
$OPT['check_parent_id'] = false;
}
$OPT['new_number'] = true;
//$focus->status = "s10";
if(isset($cc)) {
//payment condition
$cc_list = EcmGroupSale::getPositionList('ecmpaymentconditions');
$focus->ecmpaymentcondition_id = $cc['default_payment_condition'];
$focus->ecmpaymentcondition_name = $cc_list[$cc['default_payment_condition']];
//delivery condition
$cc_list = EcmGroupSale::getPositionList('ecmdeliveryconditions');
$focus->ecmdeliverycondition_id = $cc['default_delivery_condition'];
$focus->ecmdeliverycondition_name = $cc_list[$cc['default_delivery_condition']];
//default template
$focus->template_id = $cc['default_document_template'];
$fftemplateid = $focus->template_id;
}
}
//if access 'Delete' is avaible for user than he is Manager and he can confirm Quotes.
$OPT['user']['access']['send_email'] = $focus->ACLAccess("send_email");
//$OPT['old_status'] = (isset($focus->status) && $focus->status != '')?$focus->status:'registered';
if($_REQUEST['isDuplicate'] == 'true') { $_POST['isDuplicate'] = true; $focus->id = ''; $OPT['isDuplicate'] = ture; $OPT['new_number'] = true; }
if(!isset($focus->discount) || $focus->discount == '') $focus->discount = '0.00';
if($OPT['new_number'] == true) {
$datef = $current_user->getPreference('datef');
if($datef != '') $sugar_config['datef'];
$focus->register_date = date($datef);
$focus->payment_date = date($datef,mktime()+30*24*60*60);
$focus->sell_date = date($datef);
}
include_once("modules/EcmSales/productionHelper.php");
if($_GET['production']==1){
if(count($_REQUEST['check'])>0){
foreach($_REQUEST['check'] as $ch){
$return_array=array();
$rp=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select * from ecmproducts where id='".$ch."'"));
$sales=getSalesLast3m($rp['id']);
$guid=create_guid();
$return_array['id'] = $rp['id'];
$return_array['code'] = $rp['code'];
$return_array['name'] = $rp['name'];
$return_array['quantity'] = floor($sales/2);
$return_array['prod_quantity'] = "";
$return_array['price'] = $rp['ems_price'];
$return_array['total'] = $rp['moq']*$rp['ems_price'];
$return_array['component'] = "";
$return_array['component_quantity'] = "";
$return_array['product_id'] = "";
$return_array['guid'] = $guid;
$rrr[]=$return_array;
$wc=$GLOBALS['db']->query("select ecmproduct_id as product_id,ecmcomponent_id as id,name,code,quantity from ecmproductcomponents where ecmproduct_id='".$rp['id']."' and deleted='0'");
while($rc=$GLOBALS['db']->fetchByAssoc($wc)){
$return_array=array();
$return_array['id'] = $rc['product_id'];
$return_array['code'] = $rc['code'];
$return_array['name'] = $rc['name'];
$return_array['quantity'] = $rp['moq']*$rc['quantity'];
$return_array['prod_quantity'] = "";
$return_array['price'] = 0;
$return_array['total'] = 0;
$return_array['component'] = 1;
$return_array['component_quantity'] = $rc['quantity'];
$return_array['product_id'] = $rp['id'];
$return_array['guid'] = $guid;
$rrr[]=$return_array;
}
}
$json = getJSONobj();
$focus->position_list = str_replace('&quot;','\"',$json->encode($rrr));
}
}
$tmp = $current_user->getPreference('num_grp_sep');
if(!isset($tmp) || $tmp == '' || $tmp == NULL) $tmp = $sugar_config['default_number_grouping_seperator'];
$OPT['sep_1000'] = $tmp;
$tmp = $current_user->getPreference('dec_sep');
if(!isset($tmp) || $tmp == '' || $tmp == NULL) $tmp = $sugar_config['default_decimal_seperator'];
$OPT['dec_sep'] = $tmp;
$tmp = $current_user->getPreference('default_currency_significant_digits');
if(!isset($tmp) || $tmp == '' || $tmp == NULL) $tmp = $sugar_config['default_currency_significant_digits'];
$OPT['dec_len'] = $tmp;
$OPT['default_unit'] = "1";
$OPT['default_vat'] = "19.00";
$OPT['default_category'] = "";
$OPT['default_currency'] = "-99";
$OPT['type'] = $focus->type;
$OPT['to_is_vat_free'] = $focus->to_is_vat_free;
require_once('modules/EcmTexts/EcmText.php');
foreach($app_list_strings['ecmlanguages_dom'] as $key => $value) {
$data = EcmText::LoadText(null,null,"EcmInsideOrders",$key);
if(isset($data[0]) && isset($data[0]['data'])) $d = $data[0]['data']; else {
$d = $PDFLL;
if(!isset($d['labels'])) $d['labels'] = $PDFLL['labels'];
if(!isset($d['texts']['Contacts']['header_text'])) $d['texts']['Contacts']['header_text'] = $mod_strings['LBL_DEFAULT_CONTACT_HEADER_TEXT'];
if(!isset($d['texts']['Contacts']['footer_text'])) $d['texts']['Contacts']['footer_text'] = $mod_strings['LBL_DEFAULT_CONTACT_FOOTER_TEXT'];
if(!isset($d['texts']['Contacts']['ads_text'])) $d['texts']['Contacts']['ads_text'] = $mod_strings['LBL_DEFAULT_CONTACT_ADS_TEXT'];
if(!isset($d['texts']['Accounts']['header_text'])) $d['texts']['Accounts']['header_text'] = $mod_strings['LBL_DEFAULT_ACCOUNT_HEADER_TEXT'];
if(!isset($d['texts']['Accounts']['footer_text'])) $d['texts']['Accounts']['footer_text'] = $mod_strings['LBL_DEFAULT_ACCOUNT_FOOTER_TEXT'];
if(!isset($d['texts']['Accounts']['ads_text'])) $d['texts']['Accounts']['ads_text'] = $mod_strings['LBL_DEFAULT_ACCOUNT_ADS_TEXT'];
}
$OPT['ecmlanguage'][$key]['texts'] = $d['texts'];
}
$w=$GLOBALS['db']->query("select name,id,value from ecmvats where deleted='0' order by name");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$VAT[$r['id']]=array(
"id"=>$r['id'],
"name"=>$r['name'],
"value"=>$r['value']
);
$nvats++;
}
$show_pdf=$current_user->getPreference('show_pdf_in_div');
if(!isset($show_pdf)){
require_once('modules/EcmGroupSales/EcmGroupSale.php');
$cc = EcmGroupSale::loadSettings();
$show_pdf=$cc['show_pdf_in_div_global'];
}
$json = getJSONobj();
$scriptOpt = '<script language="javascript">
var SHOW_PDF_IN_DIV ='.$show_pdf.';
var NOOFVATS ='.$nvats.';
var VAT = '.str_replace('&quot;','\"',$json->encode($VAT)).';
var OPT = '.str_replace('&quot;','\"',$json->encode($OPT)).';
var MOD = '.str_replace('&quot;','\"',$json->encode($mod_strings)).';
var N;
</script>';
$larr=array("en_us","pl_pl","ge_ge");
foreach($larr as $la){
$lv=return_app_list_strings_language($la);
$UNIT_LANG[$la]=$lv['ecmproducts_unit_dom'];
}
$scriptOpt.='<script language="javascript">
var UNIT_LANG='.str_replace('&quot;','\"',$json->encode($UNIT_LANG)).';
</script>';
echo $scriptOpt;
require_once('include/MVC/View/SugarView.php');
require_once('modules/EcmInsideOrders/views/EditView/view.edit.ecminsideorders.php');
$edit = new ViewEditEcmInsideOrders();
$edit->ss = new Sugar_Smarty();
$edit->bean = $focus;
$edit->tplFile = 'include/ECM/EcmViews/EditView/Tabs/EditView.tpl';
$edit->module = 'EcmInsideOrders';
$edit->ss->assign("OPT",$OPT);
$edit->preDisplay();
//load currencies
require_once('modules/Currencies/Currency.php');
$currency = new Currency();
$currency_list = $currency->get_full_list('name');
$currency->retrieve('-99');
if(is_array($currency_list))
{
$currency_list = array_merge(Array($currency), $currency_list);
}
else
{
$currency_list = Array($currency);
}
$arr = array();
foreach($currency_list as $key=>$value)
{
$arr[$value->id] = $value->name;
}
$edit->ss->assign("EXCHANGE_RATE",get_select_options_with_id($arr, $focus->exchange_rate_id));
if(isset($fftemplateid) && $fftemplateid != '') $focus->template_id = $fftemplateid;
$arr_template = $focus->getTemplateList();
$tt="";
$w=$GLOBALS['db']->query("select name,id,deleted,date_modified from ecmdocumenttemplates where deleted='0' or id='".$focus->template_id."'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if($r['deleted']==1 && $_REQUEST['record']){
$tt.='<option value="'.$r['id'].'"';
if($r['id']==$focus->template_id)$tt.=' selected';
$tt.='>'.$r['name'].' till '.$r['date_modified'].'</option>';
}
elseif($r['deleted']==0){
$tt.='<option value="'.$r['id'].'"';
if($r['id']==$focus->template_id)$tt.=' selected';
$tt.='>'.$r['name'].'</option>';
}
}
$edit->ss->assign("DOCUMENT_TEMPLATES_OPTIONS", $tt);
$rdoc=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select * from ecminsideorders where id='".$_REQUEST['record']."'"));
$w=$GLOBALS['db']->query("select name,id from ecmstocks where deleted='0' order by name asc");
$rw='<option value=""></option>';
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$rw.='<option value="'.$r['id'].'"';
if($r['id']==$rdoc['rw_stock_id'])$rw.=' selected';
$rw.='>'.$r['name'].'</option>';
}
$edit->ss->assign("RW_STOCK", $rw);
$w=$GLOBALS['db']->query("select name,id from ecmstocks where deleted='0' order by name asc");
$pw='<option value=""></option>';
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$pw.='<option value="'.$r['id'].'"';
if($r['id']==$rdoc['pw_stock_id'])$pw.=' selected';
$pw.='>'.$r['name'].'</option>';
}
$edit->ss->assign("PW_STOCK", $pw);
$earr=array(
'Darek' => 'Darek',
'Helena' => 'Helena',
'Emila' => 'Emila',
'Bogusia Serymoch' => 'Bogusia Serymoch',
'Marcin Popławski' => 'Marcin Popławski',
);
foreach($earr as $ea){
$eas.='<option value="'.$ea.'"';
if(in_array($ea,explode("|",$rdoc['employers'])))$eas.=' selected';
$eas.='>'.$ea.'</option>';
}
$edit->ss->assign("EMPLOYERS", $eas);
$edit->ss->assign("POSITION_LIST",$focus->position_list);
$edit->ss->assign("MFP",$focus->loadParserArray());
echo $edit->display();
?>