[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 217/219: Acc_Account : add function , improve
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 217/219: Acc_Account : add function , improve function verify |
Date: |
Mon, 18 Dec 2017 13:23:05 -0500 (EST) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit b8c4d3a5132c7062bc6c12e2c9fa0ffe7dc9b1f3
Author: Dany De Bontridder <address@hidden>
Date: Sun Dec 17 18:23:18 2017 +0100
Acc_Account : add function , improve function verify
---
include/class/acc_account.class.php | 51 ++++++++++++++++++++++++++++++++++---
1 file changed, 48 insertions(+), 3 deletions(-)
diff --git a/include/class/acc_account.class.php
b/include/class/acc_account.class.php
index b3b8057..1d1e15e 100644
--- a/include/class/acc_account.class.php
+++ b/include/class/acc_account.class.php
@@ -53,11 +53,14 @@ class Acc_Account
$this->db=$p_cn;
$id=-1;
if ( trim($pcm_val) != "" ) {
+ $pcm_val=$this->db->get_value("select format_account($1)",
+ array($pcm_val));
$id=$p_cn->get_value("select id from tmp_pcmn where
pcm_val=$1",[$pcm_val]);
}
if ( $id == "") { $id=-1;}
$this->data_sql=new Tmp_Pcmn_SQL($p_cn, $id);
$this->data_sql->pcm_val=$pcm_val;
+
}
public function get_parameter($p_string)
{
@@ -104,6 +107,22 @@ class Acc_Account
return $this->db->get_value($sql,array($p_value));
}
/**
+ * Find the parent of an account
+ * @return string (pcm_val)
+ */
+ function find_parent() {
+ $name=$this->data_sql->pcm_val;
+ $length_name=strlen($name);
+ $parent="";
+ for ($i = 1;$i <$length_name;$i++) {
+ $parent=mb_substr($name, 0, $length_name-$i);
+ $exist=$this->db->get_value("select count(*) from tmp_pcmn where
pcm_val=$1",[$parent]);
+ if ( $exist == 1) return $parent;
+ }
+
+ return $parent;
+ }
+ /**
* Check before inserting or updating
*/
function verify() {
@@ -112,15 +131,36 @@ class Acc_Account
[$this->data_sql->pcm_val,$this->data_sql->id]);
if ( $count > 0)
throw new Exception (_("Poste en double"),EXC_DUPLICATE);
+
if (trim($this->data_sql->pcm_lib)=="")
throw new Exception (_("Libellé vide"),EXC_PARAM_VALUE);
+
+ // can not depend of itself
+ if ( $this->data_sql->pcm_val_parent == $this->data_sql->pcm_val)
+ throw new Exception (_("Poste parent incorrect"),EXC_PARAM_VALUE);
+
+ if ( $this->data_sql->pcm_val_parent == "") {
+ $account=$this->find_parent();
+ $this->data_sql->pcm_val_parent=$account;
+ if ($account == "")
+ throw new Exception (_("Poste Parent n'existe
pas"),EXC_PARAM_VALUE);
+ }
+
+ // purpose not clear
if ( $this->data_sql->count(" where pcm_val = $1 and pcm_val <> $2",
[$this->data_sql->pcm_val_parent,$this->data_sql->pcm_val])
== 0)
- throw new Exception (_("Parent n'existe pas"),EXC_PARAM_VALUE);
+ throw new Exception (_("Poste Parent n'existe
pas"),EXC_PARAM_VALUE);
+
+
if ( $this->data_sql->pcm_direct_use != 'N' &&
$this->data_sql->pcm_direct_use != 'Y')
throw new Exception (_("Paramètre incorrect"),EXC_PARAM_VALUE);
+
if (
trim($this->data_sql->pcm_val)==""||trim($this->data_sql->pcm_val_parent)=="")
throw new Exception (_("Paramètre incorrect"),EXC_PARAM_VALUE);
+
+ if ( strlen($this->data_sql->pcm_val)>40) {
+ throw new Exception (_("Poste comptable doit être de 40 caractères
maximum"),EXC_PARAM_VALUE);
+ }
}
function update() {
@@ -143,8 +183,13 @@ class Acc_Account
$this->data_sql->delete();
}
+
function save() {
- $this->verify();
- $this->data_sql->save();
+ try {
+ $this->verify();
+ $this->data_sql->save();
+ } catch (Exception $e) {
+ throw $e;
+ }
}
}
- [Noalyss-commit] [noalyss] 77/219: PRINTJRN : enlève num opération, (continued)
- [Noalyss-commit] [noalyss] 77/219: PRINTJRN : enlève num opération, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 145/219: ANC : Bouton "recherche" sont des loupes, ajout title, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 168/219: Task #1476 : prevent the use of some accounting Code cleaning , remove obsolete files, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 161/219: Noalyss_SQL :: count add a space, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 107/219: task #0001272: Rendre possible l'appel de la calculatrice depuis le fin fond d'une page., Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 164/219: Code cleaning : remove obsolete, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 83/219: NUM_FIELD = 40, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 129/219: Anc ODS : esthetic search analytic accounting, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 188/219: Plan Comptable : max longueur du poste = 40, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 69/219: HttpInput : do not use in_array but array_key_exists,, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 217/219: Acc_Account : add function , improve function verify,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 49/219: improve esthetic, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 136/219: Infobulle : avoid that the info balloon exceed limit of the display, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 24/219: Code improve : Replace HtmlInput::generate_id obsolete , fix bug in the filter for detail history, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 171/219: remove useless, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 61/219: Inplace_Edit : improve button + test, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 124/219: indentation, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 21/219: Improve debugging and improve manage_table_sql element will be added at the right place Manage_Table_SQL can work also with a SQL query or a view Icon place can be modified, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 34/219: rename scenario files, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 31/219: Task #0001443: opérations rapprochées : bug quand on utilise des tva avec autoliquidation Documentation, Dany De Bontridder, 2017/12/18
- [Noalyss-commit] [noalyss] 63/219: Analytic : change the name and description in Ajax, improve esthetic, Dany De Bontridder, 2017/12/18