diff --git a/include/cfgledger.inc.php b/include/cfgledger.inc.php index 9da41a3a9..679827d06 100644 --- a/include/cfgledger.inc.php +++ b/include/cfgledger.inc.php @@ -54,7 +54,7 @@ if ( $action_frm == 'update') { try { - $ledger->id=$http->post('p_jrn',"number"); + $ledger->set_ledger_id($http->post('p_jrn',"number")); if ( $ledger->load() == -1) throw new Exception (_('Journal inexistant')); $ledger->verify_ledger($_POST); $ledger->update($_POST); @@ -72,7 +72,7 @@ if ( $action_frm == 'update') ////////////////////////////////////////////////////////////////////////// if ($action_frm == 'delete' ) { - $ledger->id=$http->post('p_jrn',"number"); + $ledger->set_ledger_id($http->post('p_jrn',"number")); $ledger->load(); $name=$ledger->get_name(); try { @@ -104,7 +104,7 @@ if (isset($_POST['add'])) $ledger->verify_ledger($_POST); $ledger->save_new($_POST); $sa="detail"; - $a[]=["key"=>'p_jrn',"value"=>$ledger->id]; + $a[]=["key"=>'p_jrn',"value"=>$ledger->get_ledger_id()]; put_global($a); $show_menu=1; } @@ -129,7 +129,7 @@ switch ($sa) case 'detail': /* detail of a ledger */ try { - $ledger->id=$http->request('p_jrn',"number"); + $ledger->set_ledger_id($http->request('p_jrn',"number")); echo '
'; echo '
'; echo $ledger->display_ledger(); diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index 7487b7ba6..a25125772 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -22,6 +22,7 @@ require_once NOALYSS_INCLUDE.'/lib/iselect.class.php'; require_once NOALYSS_INCLUDE.'/lib/icard.class.php'; require_once NOALYSS_INCLUDE.'/lib/ispan.class.php'; require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php'; +require_once NOALYSS_INCLUDE.'/lib/input_switch.class.php'; require_once NOALYSS_INCLUDE.'/lib/idate.class.php'; require_once NOALYSS_INCLUDE.'/lib/itext.class.php'; require_once NOALYSS_INCLUDE.'/lib/icheckbox.class.php'; @@ -75,11 +76,12 @@ class Acc_Ledger extends jrn_def_sql function __construct($p_cn, $p_id) { $this->id=$p_id; - $this->name=&$this->jrn_def_name; + $this->ledger_name=&$this->jrn_def_name; $this->jrn_def_id=&$this->id; $this->db=$p_cn; $this->row=null; $this->nb=MAX_ARTICLE; + parent::__construct($p_cn, $p_id); } function get_last_pj() @@ -104,7 +106,23 @@ class Acc_Ledger extends jrn_def_sql $this->db->create_sequence("s_jrn_pj".$this->id); return 0; } - + /** + * Set the jrn_def.jrn_def_id + * @param integer $p_id + */ + function set_ledger_id($p_id) + { + $this->id=$p_id; + $this->jrn_def_id=&$this->id; + } + /** + * Set the jrn_def.jrn_def_id + * @return integer + */ + function get_ledger_id() + { + return $this->id; + } /** * @brief Return the type of a ledger (ACH,VEN,ODS or FIN) or GL * @@ -113,7 +131,7 @@ class Acc_Ledger extends jrn_def_sql { if ($this->id==0) { - $this->name=_(" Tous les journaux"); + $this->ledger_name=_(" Tous les journaux"); $this->type="GL"; return "GL"; } @@ -370,8 +388,8 @@ class Acc_Ledger extends jrn_def_sql { if ($this->id==0) { - $this->name=_("Grand Livre"); - return $this->name; + $this->ledger_name=_("Grand Livre"); + return $this->ledger_name; } $Res=$this->db->exec_sql("select jrn_def_name from ". @@ -380,7 +398,7 @@ class Acc_Ledger extends jrn_def_sql if ($Max==0) return null; $ret=Database::fetch_array($Res, 0); - $this->name=$ret['jrn_def_name']; + $this->ledger_name=$ret['jrn_def_name']; return $ret['jrn_def_name']; } @@ -417,18 +435,15 @@ class Acc_Ledger extends jrn_def_sql if ($this->id==0) return; - $Res=$this->db->exec_sql("select jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type, - jrn_deb_max_line,jrn_cred_max_line,jrn_def_ech,jrn_def_ech_lib,jrn_def_code, - jrn_def_fiche_deb,jrn_def_fiche_cred,jrn_def_pj_pref + $Res=$this->db->get_row("select * from jrn_Def where jrn_def_id=$1", array($this->id)); - $Count=Database::num_row($Res); - if ($Count==0) + if ($Res == NULL) { echo '

'._('Parametres journaux non trouves').'

'; return null; } - return Database::fetch_array($Res, 0); + return $Res; } /** @@ -1015,7 +1030,7 @@ class Acc_Ledger extends jrn_def_sql * permitted card, 5 not in the user's period, 6 closed period * */ - function verify($p_array) + function verify_operation($p_array) { if (is_array($p_array)==false||empty($p_array)) throw new Exception("Array empty"); @@ -2285,6 +2300,12 @@ class Acc_Ledger extends jrn_def_sql ["label"=>_("Désactivé"),"value"=>0] ]; $actif->selected=$this->jrn_enable; + + $negative=new InputSwitch('negative_amount',$this->jrn_def_negative_amount); + + $negative_warning=new IText("negative_warning",_($this->jrn_def_negative_warning)); + $negative_warning->size=80; + require_once NOALYSS_TEMPLATE.'/param_jrn.php'; } @@ -2337,6 +2358,12 @@ class Acc_Ledger extends jrn_def_sql { throw new Exception(_('Choix du type de journal est obligatoire')); } + if ($negative_amount == 1 && trim($negative_warning)=="") { + throw new Exception(_("Avertissement ne peut être vide")); + } + if ( $negative_amount <> 0 && $negative_amount <> 1 ){ + throw new Exception(_("Valeur invalide")); + } } catch (Exception $e) { @@ -2365,6 +2392,9 @@ class Acc_Ledger extends jrn_def_sql $this->jrn_deb_max_line=($min_row<1)?1:$min_row; $this->jrn_def_description=$p_description; $this->jrn_enable=$jrn_enable; + $this->jrn_def_negative_amount=$negative_amount; + $this->jrn_def_negative_warning=$negative_warning; + switch ($this->jrn_def_type) { case 'ACH': @@ -2521,6 +2551,9 @@ class Acc_Ledger extends jrn_def_sql $cn=$this->db; $min_row=new INum("min_row", MAX_ARTICLE); $min_row->prec=0; + $negative=new InputSwitch('negative_amount',0); + $negative_warning=new IText('negative_warning',_("Attention, ce journal doit utiliser des montants négatifs")); + $negative_warning->size=80; require_once NOALYSS_TEMPLATE.'/param_jrn.php'; } @@ -2544,6 +2577,11 @@ class Acc_Ledger extends jrn_def_sql trim(substr($this->jrn_def_type, 0, 1)), Acc_Ledger::next_number($this->db, $this->jrn_def_type)); $this->jrn_def_description=$p_description; + $this->currency_id=0; + $this->jrn_def_negative_amount=$negative_amount; + $this->jrn_def_negative_warning=$negative_warning; + $this->jrn_enable=1; + switch ($this->jrn_def_type) { case 'ACH': @@ -2577,7 +2615,7 @@ class Acc_Ledger extends jrn_def_sql $this->jrn_def_num_op=(isset($numb_operation))?1:0; break; } - + parent::insert(); } @@ -2888,6 +2926,23 @@ class Acc_Ledger extends jrn_def_sql return FALSE; } + /** + * If the amount is positive and the ledger expects a negative amount, il will return the saved warning + * + * @param int $p_amount amount to check + * @throws Exception 1 if invalid ledger + */ + function display_negative_warning($p_amount) + { + if ($this->id == 0) { + throw new Exception(_("Journal invalide"), 1); + } + $ledger=new Jrn_def_SQL($this->db,$this->id); + if ( $p_amount > 0 && $ledger->getp("jrn_def_negative_amount")==1){ + return _($ledger->getp("jrn_def_negative_warning")); + } + return ""; + } } ?> diff --git a/include/class/acc_ledger_fin.class.php b/include/class/acc_ledger_fin.class.php index d361faa72..b9023ac70 100644 --- a/include/class/acc_ledger_fin.class.php +++ b/include/class/acc_ledger_fin.class.php @@ -53,7 +53,7 @@ class Acc_Ledger_Fin extends Acc_Ledger * @throw Exception on error occurs */ - public function verify($p_array) + public function verify_operation($p_array) { global $g_user; if (is_array($p_array ) == false || empty($p_array)) diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index 56cb2946d..f47974928 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -58,7 +58,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger *\return String *\throw Exception if an error occurs */ - public function verify($p_array) + public function verify_operation($p_array) { global $g_parameter,$g_user; @@ -1705,7 +1705,13 @@ EOF; $r.='
'; } // check for upload piece - + /* + * warning if the amount is positive and expecting a negative one + */ + $negative=$this->display_negative_warning($tot); + if ( $negative != "") { + $r.=span($negative,'class="warning" '); + } return $r; } diff --git a/include/class/acc_ledger_sold.class.php b/include/class/acc_ledger_sold.class.php index 053638385..ae4535a38 100644 --- a/include/class/acc_ledger_sold.class.php +++ b/include/class/acc_ledger_sold.class.php @@ -62,7 +62,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { * \throw Exception if an error occurs */ - public function verify($p_array) { + public function verify_operation($p_array) { global $g_parameter, $g_user; if (is_array($p_array ) == false || empty($p_array)) @@ -904,6 +904,8 @@ EOF; $r.='
Total '.hb($tot); } $r.=''; + + /* Add hidden */ $r.=HtmlInput::hidden('e_client', $e_client); $r.=HtmlInput::hidden('nb_item', $nb_item); @@ -958,6 +960,13 @@ EOF; } $r.=HtmlInput::hidden("e_quant" . $i, ${"e_quant" . $i}); } + /* + * warning if the amount is positive and expecting a negative one + */ + $negative=$this->display_negative_warning($tot); + if ( $negative != "") { + $r.=span($negative,'class="warning" '); + } return $r; } diff --git a/include/class/periode.class.php b/include/class/periode.class.php index 322dd120a..734cdba41 100644 --- a/include/class/periode.class.php +++ b/include/class/periode.class.php @@ -104,18 +104,20 @@ class Periode { /* if jrn_Def_id == 0 then we check the global otherwise we check a ledger */ - if ($this->jrn_def_id!=0) + if ($this->jrn_def_id!=0){ $sql="select status from jrn_periode ". - " where jrn_def_id=".$this->jrn_def_id. - " and p_id =".$this->p_id; - else + " where jrn_def_id=$1 ". + " and p_id = $2"; + $status=$this->cn->get_value($sql,[$this->jrn_def_id,$this->p_id]); + } + else { $sql="select p_closed as status from parm_periode ". " where ". - " p_id =".$this->p_id; - $res=$this->cn->exec_sql($sql); - $status=Database::fetch_result($res, 0, 0); - if ($status=='OP'||$status=='f') - return 1; + " p_id = $1 "; + $status=$this->cn->get_value($sql,[$this->p_id]); + } + + if ($status=='OP'||$status=='f') return 1; return 0; } diff --git a/include/class/tax_summary.class.php b/include/class/tax_summary.class.php new file mode 100644 index 000000000..8c482b238 --- /dev/null +++ b/include/class/tax_summary.class.php @@ -0,0 +1,355 @@ +db=$db; + $this->set_date_start($p_start); + $this->set_date_end($p_end); + + } + + /** + * @return Database + */ + public function get_db() + { + return $this->db; + return $this; + } + + /** + * @param Database $db + */ + public function set_db($db) + { + $this->db = $db; + return $this; + } + + /** + * @return mixed + */ + public function get_date_start() + { + return $this->date_start; + return $this; + } + + /** + * @param mixed $date_start + */ + public function set_date_start($date_start) + { + if (isDate($date_start) == NULL) throw Exception(_("Format date invalide") . $date_start); + $this->date_start = $date_start; + return $this; + } + + /** + * @return mixed + */ + public function get_date_end() + { + return $this->date_end; + return $this; + } + + /** + * @param mixed $date_end + */ + public function set_date_end($date_end) + { + if (isDate($date_end) == NULL) throw Exception(_("Format date invalide") . $date_end); + $this->date_end = $date_end; + return $this; + } + + /** + * @brief depends of quant_* table, so we must check first that everything + * is in these tables + */ + function check() + { + /*-------------SALE ---------------------------------*/ + $sql="select count(*) + from + jrnx + join quant_sold on (quant_sold.j_id = jrnx.j_id) + where + jrnx.j_jrn_def in (select jrn_def_id from jrn_def where jrn_def_type = 'VEN') + and j_date >= to_date($1,'DD.MM.YYYY') + 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(_("Aucune Donnée")); + } + /*-------------Purchase ---------------------------------*/ + $sql="select count(*) + from + jrnx + join quant_purchase as qp on (jrnx.j_id = qp.j_id) + where + jrnx.j_jrn_def in (select jrn_def_id from jrn_def where jrn_def_type = 'ACH') + and j_date >= to_date($1,'DD.MM.YYYY') + 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(_("Aucune Donnée")); + + } + } + + /** + * Total for each sales ledger + * @return array + */ + function get_row_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, + 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; + + } + + + /** + * Total for each purchase ledger + * @return array + */ + function get_row_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, + j_jrn_def + 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 j_jrn_def,qp_vat_code) + select jrn_def_name, + tva_label , + tva_rate, + tva_both_side, + qp_vat_code, + amount_vat, + amount_wovat, + amount_sided, + amount_noded_amount, + amount_noded_tax, + amount_noded_return, + amount_private + from + detail_tva + 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]); + return $array; + } + + /** + * Summary for all sales ledger + */ + 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, + tva_both_side, + amount_vat, + amount_wovat, + amount_sided + 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]); + 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) + select + tva_label , + tva_rate, + tva_both_side, + qp_vat_code, + amount_vat, + amount_wovat, + amount_sided, + amount_noded_amount, + amount_noded_tax, + amount_noded_return, + amount_private + from + 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]); + + return $array; + } + /** + * @brief display the summary of VAT in the range of date + */ + function display() + { + require_once NOALYSS_INCLUDE."/template/tax_summary_display.php"; + } + /** + * @brief display a form to export in CSV + * @see export_printtva_csv.php + */ + function form_export_csv() + { + 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::submit("CSV:printtva",_("Export CSV")); + echo ''; + } + + /** + * @brief display a form to export in PDF + * @see export_printtva_pdf.php + */ + function form_export_pdf() + { + 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 '
'; + } + + +} diff --git a/include/compta_ach.inc.php b/include/compta_ach.inc.php index 5ad7e6ea2..71f2af850 100644 --- a/include/compta_ach.inc.php +++ b/include/compta_ach.inc.php @@ -54,7 +54,7 @@ if (isset($_POST['view_invoice'])) $Ledger = new Acc_Ledger_Purchase($cn, $post_jrn); try { - $Ledger->verify($_POST); + $Ledger->verify_operation($_POST); } catch (Exception $e) { @@ -68,10 +68,8 @@ if (isset($_POST['view_invoice'])) echo '
'; echo '
'; echo h1(_("Confirmation")); - echo '
'; - - echo '
'; - echo h2(_("Attention, cette opération n'est pas encore sauvée : vous devez encore confirmer"),' class="notice"'); + echo h1(_("Confirmation")); + echo span(_("Vous devez encore confirmer"),' class="notice"'); echo '
'; echo '
'; @@ -136,7 +134,7 @@ if (isset($_POST['record'])) $Ledger = new Acc_Ledger_Purchase($cn, $post_jrn); try { - $Ledger->verify($_POST); + $Ledger->verify_operation($_POST); } catch (Exception $e) { @@ -252,7 +250,7 @@ echo '
'; echo '
'; -echo '

'.$p_msg.'

'; +echo ''.$p_msg.''; try { $payment=$http->request("e_mp", "string",0); diff --git a/include/compta_fin.inc.php b/include/compta_fin.inc.php index 080916d1a..397b30098 100644 --- a/include/compta_fin.inc.php +++ b/include/compta_fin.inc.php @@ -65,7 +65,7 @@ if ( isset($_POST['save'])) { try { - $Ledger->verify($_POST); + $Ledger->verify_operation($_POST); } catch (Exception $e) { @@ -97,7 +97,7 @@ if ( isset($_POST['confirm'])) { try { - $Ledger->verify($_POST); + $Ledger->verify_operation($_POST); } catch (Exception $e) { @@ -133,7 +133,7 @@ if ( isset($_POST['correct'])) //---------------------------------------- // Blank form //---------------------------------------- -echo '

'.$p_msg.'

'; +echo ''.$p_msg.''; echo '
'; echo HtmlInput::hidden('ledger_type','fin'); diff --git a/include/compta_ods.inc.php b/include/compta_ods.inc.php index cbdabcb98..c6360dade 100644 --- a/include/compta_ods.inc.php +++ b/include/compta_ods.inc.php @@ -72,17 +72,17 @@ if (!isset($_POST['summary']) && !isset($_POST['save'])) } elseif (isset($_POST['summary'])) { - try { - $ledger->verify($_POST); - require_once NOALYSS_INCLUDE.'/operation_ods_confirm.inc.php'; - } catch (Exception $e) - { - echo alert($e->getMessage()); - $p_msg=$e->getMessage(); - require_once NOALYSS_INCLUDE.'/operation_ods_new.inc.php'; + try { + $ledger->verify_operation($_POST); + require_once NOALYSS_INCLUDE.'/operation_ods_confirm.inc.php'; + } catch (Exception $e) + { + echo alert($e->getMessage()); + $p_msg=$e->getMessage(); + require_once NOALYSS_INCLUDE.'/operation_ods_new.inc.php'; - } - return; + } + return; } elseif (isset($_POST['save'])) { @@ -120,16 +120,16 @@ elseif (isset($_POST['save'])) } catch (Exception $e) { - echo '

'._('Opération non extournée'). + echo ''._('Opération non extournée'). $e->getMessage(). - '

'; + ''; } } else { // warning because date is invalid - echo '

'._('Date invalide, opération non extournée').'

'; + echo ''._('Date invalide, opération non extournée').''; } } echo '
    '; diff --git a/include/compta_ven.inc.php b/include/compta_ven.inc.php index 756466904..702bb71b2 100644 --- a/include/compta_ven.inc.php +++ b/include/compta_ven.inc.php @@ -37,7 +37,7 @@ $str_dossier=dossier::get(); global $g_parameter; $http=new HttpInput(); $strac=$http->request('ac'); -$ac="ac=".$_REQUEST['ac']; +$ac="ac=".$strac; $p_msg=""; //---------------------------------------------------------------------- // Encode a new invoice @@ -48,7 +48,7 @@ $p_msg=""; // Check privilege if ( isset($_REQUEST['p_jrn']) && - $g_user->check_jrn($_REQUEST['p_jrn']) != 'W' ) + $g_user->check_jrn($http->post("p_jrn","number")) != 'W' ) { NoAccess(); @@ -58,10 +58,11 @@ $p_msg=""; /* if a new invoice is encoded, we display a form for confirmation */ if ( isset ($_POST['view_invoice'] ) ) { - $Ledger=new Acc_Ledger_Sold($cn,$_POST['p_jrn']); + $p_jrn=$http->post("p_jrn","number"); + $Ledger=new Acc_Ledger_Sold($cn,$p_jrn); try { - $Ledger->verify($_POST); + $Ledger->verify_operation($_POST); } catch (Exception $e) { @@ -76,10 +77,7 @@ $p_msg=""; echo '
    '; echo h1(_("Confirmation")); - echo '
    '; - - echo '
    '; - echo h2(_("Attention, cette opération n'est pas encore sauvée : vous devez encore confirmer"),' class="notice"'); + echo span(_("Vous devez encore confirmer"),' class="notice"'); echo '
    '; echo '
    '; @@ -152,7 +150,7 @@ show_tabs(a_tab,'facturation_div_id'); $Ledger=new Acc_Ledger_Sold($cn,$_POST['p_jrn']); try { - $Ledger->verify($_POST); + $Ledger->verify_operation($_POST); } catch (Exception $e) { @@ -272,7 +270,7 @@ echo $op->form_get('do.php?'.$url); echo '
    '; */ echo '
    '; -echo '

    '.$p_msg.'

    '; +echo ''.$p_msg.''; try { $payment=$http->request("e_mp","string", 0); @@ -316,7 +314,7 @@ try else { echo HtmlInput::hidden("ledger_type", "VEN"); - echo HtmlInput::hidden("ac", $_REQUEST['ac']); + echo HtmlInput::hidden("ac", $strac); echo HtmlInput::hidden("sa", "p"); echo $Ledger->input($array); diff --git a/include/database/jrn_def_sql.class.php b/include/database/jrn_def_sql.class.php index 4f7afc406..413e4d267 100644 --- a/include/database/jrn_def_sql.class.php +++ b/include/database/jrn_def_sql.class.php @@ -1,5 +1,7 @@ column_name,"email"=>"column_name_email","val3"=>0); */ - protected $variable = array( - "jrn_def_id" => "jrn_def_id", - "jrn_def_name" => "jrn_def_name" - , "jrn_def_class_deb" => "jrn_def_class_deb" - , "jrn_def_class_cred" => "jrn_def_class_cred" - , "jrn_def_fiche_deb" => "jrn_def_fiche_deb" - , "jrn_def_fiche_cred" => "jrn_def_fiche_cred" - , "jrn_deb_max_line" => "jrn_deb_max_line" - , "jrn_cred_max_line" => "jrn_cred_max_line" - , "jrn_def_ech" => "jrn_def_ech" - , "jrn_def_ech_lib" => "jrn_def_ech_lib" - , "jrn_def_type" => "jrn_def_type" - , "jrn_def_code" => "jrn_def_code" - , "jrn_def_pj_pref" => "jrn_def_pj_pref" - , "jrn_def_bank" => "jrn_def_bank" - , "jrn_def_num_op" => "jrn_def_num_op" - , "jrn_def_description" => "jrn_def_description" - ); + function __construct(Database $p_cn, $p_id=-1) + { + $this->table="public.jrn_def"; + $this->primary_key="jrn_def_id"; + /* + * List of columns + */ + $this->name=array( + "jrn_def_id"=>"jrn_def_id" + , "jrn_def_name"=>"jrn_def_name" + , "jrn_def_class_deb"=>"jrn_def_class_deb" + , "jrn_def_class_cred"=>"jrn_def_class_cred" + , "jrn_def_fiche_deb"=>"jrn_def_fiche_deb" + , "jrn_def_fiche_cred"=>"jrn_def_fiche_cred" + , "jrn_deb_max_line"=>"jrn_deb_max_line" + , "jrn_cred_max_line"=>"jrn_cred_max_line" + , "jrn_def_ech"=>"jrn_def_ech" + , "jrn_def_ech_lib"=>"jrn_def_ech_lib" + , "jrn_def_type"=>"jrn_def_type" + , "jrn_def_code"=>"jrn_def_code" + , "jrn_def_pj_pref"=>"jrn_def_pj_pref" + , "jrn_def_bank"=>"jrn_def_bank" + , "jrn_def_num_op"=>"jrn_def_num_op" + , "jrn_def_description"=>"jrn_def_description" + , "jrn_enable"=>"jrn_enable" + , "currency_id"=>"currency_id" + , "jrn_def_negative_amount"=>"jrn_def_negative_amount" + , "jrn_def_negative_warning"=>"jrn_def_negative_warning" + ); + /* + * Type of columns + */ + $this->type=array( + "jrn_def_id"=>"numeric" + , "jrn_def_name"=>"text" + , "jrn_def_class_deb"=>"text" + , "jrn_def_class_cred"=>"text" + , "jrn_def_fiche_deb"=>"text" + , "jrn_def_fiche_cred"=>"text" + , "jrn_deb_max_line"=>"numeric" + , "jrn_cred_max_line"=>"numeric" + , "jrn_def_ech"=>"boolean" + , "jrn_def_ech_lib"=>"text" + , "jrn_def_type"=>"text" + , "jrn_def_code"=>"text" + , "jrn_def_pj_pref"=>"text" + , "jrn_def_bank"=>"numeric" + , "jrn_def_num_op"=>"numeric" + , "jrn_def_description"=>"text" + , "jrn_enable"=>"numeric" + , "currency_id"=>"numeric" + , "jrn_def_negative_amount"=>"text" + ,"jrn_def_negative_warning"=>"text" + ); - function __construct(& $p_cn, $p_id=-1) - { - $this->db = $p_cn; - $this->jrn_def_id = $p_id; - if ($p_id == -1) - { - /* Initialize an empty object */ - foreach ($this->variable as $key => $value) - $this->$value = null; - $this->jrn_def_id = $p_id; - } - else - { - /* load it */ + $this->default=array( + "jrn_def_id"=>"auto" + ); - $this->load(); - } - } - - public function get_parameter($p_string) - { - if (array_key_exists($p_string, $this->variable)) - { - $idx = $this->variable[$p_string]; - return $this->$idx; - } - else - throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant'); - } - - public function set_parameter($p_string, $p_value) - { - if (array_key_exists($p_string, $this->variable)) - { - $idx = $this->variable[$p_string]; - $this->$idx = $p_value; - } - else - throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant'); - } - - public function get_info() - { - return var_export($this, true); - } - - public function verify_sql() - { - // Verify that the elt we want to add is correct - /* verify only the datatype */ - if (trim($this->jrn_def_name) == '') - $this->jrn_def_name = null; - if (trim($this->jrn_def_class_deb) == '') - $this->jrn_def_class_deb = null; - if (trim($this->jrn_def_class_cred) == '') - $this->jrn_def_class_cred = null; - if (trim($this->jrn_def_fiche_deb) == '') - $this->jrn_def_fiche_deb = null; - if (trim($this->jrn_def_fiche_cred) == '') - $this->jrn_def_fiche_cred = null; - if (trim($this->jrn_deb_max_line) == '') - $this->jrn_deb_max_line = null; - if ($this->jrn_deb_max_line !== null && settype($this->jrn_deb_max_line, 'float') == false) - throw new Exception('DATATYPE jrn_deb_max_line $this->jrn_deb_max_line non numerique'); - if (trim($this->jrn_cred_max_line) == '') - $this->jrn_cred_max_line = null; - if ($this->jrn_cred_max_line !== null && settype($this->jrn_cred_max_line, 'float') == false) - throw new Exception('DATATYPE jrn_cred_max_line $this->jrn_cred_max_line non numerique'); - if (trim($this->jrn_def_ech) == '') - $this->jrn_def_ech = null; - if (trim($this->jrn_def_ech_lib) == '') - $this->jrn_def_ech_lib = null; - if (trim($this->jrn_def_type) == '') - $this->jrn_def_type = null; - if (trim($this->jrn_def_code) == '') - $this->jrn_def_code = null; - if (trim($this->jrn_def_pj_pref) == '') - $this->jrn_def_pj_pref = null; - if (trim($this->jrn_def_bank) == '') - $this->jrn_def_bank = null; - if ($this->jrn_def_bank !== null && settype($this->jrn_def_bank, 'float') == false) - throw new Exception('DATATYPE jrn_def_bank $this->jrn_def_bank non numerique'); - if (trim($this->jrn_def_num_op) == '') - $this->jrn_def_num_op = null; - if ($this->jrn_def_num_op !== null && settype($this->jrn_def_num_op, 'float') == false) - throw new Exception('DATATYPE jrn_def_num_op $this->jrn_def_num_op non numerique'); - } - - public function save($p_string='') - { - /* please adapt */ - if ($this->jrn_def_id == -1) - $this->insert(); - else - $this->update(); - } - - /** - * @brief retrieve array of object thanks a condition - * @param $cond condition (where clause) (optional by default all the rows are fetched) - * you can use this parameter for the order or subselect - * @param $p_array array for the SQL stmt - * @see Database::exec_sql get_object Database::num_row - * @return the return value of exec_sql - */ - public function seek($cond='', $p_array=null) - { - $sql = "select * from public.jrn_def $cond"; - $aobj = array(); - $ret = $this->db->exec_sql($sql, $p_array); - return $ret; - } - - /** - * get_seek return the next object, the return of the query must have all the column - * of the object - * @param $p_ret is the return value of an exec_sql - * @param $idx is the index - * @see seek - * @return object - */ - public function get_object($p_ret, $idx) - { - // map each row in a object - $oobj = new Jrn_Def_sql($this->db); - $array = Database::fetch_array($p_ret, $idx); - foreach ($array as $idx => $value) - { - $oobj->$idx = $value; - } - return $oobj; - } - - public function insert($p_array=null) - { - if ($this->verify_sql() != 0) - return; - if ($this->jrn_def_id == -1) - { - /* please adapt */ - $sql = "insert into public.jrn_def(jrn_def_name -,jrn_def_class_deb -,jrn_def_class_cred -,jrn_def_fiche_deb -,jrn_def_fiche_cred -,jrn_deb_max_line -,jrn_cred_max_line -,jrn_def_ech -,jrn_def_ech_lib -,jrn_def_type -,jrn_def_code -,jrn_def_pj_pref -,jrn_def_bank -,jrn_def_num_op -,jrn_def_description -) values ($1 -,$2 -,$3 -,$4 -,$5 -,$6 -,$7 -,$8 -,$9 -,$10 -,$11 -,$12 -,$13 -,$14 -,$15 -) returning jrn_def_id"; - - $this->jrn_def_id = $this->db->get_value( - $sql, array($this->jrn_def_name - , $this->jrn_def_class_deb - , $this->jrn_def_class_cred - , $this->jrn_def_fiche_deb - , $this->jrn_def_fiche_cred - , $this->jrn_deb_max_line - , $this->jrn_cred_max_line - , $this->jrn_def_ech - , $this->jrn_def_ech_lib - , $this->jrn_def_type - , $this->jrn_def_code - , $this->jrn_def_pj_pref - , $this->jrn_def_bank - , $this->jrn_def_num_op - , strip_tags($this->jrn_def_description) - ) - ); - } - else - { - $sql = "insert into public.jrn_def(jrn_def_name -,jrn_def_class_deb -,jrn_def_class_cred -,jrn_def_fiche_deb -,jrn_def_fiche_cred -,jrn_deb_max_line -,jrn_cred_max_line -,jrn_def_ech -,jrn_def_ech_lib -,jrn_def_type -,jrn_def_code -,jrn_def_pj_pref -,jrn_def_bank -,jrn_def_num_op -,jrn_def_id -,jrn_def_description, -jrn_enable) values ($1 -,$2 -,$3 -,$4 -,$5 -,$6 -,$7 -,$8 -,$9 -,$10 -,$11 -,$12 -,$13 -,$14 -,$15 -,$16 -,1 -) returning jrn_def_id"; - - $this->jrn_def_id = $this->db->get_value( - $sql, array($this->jrn_def_name - , $this->jrn_def_class_deb - , $this->jrn_def_class_cred - , $this->jrn_def_fiche_deb - , $this->jrn_def_fiche_cred - , $this->jrn_deb_max_line - , $this->jrn_cred_max_line - , $this->jrn_def_ech - , $this->jrn_def_ech_lib - , $this->jrn_def_type - , $this->jrn_def_code - , $this->jrn_def_pj_pref - , $this->jrn_def_bank - , $this->jrn_def_num_op - , $this->jrn_def_id - , strip_tags($this->jrn_def_description)) - ); - } - } - - public function update($p_string='') - { - if ($this->verify_sql() != 0) - return; - /* please adapt */ - $sql = " update public.jrn_def set jrn_def_name = $1 -,jrn_def_class_deb = $2 -,jrn_def_class_cred = $3 -,jrn_def_fiche_deb = $4 -,jrn_def_fiche_cred = $5 -,jrn_deb_max_line = $6 -,jrn_cred_max_line = $7 -,jrn_def_ech = $8 -,jrn_def_ech_lib = $9 -,jrn_def_type = $10 -,jrn_def_code = $11 -,jrn_def_pj_pref = $12 -,jrn_def_bank = $13 -,jrn_def_num_op = $14 -,jrn_def_description = $15 -,jrn_enable=$17 - where jrn_def_id= $16"; - $res = $this->db->exec_sql( - $sql, array($this->jrn_def_name - , $this->jrn_def_class_deb - , $this->jrn_def_class_cred - , $this->jrn_def_fiche_deb - , $this->jrn_def_fiche_cred - , $this->jrn_deb_max_line - , $this->jrn_cred_max_line - , $this->jrn_def_ech - , $this->jrn_def_ech_lib - , $this->jrn_def_type - , $this->jrn_def_code - , $this->jrn_def_pj_pref - , $this->jrn_def_bank - , $this->jrn_def_num_op - , strip_tags($this->jrn_def_description) - , $this->jrn_def_id - , $this->jrn_enable - ) - ); - } - - /** - * @brief load a object - * @return 0 on success -1 the object is not found - */ - public function load() - { - - $sql = "select jrn_def_name -,jrn_def_class_deb -,jrn_def_class_cred -,jrn_def_fiche_deb -,jrn_def_fiche_cred -,jrn_deb_max_line -,jrn_cred_max_line -,jrn_def_ech -,jrn_def_ech_lib -,jrn_def_type -,jrn_def_code -,jrn_def_pj_pref -,jrn_def_bank -,jrn_def_num_op -,jrn_def_description -,jrn_enable - from public.jrn_def where jrn_def_id=$1"; - /* please adapt */ - $res = $this->db->get_array( - $sql, array($this->jrn_def_id) - ); - - if (count($res) == 0) - { - /* Initialize an empty object */ - foreach ($this->variable as $key => $value) - $this->$key = ''; - - return -1; - } - foreach ($res[0] as $idx => $value) - { - $this->$idx = $value; - } - return 0; - } - - public function delete() - { - $sql = "delete from public.jrn_def where jrn_def_id=$1"; - $res = $this->db->exec_sql($sql, array($this->jrn_def_id)); - } - - /** - * Unit test for the class - */ - static function test_me() - { - } + $this->date_format="DD.MM.YYYY"; + parent::__construct($p_cn, $p_id); + } } - -// Jrn_Def_sql::test_me(); -?> diff --git a/include/export/export_printtva_csv.php b/include/export/export_printtva_csv.php new file mode 100644 index 000000000..c84ffe267 --- /dev/null +++ b/include/export/export_printtva_csv.php @@ -0,0 +1,83 @@ +get("date_start"),$http->get("date_end")); +$tax_summary->check(); + +$csv=new Noalyss_Csv("summary_tva"); +$csv->send_header(); +// Sale +$csv->write_header([ + _("Journal"), + ("Code TVA"), + _("Taux"), + _("Montant HT"), + _("Montant TVA"), + _("Montant Autoliquidation")]); +$array=$tax_summary->get_row_sale(); +$nb_array=count($array); +for ($i=0;$i < $nb_array;$i++) { + $csv->add ($array[$i]['jrn_def_name']); + $csv->add ($array[$i]['tva_label']); + $csv->add ($array[$i]['tva_rate'],'number'); + $csv->add ($array[$i]['amount_wovat'],'number'); + $csv->add ($array[$i]['amount_vat'],'number'); + $csv->add ($array[$i]['amount_sided'],'number'); + $csv->write(); +} +//Purchase +$csv->write_header([ + _("Journal"), + ("Code TVA"), + _("Taux"), + _("Montant HT"), + _("Privée"), + _("Montant TVA"), + _("Montant Autoliquidation"), + _("Montant ND"), + _("TVA Non Déd"), + _("TVA Non Déd & récup") + ]); +$array=$tax_summary->get_row_purchase(); +$nb_array=count($array); +for ($i=0;$i < $nb_array;$i++) { + $csv->add ($array[$i]['jrn_def_name']); + $csv->add ($array[$i]['tva_label']); + $csv->add ($array[$i]['tva_rate'],'number'); + $csv->add ($array[$i]['amount_wovat'],'number'); + $csv->add ($array[$i]['amount_private'],'number'); + $csv->add ($array[$i]['amount_vat'],'number'); + $csv->add ($array[$i]['amount_sided'],'number'); + $csv->add ($array[$i]['amount_noded_amount'],'number'); + $csv->add ($array[$i]['amount_noded_tax'],'number'); + $csv->add ($array[$i]['amount_noded_return'],'number'); + $csv->write(); +} diff --git a/include/export/export_printtva_pdf.php b/include/export/export_printtva_pdf.php new file mode 100644 index 000000000..ab337ea0a --- /dev/null +++ b/include/export/export_printtva_pdf.php @@ -0,0 +1,353 @@ +request("date_start"); +$to_periode = $http->request("date_end"); + + +$gDossier = dossier::id(); + +/* Security */ +$cn = Dossier::connect(); +$tax_summary = new Tax_Summary($cn, $from_periode, $to_periode); +$pdf = new PDFLand($cn); +$pdf->setDossierInfo(sprintf(_("Date") . " : %s %s", $from_periode, $to_periode)); +$pdf->AliasNbPages(); +$pdf->AddPage(); +$pdf->SetAuthor('NOALYSS'); +$pdf->setTitle(_("Résumé TVA"), true); + + + + +//------------------------------------------------------------------------- +// Sales +//------------------------------------------------------------------------- +$a_sale_header = [_("Code TVA"), _("Taux"), _("Montant HT"), _("Montant TVA"), + _("Montant Autoliquidation")]; +$nb_sale = count($a_sale_header); +$array = $tax_summary->get_row_sale(); +// Table header +$nb_array = count($array); +$tot_vat = 0; +$tot_wovat = 0; +$tot_sided = 0; +$ledger_name = ""; +//------------------------------------------------------------------------- +// For each sale ledger +//------------------------------------------------------------------------- +// Table with total +$a_col=['tva_label','tva_rate','amount_wovat','amount_vat','amount_sided']; +$nb_col=count($a_col); +$a_tot=[]; +// initialize totals +for ($e=2;$e<$nb_col;$e++){ + $a_tot[$a_col[$e]]=0; +} + +for ($i = 0; $i < $nb_array; $i++) { + for ($e=2;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + $a_tot[$colname]=bcadd($a_tot[$colname],$array[$i][$colname]); + } + + if ($i == 0) { + // Display ledger name + + $ledger_name = $array[$i]['jrn_def_name']; + $pdf->SetFont('DejaVuCond', 'B', 10); + $pdf->write_cell(50, 8, $ledger_name); + $pdf->line_new(); + + // Display Header + $pdf->SetFont('DejaVuCond', 'B', 7); + for ($e=0;$e<$nb_col;$e++){ + if ( $e == 0 ) { + $pdf->write_cell(40, 5,$a_sale_header[$e], 1, 0, 'L'); + } else { + $pdf->write_cell(40, 5,$a_sale_header[$e], 1, 0, 'R'); + } + $a_tot[$colname]=0; + } + $pdf->line_new(); + $pdf->SetFont('DejaVuCond', '', 7); + } + if ($ledger_name != $array[$i]['jrn_def_name']) { + // Display totals + $pdf->SetFont('DejaVuCond', 'B', 7); + $pdf->line_new(); + $pdf->write_cell(70, 5, ""); + for ($e=2;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + $pdf->write_cell(40, 5, nbm($a_tot[$colname]), 0, 0, 'R'); + $a_tot[$colname]=0; + } + $pdf->line_new(); + $pdf->SetFont('DejaVuCond', 'B', 7); + + // Display ledger name + $ledger_name = $array[$i]['jrn_def_name']; + $pdf->SetFont('DejaVuCond', 'B', 10); + $pdf->write_cell(50, 8, $ledger_name); + $pdf->line_new(); + + // Display Header + for ($e=0;$e<$nb_col;$e++){ + if ( $e == 0 ) { + $pdf->write_cell(40, 5,$a_sale_header[$e], 1, 0, 'L'); + } else { + $pdf->write_cell(40, 5,$a_sale_header[$e], 1, 0, 'R'); + } + $a_tot[$colname]=0; + } + } + for ($e=0;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + if ( $e ==0 ) { + $pdf->write_cell(40, 5, $array[$i][$colname], 1, 0, 'L'); + } elseif ($e == 1 ){ + $pdf->write_cell(40, 5, nbm($array[$i][$colname]*100), 1, 0, 'R'); + }else { + $pdf->write_cell(40, 5, nbm($array[$i][$colname]), 1, 0, 'R'); + } + } + $pdf->line_new(); +} +$pdf->SetFont('DejaVuCond', 'B', 7); +$pdf->write_cell(80, 5, ""); +for ($e=2;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + $pdf->write_cell(40, 5, nbm($a_tot[$colname]), 1, 0, 'R'); +} + +//------------------------------------------------------------------------- +// Summary sales +//------------------------------------------------------------------------- +$a_sum = $tax_summary->get_summary_sale(); +$pdf->line_new(); +$pdf->SetFont('DejaVuCond', 'B', 10); +$pdf->write_cell(50, 8, _("Résumé TVA vente")); +$pdf->line_new(); + +$pdf->SetFont('DejaVuCond', 'B', 7); +for ($i = 0; $i < $nb_sale; $i++) { + if ($i > 0 ) { + $pdf->write_cell(40, 5, $a_sale_header[$i], 1, 0, 'R'); + } else { + $pdf->write_cell(40, 5, $a_sale_header[$i], 1, 0, 'L'); + } +} +$pdf->line_new(); + +$nb_array = count($array); +// initialize totals +for ($e=2;$e<$nb_col;$e++){ + $a_tot[$a_col[$e]]=0; +} +$pdf->SetFont('DejaVuCond', '', 7); + +for ($i = 0; $i < $nb_array; $i++) { + // display each row + for ($e=0;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + if ( $e ==0 ) { + // first column TVA_LABEL + $pdf->write_cell(40, 5, $array[$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'); + }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'); + } + } + $pdf->line_new(); +} +$pdf->SetFont('DejaVuCond', 'B', 7); +$pdf->write_cell(80, 5, ""); +for ($e=2;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + $pdf->write_cell(40, 5, nbm($a_tot[$colname]), 1, 0, 'R'); +} +$pdf->line_new(); + +//------------------------------------------------------------------------------------------ +// Purchase +//------------------------------------------------------------------------------------------ +$array = $tax_summary->get_row_purchase(); +$a_colp=['tva_label','tva_rate','amount_wovat','amount_private','amount_vat','amount_sided', + 'amount_noded_amount','amount_noded_tax','amount_noded_return']; +$a_purchase_header = [_("Code TVA"), _("Taux"), _("Montant HT"), _("Privée"), _("Montant TVA"), + _("Montant Autoliquidation"), _("Montant Non Déd"), _("TVA Non Déd"), _("TVA Non Déd & récup")]; +$nb_purchase = count($a_purchase_header); + +for ($e=2;$e<$nb_col;$e++){ + $a_tot[$a_col[$e]]=0; +} + +for ($i = 0; $i < $nb_array; $i++) { + for ($e=2;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + $a_tot[$colname]=bcadd($a_tot[$colname],$array[$i][$colname]); + } + + if ($i == 0) { + // Display ledger name + + $ledger_name = $array[$i]['jrn_def_name']; + $pdf->SetFont('DejaVuCond', 'B', 10); + $pdf->write_cell(50, 8, $ledger_name); + $pdf->line_new(); + + // Display Header + $pdf->SetFont('DejaVuCond', 'B', 7); + for ($e=0;$e<$nb_col;$e++){ + if ( $e == 0 ) { + $pdf->write_cell(40, 5,$a_purchase_header[$e], 1, 0, 'L'); + } else { + $pdf->write_cell(40, 5,$a_purchase_header[$e], 1, 0, 'R'); + } + $a_tot[$colname]=0; + } + $pdf->line_new(); + $pdf->SetFont('DejaVuCond', '', 7); + } + if ($ledger_name != $array[$i]['jrn_def_name']) { + // Display totals + $pdf->SetFont('DejaVuCond', 'B', 7); + $pdf->line_new(); + $pdf->write_cell(70, 5, ""); + for ($e=2;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + $pdf->write_cell(40, 5, nbm($a_tot[$colname]), 0, 0, 'R'); + $a_tot[$colname]=0; + } + $pdf->line_new(); + $pdf->SetFont('DejaVuCond', 'B', 7); + + // Display ledger name + $ledger_name = $array[$i]['jrn_def_name']; + $pdf->SetFont('DejaVuCond', 'B', 10); + $pdf->write_cell(50, 8, $ledger_name); + $pdf->line_new(); + + // Display Header + for ($e=0;$e<$nb_col;$e++){ + if ( $e == 0 ) { + $pdf->write_cell(40, 5,$a_purchase_header[$e], 1, 0, 'L'); + } else { + $pdf->write_cell(40, 5,$a_purchase_header[$e], 1, 0, 'R'); + } + $a_tot[$colname]=0; + } + } + for ($e=0;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + if ( $e ==0 ) { + $pdf->write_cell(40, 5, $array[$i][$colname], 1, 0, 'L'); + } elseif ($e == 1 ){ + $pdf->write_cell(40, 5, nbm($array[$i][$colname]*100), 1, 0, 'R'); + }else { + $pdf->write_cell(40, 5, nbm($array[$i][$colname]), 1, 0, 'R'); + } + } + $pdf->line_new(); +} +$pdf->SetFont('DejaVuCond', 'B', 7); +$pdf->write_cell(80, 5, ""); +for ($e=2;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + $pdf->write_cell(40, 5, nbm($a_tot[$colname]), 1, 0, 'R'); +} + +//------------------------------------------------------------------------- +// Summary sales +//------------------------------------------------------------------------- +$a_sum = $tax_summary->get_summary_sale(); +$pdf->line_new(); +$pdf->SetFont('DejaVuCond', 'B', 10); +$pdf->write_cell(50, 8, _("Résumé TVA Achat")); +$pdf->line_new(); + +$pdf->SetFont('DejaVuCond', 'B', 7); +for ($e=0;$e<$nb_col;$e++){ + if ( $e == 0 ) { + $pdf->write_cell(40, 5,$a_purchase_header[$e], 1, 0, 'L'); + } else { + $pdf->write_cell(40, 5,$a_purchase_header[$e], 1, 0, 'R'); + } + $a_tot[$colname]=0; +} +$pdf->line_new(); + +$nb_array = count($array); +// initialize totals +for ($e=2;$e<$nb_col;$e++){ + $a_tot[$a_col[$e]]=0; +} +$pdf->SetFont('DejaVuCond', '', 7); + +for ($i = 0; $i < $nb_array; $i++) { + // display each row + for ($e=0;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + if ( $e ==0 ) { + // first column TVA_LABEL + $pdf->write_cell(40, 5, $array[$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'); + }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'); + } + } + $pdf->line_new(); +} +$pdf->SetFont('DejaVuCond', 'B', 7); +$pdf->write_cell(80, 5, ""); +for ($e=2;$e<$nb_col;$e++){ + $colname=$a_col[$e]; + $pdf->write_cell(40, 5, nbm($a_tot[$colname]), 1, 0, 'R'); +} +$pdf->line_new(); + + +//---------------------------------- Output -------------------------------------------------- + +$fDate = date('Ymd-Hi'); + +$pdf->Output('tva-' . $fDate . '.pdf', 'D'); \ No newline at end of file diff --git a/include/lib/message_javascript.php b/include/lib/message_javascript.php index 03c3f3fb0..9333a2dd2 100644 --- a/include/lib/message_javascript.php +++ b/include/lib/message_javascript.php @@ -103,5 +103,5 @@ content[69]=""; content[70]=""; content[71]=""; content[72]=""; - +content[73]=""; \ No newline at end of file diff --git a/include/operation_ods_new.inc.php b/include/operation_ods_new.inc.php index f3dcacdc7..9396314ad 100644 --- a/include/operation_ods_new.inc.php +++ b/include/operation_ods_new.inc.php @@ -63,7 +63,7 @@ if ( isset ($_GET['action']) && ! isset($_POST['correct']) && ! isset($correct) $p_post=null; if ( isset($_REQUEST['pre_def']) && $_REQUEST['pre_def'] != '') { - $op->set_od_id($_REQUEST['pre_def']); + $op->set_od_id($http->request('pre_def','number')); $p_post=$op->compute_array(); } } diff --git a/include/tax_summary.inc.php b/include/tax_summary.inc.php new file mode 100644 index 000000000..650ddbe0c --- /dev/null +++ b/include/tax_summary.inc.php @@ -0,0 +1,72 @@ +get_limit_current_exercice(); + +$start = $http->request("start_date", "date", $limit[0]); +$end = $http->request("end_date", "date", $limit[1]); + +$start_periode = new IDate("start_date", $start); +$end_periode = new IDate("end_date", $end); +echo ''; +echo HtmlInput::array_to_hidden(['gDossier','ac'],$_GET); +echo HtmlInput::hidden("do","display"); +printf(_("Période du %s au %s"), + $start_periode->input(), + $end_periode->input()); + +echo HtmlInput::submit("show_tax_summary",_("Afficher")); +echo ''; +echo '
    '; +if ( $http->get("do","string","no") == "display") +{ + $tax_summary=new Tax_Summary($cn,$start_periode->value,$end_periode->value); + try { + $tax_summary->check(); + echo '
      '; + echo '
    • '; + echo $tax_summary->form_export_csv(); + echo '
    • '; + echo '
    • '; + echo $tax_summary->form_export_pdf(); + echo '
    • '; + echo '
    '; + $tax_summary->display(); + echo '
      '; + echo '
    • '; + echo $tax_summary->form_export_csv(); + echo '
    • '; + echo '
    • '; + echo $tax_summary->form_export_pdf(); + echo '
    • '; + echo '
    '; + + } catch (Exception $e) { + echo $e->getMessage(); + } +} diff --git a/include/template/param_jrn.php b/include/template/param_jrn.php index 4e9e5058b..b5af8cec9 100644 --- a/include/template/param_jrn.php +++ b/include/template/param_jrn.php @@ -16,10 +16,13 @@ - + @@ -33,46 +36,87 @@ if ( $new || $type=='ODS' ): endif; ?> - - - - - - input();?> - - - - - - - -name='bank'; -$card->extra=$cn->make_list('select fd_id from fiche_def where frd_id=4'); -$card->set_dblclick("fill_ipopcard(this);"); -$card->set_function('fill_data'); -$card->set_attribute('ipopup','ipop_card'); -$list=$cn->make_list('select fd_id from fiche_def where frd_id=4'); -$card->set_attribute('typecard',$list); + + + + + + input();?> + + + + + + + + name='bank'; + $card->extra=$cn->make_list('select fd_id from fiche_def where frd_id=4'); + $card->set_dblclick("fill_ipopcard(this);"); + $card->set_function('fill_data'); + $card->set_attribute('ipopup','ipop_card'); + $list=$cn->make_list('select fd_id from fiche_def where frd_id=4'); + $card->set_attribute('typecard',$list); -$card->value=$qcode_bank; -echo $card->search(); -echo $card->input(); -echo $str_add_button; + $card->value=$qcode_bank; + echo $card->search(); + echo $card->input(); + echo $str_add_button; + ?> + + + + + + - - - - + + + + + + + + + javascript="toggle_row_warning_enable('negative_amount','row_warning')"; + $negative->input(); + ?> + + + + + + + + input();?> + + + - + + + - + input()?> @@ -103,32 +147,33 @@ echo $str_add_button; - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - input()?> - + + + + + + + + + + + + + + + input()?> + + @@ -365,6 +410,8 @@ echo $str_add_button; $('type_ods').style.display='none'; $('type_fin').style.display='none'; $('type_fin2').style.display='none'; + $('neg_amount').style.display='none'; + $('row_warning').style.display='none'; } function show_ledger_div() { @@ -381,6 +428,19 @@ echo $str_add_button; hide_row(); $('type_ods').style.display='table-row'; break; + case 'ACH': + hide_row(); + $('neg_amount').style.display='table-row'; + toggle_row_warning_enable('negative_amount','row_warning'); + + break; + case 'VEN': + hide_row(); + $('neg_amount').style.display='table-row'; + toggle_row_warning_enable('negative_amount','row_warning'); + + break; + default: hide_row(); } @@ -396,3 +456,10 @@ echo $str_add_button; ?> + + + \ No newline at end of file diff --git a/include/template/tax_summary_display.php b/include/template/tax_summary_display.php new file mode 100644 index 000000000..84bb1b530 --- /dev/null +++ b/include/template/tax_summary_display.php @@ -0,0 +1,375 @@ + +

    + +get_row_sale(); +$nb_array=count($array); +$ledger=""; +$r=0; +$tot_vat=0;$tot_wovat=0;$tot_sided=0; + +for ($i=0;$i < $nb_array;$i++): + + if ( $ledger != $array[$i]['jrn_def_name']): + if ( $ledger != "") : + // last row with total + echo ''; + echo td(); + echo td(); + echo td(nbm($tot_wovat),' class="num" '); + echo td(nbm($tot_vat),' class="num" '); + echo td(nbm($tot_sided),' class="num" '); + echo ''; + echo ''; + endif; + $ledger=$array[$i]['jrn_def_name']; + //reinitialize sum + $tot_vat=0;$tot_wovat=0;$tot_sided=0; + + printf("

    %s

    ",$ledger); + echo ''; + echo ''; + echo th(_("Code TVA")); + echo th(_("Taux"),'class="num"'); + echo th(_("Montant HT"),'class="num"'); + echo th(_("Montant TVA"),'class="num"'); + echo th(_("Montant Autoliquidation"),'class="num"'); + echo ''; + $r=0; + endif; + $color=($r%2==0)?"even":"odd"; +?> + + + + + + + + + + 0): +// last row with total + echo ''; + echo td(); + echo td(); + echo td(nbm($tot_wovat),' class="num" '); + echo td(nbm($tot_vat),' class="num" '); + echo td(nbm($tot_sided),' class="num" '); + echo ''; +else: + echo _("Aucune donnée"); +endif; + echo '
    + + + % + + + + + + +
    '; +?> +

    +get_summary_sale(); +?> + + + + + + + + + + + + + + + + + +'; + echo td(); + echo td(); + echo td(nbm($tot_wovat),' class="num" '); + echo td(nbm($tot_vat),' class="num" '); + echo td(nbm($tot_sided),' class="num" '); + echo ''; + ?> +
    + + + + + + + + + +
    + + + % + + + + + + +
    +get_summary_sale(); + + +?> +

    +get_row_purchase(); +$nb_array=count($array); +$ledger=""; +$r=0; +$tot_vat=0;$tot_wovat=0;$tot_sided=0;$tot_noded_amount=0;$tot_noded_tax=0;$tot_noded_return=0;$tot_private=0; +for ($i=0;$i < $nb_array;$i++): + + if ( $ledger != $array[$i]['jrn_def_name']): + if ( $ledger != "") : + // last row with total + echo ''; + echo td(); + echo td(); + echo td(nbm($tot_wovat),' class="num" '); + echo td(nbm($tot_private),' class="num" '); + echo td(nbm($tot_vat),' class="num" '); + echo td(nbm($tot_sided),' class="num" '); + echo td(nbm($tot_noded_amount),' class="num" '); + echo td(nbm($tot_noded_tax),' class="num" '); + echo td(nbm($tot_noded_return),' class="num" '); + echo ''; + echo ''; + endif; + $ledger=$array[$i]['jrn_def_name']; + //reinitialize sum + $tot_vat=0;$tot_wovat=0;$tot_sided=0;$tot_noded_amount=0;$tot_noded_tax=0;$tot_noded_return=0;$tot_private=0; + + printf("

    %s

    ",$ledger); + echo ''; + echo ''; + echo th(_("Code TVA")); + echo th(_("Taux"),'class="num"'); + echo th(_("Montant HT"),'class="num"'); + echo th(_("Privée"),'class="num"'); + echo th(_("Montant TVA"),'class="num"'); + echo th(_("Montant Autoliquidation"),'class="num"'); + echo th(_("Montant Non Déd"),'class="num"'); + echo th(_("TVA Non Déd"),'class="num"'); + echo th(_("TVA Non Déd & récup"),'class="num"'); + echo ''; + $r=0; + endif; + $color=($r%2==0)?"even":"odd"; + ?> + + + + + + + + + + + + + + 0): + echo ''; + echo td(); + echo td(); + echo td(nbm($tot_wovat),' class="num" '); + echo td(nbm($tot_private),' class="num" '); + echo td(nbm($tot_vat),' class="num" '); + echo td(nbm($tot_sided),' class="num" '); + echo td(nbm($tot_noded_amount),' class="num" '); + echo td(nbm($tot_noded_tax),' class="num" '); + echo td(nbm($tot_noded_return),' class="num" '); + echo ''; +else: + echo _("Aucune donnée"); +endif; +echo '
    + + + % + + + + + + + + + + + + + + +
    '; +?> +

    +get_summary_purchase(); +?> + + + + + + + + + + + + + + + + + + + + + + + + + + '; + echo td(); + echo td(); + echo td(nbm($tot_wovat),' class="num" '); + echo td(nbm($tot_private),' class="num" '); + echo td(nbm($tot_vat),' class="num" '); + echo td(nbm($tot_sided),' class="num" '); + echo td(nbm($tot_noded_amount),' class="num" '); + echo td(nbm($tot_noded_tax),' class="num" '); + echo td(nbm($tot_noded_return),' class="num" '); + echo ''; + ?> +
    + + + + + + + + + + + + + + + + + +
    + + + % + + + + + + + + + + + + + + +
    diff --git a/unit-test/include/class/acc_balanceTest.class.php b/unit-test/include/class/acc_balanceTest.class.php index 0799c9b48..0cb572496 100644 --- a/unit-test/include/class/acc_balanceTest.class.php +++ b/unit-test/include/class/acc_balanceTest.class.php @@ -18,11 +18,13 @@ class Acc_BalanceTest extends TestCase */ protected function setUp() { - global $g_connection, $g_parameter; + global $g_connection, $g_parameter,$g_user; $_REQUEST['gDossier']=DOSSIER; $g_connection=new Database(DOSSIER); $g_parameter=new Noalyss_Parameter_Folder($g_connection); $this->object=new Acc_Balance($g_connection); + + } /** @@ -40,11 +42,12 @@ class Acc_BalanceTest extends TestCase */ public function testGet_row() { - $this->object->get_row(1,200); - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'DATA : cannot be tested' - ); + global $g_connection,$g_user; + $g_user=new User($g_connection,1); + + $max=$g_connection->get_value("select max(p_id) from parm_periode"); + $min=$g_connection->get_value("select min(p_id) from parm_periode"); + $this->object->get_row($min,$max); } /** diff --git a/unit-test/include/class/acc_ledgerTest.class.php b/unit-test/include/class/acc_ledgerTest.class.php index efc81cb63..1c91653d3 100644 --- a/unit-test/include/class/acc_ledgerTest.class.php +++ b/unit-test/include/class/acc_ledgerTest.class.php @@ -17,6 +17,32 @@ class Acc_LedgerTest extends TestCase $dataSet->addTable('jrn', dirname(__FILE__)."/jrn.csv"); return $dataSet; } + /** + * Get an operation + * @global type $g_connection + * @return type + */ + private function get_jrn_id($p_ledger='ODS') + { + global $g_connection; + $jr_id=$g_connection->get_value("select max(jr_id) from jrn join jrn_def " + . "on (jrn_def_id=jr_def_id) " + . " where " + . " jrn_def_type=$1",[$p_ledger]); + return $jr_id; + } + /** + * Return 1 if operation does exist otherwise zero + * @global type $g_connection + * @param type $p_jr_id + * @return type + */ + private function exist_operation($p_jr_id) + { + global $g_connection; + $jr_id=$g_connection->get_value("select count(*) from jrn where jr_id=$1",[$p_jr_id]); + return $jr_id; + } /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. @@ -43,9 +69,10 @@ class Acc_LedgerTest extends TestCase public function testGet_last_pj() { - $this->object->id=1; - $array=$this->object->get_last(2); - $this->assertEquals(2,count($array)); + $this->object->id=2; + $sPj=$this->object->get_last_pj(2); + print_r("get_last_pj $sPj"); + $this->assertEquals(5,$sPj); } @@ -78,16 +105,51 @@ class Acc_LedgerTest extends TestCase */ public function testDelete() { + global $g_connection; + $jr_id=$g_connection->get_value("select max(jr_id) from jrn"); + $this->object->jr_id=$jr_id; $this->object->delete(); + $count=$g_connection->get_value("select count(*) from jrn where jr_id=$1",[$jr_id]); + $this->assertEquals($count,0); + } + public function delete_ledger() + { + global $g_connection; + // a . create a ledger and delete it + $array=["p_jrn_def_name"=>"UNITTEST","p_ech_lib"=>"","p_jrn_deb_max_line"=>7,'p_jrn_type'=>'ODS','jrn_def_pj_pref'=>'TT/','min_row'=>5,'p_description'=>'LEDGER UNIT TEST','jrn_def_negative_amount'=>0,'jrn_def_negative_warning'=>'Warning']; + $this->object->save_new($array); + + // Get it + $last_ledger_inserted=$g_connection->get_value("select max(jrn_def_id) from jrn_def"); + $name=$g_connection->get_value("select jrn_def_name from jrn_def where jrn_def_id=$1",[$last_ledger_inserted]); + $this->assertEquals($name,'UNITTEST'); + + // drop it + $this->object->delete_ledger(); + $cnt=$g_connection->get_value("select count(*) from jrn_def where jrn_def_id=$1",[$last_ledger_inserted]); + $this->assertEquals($cnt,0); + $ok=0; + // Try to delete a ledger which is used + try { + $jr_id=$g_connection->get_value("select max(jr_id) from jrn"); + $ledger_id=$g_connection->get_value("select jr_def_id from jrn where jr_id=$1",[$jr_id]); + $ledger=new Acc_Legder($g_connection,$ledger_id); + $ledger->delete_ledger(); + } catch (Exception $ex) { + $ok=1; + } + $this->assertEquals($ok,1); + $cnt=$g_connection->get_value("select count(*) from jrn_def where jrn_def_id=$1",[$ledger_id]); + $this->assertEquals($cnt,1); } - /** * @covers Acc_Ledger::display_warning * @todo Implement testDisplay_warning(). */ public function testDisplay_warning() { - $this->object->display_warning("Alert", "warning"); + $str=$this->object->display_warning(["First Line","Second Line"], "warning"); + $this->assertEquals('

    warning

    1. First Line
    2. Second Line

    ',$str); } /** @@ -96,7 +158,22 @@ class Acc_LedgerTest extends TestCase */ public function testReverse() { - $this->object->reverse('01.01.2014'); + global $g_connection; + $this->object->jr_id=$g_connection->get_value("select max(jr_id) from jrn "); + $this->assertLessThan($this->object->jr_id,"0","found jr_id ".$this->object->jr_id); + $this->assertFalse(empty($this->object->jr_id),"not found jr_id "); + + $this->object->id=$g_connection->get_value("select jr_def_id from jrn where jr_id=$1",[$this->object->jr_id]); + $this->assertGreaterThan($this->object->id,"0","found id ".$this->object->id); + $this->assertFalse(empty($this->object->id),"not found id "); + print_r("jr_id = ".$this->object->jr_id); + print_r("id = ".$this->object->id); + $date=$g_connection->get_value ("select to_char(max(p_start),'DD.MM.YYYY') from parm_periode where p_closed='f'"); + $this->object->reverse($date,'unit test'.$date); + $check=$g_connection->get_value("select jr_id from jrn where jr_comment=$1",["unit test".$date]); + $this->assertFalse(empty($check),"NOT REVERSED" ); + $this->object->jr_id=$check; + $this->object->delete(); } /** @@ -110,28 +187,22 @@ class Acc_LedgerTest extends TestCase $this->assertEquals('Achat',$name); } - /** - * @covers Acc_Ledger::get_row - * @todo Implement testGet_row(). - */ - public function testGet_row() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - /** * @covers Acc_Ledger::get_rowSimple * @todo Implement testGet_rowSimple(). */ public function testGet_rowSimple() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + global $g_connection; + $last=$g_connection->get_value("select max(p_id) from parm_periode"); + $first=$g_connection->get_value("select min(p_id) from parm_periode"); + $id=$this->object->id; + $this->object->id=2; + $array=$this->object->get_rowSimple($first,$last); + $this->assertTrue(is_array($array),"get_rowSimple does not return an array"); + $this->assertGreaterThan(0,count($array)); + $this->object->id=$id; + } /** @@ -140,46 +211,9 @@ class Acc_LedgerTest extends TestCase */ public function testGuess_pj() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Acc_Ledger::list_operation_to_reconcile - * @todo Implement testList_operation_to_reconcile(). - */ - public function testList_operation_to_reconcile() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Acc_Ledger::list_operation - * @todo Implement testList_operation(). - */ - public function testList_operation() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers Acc_Ledger::get_detail - * @todo Implement testGet_detail(). - */ - public function testGet_detail() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->object->id=2; + $r=$this->object->guess_pj(); + $this->assertEquals("VEN6",$r); } /** @@ -188,10 +222,11 @@ class Acc_LedgerTest extends TestCase */ public function testGet_propertie() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + global $g_connection; + $this->object->id=2; + $array=$this->object->get_propertie(); + // there are 16 columns in jrn_def + $this->assertEquals(count($array),20); } /** @@ -205,7 +240,38 @@ class Acc_LedgerTest extends TestCase 'This test has not been implemented yet.' ); } - + /** + * @covers Acc_Ledger::display_negative_warning + */ + public function testDisplay_negative_warning() + { + global $g_connection; + $msg="WARNING ! WARNING !"; + $acc_ledger=new Jrn_def_SQL($g_connection,2); + $acc_ledger_old=clone $acc_ledger; + $acc_ledger->setp("jrn_def_negative_amount",1); + $acc_ledger->setp("jrn_def_negative_warning",$msg); + $acc_ledger->save(); + $this->object->set_ledger_id(2); + $result=$this->object->display_negative_warning(-1); + $this->assertEquals($result,""); + $result=$this->object->display_negative_warning(1); + $this->assertEquals($result,$msg); + + $acc_ledger_old->save(); + $id=$this->object->get_ledger_id(); + $ok=0; + try { + $this->object->set_ledger_id(0); + $result=$this->object->display_negative_warning(1); + } catch (Exception $e) { + $this->assertEquals($e->getCode(),1); + $ok=1; + } + $this->assertEquals($ok,1); + $this->object->set_ledger_id($id); + + } /** * @covers Acc_Ledger::get_solde * @todo Implement testGet_solde(). @@ -666,9 +732,36 @@ class Acc_LedgerTest extends TestCase */ public function testGet_tiers() { - $this->object->get_tiers($p_jrn_type, $jr_id); - } + global $g_connection; + $jr_id=$this->get_jrn_id(); + $this->assertEquals($this->object->get_tiers("ODS", $jr_id)," "); + $jr_id=$this->get_jrn_id("ACH"); + $this->assertTrue($this->object->get_tiers("ACH",$jr_id)!=' '); + + $jr_id=$this->get_jrn_id("FIN"); + $this->assertTrue($this->object->get_tiers('FIN',$jr_id)!=' '); + + $jr_id=$this->get_jrn_id("VEN"); + $this->assertTrue($this->object->get_tiers("VEN",$jr_id)!=' '); + + } + public function testGet_tiers_id() + { + global $g_connection; + $jr_id=$this->get_jrn_id(); + $this->assertEquals($this->object->get_tiers_id("ODS", $jr_id),0); + + $jr_id=$this->get_jrn_id("ACH"); + $this->assertGreaterThan(0,$this->object->get_tiers_id("ACH",$jr_id)); + + $jr_id=$this->get_jrn_id("FIN"); + $this->assertGreaterThan(0,$this->object->get_tiers_id("FIN",$jr_id)); + + $jr_id=$this->get_jrn_id("VEN"); + $this->assertGreaterThan(0,$this->object->get_tiers_id("VEN",$jr_id)); + + } /** * @covers Acc_Ledger::listing * @todo Implement testListing(). @@ -719,14 +812,12 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::input_paid - * @todo Implement testInput_paid(). */ public function testInput_paid() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $r=$this->object->input_paid(0); + $this->assertStringStartsWith('
    ',$r); + $this->assertStringEndsWith('
    ',$r); } /** @@ -743,14 +834,30 @@ class Acc_LedgerTest extends TestCase /** * @covers Acc_Ledger::save_new - * @todo Implement testSave_new(). */ public function testSave_new() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + global $g_connection; + + $array=["p_jrn_name"=>"UNITTEST", + "p_ech_lib"=>"", + "p_jrn_deb_max_line"=>7, + 'p_jrn_class_deb'=>'4*', + 'p_jrn_type'=>'ODS', + 'jrn_def_pj_pref'=>'TT/', + 'min_row'=>5, + 'p_description'=>'LEDGER UNIT TEST', + 'jrn_def_negative_amount'=>0, + 'jrn_def_negative_warning'=>'Warning']; + + + $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']]); + $this->assertGreaterThan($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']]); + $this->assertEquals($jrn_def_id,""); } /** @@ -759,10 +866,23 @@ class Acc_LedgerTest extends TestCase */ public function testDelete_ledger() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + global $g_connection; + $array=["p_jrn_name"=>"UNITTEST", + "p_ech_lib"=>"", + "p_jrn_deb_max_line"=>7, + 'p_jrn_class_deb'=>'4*', + 'p_jrn_type'=>'ODS', + 'jrn_def_pj_pref'=>'TT/', + 'min_row'=>5, + 'p_description'=>'LEDGER UNIT TEST']; + + $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']]); + $this->assertGreaterThan($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']]); + $this->assertEquals($jrn_def_id,""); } /** @@ -771,10 +891,15 @@ class Acc_LedgerTest extends TestCase */ public function testGet_operation_date() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $res=$this->object->get_operation_date('01.01.2010','VEN','>'); + $this->assertGreaterThan(0,count($res),'Failed VEN'); + $res=$this->object->get_operation_date('01.01.2010','ACH','>'); + $this->assertGreaterThan(0,count($res),'Failed ACH '); + $res=$this->object->get_operation_date('01.01.2000','VEN','<'); + $this->assertEquals(count($res),0,'Failed VEN before '); + $res=$this->object->get_operation_date('01.01.2000','ACH','<'); + $this->assertEquals(count($res),0,'Failed ACH before'); + } /** @@ -783,10 +908,7 @@ class Acc_LedgerTest extends TestCase */ public function testGet_supplier_now() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->assertTrue(is_array($this->object->get_supplier_now())); } /** @@ -795,10 +917,7 @@ class Acc_LedgerTest extends TestCase */ public function testGet_supplier_late() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->assertTrue(is_array($this->object->get_supplier_late())); } /** @@ -807,10 +926,7 @@ class Acc_LedgerTest extends TestCase */ public function testGet_customer_now() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->assertTrue(is_array($this->object->get_customer_now())); } /** @@ -819,10 +935,7 @@ class Acc_LedgerTest extends TestCase */ public function testGet_customer_late() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->assertTrue(is_array($this->object->get_customer_late())); } /**