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>'".$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 |