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 "
| Date | ',$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( - '
|---|