Task #0002376: Numéro de pièce, remplissage avec des 0 code : renommage de set_pj par update_receipt

This commit is contained in:
sparkyx 2024-09-03 17:59:50 +02:00
parent 1d3b37db58
commit 28ee90c45d
13 changed files with 109 additions and 21 deletions

View file

@ -85,6 +85,13 @@ class Acc_Ledger extends jrn_def_sql
$this->currency_id=0; $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() function get_last_pj()
{ {
if (isNumber($this->id)==0) if (isNumber($this->id)==0)
@ -417,7 +424,7 @@ class Acc_Ledger extends jrn_def_sql
$reverse_accOp->set_id($reverse_id); $reverse_accOp->set_id($reverse_id);
$reverse_accOp->pj=$old_receipt['jr_pj_number']; $reverse_accOp->pj=$old_receipt['jr_pj_number'];
$reverse_accOp->jrn=$old_receipt['jr_def_id']; $reverse_accOp->jrn=$old_receipt['jr_def_id'];
$reverse_accOp->set_pj(); $reverse_accOp->update_receipt();
// Check return code // Check return code
} catch (\Exception $e){ } catch (\Exception $e){
throw new \Exception('Echec extourne'); throw new \Exception('Echec extourne');
@ -508,8 +515,10 @@ class Acc_Ledger extends jrn_def_sql
{ {
$prop=$this->get_propertie(); $prop=$this->get_propertie();
$pj_pref=$prop["jrn_def_pj_pref"]; $pj_pref=$prop["jrn_def_pj_pref"];
$padding=$prop['jrn_def_pj_padding'];
$pj_seq=$this->get_last_pj()+1; $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) if ($jr_id==false)
throw new Exception(_('Balance incorrecte')); throw new Exception(_('Balance incorrecte'));
$acc_end->pj=$e_pj; $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 e_suggest != e_pj then do not increment sequence */
if ($this->pj == $e_pj_suggest &&noalyss_strlentrim($e_pj)!=0) 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 // use of quantity in ledger
$quantity=new InputSwitch('p_jrn_quantity',$this->jrn_def_quantity); $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'; 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")); _("Attention, ce journal doit utiliser des montants négatifs"));
$this->jrn_def_quantity=$http->extract('p_jrn_quantity','string',1); $this->jrn_def_quantity=$http->extract('p_jrn_quantity','string',1);
$jrn_def_pj_seq=$http->extract("jrn_def_pj_seq"); $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) switch ($this->jrn_def_type)
{ {
case 'ACH': case 'ACH':
@ -3016,7 +3028,7 @@ class Acc_Ledger extends jrn_def_sql
$negative_warning->size="55"; $negative_warning->size="55";
// use of quantity in ledger // use of quantity in ledger
$quantity=new InputSwitch('p_jrn_quantity',1); $quantity=new InputSwitch('p_jrn_quantity',1);
$padding = new \INum ('p_jrn_padding',5);
require_once NOALYSS_TEMPLATE.'/param_jrn.php'; 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_amount=$negative_amount;
$this->jrn_def_negative_warning=$negative_warning; $this->jrn_def_negative_warning=$negative_warning;
$this->jrn_enable=1; $this->jrn_enable=1;
$this->jrn_def_pj_padding=$p_jrn_padding;
switch ($this->jrn_def_type) switch ($this->jrn_def_type)
{ {
case 'ACH': case 'ACH':

View file

@ -979,7 +979,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
$acc_operation->pj=$e_pj; $acc_operation->pj=$e_pj;
$jr_id=$acc_operation->insert_jrn(); $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)); $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); $internal=$this->compute_internal_code($seq);

View file

@ -916,7 +916,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
if ( ! $this->jr_id=$acc_operation->insert_jrn() ) { if ( ! $this->jr_id=$acc_operation->insert_jrn() ) {
throw new Exception (_("Erreur de balance")); throw new Exception (_("Erreur de balance"));
} }
$this->pj=$acc_operation->set_pj(); $this->pj=$acc_operation->update_receipt();
// Set Internal code // Set Internal code
$this->grpt_id=$seq; $this->grpt_id=$seq;
@ -1052,7 +1052,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
// add an automatic PJ if ODS // add an automatic PJ if ODS
if ($acjrn->get_type()=="ODS") { if ($acjrn->get_type()=="ODS") {
$acc_pay->pj=$acjrn->guess_pj(); $acc_pay->pj=$acjrn->guess_pj();
$acc_pay->set_pj(); $acc_pay->update_receipt();
} }
$r1=$this->get_id($internal); $r1=$this->get_id($internal);
$r2=$this->get_id($acinternal); $r2=$this->get_id($acinternal);

View file

@ -627,7 +627,7 @@ class Acc_Ledger_Sale extends Acc_Ledger {
throw new Exception (_("Erreur de balance")); 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 // add an automatic PJ if ODS
if ($acjrn->get_type()=="ODS") { if ($acjrn->get_type()=="ODS") {
$acc_pay->pj=$acjrn->guess_pj(); $acc_pay->pj=$acjrn->guess_pj();
$acc_pay->set_pj(); $acc_pay->update_receipt();
} }
$r1 = $this->get_id($internal); $r1 = $this->get_id($internal);
$r2 = $this->get_id($acinternal); $r2 = $this->get_id($acinternal);

View file

@ -270,11 +270,11 @@ EOF;
*\brief set the pj of a operation in jrn. the jr_id must be set *\brief set the pj of a operation in jrn. the jr_id must be set
*\note if the jr_id it fails *\note if the jr_id it fails
*/ */
function set_pj() function update_receipt()
{ {
if ( noalyss_strlentrim($this->pj) == 0 ) 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"; $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
$this->db->exec_sql($sql,array(null,$this->jr_id)); $this->db->exec_sql($sql,array(null,$this->jr_id));
return ''; return '';
@ -307,9 +307,14 @@ EOF;
$flag=2; $flag=2;
break; 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); $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 */ /* 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 $c=$this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 and jr_def_id=$2

View file

@ -1345,7 +1345,7 @@ class Follow_Up
/** /**
* @brief display a form with the saved search * @brief display a form with the saved search
* @return voidµ * @return void
*/ */
public static function display_saved_search() public static function display_saved_search()
{ {

View file

@ -28,7 +28,7 @@ global $version_noalyss;
define('NOALYSS_VERSION', 9300 ); define('NOALYSS_VERSION', 9300 );
// Database schema version // Database schema version
define("DBVERSION", 200); define("DBVERSION", 201);
// version for MONO_DATABASE // version for MONO_DATABASE
define("MONO_DATABASE", 25); define("MONO_DATABASE", 25);

View file

@ -59,6 +59,7 @@ class Jrn_def_SQL extends Table_Data_SQL
, "jrn_def_negative_amount"=>"jrn_def_negative_amount" , "jrn_def_negative_amount"=>"jrn_def_negative_amount"
, "jrn_def_negative_warning"=>"jrn_def_negative_warning" , "jrn_def_negative_warning"=>"jrn_def_negative_warning"
, 'jrn_def_quantity'=>'jrn_def_quantity' , 'jrn_def_quantity'=>'jrn_def_quantity'
,'jrn_def_pj_padding'=>'jrn_def_pj_padding'
); );
/* /*
* Type of columns * Type of columns
@ -85,6 +86,7 @@ class Jrn_def_SQL extends Table_Data_SQL
, "jrn_def_negative_amount"=>"text" , "jrn_def_negative_amount"=>"text"
,"jrn_def_negative_warning"=>"text" ,"jrn_def_negative_warning"=>"text"
,'jrn_def_quantity'=>"numeric" ,'jrn_def_quantity'=>"numeric"
,'jrn_def_pj_padding'=>'numeric'
); );
$this->default=array( $this->default=array(

View file

@ -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;

View file

@ -158,6 +158,15 @@ endif;
<TD> <TD>
<?php echo $pj_pref; ?> <?php echo $pj_pref; ?>
</TD> </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> </TR>
<?php if ( $new == 0 ) : ?> <?php if ( $new == 0 ) : ?>
@ -167,7 +176,8 @@ endif;
<?php echo Icon_Action::infobulle(40);?> <?php echo Icon_Action::infobulle(40);?>
</TD> </TD>
<TD> <TD>
<?php echo $last_seq?>
<?php echo str_pad($last_seq,$this->jrn_def_pj_padding??0,'0',STR_PAD_LEFT)?>
</TD> </TD>
</TR> </TR>

View file

@ -1,4 +1,2 @@
begin;
select replace_menu_code('CCARDAT','C0CARD');

View file

@ -263,7 +263,7 @@ class Acc_LedgerTest extends TestCase
$this->object->id=2; $this->object->id=2;
$array=$this->object->get_propertie(); $array=$this->object->get_propertie();
// there are 16 columns in jrn_def // there are 16 columns in jrn_def
$this->assertEquals(count($array),21); $this->assertEquals(count($array),22);
$this->object->id=0; $this->object->id=0;
$array=$this->object->get_propertie(); $array=$this->object->get_propertie();
$this->assertEquals(null,$array); $this->assertEquals(null,$array);
@ -465,6 +465,7 @@ class Acc_LedgerTest extends TestCase
"FIN_FICHE_DEF"=>[2,3,4], "FIN_FICHE_DEF"=>[2,3,4],
"defaultCurrency"=>0, "defaultCurrency"=>0,
"p_jrn_deb_max_line" => 10, "p_jrn_deb_max_line" => 10,
"p_jrn_padding" => 10
]; ];
// - update it // - update it
$acc_ledger=new Acc_Ledger($g_connection,-1); $acc_ledger=new Acc_Ledger($g_connection,-1);
@ -484,7 +485,8 @@ class Acc_LedgerTest extends TestCase
"jrn_def_pj_seq" => 0, "jrn_def_pj_seq" => 0,
"jrn_enable" => 0, "jrn_enable" => 0,
"FIN_FICHEDEB" =>array(2,3,4), "FIN_FICHEDEB" =>array(2,3,4),
"defaultCurrency"=>0 "defaultCurrency"=>0,
"p_jrn_padding" => 10
); );
$acc_ledger->update($update); $acc_ledger->update($update);
@ -899,7 +901,7 @@ class Acc_LedgerTest extends TestCase
ob_end_clean(); ob_end_clean();
\Noalyss\Facility::save_file(__DIR__."/file", "acc_ledger-input_new.html", $result); \Noalyss\Facility::save_file(__DIR__."/file", "acc_ledger-input_new.html", $result);
$size=filesize(__DIR__."/file/acc_ledger-input_new.html"); $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, 'min_row'=>5,
'p_description'=>'LEDGER UNIT TEST', 'p_description'=>'LEDGER UNIT TEST',
'negative_amount'=>0, 'negative_amount'=>0,
"p_jrn_padding" => 10,
'negative_warning'=>'Warning']; 'negative_warning'=>'Warning'];
// clean ledger if exists // clean ledger if exists
@ -952,6 +955,7 @@ class Acc_LedgerTest extends TestCase
'min_row'=>5, 'min_row'=>5,
'p_description'=>'LEDGER UNIT TEST', 'p_description'=>'LEDGER UNIT TEST',
'negative_amount'=>0, 'negative_amount'=>0,
"p_jrn_padding" => 10,
'negative_warning'=>'Warning']; 'negative_warning'=>'Warning'];
$g_connection->exec_sql("delete from jrn_def where jrn_def_description=$1",['LEDGER UNIT TEST']); $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, 'min_row'=>5,
'p_description'=>'LEDGER UNIT TEST', 'p_description'=>'LEDGER UNIT TEST',
'negative_amount'=>0, 'negative_amount'=>0,
"p_jrn_padding" => 10,
'negative_warning'=>'Warning']; 'negative_warning'=>'Warning'];
// clean ledger if exists // clean ledger if exists
$g_connection->exec_sql("delete from jrn_def where jrn_def_name=$1",[$array['p_jrn_name']]); $g_connection->exec_sql("delete from jrn_def where jrn_def_name=$1",[$array['p_jrn_name']]);

View file

@ -312,4 +312,53 @@ class Acc_OperationTest extends TestCase
$result); $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'] ]);
}
} }