242 lines
8.1 KiB
PHP
Executable File
242 lines
8.1 KiB
PHP
Executable File
|
|
|
|
|
|
<?
|
|
include_once("modules/EcmPaymentStates/helper.php");
|
|
|
|
function sum_saldo($id,$ret){
|
|
$winien_n_roz=0;
|
|
$winien_roz=0;
|
|
$ma_n_roz=0;
|
|
$ma_roz=0;
|
|
if($ret==0){
|
|
$where="and t.payment_date < '".date("Y-m-d")."' ";
|
|
} else {
|
|
$where='';
|
|
}
|
|
$w=$GLOBALS['db']->query("select t.paid,t.value,t.payment_date,fk.currency_value from ecmtransactions as t join ecminvoiceouts as fk on fk.id=t.record_id where t.parent_id='" . $id . "' and t.type=0 and t.deleted='0' and t.payment_date > '2011-12-31' $where order by t.date_entered desc");
|
|
|
|
//echo "select * from ecmtransactions where parent_id='" . $id . "' and type=0 and deleted='0' and payment_date > '2011-12-31' $where order by date_entered desc";
|
|
while($rinv = $GLOBALS ['db']->fetchByAssoc ($w)){
|
|
if ($rinv ['payment_date'] < '2008-12-31' && $rinv ['paid'] == 0)
|
|
continue;
|
|
//$total+=$rinv['value'];
|
|
if($rinv['currency_value']=='')$rinv['currency_value']=1;
|
|
|
|
if($rinv ['paid']==0){
|
|
$winien_n_roz+=$rinv ['value']*$rinv['currency_value'];
|
|
}
|
|
if($rinv['paid']==1){$winien_roz+=$rinv ['value']*$rinv['currency_value'];}
|
|
|
|
}
|
|
|
|
$query="select * from ecmtransactions where parent_id='" . $id . "' and type=1 and deleted='0' and payment_date > '2011-12-31' $where order by date_entered desc";
|
|
|
|
$w= $GLOBALS ['db']->query ( $query);
|
|
while($rinv = $GLOBALS ['db']->fetchByAssoc ($w)){
|
|
if($rinv['currency_value']=='')$rinv['currency_value']=1;
|
|
if ($rinv ['payment_date'] < '2008-12-31' && $rinv ['paid'] == 0)
|
|
continue;
|
|
if($rinv ['paid']==0){ $ma_n_roz+=$rinv ['value']*$rinv['currency_value'];
|
|
}
|
|
if($rinv['paid']==1){$ma_roz+=$rinv ['value']*$rinv['currency_value'];
|
|
}
|
|
}
|
|
if($ret==1){
|
|
return ($ma_roz + $ma_n_roz) - ($winien_roz + $winien_n_roz) ;
|
|
} else {
|
|
return ($ma_n_roz - $winien_n_roz);
|
|
}
|
|
if($ret==2) return $winien_n_roz;
|
|
}
|
|
function zaleg_dat($id,$zakres){
|
|
if($zakres==null){
|
|
$date = new DateTime(date("Y-m-d"));
|
|
$date->modify('-4 month');
|
|
$add="t.payment_date<'".$date->format('Y-m-d')."' and t.payment_date > '2011-12-31'";
|
|
}
|
|
if($zakres==30){
|
|
$date = new DateTime(date("Y-m-d"));
|
|
$s=$date->format('Y-m-d');
|
|
$date->modify('-1 month');
|
|
$add="t.payment_date between '".$date->format('Y-m-d')."' and '".$s."'";
|
|
}
|
|
if($zakres==60){
|
|
$date = new DateTime(date("Y-m-d"));
|
|
$date->modify('-1 month');
|
|
$s=$date->format('Y-m-d');
|
|
$date->modify('-1 month');
|
|
$add="t.payment_date between '".$date->format('Y-m-d')."' and '".$s."'";
|
|
}
|
|
if($zakres==180){
|
|
$date = new DateTime(date("Y-m-d"));
|
|
$date->modify('-3 month');
|
|
$s=$date->format('Y-m-d');
|
|
$date->modify('-1 month');
|
|
$add="t.payment_date between '".$date->format('Y-m-d')."' and '".$s."'";
|
|
}
|
|
if($zakres==90){
|
|
$date = new DateTime(date("Y-m-d"));
|
|
$date->modify('-2 month');
|
|
$s=$date->format('Y-m-d');
|
|
$date->modify('-1 month');
|
|
$add="t.payment_date between '".$date->format('Y-m-d')."' and '".$s."'";
|
|
}
|
|
$w=$GLOBALS['db']->query("select sum( CASE
|
|
WHEN fk.currency_value is null
|
|
then 1 *t.value ELSE fk.currency_value*t.value end) as value from ecmtransactions as t
|
|
join ecminvoiceouts as fk on fk.id=t.record_id where t.parent_id='".$id."' and ".$add." and t.paid='0' and t.type='0' group by t.parent_id");
|
|
$w2=$GLOBALS['db']->query("select sum( CASE
|
|
WHEN currency_value is null
|
|
then 1 *value ELSE currency_value*value end) as value as value from ecmtransactions where parent_id='".$id."' and ".$add." and paid='0' and type='1' group by parent_id");
|
|
//echo "select sum(value) as value from ecmtransactions where parent_id='".$id."' and ".$add." and paid='0' group by parent_name '".$zakres."'<br>";
|
|
$rinv = $GLOBALS ['db']->fetchByAssoc ($w);
|
|
$rinv2 = $GLOBALS ['db']->fetchByAssoc ($w2);
|
|
return abs($rinv['value']-$rinv2['value']);
|
|
}
|
|
|
|
$saldo=0;
|
|
$zal=0;
|
|
$zal_180=0;
|
|
$zal_30=0;
|
|
$zal_60=0;
|
|
$zal_90=0;
|
|
?>
|
|
<table cellspacing="0" cellpadding="0" border="0"><tr><td></td><td><h2>Rozrachunki: Salda</h2></td></tr></table>
|
|
<br />
|
|
<input type="button" class="button" value="Utwórz XLS" name="create_xls" onclick="location.href='index.php?module=EcmPaymentStates&action=CreateXLSsummary&to_pdf=1';" />
|
|
<?php
|
|
//print_r($acc);
|
|
$tds1='<td class="listViewThS1" style="text-align:right;">';
|
|
|
|
$trs='<tr>';
|
|
$trs_grey='<tr style="background-color: #e6e6e6;">';
|
|
$tre='</tr>';
|
|
|
|
$tds='<td class="oddListRowS1" style="text-align:right;">';
|
|
$tds2='<td class="oddListRowS1" style="text-align:left;">';
|
|
$tde='</td>';
|
|
|
|
$tbs='<table cellpadding="0" cellspacing="0" border="0" class="ListView" style="width:100%;">';
|
|
$tbe='</table>';
|
|
|
|
$t.=$tbs;
|
|
$t.=$trs;
|
|
$t.=$tds2;
|
|
$t.="Kontrahent";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.="Saldo";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.="Nierozliczone";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.="Po terminie";
|
|
$t.=$tde;
|
|
|
|
$t.=$tds1;
|
|
$t.="1-30";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.="30-60";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.="60-90";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.="90-180";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.="180-...";
|
|
$t.=$tde;
|
|
$t.=$tre;
|
|
|
|
$z="select sum(value),ac.name as parent_name,t.parent_id from ecmtransactions as t join accounts as ac on ac.id=t.parent_id where t.parent_id!='' and t.parent_id is not null and t.payment_date < '".date("Y-m-d H:i:s")."' and t.paid='0' and t.deleted='0' and t.payment_date > '2011-12-31' group by t.parent_id order by t.parent_name";
|
|
|
|
$w=$GLOBALS['db']->query($z);
|
|
|
|
$nieroz=0;
|
|
$array_sort=array();
|
|
while($r=$GLOBALS['db']->fetchByAssoc($w)){
|
|
//echo $r['parent_name'];
|
|
if ($i % 2 == 1)
|
|
$t.=$trs;
|
|
else
|
|
$t.=$trs_grey;
|
|
//$t.=$trs;
|
|
$t.=$tds2;
|
|
$t.='<a href="index.php?action=index&module=EcmPaymentStates¬t_matched=0&account_name='.$r['parent_name'].'&account_id='.$r['parent_id'].'&button=Search">'.str_replace("<","<",str_replace(">",">",$r['parent_name'])).'</a>';
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.=number_format(sum_saldo($r['parent_id'],1),2,",",".");
|
|
$saldo+=sum_saldo($r['parent_id'],1);
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<a href="index.php?action=index&module=EcmPaymentStates&matched=1&account_name='.$r['parent_name'].'&account_id='.$r['parent_id'].'&button=Search">'.str_replace("<","<",str_replace(">",">",number_format(abs(sum_saldo($r['parent_id'],2)),2,",","."))).'</a>';
|
|
$nieroz+=sum_saldo($r['parent_id'],2);
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.=number_format(abs(sum_saldo($r['parent_id'],0)),2,",",".");
|
|
$po_t+=sum_saldo($r['parent_id'],0);
|
|
$t.=$tde;
|
|
|
|
$t.=$tds;
|
|
$t.='<a href="index.php?module=EcmPaymentStates&action=summary_inv&account_id='.$r['parent_id'].'&start=1&end=30">'.number_format(zaleg_dat($r['parent_id'],30),2,",",".").'</a>';
|
|
$zal_30+=zaleg_dat($r['parent_id'],30);
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<a href="index.php?module=EcmPaymentStates&action=summary_inv&account_id='.$r['parent_id'].'&start=30&end=60">'.number_format(zaleg_dat($r['parent_id'],60),2,",",".").'</a>';
|
|
$zal_60+=zaleg_dat($r['parent_id'],60);
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<a href="index.php?module=EcmPaymentStates&action=summary_inv&account_id='.$r['parent_id'].'&start=60&end=90">'.number_format(zaleg_dat($r['parent_id'],90),2,",",".").'</a>';
|
|
$zal_90+=zaleg_dat($r['parent_id'],90);
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<a href="index.php?module=EcmPaymentStates&action=summary_inv&account_id='.$r['parent_id'].'&start=90&end=180">'.number_format(zaleg_dat($r['parent_id'],180),2,",",".").'</a>';
|
|
$zal+=zaleg_dat($r['parent_id'],180);
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<a href="index.php?module=EcmPaymentStates&action=summary_inv&account_id='.$r['parent_id'].'&start=180&end=...">'.number_format(zaleg_dat($r['parent_id'],null),2,",",".").'</a>';
|
|
$zal_180+=zaleg_dat($r['parent_id'],null);
|
|
$t.=$tde;
|
|
$t.=$tre;
|
|
|
|
$i++;
|
|
}
|
|
|
|
|
|
$t.=$trs;
|
|
$t.=$tds;
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<strong>'.number_format($saldo,2,",",".").'</strong>';
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<strong>'.number_format(abs($nieroz),2,",",".").'</strong>';
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<strong>'.number_format(abs($po_t),2,",",".").'</strong>';
|
|
$t.=$tde;
|
|
|
|
$t.=$tds;
|
|
$t.='<strong>'.number_format(abs($zal_30),2,",",".").'</strong>';
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<strong>'.number_format(abs($zal_60),2,",",".").'</strong>';
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<strong>'.number_format(abs($zal_90),2,",",".").'</strong>';
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<strong>'.number_format(abs($zal),2,",",".").'</strong>';
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<strong>'.number_format(abs($zal_180),2,",",".").'</strong>';
|
|
$t.=$tde;
|
|
$t.=$tre;
|
|
|
|
$t.=$tbe;
|
|
echo $t;
|
|
?>
|