noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 12/27: #1369: Étendre la comptabilité analyt


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 12/27: #1369: Étendre la comptabilité analytique à tous les postes? #1716: GROS SOUCI CA - ventilation 4 et 5. 5 phantôme! #1479: PROPOSITION CA - paramétrage comptes actifs
Date: Wed, 4 Sep 2019 15:24:53 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit e57aa7d86392ce89ab2267822f9fed1a633b24bb
Author: Dany De Bontridder <address@hidden>
Date:   Thu Aug 29 09:43:22 2019 +0200

    #1369: Étendre la comptabilité analytique à tous les postes?
    #1716: GROS SOUCI CA - ventilation 4 et 5. 5 phantôme!
    #1479: PROPOSITION CA - paramétrage comptes actifs
---
 include/ajax/ajax_anc_key_compute.php            |  2 +-
 include/class/acc_ledger_fin.class.php           |  2 +-
 include/class/acc_ledger_purchase.class.php      |  2 +-
 include/class/acc_ledger_sold.class.php          |  5 +-
 include/class/noalyss_parameter_folder.class.php | 91 +++++++++++++++++++-----
 include/company.inc.php                          | 18 ++++-
 include/template/ledger_detail_ach.php           |  2 +-
 include/template/ledger_detail_fin.php           |  2 +-
 include/template/ledger_detail_misc.php          |  2 +-
 include/template/ledger_detail_ven.php           |  2 +-
 10 files changed, 98 insertions(+), 30 deletions(-)

diff --git a/include/ajax/ajax_anc_key_compute.php 
b/include/ajax/ajax_anc_key_compute.php
index c04d643..63c48c7 100644
--- a/include/ajax/ajax_anc_key_compute.php
+++ b/include/ajax/ajax_anc_key_compute.php
@@ -48,7 +48,7 @@ catch (Exception $exc)
     error_log($exc->getTraceAsString());
     return;
 }
-
+ob_start();
 $compute_key=new Anc_Key($key);
 $pos=strrpos($target,"t");
 $row=substr($target,$pos+1);
diff --git a/include/class/acc_ledger_fin.class.php 
b/include/class/acc_ledger_fin.class.php
index b9023ac..c27c16c 100644
--- a/include/class/acc_ledger_fin.class.php
+++ b/include/class/acc_ledger_fin.class.php
@@ -612,7 +612,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
                        }
                        $r.='</td>';
                        // encode the pa
-                       if ($g_parameter->MY_ANALYTIC != 'nu' && 
preg_match("/^[6,7]/", $fTiers->strAttribut(ATTR_DEF_ACCOUNT)) == 1) // use of 
AA
+                       if ($g_parameter->MY_ANALYTIC != 'nu' && 
$g_parameter->match_analytic($fTiers->strAttribut(ATTR_DEF_ACCOUNT)) == 1) // 
use of AA
                        {
                                // show form
                                $anc_op = new Anc_Operation($this->db);
diff --git a/include/class/acc_ledger_purchase.class.php 
b/include/class/acc_ledger_purchase.class.php
index f479749..2ac7bec 100644
--- a/include/class/acc_ledger_purchase.class.php
+++ b/include/class/acc_ledger_purchase.class.php
@@ -656,7 +656,7 @@ class  Acc_Ledger_Purchase extends Acc_Ledger
                     
Stock_Goods::insert_goods($this->db,array('j_id'=>$j_id,'goods'=>${'e_march'.$i},'quant'=>$nNeg*${'e_quant'.$i},'dir'=>$dir,'repo'=>$repo))
 ;
                 }
 
-                if ( $g_parameter->MY_ANALYTIC != "nu" )
+                if ( $g_parameter->MY_ANALYTIC != "nu" && 
$g_parameter->match_analytic($poste_val))
                 {
                     // for each item, insert into operation_analytique */
                     $op=new Anc_Operation($this->db);
diff --git a/include/class/acc_ledger_sold.class.php 
b/include/class/acc_ledger_sold.class.php
index ae4535a..8a6ff3e 100644
--- a/include/class/acc_ledger_sold.class.php
+++ b/include/class/acc_ledger_sold.class.php
@@ -364,7 +364,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
                 }
 
 
