noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 02/03: Operation export PDF : print the amoun


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 02/03: Operation export PDF : print the amount in currency
Date: Sat, 14 Aug 2021 10:16:08 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit d66e28009436750c6c48e33cff96674259af4389
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sat Aug 14 16:13:05 2021 +0200

    Operation export PDF : print the amount in currency
---
 include/class/acc_ledger.class.php             |  2 +-
 include/class/acc_operation.class.php          | 70 ++++++++++++++++++++++++++
 include/class/pdf_operation.class.php          | 18 +++++++
 unit-test/include/class/acc_operation.Test.php | 38 ++++++++++++++
 4 files changed, 127 insertions(+), 1 deletion(-)

diff --git a/include/class/acc_ledger.class.php 
b/include/class/acc_ledger.class.php
index 7f3fa72..ec68d64 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -2616,7 +2616,7 @@ class Acc_Ledger  extends jrn_def_sql
                  $array['negative_amount'] <> 0 &&
                  $array['negative_amount'] <> 1 )
              {
-                  throw new Exception(_("Valeur invalide"));
+                  throw new Exception(_("Valeur invalide 
{$array['negative_amount']}"));
             }
         }
         catch (Exception $e)
diff --git a/include/class/acc_operation.class.php 
b/include/class/acc_operation.class.php
index ba789ac..165c286 100644
--- a/include/class/acc_operation.class.php
+++ b/include/class/acc_operation.class.php
@@ -623,6 +623,76 @@ class Acc_Operation
         $ret->get_info();
         return $ret;
     }
+     /**
+     *@brief retrieve amount in currency for the operation
+     *@return amount in currency or 0 if this operation doesn't use currency
+     *@see Acc_Sold Acc_Purchase Acc_Fin Acc_Detail Acc_Misc
+     */
+    function get_currency_amount()
+    {
+        if ( $this->det->currency_id == 0 ) {
+            return 0;
+        }
+        $ledger_id=$this->get_ledger();
+        if ( $ledger_id=='') throw new Exception(_('Journal non trouvé'));
+        $oledger=new Acc_Ledger($this->db,$ledger_id);
+
+        // retrieve info from jrn_info
+       
+
+        switch($oledger->get_type())
+        {
+        case 'VEN':
+            $sql_amount="
+                select 
+                sum(oc_amount)+sum(oc_vat_amount ) 
+                from operation_currency oc 
+                join quant_sold qs using(j_id) 
+                where 
+                oc.j_id in (select j_id 
+                    from jrnx join jrn on (jr_grpt_id=j_grpt) 
+                    where jr_id=$1);
+                ";
+            break;
+        case 'ACH':
+             $sql_amount="
+                select 
+                sum(oc_amount)+sum(oc_vat_amount ) 
+                from operation_currency oc 
+                join quant_purchase qs using(j_id) 
+                where 
+                oc.j_id in (select j_id 
+                    from jrnx join jrn on (jr_grpt_id=j_grpt) 
+                    where jr_id=$1);
+                ";
+            break;
+        case 'FIN':
+             $sql_amount="
+                select 
+                sum(oc_amount)+sum(oc_vat_amount ) 
+                from operation_currency oc 
+                join quant_fin qs using(j_id) 
+                where 
+                oc.j_id in (select j_id 
+                    from jrnx join jrn on (jr_grpt_id=j_grpt) 
+                    where jr_id=$1);
+                ";
+            break;
+        default:
+             $sql_amount="
+                select 
+                sum(oc_amount)+sum(oc_vat_amount ) 
+                from operation_currency oc 
+                join jrnx using(j_id) 
+                join jrn on (jr_grpt_id=j_grpt) 
+                where 
+                jr_id=$1 and j_debit='t';
+                ";
+            break;
+        }
+        $amount=$this->db->get_value($sql_amount,[$this->jr_id]);
+        return $amount;
+    }
     /**
      * @brief retrieve info from the jrn_info, create 2 new arrays
      * obj->info->command and obj->info->other
diff --git a/include/class/pdf_operation.class.php 
b/include/class/pdf_operation.class.php
index a8c6751..7c4081b 100644
--- a/include/class/pdf_operation.class.php
+++ b/include/class/pdf_operation.class.php
@@ -83,6 +83,21 @@ class PDF_Operation extends PDF {
         $this->pdf->line_new(4);
         $this->pdf->write_cell(50, 6, _("Nom document"));
         $this->pdf->write_cell(100, 6, $this->acc_detail->det->jr_pj_name);
+        if ($this->acc_detail->det->currency_id != 0) 
+        {
+            $currency=new 
Acc_Currency($this->cn,$this->acc_detail->det->currency_id);
+            $this->pdf->line_new(4);
+            $this->pdf->write_cell(50, 6, _("Devise"));
+            $this->pdf->write_cell(50, 6, $currency->get_code());
+            $this->pdf->write_cell(25, 6, _("Taux utilisé"));
+            $this->pdf->write_cell(30, 
6,nb($this->acc_detail->det->currency_rate,4));
+            $this->pdf->write_cell(25, 6, _("Taux référence"));
+            $this->pdf->write_cell(30, 
6,nbm($this->acc_detail->det->currency_rate_ref,4));
+            $this->pdf->line_new(4);
+            $this->pdf->write_cell(50, 6, _("Montant Devise"));
+            $this->pdf->write_cell(50, 6, 
nb($this->acc_detail->get_currency_amount(),4));
+
+        }
         $this->pdf->line_new(8);
     }
     /**
@@ -279,6 +294,9 @@ class PDF_Operation extends PDF {
         // find the reconcilied operations
         $a_reconcilied_operation=$this->cn->get_array("select 
jr_id,jra_concerned from jrn_rapt where jra_concerned=$1 or jr_id=$1",
                 [$this->jr_id]);
+        if ( empty ($a_reconcilied_operation)) {
+            return;
+        }
          $this->print_section(_("Opérations rapprochées"));
         // for each operation , print info (amount, ledger,... )
         foreach ($a_reconcilied_operation as $reconcilied_operation) {
diff --git a/unit-test/include/class/acc_operation.Test.php 
b/unit-test/include/class/acc_operation.Test.php
index 641ecc8..d0b7271 100644
--- a/unit-test/include/class/acc_operation.Test.php
+++ b/unit-test/include/class/acc_operation.Test.php
@@ -88,4 +88,42 @@ class Acc_OperationTest extends TestCase
         }
         
     }
+    /**
+     * provide data for testAmount_Currency
+     * @return type
+     */
+    public function data_amount_currency()
+    {
+        return array(
+            /* sale */
+            array(659,146.95),
+            array(657,146.95),
+            array(649,0),
+            /* purchase*/
+            array(680,680.33),
+            array(683,834.91),
+            array(526,0),
+            /* financial */
+            array(658,146.95),
+            array(684,200),
+            array(685,300),
+            /* misc operation */
+            array(686,25.25),
+            
+        );
+    }
+    /**
+     * @testdox acc_operation::get_amount_currency - sale-purchase-fin-misc
+     * @covers Acc_Operation::get_amount_currency
+     * @dataProvider data_amount_currency
+     */
+    function testGet_AmountCurrency($p_jrn_id,$p_amount_currency)
+    {
+        global $g_connection;
+        $acc_operation=new Acc_Detail($g_connection,$p_jrn_id);
+        $acc_operation->get();
+        $acc_operation->get_quant();
+        $actual_amount=round($acc_operation->get_currency_amount(),2);
+        $this->assertEquals($p_amount_currency,$actual_amount,"currency values 
doesn't match for $p_jrn_id");
+    }
 }



reply via email to

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