191 lines
9.2 KiB
PHP
191 lines
9.2 KiB
PHP
<?php
|
|
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
|
|
die ( 'Not A Valid Entry Point' );
|
|
|
|
global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings;
|
|
|
|
require_once ('modules/EcmInvoiceOuts/EcmInvoiceOut.php');
|
|
|
|
require_once ('include/time.php');
|
|
|
|
require_once ('include/json_config.php');
|
|
|
|
// add jquery
|
|
echo '<link rel="stylesheet" type="text/css" href="include/jQuery/jquery-table/jquery.appendGrid-1.3.1.css"/>';
|
|
echo '<link rel="stylesheet" type="text/css" href="include/jQuery/jquery-ui/themes/base/jquery-ui.css"/>';
|
|
echo '<script type="text/javascript" src="include/jQuery/jquery-2.1.0.min.js"></script>';
|
|
echo '<script type="text/javascript" src="include/jQuery/jquery-table/jquery.appendGrid-1.3.1.js"></script>';
|
|
echo '<script type="text/javascript" src="include/jQuery/jquery-ui/ui/jquery-ui.js"></script>';
|
|
|
|
$json_config = new json_config ();
|
|
|
|
$focus = new EcmInvoiceOut ();
|
|
|
|
if (isset ( $_REQUEST ['record'] )) {
|
|
$focus->retrieve ( $_REQUEST ['record'] );
|
|
$focus->format_all_fields ();
|
|
|
|
$OPT ['status'] = $focus->status;
|
|
}
|
|
|
|
// move to archive
|
|
if (strtotime ( $focus->register_date ) <= strtotime ( "2014-11-02" ))
|
|
header ( "Location: index.php?module=EcmInvoiceOutOlds&action=DetailView&record=" . $focus->id );
|
|
|
|
require_once ('include/MVC/View/SugarView.php');
|
|
|
|
require_once ('modules/EcmInvoiceOuts/views/DetailView/view.detail.my.php');
|
|
|
|
// create position list table
|
|
$pl = $focus->getPositionList ();
|
|
|
|
$edit = new ViewDetailMy ();
|
|
$edit->ss = new Sugar_Smarty ();
|
|
$edit->module = 'EcmInvoiceOuts';
|
|
|
|
// add pdf buttons
|
|
|
|
$btn = '<input name="quote_pdf" id="quote_pdf" title="Show PDF" accessKey="" class="button" onclick="window.open(\'index.php?module=EcmInvoiceOuts&action=createPDF&to_pdf=1&show_img=\'+$(\'#pdf_images\').val()+\'&show_ean=\'+$(\'#pdf_ean\').val()+\'&show_ean2=\'+$(\'#pdf_ean2\').val()+\'&show_recipient_code=\'+$(\'#pdf_recipient_code\').val()+\'&show_remarks=\'+$(\'#pdf_remarks\').val()+\'&record=' . $_REQUEST ['record'] . '\',\'_blank\');" type="button" value="Pokaż PDF"></div>';
|
|
$edit->ss->assign ( "CREATE_PDF", $btn );
|
|
|
|
$btn = '<input title="Generuj Katalog" class="button" onclick="if($(\'#div_cat\').css(\'display\') == \'none\'){$(\'#div_cat\').show(\'slow\'); } else { $(\'#div_cat\').hide(\'slow\'); }" type="button" name="productcat" id="productcat" value="Generuj Katalog">';
|
|
$btn .= '<div id="div_cat" style="border: 1px solid #cccccc;background:#e6e6e6;padding:5px;position:absolute;display:none;">';
|
|
$btn .= 'EAN: <select name="cat_ean" id="cat_ean"><option value="1">1</option><option value="2">2</option><option value="0">Brak</option></select><br /><br />';
|
|
$btn .= '<input name="cat_pdf" id="cat_pdf" title="Show Cat" accessKey="" class="button" onclick="window.open(\'index.php?module=EcmInvoiceOuts&action=createCatalogue&to_pdf=1&show_ean=\'+$(\'#cat_ean\').val()+\'&record=' . $_REQUEST ['record'] . '\',\'_blank\');" type="button" value="Pokaż Katalog"></div>';
|
|
$edit->ss->assign ( "CATALOGUE", $btn );
|
|
|
|
$btn = '<input title="Generuj XLS" class="button" onclick="if($(\'#div_xls\').css(\'display\') == \'none\'){$(\'#div_xls\').show(\'slow\'); } else { $(\'#div_xls\').hide(\'slow\'); }" type="button" name="productxls" id="productxls" value="Generuj XLS">';
|
|
$btn .= '<div id="div_xls" style="border: 1px solid #cccccc;background:#e6e6e6;padding:5px;position:absolute;display:none;">';
|
|
$btn .= 'EAN: <select name="xls_ean" id="xls_ean"><option value="1">1</option><option value="2">2</option><option value="0">Brak</option></select><br /><br />';
|
|
$btn .= '<input name="cat_xls" id="cat_xls" title="Generuj XLS" accessKey="" class="button" onclick="window.open(\'index.php?module=EcmInvoiceOuts&action=createXLS&to_pdf=1&show_ean=\'+$(\'#xls_ean\').val()+\'&record=' . $_REQUEST ['record'] . '\',\'_blank\');" type="button" value="Pokaż XLS"></div>';
|
|
$edit->ss->assign ( "CREATE_XLS", $btn );
|
|
$create_cor = false;
|
|
if ($focus->type != 'correct') {
|
|
$create_cor = true;
|
|
}
|
|
$can_edit = false;
|
|
global $current_user;
|
|
if (is_admin ( $current_user )){
|
|
$can_edit = true;
|
|
}
|
|
|
|
if($focus->wz_id!=""){
|
|
$a = new EcmStockDocOut();
|
|
$a->retrieve($focus->wz_id);
|
|
|
|
$wz_array[] = "<a target='_blank' href='index.php?module=EcmStockDocOuts&action=DetailView&record=$a->id'>".$a->document_no."</a>";
|
|
}
|
|
|
|
if($focus->wz_record_zb!=""){
|
|
$wzIds=explode(",",($focus->wz_record_zb));
|
|
|
|
foreach ($wzIds as $id){
|
|
if($id!=""){
|
|
$a = new EcmStockDocOut();
|
|
$a->retrieve($id);
|
|
|
|
$wz_array[] = "<a target='_blank' href='index.php?module=EcmStockDocOuts&action=DetailView&record=$a->id'>".$a->document_no."</a>";
|
|
}
|
|
}
|
|
}
|
|
|
|
$edit->ss->assign("wz_no",implode(',',$wz_array));
|
|
|
|
$a = new EcmSale();
|
|
$a->retrieve($focus->so_id);
|
|
$the_array ['ZS_NO'] = "<a target='_blank' href='index.php?module=EcmSales&action=DetailView&record=$a->id'>".$a->document_no."</a>";
|
|
$edit->ss->assign("zs_no", $the_array ['ZS_NO']);
|
|
|
|
$edit->ss->assign ( "CAN_EDIT", $can_edit );
|
|
$edit->ss->assign ( "CREATE_COR", $create_cor );
|
|
$edit->ss->assign ( "CREATED_BY_NAME", $focus->created_by_name );
|
|
$edit->ss->assign ( "MODIFIED_BY_NAME", $focus->modified_by_name );
|
|
$edit->ss->assign("CAN_CREATE_PZ", $focus->parent_id=='1b9643ca-5b1a-8f9b-b809-586b5619b068' && $focus->type=='normal' && strtotime($focus->register_date) > strtotime("19.01.2023"));
|
|
// 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>, ';
|
|
}
|
|
} 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>, ';
|
|
}
|
|
}
|
|
$edit->ss->assign ( "INVOICES_INFO", substr($inv,0,-6) );
|
|
|
|
if ($focus->parent_id === '1b9643ca-5b1a-8f9b-b809-586b5619b068') {
|
|
require_once('REST/config.php');
|
|
|
|
$curl = curl_init();
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET' );
|
|
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
|
curl_setopt($curl, CURLOPT_URL, 'https://crm.twinpol.com/REST/index.php?action=getStocks&key='.$restConfig['twinpolKey']);
|
|
$twinpolStocks = json_decode(curl_exec($curl));
|
|
|
|
$btn ='<input title="Utwórz PZ w Twinpol" class="button" onclick="if($(\'#div_pz\').css(\'display\') == \'none\'){$(\'#div_pz\').show(\'slow\'); } else { $(\'#div_pz\').hide(\'slow\'); }" type="button" name="create_pz" id="create_pz" value="Utwórz PZ w Twinpol">';
|
|
$btn .= '<div id="div_pz" style="border: 1px solid #cccccc;background:#e6e6e6;padding:5px;position:absolute;display:none;">';
|
|
$btn .= 'Magazyn: <select name="pz_stock" id="pz_stock">';
|
|
foreach ($twinpolStocks as $s) {
|
|
$btn .= '<option value="'.$s->id.'">'.$s->name.'</option>';
|
|
}
|
|
$btn .= '</select><br /><br />';
|
|
$btn .= '<input name="pz_btn" id="pz_btn" title="Create" accessKey="" class="button" onclick="window.open(\'https://crm.twinpol.com/REST/index.php?action=createPzFromInvoice&stock_id=\'+$(\'#pz_stock\').val()+\'&record='.$_REQUEST['record'].'&key='.$restConfig['twinpolKey'].'\',\'blank\');" type="button" value="Utwórz"></div>';
|
|
|
|
$edit->ss->assign('CREATE_PZ', $btn);
|
|
}
|
|
$edit->bean = $focus;
|
|
$edit->tplFile = 'include/ECM/EcmViews/DetailView/Tabs/DetailView.tpl';
|
|
|
|
$edit->preDisplay ();
|
|
|
|
// check number
|
|
$db = $GLOBALS ['db'];
|
|
$res = $db->query ( "SELECT id FROM ecminvoiceouts WHERE document_no='$focus->document_no' AND deleted='0'" );
|
|
if ($res->num_rows > 1) {
|
|
echo '<h1 style="color: red;">Błąd numeracji, skontaktuj się z administratorem! Nie drukuj/publikuj dokumentu!</h1>';
|
|
}
|
|
// check total
|
|
if ($focus->total_netto == 0) {
|
|
echo '<h1 style="color: red;">Błąd sumy, skontaktuj się z administratorem! Nie drukuj/publikuj dokumentu!</h1>';
|
|
}
|
|
// is canceled
|
|
if ($focus->canceled == 1) {
|
|
echo '<h1 style="color: red;">Faktura anulowana! Nie publikuj dokumentu!</h1>';
|
|
}
|
|
|
|
echo $edit->display ();
|
|
|
|
require_once ('include/SubPanel/SubPanelTiles.php');
|
|
$subpanel = new SubPanelTiles ( $focus, 'EcmInvoiceOuts' );
|
|
echo $subpanel->display ();
|
|
// loading view
|
|
echo '<link rel="stylesheet" type="text/css" href="modules/EcmInvoiceOuts/javascript/helper.css" media="screen" /><div class="loading_panel"></div>';
|
|
?>
|