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

157 lines
7.9 KiB
PHP
Executable File

<?php
ini_set('display_errors',1);
global $db;
require_once('include/utils.php');
$stop = new DateTime('NOW');
$start = clone $stop;
$start->sub(new DateInterval('P3Y'));
$currentTo = @$_GET['date_to'] ? : $stop->format('t.m.Y');
$currentFrom = @$_GET['date_from'] ? : $start->format('01.m.Y');
include_once ("include/MPDF57/mpdf.php");
$p = new mPDF ( '', 'A4', null, 'helvetica', 8, 8, 30, 30, 5, 5 );
$mpdf->mirrorMargins = 1;
$i=0;
if(isset($_GET['process'])){
echo 'AAAA';
$additionalWhereConditions = array(
'\'' . $start->format('Y-m-01') . '\'',
'\'' . $stop->format('Y-m-t') . '\'',
);
if($from = @$_GET['date_from']) {
$fromDate = new DateTime($from);
$additionalWhereConditions[0] = '\'' . $fromDate->format('Y-m-d') . '\'';
}
if($to = @$_GET['date_to']) {
$toDate = new DateTime($to);
$additionalWhereConditions[1] = '\'' . $toDate->format('Y-m-d') . '\'';
}
if($_GET['kasjer']!=''){
$kasjer=" and `created_by`='".$_GET['kasjer']."'";
}
$additionalWhere = '`date_entered` BETWEEN ' . implode(' AND ', $additionalWhereConditions)." and `ecmcash_id`='".$_GET['ecmcash_id']."'".$kasjer;
$query = '
SELECT
`description`,`ecmkpkw_name`,`amount`,`document_no`,
`parent_address_street`,`parent_address_city`,`parent_address_postalcode`,
`parent_address_country`,`parent_contact_name`,`parent_contact_title`,
`date_entered`,`dir`,`parent_name`
FROM `ecmkpkw`
WHERE
' . (additionalWhere ? ($additionalWhere) : '') . '
ORDER BY
`date_entered` ASC;
';
$result = $db->query($query);
$query_bo = "SELECT SUM(IF(dir = 0, amount, -amount)) AS `sum` FROM `ecmkpkw` WHERE `date_entered` < ".$additionalWhereConditions[0]." and `ecmcash_id`='".$_GET['ecmcash_id']."'".$kasjer;
//echo $query_bo; exit;
$result_bo = $db->query($query_bo);
if($row_bo = $db->fetchByAssoc($db->query($query_bo)))
{
$bo = $row_bo["sum"];
//ECHO $row["sum"];
}
$tabelka='<br><br><table style="padding-top: 0px; margin-top:0px; border: 0.1 solid black; border-collapse: collapse;width:100%;font-size: 10pt;">
<thead>
<tr style="border: 0.1 solid black;">
<th style="border: 0.1 solid black; width:3%; height:50px;background-color: #E6E6FA;">Lp</th>
<th style="border: 0.1 solid black; width:18%;background-color: #E6E6FA;">Nr dokumentu<br>Data wystawienia</th>
<th style="border: 0.1 solid black; width:24%;background-color: #E6E6FA;">Tytuł</th>
<th style="border: 0.1 solid black; width:24%;background-color: #E6E6FA;">Kontrahent</th>
<th style="border: 0.1 solid black; width:15%;background-color: #E6E6FA;">Przychód</th>
<th style="border: 0.1 solid black; width:15%;background-color: #E6E6FA;">Rozchód </th>
</tr>
</thead>';
$suma1=0;
$suma2=0;
while($row = $db->fetchByAssoc($result)){
if($row['dir']==0) { $liczba1=format_number($row['amount']); $suma1 += $row['amount']; } else $liczba1="&nbsp;";
if($row['dir']==1) { $liczba2=format_number($row['amount']); $suma2 += $row['amount']; } else $liczba2="&nbsp;";
$i++;
$tabelka.='<tr style="border: 0.1 solid black;">
<td style="border: 0.1 solid black; width:3%;font-size: 8pt;text-align:center;">'.$i.'</td>
<td style="border: 0.1 solid black; width:18%;font-size: 8pt;text-align:center;"><table><tr style="width:100%;font-size: 8pt;"><td style="width:100%;font-size: 8pt;">'.$row['document_no'].'</td></tr><tr style="width:100%;"><td style="width:100%;font-size: 8pt;">'.date("d.m.Y", strtotime($row['date_entered'])).'</td></tr></table></td>
<td style="border: 0.1 solid black; width:24%;font-size: 8pt;text-align:left;">&nbsp;'.$row['ecmkpkw_name'].'</td>
<td style="border: 0.1 solid black; width:24%;font-size: 8pt;text-align:left;">&nbsp;'.$row['parent_name'].'</td>
<td style="border: 0.1 solid black; width:15%;font-size: 8pt;text-align:right;">'.$liczba1.'</td>
<td style="border: 0.1 solid black; width:15%;font-size: 8pt;text-align:right;">'.$liczba2.'</td>
</tr>';
}
$tabelka.='</table>';
}
$tabelka.='<br>
<table style="padding-top: 0px; margin-top:0px; border: 0 solid black; border-collapse: collapse;width:100%;font-size: 10pt;">
<tr>
<td style="border: 0 solid black; width:3%;font-size: 8pt;text-align:center;"></td>
<td style="border: 0 solid black; width:18%;font-size: 8pt;text-align:center;"></td>
<td style="border: 0 solid black; width:24%;font-size: 8pt;text-align:left;"></td>
<td style="border: 0.1 solid black; width:24%;font-size: 8pt;text-align:left;">'.translate('LBL_VALUE', 'EcmKpkw').':</td>
<td style="border: 0.1 solid black; width:15%;font-size: 8pt;text-align:right;">'.format_number(($suma1)).'</td>
<td style="border: 0.1 solid black; width:15%;font-size: 8pt;text-align:right;">'.format_number(($suma2)).'</td>
</tr>
<tr>
<td style="border: 0 solid black; width:3%;font-size: 8pt;text-align:center;"></td>
<td style="border: 0 solid black; width:18%;font-size: 8pt;text-align:center;"></td>
<td style="border: 0 solid black; width:24%;font-size: 8pt;text-align:left;"></td>
<td style="border: 0.1 solid black; width:24%;font-size: 8pt;text-align:left;">'.translate('LBL_VALUE_BEFORE', 'EcmKpkw').':</td>
<td style="border: 0.1 solid black; width:15%;font-size: 8pt;text-align:right;">'.format_number(($bo)).'</td>
<td style="border: 0.1 solid black; width:15%;font-size: 8pt;text-align:right;"></td>
</tr>
<tr>
<td style="border: 0 solid black; width:3%;font-size: 8pt;text-align:center;"></td>
<td style="border: 0 solid black; width:18%;font-size: 8pt;text-align:center;"></td>
<td style="border: 0 solid black; width:24%;font-size: 8pt;text-align:left;"></td>
<td style="border: 0.1 solid black; width:24%;font-size: 8pt;text-align:left;">'.translate('LBL_VALUE_TOTAL', 'EcmKpkw').':</td>
<td style="border: 0.1 solid black; width:15%;font-size: 8pt;text-align:right;">'.format_number((($bo+$suma1)-$suma2)).'</td>
<td style="border: 0.1 solid black; width:15%;font-size: 8pt;text-align:right;"></td>
</tr>
</table>';
$header='<h2 style="text-align:center;">'.translate('LBL_RAPORT_TITLE2', 'EcmKpkw').'</h2>
<table style="width: 100%;">
<tr>
<td style="width: 70%;"></td>
<td style="width: 10%;font-size: 8pt;"><b>'.translate('LBL_TIME2', 'EcmKpkw').':</b></td>
<td style="width: 20%;font-size: 8pt;">'.$fromDate->format('d.m.Y')." - ".$toDate->format('d.m.Y').'</td>
</tr>
<tr>
<td style="width: 70%;"></td>
<td style="width: 10%;font-size: 8pt;"><b>'.translate('LBL_CASH2', 'EcmKpkw').':</b></td>
<td style="width: 20%;font-size: 8pt;">'.$_GET['cash_name'].'</td>
</tr>
<tr>
<td style="width: 70%;"></td>
<td style="width: 10%;font-size: 8pt;"><b>'.translate('LBL_CURRENCY_PDF2', 'EcmKpkw').':</b></td>
<td style="width: 20%;font-size: 8pt;">'.$_GET['id_currency'].'</td>
</tr>';
if($_GET['kasjer']!=''){
$us=new User;
$us->retrieve($_GET['kasjer']);
$header.=' <tr>
<td style="width: 70%;"></td>
<td style="width: 10%;font-size: 8pt;"><b>Kasjer:</b></td>
<td style="width: 20%;font-size: 8pt;">'. $us->full_name.'</td>
</tr>';
}
$header.='</table>';
$p->SetHTMLHeader ( $header );
$p->WriteHTML ($tabelka );
$p->Output ();
echo $header;