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,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;
}
}
?>