noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 02/05: Allow to use 4 decimal for Sales + pre


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 02/05: Allow to use 4 decimal for Sales + predefined operation and display detail
Date: Thu, 22 Oct 2015 11:53:19 +0000

sparkyx pushed a commit to branch master
in repository noalyss.

commit 5af7053d267ec19c6b92a2305dc5e8b9f6e87cf0
Author: Dany De Bontridder <address@hidden>
Date:   Thu Oct 22 11:42:19 2015 +0200

     Allow to use 4 decimal for Sales + predefined operation and display detail
---
 include/class/class_acc_ledger_sold.php |   16 ++++++++++------
 include/class/class_acc_operation.php   |    5 +++--
 include/class/class_pre_op_ven.php      |   27 +++++++++++++++++++--------
 include/class/class_pre_operation.php   |    2 +-
 include/lib/ac_common.php               |    5 +++--
 include/template/ledger_detail_ven.php  |    6 ++----
 sql/upgrade.sql                         |   24 ++++++++++++++++++++++++
 7 files changed, 62 insertions(+), 23 deletions(-)

diff --git a/include/class/class_acc_ledger_sold.php 
b/include/class/class_acc_ledger_sold.php
index 3a381ef..22c6990 100644
--- a/include/class/class_acc_ledger_sold.php
+++ b/include/class/class_acc_ledger_sold.php
@@ -363,7 +363,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
                 }
                 if ($g_parameter->MY_TVA_USE == 'Y') {
                     /* save into quant_sold */
-                    $r = $this->db->exec_sql("select insert_quant_sold 
($1,$2,$3,$4,$5,$6,$7,$8,$9)", array(null, /* 1 */
+                    $r = $this->db->exec_sql("select insert_quant_sold 
($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)", array(null, /* 1 */
                         $j_id, /* 2 */
                         ${'e_march' . $i}, /* 3 */
                         ${'e_quant' . $i}, /* 4 */
@@ -371,9 +371,11 @@ class Acc_Ledger_Sold extends Acc_Ledger {
                         $tva_item, /* 6 */
                         $idx_tva, /* 7 */
                         $e_client, /* 8 */
-                        $n_both));
+                        $n_both, /* 9 */
+                        ${'e_march' . $i . '_price'} /* Price /unit */ 
+                        ));
                 } else {
-                    $r = $this->db->exec_sql("select insert_quant_sold 
($1,$2,$3,$4,$5,$6,$7,$8,$9) ", array(null, /* 1 */
+                    $r = $this->db->exec_sql("select insert_quant_sold 
($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) ", array(null, /* 1 */
                         $j_id, /* 2 */
                         ${'e_march' . $i}, /* 3 */
                         ${'e_quant' . $i}, /* 4 */
@@ -381,7 +383,9 @@ class Acc_Ledger_Sold extends Acc_Ledger {
                         0,
                         null,
                         $e_client,
-                        0));
+                        0, /* 9 */
+                        ${'e_march' . $i . '_price'} /* Price /unit */ 
+                        ));
                 }  // if ( $g_parameter->MY_TVA_USE=='Y') {
             }// end loop : save all items
 
@@ -750,7 +754,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
             $r.=$fiche_name;
             $r.='</td>';
             $r.='<td class="num">';
-            $r.=nbm(${"e_march" . $i . "_price"});
+            $r.=nbm(${"e_march" . $i . "_price"},4);
             $r.='</td>';
             $r.='<td class="num">';
             $r.=nbm(${"e_quant" . $i});
@@ -1249,7 +1253,7 @@ EOF;
             $Price = new INum();
             $Price->setReadOnly(false);
             $Price->size = 9;
-            $Price->javascript = 
"onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
+            $Price->javascript = 
"onBlur='format_number(this,4);clean_tva($i);compute_ledger($i)'";
             $array[$i]['pu'] = $Price->input("e_march" . $i . "_price", 
$march_price);
             $array[$i]['tva'] = '';
             $array[$i]['amount_tva'] = '';
diff --git a/include/class/class_acc_operation.php 
b/include/class/class_acc_operation.php
index 6a1c0fa..7d5df8e 100644
--- a/include/class/class_acc_operation.php
+++ b/include/class/class_acc_operation.php
@@ -26,7 +26,8 @@
 require_once NOALYSS_INCLUDE.'/class/class_user.php';
 require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
 
-/*! \brief  this file match the tables jrn & jrnx the purpose is to
+/*!
+ * \brief  this file match the tables jrn & jrnx the purpose is to
  *   remove or save accountant writing to these table.
  *
  */
@@ -661,7 +662,7 @@ class Acc_Sold extends Acc_Detail
     {
         parent::get();
         $sql="SELECT qs_id, qs_internal, qs_fiche, qs_quantite, qs_price, 
qs_vat,
-             qs_vat_code, qs_client, qs_valid, j_id,j_text,qs_vat_sided
+             qs_vat_code, qs_client, qs_valid, j_id,j_text,qs_vat_sided , 
qs_unit
              FROM quant_sold  join jrnx using(j_id) where j_grpt=$1";
         
$this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
     }
diff --git a/include/class/class_pre_op_ven.php 
b/include/class/class_pre_op_ven.php
index 6a8e4d8..0ca812d 100644
--- a/include/class/class_pre_op_ven.php
+++ b/include/class/class_pre_op_ven.php
@@ -47,6 +47,9 @@ class Pre_op_ven extends Pre_operation_detail
             $this->$march=$_POST['e_march'.$i];
             $this->{"e_march".$i."_price"}=$_POST['e_march'.$i."_price"];
             
