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>'".$date->format('Y-m-d')."' and t.payment_date < '".$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>'".$date->format('Y-m-d')."' and t.payment_date < '".$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>'".$date->format('Y-m-d')."' and t.payment_date < '".$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>'".$date->format('Y-m-d')."' and t.payment_date < '".$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 t.currency_value is null then 1 *t.value ELSE t.currency_value*t.value end) as value from ecmtransactions as t 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."'
"; $rinv = $GLOBALS ['db']->fetchByAssoc ($w); //$rinv2 = $GLOBALS ['db']->fetchByAssoc ($w2); return abs($rinv['value']); } $saldo=0; $zal=0; $zal_180=0; $zal_30=0; $zal_60=0; $zal_90=0; ?>

Rozrachunki: Salda


'; $trs=''; $trs_grey=''; $tre=''; $tds=''; $tds2=''; $tde=''; $tbs=''; $tbe='
'; $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(); $abc=0; 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.=''.str_replace("<","<",str_replace(">",">",$r['parent_name'])).''; $array_sort[$abc]['parent_id']=$r['parent_id']; $t.=$tde; $t.=$tds; $t.=number_format(sum_saldo($r['parent_id'],1),2,",","."); $saldo+=sum_saldo($r['parent_id'],1); $array_sort[$abc]['salto']=sum_saldo($r['parent_id'],1); $t.=$tde; $t.=$tds; $t.=''.str_replace("<","<",str_replace(">",">",number_format(abs(sum_saldo($r['parent_id'],2)),2,",","."))).''; $nieroz+=sum_saldo($r['parent_id'],2); $array_sort[$abc]['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); $array_sort[$abc]['po_t']=sum_saldo($r['parent_id'],0); $t.=$tde; $t.=$tds; $t.=''.number_format(zaleg_dat($r['parent_id'],30),2,",",".").''; $zal_30+=zaleg_dat($r['parent_id'],30); $array_sort[$abc]['30']=zaleg_dat($r['parent_id'],30); $t.=$tde; $t.=$tds; $t.=''.number_format(zaleg_dat($r['parent_id'],60),2,",",".").''; $zal_60+=zaleg_dat($r['parent_id'],60); $array_sort[$abc]['60']=zaleg_dat($r['parent_id'],60); $t.=$tde; $t.=$tds; $t.=''.number_format(zaleg_dat($r['parent_id'],90),2,",",".").''; $zal_90+=zaleg_dat($r['parent_id'],90); $array_sort[$abc]['90']=zaleg_dat($r['parent_id'],90); $t.=$tde; $t.=$tds; $t.=''.number_format(zaleg_dat($r['parent_id'],180),2,",",".").''; $zal+=zaleg_dat($r['parent_id'],180); $array_sort[$abc]['180']=zaleg_dat($r['parent_id'],180); $t.=$tde; $t.=$tds; $t.=''.number_format(zaleg_dat($r['parent_id'],null),2,",",".").''; $zal_180+=zaleg_dat($r['parent_id'],null); $array_sort[$abc]['null']=zaleg_dat($r['parent_id'],null); $t.=$tde; $t.=$tre; $i++; $abc++; } //print_r($array_sort); $t.=$trs; $t.=$tds; $t.=$tde; $t.=$tds; $t.=''.number_format($saldo,2,",",".").''; $t.=$tde; $t.=$tds; $t.=''.number_format(abs($nieroz),2,",",".").''; $t.=$tde; $t.=$tds; $t.=''.number_format(abs($po_t),2,",",".").''; $t.=$tde; $t.=$tds; $t.=''.number_format(abs($zal_30),2,",",".").''; $t.=$tde; $t.=$tds; $t.=''.number_format(abs($zal_60),2,",",".").''; $t.=$tde; $t.=$tds; $t.=''.number_format(abs($zal_90),2,",",".").''; $t.=$tde; $t.=$tds; $t.=''.number_format(abs($zal),2,",",".").''; $t.=$tde; $t.=$tds; $t.=''.number_format(abs($zal_180),2,",",".").''; $t.=$tde; $t.=$tre; $t.=$tbe; echo $t; ?>