Add php files

This commit is contained in:
2025-05-12 15:44:39 +00:00
parent c951760058
commit 82d5804ac4
9534 changed files with 2638137 additions and 0 deletions

View File

@@ -0,0 +1,555 @@
<?php
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
die ( 'Not A Valid Entry Point' );
$db = $GLOBALS['db'];
if($_REQUEST['account_id']=='')$_REQUEST['account_id']=$_REQUEST['record'];
$account_id = $_REQUEST['account_id'];
//if (isset($_REQUEST['rid']))
$change_date = '2014-09-03'; //data zmiany systemu rozliczania
$umowa_id=$_REQUEST['agreement'];
$ss = new Sugar_Smarty ();
global $mod_strings;
$ss->assign ( "MOD", $mod_strings );
global $app_strings;
$ss->assign ( "APP", $app_strings );
//var_dump($app_strings);
//brak kontrahenta, tylko wyszukiwanie
if (!$account_id || $account_id=='') {
echo $ss->display ( 'modules/EcmPaymentStates/tpls/AccountPaymentStates.tpl' );
return;
}
$a = new Account();
$a->retrieve($account_id);
global $timedate;
$query_w='';
$query_ma='';
$label='Wszystkie';
if($_REQUEST['switch_show']=='')$_REQUEST['switch_show']=3;
switch ($_REQUEST['switch_show']){
case 1:
$query_w="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$a->id."'
AND type='0'
ORDER BY payment_date desc";
$query_ma="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$a->id."'
AND type='1'
ORDER BY payment_date desc";
$label='Wszystkie';
break;
case 2:
$query_w="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$a->id."'
AND type='0' AND (SELECT count(*) FROM ecmtransactions_rel WHERE ecmtransaction_a_id=ecmtransactions.id OR ecmtransaction_b_id=ecmtransactions.id)>0
ORDER BY payment_date desc";
$query_ma="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$a->id."'
AND type='1' AND (SELECT count(*) FROM ecmtransactions_rel WHERE ecmtransaction_a_id=ecmtransactions.id OR ecmtransaction_b_id=ecmtransactions.id)>0
ORDER BY payment_date desc";
$label='Rozliczone';
break;
case 3:
$query_w="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$a->id."'
AND type='0' AND (settled='0' or settled=null)
ORDER BY payment_date desc";
$query_ma="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$a->id."'
AND type='1' AND (settled='0' or settled=null)
ORDER BY payment_date desc";
$label='Nierozliczone';
break;
case 4:
$query_w="
SELECT t.* FROM ecmtransactions t
inner join ecmtransactions_rel r on r.ecmtransaction_a_id=t.id
inner join ecmtransactions t2 on
t2.id=r.ecmtransaction_b_id
WHERE
t.parent_id='".$a->id."'
AND t.type='0'
and t.settled=1
and t.payment_date < t2.payment_date
ORDER BY t.payment_date desc";
$query_ma="
SELECT t.* FROM ecmtransactions t
inner join ecmtransactions_rel r on r.ecmtransaction_b_id=t.id
inner join ecmtransactions t2 on
t2.id=r.ecmtransaction_a_id
WHERE
t.parent_id='".$a->id."'
AND t.type='1'
and t.settled=1
and t.payment_date>t2.payment_date group by t.id
ORDER BY t.payment_date desc";
$label='Rozliczone po terminie';
break;
case 5:
$query_w="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$a->id."'
AND type='0'
AND (settled='0' OR settled IS NULL) and payment_date < '".date("Y-m-d")."'
ORDER BY payment_date desc";
$query_ma="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$a->id."'
AND type='1'
AND (settled='0' OR settled IS NULL) and payment_date < '".date("Y-m-d")."'
ORDER BY payment_date desc";
$label='Nierozliczone po terminie';
break;
}
$res = $db->query($query_w);
$total_winien = 0;
$winien = array();
$totals_w['wartosc']=0;
$totals_w['roz']=0;
$totals_w['nie']=0;
while ($r = $db->fetchByAssoc($res)) {
$tmp = array();
$tmp['settled_with'] = array();
$total_settled = 0;
if($umowa_id!=''){
if($r['record_id']!=$umowa_id){
if($r['record_type']=='EcmInvoiceOuts'){
$m= new EcmInvoiceOut();
$m->retrieve($r['record_id']);
if($m->ecmagreement_id!=$umowa_id){
continue;
}
} else {
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
$skip=true;
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
if($t['record_type']=='EcmInvoiceOuts'){
$m= new EcmInvoiceOut();
$m->retrieve($t['record_id']);
if($m->ecmagreement_id==$umowa_id){
$skip==false;
}
} else {
if($t['record_id']==$umowa_id){
$skip=false;
}
}
}
if($skip==true){
continue;
}
}
}
}
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
$tmp2 = array();
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp2['value']=$rr['value'];
if($t['type']==0 && $rel->num_rows==1){
if(abs($rr['value'])==abs($r['value'])){
if($r['value']>0){
$rr['value']=abs($rr['value']);
} else {
$v = -1 * abs( $rr['value']);
$rr['value']=$v;
}
} else {
$rr['value']=abs($rr['value']);
}
} else {
if(abs($rr['value'])==abs($r['value'])){
if($r['value']>0){
$rr['value']=abs($rr['value']);
} else {
$v = -1 * abs( $rr['value']);
$rr['value']=$v;
}
} else {
if($r['value']>0){
$rr['value']=abs($rr['value']);
}
}
}
$tmp['settled_with'][] = $tmp2;
$total_settled+=floatval($rr['value']);
}
//date comparsion
if ($r['settled'] == '1') {
if($total_settled==0){
$total_settled=$r['value'];
}
} else $r['settled'] = '0'; //prevent null
$tmp['register_date'] = $timedate->to_display_date($r['payment_date']);
if($r['record_type']!=''){
$module=substr($r['record_type'],0,strlen($r['record_type'])-1);
$m = new $module();
$m->retrieve($r['record_id']);
$add=' z dnia '.date('d.m.Y',strtotime($m->register_date));
} else {
$add='';
}
$tmp['document_no'] = '<a href="index.php?module=EcmTransactions&action=DetailView&record='.$r['id'].'" traget="new">'.$r['name'].' '.$add.'</a>';
$tmp['total'] = format_number($r['value']);
$tmp['settled'] = format_number($total_settled);
$totals_w['wartosc']+=$r['value'];
$totals_w['roz']+=$total_settled;
$totals_w['nie']+=floatval(unsettledValue($total_settled,$r['value']));
if($r['settled']==1){
if($_REQUEST['switch_show']==1){
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_winien+=floatval($r['value']);
} else {
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_winien+=floatval(unsettledValue($total_settled,$r['value']));
}
}else{
if($_REQUEST['switch_show']==1){
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_winien+=floatval($r['value']);
} else {
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_winien+=floatval(unsettledValue($total_settled,$r['value']));
}
}
$tmp['id'] = $r['id'];
$tmp['sort_date']=date('Ymd',strtotime($r['payment_date']));
$tmp['note']= $r['note'];
$tmp['type']='0';
$tmp['note_id']= $r['note_id'];
$tmp['is_settled'] = $r['settled'];
$winien[] = $tmp;
}
$totals_m['wartosc']=0;
$totals_m['roz']=0;
$totals_m['nie']=0;
$ss -> assign('WINIEN', $winien);
$res = $db->query($query_ma);
$ma = array();
$total_ma = 0;
while ($r = $db->fetchByAssoc($res)) {
$tmp = array();
$tmp['settled_with'] = array();
$total_settled = 0;
if($umowa_id!=''){
if($r['record_id']!=$umowa_id){
if($r['record_type']=='EcmInvoiceOuts'){
$m= new EcmInvoiceOut();
$m->retrieve($r['record_id']);
if($m->ecmagreement_id!=$umowa_id){
continue;
}
} else {
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
$skip=true;
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
if($t['record_type']=='EcmInvoiceOuts'){
$m= new EcmInvoiceOut();
$m->retrieve($t['record_id']);
if($m->ecmagreement_id==$umowa_id){
$skip==false;
}
} else {
if($t['record_id']==$umowa_id){
$skip=false;
}
}
}
if($skip==true){
continue;
}
}
}
}
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
$tmp2 = array();
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp2['value']=$rr['value'];
if($t['type']==0 && $rel->num_rows==1){
if(abs($rr['value'])==abs($r['value'])){
if($r['value']>0){
$rr['value']=abs($rr['value']);
} else {
$v = -1 * abs( $rr['value']);
$rr['value']=$v;
}
}
}else {
$rr['value']=abs($rr['value']);
}
$tmp['settled_with'][] = $tmp2;
$total_settled+=floatval($rr['value']);
}
//date comparsion
if ($r['settled'] == '1') {
if($total_settled==0){
$total_settled=$r['value'];
}
} else $r['settled'] = '0'; //prevent null
$tmp['register_date'] = $timedate->to_display_date($r['payment_date']);
if($r['record_type']!=''){
$module=substr($r['record_type'],0,strlen($r['record_type'])-1);
$m = new $module();
$m->retrieve($r['record_id']);
if($m->register_date!=""){
$add=' z dnia '.date('d.m.Y',strtotime($m->register_date));
} else {
if($m->document_date!=""){
$add=' z dnia '.date('d.m.Y',strtotime($m->document_date));
}
}
} else {
$add='';
}
$tmp['sort_date']=date('Ymd',strtotime($r['payment_date']));
$tmp['name'] = '<a href="index.php?module=EcmTransactions&action=DetailView&record='.$r['id'].'" traget="new">'.$r['name'].' '.$add.'</a>';
$tmp['total'] = format_number($r['value']);
$tmp['settled'] = format_number($total_settled);
$totals_m['wartosc']+=$r['value'];
$totals_m['roz']+=$total_settled;
$totals_m['nie']+=floatval(unsettledValue($total_settled,$r['value']));
if($r['settled']==1){
if($_REQUEST['switch_show']==1){
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_ma+=floatval($r['value']);
} else {
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_ma+=floatval(unsettledValue($total_settled,$r['value']));
}
//$tmp['unsettled'] = format_number(abs($r['value'])-$total_settled); echo 'rozliczone';
}else{
if($_REQUEST['switch_show']==1){
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_ma+=floatval($r['value']);
} else {
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_ma+=floatval(unsettledValue($total_settled,$r['value']));
}
}
$tmp['is_settled'] = $r['settled'];
$tmp['type']='1';
$tmp['id'] = $r['id'];
$ma[] = $tmp;
//$total_ma+=floatval($r['value']);
}
$sea = new SugarEmailAddress;
// Grab the array of addresses
$emails = $sea->getAddressesByGUID( $account_id, 'Accounts');
$ss -> assign('MA', $ma);
$sum = array();
$sum['WINIEN'] = format_number($total_winien);
$sum['MA'] = format_number($total_ma);
$sum['SALDO'] = format_number($total_ma-$total_winien);
$ss->assign('SUM', $sum);
//$ss->assign('EMAILLIST',getEmails($account_id));
$ss->assign('umowy',getAgreements($account_id));
$ss->assign('umowa_sel',$umowa_id);
$ss->assign('SWITCH_SHOW', $_REQUEST['switch_show']);
$ss->assign('PROCESS', '1');
$c = new EcmSysInfo();
$ss->assign("number",$a->phone_office);
$ss->assign('CURRENT_COMPANY', $c->getShortName());
$ss->assign('ACCOUNT', array('ID'=>$account_id, 'NAME'=>$a->name));
$ss->assign('EMAILLIST',$emails);
$ss->assign("system_name",$c->getShortName());
if( $_REQUEST['toPDF'] == '1' ) {
$info = new EcmSysInfo();
$all_transactions=array_merge($ma,$winien);
$all_transactions=array_sort_by_key($all_transactions,'sort_date',SORT_ASC);
$ss->assign('transactions',$all_transactions);
$ss->assign('totals_w',$totals_w);
$ss->assign('totals_m',$totals_m);
$ss->assign('saldo',$totals_m['wartosc']-$totals_w['wartosc']);
$output = $ss->fetch( 'modules/EcmPaymentStates/tpls/PDF/AccountPaymentStatespdf.tpl' );
include_once ("include/MPDF60/mpdf60/mpdf.php");
unset($smarty);
$p = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 25, 10, 5, 5 );
$p->setFooter('Strona {PAGENO} z {nbpg}');
$p->SetHTMLHeader('<p style="text-align:left;font-size: 10px;">'.$info->getName().'<br>
Kontrahent: '.$a->name.'<br>Rozrachunki: '.$label.'<br>Data wydruku: '.date("d.m.Y").'<br>Strona {PAGENO} z {nbpg}</p>');
//$p->setTitle($mod_strings["LBL_REPORT_STOCKS_DOCS"]);
//echo $output;
$p->writeHTML( $output );
$p->Output ();
} else {
echo $ss->display ( 'modules/EcmPaymentStates/tpls/AccountPaymentStates.tpl' );
}
unset($a);
function array_sort_by_key($array, $on, $order=SORT_ASC)
{
$new_array = array();
$sortable_array = array();
if (count($array) > 0) {
foreach ($array as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $on) {
$sortable_array[$k] = $v2;
}
}
} else {
$sortable_array[$k] = $v;
}
}
switch ($order) {
case SORT_ASC:
asort($sortable_array);
break;
case SORT_DESC:
arsort($sortable_array);
break;
}
foreach ($sortable_array as $k => $v) {
$new_array[$k] = $array[$k];
}
}
return $new_array;
}
function unsettledFormatValue($settled,$val){
if($settled<0 && $val>0){
return format_number($val+$settled);
}
if($settled<0 && $val<0){
return format_number($val+abs($settled));
}
if($settled>0 && $val>0){
return format_number($val-abs($settled));
}
if($settled>0 && $val<0){
return format_number($val+$settled);
}
if($settled==0 && $val<0){
return format_number($val);
}
if($settled==0 && $val>0){
return format_number($val);
}
}
function getAgreements($id){
$db=$GLOBALS['db'];
$zap="select id,document_no from ecmagreements where parent_id='".$id."' and deleted=0";
$res=$db->query($zap);
$as=array();
while($dane=$db->fetchByAssoc($res)){
$as[]=$dane;
}
return $as;
}
function unsettledValue($settled,$val){
if($settled<0 && $val>0){
return ($val+$settled);
}
if($settled<0 && $val<0){
return ($val+abs($settled));
}
if($settled>0 && $val>0){
return ($val-abs($settled));
}
if($settled>0 && $val<0){
return ($val+$settled);
}
return $val;
}
function getEmails ($id)
{
$sea = new SugarEmailAddress();
$addresses = $sea->getAddressesByGUID($id, 'Accounts');
$return = array();
foreach ($addresses as $address) {
if ($address['email_address'] != '' && $address['opt_out'] == 1) {
$return[] = $address['email_address'];
}
}
return $return;
}

View File

@@ -0,0 +1,116 @@
<?php
set_include_path('include/PHPExcel/');
include 'PHPExcel.php';
include 'PHPExcel/Writer/Excel2007.php';
include 'PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("E5 CRM");
$objPHPExcel->getProperties()->setLastModifiedBy("E5 CRM");
$objPHPExcel->getProperties()->setTitle("Office 2007 PAYMENTS");
$objPHPExcel->getProperties()->setSubject("Office 2007 PAYMENTS");
$objPHPExcel->getProperties()->setDescription("PAYMENTS");
$alf="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
$objPHPExcel->getActiveSheet()->setTitle('Simple');
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue("B1","Register date");
$objPHPExcel->getActiveSheet()->SetCellValue("C1","Name");
$objPHPExcel->getActiveSheet()->SetCellValue("D1","Total");
$objPHPExcel->getActiveSheet()->SetCellValue("G1","Payment date");
$objPHPExcel->getActiveSheet()->SetCellValue("H1","Name");
$objPHPExcel->getActiveSheet()->SetCellValue("I1","Value");
$i=2;
if($_REQUEST['not_matched']==1){
$wh_paid_i=true;
$wh_paid_p=true;
}
$w=$GLOBALS['db']->query("select p.id,p.document_no,p.paid,p.register_date,p.payment_date,p.total,p.ecminvoiceout_id from ecmpayments_ecminvoiceouts as p where p.deleted='0' and p.account_id='".$_REQUEST['account_id']."' order by p.register_date desc,p.document_no desc");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if($r['paid']!=0)$paid="*";
else $paid="";
$exp=explode("-",$r['register_date']);
if($r['paid']==0)$arrear+=$r['total'];
if($r['paid']==0 || !$wh_paid_i){
$objPHPExcel->getActiveSheet()->SetCellValue("A".$i,$paid);
$objPHPExcel->getActiveSheet()->SetCellValue("B".$i,$r['register_date']);
$objPHPExcel->getActiveSheet()->SetCellValue("C".$i,$r['document_no']);
$objPHPExcel->getActiveSheet()->SetCellValue("D".$i,$r['total']);
$i++;
}
$total_wn+=$r['total'];
}
$i=2;
$w=$GLOBALS['db']->query("select payment_date,id,description,value,paid,name from ecmpayments where deleted='0' and parent_id='".$_REQUEST['account_id']."' order by payment_date desc,description desc");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if($r['paid'])$paid="*";
else $paid="";
if($r['paid']==0 || !$wh_paid_p){
$objPHPExcel->getActiveSheet()->SetCellValue("F".$i,$paid);
$objPHPExcel->getActiveSheet()->SetCellValue("G".$i,$r['payment_date']);
$objPHPExcel->getActiveSheet()->SetCellValue("H".$i,$r['name']);
$objPHPExcel->getActiveSheet()->SetCellValue("I".$i,$r['value']);
$i++;
}
$total_ma+=$r['value'];
}
$objPHPExcel->getActiveSheet()->duplicateStyleArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'F0F0F0')
),
'borders' => array(
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
),
"A1:I1"
);
/*
$objPHPExcel->getActiveSheet()->duplicateStyleArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'F0F0F0')
),
'borders' => array(
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
),
"A".($i).":I".($i)
);*/
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
chmod("cache/upload",0777);
$microtime=str_replace(".","",str_replace(" ","",microtime()));
$name="cache/upload/PaymentStates".$microtime.".xlsx";
$objWriter->save($name);
chmod($name,0777);
header("Location: ".$name);
?>

View File

@@ -0,0 +1,202 @@
<?php
ini_set('memory_limit', '-1');
set_time_limit (999);
include_once("modules/EcmPaymentStates/helper.php");
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors', '1');
set_include_path('include/PHPExcel/');
include 'PHPExcel.php';
include 'PHPExcel/Writer/Excel2007.php';
include 'PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("E5 CRM");
$objPHPExcel->getProperties()->setLastModifiedBy("E5 CRM");
$objPHPExcel->getProperties()->setTitle("Office 2007 PAYMENTS");
$objPHPExcel->getProperties()->setSubject("Office 2007 PAYMENTS");
$objPHPExcel->getProperties()->setDescription("PAYMENTS");
$alf="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
$objPHPExcel->getActiveSheet()->setTitle('Simple');
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue("A1","Kontrahent");
$objPHPExcel->getActiveSheet()->SetCellValue("B1","Bilans");
$objPHPExcel->getActiveSheet()->SetCellValue("C1","Podsumowanie");
$objPHPExcel->getActiveSheet()->SetCellValue("D1","Nie przeterminowane");
$objPHPExcel->getActiveSheet()->SetCellValue("E1","1-30");
$objPHPExcel->getActiveSheet()->SetCellValue("F1","30-60");
$objPHPExcel->getActiveSheet()->SetCellValue("G1","60-90");
$objPHPExcel->getActiveSheet()->SetCellValue("H1","90-180");
$objPHPExcel->getActiveSheet()->SetCellValue("I1","180-...");
$i=2;
$b=2;
$w=$GLOBALS['db']->query("select distinct account_id from ecmpayments_ecminvoiceouts where account_id!='' and account_id is not null");
while($r=$GLOBALS['db']->fetchByAssoc($w))$acc[$r['account_id']]="id='".$r['account_id']."'";
$z="select * from accounts where deleted='0' and (".implode(" or ",$acc).") order by name asc";
$w=$GLOBALS['db']->query($z);
$tmp = array();
$objPHPExcel->createSheet(1);
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
$objPHPExcel->getActiveSheet()->setTitle('Faktury');
$objPHPExcel->setActiveSheetIndex(0);
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$ac=0;
$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;
$gz=$GLOBALS['db']->query("SELECT document_no,total,subtotal,register_date,currency_id FROM crm.ecminvoiceouts WHERE parent_id='".$r['id']."' AND paid=0");
while($em=$GLOBALS['db']->fetchByAssoc($gz)){
$cu=$GLOBALS['db']->query("SELECT name FROM crm.currencies WHERE id='".$em['currency_id']."'");
$cur=$GLOBALS['db']->fetchByAssoc($cu);
$objPHPExcel->setActiveSheetIndex(1);
if($ac==0){
$g=$b-1;$objPHPExcel->getActiveSheet()->SetCellValue("A".$g,$r['name']);
$objPHPExcel->getActiveSheet()->SetCellValue("A".$b,'Nr faktury');
$objPHPExcel->getActiveSheet()->SetCellValue("B".$b,'Data wystawienia');
$objPHPExcel->getActiveSheet()->SetCellValue("C".$b,'Kwota netto');
$objPHPExcel->getActiveSheet()->SetCellValue("D".$b,'Kwota brutto');
$objPHPExcel->getActiveSheet()->SetCellValue("E".$b,'Waluta');
$b++;
}
$objPHPExcel->getActiveSheet()->SetCellValue("A".$b,$em['document_no']);
$objPHPExcel->getActiveSheet()->SetCellValue("B".$b,$em['register_date']);
$objPHPExcel->getActiveSheet()->SetCellValue("C".$b,number_format($em['subtotal'],2,",","."));
$objPHPExcel->getActiveSheet()->SetCellValue("D".$b,number_format($em['total'],2,",","."));
if($cur['name']==''){
$objPHPExcel->getActiveSheet()->SetCellValue("E".$b,$em['currency_id']);
} else {
$objPHPExcel->getActiveSheet()->SetCellValue("E".$b,$cur['name']);
}
$b++;
$ac++;
// echo 'lol';
$objPHPExcel->setActiveSheetIndex(0);
}$b+=2;
$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;
$objPHPExcel->getActiveSheet()->SetCellValue("A".$i,$r['name']);
$objPHPExcel->getActiveSheet()->SetCellValue("B".$i,number_format($l_ballance,2,",","."));
$objPHPExcel->getActiveSheet()->SetCellValue("C".$i,number_format($l_summary,2,",","."));
$objPHPExcel->getActiveSheet()->SetCellValue("D".$i,$l_actual_sum);
$objPHPExcel->getActiveSheet()->SetCellValue("E".$i,$l_sum_1_30);
$objPHPExcel->getActiveSheet()->SetCellValue("F".$i,$l_sum_30_60);
$objPHPExcel->getActiveSheet()->SetCellValue("G".$i,$l_sum_60_90);
$objPHPExcel->getActiveSheet()->SetCellValue("H".$i,$l_sum_90_180);
$objPHPExcel->getActiveSheet()->SetCellValue("I".$i,$l_sum_180);
$i++;
}
$b=$i;
$objPHPExcel->getActiveSheet()->SetCellValue("B".$i,$ballance);
$objPHPExcel->getActiveSheet()->SetCellValue("C".$i,$summary);
$objPHPExcel->getActiveSheet()->SetCellValue("D".$i,$actual_sum);
$objPHPExcel->getActiveSheet()->SetCellValue("E".$i,$sum_1_30);
$objPHPExcel->getActiveSheet()->SetCellValue("F".$i,$sum_30_60);
$objPHPExcel->getActiveSheet()->SetCellValue("G".$i,$sum_60_90);
$objPHPExcel->getActiveSheet()->SetCellValue("H".$i,$sum_90_180);
$objPHPExcel->getActiveSheet()->SetCellValue("I".$i,$sum_180);
$objPHPExcel->getActiveSheet()->duplicateStyleArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'F0F0F0')
),
'borders' => array(
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
),
"A1:I1"
);
$objPHPExcel->getActiveSheet()->duplicateStyleArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'F0F0F0')
),
'borders' => array(
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
),
"A".($i).":I".($i)
);
$b+=2;
/*
foreach ($tmp as $v1) {
$a=0;
$b++;
foreach ($v1 as $v2) {
//echo $v2['name'];
if($a==0){
$g=$b-1;$objPHPExcel->getActiveSheet()->SetCellValue("A".$g,$v2['cp']);
$objPHPExcel->getActiveSheet()->SetCellValue("A".$b,'Nr faktury');
$objPHPExcel->getActiveSheet()->SetCellValue("B".$b,'Data wystawienia');
$objPHPExcel->getActiveSheet()->SetCellValue("C".$b,'Kwota netto');
$objPHPExcel->getActiveSheet()->SetCellValue("D".$b,'Kwota brutto');
$b++;
}
$objPHPExcel->getActiveSheet()->SetCellValue("A".$b,$v2['document_no']);
$objPHPExcel->getActiveSheet()->SetCellValue("B".$b,$v2['register_date']);
$objPHPExcel->getActiveSheet()->SetCellValue("C".$b,$v2['subtotal']);
$b++;
$a++;
}
$b+=2;
}
*/
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
chmod("cache/upload",0777);
$microtime=str_replace(".","",str_replace(" ","",microtime()));
$name="cache/upload/PaymentsSummary".$microtime.".xlsx";
$objWriter->save($name);
chmod($name,0777);
header("Location: ".$name);
?>

View File

@@ -0,0 +1,110 @@
<?php
include_once("modules/EcmPaymentStates/helper.php");
set_include_path('include/PHPExcel/');
include 'PHPExcel.php';
include 'PHPExcel/Writer/Excel2007.php';
include 'PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("E5 CRM");
$objPHPExcel->getProperties()->setLastModifiedBy("E5 CRM");
$objPHPExcel->getProperties()->setTitle("Office 2007 PAYMENTS");
$objPHPExcel->getProperties()->setSubject("Office 2007 PAYMENTS");
$objPHPExcel->getProperties()->setDescription("PAYMENTS");
$alf="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
$objPHPExcel->getActiveSheet()->setTitle('Simple');
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue("A1","Number");
$objPHPExcel->getActiveSheet()->SetCellValue("B1","Type");
$objPHPExcel->getActiveSheet()->SetCellValue("C1","Name");
$objPHPExcel->getActiveSheet()->SetCellValue("D1","To");
$objPHPExcel->getActiveSheet()->SetCellValue("E1","Total");
$objPHPExcel->getActiveSheet()->SetCellValue("F1","Document Date");
$objPHPExcel->getActiveSheet()->SetCellValue("G1","User");
$i=2;
if($_REQUEST['end']=="...")$_REQUEST['end']=0;
$inv=getInvoices($_REQUEST['account_id'],$_REQUEST['start'],$_REQUEST['end']);
foreach($inv as $in){
$invs[]="p.id='".$in."'";
}
$z="select p.total,p.document_no,p.register_date,p.ecminvoiceout_id from ecmpayments_ecminvoiceouts as p where p.deleted='0' and (".implode(" or ",$invs).") order by p.register_date desc";
$w=$GLOBALS['db']->query($z);
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if($rr['type']=="correct")$type="Correct";
else $type="Normal";
if(!$rr['name'])$name="blank";
else $name=$rr['name'];
$rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select * from ecminvoiceouts where document_no='".$r['document_no']."'"));
if(!$rr['register_date'])$rr['register_date']=$r['register_date'];
$rrr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select user_name from users where id='".$rr['assigned_user_id']."'"));
$user=$rrr['user_name'];
$objPHPExcel->getActiveSheet()->SetCellValue("A".$i,$r['document_no']);
$objPHPExcel->getActiveSheet()->SetCellValue("B".$i,$type);
$objPHPExcel->getActiveSheet()->SetCellValue("C".$i,$name);
$objPHPExcel->getActiveSheet()->SetCellValue("D".$i,$rr['parent_name']);
$objPHPExcel->getActiveSheet()->SetCellValue("E".$i,$r['total']);
$objPHPExcel->getActiveSheet()->SetCellValue("F".$i,$rr['register_date']);
$objPHPExcel->getActiveSheet()->SetCellValue("G".$i,$user);
$i++;
}
$objPHPExcel->getActiveSheet()->duplicateStyleArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'F0F0F0')
),
'borders' => array(
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
),
"A1:G1"
);
$objPHPExcel->getActiveSheet()->duplicateStyleArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'F0F0F0')
),
'borders' => array(
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
),
"A".($i).":G".($i)
);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
chmod("cache/upload",0777);
$microtime=str_replace(".","",str_replace(" ","",microtime()));
$name="cache/upload/PaymentsSummary".$microtime.".xlsx";
$objWriter->save($name);
chmod($name,0777);
header("Location: ".$name);
?>

View File

@@ -0,0 +1,221 @@
<?php
// helper functions
function getData($id, $expired) {
$db = $GLOBALS ['db'];
$saldo = false;
$settled = " t.settled!='1' AND ";
switch ($expired) {
case 0 :
$payment_date = "1=1";
break;
case 1 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
break;
case 2 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-30 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date BETWEEN '$d_f' AND '$d_t'";
break;
case 3 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-31 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-60 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date BETWEEN '$d_f' AND '$d_t'";
break;
case 4 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-61 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-90 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date BETWEEN '$d_f' AND '$d_t'";
break;
case 5 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-91 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-180 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date BETWEEN '$d_f' AND '$d_t'";
break;
case 6 :
$date = new DateTime ( date ( "Y-m-d" ) );
$date->modify ( '-181 days' );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date < '$d'";
break;
case 7 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d'";
break;
case 8 :
$payment_date = " 1=1 ";
$saldo = true;
$settled = " 1=1 AND ";
break;
case 9:
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
$settled = " 1=1 AND ";
$saldo = true;
break;
}
//start WINIEN
$r = $db->fetchByAssoc ( $db->query ( "
SELECT
sum(
CASE WHEN t.currency_id='PLN' THEN t.value
ELSE t.value*t.currency_value
END
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='1' AND
t.register_date > '2011-12-31' AND
" . $payment_date . "
" ) );
//get part settled transactions
if (!$saldo)
$s = $db->fetchByAssoc($db->query("
SELECT
sum(
CASE WHEN t.currency_id='PLN' THEN rel.value
ELSE rel.value*t.currency_value
END
) AS settled, t.id
FROM ecmtransactions_rel AS rel
INNER JOIN ecmtransactions AS t
ON rel.ecmtransaction_b_id = t.id
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
t.type='1' AND
t.register_date > '2011-12-31' AND
" .$payment_date. "
"));
if (! is_numeric ( $r ['sum'] ))
$r ['sum'] = 0;
if (! is_numeric ( $s ['settled'] ))
$s ['settled'] = 0;
if (floatval($s['settled']) > 0)
$r['sum'] = floatval($r['sum']) - floatval($s['settled']);
$sum = $r['sum'];
//END WINIEN
$r['sum'] = 0;
if ($saldo) {
$r = $db->fetchByAssoc ( $db->query ( "
SELECT
sum(
CASE WHEN t.currency_id='PLN' THEN t.value
ELSE t.value*t.currency_value
END
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
t.type='0' AND
t.register_date > '2011-12-31' AND
" . $payment_date . "
" ) );
}
//END MA
return $sum - $r ['sum'];
}
// sort comparing functions
function cmpUnsettled($a, $b) {
if ($a ['unsettled'] == $b ['unsettled']) {
return 0;
}
return ($a ['unsettled'] < $b ['unsettled']) ? - 1 : 1;
}
function cmpUnsettledDesc($a, $b) {
if ($a ['unsettled'] == $b ['unsettled']) {
return 0;
}
return ($a ['unsettled'] < $b ['unsettled']) ? 1 : - 1;
}
function cmpNotOverdue($a, $b) {
if ($a ['not_overdue'] == $b ['not_overdue']) {
return 0;
}
return ($a ['not_overdue'] < $b ['not_overdue']) ? - 1 : 1;
}
function cmpNotOverdueDesc($a, $b) {
if ($a ['not_overdue'] == $b ['not_overdue']) {
return 0;
}
return ($a ['not_overdue'] < $b ['not_overdue']) ? 1 : - 1;
}
function cmpOverdue($a, $b) {
if ($a ['overdue'] == $b ['overdue']) {
return 0;
}
return ($a ['overdue'] < $b ['overdue']) ? - 1 : 1;
}
function cmpOverdueDesc($a, $b) {
if ($a ['overdue'] == $b ['overdue']) {
return 0;
}
return ($a ['overdue'] < $b ['overdue']) ? 1 : - 1;
}
function cmpAccount($a, $b) {
return strnatcmp ( $a ['name'], $b ['name'] );
}
function cmpAccountDesc($a, $b) {
return - 1 * strnatcmp ( $a ['name'], $b ['name'] );
}
function cmpSaldo($a, $b) {
if ($a ['saldo'] == $b ['saldo']) {
return 0;
}
return ($a ['saldo'] < $b ['saldo']) ? - 1 : 1;
}
function cmpSaldoDesc($a, $b) {
if ($a ['saldo'] == $b ['saldo']) {
return 0;
}
return ($a ['saldo'] < $b ['saldo']) ? 1 : -1;
}
function cmpTodaySaldo($a, $b) {
if ($a ['today_saldo'] == $b ['today_saldo']) {
return 0;
}
return ($a ['today_saldo'] < $b ['today_saldo']) ? - 1 : 1;
}
function cmpTodaySaldoDesc($a, $b) {
if ($a ['today_saldo'] == $b ['today_saldo']) {
return 0;
}
return ($a ['today_saldo'] < $b ['today_saldo']) ? 1 : -1;
}?>

View File

@@ -0,0 +1,45 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
global $mod_strings;
$dashletMeta['MySaldoDashlet'] = array(
'title' => 'Salda',
'description' => 'Salda',
'category' => 'Module Views');
?>

View File

@@ -0,0 +1,285 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/Dashlets/Dashlet.php');
require_once('include/Sugar_Smarty.php');
require_once('Helper.php');
class MySaldoDashlet extends Dashlet {
var $savedText; // users's saved text
var $height = '300'; // height of the pad
var $firstLoad = 'yes';
function MySaldoDashlet($id, $def = null) {
global $current_user, $mod_strings, $app_strings;
require('modules/EcmPaymentStates/Dashlets/MySaldoDashlet/MySaldoDashlet.meta.php');
require('modules/EcmCharts/language/pl_pl.lang.php');
parent::Dashlet($id); // call parent constructor
$this->isConfigurable = true; // dashlet is configurable
$this->hasScript = false; // dashlet has java ipt attached to it
$options = $this->loadOptions();
// if no custom title, use default
if(!$options["title"])
$options["title"] = "Salda";
$this->title = $options["title"];
}
function display() {
global $current_user, $mod_strings, $app_strings;
// prepare data
$db = $GLOBALS ['db'];
if ($_REQUEST['account_type'])
$account_type = $_REQUEST['account_type'];
else
$account_type = '';
if ($_REQUEST['saldo_type'])
$saldo_type = $_REQUEST['saldo_type'];
else
$saldo_type = '';
if ($_REQUEST['type2'])
$and = " and account_type2='".$_REQUEST['type2']."'";
else
$saldo_type = '';
// get list of accounts
$saldo_type='minus';
if ($account_type == '')
$clients = $db->query ( "SELECT distinct t.parent_id FROM ecmtransactions as t
INNER JOIN accounts AS a
ON t.parent_id = a.id
WHERE t.settled!='1' AND t.deleted='0' ".$and." ORDER BY t.parent_name" );
else
$clients = $db->query ( "
SELECT distinct t.parent_id FROM ecmtransactions AS t
INNER JOIN accounts AS a
ON t.parent_id = a.id
WHERE
t.settled!='1' AND
t.deleted='0' AND
a.account_type = '$account_type' ".$and."
ORDER BY t.parent_name;
" );
// arrays to handle data for SMARTY
$data = array ();
$sum = array ();
$sum['saldo'] = 0;
$sum['today_saldo'] = 0;
$sum ['unsettled'] = 0;
$sum ['not_overdue'] = 0;
$sum ['overdue'] = 0;
$sum ['2'] = 0; // 1..30
$sum ['3'] = 0; // 31..60
$sum ['4'] = 0; // 61..90
$sum ['5'] = 0; // 91..180
$sum ['6'] = 0; // 180..
$sum ['8'] = 0;
$sum ['9'] = 0;
$sum ['10'] = 0;
while ( $c = $db->fetchByAssoc ( $clients ) ) {
$row = array ();
$row['id'] = $c['parent_id'];
$tt= $db->fetchByAssoc ( $db->query ( "SELECT name FROM accounts WHERE id='" . $c ['parent_id'] . "'" ) );
$row ['name'] =$tt['name'];
$row ['unsettled'] = getData ( $c ['parent_id'], 0 );
$row ['not_overdue'] = getData ( $c ['parent_id'], 7 );
$row ['overdue'] = getData ( $c ['parent_id'], 1 );
$row ['2'] = getData ( $c ['parent_id'], 2 ); // 1..30
$row ['3'] = getData ( $c ['parent_id'], 3 ); // 31..60
$row ['4'] = getData ( $c ['parent_id'], 4 ); // 61..90
$row ['5'] = getData ( $c ['parent_id'], 5 ); // 91..180
$row ['6'] = getData ( $c ['parent_id'], 6 ); // 180..
$row ['saldo'] = getData ( $c ['parent_id'], 8 );
$row ['today_saldo'] = getData ( $c ['parent_id'], 9 );
if($saldo_type=='plus' && !($row ['saldo']>0))continue;
if($saldo_type=='minus' && $row ['saldo']>0)continue;
$sum ['unsettled'] += $row ['unsettled'];
$sum ['not_overdue'] += $row ['not_overdue'];
$sum ['overdue'] += $row ['overdue'];
$sum ['2'] += $row ['2']; // 1..30
$sum ['3'] += $row ['3']; // 31..60
$sum ['4'] += $row ['4']; // 61..90
$sum ['5'] += $row ['5']; // 91..180
$sum ['6'] += $row ['6']; // 180..
$sum ['saldo'] += $row ['saldo'];
$sum ['today_saldo'] += $row ['today_saldo'];
$data [] = $row;
}
// format sum
$sum ['unsettled'] = format_number ( $sum ['unsettled'] );
$sum ['not_overdue'] = format_number ( $sum ['not_overdue'] );
$sum ['overdue'] = format_number ( $sum ['overdue'] );
$sum ['2'] = format_number ( $sum ['2'] ); // 1..30
$sum ['3'] = format_number ( $sum ['3'] ); // 31..60
$sum ['4'] = format_number ( $sum ['4'] ); // 61..90
$sum ['5'] = format_number ( $sum ['5'] ); // 91..180
$sum ['6'] = format_number ( $sum ['6'] ); // 180..
$sum ['saldo'] = format_number ( $sum ['saldo'] );
$sum ['today_saldo'] = format_number ( $sum ['today_saldo'] );
// sort
$sort = array ();
if ($_REQUEST ['sort'] && $_REQUEST ['sort'] != '')
switch ($_REQUEST ['sort']) {
case 'unsettled' :
if ($_REQUEST ['sortType'] == 'asc') {
usort ( $data, "cmpUnsettled" );
$sort ['unsettled'] = 'desc'; // now is asc, so next is desc
}
if ($_REQUEST ['sortType'] == 'desc') {
usort ( $data, "cmpUnsettledDesc" );
$sort ['unsettled'] = 'asc'; // same story
}
break;
case 'account' :
if ($_REQUEST ['sortType'] == 'asc') {
usort ( $data, "cmpAccount" );
$sort ['account'] = 'desc'; // now is asc, so next is desc
}
if ($_REQUEST ['sortType'] == 'desc') {
usort ( $data, "cmpAccountDesc" );
$sort ['account'] = 'asc'; // same story
}
break;
case 'not_overdue' :
if ($_REQUEST ['sortType'] == 'asc') {
usort ( $data, "cmpNotOverdue" );
$sort ['not_overdue'] = 'desc'; // now is asc, so next is desc
}
if ($_REQUEST ['sortType'] == 'desc') {
usort ( $data, "cmpNotOverdueDesc" );
$sort ['not_overdue'] = 'asc'; // same story
}
break;
case 'overdue' :
if ($_REQUEST ['sortType'] == 'asc') {
usort ( $data, "cmpOverdue" );
$sort ['overdue'] = 'desc'; // now is asc, so next is desc
}
if ($_REQUEST ['sortType'] == 'desc') {
usort ( $data, "cmpOverdueDesc" );
$sort ['overdue'] = 'asc'; // same story
}
break;
case 'saldo' :
if ($_REQUEST ['sortType'] == 'asc') {
usort ( $data, "cmpSaldo" );
$sort ['saldo'] = 'desc'; // now is asc, so next is desc
}
if ($_REQUEST ['sortType'] == 'desc') {
usort ( $data, "cmpSaldoDesc" );
$sort ['saldo'] = 'asc'; // same story
}
break;
case 'today_saldo' :
if ($_REQUEST ['sortType'] == 'asc') {
usort ( $data, "cmpTodaySaldo" );
$sort ['today_saldo'] = 'desc'; // now is asc, so next is desc
}
if ($_REQUEST ['sortType'] == 'desc') {
usort ( $data, "cmpTodaySaldoDesc" );
$sort ['today_saldo'] = 'asc'; // same story
}
break;
}
// format data
foreach ( $data as $key => $row ) {
// format numbers
$row ['unsettled'] = format_number ( $row ['unsettled'] );
$row ['not_overdue'] = format_number ( $row ['not_overdue'] );
$row ['overdue'] = format_number ( $row ['overdue'] );
$row ['2'] = format_number ( $row ['2'] ); // 1..30
$row ['3'] = format_number ( $row ['3'] ); // 31..60
$row ['4'] = format_number ( $row ['4'] ); // 61..90
$row ['5'] = format_number ( $row ['5'] ); // 91..180
$row ['6'] = format_number ( $row ['6'] ); // 180..
$row ['saldo'] = format_number ( $row ['saldo'] );
$row ['today_saldo'] = format_number ( $row ['today_saldo'] );
$data [$key] = $row;
}
// create & execute smarty
$ss = new Sugar_Smarty ();
global $mod_strings;
$ss->assign ( "MOD", $mod_strings );
$ss->assign ( "DATA", $data );
$ss->assign ( "SUM", $sum );
$ss->assign ( "SORT", $sort );
$ss->assign("account_type", $account_type);
$ss->assign("saldo_type",$saldo_type);
$ss->assign("type",$_REQUEST['type2']);
$ss->assign("type2",$app_list_strings['account_type2_dom']);
$output = $ss->fetch('modules/EcmPaymentStates/Dashlets/MySaldoDashlet/MySaldoDashlet.tpl');
// return parent::display for title and smarty template
return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $output;
}
function displayOptions() {
global $mod_strings,$current_user;
// format daty
$smarty = new Sugar_Smarty();
// Pobieram ustawienia
$options = $this->loadOptions();
// Data od
$Calendar_daFormat = str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));
if(!$options['date_from'])
$options['date_from'] = '01.01.2010';
//The id must be assigned in all dashlet options pages
$smarty->assign('id', $this->id);
// Typ dokumentu: all, normal, correct
$smarty->assign('date_from', $options["date_from"]);
$smarty->assign("dateFormat", $Calendar_daFormat);
$smarty->assign('LANG', $mod_strings);
$smarty->assign('title', $options["title"]);
// Pokazywać dane porównawcze? Tak: enabled, nie: disabled
// Przekazuję widok opcji do metody displayOptions()
return parent::displayOptions() . $smarty->fetch('modules/EcmPaymentStates/Dashlets/MySaldoDashlet/MySaldoDashletOptions.tpl');
}
// Zapisywanie opcji dashletu
function saveOptions($req) {
$options = array();
$options["year"] = $req["year"];
$options["comparativeData"] = $req["comparativeData"];
$options["type"] = $req["type"];
$options["chartType"] = $req["chartType"];
$options["title"] = $req["title"];
if( $req["account_name"] == '' )
{
$options["contractor_name"] = '';
$options["contractor_id"] = '';
} else {
$options["contractor_name"] = $req['account_name'];
$options["contractor_id"] = $req['account_id'];
}
return $options;
}
}
?>

View File

@@ -0,0 +1,36 @@
<?
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings, $current_user, $app_list_strings;
require_once('modules/EcmPaymentStates/EcmPaymentState.php');
require_once('modules/EcmPaymentStates/Forms.php');
require_once ('include/time.php');
require_once('include/json_config.php');
$json_config = new json_config();
$focus = new EcmPaymentState();
if(isset($_REQUEST['record']))$focus->retrieve($_REQUEST['record']);
require_once('include/MVC/View/SugarView.php');
if(file_exists('modules/EcmPaymentStates/views/view.detail.php')) {
require_once('modules/EcmPaymentStates/views/view.detail.php');
$detail = new EcmPaymentState();
}
else{
require_once('include/MVC/View/views/view.detail.php');
$detail = new ViewDetail();
$detail->ss = new Sugar_Smarty();
$detail->module = 'EcmPaymentStates';
}
global $app_list_strings;
$detail->bean = $focus;
$detail->preDisplay();
echo $detail->display();
?>

View File

@@ -0,0 +1,161 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: TODO: To be written.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
* Contributor(s): ______________________________________..
********************************************************************************/
require_once('data/SugarBean.php');
require_once('include/utils.php');
class EcmPaymentState extends SugarBean {
var $field_name_map = array();
var $id;
var $date_entered;
var $date_modified;
var $modified_user_id;
var $assigned_user_id;
var $name;
var $value;
var $module_dir = 'EcmPaymentStates';
var $table_name = "ecmpaymentstates";
var $object_name = "EcmPaymentState";
var $new_schema = true;
var $additional_column_fields = array('assigned_user_name', 'assigned_user_id');
function EcmPaymentState() {
parent::SugarBean();
$this->setupCustomFields('EcmPaymentStates');
foreach($this->field_defs as $field){
$this->field_name_map[$field['name']] = $field;
}
}
function get_summary_text(){
return $this->name;
}
function create_list_query($order_by, $where, $show_deleted = 0){
$custom_join = $this->custom_fields->getJOIN();
$query ="SELECT ";
$query.="ecmpaymentstates.*,users.user_name as assigned_user_name";
if($custom_join)$query.=$custom_join['select'];
$query.=" FROM ecmpaymentstates ";
$query.="LEFT JOIN users ON ecmpaymentstates.assigned_user_id=users.id";
$query.=" ";
if($custom_join)$query.=$custom_join['join'];
$where_auto='1=1';
if($show_deleted==0)$where_auto=" $this->table_name.deleted=0 ";
elseif($show_deleted==1)$where_auto=" $this->table_name.deleted=1 ";
if($where!="")$query.="where $where AND ".$where_auto;
else $query.="where ".$where_auto;
if(substr_count($order_by,'.')>0)$query .= " ORDER BY $order_by";
elseif($order_by != "")$query .= " ORDER BY $order_by";
else $query .= " ORDER BY ecmpaymentstates.name";
return $query;
}
function create_export_query($order_by,$where){
$custom_join = $this->custom_fields->getJOIN();
$query ="SELECT ";
$query.="ecmpaymentstates.*,users.user_name as assigned_user_name";
if($custom_join)$query.=$custom_join['select'];
$query.=" FROM ecmpaymentstates ";
$query.="LEFT JOIN users ON ecmpaymentstates.assigned_user_id=users.id";
$query.=" ";
if($custom_join)$query.=$custom_join['join'];
$where_auto='1=1';
if($show_deleted==0)$where_auto=" $this->table_name.deleted=0 ";
elseif($show_deleted==1)$where_auto=" $this->table_name.deleted=1 ";
if($where!="")$query.="where $where AND ".$where_auto;
else $query.="where ".$where_auto;
if(substr_count($order_by,'.')>0)$query .= " ORDER BY $order_by";
elseif($order_by != "")$query .= " ORDER BY $order_by";
else $query .= " ORDER BY ecmpaymentstates.name";
return $query;
}
function fill_in_additional_list_fields(){
}
function fill_in_additional_detail_fields(){
parent::fill_in_additional_detail_fields();
}
function get_list_view_data(){
global $current_language;
$the_array=parent::get_list_view_data();
$app_list_strings=return_app_list_strings_language($current_language);
$mod_strings=return_module_language($current_language,'EcmPaymentStates');
$the_array['NAME']=(($this->name == "") ? "<em>blank</em>" : $this->name);
$the_array['ENCODED_NAME']=$this->name;
return $the_array;
}
function build_generic_where_clause($the_query_string){
$where_clauses=array();
$the_query_string=PearDatabase::quote(from_html($the_query_string));
array_push($where_clauses,"ecmpaymentstates.name like '$the_query_string%'");
$the_where="";
foreach($where_clauses as $clause){
if($the_where!="")$the_where.=" or ";
$the_where.=$clause;
}
return $the_where;
}
function set_notification_body($xtpl,$ecmpaymentstate)
{
global $mod_strings,$app_list_strings;
$xtpl->assign("ECMPAYMENTSTATE_SUBJECT",$ecmpaymentstate->name);
return $xtpl;
}
function bean_implements($interface){
switch($interface){
case 'ACL':return true;
}
return false;
}
function save($check_notify=FALSE){
return parent::save($check_notify);
}
}
?>

View File

@@ -0,0 +1,74 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*
require_once('include/EditView/QuickCreate.php');
require_once('modules/EcmPaymentStates/EcmPaymentState.php');
require_once('include/javascript/javascript.php');
class EcmPaymentStatesQuickCreate extends QuickCreate {
var $javascript;
function process() {
global $current_user, $timedate, $app_list_strings, $current_language, $mod_strings;
$mod_strings = return_module_language($current_language, 'EcmPaymentStates');
parent::process();
$this->ss->assign("PRIORITY_OPTIONS", get_select_options_with_id($app_list_strings['ecmpaymentstate_priority_dom'], $app_list_strings['ecmpaymentstate_priority_default_key']));
$this->ss->assign("STATUS_OPTIONS", get_select_options_with_id($app_list_strings['ecmpaymentstate_status_dom'], $app_list_strings['ecmpaymentstate_status_default_key']));
$this->ss->assign("TYPE_OPTIONS", get_select_options_with_id($app_list_strings['ecmpaymentstate_type_dom'],$app_list_strings['ecmpaymentstate_type_default_key']));
if($this->viaAJAX) { // override for ajax call
$this->ss->assign('saveOnclick', "onclick='if(check_form(\"ecmpaymentstatesQuickCreate\")) return SUGAR.subpanelUtils.inlineSave(this.form.id, \"ecmpaymentstates\"); else return false;'");
$this->ss->assign('cancelOnclick', "onclick='return SUGAR.subpanelUtils.cancelCreate(\"subpanel_ecmpaymentstates\")';");
}
$this->ss->assign('viaAJAX', $this->viaAJAX);
$this->javascript = new javascript();
$this->javascript->setFormName('ecmpaymentstatesQuickCreate');
$focus = new EcmPaymentState();
$this->javascript->setSugarBean($focus);
$this->javascript->addAllFields('');
$this->ss->assign('additionalScripts', $this->javascript->getScript(false));
}
}
*/
?>

View File

@@ -0,0 +1,37 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*********************************************************************************/
require_once('include/EditView/SideQuickCreate.php');

View File

@@ -0,0 +1,49 @@
<?
$c1 = explode("|",substr($_GET['inv'],0,-1));
$c2 = explode("|",substr($_GET['pay'],0,-1));
$account_id = $_GET['account_id'];
$tot_t=0.00;
$tot_v=0.00;
for($j=0;$j<count($c1);$j++){
if($c1[$j]){
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select total from ecmpayments_ecminvoiceouts where id='".$c1[$j]."'"));
$tot_t+=$r['total'];
}
}
for($j=0;$j<count($c2);$j++){
if($c2[$j]){
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select value from ecmpayments where id='".$c2[$j]."'"));
$tot_v+=$r['value'];
}
}
if(round($tot_t,2)-round($tot_v,2)> abs(0.5)){
echo "Error: totals not match, invoices: ".$tot_t.", payments: ".$tot_v;
die();
}
else{
for($j=0;$j<count($c1);$j++){
if($c1[$j]) {
$GLOBALS['db']->query("update ecmpayments_ecminvoiceouts set paid='1',payment_date='".date("Y-m-d")."' where id='".$c1[$j]."'");
$GLOBALS['db']->query("update ecminvoiceouts as i inner join ecmpayments_ecminvoiceouts as pi on i.id=pi.ecminvoiceout_id set i.paid=pi.paid where pi.id='".$c1[$j]."'");
}
}
for($j=0;$j<count($c2);$j++){
if($c2[$j]) {
$GLOBALS['db']->query("update ecmpayments set paid='1' where id='".$c2[$j]."'");
$GLOBALS['db']->query("update ecminvoiceouts as i inner join ecmpayments_ecminvoiceouts as pi on i.id=pi.ecminvoiceout_id set i.paid=pi.paid where pi.id='".$c2[$j]."'");
}
}
$str="";
foreach($_POST as $k => $v){
$str.="&".$k."=".$v;
}
for($j=0;$j<count($c1);$j++){
for($i=0;$i<count($c2);$i++){
$GLOBALS['db']->query("insert into ecmpayments_ecminvoiceouts_rel(id,ee_id,ecmpayment_id) values('".create_guid()."','".$c1[$j]."','".$c2[$i]."');");
}
}
header("Location: index.php?module=EcmPaymentStates&action=index&account_id=".$account_id);
}
?>

View File

@@ -0,0 +1,58 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: TODO To be written.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
* Contributor(s): ______________________________________..
********************************************************************************/
global $mod_strings;
if(ACLController::checkAccess('EcmPaymentStates', 'list', true)){
$module_menu[]=array("index.php?module=EcmPaymentStates&action=AccountPaymentStates&return_module=EcmPaymentStates&return_action=DetailView", $mod_strings['LNK_ECMPAYMENTSTATE_LIST'],"EcmPaymentStates", 'EcmPaymentStates');
$module_menu[]=array("index.php?module=EcmPaymentStates&action=summaryNew&return_module=EcmPaymentStates&return_action=DetailView", $mod_strings['LNK_ECMPAYMENTSTATE_SUMMARY'],"EcmPaymentStates", 'EcmPaymentStates');
$module_menu[]=array("index.php?module=EcmPaymentStates&action=interestView&step=detailAction", 'Odsetki',"EcmPaymentStates", 'EcmPaymentStates');
$module_menu[]=array("index.php?module=EcmReports&action=SendSMS", 'Wysłane SMSy',"EcmPaymentStates", 'EcmPaymentStates');
//$module_menu[]=array("index.php?module=EcmPaymentStates&action=importCSV&return_module=EcmPaymentStates&return_action=DetailView", "Import CSV","EcmPaymentStates", 'EcmPaymentStates');
//$module_menu[]=array("index.php?module=EcmPaymentStates&action=importDBF&return_module=EcmPaymentStates&return_action=DetailView", "Import DBF","EcmPaymentStates", 'EcmPaymentStates');
//$module_menu[]=array("index.php?module=EcmPaymentStates&action=importTXT&return_module=EcmPaymentStates&return_action=DetailView", "Import TXT","EcmPaymentStates", 'EcmPaymentStates');
}
if(ACLController::checkAccess('EcmPaymentStates','list', true)) $module_menu[]=array('#', '<span style="display: none">wp_shortcut_fill_0</span>', '');
?>

View File

@@ -0,0 +1,248 @@
<?php
$w = "35"; // first column width
$w3 = "35";
$w2 = "15"; // second column width
$content = '<p style="text-align: center;"><b>Nota odsetkowa nr '.generatenumber().'</b></p>
<table style="width: 100%; font-size: 8pt;">
<tr>
<td style="width: ' . $w . '%">
<b>ODBIORCA</b>
</td>
<td style="width: ' . $w3 . '%">';
if($focus->parent_shipping_address_name!=''){
$content.= '<b>'.$labels['LBL_PDF_CONTENT_DELIVERY'].'</b>';
}
$content.= '</td>
<td style="width: ' . $w2 . '%"></td>
<td style="text-align: right"></td>
</tr>
<tr>
<td style="width: ' . $w . '%">
' . $focus->parent_name . '
</td>
<td style="width: ' . $w3 . '%">
'.$a->parent_shipping_address_name.'
</td>
<td style="width: ' . $w2 . '%"></td>
<td style="text-align: right"></td>
</tr>
<tr>
<td style="width: ' . $w . '%">
' . $a->register_address_street . '
</td>
<td style="width: ' . $w3 . '%">
' . $a->parent_shipping_address_street . '
</td>
<td style="width: ' . $w2 . '%">';
$content.= '</td>
<td style="text-align: right">
</td>
</tr>
<tr>
<td style="width: ' . $w . '%">
'. $a->register_address_postalcode . ' ' . $a->register_address_city;
if (!is_null($focus->parent_address_country) & $focus->parent_address_country!='')
$content.=', '.$a->register_address_country;
$content.='
</td>
<td style="width: ' . $w3 . '%">
'. $focus->parent_shipping_address_postalcode . ' ' . $focus->parent_shipping_address_city;
if (!is_null($focus->parent_shipping_address_country) & $focus->parent_shipping_address_country!='')
$content.=', '.$focus->parent_shipping_address_country;
$content.='
</td>
<td style="width: ' . $w2 . '%">
</td>
<td style="text-align: right">
</td>
</tr>';
$content.='
<tr>
<td valign="top" style="width: ' . $w . '%">NIP: '.$a->to_vatid;
$content.='
</td>';
$content.='
<td valign="top" style="width: ' . $w3 . '%">';
if (!is_null($focus->parent_shipping_nip) && $focus->parent_shipping_nip) {
$content.=$labels['LBL_PDF_CONTENT_NIP'].' '.$focus->parent_shipping_nip;
$nip = true;
}
if (!is_null($focus->parent_shipping_iln) && $focus->parent_shipping_iln) {
if ($nip) $content.'<br>'; $nip = false;
$content.=$labels['LBL_PDF_CONTENT_ILN'].' '.$focus->parent_shipping_iln;
}
$content.='
</td>
<td valign="top" style="width: ' . $w2 . '%"></td>
<td colspan="0" valign="top" style="text-align: right">
</td>
</tr>';
$content.='
</table>
';
$content .= '<br><table width="100%" style="font-size: 7pt;text-align:right;vertical-align:top;">
<tr><td width="11%" >Data dokumentu:<br>'.$labels['LBL_PDF_CONTENT_SELL_DATE'].'</td>
<td style="text-align: left;" width="20%"><b>' . $focus->register_date . '</b><br><b>' . $focus->sell_date . '</b></td>
<td rowspan="2" style="text-align: left;vertical-align:top;">';
if($focus->order_no!=''){
$content.=$labels['LBL_PDF_CONTENT_PARENT_DOCUMENT_NO'].':<br>';
}
$content.='</td>
<td rowspan="2" style="vertical-align:top;">';
if($focus->order_no!=''){
$content.='<b>' . $focus->order_no.'</b><br>';
}
$content.='</td></tr></table><br>';
// start items table
$columns = array ();
$columns ['position'] = array (
'field' => array (
'position'
),
'label' => 'Lp.',
'align' => 'center'
);
$columns ['name'] = array (
'field' => array (
'name',
),
'label' => 'Nazwa',
'align' => 'left'
);
$columns ['total2'] = array (
'field' => array (
'paid'
),
'label' => 'Kwota',
'align' => 'right'
);
$columns ['qty'] = array (
'field' => array (
'from',
),
'label' => 'Termin płatności',
'align' => 'right'
);
$columns ['price_netto'] = array (
'field' => array (
'to'
),
'label' => 'Data zapłaty',
'align' => 'right'
);
$columns ['total_vat'] = array (
'field' => array (
'days'
),
'label' => 'Dni po<br>Terminie',
'align' => 'right'
);
$columns ['total'] = array (
'field' => array (
'total'
),
'label' => 'Wartość<br>odsetek',
'align' => 'right'
);
// set widths
$totals = array ();
$columns ['position'] ['width'] = '5';
$columns ['name'] ['width'] = '41';
$columns ['total2'] ['width'] = '10';
$columns ['qty'] ['width'] = '10';
$columns ['price_netto'] ['width'] = '10';
$columns ['total_vat'] ['width'] = '10';
$columns ['total'] ['width'] = '10';
// rysujemy :)
$content .= '
<table style="width: 100%; font-size: 7pt; border: 0.5 solid black; border-collapse: collapse;"><thead>
<tr>
';
foreach ( $columns as $col ) {
$content .= '
<th style="border: 0.5 solid black; width: ' . $col ['width'] . '%;background-color: #E9E9E9;">' . $col ['label'] . '</th>
';
}
$content .= '
</tr></thead><tbody>
';
$counter=1;
foreach ( $positions as $pos ) {
$content .= '<tr>';
foreach ( $columns as $col ) {
$content .= '<td style="border: 0.5 solid black; text-align: ' . $col ['align'] . ';">';
foreach ( $col ['field'] as $f ) {
if (! $pos [$f] || $pos [$f] == '')
$pos [$f] = '-';
$content .= $pos [$f] . '<br>';
}
$content .= '</td>';
}
$content .= '</tr>';
}
$content .= '
</tbody></table>
';
// summary table
// get currency symbol
$c = new Currency ();
$c->retrieve ( $focus->currency_id );
$symbol = $c->symbol;
unset ( $c );
$content .= '
<br>
<table style="font-size: 9pt; border: 0.5 solid black; border-collapse: collapse; width: 300px; margin-left: 60%">
';
$content .= '
<tr>
<td style="font-size: 6.5pt; border: 0.5 solid black; width: 23%;text-align: center;background-color: #E9E9E9;">
<b>Razem odsetki</b>
</td>
<td style="font-size: 6.5pt; border: 0.5 solid black; width: 27%;text-align: right;background-color: #E9E9E9;">
<b>'.format_number($focus->total).'</b>
</td></tr>';
$content .= '
</table>';
//echo $content; die();

View File

@@ -0,0 +1,274 @@
<?php
$w = "35"; // first column width
$w3 = "35";
$w2 = "15"; // second column width
$content = '
<table style="width: 100%; font-size: 8pt;">
<tr>
<td style="width: ' . $w . '%">
<b>ODBIORCA</b>
</td>
<td style="width: ' . $w3 . '%">';
if($focus->parent_shipping_address_name!=''){
$content.= '<b>'.$labels['LBL_PDF_CONTENT_DELIVERY'].'</b>';
}
$content.= '</td>
<td style="width: ' . $w2 . '%"></td>
<td style="text-align: right"></td>
</tr>
<tr>
<td style="width: ' . $w . '%">
' . $focus->parent_name . '
</td>
<td style="width: ' . $w3 . '%">
'.$a->parent_shipping_address_name.'
</td>
<td style="width: ' . $w2 . '%"></td>
<td style="text-align: right"></td>
</tr>
<tr>
<td style="width: ' . $w . '%">
' . $a->register_address_street . '
</td>
<td style="width: ' . $w3 . '%">
' . $a->parent_shipping_address_street . '
</td>
<td style="width: ' . $w2 . '%">';
$content.= '</td>
<td style="text-align: right">
</td>
</tr>
<tr>
<td style="width: ' . $w . '%">
'. $a->register_address_postalcode . ' ' . $a->register_address_city;
if (!is_null($focus->parent_address_country) & $focus->parent_address_country!='')
$content.=', '.$a->register_address_country;
$content.='
</td>
<td style="width: ' . $w3 . '%">
'. $focus->parent_shipping_address_postalcode . ' ' . $focus->parent_shipping_address_city;
if (!is_null($focus->parent_shipping_address_country) & $focus->parent_shipping_address_country!='')
$content.=', '.$focus->parent_shipping_address_country;
$content.='
</td>
<td style="width: ' . $w2 . '%">
</td>
<td style="text-align: right">
</td>
</tr>';
$content.='
<tr>
<td valign="top" style="width: ' . $w . '%">NIP: '.$a->to_vatid;
$content.='
</td>';
$content.='
<td valign="top" style="width: ' . $w3 . '%">';
if (!is_null($focus->parent_shipping_nip) && $focus->parent_shipping_nip) {
$content.=$labels['LBL_PDF_CONTENT_NIP'].' '.$focus->parent_shipping_nip;
$nip = true;
}
if (!is_null($focus->parent_shipping_iln) && $focus->parent_shipping_iln) {
if ($nip) $content.'<br>'; $nip = false;
$content.=$labels['LBL_PDF_CONTENT_ILN'].' '.$focus->parent_shipping_iln;
}
$content.='
</td>
<td valign="top" style="width: ' . $w2 . '%"></td>
<td colspan="0" valign="top" style="text-align: right">
</td>
</tr>';
$content.='
</table>
';
if($EcmSysInfo->getDatabaseName()=='preDb_45ab7160e7af49269e17044eaed9e0ba'){
$content='';
}
$content .= '<br><table width="100%" style="font-size: 7pt;text-align:right;vertical-align:top;">
<tr><td width="11%" >Data dokumentu:<br>'.$labels['LBL_PDF_CONTENT_SELL_DATE'].'</td>
<td style="text-align: left;" width="20%"><b>' . date('d.m.Y') . '</b><br><b>' . $focus->sell_date . '</b></td>
<td rowspan="2" style="text-align: left;vertical-align:top;">';
if($focus->order_no!=''){
$content.=$labels['LBL_PDF_CONTENT_PARENT_DOCUMENT_NO'].':<br>';
}
$content.='</td>
<td rowspan="2" style="vertical-align:top;">';
if($focus->order_no!=''){
$content.='<b>' . $focus->order_no.'</b><br>';
}
$content.='</td></tr></table><br>';
if($EcmSysInfo->getDatabaseName()=='preDb_45ab7160e7af49269e17044eaed9e0ba'){
$content='<div style="width:100%;text-align: center;"><b>Wezwanie do zapłaty</b></div><br><br><div style="width:100%;text-align: left;font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wzywamy do uregulowania w terminie 7 dni od daty otrzymania niniejszego wezwania do zapłaty niżej wymienionych należności w łącznej kwocie
<b>'.format_number($focus->interest).'</b> zł<br>Należność należy przekazać na konto <b>RAIFFEISEN BANK POLSKA S.A.</b><br>nr konta 42 1750 0009 0000 0000 2627 2699<br><br></div>';
}
// start items table
$columns = array ();
$columns ['position'] = array (
'field' => array (
'position'
),
'label' => 'Lp.',
'align' => 'center'
);
$columns ['name'] = array (
'field' => array (
'name',
),
'label' => 'Nazwa',
'align' => 'left'
);
$columns ['date_doc'] = array (
'field' => array (
'date_doc',
),
'label' => 'Data dokumentu',
'align' => 'right'
);
$columns ['total2'] = array (
'field' => array (
'paid'
),
'label' => 'Kwota',
'align' => 'right'
);
$columns ['qty'] = array (
'field' => array (
'payment_date',
),
'label' => 'Termin płatności',
'align' => 'right'
);
$columns ['total_vat'] = array (
'field' => array (
'days'
),
'label' => 'Dni po<br>Terminie',
'align' => 'right'
);
$columns ['total'] = array (
'field' => array (
'total'
),
'label' => 'Odsetki<br>na dziś',
'align' => 'right'
);
// set widths
$totals = array ();
$columns ['position'] ['width'] = '5';
$columns ['name'] ['width'] = '31';
$columns ['date_doc'] ['width'] = '10';
$columns ['total2'] ['width'] = '10';
$columns ['qty'] ['width'] = '10';
$columns ['total_vat'] ['width'] = '10';
$columns ['total'] ['width'] = '10';
// rysujemy :)
$content .= '
<table style="width: 100%; font-size: 7pt; border-collapse: collapse;"><thead>
<tr>
';
foreach ( $columns as $col ) {
$content .= '
<th style="border: 0.5 solid black; width: ' . $col ['width'] . '%;background-color: #E9E9E9;">' . $col ['label'] . '</th>
';
}
$content .= '
</tr></thead><tbody>
';
$counter=1;
foreach ( $positions as $pos ) {
$content .= '<tr>';
foreach ( $columns as $col ) {
$content .= '<td style="border: 0.5 solid black; text-align: ' . $col ['align'] . ';">';
foreach ( $col ['field'] as $f ) {
if (! $pos [$f] || $pos [$f] == '')
$pos [$f] = '-';
$content .= $pos [$f] . '<br>';
}
$content .= '</td>';
}
$content .= '</tr>';
}
$content .= '
</tbody>
<tr style="border: 0 solid black;"><td style="border: 0 solid black;"></td>
tr style="border: 0 solid black;"><td style="border: 0 solid black;"></td>
<td style="border: 0 solid black;text-align:right"><b>Razem</b></td>
<td style="border: 0 solid black;text-align:right;"><b>'.format_number($focus->interest).'</b></td>
<td style="border: 0 solid black;"></td>
<td style="border: 0 solid black;"></td>
<td style="border: 0 solid black;text-align:right;"><b>'.format_number($focus->total).'</b></td>';
$content .= '</tr>
</table>
';
if($EcmSysInfo->getDatabaseName()=='preDb_45ab7160e7af49269e17044eaed9e0ba'){
$content.='<div style="width:100%;text-align: left;font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;W przypadku nie uregulowania należności w podanym wyżej terminie sprawa zostanie automatycznie skierowana na drogę sądową i wpisana do KRD<br><br></div>';
$content.='<br><BR>
<table style="width:100%">
<tr>
<td style="width:50%">
</td>
<td style="width:50%;text-align:center;">
.............................................<br>Podpis
</td>
</tr>
</table>';
}
// summary table
// get currency symbol
$c = new Currency ();
$c->retrieve ( $focus->currency_id );
$symbol = $c->symbol;
unset ( $c );
$content .= '
<br>
';
//echo $content; die();

View File

@@ -0,0 +1,100 @@
<?php
$w = "62"; //first column width
$w2 = "12"; //second column width
$footer = '
<hr>
<table style="width: 100%; font-size: 7pt;">
<tr>
<td style="width: '.$w.'%">
e5 Polska Sp. z o.o
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_KRS'].'</b>
</td>
<td style="text-align: right">
28207
</td>
</tr>
<tr>
<td style="width: '.$w.'%">
ul. Wąwozowa 11
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_NIP'].'</b>
</td>
<td style="text-align: right">
PL 525-21-73-990
</td>
</tr>
<tr>
<td style="width: '.$w.'%">
02-796 Warszawa
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_REGON'].'</b>
</td>
<td style="text-align: right">
016280234
</td>
</tr>
<tr>
<td style="width: '.$w.'%">
Tel: +48 (22) 228 20 90
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_BANK'].'</b>
</td>
<td style="text-align: right">
';
if ($bank=='milenium')
$footer.='BANK MILLENIUM';
if ($bank=='mbank')
$footer.='MBANK';
$footer.='
</td>
</tr>
<tr>
<td style="width: '.$w.'%">
Fax: +48 (56) 674 60 47
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_BANK_ACCOUNT'].'</b>
</td>
<td style="text-align: right">
';
if ($bank=='milenium')
$footer.='PL36116022020000000064080587';
if ($bank=='mbank')
$footer.='PL96114010100000548212001002';
$footer.='
</td>
</tr>
<tr>
<td style="width: '.$w.'%">
'.$user->email1.'
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_SWIFT'].'</b>
</td>
<td style="text-align: right">
';
if ($bank=='milenium')
$footer.='BIGBPLPW';
if ($bank=='mbank')
$footer.='BREXPLPW';
$footer.='
</td>
</tr>
</table>
<br>
<table style="width: 100%; font-size: 7pt;">
<tr>
<td style="width: 50%;">
{PAGENO}/{nb}
</td>
<td style="width: 50%; text-align: right">
<b>'.$focus->document_no.'</b>
</td>
</tr>
</table>
';

View File

@@ -0,0 +1,95 @@
<?php
$w = "62"; //first column width
$w2 = "12"; //second column width
$footer = '
<hr>
<table style="width: 100%; font-size: 7pt;">
<tr>
<td style="width: '.$w.'%">
e5 Polska Sp. z o.o
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_KRS'].'</b>
</td>
<td style="text-align: right">
28207
</td>
</tr>
<tr>
<td style="width: '.$w.'%">
ul. Wąwozowa 11
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_NIP'].'</b>
</td>
<td style="text-align: right">
PL 525-21-73-990
</td>
</tr>
<tr>
<td style="width: '.$w.'%">
02-796 Warszawa
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_REGON'].'</b>
</td>
<td style="text-align: right">
016280234
</td>
</tr>
<tr>
<td style="width: '.$w.'%">
Tel: +48 (22) 228 20 90
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_BANK'].'</b>
</td>
<td style="text-align: right">
';
if ($bank=='milenium')
$footer.='BANK MILLENIUM';
if ($bank=='mbank')
$footer.='MBANK';
$footer.='
</td>
</tr>
<tr>
<td style="width: '.$w.'%">
Fax: +48 (56) 674 60 47
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_BANK_ACCOUNT'].'</b>
</td>
<td style="text-align: right">
';
if ($bank=='milenium')
$footer.='35 1160 2202 0000 0000 6408 0411';
if ($bank=='mbank')
$footer.='26 1140 1010 0000 5482 1200 1001';
$footer.='
</td>
</tr>
<tr>
<td style="width: '.$w.'%">
'.$user->email1.'
</td>
<td style="width: '.$w2.'%">
<b>'.$labels['LBL_PDF_FOOTER_GIOS'].'</b>
</td>
<td style="text-align: right">
E0006254W
</td>
</tr>
</table>
<br>
<table style="width: 100%; font-size: 7pt;">
<tr>
<td style="width: 50%;">
{PAGENO}/{nb}
</td>
<td style="width: 50%; text-align: right">
<b>'.$focus->document_no.'</b>
</td>
</tr>
</table>
';

View File

@@ -0,0 +1,22 @@
<?php
$db = $GLOBALS ['db'];
$querySelect = 'SELECT text0 FROM operating_values WHERE id="16"';
$rows = $db->fetchByAssoc($db->query($querySelect));
$header = html_entity_decode($rows['text0']);
$a = new Account();
$a->retrieve($focus->parent_id);
$header='<div style="width: 100%;text-align:right;">Warszawa, dn. '.date("d.m.Y").'
</div><BR>
<table style="width:100%">
<tr>
<td style="width:50%">
BSL SP Z O.O.<br>
96-321 ŻABIA WOLA<BR>
ul. Przejazdowa 17<BR>
NIP: 7831627857
</td>
<td style="width:50%">
'.$a->name.'<br>'.$a->register_address_street.'<br>'.$a->register_address_postalcode.' '.$a->register_address_city.'<br>'.$a->to_vatid.'<br>
</td>
</tr>
</table>';

View File

@@ -0,0 +1,47 @@
<?php
function formatPDFPositions($positions, $focus) {
$result = array();
foreach ($positions as $pos) {
$pos['position'] = intval($pos['position'])+1;
$pos['total']=format_number($pos['total']);
$pos['paid']=format_number($pos['paid']);
$result[] = $pos;
}
return $result;
}
function formatPDFPositionsCorrect($pos, $focus) {
$pos['position'] = intval($pos['position'])+1;
$pos['quantity'] = $pos['quantity'];
$pos['price_netto']=format_number($pos['price_netto']);
$pos['total_vat']=format_number($pos['total_vat']);
$pos['ecmvat_value']=format_number($pos['ecmvat_value']);
$pos['total_brutto']=format_number($pos['total_brutto']);
$pos['total_netto']=format_number($pos['total_netto']);
return $pos;
}
function mysql_escape_gpc($dirty)
{
if (ini_get('magic_quotes_gpc'))
{
return $dirty;
}
else
{
return mysql_real_escape_string($dirty);
}
}

View File

@@ -0,0 +1,51 @@
<?php
$fv[]=153;$v[]=-2.44;
$fv[]=186;$v[]=-99.98;
$fv[]=284;$v[]=-755.62;
$fv[]=290;$v[]=-48.74;
$fv[]=291;$v[]=-199.96;
$fv[]=313;$v[]=-782.61;
$fv[]=314;$v[]=-971.51;
$fv[]=320;$v[]=-917.54;
$fv[]=321;$v[]=-224.97;
$fv[]=322;$v[]=-639.77;
$fv[]=323;$v[]=-575.84;
$fv[]=329;$v[]=-17.08;
$fv[]=330;$v[]=-54.90;
$fv[]=331;$v[]=-43.92;
$fv[]=332;$v[]=-43.92;
$fv[]=333;$v[]=-54.90;
$fv[]=334;$v[]=-95.99;
$fv[]=335;$v[]=-13.49;
$fv[]=336;$v[]=-39.99;
$fv[]=337;$v[]=-52.81;
$fv[]=338;$v[]=-161.31;
$fv[]=339;$v[]=-39.99;
$fv[]=340;$v[]=-103.97;
$fv[]=341;$v[]=-64.78;
$fv[]=342;$v[]=-56.00;
$fv[]=343;$v[]=-143.01;
$fv[]=344;$v[]=-31.99;
$fv[]=345;$v[]=-8.54;
$fv[]=346;$v[]=-24.00;
$fv[]=357;$v[]=-52.48;
$fv[]=358;$v[]=-24.00;
$fv[]=359;$v[]=-161.31;
$fv[]=360;$v[]=-39.99;
$fv[]=361;$v[]=-6.75;
$fv[]=362;$v[]=-20.79;
$fv[]=371;$v[]=-20.79;
$fv[]=372;$v[]=-114.16;
$fv[]=373;$v[]=-55.99;
$fv[]=374;$v[]=-17.60;
$fv[]=375;$v[]=-65.49;
$fv[]=388;$v[]=-71.22;
$fv[]=395;$v[]=-1308.82;
$fv[]=62;$v[]=-89.96;
$fv[]=76;$v[]=-22.47;
for($i=0;$i<count($fv);$i++){
echo("insert into ecmpayments_ecminvoiceouts values('".create_guid()."','','','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."','1','1','0','0','FVKOR ".$fv[$i]."/10','".$v[$i]."',134,'2010-05-19','');<br>");
}
?>

View File

@@ -0,0 +1,28 @@
<?php
function getTotal($id){
$w=$GLOBALS['db']->query("select price,ecmvat_value,quantity from ecminvoiceoutitems where ecminvoiceout_id='".$id."' and deleted='0'");
while($r=$GLOBALS['db']->fetchByAssoc($w))$total+=$r['price']*$r['quantity']*(1+$r['ecmvat_value']/100);
return $total;
}
function getTotalCorrect($id){
$w=$GLOBALS['db']->query("select price,ecmvat_value,quantity,ecminvoiceoutitem_id from ecminvoiceoutitems where ecminvoiceout_id='".$id."'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$total+=round($r['price']*$r['quantity']*(1+$r['ecmvat_value']/100),2);
$rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select price,ecmvat_value,quantity from ecminvoiceoutitems where id='".$r['ecminvoiceoutitem_id']."'"));
$total-=round($rr['price']*$rr['quantity']*(1+$rr['ecmvat_value']/100),2);
}
return $total;
}
$arr="376,377,378,379,380,381,382,383,384,385,386,387";
$e=explode(",",$arr);
foreach($e as $ee){
$no="FVKOR ".$ee."/10";
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select id,register_date from ecminvoiceouts where document_no like '".$no."'"));
$inv_id=$r['id'];
$d="2010-06-10";
$total=getTotalCorrect($inv_id);
echo "insert into ecmpayments_ecminvoiceouts set paid='0',register_date='".$d."',account_id='134',id='".create_guid()."',ecminvoiceout_id='".$inv_id."',document_no='".$no."',total=".$total.",deleted=0,created_by=1,modified_user_id=1,date_entered='".date("Y-m-d H:i:s")."'
,date_modified='".date("Y-m-d H:i:s")."';<br>";
}
?>

View File

@@ -0,0 +1,18 @@
<?
$data[]="FVKOR 018/10";
$data[]="FVKOR 021/10";
$data[]="FVKOR 023/10";
$data[]="FVKOR 022/10";
$data[]="FVKOR 020/10";
$data[]="FVKOR 012/10";
$data[]="FVKOR 003/10";
for($i=0;$i<count($data);$i++){
$e=explode(" ",$data[$i]);
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select id,document_no,total,register_date from ecminvoiceouts where document_no like '".$data[$i]."'"));
$inv_id=$r['id'];
$inv_name=$r['document_no'];
$date=$r['register_date'];
$total=$r['total'];
echo "insert into ecmpayments_ecminvoiceouts set id='".create_guid()."',ecminvoiceout_id='".$inv_id."',date_entered='".date("Y-m-d H:i:s")."',date_modified='".date("Y-m-d H:i:s")."',created_by=1,modified_user_id=1,deleted=0,paid=0,document_no='".$inv_name."',total='".$total."',account_id='134',register_date='".$date."';<br>";
}
?>

View File

@@ -0,0 +1,48 @@
<?php
/*echo "find diff<br>";
$w=$GLOBALS['db']->query("select document_no,payment_date,type,id from ecminvoiceouts where register_date>'2010-03-01'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select register_date,total from ecmpayments_ecminvoiceouts where document_no like '".$r['document_no']."'"));
if($r['payment_date']!=$rr['register_date']){
echo $r['document_no']." ".$r['payment_date']." ".$rr['register_date']."<br>";
$GLOBALS['db']->query("update ecmpayments_ecminvoiceouts set register_date='".$r['payment_date']."' where document_no like '".$r['document_no']."'");
}
if($rr['total']==0){
if($r['type']=="correct"){
$total=0;
$www=$GLOBALS['db']->query("select price,quantity,ecmvat_value,ecminvoiceoutitem_id from ecminvoiceoutitems where ecminvoiceout_id='".$r['id']."' and deleted='0'");
while($rrr=$GLOBALS['db']->fetchByAssoc($www)){
$rrrr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select price,quantity,ecmvat_value from ecminvoiceoutitems where id='".$rrr['ecminvoiceoutitem_id']."'"));
$total+=$rrr['price']*$rrr['quantity']*(1+$rrr['ecmvat_value']/100)-$rrrr['price']*$rrrr['quantity']*(1+$rrrr['ecmvat_value']/100);
}
$GLOBALS['db']->query("update ecmpayments_ecminvoiceouts set total='".$total."' where document_no='".$r['document_no']."'");
}
else{
$total=0;
$www=$GLOBALS['db']->query("select price,quantity,ecmvat_value,ecminvoiceoutitem_id from ecminvoiceoutitems where ecminvoiceout_id='".$r['id']."' and deleted='0'");
while($rrr=$GLOBALS['db']->fetchByAssoc($www)){
$total+=$rrr['price']*$rrr['quantity']*(1+$rrr['ecmvat_value']/100);
}
$GLOBALS['db']->query("update ecmpayments_ecminvoiceouts set total='".$total."' where document_no='".$r['document_no']."'");
}
echo $r['document_no']." ".$total."<br>";
}
}*/
echo "find dup<br>";
$w=$GLOBALS['db']->query("select document_no,payment_date,type,id from ecminvoiceouts where register_date>'2010-03-01'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$num=mysql_num_rows($GLOBALS['db']->query("select id from ecmpayments_ecminvoiceouts where document_no like '".$r['document_no']."'"));
if($num>1){
echo $r['document_no']." ".$num."<br>";
$i=0;
$ww=$GLOBALS['db']->query("select id from ecmpayments_ecminvoiceouts where document_no like '".$r['document_no']."'");
while($rr=$GLOBALS['db']->fetchByAssoc($ww)){
if($i!=0){
$GLOBALS['db']->query("delete from ecmpayments_ecminvoiceouts where id='".$rr['id']."'");
echo mysql_error();
}
$i++;
}
}
}
?>

View File

@@ -0,0 +1,6 @@
<?php
set_time_limit (-1);
include 'modules/EcmPaymentStates/interestModel.php';
$m= new interestModel();
$m->makeNotes();
?>

View File

@@ -0,0 +1,178 @@
<?php
//add mz 2014-12-30
//check session variable
if($_REQUEST['show']=='yes' && $_REQUEST['record2']!='')createEcmPaymentStatePdf('null','BROSWER','null',$_REQUEST['record2']);
function generatenumber(){
$db=$GLOBALS['db'];
$num=$db->fetchByAssoc($db->query("select count(*) as n from ecmpaymentstate_pdf where YEAR(date_entered)='".date("Y")."'"));
$num['n']++;
$tmp = strval($num['n']);
while (strlen($tmp) < 5)
$tmp = '0'.$tmp;
return $tmp.'/'.date("Y");
}
function calculatetotal($p){
$total=0;
foreach ($p as $k=>$v){
$total+=$p[$k]['total'];
}
return $total;
}
function calculatetotal2($p){
$total=0;
foreach ($p as $k=>$v){
$total+=$p[$k]['total']+$p[$k]['paid'];
}
return $total;
}
function calculatetotal3($p){
$total=0;
foreach ($p as $k=>$v){
$total+=$p[$k]['paid'];
}
return $total;
}
function createEcmPaymentStatePdf($record, $outputtype,$positions,$id) {
include_once ("modules/EcmPaymentStates/PDFTemplate/helper.php");
$focus = new EcmTransaction ();
$focus->retrieve ( $record );
$a= new Account();
$a->retrieve($focus->parent_id);
$user = new User ();
$user->retrieve ( $focus->assigned_user_id );
$labels = return_module_language($focus->ecmlanguage, 'EcmPaymentStates');
include_once ("include/MPDF57/mpdf.php");
$p = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 30, 45, 5, 5 );
$mpdf->mirrorMargins = 1;
$db = $GLOBALS ['db'];
// document pdf
// document already exist?
$focus->total=calculatetotal($positions);
$res = $db->query ( "SELECT footer, content FROM ecmpaymentstate_pdf WHERE id='$id'" );
if ($res->num_rows == 0) {
// create and save document
//$positions = formatPDFPositions ( $positions, $focus );
// get header
$header = '';
include ("modules/EcmPaymentStates/PDFTemplate/header.php");
$content = '';
include("modules/EcmPaymentStates/PDFTemplate/content.php");
global $current_user,$app_list_strings;
$db->query ( "INSERT INTO ecmpaymentstate_pdf VALUES ('$id','$current_user->id', NOW(),'" . urlencode ( $header ) . "', '" . urlencode( $content ) . "','')" );
} else {
$row = $db->fetchByAssoc ( $res );
$header = urldecode ( $row ['footer'] ); // punk rock!
$content = urldecode ( $row ['content'] );
}
//var_dump($positions);
$p->SetHTMLHeader ( $header );
$footer='<hr><table style="font-size: 8pt; width: 100%;vertical-align:top;">
<tr><td width="25%">Saas SystemS Sp. z o.o.<br />
ul. Lipnowska 21-23<br />
87-100 Toruń<br />
NIP: 9562307719</td><td width="25%"></td><td width="20%">Bank: <br>Numer konta:</td><td>PKO BP<br> 53 1020 5011 0000 9002 0270 6323</td></tr></table>';
//$p->SetHTMLFooter($footer);
$p->WriteHTML ( $content );
//echo $content;
// draw PDF
switch ($outputtype) {
case "BROSWER" :
$p->Output ();
return true;
case "FILE" :
$path = 'upload/fk_' . str_replace('/','',(str_replace(' ', '', $focus->document_no))) . '.pdf';
break;
case "EMAIL" :
include_once 'include/ECM/EcmSendMail/EcmSendMail.inc';
$path = EcmSendMail::TEMP_DIR . 'ZS_' . $focus->number . '.pdf';
break;
case "MULTIPDF" :
include_once 'include/ECM/EcmMultiPdf/EcmMultiPdf.inc';
$path = EcmMultiPdf::TEMP_DIR . 'EcmSales_' . $focus->id. '_' . create_guid() . '.pdf';
break;
};
$p->Output ($path, "F" );
return $path;
}
function createEcmPaymentStatePdf2($record, $outputtype,$positions,$id) {
include_once ("modules/EcmPaymentStates/PDFTemplate/helper.php");
$focus = new EcmTransaction ();
$focus->retrieve ( $record );
$a= new Account();
$a->retrieve($focus->parent_id);
$user = new User ();
$user->retrieve ( $focus->assigned_user_id );
$labels = return_module_language($focus->ecmlanguage, 'EcmPaymentStates');
include_once ("include/MPDF57/mpdf.php");
$p = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 40, 55, 5, 5 );
$mpdf->mirrorMargins = 1;
$db = $GLOBALS ['db'];
// document pdf
// document already exist?
$focus->total=calculatetotal($positions);
$focus->interest=calculatetotal3($positions);
// create and save document
$positions = formatPDFPositions ( $positions, $focus );
// get header
$header = '';
include ("modules/EcmPaymentStates/PDFTemplate/header.php");
global $current_user,$app_list_strings;
//var_dump($positions);
$EcmSysInfo = new EcmSysInfo();
if($EcmSysInfo->getDatabaseName()!='preDb_45ab7160e7af49269e17044eaed9e0ba'){
$header = $EcmSysInfo->getHeaderForModule('EcmPaymentStates');
}
$footer = $EcmSysInfo->getFooterForModule('EcmPaymentStates');
$p->SetHTMLHeader ( $header );
$content = '';
include("modules/EcmPaymentStates/PDFTemplate/content2.php");
$p->SetHTMLFooter($footer);
$p->WriteHTML ( $content );
//echo $content;
// draw PDF
switch ($outputtype) {
case "BROSWER" :
$p->Output ();
return true;
case "FILE" :
$path = 'upload/fk_' . str_replace('/','',(str_replace(' ', '', $focus->id))) . '.pdf';
break;
case "EMAIL" :
include_once 'include/ECM/EcmSendMail/EcmSendMail.inc';
$path = EcmSendMail::TEMP_DIR . 'ZS_' . $focus->number . '.pdf';
break;
case "MULTIPDF" :
include_once 'include/ECM/EcmMultiPdf/EcmMultiPdf.inc';
$path = EcmMultiPdf::TEMP_DIR . 'EcmSales_' . $focus->id. '_' . create_guid() . '.pdf';
break;
};
$p->Output ($path, "F" );
return $path;
}

View File

@@ -0,0 +1,62 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: Contains field arrays that are used for caching
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
* Contributor(s): ______________________________________..
********************************************************************************/
$fields_array['EcmPaymentState']=array(
'column_fields'=>array(
"id",
"date_entered",
"date_modified",
"modified_user_id",
"assigned_user_id",
"name",
"value"
),
'list_fields'=>array(
'id',
'assigned_user_name',
'assigned_user_id',
'name',
),
'required_fields' => array('name'=>1),
);
?>

View File

@@ -0,0 +1,8 @@
<?php
$acc = new Account():
if (isset($_REQUEST['record'])) {
$acc->retrieve($_REQUEST['record']);
echo $acc->name;
}

View File

@@ -0,0 +1,117 @@
<?php
function Hint($id,$d){
$guid=create_guid();
$hint_ = '<div class="tabForm" id="hint_div_'.$guid.'" style="border:0px solid black;position:absolute;left:720px;display:none;text-align:center;">';
$hint_ .= '<div align="center" style="width:300px">';
$hint_ .= '<textarea id="desc_'.$id.'" name="desc_'.$id.'" style="width:300px;height:180px;" maxlength="1000">'.$d.'</textarea><br />';
$hint_ .= '<div id="result_'.$id.'" style="display:none;"></div>';
$hint_ .= '<input type="hidden" id="inv_id_'.$id.'" value="'.$id.'" />';
$hint_ .= '<div align="right">';
$hint_ .= '<a href="#" onclick="mintajaxget(\'index.php?to_pdf=1&module=EcmPaymentStates&action=saveDesc&id=\'+document.getElementById(\'inv_id_'.$id.'\').value+\'&desc=\'+document.getElementById(\'desc_'.$id.'\').value,\'desc_'.$id.'\');lock_unlock_Position(\''.$guid.'\',document.getElementById(\'img_'.$guid.'\'));hideCallHint(event,\''.$guid.'\',\''.$id.'\',this);" style="cursor:pointer;">Save</a>&nbsp;&nbsp;<a href="#" onclick="lock_unlock_Position(\''.$guid.'\',document.getElementById(\'img_'.$guid.'\'));hideCallHint(event,\''.$guid.'\',\''.$id.'\',this);" style="cursor:pointer;">Cancel</a>';
$hint_ .= '</div>';
$hint_ .= '</div>';
$hint_ .= '</div>';
$hint = '<span id="'.$guid.'">'.$hint_.'</span><img src="modules/EcmCalls/images/hint_grey.gif">';
$hint = '<span id="'.$guid.'">'.$hint_.'</span><img id="img_'.$guid.'" src="modules/EcmCalls/images/hint_'.((isset($d) && $d != '')?'black':'grey').'.gif" onClick="lock_unlock_Position(\''.$guid.'\',this);" onMouseOver="showCallHint(event,\''.$guid.'\',\''.$id.'\',this,\'Note\');" onMouseOut="hideCallHint(event,\''.$guid.'\',\''.$id.'\',this);">';
return $hint;
}
function HintProduct($id,$d,$s){
$guid=create_guid();
$hint_ = '<div class="tabForm" id="hint_div_'.$guid.'" style="border:0px solid black;position:absolute;left:720px;display:none;text-align:center;">';
$hint_ .= '<div align="center" style="width:300px">';
$st=array("","sold","inprogress");
$tr['sold']="Sold";
$tr['inprogress']="In progress";
$hint_.='<select style="width:300px;" name="add_status_'.$id.'"id="add_status_'.$id.'">';
foreach($st as $status){
$hint_.='<option value="'.$status.'"';
if($status==$s)$hint_.=' selected';
$hint_.='>'.$tr[$status].'</option>';
}
$hint_.='</select>';
$hint_ .= '<textarea id="desc_'.$id.'" name="desc_'.$id.'" style="width:300px;height:180px;" maxlength="1000">'.$d.'</textarea><br />';
$hint_ .= '<div id="result_'.$id.'" style="display:none;"></div>';
$hint_ .= '<input type="hidden" id="product_'.$id.'" value="'.$id.'" />';
$hint_ .= '<div align="right">';
$hint_ .= '<a href="#" onclick="mintajaxget(\'index.php?to_pdf=1&module=EcmProducts&action=saveDesc&id=\'+document.getElementById(\'product_'.$id.'\').value+\'&desc=\'+document.getElementById(\'desc_'.$id.'\').value+\'&add_status=\'+document.getElementById(\'add_status_'.$id.'\').value,\'desc_'.$id.'\');lock_unlock_Position(\''.$guid.'\',document.getElementById(\'img_'.$guid.'\'));hideCallHint(event,\''.$guid.'\',\''.$id.'\',this);" style="cursor:pointer;">Save</a>&nbsp;&nbsp;<a href="#" onclick="lock_unlock_Position(\''.$guid.'\',document.getElementById(\'img_'.$guid.'\'));hideCallHint(event,\''.$guid.'\',\''.$id.'\',this);" style="cursor:pointer;">Cancel</a>';
$hint_ .= '</div>';
$hint_ .= '</div>';
$hint_ .= '</div>';
$hint = '<span id="'.$guid.'">'.$hint_.'</span><img src="modules/EcmCalls/images/hint_grey.gif">';
$hint = '<span id="'.$guid.'">'.$hint_.'</span><img id="img_'.$guid.'" src="modules/EcmCalls/images/hint_'.((isset($d) && $d != '')?'black':'grey').'.gif" onClick="lock_unlock_Position(\''.$guid.'\',this);" onMouseOver="showCallHint(event,\''.$guid.'\',\''.$id.'\',this,\'Note\');" onMouseOut="hideCallHint(event,\''.$guid.'\',\''.$id.'\',this);">';
return $hint;
}
function getActualSum($account_id){
$w=$GLOBALS['db']->query("select total,register_date from ecmpayments_ecminvoiceouts where paid='0' and register_date>='".date("Y-m-d")."' and account_id='".$account_id."' and deleted='0'");
while($r=$GLOBALS['db']->fetchByAssoc($w))$total+=$r['total'];
return -1*$total;
}
function getSum($account_id,$d1,$d2=0){
$w=$GLOBALS['db']->query("select total,register_date from ecmpayments_ecminvoiceouts where paid='0' and account_id='".$account_id."' and deleted='0' and register_date>'2008-12-31'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$e=explode("-",$r['register_date']);
if($d1>0 && $d2>0){
if(mktime(0,0,0,$e[1],$e[2],$e[0])+$d1*24*3600<=mktime(0,0,0,date("m"),date("d"),date("Y")) && mktime(0,0,0,$e[1],$e[2],$e[0])+$d2*24*3600>mktime(0,0,0,date("m"),date("d"),date("Y"))){
$total+=$r['total'];
}
}
elseif($d1>0 && $d2==0){
if(mktime(0,0,0,$e[1],$e[2],$e[0])+$d1*24*3600<=mktime(0,0,0,date("m"),date("d"),date("Y"))){
$total+=$r['total'];
}
}
}
return -1*$total;
}
function getInvoices($account_id,$d1,$d2=0){
//echo $account_id;
$w=$GLOBALS['db']->query("select total,register_date,ecminvoiceout_id,id from ecmpayments_ecminvoiceouts where paid='0' and account_id='".$account_id."' and deleted='0' and register_date>'2008-12-31'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$e=explode("-",$r['register_date']);
if($d1>0 && $d2>0){
if(mktime(0,0,0,$e[1],$e[2],$e[0])+$d1*24*3600<=mktime(0,0,0,date("m"),date("d"),date("Y")) && mktime(0,0,0,$e[1],$e[2],$e[0])+$d2*24*3600>mktime(0,0,0,date("m"),date("d"),date("Y"))){
$inv[]=$r['id'];
}
}
elseif($d1>0 && $d2==0){
if(mktime(0,0,0,$e[1],$e[2],$e[0])+$d1*24*3600<=mktime(0,0,0,date("m"),date("d"),date("Y"))){
$inv[]=$r['id'];
}
}
}
return $inv;
}
function getActualInvoices($account_id){
$w=$GLOBALS['db']->query("select total,register_date,ecminvoiceout_id,id from ecmpayments_ecminvoiceouts where paid='0' and register_date>='".date("Y-m-d")."' and account_id='".$account_id."' and deleted='0'");
while($r=$GLOBALS['db']->fetchByAssoc($w))$inv[]=$r['id'];
return $inv;
}
function getSummary($account_id){
$w=$GLOBALS['db']->query("select sum(total) as sum from ecmpayments_ecminvoiceouts where paid='0' and deleted='0' and account_id='".$account_id."' and register_date>'2008-12-31'");
$r=$GLOBALS['db']->fetchByAssoc($w);
$sum_wn=$r['sum'];
//$w=$GLOBALS['db']->query("select sum(value) as sum from ecmpayments where paid='0' and deleted='0' and parent_id='".$account_id."'");
//$r=$GLOBALS['db']->fetchByAssoc($w);
//$sum_ma=$r['sum'];
return ($sum_ma-$sum_wn);
}
function getBallance($account_id){
$w=$GLOBALS['db']->query("select total as sum,paid,register_date from ecmpayments_ecminvoiceouts where deleted='0' and account_id='".$account_id."'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if($r['register_date']<'2008-12-31' && $r['paid']==0){}
elseif($r['register_date']<'2008-12-31' && $r['paid']==1)$sum_wn+=$r['sum'];
elseif($r['register_date']>'2008-12-31')$sum_wn+=$r['sum'];
}
$w=$GLOBALS['db']->query("select value as sum,paid,payment_date from ecmpayments where deleted='0' and parent_id='".$account_id."'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if($r['payment_date']<'2008-12-31' && $r['paid']==0){}
elseif($r['payment_date']<'2008-12-31' && $r['paid']==1)$sum_ma+=$r['sum'];
elseif($r['payment_date']>'2008-12-31')$sum_ma+=$r['sum'];
}
return ($sum_ma-$sum_wn);
}
?>

View File

@@ -0,0 +1,89 @@
<?php
function Hint($id,$d){
$guid=create_guid();
$hint_ = '<div class="tabForm" id="hint_div_'.$guid.'" style="border:0px solid black;position:absolute;left:720px;display:none;text-align:center;">';
$hint_ .= '<div align="center" style="width:300px">';
$hint_ .= '<textarea id="desc_'.$id.'" name="desc_'.$id.'" style="width:300px;height:180px;" maxlength="1000">'.$d.'</textarea><br />';
$hint_ .= '<div id="result_'.$id.'" style="display:none;"></div>';
$hint_ .= '<input type="hidden" id="inv_id_'.$id.'" value="'.$id.'" />';
$hint_ .= '<div align="right">';
$hint_ .= '<a href="#" onclick="mintajaxget(\'index.php?to_pdf=1&module=EcmPaymentStates&action=saveDesc&id=\'+document.getElementById(\'inv_id_'.$id.'\').value+\'&desc=\'+document.getElementById(\'desc_'.$id.'\').value,\'desc_'.$id.'\');lock_unlock_Position(\''.$guid.'\',document.getElementById(\'img_'.$guid.'\'));hideCallHint(event,\''.$guid.'\',\''.$id.'\',this);" style="cursor:pointer;">Save</a>&nbsp;&nbsp;<a href="#" onclick="lock_unlock_Position(\''.$guid.'\',document.getElementById(\'img_'.$guid.'\'));hideCallHint(event,\''.$guid.'\',\''.$id.'\',this);" style="cursor:pointer;">Cancel</a>';
$hint_ .= '</div>';
$hint_ .= '</div>';
$hint_ .= '</div>';
$hint = '<span id="'.$guid.'">'.$hint_.'</span><img src="modules/EcmCalls/images/hint_grey.gif">';
$hint = '<span id="'.$guid.'">'.$hint_.'</span><img id="img_'.$guid.'" src="modules/EcmCalls/images/hint_'.((isset($d) && $d != '')?'black':'grey').'.gif" onClick="lock_unlock_Position(\''.$guid.'\',this);" onMouseOver="showCallHint(event,\''.$guid.'\',\''.$id.'\',this,\'Note\');" onMouseOut="hideCallHint(event,\''.$guid.'\',\''.$id.'\',this);">';
return $hint;
}
function getActualSum($account_id){
$w=$GLOBALS['db']->query("select total,register_date from ecmpayments_ecminvoiceouts where paid='0' and register_date>='".date("Y-m-d")."' and account_id='".$account_id."' and deleted='0'");
while($r=$GLOBALS['db']->fetchByAssoc($w))$total+=$r['total'];
return -1*$total;
}
function getSum1($account_id,$d1,$d2=0){
$w=$GLOBALS['db']->query("select total,register_date from ecmpayments_ecminvoiceouts where paid='0' and account_id='".$account_id."' and deleted='0' and register_date>'2008-12-31'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$e=explode("-",$r['register_date']);
if($d1>0 && $d2>0){
if(mktime(0,0,0,$e[1],$e[2],$e[0])+$d1*24*3600<=mktime(0,0,0,date("m"),date("d"),date("Y")) && mktime(0,0,0,$e[1],$e[2],$e[0])+$d2*24*3600>mktime(0,0,0,date("m"),date("d"),date("Y"))){
$total+=$r['total'];
}
}
elseif($d1>0 && $d2==0){
if(mktime(0,0,0,$e[1],$e[2],$e[0])+$d1*24*3600<=mktime(0,0,0,date("m"),date("d"),date("Y"))){
$total+=$r['total'];
}
}
}
return -1*$total;
}
function getInvoices($account_id,$d1,$d2=0){
$w=$GLOBALS['db']->query("select total,register_date,ecminvoiceout_id,id from ecmpayments_ecminvoiceouts where paid='0' and account_id='".$account_id."' and deleted='0' and register_date>'2008-12-31'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$e=explode("-",$r['register_date']);
if($d1>0 && $d2>0){
if(mktime(0,0,0,$e[1],$e[2],$e[0])+$d1*24*3600<=mktime(0,0,0,date("m"),date("d"),date("Y")) && mktime(0,0,0,$e[1],$e[2],$e[0])+$d2*24*3600>mktime(0,0,0,date("m"),date("d"),date("Y"))){
$inv[]=$r['id'];
}
}
elseif($d1>0 && $d2==0){
if(mktime(0,0,0,$e[1],$e[2],$e[0])+$d1*24*3600<=mktime(0,0,0,date("m"),date("d"),date("Y"))){
$inv[]=$r['id'];
}
}
}
return $inv;
}
function getActualInvoices($account_id){
$w=$GLOBALS['db']->query("select total,register_date,ecminvoiceout_id,id from ecmpayments_ecminvoiceouts where paid='0' and register_date>='".date("Y-m-d")."' and account_id='".$account_id."' and deleted='0'");
while($r=$GLOBALS['db']->fetchByAssoc($w))$inv[]=$r['id'];
return $inv;
}
function getSummary($account_id){
$w=$GLOBALS['db']->query("select sum(total) as sum from ecmpayments_ecminvoiceouts where paid='0' and deleted='0' and account_id='".$account_id."' and register_date>'2008-12-31'");
$r=$GLOBALS['db']->fetchByAssoc($w);
$sum_wn=$r['sum'];
//$w=$GLOBALS['db']->query("select sum(value) as sum from ecmpayments where paid='0' and deleted='0' and parent_id='".$account_id."'");
//$r=$GLOBALS['db']->fetchByAssoc($w);
//$sum_ma=$r['sum'];
return ($sum_ma-$sum_wn);
}
function getBallance($account_id){
$w=$GLOBALS['db']->query("select total as sum,paid,register_date from ecmpayments_ecminvoiceouts where deleted='0' and account_id='".$account_id."'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if($r['register_date']<'2008-12-31' && $r['paid']==0){}
elseif($r['register_date']<'2008-12-31' && $r['paid']==1)$sum_wn+=$r['sum'];
elseif($r['register_date']>'2008-12-31')$sum_wn+=$r['sum'];
}
$w=$GLOBALS['db']->query("select value as sum,paid,payment_date from ecmpayments where deleted='0' and parent_id='".$account_id."'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if($r['payment_date']<'2008-12-31' && $r['paid']==0){}
elseif($r['payment_date']<'2008-12-31' && $r['paid']==1)$sum_ma+=$r['sum'];
elseif($r['payment_date']>'2008-12-31')$sum_ma+=$r['sum'];
}
return ($sum_ma-$sum_wn);
}
?>

View File

@@ -0,0 +1,64 @@
<?php
/*
ini_set('display_errors',1);
$csv = array();
$lines = file('rap3.csv', FILE_IGNORE_NEW_LINES);
foreach ($lines as $key => $value)
{
$csv[$key] = str_getcsv($value);
}
echo '<pre>';
print_r($csv);
echo '</pre>';
$link = mysql_connect('localhost', 'root', '5z#JaL');
$db_selected = mysql_select_db('crm', $link);
foreach($csv as $key)
{
if($key[2]=='Przekazany'){
$r=mysql_query("INSERT INTO nr_faktury
(`nr_faktury`)
VALUES
('".$key[1]."');");
}
}
*/
$link = mysql_connect('localhost', 'root', '5z#JaL');
$db_selected = mysql_select_db('crm', $link);
$r=mysql_query("select p.id,p.document_no,p.total,p.paid,p.register_date,p.payment_date,p.total,p.ecminvoiceout_id, p.ecmpayment_id,p.account_id from ecmpayments_ecminvoiceouts as p inner join ecminvoiceouts as i on p.ecminvoiceout_id=i.id and i.type!='canceled' where p.deleted='0' and p.date_entered > '2011-12-31' order by p.date_entered limit 0,100");
$i=0;
while($dane=mysql_fetch_assoc($r)){
$req=mysql_query( "select p.id, p.name,p.value from ecmpayments_ecminvoiceouts_rel as r inner join ecmpayments as p on p.id=r.ecmpayment_id where r.ee_id='" . $dane ['id'] . "'" );
while($dane2=mysql_fetch_assoc($req)){
$szukaj=mysql_query("select * from ecmtransactions where name='".$dane2['name']."' and value='".$dane2['value']."'");
$i++;
//echo $i.': '.$dane ['id'];
//echo' <a href="https://192.168.1.131/crm/index.php?module=EcmPayments&action=DetailView&record=' . $dane2 ['id'] . '" target="new">' . $dane2 ['name'] . '</a><br>';
$szukaj_p=mysql_query("select * from ecmtransactions where name='".$dane['document_no']."' and value='".$dane['total']."'");
//echo $i.': '.$dane ['id'];
$dane4=mysql_fetch_assoc($szukaj_p);
$dane3=mysql_fetch_assoc($szukaj);
if(mysql_num_rows($szukaj_p)>0 && mysql_num_rows($szukaj)>0){
// $cos=mysql_query("insert into ecmpayments2_ecminvoiceouts(id,ecmpayment_id,ecminvoiceout_id,date_entered,paid,created_by,modified_user_id,deleted,account_id) values('".create_guid()."','".$dane4 ['id']."','".$dane3 ['id']."','".$dane['register_date']."','1','2e72f487-d92b-954e-f50c-528b10ce81c9','2e72f487-d92b-954e-f50c-528b10ce81c9','0','".$dane['account_id']."');");
echo "insert into ecmpayments2_ecminvoiceouts(id,ecmpayment_id,ecminvoiceout_id,date_entered,paid,created_by,modified_user_id,deleted,account_id) values('".create_guid()."','".$dane4 ['id']."','".$dane3 ['id']."','".$dane['register_date']."','1','2e72f487-d92b-954e-f50c-528b10ce81c9','2e72f487-d92b-954e-f50c-528b10ce81c9','0','".$dane['account_id']."'<br>";
}
/*
while($dane4=mysql_fetch_assoc($szukaj_p)){
echo' <a href="https://192.168.1.131/crm/index.php?module=EcmTransactions&action=DetailView&record=' . $dane4 ['id'] . '" target="new">' . $dane4 ['name'] . 'a</a>';
}
while($dane3=mysql_fetch_assoc($szukaj)){
//echo $i.': '.$dane ['id'];
echo' <a href="https://192.168.1.131/crm/index.php?module=EcmTransactions&action=DetailView&record=' . $dane3 ['id'] . '" target="new">' . $dane3 ['name'] . 'b</a><br>';
//echo' <a href="https://192.168.1.131/crm/index.php?module=EcmPayments&action=DetailView&record=' . $dane2 ['id'] . '" target="new">' . $dane2 ['name'] . '</a><br>';
}
*/
}
}
echo $i;
?>

View File

@@ -0,0 +1,73 @@
<?php
if($_REQUEST['type']=="save"){
require_once('include/Upload.php');
include_once("modules/EcmPayments/EcmPayment.php");
$_POST['file']=upload_file("file","modules/EcmPaymentStates/files/");
chmod("modules/EcmPaymentStates/files/".$_POST['file'],0777);
$content=file_get_contents("modules/EcmPaymentStates/files/".$_POST['file']);
$content=str_replace(" ","",$content);
$content=explode("
",$content);
$count=count($content);
for($i=0;$i<$count;$i++){
$d=explode(".",$_REQUEST['date']);
$v=explode(";",$content[$i]);
if($v[0]=="" || $v[1]=="")continue;
//echo trim($v[0])." ".$v[1]."<br>";
$p=new EcmPayment();
$p->parent_id=$_POST['account_id'];
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select ems_system_id from accounts where id='".$_POST['account_id']."'"));
$p->parent_name=$_POST['account_name'];
$p->ems_system_id=$r['ems_system_id'];
$p->name=trim($v[0]);
$v[1]=str_replace(",",".",$v[1]);
$v[1]=str_replace("&nbsp;","",$v[1]);
$v[1]=substr($v[1],2,strlen($v[1]));
$p->value=$v[1];
$p->payment_date=$_REQUEST['date'];
$id=$p->save();
$GLOBALS['db']->query("update ecmpayments set value='".$v[1]."' where id='".$id."'");
}
}
?>
<h2>Payments States: Import CSV</h2>
<br>
<form action="index.php?module=EcmPaymentStates&action=importCSV&type=save" method="post" name="importCSV" enctype="multipart/form-data">
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="border-top: 0px none; margin-bottom: 4px;" class="tabForm">
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">Account</td>
<td class="dataField" width="90%" nowrap="nowrap">
<input name="account_name" tabindex="" id="account_name" size="" value="<?php echo $_REQUEST['account_name'];?>" title="" type="text">
<input name="account_id" id="account_id" value="<?php echo $_REQUEST['account_id'];?>" type="hidden">
<input name="btn_account_name" tabindex="" title="Select [Alt+T]" accesskey="T" class="button" value="Select" onclick='open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"importCSV","field_to_name_array":{"id":"account_id","name":"account_name"}}, "single", true);' type="button"> </td>
<td class="dataLabel" width="10%" nowrap="nowrap">File</td>
<td class="dataField" width="90%" nowrap="nowrap">
<input name="file" type="file" /> </td>
</tr>
<tr>
<td class="dataLabel" nowrap="nowrap">Payment Date</td>
<td class="dataField" nowrap="nowrap">
<input autocomplete="off" name="date" id="date" value="<?php echo $_REQUEST['date'];?>" title="" tabindex="" size="11" maxlength="10" type="text">
<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_trigger" align="absmiddle" border="0">
<script type="text/javascript">
Calendar.setup ({
inputField : "date",
daFormat : "<? echo str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));?>",
button : "date_trigger",
singleClick : true,
dateStr : "",
step : 1
}
);
</script>
</td>
<td class="dataLabel" nowrap="nowrap">&nbsp;</td>
<td class="dataField" nowrap="nowrap">&nbsp;</td>
</tr>
</table>
<input class='button' type='submit' name='button' value='Import' />
</form>

View File

@@ -0,0 +1,84 @@
<?php
if($_REQUEST['type']=="save"){
require_once('include/Upload.php');
include_once("modules/EcmPayments/EcmPayment.php");
$_POST['file']=upload_file("file","modules/EcmPaymentStates/files/");
chmod("modules/EcmPaymentStates/files/".$_POST['file'],0777);
include_once("modules/EcmStockStates/class.dbf.php");
$dbf = new dbf_class("modules/EcmPaymentStates/files/".$_POST['file']);
$num_rec=$dbf->dbf_num_rec;
for($i=0;$i<$num_rec;$i++){
$row=$dbf->getRowAssoc($i);
for($j=2;$j<=20;$j++){
if($row['N'.$j]){
$nn='N'.$j;
break;
}
}
if($row['N1']=="" || $row[$nn]=="")continue;
$name=trim($row['N1']);
$name=str_replace(" ","",$name);
$name=substr($name,2);
$value=trim($row[$nn]);
$value=str_replace(" ","",$value);
//$value=substr($value,2);
$value=str_replace(",",".",$value);
$value=floatval($value);
$p=new EcmPayment();
$p->name=$name;
$p->parent_id=$_POST['account_id'];
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select ems_system_id from accounts where id='".$_POST['account_id']."'"));
$p->parent_name=$_POST['account_name'];
$p->ems_system_id=$r['ems_system_id'];
$p->value=$value;
$p->payment_date=$_REQUEST['date'];
//echo $name."#######".$value."<br>";
$id=$p->save();
$GLOBALS['db']->query("update ecmpayments set value='".$value."' where id='".$id."'");
}
header("Location: index.php?module=EcmPaymentStates&action=index&account_id=".$_POST['account_id']);
}
?>
<h2>Payments States: Import DBF</h2>
<br>
<form action="index.php?module=EcmPaymentStates&action=importDBF&type=save" method="post" name="importCSV" enctype="multipart/form-data">
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="border-top: 0px none; margin-bottom: 4px;" class="tabForm">
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">Kontrahent</td>
<td class="dataField" width="90%" nowrap="nowrap">
<input name="account_name" tabindex="" id="account_name" size="" value="<?php echo $_REQUEST['account_name'];?>" title="" type="text">
<input name="account_id" id="account_id" value="<?php echo $_REQUEST['account_id'];?>" type="hidden">
<input name="btn_account_name" tabindex="" title="Select [Alt+T]" accesskey="T" class="button" value="Select" onclick='open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"importCSV","field_to_name_array":{"id":"account_id","name":"account_name"}}, "single", true);' type="button"> </td>
<td class="dataLabel" width="10%" nowrap="nowrap">Plik</td>
<td class="dataField" width="90%" nowrap="nowrap">
<input name="file" type="file" /> </td>
</tr>
<tr>
<td class="dataLabel" nowrap="nowrap">Data płatności</td>
<td class="dataField" nowrap="nowrap">
<input autocomplete="off" name="date" id="date" value="<?php echo $_REQUEST['date'];?>" title="" tabindex="" size="11" maxlength="10" type="text">
<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_trigger" align="absmiddle" border="0">
<script type="text/javascript">
Calendar.setup ({
inputField : "date",
daFormat : "<? echo str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));?>",
button : "date_trigger",
singleClick : true,
dateStr : "",
step : 1
}
);
</script>
</td>
<td class="dataLabel" nowrap="nowrap">&nbsp;</td>
<td class="dataField" nowrap="nowrap">&nbsp;</td>
</tr>
</table>
<input class='button' type='submit' name='button' value='Importuj' />
</form>

View File

@@ -0,0 +1,84 @@
<?php
if($_REQUEST['type']=="save"){
global $current_user;
require_once('include/Upload.php');
$_POST['file']=upload_file("file","modules/EcmPaymentStates/files/");
chmod("modules/EcmPaymentStates/files/".$_POST['file'],0777);
$content=file_get_contents("modules/EcmPaymentStates/files/".$_POST['file']);
$a1=array("FV "," / ","WR ","AD ","MD ","FVKOR ","FK ","NW ","YX ","WX ","WM ","YZ ","NZ ");
$a2=array("FV","/","WR","AD","MD","FVKOR","FK","NW","YX","WX","WM","YZ","NZ");
$content=str_replace($a1,$a2,$content);
$content=explode("
",$content);
$count=count($content);
for($i=0;$i<$count;$i++){
$exp=explode(" ",$content[$i]);
$value=floatval(str_replace(",","",$exp[7]));
$name=$exp[1];
//echo $value.' - '.$name.'<br>';
$d=$exp[0];
$rd=explode(".",$d);
$register_date=$rd[2]."-".$rd[1]."-".$rd[0];
$t=new EcmTransaction();
$t->name=$name;
$t->parent_id=$_POST['account_id'];
$t->parent_name=$_POST['account_name'];
$t->value=$value;
$t->payment_date=$_REQUEST['date'];
$t->register_date=$_REQUEST['date'];
$t->created_by = $current_user->id;
$t->assigned_user_id = $current_user->id;
$t->assigned_user_id = '2';
$t->currency_id = 'PLN';
$t->currency_name = 'PLN';
$t->type='1';
//$t->type2='W_zap_dos';
$sum+=$value;
$id=$t->save();
echo $value.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$name.'<br>';
}
echo "SUMA: ".$sum;
die();
}
?>
<h2>Payments States: Import TXT</h2>
<br>
<form action="index.php?module=EcmPaymentStates&action=importTXT&type=save" method="post" name="importTXT" enctype="multipart/form-data">
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="border-top: 0px none; margin-bottom: 4px;" class="tabForm">
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">Kontrahent</td>
<td class="dataField" width="90%" nowrap="nowrap">
<input name="account_name" tabindex="" id="account_name" size="" value="<?php echo $_REQUEST['account_name'];?>" title="" type="text">
<input name="account_id" id="account_id" value="<?php echo $_REQUEST['account_id'];?>" type="hidden">
<input name="btn_account_name" tabindex="" title="Select [Alt+T]" accesskey="T" class="button" value="Select" onclick='open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"importTXT","field_to_name_array":{"id":"account_id","name":"account_name"}}, "single", true);' type="button"> </td>
<td class="dataLabel" width="10%" nowrap="nowrap">Plik</td>
<td class="dataField" width="90%" nowrap="nowrap">
<input name="file" type="file" /> </td>
</tr>
<tr>
<td class="dataLabel" nowrap="nowrap">Data pĹatnoĹci</td>
<td class="dataField" nowrap="nowrap">
<input autocomplete="off" name="date" id="date" value="<?php echo $_REQUEST['date'];?>" title="" tabindex="" size="11" maxlength="10" type="text">
<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_trigger" align="absmiddle" border="0">
<script type="text/javascript">
Calendar.setup ({
inputField : "date",
daFormat : "<? echo str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));?>",
button : "date_trigger",
singleClick : true,
dateStr : "",
step : 1
}
);
</script>
</td>
<td class="dataLabel" nowrap="nowrap">&nbsp;</td>
<td class="dataField" nowrap="nowrap">&nbsp;</td>
</tr>
</table>
<input class='button' type='submit' name='button' value='Importuj' />
</form>

View File

@@ -0,0 +1,537 @@
<?php
//ini_set('display_errors',1);
if($_REQUEST ['record']!=null)$_REQUEST ['account_id']=$_REQUEST ['record'];
$r = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "select name,to_vatid,billing_address_city,billing_address_street,account_type from accounts where id='" . $_REQUEST ['account_id'] . "'" ) );
echo $_REQUEST ['account_name'] = $r ['name'];
?>
<h2>Rozliczenia: Strona główna</h2>
<form action="index.php" method="get" name="Search">
<input type="hidden" name="action" value="index" /> <input
type="hidden" name="not_matched" value="0" /> <input type="hidden"
name="module" value="EcmPaymentStates" />
<link rel="stylesheet" href="include/jQuery/jquery-ui/themes/base/jquery-ui.css">
<script src="include/jQuery/jquery-2.1.0.min.js"></script>
<script src="include/jQuery/jquery-ui/ui/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
#draggable { width: 150px; height: 150px; padding: 0.5em; }
</style>
<script>
$(function() {
$( "div[name=info]" ).draggable();
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
function show(obj,event) {
var el = document.getElementById(obj);
el.style.display = 'block';
var x=event.clientX;
var y=event.clientY;
el.style.top = '-'+y+'px'; //or whatever
el.style.left = x+'px'; // or whatever
}
</script>
<script language="javascript">
var OPT=new Array();
OPT['dec_len']=2;
OPT['sep_1000']=".";
OPT['dec_sep']=",";
var inv = new Array();
var pay = new Array();
function formatNumber(number,add) {
if(!number) number = 0;
number = parseFloat(number);
var tmp = number.toFixed(OPT['dec_len']);
var s1 = tmp.substring(0,tmp.length-1-OPT['dec_len']);
var s2 = tmp.substring(tmp.length-OPT['dec_len'],tmp.length);
var tmp = '';
for(var i=s1.length;i>0;i-=3) {
tmp = ((i<=3)?"":OPT['sep_1000'])+s1.substring(i-3,i)+tmp;
}
s1 = tmp;
return (s1+OPT['dec_sep']+s2).toString()+((add)?add:'');
}
function unformatNumber(ufn,add) {
if(add) {
var match = /add/g;
ufn = ufn.replace(match,'');
}
var match = /Err/g;
ufn = ufn.replace(match,'');
if(!ufn) return parseFloat(0);
var pos = ufn.indexOf(OPT['dec_sep']);
var s1='', s2='';
if(pos==-1) { s1 = ufn; s2 = ''; }
else { s1 = ufn.substring(0,pos); s2 = ufn.substring(pos+1,ufn.length); }
var pos = -1;
while((pos = s1.indexOf(OPT['sep_1000'])) != -1)
s1 = s1.substring(0,pos)+s1.substring(pos+1,s1.length);
return parseFloat(s1+"."+s2);
}
function addValue(obj,value,inp){
if(obj.checked==true) {
inp.innerHTML=formatNumber(parseFloat(unformatNumber(inp.innerHTML))+parseFloat(value));
if (inp.id=="total_wn")
inv[obj.value] = 1;
if (inp.id=="total_ma")
pay[obj.value] = 1;
}
else {
inp.innerHTML=formatNumber(parseFloat(unformatNumber(inp.innerHTML))-parseFloat(value));
if (inp.id=="total_wn")
inv[obj.value] = null;
if (inp.id=="total_ma")
pay[obj.value] = null;
}
}
function doMach() {
var invoices="";
for(var i in inv) {
if (inv[i]==1)
invoices+= i+"|";
}
var payments="";
for(var i in pay) {
if (pay[i]==1)
payments+= i+"|";
}
window.location="index.php?to_pdf=1&module=EcmPaymentStates&action=Match&inv="+invoices+"&pay="+payments+"&account_id="+document.getElementById("account_id").value;
}
function doMultiMach() {
var invoices="";
for(var i in inv) {
if (inv[i]==1)
invoices+= i+"|";
}
var payments="";
for(var i in pay) {
if (pay[i]==1)
payments+= i+"|";
}
window.location="index.php?to_pdf=0&module=EcmPaymentStates&action=multiMatch&inv="+invoices+"&pay="+payments+"&account_id="+document.getElementById("account_id").value;
}
function addValuePayments(obj,value,inp){
var cb=document.getElementById("paymentsList").getElementsByTagName("input");
for(var i=0;i<cb.length;i++){
if(cb[i].type=="checkbox"){
cb[i].checked=false;
}
}
obj.checked=true;
inp.innerHTML=formatNumber(parseFloat(value));
}
</script>
<table cellspacing="2" cellpadding="2" width="100%" border="0">
<tr>
<td width="100%" style="width: 520px;">
<ul class="tablist">
<li class="active" id="tab_li_EcmPayments|basic_search"><a
class="current" id="tab_link_EcmPayments|basic_search" href="#">Podstawowe
wyszukiwanie</a></li>
</ul>
<table width="100%" cellspacing="0" cellpadding="0" border="0"
style="border-top: 0px none; margin-bottom: 4px" class="tabForm">
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">Kontrahent</td>
<td class="dataField" width="40%" nowrap="nowrap"><input
name="account_name" tabindex="" id="account_name" size=""
value="<?php echo $_REQUEST['account_name'];?>" title=""
type="text"> <input name="account_id" id="account_id"
value="<?php echo $_REQUEST['account_id'];?>" type="hidden"> <input
name="btn_account_name" tabindex="" title="Select [Alt+T]"
accesskey="T" class="button" value="Wybierz"
onclick='open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"id":"account_id","name":"account_name"}}, "single", true);'
type="button"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">NIP</td>
<td class="dataField" width="20%" nowrap="nowrap"><input
name="to_vatid" tabindex="" id="to_vatid" size=""
value="<?php echo $r['to_vatid'];?>" title=""
type="text"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">Dokument nr</td>
<td class="dataField" width="30%" nowrap="nowrap"><input
name="document_no" tabindex="" id="document_no" size=""
value="<?php echo $_REQUEST['document_no'];?>" title=""
type="text"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">Kwota</td>
<td class="dataField" width="30%" nowrap="nowrap"><input
name="value" tabindex="" id="value" size=""
value="<?php echo $_REQUEST['value'];?>" title="" type="text"></td>
</tr>
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">Indeks</td>
<td class="dataField" width="30%" nowrap="nowrap"><input
name="account_name2" tabindex="" id="account_name2" size="50"
value="<?php echo $r['index_dbf2'];?>" title=""
type="text"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">Miasto</td>
<td class="dataField" width="20%" nowrap="nowrap"><input
name="to_vatid" tabindex="" id="to_vatid" size=""
value="<?php echo $r['billing_address_city'];?>" title=""
type="text"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">Ulica</td>
<td class="dataField" width="30%" nowrap="nowrap"><input
name="document_no" tabindex="" id="document_no" size=""
value="<?php echo $r['billing_address_street'];?>" title=""
type="text"></td>
</tr>
</table> <input tabindex='2' title='Search [Alt+Q]' accessKey='Q'
class='button' onclick="document.Search.action.value='index';"
type='submit' name='button' value='Szukaj' id='search_form_submit' />&nbsp;
<input tabindex='2' title='Clear [Alt+C]' accessKey='C'
onclick="location.href='index.php?module=EcmPaymentStates&action=index';"
class='button' type='button' name='clear' value=' Wyczyść ' />
</td>
</tr>
</table></form><form method='post' id='userform' action='index.php?module=EcmPaymentStates&action=Match'>
<?php
include_once ("modules/EcmPaymentStates/helper.php");
// show all
$wh_paid_i = 0;
$wh_paid_p = 0;
// show not mached
if ($_REQUEST ['matched'] == 1) {
$wh_paid_i = 1;
$wh_paid_p = 1;
}
// show mached
if ($_REQUEST ['matched'] == 2) {
$wh_paid_i = 2;
$wh_paid_p = 2;
}
echo '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
echo '<tr valign="top"><td colspan="5">';
global $current_language;
echo '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
echo '<tr>';
echo '<td class="listViewThS1" style="width:4px;">&nbsp;</td><td class="listViewThS1" style="width:70px;">Termin płatności</td><td class="listViewThS1" style="width:180px;">Nr Dokumentu</td><td class="listViewThS1" style="width:100px;">Opis</td><td class="listViewThS1" style="width:100px; text-align: right;">Kwota&nbsp&nbsp&nbsp</td>';
echo '</tr></table><div style="height:200px;overflow:auto"><table width="100%">';
if ($_REQUEST ['document_no']){
$where_clause='and name like "'.$_REQUEST ['document_no'].'"';
}
if ($_REQUEST ['value']){
$where_value='and value = "'.unformat_number ( $_REQUEST ['value'] ).'"';
}
if($_REQUEST ['matched']==2){
$where_paid='and paid ="1"';
}
if($_REQUEST ['matched']==0){
$_REQUEST ['not_matched']=2;
}
if($_REQUEST ['matched']==1){
$where_paid='and paid ="0"';
}
if ($_REQUEST ['value'] && is_numeric ( $_REQUEST ['value'] )) {
$v = "and p.total BETWEEN(" . unformat_number ( $_REQUEST ['value'] - 1 ) . "," . unformat_number ( $_REQUEST ['value'] + 1 ) . ")";
} else
$v = "";
$total=0;
$winien_n_roz=0;
$winien_roz=0;
$licz=1;
$arr_w=array();
$arr_n=array();
$waluty= $GLOBALS ['db']->query ("select id,name,iso4217 from currencies where deleted=0");
$ab=0;
$arr_w[$ab]['id']='-99';
$arr_w[$ab]['znak']='PLN';
$arr_w[$ab]['winien_n_roz']=0;
$arr_w[$ab]['winien_roz']=0;
$arr_w[$ab]['used']=0;
$arr_n[$ab]['id']='-99';
$arr_n[$ab]['znak']='PLN';
$arr_n[$ab]['winien_n_roz']=0;
$arr_n[$ab]['winien_roz']=0;
$arr_n[$ab]['used']=0;
while($ar = $GLOBALS ['db']->fetchByAssoc ($waluty)){
$ab++;
$arr_w[$ab]['id']=$ar['id'];
$arr_w[$ab]['znak']=$ar['iso4217'];
$arr_w[$ab]['winien_n_roz']=0;
$arr_w[$ab]['winien_roz']=0;
$arr_w[$ab]['used']=0;
$arr_n[$ab]['id']=$ar['id'];
$arr_n[$ab]['znak']=$ar['iso4217'];
$arr_n[$ab]['winien_n_roz']=0;
$arr_n[$ab]['winien_roz']=0;
$arr_n[$ab]['used']=0;
}
$trs='<tr>';
$trs_grey='<tr style="background-color: #e6e6e6;">';
$query="select * from ecmtransactions where parent_id='" . $_REQUEST ['account_id'] . "' and type=0 and deleted='0' ".$where_clause." ".$where_value." ".$where_paid."and register_date > '2011-12-31' order by date_entered desc";
echo $query;
$w= $GLOBALS ['db']->query ( $query);
$abc=0;
$i=0;
while($rinv = $GLOBALS ['db']->fetchByAssoc ($w)){
$match.="";
$a= $GLOBALS ['db']->query("SELECT a.ecminvoiceout_id as tid,b.name as name,b.id as id,b.value,b.payment_date from ecmpayments2_ecminvoiceouts as a inner join ecmtransactions as b on a.ecminvoiceout_id=b.id where a.ecmpayment_id ='".$rinv['id']."'");
if ($rinv['paid']=='1' && $a->num_rows==0)
continue;
$ab++;
$total+=$rinv['value'];
$wal= $GLOBALS ['db']->query ("select currency_value,currency_id,total from ".strtolower($rinv['record_type'])." where id='".$rinv['record_id']."'");
$waluta= $GLOBALS ['db']->fetchByAssoc ($wal);
if($waluta['currency_id']=='PLN' || $waluta['currency_id']==''){$waluta['currency_id']='-99';}
$c = new Currency();
$c->retrieve($waluta['currency_id']);
$symbol = $c->iso4217;
$kk=0;
foreach($arr_w as $key=>$v){
if($arr_w[$key]['id']==$waluta['currency_id']){
$kk=$key;
$arr_w[$key]['used']=1;
}
}
if($rinv ['paid']==0){
$color = 'color: #FF0000;';
$checkbox = '<input type="checkbox" name="check1[]" value="' . $rinv ['id'] . '" onclick="addValue(this,' . $rinv ['value'] . ',document.getElementById(\'total_wn\'));">';
$winien_n_roz+=$rinv ['value'];
$arr_w[$kk]['winien_n_roz']+=$rinv ['value'];
}
if($rinv['paid']==1){
$arr_w[$kk]['winien_roz']+=$rinv ['value'];
$winien_roz+=$rinv ['value'];$checkbox ="";$color = 'color: #337000;';}
if($_REQUEST ['matched']==2){
$a= $GLOBALS ['db']->query("SELECT a.ecminvoiceout_id as tid,b.name as name,b.id as id,b.value,b.payment_date from ecmpayments2_ecminvoiceouts as a inner join ecmtransactions as b on a.ecminvoiceout_id=b.id where a.ecmpayment_id ='".$rinv['id']."'");
if($a->num_rows>0){
$show='<a href="#" onClick="show(\'draggable'.$abc.'\',event)"><img src="themes/Sugar5/images/info_inline.gif?s=bed8cd35065048ceebdc639ebe305e2c&c=1"></a>';
$match.='<div id="draggable'.$abc.'" name="info" class="ui-widget-content" style="display:none; width:300px;">
<p style="text-align: left;"><img border="0" src="themes/Sugar/images/close_inline.gif" onClick="hide(\'draggable'.$abc.'\')"></img> Wiązania do '.$rinv['name'].'</p>
<hr><table style="width: 299px;"><tr><td style="text-align: left;">Nazwa</td><td style="text-align: right;">Kwota</td><td style="text-align: right;">Data</td></tr>';
while($rinv2 = $GLOBALS ['db']->fetchByAssoc ($a)){
$match.='<tr><td style="text-align: left;"><a href="index.php?module=EcmTransactions&action=DetailView&record=' . $rinv2 ['id'] . '">' . $rinv2['name'] . '</a></td><td style="text-align: right;">'.format_number ( $rinv2['value']).'</td><td style="text-align: right;">' .date("d.m.Y", strtotime($rinv2 ['payment_date'])). '</td></tr>';
}
$abc++;
$match.='</table></div>';
} else { $match.="";$show="";}
} else {
$match.="";
}
$inv = '<a href="index.php?module=EcmTransactions&action=DetailView&record=' . $rinv ['id'] . '">' . $rinv['name'] .'</a>';
$i++;
if ($i % 2 == 1)
$str=$trs;
else
$str=$trs_grey;
$str .= '<td class="oddListRowS1" width="6%">' . $checkbox . ' '.$show.'</td><td class="oddListRowS1" width="15%">' .date("d.m.Y", strtotime($rinv ['payment_date'])). '</td><td class="oddListRowS1" width="23%" > ' . $inv . '</td><td class="oddListRowS1">'.substr($rinv ['description'],0,50).'</td><td class="oddListRowS1" style="text-align: right; ' . $color . '">' . format_number ( $rinv ['value'] ) . ' '.$symbol.'</td></tr>';
echo $str;
//$licz++;
}
echo '</table></div>';
echo '</td><td colspan="5">';
echo '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
echo '<tr>';
echo '<td class="listViewThS1" style="width:10px;">&nbsp;</td><td class="listViewThS1" style="width:6px;">&nbsp;</td><td class="listViewThS1" style="width:25px;">Kwota</td><td class="listViewThS1" style="width:200px; padding-left:20px;text-align:center;">Opis</td><td class="listViewThS1" style="width:80px;">Nr dokumentu</td><td class="listViewThS1" style="width:70px;">Data</td>';
echo '</tr></table><div style="height:200px;overflow:auto"><table width="100%">';
$ma_n_roz =0;
$ma_roz=0;
$query="select * from ecmtransactions where parent_id='" . $_REQUEST ['account_id'] . "' and type=1 and deleted='0' ".$where_clause." ".$where_value." ".$where_paid." and payment_date > '2011-12-31' order by date_entered desc";
$w= $GLOBALS ['db']->query ( $query);
$i=0;
while($rinv = $GLOBALS ['db']->fetchByAssoc ($w)){
$match.="";
// if ($rinv ['payment_date'] < '2008-12-31' && $rinv ['paid'] == 0)
// continue;
$ab= $GLOBALS ['db']->query("SELECT a.ecminvoiceout_id as tid,b.name as name,b.id as id,b.value,b.payment_date from ecmpayments2_ecminvoiceouts as a inner join ecmtransactions as b on a.ecmpayment_id=b.id where a.ecminvoiceout_id ='".$rinv['id']."'");
if ($rinv['paid']=='1' && $ab->num_rows==0)
continue;
if($rinv['currency_id']=='PLN'){$rinv['currency_id']='-99';}
$c = new Currency();
$c->retrieve($rinv['currency_id']);
$symbol = $c->iso4217;
if($rinv['currency_id']=='PLN' || $rinv['currency_id']==''){$rinv['currency_id']='-99';}
$c = new Currency();
$c->retrieve($rinv['currency_id']);
$symbol = $c->iso4217;
$kk=0;
foreach($arr_n as $key=>$v){
if($arr_n[$key]['id']==$rinv['currency_id']){
$kk=$key;
$arr_n[$key]['used']=1;
}
}
if($_REQUEST ['matched']==2){
//$ab= $GLOBALS ['db']->query("SELECT a.ecminvoiceout_id as tid,b.name as name,b.id as id,b.value,b.payment_date from ecmpayments2_ecminvoiceouts as a inner join ecmtransactions as b on a.ecmpayment_id=b.id where a.ecminvoiceout_id ='".$rinv['id']."'");
if($ab->num_rows>0){
$abc++;
$show='<a href="#" onClick="show(\'draggable'.$abc.'\',event)"><img src="themes/Sugar5/images/info_inline.gif?s=bed8cd35065048ceebdc639ebe305e2c&c=1"></a>';
$match.='<div id="draggable'.$abc.'" name="info" class="ui-widget-content" style="display:none; width: 300px;">
<p style="text-align: left;"><img border="0" src="themes/Sugar/images/close_inline.gif" onClick="hide(\'draggable'.$abc.'\')"></img> Wiązania do '.$rinv['name'].'</p>
</a><hr><table style="width: 299px;"><tr><td style="text-align: left;">Nazwa</td><td style="text-align: right;">Kwota</td><td style="text-align: right;">Data</td></tr>';
while($rinv2 = $GLOBALS ['db']->fetchByAssoc ($ab)){
$match.='<tr><td style="text-align: left;"><a href="index.php?module=EcmTransactions&action=DetailView&record=' . $rinv2 ['id'] . '">' . $rinv2['name'] . '</a></td><td style="text-align: right;">'.format_number ( $rinv2['value']).'</td><td style="text-align: right;">' .date("d.m.Y", strtotime($rinv2 ['payment_date'])). '</td></tr>';
}
$match.='</table></div>';
} else { $match.=""; $show='';}
} else {
$match.="";
}
if($rinv ['paid']==0){
$arr_n[$kk]['winien_n_roz']+=$rinv ['value'];
$ma_n_roz+=$rinv ['value'];
$checkbox2 = '<input type="checkbox" name="check2[]" value="' . $rinv ['id'] . '" onclick="addValue(this,' . $rinv ['value'] . ',document.getElementById(\'total_ma\'));">';
$color = ' color: #FF3333;';
}
if($rinv['paid']==1){
$arr_n[$kk]['winien_roz']+=$rinv ['value'];
$ma_roz+=$rinv ['value'];
// $paid = "*";
$checkbox2 = "";
$color = ' color: #337000;';}
$total+=$rinv['value'];
//$inv = '<a href="index.php?module=EcmPayments2&action=DetailView&record=' . $rinv ['id'] . '">' . $rinv['name'] . '</a>';
$i++;
if ($i % 2 == 1)
$str=$trs;
else
$str=$trs_grey;
$str .= '<td class="oddListRowS1" width="3%">' . $checkbox2 . ' '.$show.'</td><td class="oddListRowS1" style="' . $color . 'text-align: right;" width="10%">' . format_number ( $rinv ['value'] ) . ' '.$symbol.'&nbsp&nbsp</td><td class="oddListRowS1" width="28%">'.substr($rinv ['description'],0,50).'</td><td class="oddListRowS1" width="20%"><a href="index.php?module=EcmTransactions&action=DetailView&record=' . $rinv ['id'] . '">' . $rinv ['name'] . '</a></td><td width="10%"">' .date("d.m.Y", strtotime($rinv ['payment_date'])). '</td></tr>';
echo $str;
}
echo '</table></div></td></tr></table>';
echo '</td></tr></table>';
echo '<table><tr>';
echo '<td style="text-align: left;" id="total_wn">0,00</td>';
echo '<td style="text-align: right;" id="total_ma">0,00</td>';
echo '</tr></table>';
echo '<table><tr><td align="left">
<a href="index.php?module=EcmTransactions&action=EditView&parent_id=' . $_REQUEST ['account_id'] . '&type=0&return_module=EcmPaymentStates&return_action=index&return_id='.$_REQUEST ['account_id'].'">
<input type="button" value="Utwórz transakcje Winien"/>
</a>
</td><td align="right">
<a href="index.php?module=EcmTransactions&action=EditView&parent_id=' . $_REQUEST ['account_id'] . '&type=1&return_module=EcmPaymentStates&return_action=index&return_id='.$_REQUEST ['account_id'].'">
<input type="button" value="Utwórz transakcje Ma"/>
</a>
</td></tr></table>';
?>
<table width="100%">
<tr>
<td colspan="2" style="font-size: 18px; text-align: center">
<table cellspacing="3" cellpadding="3" border="0" width="100%"
style="font-size: 20px; border: 1px solid #cccccc;">
<tr style="font-weight: bold; background: #e6e6e6;">
<td style="text-align: center;">Razem Winien</td>
<td style="text-align: center;">Saldo</td>
<td style="text-align: center;">Razem Ma</td>
</tr>
<tr>
<td style="text-align: center;">
<?php
// $total_wn-=4635096.97;
//var_dump($arr_w);
foreach($arr_w as $key=>$v){
if($arr_w[$key]['used']==1){
echo format_number ($arr_w[$key]['winien_roz']+$arr_w[$key]['winien_n_roz'])." ".$arr_w[$key]['znak'].'<p style="font-size: 12px;">Nierozliczone: '.format_number ($arr_w[$key]['winien_n_roz'] ).' '.$arr_w[$key]['znak'].'</p>';
}
}
/*
echo 'Razem<br>';
echo format_number ( $winien_roz + $winien_n_roz );
echo '<br>';
echo '<p style="font-size: 12px;">Nierozliczone: ' . format_number ( $winien_n_roz ) . '</p>';
*/
?>
</td>
<td style="text-align: center;">
<?php
foreach($arr_w as $key=>$v){
if($arr_w[$key]['used']==1 || $arr_n[$key]['used']==1){
if((($arr_n[$key]['winien_roz']+$arr_n[$key]['winien_n_roz'])-($arr_w[$key]['winien_roz']+$arr_w[$key]['winien_n_roz']))>0){
$color='black;';
} else {
if((($arr_n[$key]['winien_roz']+$arr_n[$key]['winien_n_roz'])-($arr_w[$key]['winien_roz']+$arr_w[$key]['winien_n_roz']))<0){
$color='red;';
}
}
echo '<p style="color: '.$color.';">';
echo format_number(($arr_n[$key]['winien_roz']+$arr_n[$key]['winien_n_roz'])-($arr_w[$key]['winien_roz']+$arr_w[$key]['winien_n_roz']))." ".$arr_w[$key]['znak'];
echo '</p>';
}
}
/*
$wartosc=(($ma_roz + $ma_n_roz) - ($winien_roz + $winien_n_roz));
if($r['account_type']=='rs' || $r['account_type']=='sup'){
if($wartosc>0){
$color='red;';
}
} else {
if($wartosc<0){
$color='red;';
}
}
echo '<p style="color: '.$color.';">';
echo format_number ( $wartosc );
echo '</p>';
*/
?>
</td>
<td style="text-align: center;">
<?php
//echo "<pre>";
//var_dump($arr_n);
foreach($arr_n as $key=>$v){
if($arr_n[$key]['used']==1){
echo format_number ($arr_n[$key]['winien_roz']+$arr_n[$key]['winien_n_roz'])." ".$arr_n[$key]['znak'].'<p style="font-size: 12px;">Nierozliczone: '.format_number ($arr_n[$key]['winien_n_roz'] ).' '.$arr_n[$key]['znak'].'</p>';
}
}
/*
echo 'Razem<br>';
echo format_number ( $ma_roz + $ma_n_roz );
echo '<br>';
echo '<p style="font-size: 12px;">Nierozliczone: ' . format_number ( $ma_n_roz ) . '</p>';
*/
?>
</td>
</table><input type='hidden' id='userform' value="<?php echo $_REQUEST['account_id'];?>"
name="account_id" /><input type='submit' id='userform' type="button" class="button" value="Rozlicz"
name="match" /></form><input type="submit"
class="button" value="Pokaż nierozliczone"
onclick="window.location = '<?php echo "index.php?module=EcmPaymentStates&action=index&account_name=".$_REQUEST['account_name']."&matched=1&account_id=".$_REQUEST['account_id'].""; ?>';"
name= /> <input type="submit" class="button"
value="Pokaż wszystko"
onclick="window.location = '<?php echo "index.php?module=EcmPaymentStates&action=index&account_name=".$_REQUEST['account_name']."&matched=0&account_id=".$_REQUEST['account_id'].""; ?>';" /> <input type="submit" class="button"
value="Pokaż rozliczone"
onclick="window.location = '<?php echo "index.php?module=EcmPaymentStates&action=index&account_name=".$_REQUEST['account_name']."&matched=2&account_id=".$_REQUEST['account_id'].""; ?>';" /> <input type="submit" class="button"
value="Utwórz XLS"
onclick="document.Search.action.value='CreateXLS';" name="createxls" />
<input type="button" class="button"
value="MultiMach (TEST - nie używać :))"
onclick="doMultiMach();" />
<?php
echo $match;
?>

View File

@@ -0,0 +1,412 @@
<?php
//ini_set('display_errors',1);
if($_REQUEST ['record']!=null)$_REQUEST ['account_id']=$_REQUEST ['record'];
$r = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "select name,to_vatid,billing_address_city,billing_address_street,account_type from accounts where id='" . $_REQUEST ['account_id'] . "'" ) );
echo $_REQUEST ['account_name'] = $r ['name'];
//echo '<br>'."select name,to_vatid,billing_address_city,billing_address_street,account_type from accounts where id='" . $_REQUEST ['account_id'] . "'";
?>
<h2>Rozliczenia: Strona główna</h2>
<form action="index.php" method="get" name="Search">
<input type="hidden" name="action" value="index" /> <input
type="hidden" name="not_matched" value="0" /> <input type="hidden"
name="module" value="EcmPaymentStates" />
<link rel="stylesheet" href="include/jQuery/jquery-ui/themes/base/jquery-ui.css">
<script src="include/jQuery/jquery-2.1.0.min.js"></script>
<script src="include/jQuery/jquery-ui/ui/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
#draggable { width: 150px; height: 150px; padding: 0.5em; }
</style>
<script>
$(function() {
$( "div[name=lol]" ).draggable();
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
function show(obj,event) {
var el = document.getElementById(obj);
el.style.display = 'block';
var x=event.clientX;
var y=event.clientY;
//el.style.position = "absolute";
//alert(x+' '+y);
el.style.top = '-'+y+'px'; //or whatever
el.style.left = x+'px'; // or whatever
}
</script>
<script language="javascript">
var OPT=new Array();
OPT['dec_len']=2;
OPT['sep_1000']=".";
OPT['dec_sep']=",";
var inv = new Array();
var pay = new Array();
function formatNumber(number,add) {
if(!number) number = 0;
number = parseFloat(number);
var tmp = number.toFixed(OPT['dec_len']);
var s1 = tmp.substring(0,tmp.length-1-OPT['dec_len']);
var s2 = tmp.substring(tmp.length-OPT['dec_len'],tmp.length);
var tmp = '';
for(var i=s1.length;i>0;i-=3) {
tmp = ((i<=3)?"":OPT['sep_1000'])+s1.substring(i-3,i)+tmp;
}
s1 = tmp;
return (s1+OPT['dec_sep']+s2).toString()+((add)?add:'');
}
function unformatNumber(ufn,add) {
if(add) {
var match = /add/g;
ufn = ufn.replace(match,'');
}
var match = /Err/g;
ufn = ufn.replace(match,'');
if(!ufn) return parseFloat(0);
var pos = ufn.indexOf(OPT['dec_sep']);
var s1='', s2='';
if(pos==-1) { s1 = ufn; s2 = ''; }
else { s1 = ufn.substring(0,pos); s2 = ufn.substring(pos+1,ufn.length); }
var pos = -1;
while((pos = s1.indexOf(OPT['sep_1000'])) != -1)
s1 = s1.substring(0,pos)+s1.substring(pos+1,s1.length);
return parseFloat(s1+"."+s2);
}
function addValue(obj,value,inp){
if(obj.checked==true) {
inp.innerHTML=formatNumber(parseFloat(unformatNumber(inp.innerHTML))+parseFloat(value));
if (inp.id=="total_wn")
inv[obj.value] = 1;
if (inp.id=="total_ma")
pay[obj.value] = 1;
}
else {
inp.innerHTML=formatNumber(parseFloat(unformatNumber(inp.innerHTML))-parseFloat(value));
if (inp.id=="total_wn")
inv[obj.value] = null;
if (inp.id=="total_ma")
pay[obj.value] = null;
}
}
function doMach() {
var invoices="";
for(var i in inv) {
if (inv[i]==1)
invoices+= i+"|";
}
var payments="";
for(var i in pay) {
if (pay[i]==1)
payments+= i+"|";
}
window.location="index.php?to_pdf=1&module=EcmPaymentStates&action=Match&inv="+invoices+"&pay="+payments+"&account_id="+document.getElementById("account_id").value;
}
function addValuePayments(obj,value,inp){
var cb=document.getElementById("paymentsList").getElementsByTagName("input");
for(var i=0;i<cb.length;i++){
if(cb[i].type=="checkbox"){
cb[i].checked=false;
}
}
obj.checked=true;
inp.innerHTML=formatNumber(parseFloat(value));
}
</script>
<table cellspacing="2" cellpadding="2" width="100%" border="0">
<tr>
<td width="100%" style="width: 520px;">
<ul class="tablist">
<li class="active" id="tab_li_EcmPayments|basic_search"><a
class="current" id="tab_link_EcmPayments|basic_search" href="#">Podstawowe
wyszukiwanie</a></li>
</ul>
<table width="100%" cellspacing="0" cellpadding="0" border="0"
style="border-top: 0px none; margin-bottom: 4px" class="tabForm">
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">Kontrahent</td>
<td class="dataField" width="40%" nowrap="nowrap"><input
name="account_name" tabindex="" id="account_name" size=""
value="<?php echo $_REQUEST['account_name'];?>" title=""
type="text"> <input name="account_id" id="account_id"
value="<?php echo $_REQUEST['account_id'];?>" type="hidden"> <input
name="btn_account_name" tabindex="" title="Select [Alt+T]"
accesskey="T" class="button" value="Wybierz"
onclick='open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"id":"account_id","name":"account_name"}}, "single", true);'
type="button"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">NIP</td>
<td class="dataField" width="20%" nowrap="nowrap"><input
name="to_vatid" tabindex="" id="to_vatid" size=""
value="<?php echo $r['to_vatid'];?>" title=""
type="text"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">Dokument nr</td>
<td class="dataField" width="30%" nowrap="nowrap"><input
name="document_no" tabindex="" id="document_no" size=""
value="<?php echo $_REQUEST['document_no'];?>" title=""
type="text"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">Kwota</td>
<td class="dataField" width="30%" nowrap="nowrap"><input
name="value" tabindex="" id="value" size=""
value="<?php echo $_REQUEST['value'];?>" title="" type="text"></td>
</tr>
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">Indeks</td>
<td class="dataField" width="30%" nowrap="nowrap"><input
name="account_name2" tabindex="" id="account_name2" size="50"
value="<?php echo $r['index_dbf2'];?>" title=""
type="text"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">Miasto</td>
<td class="dataField" width="20%" nowrap="nowrap"><input
name="to_vatid" tabindex="" id="to_vatid" size=""
value="<?php echo $r['billing_address_city'];?>" title=""
type="text"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">Ulica</td>
<td class="dataField" width="30%" nowrap="nowrap"><input
name="document_no" tabindex="" id="document_no" size=""
value="<?php echo $r['billing_address_street'];?>" title=""
type="text"></td>
</tr>
</table> <input tabindex='2' title='Search [Alt+Q]' accessKey='Q'
class='button' onclick="document.Search.action.value='index';"
type='submit' name='button' value='Szukaj' id='search_form_submit' />&nbsp;
<input tabindex='2' title='Clear [Alt+C]' accessKey='C'
onclick="location.href='index.php?module=EcmPaymentStates&action=index';"
class='button' type='button' name='clear' value=' Wyczyść ' />
</td>
</tr>
</table></form><form method='post' id='userform' action='modules/EcmPaymentStates/Match.php'>
<?php
include_once ("modules/EcmPaymentStates/helper.php");
// show all
$wh_paid_i = 0;
$wh_paid_p = 0;
// show not mached
if ($_REQUEST ['matched'] == 1) {
$wh_paid_i = 1;
$wh_paid_p = 1;
}
// show mached
if ($_REQUEST ['matched'] == 2) {
$wh_paid_i = 2;
$wh_paid_p = 2;
}
//echo 'tt: ' . $wh_paid_p;
echo '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
echo '<tr valign="top"><td colspan="5">';
global $current_language;
echo '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
echo '<tr>';
echo '<td class="listViewThS1" style="width:4px;">&nbsp;</td><td class="listViewThS1" style="width:70px;">Termin płatności</td><td class="listViewThS1" style="width:180px;">Nr Dokumentu</td><td class="listViewThS1" style="width:100px;">Opis</td><td class="listViewThS1" style="width:100px; text-align: right;">Kwota&nbsp&nbsp&nbsp</td>';
echo '</tr></table><div style="height:200px;overflow:auto"><table width="100%">';
if ($_REQUEST ['document_no']){
$where_clause='and name like "'.$_REQUEST ['document_no'].'"';
}
if ($_REQUEST ['value']){
$where_value='and value = "'.unformat_number ( $_REQUEST ['value'] ).'"';
}
if($_REQUEST ['matched']==2){
$where_paid='and paid ="1"';
}
if($_REQUEST ['matched']==0){
$_REQUEST ['not_matched']=2;
}
if($_REQUEST ['matched']==1){
$where_paid='and paid ="0"';
}
if ($_REQUEST ['value'] && is_numeric ( $_REQUEST ['value'] )) {
$v = "and p.total BETWEEN(" . unformat_number ( $_REQUEST ['value'] - 1 ) . "," . unformat_number ( $_REQUEST ['value'] + 1 ) . ")";
} else
$v = "";
$total=0;
$winien_n_roz=0;
$winien_roz=0;
$licz=1;
$query="select * from ecmtransactions where parent_id='" . $_REQUEST ['account_id'] . "' and type=0 and deleted='0' ".$where_clause." ".$where_value." ".$where_paid."and payment_date > '2011-12-31' order by date_entered desc";
$w= $GLOBALS ['db']->query ( $query);
//echo "select * from ecmtransactions where parent_id='" . $_REQUEST ['account_id'] . "' and type=0 and deleted='0' ".$where_clause." ".$where_value." order by date_entered desc";
$abc=0;
while($rinv = $GLOBALS ['db']->fetchByAssoc ($w)){
if ($rinv ['payment_date'] < '2008-12-31' && $rinv ['paid'] == 0)
continue;
$match.="";
$ab++;
$total+=$rinv['value'];
if($rinv ['paid']==0){
$color = 'color: #FF0000;';
$checkbox = '<input type="checkbox" name="check1[]" value="' . $rinv ['id'] . '" onclick="addValue(this,' . $rinv ['value'] . ',document.getElementById(\'total_wn\'));">';
$winien_n_roz+=$rinv ['value'];
}
if($rinv['paid']==1){$winien_roz+=$rinv ['value'];$checkbox ="";$color = 'color: #33FF00;';}
if($_REQUEST ['matched']==2){
$a= $GLOBALS ['db']->query("SELECT a.ecminvoiceout_id as tid,b.name as name,b.id as id,b.value,b.payment_date from ecmpayments2_ecminvoiceouts as a inner join ecmtransactions as b on a.ecminvoiceout_id=b.id where a.ecmpayment_id ='".$rinv['id']."'");
if($a->num_rows>0){
$show='<a href="#" onClick="show(\'draggable'.$abc.'\',event)"><img src="themes/Sugar5/images/info_inline.gif?s=bed8cd35065048ceebdc639ebe305e2c&c=1"></a>';
$match.='<div id="draggable'.$abc.'" name="lol" class="ui-widget-content" style="display:none; width:300px;">
<p style="text-align: left;"><img border="0" src="themes/Sugar/images/close_inline.gif" onClick="hide(\'draggable'.$abc.'\')"></img> Wiązania do '.$rinv['name'].'</p>
<hr><table style="width: 299px;"><tr><td style="text-align: left;">Nazwa</td><td>Kwota</td><td style="text-align: right;">Data</td></tr>';
while($rinv2 = $GLOBALS ['db']->fetchByAssoc ($a)){
$match.='<tr><td style="text-align: left;"><a href="index.php?module=EcmTransactions&action=DetailView&record=' . $rinv2 ['id'] . '">' . $rinv2['name'] . '</a></td><td>'.$rinv2['value'].'</td><td style="text-align: right;">'.$rinv2['payment_date'].'</td></tr>';
}
$abc++;
$match.='</table></div>';
} else { $match.="";$show="";}
} else {
$match.="";
}
$inv = '<a href="index.php?module=EcmTransactions&action=DetailView&record=' . $rinv ['id'] . '">' . $rinv['name'] .'</a>';
$str = '<tr><td class="oddListRowS1" width="4%">' . $checkbox . ' '.$show.'</td><td class="oddListRowS1" width="15%">' .date("d.m.Y", strtotime($rinv ['payment_date'])). '</td><td class="oddListRowS1" width="23%" > ' . $inv . '</td><td class="oddListRowS1">'.substr($rinv ['description'],0,50).'</td><td class="oddListRowS1" style="text-align: right; ' . $color . '">' . format_number ( $rinv ['value'] ) . '</td></tr>';
echo $str;
//$licz++;
}
echo '</table></div>';
echo '</td><td colspan="5">';
echo '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
echo '<tr>';
echo '<td class="listViewThS1" style="width:10px;">&nbsp;</td><td class="listViewThS1" style="width:6px;">&nbsp;</td><td class="listViewThS1" style="width:25px;">Kwota</td><td class="listViewThS1" style="width:200px; padding-left:20px;text-align:center;">Opis</td><td class="listViewThS1" style="width:80px;">Nr dokumentu</td><td class="listViewThS1" style="width:70px;">Termin płatności</td>';
echo '</tr></table><div style="height:200px;overflow:auto"><table width="100%">';
$ma_n_roz =0;
$ma_roz=0;
$query="select * from ecmtransactions where parent_id='" . $_REQUEST ['account_id'] . "' and type=1 and deleted='0' ".$where_clause." ".$where_value." ".$where_paid." and payment_date > '2011-12-31' order by date_entered desc";
$w= $GLOBALS ['db']->query ( $query);
//echo "select * from ecmtransactions where parent_id='" . $_REQUEST ['account_id'] . "' and type=1 and deleted='0' ".$where_clause." ".$where_value." order by date_entered desc";
while($rinv = $GLOBALS ['db']->fetchByAssoc ($w)){
$match.="";
if ($rinv ['payment_date'] < '2008-12-31' && $rinv ['paid'] == 0)
continue;
if($_REQUEST ['matched']==2){
$ab= $GLOBALS ['db']->query("SELECT a.ecminvoiceout_id as tid,b.name as name,b.id as id,b.value,b.payment_date from ecmpayments2_ecminvoiceouts as a inner join ecmtransactions as b on a.ecmpayment_id=b.id where a.ecminvoiceout_id ='".$rinv['id']."'");
//echo "SELECT a.ecminvoiceout_id as tid,b.name as name,b.id as id from ecmpayments2_ecminvoiceouts as a inner join ecmtransactions as b on a.ecmpayment_id=b.id where a.ecmpayment_id ='".$rinv['id']."'<br>".$a->num_rows."";
if($ab->num_rows>0){
$abc++;
$show='<a href="#" onClick="show(\'draggable'.$abc.'\',event)"><img src="themes/Sugar5/images/info_inline.gif?s=bed8cd35065048ceebdc639ebe305e2c&c=1"></a>';
$match.='<div id="draggable'.$abc.'" name="lol" class="ui-widget-content" style="display:none; width: 300px;">
<p style="text-align: left;"><img border="0" src="themes/Sugar/images/close_inline.gif" onClick="hide(\'draggable'.$abc.'\')"></img> Wiązania do '.$rinv['name'].'</p>
</a><hr><table style="width: 299px;"><tr><td style="text-align: left;">Nazwa</td><td>Kwota</td><td style="text-align: right;">Data</td></tr>';
while($rinv2 = $GLOBALS ['db']->fetchByAssoc ($ab)){
$match.='<tr><td style="text-align: left;"><a href="index.php?module=EcmTransactions&action=DetailView&record=' . $rinv2 ['id'] . '">' . $rinv2['name'] . '</a></td><td>'.$rinv2['value'].'</td><td style="text-align: right;">'.$rinv2['payment_date'].'</td></tr>';
}
$match.='</table></div>';
} else { $match.=""; $show='';}
} else {
$match.="";
}
if($rinv ['paid']==0){ $ma_n_roz+=$rinv ['value'];
$checkbox2 = '<input type="checkbox" name="check2[]" value="' . $rinv ['id'] . '" onclick="addValue(this,' . $rinv ['value'] . ',document.getElementById(\'total_ma\'));">';
$color = ' color: #FF3333;';
}
if($rinv['paid']==1){$ma_roz+=$rinv ['value'];
// $paid = "*";
$checkbox2 = "";
$color = ' color: #33FF00;';}
$total+=$rinv['value'];
//$inv = '<a href="index.php?module=EcmPayments2&action=DetailView&record=' . $rinv ['id'] . '">' . $rinv['name'] . '</a>';
$str = '<tr><td class="oddListRowS1" width="5%">' . $checkbox2 . ' '.$show.'</td><td class="oddListRowS1" style="' . $color . '" width="10%">' . format_number ( $rinv ['value'] ) . '&nbsp&nbsp</td><td class="oddListRowS1" width="28%">'.substr($rinv ['description'],0,50).'</td><td class="oddListRowS1" width="20%"><a href="index.php?module=EcmTransactions&action=DetailView&record=' . $rinv ['id'] . '">' . $rinv ['name'] . '</a></td><td width="10%"">' .date("d.m.Y", strtotime($rinv ['payment_date'])). '</td></tr>';
echo $str;
}
echo '</table></div></td></tr></table>';
echo '</td></tr></table>';
echo '<table><tr>';
echo '<td style="text-align: left;" id="total_wn">0,00</td>';
echo '<td style="text-align: right;" id="total_ma">0,00</td>';
echo '</tr></table>';
echo '<table><tr><td align="left">
<a href="index.php?module=EcmTransactions&action=EditView&parent_id=' . $_REQUEST ['account_id'] . '&type=0&return_module=EcmPaymentStates&return_action=index&return_id='.$_REQUEST ['account_id'].'">
<input type="button" value="Utwórz transakcje Winien"/>
</a>
</td><td align="right">
<a href="index.php?module=EcmTransactions&action=EditView&parent_id=' . $_REQUEST ['account_id'] . '&type=1&return_module=EcmPaymentStates&return_action=index&return_id='.$_REQUEST ['account_id'].'">
<input type="button" value="Utwórz transakcje Ma"/>
</a>
</td></tr></table>';
?>
<table width="100%">
<tr>
<td colspan="2" style="font-size: 18px; text-align: center">
<table cellspacing="3" cellpadding="3" border="0" width="100%"
style="font-size: 20px; border: 1px solid #cccccc;">
<tr style="font-weight: bold; background: #e6e6e6;">
<td style="text-align: center;">Razem Winien</td>
<td style="text-align: center;">Saldo</td>
<td style="text-align: center;">Razem Ma</td>
</tr>
<tr>
<td style="text-align: center;">
<?php
// $total_wn-=4635096.97;
echo format_number ( $winien_roz + $winien_n_roz );
echo '<br>';
echo '<p style="font-size: 12px;">Nierozliczone: ' . format_number ( $winien_n_roz ) . '</p>';
?>
</td>
<td style="text-align: center;">
<?php
$wartosc=(($ma_roz + $ma_n_roz) - ($winien_roz + $winien_n_roz));
if($r['account_type']=='rs' || $r['account_type']=='sup'){
if($wartosc>0){
$color='red;';
}
} else {
if($wartosc<0){
$color='red;';
}
}
echo '<p style="color: '.$color.';">';
echo format_number ( $wartosc );
echo '</p>';
echo '<p style="font-size: 12px;">Nierozliczone: ' . format_number ( $ma_n_roz - $winien_n_roz ) . '</p>';
?>
</td>
<td style="text-align: center;">
<?php
echo format_number ( $ma_roz + $ma_n_roz );
echo '<br>';
echo '<p style="font-size: 12px;">Nierozliczone: ' . format_number ( $ma_n_roz ) . '</p>';
?>
</td>
</table> <input type='submit' id='userform' type="button" class="button" value="Rozlicz"
name="match" /></form><input type="submit"
class="button" value="Pokaż nierozliczone"
onclick="window.location = '<?php echo "index.php?module=EcmPaymentStates&action=index&account_name=".$_REQUEST['account_name']."&matched=1&account_id=".$_REQUEST['account_id'].""; ?>';"
name= /> <input type="submit" class="button"
value="Pokaż wszystko"
onclick="window.location = '<?php echo "index.php?module=EcmPaymentStates&action=index&account_name=".$_REQUEST['account_name']."&matched=0&account_id=".$_REQUEST['account_id'].""; ?>';" /> <input type="submit" class="button"
value="Pokaż rozliczone"
onclick="window.location = '<?php echo "index.php?module=EcmPaymentStates&action=index&account_name=".$_REQUEST['account_name']."&matched=2&account_id=".$_REQUEST['account_id'].""; ?>';" /> <input type="submit" class="button"
value="Utwórz XLS"
onclick="document.Search.action.value='CreateXLS';" name="createxls" />
<?php
echo $match;
?>

View File

@@ -0,0 +1,351 @@
<?php
if ($_GET ['action'] == "index")
$_REQUEST ['not_matched'] = 1;
if ($_REQUEST ['nott_matched'])
$_REQUEST ['not_matched'] = $_REQUEST ['nott_matched'];
if ($_REQUEST ['account_id'] == "") {
$_REQUEST ['account_id'] = 134;
$_REQUEST ['account_id'] = 134;
}
$r = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "select name from accounts where id='" . $_REQUEST ['account_id'] . "'" ) );
$_REQUEST ['account_name'] = $r ['name'];
?>
<h2>Rozliczenia: Strona główna</h2>
<form action="index.php" method="post" name="Search">
<input type="hidden" name="action" value="index" /> <input
type="hidden" name="not_matched" value="0" /> <input type="hidden"
name="module" value="EcmPaymentStates" />
<script language="javascript">
var OPT=new Array();
OPT['dec_len']=2;
OPT['sep_1000']=".";
OPT['dec_sep']=",";
var inv = new Array();
var pay = new Array();
function formatNumber(number,add) {
if(!number) number = 0;
number = parseFloat(number);
var tmp = number.toFixed(OPT['dec_len']);
var s1 = tmp.substring(0,tmp.length-1-OPT['dec_len']);
var s2 = tmp.substring(tmp.length-OPT['dec_len'],tmp.length);
var tmp = '';
for(var i=s1.length;i>0;i-=3) {
tmp = ((i<=3)?"":OPT['sep_1000'])+s1.substring(i-3,i)+tmp;
}
s1 = tmp;
return (s1+OPT['dec_sep']+s2).toString()+((add)?add:'');
}
function unformatNumber(ufn,add) {
if(add) {
var match = /add/g;
ufn = ufn.replace(match,'');
}
var match = /Err/g;
ufn = ufn.replace(match,'');
if(!ufn) return parseFloat(0);
var pos = ufn.indexOf(OPT['dec_sep']);
var s1='', s2='';
if(pos==-1) { s1 = ufn; s2 = ''; }
else { s1 = ufn.substring(0,pos); s2 = ufn.substring(pos+1,ufn.length); }
var pos = -1;
while((pos = s1.indexOf(OPT['sep_1000'])) != -1)
s1 = s1.substring(0,pos)+s1.substring(pos+1,s1.length);
return parseFloat(s1+"."+s2);
}
function addValue(obj,value,inp){
if(obj.checked==true) {
inp.innerHTML=formatNumber(parseFloat(unformatNumber(inp.innerHTML))+parseFloat(value));
if (inp.id=="total_wn")
inv[obj.value] = 1;
if (inp.id=="total_ma")
pay[obj.value] = 1;
}
else {
inp.innerHTML=formatNumber(parseFloat(unformatNumber(inp.innerHTML))-parseFloat(value));
if (inp.id=="total_wn")
inv[obj.value] = null;
if (inp.id=="total_ma")
pay[obj.value] = null;
}
}
function doMach() {
var invoices="";
for(var i in inv) {
if (inv[i]==1)
invoices+= i+"|";
}
var payments="";
for(var i in pay) {
if (pay[i]==1)
payments+= i+"|";
}
window.location="index.php?to_pdf=1&module=EcmPaymentStates&action=Match&inv="+invoices+"&pay="+payments+"&account_id="+document.getElementById("account_id").value;
}
function addValuePayments(obj,value,inp){
var cb=document.getElementById("paymentsList").getElementsByTagName("input");
for(var i=0;i<cb.length;i++){
if(cb[i].type=="checkbox"){
cb[i].checked=false;
}
}
obj.checked=true;
inp.innerHTML=formatNumber(parseFloat(value));
}
</script>
<table cellspacing="2" cellpadding="2" width="100%" border="0">
<tr>
<td width="100%" style="width: 520px;">
<ul class="tablist">
<li class="active" id="tab_li_EcmPayments|basic_search"><a
class="current" id="tab_link_EcmPayments|basic_search" href="#">Podstawowe
wyszukiwanie</a></li>
</ul>
<table width="100%" cellspacing="0" cellpadding="0" border="0"
style="border-top: 0px none; margin-bottom: 4px" class="tabForm">
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">Kontrahent</td>
<td class="dataField" width="40%" nowrap="nowrap"><input
name="account_name" tabindex="" id="account_name" size=""
value="<?php echo $_REQUEST['account_name'];?>" title=""
type="text"> <input name="account_id" id="account_id"
value="<?php echo $_REQUEST['account_id'];?>" type="hidden"> <input
name="btn_account_name" tabindex="" title="Select [Alt+T]"
accesskey="T" class="button" value="Select"
onclick='open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"id":"account_id","name":"account_name"}}, "single", true);'
type="button"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">Dokument nr</td>
<td class="dataField" width="40%" nowrap="nowrap"><input
name="document_no" tabindex="" id="document_no" size=""
value="<?php echo $_REQUEST['document_no'];?>" title=""
type="text"></td>
<td class="dataLabel" width="10%" nowrap="nowrap">Kwota</td>
<td class="dataField" width="40%" nowrap="nowrap"><input
name="value" tabindex="" id="value" size=""
value="<?php echo $_REQUEST['value'];?>" title="" type="text"></td>
</tr>
</table> <input tabindex='2' title='Search [Alt+Q]' accessKey='Q'
class='button' onclick="document.Search.action.value='index';"
type='submit' name='button' value='Szukaj' id='search_form_submit' />&nbsp;
<input tabindex='2' title='Clear [Alt+C]' accessKey='C'
onclick="location.href='index.php?module=EcmPaymentStates&action=index';"
class='button' type='button' name='clear' value=' Wyczyść ' />
</td>
</tr>
</table>
<?php
include_once ("modules/EcmPaymentStates/helper.php");
// show all
$wh_paid_i = 0;
$wh_paid_p = 0;
// show not mached
if ($_REQUEST ['not_matched'] == 1) {
$wh_paid_i = 1;
$wh_paid_p = 1;
}
// show mached
if ($_REQUEST ['not_matched'] == 2) {
$wh_paid_i = 2;
$wh_paid_p = 2;
}
echo 'tt: ' . $wh_paid_p;
echo '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
echo '<tr valign="top"><td colspan="5"><div style="height:400px;overflow:auto">';
global $current_language;
echo '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
echo '<tr>';
echo '<td class="listViewThS1" style="width:6px;">&nbsp;</td><td class="listViewThS1" style="width:6px;">&nbsp;</td><td class="listViewThS1" style="width:100px;">Termin płatności</td><td class="listViewThS1" style="width:180px;">Nazwa</td><td class="listViewThS1" style="width:100px;">Połączona płatność</td><td class="listViewThS1" style="width:100px; text-align: right;">Wartość&nbsp&nbsp&nbsp</td>';
echo '</tr>';
if ($_REQUEST ['value'] && is_numeric ( $_REQUEST ['value'] )) {
$v = "and p.total BETWEEN(" . unformat_number ( $_REQUEST ['value'] - 1 ) . "," . unformat_number ( $_REQUEST ['value'] + 1 ) . ")";
} else
$v = "";
$query = "select p.id,p.document_no,p.paid,p.register_date,p.payment_date,p.total,p.ecminvoiceout_id, p.ecmpayment_id from ecmpayments2_ecminvoiceouts as p inner join ecminvoiceouts as i on p.ecminvoiceout_id=i.id and i.type!='canceled' where p.deleted='0' and p.account_id='" . $_REQUEST ['account_id'] . "' " . $v . " order by p.date_entered desc";
$w = $GLOBALS ['db']->query ( $query );
$winien_roz = 0;
$winien_n_roz = 0;
while ( $r = $GLOBALS ['db']->fetchByAssoc ( $w ) ) {
$str = "";
if ($r ['register_date'] < '2008-12-31' && $r ['paid'] == 0)
continue;
// if($r['type']!='correct'){
$rinv = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "select description,id from ecmtransactions where id='" . $r ['ecminvoiceout_id'] . "' and type=0" ) );
if ($r ['paid'] == 0 || ! $r ['paid']) {
$paid = "&nbsp;";
$checkbox = '<input type="checkbox" name="check1[]" value="' . $r ['id'] . '" onclick="addValue(this,' . $r ['total'] . ',document.getElementById(\'total_wn\'));">';
$color = ' color: #FF3333; ';
$winien_n_roz += $r ['total'];
$paid_name = '';
} else {
$paid = "*";
$checkbox = "";
$color = ' color: #33FF00; ';
$winien_roz += $r ['total'];
// get payment
$paid_name='';
$req=$GLOBALS ['db']->query ( "select p.id, p.name from ecmpayments2_ecminvoiceouts_rel as r inner join ecmpayments2 as p on p.id=r.ecmpayment_id where r.ee_id='" . $r ['id'] . "'" );
while($wyn = $GLOBALS ['db']->fetchByAssoc ( $req )){
$paid_name .=' <a href="index.php?module=EcmPayments2&action=DetailView&record=' . $wyn ['id'] . '" target="new">' . $wyn ['name'] . '</a><br>';
}
}
$exp = explode ( "-", $r ['register_date'] );
if ($r ['paid'] == 0)
$arrear += $r ['total'];
if ($r ['ecminvoiceout_id'])
$inv = '<a href="index.php?module=EcmInvoiceOuts&action=DetailView&record=' . $r ['ecminvoiceout_id'] . '">' . $r ['document_no'] . '</a>';
else
$inv = $r ['document_no'];
$str = '<tr><td class="oddListRowS1">' . $checkbox . '</td><td class="oddListRowS1">' . $paid . '</td><td class="oddListRowS1" style="width:158px;">' . $r ['register_date'] . '</td><td class="oddListRowS1" style="width:220px;overflow:hidden">' . $inv . '</td><td class="oddListRowS1">' . $paid_name . '</td><td class="oddListRowS1" style="width:100px; text-align: right; ' . $color . '">' . format_number ( $r ['total'] ) . '&nbsp&nbsp&nbsp</td></tr>';
if ($_REQUEST ['document_no'] && ! eregi ( $_REQUEST ['document_no'], $r ['document_no'] ))
;
elseif ($_REQUEST ['document_no'] && eregi ( $_REQUEST ['document_no'], $r ['document_no'] ))
echo $str;
elseif (! $_REQUEST ['document_no']) {
if ($wh_paid_i == 0)
echo $str;
elseif ($r ['paid'] == 1 && $wh_paid_i == 2)
echo $str;
elseif ($r ['paid'] == 0 && $wh_paid_i == 1)
echo $str;
}
// }
$total_wn += $r ['total'];
}
echo '</table></div>';
echo '</td><td colspan="5"><div style="height:400px;overflow:auto">';
echo '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
echo '<tr>';
echo '<td class="listViewThS1" style="width:10px;">&nbsp;</td><td class="listViewThS1" style="width:6px;">&nbsp;</td><td class="listViewThS1" style="width:8%;">Wartość</td><td class="listViewThS1" style="width:192px; padding-left:20px;">Opis płatności</td><td class="listViewThS1" style="width:100px;">Data płatności</td><td class="listViewThS1" style="width:25px;">Typ</td>';
echo '</tr>';
$query = "select payment_date,id,description,value,paid,name from ecmtransactions where deleted='0' and parent_id='" . $_REQUEST ['account_id'] . "' and type=1 order by date_entered desc";
$w = $GLOBALS ['db']->query ( $query );
$last_date = "";
$ma_roz = 0;
$ma_n_roz = 0;
while ( $r = $GLOBALS ['db']->fetchByAssoc ( $w ) ) {
$str = "";
if ($r ['payment_date'] < '2008-12-31' && $r ['paid'] == 0)
continue;
if ($r ['paid'] == 1) {
$paid = "*";
$checkbox = "";
$color = ' color: #33FF00;';
$ma_roz += $r ['value'];
} else {
$paid = "&nbsp;";
$checkbox = '<input type="checkbox" name="check2[]" value="' . $r ['id'] . '" onclick="addValue(this,' . $r ['value'] . ',document.getElementById(\'total_ma\'));">';
$color = ' color: #FF3333;';
$ma_n_roz += $r ['value'];
}
if (str_replace ( " ", "", $r ['name'] ) == "" || ! $r ['name'])
$r ['name'] = "blank";
if (! $_REQUEST ['document_no'] && $last_date != $r ['payment_date'] && ($r ['paid'] == 0 || ! $wh_paid_p)) {
if ($wh_paid_p)
$whp = " and paid='0'";
else
$whp = "";
$rr = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "select sum(value) as sum from ecmtransactions where deleted='0' and parent_id='" . $_REQUEST ['account_id'] . "'" . $whp . " and payment_date='" . $r ['payment_date'] . "' and type=0" ) );
$sum_total = $rr ['sum'];
}
if ($r ['name'] == "blank")
$desc_name = $r ['description'];
else
$desc_name = $r ['name'];
$str = '<tr><td class="oddListRowS1" style="width:10px;">' . $checkbox . '</td><td class="oddListRowS1" style="width:10px;">' . $paid . '</td><td class="oddListRowS1" style="width:50px; text-align: right; ' . $color . '">' . format_number ( $r ['value'] ) . '&nbsp&nbsp</td><td class="oddListRowS1" style="width:270px;overflow:hidden; padding-left: 25px;"><a href="index.php?module=EcmPayments&action=DetailView&record=' . $r ['id'] . '">' . $desc_name . '</a></td><td class="oddListRowS1" style="width:100px;">' . $r ['payment_date'] . '</td></tr>';
if ($_REQUEST ['document_no'] && ! eregi ( $_REQUEST ['document_no'], $desc_name ))
;
elseif ($_REQUEST ['document_no'] && eregi ( $_REQUEST ['document_no'], $desc_name ))
echo $str;
elseif (! $_REQUEST ['document_no']) {
if ($wh_paid_p == 0)
echo $str;
elseif ($r ['paid'] == 1 && $wh_paid_p == 2)
echo $str;
elseif ($r ['paid'] == 0 && $wh_paid_p == 1)
echo $str;
}
$total_ma += $r ['value'];
if ($r ['paid'] == 0 || ! $wh_paid_p)
$last_date = $r ['payment_date'];
if ($r ['paid'] == 0)
$total_not_paid += $r ['value'];
}
echo '</table></div></td></tr></table></div>';
echo '</td></tr></table>';
echo '<table><tr>';
echo '<td style="text-align: left;" id="total_wn">0,00</td>';
echo '<td style="text-align: right;" id="total_ma">0,00</td>';
echo '</tr></table>';
echo '<table><tr><td>ttt</td><td align="right">
<a href="index.php?module=EcmPayments2&action=EditView&parent_id=' . $_REQUEST ['account_id'] . '&return_module=EcmPaymentStates&return_action=index">
<input type="button" value="Utwórz płatność"/>
</a>
</td></tr></table>';
?>
<table width="100%">
<tr>
<td colspan="2" style="font-size: 18px; text-align: center">
<table cellspacing="3" cellpadding="3" border="0" width="100%"
style="font-size: 20px; border: 1px solid #cccccc;">
<tr style="font-weight: bold; background: #e6e6e6;">
<td style="text-align: center;">Razem Winien</td>
<td style="text-align: center;">Saldo</td>
<td style="text-align: center;">Razem Ma</td>
</tr>
<tr>
<td style="text-align: center;">
<?php
// $total_wn-=4635096.97;
echo format_number ( $winien_roz + $winien_n_roz );
echo '<br>';
echo '<p style="color:#FF3333;">Nierozliczone: ' . format_number ( $winien_n_roz ) . '</p>';
?>
</td>
<td style="text-align: center;">
<?php
echo format_number ( ($ma_roz + $ma_n_roz) - ($winien_roz + $winien_n_roz) );
echo '<br>';
echo '<p style="color:#FF3333;">Nierozliczone: ' . format_number ( $ma_n_roz - $winien_n_roz ) . '</p>';
?>
</td>
<td style="text-align: center;">
<?php
echo format_number ( $ma_roz + $ma_n_roz );
echo '<br>';
echo '<p style="color:#FF3333;">Nierozliczone: ' . format_number ( $ma_n_roz ) . '</p>';
?>
</td>
</tr>
</table> <input type="button" class="button" value="Dopasuj"
onclick="doMach();" name="match" />&nbsp; <input type="submit"
class="button" value="Pokaż nie dopasowane"
onclick="document.Search.action.value='index';document.Search.not_matched.value='1';"
name="notmatched" /> <input type="submit" class="button"
value="Pokaż wszystko"
onclick="document.Search.action.value='index';document.Search.not_matched.value='0';"
name="matchednotmatched" /> <input type="submit" class="button"
value="Pokaż dopasowane"
onclick="document.Search.action.value='index';document.Search.not_matched.value='2';"
name="matchednotmatched" /> <input type="submit" class="button"
value="Utwórz XLS"
onclick="document.Search.action.value='CreateXLS';" name="createxls" />
</form>

View File

@@ -0,0 +1,44 @@
<?php
class interestController
{
public $model;
public $ss;
function __construct(){
$this->model = new interestModel();
$this->ss = new Sugar_Smarty ();
global $mod_strings;
$this->ss->assign ( "MOD", $mod_strings );
}
function editAction()
{
$this->ss->assign ( "POSITIONS",json_encode($this->model->getRecords()));
$this->ss->display ( 'modules/EcmPaymentStates/tpls/interestEditView.tpl' );
}
function saveAction()
{
$this->model->saveRecords();
header('Location: index.php?module=EcmPaymentStates&action=interestView&step=detailAction');
}
function detailAction()
{
$this->ss->assign ( "POSITIONS",$this->model->getRecords());
$this->ss->display ( 'modules/EcmPaymentStates/tpls/interestDetailView.tpl' );
}
function calculateAction(){
$this->ss->assign ( "POSITIONS",$this->model->getRecords());
$this->ss->assign ( "TABLE",$this->model->calculateRecords());
$this->ss->assign ( "TOTAL",$this->model->total);
$this->ss->assign ( "REQ",$_REQUEST);
$this->ss->display ( 'modules/EcmPaymentStates/tpls/interestDetailView.tpl' );
}
}
?>

View File

@@ -0,0 +1,29 @@
<?php
Class InterestInvoices{
public $document_list;
public $db;
public $ask;
public $res;
public $result;
public $reply;
public function searchInterestInvoices(){
$this->db=$GLOBALS['db'];
$this->ask="SELECT * FROM ecmtransactions
WHERE deleted='0' AND
record_type='EcmInvoiceOuts'
AND type='0'
AND register_date > '2011-12-31'
AND (settled='0' OR settled IS NULL) and payment_date < '".date("Y-m-d")."'
ORDER BY payment_date desc";
$this->reply=$this->db->query($this->ask);
while($this->result=$this->db->fetchByAssoc($this->reply)){
$this->document_list[]=$this->result;
}
var_dump($this->document_list);
}
}
$c=new InterestInvoices();
$c->searchInterestInvoices();

View File

@@ -0,0 +1,430 @@
<?php
define("TABLEID", 'tblAppendGrid');
class interestModel
{
private $db;
public $ask;
public $reply;
public $positions;
public $result;
public $numbers;
public $i;
public $sdate;
public $edate;
public $amount;
public $total;
public $ids;
public $notes;
public $counter;
public $uid;
function __construct(){
$this->db=$GLOBALS['db'];
}
function getRecords(){
$this->ask="select id,DATE_FORMAT(date_from,'%d.%m.%Y') as date_from,DATE_FORMAT(date_to,'%d.%m.%Y') as date_to,symbol,rate from ecmpaymentstate_interest where deleted=0 order by position asc";
$this->reply=$this->db->query($this->ask);
while($this->result=$this->db->fetchByAssoc($this->reply)){
$this->positions[]=$this->result;
}
return $this->positions;
}
function createNumber(){
$this->numbers=explode(",",$_REQUEST[TABLEID.'_rowOrder']);
}
function getPost(){
$tmp=array();
$this->positions=array();
$this->i=0;
foreach ($this->numbers as $val){
$tmp['rate']=$_REQUEST[TABLEID.'_rate_'.$val];
$tmp['date_from']=date('Y-m-d',strtotime($_REQUEST[TABLEID.'_date_from_'.$val.'_date']));
$tmp['date_to']=date('Y-m-d',strtotime($_REQUEST[TABLEID.'_date_to_'.$val.'_date']));
$tmp['symbol']=$_REQUEST[TABLEID.'_symbol_'.$val];
$tmp['position']=$this->i;
$tmp['id']=$_REQUEST[TABLEID.'_id_'.$val]!='' ? $_REQUEST[TABLEID.'_id_'.$val] : create_guid();
$this->saveRecord($tmp);
unset($tmp);
$this->i++;
}
}
function deleteOld(){
$this->db->query("delete from ecmpaymentstate_interest");
}
function saveRecord($tmp){
$this->ask='INSERT INTO ecmpaymentstate_interest SET ';
foreach ($tmp as $key=>$val){
$this->ask.=$key.'="'.$val.'", ';
}
$this->ask.='deleted=0';
$this->db->query($this->ask);
}
function saveRecords()
{
$this->deleteOld();
$this->createNumber();
$this->getPost();
}
function getInterestTable(){
$this->positions=array();
$this->ask="select * from ecmpaymentstate_interest where
(date_from >= '".$this->sdate."' or date_to >= '".$this->sdate."')
and (date_from <= '".$this->edate."' or date_to <= '".$this->edate."')";
$this->reply=$this->db->query($this->ask);
while($this->result=$this->db->fetchByAssoc($this->reply)){
$this->positions[]=$this->result;
}
// var_dump($this->positions);
}
function daybeetwen($date,$date2){
$date1 = new DateTime($date);
$date2 = new DateTime(date('Y-m-d', strtotime($date2)));
return $diff = $date2->diff($date1)->format("%a");
}
function calculateRate($typ,$dni,$proc ){
if($typ=='R')$typ='365';
if($typ=='M')$typ='30';
return (($dni/$typ)*($proc/100)*$this->amount);
}
function calculateInterest(){
$this->total=0;
for($i=0;$i<count($this->positions);$i++){
if($i==0){
if(strtotime($this->positions[$i]['date_from'])<strtotime($this->sdate)){
$this->positions[$i]['date_from']=date('Y-m-d', strtotime($this->sdate.' + 1 day'));
}
if(strtotime($this->positions[$i]['date_from'])==strtotime($this->sdate)){
$this->positions[$i]['date_from']=date('Y-m-d', strtotime($this->sdate.' + 1 day'));
}
//$this->positions[$i]['date_from']=$this->sdate;
if(strtotime($this->positions[$i]['date_to'])>strtotime($this->edate)){
$this->positions[$i]['date_to']=$this->edate;
$this->positions[$i]['days']=$this->daybeetwen($this->positions[$i]['date_from'],$this->edate);
} else {
$this->positions[$i]['days']=$this->daybeetwen($this->positions[$i]['date_from'],$this->positions[$i]['date_to']);
}
$this->positions[$i]['amount']=$this->calculateRate($this->positions[$i]['symbol'],$this->positions[$i]['days'],$this->positions[$i]['rate']);
$this->positions[$i]['date_from']=date('d.m.Y',strtotime($this->positions[$i]['date_from']));
$this->positions[$i]['date_to']=date('d.m.Y',strtotime($this->positions[$i]['date_to']));
$this->total+=$this->positions[$i]['amount'];
}
else {
if(strtotime($this->positions[$i]['date_from'])<strtotime($this->sdate)){
$this->positions[$i]['date_from']=$this->sdate;
}
if(strtotime($this->positions[$i]['date_from'])==strtotime($this->sdate)){
$this->positions[$i]['date_from']=$this->sdate;
}
//$this->positions[$i]['date_from']=$this->sdate;
if(strtotime($this->positions[$i]['date_to'])>strtotime($this->edate)){
$this->positions[$i]['date_to']=$this->edate;
$this->positions[$i]['days']=$this->daybeetwen($this->positions[$i]['date_from'],$this->edate);
} else {
$this->positions[$i]['days']=$this->daybeetwen($this->positions[$i]['date_from'],$this->positions[$i]['date_to']);
}
$this->positions[$i]['amount']=$this->calculateRate($this->positions[$i]['symbol'],$this->positions[$i]['days'],$this->positions[$i]['rate']);
$this->positions[$i]['date_from']=date('d.m.Y',strtotime($this->positions[$i]['date_from']));
$this->positions[$i]['date_to']=date('d.m.Y',strtotime($this->positions[$i]['date_to']));
$this->total+=$this->positions[$i]['amount'];
}
}
}
function rozbijDate($tmp){
$date=array();
$date[0]=date("Y",strtotime($tmp));
$date[1]=date("n",strtotime($tmp));
$date[2]=date("j",strtotime($tmp));
return $date;
}
function checkDate($tmp){
$tmp=$this->rozbijDate($tmp);
while($this->workingDayOfYear(time(), true, mktime(0,0,0,$tmp[1],$tmp[2],$tmp[0]))!=false){
$tmp = date('Y-m-d', strtotime($this->sdate.' + 1 day'));
$this->sdate=$tmp;
$tmp=$this->rozbijDate($tmp);
}
}
function loadDates($par = true){
$this->sdate=date("Y-m-d",strtotime($_REQUEST['payment_date']));
$this->edate=date("Y-m-d",strtotime($_REQUEST['payment_after_date']));
if($par==true){
$this->amount=$this->number_unformat($_REQUEST['amount'],false,',','.')/100;
} else {
$this->amount=$_REQUEST['amount'];
}
}
function json2array(){
$this->ids=explode(",",$_REQUEST['id_list']);
array_pop($this->ids);
}
function json2array2($id){
$this->ids=explode(",",$id);
array_pop($this->ids);
}
function getDatesMonitFromId($id){
$this->ask=$this->db->query("
SELECT
t.payment_date as '0', (t.value-IFNULL(sum(r.value),0)) as '2', t.name, (t.value-IFNULL(sum(r.value),0)) as value, t.register_date, t.payment_date
FROM
ecmtransactions t
left join ecmtransactions_rel r on ( r.ecmtransaction_a_id=t.id or r.ecmtransaction_b_id=t.id)
WHERE t.type='0'
AND t.register_date > '2011-12-31'
and t.id='".$id."'
ORDER BY t.register_date desc");
$this->result=$this->db->fetchByAssoc($this->ask);
}
function getDatesFromId($id){
$this->ask=$this->db->query("
SELECT t.payment_date as '0',t.value as '2',t2.payment_date as '1',t.name,t.value,t.register_date FROM ecmtransactions t
inner join ecmtransactions_rel r on ( r.ecmtransaction_a_id=t.id or r.ecmtransaction_b_id=t.id)
inner join ecmtransactions t2 on
(case r.ecmtransaction_b_id when t.id then t2.id=r.ecmtransaction_a_id else t2.id=r.ecmtransaction_b_id end)
WHERE t.type='0'
AND t.register_date > '2011-12-31'
and t.settled=1
and t.payment_date < t2.payment_date and t.id='".$id."'
ORDER BY t.register_date desc");
$this->result=$this->db->fetchByAssoc($this->ask);
}
function createRecord($name,$value,$date,$date2){
$tmp=array();
$tmp['total']=0;
$tmp['days']=0;
for ($i = 0; $i < count($this->positions); $i++) {
$tmp['total']+=$this->positions[$i]['amount'];
$tmp['days']+=$this->positions[$i]['days'];
}
$tmp['from']=$this->positions[0]['date_from'];
$tmp['to']=$this->positions[count($this->positions)-1]['date_to'];
$tmp['payment_date']=$date2;
$tmp['date_doc']=date('d.m.Y',strtotime($date));
$tmp['name']=$name;
$tmp['paid']=$value;
$tmp['position']=$this->counter;
$this->counter++;
$this->notes[]=$tmp;
}
function createID(){
$this->uid=create_guid();
}
function updateRecord($id){
$this->db->query("update ecmtransactions set note=1, note_id='".$this->uid."' where id='".$id."'");
}
function makeNotes(){
$this->notes=array();
$this->json2array();
if(count($this->ids)>0){
$this->counter=0;
$this->createID();
foreach ($this->ids as $val){
$this->getDatesFromId($val);
$name=$this->result['name'];
$value=$this->result['value'];
$date=$this->result['register_date'];
$this->calculateRecordsToNote($this->result['0'],$this->result['1'],$this->result['2']);
$this->createRecord($name,$value,$date);
$this->updateRecord($val);
}
}
include 'modules/EcmPaymentStates/createPDF.php';
createEcmPaymentStatePdf($this->ids[0],'BROSWER',$this->notes,$this->uid);
}
function makeMonit($id,$t=false){
$this->notes=array();
$this->json2array2($id);
if(count($this->ids)>0){
$this->counter=0;
// $this->createID();
foreach ($this->ids as $val){
$this->getDatesMonitFromId($val);
$name=$this->result['name'];
$value=$this->result['value'];
$date=$this->result['register_date'];
$date2=date('d.m.Y',strtotime($this->result['payment_date']));
$this->calculateRecordsToNote($this->result['0'],date("Y-m-d"),$this->result['2']);
$this->createRecord($name,$value,$date,$date2);
// $this->updateRecord($val);
}
}
if($t==true){
$b='BROSWER';
} else {
$b='FILE';
}
include 'modules/EcmPaymentStates/createPDF.php';
return createEcmPaymentStatePdf2($this->ids[0],$b,$this->notes);
}
function checkPost($start,$end,$amount){
$_REQUEST['payment_date']=$start!='' ? $start : $_REQUEST['payment_date'];
$_REQUEST['payment_after_date']=$end!='' ? $end : $_REQUEST['payment_after_date'];
$_REQUEST['amount']=$amount!='' ? $amount : $_REQUEST['amount'];
}
function calculateRecordsToNote($start,$end,$amount){
$this->checkPost($start,$end,$amount);
$this->loadDates(false);
$this->checkDate($this->sdate);
$this->getInterestTable();
$this->calculateInterest();
return $this->positions;
}
function calculateRecords(){
$this->loadDates(true);
$this->checkDate($this->sdate);
$this->getInterestTable();
$this->calculateInterest();
return $this->positions;
}
function number_unformat($number, $force_number = true, $dec_point = '.', $thousands_sep = ',') {
if ($force_number) {
$number = preg_replace('/^[^\d]+/', '', $number);
} else if (preg_match('/^[^\d]+/', $number)) {
return false;
}
$type = (strpos($number, $dec_point) === false) ? 'int' : 'float';
$number = str_replace(array($dec_point, $thousands_sep), array('.', ''), $number);
settype($number, $type);
return $number;
}
function workingDayOfYear($timeStamp = null, $freeSaturdays = true, $extraFreeDays = array(), $extraWorkingDays = array())
{
$freeHolidayDays = 0;
$addWorkingDays = 0;
$timeStamp = is_null($extraFreeDays) ? time() : $extraFreeDays;
$firstDayOfYear = date('w', mktime(0,0,0,1,1,date('Y', $timeStamp)));
$dayOfYear = date('z', $timeStamp)+1;
$year = date('Y', $timeStamp);
$day = date('j', $timeStamp);
$mon = date('n', $timeStamp);
$easterDay = easter_date($year);
$extraWorkingDays = (array)$extraWorkingDays;
$extraFreeDays = (array)$extraFreeDays;
/*
od aktualnego tygonia roku odejmujemy 1
bo aktualny tydzien nie jest jeszcze zakonczony
*/
$passedWeekends = (int)date('W', $timeStamp)-1;
$freeWeekendDays= $passedWeekends;
/*
funkcja date('W') liczy tygonie w roku rozpoczynajac od poniedzialku
stad, jezeli 1 stycznia wypada w niedziele odejmujemy jeden tydzien
jezeli wypada pozniej niz w poniedzialek, dodajemy jeden tydzien
*/
if($firstDayOfYear == 0)
{ $passedWeekends--;
}
else if ($firstDayOfYear > 1)
{ $passedWeekends++;
}
/*
lista dni ustawowo wolnych od pracy wg.
Ustawa z dnia 18 stycznia 1951 r. o dniach wolnych od pracy.
(Dz.U. 1951 nr 4 poz. 28) z pozniejszymi zmianami
isip.sejm.gov.pl/servlet/Search?todo=file&id=WDU19510040028&type=3&name=D9510028.pdf
*/
$freeDaysArray = array(
mktime(0,0,0,1,1,$year), // nowy rok
mktime(0,0,0,1,6,$year), // trzech króli
$easterDay, // pierwszy dzien wielkiej nocy
$easterDay + 86400, // drugi dzien wielkiej nocy
mktime(0,0,0,5,1,$year), // 1 maja
mktime(0,0,0,5,3,$year), // 3 maja
$easterDay + (60*86400), // boze cialo
$easterDay + (49*86400), // zielone swiatki
mktime(0,0,0,8,15,$year), // 15 sierpnia
mktime(0,0,0,11,1,$year), // 1 listopada
mktime(0,0,0,11,11,$year), // 11 listopada
mktime(0,0,0,12,25,$year), // 25 grudnia
mktime(0,0,0,12,26,$year) // 26 grudnia
);
$weekDay = date('w', $extraFreeDays[0]);
$return2= array_search($extraFreeDays[0], $freeDaysArray);
if($weekDay == 0 || $weekDay == 6 || $return2){
return true;
} else {
return false;
}
}
}
?>

View File

@@ -0,0 +1,10 @@
<?php
/** Hi ho ooo :)
*
*/
include 'modules/EcmPaymentStates/interestController.php';
include 'modules/EcmPaymentStates/interestModel.php';
$controller = new interestController();
if (isset($_REQUEST['step'])) $controller->{$_REQUEST['step']}();
?>

View File

@@ -0,0 +1,19 @@
<?php
include_once("config.php");
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);
mysql_query("set character set utf8;");
$zap=mysql_query("select document_no,payment_date,id,pdf_total,parent_id from ecminvoiceouts where payment_date > '2011-12-31'
order by payment_date asc");
while($dane=mysql_fetch_assoc($zap)){
$check=mysql_query("select id,name from ecmtransactions where value='".$dane['pdf_total']."' and parent_id='".$dane['parent_id']."' and type=0");
echo $dane['document_no'].":<br>";
while($r=mysql_fetch_assoc($check)){
if($dane['document_no']!=$r['name'])echo $r['id']." ".$r['name']."<br>";
}
}
echo mysql_num_rows($zap);

View File

@@ -0,0 +1 @@
<?php require_once('modules/EcmPaymentStates/javascript/helper.php');

View File

@@ -0,0 +1,658 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('-1');
if (!$_POST['job'] || $_POST['job']=='') die ('-1');
switch ($_POST['job']) {
case 'getTransaction': getTransaction($_POST['id']); break;
case 'createRelation': createRelation($_POST['id'], $_POST['value'], $_POST['payment']); break;
case 'createRelationM': createRelationM($_POST['id'], $_POST['value'], $_POST['payment']); break;
case 'createRelationMany': createRelationMany($_POST['id'], $_POST['value'], $_POST['payment']); break;
case 'getDetails': getDetails($_POST['id']); break;
case 'createMonit': createMonit($_POST['ids'],$_POST['parent_id'],$_POST['email'],$_POST['text']); break;
case 'sendNote': sendNote($_POST['ids'],$_POST['parent_id']); break;
case 'sendSMS': sendSMS($_POST['number'],$_POST['content']); break;
case 'createCsvFile': createCsvFile($_POST['ids'],$_POST['bank']); break;
}
function sendSMS($number,$content){
$db=$GLOBALS['db'];
$EcmSysInfo = new EcmSysInfo();
if($EcmSysInfo->getDatabaseName() == 'saassystem'){
static $content2;
$params = array(
'username' => 'admin',
'api_key' => 'rudemodz',
'message' => $content,
'number' => $number
);
$params['message']=urldecode($content);
$params['to']=$number;
$url = 'http://damznac.pl/api/sendSms';
$c = curl_init();
curl_setopt( $c, CURLOPT_URL, $url );
curl_setopt( $c, CURLOPT_POST, true );
curl_setopt( $c, CURLOPT_POSTFIELDS, $params );
curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
$content2 = curl_exec( $c );
$http_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
if($http_status != 200){
echo $content2;
} else {
echo 'OK';
return;
}
curl_close( $c );
} else {
$query="select * from operating_values where value0='smsApi'";
$res=$db->query($query);
$dane= $db->fetchByAssoc($res);
static $content2;
$params = array(
'username' => $dane['value1'],
'password' => md5($dane['value2']),
'to' => '',
'from' => 'SMSAPI',
'eco' => 0,
'message' => "",
);
$params['message']=urldecode($content);
$params['to']=$number;
if($backup == true){
$url = 'https://api2.smsapi.pl/sms.do';
}else{
$url = 'https://api.smsapi.pl/sms.do';
}
$c = curl_init();
curl_setopt( $c, CURLOPT_URL, $url );
curl_setopt( $c, CURLOPT_POST, true );
curl_setopt( $c, CURLOPT_POSTFIELDS, $params );
curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
$content2 = curl_exec( $c );
$http_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
if($http_status != 200 && $backup == false){
$backup = true;
sms_send($params, $backup);
}
curl_close( $c );
}
return 'ok';
}
function createCsvFile($ids,$bank){
$przelewy=array();
foreach ($ids as $id){
$t = new EcmTransaction();
$t->retrieve($id);
$a = new Account();
$a->retrieve($t->parent_id);
if($a->getFirstBankAccount()!=''){
$przelewy[$t->parent_id]['value']+=$t->value;
$przelewy[$t->parent_id]['index']=str_replace("'","",htmlspecialchars_decode($a->index_dbf));
$przelewy[$t->parent_id]['parent_name']=str_replace("'","",htmlspecialchars_decode($t->parent_name));
$przelewy[$t->parent_id]['parent_name']=str_replace('"',"",$przelewy[$t->parent_id]['parent_name']);
$przelewy[$t->parent_id]['account']=$a->getFirstBankAccount();
$przelewy[$t->parent_id]['desc'].=$t->name.', ';
}
}
getBankFormat($bank,$przelewy);
}
function removeBadChars($name){
$chars=array('/','?','-',"'",'(',')','+',',','.','0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','ź','Ą','Ć','Ę','Ł','Ń','Ó','Ś','Ż','Ź'
,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','ą','ć','ę','ł','ń','ó','ś','ż','|',' '
);
$new=array();
for($i=0;$i<strlen($name);$i++){
foreach ($chars as $char){
if($char==$name[$i]){
$new[]=$name[$i];
}
}
}
return implode('',$new);
}
function createLineBGZ($line){
$name=removeBadChars($line['parent_name']);
$title=removeBadChars($line['desc']);
$title=substr($title,0,140);
if(strlen($name)>35){
$name=substr($name,0,35);
$line=';'.str_replace(' ','',$line['account']).';'.$name.';;;;'.$title.';'.str_replace('.',',',$line['value']).PHP_EOL;
} else {
$line=';'.str_replace(' ','',$line['account']).';'.$name.';;;;'.$title.';'.str_replace('.',',',$line['value']).PHP_EOL;
}
return $line;
}
function getBankFormat($id,$data){
global $current_user;
$fp=fopen('import_'.$current_user->id.'.csv','w');
if($id==1){
foreach ($data as $key=>$val){
if($val['value']!=''){
$line=createLineBGZ($val);
fwrite($fp,$line);
}
}
}
fclose($fp);
echo json_encode('import_'.$current_user->id.'.csv');
return;
return '';
}
function createRelationMany($id){
global $current_user;
$db=$GLOBALS['db'];
$ids=explode(',',$id);
$prawa=0;
$lewa_id=array();
$prawa_id=array();
$lewa=0;
foreach ($ids as $i){
$t = new EcmTransaction();
$t->retrieve($i);
if($t->value>0){
$lewa+=$t->value;
$tmp=array();
$tmp['id']=$t->id;
$tmp['value']=$t->value;
$tmp['left']=$t->getRelations();
$tmp['used']=0;
$lewa_id[]=$tmp;
} else {
$prawa+=$t->value;
$tmp=array();
$tmp['id']=$t->id;
$tmp['value']=$t->value;
$tmp['left']=$t->getRelations();
$tmp['used']=0;
$prawa_id[]=$tmp;
}
}
foreach ($prawa_id as $p=>$v){
foreach ($lewa_id as $l=>$v2){
if($prawa_id[$p]['used']==0 && $lewa_id[$l]['used']==0){
if($prawa_id[$p]['left']+$lewa_id[$l]['left']<=0){
echo $prawa_id[$p]['left']." ".$lewa_id[$l]['left']."\n";
if(round($prawa_id[$p]['left']+$lewa_id[$l]['left'],2)==0.00){
$prawa_id[$p]['used']=1;
$db->query("update ecmtransactions set settled=1 where id='".$prawa_id[$p]['id']."'");
echo "update ecmtransactions set settled=1 where id='".$prawa_id[$p]['id']."'\n";
}
$prawa_id[$p]['left']+=$lewa_id[$l]['left'];
$lewa_id[$l]['used']=1;
echo "Po operacji ".$prawa_id[$p]['left']."\n";
$db->query("update ecmtransactions set settled=1 where id='".$lewa_id[$l]['id']."'");
echo "update ecmtransactions set settled=1 where id='".$lewa_id[$l]['id']."'\n";
echo "
INSERT INTO ecmtransactions_rel VALUES (
'".create_guid()."',
'".date("Y-m-d H:i:s")."',
'".$current_user->id."',
'".$prawa_id[$p]['id']."',
'".$lewa_id[$l]['id']."',
'".abs($lewa_id[$l]['left'])."'
)
";
$db->query("
INSERT INTO ecmtransactions_rel VALUES (
'".create_guid()."',
'".date("Y-m-d H:i:s")."',
'".$current_user->id."',
'".$prawa_id[$p]['id']."',
'".$lewa_id[$l]['id']."',
'".abs($lewa_id[$l]['left'])."'
)
");
} else {
$lewa_id[$l]['left']+=$prawa_id[$p]['left'];
$prawa_id[$p]['left']+=abs($prawa_id[$p]['left']);
echo "po : ".$prawa_id[$p]['left']." ".$lewa_id[$l]['left']."\n";
$prawa_id[$p]['used']=1;
$db->query("update ecmtransactions set settled=1 where id='".$prawa_id[$p]['id']."'");
echo "update ecmtransactions set settled=1 where id='".$prawa_id[$p]['id']."'";
echo "
INSERT INTO ecmtransactions_rel VALUES (
'".create_guid()."',
'".date("Y-m-d H:i:s")."',
'".$current_user->id."',
'".$prawa_id[$p]['id']."',
'".$lewa_id[$l]['id']."',
'".abs($prawa_id[$p]['value'])."'
)";
$db->query("
INSERT INTO ecmtransactions_rel VALUES (
'".create_guid()."',
'".date("Y-m-d H:i:s")."',
'".$current_user->id."',
'".$prawa_id[$p]['id']."',
'".$lewa_id[$l]['id']."',
'".abs($prawa_id[$p]['value'])."'
)");
continue;
}
}
}
}
}
function sendNote($ids,$parent_id){
global $current_user;
$db=$GLOBALS['db'];
$uq=$db->query("select google_login,CAST(AES_DECRYPT(google_password, 'jakistamhash123') as CHAR)
AS google_password FROM users where id='".$current_user->id."'");
$rul=$db->fetchByAssoc($uq);
if($rul['google_login']!='' && $rul['google_password']!=''){
require_once ("modules/EcmPaymentStates/createPDF.php");
require_once ("include/phpmailer/class.phpmailer.php");
require_once ("include/phpmailer/class.smtp.php");
$mailClassS = new PHPMailer ();
$mailClassS->isSMTP (); // Set mailer to use SMTP
$mailClassS->Host = 'smtp.gmail.com'; // Specify main and backup server
$mailClassS->SMTPAuth = true; // Enable SMTP authentication
$mailClassS->Username = $rul['google_login']; // SMTP username
$mailClassS->Password = $rul['google_password']; // SMTP password
$mailClassS->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mailClassS->Port = 587; // Set the SMTP port number - 587 for
// get email from accounts
$sea = new SugarEmailAddress;
// Grab the array of addresses
$addresses = $sea->getAddressesByGUID($parent_id, 'Accounts');
foreach ( $addresses as $address ) {
if($address['email_address']!='' && $address['opt_out']==1){
$mailClassS->addAddress ($address['email_address']); // Add address
}
}
// set sender
$mailClassS->Sender=$rul['google_login'];
$mailClassS->From =$rul['google_login'];
$mailClassS->FromName =$current_user->first_name.' '.$current_user->last_name;
$mailClassS->WordWrap = 50; // Set word wrap to 50 characters
$mailClassS->isHTML ( true ); // Set email format to HTML
$mailClassS->Subject = 'Dokument od Saas SystemS Sp. z o.o.';
$path=createEcmPaymentStatePdf('null','FILE','null',$ids);
$mailClassS->Body = 'Witam,<br><br>Nota odsetkowa';
// załącznik
if(file_exists('/var/www/html/crm/'.$path)){
$mailClassS->addAttachment($path);
}
// Read an HTML message body from an external file, convert
// referenced images to embedded,
// convert HTML into a basic plain-text alternative body
// $mailClassS->msgHTML(file_get_contents('contents.html'),
// dirname(__FILE__));
if(count($mailClassS->to)>0){
if (! $mailClassS->send ()) {
unlink('/var/www/html/crm/'.$path);
echo '-1';
} else {
unlink('/var/www/html/crm/'.$path);
echo '1';
}
} else {
echo '-1';
}
} else {
echo '-1';
}
}
function createMonit($ids,$parent_id,$email_us,$text){
//ini_set('display_errors',1);
include 'modules/EcmPaymentStates/interestModel.php';
$m= new interestModel();
global $current_user;
$db=$GLOBALS['db'];
// require_once ("modules/EcmPaymentStates/createPDF.php");
require_once ("include/phpmailer/class.phpmailer.php");
require_once ("include/phpmailer/class.smtp.php");
$mailClassS = new PHPMailer ();
$mailClassS->isSMTP (); // Set mailer to use SMTP
require_once('modules/EcmSysInfos/EcmSysInfo.php');
$EcmSysInfo = new EcmSysInfo();
$email=$EcmSysInfo->getEmailSettings();
$cc=explode(':',$email['value1']);
if($email['value1']!='' && $email['value2']!='' && $email['value3']!=''){
global $sugar_config,$current_user;
$mailClassS->isSMTP (); // Set mailer to use SMTP
$mailClassS->Host = $cc[0]; // Specify main and backup server
$mailClassS->SMTPAuth = true; // Enable SMTP authentication
$mailClassS->Username = $email['value2'];
$mailClassS->Password = $email['value3'];
$mailClassS->SMTPSecure = $email['value5'];; // Enable encryption, 'ssl' also accepted
$mailClassS->Port = $cc[1]; // Set the SMTP port number - 587 for
if($email['value4']!=''){
$mailClassS->Sender=$email['value4'];
$mailClassS->From =$email['value4'];
if(!empty($email['value6'])){
$mailClassS->AddReplyTo($email['value6'],$EcmSysInfo->getName());
}
} else {
$mailClassS->Sender=$email['value2'];
$mailClassS->From =$email['value2'];
if(!empty($email['value6'])){
$mailClassS->AddReplyTo($email['value6'], $EcmSysInfo->getName());
}
}
$mailClassS->FromName =$EcmSysInfo->getName();
$mailClassS->WordWrap = 50; // Set word wrap to 50 characters
} else {
global $sugar_config,$current_user;
$mailClassS->isSMTP (); // Set mailer to use SMTP
$mailClassS->Host = $sugar_config['sendMail_host']; // Specify main and backup server
$mailClassS->SMTPAuth = true; // Enable SMTP authentication
$mailClassS->Username = $sugar_config['sendMail_username'];
$mailClassS->Password = $sugar_config['sendMail_password'];
$mailClassS->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mailClassS->Port = 587; // Set the SMTP port number - 587 for
$mailClassS->Sender=$sugar_config['sendMail_from'];
$mailClassS->From =$sugar_config['sendMail_from'];
$mailClassS->FromName =$EcmSysInfo->getName();
$mailClassS->WordWrap = 50; // Set word wrap to 50 characters
}
//$mailClassS->SMTPDebug=2;
// get email from accounts
$sea = new SugarEmailAddress;
// Grab the array of addresses
$addresses = $sea->getAddressesByGUID($parent_id, 'Accounts');
$found=0;
foreach( $addresses as $key=>$value){
if($value['email_address']==$email_us){
$found=1;
}
}
$email_num=count($addresses)+1;
$n='email'.$email_num;
if($found==0){
$acc= new Account ();
$acc->retrieve($parent_id);
$acc->$n=$email_us;
$acc->save();
}
// $mailClassS->addAddress ($addresses[0]['email_address']);
$mailClassS->addAddress ($email_us);
// set sender
// $mailClassS->WordWrap = 50; // Set word wrap to 50 characters
$mailClassS->isHTML ( true ); // Set email format to HTML
$mailClassS->Subject = 'Dokument od '.$EcmSysInfo->getName();
$mailClassS->Body = $text;
// załącznik
$path=$m->makeMonit($ids);
if(file_exists('/var/www/html/system/'.$path)){
$mailClassS->addAttachment($path);
}
// Read an HTML message body from an external file, convert
// referenced images to embedded,
// convert HTML into a basic plain-text alternative body
// $mailClassS->msgHTML(file_get_contents('contents.html'),
// dirname(__FILE__));
if(count($mailClassS->to)>0){
if (! $mailClassS->send ()) {
unlink('/var/www/html/system/'.$path);
echo '-1';
} else {
unlink('/var/www/html/system/'.$path);
echo '1';
}
} else {
echo '-1';
}
}
function getTransaction($id) {
if (!$id || $id == '') die('-1');
$db = $GLOBALS['db'];
$res = $db->fetchByAssoc($db->query("
SELECT t.id,t.name, t.value, sum(rel.value) as settled FROM ecmtransactions AS t
INNER JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE t.id='$id'
"));
if (!$res['settled']) $res['settled'] = 0;
echo json_encode($res);
return;
}
function createRelation($id, $value, $payment) {
$db = $GLOBALS['db'];
global $current_user;
$db->query("
INSERT INTO ecmtransactions_rel VALUES (
'".create_guid()."',
'".date("Y-m-d H:i:s")."',
'".$current_user->id."',
'$id',
'$payment',
'$value'
)
");
//check is settled
//winien
$res = $db->fetchByAssoc($db->query("
SELECT (t.value-sum(abs(rel.value))) as unsettled FROM ecmtransactions AS t
INNER JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE t.id='$id'
"));
echo 'WINIEN '.$row['unsettled'].'...';
if ($res['unsettled']==0)
$db->query("UPDATE ecmtransactions SET settled='1' WHERE id='$id'");
//ma
$res = $db->fetchByAssoc($db->query("
SELECT (t.value-sum(abs(rel.value))) as unsettled FROM ecmtransactions AS t
INNER JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE t.id='$payment'
"));
echo 'MA '.$row['unsettled'].'...';
if ($res['unsettled']==0)
$db->query("UPDATE ecmtransactions SET settled='1' WHERE id='$payment'");
echo '1';
return;
}
function createRelationM($id, $value, $payment) {
$db = $GLOBALS['db'];
global $current_user;
$db->query("
INSERT INTO ecmtransactions_rel VALUES (
'".create_guid()."',
'".date("Y-m-d H:i:s")."',
'".$current_user->id."',
'$id',
'$payment',
'$value'
)
");
//check is settled
//winien
if($value>0){
$res = $db->fetchByAssoc($db->query("
SELECT (abs(t.value)-sum(rel.value)) as unsettled FROM ecmtransactions AS t
INNER JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE t.id='$id'
"));
if ($res['unsettled']==0)
$db->query("UPDATE ecmtransactions SET settled='1' WHERE id='$id'");
//ma
$res = $db->fetchByAssoc($db->query("
SELECT (abs(t.value)-sum(rel.value)) as unsettled FROM ecmtransactions AS t
INNER JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE t.id='$payment'
"));
echo 'MA '.$row['unsettled'].'...';
if ($res['unsettled']==0)
$db->query("UPDATE ecmtransactions SET settled='1' WHERE id='$payment'");
} else {
$res = $db->fetchByAssoc($db->query("
SELECT (t.value-sum(rel.value)) as unsettled FROM ecmtransactions AS t
INNER JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE t.id='$id'
"));
if ($res['unsettled']==0)
$db->query("UPDATE ecmtransactions SET settled='1' WHERE id='$id'");
//ma
$res = $db->fetchByAssoc($db->query("
SELECT (abs(t.value)-sum(abs(rel.value))) as unsettled FROM ecmtransactions AS t
INNER JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE t.id='$payment'
"));
echo 'MA '.$row['unsettled'].'...';
if ($res['unsettled']==0)
$db->query("UPDATE ecmtransactions SET settled='1' WHERE id='$payment'");
}
echo '1';
return;
}
function getDetails($id) {
$db = $GLOBALS['db'];
$result = array();
$res = $db->query("
select t.id, t.name, rel.value from ecmtransactions_rel as rel
inner join ecmtransactions as t
on t.id = rel.ecmtransaction_a_id
where rel.ecmtransaction_b_id='$id'");
while ($row = $db->fetchByAssoc($res)) {
$row['value'] = format_number($row['value']);
$result[] = $row;
}
$res = $db->query("
select t.id, t.name, rel.value from ecmtransactions_rel as rel
inner join ecmtransactions as t
on t.id = rel.ecmtransaction_b_id
where rel.ecmtransaction_a_id='$id'");
while ($row = $db->fetchByAssoc($res)) {
$row['value'] = format_number($row['value']);
$result[] = $row;
}
$ss = new Sugar_Smarty();
$ss->assign("ID", $id);
$ss->assign("RES", $result);
echo $ss->display('modules/EcmPaymentStates/tpls/AccountPaymentStatesDetail.tpl');
return true;
}

View File

@@ -0,0 +1,127 @@
<?php
if (!$_REQUEST['job']) return -1;
switch ($_REQUEST['job']) {
case 'getDetails': getDetails($_REQUEST['id']); break;
}
function getDetails($id) {
//create & execute smarty
$ss = new Sugar_Smarty();
$ss->assign("ID", $id);
$ss->assign("D2", getData($id,2));
$ss->assign("D3", getData($id,3));
$ss->assign("D4", getData($id,4));
$ss->assign("D5", getData($id,5));
$ss->assign("D6", getData($id,6));
$ss->assign("D8", getData($id,8));
$ss->assign("D9", getData($id,9));
$ss->assign("D10", getData($id,10));
echo $ss->display('modules/EcmPaymentStates/tpls/summaryDetail.tpl');
return true;
}
function getData($id, $expired) {
$db = $GLOBALS ['db'];
switch ($expired) {
case 2 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-30 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date BETWEEN '$d_f' AND '$d_t'";
break;
case 3 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-31 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-60 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date BETWEEN '$d_f' AND '$d_t'";
break;
case 4 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-61 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-90 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date BETWEEN '$d_f' AND '$d_t'";
break;
case 5 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-91 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-180 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date BETWEEN '$d_f' AND '$d_t'";
break;
case 6 :
$date = new DateTime ( date ( "Y-m-d" ) );
$date->modify ( '-181 days' );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date < '$d'";
break;
case 8 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '+30 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date BETWEEN '$d_t' AND '$d_f'";
break;
case 9 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '+31 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '+60 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date BETWEEN '$d_t' AND '$d_f'";
break;
case 10 :
$date = new DateTime ( date ( "Y-m-d" ) );
$date->modify ( '+61 days');
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d'";
break;
}
$res = $db->query ( "
SELECT
id, name, value, currency_id
FROM ecmtransactions
WHERE
record_type='EcmInvoiceOuts' AND
parent_id = '$id' AND
deleted='0' AND
(settled!='1' OR settled IS NULL) AND
register_date > '2011-12-31' AND
" . $payment_date . "
ORDER BY value DESC
" );
$return = array();
while ($r = $db->fetchByAssoc($res)) {
//search settled
$s = $db->fetchByAssoc($db->query("SELECT sum(value) as settled FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'"));
$r['value'] = format_number($r['value']);
if (!is_numeric($s['settled'])) $s['settled'] = 0;
$r['settled'] = format_number($s['settled']);
if ($r['currency_id']!='PLN' || $r['currency_id']=='' || !$r['currency_id']) {
$c = new Currency;
$c->retrieve($r['currency_id']);
$r['value'].='&nbsp;('.$c->iso4217.')';
}
$return[] = $r;
}
return $return;
}

View File

@@ -0,0 +1,242 @@
<?
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&nott_matched=0&account_name='.$r['parent_name'].'&account_id='.$r['parent_id'].'&button=Search">'.str_replace("<","&lt;",str_replace(">","&gt;",$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("<","&lt;",str_replace(">","&gt;",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;
?>

View File

@@ -0,0 +1,111 @@
<?php
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
die ( 'Not A Valid Entry Point' );
/**
* *******************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc.
* Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
* ******************************************************************************
*/
/**
* *******************************************************************************
*
* Description: Defines the English language pack for the base application.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
* Contributor(s): ______________________________________..
* ******************************************************************************
*/
$mod_strings = array (
// begin: for summary
'LBL_SUMMARY_TITLE' => 'PaymentStates: Summary',
'LBL_SUMMARY_ACCOUNT' => 'Account',
'LBL_SUMMARY_UNSETTLED' => 'Unsettled',
'LBL_SUMMARY_NOT_OVERDUE' => 'Not overdue',
'LBL_SUMMARY_NOT_OVERDUE_1_30' => '30..1',
'LBL_SUMMARY_NOT_OVERDUE_31_60' => '60..31',
'LBL_SUMMARY_NOT_OVERDUE_61' => '..61',
'LBL_SUMMARY_OVERDUE' => 'Overdue',
'LBL_SUMMARY_OVERDUE_1_30' => '1..30',
'LBL_SUMMARY_OVERDUE_31_60' => '31..60',
'LBL_SUMMARY_OVERDUE_61_90' => '61..90',
'LBL_SUMMARY_OVERDUE_91_180' => '91..180',
'LBL_SUMMARY_OVERDUE_181' => '181..',
// end: for summary
//begin: for AccountPaymentStates
'LBL_ACCOUNTPAYMENTSTATES' => 'PaymentStates: Account view',
'LBL_ACCOUNT_NAME' => 'Account',
'LBL_PAYMENT_DATE' => 'Payment date',
'LBL_DATE' => 'Date',
'LBL_NAME' => 'Name',
'LBL_VALUE' => 'Value',
'LBL_DOCUMENT_NO' => 'Document number',
'LBL_UNSETTLED' => 'Unsettled',
'LBL_SETTLED' => 'Settled',
'LBL_SHOW_SETTLED' => 'Show settled transactions',
//end: for AccountPaymentStates
'LNK_ECMPAYMENTSTATE_SUMMARY' => 'Summary',
'LBL_ASSIGNED_TO_ID' => 'Assigned To',
'LBL_VALUE' => 'Value',
'LBL_MODULE_NAME' => 'Payments States2',
'LBL_MODULE_TITLE' => 'Payments States2: Home',
'LBL_MODULE_ID' => 'Payments States2',
'LBL_SEARCH_FORM_TITLE' => 'Payments States Search',
'LBL_LIST_FORM_TITLE' => 'Payments States List',
'LBL_NEW_FORM_TITLE' => 'New Payments States',
'LBL_SUBJECT' => 'Subject:',
'LBL_ECMPAYMENTSTATE' => 'Payments States:',
'LBL_ECMPAYMENTSTATE_SUBJECT' => 'Payments States Subject:',
'LBL_LIST_SUBJECT' => 'Name',
'LBL_LIST_LAST_MODIFIED' => 'Last Modified',
'LNK_NEW_ECMPAYMENTSTATE' => 'Create Payments States',
'LNK_ECMPAYMENTSTATE_LIST' => 'Payments States',
'ERR_DELETE_RECORD' => 'You must specify a record number in order to delete the vat.',
'LBL_LIST_MY_ECMPAYMENTSTATES' => 'My Assigned Payments States',
'LBL_CREATED_BY' => 'Created by:',
'LBL_DATE_CREATED' => 'Create Date:',
'LBL_MODIFIED_BY' => 'Last Modified by:',
'LBL_DATE_LAST_MODIFIED' => 'Modify Date:',
'LBL_DEFAULT_SUBPANEL_TITLE' => 'Payments States',
'LBL_SYSTEM_ID' => 'System ID',
'LBL_LIST_ASSIGNED_TO_NAME' => 'Assigned User',
'LBL_LIST_VALUE' => 'Value',
'LBL_ASSIGNED_TO_NAME' => 'Assigned to'
)
;
?>

View File

@@ -0,0 +1,79 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Description: Defines the English language pack for the base application.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
* Contributor(s): ______________________________________..
********************************************************************************/
$mod_strings = array (
'LBL_ASSIGNED_TO_ID' => 'Assigned To',
'LBL_VALUE' => 'Value',
'LBL_MODULE_NAME' => 'Vat',
'LBL_MODULE_TITLE' => 'Vat: Home',
'LBL_MODULE_ID' => 'Vat',
'LBL_SEARCH_FORM_TITLE' => 'Vat Search',
'LBL_LIST_FORM_TITLE' => 'Vat List',
'LBL_NEW_FORM_TITLE' => 'New Vat',
'LBL_SUBJECT' => 'Subject:',
'LBL_ECMPAYMENTSTATE' => 'Vat:',
'LBL_ECMPAYMENTSTATE_SUBJECT' => 'Vat Subject:',
'LBL_LIST_SUBJECT' => 'Name',
'LBL_LIST_LAST_MODIFIED' => 'Last Modified',
'LNK_NEW_ECMPAYMENTSTATE' => 'Create Vat',
'LNK_ECMPAYMENTSTATE_LIST' => 'Vat',
'ERR_DELETE_RECORD' => 'You must specify a record number in order to delete the vat.',
'LBL_LIST_MY_ECMPAYMENTSTATES' => 'My Assigned Vat',
'LBL_CREATED_BY' => 'Created by:',
'LBL_DATE_CREATED' => 'Create Date:',
'LBL_MODIFIED_BY' => 'Last Modified by:',
'LBL_DATE_LAST_MODIFIED' => 'Modify Date:',
'LBL_DEFAULT_SUBPANEL_TITLE' => 'Vat',
'LBL_SYSTEM_ID' => 'System ID',
'LBL_LIST_ASSIGNED_TO_NAME' => 'Assigned User',
'LBL_LIST_VALUE' => 'Value',
'LBL_ASSIGNED_TO_NAME' => 'Assigned to',
);
?>

View File

@@ -0,0 +1,127 @@
<?php
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
die ( 'Not A Valid Entry Point' );
/**
* *******************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc.
* Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
* ******************************************************************************
*/
/**
* *******************************************************************************
*
* Description: Defines the English language pack for the base application.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
* Contributor(s): ______________________________________..
* ******************************************************************************
*/
$mod_strings = array (
// begin: for summary
'LBL_SUMMARY_TITLE' => 'Rozrachunki: Podsumowanie',
'LBL_SUMMARY_ACCOUNT' => 'Kontrahent',
'LBL_SUMMARY_UNSETTLED' => 'Nierozliczone',
'LBL_SUMMARY_NOT_OVERDUE' => 'Nieprzeterminowane',
'LBL_SUMMARY_NOT_OVERDUE_1_30' => '30..1',
'LBL_SUMMARY_NOT_OVERDUE_31_60' => '60..31',
'LBL_SUMMARY_NOT_OVERDUE_61' => '..61',
'LBL_SUMMARY_OVERDUE' => 'Przeterminowane',
'LBL_SUMMARY_OVERDUE_1_30' => '1..30',
'LBL_SUMMARY_OVERDUE_31_60' => '31..60',
'LBL_SUMMARY_OVERDUE_61_90' => '61..90',
'LBL_SUMMARY_OVERDUE_91_180' => '91..180',
'LBL_SUMMARY_OVERDUE_181' => '181..',
// end: for summary
// begin: for AccountPaymentStates
'LBL_ACCOUNTPAYMENTSTATES' => 'Rozrachunki: widok kontrahenta',
'LBL_ACCOUNT_NAME' => 'Kontrahent',
'LBL_PAYMENT_DATE' => 'Data płatości',
'LBL_DATE' => 'Data',
'LBL_NAME' => 'Nazwa',
'LBL_VALUE' => 'Wartość',
'LBL_DOCUMENT_NO' => 'Numer dokumentu',
'LBL_UNSETTLED' => 'Nie rozl.',
'LBL_SETTLED' => 'Rozliczone',
'LBL_SHOW_SETTLED' => 'Pokaż transakcje rozliczone',
// end: for AccountPaymentStates
'LNK_ECMPAYMENTSTATE_SUMMARY' => 'Salda',
'LBL_ASSIGNED_TO_ID' => 'Przypisane Do',
'LBL_VALUE' => 'Wartość',
'LBL_MODULE_NAME' => 'Rozrachunki2',
'LBL_MODULE_TITLE' => 'Rozrachunki: STrona Główna2',
'LBL_MODULE_ID' => 'Rozrachunki2',
'LBL_SEARCH_FORM_TITLE' => 'Rozrachunki Wyszukiwanie',
'LBL_LIST_FORM_TITLE' => 'Lista Stawek Vat',
'LBL_NEW_FORM_TITLE' => 'Nowa Stawka Vat',
'LBL_SUBJECT' => 'Tytuł:',
'LBL_ECMPAYMENTSTATE' => 'Stawka Vat:',
'LBL_ECMPAYMENTSTATE_SUBJECT' => 'Nazwa Rozrachunki:',
'LBL_LIST_SUBJECT' => 'Nazwa',
'LBL_LIST_LAST_MODIFIED' => 'Ostatnia Modyfikacja',
'LNK_NEW_ECMPAYMENTSTATE' => 'Utwórz Stawkę Vat',
'LNK_ECMPAYMENTSTATE_LIST' => 'Rozrachunki',
'ERR_DELETE_RECORD' => 'Podaj numer rekordu aby usunąć stawkę vat.',
'LBL_LIST_MY_ECMPAYMENTSTATES' => 'Moje Przypisane Rozrachunki',
'LBL_CREATED_BY' => 'Utworzone Przez:',
'LBL_DATE_CREATED' => 'Data Utworzenia:',
'LBL_MODIFIED_BY' => 'Ostatnio Modyfikowane Przez:',
'LBL_DATE_LAST_MODIFIED' => 'Data Modyfikacji:',
'LBL_DEFAULT_SUBPANEL_TITLE' => 'Rozrachunki',
'LBL_SYSTEM_ID' => 'System ID',
'LBL_LIST_ASSIGNED_TO_NAME' => 'Przypisany Użytkownik',
'LBL_LIST_VALUE' => 'Wartość',
'LBL_ASSIGNED_TO_NAME' => 'Przypisane Do',
// TABELA odsetek
'LBL_INTERESTTABLE'=>'Tabela odsetek',
'LBL_INTERESTTABLE_INFO'=>'Warunki odsetek do transakcji',
'LBL_INTEREST_CALC'=>'Kalkulator odsetek',
'LBL_INTEREST_PAYMENT_TERM'=>'Termin zapłaty',
'LBL_INTEREST_AMOUNT'=>'Uiszczenie zapłaty',
'LBL_INTEREST_AFTER_PAID'=>'Kwota zaległości',
'LBL_AFER_P'=>"Rozliczone po terminie",
'LBL_SHOW_SETTLED_ON' => 'Pokaż rozliczone',
'LBL_SHOW_SETTLED_OFF' => 'Ukryj rozliczone',
'LBL_SHOW_ALL_ON' => 'Pokaż wszystkie',
'LBL_SHOW_NOT_SETTLED_ON' => 'Pokaż nierozliczone',
'LBL_SHOW_NOT_SETTLED_OFF' => 'Ukryj nierozliczone',
'LBL_SHOW_ALL_OFF' => 'Ukryj wszystkie',
'LBL_AFER_P_ON' => 'Pokaż rozliczone po terminie',
'LBL_AFER_P_OFF' => 'Ukryj rozliczone po terminie',
'LBL_AFER_T_OFF' => 'Ukryj nierozliczone po terminie',
'LBL_AFER_T_ON' => 'Pokaż nierozliczone po terminie',
);
?>

View File

@@ -0,0 +1,5 @@
<?php
include 'modules/EcmPaymentStates/interestModel.php';
$m= new interestModel();
$path=$m->makeMonit($_REQUEST['aa'],true);
?>

View File

@@ -0,0 +1,44 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
$searchFields['EcmPaymentStates'] =
array (
'name' => array( 'query_type'=>'default'),
'value' => array( 'query_type'=>'default'),
'current_user_only'=> array('query_type'=>'default','db_field'=>array('assigned_user_id'),'my_items'=>true),
'assigned_user_id'=> array('query_type'=>'default'),
);
?>

View File

@@ -0,0 +1,64 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*********************************************************************************/
require_once('include/utils.php');
function additionalDetailsEcmPaymentState($fields) {
static $mod_strings;
global $app_strings;
if(empty($mod_strings)) {
global $current_language;
$mod_strings = return_module_language($current_language, 'EcmPaymentStates');
}
$overlib_string = '';
if(!empty($fields['DATE_ENTERED']))
$overlib_string .= '<b>'. $app_strings['LBL_DATE_ENTERED'] . '</b> ' . $fields['DATE_ENTERED'] . '<br>';
if(!empty($fields['NAME']))
$overlib_string .= '<b>'. $mod_strings['LBL_NAME'] . '</b> ' . $fields['NAME'] . '<br>';
return array('fieldToAddTo' => 'NAME',
'string' => $overlib_string,
'editLink' => "index.php?action=EditView&module=EcmPaymentStates&return_module=EcmPaymentStates&record={$fields['ID']}",
'viewLink' => "index.php?action=DetailView&module=EcmPaymentStates&return_module=EcmPaymentStates&record={$fields['ID']}");
}
?>

View File

@@ -0,0 +1,67 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
$viewdefs['EcmPaymentStates']['DetailView'] = array(
'templateMeta'=>array(
'form'=>array(
'buttons'=>array(
'EDIT',
'DUPLICATE',
'DELETE',
)
),
'maxColumns'=>'2',
'widths'=>array(
array(
'label'=>'10',
'field' =>'30'
),
array(
'label'=>'10',
'field'=>'30'
)
),
),
'panels'=>array(
array(
'name',
'assigned_user_name',
),
array(
'value',
),
)
);
?>

View File

@@ -0,0 +1,52 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
$viewdefs['EcmPaymentStates']['EditView'] = array(
'templateMeta'=>array(
'form' => array('buttons'=>array('SAVE', 'CANCEL')),
'maxColumns'=>'2',
'widths'=>array(
array('label'=>'10','field'=>'30'),
array('label'=>'10','field'=>'30'),
),
),
'panels'=>array(
'default'=>array(
array('name','assigned_user_name'),
array('value'),
),
),
);
?>

View File

@@ -0,0 +1,56 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
$listViewDefs['EcmPaymentStates'] = array(
'NAME' => array(
'width' => '32',
'label' => 'LBL_LIST_SUBJECT',
'default' => true,
'link' => true),
'VALUE' => array(
'width' => '10',
'label' => 'LBL_LIST_VALUE',
'default' => true),
'ASSIGNED_USER_NAME' => array(
'width' => '9',
'label' => 'LBL_LIST_ASSIGNED_USER',
'default' => true)
);
?>

View File

@@ -0,0 +1,51 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*
* Created on Jun 1, 2007
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
$metafiles['EcmPaymentStates'] = array(
'detailviewdefs' => 'modules/EcmPaymentStates/metadata/detailviewdefs.php',
'editviewdefs' => 'modules/EcmPaymentStates/metadata/editviewdefs.php',
'listviewdefs' => 'modules/EcmPaymentStates/metadata/listviewdefs.php',
'searchdefs' => 'modules/EcmPaymentStates/metadata/searchdefs.php',
'popupdefs' => 'modules/EcmPaymentStates/metadata/popupdefs.php',
'searchfields' => 'modules/EcmPaymentStates/metadata/SearchFields.php',
);
?>

View File

@@ -0,0 +1,67 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
$popupMeta = array('moduleMain' => 'EcmPaymentState',
'varName' => 'ECMPAYMENTSTATE',
'orderBy' => 'ecmpaymentstates.name',
'whereClauses' =>
array('name' => 'ecmpaymentstates.name'),
'listviewdefs' => array(
'NAME' => array(
'width' => '32',
'label' => 'LBL_LIST_SUBJECT',
'default' => true,
'link' => true),
'VALUE' => array(
'width' => '10',
'label' => 'LBL_LIST_VALUE',
'default' => true),
'ASSIGNED_USER_NAME' => array(
'width' => '9',
'label' => 'LBL_LIST_ASSIGNED_USER',
'default' => true)
),
'searchdefs' => array(
'name',
'value',
array('name' => 'assigned_user_id', 'type' => 'enum', 'label' => 'LBL_ASSIGNED_TO', 'function' => array('name' => 'get_user_array', 'params' => array(false))),
)
);
?>

View File

@@ -0,0 +1,59 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*
* Created on May 29, 2007
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
$searchdefs['EcmPaymentStates'] = array(
'templateMeta' => array(
'maxColumns' => '3',
'widths' => array('label' => '10', 'field' => '30'),
),
'layout' => array(
'basic_search' => array(
'name',
array('name'=>'current_user_only', 'label'=>'LBL_CURRENT_USER_FILTER', 'type'=>'bool'),
),
'advanced_search' => array(
'name',
'value',
array('name' => 'assigned_user_id', 'type' => 'enum', 'label' => 'LBL_ASSIGNED_TO', 'function' => array('name' => 'get_user_array', 'params' => array(false))),
),
),
);
?>

View File

@@ -0,0 +1,65 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
$GLOBALS['studioDefs']['EcmPaymentStates'] = array(
'LBL_DETAILVIEW'=>array(
'template'=>'xtpl',
'template_file'=>'modules/EcmPaymentStates/DetailView.html',
'php_file'=>'modules/EcmPaymentStates/DetailView.php',
'type'=>'DetailView',
),
'LBL_EDITVIEW'=>array(
'template'=>'xtpl',
'template_file'=>'modules/EcmPaymentStates/EditView.html',
'php_file'=>'modules/EcmPaymentStates/EditView.php',
'type'=>'EditView',
),
'LBL_LISTVIEW'=>array(
'template'=>'listview',
'meta_file'=>'modules/EcmPaymentStates/listviewdefs.php',
'type'=>'ListView',
),
'LBL_SEARCHFORM'=>array(
'template'=>'xtpl',
'template_file'=>'modules/EcmPaymentStates/SearchForm.html',
'php_file'=>'modules/EcmPaymentStates/ListView.php',
'type'=>'SearchForm',
),
);

View File

@@ -0,0 +1,42 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* Layout definition for EcmPaymentStates
*
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
$layout_defs['EcmPaymentStates']['subpanel_setup'] = array(
);
?>

View File

@@ -0,0 +1,91 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* Subpanel Layout definition for EcmPaymentStates
*
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
$subpanel_layout = array(
'top_buttons' => array(
array('widget_class' => 'SubPanelTopCreateButton'),
array('widget_class' => 'SubPanelTopSelectButton', 'popup_module' => 'EcmPaymentStates'),
),
'where' => '',
'list_fields' => array(
'ecmpaymentstate_number'=>array(
'vname' => 'LBL_LIST_NUMBER',
'width' => '5%',
),
'name'=>array(
'vname' => 'LBL_LIST_SUBJECT',
'widget_class' => 'SubPanelDetailViewLink',
'width' => '50%',
),
'status'=>array(
'vname' => 'LBL_LIST_STATUS',
'width' => '15%',
),
'type'=>array(
'vname' => 'LBL_LIST_TYPE',
'width' => '15%',
),
'priority'=>array(
'vname' => 'LBL_LIST_PRIORITY',
'width' => '11%',
),
'assigned_user_name' => array (
'name' => 'assigned_user_name',
'vname' => 'LBL_LIST_ASSIGNED_TO_NAME',
),
'edit_button'=>array(
'widget_class' => 'SubPanelEditButton',
'module' => 'EcmPaymentStates',
'width' => '4%',
),
'remove_button'=>array(
'widget_class' => 'SubPanelRemoveButton',
'module' => 'EcmPaymentStates',
'width' => '5%',
),
),
);
?>

View File

@@ -0,0 +1,48 @@
<?php
//add jquery
echo '<link rel="stylesheet" type="text/css" href="include/jQuery/jquery-table/jquery.appendGrid-1.3.1.css"/>';
echo '<link rel="stylesheet" type="text/css" href="include/jQuery/jquery-ui/themes/base/jquery-ui.css"/>';
echo '<script type="text/javascript"
src="include/jQuery/jquery-2.1.0.min.js"></script>';
echo '<script type="text/javascript"
src="include/jQuery/jquery-table/jquery.appendGrid-1.3.1.js"></script>';
echo '<script type="text/javascript"
src="include/jQuery/jquery-ui/ui/jquery-ui.js"></script>';
//create data arrays
$left = explode("|", rtrim($_REQUEST['inv'],"|"));
$right = explode("|", rtrim($_REQUEST['pay'],"|"));
//draw main table
$a = new Account();
$a->retrieve($_REQUEST['account_id']);
$html = '<h1>'.$a->name.'</h1><br><table style="border: 1 px solid; width: 100%;">';
unset($a);
$html .= '<tr><td style="width: 50%;">Lewa<table id="left_site" style="width: 100%;"></table><div id="left_drop" style="width:100%; border: 2px dashed red;">&nbsp;<br>&nbsp;</div></td><td>Prawa<table id="right_site" style="width: 100%"></table><div id="right_drop" style="width:100%; border: 2px dashed green;">&nbsp;<br>&nbsp;</div></td></tr>';
$html .= '<tr><td colspan="2" style="width: 100%;"><br><br></td></tr>';
$html .= '<tr><td valign="top" align="center">';
foreach ($left as $v) {
$html.='<div id="draggable_'.$v.'" class="ui-widget-content" style="width: 90%; height: 30px; border: 1px dashed blue;"><p>'.getTransactionRow($v).'</p></div>';
}
$html.= '</td><td valign="top" align="center">';
foreach ($right as $v) {
$html.='<div id="draggable_'.$v.'" class="ui-widget-content" style="width: 90%; height: 30px; border: 1px dashed blue;"><p>'.getTransactionRow($v).'</p></div>';
}
$html.='</td></tr>';
$html.= '</table>';
//create jQuery functions
$html.='
<script src="modules/EcmPaymentStates/javascript/multiMatch.js"></script>
';
echo $html;
function getTransactionRow($id) {
$t = new EcmTransaction();
$t->retrieve($id);
$ret = '<table style="width: 100%"><tr><td style="width: 100px;"><p id="name">'.$t->name.'</p></td><td style="width: 15px;"><p id="date">'.$t->payment_date.'</p></td><td style="width: 15px;">'.$t->value.'</td><td style="width: 15px;"><input disabled type="text" value="'.$t->value.'"/></td></tr></table>';
unset($t);
return $ret;
}
?>

View File

@@ -0,0 +1,26 @@
<?php
/*
* Import danych z ecmpayments2_ecminvoiceouts do ecmtransactions_rel
* przy wdrażaniu nowych rozrachunków
*
* MZ
* 2014-08-29
*
*/
$db = $GLOBALS['db'];
$res = $db->query("SELECT pi.*, t.value FROM ecmpayments2_ecminvoiceouts as pi
INNER JOIN ecmtransactions as t ON t.id = pi.ecminvoiceout_id WHERE pi.deleted='0'");
while ($r = $db->fetchByAssoc($res)) {
if (is_null($r['ecmpayment_id']) || $r[ecmpayment_id]=='' || is_null($r['ecminvoiceout_id']) || $r['ecminvoiceout_id']=='') {
continue;
}
global $current_user;
$q="INSERT INTO ecmtransactions_rel VALUES ('".create_guid()."','".date('Y-m-d H:i:s')."',
'".$current_user->id."', '".$r['ecmpayment_id']."', '".$r['ecminvoiceout_id']."', '".$r['value']."')";
$db->query($q);
}
?>

33
modules/EcmPaymentStates/nm.php Executable file
View File

@@ -0,0 +1,33 @@
<?php
$sql=mysql_connect("localhost","e5crm.more7.com","5z#JaL");
mysql_select_db("e5crm_more7_com");
$w=$GLOBALS['db']->query("select distinct ee_id,ecmpayment_id from ecmpayments_ecminvoiceouts_rel");
$arr=array();
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if(in_array($r['ee_id'],$arr))continue;
if(in_array($r['ecmpayment_id'],$arr))continue;
$p=array();
$e=array();
$total_ee=0;
$total_p=0;
$ww=$GLOBALS['db']->query("select ecmpayment_id from ecmpayments_ecminvoiceouts_rel where ee_id='".$r['ee_id']."'");
while($rr=$GLOBALS['db']->fetchByAssoc($ww)){
$p[]="id='".$rr['ecmpayment_id']."'";
}
$ww=$GLOBALS['db']->query("select ee_id from ecmpayments_ecminvoiceouts_rel where ecmpayment_id='".$r['ecmpayment_id']."'");
while($rr=$GLOBALS['db']->fetchByAssoc($ww)){
$e[]="id='".$rr['ee_id']."'";
}
$e[]="id='".$r['ee_id']."'";
$p[]="id='".$r['ecmpayment_id']."'";
$ww=$GLOBALS['db']->query("select date_entered,total from ecmpayments_ecminvoiceouts where ".implode(" or ",$e));
while($rr=$GLOBALS['db']->fetchByAssoc($ww))$total_ee+=(float)$rr['total'];
$ww=$GLOBALS['db']->query("select date_entered,value from ecmpayments where ".implode(" or ",$p));
while($rr=$GLOBALS['db']->fetchByAssoc($ww)){$datee=$rr['date_entered'];$total_p+=(float)$rr['value'];}
if(round(($total_ee-$total_p),2)<0 || round(($total_ee-$total_p),2)>0)
echo $datee." ".$total_ee."-".$total_p."=".round(($total_ee-$total_p),2)."\n";
}
echo $total;
mysql_close($sql);
?>

View File

@@ -0,0 +1,496 @@
<?php
// helper functions
function getData2($id, $expired) {
$db = $GLOBALS ['db'];
$saldo = false;
$settled = " t.settled!='1' AND ";
switch ($expired) {
case 1 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
break;
case 2 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-30 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date < '$d_t'";
break;
case 3 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-31 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-60 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date <= '$d_t'";
break;
case 4 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-61 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-90 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date <= '$d_t'";
break;
case 5 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-91 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-180 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date <= '$d_t'";
break;
case 6 :
$date = new DateTime ( date ( "Y-m-d" ) );
$date->modify ( '-181 days' );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
break;
case 9:
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
$settled = " ";
$saldo = true;
break;
}
//start WINIEN
if($_REQUEST['account_type']=='rec')$typ=0;else $typ=1;
$zap= $db->query ( "
SELECT
(
t.value
) AS value,t.id
FROM ecmtransactions AS t
left JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='0' AND
" . $payment_date . " group by t.id
" );
$suma=0;
$total_settled=0;
while($r = $db->fetchByAssoc ($zap)){
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransansactions WHERE id='$rel_id'"));
if($t['deleted']==1)continue;
$tmp2 = array();
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp['settled_with'][] = $tmp2;
if($t['type']==0){
if($r['value']<0 && $rr['value']<0){
$total_settled+=abs(floatval($rr['value']));
} else {
$total_settled+=floatval($rr['value']);
}
} else {
$total_settled+=abs(floatval($rr['value']));
}
}
$suma+=$r['value'];
}
$zap= $db->query ( "
SELECT
(
t.value
) AS value,t.id
FROM ecmtransactions AS t
left JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='1' AND
" . $payment_date . " group by t.id
" );
$suma2=0;
$total_settled2=0;
while($r = $db->fetchByAssoc ($zap)){
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransansactions WHERE id='$rel_id'"));
$tmp2 = array();
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp['settled_with'][] = $tmp2;
$total_settled2+=floatval($rr['value']);
}
$suma2+=$r['value'];
}
return $total_settled-$suma+$suma2-$total_settled2;
return $total_settled-$suma;
}
function getData($id, $expired) {
$db = $GLOBALS ['db'];
$saldo = false;
$settled = " t.settled!='1' AND ";
switch ($expired) {
case 0 :
$payment_date = "1=1";
break;
case 1 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
$saldo=true;
break;
case 2 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-30 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 3 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-31 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-60 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 4 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-61 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-90 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 5 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-91 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-180 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 6 :
$date = new DateTime ( date ( "Y-m-d" ) );
$date->modify ( '-181 days' );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date < '$d'";
break;
case 7 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d'";
break;
case 8 :
$payment_date = " 1=1 ";
$saldo = true;
$settled = " 1=1 and";
break;
case 9:
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
$settled = " 1=1 AND ";
$saldo = true;
break;
}
//start WINIEN
$r = $db->fetchByAssoc ( $db->query ( "
SELECT
sum(
t.value
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='1' AND
" . $payment_date . "
" ) );
//get part settled transactions
/*
if (!$saldo){
$s = $db->fetchByAssoc($db->query("
SELECT
sum(
CASE WHEN t.currency_id='PLN' THEN t.value
ELSE t.value*t.currency_value
END
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='0' AND
t.register_date > '2011-12-31' AND
" . $payment_date . "
"));
}
*/
if (!$saldo){
return $r['sum'];
}
if (! is_numeric ( $r ['sum'] ))
$r ['sum'] = 0;
if (! is_numeric ( $s ['settled'] ))
$s ['settled'] = 0;
if (floatval($s['settled']) > 0)
$r['sum'] = floatval($r['sum']) - floatval($s['settled']);
$sum = $r['sum'];
//END WINIEN
$r['sum'] = 0;
if ($saldo) {
$r = $db->fetchByAssoc ( $db->query ( "
SELECT
sum(
t.value
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='0' AND
" . $payment_date . "
" ) );
}
$res=$sum - $r ['sum'];
if($expired==1 && $res>0){
return 0;
}
//END MA
return $res;
}
$id=array();
$ids=explode(',',$_REQUEST['idToPdf']);
foreach ($ids as $key){
if($ids[$key]!=''){
$id=$ids[$key];
}
}
$db=$GLOBALS['db'];
$zap=$db->query("
select
a.name,
a.id,
a.index_dbf,
a.currency_id as wal,
(sum(CASE
WHEN t.type = 1 THEN t.value else 0
END)-
sum(CASE
WHEN t.type = 0 THEN t.value else 0
END)) as saldo,
(sum(CASE
WHEN t.type = 1 and t.settled!=1 THEN t.value else 0
END)-
sum(CASE
WHEN t.type = 0 and t.settled!=1 THEN t.value else 0
END)) as zaleglosc,t2.name as name2,t2.value,t2.payment_date,t2.type
from
accounts a
inner join
ecmtransactions t ON t.parent_id = a.id
left join ecmtransactions t2 on t2.parent_id=a.id
where
a.id in ('".implode("','",$ids)."') and t2.settled!=1 and t2.deleted=0
group by a.id,t2.id order by a.index_dbf");
$wynik=array();
while($dane=$db->fetchByAssoc($zap)){
$tmp=array();
$c= new Currency();
$c->retrieve($dane['wal']);
$wynik[$dane['index_dbf']]['name']=$dane['name'];
$wynik[$dane['index_dbf']]['index_dbf']=$dane['index_dbf'];
$wynik[$dane['index_dbf']]['saldo']=getData($dane['id'],8);
$wynik[$dane['index_dbf']]['zaleglosc']=getData2($dane['id'],9);
$wynik[$dane['index_dbf']]['wal']=$c->name;
$wynik[$dane['index_dbf']]['ksac']=$dane['ks_account'];
$tmp['name']=$dane['name2'];
$tmp['value']=$dane['value'];
$tmp['payment_date']=$dane['payment_date'];
$tmp['type']=$dane['type'];
$wynik[$dane['index_dbf']]['poz'][]=$tmp;
}
ob_start();
?>
<style>
.boldtable, .boldtable TD, .boldtable TH
{
font-family:sans-serif;
font-size:8pt;
border-collapse: collapse;
}
tr.separated td {
/* set border style for separated rows */
border-bottom: 1px solid black;
border-top: 1px solid black;
}
</style>
<table>
<tr>
<?php
$ecmsysinfos = new EcmSysInfo();
$header = $ecmsysinfos->getName();
?>
<td><?php echo $header;?><br>
Data wydruku: <?php echo date("d.m.Y");?><br>
<?php echo $_REQUEST['title'];?></td>
</tr>
</table>
<table width="100%" class="boldtable">
<tr class='separated'>
<td>INDEKS</td>
<td>NAZWA</td>
<td style="text-align:right;">SALDO</td>
<td style="text-align:right;">ZALEGŁOŚĆ</td>
<td style="text-align:right;">KONTO KS</td>
</tr>
<?php
$total=0;
$total=2;
$total3=0;
$total4=0;
foreach ($wynik as $val=>$key){
echo "<tr>
<td>".$wynik[$val]['index_dbf']."</td>
<td>".$wynik[$val]['name']."</td>
<td style='text-align:right;'>".format_number($wynik[$val]['saldo'])." ".$wynik[$val]['wal']."</td>
<td style='text-align:right;'>".format_number($wynik[$val]['zaleglosc'])." ".$wynik[$val]['wal']."</td>
<td style='text-align:right;'>".$wynik[$val]['ksac']."</td>
</tr>";
if($wynik[$val]['wal']=='PLN'){
$total+=$wynik[$val]['saldo'];
$total2+=$wynik[$val]['zaleglosc'];
} else {
$total3+=$wynik[$val]['saldo'];
$total4+=$wynik[$val]['zaleglosc'];
}
}
echo '<tr class="separated">
<td></td>
<td>Razem EUR:</td>
<td style="text-align:right;">'.format_number($total3).'</td>
<td style="text-align:right;">'.format_number($total4).'</td>
<td style="text-align:right;"></td>
</tr>';
echo '<tr class="separated">
<td></td>
<td>Razem PLN:</td>
<td style="text-align:right;">'.format_number($total).'</td>
<td style="text-align:right;">'.format_number($total2).'</td>
<td style="text-align:right;"></td>
</tr>';
?>
</table>
<?php
if($_REQUEST['pdf_type']=='1'){
?>
<br>
<table width="100%" class="boldtable">
<tr class='separated'>
<td>INDEKS</td>
<td>NAZWA</td>
<td style="text-align:right;"></td>
<td style="text-align:right;">SALDO</td>
<td style="text-align:right;">ZALEGŁOŚĆ</td>
<td style="text-align:right;">KONTO KS</td>
</tr>
<?php
$content=null;
foreach ($wynik as $val=>$key){
$content.= "<tr class='separated'>
<td>".$wynik[$val]['index_dbf']."</td>
<td>".$wynik[$val]['name']."</td><td style='text-align:right;'></td>
<td style='text-align:right;'>".format_number($wynik[$val]['saldo'])."</td>
<td style='text-align:right;'>".format_number($wynik[$val]['zaleglosc'])."</td>
<td style='text-align:right;'>".$wynik[$val]['ksac']."</td>
</tr>";
if(count($wynik[$val]['poz'])>0){
foreach ($wynik[$val]['poz'] as $v=>$k){
if($wynik[$val]['poz'][$v]['type']==0){
$t="(Wn)";
} else {
$t="(Ma)";
}
if(date("d.m.Y",strtotime($wynik[$val]['poz'][$v]['payment_date']))=='01.01.1970'){
$data='';
} else {
$data=date("d.m.Y",strtotime($wynik[$val]['poz'][$v]['payment_date']));
}
$content.="<tr>
<td></td>
<td>".$wynik[$val]['poz'][$v]['name']."</td><td style='text-align:right;'>".$t."</td>
<td style='text-align:right;'>".format_number($wynik[$val]['poz'][$v]['value'])."</td>
<td style='text-align:right;'>".$data."</td>
<td style='text-align:right;'></td>
</tr>";
}
}
}
$content.='</table>';
}
include_once ("include/MPDF57/mpdf.php");
$mPDF = new mPDF ( 'pl', 'A4', 9, 'arial', 10, 10,10, 10, 14, 20);
$mPDF->setAutoTopMargi = 'stretch';
$mPDF->setAutoBottomMargin = 'stretch';
$mPDF->mirrorMargins = 1;
$mPDF->WriteHTML(ob_get_clean().$content);
$mPDF->Output('saldo_'.date('d_m_Y').'pdf', "I");
?>

156
modules/EcmPaymentStates/rap2.php Executable file
View File

@@ -0,0 +1,156 @@
<?php
$id=array();
$ids=explode(',',$_REQUEST['idToPdf']);
foreach ($ids as $key){
if($ids[$key]!=''){
$id=$ids[$key];
}
}
$db=$GLOBALS['db'];
$zap=$db->query("
select
a.name,
a.id,
a.index_dbf,
a.ks_account,
(sum(CASE
WHEN t.type = 1 and t.settled!=1 THEN t.value else 0
END)-
sum(CASE
WHEN t.type = 0 and t.settled!=1 THEN t.value else 0
END)) as saldo,
(sum(CASE
WHEN t.type = 1 and t.settled!=1 and t.payment_date< now() then t.value else 0
END)-
sum(CASE
WHEN t.type = 0 and t.settled!=1 and t.payment_date< now() THEN t.value else 0
END)) as zaleglosc
from
accounts a
inner join
ecmtransactions t ON t.parent_id = a.id
where
a.id in ('".implode("','",$ids)."')
group by a.id order by a.index_dbf");
$wynik=array();
while($dane=$db->fetchByAssoc($zap)){
$tmp=array();
if($dane['saldo']=='0.00')continue;
$wynik[$dane['index_dbf']]['name']=$dane['name'];
$wynik[$dane['index_dbf']]['index_dbf']=$dane['index_dbf'];
$wynik[$dane['index_dbf']]['saldo']=$dane['saldo'];
$wynik[$dane['index_dbf']]['zaleglosc']=$dane['zaleglosc'];
$wynik[$dane['index_dbf']]['ksac']=$dane['ks_account'];
$zap2=$db->query("select name,value,payment_date,type from ecmtransactions where parent_id='".$dane['id']."' and settled!=1");
while($dane2=$db->fetchByAssoc($zap2)){
$tmp=array();
$tmp['name']=$dane2['name'];
$tmp['value']=$dane2['value'];
$tmp['payment_date']=$dane2['payment_date'];
$tmp['type']=$dane2['type'];
$wynik[$dane['index_dbf']]['poz'][]=$tmp;
}
}
?>
<style>
.boldtable, .boldtable TD, .boldtable TH
{
font-family:sans-serif;
font-size:8pt;
border-collapse: collapse;
}
tr.separated td {
/* set border style for separated rows */
border-bottom: 1px solid black;
border-top: 1px solid black;
}
</style>
<table>
<tr>
<td>Saas Systems<br>
Data wydruku: <?php echo date("d.m.Y");?><br>
<?php echo $_REQUEST['title'];?></td>
</tr>
</table>
<table width="100%" class="boldtable">
<tr class='separated'>
<td>INDEKS</td>
<td>NAZWA</td>
<td style="text-align:right;">SALDO</td>
<td style="text-align:right;">ZALEGŁOŚĆ</td>
<td style="text-align:right;">KONTO KS</td>
</tr>
<?php
foreach ($wynik as $val=>$key){
if($wynik[$val]['zaleglosc']>0){
$zal=0;
} else {
$zal=$wynik[$val]['zaleglosc'];
}
echo "<tr>
<td>".$wynik[$val]['index_dbf']."</td>
<td>".$wynik[$val]['name']."</td>
<td style='text-align:right;'>".format_number($wynik[$val]['saldo'])."</td>
<td style='text-align:right;'>".format_number($zal)."</td>
<td style='text-align:right;'>".$wynik[$val]['ksac']."</td>
</tr>";
}
?>
</table>
<br>
<table width="100%" class="boldtable">
<tr class='separated'>
<td>INDEKS</td>
<td>NAZWA</td>
<td style="text-align:right;"></td>
<td style="text-align:right;">SALDO</td>
<td style="text-align:right;">ZALEGŁOŚĆ</td>
<td style="text-align:right;">KONTO KS</td>
</tr>
<?php
foreach ($wynik as $val=>$key){
if($wynik[$val]['zaleglosc']>0){
$zal=0;
} else {
$zal=$wynik[$val]['zaleglosc'];
}
echo "<tr class='separated'>
<td>".$wynik[$val]['index_dbf']."</td>
<td>".$wynik[$val]['name']."</td><td style='text-align:right;'></td>
<td style='text-align:right;'>".format_number($wynik[$val]['saldo'])."</td>
<td style='text-align:right;'>".format_number($zal)."</td>
<td style='text-align:right;'>".$wynik[$val]['ksac']."</td>
</tr>";
if(count($wynik[$val]['poz'])>0){
foreach ($wynik[$val]['poz'] as $v=>$k){
if($wynik[$val]['poz'][$v]['type']==0){
$t="(Wn)";
} else {
$t="(Ma)";
}
if(date("d.m.Y",strtotime($wynik[$val]['poz'][$v]['payment_date']))=='01.01.1970'){
$data='';
} else {
$data=date("d.m.Y",strtotime($wynik[$val]['poz'][$v]['payment_date']));
}
echo "<tr>
<td></td>
<td>".$wynik[$val]['poz'][$v]['name']."</td><td style='text-align:right;'>".$t."</td>
<td style='text-align:right;'>".format_number($wynik[$val]['poz'][$v]['value'])."</td>
<td style='text-align:right;'>".$data."</td>
<td style='text-align:right;'></td>
</tr>";
}
}
}
?>

View File

@@ -0,0 +1,32 @@
<?php
$inv = $GLOBALS['db']->query("SELECT i.id, i.ecminvoiceout_id, i.discount, i.document_no as d FROM ecminvoiceouts as i INNER JOIN ecmpayments_ecminvoiceouts as pi ON pi.ecminvoiceout_id=i.id");
while ($inv_row = $GLOBALS['db']->fetchByAssoc($inv)) {
$total=0;
if($inv_row['ecminvoiceout_id']){
$w=$GLOBALS['db']->query("select price,ecmvat_value,quantity,ecminvoiceoutitem_id from ecminvoiceoutitems where ecminvoiceout_id='".$inv_row['id']."'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$total+=$r['price']*$r['quantity']+round($r['price']*$r['quantity']*$r['ecmvat_value']/100,2);
$rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select price,quantity,ecmvat_value from ecminvoiceoutitems where id='".$r['ecminvoiceoutitem_id']."'"));
$total-=$rr['price']*$rr['quantity']+round($rr['price']*$rr['quantity']*$rr['ecmvat_value']/100,2);
}
}
else{
$w=$GLOBALS['db']->query("select price,ecmvat_value,quantity,ecminvoiceoutitem_id from ecminvoiceoutitems where ecminvoiceout_id='".$inv_row['id']."'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$total+=($r['price']*$r['quantity'])+round(($r['price']*$r['quantity']*$r['ecmvat_value']/100),2);
}
}
$total -= $inv_row['discount'];
$total = round($total, 2);
echo $inv_row['d'].': '.$total.'<br>';
//update
$GLOBALS['db']->query("update ecminvoiceouts set total=$total where id='".$inv_row['id']."'");
$GLOBALS['db']->query("update ecmpayments_ecminvoiceouts set total=$total where ecminvoiceout_id='".$inv_row['id']."'");
}
?>

View File

@@ -0,0 +1,85 @@
<?php
$db = $GLOBALS['db'];
$inv = $db->query("SELECT * FROM ecminvoiceouts WHERE deleted='0' AND canceled='0' AND YEAR(register_date) IN ('2012','2013','2014') AND paid='0' ORDER BY parent_id");
$errors = array();
while ($i = $db->fetchByAssoc($inv)) {
$tr = $db->query("SELECT * FROM ecmtransactions WHERE record_id = '".$i['id']."' AND deleted='0'");
if ($tr->num_rows==0) {
$errors[$i['parent_name']]['no_transaction'][] = $i['document_no'];
addTransaction($i['id']);
continue;
}
if ($tr->num_rows>1) $errors[$i['parent_name']]['duplicate_transaction'][] = $i['document_no'];
$t = $db->fetchByAssoc($tr);
if ($i['total'] != $t['value']) {
//echo round(abs(floatval($i['total'])-floatval($t['value'])),2).'<br>';
$tmp = array();
$tmp['t'] = $t['value'];
$tmp['i'] = $i['total'];
$tmp['b'] = $i['subtotal'];
if (round(abs(floatval($i['total'])-floatval($t['value'])),2)<0.03) {
$i['document_no'] = '<b>'.$i['document_no'].'</b>';
repairTransaction($t['id'], $i['total']);
}
if (floatval($i['total'])==0 && floatval($i['subtotal'])!= 0 ) {
repairInvoice($i['id'], $t['value']);
$i['document_no'] = '<b>'.$i['document_no'].'</b>';
}
$tmp['d'] = $i['document_no'];
$errors[$i['parent_name']]['wrong_transaction'][] = $tmp;
}
if ($i['total']==0 && $t['value']== 0) {
$tmp = array();
$tmp['t'] = $t['value'];
$tmp['i'] = $i['total'];
$tmp['d'] = $i['document_no'];
$errors[$i['parent_name']]['zero_transaction'][] = $tmp;
}
}
foreach ($errors as $parent=>$val) {
echo '<h1>Klient: '.$parent.'</h1><br>';
echo '<h2>Brak transakcji</h2>';
foreach ($val['no_transaction'] as $v) {
echo $v.'<br>';
}
echo '<h2>Zduplikowana transakcja</h2>';
foreach ($val['duplicate_transaction'] as $v) {
echo $v.'<br>';
}
echo '<h2>Błędna kwota</h2>';
foreach ($val['wrong_transaction'] as $v) {
echo $v['d'].': '.$v['i'].' | '.$v['t'].' | '.$v['b'].'<br>';
}
echo '<h2>Transakcja zerowa</h2>';
foreach ($val['zero_transaction'] as $v) {
echo $v['d'].': '.$v['i'].' | '.$v['t'].'<br>';
}
echo '<br><br><br>';
}
function repairInvoice($inv_id, $total) {
return;
$GLOBALS['db']->query("UPDATE ecminvoiceouts SET total='$total' WHERE id='$inv_id'");
}
function repairTransaction($trans_id, $value) {
return;
$GLOBALS['db']->query("UPDATE ecmtransactions SET value='$value' WHERE id='$trans_id'");
}
function addTransaction($inv_id) {
return;
$db = $GLOBALS['db'];
$r = $db->fetchByAssoc($db->query("SELECT * FROM ecminvoiceouts WHERE id='$inv_id'"));
//add transaction
$db->query ("INSERT INTO ecmtransactions(id,name,date_entered,date_modified,modified_user_id,created_by,description,deleted,assigned_user_id,value,parent_name,parent_id,payment_date,type,paid,register_date,record_id,record_type,currency_id,currency_value)VALUES('".create_guid()."','".$r['document_no']."','".$r['date_entered']."','".$r['date_entered']."','2','2','','".$r['canceled']."','".$r['assigned_user_id']."','".$r['total']."','".$r['parent_name']."','".$r['parent_id']."','".$r['payment_date']."','0','".$r['paid']."','".$r['register_date']."','".$r['id']."','EcmInvoiceOuts','".$r['currency_id'] ."','".$r['currency_value'] ."')");
}
?>

View File

@@ -0,0 +1,27 @@
<?php
$db = $GLOBALS['db'];
$inv = $db->query("
SELECT t.paid, i.document_no, i.id
FROM ecmtransactions as t
INNER JOIN ecminvoiceouts as i
ON t.record_id = i.id
WHERE
t.deleted='0' AND
t.register_date > '2011-12-31'
ORDER BY t.register_date DESC");
while ($i = $db->fetchByAssoc($inv)) {
if ($i['paid']=='1') {
$q = "SELECT pi.paid, pi.deleted, t.id
FROM ecmpayments2_ecminvoiceouts as pi
INNER JOIN ecmtransactions as t
ON t.id = pi.ecmpayment_id
WHERE
ecminvoiceout_id='".$i['id']."'";
$payment = $db->query($q);
if ($payment->num_rows != 0)
echo $q.'<br><br>';
}
}
?>

View File

@@ -0,0 +1,4 @@
<?php
$GLOBALS['db']->query("update ecminvoiceouts set description='".$_REQUEST['desc']."' where id='".$_REQUEST['id']."'");
echo $_REQUEST['desc'];
?>

View File

@@ -0,0 +1,141 @@
<?
include_once("modules/EcmPaymentStates/helper.php");
?>
<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
$w=$GLOBALS['db']->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='<td class="listViewThS1">';
$trs='<tr>';
$trs_grey='<tr style="background-color: #e6e6e6;">';
$tre='</tr>';
$tds='<td class="oddListRowS1">';
$tde='</td>';
$tbs='<table cellpadding="0" cellspacing="0" border="0" class="ListView" style="width:100%;">';
$tbe='</table>';
$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.='<a href="index.php?action=index&module=EcmPaymentStates&nott_matched=0&account_name='.$r['name'].'&account_id='.$r['id'].'&button=Search">'.str_replace("<","&lt;",str_replace(">","&gt;",$r['name'])).'</a>';
$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.='<a href="index.php?module=EcmPaymentStates&action=summary_inv&account_id='.$r['id'].'&start=1&end=30">'.number_format($l_sum_1_30,2,",",".").'</a>';
$t.=$tde;
$t.=$tds;
$t.='<a href="index.php?module=EcmPaymentStates&action=summary_inv&account_id='.$r['id'].'&start=30&end=60">'.number_format($l_sum_30_60,2,",",".").'</a>';
$t.=$tde;
$t.=$tds;
$t.='<a href="index.php?module=EcmPaymentStates&action=summary_inv&account_id='.$r['id'].'&start=60&end=90">'.number_format($l_sum_60_90,2,",",".").'</a>';
$t.=$tde;
$t.=$tds;
$t.='<a href="index.php?module=EcmPaymentStates&action=summary_inv&account_id='.$r['id'].'&start=90&end=180">'.number_format($l_sum_90_180,2,",",".").'</a>';
$t.=$tde;
$t.=$tds;
$t.='<a href="index.php?module=EcmPaymentStates&action=summary_inv&account_id='.$r['id'].'&start=180&end=...">'.number_format($l_sum_180,2,",",".").'</a>';
$t.=$tde;
$t.=$tre;
$i++;
}
$t.=$trs;
$t.=$tds;
$t.=$tde;
$t.=$tds;
$t.='<strong>'.number_format($ballance,2,",",".").'</strong>';
$t.=$tde;
$t.=$tds;
$t.='<strong>'.number_format($summary,2,",",".").'</strong>';
$t.=$tde;
$t.=$tds;
$t.='<strong>'.number_format($sum_1_30,2,",",".").'</strong>';
$t.=$tde;
$t.=$tds;
$t.='<strong>'.number_format($sum_30_60,2,",",".").'</strong>';
$t.=$tde;
$t.=$tds;
$t.='<strong>'.number_format($sum_60_90,2,",",".").'</strong>';
$t.=$tde;
$t.=$tds;
$t.='<strong>'.number_format($sum_90_180,2,",",".").'</strong>';
$t.=$tde;
$t.=$tds;
$t.='<strong>'.number_format($sum_180,2,",",".").'</strong>';
$t.=$tde;
$t.=$tre;
$t.=$tbe;
echo $t;
?>

View File

@@ -0,0 +1,293 @@
<script type="text/javascript">
function createOrderLink(column) {
<?php
if ($_GET ['order_by'])
echo 'var order_by =\'' . $_GET ['order_by'] . '\';';
else
echo 'var order_by =\'p.name\';';
if ($_GET ['order_type'])
echo 'var order_type =\'' . $_GET ['order_type'] . '\';';
else
echo 'var order_type =\'ASC\';';
if (!$_GET['year']) $_GET['year'] = date('%Y');
// $_GET copy
$get = '';
echo 'var get=\'\';';
foreach ( $_GET as $k => $v ) {
if (($k != 'order_by') && ($k != 'order_type'))
if (is_array ( $v )) {
$tmp = '';
foreach ( $v as $k2 => $v2 )
$tmp .= '&' . $k . '[]=' . $v2;
echo 'var get=get+\'' . $tmp . '\';';
} else
echo 'var get=get+\'&' . $k . '=' . $v . '\';';
}
?>
var link;
if (column == order_by) {
if (order_type == 'ASC')
link='index.php?order_by='+column+'&order_type=DESC'+get;
if (order_type == 'DESC') {
link='index.php?order_by='+column+'&order_type=ASC'+get;
}
} else
link='index.php?order_by='+column+'&order_type=ASC'+get;
location.href = link;
}
</script>
<?
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."'<br>";
$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;
?>
<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.='<a class="listViewThLinkS1"
href="javascript:createOrderLink(\'parent_id\')">Kontrahent</a>';
$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.='<a href="index.php?action=index&module=EcmPaymentStates&nott_matched=0&account_name='.$r['parent_name'].'&account_id='.$r['parent_id'].'&button=Search">'.str_replace("<","&lt;",str_replace(">","&gt;",$r['parent_name'])).'</a>';
$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.='<a href="index.php?action=index&module=EcmPaymentStates&matched=1&account_name='.$r['parent_name'].'&account_id='.$r['parent_id'].'&button=Search">'.str_replace("<","&lt;",str_replace(">","&gt;",number_format(abs(sum_saldo($r['parent_id'],2)),2,",","."))).'</a>';
$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.='<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);
$array_sort[$abc]['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);
$array_sort[$abc]['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);
$array_sort[$abc]['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);
$array_sort[$abc]['180']=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);
$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.='<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;
?>

View File

@@ -0,0 +1,739 @@
<?php
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
die ( 'Not A Valid Entry Point' );
ini_set('memory_limit','-1');
ini_set('max_execution_time','-1');
// prepare data
$db = $GLOBALS ['db'];
$db->query('RESET QUERY CACHE;');
$db->query('FLUSH QUERY CACHE');
if($_REQUEST['submit']){
if ($_REQUEST['account_type'])
$account_type = $_REQUEST['account_type'];
else
$account_type = '';
if($_REQUEST['account_type']=='a'){
$account_type = '';
}
if ($_REQUEST['saldo_type'])
$saldo_type = $_REQUEST['saldo_type'];
else
$saldo_type = '';
if ($_REQUEST['type2'])
$and = " and account_type2='".$_REQUEST['type2']."'";
if($saldo_type!=''){
$type="t.settled!='1' and";
} else {
$type='';
}
if ($_REQUEST['user_id']!=''){
$and.= " and a.assigned_user_id='".$_REQUEST['user_id']."'";
} else {
$type='';
}
// get list of accounts
if ($account_type == '')
$clients = $db->query ( "SELECT distinct t.parent_id,a.index_dbf as index_dbf FROM ecmtransactions as t
INNER JOIN accounts AS a
ON t.parent_id = a.id
WHERE ".$type." t.deleted='0' ".$and." ORDER BY a.index_dbf" );
else
$clients = $db->query ( "
SELECT distinct t.parent_id, a.index_dbf as index_dbf FROM ecmtransactions AS t
INNER JOIN accounts AS a
ON t.parent_id = a.id
WHERE
".$type."
t.deleted='0' AND (a.account_type='rs' OR
a.account_type = '$account_type') ".$and."
ORDER BY a.index_dbf
" );
// arrays to handle data for SMARTY
$data = array ();
$sum = array ();
$idToPdf='';
while ( $c = $db->fetchByAssoc ( $clients ) ) {
$row = array ();
$row['id'] = $c['parent_id'];
$tt= $db->fetchByAssoc ( $db->query ( "SELECT name FROM accounts WHERE id='" . $c ['parent_id'] . "'" ) );
$row ['name'] =$tt['name'];
$a=New Account();
$a->retrieve($c['parent_id']);
$a->currency_id;
if($a->id=='')continue;
$row ['unsettled'] = getData ( $c ['parent_id'], 0 );
$row ['not_overdue'] = getData ( $c ['parent_id'], 7 );
$row ['overdue'] = getData ( $c ['parent_id'], 1 );
$row ['2'] =getData2 ( $c ['parent_id'], 2 ); // 1..30
$row ['3'] = getData2 ( $c ['parent_id'], 3 ); // 31..60
$row ['4'] = getData2 ( $c ['parent_id'], 4 ); // 61..90
$row ['5'] = getData2 ( $c ['parent_id'], 5 ); // 91..180
$row ['6'] = getData2 ( $c ['parent_id'], 6 ); // 180..
$row['index']=$c['index_dbf'];
$row ['saldo'] = getData ( $c ['parent_id'], 8 );
$row ['today_saldo'] = 0; // getData2 ( $c ['parent_id'],9,$_REQUEST['saldo_date_val'] );
$c= new Currency();
if($a->currency_id=='')$a->currency_id='PLN';
$c->retrieve($a->currency_id);
$row ['currency_id']=$c->name;
if($saldo_type=='plus' && !($row ['saldo']>0))continue;
if($saldo_type=='minus' && $row ['saldo']>=0 )continue;
if($saldo_type=='zero' && !$row ['saldo']==0 )continue;
if($saldo_type=='' && $row ['saldo']==0 )continue;
$idToPdf.=$row['id'].',';
$sum [$a->currency_id]['unsettled'] += $row ['unsettled'];
$sum [$a->currency_id]['not_overdue'] += $row ['not_overdue'];
$sum [$a->currency_id]['overdue'] += $row ['overdue'];
$sum [$a->currency_id]['2'] += $row ['2']; // 1..30
$sum [$a->currency_id]['3'] += $row ['3']; // 31..60
$sum [$a->currency_id]['4'] += $row ['4']; // 61..90
$sum [$a->currency_id]['5'] += $row ['5']; // 91..180
$sum [$a->currency_id]['6'] += $row ['6']; // 180..
$sum [$a->currency_id]['saldo'] += $row ['saldo'];
$sum [$a->currency_id]['today_saldo'] += $row ['today_saldo'];
$sum [$a->currency_id]['currency_id']=$c->name;
$data [] = $row;
}
// sort
$sort = array ();
}
$user_list=array();
$z=$db->query("select id,first_name,last_name from users where deleted=0");
while($dane=$db->fetchByAssoc($z)){
$user_list[$dane['id']]=$dane['first_name'].' '.$dane['last_name'];
}
// create & execute smarty
$ss = new Sugar_Smarty ();
global $mod_strings,$app_list_strings;
$ss->assign ( "MOD", $mod_strings );
$ss->assign ( "DATA", $data );
$ss->assign ( "SUM", $sum );
$ss->assign ( "SORT", $sort );
$ss->assign("account_type", $account_type);
$app_list_strings['account_type_dom']['a']='Wszystkie';
$ss->assign("account_type_list", $app_list_strings['account_type_dom']);
$ss->assign("saldo_type",$saldo_type);
$ss->assign("saldo_date_val",$_REQUEST['saldo_date_val']);
$ss->assign("idToPdf",$idToPdf);
$ss->assign("type",$_REQUEST['type2']);
$ss->assign("type2",$app_list_strings['account_type2_dom']);
$ss->assign("user_id",$_REQUEST['user_id']);
$ss->assign("users",$user_list);
echo $ss->display ( 'modules/EcmPaymentStates/tpls/summary1.tpl' );
// helper functions
function getData2($id, $expired,$dates = null) {
$db = $GLOBALS ['db'];
$saldo = false;
$settled = " t.settled!='1' AND ";
switch ($expired) {
case 1 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
break;
case 2 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-30 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date < '$d_t'";
break;
case 3 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-31 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-60 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date <= '$d_t'";
break;
case 4 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-61 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-90 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date <= '$d_t'";
break;
case 5 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-91 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-180 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date <= '$d_t'";
break;
case 6 :
$date = new DateTime ( date ( "Y-m-d" ) );
$date->modify ( '-181 days' );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
break;
case 9:
if($dates==null){
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
} else {
$date = new DateTime ( date ( "Y-m-d",strtotime($dates) ) );
$d = $date->format ( 'Y-m-d' );
}
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
$settled = " ";
$saldo = true;
break;
}
//start WINIEN
if($_REQUEST['account_type']=='rec')$typ=0;else $typ=1;
$zap= $db->query ( "
SELECT
(
t.value
) AS value,t.id
FROM ecmtransactions AS t
left JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='0' AND
" . $payment_date . " group by t.id
" );
$suma=0;
$total_settled=0;
while($r = $db->fetchByAssoc ($zap)){
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
$tmp2 = array();
if($t['deleted']==1)continue;
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp['settled_with'][] = $tmp2;
if($expired==9){
if($dates==null){
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
} else {
$date = new DateTime ( date ( "Y-m-d",strtotime($dates) ) );
$d = $date->format ( 'Y-m-d' );
}
$date2 = new DateTime ( $t['payment_date'] );
if($date2>$date)continue;
}
if($t['type']==0){
if($r['value']<0 && $rr['value']<0){
$total_settled+=abs(floatval($rr['value']));
} else {
$total_settled+=floatval($rr['value']);
}
} else {
$total_settled+=abs(floatval($rr['value']));
}
}
$suma+=$r['value'];
}
$zap= $db->query ( "
SELECT
(
t.value
) AS value,t.id
FROM ecmtransactions AS t
left JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='1' AND
" . $payment_date . " group by t.id
" );
$suma2=0;
$total_settled2=0;
while($r = $db->fetchByAssoc ($zap)){
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
if($t['deleted']==1)continue;
$tmp2 = array();
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp['settled_with'][] = $tmp2;
if($expired==9){
if($dates==null){
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
} else {
$date = new DateTime ( date ( "Y-m-d",strtotime($dates) ) );
$d = $date->format ( 'Y-m-d' );
}
$date2 = new DateTime ( $t['payment_date'] );
if($date2>$date)continue;
}
$total_settled2+=abs(floatval($rr['value']));
}
$suma2+=$r['value'];
}
return $total_settled-$suma+$suma2-$total_settled2;
return $total_settled-$suma;
}
function getSaldo($id){
$db = $GLOBALS ['db'];
$query_w="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$id."'
AND type='0'
ORDER BY payment_date desc";
$query_ma="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$id."'
AND type='1'
ORDER BY payment_date desc";
$res = $db->query($query_w);
$total_winien = 0;
$winien = array();
while ($r = $db->fetchByAssoc($res)) {
$tmp = array();
$tmp['settled_with'] = array();
$total_settled = 0;
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
$tmp2 = array();
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp2['value']=$rr['value'];
if($t['type']==0 && $rel->num_rows==1){
if(abs($rr['value'])==abs($r['value'])){
if($r['value']>0){
$rr['value']=abs($rr['value']);
} else {
$v = -1 * abs( $rr['value']);
$rr['value']=$v;
}
}
} else {
if(abs($rr['value'])==abs($r['value'])){
if($r['value']>0){
$rr['value']=abs($rr['value']);
} else {
$v = -1 * abs( $rr['value']);
$rr['value']=$v;
}
} else {
if($r['value']>0){
$rr['value']=abs($rr['value']);
}
}
}
$tmp['settled_with'][] = $tmp2;
$total_settled+=floatval($rr['value']);
}
//date comparsion
if ($r['settled'] == '1') {
$d1 = new DateTime($r['register_date']);
$d2 = new DateTime($change_date);
if ($d1 < $d2)
$total_settled = $r['value'];
} else $r['settled'] = '0'; //prevent null
$tmp['document_no'] = '<a href="index.php?module=EcmTransactions&action=DetailView&record='.$r['id'].'" traget="new">'.$r['name'].'</a>';
$tmp['total'] = format_number($r['value']);
$tmp['settled'] = format_number($total_settled);
if($r['settled']==1){
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_winien+=floatval(unsettledValue($total_settled,$r['value']));
}else{
$tmp['unsettled'] = format_number($r['value']-$total_settled);
$total_winien+=floatval($r['value']-$total_settled);
}
$tmp['id'] = $r['id'];
$tmp['note']= $r['note'];
$tmp['note_id']= $r['note_id'];
$tmp['is_settled'] = $r['settled'];
}
$res = $db->query($query_ma);
$ma = array();
$total_ma = 0;
while ($r = $db->fetchByAssoc($res)) {
$tmp = array();
$tmp['settled_with'] = array();
$total_settled = 0;
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
$tmp2 = array();
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp2['value']=$rr['value'];
if($t['type']==0 && $rel->num_rows==1){
if(abs($rr['value'])==abs($r['value'])){
if($r['value']>0){
$rr['value']=abs($rr['value']);
} else {
$v = -1 * abs( $rr['value']);
$rr['value']=$v;
}
}
}
$tmp['settled_with'][] = $tmp2;
$total_settled+=floatval($rr['value']);
}
//date comparsion
if ($r['settled'] == '1') {
$d1 = new DateTime($r['register_date']);
$d2 = new DateTime($change_date);
if ($d1 < $d2)
$total_settled = $r['value'];
} else $r['settled'] = '0'; //prevent null
$tmp['name'] = '<a href="index.php?module=EcmTransactions&action=DetailView&record='.$r['id'].'" traget="new">'.$r['name'].'</a>';
$tmp['total'] = format_number($r['value']);
$tmp['settled'] = format_number($total_settled);
if($r['settled']==1){
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_winien+=floatval(unsettledValue($total_settled,$r['value']));
//$tmp['unsettled'] = format_number(abs($r['value'])-$total_settled); echo 'rozliczone';
}else{
$tmp['unsettled'] = format_number($r['value']-$total_settled);
$total_winien+=floatval($r['value']-$total_settled);
}
$tmp['is_settled'] = $r['settled'];
$tmp['id'] = $r['id'];
$ma[] = $tmp;
//$total_ma+=floatval($r['value']);
}
return $total_ma - $total_winien;
}
function unsettledFormatValue($settled,$val){
if($settled<0 && $val>0){
return format_number($val+$settled);
}
if($settled<0 && $val<0){
return format_number($val+abs($settled));
}
if($settled>0 && $val>0){
return format_number($val-abs($settled));
}
if($settled>0 && $val<0){
return format_number($val+$settled);
}
}
function unsettledValue($settled,$val){
if($settled<0 && $val>0){
return ($val+$settled);
}
if($settled<0 && $val<0){
return ($val+abs($settled));
}
if($settled>0 && $val>0){
return ($val-abs($settled));
}
if($settled>0 && $val<0){
return ($val+$settled);
}
}
function getData($id, $expired) {
$db = $GLOBALS ['db'];
$saldo = false;
$settled = " t.settled!='1' AND ";
switch ($expired) {
case 0 :
$payment_date = "1=1";
break;
case 1 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
$saldo=true;
break;
case 2 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-30 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 3 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-31 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-60 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 4 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-61 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-90 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 5 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-91 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-180 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 6 :
$date = new DateTime ( date ( "Y-m-d" ) );
$date->modify ( '-181 days' );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date < '$d'";
break;
case 7 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d'";
break;
case 8 :
$payment_date = " 1=1 ";
$saldo = true;
$settled = " 1=1 and";
break;
case 9:
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
$settled = " 1=1 AND ";
$saldo = true;
break;
}
//start WINIEN
$r = $db->fetchByAssoc ( $db->query ( "
SELECT
sum(
t.value
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='1' AND
" . $payment_date . "
" ) );
//get part settled transactions
/*
if (!$saldo){
$s = $db->fetchByAssoc($db->query("
SELECT
sum(
CASE WHEN t.currency_id='PLN' THEN t.value
ELSE t.value*t.currency_value
END
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='0' AND
t.register_date > '2011-12-31' AND
" . $payment_date . "
"));
}
*/
if (!$saldo){
return $r['sum'];
}
if (! is_numeric ( $r ['sum'] ))
$r ['sum'] = 0;
if (! is_numeric ( $s ['settled'] ))
$s ['settled'] = 0;
if (floatval($s['settled']) > 0)
$r['sum'] = floatval($r['sum']) - floatval($s['settled']);
$sum = $r['sum'];
//END WINIEN
$r['sum'] = 0;
if ($saldo) {
$r = $db->fetchByAssoc ( $db->query ( "
SELECT
sum(
t.value
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='0' AND
" . $payment_date . "
" ) );
}
$res=$sum - $r ['sum'];
if($expired==1 && $res>0){
return 0;
}
//END MA
return $res;
}
// sort comparing functions
function cmpUnsettled($a, $b) {
if ($a ['unsettled'] == $b ['unsettled']) {
return 0;
}
return ($a ['unsettled'] < $b ['unsettled']) ? - 1 : 1;
}
function cmpUnsettledDesc($a, $b) {
if ($a ['unsettled'] == $b ['unsettled']) {
return 0;
}
return ($a ['unsettled'] < $b ['unsettled']) ? 1 : - 1;
}
function cmpNotOverdue($a, $b) {
if ($a ['not_overdue'] == $b ['not_overdue']) {
return 0;
}
return ($a ['not_overdue'] < $b ['not_overdue']) ? - 1 : 1;
}
function cmpNotOverdueDesc($a, $b) {
if ($a ['not_overdue'] == $b ['not_overdue']) {
return 0;
}
return ($a ['not_overdue'] < $b ['not_overdue']) ? 1 : - 1;
}
function cmpOverdue($a, $b) {
if ($a ['overdue'] == $b ['overdue']) {
return 0;
}
return ($a ['overdue'] < $b ['overdue']) ? - 1 : 1;
}
function cmpOverdueDesc($a, $b) {
if ($a ['overdue'] == $b ['overdue']) {
return 0;
}
return ($a ['overdue'] < $b ['overdue']) ? 1 : - 1;
}
function cmpAccount($a, $b) {
return strnatcmp ( $a ['name'], $b ['name'] );
}
function cmpAccountDesc($a, $b) {
return - 1 * strnatcmp ( $a ['name'], $b ['name'] );
}
function cmpSaldo($a, $b) {
if ($a ['saldo'] == $b ['saldo']) {
return 0;
}
return ($a ['saldo'] < $b ['saldo']) ? - 1 : 1;
}
function cmpSaldoDesc($a, $b) {
if ($a ['saldo'] == $b ['saldo']) {
return 0;
}
return ($a ['saldo'] < $b ['saldo']) ? 1 : -1;
}
function cmpTodaySaldo($a, $b) {
if ($a ['today_saldo'] == $b ['today_saldo']) {
return 0;
}
return ($a ['today_saldo'] < $b ['today_saldo']) ? - 1 : 1;
}
function cmpTodaySaldoDesc($a, $b) {
if ($a ['today_saldo'] == $b ['today_saldo']) {
return 0;
}
return ($a ['today_saldo'] < $b ['today_saldo']) ? 1 : -1;
}
?>

View File

@@ -0,0 +1,734 @@
<?php
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
die ( 'Not A Valid Entry Point' );
ini_set('memory_limit','-1');
ini_set('max_execution_time','-1');
// prepare data
$db = $GLOBALS ['db'];
if($_REQUEST['submit']){
if ($_REQUEST['account_type'])
$account_type = $_REQUEST['account_type'];
else
$account_type = '';
if($_REQUEST['account_type']=='a'){
$account_type = '';
}
if ($_REQUEST['saldo_type'])
$saldo_type = $_REQUEST['saldo_type'];
else
$saldo_type = '';
if ($_REQUEST['type2'])
$and = " and account_type2='".$_REQUEST['type2']."'";
if($saldo_type!=''){
$type="t.settled!='1' and";
} else {
$type='';
}
if ($_REQUEST['user_id']!=''){
$and.= " and a.assigned_user_id='".$_REQUEST['user_id']."'";
} else {
$type='';
}
// get list of accounts
if ($account_type == '')
$clients = $db->query ( "SELECT distinct t.parent_id FROM ecmtransactions as t
INNER JOIN accounts AS a
ON t.parent_id = a.id
WHERE ".$type." t.deleted='0' ".$and." ORDER BY a.index_dbf" );
else
$clients = $db->query ( "
SELECT distinct t.parent_id FROM ecmtransactions AS t
INNER JOIN accounts AS a
ON t.parent_id = a.id
WHERE
".$type."
t.deleted='0' AND (a.account_type='rs' OR
a.account_type = '$account_type') ".$and."
ORDER BY a.index_dbf
" );
// arrays to handle data for SMARTY
$data = array ();
$sum = array ();
$idToPdf='';
while ( $c = $db->fetchByAssoc ( $clients ) ) {
$row = array ();
$row['id'] = $c['parent_id'];
$tt= $db->fetchByAssoc ( $db->query ( "SELECT name FROM accounts WHERE id='" . $c ['parent_id'] . "'" ) );
$row ['name'] =$tt['name'];
$a=New Account();
$a->retrieve($c['parent_id']);
$a->currency_id;
if($a->id=='')continue;
$row ['unsettled'] = getData ( $c ['parent_id'], 0 );
$row ['not_overdue'] = getData ( $c ['parent_id'], 7 );
$row ['overdue'] = getData ( $c ['parent_id'], 1 );
$row ['2'] = getData2 ( $c ['parent_id'], 2 ); // 1..30
$row ['3'] = getData2 ( $c ['parent_id'], 3 ); // 31..60
$row ['4'] = getData2 ( $c ['parent_id'], 4 ); // 61..90
$row ['5'] = getData2 ( $c ['parent_id'], 5 ); // 91..180
$row ['6'] = getData2 ( $c ['parent_id'], 6 ); // 180..
$row ['saldo'] = getData ( $c ['parent_id'], 8 );
$row ['today_saldo'] = getData2 ( $c ['parent_id'],9,$_REQUEST['saldo_date_val'] );
$c= new Currency();
if($a->currency_id=='')$a->currency_id='PLN';
$c->retrieve($a->currency_id);
$row ['currency_id']=$c->name;
if($saldo_type=='plus' && !($row ['saldo']>0))continue;
if($saldo_type=='minus' && $row ['saldo']>=0 )continue;
if($saldo_type=='zero' && !$row ['saldo']==0 )continue;
$idToPdf.=$row['id'].',';
$sum [$a->currency_id]['unsettled'] += $row ['unsettled'];
$sum [$a->currency_id]['not_overdue'] += $row ['not_overdue'];
$sum [$a->currency_id]['overdue'] += $row ['overdue'];
$sum [$a->currency_id]['2'] += $row ['2']; // 1..30
$sum [$a->currency_id]['3'] += $row ['3']; // 31..60
$sum [$a->currency_id]['4'] += $row ['4']; // 61..90
$sum [$a->currency_id]['5'] += $row ['5']; // 91..180
$sum [$a->currency_id]['6'] += $row ['6']; // 180..
$sum [$a->currency_id]['saldo'] += $row ['saldo'];
$sum [$a->currency_id]['today_saldo'] += $row ['today_saldo'];
$sum [$a->currency_id]['currency_id']=$c->name;
$data [] = $row;
}
// sort
$sort = array ();
}
$user_list=array();
$z=$db->query("select id,first_name,last_name from users where deleted=0");
while($dane=$db->fetchByAssoc($z)){
$user_list[$dane['id']]=$dane['first_name'].' '.$dane['last_name'];
}
// create & execute smarty
$ss = new Sugar_Smarty ();
global $mod_strings,$app_list_strings;
$ss->assign ( "MOD", $mod_strings );
$ss->assign ( "DATA", $data );
$ss->assign ( "SUM", $sum );
$ss->assign ( "SORT", $sort );
$ss->assign("account_type", $account_type);
$app_list_strings['account_type_dom']['a']='Wszystkie';
$ss->assign("account_type_list", $app_list_strings['account_type_dom']);
$ss->assign("saldo_type",$saldo_type);
$ss->assign("saldo_date_val",$_REQUEST['saldo_date_val']);
$ss->assign("idToPdf",$idToPdf);
$ss->assign("type",$_REQUEST['type2']);
$ss->assign("type2",$app_list_strings['account_type2_dom']);
$ss->assign("user_id",$_REQUEST['user_id']);
$ss->assign("users",$user_list);
echo $ss->display ( 'modules/EcmPaymentStates/tpls/summary.tpl' );
// helper functions
function getData2($id, $expired,$dates = null) {
$db = $GLOBALS ['db'];
$saldo = false;
$settled = " t.settled!='1' AND ";
switch ($expired) {
case 1 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
break;
case 2 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-30 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date < '$d_t'";
break;
case 3 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-31 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-60 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date <= '$d_t'";
break;
case 4 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-61 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-90 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date <= '$d_t'";
break;
case 5 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-91 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-180 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d_f' AND payment_date <= '$d_t'";
break;
case 6 :
$date = new DateTime ( date ( "Y-m-d" ) );
$date->modify ( '-181 days' );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
break;
case 9:
if($dates==null){
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
} else {
$date = new DateTime ( date ( "Y-m-d",strtotime($dates) ) );
$d = $date->format ( 'Y-m-d' );
}
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
$settled = " ";
$saldo = true;
break;
}
//start WINIEN
if($_REQUEST['account_type']=='rec')$typ=0;else $typ=1;
$zap= $db->query ( "
SELECT
(
t.value
) AS value,t.id
FROM ecmtransactions AS t
left JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='0' AND
" . $payment_date . " group by t.id
" );
$suma=0;
$total_settled=0;
while($r = $db->fetchByAssoc ($zap)){
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
$tmp2 = array();
if($t['deleted']==1)continue;
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp['settled_with'][] = $tmp2;
if($expired==9){
if($dates==null){
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
} else {
$date = new DateTime ( date ( "Y-m-d",strtotime($dates) ) );
$d = $date->format ( 'Y-m-d' );
}
$date2 = new DateTime ( $t['payment_date'] );
if($date2>$date)continue;
}
if($t['type']==0){
if($r['value']<0 && $rr['value']<0){
$total_settled+=abs(floatval($rr['value']));
} else {
$total_settled+=floatval($rr['value']);
}
} else {
$total_settled+=abs(floatval($rr['value']));
}
}
$suma+=$r['value'];
}
$zap= $db->query ( "
SELECT
(
t.value
) AS value,t.id
FROM ecmtransactions AS t
left JOIN ecmtransactions_rel AS rel
ON (rel.ecmtransaction_a_id=t.id OR rel.ecmtransaction_b_id=t.id)
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='1' AND
" . $payment_date . " group by t.id
" );
$suma2=0;
$total_settled2=0;
while($r = $db->fetchByAssoc ($zap)){
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
if($t['deleted']==1)continue;
$tmp2 = array();
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp['settled_with'][] = $tmp2;
if($expired==9){
if($dates==null){
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
} else {
$date = new DateTime ( date ( "Y-m-d",strtotime($dates) ) );
$d = $date->format ( 'Y-m-d' );
}
$date2 = new DateTime ( $t['payment_date'] );
if($date2>$date)continue;
}
$total_settled2+=abs(floatval($rr['value']));
}
$suma2+=$r['value'];
}
return $total_settled-$suma+$suma2-$total_settled2;
return $total_settled-$suma;
}
function getSaldo($id){
$db = $GLOBALS ['db'];
$query_w="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$id."'
AND type='0'
ORDER BY payment_date desc";
$query_ma="
SELECT * FROM ecmtransactions
WHERE deleted='0' AND
parent_id='".$id."'
AND type='1'
ORDER BY payment_date desc";
$res = $db->query($query_w);
$total_winien = 0;
$winien = array();
while ($r = $db->fetchByAssoc($res)) {
$tmp = array();
$tmp['settled_with'] = array();
$total_settled = 0;
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
$tmp2 = array();
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp2['value']=$rr['value'];
if($t['type']==0 && $rel->num_rows==1){
if(abs($rr['value'])==abs($r['value'])){
if($r['value']>0){
$rr['value']=abs($rr['value']);
} else {
$v = -1 * abs( $rr['value']);
$rr['value']=$v;
}
}
} else {
if(abs($rr['value'])==abs($r['value'])){
if($r['value']>0){
$rr['value']=abs($rr['value']);
} else {
$v = -1 * abs( $rr['value']);
$rr['value']=$v;
}
} else {
if($r['value']>0){
$rr['value']=abs($rr['value']);
}
}
}
$tmp['settled_with'][] = $tmp2;
$total_settled+=floatval($rr['value']);
}
//date comparsion
if ($r['settled'] == '1') {
$d1 = new DateTime($r['register_date']);
$d2 = new DateTime($change_date);
if ($d1 < $d2)
$total_settled = $r['value'];
} else $r['settled'] = '0'; //prevent null
$tmp['document_no'] = '<a href="index.php?module=EcmTransactions&action=DetailView&record='.$r['id'].'" traget="new">'.$r['name'].'</a>';
$tmp['total'] = format_number($r['value']);
$tmp['settled'] = format_number($total_settled);
if($r['settled']==1){
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_winien+=floatval(unsettledValue($total_settled,$r['value']));
}else{
$tmp['unsettled'] = format_number($r['value']-$total_settled);
$total_winien+=floatval($r['value']-$total_settled);
}
$tmp['id'] = $r['id'];
$tmp['note']= $r['note'];
$tmp['note_id']= $r['note_id'];
$tmp['is_settled'] = $r['settled'];
}
$res = $db->query($query_ma);
$ma = array();
$total_ma = 0;
while ($r = $db->fetchByAssoc($res)) {
$tmp = array();
$tmp['settled_with'] = array();
$total_settled = 0;
$rel = $db->query("SELECT * FROM ecmtransactions_rel WHERE ecmtransaction_a_id='".$r['id']."' OR ecmtransaction_b_id='".$r['id']."'");
while ($rr = $db->fetchByAssoc($rel)) {
if ($rr['ecmtransaction_a_id'] == $r['id'])
$rel_id = $rr['ecmtransaction_b_id'];
else
$rel_id = $rr['ecmtransaction_a_id'];
$t = $db->fetchByAssoc($db->query("SELECT * FROM ecmtransactions WHERE id='$rel_id'"));
$tmp2 = array();
$tmp2['name'] = $t['name'];
$tmp2['trans_id'] = $t['id'];
$tmp2['value']=$rr['value'];
if($t['type']==0 && $rel->num_rows==1){
if(abs($rr['value'])==abs($r['value'])){
if($r['value']>0){
$rr['value']=abs($rr['value']);
} else {
$v = -1 * abs( $rr['value']);
$rr['value']=$v;
}
}
}
$tmp['settled_with'][] = $tmp2;
$total_settled+=floatval($rr['value']);
}
//date comparsion
if ($r['settled'] == '1') {
$d1 = new DateTime($r['register_date']);
$d2 = new DateTime($change_date);
if ($d1 < $d2)
$total_settled = $r['value'];
} else $r['settled'] = '0'; //prevent null
$tmp['name'] = '<a href="index.php?module=EcmTransactions&action=DetailView&record='.$r['id'].'" traget="new">'.$r['name'].'</a>';
$tmp['total'] = format_number($r['value']);
$tmp['settled'] = format_number($total_settled);
if($r['settled']==1){
$tmp['unsettled'] = unsettledFormatValue($total_settled,$r['value']);
$total_winien+=floatval(unsettledValue($total_settled,$r['value']));
//$tmp['unsettled'] = format_number(abs($r['value'])-$total_settled); echo 'rozliczone';
}else{
$tmp['unsettled'] = format_number($r['value']-$total_settled);
$total_winien+=floatval($r['value']-$total_settled);
}
$tmp['is_settled'] = $r['settled'];
$tmp['id'] = $r['id'];
$ma[] = $tmp;
//$total_ma+=floatval($r['value']);
}
return $total_ma - $total_winien;
}
function unsettledFormatValue($settled,$val){
if($settled<0 && $val>0){
return format_number($val+$settled);
}
if($settled<0 && $val<0){
return format_number($val+abs($settled));
}
if($settled>0 && $val>0){
return format_number($val-abs($settled));
}
if($settled>0 && $val<0){
return format_number($val+$settled);
}
}
function unsettledValue($settled,$val){
if($settled<0 && $val>0){
return ($val+$settled);
}
if($settled<0 && $val<0){
return ($val+abs($settled));
}
if($settled>0 && $val>0){
return ($val-abs($settled));
}
if($settled>0 && $val<0){
return ($val+$settled);
}
}
function getData($id, $expired) {
$db = $GLOBALS ['db'];
$saldo = false;
$settled = " t.settled!='1' AND ";
switch ($expired) {
case 0 :
$payment_date = "1=1";
break;
case 1 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
$saldo=true;
break;
case 2 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-30 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 3 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-31 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-60 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 4 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-61 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-90 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 5 :
$date_to = new DateTime ( date ( "Y-m-d" ) );
$date_to->modify ( '-91 days' );
$d_t = $date_to->format ( 'Y-m-d' );
$date_from = new DateTime ( date ( "Y-m-d" ) );
$date_from->modify ( '-180 days' );
$d_f = $date_from->format ( 'Y-m-d' );
$payment_date = " payment_date > '$d_f' AND payment_date < '$d_t'";
break;
case 6 :
$date = new DateTime ( date ( "Y-m-d" ) );
$date->modify ( '-181 days' );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date < '$d'";
break;
case 7 :
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date >= '$d'";
break;
case 8 :
$payment_date = " 1=1 ";
$saldo = true;
$settled = " 1=1 and";
break;
case 9:
$date = new DateTime ( date ( "Y-m-d" ) );
$d = $date->format ( 'Y-m-d' );
$payment_date = " payment_date <= '$d'";
$settled = " 1=1 AND ";
$saldo = true;
break;
}
//start WINIEN
$r = $db->fetchByAssoc ( $db->query ( "
SELECT
sum(
t.value
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='1' AND
" . $payment_date . "
" ) );
//get part settled transactions
/*
if (!$saldo){
$s = $db->fetchByAssoc($db->query("
SELECT
sum(
CASE WHEN t.currency_id='PLN' THEN t.value
ELSE t.value*t.currency_value
END
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='0' AND
t.register_date > '2011-12-31' AND
" . $payment_date . "
"));
}
*/
if (!$saldo){
return $r['sum'];
}
if (! is_numeric ( $r ['sum'] ))
$r ['sum'] = 0;
if (! is_numeric ( $s ['settled'] ))
$s ['settled'] = 0;
if (floatval($s['settled']) > 0)
$r['sum'] = floatval($r['sum']) - floatval($s['settled']);
$sum = $r['sum'];
//END WINIEN
$r['sum'] = 0;
if ($saldo) {
$r = $db->fetchByAssoc ( $db->query ( "
SELECT
sum(
t.value
) AS sum
FROM ecmtransactions AS t
WHERE
t.parent_id = '$id' AND
t.deleted='0' AND
" .$settled. "
t.type='0' AND
" . $payment_date . "
" ) );
}
$res=$sum - $r ['sum'];
if($expired==1 && $res>0){
return 0;
}
//END MA
return $res;
}
// sort comparing functions
function cmpUnsettled($a, $b) {
if ($a ['unsettled'] == $b ['unsettled']) {
return 0;
}
return ($a ['unsettled'] < $b ['unsettled']) ? - 1 : 1;
}
function cmpUnsettledDesc($a, $b) {
if ($a ['unsettled'] == $b ['unsettled']) {
return 0;
}
return ($a ['unsettled'] < $b ['unsettled']) ? 1 : - 1;
}
function cmpNotOverdue($a, $b) {
if ($a ['not_overdue'] == $b ['not_overdue']) {
return 0;
}
return ($a ['not_overdue'] < $b ['not_overdue']) ? - 1 : 1;
}
function cmpNotOverdueDesc($a, $b) {
if ($a ['not_overdue'] == $b ['not_overdue']) {
return 0;
}
return ($a ['not_overdue'] < $b ['not_overdue']) ? 1 : - 1;
}
function cmpOverdue($a, $b) {
if ($a ['overdue'] == $b ['overdue']) {
return 0;
}
return ($a ['overdue'] < $b ['overdue']) ? - 1 : 1;
}
function cmpOverdueDesc($a, $b) {
if ($a ['overdue'] == $b ['overdue']) {
return 0;
}
return ($a ['overdue'] < $b ['overdue']) ? 1 : - 1;
}
function cmpAccount($a, $b) {
return strnatcmp ( $a ['name'], $b ['name'] );
}
function cmpAccountDesc($a, $b) {
return - 1 * strnatcmp ( $a ['name'], $b ['name'] );
}
function cmpSaldo($a, $b) {
if ($a ['saldo'] == $b ['saldo']) {
return 0;
}
return ($a ['saldo'] < $b ['saldo']) ? - 1 : 1;
}
function cmpSaldoDesc($a, $b) {
if ($a ['saldo'] == $b ['saldo']) {
return 0;
}
return ($a ['saldo'] < $b ['saldo']) ? 1 : -1;
}
function cmpTodaySaldo($a, $b) {
if ($a ['today_saldo'] == $b ['today_saldo']) {
return 0;
}
return ($a ['today_saldo'] < $b ['today_saldo']) ? - 1 : 1;
}
function cmpTodaySaldoDesc($a, $b) {
if ($a ['today_saldo'] == $b ['today_saldo']) {
return 0;
}
return ($a ['today_saldo'] < $b ['today_saldo']) ? 1 : -1;
}
?>

View File

@@ -0,0 +1,139 @@
<?
include_once("modules/EcmPaymentStates/helper.php");
global $current_language;
echo '<script type="text/javascript" src="cache/jsLanguage/EcmCalls/'.$current_language.'.js"></script>';
echo '<img id="EcmCalls_image_assign" src="modules/EcmCalls/images/assign_call.gif" style="display:none;" />';
echo '<img id="EcmCalls_image_search" src="modules/EcmCalls/images/search_call.gif" style="display:none;" />';
echo '<script type="text/javascript" src="include/JSON.js"></script>';
echo '<script type="text/javascript" src="modules/EcmCalls/Hint.js"></script>';
echo '<script language="javascript" src="modules/EcmCalls/DoCall.js"></script>';
echo '<script language="javascript" src="modules/EcmCalls/ListView.js"></script>';
echo '<link rel="stylesheet" type="text/css" href="modules/EcmCalls/Hint.css" />';
$w=$GLOBALS['db']->query("select distinct name from accounts where id='".$_REQUEST['account_id']."'");
$r=$GLOBALS['db']->fetchByAssoc($w);
$aname=$r['name'];
if($_REQUEST['actual_sum']!=1)$title=$aname." - ".$_REQUEST['start']." - ".$_REQUEST['end'];
else $title=$aname." - Not overdue";
?>
<table cellspacing="0" cellpadding="0" border="0"><tr><td></td><td><h2>Payments States: Summary - <?php echo $title;?></h2></td></tr></table>
<br />
<input type="button" class="button" value="Create XLS" name="create_xls" onclick="location.href='index.php?module=EcmPaymentStates&action=CreateXLSsummary_inv&to_pdf=1&account_id=<?php echo $_REQUEST['account_id'];?>&start=<?php echo $_REQUEST['start'];?>&end=<?php echo $_REQUEST['end'];?>';" />
<?php
if($_REQUEST['end']=="...")$_REQUEST['end']=0;
if($_REQUEST['actual_sum']==1)$inv=getActualInvoices($_REQUEST['account_id']);
else $inv=getInvoices($_REQUEST['account_id'],$_REQUEST['start'],$_REQUEST['end']);
if (!is_array($inv)) return;
foreach($inv as $in){
$invs[]="p.id='".$in."'";
}
$tds1='<td class="listViewThS1">';
$trs='<tr>';
$tre='</tr>';
$tds='<td class="oddListRowS1">';
$tde='</td>';
$tbs='<table cellpadding="0" cellspacing="0" border="0" class="ListView" style="width:100%;">';
$tbe='</table>';
echo '
<script language="javascript" src="modules/EcmProducts/helper.js"></script>
<script language="javascript">
function showDiv(obj,value,inv_id){
var div=document.getElementById("div_desc");
document.getElementById("desc").value="";
document.getElementById("desc").value=document.getElementById("desc"+inv_id).value;
document.getElementById("inv_id").value=inv_id;
div.style.display="";
var x=findPosX(obj)-180;
var y=findPosY(obj);
moveDiv(div,y,(x+10));
}
</script>';
echo '<div id="div_desc" style="border: 1px solid #cccccc;background:#e6e6e6;padding:5px;text-align:center;position:absolute;display:none;">';
echo '<textarea id="desc1" name="desc1" style="display:none;"></textarea><br />';
echo '<textarea id="desc" name="desc"></textarea><br />';
echo '<div id="result" style="display:none;"></div>';
echo '<input type="hidden" id="inv_id" />';
echo '<input type="button" class="button" value="Save" onclick="mintajaxget(\'index.php?to_pdf=1&module=EcmPaymentStates&action=saveDesc&id=\'+document.getElementById(\'inv_id\').value+\'&desc=\'+document.getElementById(\'desc\').value,\'desc\'+document.getElementById(\'inv_id\').value);document.getElementById(\'div_desc\').style.display=\'none\';" />&nbsp;';
echo '<input type="button" class="button" value="Close" onclick="document.getElementById(\'div_desc\').style.display=\'none\';" />';
echo '</div>';
$t.=$tbs;
$t.=$trs;
$t.=$tds1;
$t.="Number";
$t.=$tde;
$t.=$tds1;
$t.="Type";
$t.=$tde;
$t.=$tds1;
$t.="Name";
$t.=$tde;
$t.=$tds1;
$t.="To";
$t.=$tde;
$t.=$tds1;
$t.="Total";
$t.=$tde;
$t.=$tds1;
$t.="Document Date";
$t.=$tde;
$t.=$tds1;
$t.="User";
$t.=$tde;
$t.=$tds1;
$t.='&nbsp;';
$t.=$tde;
$t.=$tre;
$z="select p.total,p.document_no,p.register_date,p.ecminvoiceout_id from ecmpayments_ecminvoiceouts as p where p.deleted='0' and (".implode(" or ",$invs).") order by p.register_date desc";
$w=$GLOBALS['db']->query($z);
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select id,register_date,parent_name,parent_id, type from ecminvoiceouts where document_no='".$r['document_no']."' and deleted='0' and canceled='0'"));
if(!$rr['register_date'])$rr['register_date']=$r['register_date'];
$rrr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select user_name from users where id='".$rr['assigned_user_id']."'"));
$user=$rrr['user_name'];
if($rr['type']=="correct")$type="Correct";
else $type="Normal";
if(!$rr['name'])$name="blank";
else $name=$rr['name'];
$t.=$trs;
$t.=$tds;
$t.='<a href="index.php?action=DetailView&module=EcmInvoiceOuts&record='.$rr['id'].'">'.$r['document_no'].'</a>';
$t.=$tde;
$t.=$tds;
$t.=$type;
$t.=$tde;
$t.=$tds;
$t.='<a href="index.php?action=DetailView&module=EcmInvoiceOuts&record='.$rr['id'].'">'.$name.'</a>';
$t.=$tde;
$t.=$tds;
$t.='<a href="index.php?action=DetailView&module=Accounts&record='.$rr['parent_id'].'">'.$rr['parent_name'].'</a>';
$t.=$tde;
$t.=$tds;
$t.=number_format($r['total'],2,",",".");
$t.=$tde;
$t.=$tds;
$t.=$GLOBALS['timedate']->to_display_date($rr['register_date']);
$t.=$tde;
$t.=$tds;
$t.=$user;
$t.=$tde;
$t.=$tds;
$t.=Hint($r['ecminvoiceout_id'],$rinv['description']);
$t.=$tde;
$t.=$tre;
$i++;
}
$t.=$tbe;
echo $t;
?>

View File

@@ -0,0 +1 @@
<?php require_once('modules/EcmPaymentStates/javascript/summary_ajax.php');

151
modules/EcmPaymentStates/test.php Executable file
View File

@@ -0,0 +1,151 @@
<?php
$g=$_GET;
?>
<form action="index.php" method="get" name="Search">
<input type="hidden" name="action" value="index" />
<input type="hidden" name="not_matched" value="0" />
<input type="hidden" name="module" value="EcmPaymentStates" />
<script language="javascript">
var OPT=new Array();
OPT['dec_len']=2;
OPT['sep_1000']=".";
OPT['dec_sep']=",";
function formatNumber(number,add) {
if(!number) number = 0;
number = parseFloat(number);
var tmp = number.toFixed(OPT['dec_len']);
var s1 = tmp.substring(0,tmp.length-1-OPT['dec_len']);
var s2 = tmp.substring(tmp.length-OPT['dec_len'],tmp.length);
var tmp = '';
for(var i=s1.length;i>0;i-=3) {
tmp = ((i<=3)?"":OPT['sep_1000'])+s1.substring(i-3,i)+tmp;
}
s1 = tmp;
return (s1+OPT['dec_sep']+s2).toString()+((add)?add:'');
}
function unformatNumber(ufn,add) {
if(add) {
var match = /add/g;
ufn = ufn.replace(match,'');
}
var match = /Err/g;
ufn = ufn.replace(match,'');
if(!ufn) return parseFloat(0);
var pos = ufn.indexOf(OPT['dec_sep']);
var s1='', s2='';
if(pos==-1) { s1 = ufn; s2 = ''; }
else { s1 = ufn.substring(0,pos); s2 = ufn.substring(pos+1,ufn.length); }
var pos = -1;
while((pos = s1.indexOf(OPT['sep_1000'])) != -1)
s1 = s1.substring(0,pos)+s1.substring(pos+1,s1.length);
return parseFloat(s1+"."+s2);
}
function addValue(obj,value,inp){
if(obj.checked==true)inp.innerHTML=formatNumber(parseFloat(unformatNumber(inp.innerHTML))+parseFloat(value));
else inp.innerHTML=formatNumber(parseFloat(unformatNumber(inp.innerHTML))-parseFloat(value));
}
function addValuePayments(obj,value,inp){
var cb=document.getElementById("paymentsList").getElementsByTagName("input");
for(var i=0;i<cb.length;i++){
if(cb[i].type=="checkbox"){
cb[i].checked=false;
}
}
obj.checked=true;
inp.innerHTML=formatNumber(parseFloat(value));
}
</script>
<?php
echo '<table cellspacing="0" cellpadding="0" border="0">';
echo '<tr>';
echo '<td class="listViewThS1" width="10">&nbsp;</td><td class="listViewThS1" width="20">&nbsp;</td><td class="listViewThS1" width="100">Register Date</td><td class="listViewThS1" width="190">Name</td><td class="listViewThS1" width="100">Total</td>';
echo '<td class="listViewThS1" width="10">&nbsp;</td><td class="listViewThS1" width="20">&nbsp;</td><td class="listViewThS1" width="100">Payment Date</td><td class="listViewThS1" width="190">Name</td><td class="listViewThS1" width="100">Value</td>';
echo '</tr>';
echo '<tr valign="top"><td colspan="5"><div style="height:400px;overflow:auto">';
echo '<table cellspacing="0" cellpadding="0" border="0">';
$w=$GLOBALS['db']->query("select p.id,p.document_no,p.paid,p.register_date,p.payment_date,p.total from ecmpayments_ecminvoiceouts as p where p.deleted='0' and p.account_id='134' order by p.register_date desc,p.document_no desc");
// inner join ecmpayments_ecminvoiceouts as p on p.ecminvoiceout_id=e.id
echo mysql_error();
while($r=$GLOBALS['db']->fetchByAssoc($w)){
//if($r['type']!='correct'){
if($r['paid']==0)$paid="&nbsp;";
else $paid="*";
$exp=explode("-",$r['register_date']);
//if($paid=="&nbsp;" && mktime()>mktime(0,0,0,$exp[1],$exp[2],$exp[0])+30*24*3600)$arr+=$r['total'];
echo '<tr><td class="oddListRowS1" width="10"><input type="checkbox" name="check1[]" value="'.$r['id'].'" onclick="addValue(this,'.$r['total'].',document.getElementById(\'total_wn\'));"></td><td class="oddListRowS1" width="10">'.$paid.'</td><td class="oddListRowS1" width="100">'.$r['register_date'].'</td><td class="oddListRowS1" width="220">'.$r['document_no'].'</td><td class="oddListRowS1" width="80">'.$r['total'].'</td></tr>';
//}
$total_wn+=$r['total'];
}
echo '</table></div>';
echo '</td><td colspan="5"><div style="height:400px;overflow:auto">';
echo '<table cellspacing="0" cellpadding="0" border="0">';
$w=$GLOBALS['db']->query("select payment_date,id,description,value,paid from ecmpayments where paid!='18' and deleted='0' and parent_id='134' order by payment_date desc,description desc");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if($r['paid'])$paid="*";
else $paid="&nbsp;";
echo '<tr><td class="oddListRowS1" width="10"><input type="checkbox" name="check2[]" value="'.$r['id'].'" onclick="addValue(this,'.$r['value'].',document.getElementById(\'total_ma\'));"></td><td class="oddListRowS1" width="10">'.$paid.'</td><td class="oddListRowS1" width="100">'.$r['payment_date'].'</td><td class="oddListRowS1" width="220"><a href="index.php?module=EcmPayments&action=DetailView&record='.$r['id'].'">'.$r['description'].'</a></td><td class="oddListRowS1" width="80">'.$r['value'].'</td></tr>';
$total_ma+=$r['value'];
}
echo '</table></div>';
echo '</td></tr></table>';
?>
<table width="943">
<tr>
<td colspan="2" style="font-size: 18px;text-align:center">
<table cellspacing="3" cellpadding="3" border="0" width="100%" style="font-size: 20px; border: 1px solid #cccccc;">
<tr style="font-weight: bold; background: #e6e6e6;">
<td style="text-align: center;">
Summary WN
</td>
<td style="text-align: center;">
Summary
</td>
<td style="text-align: center;">
Summary MA
</td>
</tr>
<tr>
<td style="text-align: center;">
<?php
//$total_wn-=4635096.97;
echo number_format(($total_wn),2,",",".");
?>
</td>
<td style="text-align: center;">
<?php
echo number_format(($total_ma-$total_wn),2,",",".");
?>
</td>
<td style="text-align: center;">
<?php
echo number_format(($total_ma),2,",",".");
?>
</td>
</tr>
<tr style="font-weight: bold; background: #e6e6e6;">
<td style="text-align: center;">&nbsp;
</td>
<td style="text-align: center;">
Actual arrear
</td>
<td style="text-align: center;">&nbsp;
</td>
</tr>
<tr>
<td style="text-align: center;" id="total_wn">0,00
</td>
<td style="text-align: center;">
<?php
echo ($arr);
?>
</td>
<td style="text-align: center;" id="total_ma">0,00
</td>
</tr>
</table><br />
<input type="submit" class="button" value="Match" onclick="document.Search.action.value='Match';" name="match" />&nbsp;
<input type="submit" class="button" value="Show not matched" onclick="document.Search.action.value='index';document.Search.not_matched.value='1';" name="notmatched" />
<input type="submit" class="button" value="Show all" onclick="document.Search.action.value='index';document.Search.not_matched.value='0';" name="matchednotmatched" />
</form>

View File

@@ -0,0 +1,9 @@
<?php
$w=$GLOBALS['db']->query("select id,document_no from ecmsales where date_entered>'2011-01-02'");
$i=0;
while($r=$GLOBALS['db']->fetchByAssoc($w)){
echo '#'.$r['document_no'].'<br>';
echo "update ecmsales set number='20110103".($i+1)."',document_no='ZS 00".($i+1)."/10' where id='".$r['id']."';<br>";
$i++;
}
?>

View File

@@ -0,0 +1,7 @@
<?
$w=$GLOBALS['db']->query("select ecminvoiceout_name,id from ecminvoiceouts where type='correct' and register_date<'2010-01-01' and deleted='0' limit 2500,500");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select id from ecminvoiceouts where document_no='".$r['ecminvoiceout_name']."'"));
echo "update ecminvoiceouts set ecminvoiceout_id='".$rr['id']."' where id='".$r['id']."';<br>";
}
?>

View File

@@ -0,0 +1,43 @@
<?php
function getTotal($id){
$w=$GLOBALS['db']->query("select price,ecmvat_value,quantity from ecminvoiceoutitems where ecminvoiceout_id='".$id."' and deleted='0'");
while($r=$GLOBALS['db']->fetchByAssoc($w))$total+=round($r['price']*$r['quantity']*(1+$r['ecmvat_value']/100),2);
return $total;
}
function getTotalCorrect($id){
$w=$GLOBALS['db']->query("select price,ecmvat_value,quantity,ecminvoiceoutitem_id from ecminvoiceoutitems where ecminvoiceout_id='".$id."'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$total+=round($r['price']*$r['quantity'],2)+round($r['price']*$r['quantity']*$r['ecmvat_value']/100,2);
$rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select price,ecmvat_value,quantity from ecminvoiceoutitems where id='".$r['ecminvoiceoutitem_id']."'"));
$total-=(round($rr['price']*$rr['quantity'],2)+round($rr['price']*$rr['quantity']*$rr['ecmvat_value']/100,2));
}
return $total;
}
$arr="2432,2196,2170,2169,2168,2167,2166";
$e=explode(",",$arr);
foreach($e as $ee){
$wh[]="document_no like 'FVKOR ".$ee."/11'";
}
$where=implode(" or ",$wh);
//$where="register_date>'2011-01-01' and paid='0' and account_id='134' and document_no like 'FVKOR %/11'";
$z="select ecminvoiceout_id,id,total,account_id,document_no from ecmpayments_ecminvoiceouts where (".$where.") and deleted='0'";
echo $z;
$w=$GLOBALS['db']->query($z);
echo mysql_error();
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select id,type,ecminvoiceout_id,document_no,parent_id from ecminvoiceouts where document_no='".$r['document_no']."'"));
if($rr['type']=="correct"){
$total=round(getTotalCorrect($r['ecminvoiceout_id']),2);
}
else{
$total=round(getTotal($r['ecminvoiceout_id']),2);
}
//if($rr['parent_id']==$r['account_id'] && $total==$r['total'] && $rr['id']==$r['ecminvoiceout_id'])continue;
if($total==$r['total'] && $r['total']!=0)continue;
echo "#".$rr['document_no']." ".$r['total']." ".$rr['id']."=".$r['ecminvoiceout_id']."<br>";
echo "update ecmpayments_ecminvoiceouts set total='".$total."' where id='".$r['id']."';<br>";
}
?>

View File

@@ -0,0 +1,18 @@
<?php
include_once("config.php");
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);
mysql_query("set character set utf8;");
mysql_query("SET NAMES 'utf8'");
$zap=mysql_query("select t.id,p.description from ecmtransactions as t
join ecmpayments as p on p.id=t.record_id
where t.record_type='EcmPayments';");
while($dane=mysql_fetch_assoc($zap)){
mysql_query("update ecmtransactions set description='".$dane['description']."' where id='".$dane['id']."'");
}
echo mysql_num_rows($zap);

View File

@@ -0,0 +1,94 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
$dictionary['EcmPaymentState']=array(
'table'=>'ecmpaymentstates',
'audited'=>true,
'comment'=>'EcmPaymentStates',
'duplicate_merge'=>true ,
'unified_search'=>true,
'fields'=>array(
'name'=>array(
'name'=>'name',
'vname'=>'LBL_NAME',
'type'=>'varchar',
'len'=>'255',
),
'value'=>array(
'name'=>'value',
'vname'=>'LBL_VALUE',
'type'=>'decimal',
'len'=>'5,2',
),
),
'indices'=>array(
array('name'=>'idx_ecmpaymentstate_id_del','type'=>'index','fields'=>array('id','deleted')),
array('name'=>'idx_ecmpaymentstate_assigned_del','type'=>'index','fields'=>array( 'deleted', 'assigned_user_id')),
),
'relationships'=>array(
'ecmpaymentstates_assigned_user'=>array(
'lhs_module'=>'Users',
'lhs_table'=>'users',
'lhs_key'=>'id',
'rhs_module'=>'EcmPaymentStates',
'rhs_table'=>'ecmpaymentstates',
'rhs_key'=>'assigned_user_id',
'relationship_type'=>'one-to-many'
),
'ecmpaymentstates_modified_user'=>array(
'lhs_module'=>'Users',
'lhs_table'=>'users',
'lhs_key'=>'id',
'rhs_module'=>'EcmPaymentStates',
'rhs_table'=>'ecmpaymentstates',
'rhs_key'=>'modified_user_id',
'relationship_type'=>'one-to-many'
),
'ecmpaymentstates_created_by'=>array(
'lhs_module'=>'Users',
'lhs_table'=>'users',
'lhs_key'=>'id',
'rhs_module'=>'EcmPaymentStates',
'rhs_table'=>'ecmpaymentstates',
'rhs_key'=>'created_by',
'relationship_type'=>'one-to-many'
)
),
'optimistic_locking'=>true,
);
require_once('include/SugarObjects/VardefManager.php');
VardefManager::createVardef('EcmPaymentStates','EcmPaymentState', array('default','assignable'));
?>