$this->{"e_march".$i."_tva_id"}=(isset($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0;
+            
$this->{"e_march".$i."_tva_amount"}=(isset($_POST['e_march'.$i."_tva_amount"]))?$_POST['e_march'.$i."_tva_amount"]:0;
+            
$this->{"e_march".$i."_tva_id"}=(isset($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0;
+            
$this->{"e_march".$i."_label"}=(isset($_POST['e_march'.$i."_label"]))?$_POST['e_march'.$i."_label"]:null;
             $this->{"e_quant".$i}=$_POST['e_quant'.$i];
 
         }
@@ -74,18 +77,26 @@ class Pre_op_ven extends Pre_operation_detail
             for ($i=0;$i<$this->operation->nb_item;$i++)
             {
                 if ( strlen(trim($this->{"e_march".$i}))==0) continue;
-                $sql=sprintf('insert into op_predef_detail 
(opd_poste,opd_amount,opd_tva_id,opd_quantity,'.
-                             'opd_debit,od_id)'.
-                             ' values '.
-                             "('%s',%.2f,%d,%f,'%s',%d)",
-                             $this->{"e_march".$i},
+                $sql= 'insert into op_predef_detail (opd_poste,'
+                        . 'opd_amount,'
+                        . 'opd_tva_id,'
+                        . 'opd_quantity,'
+                        . 'opd_debit,'
+                        . 'od_id ,'
+                        . 'opd_tva_amount,'
+                        . 'opd_comment'.
+                        ')'.
+                             ' values ($1,$2,$3,$4,$5,$6,$7,$8)';
+                $this->db->exec_sql($sql,
+                        array($this->{"e_march".$i},
                              $this->{"e_march".$i."_price"},
                              $this->{"e_march".$i."_tva_id"},
                              $this->{"e_quant".$i},
                              'f',
-                             $this->operation->od_id
-                            );
-                $this->db->exec_sql($sql);
+                             $this->operation->od_id,
+                             $this->{"e_march".$i."_tva_amount"},
+                             $this->{"e_march".$i."_label"},
+                            ));
             }
         }
         catch (Exception $e)
diff --git a/include/class/class_pre_operation.php 
b/include/class/class_pre_operation.php
index 60b031a..8b78424 100644
--- a/include/class/class_pre_operation.php
+++ b/include/class/class_pre_operation.php
@@ -157,7 +157,7 @@ class Pre_operation
         $p_array=$this->load();
         $array=array(
                    "e_comm"=>$p_array[0]["od_name"],
-                   
"nb_item"=>(($p_array[0]["od_item"]<10?10:$p_array[0]["od_item"]))   ,
+                   
"nb_item"=>(($p_array[0]["od_item"]<10)?10:$p_array[0]["od_item"])   ,
                    "p_jrn"=>$p_array[0]["jrn_def_id"],
                    "jrn_type"=>$p_array[0]["od_jrn_type"],
                    "od_description"=>$p_array['0']['od_description']
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index cb84e82..fe9061c 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -115,8 +115,9 @@ function nb($p_number)
 /**
  * format the number with a sep. for the thousand
  * @param $p_number number
+ * @param $p_dec number of decimal to display
  */
-function nbm($p_number)
+function nbm($p_number,$p_dec = 2)
 {
 
     if (trim($p_number) == '')
@@ -125,7 +126,7 @@ function nbm($p_number)
        return "0,00";
     
     $a = doubleval($p_number);
-    $r = number_format($a, 2, ",", ".");
+    $r = number_format($a, $p_dec, ",", ".");
     if (trim($r) == '')
     {
        var_dump($r);
diff --git a/include/template/ledger_detail_ven.php 
b/include/template/ledger_detail_ven.php
index 34689af..8945d60 100644
--- a/include/template/ledger_detail_ven.php
+++ b/include/template/ledger_detail_ven.php
@@ -174,10 +174,8 @@ echo $ipaid->input();
 
                     $row.=td($input->input() . $hidden);
                     $sym_tva = '';
-                    $pu = 0;
-                    if ($q['qs_quantite'] != 0)
-                        $pu = bcdiv($q['qs_price'], $q['qs_quantite']);
-                    $row.=td(nbm($pu), 'class="num"');
+                    $pu = $q['qs_unit'];
+                    $row.=td(nbm($pu,4), 'class="num"');
                     $row.=td(nbm($q['qs_quantite']), 'class="num"');
                     $sym_tva = '';
                     if ($owner->MY_TVA_USE == 'Y' && $q['qs_vat_code'] != '')
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 870dac2..1022e62 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -178,3 +178,27 @@ return NEW;
 end;
 $BODY$
 LANGUAGE plpgsql;
+
+alter table quant_sold add column qs_unit numeric(20,4) default 0;
+update quant_sold set qs_unit = qs_price / qs_quantite;
+
+CREATE OR REPLACE FUNCTION comptaproc.insert_quant_sold(p_internal text, p_jid 
numeric, p_fiche character varying, p_quant numeric, p_price numeric, p_vat 
numeric, p_vat_code integer, p_client character varying, p_tva_sided numeric, 
p_price_unit numeric)
+  RETURNS void AS
+$BODY$
+declare
+        fid_client integer;
+        fid_good   integer;
+begin
+
+        select f_id into fid_client from
+                fiche_detail where ad_id=23 and ad_value=upper(trim(p_client));
+        select f_id into fid_good from
+                fiche_detail where ad_id=23 and ad_value=upper(trim(p_fiche));
+        insert into quant_sold
+                
(qs_internal,j_id,qs_fiche,qs_quantite,qs_price,qs_vat,qs_vat_code,qs_client,qs_valid,qs_vat_sided,qs_unit)
+        values
+                
(p_internal,p_jid,fid_good,p_quant,p_price,p_vat,p_vat_code,fid_client,'Y',p_tva_sided,p_price_unit);
+        return;
+end;
+ $BODY$
+  LANGUAGE plpgsql;



reply via email to

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