From ef108c2fc830886a62d32710b6a4cc8c33211fcc Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 3 Nov 2019 10:02:22 +0100 Subject: [PATCH 01/23] TEST : bug double usage of use --- unit-test/include/class/dossierTest.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/unit-test/include/class/dossierTest.class.php b/unit-test/include/class/dossierTest.class.php index d4de0742d..21650b14c 100644 --- a/unit-test/include/class/dossierTest.class.php +++ b/unit-test/include/class/dossierTest.class.php @@ -1,6 +1,5 @@ Date: Sat, 9 Nov 2019 19:33:14 +0100 Subject: [PATCH 02/23] Task #0001762: TVA France , add the possibility to compute VAT at the date of operation , payment. PRINTTVA : Add feature summary of VAT depending of operation date, payment date or VAT setting --- include/class/tax_summary.class.php | 355 +++++---- include/class/tva_rate_mtable.class.php | 19 +- include/constant.php | 2 +- include/database/tva_rate_sql.class.php | 5 + include/database/v_tva_rate_sql.class.php | 5 + include/export/export_printtva_csv.php | 3 + include/export/export_printtva_pdf.php | 2 + include/lib/message_javascript.php | 1 + include/sql/patch/upgrade138.sql | 36 + include/tax_summary.inc.php | 10 + .../data/tax_summary_getrow_purchase_o.php | 199 ++++++ .../data/tax_summary_getrow_purchase_p.php | 48 ++ .../data/tax_summary_getrow_purchase_t.php | 183 +++++ .../class/data/tax_summary_getrow_sale_o.php | 63 ++ .../class/data/tax_summary_getrow_sale_p.php | 28 + .../class/data/tax_summary_getrow_sale_t.php | 64 ++ .../tax_summary_getsummary_purchase_o.php | 130 ++++ .../tax_summary_getsummary_purchase_p.php | 31 + .../tax_summary_getsummary_purchase_t.php | 116 +++ .../data/tax_summary_getsummary_sale_o.php | 48 ++ .../data/tax_summary_getsummary_sale_p.php | 26 + .../data/tax_summary_getsummary_sale_t.php | 48 ++ .../include/class/tax_summaryTest.class.php | 674 ++++-------------- 23 files changed, 1435 insertions(+), 661 deletions(-) create mode 100644 include/sql/patch/upgrade138.sql create mode 100644 unit-test/include/class/data/tax_summary_getrow_purchase_o.php create mode 100644 unit-test/include/class/data/tax_summary_getrow_purchase_p.php create mode 100644 unit-test/include/class/data/tax_summary_getrow_purchase_t.php create mode 100644 unit-test/include/class/data/tax_summary_getrow_sale_o.php create mode 100644 unit-test/include/class/data/tax_summary_getrow_sale_p.php create mode 100644 unit-test/include/class/data/tax_summary_getrow_sale_t.php create mode 100644 unit-test/include/class/data/tax_summary_getsummary_purchase_o.php create mode 100644 unit-test/include/class/data/tax_summary_getsummary_purchase_p.php create mode 100644 unit-test/include/class/data/tax_summary_getsummary_purchase_t.php create mode 100644 unit-test/include/class/data/tax_summary_getsummary_sale_o.php create mode 100644 unit-test/include/class/data/tax_summary_getsummary_sale_p.php create mode 100644 unit-test/include/class/data/tax_summary_getsummary_sale_t.php diff --git a/include/class/tax_summary.class.php b/include/class/tax_summary.class.php index 933751621..afc9f33ca 100644 --- a/include/class/tax_summary.class.php +++ b/include/class/tax_summary.class.php @@ -1,4 +1,5 @@ db=$db; $this->set_date_start($p_start); $this->set_date_end($p_end); + // By default the TVA is computed by parameter in tva_rate.tva_payment_purchase or tva_rate.tva_payment_sale + $this->set_tva_type("T"); + } + + public function get_tva_type() + { + return $this->tva_type; + } + + public function set_tva_type($tva_type) + { + $this->tva_type=$tva_type; + return $this; } /** @@ -53,7 +69,7 @@ class Tax_Summary */ public function set_db($db) { - $this->db = $db; + $this->db=$db; return $this; } @@ -71,8 +87,9 @@ class Tax_Summary */ public function set_date_start($date_start) { - if (isDate($date_start) == NULL) throw Exception(_("Format date invalide") . $date_start); - $this->date_start = $date_start; + if (isDate($date_start)==NULL) + throw Exception(_("Format date invalide").$date_start); + $this->date_start=$date_start; return $this; } @@ -90,8 +107,9 @@ class Tax_Summary */ public function set_date_end($date_end) { - if (isDate($date_end) == NULL) throw Exception(_("Format date invalide") . $date_end); - $this->date_end = $date_end; + if (isDate($date_end)==NULL) + throw Exception(_("Format date invalide").$date_end); + $this->date_end=$date_end; return $this; } @@ -101,7 +119,7 @@ class Tax_Summary */ function check() { - /*-------------SALE ---------------------------------*/ + /* -------------SALE --------------------------------- */ $sql="select count(*) from quant_sold @@ -113,11 +131,12 @@ class Tax_Summary and j_date <= to_date($2,'DD.MM.YYYY') ) "; - $cnt=$this->db->get_value($sql,[$this->date_start,$this->date_end]); - if ($cnt == 0) { - throw new Exception(_("Données manquantes"),100); + $cnt=$this->db->get_value($sql, [$this->date_start, $this->date_end]); + if ($cnt==0) + { + throw new Exception(_("Données manquantes"), 100); } - /*-------------Purchase ---------------------------------*/ + /* -------------Purchase --------------------------------- */ $sql="select count(*) from quant_purchase @@ -129,65 +148,33 @@ class Tax_Summary and j_date <= to_date($2,'DD.MM.YYYY') ) "; - $cnt=$this->db->get_value($sql,[$this->date_start,$this->date_end]); - if ($cnt > 0) { - throw new Exception(_("Données manquantes"),100); + $cnt=$this->db->get_value($sql, [$this->date_start, $this->date_end]); + if ($cnt>0) + { + throw new Exception(_("Données manquantes"), 100); } } - - /** - * Total for each sales ledger - * @return array - */ - function get_row_sale() + private function build_exigibility() { global $g_user; - $sql_ledger=$g_user->get_ledger_sql('ALL',3); - $sql="with detail_tva as ( - select - sum(qs_vat) as amount_vat, - sum(qs_vat_sided) as amount_sided, - sum(qs_price) as amount_wovat, - qs_vat_code, - j_jrn_def - from - quant_sold - join tva_rate on (qs_vat_code=tva_rate.tva_id) - join jrnx on (quant_sold.j_id=jrnx.j_id) - join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def) - where - j_date >= to_date($1,'DD.MM.YYYY') - and j_date <= to_date($2,'DD.MM.YYYY') - and {$sql_ledger} - group by j_jrn_def,qs_vat_code) - select jrn_def_name, - tva_label , - qs_vat_code, - tva_rate, - tva_both_side, - amount_vat, - amount_wovat, - amount_sided - from - detail_tva - join tva_rate on (tva_rate.tva_id=qs_vat_code) - join jrn_def on (jrn_def.jrn_def_id=j_jrn_def) - - order by jrn_def_name,tva_label"; - $array=$this->db->get_array($sql,[$this->date_start,$this->date_end]); - return $array; - + $sql_ledger=$g_user->get_ledger_sql('ALL', 3); + } - - /** - * Total for each purchase ledger - * @return array + * Build the SQL for sale vat + * @return string + * */ - function get_row_purchase() + private function build_sql_purchase($p_group_ledger) { global $g_user; - $sql_ledger=$g_user->get_ledger_sql('ALL',3); + $sql_ledger=$g_user->get_ledger_sql('ACH', 3); + $group_ledger=""; + if ( $p_group_ledger ) + { + $group_ledger='j_jrn_def,'; + } + $sql="with detail_tva as ( select sum(qp_vat) as amount_vat, @@ -197,18 +184,163 @@ class Tax_Summary sum(qp_nd_tva) as amount_noded_tax, sum(qp_nd_tva_recup) as amount_noded_return, sum(qp_dep_priv) as amount_private, - qp_vat_code, - j_jrn_def + {$group_ledger} + qp_vat_code from quant_purchase join tva_rate on (qp_vat_code=tva_rate.tva_id) join jrnx on (quant_purchase.j_id=jrnx.j_id) join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def) + join jrn on (jrn.jr_grpt_id=jrnx.j_grpt) + "; + if ( $this->tva_type=="O") + { + $sql=$sql." where j_date >= to_date($1,'DD.MM.YYYY') and j_date <= to_date($2,'DD.MM.YYYY') and {$sql_ledger} - group by j_jrn_def,qp_vat_code) + group by {$group_ledger} qp_vat_code) "; + } elseif ($this->tva_type=="P") { + $sql=$sql." + where + coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >= + to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD') + and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <= + to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD') + and {$sql_ledger} + group by {$group_ledger} qp_vat_code) "; + }elseif ($this->tva_type=="T") { + $sql=$sql." where + ( tva_rate.tva_payment_purchase='P' + and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >= + to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD') + and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <= + to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD') + ) + or + ( tva_rate.tva_payment_purchase='O' + and coalesce(to_char(jr_date,'YYYYMMDD'),'00000000') >= + to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD') + and coalesce(to_char(jr_date,'YYYYMMDD'),'99999999') <= + to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD') + ) + and {$sql_ledger} + group by {$group_ledger} qp_vat_code) "; + + } else { + throw new Exception(_("Exig TVA invalide"),1001); + } + return $sql; + } + /** + * Build the SQL for sale vat + * + * @param group by ledger + * + * @return string + * + */ + private function build_sql_sale($p_group_ledger=TRUE) + { + global $g_user; + $sql_ledger=$g_user->get_ledger_sql('VEN', 3); + $group_ledger=""; + if ( $p_group_ledger ) + { + $group_ledger='j_jrn_def,'; + } + $sql="with detail_tva as ( + select + sum(qs_vat) as amount_vat, + sum(qs_vat_sided) as amount_sided, + sum(qs_price) as amount_wovat, + {$group_ledger} + qs_vat_code + from + quant_sold + join tva_rate on (qs_vat_code=tva_rate.tva_id) + join jrnx on (quant_sold.j_id=jrnx.j_id) + join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def) + join jrn on (jrn.jr_grpt_id=jrnx.j_grpt)"; + if ( $this->tva_type=="O") + { + $sql=$sql." + where + j_date >= to_date($1,'DD.MM.YYYY') + and j_date <= to_date($2,'DD.MM.YYYY') + and {$sql_ledger} + group by {$group_ledger} qs_vat_code) "; + + } elseif ($this->tva_type=="P") { + $sql=$sql." + where + coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >= + to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD') + and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <= + to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD') + and {$sql_ledger} + group by {$group_ledger} qs_vat_code) "; + + } elseif ($this->tva_type=="T") { + $sql=$sql." + where + ( tva_rate.tva_payment_sale='P' + and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >= + to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD') + and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <= + to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD') + ) + or + ( tva_rate.tva_payment_sale='O' + and coalesce(to_char(jr_date,'YYYYMMDD'),'00000000') >= + to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD') + and coalesce(to_char(jr_date,'YYYYMMDD'),'99999999') <= + to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD') + ) + and {$sql_ledger} + group by {$group_ledger} qs_vat_code) + "; + } + else { + throw new Exception(_("Exig TVA invalide"),1001); + } + return $sql; + } + /** + * Total for each sales ledger + * @return array + */ + function get_row_sale() + { + $sql=$this->build_sql_sale(TRUE); + $sql.=" + select jrn_def_name, + tva_label , + qs_vat_code, + tva_rate, + tva_both_side, + amount_vat, + amount_wovat, + amount_sided, + tva_payment_sale as tva_type + from + detail_tva + join tva_rate on (tva_rate.tva_id=qs_vat_code) + join jrn_def on (jrn_def.jrn_def_id=j_jrn_def) + order by jrn_def_name,tva_label"; + + $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]); + return $array; + } + + /** + * Total for each purchase ledger + * @return array + */ + function get_row_purchase() + { + $sql=$this->build_sql_purchase(TRUE)." select jrn_def_name, tva_label , tva_rate, @@ -226,7 +358,7 @@ class Tax_Summary join tva_rate on (tva_rate.tva_id=qp_vat_code) join jrn_def on (jrn_def.jrn_def_id=j_jrn_def) order by jrn_def_name,tva_label"; - $array=$this->db->get_array($sql,[$this->date_start,$this->date_end]); + $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]); return $array; } @@ -235,66 +367,31 @@ class Tax_Summary */ function get_summary_sale() { - global $g_user; - $sql_ledger=$g_user->get_ledger_sql('ALL',3); - $sql="with detail_tva as ( - select - sum(qs_vat) as amount_vat, - sum(qs_vat_sided) as amount_sided, - sum(qs_price) as amount_wovat, - qs_vat_code - from - quant_sold - join tva_rate on (qs_vat_code=tva_rate.tva_id) - join jrnx on (quant_sold.j_id=jrnx.j_id) - join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def) - where - j_date >= to_date($1,'DD.MM.YYYY') - and j_date <= to_date($2,'DD.MM.YYYY') - and {$sql_ledger} - group by qs_vat_code) - select - tva_label , - qs_vat_code, - tva_rate, + $sql=$this->build_sql_sale(FALSE); + $sql.="select + tva_label , + qs_vat_code, + tva_rate, tva_both_side, - amount_vat, - amount_wovat, - amount_sided - from - detail_tva - join tva_rate on (tva_rate.tva_id=qs_vat_code) + amount_vat, + amount_wovat, + amount_sided, + tva_rate.tva_payment_sale + from + detail_tva + join tva_rate on (tva_rate.tva_id=qs_vat_code) order by tva_label"; - $array=$this->db->get_array($sql,[$this->date_start,$this->date_end]); + $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]); return $array; } + /** * Summary for all purchase ledger */ function get_summary_purchase() { - global $g_user; - $sql_ledger=$g_user->get_ledger_sql('ALL',3); - $sql="with detail_tva as ( - select - sum(qp_vat) as amount_vat, - sum(qp_vat_sided) as amount_sided, - sum(qp_price) as amount_wovat, - sum(qp_nd_amount) as amount_noded_amount, - sum(qp_nd_tva) as amount_noded_tax, - sum(qp_nd_tva_recup) as amount_noded_return, - sum(qp_dep_priv) as amount_private, - qp_vat_code - from - quant_purchase - join tva_rate on (qp_vat_code=tva_rate.tva_id) - join jrnx on (quant_purchase.j_id=jrnx.j_id) - join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def) - where - j_date >= to_date($1,'DD.MM.YYYY') - and j_date <= to_date($2,'DD.MM.YYYY') - and {$sql_ledger} - group by qp_vat_code) + + $sql=$this->build_sql_purchase(FALSE)." select tva_label , tva_rate, @@ -311,10 +408,11 @@ class Tax_Summary detail_tva join tva_rate on (tva_rate.tva_id=qp_vat_code) order by tva_label"; - $array=$this->db->get_array($sql,[$this->date_start,$this->date_end]); + $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]); return $array; } + /** * @brief display the summary of VAT in the range of date */ @@ -322,6 +420,7 @@ class Tax_Summary { require_once NOALYSS_INCLUDE."/template/tax_summary_display.php"; } + /** * @brief display a form to export in CSV * @see export_printtva_csv.php @@ -330,11 +429,12 @@ class Tax_Summary { echo '
'; echo Dossier::hidden(); - echo HtmlInput::hidden("act",'CSV:printtva'); - echo HtmlInput::hidden("date_start",$this->date_start); - echo HtmlInput::hidden("date_end",$this->date_end); + echo HtmlInput::hidden("act", 'CSV:printtva'); + echo HtmlInput::hidden("date_start", $this->date_start); + echo HtmlInput::hidden("date_end", $this->date_end); + echo HtmlInput::hidden("tva_type", $this->tva_type); - echo HtmlInput::submit("CSV:printtva",_("Export CSV")); + echo HtmlInput::submit("CSV:printtva", _("Export CSV")); echo '
'; } @@ -346,13 +446,12 @@ class Tax_Summary { echo '
'; echo Dossier::hidden(); - echo HtmlInput::hidden("act",'PDF:printtva'); - echo HtmlInput::hidden("date_start",$this->date_start); - echo HtmlInput::hidden("date_end",$this->date_end); - - echo HtmlInput::submit("PDF:printtva",_("Export PDF")); + echo HtmlInput::hidden("act", 'PDF:printtva'); + echo HtmlInput::hidden("date_start", $this->date_start); + echo HtmlInput::hidden("date_end", $this->date_end); + echo HtmlInput::hidden("tva_type", $this->tva_type); + echo HtmlInput::submit("PDF:printtva", _("Export PDF")); echo '
'; } - } diff --git a/include/class/tva_rate_mtable.class.php b/include/class/tva_rate_mtable.class.php index 6e21d10e4..4ffba15ac 100644 --- a/include/class/tva_rate_mtable.class.php +++ b/include/class/tva_rate_mtable.class.php @@ -57,7 +57,22 @@ class Tva_Rate_MTable extends Manage_Table_SQL ["value"=>1, "label"=>_("Autoliquidation")] )); $this->set_property_updatable("tva_id", FALSE); - $this->a_info=["tva_purchase"=>44,"tva_both_side"=>43,"tva_sale"=>45]; + $this->set_col_label("tva_payment_purchase",_("Exigible achat")); + $this->set_col_type("tva_payment_purchase","select", + array( + array("value"=>'O',"label"=>"Opération"), + array("value"=>'P',"label"=>"Paiement") + ) + ); + $this->set_col_label("tva_payment_sale",_("Exigible vente")); + $this->set_col_type("tva_payment_sale","select", + array( + array("value"=>'O',"label"=>"Opération"), + array("value"=>'P',"label"=>"Paiement") + ) + ); + $this->a_info=["tva_purchase"=>44,"tva_both_side"=>43,"tva_sale"=>45 + ,"tva_payment_sale"=>74,"tva_payment_purchase"=>74]; } /** @@ -183,6 +198,8 @@ class Tva_Rate_MTable extends Manage_Table_SQL $tva_purchase=(trim($this->table->tva_purchase)=="")?"#":$this->table->tva_purchase; $tva_sale=(trim($this->table->tva_sale)=="")?"#":$this->table->tva_sale; $tva_rate->setp("tva_poste", $tva_purchase.",".$tva_sale); + $tva_rate->setp("tva_payment_sale", $this->table->tva_payment_sale); + $tva_rate->setp("tva_payment_purchase", $this->table->tva_payment_purchase); $tva_rate->save(); // reload the row diff --git a/include/constant.php b/include/constant.php index cb856c36b..5d0fc867e 100644 --- a/include/constant.php +++ b/include/constant.php @@ -108,7 +108,7 @@ if ( !defined ("NOALYSS_PACKAGE_REPOSITORY")) { if ( ! defined ("SYSINFO_DISPLAY")) { define ("SYSINFO_DISPLAY",TRUE); } -define ("DBVERSION",138); +define ("DBVERSION",139); define ("MONO_DATABASE",25); define ("DBVERSIONREPO",18); define ('NOTFOUND','--not found--'); diff --git a/include/database/tva_rate_sql.class.php b/include/database/tva_rate_sql.class.php index da6c95c55..f23d98b52 100644 --- a/include/database/tva_rate_sql.class.php +++ b/include/database/tva_rate_sql.class.php @@ -45,6 +45,8 @@ class Tva_rate_SQL extends Noalyss_SQL , "tva_comment"=>"tva_comment" , "tva_poste"=>"tva_poste" , "tva_both_side"=>"tva_both_side" + ,"tva_payment_purchase"=>"tva_payment_purchase" + ,"tva_payment_sale"=>"tva_payment_sale" ); /* * Type of columns @@ -56,6 +58,9 @@ class Tva_rate_SQL extends Noalyss_SQL , "tva_comment"=>"text" , "tva_poste"=>"text" , "tva_both_side"=>"numeric" + ,"tva_payment_purchase"=>"text" + ,"tva_payment_sale"=>"text" + ); diff --git a/include/database/v_tva_rate_sql.class.php b/include/database/v_tva_rate_sql.class.php index 701bdc3ea..19c63fe3c 100644 --- a/include/database/v_tva_rate_sql.class.php +++ b/include/database/v_tva_rate_sql.class.php @@ -46,6 +46,9 @@ class V_Tva_Rate_SQL extends Noalyss_SQL , "tva_purchase"=>"tva_purchase" , "tva_sale"=>"tva_sale" , "tva_both_side"=>"tva_both_side" + ,'tva_payment_purchase'=>'tva_payment_purchase' + ,'tva_payment_sale'=>'tva_payment_sale' + ); /* * Type of columns @@ -58,6 +61,8 @@ class V_Tva_Rate_SQL extends Noalyss_SQL , "tva_purchase"=>"text" , "tva_sale"=>"text" , "tva_both_side"=>"numeric" + , 'tva_payment_purchase'=>'text' + , 'tva_payment_sale'=>'text' ); diff --git a/include/export/export_printtva_csv.php b/include/export/export_printtva_csv.php index ebe8ddde4..b5c75196d 100644 --- a/include/export/export_printtva_csv.php +++ b/include/export/export_printtva_csv.php @@ -30,6 +30,9 @@ require_once NOALYSS_INCLUDE."/class/tax_summary.class.php"; require_once NOALYSS_INCLUDE."/lib/noalyss_csv.class.php"; $http=new HttpInput(); $tax_summary = new Tax_Summary($cn,$http->get("date_start"),$http->get("date_end")); +$tva_type = $http->request("tva_type"); +$tax_summary->set_tva_type($tva_type); + try { $tax_summary->check(); }catch (Exception $e) diff --git a/include/export/export_printtva_pdf.php b/include/export/export_printtva_pdf.php index 028db71e2..19203c331 100644 --- a/include/export/export_printtva_pdf.php +++ b/include/export/export_printtva_pdf.php @@ -34,6 +34,7 @@ $http = new HttpInput(); $from_periode = $http->request("date_start"); $to_periode = $http->request("date_end"); +$tva_type = $http->request("tva_type"); $gDossier = dossier::id(); @@ -41,6 +42,7 @@ $gDossier = dossier::id(); /* Security */ $cn = Dossier::connect(); $tax_summary = new Tax_Summary($cn, $from_periode, $to_periode); +$tax_summary->set_tva_type($tva_type); $pdf = new PDFLand($cn); $pdf->setDossierInfo(sprintf(_("Date") . " : %s %s", $from_periode, $to_periode)); $pdf->AliasNbPages(); diff --git a/include/lib/message_javascript.php b/include/lib/message_javascript.php index 9333a2dd2..fb03d36b2 100644 --- a/include/lib/message_javascript.php +++ b/include/lib/message_javascript.php @@ -104,4 +104,5 @@ content[70]=""; content[72]=""; content[73]=""; +content[74]=""; \ No newline at end of file diff --git a/include/sql/patch/upgrade138.sql b/include/sql/patch/upgrade138.sql new file mode 100644 index 000000000..f7e341f99 --- /dev/null +++ b/include/sql/patch/upgrade138.sql @@ -0,0 +1,36 @@ +begin; +ALTER TABLE public.tva_rate ADD tva_payment_sale char(1) NULL DEFAULT 'O'; +update public.tva_rate set tva_payment_sale='O'; +ALTER TABLE public.tva_rate ADD CONSTRAINT tva_rate_sale_check CHECK (tva_payment in ('O','P')); +comment on column public.tva_rate.tva_payment_sale is 'Check if the VAT on Sale must be declared when at the date of payment (P) or the date of operation (O)'; + + +ALTER TABLE public.tva_rate ADD tva_payment_purchase char(1) NULL DEFAULT 'O'; +update public.tva_rate set tva_payment_purchase='O'; +ALTER TABLE public.tva_rate ADD CONSTRAINT tva_rate_purchase_check CHECK (tva_payment in ('O','P')); +comment on column public.tva_rate.tva_payment_purchase is 'Check if the VAT on Purchase must be declared when at the date of payment (P) or the date of operation (O)'; + + +drop VIEW public.v_tva_rate; + +CREATE OR REPLACE VIEW public.v_tva_rate +AS SELECT tva_rate.tva_id, + tva_rate.tva_rate, + tva_rate.tva_label, + tva_rate.tva_comment, + split_part(tva_rate.tva_poste, ','::text, 1) AS tva_purchase, + split_part(tva_rate.tva_poste, ','::text, 2) AS tva_sale, + tva_rate.tva_both_side, + tva_payment_purchase, + tva_payment_sale + FROM tva_rate; + +COMMENT ON VIEW public.v_tva_rate IS 'Show this table to be easily used by Tva_Rate_MTable'; +COMMENT ON COLUMN public.v_tva_rate.tva_purchase IS ' VAT used for purchase'; +COMMENT ON COLUMN public.v_tva_rate.tva_sale IS ' VAT used for sale'; +COMMENT ON COLUMN public.v_tva_rate.tva_both_side IS 'if 1 , VAT avoided '; +comment on column public.v_tva_rate.tva_payment_purchase is 'Check if the VAT on Purchase must be declared when at the date of payment (P) or the date of operation (O)'; +comment on column public.v_tva_rate.tva_payment_sale is 'Check if the VAT on Sale must be declared when at the date of payment (P) or the date of operation (O)'; + +insert into version (val,v_description) values (139,'Add VAT exigibility'); +commit ; \ No newline at end of file diff --git a/include/tax_summary.inc.php b/include/tax_summary.inc.php index 7da2ad2d5..c60e8b5b5 100644 --- a/include/tax_summary.inc.php +++ b/include/tax_summary.inc.php @@ -36,6 +36,15 @@ $end_periode = new IDate("end_date", $end); echo '
'; echo HtmlInput::array_to_hidden(['gDossier','ac'],$_GET); echo HtmlInput::hidden("do","display"); +$select_tva=new ISelect("tva_type"); +$select_tva->value=array( + array("value"=>'O',"label"=>_("Opération")), + array("value"=>'P',"label"=>_("Paiement")), + array("value"=>'T',"label"=>_("TVA")) +); +$select_tva->selected=$http->get('tva_type','string','O'); +printf(_("Calcul d'après la date")); +echo $select_tva->input(); printf(_("Période du %s au %s"), $start_periode->input(), $end_periode->input()); @@ -46,6 +55,7 @@ echo '
'; if ( $http->get("do","string","no") == "display") { $tax_summary=new Tax_Summary($cn,$start_periode->value,$end_periode->value); + $tax_summary->set_tva_type($select_tva->selected); try { try { $tax_summary->check(); diff --git a/unit-test/include/class/data/tax_summary_getrow_purchase_o.php b/unit-test/include/class/data/tax_summary_getrow_purchase_o.php new file mode 100644 index 000000000..f75c5bc60 --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getrow_purchase_o.php @@ -0,0 +1,199 @@ + + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => '0%', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '4', + 'amount_vat' => '0.0000', + 'amount_wovat' => '658.2500', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 1 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => '12%', + 'tva_rate' => '0.1200', + 'tva_both_side' => '0', + 'qp_vat_code' => '2', + 'amount_vat' => '109.8000', + 'amount_wovat' => '915.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 2 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => '21%', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1', + 'amount_vat' => '44.5300', + 'amount_wovat' => '212.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 3 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => '6%', + 'tva_rate' => '0.0600', + 'tva_both_side' => '0', + 'qp_vat_code' => '3', + 'amount_vat' => '5.2800', + 'amount_wovat' => '88.3200', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 4 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => 'ART44', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '8', + 'amount_vat' => '0.0000', + 'amount_wovat' => '315.2000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 5 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => 'EXPORT', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '6', + 'amount_vat' => '0.0000', + 'amount_wovat' => '286.9500', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 6 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => 'IMMO', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1002', + 'amount_vat' => '319.2400', + 'amount_wovat' => '1520.2000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 7 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => 'VOIT', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1003', + 'amount_vat' => '21.0000', + 'amount_wovat' => '100.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 8 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => '21%', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1', + 'amount_vat' => '244.5500', + 'amount_wovat' => '1164.5400', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 9 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => 'EXPORT', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '6', + 'amount_vat' => '0.0000', + 'amount_wovat' => '259.8000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 10 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => 'IMMO', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1002', + 'amount_vat' => '319.2400', + 'amount_wovat' => '1520.2000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 11 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => 'INTRA', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '5', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1250.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 12 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => 'VOIT', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1003', + 'amount_vat' => '42.0000', + 'amount_wovat' => '200.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getrow_purchase_p.php b/unit-test/include/class/data/tax_summary_getrow_purchase_p.php new file mode 100644 index 000000000..71caa2136 --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getrow_purchase_p.php @@ -0,0 +1,48 @@ + + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => '0%', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '4', + 'amount_vat' => '0.0000', + 'amount_wovat' => '658.2500', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 1 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => '21%', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1', + 'amount_vat' => '38.4300', + 'amount_wovat' => '183.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 2 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => '21%', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1', + 'amount_vat' => '140.0400', + 'amount_wovat' => '666.8600', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getrow_purchase_t.php b/unit-test/include/class/data/tax_summary_getrow_purchase_t.php new file mode 100644 index 000000000..5bed31568 --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getrow_purchase_t.php @@ -0,0 +1,183 @@ + + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => '0%', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '4', + 'amount_vat' => '0.0000', + 'amount_wovat' => '658.2500', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 1 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => '12%', + 'tva_rate' => '0.1200', + 'tva_both_side' => '0', + 'qp_vat_code' => '2', + 'amount_vat' => '109.8000', + 'amount_wovat' => '915.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 2 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => '21%', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1', + 'amount_vat' => '38.4300', + 'amount_wovat' => '183.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 3 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => 'ART44', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '8', + 'amount_vat' => '0.0000', + 'amount_wovat' => '315.2000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 4 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => 'EXPORT', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '6', + 'amount_vat' => '0.0000', + 'amount_wovat' => '286.9500', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 5 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => 'IMMO', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1002', + 'amount_vat' => '319.2400', + 'amount_wovat' => '1520.2000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 6 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => 'VOIT', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1003', + 'amount_vat' => '21.0000', + 'amount_wovat' => '100.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 7 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => '21%', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1', + 'amount_vat' => '140.0400', + 'amount_wovat' => '666.8600', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 8 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => 'EXPORT', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '6', + 'amount_vat' => '0.0000', + 'amount_wovat' => '259.8000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 9 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => 'IMMO', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1002', + 'amount_vat' => '319.2400', + 'amount_wovat' => '1520.2000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 10 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => 'INTRA', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '5', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1250.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 11 => + array ( + 'jrn_def_name' => 'Frais Divers', + 'tva_label' => 'VOIT', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1003', + 'amount_vat' => '42.0000', + 'amount_wovat' => '200.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getrow_sale_o.php b/unit-test/include/class/data/tax_summary_getrow_sale_o.php new file mode 100644 index 000000000..03674e9ab --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getrow_sale_o.php @@ -0,0 +1,63 @@ + + array ( + 'jrn_def_name' => 'Vente', + 'tva_label' => '21%', + 'qs_vat_code' => '1', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '219.5700', + 'amount_wovat' => '1045.6000', + 'amount_sided' => '0.0000', + 'tva_type' => 'P', + ), + 1 => + array ( + 'jrn_def_name' => 'Vente', + 'tva_label' => 'EXPORT', + 'qs_vat_code' => '6', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1047.9000', + 'amount_sided' => '0.0000', + 'tva_type' => 'O', + ), + 2 => + array ( + 'jrn_def_name' => 'Vente', + 'tva_label' => 'INTRA', + 'qs_vat_code' => '5', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1800.0000', + 'amount_sided' => '0.0000', + 'tva_type' => 'O', + ), + 3 => + array ( + 'jrn_def_name' => 'Vente', + 'tva_label' => 'VOIT', + 'qs_vat_code' => '1003', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '19.1500', + 'amount_wovat' => '91.2000', + 'amount_sided' => '0.0000', + 'tva_type' => 'P', + ), + 4 => + array ( + 'jrn_def_name' => 'Vente différée', + 'tva_label' => 'EXPORT', + 'qs_vat_code' => '6', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'amount_vat' => '0.0000', + 'amount_wovat' => '150.5600', + 'amount_sided' => '0.0000', + 'tva_type' => 'O', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getrow_sale_p.php b/unit-test/include/class/data/tax_summary_getrow_sale_p.php new file mode 100644 index 000000000..4c611e3b7 --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getrow_sale_p.php @@ -0,0 +1,28 @@ + + array ( + 'jrn_def_name' => 'Vente', + 'tva_label' => '21%', + 'qs_vat_code' => '1', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '16.8000', + 'amount_wovat' => '80.0000', + 'amount_sided' => '0.0000', + 'tva_type' => 'P', + ), + 1 => + array ( + 'jrn_def_name' => 'Vente', + 'tva_label' => 'VOIT', + 'qs_vat_code' => '1003', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '10.7500', + 'amount_wovat' => '51.2000', + 'amount_sided' => '0.0000', + 'tva_type' => 'P', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getrow_sale_t.php b/unit-test/include/class/data/tax_summary_getrow_sale_t.php new file mode 100644 index 000000000..2a0aa767b --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getrow_sale_t.php @@ -0,0 +1,64 @@ + + array ( + 'jrn_def_name' => 'Vente', + 'tva_label' => '21%', + 'qs_vat_code' => '1', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '16.8000', + 'amount_wovat' => '80.0000', + 'amount_sided' => '0.0000', + 'tva_type' => 'P', + ), + 1 => + array ( + 'jrn_def_name' => 'Vente', + 'tva_label' => 'EXPORT', + 'qs_vat_code' => '6', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1047.9000', + 'amount_sided' => '0.0000', + 'tva_type' => 'O', + ), + 2 => + array ( + 'jrn_def_name' => 'Vente', + 'tva_label' => 'INTRA', + 'qs_vat_code' => '5', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1800.0000', + 'amount_sided' => '0.0000', + 'tva_type' => 'O', + ), + 3 => + array ( + 'jrn_def_name' => 'Vente', + 'tva_label' => 'VOIT', + 'qs_vat_code' => '1003', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '10.7500', + 'amount_wovat' => '51.2000', + 'amount_sided' => '0.0000', + 'tva_type' => 'P', + ), + 4 => + array ( + 'jrn_def_name' => 'Vente différée', + 'tva_label' => 'EXPORT', + 'qs_vat_code' => '6', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'amount_vat' => '0.0000', + 'amount_wovat' => '150.5600', + 'amount_sided' => '0.0000', + 'tva_type' => 'O', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getsummary_purchase_o.php b/unit-test/include/class/data/tax_summary_getsummary_purchase_o.php new file mode 100644 index 000000000..dc6ef6766 --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getsummary_purchase_o.php @@ -0,0 +1,130 @@ + + array ( + 'tva_label' => '0%', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '4', + 'amount_vat' => '0.0000', + 'amount_wovat' => '658.2500', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 1 => + array ( + 'tva_label' => '12%', + 'tva_rate' => '0.1200', + 'tva_both_side' => '0', + 'qp_vat_code' => '2', + 'amount_vat' => '109.8000', + 'amount_wovat' => '915.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 2 => + array ( + 'tva_label' => '21%', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1', + 'amount_vat' => '289.0800', + 'amount_wovat' => '1376.5400', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 3 => + array ( + 'tva_label' => '6%', + 'tva_rate' => '0.0600', + 'tva_both_side' => '0', + 'qp_vat_code' => '3', + 'amount_vat' => '5.2800', + 'amount_wovat' => '88.3200', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 4 => + array ( + 'tva_label' => 'ART44', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '8', + 'amount_vat' => '0.0000', + 'amount_wovat' => '315.2000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 5 => + array ( + 'tva_label' => 'EXPORT', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '6', + 'amount_vat' => '0.0000', + 'amount_wovat' => '546.7500', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 6 => + array ( + 'tva_label' => 'IMMO', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1002', + 'amount_vat' => '638.4800', + 'amount_wovat' => '3040.4000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 7 => + array ( + 'tva_label' => 'INTRA', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '5', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1250.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 8 => + array ( + 'tva_label' => 'VOIT', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1003', + 'amount_vat' => '63.0000', + 'amount_wovat' => '300.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getsummary_purchase_p.php b/unit-test/include/class/data/tax_summary_getsummary_purchase_p.php new file mode 100644 index 000000000..b0a9258f7 --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getsummary_purchase_p.php @@ -0,0 +1,31 @@ + + array ( + 'tva_label' => '0%', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '4', + 'amount_vat' => '0.0000', + 'amount_wovat' => '658.2500', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 1 => + array ( + 'tva_label' => '21%', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1', + 'amount_vat' => '178.4700', + 'amount_wovat' => '849.8600', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getsummary_purchase_t.php b/unit-test/include/class/data/tax_summary_getsummary_purchase_t.php new file mode 100644 index 000000000..2f628bcf0 --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getsummary_purchase_t.php @@ -0,0 +1,116 @@ + + array ( + 'tva_label' => '0%', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '4', + 'amount_vat' => '0.0000', + 'amount_wovat' => '658.2500', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 1 => + array ( + 'tva_label' => '12%', + 'tva_rate' => '0.1200', + 'tva_both_side' => '0', + 'qp_vat_code' => '2', + 'amount_vat' => '109.8000', + 'amount_wovat' => '915.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 2 => + array ( + 'tva_label' => '21%', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1', + 'amount_vat' => '178.4700', + 'amount_wovat' => '849.8600', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 3 => + array ( + 'tva_label' => 'ART44', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '8', + 'amount_vat' => '0.0000', + 'amount_wovat' => '315.2000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 4 => + array ( + 'tva_label' => 'EXPORT', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '6', + 'amount_vat' => '0.0000', + 'amount_wovat' => '546.7500', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 5 => + array ( + 'tva_label' => 'IMMO', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1002', + 'amount_vat' => '638.4800', + 'amount_wovat' => '3040.4000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 6 => + array ( + 'tva_label' => 'INTRA', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'qp_vat_code' => '5', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1250.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 7 => + array ( + 'tva_label' => 'VOIT', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'qp_vat_code' => '1003', + 'amount_vat' => '63.0000', + 'amount_wovat' => '300.0000', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getsummary_sale_o.php b/unit-test/include/class/data/tax_summary_getsummary_sale_o.php new file mode 100644 index 000000000..64abaf88a --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getsummary_sale_o.php @@ -0,0 +1,48 @@ + + array ( + 'tva_label' => '21%', + 'qs_vat_code' => '1', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '219.5700', + 'amount_wovat' => '1045.6000', + 'amount_sided' => '0.0000', + 'tva_payment_sale' => 'P', + ), + 1 => + array ( + 'tva_label' => 'EXPORT', + 'qs_vat_code' => '6', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1198.4600', + 'amount_sided' => '0.0000', + 'tva_payment_sale' => 'O', + ), + 2 => + array ( + 'tva_label' => 'INTRA', + 'qs_vat_code' => '5', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1800.0000', + 'amount_sided' => '0.0000', + 'tva_payment_sale' => 'O', + ), + 3 => + array ( + 'tva_label' => 'VOIT', + 'qs_vat_code' => '1003', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '19.1500', + 'amount_wovat' => '91.2000', + 'amount_sided' => '0.0000', + 'tva_payment_sale' => 'P', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getsummary_sale_p.php b/unit-test/include/class/data/tax_summary_getsummary_sale_p.php new file mode 100644 index 000000000..efd438775 --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getsummary_sale_p.php @@ -0,0 +1,26 @@ + + array ( + 'tva_label' => '21%', + 'qs_vat_code' => '1', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '16.8000', + 'amount_wovat' => '80.0000', + 'amount_sided' => '0.0000', + 'tva_payment_sale' => 'P', + ), + 1 => + array ( + 'tva_label' => 'VOIT', + 'qs_vat_code' => '1003', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '10.7500', + 'amount_wovat' => '51.2000', + 'amount_sided' => '0.0000', + 'tva_payment_sale' => 'P', + ), +); diff --git a/unit-test/include/class/data/tax_summary_getsummary_sale_t.php b/unit-test/include/class/data/tax_summary_getsummary_sale_t.php new file mode 100644 index 000000000..b5adb41eb --- /dev/null +++ b/unit-test/include/class/data/tax_summary_getsummary_sale_t.php @@ -0,0 +1,48 @@ + + array ( + 'tva_label' => '21%', + 'qs_vat_code' => '1', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '16.8000', + 'amount_wovat' => '80.0000', + 'amount_sided' => '0.0000', + 'tva_payment_sale' => 'P', + ), + 1 => + array ( + 'tva_label' => 'EXPORT', + 'qs_vat_code' => '6', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1198.4600', + 'amount_sided' => '0.0000', + 'tva_payment_sale' => 'O', + ), + 2 => + array ( + 'tva_label' => 'INTRA', + 'qs_vat_code' => '5', + 'tva_rate' => '0.0000', + 'tva_both_side' => '0', + 'amount_vat' => '0.0000', + 'amount_wovat' => '1800.0000', + 'amount_sided' => '0.0000', + 'tva_payment_sale' => 'O', + ), + 3 => + array ( + 'tva_label' => 'VOIT', + 'qs_vat_code' => '1003', + 'tva_rate' => '0.2100', + 'tva_both_side' => '0', + 'amount_vat' => '10.7500', + 'amount_wovat' => '51.2000', + 'amount_sided' => '0.0000', + 'tva_payment_sale' => 'P', + ), +); diff --git a/unit-test/include/class/tax_summaryTest.class.php b/unit-test/include/class/tax_summaryTest.class.php index 1b1643c97..6719d3b85 100644 --- a/unit-test/include/class/tax_summaryTest.class.php +++ b/unit-test/include/class/tax_summaryTest.class.php @@ -85,571 +85,183 @@ class Tax_SummaryTest extends TestCase $this->expectOutputRegex("/\object->form_export_pdf(); } - - function testGet_row_purchase() + private function check_result ($p_scenario , $p_array,$p_array_expected,$jrn_type) { - $array=$this->object->get_row_purchase(); - //-- For creating the array - Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getrow_purchase.txt", print_r($array, TRUE)); - $a_result=array - ( - "0"=>array - ( - "jrn_def_name"=>"Achat", - "tva_label"=>"0%", - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "qp_vat_code"=>4, - "amount_vat"=>0.0000, - "amount_wovat"=>658.2500, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "1"=>array - ( - "jrn_def_name"=>"Achat", - "tva_label"=>"12%", - "tva_rate"=>0.1200, - "tva_both_side"=>0, - "qp_vat_code"=>2, - "amount_vat"=>109.8000, - "amount_wovat"=>915.0000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "2"=>array - ( - "jrn_def_name"=>"Achat", - "tva_label"=>"21%", - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "qp_vat_code"=>1, - "amount_vat"=>6.1000, - "amount_wovat"=>29.0000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "3"=>array - ( - "jrn_def_name"=>"Achat", - "tva_label"=>"6%", - "tva_rate"=>0.0600, - "tva_both_side"=>0, - "qp_vat_code"=>3, - "amount_vat"=>5.2800, - "amount_wovat"=>88.3200, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "4"=>array - ( - "jrn_def_name"=>"Achat", - "tva_label"=>"ART44", - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "qp_vat_code"=>8, - "amount_vat"=>0.0000, - "amount_wovat"=>315.2000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "5"=>array - ( - "jrn_def_name"=>"Achat", - "tva_label"=>"EXPORT", - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "qp_vat_code"=>6, - "amount_vat"=>0.0000, - "amount_wovat"=>286.9500, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "6"=>array - ( - "jrn_def_name"=>"Achat", - "tva_label"=>"IMMO", - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "qp_vat_code"=>1002, - "amount_vat"=>319.2400, - "amount_wovat"=>1520.2000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "7"=>array - ( - "jrn_def_name"=>"Achat", - "tva_label"=>"VOIT", - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "qp_vat_code"=>1003, - "amount_vat"=>21.0000, - "amount_wovat"=>100.0000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "8"=>array - ( - "jrn_def_name"=>"Frais Divers", - "tva_label"=>"21%", - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "qp_vat_code"=>1, - "amount_vat"=>244.5500, - "amount_wovat"=>1164.5400, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "9"=>array - ( - "jrn_def_name"=>"Frais Divers", - "tva_label"=>"EXPORT", - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "qp_vat_code"=>6, - "amount_vat"=>0.0000, - "amount_wovat"=>259.8000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "10"=>array - ( - "jrn_def_name"=>"Frais Divers", - "tva_label"=>"IMMO", - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "qp_vat_code"=>1002, - "amount_vat"=>319.2400, - "amount_wovat"=>1520.2000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "11"=>array - ( - "jrn_def_name"=>"Frais Divers", - "tva_label"=>"INTRA", - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "qp_vat_code"=>5, - "amount_vat"=>0.0000, - "amount_wovat"=>1250.0000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "12"=>array - ( - "jrn_def_name"=>"Frais Divers", - "tva_label"=>"VOIT", - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "qp_vat_code"=>1003, - "amount_vat"=>42.0000, - "amount_wovat"=>200.0000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000, - ) - ); - $nb_result=count($a_result); - $nb_array=count($array); + $nb_result=count($p_array_expected); + $nb_array=count($p_array); $this->assertEquals($nb_result, $nb_array); $ix=0; + switch ($jrn_type) + { + case "ACH": + $vat_code="qp_vat_code"; + break; + case "SMRACH": + $vat_code="qp_vat_code"; + break; + case "VEN": + $vat_code="qs_vat_code"; + break; + case "SMRVEN": + $vat_code="qs_vat_code"; + break; + + default: + throw new Exception(_("unknow jrn_type")); + break; + } for ($i=0; $i<$nb_result; $i++) { - $row=$a_result[$i]; + $row=$p_array_expected[$i]; for ($e=0; $e<$nb_array; $e++) { + $test_jrn_expected=""; + $test_jrn_result=""; + if ( in_array($jrn_type, ['ACH','VEN'])) + { + $test_jrn_expected=$row['jrn_def_name'] ; + $test_jrn_result=$p_array[$e]["jrn_def_name"]; + } if ( - $row['qp_vat_code']==$array[$e]['qp_vat_code'] - && $row['jrn_def_name'] == $array[$e]["jrn_def_name"] + $row[$vat_code]==$p_array[$e][$vat_code] + && $test_jrn_expected == $test_jrn_result ) { - $this->assertEquals($row['amount_vat'], $array[$e]['amount_vat'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_wovat'], $array[$e]['amount_wovat'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_sided'], $array[$e]['amount_sided'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_noded_amount'], $array[$e]['amount_noded_amount'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_noded_tax'], $array[$e]['amount_noded_tax'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_noded_return'], $array[$e]['amount_noded_return'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_private'], $array[$e]['amount_private'] - ,sprintf("Code %s ",$row['qp_vat_code'])); + $this->assertEquals($row['amount_vat'], $p_array[$e]['amount_vat'] + ,sprintf("%s Code %s ",$p_scenario,$row[$vat_code])); + + $this->assertEquals($row['amount_sided'], $p_array[$e]['amount_sided'] + ,sprintf("%s Code %s ",$p_scenario,$row[$vat_code])); + + $this->assertEquals($row['amount_wovat'], $p_array[$e]['amount_wovat'] + ,sprintf("%s Code %s ",$p_scenario,$row[$vat_code])); + + if ( $jrn_type=="ACH") { + + $this->assertEquals($row['amount_noded_amount'], $p_array[$e]['amount_noded_amount'] + ,sprintf("%s Code %s ",$p_scenario,$row[$vat_code])); + $this->assertEquals($row['amount_noded_tax'], $p_array[$e]['amount_noded_tax'] + ,sprintf("%s Code %s ",$p_scenario,$row[$vat_code])); + $this->assertEquals($row['amount_noded_return'], $p_array[$e]['amount_noded_return'] + ,sprintf("%s Code %s ",$p_scenario,$row[$vat_code])); + $this->assertEquals($row['amount_private'], $p_array[$e]['amount_private'] + ,sprintf("%s Code %s ",$p_scenario,$row[$vat_code])); + } $ix++; } } } $this->assertEquals($nb_array, $ix, 'Not all VAT CODE found'); + } + function testGet_row_purchase() + { + // Operation date + $this->object->set_tva_type("O"); + $array=$this->object->get_row_purchase(); + //-- For creating the array + // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getrow_purchase.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getrow_purchase_o.php"; + $this->check_result("tva_type = O , get_row_purchase",$array,$a_result,'ACH'); + + // Operation date + $this->object->set_tva_type("P"); + $array=$this->object->get_row_purchase(); + //-- For creating the array + // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getrow_purchase.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getrow_purchase_p.php"; + $this->check_result("tva_type = P , get_row_purchase",$array,$a_result,'ACH'); + + $this->object->set_tva_type("T"); + $array=$this->object->get_row_purchase(); + //-- For creating the array + // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getrow_purchase.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getrow_purchase_t.php"; + $this->check_result("tva_type = T , get_row_purchase",$array,$a_result,'ACH'); + + + + } function testGet_row_sale() { + $this->object->set_tva_type("O"); $array=$this->object->get_row_sale(); //-- For creating the array - //Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getrow_sale.txt", print_r($array, TRUE)); - $a_result=array - ( - "0"=>array - ( - "jrn_def_name"=>"Vente", - "tva_label"=>"21%", - "qs_vat_code"=>1, - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "amount_vat"=>219.5700, - "amount_wovat"=>1045.6000, - "amount_sided"=>0.0000 - ), - "1"=>array - ( - "jrn_def_name"=>"Vente", - "tva_label"=>"EXPORT", - "qs_vat_code"=>6, - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "amount_vat"=>0.0000, - "amount_wovat"=>1047.9000, - "amount_sided"=>0.0000 - ), - "2"=>array - ( - "jrn_def_name"=>"Vente", - "tva_label"=>"INTRA", - "qs_vat_code"=>5, - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "amount_vat"=>0.0000, - "amount_wovat"=>1800.0000, - "amount_sided"=>0.0000 - ), - "3"=>array - ( - "jrn_def_name"=>"Vente", - "tva_label"=>"VOIT", - "qs_vat_code"=>1003, - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "amount_vat"=>8.4000, - "amount_wovat"=>40.0000, - "amount_sided"=>0.0000 - ), - "4"=>Array - ( - "jrn_def_name"=>"Vente différée", - "tva_label"=>"EXPORT", - "qs_vat_code"=>6, - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "amount_vat"=>0.0000, - "amount_wovat"=>150.5600, - "amount_sided"=>0.0000 - ) - ); - $nb_result=count($a_result); - $nb_array=count($array); - $this->assertEquals($nb_result, $nb_array); - $ix=0; - for ($i=0; $i<$nb_result; $i++) - { - $row=$a_result[$i]; - for ($e=0; $e<$nb_array; $e++) - { - if ( - $row['qs_vat_code']==$array[$e]['qs_vat_code']&&$row['jrn_def_name']==$array[$e]["jrn_def_name"] - ) - { - $this->assertEquals($row['amount_vat'], $array[$e]['amount_vat'] - , sprintf("Code %s ", $row['qs_vat_code'])); - $this->assertEquals($row['amount_wovat'], $array[$e]['amount_wovat'] - , sprintf("Code %s ", $row['qs_vat_code'])); - $this->assertEquals($row['amount_sided'], $array[$e]['amount_sided'] - , sprintf("Code %s ", $row['qs_vat_code'])); - $ix++; - } - } - } - $this->assertEquals($nb_array, $ix, 'Not all VAT CODE found'); + // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getrow_sale_o.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getrow_sale_o.php"; + $this->check_result("tva_type = O , get_row_sale",$array,$a_result,'VEN'); + + + $this->object->set_tva_type("P"); + $array=$this->object->get_row_sale(); + //-- For creating the array + //Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getrow_sale_p.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getrow_sale_p.php"; + $this->check_result("tva_type = P , get_row_sale",$array,$a_result,'VEN'); + + + $this->object->set_tva_type("T"); + $array=$this->object->get_row_sale(); + //-- For creating the array + // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getrow_sale_t.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getrow_sale_t.php"; + $this->check_result("tva_type = T , get_row_sale",$array,$a_result,'VEN'); + } function testget_summary_purchase() { + $this->object->set_tva_type("T"); $array=$this->object->get_summary_purchase(); //-- For creating the array - // \Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_summary_purchase.txt", print_r($array, TRUE)); - $a_result=array - ( - "0"=>array - ( - "tva_label"=>"0%", - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "qp_vat_code"=>4, - "amount_vat"=>0.0000, - "amount_wovat"=>658.2500, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "1"=>array - ( - "tva_label"=>"12%", - "tva_rate"=>0.1200, - "tva_both_side"=>0, - "qp_vat_code"=>2, - "amount_vat"=>109.8000, - "amount_wovat"=>915.0000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "2"=>array - ( - "tva_label"=>"21%", - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "qp_vat_code"=>1, - "amount_vat"=>250.6500, - "amount_wovat"=>1193.5400, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "3"=>array - ( - "tva_label"=>"6%", - "tva_rate"=>0.0600, - "tva_both_side"=>0, - "qp_vat_code"=>3, - "amount_vat"=>5.2800, - "amount_wovat"=>88.3200, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "4"=>array - ( - "tva_label"=>"ART44", - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "qp_vat_code"=>8, - "amount_vat"=>0.0000, - "amount_wovat"=>315.2000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "5"=>array - ( - "tva_label"=>"EXPORT", - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "qp_vat_code"=>6, - "amount_vat"=>0.0000, - "amount_wovat"=>546.7500, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "6"=>array - ( - "tva_label"=>"IMMO", - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "qp_vat_code"=>1002, - "amount_vat"=>638.4800, - "amount_wovat"=>3040.4000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "7"=>array - ( - "tva_label"=>"INTRA", - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "qp_vat_code"=>5, - "amount_vat"=>0.0000, - "amount_wovat"=>1250.0000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ), - "8"=>array - ( - "tva_label"=>"VOIT", - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "qp_vat_code"=>1003, - "amount_vat"=>63.0000, - "amount_wovat"=>300.0000, - "amount_sided"=>0.0000, - "amount_noded_amount"=>0.0000, - "amount_noded_tax"=>0.0000, - "amount_noded_return"=>0.0000, - "amount_private"=>0.0000 - ) - ); - $nb_result=count($a_result); - $nb_array=count($array); - $this->assertEquals($nb_result, $nb_array); - $ix=0; - for ($i=0; $i<$nb_result; $i++) - { - $row=$a_result[$i]; - for ($e=0; $e<$nb_array; $e++) - { - if ($row['qp_vat_code']==$array[$e]['qp_vat_code']) - { - $this->assertEquals($row['amount_vat'], $array[$e]['amount_vat'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_wovat'], $array[$e]['amount_wovat'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_sided'], $array[$e]['amount_sided'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_noded_amount'], $array[$e]['amount_noded_amount'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_noded_tax'], $array[$e]['amount_noded_tax'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_noded_return'], $array[$e]['amount_noded_return'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $this->assertEquals($row['amount_private'], $array[$e]['amount_private'] - ,sprintf("Code %s ",$row['qp_vat_code'])); - $ix++; - } - } - } - $this->assertEquals($nb_array, $ix, 'Not all VAT CODE found'); + // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getsummary_purchase_t.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getsummary_purchase_t.php"; + $this->check_result("tva_type = T , get_summary_purchase",$array,$a_result,'SMRACH'); + + $this->object->set_tva_type("O"); + $array=$this->object->get_summary_purchase(); + //-- For creating the array + // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getsummary_purchase_o.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getsummary_purchase_o.php"; + $this->check_result("tva_type = O , get_summary_purchase",$array,$a_result,'SMRACH'); + + $this->object->set_tva_type("P"); + $array=$this->object->get_summary_purchase(); + //-- For creating the array + // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getsummary_purchase_p.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getsummary_purchase_p.php"; + $this->check_result("tva_type = P , get_summary_purchase",$array,$a_result,'SMRACH'); + + } function testget_summary_sale() { + $this->object->set_tva_type("O"); $array=$this->object->get_summary_sale(); //-- For creating the array - // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_summary_sale.txt", print_r($array, TRUE)); + // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getsummary_sale_o.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getsummary_sale_o.php"; + $this->check_result("tva_type = O , get_summary_sale",$array,$a_result,'SMRVEN'); + + $this->object->set_tva_type("P"); + $array=$this->object->get_summary_sale(); + //-- For creating the array + // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getsummary_sale_p.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getsummary_sale_p.php"; + $this->check_result("tva_type = P , get_summary_sale",$array,$a_result,'SMRVEN'); + + + $this->object->set_tva_type("T"); + $array=$this->object->get_summary_sale(); + //-- For creating the array + //Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getsummary_sale_t.txt", var_export($array, TRUE)); + require __DIR__."/data/tax_summary_getsummary_sale_t.php"; + $this->check_result("tva_type = T , get_summary_sale",$array,$a_result,'SMRVEN'); - $a_result=array - ( - array - ( - "tva_label"=>"21%", - "qs_vat_code"=>1, - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "amount_vat"=>219.5700, - "amount_wovat"=>1045.6000, - "amount_sided"=>0.0000 - ), - array - ( - "tva_label"=>"EXPORT", - "qs_vat_code"=>6, - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "amount_vat"=>0.0000, - "amount_wovat"=>1198.4600, - "amount_sided"=>0.0000 - ), - array - ( - "tva_label"=>"INTRA", - "qs_vat_code"=>5, - "tva_rate"=>0.0000, - "tva_both_side"=>0, - "amount_vat"=>0.0000, - "amount_wovat"=>1800.0000, - "amount_sided"=>0.0000 - ), - array - ( - "tva_label"=>"VOIT", - "qs_vat_code"=>1003, - "tva_rate"=>0.2100, - "tva_both_side"=>0, - "amount_vat"=>8.4000, - "amount_wovat"=>40.0000, - "amount_sided"=>0.0000 - ) - ); - $nb_result=count($a_result); - $nb_array=count($array); - $this->assertEquals($nb_result, $nb_array); - $ix=0; - for ($i=0; $i<$nb_result; $i++) - { - $row=$a_result[$i]; - for ($e=0; $e<$nb_array; $e++) - { - if ($row['qs_vat_code']==$array[$e]['qs_vat_code']) - { - $this->assertEquals($row['amount_vat'], $array[$e]['amount_vat'] - ,sprintf("Code %s ",$row['qs_vat_code'])); - $this->assertEquals($row['amount_wovat'], $array[$e]['amount_wovat'] - ,sprintf("Code %s ",$row['qs_vat_code'])); - $this->assertEquals($row['amount_sided'], $array[$e]['amount_sided'] - ,sprintf("Code %s ",$row['qs_vat_code'])); - $ix++; - } - } - } - $this->assertEquals($nb_array, $ix, 'Not all VAT CODE found'); + + } } From 096169b987e86895520f9a3ebd9736794a596221 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Tue, 12 Nov 2019 21:13:47 +0100 Subject: [PATCH 03/23] =?UTF-8?q?Task=20#1762=20,=20printtva=20peut=20mett?= =?UTF-8?q?re=20donner=20les=20totaux=20de=20tva=20suivant=20l'exigibilit?= =?UTF-8?q?=C3=A9=20configur=C3=A9=20par=20Code=20TVA=20,=20par=20date=20d?= =?UTF-8?q?e=20paiement=20ou=20par=20date=20d'op=C3=A9ration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/class/acc_ledger.class.php | 61 +++++---- include/class/acc_ledger_history.class.php | 81 +++++++++++- .../acc_ledger_history_financial.class.php | 6 +- .../acc_ledger_history_generic.class.php | 1 + .../acc_ledger_history_purchase.class.php | 20 ++- .../class/acc_ledger_history_sale.class.php | 17 ++- include/class/acc_ledger_purchase.class.php | 21 ++- include/class/acc_ledger_sold.class.php | 22 +++- include/class/pdf.class.php | 34 ++++- include/class/print_ledger.class.php | 46 +++++-- .../class/print_ledger_detail_item.class.php | 9 +- include/class/print_ledger_simple.class.php | 60 ++++++--- .../print_ledger_simple_without_vat.class.php | 27 ++-- include/constant.php | 2 +- include/export/export_ledger_csv.php | 9 +- include/export/export_ledger_pdf.php | 6 +- include/export/export_printtva_pdf.php | 11 +- include/impress_jrn.inc.php | 18 ++- include/lib/database_core.class.php | 2 +- include/lib/message_javascript.php | 1 + include/sql/patch/upgrade139.sql | 119 +++++++++++++++++ unit-test/create-dossier-test.sh | 2 +- .../class/acc_account_ledgerTest.class.php | 6 +- .../include/class/acc_balanceTest.class.php | 6 +- .../include/class/acc_bilanTest.class.php | 2 +- .../include/class/acc_ledgerTest.class.php | 122 +++++++++++------- .../class/acc_ledger_finTest.class.php | 5 +- ...acc_ledger_history_financialTest.class.php | 11 +- .../acc_ledger_history_genericTest.class.php | 9 +- .../acc_ledger_history_purchaseTest.class.php | 9 +- .../acc_ledger_history_saleTest.class.php | 10 +- .../class/acc_ledger_purchaseTest.class.php | 29 +++-- .../class/acc_ledger_soldTest.class.php | 36 +++--- .../data/tax_summary_getrow_purchase_t.php | 41 ++++-- .../class/data/tax_summary_getrow_sale_t.php | 8 +- .../tax_summary_getsummary_purchase_t.php | 27 +++- .../data/tax_summary_getsummary_sale_t.php | 14 +- .../include/class/tax_summaryTest.class.php | 8 +- unit-test/test-file.sh | 4 +- 39 files changed, 694 insertions(+), 228 deletions(-) create mode 100644 include/sql/patch/upgrade139.sql diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index 3fe53f67c..6c0351cd3 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -63,7 +63,7 @@ class Acc_Ledger extends jrn_def_sql var $id; /**< jrn_def.jrn_def_id */ var $db; /**< database connextion */ var $row; /**< row of the ledger */ - var $type; /**< type of the ledger ACH ODS FIN VEN or GL */ + var $ledger_type; /**< type of the ledger ACH ODS FIN VEN or GL */ var $nb; /**< default number of rows by default 10 */ @@ -130,7 +130,7 @@ class Acc_Ledger extends jrn_def_sql if ($this->id==0) { $this->ledger_name=_(" Tous les journaux"); - $this->type="GL"; + $this->ledger_type="GL"; return "GL"; } @@ -141,7 +141,7 @@ class Acc_Ledger extends jrn_def_sql if ($Max==0) return null; $ret=Database::fetch_array($Res, 0); - $this->type=$ret['jrn_def_type']; + $this->ledger_type=$ret['jrn_def_type']; return $ret['jrn_def_type']; } @@ -452,6 +452,7 @@ class Acc_Ledger extends jrn_def_sql */ function get_solde($p_from, $p_to) { + bcscale(4); $ledger=""; if ($this->id!=0) { @@ -471,9 +472,9 @@ class Acc_Ledger extends jrn_def_sql { if ($line['deb']=='t') - $deb+=$line['montant']; + $deb=bcadd($deb,$line['montant']); else - $cred+=$line['montant']; + $cred=bcadd($cred,$line['montant']); } $response=array($deb, $cred); return $response; @@ -1359,14 +1360,6 @@ class Acc_Ledger extends jrn_def_sql return true; } - /** - * @brief get all the data from request and build the object - */ - function get_request() - { - $this->id=$_REQUEST['p_jrn']; - } - /** * @brief retrieve the next number for this type of ledger * @param p_cn connx @@ -1773,18 +1766,30 @@ class Acc_Ledger extends jrn_def_sql */ public function existing_vat() { - if ($this->type=='ACH') + $array=[]; + if ($this->get_type()=='ACH') { - $array=$this->db->get_array("select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 ". - " and exists (select qp_vat_code from quant_purchase - where qp_vat_code=tva_id and exists (select j_id from jrnx where j_jrn_def = $1)) order by tva_id", + $array=$this->db->get_array("select tva_id,tva_label,tva_poste + from tva_rate + where tva_rate != 0.0000 + and exists (select qp_vat_code from quant_purchase + where + qp_vat_code=tva_id + and exists (select j_id + from jrnx where j_jrn_def = $1)) + order by tva_id", array($this->id)); } - if ($this->type=='VEN') + if ($this->get_type()=='VEN') { - $array=$this->db->get_array("select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 ". - " and exists (select qs_vat_code from quant_sold - where qs_vat_code=tva_id and exists (select j_id from jrnx where j_jrn_def = $1)) order by tva_id", + $array=$this->db->get_array("select tva_id,tva_label,tva_poste + from tva_rate + where tva_rate != 0.0000 + and exists (select qs_vat_code from quant_sold + where qs_vat_code=tva_id + and + exists (select j_id from jrnx where j_jrn_def = $1)) + order by tva_id", array($this->id)); } return $array; @@ -1808,7 +1813,7 @@ class Acc_Ledger extends jrn_def_sql */ function get_other_amount($p_jr_id) { - if ($this->type=='ACH') + if ($this->get_type()=='ACH') { $array=$this->db->get_array('select sum(qp_price) as price,sum(qp_vat) as vat '. ',sum(coalesce(qp_nd_amount,0)+coalesce(qp_dep_priv,0)) as priv'. @@ -1818,7 +1823,7 @@ class Acc_Ledger extends jrn_def_sql where j_grpt=$1 ', array($p_jr_id)); $ret=$array[0]; } - if ($this->type=='VEN') + if ($this->get_type()=='VEN') { $array=$this->db->get_array('select sum(qs_price) as price,sum(qs_vat) as vat '. ',0 as priv'. @@ -1844,14 +1849,14 @@ class Acc_Ledger extends jrn_def_sql */ function vat_operation($p_jr_id) { - if ($this->type=='ACH') + if ($this->get_type()=='ACH') { $array=$this->db->get_array('select coalesce(sum(qp_vat),0) as sum_vat,tva_id from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id) where tva_rate !=0.0 and j_grpt=$1 group by tva_id', array($p_jr_id)); } - if ($this->type=='VEN') + if ($this->get_type()=='VEN') { $array=$this->db->get_array('select coalesce(sum(qs_vat),0) as sum_vat,tva_id from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id) @@ -1903,7 +1908,7 @@ class Acc_Ledger extends jrn_def_sql $max_date=$periode_max->first_day(); bcscale(2); // min periode - if ($this->type=='ACH') + if ($this->get_type()=='ACH') { /* get all amount exclude vat */ $sql="select coalesce(sum(qp_price),0) as price". @@ -1928,7 +1933,7 @@ class Acc_Ledger extends jrn_def_sql array($min_date, $max_date, $this->id)); $ret['tva']=$array; } - if ($this->type=='VEN') + if ($this->get_type()=='VEN') { /* get all amount exclude vat */ $sql="select coalesce(sum(qs_price),0) as price". @@ -1953,7 +1958,7 @@ class Acc_Ledger extends jrn_def_sql array($min_date, $max_date, $this->id)); $ret['tva']=$array; } - if ($this->type=="FIN") + if ($this->get_type()=="FIN") { /* find the quick code of this ledger */ diff --git a/include/class/acc_ledger_history.class.php b/include/class/acc_ledger_history.class.php index 3eaf2a64d..4d3a5a383 100644 --- a/include/class/acc_ledger_history.class.php +++ b/include/class/acc_ledger_history.class.php @@ -41,6 +41,8 @@ abstract class Acc_Ledger_History protected $ma_ledger; //!< Array of ledger id : jrn_def.jrn_def_id protected $m_mode; //!< mode of export L : one line, E accounting writing , D : Detail public $db; //!< database connx + protected $ledger_type; //! type of ledger VEN , ACH , ODS, FIN + protected $filter_operation; //!< to filter paid, unpaid or all operation /** * @@ -61,6 +63,7 @@ abstract class Acc_Ledger_History $this->m_from=$p_from; $this->m_to=$p_to; $this->m_mode=$p_mode; + $this->filter_operation='all'; } /** * setter / getter @@ -70,7 +73,23 @@ abstract class Acc_Ledger_History { return $this->m_from; } - /** + public function get_ledger_type() + { + return $this->ledger_type; + } + + public function set_ledger_type($ledger_type) + { + if (! in_array($ledger_type,['ACH','ODS','VEN','FIN'])) { + record_log('Acc_Ledger_History:set_ledger_type '.var_export($ledger_type,TRUE)); + throw new Exception (_("Donnée invalide",EXC_PARAM_VALUE)); + } + + $this->ledger_type=$ledger_type; + return $this; + } + + /** * setter / getter * @returns m_to (periode id) */ @@ -141,9 +160,10 @@ abstract class Acc_Ledger_History * @param integer $p_from periode id * @param integer $p_to periode id * @param char $p_mode L (list operation) E (extended detail) A (accouting writing) D (Detailled VAT) + * @param $p_paid values are all means all operations, paid only paid operation, unpaid for only unpaid * @return Acc_Ledger_History_Generic Acc_Ledger_History_Sale Acc_Ledger_History_Financial Acc_Ledger_History_Purchase */ - static function factory(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode) + static function factory(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode,$p_paid) { // For Accounting writing , we use Acc_Ledger_History if ($p_mode=="A") @@ -183,6 +203,7 @@ abstract class Acc_Ledger_History case "ACH": $ret=new Acc_Ledger_History_Purchase($cn, $pa_ledger, $p_from, $p_to, $p_mode); + $ret->set_filter_operation($p_paid); return $ret; break; case "FIN": @@ -193,6 +214,7 @@ abstract class Acc_Ledger_History case "VEN": $ret=new Acc_Ledger_History_Sale($cn, $pa_ledger, $p_from, $p_to, $p_mode); + $ret->set_filter_operation($p_paid); return $ret; break; @@ -233,11 +255,17 @@ abstract class Acc_Ledger_History switch ($p_jrn_type) { case 'VEN': - $tiers=$this->db->get_value('select max(qs_client) from quant_sold join jrnx using (j_id) join jrn on (jr_grpt_id=j_grpt) where jrn.jr_id=$1', + $tiers=$this->db->get_value('select max(qs_client) ' + . 'from quant_sold join jrnx using (j_id) ' + . 'join jrn on (jr_grpt_id=j_grpt) where jrn.jr_id=$1', array($jr_id)); break; case 'ACH': - $tiers=$this->db->get_value('select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn on (jr_grpt_id=j_grpt) where jrn.jr_id=$1', + $tiers=$this->db->get_value('select max(qp_supplier) ' + . ' from quant_purchase ' + . ' join jrnx using (j_id) ' + . ' join jrn on (jr_grpt_id=j_grpt) ' + . ' where jrn.jr_id=$1', array($jr_id)); break; @@ -287,4 +315,49 @@ abstract class Acc_Ledger_History abstract function export_html(); abstract function get_row($p_limit, $p_offset); + + /** + * Build a SQL clause to filter operation depending if they are paid, unpaid or no filter + * @return string SQL Clause + */ + protected function build_filter_operation() + { + switch ( $this->get_filter_operation() ) + { + case 'all': + $sql_filter=""; + break; + case 'paid': + $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) "; + break; + case 'unpaid': + $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) "; + break; + default: + throw new Exception(_("Filtre invalide",5)); + + } + return $sql_filter; + } + /** + * Filter operation + */ + function get_filter_operation() + { + return $this->filter_operation; + } + /** + * Filter operation , + * @param string $filter_operation, valid : all, paid, unpaid + */ + + public function set_filter_operation($filter_operation) + { + if (in_array($filter_operation,['all','paid','unpaid'])) + { + $this->filter_operation=$filter_operation; + return $this; + } + throw new Exception(_("Filter invalide ".$filter_operation),5); + } } diff --git a/include/class/acc_ledger_history_financial.class.php b/include/class/acc_ledger_history_financial.class.php index 5b63e801d..a413ba039 100644 --- a/include/class/acc_ledger_history_financial.class.php +++ b/include/class/acc_ledger_history_financial.class.php @@ -29,7 +29,11 @@ require_once NOALYSS_INCLUDE."/class/acc_ledger_history.class.php"; class Acc_Ledger_History_Financial extends Acc_Ledger_History { - + function __construct(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode) + { + parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode); + $this->ledger_type='FIN'; + } /** * @brief display the accounting */ diff --git a/include/class/acc_ledger_history_generic.class.php b/include/class/acc_ledger_history_generic.class.php index 8014b7cd9..97207cf0c 100644 --- a/include/class/acc_ledger_history_generic.class.php +++ b/include/class/acc_ledger_history_generic.class.php @@ -49,6 +49,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History { parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode); $this->data=[]; + $this->ledger_type='ODS'; } /** diff --git a/include/class/acc_ledger_history_purchase.class.php b/include/class/acc_ledger_history_purchase.class.php index 5f2ef6f56..b53f17b50 100644 --- a/include/class/acc_ledger_history_purchase.class.php +++ b/include/class/acc_ledger_history_purchase.class.php @@ -34,14 +34,21 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History { private $data; //!< Contains rows from SQL - + public function __construct(\Database $cn, $pa_ledger, $p_from, $p_to, $p_mode) { parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode); + $this->filter_operation='all'; + $this->ledger_type='ACH'; + } + public function get_filter_operation() + { + return $this->filter_operation; } - /** + + /** * @brief display the accounting */ public function export_accounting_html() @@ -115,7 +122,7 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History 'jr_tech_per'); $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; - + $sql_filter=$this->build_filter_operation(); $ledger_list=join(",", $this->ma_ledger); $sql=" with row_purchase as @@ -142,6 +149,7 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History jr_id, jr_pj_number, to_char(jr_date,'DD.MM.YYYY') as str_date, + to_char(jr_date,'DDMMYY') as str_date_short, to_char(jr_date_paid,'DD.MM.YYYY') as str_date_paid, jr_internal, qp_supplier, @@ -154,7 +162,8 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History noded_vat, private_amount, novat+vat-tva_sided as tvac, - n_text + n_text, + jr_grpt_id from jrn join row_purchase on (qp_internal=jr_internal) @@ -162,6 +171,7 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History left join jrn_note using (jr_id) where jr_def_id in ({$ledger_list}) + {$sql_filter} and {$periode} {$cond_limite} order by jrn.jr_date, substring(jr_pj_number,'[0-9]+$')::numeric "; @@ -185,7 +195,7 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History quant_purchase where qp_internal = $1 - group by qp_vat_code,qp_internal order by qp_vat_code"); + group by qp_vat_code order by qp_vat_code"); } $nb_row=count($this->data); diff --git a/include/class/acc_ledger_history_sale.class.php b/include/class/acc_ledger_history_sale.class.php index bb92637ef..5d55b1fef 100644 --- a/include/class/acc_ledger_history_sale.class.php +++ b/include/class/acc_ledger_history_sale.class.php @@ -33,11 +33,14 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History { private $data; //!< Contains rows from SQL - + + public function __construct(\Database $cn, $pa_ledger, $p_from, $p_to, $p_mode) { parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode); + $this->filter_operation='all'; + $this->ledger_type='VEN'; } /** * Display the operation of sales with detailled VAT @@ -100,6 +103,7 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History "); } } + /** * Get the rows from jrnx and quant* tables * @param int $p_limit max of rows to returns @@ -111,7 +115,9 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History 'jr_tech_per'); $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; - + + $sql_filter=$this->build_filter_operation(); + $ledger_list=join(",", $this->ma_ledger); $sql=" with row_sale as @@ -143,13 +149,16 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History vat, tva_sided, novat, - novat+vat-tva_sided as tvac + novat+vat-tva_sided as tvac, + to_char(jr_date,'DDMMYY') as str_date_short, + jr_grpt_id from jrn join row_sale on (qs_internal=jr_internal) join client_detail on (qs_client=f_id) where jr_def_id in ({$ledger_list}) + {$sql_filter} and {$periode} {$cond_limite} order by jr_date, substring(jr_pj_number,'[0-9]+$')::numeric "; @@ -172,7 +181,7 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History quant_sold where qs_internal = $1 - group by qs_vat_code,qs_internal order by qs_vat_code"); + group by qs_vat_code order by qs_vat_code"); } diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index 1aada131c..55ad50ca0 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -1803,14 +1803,26 @@ EOF; * @param $p_end jrn.jr_tech_per to * @return handle to database result */ - function get_detail_purchase($p_from,$p_end) + function get_detail_purchase($p_from,$p_end,$p_filter_operation='all') { global $g_user; // Journal valide if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide"); - - // Securite - if ( $g_user->get_ledger_access($this->id) == 'X' ) return null; + switch ( $p_filter_operation) + { + case 'all': + $sql_filter=""; + break; + case 'paid': + $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) "; + break; + case 'unpaid': + $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) "; + break; + default: + throw new Exception(_("Filtre invalide",5)); + + } // get the data from the view $sql = "select * @@ -1818,6 +1830,7 @@ EOF; where jr_def_id = $1 and jr_date >= (select p_start from parm_periode where p_id = $2) + {$sql_filter} and jr_date <= (select p_end from parm_periode where p_id = $3) " .' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc '; $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end)); diff --git a/include/class/acc_ledger_sold.class.php b/include/class/acc_ledger_sold.class.php index 138c070b6..2f7ae135b 100644 --- a/include/class/acc_ledger_sold.class.php +++ b/include/class/acc_ledger_sold.class.php @@ -1333,13 +1333,15 @@ EOF; return $r; } /** - * Retrieve data from the view v_detail_sale + * Retrieve data from the view v_detail_sale , gives all the row of an operation + * * @remark $g_user connected user * @param $p_from jrn.jr_tech_per from * @param type $p_end jrn.jr_tech_per to + * @param $p_filter_operation valid option : all, paid, unpaid * @return type */ - function get_detail_sale($p_from,$p_end) + function get_detail_sale($p_from,$p_end,$p_filter_operation='all') { global $g_user; // Journal valide @@ -1348,12 +1350,28 @@ EOF; // Securite if ( $g_user->get_ledger_access($this->id) == 'X' ) return null; + switch ( $p_filter_operation) + { + case 'all': + $sql_filter=""; + break; + case 'paid': + $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) "; + break; + case 'unpaid': + $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) "; + break; + default: + throw new Exception(_("Filtre invalide",5)); + + } // get the data from the view $sql = "select * from v_detail_sale where jr_def_id = $1 and jr_date >= (select p_start from parm_periode where p_id = $2) + {$sql_filter} and jr_date <= (select p_end from parm_periode where p_id = $3) " .' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc '; $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end)); diff --git a/include/class/pdf.class.php b/include/class/pdf.class.php index bc13ffd24..650dafdc4 100644 --- a/include/class/pdf.class.php +++ b/include/class/pdf.class.php @@ -140,6 +140,36 @@ class PDF extends PDF_Core return array($customer_qc,$customer_name,$bank_qc,$bank_name); } } - - + + public function set_filter_operation($filter_operation) + { + if (in_array($filter_operation, ['all', 'paid', 'unpaid'])) + { + $this->filter_operation=$filter_operation; + return $this; + } + throw new Exception(_("Filter invalide ".$filter_operation), 5); + } + /** + * Build a SQL clause to filter operation depending if they are paid, unpaid or no filter + * @return string SQL Clause + */ + protected function build_filter_operation() + { + switch ($this->get_filter_operation()) + { + case 'all': + $sql_filter=""; + break; + case 'paid': + $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) "; + break; + case 'unpaid': + $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) "; + break; + default: + throw new Exception(_("Filtre invalide", 5)); + } + return $sql_filter; + } } \ No newline at end of file diff --git a/include/class/print_ledger.class.php b/include/class/print_ledger.class.php index dfa59103b..83f43c18b 100644 --- a/include/class/print_ledger.class.php +++ b/include/class/print_ledger.class.php @@ -36,7 +36,17 @@ require_once NOALYSS_INCLUDE.'/class/print_ledger_detail_item.class.php'; * */ class Print_Ledger { - + protected $filter_operation; // See Acc_Ledger_History::filter_operation + + public function set_filter_operation($filter_operation) + { + if (in_array($filter_operation,['all','paid','unpaid'])) + { + $this->filter_operation=$filter_operation; + return $this; + } + throw new Exception(_("Filter invalide ".$filter_operation),5); + } /** * Create an object Print_Ledger* depending on $p_type_export ( 0 => accounting * 1-> one row per operation 2-> detail of item) @@ -45,7 +55,8 @@ class Print_Ledger { * @param type $p_format_output CSV or PDF * @param Acc_Ledger $ledger */ - static function factory(Database $cn, $p_type_export, $p_format_output, Acc_Ledger $p_ledger) { + static function factory(Database $cn, $p_type_export, $p_format_output, Acc_Ledger $p_ledger,$p_filter_operation) + { /** * For PDF output */ @@ -67,19 +78,19 @@ class Print_Ledger { ) { $pdf=new Print_Ledger_Simple_without_vat($cn, - $p_ledger); + $p_ledger,$p_filter_operation); $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple')); return $pdf; } if ($own->MY_TVA_USE=='Y') { - $pdf=new Print_Ledger_Simple($cn, $p_ledger); + $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_filter_operation); return $pdf; } if ($own->MY_TVA_USE=='N') { $pdf=new Print_Ledger_Simple_without_vat($cn, - $p_ledger); + $p_ledger,$p_filter_operation); return $pdf; } } @@ -111,25 +122,25 @@ class Print_Ledger { ) { $pdf=new Print_Ledger_Simple_without_vat($cn, - $p_ledger); + $p_ledger,$p_filter_operation); $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple')); return $pdf; } if ($own->MY_TVA_USE=='Y') { - $pdf=new Print_Ledger_Simple($cn, $p_ledger); + $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_filter_operation); return $pdf; } if ($own->MY_TVA_USE=='N') { $pdf=new Print_Ledger_Simple_without_vat($cn, - $p_ledger); + $p_ledger,$p_filter_operation); return $pdf; } } if ($jrn_type=='FIN') - { + { $pdf=new Print_Ledger_Financial($cn, $p_ledger); return $pdf; } @@ -162,11 +173,11 @@ class Print_Ledger { ==0) ) { - $pdf=new Print_Ledger_Simple_without_vat($cn, $p_ledger); + $pdf=new Print_Ledger_Simple_without_vat($cn, $p_ledger,$p_filter_operation); $pdf->set_error('Ce journal ne peut être imprimé en mode simple'); return $pdf; } - $pdf=new Print_Ledger_Detail_Item($cn, $p_ledger); + $pdf=new Print_Ledger_Detail_Item($cn, $p_ledger,$p_filter_operation); return $pdf; case 'A': /*********************************************************** @@ -206,7 +217,10 @@ class Print_Ledger { and uj_priv in ('R','W') and ( jrn_enable=1 or - exists (select 1 from jrn where jr_def_id=jrn_def_id and jr_tech_per in (select p_id from parm_periode where p_exercice=$2))) + exists (select 1 from jrn + where + jr_def_id=jrn_def_id + and jr_tech_per in (select p_id from parm_periode where p_exercice=$2))) order by jrn_def_name "; $a_jrn=$cn->get_array($sql, array($g_user->login, $exercice)); @@ -216,8 +230,12 @@ class Print_Ledger { $a_jrn=$cn->get_array("select jrn_def_id from jrn_def join jrn_type on jrn_def_type=jrn_type_id where - jrn_enable=1 or exists(select 1 from jrn where jr_def_id=jrn_def_id and jr_tech_per in (select p_id from parm_periode where p_exercice=$1)) - order by jrn_def_name + jrn_enable=1 + or exists(select 1 from jrn + where + jr_def_id=jrn_def_id + and jr_tech_per in (select p_id from parm_periode where p_exercice=$1)) + order by jrn_def_name ", [$exercice]); } $a=[]; diff --git a/include/class/print_ledger_detail_item.class.php b/include/class/print_ledger_detail_item.class.php index 745fea52b..682c24551 100644 --- a/include/class/print_ledger_detail_item.class.php +++ b/include/class/print_ledger_detail_item.class.php @@ -29,7 +29,7 @@ require_once NOALYSS_INCLUDE.'/class/pdf_land.class.php'; class Print_Ledger_Detail_Item extends PDFLand { - public function __construct (Database $p_cn,Acc_Ledger $p_jrn) + public function __construct (Database $p_cn,Acc_Ledger $p_jrn,$p_filter_operation) { if($p_cn == null) die("No database connection. Abort."); @@ -37,6 +37,7 @@ class Print_Ledger_Detail_Item extends PDFLand parent::__construct($p_cn,'L', 'mm', 'A4'); $this->ledger=$p_jrn; $this->show_col=true; + $this->filter_operation=$p_filter_operation; } function setDossierInfo($dossier = "n/a") @@ -93,21 +94,23 @@ class Print_Ledger_Detail_Item extends PDFLand bcscale(2); $jrn_type=$this->ledger->get_type(); $http=new HttpInput(); + switch ($jrn_type) { case 'VEN': $ledger=new Acc_Ledger_Sold($this->cn, $this->ledger->jrn_def_id); - $ret_detail=$ledger->get_detail_sale($http->get('from_periode','number'),$http->get('to_periode','number')); + $ret_detail=$ledger->get_detail_sale($http->get('from_periode','number'),$http->get('to_periode','number'), $this->filter_operation); break; case 'ACH': $ledger=new Acc_Ledger_Purchase($this->cn, $this->ledger->jrn_def_id); - $ret_detail=$ledger->get_detail_purchase($http->get('from_periode','number'),$http->get('to_periode','number')); + $ret_detail=$ledger->get_detail_purchase($http->get('from_periode','number'),$http->get('to_periode','number'),$this->filter_operation); break; default: die (__FILE__.":".__LINE__.'Journal invalide'); break; } if ( $ret_detail == null ) return; + $prepared_query=new Prepared_Query($this->ledger->db); $prepared_query->prepare_reconcile_date(); diff --git a/include/class/print_ledger_simple.class.php b/include/class/print_ledger_simple.class.php index 7e065586b..26aa342ef 100644 --- a/include/class/print_ledger_simple.class.php +++ b/include/class/print_ledger_simple.class.php @@ -28,10 +28,11 @@ require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; class Print_Ledger_Simple extends PDF { - public function __construct ($p_cn, Acc_Ledger $p_jrn) + public function __construct ($p_cn, Acc_Ledger $p_jrn,$p_filter_operation) { $http=new HttpInput(); + $this->filter_operation=$p_filter_operation; if($p_cn == null) die("No database connection. Abort."); parent::__construct($p_cn,'L', 'mm', 'A4'); @@ -123,7 +124,10 @@ class Print_Ledger_Simple extends PDF $this->SetFont('DejaVu','',6); // page Header - $this->Cell(143,6,'report',0,0,'R'); + if ( ! $flag_tva) + $this->Cell(143,6,'report',0,0,'R'); + else + $this->Cell(78,6,'report',0,0,'R'); $this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */ if ( $this->jrn_type != 'VEN') { @@ -157,7 +161,12 @@ class Print_Ledger_Simple extends PDF //Position at 3 cm from bottom $this->SetY(-20); /* write reporting */ - $this->Cell(143,6,'Total page ','T',0,'R'); /* HTVA */ + $flag_tva=(count($this->a_Tva) > 4)?true:false; + if ( ! $flag_tva) + $this->Cell(143,6,'Total page ','T',0,'R'); /* HTVA */ + else + $this->Cell(78,6,'Total page ','T',0,'R'); /* HTVA */ + $this->Cell(15,6,nbm($this->tp_htva),'T',0,'R'); /* HTVA */ if ( $this->jrn_type !='VEN') { @@ -173,8 +182,13 @@ class Print_Ledger_Simple extends PDF $this->Cell(15,6,nbm($this->tp_tvac),'T',0,'R'); /* Tvac */ $this->Ln(2); - - $this->Cell(143,6,'report',0,0,'R'); /* HTVA */ + $flag_tva=(count($this->a_Tva) > 4)?true:false; + + if ( ! $flag_tva) + $this->Cell(143,6,'report',0,0,'R'); + else + $this->Cell(78,6,'report',0,0,'R'); + $this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */ if ( $this->jrn_type !='VEN') { @@ -208,11 +222,20 @@ class Print_Ledger_Simple extends PDF bcscale(2); $http=new HttpInput(); - $a_jrn=$this->ledger->get_operation($http->get('from_periode',"number"), - $http->get('to_periode',"number")); - + $ledger_history=Acc_Ledger_History::factory($this->cn, + array($this->ledger->id), + $http->get('from_periode','number'), + $http->get('to_periode','number'), + 'D', + $this->filter_operation); + $ledger_history->get_row(); + $a_jrn=$ledger_history->get_data(); + if ( $a_jrn == null ) return; + // Count the number of VAT cols + $flag_tva=(count($this->a_Tva) > 4)?true:false; + // Prepare the query for reconcile date $prepared_query=new Prepared_Query($this->ledger->db); $prepared_query->prepare_reconcile_date(); @@ -239,22 +262,23 @@ class Print_Ledger_Simple extends PDF } $row=$a_jrn[$i]; - $ret_reconcile=$this->ledger->db->execute('reconcile_date',array($row['id'])); - $this->LongLine(15,5,($row['pj']),0); - $this->write_cell(10,5,$row['date_fmt'],0,0); - $this->write_cell(13,5,$row['internal'],0,0); - list($qc,$name)=$this->get_tiers($row['id'],$this->jrn_type); + $ret_reconcile=$this->ledger->db->execute('reconcile_date',array($row['jr_id'])); + $this->LongLine(15,5,($row['jr_pj_number']),0); + $this->write_cell(10,5,$row['str_date_short'],0,0); + $this->write_cell(13,5,$row['jr_internal'],0,0); + list($qc,$name)=$this->get_tiers($row['jr_id'],$this->jrn_type); $this->LongLine(40,5,"[".$qc."]".$name,0,'L'); - $this->LongLine(65,5,mb_substr($row['comment'],0,150),0,'L'); + if ( !$flag_tva ) { + $this->LongLine(65,5,mb_substr($row['jr_comment'],0,150),0,'L'); + } /* get other amount (without vat, total vat included, private, ND */ $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']); - - $this->write_cell(15,5,nbm($other['price']),0,0,'R'); - if ( $this->jrn_type !='VEN') + + if ( $ledger_history->get_ledger_type() !='VEN') { $this->write_cell(15,5,nbm($other['priv']),0,0,'R'); $this->write_cell(15,5,nbm($other['tva_nd']),0,0,'R'); @@ -271,11 +295,11 @@ class Print_Ledger_Simple extends PDF $l_tvac=bcadd($l_tvac,$other['tva_nd']); $this->write_cell(15,5,nbm($l_tvac),0,0,'R'); $this->line_new(2); - $this->write_cell(15,5, _("Payé par")); // Add the payment information on another row $max=Database::num_row($ret_reconcile); $str_payment=""; if ($max > 0) { + $this->write_cell(15,5, _("Payé par")); $sep=""; for ($e=0;$e<$max;$e++) { $row=Database::fetch_array($ret_reconcile, $e); diff --git a/include/class/print_ledger_simple_without_vat.class.php b/include/class/print_ledger_simple_without_vat.class.php index 688638dc2..751961cc7 100644 --- a/include/class/print_ledger_simple_without_vat.class.php +++ b/include/class/print_ledger_simple_without_vat.class.php @@ -27,7 +27,8 @@ require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; class Print_Ledger_Simple_Without_Vat extends PDF { - public function __construct ($p_cn,$p_jrn) + private $filter_operation; + public function __construct ($p_cn,$p_jrn,$p_filter_operation) { if($p_cn == null) die("No database connection. Abort."); @@ -47,7 +48,7 @@ class Print_Ledger_Simple_Without_Vat extends PDF $this->rap_htva=$this->previous['price']; $this->rap_tvac=$this->previous['price']; $this->rap_priv=$this->previous['priv']; - + $this->filter_operation=$p_filter_operation; } @@ -142,8 +143,14 @@ class Print_Ledger_Simple_Without_Vat extends PDF function export() { $http=new HttpInput; - $a_jrn=$this->ledger->get_operation($http->get('from_periode','number'),$http->get('to_periode','number')); - + $ledger_history=Acc_Ledger_History::factory($this->cn, + array($this->ledger->id), + $http->get('from_periode','number'), + $http->get('to_periode','number'), + 'D', + $this->filter_operation); + $a_jrn=$ledger_history->get_row(); + if ( $a_jrn == null ) return; // Prepare the query for reconcile date @@ -154,14 +161,14 @@ class Print_Ledger_Simple_Without_Vat extends PDF { $row=$a_jrn[$i]; - $this->LongLine(15,5,($row['pj']),0); - $this->write_cell(15,5,$row['date_fmt'],0,0); - $this->write_cell(20,5,$row['internal'],0,0); - list($qc,$name)=$this->get_tiers($row['id'],$this->jrn_type); + $this->LongLine(15,5,($row['jr_pj_number']),0); + $this->write_cell(15,5,$row['str_date_short'],0,0); + $this->write_cell(20,5,$row['jr_internal'],0,0); + list($qc,$name)=$this->get_tiers($row['jr_id'],$this->jrn_type); $this->write_cell(20,5,$qc,0,0); $this->LongLine(40,5,$name,0,'L'); - $this->LongLine(105,5,$row['comment'],0,'L'); + $this->LongLine(105,5,$row['jr_comment'],0,'L'); /* get other amount (without vat, total vat included, private, ND */ $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']); @@ -171,7 +178,7 @@ class Print_Ledger_Simple_Without_Vat extends PDF $this->rap_priv+=$other['priv']; - if ( $this->jrn_type !='VEN') + if ( $ledger_history->get_ledger_type() !='VEN') { $this->write_cell(15,5,sprintf("%.2f",$other['priv']),0,0,'R'); } diff --git a/include/constant.php b/include/constant.php index 5d0fc867e..5f5dc71a4 100644 --- a/include/constant.php +++ b/include/constant.php @@ -108,7 +108,7 @@ if ( !defined ("NOALYSS_PACKAGE_REPOSITORY")) { if ( ! defined ("SYSINFO_DISPLAY")) { define ("SYSINFO_DISPLAY",TRUE); } -define ("DBVERSION",139); +define ("DBVERSION",140); define ("MONO_DATABASE",25); define ("DBVERSIONREPO",18); define ('NOTFOUND','--not found--'); diff --git a/include/export/export_ledger_csv.php b/include/export/export_ledger_csv.php index 507055a1c..8249fc97c 100644 --- a/include/export/export_ledger_csv.php +++ b/include/export/export_ledger_csv.php @@ -57,6 +57,7 @@ try $get_option=$http->get('p_simple', "string"); $get_from_periode=$http->get('from_periode', 'number'); $get_to_periode=$http->get('to_periode', 'number'); + $filter_operation=$http->get("operation_type"); } catch (Exception $exc) { @@ -119,14 +120,14 @@ if ( $get_option=="E") case 'VEN': $ledger=new Acc_Ledger_Sold($cn, $get_jrn); $ret_detail=$ledger->get_detail_sale($get_from_periode, - $get_to_periode); + $get_to_periode,$filter_operation); $a_heading=Acc_Ledger_Sold::heading_detail_sale(); break; case 'ACH': $ledger=new Acc_Ledger_Purchase($cn, $get_jrn); $ret_detail=$ledger->get_detail_purchase($get_from_periode, - $get_to_periode); + $get_to_periode,$filter_operation); $a_heading=Acc_Ledger_Purchase::heading_detail_purchase(); break; default: @@ -199,6 +200,7 @@ if ($get_option=='A') $get_from_periode, $get_to_periode, 'A'); } + $acc_ledger_history->set_filter_operation($filter_operation); $acc_ledger_history->export_csv(); exit; } @@ -298,6 +300,7 @@ if ($get_option=="L" || $get_option == 'D') $get_from_periode, $get_to_periode, 'D'); } + $acc_ledger_history->set_filter_operation($filter_operation); $acc_ledger_history->export_csv(); return; } @@ -309,12 +312,14 @@ if ($get_option=="L" || $get_option == 'D') { $acc_ledger_history=new Acc_Ledger_History_Purchase($cn, [$Jrn->id], $get_from_periode, $get_to_periode, 'D'); + $acc_ledger_history->set_filter_operation($filter_operation); $acc_ledger_history->export_csv(); } if ($jrn_type=="VEN") { $acc_ledger_history=new Acc_Ledger_History_Sale($cn, [$Jrn->id], $get_from_periode, $get_to_periode, 'D'); + $acc_ledger_history->set_filter_operation($filter_operation); $acc_ledger_history->export_csv(); } } diff --git a/include/export/export_ledger_pdf.php b/include/export/export_ledger_pdf.php index 5312ca267..7cdbb18f1 100644 --- a/include/export/export_ledger_pdf.php +++ b/include/export/export_ledger_pdf.php @@ -46,7 +46,7 @@ try { $jrn_id=$http->get('jrn_id',"number"); $p_simple=$http->get('p_simple',"string"); - + $filter_operation=$http->get("operation_type"); } catch (Exception $exc) @@ -74,8 +74,8 @@ $ret = ""; $jrn_type = $Jrn->get_type(); -$pdf = Print_Ledger::factory($cn, $p_simple, "PDF", $Jrn); - +$pdf = Print_Ledger::factory($cn, $p_simple, "PDF", $Jrn,$filter_operation); +$pdf->set_filter_operation($filter_operation); $pdf->setDossierInfo($Jrn->jrn_def_name); $pdf->AliasNbPages(); $pdf->AddPage(); diff --git a/include/export/export_printtva_pdf.php b/include/export/export_printtva_pdf.php index 19203c331..4954bf4ac 100644 --- a/include/export/export_printtva_pdf.php +++ b/include/export/export_printtva_pdf.php @@ -174,7 +174,7 @@ for ($i = 0; $i < $nb_sale; $i++) { } $pdf->line_new(); -$nb_array = count($array); +$nb_array = count($a_sum); // initialize totals for ($e=2;$e<$nb_col;$e++){ $a_tot[$a_col[$e]]=0; @@ -187,14 +187,14 @@ for ($i = 0; $i < $nb_array; $i++) { $colname=$a_col[$e]; if ( $e ==0 ) { // first column TVA_LABEL - $pdf->write_cell(40, 5, $array[$i][$colname], 1, 0, 'L'); + $pdf->write_cell(40, 5, $a_sum[$i][$colname], 1, 0, 'L'); } elseif ($e == 1 ){ // Secund col. tva rate - $pdf->write_cell(40, 5, nbm($array[$i][$colname]*100), 1, 0, 'R'); + $pdf->write_cell(40, 5, nbm($a_sum[$i][$colname]*100), 1, 0, 'R'); }else { // Other cols,display amount and compute total - $a_tot[$colname] = bcadd($a_tot[$colname], $array[$i][$colname]); - $pdf->write_cell(40, 5, nbm($array[$i][$colname]), 1, 0, 'R'); + $a_tot[$colname] = bcadd($a_tot[$colname], $a_sum[$i][$colname]); + $pdf->write_cell(40, 5, nbm($a_sum[$i][$colname]), 1, 0, 'R'); } } $pdf->line_new(); @@ -328,6 +328,7 @@ for ($e=0;$e<$nb_col;$e++){ } $pdf->line_new(); +$array=$tax_summary->get_summary_purchase(); $nb_array = count($array); // initialize totals for ($e=2;$e<$nb_col;$e++){ diff --git a/include/impress_jrn.inc.php b/include/impress_jrn.inc.php index 0b81f45a6..aaaadd12b 100644 --- a/include/impress_jrn.inc.php +++ b/include/impress_jrn.inc.php @@ -150,6 +150,20 @@ $a = array( ); $w->selected = 1; print ''; +/// All operation +$s_operation = new ISelect("operation_type"); +$s_operation->value=array( + array("label"=>_("Toutes les opérations"),"value"=>"all"), + array("label"=>_("Uniquement payées"),"value"=>"paid"), + array("label"=>_("Uniquement non payées"),"value"=>"unpaid") + ); +$s_operation->selected=$http->get("operation_type","string","all"); +echo ""; +echo td(_("Uniquement pour journaux vente et achat").Icon_Action::infobulle(75)); +echo td($s_operation->input()); +echo ''; + +/// Type of printing print ''; $simple=$http->get("p_simple","string","L"); $w->selected = $simple; @@ -182,6 +196,7 @@ if (isset($_REQUEST['bt_html'])) $hid->input("jrn_id", $jrn_id) . $hid->input("from_periode", $from_periode) . $hid->input("to_periode", $to_periode); + echo $hid->input("operation_type", $s_operation->selected); echo $hid->input("p_simple", $simple); echo HtmlInput::get_to_hidden(array('ac', 'type')); echo ""; @@ -195,6 +210,7 @@ if (isset($_REQUEST['bt_html'])) $hid->input("from_periode", $from_periode) . $hid->input("to_periode", $to_periode); echo $hid->input("p_simple", $simple); + echo $hid->input("operation_type", $s_operation->selected); echo HtmlInput::get_to_hidden(array('ac', 'type')); echo ""; @@ -220,7 +236,7 @@ if (isset($_REQUEST['bt_html'])) $a_ledger=[$jrn_id]; } - $ledger_history=Acc_Ledger_History::factory($cn,$a_ledger,$from_periode,$to_periode,$simple); + $ledger_history=Acc_Ledger_History::factory($cn,$a_ledger,$from_periode,$to_periode,$simple,$s_operation->selected); $ledger_history->export_html(); diff --git a/include/lib/database_core.class.php b/include/lib/database_core.class.php index 8a8d3d24c..3deb582af 100644 --- a/include/lib/database_core.class.php +++ b/include/lib/database_core.class.php @@ -953,7 +953,7 @@ class DatabaseCore static function nb_column($p_ret) { return pg_num_fields($p_ret); } - + } /* test::test_me(); */ diff --git a/include/lib/message_javascript.php b/include/lib/message_javascript.php index fb03d36b2..c702b588e 100644 --- a/include/lib/message_javascript.php +++ b/include/lib/message_javascript.php @@ -105,4 +105,5 @@ content[71]=""; content[73]=""; content[74]=""; +content[75]=""; \ No newline at end of file diff --git a/include/sql/patch/upgrade139.sql b/include/sql/patch/upgrade139.sql new file mode 100644 index 000000000..105adfa4c --- /dev/null +++ b/include/sql/patch/upgrade139.sql @@ -0,0 +1,119 @@ +begin; +DROP VIEW public.v_detail_sale; +DROP VIEW public.v_detail_purchase; + +CREATE OR REPLACE VIEW public.v_detail_sale +AS WITH m AS ( + SELECT sum(quant_sold_1.qs_price) AS htva, + sum(quant_sold_1.qs_vat) AS tot_vat, + sum(quant_sold_1.qs_vat_sided) AS tot_tva_np, + jrn_1.jr_id + FROM quant_sold quant_sold_1 + JOIN jrnx jrnx_1 USING (j_id) + JOIN jrn jrn_1 ON jrnx_1.j_grpt = jrn_1.jr_grpt_id + GROUP BY jrn_1.jr_id + ) + SELECT jrn.jr_id, + jrn.jr_date, + jrn.jr_date_paid, + jrn.jr_ech, + jrn.jr_tech_per, + jrn.jr_comment, + jrn.jr_pj_number, + jrn.jr_internal, + jrn.jr_def_id, + jrnx.j_poste, + jrnx.j_text, + jrnx.j_qcode, + jrn.jr_rapt, + quant_sold.qs_fiche AS item_card, + a.name AS item_name, + quant_sold.qs_client, + b.vw_name AS tiers_name, + b.quick_code, + tva_rate.tva_label, + tva_rate.tva_comment, + tva_rate.tva_both_side, + quant_sold.qs_vat_sided AS vat_sided, + quant_sold.qs_vat_code AS vat_code, + quant_sold.qs_vat AS vat, + quant_sold.qs_price AS price, + quant_sold.qs_quantite AS quantity, + quant_sold.qs_price / quant_sold.qs_quantite AS price_per_unit, + m.htva, + m.tot_vat, + m.tot_tva_np, + oc.oc_amount, + oc.oc_vat_amount, + ( SELECT currency.cr_code_iso + FROM currency + WHERE jrn.currency_id = currency.id) AS cr_code_iso + FROM jrn + JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt + JOIN quant_sold USING (j_id) + JOIN vw_fiche_name a ON quant_sold.qs_fiche = a.f_id + JOIN vw_fiche_attr b ON quant_sold.qs_client = b.f_id + JOIN tva_rate ON quant_sold.qs_vat_code = tva_rate.tva_id + JOIN m ON m.jr_id = jrn.jr_id + LEFT JOIN operation_currency oc ON oc.j_id = jrnx.j_id; + + +CREATE OR REPLACE VIEW public.v_detail_purchase +AS WITH m AS ( + SELECT sum(quant_purchase_1.qp_price) AS htva, + sum(quant_purchase_1.qp_vat) AS tot_vat, + sum(quant_purchase_1.qp_vat_sided) AS tot_tva_np, + jrn_1.jr_id + FROM quant_purchase quant_purchase_1 + JOIN jrnx jrnx_1 USING (j_id) + JOIN jrn jrn_1 ON jrnx_1.j_grpt = jrn_1.jr_grpt_id + GROUP BY jrn_1.jr_id + ) + SELECT jrn.jr_id, + jrn.jr_date, + jrn.jr_date_paid, + jrn.jr_ech, + jrn.jr_tech_per, + jrn.jr_comment, + jrn.jr_pj_number, + jrn.jr_internal, + jrn.jr_def_id, + jrnx.j_poste, + jrnx.j_text, + jrnx.j_qcode, + jrn.jr_rapt, + quant_purchase.qp_fiche AS item_card, + a.name AS item_name, + quant_purchase.qp_supplier, + b.vw_name AS tiers_name, + b.quick_code, + tva_rate.tva_label, + tva_rate.tva_comment, + tva_rate.tva_both_side, + quant_purchase.qp_vat_sided AS vat_sided, + quant_purchase.qp_vat_code AS vat_code, + quant_purchase.qp_vat AS vat, + quant_purchase.qp_price AS price, + quant_purchase.qp_quantite AS quantity, + quant_purchase.qp_price / quant_purchase.qp_quantite AS price_per_unit, + quant_purchase.qp_nd_amount AS non_ded_amount, + quant_purchase.qp_nd_tva AS non_ded_tva, + quant_purchase.qp_nd_tva_recup AS non_ded_tva_recup, + m.htva, + m.tot_vat, + m.tot_tva_np, + oc.oc_amount, + oc.oc_vat_amount, + ( SELECT currency.cr_code_iso + FROM currency + WHERE jrn.currency_id = currency.id) AS cr_code_iso + FROM jrn + JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt + JOIN quant_purchase USING (j_id) + JOIN vw_fiche_name a ON quant_purchase.qp_fiche = a.f_id + JOIN vw_fiche_attr b ON quant_purchase.qp_supplier = b.f_id + JOIN tva_rate ON quant_purchase.qp_vat_code = tva_rate.tva_id + JOIN m ON m.jr_id = jrn.jr_id + LEFT JOIN operation_currency oc ON oc.j_id = jrnx.j_id; +insert into version (val,v_description) values (140,'Filter operation PRINTJRN'); +commit ; \ No newline at end of file diff --git a/unit-test/create-dossier-test.sh b/unit-test/create-dossier-test.sh index 47884ba16..51d1d3607 100755 --- a/unit-test/create-dossier-test.sh +++ b/unit-test/create-dossier-test.sh @@ -3,5 +3,5 @@ DOSSIER_TEST=rel70dossier25 createdb $DOSSIER_TEST -pg_restore -Fc --no-owner --no-privilege --verbose -d $DOSSIER_TEST db/dossiertest191101-2109.bin +pg_restore -Fc --no-owner --no-privilege --verbose -d $DOSSIER_TEST db/dossiertest191112-1806.bin diff --git a/unit-test/include/class/acc_account_ledgerTest.class.php b/unit-test/include/class/acc_account_ledgerTest.class.php index 9882b3247..d9c5101f2 100644 --- a/unit-test/include/class/acc_account_ledgerTest.class.php +++ b/unit-test/include/class/acc_account_ledgerTest.class.php @@ -201,10 +201,10 @@ class Acc_Account_LedgerTest extends TestCase function DataBelong_ledger() { return array( - array(0, -1), + array(-1, 0), array(1, -1), - array(3, -1), - array(2, 0), + array(3, 0), + array(2, -1), array(4, 0) ); } diff --git a/unit-test/include/class/acc_balanceTest.class.php b/unit-test/include/class/acc_balanceTest.class.php index 5f8193707..a649f11cd 100644 --- a/unit-test/include/class/acc_balanceTest.class.php +++ b/unit-test/include/class/acc_balanceTest.class.php @@ -48,7 +48,7 @@ class Acc_BalanceTest extends TestCase $min=$g_connection->get_value("select min(p_id) from parm_periode"); $this->object->jrn=NULL; $array=$this->object->get_row($min,$max); - $this->assertEquals(29,count($array)); + $this->assertEquals(31,count($array)); $this->object->jrn=[2,4]; $array=$this->object->get_row($min,$max); $this->assertEquals(10,count($array)); @@ -64,9 +64,9 @@ class Acc_BalanceTest extends TestCase $this->object->filter_cat(array()); $this->assertEquals($this->object->jrn,null); $this->object->filter_cat(array('2'=>'FIN')); - $this->assertEquals($this->object->jrn,[1]); + $this->assertEquals([1,83],$this->object->jrn); $this->object->filter_cat(array('1'=>'ACH','2'=>'FIN')); - $this->assertEquals($this->object->jrn,[3,35,1]); + $this->assertEquals($this->object->jrn,[3,35,1,83]); } /** *@covers Acc_Balance::summary_add diff --git a/unit-test/include/class/acc_bilanTest.class.php b/unit-test/include/class/acc_bilanTest.class.php index c72baa648..fa8a5dfc7 100644 --- a/unit-test/include/class/acc_bilanTest.class.php +++ b/unit-test/include/class/acc_bilanTest.class.php @@ -140,7 +140,7 @@ class Acc_BilanTest extends TestCase $this->assertTrue(isset($this->object->C70)); $this->assertTrue(isset($this->object->C60)); - $this->assertEquals($this->object->C70,445.6); + $this->assertEquals($this->object->C70,456.8); $this->assertEquals($this->object->C60,0); } diff --git a/unit-test/include/class/acc_ledgerTest.class.php b/unit-test/include/class/acc_ledgerTest.class.php index 1e50b480b..fbc516180 100644 --- a/unit-test/include/class/acc_ledgerTest.class.php +++ b/unit-test/include/class/acc_ledgerTest.class.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; /** - * Generated by PHPUnit_SkeletonGenerator on 2014-11-09 at 12:39:58. + * @coversDefaultClass Acc_Ledger */ class Acc_LedgerTest extends TestCase { @@ -11,7 +11,7 @@ class Acc_LedgerTest extends TestCase * @var Acc_Ledger */ protected $object; - protected function getDataSet() + protected function getDataSet() { $dataSet = new PHPUnit_Extensions_Database_DataSet_CsvDataSet(); $dataSet->addTable('jrn', dirname(__FILE__)."/jrn.csv"); @@ -61,23 +61,44 @@ class Acc_LedgerTest extends TestCase { } - + /** + * covers ::existing_vat + * covers ::get_type + */ + public function testExisting_vat() + { + $this->object->set_ledger_id(2); + $this->assertEquals($this->object->get_type(),'VEN',"Sales ledger"); + $a_vat=$this->object->existing_vat(); + $this->assertEquals(2,count($a_vat)); + + $this->object->set_ledger_id(3); + $this->assertEquals($this->object->get_type(),'ACH',"Purchases ledger"); + $a_vat=$this->object->existing_vat(); + $this->assertEquals(5,count($a_vat)); + } /** * @covers Acc_Ledger::get_last_pj - * @todo Implement testGet_last_pj(). */ public function testGet_last_pj() { $this->object->id=2; $sPj=$this->object->get_last_pj(2); - $this->assertEquals(9,$sPj); + $this->assertEquals(40,$sPj); + $this->object->id=0; + + try { + $this->object->get_last_pj(); + $this->assertTrue(FALSE,"get_last_pj exception non lancée"); + } catch (Exception $ex) { + $this->assertTrue(TRUE,"Exception si id =0"); + } } /** * @covers Acc_Ledger::get_type - * @todo Implement testGet_type(). */ public function testGet_type() { @@ -96,6 +117,10 @@ class Acc_LedgerTest extends TestCase $this->object->id=3; $type=$this->object->get_type(); $this->assertEquals('ACH',$type); + + $this->object->id=999; + $type=$this->object->get_type(); + $this->assertEquals(null,$type); } @@ -138,7 +163,6 @@ class Acc_LedgerTest extends TestCase } /** * @covers Acc_Ledger::display_warning - * @todo Implement testDisplay_warning(). */ public function testDisplay_warning() { @@ -148,7 +172,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::reverse - * @todo Implement testReverse(). */ public function testReverse() { @@ -170,18 +193,24 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_name - * @todo Implement testGet_name(). */ public function testGet_name() { $this->object->id=3; $name=$this->object->get_name(); $this->assertEquals('Achat',$name); + + $this->object->id=0; + $name=$this->object->get_name(); + $this->assertEquals('Grand Livre',$name); + + $this->object->id=1000; + $name=$this->object->get_name(); + $this->assertEquals(null,$name); } /** * @covers Acc_Ledger::get_rowSimple - * @todo Implement testGet_rowSimple(). */ public function testGet_rowSimple() { @@ -199,18 +228,16 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::guess_pj - * @todo Implement testGuess_pj(). */ public function testGuess_pj() { $this->object->id=2; $r=$this->object->guess_pj(); - $this->assertEquals("VEN10",$r); + $this->assertEquals("VEN40",$r); } /** * @covers Acc_Ledger::get_propertie - * @todo Implement testGet_propertie(). */ public function testGet_propertie() { @@ -219,6 +246,9 @@ class Acc_LedgerTest extends TestCase $array=$this->object->get_propertie(); // there are 16 columns in jrn_def $this->assertEquals(count($array),20); + $this->object->id=0; + $array=$this->object->get_propertie(); + $this->assertEquals(null,$array); } /** @@ -255,7 +285,6 @@ class Acc_LedgerTest extends TestCase } /** * @covers Acc_Ledger::get_solde - * @todo Implement testGet_solde(). */ public function testGet_solde() { @@ -264,23 +293,21 @@ class Acc_LedgerTest extends TestCase $max=$g_connection->get_value("select max(p_id) from parm_periode"); $min=$g_connection->get_value("select min(p_id) from parm_periode"); $solde=$ledger->get_solde($min,$max); - $this->assertEquals($solde[0],490.77); - $this->assertEquals($solde[1],490.77); + $this->assertEquals($solde[0],4175.02); + $this->assertEquals($solde[1],4175.02); } /** * @covers Acc_Ledger::select_ledger - * @todo Implement testSelect_ledger(). */ public function testSelect_ledger() { $select_available=$this->object->select_ledger(); - $this->assertEquals(4,count($select_available->value)); + $this->assertEquals(7,count($select_available->value)); } /** * @covers Acc_Ledger::get_fiche_def - * @todo Implement testGet_fiche_def(). */ public function testGet_fiche_def() { @@ -293,7 +320,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_class_def - * @todo Implement testGet_class_def(). */ public function testGet_class_def() { @@ -306,7 +332,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::confirm - * @todo Implement testConfirm(). */ public function testConfirm() { @@ -358,7 +383,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_min_row - * @todo Implement testGet_min_row(). */ public function testGet_min_row() { @@ -375,7 +399,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::input - * @todo Implement testInput(). */ public function testInput() { @@ -406,7 +429,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::is_closed - * @todo Implement testIs_closed(). */ public function testIs_closed() { @@ -418,7 +440,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::verify - * @todo Implement testVerify(). */ public function testVerify_Ledger() { @@ -451,7 +472,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::compute_internal_code - * @todo Implement testCompute_internal_code(). */ public function testCompute_internal_code() { @@ -506,6 +526,8 @@ class Acc_LedgerTest extends TestCase $this->assertEquals(1,$cnt); $ledger->delete(); + $g_connection->exec_sql("alter sequence s_jrn_pj4 restart with 43"); + $cnt=$g_connection->get_value("select count(*) from jrn where jr_mt=$1",[$array['mt']]); $this->assertEquals(0,$cnt); @@ -513,7 +535,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::next_number - * @todo Implement testNext_number(). */ public function testNext_number() { @@ -524,7 +545,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_first - * @todo Implement testGet_first(). */ public function testGet_first() { @@ -536,7 +556,9 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_all_fiche_def - * @todo Implement testGet_all_fiche_def(). + * @todo + * $this->object->set_ledger_id(3); + $this->assertEquals($this->object->is_enable(),TRUE); Implement testGet_all_fiche_def(). */ public function testGet_all_fiche_def() { @@ -547,16 +569,15 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_saldo_exercice - * @todo Implement testGet_saldo_exercice(). */ public function testGet_saldo_exercice() { $result=[ - ["solde"=> 658.2500 , "j_poste"=> "4400004", "j_qcode"=> "FOURNI"], + ["solde"=> 658.25 , "j_poste"=> "4400004", "j_qcode"=> "FOURNI"], ["solde"=> 490.7700 , "j_poste"=> "4000005", "j_qcode"=> "CLIENT1"], - ["solde"=> 21.9600, "j_poste"=> "4112", "j_qcode"=> ""], + ["solde"=> 87.8400, "j_poste"=> "4112", "j_qcode"=> ""], ["solde"=>-85.1700 , "j_poste"=> "4511", "j_qcode"=> ""], - ["solde"=> -863.2100 , "j_poste"=>"4400005", "j_qcode"=> "FOURNI1"] + ["solde"=> -1496.3400 , "j_poste"=>"4400005", "j_qcode"=> "FOURNI1"] ]; $get=$this->object->get_saldo_exercice("2018"); $nb_get=count($get); @@ -580,18 +601,16 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_last_date - * @todo Implement testGet_last_date(). */ public function testGet_last_date() { $this->object->set_ledger_id(2); $last_date=$this->object->get_last_date(); - $this->assertEquals("24.04.2018",$last_date); + $this->assertEquals("24.04.2019",$last_date); } /** * @covers Acc_Ledger::get_id - * @todo Implement testGet_id(). */ public function testGet_id() { @@ -603,7 +622,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::array_cat - * @todo Implement testArray_cat(). */ public function testArray_cat() { @@ -613,7 +631,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_tiers - * @todo Implement testGet_tiers(). */ public function testGet_tiers() { @@ -631,6 +648,9 @@ class Acc_LedgerTest extends TestCase $this->assertTrue($this->object->get_tiers("VEN",$jr_id)!=' '); } + /** + * @covers Acc_Ledger::get_tiers_id + */ public function testGet_tiers_id() { global $g_connection; @@ -650,7 +670,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::verify_ledger - * @todo Implement testVerify_ledger(). */ public function testVerify_Operation() { @@ -751,7 +770,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::input_new - * @todo Implement testInput_new(). */ public function testInput_new() { @@ -802,7 +820,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::delete_ledger - * @todo Implement testDelete_ledger(). */ public function testDelete_ledger() { @@ -832,7 +849,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_operation_date - * @todo Implement testGet_operation_date(). */ public function testGet_operation_date() { @@ -849,7 +865,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_supplier_now - * @todo Implement testGet_supplier_now(). */ public function testGet_supplier_now() { @@ -858,7 +873,6 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_supplier_late - * @todo Implement testGet_supplier_late(). */ public function testGet_supplier_late() { @@ -867,20 +881,34 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::get_customer_now - * @todo Implement testGet_customer_now(). */ public function testGet_customer_now() { $this->assertTrue(is_array($this->object->get_customer_now())); } - /** + /** * @covers Acc_Ledger::get_customer_late - * @todo Implement testGet_customer_late(). */ public function testGet_customer_late() { $this->assertTrue(is_array($this->object->get_customer_late())); } + /** + * @covers Acc_Ledger::set_ledger_id + * @covers Acc_Ledger::is_enable + */ + public function testIs_Enable() + { + $this->object->set_ledger_id(83); + $this->assertEquals($this->object->is_enable(),0); + + $this->object->set_ledger_id(4); + $this->assertEquals($this->object->is_enable(),1); + $this->object->set_ledger_id(2); + $this->assertEquals($this->object->is_enable(),1); + $this->object->set_ledger_id(3); + $this->assertEquals($this->object->is_enable(),1); + } } diff --git a/unit-test/include/class/acc_ledger_finTest.class.php b/unit-test/include/class/acc_ledger_finTest.class.php index 4e3d4718e..69eeb34f5 100644 --- a/unit-test/include/class/acc_ledger_finTest.class.php +++ b/unit-test/include/class/acc_ledger_finTest.class.php @@ -108,6 +108,7 @@ class Acc_Ledger_FinTest extends TestCase $this->assertContains('',$result); $this->assertContains('',$result); + } private function clean_operation() { @@ -125,6 +126,8 @@ class Acc_Ledger_FinTest extends TestCase [ '1572695340.6768'] ); $g_connection->exec_sql(' delete from jrnx where j_grpt not in (select jr_grpt_id from jrn)'); + $g_connection->exec_sql("alter sequence s_jrn_pj1 restart with 48"); + $g_connection->commit(); } @@ -154,7 +157,7 @@ class Acc_Ledger_FinTest extends TestCase $ret=$this->object->insert($array); $this->assertContains('',$ret); $this->assertContains(' HREF="javascript:modifyOperation',$ret); - $this->assertContains('-935,91',$ret); + $this->assertContains('-1.095,39',$ret); $this->clean_operation(); } diff --git a/unit-test/include/class/acc_ledger_history_financialTest.class.php b/unit-test/include/class/acc_ledger_history_financialTest.class.php index 7e556543b..ae420120d 100644 --- a/unit-test/include/class/acc_ledger_history_financialTest.class.php +++ b/unit-test/include/class/acc_ledger_history_financialTest.class.php @@ -24,6 +24,7 @@ use PHPUnit\Framework\TestCase; /** * @file * @brief concerne acc_ledger_history_financialTest.class + * @coversDefaultClass Acc_History_Financial */ class Acc_Ledger_History_FinancialTest extends TestCase { @@ -63,7 +64,7 @@ class Acc_Ledger_History_FinancialTest extends TestCase function testGet__row() { $this->object->get_row(); - $this->assertEquals(5, count($this->object->get_data())); + $this->assertEquals(7, count($this->object->get_data())); } //@covers Acc_Ledger_History_Financial::export_html @@ -93,4 +94,12 @@ class Acc_Ledger_History_FinancialTest extends TestCase $this->assertFileExists(__DIR__."/file/".$name); } + /** + * @covers Acc_Ledger_History::get_ledger_type + */ + + function testGet_Ledger_type() + { + $this->assertEquals($this->object->get_ledger_type(),'FIN'); + } } diff --git a/unit-test/include/class/acc_ledger_history_genericTest.class.php b/unit-test/include/class/acc_ledger_history_genericTest.class.php index c9b3f4605..a7c0436ba 100644 --- a/unit-test/include/class/acc_ledger_history_genericTest.class.php +++ b/unit-test/include/class/acc_ledger_history_genericTest.class.php @@ -113,5 +113,12 @@ class Acc_Ledger_History_GenericTest extends TestCase $this->save_file($name, $content); $this->assertFileExists(__DIR__."/file/".$name); } - + /** + * @covers Acc_Ledger_History::get_ledger_type + */ + + function testGet_Ledger_type() + { + $this->assertEquals($this->object->get_ledger_type(),'ODS'); + } } diff --git a/unit-test/include/class/acc_ledger_history_purchaseTest.class.php b/unit-test/include/class/acc_ledger_history_purchaseTest.class.php index cead9a357..c9eca215e 100644 --- a/unit-test/include/class/acc_ledger_history_purchaseTest.class.php +++ b/unit-test/include/class/acc_ledger_history_purchaseTest.class.php @@ -62,7 +62,7 @@ class Acc_Ledger_History_PurchaseTest extends TestCase function testGet_Row() { $this->object->get_row(); - $this->assertSame(count($this->object->get_data()),65); + $this->assertSame(count($this->object->get_data()),14); } //@covers Acc_Ledger_History_Financial::export_oneline_html @@ -112,5 +112,12 @@ class Acc_Ledger_History_PurchaseTest extends TestCase $this->save_file($name, $content); $this->assertFileExists(__DIR__."/file/".$name); } + /** + * @covers Acc_Ledger_History::get_ledger_type + */ + function testGet_Ledger_type() + { + $this->assertEquals($this->object->get_ledger_type(),'ACH'); + } } diff --git a/unit-test/include/class/acc_ledger_history_saleTest.class.php b/unit-test/include/class/acc_ledger_history_saleTest.class.php index 01cc92402..49ee0e02d 100644 --- a/unit-test/include/class/acc_ledger_history_saleTest.class.php +++ b/unit-test/include/class/acc_ledger_history_saleTest.class.php @@ -55,7 +55,7 @@ class Acc_Ledger_History_SaleTest extends TestCase function testGet_row() { $this->object->get_row(); - $this->assertSame(count($this->object->get_data()),4); + $this->assertSame(count($this->object->get_data()),6); } private function save_file($p_name,$content) { @@ -110,4 +110,12 @@ class Acc_Ledger_History_SaleTest extends TestCase $this->save_file($name, $content); $this->assertFileExists(__DIR__."/file/".$name); } + /** + * @covers Acc_Ledger_History::get_ledger_type + */ + + function testGet_Ledger_type() + { + $this->assertEquals($this->object->get_ledger_type(),'VEN'); + } } diff --git a/unit-test/include/class/acc_ledger_purchaseTest.class.php b/unit-test/include/class/acc_ledger_purchaseTest.class.php index e29421a48..966f613e4 100644 --- a/unit-test/include/class/acc_ledger_purchaseTest.class.php +++ b/unit-test/include/class/acc_ledger_purchaseTest.class.php @@ -3,8 +3,9 @@ use PHPUnit\Framework\TestCase; /** - * Generated by PHPUnit_SkeletonGenerator on 2014-11-08 at 14:20:36. * @backupGlobals enabled + * @coversDefaultClass Acc_Ledger_Purchase + * */ class Acc_Ledger_PurchaseTest extends TestCase { @@ -102,7 +103,6 @@ class Acc_Ledger_PurchaseTest extends TestCase /** * @covers Acc_Ledger_Purchase::insert - * @todo Implement testInsert(). */ public function testInsert() { @@ -128,7 +128,6 @@ class Acc_Ledger_PurchaseTest extends TestCase /** * @covers Acc_Ledger_Purchase::input - * @todo Implement testInput(). */ public function testInput() { @@ -138,7 +137,7 @@ class Acc_Ledger_PurchaseTest extends TestCase "acc_ledger_purchase_input.html", \Noalyss\Facility::page_start().$res); $this->assertContains( - '',$res); @@ -147,7 +146,6 @@ class Acc_Ledger_PurchaseTest extends TestCase /** * @covers Acc_Ledger_Purchase::confirm - * @todo Implement testConfirm(). */ public function testConfirm() { @@ -161,14 +159,29 @@ class Acc_Ledger_PurchaseTest extends TestCase $this->assertContains("value=\"Efface détail\" onClick=\"anc_key_clean('25','','658.25','','','0');",$ret); $this->assertContains('NAME="e_quant0" VALUE="1">',$ret); } - + private function clean_operation() { global $g_connection; $g_connection->exec_sql("delete from jrn where jr_mt=$1", ["1572704002.1732"]); $g_connection->exec_sql("delete from jrnx where j_grpt not in (select jr_grpt_id from jrn)"); + $g_connection->exec_sql("alter sequence s_jrn_pj3 restart with 52"); + } + /** + * @covers ::get_detail_purchase + */ + public function testget_detail_purchase() + { + // 92 = 1.1.2018 and 103 = 31.12.2018 + $ret=$this->object->get_detail_purchase(92,103,'all'); + $this->assertEquals(7,Database::num_row($ret),"all operation (no filter)"); + + + $ret=$this->object->get_detail_purchase(92,103,'paid'); + $this->assertEquals(2,Database::num_row($ret),'only paid operations'); - - + $ret=$this->object->get_detail_purchase(92,103,'unpaid'); + $this->assertEquals(5,Database::num_row($ret),'only unpaid operations'); + } } diff --git a/unit-test/include/class/acc_ledger_soldTest.class.php b/unit-test/include/class/acc_ledger_soldTest.class.php index 1ce4824e5..b5745bb00 100644 --- a/unit-test/include/class/acc_ledger_soldTest.class.php +++ b/unit-test/include/class/acc_ledger_soldTest.class.php @@ -3,8 +3,8 @@ use PHPUnit\Framework\TestCase; /** - * Generated by PHPUnit_SkeletonGenerator on 2014-11-08 at 14:20:37. * @backupGlobals enabled + * @coversDefaultClass Acc_Ledger_Sold */ class Acc_Ledger_SoldTest extends TestCase { @@ -83,6 +83,7 @@ class Acc_Ledger_SoldTest extends TestCase global $g_connection; $g_connection->exec_sql("delete from jrn where jr_mt=$1", ["1572714478.3155"]); $g_connection->exec_sql("delete from jrnx where j_grpt not in (select jr_grpt_id from jrn)"); + $g_connection->exec_sql("alter sequence s_jrn_pj2 restart with 40"); } /** * @covers Acc_Ledger_Sold::verify @@ -90,6 +91,7 @@ class Acc_Ledger_SoldTest extends TestCase public function testVerify() { $this->object->verify_operation($this->array); + $this->assertTrue(TRUE); } /** @@ -157,17 +159,6 @@ class Acc_Ledger_SoldTest extends TestCase $this->assertContains('ID="add_item" VALUE="Ajout article" onClick="ledger_add_row()">', $info); } - /** - * @covers Acc_Ledger_Sold::get_detail_sale - * @todo Implement testGet_detail_sale(). - */ - public function testGet_detail_sale() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } /** * @covers Acc_Ledger_Sold::heading_detail_sale @@ -175,10 +166,23 @@ class Acc_Ledger_SoldTest extends TestCase */ public function testHeading_detail_sale() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $a=$this->object->heading_detail_sale(); + $this->assertEquals(28,count($a)); } + /** + * @covers Acc_Ledger_Sold::get_detail_sale + */ + public function testget_detail_sale() + { + // 92 = 1.1.2018 and 103 = 31.12.2018 + $ret=$this->object->get_detail_sale(92,103,'all'); + $this->assertEquals(7,Database::num_row($ret),"all operation (no filter)"); + + + $ret=$this->object->get_detail_sale(92,103,'paid'); + $this->assertEquals(2,Database::num_row($ret),'only paid operations'); + $ret=$this->object->get_detail_sale(92,103,'unpaid'); + $this->assertEquals(5,Database::num_row($ret),'only unpaid operations'); + } } diff --git a/unit-test/include/class/data/tax_summary_getrow_purchase_t.php b/unit-test/include/class/data/tax_summary_getrow_purchase_t.php index 5bed31568..48f440a0a 100644 --- a/unit-test/include/class/data/tax_summary_getrow_purchase_t.php +++ b/unit-test/include/class/data/tax_summary_getrow_purchase_t.php @@ -1,5 +1,5 @@ array ( 'jrn_def_name' => 'Achat', @@ -37,8 +37,8 @@ $a_result = array ( 'tva_rate' => '0.2100', 'tva_both_side' => '0', 'qp_vat_code' => '1', - 'amount_vat' => '38.4300', - 'amount_wovat' => '183.0000', + 'amount_vat' => '44.5300', + 'amount_wovat' => '212.0000', 'amount_sided' => '0.0000', 'amount_noded_amount' => '0.0000', 'amount_noded_tax' => '0.0000', @@ -46,6 +46,21 @@ $a_result = array ( 'amount_private' => '0.0000', ), 3 => + array ( + 'jrn_def_name' => 'Achat', + 'tva_label' => '6%', + 'tva_rate' => '0.0600', + 'tva_both_side' => '0', + 'qp_vat_code' => '3', + 'amount_vat' => '5.2800', + 'amount_wovat' => '88.3200', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 4 => array ( 'jrn_def_name' => 'Achat', 'tva_label' => 'ART44', @@ -60,7 +75,7 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 4 => + 5 => array ( 'jrn_def_name' => 'Achat', 'tva_label' => 'EXPORT', @@ -75,7 +90,7 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 5 => + 6 => array ( 'jrn_def_name' => 'Achat', 'tva_label' => 'IMMO', @@ -90,7 +105,7 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 6 => + 7 => array ( 'jrn_def_name' => 'Achat', 'tva_label' => 'VOIT', @@ -105,22 +120,22 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 7 => + 8 => array ( 'jrn_def_name' => 'Frais Divers', 'tva_label' => '21%', 'tva_rate' => '0.2100', 'tva_both_side' => '0', 'qp_vat_code' => '1', - 'amount_vat' => '140.0400', - 'amount_wovat' => '666.8600', + 'amount_vat' => '244.5500', + 'amount_wovat' => '1164.5400', 'amount_sided' => '0.0000', 'amount_noded_amount' => '0.0000', 'amount_noded_tax' => '0.0000', 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 8 => + 9 => array ( 'jrn_def_name' => 'Frais Divers', 'tva_label' => 'EXPORT', @@ -135,7 +150,7 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 9 => + 10 => array ( 'jrn_def_name' => 'Frais Divers', 'tva_label' => 'IMMO', @@ -150,7 +165,7 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 10 => + 11 => array ( 'jrn_def_name' => 'Frais Divers', 'tva_label' => 'INTRA', @@ -165,7 +180,7 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 11 => + 12 => array ( 'jrn_def_name' => 'Frais Divers', 'tva_label' => 'VOIT', diff --git a/unit-test/include/class/data/tax_summary_getrow_sale_t.php b/unit-test/include/class/data/tax_summary_getrow_sale_t.php index 2a0aa767b..40bb4c765 100644 --- a/unit-test/include/class/data/tax_summary_getrow_sale_t.php +++ b/unit-test/include/class/data/tax_summary_getrow_sale_t.php @@ -8,8 +8,8 @@ array ( 'qs_vat_code' => '1', 'tva_rate' => '0.2100', 'tva_both_side' => '0', - 'amount_vat' => '16.8000', - 'amount_wovat' => '80.0000', + 'amount_vat' => '219.5700', + 'amount_wovat' => '1045.6000', 'amount_sided' => '0.0000', 'tva_type' => 'P', ), @@ -44,8 +44,8 @@ array ( 'qs_vat_code' => '1003', 'tva_rate' => '0.2100', 'tva_both_side' => '0', - 'amount_vat' => '10.7500', - 'amount_wovat' => '51.2000', + 'amount_vat' => '19.1500', + 'amount_wovat' => '91.2000', 'amount_sided' => '0.0000', 'tva_type' => 'P', ), diff --git a/unit-test/include/class/data/tax_summary_getsummary_purchase_t.php b/unit-test/include/class/data/tax_summary_getsummary_purchase_t.php index 2f628bcf0..a70d697bc 100644 --- a/unit-test/include/class/data/tax_summary_getsummary_purchase_t.php +++ b/unit-test/include/class/data/tax_summary_getsummary_purchase_t.php @@ -1,5 +1,4 @@ array ( @@ -35,8 +34,8 @@ $a_result = array ( 'tva_rate' => '0.2100', 'tva_both_side' => '0', 'qp_vat_code' => '1', - 'amount_vat' => '178.4700', - 'amount_wovat' => '849.8600', + 'amount_vat' => '289.0800', + 'amount_wovat' => '1376.5400', 'amount_sided' => '0.0000', 'amount_noded_amount' => '0.0000', 'amount_noded_tax' => '0.0000', @@ -44,6 +43,20 @@ $a_result = array ( 'amount_private' => '0.0000', ), 3 => + array ( + 'tva_label' => '6%', + 'tva_rate' => '0.0600', + 'tva_both_side' => '0', + 'qp_vat_code' => '3', + 'amount_vat' => '5.2800', + 'amount_wovat' => '88.3200', + 'amount_sided' => '0.0000', + 'amount_noded_amount' => '0.0000', + 'amount_noded_tax' => '0.0000', + 'amount_noded_return' => '0.0000', + 'amount_private' => '0.0000', + ), + 4 => array ( 'tva_label' => 'ART44', 'tva_rate' => '0.0000', @@ -57,7 +70,7 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 4 => + 5 => array ( 'tva_label' => 'EXPORT', 'tva_rate' => '0.0000', @@ -71,7 +84,7 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 5 => + 6 => array ( 'tva_label' => 'IMMO', 'tva_rate' => '0.2100', @@ -85,7 +98,7 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 6 => + 7 => array ( 'tva_label' => 'INTRA', 'tva_rate' => '0.0000', @@ -99,7 +112,7 @@ $a_result = array ( 'amount_noded_return' => '0.0000', 'amount_private' => '0.0000', ), - 7 => + 8 => array ( 'tva_label' => 'VOIT', 'tva_rate' => '0.2100', diff --git a/unit-test/include/class/data/tax_summary_getsummary_sale_t.php b/unit-test/include/class/data/tax_summary_getsummary_sale_t.php index b5adb41eb..37a88cc5b 100644 --- a/unit-test/include/class/data/tax_summary_getsummary_sale_t.php +++ b/unit-test/include/class/data/tax_summary_getsummary_sale_t.php @@ -1,5 +1,5 @@ array ( @@ -7,10 +7,10 @@ array ( 'qs_vat_code' => '1', 'tva_rate' => '0.2100', 'tva_both_side' => '0', - 'amount_vat' => '16.8000', - 'amount_wovat' => '80.0000', + 'amount_vat' => '219.5700', + 'amount_wovat' => '1045.6000', 'amount_sided' => '0.0000', - 'tva_payment_sale' => 'P', + 'tva_payment_sale' => 'O', ), 1 => array ( @@ -40,9 +40,9 @@ array ( 'qs_vat_code' => '1003', 'tva_rate' => '0.2100', 'tva_both_side' => '0', - 'amount_vat' => '10.7500', - 'amount_wovat' => '51.2000', + 'amount_vat' => '19.1500', + 'amount_wovat' => '91.2000', 'amount_sided' => '0.0000', - 'tva_payment_sale' => 'P', + 'tva_payment_sale' => 'O', ), ); diff --git a/unit-test/include/class/tax_summaryTest.class.php b/unit-test/include/class/tax_summaryTest.class.php index 6719d3b85..2b6d37058 100644 --- a/unit-test/include/class/tax_summaryTest.class.php +++ b/unit-test/include/class/tax_summaryTest.class.php @@ -89,7 +89,7 @@ class Tax_SummaryTest extends TestCase { $nb_result=count($p_array_expected); $nb_array=count($p_array); - $this->assertEquals($nb_result, $nb_array); + $this->assertEquals($nb_result, $nb_array,$p_scenario); $ix=0; switch ($jrn_type) { @@ -204,7 +204,7 @@ class Tax_SummaryTest extends TestCase $this->object->set_tva_type("T"); $array=$this->object->get_row_sale(); //-- For creating the array - // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getrow_sale_t.txt", var_export($array, TRUE)); + //Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getrow_sale_t.txt", var_export($array, TRUE)); require __DIR__."/data/tax_summary_getrow_sale_t.php"; $this->check_result("tva_type = T , get_row_sale",$array,$a_result,'VEN'); @@ -215,7 +215,7 @@ class Tax_SummaryTest extends TestCase $this->object->set_tva_type("T"); $array=$this->object->get_summary_purchase(); //-- For creating the array - // Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getsummary_purchase_t.txt", var_export($array, TRUE)); + Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getsummary_purchase_t.txt", var_export($array, TRUE)); require __DIR__."/data/tax_summary_getsummary_purchase_t.php"; $this->check_result("tva_type = T , get_summary_purchase",$array,$a_result,'SMRACH'); @@ -256,7 +256,7 @@ class Tax_SummaryTest extends TestCase $this->object->set_tva_type("T"); $array=$this->object->get_summary_sale(); //-- For creating the array - //Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getsummary_sale_t.txt", var_export($array, TRUE)); + Noalyss\Facility::save_file(__DIR__."/file", "tax_summary_getsummary_sale_t.txt", var_export($array, TRUE)); require __DIR__."/data/tax_summary_getsummary_sale_t.php"; $this->check_result("tva_type = T , get_summary_sale",$array,$a_result,'SMRVEN'); diff --git a/unit-test/test-file.sh b/unit-test/test-file.sh index 8b2e879c3..166e8013e 100755 --- a/unit-test/test-file.sh +++ b/unit-test/test-file.sh @@ -37,6 +37,8 @@ if [ ! -z "$FUNCTION" ] ; then $PHPUNIT --bootstrap bootstrap.php --verbose --color --filter $FUNCTION $FILETOTEST else - $PHPUNIT --bootstrap bootstrap.php --color $FILETOTEST + # $PHPUNIT --bootstrap bootstrap.php --whitelist $FILETOTEST --coverage-text=${FILETOTEST%.php}.txt --color $FILETOTEST + $PHPUNIT --bootstrap bootstrap.php --whitelist=../include/class --coverage-html=coverage --color $FILETOTEST + #$PHPUNIT --bootstrap bootstrap.php $FILETOTEST --testdox-html ${FILETOTEST%.php}-testdox.html --color $FILETOTEST fi From 20601e053f11c11f710d280b5f499a20f602f641 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Tue, 12 Nov 2019 21:23:24 +0100 Subject: [PATCH 04/23] Task #0001762: TVA France Erreur dans script SQL --- include/sql/patch/upgrade138.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/sql/patch/upgrade138.sql b/include/sql/patch/upgrade138.sql index f7e341f99..39e5b3118 100644 --- a/include/sql/patch/upgrade138.sql +++ b/include/sql/patch/upgrade138.sql @@ -1,13 +1,13 @@ begin; ALTER TABLE public.tva_rate ADD tva_payment_sale char(1) NULL DEFAULT 'O'; update public.tva_rate set tva_payment_sale='O'; -ALTER TABLE public.tva_rate ADD CONSTRAINT tva_rate_sale_check CHECK (tva_payment in ('O','P')); +ALTER TABLE public.tva_rate ADD CONSTRAINT tva_rate_sale_check CHECK (tva_payment_sale in ('O','P')); comment on column public.tva_rate.tva_payment_sale is 'Check if the VAT on Sale must be declared when at the date of payment (P) or the date of operation (O)'; ALTER TABLE public.tva_rate ADD tva_payment_purchase char(1) NULL DEFAULT 'O'; update public.tva_rate set tva_payment_purchase='O'; -ALTER TABLE public.tva_rate ADD CONSTRAINT tva_rate_purchase_check CHECK (tva_payment in ('O','P')); +ALTER TABLE public.tva_rate ADD CONSTRAINT tva_rate_purchase_check CHECK (tva_payment_purchase in ('O','P')); comment on column public.tva_rate.tva_payment_purchase is 'Check if the VAT on Purchase must be declared when at the date of payment (P) or the date of operation (O)'; From b0a2ee222c6947d306abe55271698ab362391592 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Wed, 13 Nov 2019 20:10:10 +0100 Subject: [PATCH 05/23] rename test files: --- ....class.php => acc_account_ledger.Test.php} | 0 ...nceTest.class.php => acc_balance.Test.php} | 0 ...bilanTest.class.php => acc_bilan.Test.php} | 0 ...uteTest.class.php => acc_compute.Test.php} | 0 ...dgerTest.class.php => acc_ledger.Test.php} | 0 ...Test.class.php => acc_ledger_fin.Test.php} | 0 .../include/class/acc_ledger_historyTest.php | 136 ++++++++++++++++++ ... => acc_ledger_history_financial.Test.php} | 0 ...hp => acc_ledger_history_generic.Test.php} | 0 ...p => acc_ledger_history_purchase.Test.php} | 0 ...s.php => acc_ledger_history_sale.Test.php} | 0 ...est.class.php => acc_ledger_info.Test.php} | 0 ...class.php => acc_ledger_purchase.Test.php} | 0 ...est.class.php => acc_ledger_sold.Test.php} | 0 ...nTest.class.php => acc_operation.Test.php} | 0 ...eTest.class.php => acc_parm_code.Test.php} | 0 ...Test.class.php => anc_grandlivre.Test.php} | 0 ...anc_keyTest.class.php => anc_key.Test.php} | 0 ...sqlTest.class.php => anc_key_sql.Test.php} | 0 ...nTest.class.php => anc_operation.Test.php} | 0 ...dossierTest.class.php => dossier.Test.php} | 0 .../{ficheTest.class.php => fiche.Test.php} | 0 ....php => noalyss_parameter_folder.Test.php} | 0 ...aryTest.class.php => tax_summary.Test.php} | 0 .../{userTest.class.php => user.Test.php} | 6 - unit-test/test-file.sh | 10 +- 26 files changed, 143 insertions(+), 9 deletions(-) rename unit-test/include/class/{acc_account_ledgerTest.class.php => acc_account_ledger.Test.php} (100%) rename unit-test/include/class/{acc_balanceTest.class.php => acc_balance.Test.php} (100%) rename unit-test/include/class/{acc_bilanTest.class.php => acc_bilan.Test.php} (100%) rename unit-test/include/class/{acc_computeTest.class.php => acc_compute.Test.php} (100%) rename unit-test/include/class/{acc_ledgerTest.class.php => acc_ledger.Test.php} (100%) rename unit-test/include/class/{acc_ledger_finTest.class.php => acc_ledger_fin.Test.php} (100%) create mode 100644 unit-test/include/class/acc_ledger_historyTest.php rename unit-test/include/class/{acc_ledger_history_financialTest.class.php => acc_ledger_history_financial.Test.php} (100%) rename unit-test/include/class/{acc_ledger_history_genericTest.class.php => acc_ledger_history_generic.Test.php} (100%) rename unit-test/include/class/{acc_ledger_history_purchaseTest.class.php => acc_ledger_history_purchase.Test.php} (100%) rename unit-test/include/class/{acc_ledger_history_saleTest.class.php => acc_ledger_history_sale.Test.php} (100%) rename unit-test/include/class/{acc_ledger_infoTest.class.php => acc_ledger_info.Test.php} (100%) rename unit-test/include/class/{acc_ledger_purchaseTest.class.php => acc_ledger_purchase.Test.php} (100%) rename unit-test/include/class/{acc_ledger_soldTest.class.php => acc_ledger_sold.Test.php} (100%) rename unit-test/include/class/{acc_operationTest.class.php => acc_operation.Test.php} (100%) rename unit-test/include/class/{acc_parm_codeTest.class.php => acc_parm_code.Test.php} (100%) rename unit-test/include/class/{anc_grandlivreTest.class.php => anc_grandlivre.Test.php} (100%) rename unit-test/include/class/{anc_keyTest.class.php => anc_key.Test.php} (100%) rename unit-test/include/class/{anc_key_sqlTest.class.php => anc_key_sql.Test.php} (100%) rename unit-test/include/class/{anc_operationTest.class.php => anc_operation.Test.php} (100%) rename unit-test/include/class/{dossierTest.class.php => dossier.Test.php} (100%) rename unit-test/include/class/{ficheTest.class.php => fiche.Test.php} (100%) rename unit-test/include/class/{noalyss_parameter_folderTest.class.php => noalyss_parameter_folder.Test.php} (100%) rename unit-test/include/class/{tax_summaryTest.class.php => tax_summary.Test.php} (100%) rename unit-test/include/class/{userTest.class.php => user.Test.php} (98%) diff --git a/unit-test/include/class/acc_account_ledgerTest.class.php b/unit-test/include/class/acc_account_ledger.Test.php similarity index 100% rename from unit-test/include/class/acc_account_ledgerTest.class.php rename to unit-test/include/class/acc_account_ledger.Test.php diff --git a/unit-test/include/class/acc_balanceTest.class.php b/unit-test/include/class/acc_balance.Test.php similarity index 100% rename from unit-test/include/class/acc_balanceTest.class.php rename to unit-test/include/class/acc_balance.Test.php diff --git a/unit-test/include/class/acc_bilanTest.class.php b/unit-test/include/class/acc_bilan.Test.php similarity index 100% rename from unit-test/include/class/acc_bilanTest.class.php rename to unit-test/include/class/acc_bilan.Test.php diff --git a/unit-test/include/class/acc_computeTest.class.php b/unit-test/include/class/acc_compute.Test.php similarity index 100% rename from unit-test/include/class/acc_computeTest.class.php rename to unit-test/include/class/acc_compute.Test.php diff --git a/unit-test/include/class/acc_ledgerTest.class.php b/unit-test/include/class/acc_ledger.Test.php similarity index 100% rename from unit-test/include/class/acc_ledgerTest.class.php rename to unit-test/include/class/acc_ledger.Test.php diff --git a/unit-test/include/class/acc_ledger_finTest.class.php b/unit-test/include/class/acc_ledger_fin.Test.php similarity index 100% rename from unit-test/include/class/acc_ledger_finTest.class.php rename to unit-test/include/class/acc_ledger_fin.Test.php diff --git a/unit-test/include/class/acc_ledger_historyTest.php b/unit-test/include/class/acc_ledger_historyTest.php new file mode 100644 index 000000000..38f8d4e37 --- /dev/null +++ b/unit-test/include/class/acc_ledger_historyTest.php @@ -0,0 +1,136 @@ + + +/** + * @file + * @brief concerne acc_ledger_historyTest.class + * @coversDefaultClass Acc_Ledger_History + */ +class Acc_Ledger_HistoryTest extends TestCase +{ + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + include 'global.php'; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + } + /** + * @covers Acc_Ledger_History::factory + * @covers ::get_ledger_type + * @covers ::set_filter_operation + */ + function testFactory() + { + global $g_connection; + $p_min_id=$g_connection->get_value("select p_id from parm_periode order by p_start limit 1"); + $p_max_id=$g_connection->get_value("select p_id from parm_periode order by p_start desc limit 1"); + + $object=Acc_Ledger_History::factory($g_connection, [1],$p_min_id ,$p_max_id , "D", 'all'); + $this->assertEquals('FIN',$object->get_ledger_type()); + + $object=Acc_Ledger_History::factory($g_connection, [4],$p_min_id ,$p_max_id , "D", 'all'); + $this->assertEquals('ODS',$object->get_ledger_type()); + + $object=Acc_Ledger_History::factory($g_connection, [2],$p_min_id ,$p_max_id , "D", 'all'); + $this->assertEquals('VEN',$object->get_ledger_type()); + + $object=Acc_Ledger_History::factory($g_connection, [3],$p_min_id ,$p_max_id , "D", 'all'); + $this->assertEquals('ACH',$object->get_ledger_type()); + + } + /** + * @covers ::get_tiers + * @covers ::get_tiers_id + */ + function testGet_tiers() + { + global $g_connection; + $p_min_id=$g_connection->get_value("select p_id from parm_periode order by p_start limit 1"); + $p_max_id=$g_connection->get_value("select p_id from parm_periode order by p_start desc limit 1"); + + $object=Acc_Ledger_History::factory($g_connection, [1],$p_min_id ,$p_max_id , "E", 'paid'); + $this->assertEquals(" ",$object->get_tiers('ODS',213)); + + $this->assertEquals("Client 2",trim($object->get_tiers('VEN',213))); + + + } + /** + * @covers ::get_filter_operation + */ + function testget_Filter_Operation() + { + global $g_connection; + $p_min_id=$g_connection->get_value("select p_id from parm_periode order by p_start limit 1"); + $p_max_id=$g_connection->get_value("select p_id from parm_periode order by p_start desc limit 1"); + + $object=Acc_Ledger_History::factory($g_connection, [2],$p_min_id ,$p_max_id , "D", 'all'); + $this->assertEquals("all",$object->get_filter_operation()) ; + + $object=Acc_Ledger_History::factory($g_connection, [3],$p_min_id ,$p_max_id , "D", 'all'); + $this->assertEquals("all",$object->get_filter_operation()) ; + + $object=Acc_Ledger_History::factory($g_connection, [1],$p_min_id ,$p_max_id , "D", 'all'); + $this->assertEquals("all",$object->get_filter_operation()) ; + } + /** + * @covers ::build_filter_operation + * @covers ::set_filter_operation + * + */ + function testBuild_filter_operation() + { + global $g_connection; + $p_min_id=$g_connection->get_value("select p_id from parm_periode order by p_start limit 1"); + $p_max_id=$g_connection->get_value("select p_id from parm_periode order by p_start desc limit 1"); + $object=Acc_Ledger_History::factory($g_connection, [2],$p_min_id ,$p_max_id , "D", 'all'); + $object->get_row(); + $a_row=$object->get_data(); + $this->assertEquals(7,count($a_row)); + + $object->set_filter_operation("paid"); + $object->get_row(); + $a_row=$object->get_data(); + $this->assertEquals(3,count($a_row)); + + $object->set_filter_operation("unpaid"); + $object->get_row(); + $a_row=$object->get_data(); + $this->assertEquals(4,count($a_row)); + + + } + +} \ No newline at end of file diff --git a/unit-test/include/class/acc_ledger_history_financialTest.class.php b/unit-test/include/class/acc_ledger_history_financial.Test.php similarity index 100% rename from unit-test/include/class/acc_ledger_history_financialTest.class.php rename to unit-test/include/class/acc_ledger_history_financial.Test.php diff --git a/unit-test/include/class/acc_ledger_history_genericTest.class.php b/unit-test/include/class/acc_ledger_history_generic.Test.php similarity index 100% rename from unit-test/include/class/acc_ledger_history_genericTest.class.php rename to unit-test/include/class/acc_ledger_history_generic.Test.php diff --git a/unit-test/include/class/acc_ledger_history_purchaseTest.class.php b/unit-test/include/class/acc_ledger_history_purchase.Test.php similarity index 100% rename from unit-test/include/class/acc_ledger_history_purchaseTest.class.php rename to unit-test/include/class/acc_ledger_history_purchase.Test.php diff --git a/unit-test/include/class/acc_ledger_history_saleTest.class.php b/unit-test/include/class/acc_ledger_history_sale.Test.php similarity index 100% rename from unit-test/include/class/acc_ledger_history_saleTest.class.php rename to unit-test/include/class/acc_ledger_history_sale.Test.php diff --git a/unit-test/include/class/acc_ledger_infoTest.class.php b/unit-test/include/class/acc_ledger_info.Test.php similarity index 100% rename from unit-test/include/class/acc_ledger_infoTest.class.php rename to unit-test/include/class/acc_ledger_info.Test.php diff --git a/unit-test/include/class/acc_ledger_purchaseTest.class.php b/unit-test/include/class/acc_ledger_purchase.Test.php similarity index 100% rename from unit-test/include/class/acc_ledger_purchaseTest.class.php rename to unit-test/include/class/acc_ledger_purchase.Test.php diff --git a/unit-test/include/class/acc_ledger_soldTest.class.php b/unit-test/include/class/acc_ledger_sold.Test.php similarity index 100% rename from unit-test/include/class/acc_ledger_soldTest.class.php rename to unit-test/include/class/acc_ledger_sold.Test.php diff --git a/unit-test/include/class/acc_operationTest.class.php b/unit-test/include/class/acc_operation.Test.php similarity index 100% rename from unit-test/include/class/acc_operationTest.class.php rename to unit-test/include/class/acc_operation.Test.php diff --git a/unit-test/include/class/acc_parm_codeTest.class.php b/unit-test/include/class/acc_parm_code.Test.php similarity index 100% rename from unit-test/include/class/acc_parm_codeTest.class.php rename to unit-test/include/class/acc_parm_code.Test.php diff --git a/unit-test/include/class/anc_grandlivreTest.class.php b/unit-test/include/class/anc_grandlivre.Test.php similarity index 100% rename from unit-test/include/class/anc_grandlivreTest.class.php rename to unit-test/include/class/anc_grandlivre.Test.php diff --git a/unit-test/include/class/anc_keyTest.class.php b/unit-test/include/class/anc_key.Test.php similarity index 100% rename from unit-test/include/class/anc_keyTest.class.php rename to unit-test/include/class/anc_key.Test.php diff --git a/unit-test/include/class/anc_key_sqlTest.class.php b/unit-test/include/class/anc_key_sql.Test.php similarity index 100% rename from unit-test/include/class/anc_key_sqlTest.class.php rename to unit-test/include/class/anc_key_sql.Test.php diff --git a/unit-test/include/class/anc_operationTest.class.php b/unit-test/include/class/anc_operation.Test.php similarity index 100% rename from unit-test/include/class/anc_operationTest.class.php rename to unit-test/include/class/anc_operation.Test.php diff --git a/unit-test/include/class/dossierTest.class.php b/unit-test/include/class/dossier.Test.php similarity index 100% rename from unit-test/include/class/dossierTest.class.php rename to unit-test/include/class/dossier.Test.php diff --git a/unit-test/include/class/ficheTest.class.php b/unit-test/include/class/fiche.Test.php similarity index 100% rename from unit-test/include/class/ficheTest.class.php rename to unit-test/include/class/fiche.Test.php diff --git a/unit-test/include/class/noalyss_parameter_folderTest.class.php b/unit-test/include/class/noalyss_parameter_folder.Test.php similarity index 100% rename from unit-test/include/class/noalyss_parameter_folderTest.class.php rename to unit-test/include/class/noalyss_parameter_folder.Test.php diff --git a/unit-test/include/class/tax_summaryTest.class.php b/unit-test/include/class/tax_summary.Test.php similarity index 100% rename from unit-test/include/class/tax_summaryTest.class.php rename to unit-test/include/class/tax_summary.Test.php diff --git a/unit-test/include/class/userTest.class.php b/unit-test/include/class/user.Test.php similarity index 98% rename from unit-test/include/class/userTest.class.php rename to unit-test/include/class/user.Test.php index cbef9d61a..727994c0a 100644 --- a/unit-test/include/class/userTest.class.php +++ b/unit-test/include/class/user.Test.php @@ -56,7 +56,6 @@ class UserTest extends TestCase /** * @covers User::load - * @todo Implement testLoad(). */ public function testLoad() { @@ -74,14 +73,9 @@ class UserTest extends TestCase /** * @covers User::save - * @todo Implement testSave(). */ public function testSave() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); } /** diff --git a/unit-test/test-file.sh b/unit-test/test-file.sh index 166e8013e..2381d4089 100755 --- a/unit-test/test-file.sh +++ b/unit-test/test-file.sh @@ -4,7 +4,11 @@ help(){ echo " -f filename , file to test" echo " -i function , optional filter to a function" } -PHPUNIT=./phpunit + +cd `dirname $0` + +CUR_DIR=`pwd` +PHPUNIT=$CUR_DIR/phpunit FILETOTEST="" FUNCTION="" while getopts "f:i:" opt; do @@ -34,11 +38,11 @@ fi if [ ! -z "$FUNCTION" ] ; then echo "testing $FILETOTEST $FUNCTION" - $PHPUNIT --bootstrap bootstrap.php --verbose --color --filter $FUNCTION $FILETOTEST + $PHPUNIT --bootstrap $CUR_DIR/bootstrap.php --verbose --color --filter $FUNCTION $FILETOTEST else # $PHPUNIT --bootstrap bootstrap.php --whitelist $FILETOTEST --coverage-text=${FILETOTEST%.php}.txt --color $FILETOTEST - $PHPUNIT --bootstrap bootstrap.php --whitelist=../include/class --coverage-html=coverage --color $FILETOTEST + $PHPUNIT --bootstrap $CUR_DIR/bootstrap.php --whitelist=$CUR_DIR/../include/class --coverage-html=coverage --color $FILETOTEST #$PHPUNIT --bootstrap bootstrap.php $FILETOTEST --testdox-html ${FILETOTEST%.php}-testdox.html --color $FILETOTEST fi From e8f235b935321523e52ba66e3c0b17e59a661902 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 17 Nov 2019 11:16:28 +0100 Subject: [PATCH 06/23] PDFTK Convert in PDF if working from home, see http://wiki.noalyss.eu/doku.php?id=menu:ancgl --- include/class/document_export.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/class/document_export.class.php b/include/class/document_export.class.php index f491ab11a..66d5382d0 100644 --- a/include/class/document_export.class.php +++ b/include/class/document_export.class.php @@ -38,8 +38,8 @@ class Document_Export // Create 2 temporary folders 1. convert to PDF + stamp // 2. store result $this->feedback = array(); - $this->store_convert = tempnam(sys_get_temp_dir(), 'convert_'); - $this->store_pdf = tempnam(sys_get_temp_dir(), 'pdf_'); + $this->store_convert = tempnam($_ENV['TMP'], 'convert_'); + $this->store_pdf = tempnam($_ENV['TMP'], 'pdf_'); unlink($this->store_convert); unlink($this->store_pdf); umask(0); @@ -277,7 +277,7 @@ class Document_Export $progress->set_value(100); // remove files from "conversion folder" - $this->clean_folder(); + // $this->clean_folder(); } /** From 362d3d31f16d3b69f5c1185d2fe3635fb6063ba2 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 17 Nov 2019 13:16:09 +0100 Subject: [PATCH 07/23] Acc_Ledger::id == 0 for Main Ledger --- include/class/acc_ledger.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index 6c0351cd3..dabc16a3f 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -79,7 +79,7 @@ class Acc_Ledger extends jrn_def_sql $this->db=$p_cn; $this->row=null; $this->nb=MAX_ARTICLE; - parent::__construct($p_cn, $p_id); + if ($p_id <> 0 ) parent::__construct($p_cn, $p_id); } function get_last_pj() From 1854dbd9b18b10006a5ef74a81448150e314022f Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 17 Nov 2019 14:14:31 +0100 Subject: [PATCH 08/23] Task #1762 Exigibility VAT : Print ledger for paid , unpaid or all operations PHPUNIT Test Files --- include/class/pdf.class.php | 23 +- include/class/print_ledger.class.php | 347 +++++++++++------- include/class/print_ledger_detail.class.php | 15 +- .../class/print_ledger_detail_item.class.php | 29 +- include/class/print_ledger_fin.class.php | 20 +- include/class/print_ledger_misc.class.php | 17 +- include/class/print_ledger_simple.class.php | 41 +-- .../print_ledger_simple_without_vat.class.php | 40 +- include/export/export_ledger_csv.php | 12 +- include/export/export_ledger_pdf.php | 7 +- unit-test/include/class/print_LedgerTest.php | 147 ++++++++ .../class/print_ledger_detail.classTest.php | 81 ++++ .../print_ledger_detail_item.classTest.php | 162 ++++++++ .../class/print_ledger_fin.classTest.php | 111 ++++++ .../class/print_ledger_misc.classTest.php | 89 +++++ .../class/print_ledger_simple.classTest.php | 166 +++++++++ ...nt_ledger_simple_without_vat.classTest.php | 161 ++++++++ 17 files changed, 1221 insertions(+), 247 deletions(-) create mode 100644 unit-test/include/class/print_LedgerTest.php create mode 100644 unit-test/include/class/print_ledger_detail.classTest.php create mode 100644 unit-test/include/class/print_ledger_detail_item.classTest.php create mode 100644 unit-test/include/class/print_ledger_fin.classTest.php create mode 100644 unit-test/include/class/print_ledger_misc.classTest.php create mode 100644 unit-test/include/class/print_ledger_simple.classTest.php create mode 100644 unit-test/include/class/print_ledger_simple_without_vat.classTest.php diff --git a/include/class/pdf.class.php b/include/class/pdf.class.php index 650dafdc4..6f059e95f 100644 --- a/include/class/pdf.class.php +++ b/include/class/pdf.class.php @@ -150,26 +150,5 @@ class PDF extends PDF_Core } throw new Exception(_("Filter invalide ".$filter_operation), 5); } - /** - * Build a SQL clause to filter operation depending if they are paid, unpaid or no filter - * @return string SQL Clause - */ - protected function build_filter_operation() - { - switch ($this->get_filter_operation()) - { - case 'all': - $sql_filter=""; - break; - case 'paid': - $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) "; - break; - case 'unpaid': - $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) "; - break; - default: - throw new Exception(_("Filtre invalide", 5)); - } - return $sql_filter; - } + } \ No newline at end of file diff --git a/include/class/print_ledger.class.php b/include/class/print_ledger.class.php index 83f43c18b..8b8213ff6 100644 --- a/include/class/print_ledger.class.php +++ b/include/class/print_ledger.class.php @@ -24,20 +24,75 @@ * @author danydb */ require_once NOALYSS_INCLUDE.'/class/database.class.php'; -require_once NOALYSS_INCLUDE.'/class/print_ledger_detail.class.php'; -require_once NOALYSS_INCLUDE.'/class/print_ledger_simple.class.php'; -require_once NOALYSS_INCLUDE.'/class/print_ledger_simple_without_vat.class.php'; -require_once NOALYSS_INCLUDE.'/class/print_ledger_fin.class.php'; -require_once NOALYSS_INCLUDE.'/class/print_ledger_misc.class.php'; -require_once NOALYSS_INCLUDE.'/class/print_ledger_detail_item.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; /** * @brief Strategie class for the print_ledger class * - */ -class Print_Ledger { +*/ +class Print_Ledger extends PDF +{ protected $filter_operation; // See Acc_Ledger_History::filter_operation - + private $ledger ; //!< concerned Ledger + private $from ; //! integer parm_periode.p_id , start periode; + private $to ; //! integer parm_periode.p_id , end periode; + public function __construct(\Database $p_cn, + $orientation, + $unit, + $format, + Acc_Ledger $p_ledger, + $p_from, + $p_to, + $p_filter_operation) + { + parent::__construct($p_cn, $orientation, $unit, $format); + $this->ledger=$p_ledger; + $this->from=$p_from; + $this->to=$p_to; + $this->set_filter_operation($p_filter_operation); + } + public function get_ledger() + { + return $this->ledger; + } + + public function get_from() + { + return $this->from; + } + + public function get_to() + { + return $this->to; + } + + public function set_ledger($ledger) + { + $this->ledger=$ledger; + return $this; + } + + public function set_from($from) + { + $this->from=$from; + return $this; + } + + public function set_to($to) + { + $this->to=$to; + return $this; + } + function get_filter_operation() + { + return $this->filter_operation; + } + /** + * Filter the operations , + * @param string $filter_operation : all , paid, unpaid + * @return $this + * @throws Exception 5 , if filter invalid + */ public function set_filter_operation($filter_operation) { if (in_array($filter_operation,['all','paid','unpaid'])) @@ -50,122 +105,39 @@ class Print_Ledger { /** * Create an object Print_Ledger* depending on $p_type_export ( 0 => accounting * 1-> one row per operation 2-> detail of item) - * @param type $cn - * @param type $p_type_export - * @param type $p_format_output CSV or PDF + * @param Database $cn + * @param char $p_type_export E(xtended) L(isting) A(ccounting) D(etail) * @param Acc_Ledger $ledger */ - static function factory(Database $cn, $p_type_export, $p_format_output, Acc_Ledger $p_ledger,$p_filter_operation) + static function factory(Database $cn, $p_type_export, Acc_Ledger $p_ledger,$p_from,$p_to,$p_filter_operation) { + /** + * @Bug + * Strange PHP Bug when autoloader is not used , the require_once doesn't seems to + * work properly and does not include the files , except if you put them here + * + * if you put them on the top of this file, export_ledger_pdf.php will include the files + * but not export_ledger_csv.php + */ + require_once NOALYSS_INCLUDE.'/class/print_ledger_detail.class.php'; + require_once NOALYSS_INCLUDE.'/class/print_ledger_simple.class.php'; + require_once NOALYSS_INCLUDE.'/class/print_ledger_simple_without_vat.class.php'; + require_once NOALYSS_INCLUDE.'/class/print_ledger_fin.class.php'; + require_once NOALYSS_INCLUDE.'/class/print_ledger_misc.class.php'; + require_once NOALYSS_INCLUDE.'/class/print_ledger_detail_item.class.php'; + /** * For PDF output */ - if ($p_format_output == 'PDF') { - switch ($p_type_export) { - case 'D': - $own=new Noalyss_Parameter_Folder($cn); - $jrn_type=$p_ledger->get_type(); - //--------------------------------------------- - // Detailled Printing (accounting ) - //--------------------------------------------- - if ($jrn_type=='ACH'||$jrn_type=='VEN') - { - if ( - ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase') - ==0)|| - ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold') - ==0) - ) - { - $pdf=new Print_Ledger_Simple_without_vat($cn, - $p_ledger,$p_filter_operation); - $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple')); - return $pdf; - } - if ($own->MY_TVA_USE=='Y') - { - $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_filter_operation); - return $pdf; - } - if ($own->MY_TVA_USE=='N') - { - $pdf=new Print_Ledger_Simple_without_vat($cn, - $p_ledger,$p_filter_operation); - return $pdf; - } - } - elseif ($jrn_type=='FIN') - { - $pdf=new Print_Ledger_Financial($cn, $p_ledger); - return $pdf; - } else - { - return new Print_Ledger_Detail($cn, $p_ledger); - } - break; - - case 'L': - //---------------------------------------------------------------------- - // Simple Printing Purchase Ledger - //--------------------------------------------------------------------- - $own=new Noalyss_Parameter_Folder($cn); - $jrn_type=$p_ledger->get_type(); - - - if ($jrn_type=='ACH'||$jrn_type=='VEN') - { - if ( - ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase') - ==0)|| - ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold') - ==0) - ) - { - $pdf=new Print_Ledger_Simple_without_vat($cn, - $p_ledger,$p_filter_operation); - $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple')); - return $pdf; - } - if ($own->MY_TVA_USE=='Y') - { - $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_filter_operation); - return $pdf; - } - if ($own->MY_TVA_USE=='N') - { - $pdf=new Print_Ledger_Simple_without_vat($cn, - $p_ledger,$p_filter_operation); - return $pdf; - } - } - - if ($jrn_type=='FIN') - { - $pdf=new Print_Ledger_Financial($cn, $p_ledger); - return $pdf; - } - if ($jrn_type=='ODS'||$p_ledger->id==0) - { - $pdf=new Print_Ledger_Misc($cn, $p_ledger); - return $pdf; - } - break; - case 'E': - /********************************************************** - * Print Detail Operation + Item - * ********************************************************* */ - $own=new Noalyss_Parameter_Folder($cn); - $jrn_type=$p_ledger->get_type(); - if ($jrn_type=='FIN') - { - $pdf=new Print_Ledger_Detail($cn, $p_ledger); - return $pdf; - } - if ($jrn_type=='ODS'||$p_ledger->id==0) - { - $pdf=new Print_Ledger_Detail($cn, $p_ledger); - return $pdf; - } + switch ($p_type_export) { + case 'D': + $own=new Noalyss_Parameter_Folder($cn); + $jrn_type=$p_ledger->get_type(); + //--------------------------------------------- + // Detailled Printing (accounting ) + //--------------------------------------------- + if ($jrn_type=='ACH'||$jrn_type=='VEN') + { if ( ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase') ==0)|| @@ -173,21 +145,113 @@ class Print_Ledger { ==0) ) { - $pdf=new Print_Ledger_Simple_without_vat($cn, $p_ledger,$p_filter_operation); - $pdf->set_error('Ce journal ne peut être imprimé en mode simple'); + $pdf=new Print_Ledger_Simple_without_vat($cn, + $p_ledger,$p_from,$p_to,$p_filter_operation); + $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple')); return $pdf; } - $pdf=new Print_Ledger_Detail_Item($cn, $p_ledger,$p_filter_operation); + if ($own->MY_TVA_USE=='Y') + { + $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_from,$p_to,$p_filter_operation); + return $pdf; + } + if ($own->MY_TVA_USE=='N') + { + $pdf=new Print_Ledger_Simple_without_vat($cn, + $p_ledger,$p_from,$p_to,$p_filter_operation); + return $pdf; + } + } + elseif ($jrn_type=='FIN') + { + $pdf=new Print_Ledger_Financial($cn, $p_ledger,$p_from,$p_to); return $pdf; - case 'A': - /*********************************************************** - * Accounting - */ - $pdf=new Print_Ledger_Detail($cn, $p_ledger); + } else + { + return new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to); + } + break; + + case 'L': + //---------------------------------------------------------------------- + // Simple Printing Purchase Ledger + //--------------------------------------------------------------------- + $own=new Noalyss_Parameter_Folder($cn); + $jrn_type=$p_ledger->get_type(); + + + if ($jrn_type=='ACH'||$jrn_type=='VEN') + { + if ( + ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase') + ==0)|| + ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold') + ==0) + ) + { + $pdf=new Print_Ledger_Simple_without_vat($cn, + $p_ledger,$p_from,$p_to,$p_filter_operation); + $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple')); + return $pdf; + } + if ($own->MY_TVA_USE=='Y') + { + $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_from,$p_to,$p_filter_operation); + return $pdf; + } + if ($own->MY_TVA_USE=='N') + { + $pdf=new Print_Ledger_Simple_without_vat($cn, + $p_ledger,$p_from,$p_to,$p_filter_operation); + return $pdf; + } + } + + if ($jrn_type=='FIN') + { + $pdf=new Print_Ledger_Financial($cn, $p_ledger,$p_from,$p_to); return $pdf; - break; - } // end switch - } // end $p_format == PDF + } + $pdf=new Print_Ledger_Misc($cn, $p_ledger,$p_from,$p_to); + return $pdf; + break; + case 'E': + /********************************************************** + * Print Detail Operation + Item + * ********************************************************* */ + $own=new Noalyss_Parameter_Folder($cn); + $jrn_type=$p_ledger->get_type(); + if ($jrn_type=='FIN') + { + $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to); + return $pdf; + } + if ($jrn_type=='ODS'||$p_ledger->id==0) + { + $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to); + return $pdf; + } + if ( + ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase') + ==0)|| + ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold') + ==0) + ) + { + $pdf=new Print_Ledger_Simple_without_vat($cn, $p_ledger,$p_from,$p_to,$p_filter_operation); + $pdf->set_error('Ce journal ne peut être imprimé en mode simple'); + return $pdf; + } + $pdf=new Print_Ledger_Detail_Item($cn, $p_ledger,$p_from,$p_to,$p_filter_operation); + return $pdf; + case 'A': + /*********************************************************** + * Accounting + */ + $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to); + return $pdf; + break; + } // end switch } // end function @@ -246,7 +310,28 @@ class Print_Ledger { } return $a; } - + /** + * Build a SQL clause to filter operation depending if they are paid, unpaid or no filter + * @return string SQL Clause + */ + protected function build_filter_operation() + { + switch ($this->get_filter_operation()) + { + case 'all': + $sql_filter=""; + break; + case 'paid': + $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) "; + break; + case 'unpaid': + $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) "; + break; + default: + throw new Exception(_("Filtre invalide", 5)); + } + return $sql_filter; + } } ?> diff --git a/include/class/print_ledger_detail.class.php b/include/class/print_ledger_detail.class.php index 2c59ecfb8..baa7e8fae 100644 --- a/include/class/print_ledger_detail.class.php +++ b/include/class/print_ledger_detail.class.php @@ -23,19 +23,16 @@ * \brief this class extends PDF and let you export the detailled printing * of any ledgers */ -require_once NOALYSS_INCLUDE.'/class/pdf_land.class.php'; +require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php'; -class Print_Ledger_Detail extends PDF + +class Print_Ledger_Detail extends Print_Ledger { - public function __construct ($p_cn = null, Acc_Ledger $ledger) + public function __construct (Database $p_cn , Acc_Ledger $ledger,$p_from,$p_to) { - if($p_cn == null) die("No database connection. Abort."); + parent::__construct($p_cn,'L', 'mm', 'A4',$ledger,$p_from,$p_to,'all'); - parent::__construct($p_cn,'L', 'mm', 'A4'); - $this->ledger=$ledger; - date_default_timezone_set ('Europe/Paris'); - } function setDossierInfo($dossier = "n/a") @@ -73,7 +70,7 @@ class Print_Ledger_Detail extends PDF $rap_deb=0; $rap_cred=0; // take all operations from jrn - $array=$this->ledger->get_operation($_GET['from_periode'],$_GET['to_periode']); + $array=$this->get_ledger()->get_operation($this->get_from(),$this->get_to()); $this->SetFont('DejaVu','BI',7); $this->write_cell(215,7,'report Débit',0,0,'R'); diff --git a/include/class/print_ledger_detail_item.class.php b/include/class/print_ledger_detail_item.class.php index 682c24551..c9fca66a3 100644 --- a/include/class/print_ledger_detail_item.class.php +++ b/include/class/print_ledger_detail_item.class.php @@ -25,19 +25,15 @@ */ require_once NOALYSS_INCLUDE.'/class/acc_ledger_sold.class.php'; require_once NOALYSS_INCLUDE.'/class/acc_ledger_purchase.class.php'; -require_once NOALYSS_INCLUDE.'/class/pdf_land.class.php'; +require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php'; -class Print_Ledger_Detail_Item extends PDFLand +class Print_Ledger_Detail_Item extends Print_Ledger { - public function __construct (Database $p_cn,Acc_Ledger $p_jrn,$p_filter_operation) + public function __construct (Database $p_cn,Acc_Ledger $p_jrn,$p_from,$p_to,$p_filter_operation) { - if($p_cn == null) die("No database connection. Abort."); - - parent::__construct($p_cn,'L', 'mm', 'A4'); - $this->ledger=$p_jrn; + parent::__construct($p_cn,'L', 'mm', 'A4',$p_jrn,$p_from,$p_to,$p_filter_operation); $this->show_col=true; - $this->filter_operation=$p_filter_operation; } function setDossierInfo($dossier = "n/a") @@ -77,7 +73,7 @@ class Print_Ledger_Detail_Item extends PDFLand { $this->Ln(2); $this->SetFont('Arial', 'I', 8); - $this->Cell(50,8,' Journal '.$this->ledger->get_name(),0,0,'C'); + $this->Cell(50,8,' Journal '.$this->get_ledger()->get_name(),0,0,'C'); //Arial italic 8 //Page number $this->Cell(30,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'L'); @@ -92,18 +88,17 @@ class Print_Ledger_Detail_Item extends PDFLand function export() { bcscale(2); - $jrn_type=$this->ledger->get_type(); - $http=new HttpInput(); + $jrn_type=$this->get_ledger()->get_type(); switch ($jrn_type) { case 'VEN': - $ledger=new Acc_Ledger_Sold($this->cn, $this->ledger->jrn_def_id); - $ret_detail=$ledger->get_detail_sale($http->get('from_periode','number'),$http->get('to_periode','number'), $this->filter_operation); + $ledger=new Acc_Ledger_Sold($this->cn, $this->get_ledger()->jrn_def_id); + $ret_detail=$ledger->get_detail_sale($this->get_from(),$this->get_to(), $this->filter_operation); break; case 'ACH': - $ledger=new Acc_Ledger_Purchase($this->cn, $this->ledger->jrn_def_id); - $ret_detail=$ledger->get_detail_purchase($http->get('from_periode','number'),$http->get('to_periode','number'),$this->filter_operation); + $ledger=new Acc_Ledger_Purchase($this->cn, $this->get_ledger()->jrn_def_id); + $ret_detail=$ledger->get_detail_purchase($this->get_from(),$this->get_to(),$this->filter_operation); break; default: die (__FILE__.":".__LINE__.'Journal invalide'); @@ -111,7 +106,7 @@ class Print_Ledger_Detail_Item extends PDFLand } if ( $ret_detail == null ) return; - $prepared_query=new Prepared_Query($this->ledger->db); + $prepared_query=new Prepared_Query($this->cn); $prepared_query->prepare_reconcile_date(); $nb=Database::num_row($ret_detail); @@ -141,7 +136,7 @@ class Print_Ledger_Detail_Item extends PDFLand $this->line_new(6); // Payment info // Prepare the query for reconcile date - $ret_reconcile=$this->ledger->db->execute('reconcile_date', array($row['jr_id'])); + $ret_reconcile=$this->cn->execute('reconcile_date', array($row['jr_id'])); $max=Database::num_row($ret_reconcile); for ($e=0; $e<$max; $e++) { diff --git a/include/class/print_ledger_fin.class.php b/include/class/print_ledger_fin.class.php index 3fa367fef..da9eadff1 100644 --- a/include/class/print_ledger_fin.class.php +++ b/include/class/print_ledger_fin.class.php @@ -22,16 +22,16 @@ /*!\file * \brief print a listing of financial */ -require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; -class Print_Ledger_Financial extends PDF +require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php'; + +class Print_Ledger_Financial extends Print_Ledger { private $rap_amount; /* amount from begining exercice */ private $tp_amount; /* amount total page */ - function __construct($p_cn, Acc_Ledger $p_jrn) + function __construct(Database $p_cn, Acc_Ledger $p_jrn,$p_from,$p_to) { - parent::__construct($p_cn,'P','mm','A4'); - $this->ledger=$p_jrn; + parent::__construct($p_cn,'P','mm','A4',$p_jrn,$p_from,$p_to,'all'); $this->jrn_type=$p_jrn->get_type(); // report from begin exercice @@ -40,7 +40,7 @@ class Print_Ledger_Financial extends PDF // total page $this->tp_amount=0; - $amount=$this->ledger->previous_amount($_GET['from_periode']); + $amount=$this->get_ledger()->previous_amount($this->get_from()); $this->rap_amount=$amount['amount']; } function Header() @@ -92,11 +92,13 @@ class Print_Ledger_Financial extends PDF */ function export() { - $a_jrn=$this->ledger->get_operation($_GET['from_periode'], - $_GET['to_periode']); + $ledger=$this->get_ledger(); + $a_jrn=$ledger->get_operation($this->get_from(),$this->get_to()); + $this->SetFont('DejaVu', '', 6); if ( $a_jrn == null ) return; bcscale(2); + for ( $i=0;$iwrite_cell(10,5,$row['date_fmt']); $this->write_cell(15,5,$row['internal']); - $name=$this->ledger->get_tiers($this->jrn_type,$row['id']); + $name=$ledger->get_tiers($this->jrn_type,$row['id']); $this->write_cell(40,5,$name,0,'L'); diff --git a/include/class/print_ledger_misc.class.php b/include/class/print_ledger_misc.class.php index 037f5378f..726e3752c 100644 --- a/include/class/print_ledger_misc.class.php +++ b/include/class/print_ledger_misc.class.php @@ -22,14 +22,13 @@ /*!\file * \brief print a listing of financial */ -require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; -class Print_Ledger_Misc extends PDF +require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php'; + +class Print_Ledger_Misc extends Print_Ledger { - function __construct($p_cn,$p_jrn) + function __construct(Database $p_cn,$p_jrn,$p_from,$p_to) { - parent::__construct($p_cn,'P','mm','A4'); - $this->ledger=$p_jrn; - $this->jrn_type=$p_jrn->get_type(); + parent::__construct($p_cn,'P','mm','A4',$p_jrn,$p_from,$p_to,"all"); } function Header() { @@ -70,10 +69,10 @@ class Print_Ledger_Misc extends PDF */ function export() { - $a_jrn=$this->ledger->get_rowSimple($_GET['from_periode'], - $_GET['to_periode']); + $a_jrn=$this->get_ledger()->get_rowSimple($this->get_from(),$this->get_to()); $this->SetFont('DejaVu', '', 6); if ( $a_jrn == null ) return; + $ledger=$this->get_ledger(); for ( $i=0;$iLongLine(30,5,$row['jr_pj_number']); $this->write_cell(20,5,$row['jr_internal']); $type=$this->cn->get_value("select jrn_def_type from jrn_def where jrn_def_id=$1",array($a_jrn[$i]['jr_def_id'])); - $other=mb_substr($this->ledger->get_tiers($type,$a_jrn[$i]['jr_id']),0,25); + $other=mb_substr($ledger->get_tiers($type,$a_jrn[$i]['jr_id']),0,25); $this->LongLine(25,5,$other,0,'L'); $positive=$row['montant']; $this->LongLine(80,5,$row['comment'],0,'L'); diff --git a/include/class/print_ledger_simple.class.php b/include/class/print_ledger_simple.class.php index 26aa342ef..399a8a5ad 100644 --- a/include/class/print_ledger_simple.class.php +++ b/include/class/print_ledger_simple.class.php @@ -23,21 +23,17 @@ * \brief this class extends PDF and let you export the detailled printing * of any ledgers */ -require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php'; require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; -class Print_Ledger_Simple extends PDF +class Print_Ledger_Simple extends \Print_Ledger { - public function __construct ($p_cn, Acc_Ledger $p_jrn,$p_filter_operation) + public function __construct ($p_cn, Acc_Ledger $p_jrn,$p_from,$p_to,$p_filter_operation) { - $http=new HttpInput(); - $this->filter_operation=$p_filter_operation; - if($p_cn == null) die("No database connection. Abort."); - - parent::__construct($p_cn,'L', 'mm', 'A4'); - $this->ledger=$p_jrn; - $this->a_Tva=$this->ledger->existing_vat(); + parent::__construct($p_cn,'L', 'mm', 'A4',$p_jrn,$p_from,$p_to,$p_filter_operation); + + $this->a_Tva=$this->get_ledger()->existing_vat(); foreach($this->a_Tva as $line_tva) { //initialize Amount TVA @@ -51,8 +47,8 @@ class Print_Ledger_Simple extends PDF * get rappel to initialize amount rap_xx *the easiest way is to compute sum from quant_ */ - $from_periode=$http->get('from_periode',"number"); - $this->previous=$this->ledger->previous_amount($from_periode); + $from_periode=$this->get_from(); + $this->previous=$this->get_ledger()->previous_amount($from_periode); /* initialize the amount to report */ foreach($this->previous['tva'] as $line_tva) @@ -219,15 +215,14 @@ class Print_Ledger_Simple extends PDF */ function export() { - bcscale(2); - $http=new HttpInput(); - + bcscale(2); + $ledger=$this->get_ledger(); $ledger_history=Acc_Ledger_History::factory($this->cn, - array($this->ledger->id), - $http->get('from_periode','number'), - $http->get('to_periode','number'), + array($ledger->id), + $this->get_from(), + $this->get_to(), 'D', - $this->filter_operation); + $this->get_filter_operation()); $ledger_history->get_row(); $a_jrn=$ledger_history->get_data(); @@ -237,7 +232,7 @@ class Print_Ledger_Simple extends PDF $flag_tva=(count($this->a_Tva) > 4)?true:false; // Prepare the query for reconcile date - $prepared_query=new Prepared_Query($this->ledger->db); + $prepared_query=new Prepared_Query($ledger->db); $prepared_query->prepare_reconcile_date(); for ( $i=0;$iledger->vat_operation($a_jrn[$i]['jr_grpt_id']); + $aAmountVat=$ledger->vat_operation($a_jrn[$i]['jr_grpt_id']); // put vat into array for ($f=0;$fledger->db->execute('reconcile_date',array($row['jr_id'])); + $ret_reconcile=$ledger->db->execute('reconcile_date',array($row['jr_id'])); $this->LongLine(15,5,($row['jr_pj_number']),0); $this->write_cell(10,5,$row['str_date_short'],0,0); $this->write_cell(13,5,$row['jr_internal'],0,0); @@ -274,7 +269,7 @@ class Print_Ledger_Simple extends PDF } /* get other amount (without vat, total vat included, private, ND */ - $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']); + $other=$ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']); $this->write_cell(15,5,nbm($other['price']),0,0,'R'); diff --git a/include/class/print_ledger_simple_without_vat.class.php b/include/class/print_ledger_simple_without_vat.class.php index 751961cc7..bbc3c5f92 100644 --- a/include/class/print_ledger_simple_without_vat.class.php +++ b/include/class/print_ledger_simple_without_vat.class.php @@ -23,18 +23,15 @@ * \brief this class extends PDF and let you export the detailled printing * of any ledgers */ -require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php'; -class Print_Ledger_Simple_Without_Vat extends PDF +class Print_Ledger_Simple_Without_Vat extends Print_Ledger { - private $filter_operation; - public function __construct ($p_cn,$p_jrn,$p_filter_operation) + public function __construct ($p_cn,$p_jrn,$p_from,$p_to,$p_filter_operation) { - if($p_cn == null) die("No database connection. Abort."); - parent::__construct($p_cn,'L', 'mm', 'A4'); - $this->ledger=$p_jrn; + parent::__construct($p_cn,'L', 'mm', 'A4',$p_jrn,$p_from,$p_to,$p_filter_operation); $this->jrn_type=$p_jrn->get_type(); //---------------------------------------------------------------------- /* report @@ -42,13 +39,12 @@ class Print_Ledger_Simple_Without_Vat extends PDF * get rappel to initialize amount rap_xx *the easiest way is to compute sum from quant_ */ - $this->previous=$this->ledger->previous_amount($_GET['from_periode']); + $this->previous=$this->get_ledger()->previous_amount($p_from); $this->rap_htva=$this->previous['price']; $this->rap_tvac=$this->previous['price']; $this->rap_priv=$this->previous['priv']; - $this->filter_operation=$p_filter_operation; } @@ -142,21 +138,25 @@ class Print_Ledger_Simple_Without_Vat extends PDF */ function export() { - $http=new HttpInput; - $ledger_history=Acc_Ledger_History::factory($this->cn, - array($this->ledger->id), - $http->get('from_periode','number'), - $http->get('to_periode','number'), - 'D', - $this->filter_operation); - $a_jrn=$ledger_history->get_row(); - if ( $a_jrn == null ) return; + $ledger_history=Acc_Ledger_History::factory($this->cn, + array($this->get_ledger()->id), + $this->get_from(), + $this->get_to(), + 'D', + $this->get_filter_operation()); + + $ledger_history->get_row(); + $a_jrn=$ledger_history->get_data(); + + if ( empty($a_jrn ) ) return; // Prepare the query for reconcile date $prepared_query=new Prepared_Query($this->cn); $prepared_query->prepare_reconcile_date(); + $ledger=$this->get_ledger(); + for ( $i=0;$iLongLine(105,5,$row['jr_comment'],0,'L'); /* get other amount (without vat, total vat included, private, ND */ - $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']); + $other=$ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']); $this->tp_htva+=$other['price']; $this->tp_priv+=$other['priv']; $this->rap_htva+=$other['price']; @@ -184,7 +184,7 @@ class Print_Ledger_Simple_Without_Vat extends PDF } $this->write_cell(15,5,sprintf("%.2f",$other['price']),0,0,'R'); - $ret_reconcile=$this->cn->execute('reconcile_date',array($row['id'])); + $ret_reconcile=$this->cn->execute('reconcile_date',array($row['jr_id'])); $max=Database::num_row($ret_reconcile); $str_payment=""; if ($max > 0) { diff --git a/include/export/export_ledger_csv.php b/include/export/export_ledger_csv.php index 8249fc97c..b18377b55 100644 --- a/include/export/export_ledger_csv.php +++ b/include/export/export_ledger_csv.php @@ -28,19 +28,22 @@ */ if (!defined('ALLOWED')) die('Appel direct ne sont pas permis'); + include_once NOALYSS_INCLUDE."/lib/ac_common.php"; require_once NOALYSS_INCLUDE.'/class/noalyss_parameter_folder.class.php'; require_once NOALYSS_INCLUDE.'/class/acc_ledger_sold.class.php'; require_once NOALYSS_INCLUDE.'/class/acc_ledger_purchase.class.php'; require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php'; -require_once NOALYSS_INCLUDE.'/class/dossier.class.php'; -$gDossier=dossier::id(); + +require_once NOALYSS_INCLUDE.'/class/dossier.class.php'; require_once NOALYSS_INCLUDE.'/class/database.class.php'; require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php'; require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php'; - require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; + + +$gDossier=dossier::id(); $http=new HttpInput(); $export=new Noalyss_Csv(_('journal')); @@ -87,12 +90,13 @@ if ($get_jrn==0) { // find out all the available ledgers for the current user $a_jrn=Print_Ledger::available_ledger($get_from_periode); + $Jrn=new Acc_Ledger($cn,0); } else { $a_jrn=$get_jrn; + $Jrn=new Acc_Ledger($cn, $get_jrn); } -$Jrn=new Acc_Ledger($cn, $get_jrn); $Jrn->get_name(); $jrn_type=$Jrn->get_type(); diff --git a/include/export/export_ledger_pdf.php b/include/export/export_ledger_pdf.php index 7cdbb18f1..9ed69aa81 100644 --- a/include/export/export_ledger_pdf.php +++ b/include/export/export_ledger_pdf.php @@ -47,6 +47,8 @@ try $jrn_id=$http->get('jrn_id',"number"); $p_simple=$http->get('p_simple',"string"); $filter_operation=$http->get("operation_type"); + $from=$http->get("from_periode","number"); + $to=$http->get("to_periode","number"); } catch (Exception $exc) @@ -71,11 +73,10 @@ if ($jrn_id != 0 && $g_user->check_jrn($jrn_id) == 'X') { } $ret = ""; - +if ( $jrn_id == 0 ) $Jrn->id=0; $jrn_type = $Jrn->get_type(); -$pdf = Print_Ledger::factory($cn, $p_simple, "PDF", $Jrn,$filter_operation); -$pdf->set_filter_operation($filter_operation); +$pdf = Print_Ledger::factory($cn, $p_simple, $Jrn,$from,$to,$filter_operation); $pdf->setDossierInfo($Jrn->jrn_def_name); $pdf->AliasNbPages(); $pdf->AddPage(); diff --git a/unit-test/include/class/print_LedgerTest.php b/unit-test/include/class/print_LedgerTest.php new file mode 100644 index 000000000..9286dc1af --- /dev/null +++ b/unit-test/include/class/print_LedgerTest.php @@ -0,0 +1,147 @@ + + +/** + * @file + * @brief concerne print_LedgerTest + * @coversDefaultClass Print_Ledger + */ +class print_LedgerTest extends TestCase +{ + + /** + * @var + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + include 'global.php'; + // Exercice 2018 + $this->from=92; + $this->to=103; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + } + /** + * + * @covers ::factory + */ + function testFactory() + { + global $g_connection; + $ledger_sale=new Acc_Ledger_Sold($g_connection,2); + $p_from=$this->from; + $p_to=$this->to; + + // Check Sales + $ledger=\Print_Ledger::factory($g_connection,"D", $ledger_sale, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Simple + ,"Sale Detail returns Print_Ledger_Simple"); + + $ledger=\Print_Ledger::factory($g_connection,"L", $ledger_sale, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Simple + ,"Sale Listing returns Print_Ledger_Simple"); + + $ledger=\Print_Ledger::factory($g_connection,"E", $ledger_sale, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + ,"Sale Extended returns Print_Ledger_Detail_Item"); + + $ledger=\Print_Ledger::factory($g_connection,"A", $ledger_sale, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail, + "Sale Accounting returns Print_Ledger_Detail"); + + // Check Purchase + $ledger_purchase=new Acc_Ledger_Purchase($g_connection,3); + $ledger=\Print_Ledger::factory($g_connection,"D", $ledger_purchase, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Simple + ,"Purchase Detail returns Print_Ledger_Simple"); + + $ledger=\Print_Ledger::factory($g_connection,"L", $ledger_purchase, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Simple + ,"Purchase Listing returns Print_Ledger_Simple"); + + $ledger=\Print_Ledger::factory($g_connection,"E", $ledger_purchase, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + ,"Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger=\Print_Ledger::factory($g_connection,"A", $ledger_purchase, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail + ,"Purchase Accounting returns Print_Ledger_Detail"); + + // Check Misc + $ledger_misc=new Acc_Ledger($g_connection,4); + $ledger=\Print_Ledger::factory($g_connection,"D", $ledger_misc, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail + ,"Misc. Detail returns Print_Ledger_Detail"); + + $ledger=\Print_Ledger::factory($g_connection,"L", $ledger_misc, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Misc + ,"Misc. Listing returns Print_Ledger_Misc"); + + $ledger=\Print_Ledger::factory($g_connection,"E", $ledger_misc, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail + ,"Misc. Extended returns Print_Ledger_Detail"); + + $ledger=\Print_Ledger::factory($g_connection,"A", $ledger_misc, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail + ,"Misc. Accounting returns Print_Ledger_Detail"); + + // Financial + $ledger_fin=new Acc_Ledger_Fin($g_connection,1); + $ledger=\Print_Ledger::factory($g_connection,"D", $ledger_fin, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Financial + ,"Fin. Detail returns Print_Ledger_Financial"); + + $ledger=\Print_Ledger::factory($g_connection,"L", $ledger_fin, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Financial + ,"Fin. Detail returns Print_Ledger_Financial"); + + $ledger=\Print_Ledger::factory($g_connection,"E", $ledger_fin, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail + ,"Fin. Detail returns Print_Ledger_Financial"); + + $ledger=\Print_Ledger::factory($g_connection,"A", $ledger_fin, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail + ,"Fin. Detail returns Print_Ledger_Detail"); + + } + //@covers \Print_Ledger::available_ledger + function test_availableLedger() + { + $a_jrn=\Print_Ledger::available_ledger(94); + $this->assertEquals(6,count($a_jrn),"Number of available ledger correct"); + } + +} diff --git a/unit-test/include/class/print_ledger_detail.classTest.php b/unit-test/include/class/print_ledger_detail.classTest.php new file mode 100644 index 000000000..769e486d5 --- /dev/null +++ b/unit-test/include/class/print_ledger_detail.classTest.php @@ -0,0 +1,81 @@ + + +/** + * @file + * @brief concerne print_ledger_detail + * @coversDefaultClass Print_Ledger_Detail + */ +include_once 'global.php'; + +class Print_Ledger_DetailTest extends TestCase +{ + + /** + * @var + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + $this->from=92; + $this->to=103; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + + + } + function test_export() + { + global $g_connection; + $p_from=$this->from; + $p_to=$this->to; + + // Financial + $ledger_fin=new Acc_Ledger($g_connection,4); + $ledger=\Print_Ledger::factory($g_connection,"D", $ledger_fin, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail + ,"Misc. Detail returns Print_Ledger"); + + $ledger->setDossierInfo($ledger_fin->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/misc-detail.pdf","F"); + $this->assertFileExists(__DIR__."/file/misc-detail.pdf"); + } + +} diff --git a/unit-test/include/class/print_ledger_detail_item.classTest.php b/unit-test/include/class/print_ledger_detail_item.classTest.php new file mode 100644 index 000000000..56cbd24f0 --- /dev/null +++ b/unit-test/include/class/print_ledger_detail_item.classTest.php @@ -0,0 +1,162 @@ + + +/** + * @file + * @brief concerne print_ledger_detail_item.classTest + * @coversDefaultClass print_ledger_detail_item + */ +class Print_Ledger_Detail_ItemTest extends TestCase +{ + + /** + * @var + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + include 'global.php'; + $this->from=92; + $this->to=103; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + } + + public function test_Export() + { + global $g_connection; + $p_from=$this->from; + $p_to=$this->to; + //------------------------------------------------------------------------------------------------------------- + // Purchase + //------------------------------------------------------------------------------------------------------------- + + $ledger_purchase=new Acc_Ledger_Purchase($g_connection,3); + + // Paid + //------------ + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_purchase, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_purchase->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Achat Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_detail_purchase_paid.pdf","F"); + + // Unpaid + //------------ + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_purchase, $p_from, $p_to, "unpaid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_purchase->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Non Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_detail_purchase_unpaid.pdf","F"); + $this->assertFileExists(__DIR__."/file/print_ledger_detail_purchase_unpaid.pdf"); + + // All + //------------ + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_purchase, $p_from, $p_to, "all"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_purchase->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Achat tous"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_detail_purchase_all.pdf","F"); + $this->assertFileExists(__DIR__."/file/print_ledger_detail_purchase_all.pdf"); + + //------------------------------------------------------------------------------------------------------------- + // Sale + //------------------------------------------------------------------------------------------------------------- + $ledger_sale=new Acc_Ledger_Sold($g_connection,2); + + // Paid + //----------------- + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_sale, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_sale->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Vente Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_detail_sale_paid.pdf","F"); + + // Unpaid + //----------------- + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_sale, $p_from, $p_to, "unpaid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_sale->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Non Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_detail_sale_unpaid.pdf","F"); + $this->assertFileExists(__DIR__."/file/print_ledger_detail_sale_unpaid.pdf"); + + // All + //----------------- + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_sale, $p_from, $p_to, "all"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_sale->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Vente tous"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_detail_sale_all.pdf","F"); + $this->assertFileExists(__DIR__."/file/print_ledger_detail_sale_all.pdf"); + } + +} diff --git a/unit-test/include/class/print_ledger_fin.classTest.php b/unit-test/include/class/print_ledger_fin.classTest.php new file mode 100644 index 000000000..8c6377881 --- /dev/null +++ b/unit-test/include/class/print_ledger_fin.classTest.php @@ -0,0 +1,111 @@ + + +/** + * @file + * @brief concerne print_ledger_fin.classTest + * @coversDefaultClass Print_Ledger_Fin + */ +class Print_Ledger_FinTest extends TestCase +{ + + /** + * @var + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + include 'global.php'; + $this->from=92; + $this->to=103; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + } + public function test_Export() + { + global $g_connection; + $p_from=$this->from; + $p_to=$this->to; + + // Financial + $ledger_fin=new Acc_Ledger_Fin($g_connection,1); + $ledger=\Print_Ledger::factory($g_connection,"D", $ledger_fin, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Financial + ,"Fin. Detail returns Print_Ledger_Financial"); + + $ledger->setDossierInfo($ledger_fin->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/financial-detail.pdf","F"); + + $ledger=\Print_Ledger::factory($g_connection,"L", $ledger_fin, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Financial + ,"Fin. Detail returns Print_Ledger_Financial"); + $ledger->setDossierInfo($ledger_fin->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/financial-listing.pdf","F"); + + + $ledger=\Print_Ledger::factory($g_connection,"E", $ledger_fin, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail + ,"Fin. Detail returns Print_Ledger_Financial"); + $ledger->setDossierInfo($ledger_fin->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/financial-extended.pdf","F"); + + $ledger=\Print_Ledger::factory($g_connection,"A", $ledger_fin, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail + ,"Fin. Detail returns Print_Ledger_Detail"); + $ledger->setDossierInfo($ledger_fin->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/financial-accounting.pdf","F"); + } + +} diff --git a/unit-test/include/class/print_ledger_misc.classTest.php b/unit-test/include/class/print_ledger_misc.classTest.php new file mode 100644 index 000000000..938ca765f --- /dev/null +++ b/unit-test/include/class/print_ledger_misc.classTest.php @@ -0,0 +1,89 @@ + + +/** + * @file + * @brief concerne print_ledger_misc.classTest + */ +class Print_Ledger_MiscTest extends TestCase +{ + + /** + * @var + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + include 'global.php'; + // Exercice 2018 + $this->from=92; + $this->to=103; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + } + + function test_export() + { + global $g_connection; + $p_from=$this->from; + $p_to=$this->to; + + // Check Misc + $ledger_misc=new Acc_Ledger($g_connection, 4); + $ledger=\Print_Ledger::factory($g_connection, "D", $ledger_misc, $p_from, $p_to, "all"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail + , "Misc. Detail returns Print_Ledger_Detail"); + + $ledger->setDossierInfo($ledger_misc->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Opérations diverses "), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_detail_misc.pdf", "F"); + + $ledger=\Print_Ledger::factory($g_connection, "L", $ledger_misc, $p_from, $p_to, "all"); + $this->assertTrue($ledger instanceof Print_Ledger_Misc + , "Misc. Listing returns Print_Ledger_Misc"); + $ledger->setDossierInfo($ledger_misc->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Opérations diverses"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_misc.pdf", "F"); + } + +} diff --git a/unit-test/include/class/print_ledger_simple.classTest.php b/unit-test/include/class/print_ledger_simple.classTest.php new file mode 100644 index 000000000..1cf71058b --- /dev/null +++ b/unit-test/include/class/print_ledger_simple.classTest.php @@ -0,0 +1,166 @@ + + +/** + * @file + * @brief concern Print_Ledger_Simple + * @coversDefaultClass Print_Ledger_Simple + */ +class print_ledger_simpleTest extends TestCase +{ + + /** + * @var + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + include 'global.php'; + // Exercice 2018 + $this->from=92; + $this->to=103; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + } + + /** + * @covers ::export + */ + function test_export() + { + global $g_connection; + $p_from=$this->from; + $p_to=$this->to; + //------------------------------------------------------------------------------------------------------------- + // Purchase + //------------------------------------------------------------------------------------------------------------- + + $ledger_purchase=new Acc_Ledger_Purchase($g_connection, 3); + + // Paid + //------------ + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_purchase, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_purchase->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Achat Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_simple_purchase_paid.pdf", "F"); + + // Unpaid + //------------ + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_purchase, $p_from, $p_to, "unpaid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_purchase->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Non Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_simple_purchase_unpaid.pdf", "F"); + $this->assertFileExists(__DIR__."/file/print_ledger_simple_purchase_unpaid.pdf"); + + // All + //------------ + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_purchase, $p_from, $p_to, "all"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_purchase->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Achat tous"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_simple_purchase_all.pdf", "F"); + $this->assertFileExists(__DIR__."/file/print_ledger_simple_purchase_all.pdf"); + + //------------------------------------------------------------------------------------------------------------- + // Sale + //------------------------------------------------------------------------------------------------------------- + $ledger_sale=new Acc_Ledger_Sold($g_connection, 2); + + // Paid + //----------------- + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_sale, $p_from, $p_to, "paid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_sale->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Vente Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_simple_sale_paid.pdf", "F"); + + // Unpaid + //----------------- + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_sale, $p_from, $p_to, "unpaid"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_sale->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Non Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_simple_sale_unpaid.pdf", "F"); + $this->assertFileExists(__DIR__."/file/print_ledger_simple_sale_unpaid.pdf"); + + // All + //----------------- + $ledger=\Print_Ledger::factory($g_connection, "E", $ledger_sale, $p_from, $p_to, "all"); + $this->assertTrue($ledger instanceof Print_Ledger_Detail_Item + , "Purchase Extended returns Print_Ledger_Detail_Item"); + + $ledger->setDossierInfo($ledger_sale->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Vente tous"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_ledger_simple_sale_all.pdf", "F"); + $this->assertFileExists(__DIR__."/file/print_ledger_simple_sale_all.pdf"); + } + +} diff --git a/unit-test/include/class/print_ledger_simple_without_vat.classTest.php b/unit-test/include/class/print_ledger_simple_without_vat.classTest.php new file mode 100644 index 000000000..865aa804b --- /dev/null +++ b/unit-test/include/class/print_ledger_simple_without_vat.classTest.php @@ -0,0 +1,161 @@ + + +/** + * @file + * @brief concern print_ledger_simple_without_vat + * @coversDefaultClass print_ledger_simple_without_vat + */ +class Print_Ledger_Simple_Without_VatTest extends TestCase +{ + + /** + * @var + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + include 'global.php'; + // Exercice 2018 + $this->from=92; + $this->to=103; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + } + + /** + * @covers ::export + */ + function test_export() + { + global $g_connection; + $p_from=$this->from; + $p_to=$this->to; + //------------------------------------------------------------------------------------------------------------- + // Purchase + //------------------------------------------------------------------------------------------------------------- + + $ledger_purchase=new Acc_Ledger_Purchase($g_connection, 3); + + // Paid + //------------ + + $ledger=new Print_Ledger_Simple_Without_Vat($g_connection, + $ledger_purchase, $p_from, $p_to, "paid"); + + $ledger->setDossierInfo($ledger_purchase->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Achat Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_Ledger_simple_without_vat_purchase_paid.pdf", "F"); + + // Unpaid + //------------ + $ledger=new Print_Ledger_Simple_Without_Vat($g_connection, + $ledger_purchase, $p_from, $p_to, "unpaid"); + + $ledger->setDossierInfo($ledger_purchase->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Non Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_Ledger_simple_without_vat_purchase_unpaid.pdf", "F"); + $this->assertFileExists(__DIR__."/file/print_Ledger_simple_without_vat_purchase_unpaid.pdf"); + + // All + //------------ + $ledger=new Print_Ledger_Simple_Without_Vat($g_connection, + $ledger_purchase, $p_from, $p_to, "all"); + + $ledger->setDossierInfo($ledger_purchase->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Achat tous"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_Ledger_simple_without_vat_purchase_all.pdf", "F"); + $this->assertFileExists(__DIR__."/file/print_Ledger_simple_without_vat_purchase_all.pdf"); + + //------------------------------------------------------------------------------------------------------------- + // Sale + //------------------------------------------------------------------------------------------------------------- + $ledger_sale=new Acc_Ledger_Sold($g_connection, 2); + + // Paid + //----------------- + $ledger=new Print_Ledger_Simple_Without_Vat($g_connection, + $ledger_sale, $p_from, $p_to, "paid"); + + $ledger->setDossierInfo($ledger_sale->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Vente Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_Ledger_simple_without_vat_sale_paid.pdf", "F"); + + // Unpaid + //----------------- + $ledger=new Print_Ledger_Simple_Without_Vat($g_connection, + $ledger_sale, $p_from, $p_to, "unpaid"); + + $ledger->setDossierInfo($ledger_sale->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Non Payé"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_Ledger_simple_without_vat_sale_unpaid.pdf", "F"); + $this->assertFileExists(__DIR__."/file/print_Ledger_simple_without_vat_sale_unpaid.pdf"); + + // All + //----------------- + $ledger=new Print_Ledger_Simple_Without_Vat($g_connection, + $ledger_sale, $p_from, $p_to, "all"); + + $ledger->setDossierInfo($ledger_sale->jrn_def_name); + $ledger->AliasNbPages(); + $ledger->AddPage(); + $ledger->SetAuthor('NOALYSS'); + $ledger->setTitle(_("Journal Vente tous"), true); + $ledger->export(); + $ledger->Output(__DIR__."/file/print_Ledger_simple_without_vat_sale_all.pdf", "F"); + $this->assertFileExists(__DIR__."/file/print_Ledger_simple_without_vat_sale_all.pdf"); + } + +} From 1e37a91cb2d881a61616a053d426ca0cf4122b0a Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 17 Nov 2019 21:33:43 +0100 Subject: [PATCH 09/23] remove Obsolete --- include/class/acc_account_ledger.class.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/include/class/acc_account_ledger.class.php b/include/class/acc_account_ledger.class.php index a33d4d20c..3cc75754a 100644 --- a/include/class/acc_account_ledger.class.php +++ b/include/class/acc_account_ledger.class.php @@ -260,15 +260,7 @@ class Acc_Account_Ledger return true; } - /*!\brief Get all the value for this object from the database - * the data member are set - * \return false if this account doesn't exist otherwise true - */ - function get() - { - echo "OBSOLETE Acc_Account_Ledger->get(), a remplacer par Acc_Account_Ledger->load()"; - return $this->load(); - } + /*! * \brief give the balance of an account From 1d78f24bee67859ecef66740e94a9129e422cbbd Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 17 Nov 2019 21:34:22 +0100 Subject: [PATCH 10/23] Correct report amount --- include/class/acc_ledger.class.php | 40 ++++++++++++++------- include/class/print_ledger_simple.class.php | 2 +- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index dabc16a3f..2221c1e15 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -46,7 +46,6 @@ require_once NOALYSS_INCLUDE.'/lib/sort_table.class.php'; require_once NOALYSS_INCLUDE.'/database/jrn_def_sql.class.php'; require_once NOALYSS_INCLUDE.'/class/acc_payment.class.php'; require_once NOALYSS_INCLUDE.'/class/acc_ledger_history.class.php'; -//require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php'; require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; require_once NOALYSS_INCLUDE.'/class/pre_op_ods.class.php'; @@ -571,7 +570,7 @@ class Acc_Ledger extends jrn_def_sql global $g_parameter; $msg=array(); if (!$p_readonly) - $msg=$this->verify($p_array); + $msg=$this->verify_operation($p_array); $this->id=$p_array['p_jrn']; if (empty($p_array)) return _("Aucun résultat"); @@ -1926,8 +1925,12 @@ class Acc_Ledger extends jrn_def_sql $ret=$array[0]; /* retrieve all vat code */ $array=$this->db->get_array("select coalesce(sum(qp_vat),0) as sum_vat,tva_id - from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id) - where tva_rate !=0 and j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') + from quant_purchase as p + right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id) + where + tva_rate !=0 + and j_date >= to_date($1,'DD.MM.YYYY') + and j_date < to_date($2,'DD.MM.YYYY') and j_jrn_def = $3 group by tva_id", array($min_date, $max_date, $this->id)); @@ -1941,7 +1944,7 @@ class Acc_Ledger extends jrn_def_sql ',0 as priv'. ',0 as tva_nd'. ',coalesce(sum(qs_vat_sided),0) as reversed'. - ',coalesce(sum(qs_vat_sided),0) as tva_np'. + ',0 as tva_np'. ' from quant_sold join jrnx using(j_id) '. " where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ". ' and j_jrn_def = $3'; @@ -1950,10 +1953,14 @@ class Acc_Ledger extends jrn_def_sql $ret=$array[0]; /* retrieve all vat code */ $array=$this->db->get_array("select coalesce(sum(qs_vat),0) as sum_vat,tva_id - from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id) - where tva_rate !=0 and - j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') - and j_jrn_def = $3 + from quant_sold as p + right join tva_rate on (qs_vat_code=tva_id) + join jrnx using(j_id) + where + tva_rate !=0 and + j_date >= to_date($1,'DD.MM.YYYY') + and j_date < to_date($2,'DD.MM.YYYY') + and j_jrn_def = $3 group by tva_id", array($min_date, $max_date, $this->id)); $ret['tva']=$array; @@ -1965,10 +1972,19 @@ class Acc_Ledger extends jrn_def_sql $ledger=new Acc_Ledger_Fin($this->db, $this->id); $qcode=$ledger->get_bank(); $bank_card=new Fiche($this->db, $qcode); - + $periode=new Periode($this->db); + //$periode->find_periode($min_date); + //$a_date=$periode->get_limit($periode->get_exercice()); + /* add the amount from Opening Writing */ - $cond=sprintf(" j_jrn_def <> %d and j_date >= to_date('%s','DD.MM.YYYY') and j_date < to_date('%s','DD.MM.YYYY') ", - $this->id, $min_date, $max_date); + if ( $min_date <> $max_date) + { + $cond=sprintf("j_date >= to_date('%s','DD.MM.YYYY') and j_date < to_date('%s','DD.MM.YYYY') ", + $min_date,$max_date); + }else{ + $cond=sprintf("j_date = to_date('%s','DD.MM.YYYY') ", + $min_date); + } $saldo=$bank_card->get_bk_balance($cond); $ret['amount']=bcsub($saldo['debit'], $saldo['credit']); } diff --git a/include/class/print_ledger_simple.class.php b/include/class/print_ledger_simple.class.php index 399a8a5ad..a92a7e9c2 100644 --- a/include/class/print_ledger_simple.class.php +++ b/include/class/print_ledger_simple.class.php @@ -215,7 +215,7 @@ class Print_Ledger_Simple extends \Print_Ledger */ function export() { - bcscale(2); + bcscale(4); $ledger=$this->get_ledger(); $ledger_history=Acc_Ledger_History::factory($this->cn, array($ledger->id), From 2819f49db4cba4dfca3f246892d23eed9d7837ad Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 17 Nov 2019 21:34:59 +0100 Subject: [PATCH 11/23] In Acc_Ledger, the type shouldn't be overrided , create new attr ledger_type --- include/class/acc_ledger_fin.class.php | 2 +- include/class/acc_ledger_purchase.class.php | 2 +- include/class/acc_ledger_sold.class.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/class/acc_ledger_fin.class.php b/include/class/acc_ledger_fin.class.php index 887078c23..6392d8602 100644 --- a/include/class/acc_ledger_fin.class.php +++ b/include/class/acc_ledger_fin.class.php @@ -42,7 +42,7 @@ class Acc_Ledger_Fin extends Acc_Ledger function __construct($p_cn, $p_init) { parent::__construct($p_cn, $p_init); - $this->type = 'FIN'; + $this->ledger_type = 'FIN'; } /** diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index 55ad50ca0..dcbaf3a3d 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -50,7 +50,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger { function __construct ($p_cn,$p_init) { - $this->type='ACH'; + $this->ledger_type='ACH'; parent::__construct($p_cn,$p_init); } /*!\brief verify that the data are correct before inserting or confirming diff --git a/include/class/acc_ledger_sold.class.php b/include/class/acc_ledger_sold.class.php index 2f7ae135b..e5b21eaab 100644 --- a/include/class/acc_ledger_sold.class.php +++ b/include/class/acc_ledger_sold.class.php @@ -53,7 +53,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { function __construct($p_cn, $p_init) { parent::__construct($p_cn, $p_init); - $this->type = 'VEN'; + $this->ledger_type = 'VEN'; } /*!\brief verify that the data are correct before inserting or confirming From 2d6a28119710a93e7786ec46a59ab674580d6ac4 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 17 Nov 2019 21:35:23 +0100 Subject: [PATCH 12/23] Improve PHPUNIT test --- unit-test/create-dossier-test.sh | 3 +- unit-test/facility.class.php | 1 + .../include/class/acc_account_ledger.Test.php | 275 +++++++++++++----- unit-test/include/class/acc_balance.Test.php | 4 +- unit-test/include/class/acc_ledger.Test.php | 21 +- .../include/class/acc_ledger_sold.Test.php | 5 +- .../include/class/acc_operation.Test.php | 12 - .../include/class/anc_grandlivre.Test.php | 1 - unit-test/test-file.sh | 4 +- 9 files changed, 220 insertions(+), 106 deletions(-) diff --git a/unit-test/create-dossier-test.sh b/unit-test/create-dossier-test.sh index 51d1d3607..f838f52ae 100755 --- a/unit-test/create-dossier-test.sh +++ b/unit-test/create-dossier-test.sh @@ -2,6 +2,7 @@ DOSSIER_TEST=rel70dossier25 +dropdb $DOSSIER_TEST createdb $DOSSIER_TEST -pg_restore -Fc --no-owner --no-privilege --verbose -d $DOSSIER_TEST db/dossiertest191112-1806.bin +pg_restore -Fc --no-owner --no-privilege --verbose -d $DOSSIER_TEST db/dossiertest191117-0909.bin diff --git a/unit-test/facility.class.php b/unit-test/facility.class.php index c32a55aff..3f1d0794e 100644 --- a/unit-test/facility.class.php +++ b/unit-test/facility.class.php @@ -61,6 +61,7 @@ EOF; */ static function save_file($p_dir, $p_file, $p_content) { + printf (" saving %s/%s please check this file \n ",$p_dir,$p_file); $hFile=fopen($p_dir."/".$p_file, "w+"); fwrite($hFile, $p_content); fclose($hFile); diff --git a/unit-test/include/class/acc_account_ledger.Test.php b/unit-test/include/class/acc_account_ledger.Test.php index d9c5101f2..c9a79c461 100644 --- a/unit-test/include/class/acc_account_ledger.Test.php +++ b/unit-test/include/class/acc_account_ledger.Test.php @@ -1,8 +1,10 @@ object->get_row(92,103); - $this->assertEquals(count($array),3); + $array=$this->object->get_row(92, 103); + $this->assertEquals(count($array), 3); } /** * @covers Acc_Account_Ledger::get_row_date - * @todo Implement testGet_row_date(). */ public function testGet_row_date() { - $this->object->get_row_date('01.01.2017', '01.02.2017', 0); + 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, + ), + 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, + ), + 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, + ), + 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, + ), + 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, + ), + 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, + ), + ), + 1=>'0', + 2=>'114.5700', + ); + $this->assertEquals($expected, $a_array); } + function dataGet_Name() { return array( - array('10','Capital '), - array('01','Poste inconnu') + array('10', 'Capital '), + array('01', 'Poste inconnu') ); } + /** * @covers Acc_Account_Ledger::get_name - * @todo Implement testGet_name(). * @dataProvider dataGet_Name */ - public function testGet_name($id,$result) + public function testGet_name($id, $result) { - $this->object->id=$id; - $this->assertEquals($this->object->get_name(),$result); + $this->object->id=$id; + $this->assertEquals($this->object->get_name(), $result); } /** * @covers Acc_Account_Ledger::do_exist - * @todo Implement testDo_exist(). * @dataProvider dataDo_exist */ public function testDo_exist($p_value, $result) @@ -95,102 +244,79 @@ class Acc_Account_LedgerTest extends TestCase /** * @covers Acc_Account_Ledger::load - * @todo Implement testLoad(). */ public function testLoad() { $this->object->load(); - - } - - /** - * @covers Acc_Account_Ledger::get - * @todo Implement testGet(). - */ - public function testGet() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->assertTrue($this->object->id==400, "test load"); } /** * @covers Acc_Account_Ledger::get_solde - * @todo Implement testGet_solde(). */ public function testGet_solde() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + global $g_connection; + $accounting=new Acc_Account_Ledger($g_connection, '4511'); + $this->assertEquals($accounting->get_solde(),248.97); } /** * @covers Acc_Account_Ledger::get_solde_detail - * @todo Implement testGet_solde_detail(). */ public function testGet_solde_detail() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + global $g_connection; + $accounting=new Acc_Account_Ledger($g_connection, '4511'); + $expected=array ( + 'debit' => '0', + 'credit' => '248.9700', + 'solde' => 248, + ); + $this->assertEquals($accounting->get_solde_detail(),$expected); } /** * @covers Acc_Account_Ledger::isTVA - * @todo Implement testIsTVA(). */ public function testIsTVA() { $this->object->id="4111"; - $this->assertEquals($this->object->isTVA(),1); + $this->assertEquals($this->object->isTVA(), 1); $this->object->id=10; - $this->assertEquals($this->object->isTVA(),0); - + $this->assertEquals($this->object->isTVA(), 0); } /** * @covers Acc_Account_Ledger::HtmlTable - * @todo Implement testHtmlTable(). */ public function testHtmlTable() { - $this->assertTrue(true,'Ne peut être testé car vue HTML'); + $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'), + return array( + array(0, "="), + array(1000, 'D'), + array(-1000, 'C'), ); } - /** - * @covers Acc_Account_Ledger::get_amount_side - * @todo Implement testGet_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::HtmlTableHeader - * @todo Implement testHtmlTableHeader(). + * @covers Acc_Account_Ledger::get_amount_side + * @dataProvider dataGet_amount_side */ - public function testHtmlTableHeader() + public function testGet_amount_side($amount, $result) { - // Remove the following lines when you implement this test. - $this->assertTrue(true,'Ne peut être testé car vue HTML'); + $this->assertEquals($this->object->get_amount_side($amount), $result); } + + /** * @covers Acc_Account_Ledger::belong_ledger - * @todo Implement testBelong_ledger(). * @dataProvider DataBelong_ledger */ public function testBelong_ledger($p_jrn, $result) @@ -208,38 +334,33 @@ class Acc_Account_LedgerTest extends TestCase array(4, 0) ); } + public function dataGet_account_ledger() { return array( - array(0,array()), - array(1,array('5*','')), - array(2,array('4*')), - array(3,array('6*')) - + array(0, array()), + array(1, array('5*', '')), + array(2, array('4*')), + array(3, array('6*')) ); } + /** * @covers Acc_Account_Ledger::get_account_ledger - * @todo Implement testGet_account_ledger(). * @dataProvider dataGet_account_ledger */ - public function testGet_account_ledger($p_jrn,$result) + public function testGet_account_ledger($p_jrn, $result) { - echo "ledger $p_jrn"; - $this->assertEquals($this->object->get_account_ledger($p_jrn),$result); - printf ("\n"); + $this->assertEquals($this->object->get_account_ledger($p_jrn), $result); } /** * @covers Acc_Account_Ledger::build_sql_account - * @todo Implement testBuild_sql_account(). * @dataProvider DataBuild_Sql_account */ public function testBuild_sql_account($p_jrn, $result) { - print "\n--------------------\n"; $value=$this->object->build_sql_account($p_jrn); - printf(" ledger %s [%s]", $p_jrn, $value); $this->assertEquals(trim($value), $result); } @@ -275,6 +396,4 @@ class Acc_Account_LedgerTest extends TestCase $this->assertEquals($p_card, $result[0]['f_id']); } - - } diff --git a/unit-test/include/class/acc_balance.Test.php b/unit-test/include/class/acc_balance.Test.php index a649f11cd..0a83f9233 100644 --- a/unit-test/include/class/acc_balance.Test.php +++ b/unit-test/include/class/acc_balance.Test.php @@ -48,10 +48,10 @@ class Acc_BalanceTest extends TestCase $min=$g_connection->get_value("select min(p_id) from parm_periode"); $this->object->jrn=NULL; $array=$this->object->get_row($min,$max); - $this->assertEquals(31,count($array)); + $this->assertEquals(32,count($array)); $this->object->jrn=[2,4]; $array=$this->object->get_row($min,$max); - $this->assertEquals(10,count($array)); + $this->assertEquals(12,count($array)); } diff --git a/unit-test/include/class/acc_ledger.Test.php b/unit-test/include/class/acc_ledger.Test.php index fbc516180..93e8af5bc 100644 --- a/unit-test/include/class/acc_ledger.Test.php +++ b/unit-test/include/class/acc_ledger.Test.php @@ -85,7 +85,7 @@ class Acc_LedgerTest extends TestCase $this->object->id=2; $sPj=$this->object->get_last_pj(2); - $this->assertEquals(40,$sPj); + $this->assertEquals(39,$sPj); $this->object->id=0; try { @@ -564,7 +564,7 @@ class Acc_LedgerTest extends TestCase { global $g_connection; $ledger=new Acc_Ledger($g_connection,4); - $this->assertEquals("3,2,4",$ledger->get_all_fiche_def()); + $this->assertEquals("3,2,4,5",$ledger->get_all_fiche_def()); } /** @@ -574,9 +574,9 @@ class Acc_LedgerTest extends TestCase { $result=[ ["solde"=> 658.25 , "j_poste"=> "4400004", "j_qcode"=> "FOURNI"], - ["solde"=> 490.7700 , "j_poste"=> "4000005", "j_qcode"=> "CLIENT1"], + ["solde"=> 660.17 , "j_poste"=> "4000005", "j_qcode"=> "CLIENT1"], ["solde"=> 87.8400, "j_poste"=> "4112", "j_qcode"=> ""], - ["solde"=>-85.1700 , "j_poste"=> "4511", "j_qcode"=> ""], + ["solde"=>-114.57 , "j_poste"=> "4511", "j_qcode"=> ""], ["solde"=> -1496.3400 , "j_poste"=>"4400005", "j_qcode"=> "FOURNI1"] ]; $get=$this->object->get_saldo_exercice("2018"); @@ -794,7 +794,7 @@ class Acc_LedgerTest extends TestCase public function testSave_new() { global $g_connection; - + $ledger=new Acc_Ledger($g_connection,-1); $array=["p_jrn_name"=>"UNITTEST", "p_ech_lib"=>"", "p_jrn_deb_max_line"=>7, @@ -809,12 +809,14 @@ class Acc_LedgerTest extends TestCase // clean ledger if exists $g_connection->exec_sql("delete from jrn_def where jrn_def_name=$1",[$array['p_jrn_name']]); - $this->object->save_new($array); - $jrn_def_id=$g_connection->get_value("select jrn_def_id from jrn_def where jrn_def_name=$1",[$array['p_jrn_name']]); + $ledger->save_new($array); + $jrn_def_id=$g_connection->get_value("select jrn_def_id from jrn_def where jrn_def_name=$1", + [$array['p_jrn_name']]); $this->assertLessThan($jrn_def_id,0); $ledger=new Acc_Ledger($g_connection,$jrn_def_id); $ledger->delete_ledger(); - $jrn_def_id=$g_connection->get_value("select jrn_def_id from jrn_def where jrn_def_name=$1",[$array['p_jrn_name']]); + $jrn_def_id=$g_connection->get_value("select jrn_def_id from jrn_def where jrn_def_name=$1", + [$array['p_jrn_name']]); $this->assertEquals($jrn_def_id,""); } @@ -838,7 +840,8 @@ class Acc_LedgerTest extends TestCase $g_connection->exec_sql("delete from jrn_def where jrn_def_name=$1",[$array['p_jrn_name']]); // Recreate it - $this->object->save_new($array); + $ledger=new Acc_Ledger($g_connection,-1); + $ledger->save_new($array); $jrn_def_id=$g_connection->get_value("select jrn_def_id from jrn_def where jrn_def_name=$1",[$array['p_jrn_name']]); $this->assertLessThan($jrn_def_id,0); $ledger=new Acc_Ledger($g_connection,$jrn_def_id); diff --git a/unit-test/include/class/acc_ledger_sold.Test.php b/unit-test/include/class/acc_ledger_sold.Test.php index b5745bb00..c700a8829 100644 --- a/unit-test/include/class/acc_ledger_sold.Test.php +++ b/unit-test/include/class/acc_ledger_sold.Test.php @@ -142,8 +142,11 @@ class Acc_Ledger_SoldTest extends TestCase */ public function testInput() { + global $g_connection; $_REQUEST['ac']='VEN'; - $info=$this->object->input($this->array); + $object=new Acc_Ledger_Sold($g_connection, 2); + + $info=$object->input($this->array); if (!is_string($info)) { $this->assertTrue(FALSE); diff --git a/unit-test/include/class/acc_operation.Test.php b/unit-test/include/class/acc_operation.Test.php index c2935c5de..641ecc880 100644 --- a/unit-test/include/class/acc_operation.Test.php +++ b/unit-test/include/class/acc_operation.Test.php @@ -32,17 +32,8 @@ class Acc_OperationTest extends TestCase { } - /** - * @covers Acc_OperationTest::get - * @todo Implement testGet(). - */ - public function testGet() - { - $this->assertEquals(0,0); - } /** *@covers Acc_Operation::seek_group - * @todo Implement seek_group() */ public function testSeek_group() { @@ -52,7 +43,6 @@ class Acc_OperationTest extends TestCase } /** * @covers Acc_Operation::set_id - * @todo Implement testId() * */ public function testSet_id() @@ -67,7 +57,6 @@ class Acc_OperationTest extends TestCase } /** * @covers Acc_Operation::set_paid - * @todo Implement testSet_paid */ function testSet_Paid() { @@ -85,7 +74,6 @@ class Acc_OperationTest extends TestCase } /** * @covers Acc_Operation::get_amount - * @todo Implement testGet_amount */ function testGet_Amount() { diff --git a/unit-test/include/class/anc_grandlivre.Test.php b/unit-test/include/class/anc_grandlivre.Test.php index f43d22673..9a80e9604 100644 --- a/unit-test/include/class/anc_grandlivre.Test.php +++ b/unit-test/include/class/anc_grandlivre.Test.php @@ -19,7 +19,6 @@ class Anc_GrandLivreTest extends TestCase protected function setUp() { global $g_connection; - $this->object=new Anc_GrandLivre($g_connection); } /** diff --git a/unit-test/test-file.sh b/unit-test/test-file.sh index 2381d4089..ef2be52bc 100755 --- a/unit-test/test-file.sh +++ b/unit-test/test-file.sh @@ -42,7 +42,7 @@ if [ ! -z "$FUNCTION" ] ; then else # $PHPUNIT --bootstrap bootstrap.php --whitelist $FILETOTEST --coverage-text=${FILETOTEST%.php}.txt --color $FILETOTEST - $PHPUNIT --bootstrap $CUR_DIR/bootstrap.php --whitelist=$CUR_DIR/../include/class --coverage-html=coverage --color $FILETOTEST - #$PHPUNIT --bootstrap bootstrap.php $FILETOTEST --testdox-html ${FILETOTEST%.php}-testdox.html --color $FILETOTEST + # $PHPUNIT --bootstrap $CUR_DIR/bootstrap.php --whitelist=$CUR_DIR/../include/class --coverage-html=coverage --color $FILETOTEST + $PHPUNIT --bootstrap bootstrap.php $FILETOTEST --testdox-html ${FILETOTEST%.php}-testdox.html --color $FILETOTEST fi From 224e43199f1d8294dc77b79d0fc4f532fd9b4da2 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 24 Nov 2019 15:19:51 +0100 Subject: [PATCH 13/23] cosmetid add a button close for the "forget-email-box" --- html/index.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/html/index.php b/html/index.php index cb1bb3f48..8d860843d 100644 --- a/html/index.php +++ b/html/index.php @@ -205,7 +205,6 @@ echo ' '; - if ( $g_captcha == true ) { echo '
Date 0.0
'; @@ -255,8 +254,7 @@ echo ' Email

- - + From a099feae1795e4b29dcdc2d4fb5ac6f038267792 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Wed, 20 Nov 2019 20:37:02 +0100 Subject: [PATCH 14/23] Bug PHP : confuse NULL and 0 --- include/lib/inum.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/lib/inum.class.php b/include/lib/inum.class.php index f2755c499..6cc9f4e1c 100644 --- a/include/lib/inum.class.php +++ b/include/lib/inum.class.php @@ -82,7 +82,7 @@ class INum extends IText $this->javascript='onchange="format_number(this,'.$this->prec.');"'; } $this->name=($p_name==null)?$this->name:$p_name; - $this->value=($p_value==null)?$this->value:$p_value; + $this->value=($p_value===null)?$this->value:$p_value; $this->id=($this->id=="")?$this->name:$this->id; if ($this->readOnly==true) From f9012b0a2470b6ab4d4f49d4f36d9b63cd225069 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Wed, 20 Nov 2019 20:45:33 +0100 Subject: [PATCH 15/23] Bug Array to string conversion error --- include/class/acc_ledger_sold.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/class/acc_ledger_sold.class.php b/include/class/acc_ledger_sold.class.php index e5b21eaab..5867d8d91 100644 --- a/include/class/acc_ledger_sold.class.php +++ b/include/class/acc_ledger_sold.class.php @@ -609,7 +609,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { 'Erreur dans l\'enregistrement ' . __FILE__ . ':' . __LINE__ . ' ' . $e->getMessage(); - echo $e->getTrace(); + echo $e->getTraceAsString(); $this->db->rollback(); throw new Exception ($e); From 9d1f3f0821f7feb0d022bdb7595d39474bd2af31 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Wed, 20 Nov 2019 20:56:28 +0100 Subject: [PATCH 16/23] Bug : when e_march is null it is considered as an empty string instead of 0 --- include/class/acc_ledger_purchase.class.php | 4 ++++ include/class/acc_ledger_sold.class.php | 3 +++ 2 files changed, 7 insertions(+) diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index dcbaf3a3d..7306185e8 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -669,6 +669,10 @@ class Acc_Ledger_Purchase extends Acc_Ledger } // insert into quant_purchase //----- + if (empty( ${'e_march' . $i . '_price'} ) ) ${'e_march' . $i . '_price'} = 0; + if (empty( ${'e_march' . $i } ) ) ${'e_march' . $i } = 0; + if (empty( ${'e_quant' . $i } ) ) ${'e_quant' . $i } = 0; + if ( $g_parameter->MY_TVA_USE=='Y') { diff --git a/include/class/acc_ledger_sold.class.php b/include/class/acc_ledger_sold.class.php index 5867d8d91..524fa4cf8 100644 --- a/include/class/acc_ledger_sold.class.php +++ b/include/class/acc_ledger_sold.class.php @@ -374,6 +374,9 @@ class Acc_Ledger_Sold extends Acc_Ledger { $op->oa_description = sql_string($e_comm); $op->save_form_plan($_POST, $i, $j_id); } + if (empty( ${'e_march' . $i . '_price'} ) ) ${'e_march' . $i . '_price'} = 0; + if (empty( ${'e_march' . $i } ) ) ${'e_march' . $i } = 0; + if (empty( ${'e_quant' . $i } ) ) ${'e_quant' . $i } = 0; if ($g_parameter->MY_TVA_USE == 'Y') { /* save into quant_sold */ $r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)", array(null, /* 1 */ From 3a92b56b579129dec631883aaf5f62df0e818f7e Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 24 Nov 2019 20:40:07 +0100 Subject: [PATCH 17/23] Cosmetic --- html/index.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/html/index.css b/html/index.css index ecb028694..cd359a6e7 100644 --- a/html/index.css +++ b/html/index.css @@ -183,7 +183,7 @@ BODY { left:0px; top:20px; - height: 15%; + /*! height: 15%; */ } #login_frm { position:absolute; @@ -203,7 +203,7 @@ BODY { width: 20rem; } } -@media only screen and (min-width : 1100px) { +@media only screen and (max-width : 1100px) { #alternate_browser { position:absolute; bottom: 30px; @@ -229,7 +229,7 @@ BODY { } #recover_link { position:absolute; - top:397px; + /*! top:397px; */ left:539px; background-color: white; width:auto; @@ -274,11 +274,11 @@ BODY { width: 24rem; } #recover_link { - position:absolute; - top:55%; + position:fixed; left:55%; background-color: white; margin-top:0px; + bottom: 10px; } #recover_box { From 5eb7c71b0d15d9ccb0713c3bb30d7adff6c7d659 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 24 Nov 2019 20:40:26 +0100 Subject: [PATCH 18/23] Remove useless Risky --- unit-test/include/class/dossier.Test.php | 193 --------- unit-test/include/class/fiche.Test.php | 482 +-------------------- unit-test/include/class/user.Test.php | 523 ----------------------- 3 files changed, 1 insertion(+), 1197 deletions(-) diff --git a/unit-test/include/class/dossier.Test.php b/unit-test/include/class/dossier.Test.php index 21650b14c..afba77c93 100644 --- a/unit-test/include/class/dossier.Test.php +++ b/unit-test/include/class/dossier.Test.php @@ -29,201 +29,8 @@ class DossierTest extends TestCase } - /** - * @covers Dossier::id - * @todo Implement testId(). - */ - public function testId() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::show_dossier - * @todo Implement testShow_dossier(). - */ - public function testShow_dossier() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::count - * @todo Implement testCount(). - */ - public function testCount() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::get_user_folder - * @todo Implement testGet_user_folder(). - */ - public function testGet_user_folder() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::check - * @todo Implement testCheck(). - */ - public function testCheck() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::get - * @todo Implement testGet(). - */ - public function testGet() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::hidden - * @todo Implement testHidden(). - */ - public function testHidden() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::name - * @todo Implement testName(). - */ - public function testName() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::get_parameter - * @todo Implement testGet_parameter(). - */ - public function testGet_parameter() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::set_parameter - * @todo Implement testSet_parameter(). - */ - public function testSet_parameter() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::get_info - * @todo Implement testGet_info(). - */ - public function testGet_info() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::save - * @todo Implement testSave(). - */ - public function testSave() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::update - * @todo Implement testUpdate(). - */ - public function testUpdate() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::load - * @todo Implement testLoad(). - */ - public function testLoad() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::get_version - * @todo Implement testGet_version(). - */ - public function testGet_version() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Dossier::connect - * @todo Implement testConnect(). - */ - public function testConnect() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - /** * @covers Dossier::synchro_admin - * @todo Implement testSynchro_admin(). */ public function testSynchro_admin() { diff --git a/unit-test/include/class/fiche.Test.php b/unit-test/include/class/fiche.Test.php index 06528abd5..e3fe39cd5 100644 --- a/unit-test/include/class/fiche.Test.php +++ b/unit-test/include/class/fiche.Test.php @@ -55,493 +55,13 @@ class FicheTest extends TestCase } - /** - * @covers Fiche::get_by_qcode - * @todo Implement testGet_by_qcode(). - */ - public function testGet_by_qcode() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::setAttribut - * @todo Implement testSetAttribut(). - */ - public function testSetAttribut() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::getAttribut - * @todo Implement testGetAttribut(). - */ - public function testGetAttribut() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::seek - * @todo Implement testSeek(). - */ - public function testSeek() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::size - * @todo Implement testSize(). - */ - public function testSize() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::count_by_modele - * @todo Implement testCount_by_modele(). - */ - public function testCount_by_modele() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::GetByDef - * @todo Implement testGetByDef(). - */ - public function testGetByDef() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::ShowTable - * @todo Implement testShowTable(). - */ - public function testShowTable() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::strAttribut - * @todo Implement testStrAttribut(). - */ - public function testStrAttribut() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::to_array - * @todo Implement testTo_array(). - */ - public function testTo_array() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::blank - * @todo Implement testBlank(). - */ - public function testBlank() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::Display - * @todo Implement testDisplay(). - */ - public function testDisplay() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::Save - * @todo Implement testSave(). - */ - public function testSave() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::insert - * @todo Implement testInsert(). - */ - public function testInsert() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::update - * @todo Implement testUpdate(). - */ - public function testUpdate() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::remove - * @todo Implement testRemove(). - */ - public function testRemove() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::getName - * @todo Implement testGetName(). - */ - public function testGetName() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_quick_code - * @todo Implement testGet_quick_code(). - */ - public function testGet_quick_code() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::Get - * @todo Implement testGet(). - */ - public function testGet() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_by_category - * @todo Implement testGet_by_category(). - */ - public function testGet_by_category() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_fiche_def_ref_id - * @todo Implement testGet_fiche_def_ref_id(). - */ - public function testGet_fiche_def_ref_id() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_row_date - * @todo Implement testGet_row_date(). - */ - public function testGet_row_date() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - /** * @covers Fiche::get_row - * @todo Implement testGet_row(). */ public function testGet_row() { - $this->object->get_row(235,238); + $this->assertTrue(is_array($this->object->get_row(235,238))); } - /** - * @covers Fiche::HtmlTableDetail - * @todo Implement testHtmlTableDetail(). - */ - public function testHtmlTableDetail() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::HtmlTable - * @todo Implement testHtmlTable(). - */ - public function testHtmlTable() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::HtmlTableHeader - * @todo Implement testHtmlTableHeader(). - */ - public function testHtmlTableHeader() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_solde_detail - * @todo Implement testGet_solde_detail(). - */ - public function testGet_solde_detail() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_bk_balance - * @todo Implement testGet_bk_balance(). - */ - public function testGet_bk_balance() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::empty_attribute - * @todo Implement testEmpty_attribute(). - */ - public function testEmpty_attribute() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::Summary - * @todo Implement testSummary(). - */ - public function testSummary() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_categorie - * @todo Implement testGet_categorie(). - */ - public function testGet_categorie() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::belong_ledger - * @todo Implement testBelong_ledger(). - */ - public function testBelong_ledger() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_fiche_def - * @todo Implement testGet_fiche_def(). - */ - public function testGet_fiche_def() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::is_used - * @todo Implement testIs_used(). - */ - public function testIs_used() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::delete - * @todo Implement testDelete(). - */ - public function testDelete() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::build_sql - * @todo Implement testBuild_sql(). - */ - public function testBuild_sql() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::move_to - * @todo Implement testMove_to(). - */ - public function testMove_to() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_amount_side - * @todo Implement testGet_amount_side(). - */ - public function testGet_amount_side() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::test_me - * @todo Implement testTest_me(). - */ - public function testTest_me() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_gestion_title - * @todo Implement testGet_gestion_title(). - */ - public function testGet_gestion_title() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Fiche::get_all_account - * @todo Implement testGet_all_account(). - */ - public function testGet_all_account() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } } diff --git a/unit-test/include/class/user.Test.php b/unit-test/include/class/user.Test.php index 727994c0a..f8e12723d 100644 --- a/unit-test/include/class/user.Test.php +++ b/unit-test/include/class/user.Test.php @@ -71,529 +71,6 @@ class UserTest extends TestCase $this->assertEquals($this->object->email, USE_EMAIL); } - /** - * @covers User::save - */ - public function testSave() - { - } - - /** - * @covers User::insert - * @todo Implement testInsert(). - */ - public function testInsert() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::Check - * @todo Implement testCheck(). - */ - public function testCheck() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_folder_access - * @todo Implement testGet_folder_access(). - */ - public function testGet_folder_access() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::set_folder_access - * @todo Implement testSet_folder_access(). - */ - public function testSet_folder_access() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_ledger_access - * @todo Implement testGet_ledger_access(). - */ - public function testGet_ledger_access() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_ledger - * @todo Implement testGet_ledger(). - */ - public function testGet_ledger() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_ledger_sql - * @todo Implement testGet_ledger_sql(). - */ - public function testGet_ledger_sql() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::Admin - * @todo Implement testAdmin(). - */ - public function testAdmin() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::set_periode - * @todo Implement testSet_periode(). - */ - public function testSet_periode() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_periode - * @todo Implement testGet_periode(). - */ - public function testGet_periode() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_mini_report - * @todo Implement testGet_mini_report(). - */ - public function testGet_mini_report() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::set_mini_report - * @todo Implement testSet_mini_report(). - */ - public function testSet_mini_report() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::save_global_preference - * @todo Implement testSave_global_preference(). - */ - public function testSave_global_preference() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_preference - * @todo Implement testGet_preference(). - */ - public function testGet_preference() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::check_module - * @todo Implement testCheck_module(). - */ - public function testCheck_module() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::check_action - * @todo Implement testCheck_action(). - */ - public function testCheck_action() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::load_global_pref - * @todo Implement testLoad_global_pref(). - */ - public function testLoad_global_pref() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::insert_default_global_pref - * @todo Implement testInsert_default_global_pref(). - */ - public function testInsert_default_global_pref() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::update_global_pref - * @todo Implement testUpdate_global_pref(). - */ - public function testUpdate_global_pref() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_exercice - * @todo Implement testGet_exercice(). - */ - public function testGet_exercice() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::can_request - * @todo Implement testCan_request(). - */ - public function testCan_request() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::check_print - * @todo Implement testCheck_print(). - */ - public function testCheck_print() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::can_print - * @todo Implement testCan_print(). - */ - public function testCan_print() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::is_local_admin - * @todo Implement testIs_local_admin(). - */ - public function testIs_local_admin() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_available_repository - * @todo Implement testGet_available_repository(). - */ - public function testGet_available_repository() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_list - * @todo Implement testGet_list(). - */ - public function testGet_list() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::check_jrn - * @todo Implement testCheck_jrn(). - */ - public function testCheck_jrn() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::check_dossier - * @todo Implement testCheck_dossier(). - */ - public function testCheck_dossier() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_limit_current_exercice - * @todo Implement testGet_limit_current_exercice(). - */ - public function testGet_limit_current_exercice() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::show_dossier - * @todo Implement testShow_dossier(). - */ - public function testShow_dossier() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_available_folder - * @todo Implement testGet_available_folder(). - */ - public function testGet_available_folder() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::audit - * @todo Implement testAudit(). - */ - public function testAudit() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::save_profile - * @todo Implement testSave_profile(). - */ - public function testSave_profile() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_profile - * @todo Implement testGet_profile(). - */ - public function testGet_profile() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_writable_profile - * @todo Implement testGet_writable_profile(). - */ - public function testGet_writable_profile() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::get_readable_profile - * @todo Implement testGet_readable_profile(). - */ - public function testGet_readable_profile() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::can_add_action - * @todo Implement testCan_add_action(). - */ - public function testCan_add_action() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::can_write_action - * @todo Implement testCan_write_action(). - */ - public function testCan_write_action() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::can_read_action - * @todo Implement testCan_read_action(). - */ - public function testCan_read_action() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::can_write_repo - * @todo Implement testCan_write_repo(). - */ - public function testCan_write_repo() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::can_read_repo - * @todo Implement testCan_read_repo(). - */ - public function testCan_read_repo() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::save_password - * @todo Implement testSave_password(). - */ - public function testSave_password() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers User::save_email - * @todo Implement testSave_email(). - */ - public function testSave_email() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - /** * @covers User::revoke_access * @todo Implement testRevoke_access(). From b227bac71a8339b35b24717586692ef57fa0024c Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 24 Nov 2019 20:41:10 +0100 Subject: [PATCH 19/23] Data_SQL Function prefix turn an object to an array but key can have a prefix --- include/lib/noalyss_sql.class.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/lib/noalyss_sql.class.php b/include/lib/noalyss_sql.class.php index 1eb466d3b..25edb2f57 100644 --- a/include/lib/noalyss_sql.class.php +++ b/include/lib/noalyss_sql.class.php @@ -312,16 +312,17 @@ abstract class Noalyss_SQL extends Data_SQL return $this; } /** - * Turn an object (row) into an array + * Turn an object (row) into an array, and the key could be prefixed with $prefix + * @param string $prefix before the key * @return array */ - public function to_array() + public function to_array($prefix="") { $array=array(); foreach ($this->name as $key=> $value) { - - $array[$key]=$this->$key; + $nkey=$prefix.$key; + $array[$nkey]=$this->$key; } return $array; } From 34ca0169918e62dba2adde5094f5f3a8d6e77afd Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 24 Nov 2019 20:50:06 +0100 Subject: [PATCH 20/23] PHPUNIT Suppress risky test --- .../include/class/anc_grandlivre.Test.php | 80 -------- unit-test/include/class/anc_key.Test.php | 107 ---------- .../include/class/anc_operation.Test.php | 193 +----------------- 3 files changed, 1 insertion(+), 379 deletions(-) diff --git a/unit-test/include/class/anc_grandlivre.Test.php b/unit-test/include/class/anc_grandlivre.Test.php index 9a80e9604..404f5ec3a 100644 --- a/unit-test/include/class/anc_grandlivre.Test.php +++ b/unit-test/include/class/anc_grandlivre.Test.php @@ -30,84 +30,4 @@ class Anc_GrandLivreTest extends TestCase } - /** - * @covers Anc_GrandLivre::set_sql_filter - */ - public function testSet_sql_filter() - { - - } - - /** - * @covers Anc_GrandLivre::load - * @todo Implement testLoad(). - */ - public function testLoad() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_GrandLivre::load_csv - * @todo Implement testLoad_csv(). - */ - public function testLoad_csv() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_GrandLivre::button_export_pdf - * @todo Implement testButton_export_pdf(). - */ - public function testButton_export_pdf() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_GrandLivre::display_html - * @todo Implement testDisplay_html(). - */ - public function testDisplay_html() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_GrandLivre::show_button - * @todo Implement testShow_button(). - */ - public function testShow_button() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_GrandLivre::display_csv - * @todo Implement testDisplay_csv(). - */ - public function testDisplay_csv() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - } diff --git a/unit-test/include/class/anc_key.Test.php b/unit-test/include/class/anc_key.Test.php index 9fdffffb3..d94d4ebb2 100644 --- a/unit-test/include/class/anc_key.Test.php +++ b/unit-test/include/class/anc_key.Test.php @@ -30,112 +30,5 @@ class Anc_KeyTest extends TestCase } - /** - * @covers Anc_Key::key_avaiable - * @todo Implement testKey_avaiable(). - */ - public function testKey_avaiable() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Key::display_choice - * @todo Implement testDisplay_choice(). - */ - public function testDisplay_choice() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Key::display_list - * @todo Implement testDisplay_list(). - */ - public function testDisplay_list() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Key::input - * @todo Implement testInput(). - */ - public function testInput() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Key::verify - * @todo Implement testVerify(). - */ - public function testVerify() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Key::save - * @todo Implement testSave(). - */ - public function testSave() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Key::fill_table - * @todo Implement testFill_table(). - */ - public function testFill_table() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Key::key_add - * @todo Implement testKey_add(). - */ - public function testKey_add() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Key::delete - * @todo Implement testDelete(). - */ - public function testDelete() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } } diff --git a/unit-test/include/class/anc_operation.Test.php b/unit-test/include/class/anc_operation.Test.php index 5570d81de..b29da820b 100644 --- a/unit-test/include/class/anc_operation.Test.php +++ b/unit-test/include/class/anc_operation.Test.php @@ -18,7 +18,7 @@ class Anc_OperationTest extends TestCase */ protected function setUp() { - $this->object=new Anc_Operation; + // $this->object=new Anc_Operation; } /** @@ -30,196 +30,5 @@ class Anc_OperationTest extends TestCase } - /** - * @covers Anc_Operation::add - * @todo Implement testAdd(). - */ - public function testAdd() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::delete - * @todo Implement testDelete(). - */ - public function testDelete() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::get_list - * @todo Implement testGet_list(). - */ - public function testGet_list() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::html_table - * @todo Implement testHtml_table(). - */ - public function testHtml_table() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::get_by_jid - * @todo Implement testGet_by_jid(). - */ - public function testGet_by_jid() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::update_from_jrnx - * @todo Implement testUpdate_from_jrnx(). - */ - public function testUpdate_from_jrnx() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::get_jrid - * @todo Implement testGet_jrid(). - */ - public function testGet_jrid() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::get_balance - * @todo Implement testGet_balance(). - */ - public function testGet_balance() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::display_form_plan - * @todo Implement testDisplay_form_plan(). - */ - public function testDisplay_form_plan() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::save_form_plan_vat_nd - * @todo Implement testSave_form_plan_vat_nd(). - */ - public function testSave_form_plan_vat_nd() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::save_form_plan - * @todo Implement testSave_form_plan(). - */ - public function testSave_form_plan() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::save_update_form - * @todo Implement testSave_update_form(). - */ - public function testSave_update_form() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::to_request - * @todo Implement testTo_request(). - */ - public function testTo_request() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::delete_by_jid - * @todo Implement testDelete_by_jid(). - */ - public function testDelete_by_jid() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::display_table - * @todo Implement testDisplay_table(). - */ - public function testDisplay_table() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Anc_Operation::test_me - * @todo Implement testTest_me(). - */ - public function testTest_me() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } } From c3e7bc0c3194f9a59bcfbb3d0e914639a57a2a3a Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 24 Nov 2019 20:52:15 +0100 Subject: [PATCH 21/23] Fix problem with Acc_Ledger_purchase or sold and quantity or vat amount were an empty string --- include/class/acc_ledger_purchase.class.php | 2 +- include/class/acc_ledger_sold.class.php | 3 +- .../class/acc_ledger_purchase.Test.php | 76 ++++++++++++++++++- .../include/class/acc_ledger_sold.Test.php | 49 ++++++++++++ 4 files changed, 126 insertions(+), 4 deletions(-) diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index 7306185e8..a37cea8da 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -544,7 +544,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger for ($i=0;$i< $nb_item;$i++) { $n_both=0; - if ( strlen(trim(${'e_march'.$i})) == 0 ) continue; + if ( empty(${'e_march'.$i}) || empty(${'e_quant'.$i}) ) continue; /* First we save all the items without vat */ $fiche=new Fiche($this->db); diff --git a/include/class/acc_ledger_sold.class.php b/include/class/acc_ledger_sold.class.php index 524fa4cf8..e2dc5fd64 100644 --- a/include/class/acc_ledger_sold.class.php +++ b/include/class/acc_ledger_sold.class.php @@ -285,8 +285,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { /* Save all the items without vat */ for ($i = 0; $i < $nb_item; $i++) { $n_both = 0; - if (strlen(trim(${'e_march' . $i})) == 0) - continue; + if ( empty(${'e_march'.$i}) || empty(${'e_quant'.$i}) ) continue; /* First we save all the items without vat */ $fiche = new Fiche($this->db); diff --git a/unit-test/include/class/acc_ledger_purchase.Test.php b/unit-test/include/class/acc_ledger_purchase.Test.php index 966f613e4..b75073346 100644 --- a/unit-test/include/class/acc_ledger_purchase.Test.php +++ b/unit-test/include/class/acc_ledger_purchase.Test.php @@ -123,7 +123,81 @@ class Acc_Ledger_PurchaseTest extends TestCase $this->assertEquals(1, $g_connection->get_value ("select count(*) from jrn where jr_mt=$1",["1572704002.1732"])); $this->clean_operation(); - + + // If some data are corruptes + $sql=" + from quant_purchase + join jrnx using(j_id) + join jrn on (jr_grpt_id=j_grpt) + where + jr_mt='1572704002.1732' + and j_qcode='DOCUME' + "; + // Test space in e_quant0 instead of zero + $array=$this->array; + $array["mt"]="1572704002.1732"; + $array["nb_item"]=2; + $array["pa_id"]=array(2); + $array["op"]=array(0); + $array["amount_t0"]=658.25; + $array['hplan']=array(array(-1)); + $array["val"]=array(array(658.25)); + $array=array_merge($array, array("e_march1"=>"DOCUME", + "e_march1_price"=>18.25, + "e_quant1"=>"", + "htva_march1"=>18.25, + "e_march1_tva_id"=>1, + "e_march1_tva_amount"=>22.08, + "tva_march1"=>3.83, + "tvac_march1"=>22.05)); + + $this->object->insert($array); + $this->assertEquals(0,$g_connection->get_value("select count(*) ".$sql)); + $this->clean_operation(); + + // Test space in e_march0_price instead of zero must be + $array=$this->array; + $array["mt"]="1572704002.1732"; + $array["nb_item"]=2; + $array["pa_id"]=array(2); + $array["op"]=array(0); + $array["amount_t0"]=658.25; + $array['hplan']=array(array(-1)); + $array["val"]=array(array(658.25)); + $array=array_merge($array, array("e_march1"=>"DOCUME", + "e_march1_price"=>18.25, + "e_quant1"=>1, + "htva_march1"=>18.25, + "e_march1_tva_id"=>1, + "e_march1_tva_amount"=>"", + "tva_march1"=>3.83, + "tvac_march1"=>22.05)); + $this->object->insert($array); + $this->assertEquals(3.83,$g_connection->get_value("select qp_vat ".$sql)); + $this->clean_operation(); + + // Test space in e_march0_tva_amount instead of zero must be calculated + $array=$this->array; + $array["mt"]="1572704002.1732"; + $array["nb_item"]=2; + $array["pa_id"]=array(2); + $array["op"]=array(0); + $array["amount_t0"]=658.25; + $array['hplan']=array(array(-1)); + $array["val"]=array(array(658.25)); + $array=array_merge($array, array("e_march1"=>"DOCUME", + "e_march1_price"=>18.25, + "e_quant1"=>1, + "htva_march1"=>18.25, + "e_march1_tva_id"=>1, + "e_march1_tva_amount"=>22.08, + "tva_march1"=>"", + "tvac_march1"=>22.05)); + + $this->object->insert($array); + $this->assertEquals(22.08,$g_connection->get_value("select qp_vat ".$sql)); + $this->clean_operation(); + } /** diff --git a/unit-test/include/class/acc_ledger_sold.Test.php b/unit-test/include/class/acc_ledger_sold.Test.php index c700a8829..3ec3e876e 100644 --- a/unit-test/include/class/acc_ledger_sold.Test.php +++ b/unit-test/include/class/acc_ledger_sold.Test.php @@ -115,6 +115,55 @@ class Acc_Ledger_SoldTest extends TestCase $cnt=$g_connection->get_value("select count(*) from jrn where jr_mt=$1",["1572714478.3155"]); $this->assertEquals(1,$cnt); $this->clean_operation(); + + // If some data are corruptes + $sql=" + from quant_sold + join jrnx using(j_id) + join jrn on (jr_grpt_id=j_grpt) + where + jr_mt='1572714478.3155' + and j_qcode='MARCHA' + "; + // Test space in e_quant1 instead of zero + $array=$this->array; + $array["pa_id"]=array(2); + $array["op"]=array(0, 1); + $array["amount_t0"]=24.2; + $array["hplan"]=array(array(-1), array(-1)); + $array["val"]=array(array(24, 2), array(1212.5)); + $array["mt"]="1572714478.3155"; + $array['e_quant1']=""; + $this->object->insert($array); + $this->assertEquals(0,$g_connection->get_value("select count(*) ".$sql)); + $this->clean_operation(); + + // Test space in e_march1_price instead of zero must be + $array=$this->array; + $array["pa_id"]=array(2); + $array["op"]=array(0, 1); + $array["amount_t0"]=24.2; + $array["hplan"]=array(array(-1), array(-1)); + $array["val"]=array(array(24, 2), array(1212.5)); + $array["mt"]="1572714478.3155"; + $array['e_march1_tva_amount']=""; + $this->object->insert($array); + $this->assertEquals(254.6250,$g_connection->get_value("select qs_vat ".$sql)); + $this->clean_operation(); + + // Test space in e_march1_tva_amount instead of zero must be calculated + $array=$this->array; + $array["pa_id"]=array(2); + $array["op"]=array(0, 1); + $array["amount_t0"]=24.2; + $array["hplan"]=array(array(-1), array(-1)); + $array["val"]=array(array(24, 2), array(1212.5)); + $array["mt"]="1572714478.3155"; + $array['tva_march1']=""; + $this->object->insert($array); + $this->assertEquals(254.63,$g_connection->get_value("select qs_vat ".$sql)); + $this->clean_operation(); + } /** From 9e5b19d6d3bdea8f76ad748a85220e0db89985e2 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 24 Nov 2019 20:53:23 +0100 Subject: [PATCH 22/23] Search operation : all, paid or unpaid, including the CSV export and the filter --- html/js/acc_ledger.js | 20 +++++------ include/ajax/ajax_search_filter.php | 2 +- include/class/acc_ledger_search.class.php | 40 +++++++++++++++++----- include/constant.php | 2 +- include/database/user_filter_sql.class.php | 4 +-- include/template/ledger_search.php | 2 +- 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js index 2c7315e1b..d6b288252 100644 --- a/html/js/acc_ledger.js +++ b/html/js/acc_ledger.js @@ -1298,7 +1298,9 @@ function manage_search_filter(p_obj) { * @see Acc_Ledger_Search */ function save_filter(p_div,p_dossier) { - var elt=['ledger_type','nb_jrn','date_start','date_end','date_paid_start','date_paid_end','desc','amount_min','amount_max','qcode','accounting']; + var elt=['ledger_type','nb_jrn','date_start','date_end', + 'date_paid_start','date_paid_end','desc','amount_min','amount_max','qcode','accounting', + 'operation_filter']; var eltValue={}; eltValue['gDossier']=p_dossier; eltValue['op']="save_filter"; @@ -1322,8 +1324,6 @@ function save_filter(p_div,p_dossier) { } } - //unpaid - eltValue['unpaid']=$(p_div+"unpaid").checked; new Ajax.Request('ajax_misc.php', { method:"POST", parameters:eltValue, @@ -1361,7 +1361,8 @@ function load_filter(p_div,p_dossier,p_filter_id) { try { var answer=req.responseJSON; console.log(answer); - var elt=['ledger_type','date_start','date_end','date_paid_start','date_paid_end','desc','amount_min','amount_max','qcode','accounting']; + var elt=['ledger_type','date_start','date_end','date_paid_start','date_paid_end', + 'desc','amount_min','amount_max','qcode','accounting','operation_filter']; for (var i=0;ipost("date_paid_start", 'string', NULL)); $new->setp("date_paid_end", $http->post("date_paid_end", 'string', NULL)); $new->setp("ledger_type", $http->post("ledger_type", 'string')); - $new->setp("unpaid", $http->post("unpaid", 'string', NULL)); + $new->setp("operation_filter", $http->post("operation_filter", 'string', NULL)); $new->setp("filter_name", h($http->post("filter_name", 'string'))); $aJrn=[]; $max=$http->post("nb_jrn"); diff --git a/include/class/acc_ledger_search.class.php b/include/class/acc_ledger_search.class.php index f9891a153..9ffc29292 100644 --- a/include/class/acc_ledger_search.class.php +++ b/include/class/acc_ledger_search.class.php @@ -204,15 +204,23 @@ class Acc_Ledger_Search $f_accounting->set_attribute('account', $this->div.'accounting'); $info=Icon_Action::infobulle(13); - $f_paid=new ICheckbox('unpaid', null, $this->div.'unpaid'); - $f_paid->selected=(isset($_REQUEST['unpaid']))?true:false; + // Status of the operation : paid, unpaid or all + $f_paid=new ISelect('operation_filter', null, $this->div.'operation_filter'); + $f_paid->value=array(["value"=>'all',"label"=>_("Toutes")], + ["value"=>'unpaid',"label"=>_("Non payées")], + ["value"=>'paid',"label"=>_("Payées")] + ); + $f_paid->selected=$http->request("operation_filter","string","all"); $r.=dossier::hidden(); $r.=HtmlInput::hidden('ledger_type', $this->type, $this->div."ledger_type"); - $r.=HtmlInput::hidden('ac', $_REQUEST['ac']); + $r.=HtmlInput::hidden('ac', $http->request('ac')); + + // to avoid to find a given operation if (isset($_REQUEST['hide_operation'])) - $r.=HtmlInput::hidden("hide_operation", $_REQUEST['hide_operation']); + $r.=HtmlInput::hidden("hide_operation", $http->request('hide_operation')); + ob_start(); $search_filter=$this->build_search_filter(); require_once NOALYSS_TEMPLATE.'/ledger_search.php'; @@ -526,12 +534,26 @@ class Acc_Ledger_Search $and=" and "; } - // Only the unpaid - if (isset($unpaid)) - { - $fil_paid=$and.SQL_LIST_UNPAID_INVOICE; - $and=" and "; + // Only the unpaid, paid or all + if ( isset($operation_filter)) { + switch ($operation_filter) { + case "unpaid": + $fil_paid=$and."(jr_rapt is null or jr_rapt = '') and jr_valid = true "; + $and=" and "; + break; + case "all": + $fil_paid=""; + break; + case "paid": + $fil_paid=$and."(jr_rapt is not null or jr_rapt = 'paid') and jr_valid = true "; + $and=" and "; + break; + default: + throw new Exception(_("ALS01 Etat inconnu"),10); + + } } + // Operations which must not be seen in the result if ( isset ($hide_operation) && trim($hide_operation) !="") { $fil_hide_operation=$and.sprintf( ' jr_id not in (%s)',sql_string($hide_operation)); diff --git a/include/constant.php b/include/constant.php index 5f5dc71a4..e0330010b 100644 --- a/include/constant.php +++ b/include/constant.php @@ -108,7 +108,7 @@ if ( !defined ("NOALYSS_PACKAGE_REPOSITORY")) { if ( ! defined ("SYSINFO_DISPLAY")) { define ("SYSINFO_DISPLAY",TRUE); } -define ("DBVERSION",140); +define ("DBVERSION",141); define ("MONO_DATABASE",25); define ("DBVERSIONREPO",18); define ('NOTFOUND','--not found--'); diff --git a/include/database/user_filter_sql.class.php b/include/database/user_filter_sql.class.php index 4f5e56959..72ebb83c9 100644 --- a/include/database/user_filter_sql.class.php +++ b/include/database/user_filter_sql.class.php @@ -54,7 +54,7 @@ class User_filter_SQL extends Noalyss_SQL , "date_paid_end"=>"date_paid_end" , "ledger_type"=>"ledger_type" , "all_ledger"=>"all_ledger" - ,"unpaid"=>"unpaid" + ,"operation_filter"=>"operation_filter" ,'filter_name'=>"filter_name" ); /* @@ -76,7 +76,7 @@ class User_filter_SQL extends Noalyss_SQL , "date_paid_end"=>"text" , "ledger_type"=>"text" , "all_ledger"=>"numeric" - ,"unpaid"=>"text" + ,"operation_filter"=>"text" ,"filter_name"=>"text" ); diff --git a/include/template/ledger_search.php b/include/template/ledger_search.php index 8d7b827d2..c22dd2086 100644 --- a/include/template/ledger_search.php +++ b/include/template/ledger_search.php @@ -80,7 +80,7 @@ echo $f_accounting->input(); ?>
- + From 9f54258d8f048a073de6ba30f609612bddec3290 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 24 Nov 2019 21:59:47 +0100 Subject: [PATCH 23/23] File to restore for testing --- unit-test/create-dossier-test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unit-test/create-dossier-test.sh b/unit-test/create-dossier-test.sh index f838f52ae..74eb39ac5 100755 --- a/unit-test/create-dossier-test.sh +++ b/unit-test/create-dossier-test.sh @@ -1,8 +1,9 @@ #!/bin/bash DOSSIER_TEST=rel70dossier25 +FILE_TEST=dossiertest191124-2109.bin dropdb $DOSSIER_TEST createdb $DOSSIER_TEST -pg_restore -Fc --no-owner --no-privilege --verbose -d $DOSSIER_TEST db/dossiertest191117-0909.bin +pg_restore -Fc --no-owner --no-privilege --verbose -d $DOSSIER_TEST db/$FILE_TEST