diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index 488c81182..ec804adce 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -85,6 +85,13 @@ class Acc_Ledger extends jrn_def_sql $this->currency_id=0; } } + + /** + * @brief returns the sequence number of the receipt for the current ledger + * or create the sequence if it doesn't exist + * @return int + * @throws Exception if the ledger doesn't exist + */ function get_last_pj() { if (isNumber($this->id)==0) @@ -417,7 +424,7 @@ class Acc_Ledger extends jrn_def_sql $reverse_accOp->set_id($reverse_id); $reverse_accOp->pj=$old_receipt['jr_pj_number']; $reverse_accOp->jrn=$old_receipt['jr_def_id']; - $reverse_accOp->set_pj(); + $reverse_accOp->update_receipt(); // Check return code } catch (\Exception $e){ throw new \Exception('Echec extourne'); @@ -508,8 +515,10 @@ class Acc_Ledger extends jrn_def_sql { $prop=$this->get_propertie(); $pj_pref=$prop["jrn_def_pj_pref"]; + $padding=$prop['jrn_def_pj_padding']; $pj_seq=$this->get_last_pj()+1; - return $pj_pref.$pj_seq; + return $pj_pref.str_pad($pj_seq,$padding??0,'0',STR_PAD_LEFT); + } @@ -1584,7 +1593,7 @@ class Acc_Ledger extends jrn_def_sql if ($jr_id==false) throw new Exception(_('Balance incorrecte')); $acc_end->pj=$e_pj; - $this->pj=$acc_end->set_pj(); + $this->pj=$acc_end->update_receipt(); /* if e_suggest != e_pj then do not increment sequence */ if ($this->pj == $e_pj_suggest &&noalyss_strlentrim($e_pj)!=0) { @@ -2689,6 +2698,8 @@ class Acc_Ledger extends jrn_def_sql // use of quantity in ledger $quantity=new InputSwitch('p_jrn_quantity',$this->jrn_def_quantity); + // padding + $padding = new \INum ('p_jrn_padding',$this->jrn_def_pj_padding); require_once NOALYSS_TEMPLATE.'/param_jrn.php'; } @@ -2839,6 +2850,7 @@ class Acc_Ledger extends jrn_def_sql _("Attention, ce journal doit utiliser des montants négatifs")); $this->jrn_def_quantity=$http->extract('p_jrn_quantity','string',1); $jrn_def_pj_seq=$http->extract("jrn_def_pj_seq"); + $this->jrn_def_pj_padding=$http->extract('p_jrn_padding','number'); switch ($this->jrn_def_type) { case 'ACH': @@ -3016,7 +3028,7 @@ class Acc_Ledger extends jrn_def_sql $negative_warning->size="55"; // use of quantity in ledger $quantity=new InputSwitch('p_jrn_quantity',1); - + $padding = new \INum ('p_jrn_padding',5); require_once NOALYSS_TEMPLATE.'/param_jrn.php'; } @@ -3079,7 +3091,7 @@ class Acc_Ledger extends jrn_def_sql $this->jrn_def_negative_amount=$negative_amount; $this->jrn_def_negative_warning=$negative_warning; $this->jrn_enable=1; - + $this->jrn_def_pj_padding=$p_jrn_padding; switch ($this->jrn_def_type) { case 'ACH': diff --git a/include/class/acc_ledger_fin.class.php b/include/class/acc_ledger_fin.class.php index 288ee9025..394284953 100644 --- a/include/class/acc_ledger_fin.class.php +++ b/include/class/acc_ledger_fin.class.php @@ -979,7 +979,7 @@ class Acc_Ledger_Fin extends Acc_Ledger $acc_operation->pj=$e_pj; $jr_id=$acc_operation->insert_jrn(); - // $acc_operation->set_pj(); + // $acc_operation->update_receipt(); $this->db->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj, $jr_id)); $internal=$this->compute_internal_code($seq); diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index 61a883561..ad114e14f 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -916,7 +916,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger if ( ! $this->jr_id=$acc_operation->insert_jrn() ) { throw new Exception (_("Erreur de balance")); } - $this->pj=$acc_operation->set_pj(); + $this->pj=$acc_operation->update_receipt(); // Set Internal code $this->grpt_id=$seq; @@ -1052,7 +1052,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger // add an automatic PJ if ODS if ($acjrn->get_type()=="ODS") { $acc_pay->pj=$acjrn->guess_pj(); - $acc_pay->set_pj(); + $acc_pay->update_receipt(); } $r1=$this->get_id($internal); $r2=$this->get_id($acinternal); diff --git a/include/class/acc_ledger_sale.class.php b/include/class/acc_ledger_sale.class.php index c567bd3f3..5fa2f583a 100644 --- a/include/class/acc_ledger_sale.class.php +++ b/include/class/acc_ledger_sale.class.php @@ -627,7 +627,7 @@ class Acc_Ledger_Sale extends Acc_Ledger { throw new Exception (_("Erreur de balance")); } - $this->pj = $acc_operation->set_pj(); + $this->pj = $acc_operation->update_receipt(); /** * @@ -758,7 +758,7 @@ class Acc_Ledger_Sale extends Acc_Ledger { // add an automatic PJ if ODS if ($acjrn->get_type()=="ODS") { $acc_pay->pj=$acjrn->guess_pj(); - $acc_pay->set_pj(); + $acc_pay->update_receipt(); } $r1 = $this->get_id($internal); $r2 = $this->get_id($acinternal); diff --git a/include/class/acc_operation.class.php b/include/class/acc_operation.class.php index 0811cfff0..a09581c95 100644 --- a/include/class/acc_operation.class.php +++ b/include/class/acc_operation.class.php @@ -270,11 +270,11 @@ EOF; *\brief set the pj of a operation in jrn. the jr_id must be set *\note if the jr_id it fails */ - function set_pj() + function update_receipt() { if ( noalyss_strlentrim($this->pj) == 0 ) { - echo __LINE__."debug {$this->pj} est vide"; + // echo __LINE__."debug {$this->pj} est vide"; $sql="update jrn set jr_pj_number=$1 where jr_id=$2"; $this->db->exec_sql($sql,array(null,$this->jr_id)); return ''; @@ -307,9 +307,14 @@ EOF; $flag=2; break; } + /* get padding */ + $padding=$this->db->get_value("select jrn_def_pj_padding from jrn_def where jrn_def_id=$1", + array($this->jrn)); $seq=$this->db->get_next_seq('s_jrn_pj'.$this->jrn); - $this->pj=$pref.$seq; + + // see Acc_Ledger::guess_pj + $this->pj=$pref.str_pad($seq,$padding??0,'0',STR_PAD_LEFT); /* check if the new pj numb exist */ $c=$this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 and jr_def_id=$2 diff --git a/include/class/follow_up.class.php b/include/class/follow_up.class.php index 128311e78..c058174ad 100644 --- a/include/class/follow_up.class.php +++ b/include/class/follow_up.class.php @@ -1345,7 +1345,7 @@ class Follow_Up /** * @brief display a form with the saved search - * @return voidµ + * @return void */ public static function display_saved_search() { diff --git a/include/constant.php b/include/constant.php index 108684071..fa0cbef37 100644 --- a/include/constant.php +++ b/include/constant.php @@ -28,7 +28,7 @@ global $version_noalyss; define('NOALYSS_VERSION', 9300 ); // Database schema version -define("DBVERSION", 200); +define("DBVERSION", 201); // version for MONO_DATABASE define("MONO_DATABASE", 25); diff --git a/include/database/jrn_def_sql.class.php b/include/database/jrn_def_sql.class.php index 88602267b..24cabd967 100644 --- a/include/database/jrn_def_sql.class.php +++ b/include/database/jrn_def_sql.class.php @@ -59,6 +59,7 @@ class Jrn_def_SQL extends Table_Data_SQL , "jrn_def_negative_amount"=>"jrn_def_negative_amount" , "jrn_def_negative_warning"=>"jrn_def_negative_warning" , 'jrn_def_quantity'=>'jrn_def_quantity' + ,'jrn_def_pj_padding'=>'jrn_def_pj_padding' ); /* * Type of columns @@ -85,6 +86,7 @@ class Jrn_def_SQL extends Table_Data_SQL , "jrn_def_negative_amount"=>"text" ,"jrn_def_negative_warning"=>"text" ,'jrn_def_quantity'=>"numeric" + ,'jrn_def_pj_padding'=>'numeric' ); $this->default=array( diff --git a/include/sql/patch/upgrade200.sql b/include/sql/patch/upgrade200.sql new file mode 100644 index 000000000..a30bc79b4 --- /dev/null +++ b/include/sql/patch/upgrade200.sql @@ -0,0 +1,7 @@ +begin; + +alter table jrn_def add column jrn_def_pj_padding int; +update jrn_def set jrn_def_pj_padding=0; +alter table jrn_def alter jrn_def_pj_padding set default 0; +insert into version (val,v_description) values (201,'receipt with padding '); +commit; \ No newline at end of file diff --git a/include/template/param_jrn.php b/include/template/param_jrn.php index 259988056..d4dbb4a3a 100644 --- a/include/template/param_jrn.php +++ b/include/template/param_jrn.php @@ -158,6 +158,15 @@ endif;