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

179 lines
5.4 KiB
PHP

<?php
if (!$_REQUEST['settings'] || $_REQUEST['settings']=="")
die('Błąd parametrów');
$tmp = base64_decode($_REQUEST['settings']);;
$settings = objectToArray(json_decode($tmp));
$module = $settings['module'];
$fields = $settings['fields'];
$table = $settings['table'];
$where = base64_decode($settings['where']);
//vd($settings, true);
if($where!=''){
$where.=' and '.strtolower($module).'.deleted=0 ';
} else {
$where.=' '.strtolower($module).'.deleted=0 ';
}
if( $_SESSION[$module.'_order']!=''){
$where.=' order by '.$_SESSION[$module.'_order'];
}
$l = return_module_language('pl_pl', $module);
global $app_strings;
$l = array_merge($l, $app_strings);
include "modules/$module/metadata/listviewdefs.php";
$lvd = $listViewDefs[$module];
$db = $GLOBALS['db'];
$html = '<h1>'.$l['LBL_LIST_FORM_TITLE'].'</h1>';
if ($settings['date_from'] || $settings['date_to'] || is_array($settings['stocks']) || $settings['ecmproductstockindex_id']
|| is_array($settings['stocks_in']) || is_array($settings['stocks_out'])) {
$html.='Kryteria wyszukiwania:<br>';
if ($settings['date_from'] && $settings['date_from']!="")
$html.="Data od:&nbsp;".$settings['date_from'].'<br>';
if ($settings['date_to'] && $settings['date_to']!="")
$html.="Data od:&nbsp;".$settings['date_to'].'<br>';
if (is_array($settings['stocks'])) {
require_once 'modules/EcmStocks/EcmStock.php';
$html.="Magazyn:&nbsp;";
foreach ($settings['stocks'] as $k=>$v) {
$s = new EcmStock();
$s->retrieve($v);
$html.=$s->name;
unset($s);
}
$html.='<br>';
}
if (is_array($settings['stocks_out'])) {
require_once 'modules/EcmStocks/EcmStock.php';
$html.="Z magazynu:&nbsp;";
foreach ($settings['stocks_out'] as $k=>$v) {
$s = new EcmStock();
$s->retrieve($v);
$html.=$s->name;
unset($s);
}
$html.='<br>';
}
if (is_array($settings['stocks_in'])) {
require_once 'modules/EcmStocks/EcmStock.php';
$html.="Na magazyn:&nbsp;";
foreach ($settings['stocks_in'] as $k=>$v) {
$s = new EcmStock();
$s->retrieve($v);
$html.=$s->name;
unset($s);
}
$html.='<br>';
}
if ($settings['ecmproductstockindex_id'] && $settings['ecmproductstockindex_id']!="") {
$k = new EcmProductStockIndex();
$k->retrieve($settings['ecmproductstockindex_id']);
$html.='Kartoteka materiałowa: '.$k->name.'<br>';
}
$html.='<br>';
}
$html .= '<table style="width: 100%; font-size: 7pt; border: 0.5 solid black; border-collapse: collapse"><thead><tr>';
foreach ($settings['fields'] as $name => $v) {
if ($v['name'] == 'options') continue;
if ($l[$v['label']] && $l[$v['label']]!="")
$label = $l[$v['label']];
elseif ($lvd[strtoupper($v['name'])]['label'] && $lvd[strtoupper($v['name'])]['label']!="")
$label = $lvd[strtoupper($v['name'])]['label'];
else
$label = "&nbsp;";
if ($lvd[strtoupper($v['name'])]['align'] && $lvd[strtoupper($v['name'])]['align']!="")
$align = $lvd[strtoupper($v['name'])]['align'];
else
$align="left";
$html.='<th style="border: 1 solid black;background: rgb(233,233,233); text-align: '.$align.';">'.$label.'</th>';
}
$html.='</tr></thead><tbody>';
$q = "SELECT id FROM $table ";
if ($where && $where!="")
$q.=" WHERE $where";
$res = $db->query($q);
$m = substr($module,0,-1);
while ($row = $db->fetchByAssoc($res)) {
$bean = new $m();
$f = $bean->retrieve($row['id']);
$the_array = $f->get_list_view_data();
$html.='<tr>';
foreach ($settings['fields'] as $k=>$v) {
if ($v['name'] == 'options') continue;
if ($lvd[strtoupper($v['name'])]['align'] && $lvd[strtoupper($v['name'])]['align']!="")
$align = $lvd[strtoupper($v['name'])]['align'];
else
$align="left";
if($bean->canceled==1){
$html.='<td style="padding-left: 5px; border: 0.5 solid black; text-align: '.$align.';background: rgb(233,233,233);"><strike>'.$the_array[strtoupper($v['name'])].'<strike></td>';
} else {
$html.='<td style="padding-left: 5px; border: 0.5 solid black; text-align: '.$align.';">'.$the_array[strtoupper($v['name'])].'</td>';
}
}
$html.='</tr>';
unset($bean);
}
if ($settings['showSum'] == "1") {
$html.='<tr>';
foreach ($settings['fields'] as $k=>$v) {
if ($v['name'] == 'options') continue;
if ($lvd[strtoupper($v['name'])]['align'] && $lvd[strtoupper($v['name'])]['align']!="")
$align = $lvd[strtoupper($v['name'])]['align'];
else
$align="left";
if ($v['summary'] && $v['summary']!="")
$s = $v['summary'];
else
$s = '&nbsp;';
$html.='<td style="padding-left: 5px; border: 0.5 solid black; text-align: '.$align.';font-weight:bold">'.$v['summary'].'</td>';
}
$html.='</tr>';
}
$html.='</tbody></table>';
include_once ("include/MPDF57/mpdf.php");
$p = new mPDF('', 'A4', null, 'helvetica', 10, 10, 30, 45, 5, 5);
$p->mirrorMargins = 1;
//$p->DisableTags('');
$p->WriteHTML($html);
$p->Output("$module-list.pdf", "I");
//helper
function vd($v, $die = false) {
echo '<pre>'; var_dump($v); echo '</pre>';
if ($die == true) die();
}
function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
}
else {
// Return array
return $d;
}
}