include_once("modules/EcmPaymentStates/helper.php");
?>
query("select distinct account_id from ecmpayments_ecminvoiceouts where account_id!='' and account_id is not null and deleted='0'");
while($r=$GLOBALS['db']->fetchByAssoc($w))$acc[$r['account_id']]="id='".$r['account_id']."'";
$tds1='';
$trs=' ';
$trs_grey=' ';
$tre=' ';
$tds='';
$tde=' ';
$tbs='';
$t.=$tbs;
$t.=$trs;
$t.=$tds1;
$t.="Kontrahent";
$t.=$tde;
$t.=$tds1;
$t.="Saldo";
$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 * from accounts where deleted='0' and (".implode(" or ",$acc).") order by name asc";
$w=$GLOBALS['db']->query($z);
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if ($i % 2 == 1)
$t.=$trs;
else
$t.=$trs_grey;
$l_summary=getSummary($r['id']);
$l_ballance=getBallance($r['id']);
$l_actual_sum=getActualSum($r['id']);
$l_sum_1_30=getSum($r['id'],1,30);
$l_sum_30_60=getSum($r['id'],30,60);
$l_sum_60_90=getSum($r['id'],60,90);
$l_sum_90_180=getSum($r['id'],90,180);
$l_sum_180=getSum($r['id'],180);
if(round($l_summary+$l_actual_sum+$l_sum_1_30+$l_sum_30_60+$l_sum_60_90+$l_sum_90_180+$l_sum_180,2)==0.00)continue;
$summary+=$l_summary;
$ballance+=$l_ballance;
$actual_sum+=$l_actual_sum;
$sum_1_30+=$l_sum_1_30;
$sum_30_60+=$l_sum_30_60;
$sum_60_90+=$l_sum_60_90;
$sum_90_180+=$l_sum_90_180;
$sum_180+=$l_sum_180;
//$t.=$trs;
$t.=$tds;
$t.=''.str_replace("<","<",str_replace(">",">",$r['name'])).' ';
$t.=$tde;
$t.=$tds;
$t.=number_format($l_ballance,2,",",".");
$t.=$tde;
$t.=$tds;
$t.=number_format($l_summary,2,",",".");
$t.=$tde;
$t.=$tds;
$t.=''.number_format($l_sum_1_30,2,",",".").' ';
$t.=$tde;
$t.=$tds;
$t.=''.number_format($l_sum_30_60,2,",",".").' ';
$t.=$tde;
$t.=$tds;
$t.=''.number_format($l_sum_60_90,2,",",".").' ';
$t.=$tde;
$t.=$tds;
$t.=''.number_format($l_sum_90_180,2,",",".").' ';
$t.=$tde;
$t.=$tds;
$t.=''.number_format($l_sum_180,2,",",".").' ';
$t.=$tde;
$t.=$tre;
$i++;
}
$t.=$trs;
$t.=$tds;
$t.=$tde;
$t.=$tds;
$t.=''.number_format($ballance,2,",",".").' ';
$t.=$tde;
$t.=$tds;
$t.=''.number_format($summary,2,",",".").' ';
$t.=$tde;
$t.=$tds;
$t.=''.number_format($sum_1_30,2,",",".").' ';
$t.=$tde;
$t.=$tds;
$t.=''.number_format($sum_30_60,2,",",".").' ';
$t.=$tde;
$t.=$tds;
$t.=''.number_format($sum_60_90,2,",",".").' ';
$t.=$tde;
$t.=$tds;
$t.=''.number_format($sum_90_180,2,",",".").' ';
$t.=$tde;
$t.=$tds;
$t.=''.number_format($sum_180,2,",",".").' ';
$t.=$tde;
$t.=$tre;
$t.=$tbe;
echo $t;
?>