noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 119/162: Currency = payment automatic for Sal


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 119/162: Currency = payment automatic for Sales and Purchases
Date: Sat, 11 Jul 2020 13:23:57 -0400 (EDT)

sparkyx pushed a commit to annotated tag E-4
in repository noalyss.

commit 65393e331cdc1ce052306ef038be6aadbc204210
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Sun Dec 9 18:45:34 2018 +0100

    Currency = payment automatic for Sales and Purchases
---
 include/class/acc_ledger_purchase.class.php | 23 ++++++++++++++++++++---
 include/class/acc_ledger_sold.class.php     | 22 ++++++++++++++++++++--
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/include/class/acc_ledger_purchase.class.php 
b/include/class/acc_ledger_purchase.class.php
index 76e0c03..2fc3cd5 100644
--- a/include/class/acc_ledger_purchase.class.php
+++ b/include/class/acc_ledger_purchase.class.php
@@ -547,7 +547,7 @@ class  Acc_Ledger_Purchase extends Acc_Ledger
             $tot_tva_ndded=0;
             $tot_tva_reversed=0;
             $tva=array();
-            
+            $tot_amount_cur=0;
             // find the currency from v_currency_last_value
             $currency_rate_ref=new Acc_Currency($this->db, $p_currency_code);
             
@@ -755,6 +755,8 @@ class  Acc_Ledger_Purchase extends Acc_Ledger
                 $operation_currency->oc_price_unit=${'e_march'.$i.'_price'};
                 $operation_currency->j_id=$j_id;
                 $operation_currency->insert();
+                
$tot_amount_cur=round(bcadd($tot_amount_cur,$acc_amount->amount_currency),2);
+                
$tot_amount_cur=round(bcadd($tot_amount_cur,$acc_amount->amount_vat_currency),2);
                 if (DEBUG ) {
                     echo __LINE__." insert into operation currency 
oc_amount:{$acc_amount->amount_currency} oc_vat_amount 
{$acc_amount->amount_vat_currency} <br>";
                 }
@@ -950,13 +952,28 @@ class  Acc_Ledger_Purchase extends Acc_Ledger
                 $acc_pay->grpt=$acseq;
                 $acc_pay->jrn=$mp->get_parameter('ledger_target');
                 $acc_pay->periode=$tperiode;
-                               $acc_pay->type=($famount>=0)?'d':'c';
+               $acc_pay->type=($famount>=0)?'d':'c';
                 $let_other=$acc_pay->insert_jrnx();
-
+                
+                // insert into operation_currency
+                $operation_currency=new Operation_currency_SQL($this->db);
+                $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
+                $operation_currency->oc_vat_amount=0;
+                $operation_currency->oc_price_unit=0;
+                $operation_currency->j_id=$let_other;
+                $operation_currency->insert();                
+                
                 /* insert into jrn */
                 $acc_pay->mt=$mt;
                 $acc_pay->desc=(!isset($e_comm_paiement) || 
strlen(trim($e_comm_paiement)) == 0) ?$e_comm:$e_comm_paiement;
                 
+                // Add info for currency
+                $acc_pay->currency_id=$p_currency_code;
+                $acc_pay->currency_rate=$p_currency_rate;
+                $acc_pay->currency_rate_ref=$currency_rate_ref->get_rate();
+                
+                
+                // insert into the table JRN
                 $mp_jr_id=$acc_pay->insert_jrn();
                 $acjrn->grpt_id=$acseq;
                 $acjrn->update_internal_code($acinternal);
diff --git a/include/class/acc_ledger_sold.class.php 
b/include/class/acc_ledger_sold.class.php
index ebf58c9..472de16 100644
--- a/include/class/acc_ledger_sold.class.php
+++ b/include/class/acc_ledger_sold.class.php
@@ -284,6 +284,8 @@ class Acc_Ledger_Sold extends Acc_Ledger {
             $tot_amount = 0;
             $tot_tva = 0;
             $tot_debit = 0;
+            $tot_amount_cur=0;
+
             $this->db->start();
             $tva = array();
              // find the currency from v_currency_last_value
@@ -440,6 +442,8 @@ class Acc_Ledger_Sold extends Acc_Ledger {
                 $operation_currency->oc_price_unit=${'e_march'.$i.'_price'};
                 $operation_currency->j_id=$j_id;
                 $operation_currency->insert();
+                
$tot_amount_cur=round(bcadd($tot_amount_cur,$amount_currency),2);
+                
$tot_amount_cur=round(bcadd($tot_amount_cur,$tva_item_currency),2);
             }// end loop : save all items
 
             /*  save total customer */
@@ -608,9 +612,9 @@ class Acc_Ledger_Sold extends Acc_Ledger {
                     $poste_val = $sposte;
                 }
                  // Convert paid amount in EUR
-                $acompte=bcmul($acompte, $p_currency_rate);   
+                $acompte_eur=bcmul($acompte, $p_currency_rate);   
 
-                $famount=bcsub($cust_amount,$acompte);
+                $famount=bcsub($cust_amount,$acompte_eur);
                 $acc_pay->poste = $poste_val;
                 $acc_pay->qcode = $fqcode;
                 $acc_pay->amount = abs(round($famount, 2));
@@ -635,6 +639,20 @@ class Acc_Ledger_Sold extends Acc_Ledger {
                 $acc_pay->type = ($famount >= 0) ? 'c' : 'd';
                 $let_other = $acc_pay->insert_jrnx();
 
+                // insert into operation_currency
+                $operation_currency=new Operation_currency_SQL($this->db);
+                $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
+                $operation_currency->oc_vat_amount=0;
+                $operation_currency->oc_price_unit=0;
+                $operation_currency->j_id=$let_other;
+                $operation_currency->insert();                
+                
+                // Add info for currency
+                $acc_pay->currency_id=$p_currency_code;
+                $acc_pay->currency_rate=$p_currency_rate;
+                $acc_pay->currency_rate_ref=$currency_rate_ref->get_rate();
+                
+                
                 /* insert into jrn */
                 $acc_pay->mt = $mt;
                 $acjrn->grpt_id = $acseq;



reply via email to

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