-                if ($g_parameter->MY_ANALYTIC != "nu") {
+                if ($g_parameter->MY_ANALYTIC != "nu" && 
$g_parameter->match_analytic($poste_val)) {
                     // for each item, insert into operation_analytique */
                     $op = new Anc_Operation($this->db);
                     $op->oa_group = $group;
@@ -819,7 +819,8 @@ class Acc_Ledger_Sold extends Acc_Ledger {
                 $r.='</td>';
             }
             // encode the pa
-            if ($g_parameter->MY_ANALYTIC != 'nu') { // use of AA
+            if ($g_parameter->MY_ANALYTIC != 'nu' 
+                    && 
$g_parameter->match_analytic($fiche->strAttribut(ATTR_DEF_ACCOUNT))==TRUE) { // 
use of AA
                 // show form
                 $anc_op = new Anc_Operation($this->db);
                 $null = ($g_parameter->MY_ANALYTIC == 'op') ? 1 : 0;
diff --git a/include/class/noalyss_parameter_folder.class.php 
b/include/class/noalyss_parameter_folder.class.php
index 8f78442..a9db097 100644
--- a/include/class/noalyss_parameter_folder.class.php
+++ b/include/class/noalyss_parameter_folder.class.php
@@ -45,6 +45,7 @@ class Noalyss_Parameter_Folder
     var $MY_ALPHANUM;
     var $MY_UPDLAB;
     var $MY_STOCK;
+    var $MY_ANC_FILTER;
     
     // constructor
     function __construct($p_cn)
@@ -61,14 +62,51 @@ class Noalyss_Parameter_Folder
         }
 
     }
-    function check(&$p_value)
+    function check_anc_filter($p_value)
     {
-        if ($p_value == 'MY_STRICT'
-                && $this->MY_STRICT != 'Y'
-                && $this->MY_STRICT != 'N')
-            $p_value='N';
-        $p_value=htmlspecialchars($p_value);
+        $tmp_value=$p_value;
+        $tmp_value=preg_replace("/[0-9]|,/", '', $p_value);
+        if ( $tmp_value != "") {
+            throw new Exception (sprintf(_("Valeur invalide 
%s"),$tmp_value),1000);
+        }
+        if (trim($p_value) == "") {
+            throw new Exception (sprintf(_("Erreur Filtre analytique 
%s"),$tmp_value),1001);
+            
+        }
+        
+    }
+    function check($p_attr, $p_value)
+    {
+        $ret_value=$p_value;
+        switch ($p_attr)
+        {
+            case 'MY_STRICT':
+                
+                if (empty(trim($p_value)) ||($p_value!='Y'&&$p_value!='N'))
+                {
+                    $ret_value='N';
+                }
+                
+                break;
+            case 'MY_ANC_FILTER':
+                try
+                {
+                    $p_value=str_replace(" ", "", $p_value);
+                    $this->check_anc_filter($p_value);
+                    $ret_value=$p_value;
+                }
+                catch (Exception $exc)
+                {
+                    throw $exc;
+                }
+
+                break;
+            default :
+                $ret_value=htmlspecialchars($p_value);
+        }
+        return $ret_value;
     }
+
     /*!
      **************************************************
      * \brief  save the parameter into the database by inserting or updating
@@ -79,20 +117,24 @@ class Noalyss_Parameter_Folder
      */
     function save($p_attr)
     {
-        $this->check($p_attr);
-        $value=$this->$p_attr;
-        // check if the parameter does exist
-        if ( $this->db->get_value('select count(*) from parameter where 
pr_id=$1',array($p_attr)) != 0 )
-        {
-            $Res=$this->db->exec_sql("update parameter set pr_value=$1 where 
pr_id=$2",
-                                     array($value,$p_attr));
-        }
-        else
-        {
+        try {
+            $value=$this->check($p_attr,$this->$p_attr);
+
+            // check if the parameter does exist
+            if ( $this->db->get_value('select count(*) from parameter where 
pr_id=$1',array($p_attr)) != 0 )
+            {
+                $Res=$this->db->exec_sql("update parameter set pr_value=$1 
where pr_id=$2",
+                                         array($value,$p_attr));
+            }
+            else
+            {
 
-            $Res=$this->db->exec_sql("insert into parameter (pr_id,pr_value) 
values( $1,$2)",
-                                     array($p_attr,$value));
+                $Res=$this->db->exec_sql("insert into parameter 
(pr_id,pr_value) values( $1,$2)",
+                                         array($p_attr,$value));
 
+            }
+        } catch (Exception $e) {
+             throw $e;
         }
 
     }
@@ -124,8 +166,19 @@ class Noalyss_Parameter_Folder
         $this->save('MY_ALPHANUM');
         $this->save('MY_UPDLAB');
         $this->save('MY_STOCK');
+        $this->save("MY_ANC_FILTER");
 
-
+    }
+    /**
+     * Check if an accounting match the anc_filter
+     * @param string $p_accounting 
+     * @return boolean FALSE does not match , TRUE matches
+     */
+    function match_analytic($p_accounting)
+    {
+        $string="/^[".$this->MY_ANC_FILTER."]+/";
+        if ( preg_match($string,$p_accounting) == 0 ) return FALSE;
+        return TRUE;
     }
 
 }
diff --git a/include/company.inc.php b/include/company.inc.php
index c7dcc54..2bd6ae2 100644
--- a/include/company.inc.php
+++ b/include/company.inc.php
@@ -48,8 +48,12 @@ if (isset($_POST['record_company']))
        $m->MY_ALPHANUM = $http->post("p_alphanum");
        $m->MY_UPDLAB = $http->post("p_updlab");
        $m->MY_STOCK =$http->post("p_stock");
-
-       $m->Update();
+       $m->MY_ANC_FILTER=$http->post("p_anc_filter");
+        try {
+            $m->Update();
+        } catch (Exception $e) {
+            alert($e->getMessage());
+        }
 }
 
 $my = new Noalyss_Parameter_Folder($cn);
@@ -111,6 +115,10 @@ $stock->value = array(
 $stock->selected = $my->MY_STOCK;
 $stock->table = 1;
 
+$anc_filter=new IText("p_anc_filter", $my->MY_ANC_FILTER);
+$anc_filter->placeholder='6,7';
+$anc_filter->title=_("Uniquement des chiffres séparés par des virgules");
+
 // other parameters
 $all = new IText();
 $all->table = 1;
@@ -135,6 +143,12 @@ echo "<tr>" . td(_("Pays"), 'style="text-align:right"') . 
$all->input("p_pays",
 $all->value = '';
 echo "<tr>" . td(_("Numéro de Tva"), 'style="text-align:right"') . 
$all->input("p_tva", $my->MY_TVA) . "</tr>";
 echo "<tr>" . td(_("Utilisation de la compta. analytique"), 
'style="text-align:right"') . $compta->input("p_compta", $array) . "</tr>";
+echo '<tr>'. td(_("Opération analytique uniquement pour les postes comptables 
commençant par")).
+        '<td>'.
+        $anc_filter->input().
+        Icon_Action::tips($anc_filter->title);
+        '</td>'.
+        '</tr>';
 echo "<tr>" . td(_("Utilisation des stocks"), 'style="text-align:right"') . 
$stock->input() . "</tr>";
 
 echo "<tr>" . td(_("Utilisation du mode strict "), 'style="text-align:right"') 
. $strict->input("p_strict", $strict_array) . "</tr>";
diff --git a/include/template/ledger_detail_ach.php 
b/include/template/ledger_detail_ach.php
index 97981af..7513aa0 100644
--- a/include/template/ledger_detail_ach.php
+++ b/include/template/ledger_detail_ach.php
@@ -225,7 +225,7 @@ $str_anc="";
                     if ($owner->MY_ANALYTIC != "nu" /*&& $div == 'popup'*/ )
                     {
                         $poste = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
-                        if (preg_match('/^(6|7)/', $poste))
+                        if ( $g_parameter->match_analytic($poste))
                         {
                             $anc_op = new Anc_Operation($cn);
                             $anc_op->j_id = $q['j_id'];
diff --git a/include/template/ledger_detail_fin.php 
b/include/template/ledger_detail_fin.php
index a34f4b6..291a125 100644
--- a/include/template/ledger_detail_fin.php
+++ b/include/template/ledger_detail_fin.php
@@ -118,7 +118,7 @@ echo td(_('Pièce')).td($itext->input());
     if ( $owner->MY_ANALYTIC != "nu" /*&& $div == 'popup'*/)
       {
        $poste=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
-       if ( preg_match('/^(6|7)/',$q[$e]['j_poste']))
+       if (  $g_parameter->match_analytic($q[$e]['j_poste']))
          {
             $qcode=$fiche->strAttribut(ATTR_DEF_QUICKCODE);
            $anc_op=new Anc_Operation($cn);
diff --git a/include/template/ledger_detail_misc.php 
b/include/template/ledger_detail_misc.php
index 27ce898..eb00e11 100644
--- a/include/template/ledger_detail_misc.php
+++ b/include/template/ledger_detail_misc.php
@@ -161,7 +161,7 @@ $amount_idx=0;
     $row.=($q[$e]['j_debit']=='f')?$montant:td('');
     /* Analytic accountancy */
     if ( $owner->MY_ANALYTIC != "nu" /*&& $div=='popup'*/){
-      if ( preg_match('/^(6|7)/',$q[$e]['j_poste'])) {
+      if (  $g_parameter->match_analytic($q[$e]['j_poste'])) {
 
        echo HtmlInput::hidden("amount_t".$amount_idx,$q[$e]['j_montant']);
        $anc_op=new Anc_Operation($cn);
diff --git a/include/template/ledger_detail_ven.php 
b/include/template/ledger_detail_ven.php
index fa7c3ac..f68b51e 100644
--- a/include/template/ledger_detail_ven.php
+++ b/include/template/ledger_detail_ven.php
@@ -223,7 +223,7 @@ echo $ipaid->input();
                     if ($owner->MY_ANALYTIC != "nu" /*&& $div == 'popup' */ )
                     {
                         $poste = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
-                        if (preg_match('/^(6|7)/', $poste))
+                        if ( $g_parameter->match_analytic($poste))
                         {
                             $anc_op = new Anc_Operation($cn);
                             $anc_op->in_div=$div;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]