Forgot the immediate allocations.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 5 Jan 2009 15:41:38 +0000 (15:41 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 5 Jan 2009 15:41:38 +0000 (15:41 +0000)
CHANGELOG.txt
purchasing/includes/db/invoice_db.inc
purchasing/supplier_credit.php
purchasing/view/view_supp_credit.php

index cdc9969a1df633c8abb32d74e9080c5f4d9590d2..39dd30b8dabfeef835053da6526e893a2ec7c8a2 100644 (file)
@@ -23,9 +23,11 @@ $ -> Affected files
 + Possibility to 'Credit This' in supplier transactions like in customer transaction.
   If there are many invoice items during a year, there would be many rows suggestions.
 $ /purchasing/includes/db/grn_db.inc
+  /purchasing/includes/db/invoice_db.inc
   /purchasing/includes/ui/invoice_ui.inc
   /purchasing/supplier_credit.php
   /purchasing/inquiry/supplier_inquiry.php
+  /purchasing/view/view_supp_credit.php
   
 22-Dec-2008 Janusz Dobrowolski
 # Fixed item_code database update on item creation.
index 96fa45ce6f132851bea01518a1d921c37e652fe6..4980529770f87249f67ec2078ab0025dac4e7361 100644 (file)
@@ -107,7 +107,7 @@ function get_diff_in_home_currency($supplier, $old_date, $date, $amount1, $amoun
 }
 //----------------------------------------------------------------------------------------
 
-function add_supp_invoice($supp_trans) // do not receive as ref because we change locally
+function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref because we change locally
 {
        //$company_currency = get_company_currency();
        /*Start an sql transaction */
@@ -271,6 +271,34 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
 
        references::save_last($supp_trans->reference, $trans_type);
 
+       if ($invoice_no != 0)
+       {
+               $invoice_alloc_balance = get_supp_trans_allocation_balance(20, $invoice_no);
+               if ($invoice_alloc_balance > 0) 
+               {       //the invoice is not already fully allocated 
+
+                       $trans = get_supp_trans($invoice_no, 20);
+                       $total = $trans['Total'];
+
+                       $allocate_amount = ($invoice_alloc_balance > $total) ? $total : $invoice_alloc_balance;
+                       /*Now insert the allocation record if > 0 */
+                       if ($allocate_amount != 0) 
+                       {
+                               update_supp_trans_allocation(20, $invoice_no, $allocate_amount);
+                               update_supp_trans_allocation(21, $invoice_id, $allocate_amount); // ***
+                               add_supp_allocation($allocate_amount, 21, $invoice_id, 20, $invoice_no,
+                                       $date_);
+                               // Exchange Variations Joe Hunt 2008-09-20 ////////////////////////////////////////
+
+                               exchange_variation(21, $invoice_id, 20, $invoice_no, $date_,
+                                       $allocate_amount, payment_person_types::supplier());
+
+                               ///////////////////////////////////////////////////////////////////////////
+                       }
+               }
+       }
+       
+
     commit_transaction();
 
     return $invoice_id;
index 16c78c9c5e7c1425ae7795ae8925eca40d6310ff..e6c83e64fb286f937e239f5db004a72509456369 100644 (file)
@@ -211,7 +211,10 @@ function handle_commit_credit_note()
        if (!check_data())
                return;
 
-       $invoice_no = add_supp_invoice($_SESSION['supp_trans']);
+       if (isset($_POST['invoice_no']))
+               $invoice_no = add_supp_invoice($_SESSION['supp_trans'], $_POST['invoice_no']);
+       else
+               $invoice_no = add_supp_invoice($_SESSION['supp_trans']);
 
     $_SESSION['supp_trans']->clear_items();
     unset($_SESSION['supp_trans']);
index 64ed9b8cd812e5ec37e57c39ff25c823dea1e9ee..64efdbe5a92bdc4128e4c78d4a9cd5cb9d00c1c0 100644 (file)
@@ -63,8 +63,7 @@ $voided = is_voided_display(21, $trans_no, _("This credit note has been voided."
 
 if (!$voided)
 {
-       $tax_total = 0; // ??????
-       display_allocations_from(payment_person_types::supplier(), $supp_trans->supplier_id, 21, $trans_no, -($supp_trans->ov_amount + $tax_total));
+       display_allocations_from(payment_person_types::supplier(), $supp_trans->supplier_id, 21, $trans_no, -($supp_trans->ov_amount + $supp_trans->ov_gst));
 }
 
 end_page(true);