303 lines
9.2 KiB
PHP
303 lines
9.2 KiB
PHP
|
|
<?php
|
||
|
|
require_once ('include/utils.php');
|
||
|
|
$data = array();
|
||
|
|
$date_from = date("Y-M-D");
|
||
|
|
$date_to = date("Y-m-d");
|
||
|
|
|
||
|
|
$tmp3 = array();
|
||
|
|
$vat_id;
|
||
|
|
|
||
|
|
|
||
|
|
// Ustawienia daty
|
||
|
|
if (!$_GET ['date_from']) {
|
||
|
|
$date_from = date("Y-M-01");
|
||
|
|
} else {
|
||
|
|
$date_from = $_GET ['date_from'];
|
||
|
|
}
|
||
|
|
if (!$_GET ['date_to']) {
|
||
|
|
$date_to = date("Y-m-d");
|
||
|
|
} else {
|
||
|
|
$date_to = $_GET ['date_to'];
|
||
|
|
}
|
||
|
|
// formatowanie daty
|
||
|
|
$Calendar_daFormat = str_replace("d", "%d", str_replace("m", "%m", str_replace("Y", "%Y", $GLOBALS ['timedate']->get_date_format())));
|
||
|
|
$date_from = $GLOBALS ['timedate']->to_display_date($date_from);
|
||
|
|
$date_to = $GLOBALS ['timedate']->to_display_date($date_to);
|
||
|
|
$date = new DateTime ();
|
||
|
|
$current_date_formatted = $date->format('d.m.Y');
|
||
|
|
|
||
|
|
|
||
|
|
$category = $GLOBALS['app_list_strings'] ['document_category_dom'];
|
||
|
|
|
||
|
|
$category_list = array('invoice_costs' => $category['invoice_costs'], 'invoice_goods'=> $category['invoice_goods']);
|
||
|
|
$category= array();
|
||
|
|
|
||
|
|
if (isset ( $_GET ['category'] )) {
|
||
|
|
foreach ( $_GET ['category'] as $selectedOption ) {
|
||
|
|
array_push($category, $selectedOption);
|
||
|
|
}
|
||
|
|
}else {
|
||
|
|
$category = array('invoice_costs' => $category['invoice_costs'], 'invoice_goods'=> $category['invoice_goods']);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
global $app_list_strings;
|
||
|
|
global $mod_strings;
|
||
|
|
$db = $GLOBALS ['db'];
|
||
|
|
|
||
|
|
$subquery = "SELECT id
|
||
|
|
FROM documents
|
||
|
|
WHERE deleted= '0'
|
||
|
|
AND register_date >= STR_TO_DATE('" . $date_from . "','%d.%m.%Y')
|
||
|
|
AND register_date <= STR_TO_DATE('" . $date_to . "','%d.%m.%Y') ";
|
||
|
|
|
||
|
|
$query = " SELECT
|
||
|
|
acc.id accid,
|
||
|
|
dcn.id document_id,
|
||
|
|
dcn.parent_id,
|
||
|
|
dcn.document_number,
|
||
|
|
dcn.document_date,
|
||
|
|
dcn.category_id,
|
||
|
|
dcn.register_date,
|
||
|
|
acc.name,
|
||
|
|
acc.register_address_city,
|
||
|
|
acc.register_address_postalcode,
|
||
|
|
acc.register_address_street,
|
||
|
|
acc.to_vatid
|
||
|
|
|
||
|
|
FROM
|
||
|
|
documents_accounts da
|
||
|
|
LEFT JOIN
|
||
|
|
documents dcn ON da.document_id = dcn.id
|
||
|
|
|
||
|
|
LEFT JOIN
|
||
|
|
accounts acc ON da.parent_id = acc.id
|
||
|
|
WHERE
|
||
|
|
da.parent_type = 'Account'
|
||
|
|
AND da.deleted = '0'";
|
||
|
|
$checkifselected =array();
|
||
|
|
foreach ($category as $key => $val){
|
||
|
|
$checkifselected[$val] = '';
|
||
|
|
}
|
||
|
|
if (isset($checkifselected['invoice_costs']) && (!isset($checkifselected['invoice_goods'])))
|
||
|
|
{
|
||
|
|
$query.=" AND category_id = 'invoice_costs'";
|
||
|
|
}
|
||
|
|
else if (!isset($checkifselected['invoice_costs']) && (isset($checkifselected['invoice_goods'])))
|
||
|
|
{
|
||
|
|
$query.=" AND category_id = 'invoice_goods'";
|
||
|
|
}
|
||
|
|
else if (isset($checkifselected['invoice_costs']) && (isset($checkifselected['invoice_goods'])))
|
||
|
|
{
|
||
|
|
$query.=" AND (category_id = 'invoice_costs'
|
||
|
|
OR category_id = 'invoice_goods') ";
|
||
|
|
}
|
||
|
|
|
||
|
|
unset($checkifselected);
|
||
|
|
$query .= "AND dcn.id IN (SELECT
|
||
|
|
id
|
||
|
|
FROM
|
||
|
|
documents
|
||
|
|
WHERE
|
||
|
|
deleted = '0'
|
||
|
|
AND dcn.register_date IS NOT NULL
|
||
|
|
AND dcn.id IN (" . $subquery . "))
|
||
|
|
ORDER BY dcn.document_name";
|
||
|
|
|
||
|
|
|
||
|
|
$rows = $db->query($query);
|
||
|
|
while ($r = $db->fetchByAssoc($rows)) {
|
||
|
|
$row = array();
|
||
|
|
$queryvat = 'SELECT
|
||
|
|
id,
|
||
|
|
document_id,
|
||
|
|
vat_value,
|
||
|
|
vat_id,
|
||
|
|
netto,
|
||
|
|
vat
|
||
|
|
FROM
|
||
|
|
documents_vat where document_id = "' . $r ['document_id'] . '"
|
||
|
|
AND deleted = "0"
|
||
|
|
AND netto > "0"
|
||
|
|
ORDER BY position';
|
||
|
|
|
||
|
|
$rowsv = $db->query($queryvat);
|
||
|
|
$row ['vaty'] = array();
|
||
|
|
$row ['vatsumapozycja'] = 0;
|
||
|
|
$sumabrutto = 0;
|
||
|
|
while ($rr = $db->fetchByAssoc($rowsv)) {
|
||
|
|
$tmp2 = array();
|
||
|
|
$tmp2 ['vat_value'] = $rr ['vat_value'];
|
||
|
|
$tmp2 ['vat_id'] = $rr ['vat_id'];
|
||
|
|
$tmp2 ['netto'] = $rr ['netto'];
|
||
|
|
$tmp2 ['vat'] = $rr ['vat'];
|
||
|
|
$tmp2 ['sumabrutto'] += $rr['vat'] + $rr['netto'];
|
||
|
|
$row ['vatsumapozycja'] += $rr ['vat'];
|
||
|
|
$row ['value'] += $rr ['netto'] + $rr ['vat'];
|
||
|
|
$row ['vaty'] [] = $tmp2;
|
||
|
|
if (isset($tmp3 [$rr ['vat_value']])) {
|
||
|
|
$tmp3 [$rr ['vat_value']] ['sumanetto'] += $rr ['netto'];
|
||
|
|
$tmp3 [$rr ['vat_value']] ['sumavat'] += $rr ['vat'];
|
||
|
|
$sumanetto += $rr ['netto'];
|
||
|
|
$sumavat += $rr['vat'];
|
||
|
|
$sumabrutto += $sumanetto + $sumavat;
|
||
|
|
|
||
|
|
} else {
|
||
|
|
$tmp3 [$rr ['vat_value']] = array();
|
||
|
|
$tmp3 [$rr ['vat_value']] ['sumanetto'] = $rr ['netto'];
|
||
|
|
$tmp3 [$rr ['vat_value']] ['sumavat'] = $rr ['vat'];
|
||
|
|
$sumanetto += $rr ['netto'];
|
||
|
|
$sumavat += $rr['vat'];
|
||
|
|
$sumabrutto += $sumanetto + $sumavat;
|
||
|
|
}
|
||
|
|
|
||
|
|
$porownanie = ($tmp3[$rr['vat_value']]);
|
||
|
|
$tablica_z_podzielonymi_wartosciami_procentow = str_split($rr['vat_value']);
|
||
|
|
$suma_czarow=0;
|
||
|
|
foreach($tablica_z_podzielonymi_wartosciami_procentow as $key=>$t)
|
||
|
|
{ $suma_czarow += ord($t);}
|
||
|
|
$tab=(ord($tablica_z_podzielonymi_wartosciami_procentow));
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$row ['document_id'] = $r ['document_id'];
|
||
|
|
$row ['id'] = $r ['accid'];
|
||
|
|
$row ['document_number'] = $r ['document_number'];
|
||
|
|
$row ['name'] = $r ['name'];
|
||
|
|
$row ['register_address_postalcode'] = $r ['register_address_postalcode'];
|
||
|
|
$row ['register_address_city'] = $r ['register_address_city'];
|
||
|
|
$row ['register_address_street'] = $r ['register_address_street'];
|
||
|
|
$row ['document_date'] = $r ['document_date'];
|
||
|
|
$row ['category_id'] = $r ['category_id'];
|
||
|
|
$row ['active_date'] = $r ['active_date'];
|
||
|
|
$row ['to_vatid'] = $r ['to_vatid'];
|
||
|
|
$row ['register_date'] = $r ['register_date'];
|
||
|
|
|
||
|
|
$data [] = $row;
|
||
|
|
|
||
|
|
$sumvat += $row ['vatsumapozycja'];
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach ($tmp3 as $key => $value) {
|
||
|
|
if ($value ['sumavat'] == 0) {
|
||
|
|
$tmp3 [$key] ['sumavat'] = NULL;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$smarty = new Sugar_Smarty ();
|
||
|
|
$smarty->assign('MOD', $mod_strings);
|
||
|
|
|
||
|
|
$smarty->assign('date_from', $date_from);
|
||
|
|
$smarty->assign('date_to', $date_to);
|
||
|
|
$smarty->assign('dateFormat', $Calendar_daFormat);
|
||
|
|
$smarty->assign('netto', $dvnetto);
|
||
|
|
$smarty->assign('wartosc', $wartosc);
|
||
|
|
$smarty->assign('vat', $dvvat);
|
||
|
|
$smarty->assign('to_vatid', $to_vatid);
|
||
|
|
$smarty->assign('document_number', $document_number);
|
||
|
|
$smarty->assign('name', $name);
|
||
|
|
$smarty->assign('SumaNetto', $sumanetto);
|
||
|
|
$smarty->assign('SumaBrutto', $sumabrutto);
|
||
|
|
$smarty->assign('SumaVat', $sumvat);
|
||
|
|
$smarty->assign('vat', $vat);
|
||
|
|
$smarty->assign('vat_value', $tmp3);
|
||
|
|
$smarty->assign('value', $value);
|
||
|
|
$smarty->assign('category', $category_list);
|
||
|
|
$smarty->assign('category_selected', $category);
|
||
|
|
$smarty->assign('current_date_formatted', $current_date_formatted);
|
||
|
|
|
||
|
|
if ($_GET ['to_pdf'] == '1') {
|
||
|
|
$dataPart = NULL;
|
||
|
|
$dataPart = array_chunk($data, 20);
|
||
|
|
$pageVatSum = array();
|
||
|
|
$pageBruttoVat = array();
|
||
|
|
$partialVatSum = array();
|
||
|
|
$partialBruttoVat = array();
|
||
|
|
|
||
|
|
$tmpVatSum = array();
|
||
|
|
$tmpBruttoVat = array();
|
||
|
|
foreach ($tmp3 as $vatkey => $costampotrzebnego) {
|
||
|
|
$tmpVatSum [$vatkey] = array();
|
||
|
|
$tmpVatSum [$vatkey] ['netto'] = 0;
|
||
|
|
if ($costampotrzebnego['sumavat'] == null) {
|
||
|
|
$tmpVatSum [$vatkey] ['vat'] = 'null';
|
||
|
|
} else {
|
||
|
|
$tmpVatSum [$vatkey] ['vat'] = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
$tmpBruttoVat ['brutto'] = 0;
|
||
|
|
$tmpBruttoVat ['vat'] = 0;
|
||
|
|
foreach ($dataPart as $key => $value123) {
|
||
|
|
$pageVatSum [$key] = array();
|
||
|
|
$pageBruttoVat [$key] = array();
|
||
|
|
foreach ($tmp3 as $vatkey => $costampotrzebnego) {
|
||
|
|
$pageVatSum [$key] [$vatkey] = array();
|
||
|
|
$partialVatSum [$key] [$vatkey] = array();
|
||
|
|
$pageVatSum [$key] [$vatkey] ['netto'] = 0;
|
||
|
|
$partialVatSum [$key] [$vatkey] ['netto'] = 0;
|
||
|
|
if ($costampotrzebnego['sumavat'] == null) {
|
||
|
|
$pageVatSum [$key] [$vatkey] ['vat'] = 'null';
|
||
|
|
$partialVatSum [$key] [$vatkey] ['vat'] = 'null';
|
||
|
|
} else {
|
||
|
|
$pageVatSum [$key] [$vatkey] ['vat'] = 0;
|
||
|
|
$partialVatSum[$key] [$vatkey] ['vat'] = 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$pageBruttoVat [$key]['brutto'] = 0;
|
||
|
|
$pageBruttoVat [$key]['vat'] = 0;
|
||
|
|
foreach ($value123 as $key2 => $val123) {
|
||
|
|
foreach ($val123 ['vaty'] as $k => $vat123) {
|
||
|
|
$pageVatSum [$key] [$vat123 ['vat_value']] ['netto'] += $vat123 ['netto'];
|
||
|
|
$tmpVatSum [$vat123 ['vat_value']] ['netto'] += $vat123 ['netto'];
|
||
|
|
$kolejka = array_unshift ($kolejka, $vat123['netto']);
|
||
|
|
$kolejka1= array_unshift ($kolejka1, $vat123['vat']);
|
||
|
|
if ($vat123 ['vat'] != 0) {
|
||
|
|
$pageVatSum [$key] [$vat123 ['vat_value']] ['vat'] += $vat123 ['vat'];
|
||
|
|
$tmpVatSum [$vat123 ['vat_value']] ['vat'] += $vat123 ['vat'];
|
||
|
|
}
|
||
|
|
$pageBruttoVat [$key]['brutto'] += $vat123 ['netto'] + $vat123 ['vat'];
|
||
|
|
$pageBruttoVat [$key]['vat'] += $vat123 ['vat'];
|
||
|
|
$tmpBruttoVat ['brutto'] += $vat123 ['netto'] + $vat123 ['vat'];
|
||
|
|
$tmpBruttoVat ['vat'] += $vat123 ['vat'];
|
||
|
|
}
|
||
|
|
var_dump($kolejka);
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach ($tmpVatSum as $vatKey => $vatValue) {
|
||
|
|
$partialVatSum [$key] [$vatKey] ['netto'] += $vatValue ['netto'];
|
||
|
|
if ($vatValue['vat'] != 'null') {
|
||
|
|
$partialVatSum [$key] [$vatKey] ['vat'] += $vatValue ['vat'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$partialBruttoVat [$key] ['brutto'] = $tmpBruttoVat ['brutto'];
|
||
|
|
$partialBruttoVat [$key] ['vat'] = $tmpBruttoVat ['vat'];
|
||
|
|
}
|
||
|
|
$smarty->assign('pageBruttoVat', $pageBruttoVat);
|
||
|
|
$smarty->assign('pageVatSum', $pageVatSum);
|
||
|
|
|
||
|
|
$smarty->assign('partialBruttoVat', $partialBruttoVat);
|
||
|
|
$smarty->assign('partialVatSum', $partialVatSum);
|
||
|
|
|
||
|
|
$smarty->assign('dataPart', $dataPart);
|
||
|
|
$smarty -> assign('category_id', $app_list_strings['document_category_dom']);
|
||
|
|
|
||
|
|
// echo $smarty->display('modules/EcmReports/tpls/PDF/ReportBuyesByVat.tpl');
|
||
|
|
|
||
|
|
$output = $smarty->fetch ( 'modules/EcmReports/tpls/PDF/ReportBuyesByVat.tpl' );
|
||
|
|
include_once ("include/MPDF57/mpdf.php");
|
||
|
|
$p = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 35, 10, 5, 5 );
|
||
|
|
$p->setTitle ( $mod_strings ["LBL_REPORT_RECEIVE_REGISTER"] );
|
||
|
|
$p->setFooter ( '{PAGENO}' );
|
||
|
|
$p->writeHTML ( $output );
|
||
|
|
$p->Output ( 'RaportRejestrPrzyjecia.pdf', 'I' );
|
||
|
|
} else {
|
||
|
|
$smarty->assign('data', $data);
|
||
|
|
echo $smarty->display('modules/EcmReports/tpls/ReportBuyesByVat.tpl');
|
||
|
|
}
|
||
|
|
?>
|