[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 04/07: Optional attribute for using quantity
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 04/07: Optional attribute for using quantity |
Date: |
Sat, 3 Sep 2022 17:16:04 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 868d78a862ced8cac31954a965951f04e39d3c0a
Author: Dany De Bontridder <dany@alchimerys.be>
AuthorDate: Sat Sep 3 18:49:17 2022 +0200
Optional attribute for using quantity
---
include/class/acc_ledger.class.php | 111 +++++++++++++++++++----------
include/constant.php | 2 +-
include/database/jrn_def_sql.class.php | 2 +
include/template/param_jrn.php | 29 ++++----
unit-test/global.php | 1 -
unit-test/include/class/acc_ledgerTest.php | 34 ++++++++-
6 files changed, 125 insertions(+), 54 deletions(-)
diff --git a/include/class/acc_ledger.class.php
b/include/class/acc_ledger.class.php
index a5ba23aaa..80bec9839 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -2575,8 +2575,8 @@ class Acc_Ledger extends jrn_def_sql
/* Load the card */
$card=$this->get_fiche_def();
- $rdeb=explode(',', $card['deb']);
- $rcred=explode(',', $card['cred']);
+ $rdeb=noalyss_explode(',', $card['deb']);
+ $rcred=noalyss_explode(',', $card['cred']);
/* Numbering (only FIN) */
$num_op=new ICheckBox('numb_operation');
if ($this->jrn_def_num_op==1)
@@ -2607,8 +2607,11 @@ class Acc_Ledger extends jrn_def_sql
$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;
-
+ $negative_warning->size=55;
+
+ // use of quantity in ledger
+ $quantity=new InputSwitch('p_jrn_quantity',$this->jrn_def_quantity);
+
require_once NOALYSS_TEMPLATE.'/param_jrn.php';
}
@@ -2654,12 +2657,14 @@ class Acc_Ledger extends jrn_def_sql
*/
function verify_ledger($array)
{
-
- $p_jrn=$array['p_jrn'];
- $p_jrn_deb_max_line=$array['p_jrn_deb_max_line'];
- $p_jrn_name=$array['p_jrn_name'];
- $p_jrn_type=$array['p_jrn_type'];
-
+ $http=new HttpInput();
+ $http->set_array($array);
+ $p_jrn=$http->extract('p_jrn',);
+ $p_jrn_deb_max_line=$http->extract('p_jrn_deb_max_line');
+ $p_jrn_name=$http->extract('p_jrn_name');
+ $p_jrn_type=$http->extract('p_jrn_type');
+ $p_jrn_quantity=$http->extract('p_jrn_quantity','number',0);
+
try
{
if (isNumber($p_jrn)==0)
@@ -2711,39 +2716,55 @@ class Acc_Ledger extends jrn_def_sql
* @param type $array normally post
* @see verify_ledger
*/
- function update($array='')
+ function update($array=null)
{
- if ($array==null)
- throw new Exception('save cannot use a empty array');
+
$this->jrn_def_quantity=(!isset($this->jrn_def_quantity)||$this->jrn_def_quantity===null)?1:$this->jrn_def_quantity;
- extract($array, EXTR_SKIP);
- $this->jrn_def_id=$p_jrn;
- $this->jrn_def_name=$p_jrn_name;
- $this->jrn_def_ech_lib=$p_ech_lib;
+ if ($array==null) {
+ // update with the current value
+ parent::update();
+ return;
+ }
+
+ $http=new HttpInput();
+ $http->set_array($array);
+ $p_jrn_deb_max_line=$http->extract("p_jrn_deb_max_line","number",-1);
+ $min_row=$http->extract("min_row");
+
+ $this->jrn_def_id=$http->extract('p_jrn');
+ $this->jrn_def_name=$http->extract('p_jrn_name');
+ $this->jrn_def_ech_lib=$http->extract('p_ech_lib');
$this->jrn_def_max_line_deb=($p_jrn_deb_max_line<1)?1:$p_jrn_deb_max_line;
- $this->jrn_def_type=$p_jrn_type;
- $this->jrn_def_pj_pref=$jrn_def_pj_pref;
+ $this->jrn_def_type=$http->extract('p_jrn_type');
+ $this->jrn_def_pj_pref=$http->extract('jrn_def_pj_pref');
$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_description=$http->extract('p_description');
+ $this->jrn_enable=$http->extract('jrn_enable');
$this->currency_id=0;
-
$this->jrn_def_negative_amount=(isset($negative_amount))?$negative_amount:'0';
- $this->jrn_def_negative_warning=(isset
($negative_warning))?$negative_warning:_("Attention, ce journal doit utiliser
des montants négatifs");
-
+
$this->jrn_def_negative_amount=$http->extract('negative_amount','string',0);
+
$this->jrn_def_negative_warning=$http->extract("negative_warning",'string',
+ _("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");
switch ($this->jrn_def_type)
{
case 'ACH':
-
$this->jrn_def_fiche_cred=(isset($ACH_FICHECRED))?join(',',$ACH_FICHECRED):'';
-
$this->jrn_def_fiche_deb=(isset($ACH_FICHEDEB))?join(',',$ACH_FICHEDEB):"";
+ $ACH_FICHECRED=$http->extract('ACH_FICHECRED','array',array());
+ $ACH_FICHEDEB=$http->extract('ACH_FICHEDEB','array',array());
+
$this->jrn_def_fiche_cred=(!empty($ACH_FICHECRED))?join(',',$ACH_FICHECRED):'';
+
$this->jrn_def_fiche_deb=(!empty($ACH_FICHEDEB))?join(',',$ACH_FICHEDEB):"";
break;
case 'VEN':
-
$this->jrn_def_fiche_cred=(isset($VEN_FICHECRED))?join(',',$VEN_FICHECRED):'';
-
$this->jrn_def_fiche_deb=(isset($VEN_FICHEDEB))?join(',',$VEN_FICHEDEB):"";
+ $VEN_FICHECRED=$http->extract('VEN_FICHECRED','array',array());
+ $VEN_FICHEDEB=$http->extract('VEN_FICHEDEB','array',array());
+
$this->jrn_def_fiche_cred=(!empty($VEN_FICHECRED))?join(',',$VEN_FICHECRED):'';
+
$this->jrn_def_fiche_deb=(!empty($VEN_FICHEDEB))?join(',',$VEN_FICHEDEB):"";
break;
case 'ODS':
- $this->jrn_def_class_deb=$p_jrn_class_deb;
-
$this->jrn_def_fiche_deb=(isset($ODS_FICHEDEB))?join(',',$ODS_FICHEDEB):''; ;
+
$this->jrn_def_class_deb=$http->extract('p_jrn_class_deb','string');
+ $ODS_FICHEDEB=$http->extract('ODS_FICHEDEB','array',array());
+
$this->jrn_def_fiche_deb=(!empty($ODS_FICHEDEB))?join(',',$ODS_FICHEDEB):''; ;
$this->jrn_def_fiche_cred=null;
break;
@@ -2752,10 +2773,11 @@ class Acc_Ledger extends jrn_def_sql
$result=$a->get_by_qcode(trim(strtoupper($_POST['bank'])),
false);
$bank=$a->id;
$this->jrn_def_bank=$bank;
-
$this->jrn_def_fiche_deb=(isset($FIN_FICHEDEB))?join(',',$FIN_FICHEDEB):"";
+ $FIN_FICHEDEB=$http->extract('FIN_FICHEDEB','array',array());
+
$this->jrn_def_fiche_deb=(!empty($FIN_FICHEDEB))?join(',',$FIN_FICHEDEB):"";
if ($result==-1)
throw new Exception(_("Aucun compte en banque n'est
donné"));
- $this->jrn_def_num_op=(isset($numb_operation))?1:0;
+
$this->jrn_def_num_op=$http->extract('numb_operation','string',0);
// if nb operation == 0 then update currency_id
$nb_operation = $this->db->get_value("select count(*) from jrn
where jr_def_id=$1",
[$this->jrn_def_id]);
@@ -2775,7 +2797,7 @@ class Acc_Ledger extends jrn_def_sql
//Reset sequence if needed
if ($jrn_def_pj_seq!=0)
{
- $Res=$this->db->alter_seq("s_jrn_pj".$p_jrn, $jrn_def_pj_seq);
+ $Res=$this->db->alter_seq("s_jrn_pj".$this->jrn_def_id,
$jrn_def_pj_seq);
}
}
/**
@@ -2813,7 +2835,6 @@ class Acc_Ledger extends jrn_def_sql
$previous_p_jrn_name=$http->post('p_jrn_name', "string", '');
$previous_p_jrn_type=$http->post("p_jrn_type", "string", "");
// }
- global $g_user;
$f_add_button=new ISmallButton('add_card');
$f_add_button->label=_('Créer une nouvelle fiche');
$f_add_button->tabindex=-1;
@@ -2899,7 +2920,10 @@ class Acc_Ledger extends jrn_def_sql
$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;
+ $negative_warning->size="55";
+ // use of quantity in ledger
+ $quantity=new InputSwitch('p_jrn_quantity',1);
+
require_once NOALYSS_TEMPLATE.'/param_jrn.php';
}
@@ -2958,7 +2982,7 @@ class Acc_Ledger extends jrn_def_sql
$this->currency_id=$defaultCurrency;
break;
}
-
+
$this->jrn_def_quantity=(!isset($this->jrn_def_quantity)||$this->jrn_def_quantity==null)?1:$this->jrn_def_quantity;
parent::insert();
}
@@ -3239,6 +3263,21 @@ class Acc_Ledger extends jrn_def_sql
{
return $this->db->get_value("select jrn_enable from jrn_def where
jrn_def_id=$1",[$this->id]);
}
+ /**
+ * Check if a ledger is enabled , 1 for yes and 0 if disabled
+ */
+ function has_quantity()
+ {
+ return $this->jrn_def_quantity;
+ }
+ /**
+ * @brief set quantity for the ledger to 1 or 0,
+ * @note do not save in the DB
+ */
+ function set_quantity($p_value)
+ {
+ $this->jrn_def_quantity=$p_value;
+ }
/**
* Check if the operation is used in the table quant*
* @param integer $p_grpt_id
diff --git a/include/constant.php b/include/constant.php
index c84ad6a07..302f249dd 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -115,7 +115,7 @@ if (!defined("NOALYSS_PACKAGE_REPOSITORY")) {
if (!defined("SYSINFO_DISPLAY")) {
define("SYSINFO_DISPLAY", TRUE);
}
-define("DBVERSION", 176);
+define("DBVERSION", 177);
define("MONO_DATABASE", 25);
define("DBVERSIONREPO", 20);
define('NOTFOUND', '--not found--');
diff --git a/include/database/jrn_def_sql.class.php
b/include/database/jrn_def_sql.class.php
index 0fb862756..88602267b 100644
--- a/include/database/jrn_def_sql.class.php
+++ b/include/database/jrn_def_sql.class.php
@@ -58,6 +58,7 @@ class Jrn_def_SQL extends Table_Data_SQL
, "currency_id"=>"currency_id"
, "jrn_def_negative_amount"=>"jrn_def_negative_amount"
, "jrn_def_negative_warning"=>"jrn_def_negative_warning"
+ , 'jrn_def_quantity'=>'jrn_def_quantity'
);
/*
* Type of columns
@@ -83,6 +84,7 @@ class Jrn_def_SQL extends Table_Data_SQL
, "currency_id"=>"numeric"
, "jrn_def_negative_amount"=>"text"
,"jrn_def_negative_warning"=>"text"
+ ,'jrn_def_quantity'=>"numeric"
);
$this->default=array(
diff --git a/include/template/param_jrn.php b/include/template/param_jrn.php
index 04a62068a..259988056 100644
--- a/include/template/param_jrn.php
+++ b/include/template/param_jrn.php
@@ -101,6 +101,8 @@ if ( $type == 'ACH' || $type == 'VEN'||$new):
echo $negative->input();
?>
</td>
+
+
</tr>
<tr id="row_warning">
<td style="white-space: nowrap">
@@ -110,6 +112,17 @@ if ( $type == 'ACH' || $type == 'VEN'||$new):
<?php echo $negative_warning->input();?>
</td>
</tr>
+ <tr>
+ <td>
+ <?php echo _('Utilisation des quantités')?>
+ </td>
+ <td>
+
+ <?php
+ echo $quantity->input();
+ ?>
+ </td>
+ </tr>
<?php
endif;
?>
@@ -225,7 +238,7 @@ endif;
for ($i=0;$i<$num;$i++) {
$res=$cn->fetch($i);
$CHECKED=" unchecked";
- foreach ( $rdeb as $element) {
+ foreach ( $rdeb as $element) {
if ( $element == $res['fd_id'] ) {
$CHECKED="CHECKED";
break;
@@ -346,12 +359,7 @@ endif;
printf ('<TD> <INPUT TYPE="CHECKBOX" VALUE="%s" NAME="ODS_FICHEDEB[]"
class="ods_fichedeb" %s>%s</TD>',
$res['fd_id'],$CHECKED,$res['fd_label']);
$CHECKED=" unchecked";
- foreach ( $rcred as $element) {
- if ( $element == $res['fd_id'] ) {
- $CHECKED="CHECKED";
- break;
- }
- }
+
echo '</TR>';
}
?>
@@ -397,12 +405,7 @@ endif;
printf ('<TD> <INPUT TYPE="CHECKBOX" VALUE="%s" NAME="FIN_FICHEDEB[]"
class="fin_fichedeb" %s>%s</TD>',
$res['fd_id'],$CHECKED,$res['fd_label']);
$CHECKED=" unchecked";
- foreach ( $rcred as $element) {
- if ( $element == $res['fd_id'] ) {
- $CHECKED="CHECKED";
- break;
- }
- }
+
echo '</TR>';
}
?>
diff --git a/unit-test/global.php b/unit-test/global.php
index 65d6ad84d..ff0db6b3c 100644
--- a/unit-test/global.php
+++ b/unit-test/global.php
@@ -40,5 +40,4 @@ $_SESSION[SESSION_KEY.'csv_encoding']='utf8';
$_SESSION[SESSION_KEY.'access_mode']='PC';
$g_user=new User($g_connection);
$_ENV['TMP']="/tmp/";
-
require_once __DIR__.'/facility.class.php';
diff --git a/unit-test/include/class/acc_ledgerTest.php
b/unit-test/include/class/acc_ledgerTest.php
index 1886b6f9a..1fae92b93 100644
--- a/unit-test/include/class/acc_ledgerTest.php
+++ b/unit-test/include/class/acc_ledgerTest.php
@@ -20,7 +20,7 @@ class Acc_LedgerTest extends TestCase
/**
* Get an operation
* @global type $g_connection
- * @return type
+ * @return type20
*/
private function get_jrn_id($p_ledger='ODS')
{
@@ -61,6 +61,15 @@ class Acc_LedgerTest extends TestCase
{
}
+
+ /**
+ * @backupGlobals enabled
+ */
+ static function tearDownAfterClass():void
+ {
+ global $g_connection;
+ $g_connection->exec_sql("update jrn_def set jrn_def_quantity=0 where
jrn_def_id=4");
+ }
/**
* covers ::existing_vat
* covers ::get_type
@@ -245,7 +254,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),20);
+ $this->assertEquals(count($array),21);
$this->object->id=0;
$array=$this->object->get_propertie();
$this->assertEquals(null,$array);
@@ -399,6 +408,25 @@ class Acc_LedgerTest extends TestCase
}
}
+ /**
+ * @testdox Check if the column jrn_def_quantity is properly saved
+ * @return void
+ * @throws Exception
+ */
+ function testQuantity()
+ {
+ global $g_connection;
+ $ledger=new Acc_Ledger($g_connection,4);
+ $ledger->set_quantity(1);
+ $ledger->update();
+ $ledger->load();
+ $this->assertEquals(1,$ledger->has_quantity(),'jrn_def_quantity is not
saved');
+ $ledger->set_quantity(0);
+ $ledger->update();
+ $ledger->load();
+ $this->assertEquals(0,$ledger->has_quantity(),'jrn_def_quantity is not
saved');
+
+ }
/**
* @covers Acc_Ledger::input
*/
@@ -822,7 +850,7 @@ class Acc_LedgerTest extends TestCase
\Noalyss\Facility::save_file(__DIR__."/file",
"acc_ledger-input_new.html", $result);
$size=filesize(__DIR__."/file/acc_ledger-input_new.html");
- $this->assertEquals(15969,$size," output input_new is not what it is
expected");
+ $this->assertEquals(16514,$size," output input_new is not what it is
expected");
}
/**
- [Noalyss-commit] [noalyss] branch master updated (407e05671 -> 9d5fc4180), Dany De Bontridder, 2022/09/03
- [Noalyss-commit] [noalyss] 03/07: Fix code : invalid CSS removed, Dany De Bontridder, 2022/09/03
- [Noalyss-commit] [noalyss] 06/07: New : 0002190: Journaux : option pour supprimer la quantité, Dany De Bontridder, 2022/09/03
- [Noalyss-commit] [noalyss] 02/07: Fix cosmetic bug : css_size will be used if it is null,, Dany De Bontridder, 2022/09/03
- [Noalyss-commit] [noalyss] 04/07: Optional attribute for using quantity,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 07/07: Merge branch 'devel', Dany De Bontridder, 2022/09/03
- [Noalyss-commit] [noalyss] 05/07: New : 0002190: Journaux : option pour supprimer la quantité, Dany De Bontridder, 2022/09/03
- [Noalyss-commit] [noalyss] 01/07: Compatibilty PHP8.1 deprecated explode with NULL, Dany De Bontridder, 2022/09/03