Files
crm.twinpol.com/modules/EcmReportsBackUp20151106/AgreementRaport.php
2025-05-12 15:44:39 +00:00

63 lines
2.5 KiB
PHP
Executable File

<?php
function dateV($format,$timestamp=null){
$to_convert = array(
'l'=>array('dat'=>'N','str'=>array('Poniedziałek','Wtorek','Środa','Czwartek','Piątek','Sobota','Niedziela')),
'F'=>array('dat'=>'n','str'=>array('styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień')),
'f'=>array('dat'=>'n','str'=>array('stycznia','lutego','marca','kwietnia','maja','czerwca','lipca','sierpnia','września','października','listopada','grudnia'))
);
if ($pieces = preg_split('#[:/.\-, ]#', $format)){
if ($timestamp === null) { $timestamp = time(); }
foreach ($pieces as $datepart){
if (array_key_exists($datepart,$to_convert)){
$replace[] = $to_convert[$datepart]['str'][(date($to_convert[$datepart]['dat'],$timestamp)-1)];
}else{
$replace[] = date($datepart,$timestamp);
}
}
$result = strtr($format,array_combine($pieces,$replace));
return $result;
}
}
$Calendar_daFormat = str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));
// Default value from date input
if($_REQUEST['date_to']==''){
$date_from ='01.01.2010';
} else {
$date_from =$_REQUEST['date_from'];
}
$dateq=date("Y-m-d",strtotime($date_from));
$db=$GLOBALS['db'];
$total=0;
$total_o=0;
$total_p=0;
$total_r=0;
$q=$db->query("select payment_date,(interest_rate) as rate,sum(rate_of_commission) as rate2,sum(principal_value) as rate3,sum(rate_of_commission+principal_value+interest_rate) as total from ecmagreementitems
where payment_date>='".$dateq."'
group by payment_date asc");
$table=array();
$chart=array();
while($row=$db->fetchByAssoc($q)){
$row['payment_date']=dateV('Y F',strtotime($row['payment_date']));
$total+=$row['total'];
$total_o+=$row['rate'];
$total_p+=$row['rate2'];
$total_r+=$row['rate3'];
$table[]=$row;
}
// create & execute smarty
$smarty = new Sugar_Smarty ();
global $mod_strings;
$smarty->assign ( "MOD", $mod_strings );
$smarty -> assign("dateFormat", $Calendar_daFormat);
$smarty -> assign( "date_from", $date_from );
$smarty -> assign("TABLE",$table);
$smarty -> assign("total",$total);
$smarty -> assign("total_o",$total_o);
$smarty -> assign("total_p",$total_p);
$smarty -> assign("total_r",$total_r);
$smarty -> assign( "date_to", $date_to );
$smarty->display ( 'modules/EcmReports/tpls/AgreementRaport.tpl' );
?>