[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 18/86: Task #0002376: Numéro de pièce, rempli
From: |
dwm |
Subject: |
[Noalyss-commit] [noalyss] 18/86: Task #0002376: Numéro de pièce, remplissage avec des 0 code : renommage de set_pj par update_receipt |
Date: |
Thu, 19 Sep 2024 02:41:49 -0400 (EDT) |
sparkyx pushed a commit to branch unstable
in repository noalyss.
commit fd55fb8f35973bc3dd43d9111ab0cdadb4b24323
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Tue Sep 3 17:59:50 2024 +0200
Task #0002376: Numéro de pièce, remplissage avec des 0 code : renommage de
set_pj par update_receipt
---
include/class/acc_ledger.class.php | 22 +++++++++---
include/class/acc_ledger_fin.class.php | 2 +-
include/class/acc_ledger_purchase.class.php | 4 +--
include/class/acc_ledger_sale.class.php | 4 +--
include/class/acc_operation.class.php | 11 ++++--
include/class/follow_up.class.php | 2 +-
include/constant.php | 2 +-
include/database/jrn_def_sql.class.php | 2 ++
include/sql/patch/upgrade200.sql | 7 ++++
include/template/param_jrn.php | 12 ++++++-
sql/upgrade.sql | 2 --
unit-test/include/class/acc_ledgerTest.php | 11 ++++--
unit-test/include/class/acc_operationTest.php | 49 +++++++++++++++++++++++++++
13 files changed, 109 insertions(+), 21 deletions(-)
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;
<TD>
<?php echo $pj_pref; ?>
</TD>
+</TR>
+ <tr>
+ <td>
+ <?=_("Nombre de caractère du numéro de pièce, remplissage avec des 0
")?>
+ </td>
+ <td>
+ <?=$padding->input()?>
+ </td>
+ </tr>
</TR>
<?php if ( $new == 0 ) : ?>
@@ -167,7 +176,8 @@ endif;
<?php echo Icon_Action::infobulle(40);?>
</TD>
<TD>
- <?php echo $last_seq?>
+
+ <?php echo
str_pad($last_seq,$this->jrn_def_pj_padding??0,'0',STR_PAD_LEFT)?>
</TD>
</TR>
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 0a1bfa1c3..139597f9c 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -1,4 +1,2 @@
-begin;
-select replace_menu_code('CCARDAT','C0CARD');
diff --git a/unit-test/include/class/acc_ledgerTest.php
b/unit-test/include/class/acc_ledgerTest.php
index 5705ff14d..b8bb5d86c 100644
--- a/unit-test/include/class/acc_ledgerTest.php
+++ b/unit-test/include/class/acc_ledgerTest.php
@@ -263,7 +263,7 @@ class Acc_LedgerTest extends TestCase
$this->object->id=2;
$array=$this->object->get_propertie();
// there are 16 columns in jrn_def
- $this->assertEquals(count($array),21);
+ $this->assertEquals(count($array),22);
$this->object->id=0;
$array=$this->object->get_propertie();
$this->assertEquals(null,$array);
@@ -465,6 +465,7 @@ class Acc_LedgerTest extends TestCase
"FIN_FICHE_DEF"=>[2,3,4],
"defaultCurrency"=>0,
"p_jrn_deb_max_line" => 10,
+ "p_jrn_padding" => 10
];
// - update it
$acc_ledger=new Acc_Ledger($g_connection,-1);
@@ -484,7 +485,8 @@ class Acc_LedgerTest extends TestCase
"jrn_def_pj_seq" => 0,
"jrn_enable" => 0,
"FIN_FICHEDEB" =>array(2,3,4),
- "defaultCurrency"=>0
+ "defaultCurrency"=>0,
+ "p_jrn_padding" => 10
);
$acc_ledger->update($update);
@@ -899,7 +901,7 @@ class Acc_LedgerTest extends TestCase
ob_end_clean();
\Noalyss\Facility::save_file(__DIR__."/file",
"acc_ledger-input_new.html", $result);
$size=filesize(__DIR__."/file/acc_ledger-input_new.html");
- $this->assertTrue($size == 15664 ," output input_new is not what it
is expected");
+ $this->assertTrue($size == 15948 ," output input_new is not what it
is expected");
}
@@ -919,6 +921,7 @@ class Acc_LedgerTest extends TestCase
'min_row'=>5,
'p_description'=>'LEDGER UNIT TEST',
'negative_amount'=>0,
+ "p_jrn_padding" => 10,
'negative_warning'=>'Warning'];
// clean ledger if exists
@@ -952,6 +955,7 @@ class Acc_LedgerTest extends TestCase
'min_row'=>5,
'p_description'=>'LEDGER UNIT TEST',
'negative_amount'=>0,
+ "p_jrn_padding" => 10,
'negative_warning'=>'Warning'];
$g_connection->exec_sql("delete from jrn_def where
jrn_def_description=$1",['LEDGER UNIT TEST']);
@@ -980,6 +984,7 @@ class Acc_LedgerTest extends TestCase
'min_row'=>5,
'p_description'=>'LEDGER UNIT TEST',
'negative_amount'=>0,
+ "p_jrn_padding" => 10,
'negative_warning'=>'Warning'];
// clean ledger if exists
$g_connection->exec_sql("delete from jrn_def where
jrn_def_name=$1",[$array['p_jrn_name']]);
diff --git a/unit-test/include/class/acc_operationTest.php
b/unit-test/include/class/acc_operationTest.php
index 5bfbf27da..ba9c9335e 100644
--- a/unit-test/include/class/acc_operationTest.php
+++ b/unit-test/include/class/acc_operationTest.php
@@ -312,4 +312,53 @@ class Acc_OperationTest extends TestCase
$result);
}
+ function testUpdate_receipt() {
+ global $g_connection;
+
+ $receipt=$g_connection->get_value("select jr_pj_number from jrn where
jr_id=250");
+ // $this->assertEquals('BP19-1',$receipt,'Receipt number incorrect');
+ $acc_operation=new Acc_Operation($g_connection);
+ $acc_operation->set_id(250);
+ $this->pj="";
+ $acc_operation->update_receipt();
+ $new_receipt=$g_connection->get_value("select jr_pj_number from jrn
where jr_id=250");
+ $this->assertTrue($new_receipt== null,'receipt not set to null ');
+
+ $acc_operation->pj='BP-99';
+ $acc_operation->update_receipt();
+ $new_receipt=$g_connection->get_value("select jr_pj_number from jrn
where jr_id=250");
+ $this->assertTrue($new_receipt != null,'receipt not compute');
+ $this->assertTrue($new_receipt =='BP-99',"[$new_receipt]".'receipt not
set');
+
+ // padding 5
+ $ledger=new \Acc_Ledger($g_connection, 83);
+ $save_prop=$ledger->get_propertie();
+ $g_connection->exec_sql('update jrn_def set jrn_def_pj_padding = 5
where jrn_def_id=83');
+ $acc_operation->pj=$ledger->guess_pj();
+ $acc_operation->update_receipt();
+ $new_receipt=$g_connection->get_value("select jr_pj_number from jrn
where jr_id=250");
+ $this->assertTrue($new_receipt =='BP19-00003',"[$new_receipt] receipt
not set");
+
+ // padding 3
+ $g_connection->exec_sql('update jrn_def set jrn_def_pj_padding = 3
where jrn_def_id=83');
+ $acc_operation->pj=$ledger->guess_pj();
+ $acc_operation->update_receipt();
+ $new_receipt=$g_connection->get_value("select jr_pj_number from jrn
where jr_id=250");
+ $this->assertTrue($new_receipt =='BP19-003',"[$new_receipt] receipt
not set");
+
+ // default no padding
+ $g_connection->exec_sql('update jrn_def set jrn_def_pj_padding = 0
where jrn_def_id=83');
+ $acc_operation->pj=$ledger->guess_pj();
+ $acc_operation->update_receipt();
+ $new_receipt=$g_connection->get_value("select jr_pj_number from jrn
where jr_id=250");
+ $this->assertTrue($new_receipt =='BP19-3',"[$new_receipt] receipt not
set");
+
+ // reset to original value
+ $acc_operation->pj=$receipt;
+ $acc_operation->update_receipt();
+ $g_connection->exec_sql('update jrn_def set jrn_def_pj_padding = $1
where jrn_def_id=83',[$save_prop['jrn_def_pj_padding'] ]);
+
+
+ }
+
}
- [Noalyss-commit] [noalyss] 49/86: Improve message, (continued)
- [Noalyss-commit] [noalyss] 49/86: Improve message, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 55/86: Merge branch 'stable' into unstable, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 57/86: Bug : when only one extension, it fails, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 50/86: Translation, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 63/86: Bug : when only one extension, it fails, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 70/86: Cosmetic, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 82/86: Change color border, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 83/86: Change color border, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 81/86: Cosmetic : menu and module , animate, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 86/86: Cosmetic g_failed, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 18/86: Task #0002376: Numéro de pièce, remplissage avec des 0 code : renommage de set_pj par update_receipt,
dwm <=
- [Noalyss-commit] [noalyss] 47/86: Improve : creation db , mod1 , mod2 and account_repository remove the alter table disable all triggers, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 08/86: CFGMENU : bug cannot update menu, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 54/86: Translation Cosmetic: without z-index, the class col is behind the autocomplete div in COMPANY Fix Create user , password not set Improve : creation db , mod1 , mod2 and account_repository remove the alter table disable all triggers Bug : some db doesn't have the view v_quant_detail Fix bug CSV for P1TVA , wrong header, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 52/86: Translation Cosmetic: without z-index, the class col is behind the autocomplete div in COMPANY Fix Create user , password not set Improve : creation db , mod1 , mod2 and account_repository remove the alter table disable all triggers Bug : some db doesn't have the view v_quant_detail Fix bug CSV for P1TVA , wrong header, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 21/86: Task #0002376: Numéro de pièce, remplissage avec des 0 code : renommage de set_pj par update_receipt, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 45/86: Cosmetic: without z-index, the class col is behind the autocomplete div in COMPANY, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 38/86: Fix bug CSV for P1TVA , wrong header, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 25/86: Cosmetic add inner_box2, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 36/86: RECONCILE : VAT ND not in account, dwm, 2024/09/19
- [Noalyss-commit] [noalyss] 39/86: Fix bug CSV for P1TVA , wrong header, dwm, 2024/09/19