Fix merge issue

This commit is contained in:
sparkyx 2023-12-08 14:00:32 +01:00
commit 98390d4d48
9 changed files with 242 additions and 626 deletions

View file

@ -113,55 +113,18 @@ class Acc_Account_Ledger
}
return array($this->row,$this->tot_deb,$this->tot_cred);
}
/*!
* \brief Get data for accounting entry between 2 date
*
*\param $p_from date from DD.MM.YYYY
*\param $p_to end date DD.MM.YYYY
*\param $let 0 means all rows, 1 only lettered, 2 only unlettered
*\param $solded 0 means all account, 1 means only accounts with a saldo <> 0
*\note the data are filtered by the access of the current user
* \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
* (tot_deb,tot_credit
*
/**
* @brief build the SQL for get_row_data
* @param $p_from date d.m.Y start date
* @param $p_to date d.m.Y until date
* @param $sql_let sql string for getting lettering info
* @param $filter_sql string SQL for filtering the ledgers , to respect security on ledgers
* @return sql SELECT
*/
function get_row_date($p_from,$p_to,$let=0,$solded=0)
function make_sql_accounting_detail($p_from,$p_to,$sql_let,$filter_sql)
{
global $g_user;
$filter_sql=$g_user->get_ledger_sql('ALL',3);
$sql_let='';
switch ($let)
{
case 0:
break;
case 1:
$sql_let=' and j1.j_id in (select j_id from letter_cred union all select j_id from letter_deb)';
break;
case '2':
$sql_let=' and j1.j_id not in (select j_id from letter_cred union all select j_id from letter_deb) ';
break;
}
if ( $solded == 1)
{
$filter=noalyss_str_replace('jrn_def_id','jr_def_id',$filter_sql);
$bal_sql="select sum(amount_deb) as s_deb,sum(amount_cred) as s_cred, j_poste
from
(select case when j_debit='t' then j_montant else 0 end as amount_deb,
case when j_debit='f' then j_montant else 0 end as amount_cred,
j_poste
from jrnx join jrn on (j_grpt = jr_grpt_id)
where
j_poste=$1 and
$filter and
( to_date($2,'DD.MM.YYYY') <= j_date and
to_date($3,'DD.MM.YYYY') >= j_date )) as signed_amount
group by j_poste
";
$r=$this->db->get_array($bal_sql,array($this->id,$p_from,$p_to));
if ( $this->db->count() == 0 ) return array();
if ($r[0]['s_deb']==$r[0]['s_cred']) return array();
}
$this->row=$this->db->get_array("
$sql = "
with sqlletter as (select j_id,jl_id from letter_cred union all select j_id , jl_id from letter_deb )
select j1.j_id,jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,
j_qcode
@ -202,8 +165,44 @@ class Acc_Account_Ledger
( to_date($2,'DD.MM.YYYY') <= j_date and
to_date($3,'DD.MM.YYYY') >= j_date )
and $filter_sql $sql_let
order by j_date,substring(jr_pj_number,'[0-9]+$') asc",array($this->id,$p_from,$p_to));
$res_saldo = $this->db->exec_sql("select sum(deb_montant),sum(cred_montant) from
order by j_date,substring(jr_pj_number,'[0-9]+$') asc";
return $sql;
}
/**
* @brief make the SQL for the balanced accounting
* @param $filter filter to respect the security on ledger
* @return sql SELECT
*/
public function make_sql_not_balanced_account($filter)
{
$bal_sql="select sum(amount_deb) as s_deb,sum(amount_cred) as s_cred, j_poste
from
(select case when j_debit='t' then j_montant else 0 end as amount_deb,
case when j_debit='f' then j_montant else 0 end as amount_cred,
j_poste
from jrnx join jrn on (j_grpt = jr_grpt_id)
where
j_poste=$1 and
$filter and
( to_date($2,'DD.MM.YYYY') <= j_date and
to_date($3,'DD.MM.YYYY') >= j_date )) as signed_amount
group by j_poste
";
return $bal_sql;
}
/**
* @brief make the SQL for the balance of an accounting
* @param $filter_sql filter to respect the security on ledger
* @param $sql_let string for getting lettering info
* @return sql SELECT
*
*/
public function make_sql_saldo_account($filter_sql,$sql_let)
{
$sql_saldo="select sum(deb_montant) as deb,sum(cred_montant) as cred
from
(select case when j_debit='t' then j_montant else 0 end as deb_montant,
case when j_debit='f' then j_montant else 0 end as cred_montant
from jrnx j1
@ -214,14 +213,74 @@ class Acc_Account_Ledger
where j_poste=$1 and
( to_date($2,'DD.MM.YYYY') <= j_date and
to_date($3,'DD.MM.YYYY') >= j_date )
and $filter_sql $sql_let ) as m",array($this->id,$p_from,$p_to));
$this->tot_deb=$this->tot_cred=0;
if ( Database::num_row($res_saldo) > 0 ) {
$this->tot_deb=Database::fetch_result($res_saldo, 0, 0);
$this->tot_cred=Database::fetch_result($res_saldo, 0, 1);
and $filter_sql $sql_let ) as m";
return $sql_saldo;
}
/*!
* \brief Get data for accounting entry between 2 date
*
*\param $p_from date from DD.MM.YYYY
*\param $p_to end date DD.MM.YYYY
*\param $let 0 means all rows, 1 only lettered, 2 only unlettered
*\param $solded 0 means all account, 1 means only accounts with a saldo <> 0
*\note the data are filtered by the access of the current user
* \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
* (tot_deb,tot_credit
*
*/
function get_row_date($p_from, $p_to, $let = 0, $solded = 0)
{
global $g_user;
$filter_sql = $g_user->get_ledger_sql('ALL', 3);
$sql_let = '';
switch ($let) {
case 0:
break;
case 1:
$sql_let = ' and j1.j_id in (select j_id from letter_cred union all select j_id from letter_deb)';
break;
case '2':
$sql_let = ' and j1.j_id not in (select j_id from letter_cred union all select j_id from letter_deb) ';
break;
}
return array($this->row,$this->tot_deb,$this->tot_cred);
// if accounting is balanced , D = C then returns an empty array
if ($solded == 1) {
if ($this->db->is_prepare("not_balanced_account") == false) {
$filter=noalyss_str_replace('jrn_def_id','jr_def_id',$filter_sql);
$sql_balanced = $this->make_sql_not_balanced_account($filter);
$this->db->prepare("not_balanced_account", $sql_balanced);
}
$ret_balanced = $this->db->execute("not_balanced_account", array($this->id, $p_from, $p_to));
$r = Database::fetch_all($ret_balanced);
if (empty($r)) return array();
if ($r[0]['s_deb'] == $r[0]['s_cred']) return array();
}
// get the detail of accouting
if (!$this->db->is_prepare("sql_accounting_detail")) {
$sql = $this->make_sql_accounting_detail($p_from, $p_to, $sql_let, $filter_sql);
$this->db->prepare("sql_accounting_detail", $sql);
}
$ret = $this->db->execute("sql_accounting_detail", array($this->id, $p_from, $p_to));
$this->row = Database::fetch_all($ret);
// $this->row=$this->db->get_array(,array($this->id,$p_from,$p_to));
if ($this->db->is_prepare("saldo_account") == false) {
$sql_saldo = $this->make_sql_saldo_account($filter_sql, $sql_let);
$this->db->prepare("saldo_account", $sql_saldo);
}
$res_saldo = $this->db->execute("saldo_account", array($this->id, $p_from, $p_to));
$result=Database::fetch_all($res_saldo);
$this->tot_deb = $this->tot_cred = 0;
if (! empty($result) > 0) {
$this->tot_deb = $result[0]['deb'];
$this->tot_cred = $result[0]['cred'];
}
return array($this->row, $this->tot_deb, $this->tot_cred);
}
@ -786,5 +845,34 @@ class Acc_Account_Ledger
function filter_history($p_table_id) {
return _('Filtre rapide').' '.HtmlInput::filter_table($p_table_id, '0,1,2,3,4,5,6,7,8,9,10', 1);
}
public static function get_used_accounting($from_date, $to_date, $from_accounting, $to_accounting)
{
// check date
if (isDate($from_date) != $from_date || isDate($to_date) != $to_date) {
return array();
}
// build query
$sql = "select pcm_val,pcm_lib from tmp_pcmn
where pcm_val in
(select j_poste from jrnx where j_date >= to_date('$from_date','DD.MM.YYYY')
and j_date <= to_date('$to_date','DD.MM.YYYY') ) ";
$cond_poste="";
if ($from_accounting != '') {
$cond_poste .= "and pcm_val >= upper ('" . Database::escape_string($from_accounting) . "')";
}
if ($to_accounting != '') {
$cond_poste .= " and pcm_val <= upper ('" . Database::escape_string($to_accounting) . "')";
}
$sql = $sql . $cond_poste . ' order by pcm_val::text';
// get array
$cn=Dossier::connect();
$a_poste = $cn->get_array($sql);
// return array
return $a_poste;
}
}

View file

@ -90,6 +90,12 @@ $g_succeed = "<span style=\"font-size:18px;color:green\">&#x2713;</span>";
define('SMALLX', '#xe816;');
define('BUTTONADD', "&#10010;");
// If noalyss_version is not defined it is likely directly taken from
// git and so this variable is not set, this cause some issue
if (! defined ("NOALYSS_VERSION"))
{
define("NOALYSS_VERSION",9999);
}
define('SVNINFO', NOALYSS_VERSION);
if (!defined('DEBUGNOALYSS')) {
define("DEBUGNOALYSS", 0);

View file

@ -53,33 +53,12 @@ $gDossier=dossier::id();
$cn=Dossier::connect();
$export=new Noalyss_Csv(_('grandlivre'));
$poste_id=$http->get('poste_id',"string","");
$accounting_item_id=$http->get('poste_id',"string","");
$export->send_header();
$cond_poste='';
$sql="select pcm_val from tmp_pcmn ";
if ($from_poste != '')
{
$cond_poste = ' where ';
$cond_poste .=" pcm_val >= upper ('".Database::escape_string($from_poste)."')";
}
if ( $to_poste != '')
{
if ( $cond_poste == '')
{
$cond_poste = " where pcm_val <= upper ('".Database::escape_string($to_poste)."')";
}
else
{
$cond_poste.=" and pcm_val <= upper ('".Database::escape_string($to_poste)."')";
}
}
$a_accounting=Acc_Account_Ledger::get_used_accounting($from_periode,$to_periode,$from_poste,$to_poste);
$sql=$sql.$cond_poste.' order by pcm_val::text';
$a_poste=$cn->get_array($sql);
if ( count($a_poste) == 0 )
if ( count($a_accounting) == 0 )
{
echo _('Aucun résultat');
printf("\n");
@ -92,13 +71,13 @@ $header = array( _("Date"), _("Référence"), _("Libellé"), _("Pièce"),_("Lett
$l=(isset($_GET['letter']))?2:0;
$s=(isset($_REQUEST['solded']))?1:0;
foreach ($a_poste as $poste)
foreach ($a_accounting as $accounting_item)
{
$Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
$acc_account_ledger=new Acc_Account_Ledger($cn,$accounting_item['pcm_val']);
$array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s);
$array1=$acc_account_ledger->get_row_date($from_periode,$to_periode,$l,$s);
// don't print empty account
if ( count($array1) == 0 )
{
@ -114,7 +93,7 @@ foreach ($a_poste as $poste)
continue;
}
$export->add(sprintf("%s - %s ",$Poste->id,$Poste->get_name()));
$export->add(sprintf("%s - %s ",$accounting_item['pcm_val'],$accounting_item['pcm_lib']));
$export->write();
$export->write_header($header);
@ -123,7 +102,7 @@ foreach ($a_poste as $poste)
$solde_c = 0.0;
bcscale(2);
$current_exercice="";
foreach ($Poste->row as $detail)
foreach ($acc_account_ledger->row as $detail)
{
/*
@ -148,7 +127,7 @@ foreach ($a_poste as $poste)
$export->add($current_exercice);
$export->add("");
$export->add("");
$export->add(_('Total')." ".$Poste->id);
$export->add(_('Total')." ".$acc_account_ledger->id);
if ( $solde_d > 0 ) {
$export->add($solde_d,"number");
} else {
@ -200,7 +179,7 @@ foreach ($a_poste as $poste)
else
$export->add("");
$export->add(abs($solde),"number");
$export->add($Poste->get_amount_side($solde),"text");
$export->add($acc_account_ledger->get_amount_side($solde),"text");
$export->write();
}
@ -210,7 +189,7 @@ foreach ($a_poste as $poste)
$export->add($current_exercice);
$export->add("");
$export->add("");
$export->add(_('Total').$Poste->id);
$export->add(_('Total').$acc_account_ledger->id);
if ($solde_d > 0 ) $export->add($solde_d,"number"); else $export->add("");
if ($solde_c > 0 ) $export->add($solde_c,"number"); else $export->add("");
$export->add(abs($solde_c-$solde_d),"number");

View file

@ -41,29 +41,7 @@ $cn=Dossier::connect();
$g_user->Check();
$g_user->check_dossier($gDossier);
$sql="select pcm_val from tmp_pcmn ";
$cond_poste="";
if ($from_poste != '')
{
$cond_poste = ' where ';
$cond_poste .=' pcm_val >= upper (\''.Database::escape_string($from_poste).'\')';
}
if ( $to_poste != '')
{
if ( $cond_poste == '')
{
$cond_poste = ' where pcm_val <= upper (\''.Database::escape_string($to_poste).'\')';
}
else
{
$cond_poste.=' and pcm_val <= upper (\''.Database::escape_string($to_poste).'\')';
}
}
$sql=$sql.$cond_poste.' order by pcm_val::text';
$a_poste=$cn->get_array($sql);
$a_accounting=Acc_Account_Ledger::get_used_accounting($from_periode,$to_periode,$from_poste,$to_poste);
$pdf = new PDF($cn);
$pdf->setDossierInfo(_(" Periode : ").$from_periode." - ".$to_periode);
@ -72,7 +50,7 @@ $pdf->AddPage();
$pdf->setTitle("Grand Livre",true);
$pdf->SetAuthor('NOALYSS');
if ( count($a_poste) == 0 )
if ( count($a_accounting) == 0 )
{
$pdf->Output();
return;
@ -87,13 +65,12 @@ $width = array( 13 , 20 , 60 , 15 , 12 , 20 , 20
$l=(isset($_REQUEST['letter']))?2:0;
$s=(isset($_REQUEST['solded']))?1:0;
foreach ($a_poste as $poste)
foreach ($a_accounting as $accounting_item)
{
$Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
$array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s);
$acc_account_ledger=new Acc_Account_Ledger($cn,$accounting_item['pcm_val']);
$array1=$acc_account_ledger->get_row_date($from_periode,$to_periode,$l,$s);
// don't print empty account
if (empty($array1) || count($array1[0]) == 0 )
{
@ -104,7 +81,7 @@ foreach ($a_poste as $poste)
$tot_cred=$array1[2];
$pdf->SetFont('DejaVuCond','',10);
$Libelle=sprintf("%s - %s ",$Poste->id,$Poste->get_name());
$Libelle=sprintf("%s - %s ",$accounting_item['pcm_val'],$accounting_item['pcm_lib']);
$pdf->write_cell(0, 7, $Libelle, 1, 1, 'C');
$pdf->SetFont('DejaVuCond','',6);
@ -119,7 +96,7 @@ foreach ($a_poste as $poste)
$solde_d = 0.0;
$solde_c = 0.0;
$current_exercice="";
foreach ($Poste->row as $detail)
foreach ($acc_account_ledger->row as $detail)
{
/*
@ -151,7 +128,7 @@ foreach ($a_poste as $poste)
$i++;
$pdf->write_cell($width[$i], 6, '', 0, 0, $lor[$i]);
$i++;
$pdf->write_cell($width[$i], 6, 'Total du compte '.$Poste->id, 0, 0, 'R');
$pdf->write_cell($width[$i], 6, 'Total du compte '.$acc_account_ledger->id, 0, 0, 'R');
$i++;
$pdf->write_cell($width[$i], 6, ($solde_d > 0 ? nbm($solde_d) : ''), 0, 0, $lor[$i]);
$i++;
@ -184,7 +161,7 @@ foreach ($a_poste as $poste)
}
$i = 0;
$side=" ".$Poste->get_amount_side($solde);
$side=" ".$acc_account_ledger->get_amount_side($solde);
$pdf->LongLine($width[$i], 6, shrink_date($detail['j_date_fmt']), 0, $lor[$i]);
$i++;
$pdf->LongLine($width[$i], 6, $detail['jr_internal'], 0, $lor[$i] );
@ -220,7 +197,7 @@ foreach ($a_poste as $poste)
$i++;
$pdf->write_cell($width[$i], 6, '', 0, 0, $lor[$i]);
$i++;
$pdf->write_cell($width[$i], 6, 'Total du compte '.$Poste->id, 0, 0, 'R');
$pdf->write_cell($width[$i], 6, 'Total du compte '.$acc_account_ledger->id, 0, 0, 'R');
$i++;
$pdf->write_cell($width[$i], 6, ($solde_d > 0 ? nbm($solde_d) : ''), 0, 0, $lor[$i]);
$i++;

View file

@ -104,44 +104,29 @@ echo '</div>';
//-----------------------------------------------------
if ( isset( $_REQUEST['bt_html'] ) )
{
if ( DEBUGNOALYSS > 1 ) \Noalyss\Dbg::timer_start();
echo '<div class="content">';
echo Acc_Account_Ledger::HtmlTableHeader("gl_comptes");
echo '</div>';
$sql='select pcm_val from tmp_pcmn ';
$cond_poste='';
try {
$from_periode=$http->request("from_periode","date");
$to_periode=$http->request("to_periode","date");
if ($from_poste->value != '')
{
$cond_poste = ' where ';
$cond_poste .=' pcm_val >= upper (\''.Database::escape_string($from_poste->value).'\')';
}
if ( $to_poste->value != '')
{
if ( $cond_poste == '')
{
$cond_poste = ' where pcm_val <= upper (\''.Database::escape_string($to_poste->value).'\')';
}
else
{
$cond_poste.=' and pcm_val <= upper (\''.Database::escape_string($to_poste->value).'\')';
}
}
$sql=$sql.$cond_poste.' order by pcm_val::text';
$a_poste=$cn->get_array($sql);
if ( sizeof($a_poste) == 0 )
{
die("Nothing here. Strange.");
exit;
}
if ( isDate($_REQUEST['from_periode'])==null || isDate($_REQUEST['to_periode'])==null)
{
} catch (Exception $e) {
echo alert(_('Date malformée, désolée'));
return;
}
$a_accounting=Acc_Account_Ledger::get_used_accounting($from_periode,$to_periode,$from_poste->value,$to_poste->value);
if ( sizeof($a_accounting) == 0 )
{
echo_warning(_("Aucune donnée"));
return;
}
echo '<div class="content">';
@ -150,14 +135,12 @@ if ( isset( $_REQUEST['bt_html'] ) )
$s=(isset($_REQUEST['solded']))?1:0;
foreach ($a_poste as $poste_id )
foreach ($a_accounting as $accounting_id )
{
$Poste=new Acc_Account_Ledger ($cn, $poste_id['pcm_val']);
$Poste->load();
$acc_account_ledger=new Acc_Account_Ledger ($cn, $accounting_id['pcm_val']);
$Poste->get_row_date( $_GET['from_periode'], $_GET['to_periode'],$l,$s);
if ( empty($Poste->row))
$acc_account_ledger->get_row_date( $from_periode, $to_periode,$l,$s);
if ( empty($acc_account_ledger->row))
{
continue;
}
@ -165,7 +148,7 @@ if ( isset( $_REQUEST['bt_html'] ) )
echo '<tr >
<td colspan="8" style="width:auto">
<h2 class="">'. $poste_id['pcm_val'].' '.h($Poste->label).'</h2>
<h2 class="">'. $accounting_id['pcm_val'].' '.h($accounting_id['pcm_lib']).'</h2>
</td>
</tr>';
@ -188,7 +171,7 @@ if ( isset( $_REQUEST['bt_html'] ) )
$i=0;
$current_exercice="";
foreach ($Poste->row as $detail)
foreach ($acc_account_ledger->row as $detail)
{
/*
* separation per exercice
@ -199,7 +182,7 @@ if ( isset( $_REQUEST['bt_html'] ) )
echo '<tr class="highlight">
<td>'.$current_exercice.'</td>
<td>'.''.'</td>
<td>'._("Total du compte").$poste_id['pcm_val'].'</td>
<td>'._("Total du compte").$accounting_id['pcm_val'].'</td>
<td>'.''.'</td>'.td("").
'<td align="right">'.($solde_d > 0 ? nbm( $solde_d) : '').'</td>
<td align="right">'.($solde_c > 0 ? nbm( $solde_c) : '').'</td>
@ -232,7 +215,7 @@ if ( isset( $_REQUEST['bt_html'] ) )
$solde = bcadd($solde,$detail['deb_montant']);
$solde_d = bcadd($solde_d,$detail['deb_montant']);
}
$side="&nbsp;".$Poste->get_amount_side($solde);
$side="&nbsp;".$acc_account_ledger->get_amount_side($solde);
$letter="";
$html_let="";
if ($detail['letter'] > 0) {
@ -256,7 +239,7 @@ if ( isset( $_REQUEST['bt_html'] ) )
echo '<tr class="highlight">
<td>'.$current_exercice.'</td>
<td>'.''.'</td>
<td>'.'<b>'.'Total du compte '.$poste_id['pcm_val'].'</b>'.'</td>
<td>'.'<b>'.'Total du compte '.$accounting_id['pcm_val'].'</b>'.'</td>
<td>'.''.'</td>'.td("").
'<td align="right">'.'<b>'.($solde_d > 0 ? nbm( $solde_d) : '').'</b>'.'</td>
<td align="right">'.'<b>'.($solde_c > 0 ? nbm( $solde_c) : '').'</b>'.'</td>
@ -272,6 +255,8 @@ if ( isset( $_REQUEST['bt_html'] ) )
echo '</table>';
echo Acc_Account_Ledger::HtmlTableHeader("gl_comptes");
echo "</div>";
exit;
if (DEBUGNOALYSS> 1) echo \Noalyss\Dbg::hidden_info("\$acc_account_ledger", $acc_account_ledger);
if ( DEBUGNOALYSS > 1 ) \Noalyss\Dbg::timer_show();
return;
}
?>

View file

@ -767,7 +767,7 @@ class DatabaseCore
static function fetch_all($ret)
{
return pg_fetch_all($ret);
return pg_fetch_all($ret,PGSQL_ASSOC);
}
/**
@ -1024,7 +1024,28 @@ class DatabaseCore
}
}
/**
* @brief clear a prepare stmt
* @see DatabaseCore::is_prepare
* @see DatabaseCore::execute
* @see DatabaseCore::prepare
* @param $sql_name name of the prepare SQL
*/
function clear_prepare($sql_name)
{
pg_exec($this->db,sprintf('DEALLOCATE "%s"'),DatabaseCore::escape_string($sql_name));
}
/**
* @brief clear all prepare stmt
* @see DatabaseCore::is_prepare
* @see DatabaseCore::execute
* @see DatabaseCore::prepare
*/
function clear_all_prepare()
{
pg_exec($this->db,'DEALLOCATE ALL');
}
}
/* test::test_me(); */

View file

@ -134,5 +134,20 @@ EOF;
EOF;
return $r;
}
public static function timer_start()
{
global $timer;
$timer=hrtime(true);
}
public static function timer_show()
{
global $timer;
// $delta=$timer-microtime(true) ;
echo '<span style="font-size:80%;color:navy;background:lightgreen">';
echo _("Temps écoulé : ");
echo (hrtime(true)-$timer)/1e+6;
echo '</span>';
}
}
?>

View file

@ -1,455 +0,0 @@
<?php
use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator on 2014-10-31 at 20:33:22.
*
*/
class Acc_Account_LedgerTest extends TestCase
{
/**
* @var Acc_Account_Ledger
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
*/
protected function setUp():void
{
global $g_connection, $g_parameter, $g_user;
$_REQUEST['gDossier']=DOSSIER;
$g_connection=new Database(DOSSIER);
$g_parameter=new Noalyss_Parameter_Folder($g_connection);
$g_user=new Noalyss_user($g_connection);
$this->object=new Acc_Account_Ledger($g_connection, 400);
$g_connection->exec_sql("update jrn_def set jrn_def_class_deb='4* 2*' where jrn_def_type='ODS'");
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown():void
{
}
/**
* @covers Acc_Account_Ledger::get_row
*/
public function testGet_row()
{
$array=$this->object->get_row(92, 103);
$this->assertEquals(count($array), 3);
}
/**
* @covers Acc_Account_Ledger::get_row_date
*/
public function testGet_row_date()
{
global $g_user, $g_connection;
$accounting=new Acc_Account_Ledger($g_connection, '4511');
$a_array=$accounting->get_row_date('01.01.2018', '31.12.2018', 0);
$expected=array(
0=>
array(
0=>
array(
'j_id'=>'820',
'jr_id'=>'317',
'j_date_fmt'=>'01.01.2018',
'j_date'=>'2018-01-01',
'j_qcode'=>NULL,
'deb_montant'=>'0',
'cred_montant'=>'8.4000',
'description'=>'Ecriture d\'ouverture 2018 TVA à payer 21%',
'jrn_name'=>'Opération Diverses',
'j_debit'=>'f',
'jr_internal'=>'O000172',
'jr_pj_number'=>'ODS44',
'letter'=>NULL,
'pcm_lib'=>'TVA à payer 21%',
'jr_optype'=>'OPE',
'jr_tech_per'=>'92',
'p_exercice'=>'2018',
'jrn_def_name'=>'Opération Diverses',
'jrn_def_code'=>'O01',
'delta_letter'=>NULL,
'currency_rate' => '1.000000',
'currency_rate_ref' => '1.000000',
'currency_id' => '0',
'cr_code_iso' => 'EUR',
'j_montant' => '8.4000',
'oc_amount' => null,
'oc_vat_amount' => null
,'op_analytic' => '0'
),
1=>
array(
'j_id'=>'6',
'jr_id'=>'2',
'j_date_fmt'=>'24.02.2018',
'j_date'=>'2018-02-24',
'j_qcode'=>NULL,
'deb_montant'=>'0',
'cred_montant'=>'8.4000',
'description'=>'Déplacement',
'jrn_name'=>'Vente',
'j_debit'=>'f',
'jr_internal'=>'V000002',
'jr_pj_number'=>'VEN2',
'letter'=>NULL,
'pcm_lib'=>'TVA à payer 21%',
'jr_optype'=>'NOR',
'jr_tech_per'=>'93',
'p_exercice'=>'2018',
'jrn_def_name'=>'Vente',
'jrn_def_code'=>'V01',
'delta_letter'=>NULL,
'currency_rate' => '1.000000'
,'currency_rate_ref' => '1.000000'
,'currency_id' => '0'
,'cr_code_iso' => 'EUR'
,'j_montant' => '8.4000'
,'oc_amount' => null
,'oc_vat_amount' => null
,'op_analytic' => '0'
),
2=>
array(
'j_id'=>'9',
'jr_id'=>'3',
'j_date_fmt'=>'24.02.2018',
'j_date'=>'2018-02-24',
'j_qcode'=>NULL,
'deb_montant'=>'0',
'cred_montant'=>'5.2900',
'description'=>'Vente de marchandises',
'jrn_name'=>'Vente',
'j_debit'=>'f',
'jr_internal'=>'V000003',
'jr_pj_number'=>'VEN3',
'letter'=>NULL,
'pcm_lib'=>'TVA à payer 21%',
'jr_optype'=>'NOR',
'jr_tech_per'=>'93',
'p_exercice'=>'2018',
'jrn_def_name'=>'Vente',
'jrn_def_code'=>'V01',
'delta_letter'=>NULL,
'currency_rate' => '1.000000'
,'currency_rate_ref' => '1.000000'
,'currency_id' => '0'
,'cr_code_iso' => 'EUR'
,'j_montant' => '5.2900'
,'oc_amount' => null
,'oc_vat_amount' => null
,'op_analytic' => '0'
),
3=>
array(
'j_id'=>'13',
'jr_id'=>'4',
'j_date_fmt'=>'24.02.2018',
'j_date'=>'2018-02-24',
'j_qcode'=>NULL,
'deb_montant'=>'0',
'cred_montant'=>'35.7400',
'description'=>'Vente de marchandises',
'jrn_name'=>'Vente',
'j_debit'=>'f',
'jr_internal'=>'V000004',
'jr_pj_number'=>'VEN4',
'letter'=>NULL,
'pcm_lib'=>'TVA à payer 21%',
'jr_optype'=>'NOR',
'jr_tech_per'=>'93',
'p_exercice'=>'2018',
'jrn_def_name'=>'Vente',
'jrn_def_code'=>'V01',
'delta_letter'=>NULL,
'currency_rate' => '1.000000',
'currency_rate_ref' => '1.000000',
'currency_id' => '0',
'cr_code_iso' => 'EUR',
'j_montant' => '35.7400',
'oc_amount' => null,
'oc_vat_amount' => null
,'op_analytic' => '0'
),
4=>
array(
'j_id'=>'17',
'jr_id'=>'5',
'j_date_fmt'=>'24.04.2018',
'j_date'=>'2018-04-24',
'j_qcode'=>NULL,
'deb_montant'=>'0',
'cred_montant'=>'35.7400',
'description'=>'Marchandise et Déplacement',
'jrn_name'=>'Vente',
'j_debit'=>'f',
'jr_internal'=>'V000005',
'jr_pj_number'=>'VEN5',
'letter'=>NULL,
'pcm_lib'=>'TVA à payer 21%',
'jr_optype'=>'NOR',
'jr_tech_per'=>'95',
'p_exercice'=>'2018',
'jrn_def_name'=>'Vente',
'jrn_def_code'=>'V01',
'delta_letter'=>NULL,
'currency_rate' => '1.000000',
'currency_rate_ref' => '1.000000',
'currency_id' => '0',
'cr_code_iso' => 'EUR',
'j_montant' => '35.7400',
'oc_amount' => null,
'oc_vat_amount' => null
,'op_analytic' => '0'
),
5=>
array(
'j_id'=>'818',
'jr_id'=>'316',
'j_date_fmt'=>'12.09.2018',
'j_date'=>'2018-09-12',
'j_qcode'=>NULL,
'deb_montant'=>'0',
'cred_montant'=>'21.0000',
'description'=>'Vente en OD TVA à payer 21%',
'jrn_name'=>'Opération Diverses',
'j_debit'=>'f',
'jr_internal'=>'O000171',
'jr_pj_number'=>'ODS43',
'letter'=>NULL,
'pcm_lib'=>'TVA à payer 21%',
'jr_optype'=>'NOR',
'jr_tech_per'=>'100',
'p_exercice'=>'2018',
'jrn_def_name'=>'Opération Diverses',
'jrn_def_code'=>'O01',
'delta_letter'=>NULL,
'currency_rate' => '1.000000',
'currency_rate_ref' => '1.000000',
'currency_id' => '0',
'cr_code_iso' => 'EUR',
'j_montant' => '21.0000',
'oc_amount' => null,
'oc_vat_amount' => null
,'op_analytic' => '0'
),
),
1=>'0',
2=>'114.5700',
);
$this->assertEquals($expected, $a_array);
}
function dataGet_Name()
{
return array(
array('10', 'Capital '),
array('01', 'Poste inconnu')
);
}
/**
* @covers Acc_Account_Ledger::get_name
* @dataProvider dataGet_Name
*/
public function testGet_name($id, $result)
{
$this->object->id=$id;
$this->assertEquals($this->object->get_name(), $result);
}
/**
* @covers Acc_Account_Ledger::do_exist
* @dataProvider dataDo_exist
*/
public function testDo_exist($p_value, $result)
{
$this->object->id=$p_value;
$this->assertEquals($this->object->do_exist(), $result);
}
function dataDo_exist()
{
return array(
array('400', 1),
array('400A', 0),
array('550', 1),
array('60BXX', 0)
);
}
/**
* @covers Acc_Account_Ledger::load
*/
public function testLoad()
{
$this->object->load();
$this->assertTrue($this->object->id==400, "test load");
}
/**
* @covers Acc_Account_Ledger::get_solde
*/
public function testGet_solde()
{
global $g_connection;
$accounting=new Acc_Account_Ledger($g_connection, '4511');
$this->assertEquals(356.85,$accounting->get_solde(),"get_solde");
}
/**
* @covers Acc_Account_Ledger::get_solde_detail
*/
public function testGet_solde_detail()
{
global $g_connection;
$accounting=new Acc_Account_Ledger($g_connection, '4511');
$expected=array (
'debit' => '0',
'credit' => '356.8500',
'solde' => 356.85,
);
$this->assertEquals($accounting->get_solde_detail(),$expected);
}
/**
* @covers Acc_Account_Ledger::isTVA
*/
public function testIsTVA()
{
$this->object->id="4111";
$this->assertEquals($this->object->isTVA(), 1);
$this->object->id=10;
$this->assertEquals($this->object->isTVA(), 0);
}
/**
* @covers Acc_Account_Ledger::HtmlTable
*/
public function testHtmlTable()
{
$this->assertTrue(true, 'Ne peut être testé car vue HTML');
}
public function dataGet_amount_side()
{
return array(
array(0, "="),
array(1000, 'D'),
array(-1000, 'C'),
);
}
/**
* @covers Acc_Account_Ledger::get_amount_side
* @dataProvider dataGet_amount_side
*/
public function testGet_amount_side($amount, $result)
{
$this->assertEquals($this->object->get_amount_side($amount), $result);
}
/**
* @covers Acc_Account_Ledger::belong_ledger
* @dataProvider DataBelong_ledger
*/
public function testBelong_ledger($p_jrn, $result)
{
$this->assertEquals($this->object->belong_ledger($p_jrn), $result);
}
function DataBelong_ledger()
{
return array(
array(-1, 0),
array(1, -1),
array(3, 0),
array(2, -1),
array(4, 0)
);
}
public function dataGet_account_ledger()
{
return array(
array(0, array()),
array(1, array()),
array(2, array()),
array(3, array()),
array(4, array('4*','2*'))
);
}
/**
* @covers Acc_Account_Ledger::get_account_ledger
* @dataProvider dataGet_account_ledger
*/
public function testGet_account_ledger($p_jrn, $result)
{
$this->assertEquals($this->object->get_account_ledger($p_jrn), $result);
}
/**
* @covers Acc_Account_Ledger::build_sql_account
* @dataProvider DataBuild_Sql_account
*/
public function testBuild_sql_account($p_jrn, $result)
{
$value=$this->object->build_sql_account($p_jrn);
$this->assertEquals(trim($value), $result);
}
public function DataBuild_Sql_account()
{
return array(
array(0, ""),
array(1, ""),
array(2, ""),
array(3, ""),
array(4, "pcm_val::text like '4%' or pcm_val::text like '2%'")
);
}
function dataFind_Card()
{
return array(
array('6191', '27'),
array('6192', '28'),
array('4400004', '25')
);
}
/**
* @covers Acc_Account_Ledger::find_card
* @todo Implement testFind_card().
* @dataProvider dataFind_Card()
*/
public function testFind_card($p_value, $p_card)
{
$this->object->id=$p_value;
$result=$this->object->find_card();
$this->assertEquals($p_card, $result[0]['f_id']);
}
}

View file

@ -9,15 +9,15 @@ help(){
}
cd `dirname $0`
export XDEBUG_MODE=off
CUR_DIR=`pwd`
PHPUNIT=$CUR_DIR/phpunit
FILETOTEST=""
FUNCTION=""
COVERAGE=""
FOLDERTEST=""
#PHPINI="/usr/bin/php"
PHPINI="/usr/bin/php "
PHPINI="/opt/php/8.1/bin/php"
#PHPINI="/usr/bin/php "
while getopts "f:i:cd:x" opt; do
case $opt in
d)