This commit is contained in:
2024-04-27 09:23:34 +02:00
commit 11e713ca6f
11884 changed files with 3263371 additions and 0 deletions

View File

@@ -0,0 +1,360 @@
<?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;
require_once('modules/EcmInvoiceOutOlds/EcmInvoiceOutOld.php');
require_once('modules/EcmInvoiceOutOlds/Forms.php');
require_once ('include/time.php');
require_once('include/json_config.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;
$focus = new EcmInvoiceOutOld();
if (isset($_REQUEST['record'])) {
$focus->retrieve($_REQUEST['record']);
$focus->format_all_fields();
if (isset($_REQUEST['status']) && $_REQUEST['status'] != '') {
$focus->doNotAccepted();
}
//echo '<pre>PL:' . var_export($focus->getPositionList(true), true);
$focus->position_list = str_replace('&quot;', '\"', $focus->getPositionList());
$t = $focus->calculate($focus->getPositionList(true));
$to_paid = format_number($focus->total);
if (!$focus->prepaid) $focus->prepaid=0;
if (!$focus->paid_val) $focus->paid_val=0;
echo $focus->prepaid.' '.$focus->paid_val;
$left = format_number($focus->total - $focus->paid_val - $focus->prepaid);
$weight_netto = $t['weight_netto'];
$OPT['status'] = $focus->status;
} else {
$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);
}
if (isset($_REQUEST['send_email']) && $_REQUEST['send_email'] == '1')
$OPT['setTab'] = 'EMAIL';
$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['invoice']['type'] = $focus->type;
$OPT['to_is_vat_free'] = $focus->to_is_vat_free;
$cq = $current_user->getPreference('confirm_invoiceouts');
$OPT['user']['confirm_invoiceouts'] = ((isset($cq) && $cq) ? 1 : 0);
$json = getJSONobj();
$w = $GLOBALS[db]->query("select name,id,value from ecmvats where deleted='0' order by name");
$nvats = mysql_num_rows($w);
while ($r = $GLOBALS[db]->fetchByAssoc($w)) {
$VAT[$r['id']] = array(
"id" => $r['id'],
"name" => $r['name'],
"value" => $r['value']
);
}
$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'];
}
global $mod_strings;
//check if errors
//add mz 2014-06-26
$error = false; //hope! always hope! :)
$what_error = array();
//check duplicate numbers
$db = $GLOBALS['db'];
$nr = $db->query("SELECT id FROM ecminvoiceoutolds WHERE deleted='0' AND canceled='0' AND document_no='$focus->document_no'");
if (intval($nr->num_rows)>1) {
$error = true;
$what_error[] = 'Duplikat numeru';
}
//check totals
if (floatval($focus->subtotal)==0 || floatval($focus->total)==0) {
$error = true;
$what_error[] = 'Zerowa wartość';
}
//correct subtotal > 0??
if ($focus->type=='correct' && (floatval($focus->subtotal>0) || floatval($focus->total)>0)) {
$error = true;
$what_error[] = 'Nieujemna korekta';
}
//check transaction
//double or not exists?
$trans = $db->query("SELECT id, value FROM ecmtransactions WHERE deleted='0' AND record_id='$focus->id'");
//echo "SELECT id, value FROM ecmtransactions WHERE deleted='0' AND record_id='$focus->id'<br>";
if (intval($trans->num_rows)!=1) {
if (floatval($focus->paid_val) != $focus->total) {
$error = true;
$what_error[] = 'Brak transakcji';
}
} else { //wrong transaction value
$t = $db->fetchByAssoc($trans);
if (floatval($t['value']) != floatval($focus->total)) {
$error = true;
$what_error[] = 'Zła wartość transakcji';
}
}
//admin can do all!
global $current_user;
if ($current_user->id=='1' || $current_user->id=='cc468949-70d1-18d4-36e7-52e785735f91') {
if ($error) var_dump($what_error);
$error = false;
}
//end mz
$scriptOpt = '<script language="javascript">
var SHOW_PDF_IN_DIV =' . $show_pdf . ';
var UNIT =' . str_replace('&quot;', '\"', $json->encode($GLOBALS['app_list_strings']['ecmproducts_unit_dom'])) . ';
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 INV_ERROR = '.($error == true ? '1':'0').';
var N;
</script>';
echo $scriptOpt;
require_once('include/MVC/View/SugarView.php');
require_once('modules/EcmInvoiceOutOlds/view/DetailView/view.detail.my.php');
$edit = new ViewDetailMy();
$edit->ss = new Sugar_Smarty();
$edit->module = 'EcmInvoiceOutOlds';
$edit->bean = $focus;
$edit->tplFile = 'include/ECM/EcmViews/DetailView/Tabs/DetailView.tpl';
$edit->bean->total = unformat_number($edit->bean->total);
$edit->preDisplay();
$arr_template = $focus->getTemplateList();
if (isset($focus->template_id))
$edit->ss->assign("DOCUMENT_TEMPLATES_OPTIONS", get_select_options_with_id($arr_template, $focus->template_id));
else
$edit->ss->assign("DOCUMENT_TEMPLATES_OPTIONS", get_select_options_with_id($arr_template, ''));
$edit->ss->assign("POSITION_LIST", $focus->position_list);
$edit->ss->assign("EMAIL_LINK", $focus->createSendEmailLink());
$edit->ss->assign("LEFT", $left);
$edit->ss->assign("TO_PAID", $to_paid);
$edit->ss->assign("WEIGHT_TOTAL", $weight_netto);
// get corrects or corrected invoices
$db = $GLOBALS['db'];
if ($focus->type == 'correct') {
$ret = $db->query ( "
SELECT distinct o.ecminvoiceout_id
FROM
ecminvoiceoutitems as ii
INNER JOIN ecminvoiceouts as i
ON ii.ecminvoiceout_id = i.id
INNER JOIN ecminvoiceoutitems AS o
ON o.id = ii.ecminvoiceoutitem_id
WHERE
ii.ecminvoiceout_id = '$focus->id'" );
$inv = "";
while ($row = $db->fetchByAssoc($ret)) {
$i = $db->fetchByAssoc($db->query("SELECT id, document_no FROM ecminvoiceouts WHERE id ='".$row['ecminvoiceout_id']."'"));
$inv.='<a href="index.php?module=EcmInvoiceOuts&action=DetailView&record='.$i['id'].'" target="new">'.$i['document_no'].'</a>,&nbsp';
}
} else if ($focus->type == 'normal') {
$ret = $db->query( "
SELECT DISTINCT c.document_no, c.id FROM
ecminvoiceoutitems as ic #items from correstc
INNER JOIN ecminvoiceouts AS c #correct
ON c.id = ic.ecminvoiceout_id
WHERE
ic.ecminvoiceoutitem_id IN (
SELECT id FROM ecminvoiceoutitems WHERE
ecminvoiceout_id='".$focus->id."'
)
AND c.deleted='0' AND c.canceled='0';
");
while ($i = $db->fetchByAssoc($ret)) {
$inv.='<a href="index.php?module=EcmInvoiceOuts&action=DetailView&record='.$i['id'].'" target="new">'.$i['document_no'].'</a>,&nbsp';
}
}
$edit->ss->assign ( "INVOICES_INFO", substr($inv,0,-6) );
$email_link_tab = '<script language="javascript">YAHOO.util.Event.addListener(window,"load",function(){setEMAIL = function(){' . $focus->createSendEmailLink() . '}});</script>';
$desc.='<input title="Generuj PDF" class="button" onclick="if(document.getElementById(\'div_desc\').style.display==\'none\')document.getElementById(\'div_desc\').style.display=\'block\';else document.getElementById(\'div_desc\').style.display=\'none\';" type="button" name="productcard" id="productcard" value="Generuj PDF">';
$desc .= '<div id="div_desc" style="border: 1px solid #cccccc;background:#e6e6e6;padding:5px;position:absolute;display:none;">';
$desc .= 'Typ: <select name="preview_type" id="preview_type"><option value>Faktura</option><option value="exp">Lista rozchodowa</option><option value="pl">Specyfikacja wysyłki</option></select><br /><br />';
$desc.='<input name="quote_pdf" id="quote_pdf" title="Show PDF" accessKey="" class="button" onclick="window.open(\'index.php?module=EcmInvoiceOutOlds&action=previewPDF&to_pdf=1&preview_type=\'+document.getElementById(\'preview_type\').value+\'&record='.$_REQUEST['record'].'\',\'_blank\');" type="button" value="Pokaż PDF">';
$edit->ss->assign("CATALOGUE",$desc);
$edit->ss->assign("EMAIL_LINK_TAB", $email_link_tab);
$r = $GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select id from ecmstockdoccorrects where ecminvoiceoutold_id='" . $focus->id . "'"));
if ($r['id'])
$edit->ss->assign("hasCorrect", $r['id']);
$edit->ss->assign("OPT", $OPT);
echo $edit->display();
/*
$GLOBALS['focus'] = $focus;
require_once('include/SubPanel/SubPanelTiles.php');
$subpanel = new SubPanelTiles($this->bean, $this->module);
//get available list of subpanels
$alltabs=$subpanel->subpanel_definitions->get_available_tabs();
if (!empty($alltabs)) {
//iterate through list, and filter out all but 3 subpanels
foreach ($alltabs as $key=>$name) {
if ($name != 'prospectlists' && $name!='emailmarketing' && $name != 'tracked_urls') {
//exclude subpanels that are not prospectlists, emailmarketing, or tracked urls
$subpanel->subpanel_definitions->exclude_tab($name);
}
}
//only show email marketing subpanel for email/newsletter campaigns
if ($this->bean->campaign_type != 'Email' && $this->bean->campaign_type != 'NewsLetter' ) {
//exclude subpanels that are not prospectlists, emailmarketing, or tracked urls
$subpanel->subpanel_definitions->exclude_tab('emailmarketing');
}
}
//show filtered subpanel list
echo $subpanel->display();
*/
/*
$_REQUEST['type'] = 'out';
$_REQUEST['parent_id'] = (isset($focus->id) && $focus->id != '')? $focus->id : '';
$_REQUEST['parent_type'] = 'EcmInvoiceOutOlds';
$_REQUEST['record'] = '';
$ob = '';
ob_start();
require_once('modules/EcmInvoiceOutOlds/Emails.php');
$ob = ob_get_contents();
ob_end_clean();
$mod_strings = return_module_language($current_language, 'EcmInvoiceOutOlds');
$edit->ss->assign("EMAILS",$ob);
*/
/*
require_once('include/SubPanel/SubPanelTiles.php');
$subpanel = new SubPanelTiles($focus, 'EcmInvoiceOutOlds');
echo $subpanel->display();
*/
echo '<div id="subpanels_div">';
require_once('subpanels.php');
echo '</div>';