Fix for exchange variation when allocating payments. re-inserted in System and GL...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 20 Sep 2008 15:23:51 +0000 (15:23 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 20 Sep 2008 15:23:51 +0000 (15:23 +0000)
CHANGELOG.txt
admin/db/company_db.inc
admin/gl_setup.php
includes/banking.inc
purchasing/allocations/supplier_allocate.php
purchasing/includes/db/suppalloc_db.inc
reporting/includes/tcpdf.php
sales/allocations/customer_allocate.php
sales/includes/db/custalloc_db.inc
sales/includes/db/payment_db.inc
sales/includes/db/sales_credit_db.inc

index 0400ed9c6073baa3223815b62d39fc039c33490e..85569f0775225b3e2ba8ea8199c573bac9c40bc5 100644 (file)
@@ -19,6 +19,21 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+20-Sep-2008 Joe Hunt
+# Fix for exchange variation when allocating payments. re-inserted in System and GL Setup.
+$ /admin/gl_setup.php
+  /admin/db/company_db
+  /includes/banking.inc
+  /purchasing/allocations/supplier_allocate.php
+  /purchasing/includes/db/suppalloc_db.inc
+  /sales/allocations/customer_allocate.php
+  /sales/includes/db/custalloc_db.inc
+  /sales/includes/db/payment_db.inc
+  /sales/includes/db/sales_credit_db.inc
+! New tcpdf.php file. Minor bugfixes from tcpdf.org
+  /reporting/includes/tcpdf.php
+  
+
 18-Sep-2008 Janusz Dobrowolski
 + Support for calling external pages during document entry (e.g. for adding customer/supplier/items).
 $ /index.php
index ea99d8722c12e454a01d9b2a48c3816e889054a5..8a832211bee06d4369d8dcd736227dca87c67eb4 100644 (file)
@@ -1,8 +1,9 @@
 <?php
 
 
-function update_company_gl_setup($debtors_act, $pyt_discount_act, $creditors_act, 
+function update_company_gl_setup($debtors_act, $pyt_discount_act, $creditors_act,
                $freight_act,
+               $exchange_diff_act,
                $default_sales_act,
                $default_sales_discount_act,
                $default_prompt_payment_act,
@@ -23,6 +24,7 @@ function update_company_gl_setup($debtors_act, $pyt_discount_act, $creditors_act
                debtors_act=".db_escape($debtors_act).", pyt_discount_act=".db_escape($pyt_discount_act).",
                creditors_act=".db_escape($creditors_act).",
                freight_act=".db_escape($freight_act).",
+               exchange_diff_act=".db_escape($exchange_diff_act).",
                default_sales_act=".db_escape($default_sales_act).",
                default_sales_discount_act=".db_escape($default_sales_discount_act).",
                default_prompt_payment_act=".db_escape($default_prompt_payment_act).",
@@ -156,7 +158,7 @@ function delete_fiscalyear($id)
 function get_base_sales_type()
 {
        $sql = "SELECT base_sales FROM ".TB_PREF."company WHERE coy_code=1";
-       
+
        $result = db_query($sql, "could not get base sales type");
        $myrow = db_fetch($result);
        return $myrow[0];
index 044a111a19e851e98c3e2d7c55a6f0498b2a0279..b69397477570010ac9a1d8403ee27a91439461a6 100644 (file)
@@ -14,23 +14,23 @@ include_once($path_to_root . "/admin/db/company_db.inc");
 
 //-------------------------------------------------------------------------------------------------
 
-function can_process() 
+function can_process()
 {
-       if (!check_num('po_over_receive', 0, 100)) 
+       if (!check_num('po_over_receive', 0, 100))
        {
                display_error(_("The delivery over-receive allowance must be between 0 and 100."));
                set_focus('po_over_receive');
                return false;
        }
 
-       if (!check_num('po_over_charge', 0, 100)) 
+       if (!check_num('po_over_charge', 0, 100))
        {
                display_error(_("The invoice over-charge allowance must be between 0 and 100."));
                set_focus('po_over_charge');
                return false;
        }
 
-       if (!check_num('past_due_days', 0, 100)) 
+       if (!check_num('past_due_days', 0, 100))
        {
                display_error(_("The past due days interval allowance must be between 0 and 100."));
                set_focus('past_due_days');
@@ -41,10 +41,11 @@ function can_process()
 
 //-------------------------------------------------------------------------------------------------
 
-if (isset($_POST['submit']) && can_process()) 
+if (isset($_POST['submit']) && can_process())
 {
        update_company_gl_setup($_POST['debtors_act'], $_POST['pyt_discount_act'],
                $_POST['creditors_act'], $_POST['freight_act'],
+               $_POST['exchange_diff_act'],
                $_POST['default_sales_act'],
                $_POST['default_sales_discount_act'],
                $_POST['default_prompt_payment_act'],
@@ -77,6 +78,7 @@ $_POST['creditors_act']  = $myrow["creditors_act"];
 $_POST['freight_act'] = $myrow["freight_act"];
 $_POST['pyt_discount_act']  = $myrow["pyt_discount_act"];
 
+$_POST['exchange_diff_act'] = $myrow["exchange_diff_act"];
 $_POST['default_sales_act'] = $myrow["default_sales_act"];
 $_POST['default_sales_discount_act']  = $myrow["default_sales_discount_act"];
 $_POST['default_prompt_payment_act']  = $myrow["default_prompt_payment_act"];
@@ -109,15 +111,15 @@ table_section_title(_("General GL"));
 //gl_all_accounts_list_row(_("Payroll Account:"), 'payroll_act', $_POST['payroll_act']);
 
 text_row(_("Past Due Days Interval:"), 'past_due_days', $_POST['past_due_days'], 6, 6, '', "", _("days"));
+
+gl_all_accounts_list_row(_("Exchange Variances Account:"), 'exchange_diff_act', $_POST['exchange_diff_act']);
+
 //---------------
 
 table_section_title(_("Customers and Sales"));
 
 text_row(_("Default Credit Limit:"), 'default_credit_limit', $_POST['default_credit_limit'], 12, 12);
 
-// Not used in FA2.0.
-//gl_all_accounts_list_row(_("Sales Exchange Variances Account:"), 'exchange_diff_act', $_POST['exchange_diff_act']);
-
 gl_all_accounts_list_row(_("Shipping Charged Account:"), 'freight_act', $_POST['freight_act']);
 
 //---------------
index 5e5f346e0fe3f009d2732bda43101cb78a7edbc3..e3232a768a26bc14e84504ce26ff509df490857e 100644 (file)
@@ -8,7 +8,7 @@ function is_bank_account($account_code)
 {
        $sql= "SELECT account_code FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'";
        $result = db_query($sql, "retreive bank account currency");
-       
+
        return (db_num_rows($result) > 0);
 }
 
@@ -26,9 +26,9 @@ function get_company_currency()
        $sql= "SELECT curr_default FROM ".TB_PREF."company";
        $result = db_query($sql, "retreive company currency");
 
-       if (db_num_rows($result) == 0)  
+       if (db_num_rows($result) == 0)
                display_db_error("Could not find the requested currency. Fatal.", $sql);
-       
+
        $myrow = db_fetch_row($result);
        return $myrow[0];
 }
@@ -39,9 +39,9 @@ function get_bank_account_currency($bankAccount)
 {
        $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE account_code='$bankAccount'";
        $result = db_query($sql, "retreive bank account currency");
-       
+
        $myrow = db_fetch_row($result);
-       return $myrow[0];       
+       return $myrow[0];
 }
 
 //----------------------------------------------------------------------------------
@@ -49,23 +49,23 @@ function get_bank_account_currency($bankAccount)
 function get_customer_currency($customer_id)
 {
     $sql = "SELECT curr_code FROM ".TB_PREF."debtors_master WHERE debtor_no = '$customer_id'";
-                       
+
        $result = db_query($sql, "Retreive currency of customer $customer_id");
-       
-       $myrow=db_fetch_row($result);   
-       return $myrow[0];               
+
+       $myrow=db_fetch_row($result);
+       return $myrow[0];
 }
 
-//----------------------------------------------------------------------------------   
+//----------------------------------------------------------------------------------
 
 function get_supplier_currency($supplier_id)
 {
     $sql = "SELECT curr_code FROM ".TB_PREF."suppliers WHERE supplier_id = '$supplier_id'";
-                       
+
        $result = db_query($sql, "Retreive currency of supplier $supplier_id");
-       
-       $myrow=db_fetch_row($result);   
-       return $myrow[0];               
+
+       $myrow=db_fetch_row($result);
+       return $myrow[0];
 }
 
 //----------------------------------------------------------------------------------
@@ -74,30 +74,30 @@ function get_exchange_rate_from_home_currency($currency_code, $date_)
 {
        if ($currency_code == get_company_currency())
                return 1.0000;
-               
+
        $date = date2sql($date_);
-               
-       $sql = "SELECT rate_buy, max(date_) as date_ FROM ".TB_PREF."exchange_rates WHERE curr_code = '$currency_code' 
+
+       $sql = "SELECT rate_buy, max(date_) as date_ FROM ".TB_PREF."exchange_rates WHERE curr_code = '$currency_code'
                                AND date_ <= '$date' GROUP BY rate_buy ORDER BY date_ Desc LIMIT 1";
-       
+
        $result = db_query($sql, "could not query exchange rates");
-       
-       if (db_num_rows($result) == 0) 
+
+       if (db_num_rows($result) == 0)
        {
                // no stored exchange rate, just return 1
                display_error(_("Cannot get exchange rate for this currency. Please add exchange rate manually on Exchange Rates page.") );
                return 1.000;
        }
-       
-       $myrow = db_fetch_row($result); 
-       return $myrow[0];       
+
+       $myrow = db_fetch_row($result);
+       return $myrow[0];
 }
 
 //----------------------------------------------------------------------------------
 
 function get_exchange_rate_to_home_currency($currency_code, $date_)
 {
-       return 1 / get_exchange_rate_from_home_currency($currency_code, $date_);        
+       return 1 / get_exchange_rate_from_home_currency($currency_code, $date_);
 }
 
 //----------------------------------------------------------------------------------
@@ -108,25 +108,25 @@ function to_home_currency($amount, $currency_code, $date_)
        return round($amount / $ex_rate,  user_price_dec());
 }
 
-//----------------------------------------------------------------------------------           
+//----------------------------------------------------------------------------------
 
 function get_exchange_rate_from_to($from_curr_code, $to_curr_code, $date_)
 {
 //     echo "converting from $from_curr_code to $to_curr_code <BR>";
        if ($from_curr_code == $to_curr_code)
                return 1.0000;
-               
+
        $home_currency = get_company_currency();
-       if ($to_curr_code == $home_currency) 
+       if ($to_curr_code == $home_currency)
        {
                return get_exchange_rate_to_home_currency($from_curr_code, $date_);
-       } 
-       
-       if ($from_curr_code == $home_currency) 
+       }
+
+       if ($from_curr_code == $home_currency)
        {
-               return get_exchange_rate_from_home_currency($to_curr_code, $date_);             
-       }       
-       
+               return get_exchange_rate_from_home_currency($to_curr_code, $date_);
+       }
+
        // neither from or to are the home currency
         return get_exchange_rate_to_home_currency($from_curr_code, $date_) / get_exchange_rate_to_home_currency($to_curr_code, $date_);
 }
@@ -136,9 +136,45 @@ function get_exchange_rate_from_to($from_curr_code, $to_curr_code, $date_)
 function exchange_from_to($amount, $from_curr_code, $to_curr_code, $date_)
 {
        $ex_rate = get_exchange_rate_from_to($from_curr_code, $to_curr_code, $date_);
-       return $amount / $ex_rate;              
+       return $amount / $ex_rate;
 }
 
 //--------------------------------------------------------------------------------
+// Exchange Variations Joe Hunt 2008-09-20 ////////////////////////////////////////
+
+function exchange_variation($pyt_type, $pyt_no, $type, $trans_no, $pyt_date, $amount, $person_type, $neg=false)
+{
+       if ($person_type == payment_person_types::customer())
+       {
+               $trans = get_customer_trans($trans_no, $type);
+               $ar_ap_act = $trans['receivables_account'];
+               $person_id = $trans['debtor_no'];
+               $curr = $trans['curr_code'];
+       }
+       else
+       {
+               $trans = get_supp_trans($trans_no, $type);
+               $supp_accs = get_supplier_accounts($trans['supplier_id']);
+               $ar_ap_act = $supp_accs['payable_account'];
+               $person_id = $trans['supplier_id'];
+               $curr = $trans['SupplierCurrCode'];
+       }
+       if (is_company_currency($curr))
+               return;
+       $exc_var_act = get_company_pref('exchange_diff_act');
+       $inv_amt = to_home_currency($amount, $curr, sql2date($trans['tran_date']));
+       $pay_amt = to_home_currency($amount, $curr, $pyt_date);
+       if ($inv_amt != $pay_amt)
+       {
+               $diff = $inv_amt - $pay_amt;
+               if ($person_type == payment_person_types::supplier())
+                       $diff = -$diff;
+               if ($neg)
+                       $diff = -$diff;
+               $memo = systypes::name($type)." ".$trans_no;
+               add_gl_trans($pyt_type, $pyt_no, $pyt_date, $ar_ap_act, 0, 0, $memo, -$diff, null, $person_type, $person_id);
+               add_gl_trans($pyt_type, $pyt_no, $pyt_date, $exc_var_act, 0, 0, $memo, $diff, null, $person_type, $person_id);
+       }
+}
 
 ?>
\ No newline at end of file
index 995b2735da945fc3e30bc1645cb38ebd0663bad2..fd617a2903b694765cd6f0391b1ec98ddeee2e1f 100644 (file)
@@ -74,7 +74,7 @@ function handle_process()
        begin_transaction();
 
        // clear all the allocations for this payment/credit
-       clear_supp_alloctions($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no);
+       clear_supp_alloctions($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no, $_SESSION['alloc']->date_);
 
        // now add the new allocations
        $total_allocated = 0;
@@ -88,6 +88,14 @@ function handle_process()
 
                        update_supp_trans_allocation($alloc_item->type, $alloc_item->type_no,
                                $alloc_item->current_allocated);
+
+                       // Exchange Variations Joe Hunt 2008-09-20 ////////////////////////////////////////
+
+                       exchange_variation($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no,
+                               $alloc_item->type, $alloc_item->type_no, $_SESSION['alloc']->date_,
+                               $alloc_item->current_allocated, payment_person_types::supplier());
+
+                       ///////////////////////////////////////////////////////////////////////////
                        $total_allocated += $alloc_item->current_allocated;
                }
 
index 24fab3ba104f09a05ad1df4f6c5c1244aa40ff9c..750bea5f6b891c9e402f9a4153398b09139662a7 100644 (file)
@@ -2,15 +2,15 @@
 
 //----------------------------------------------------------------------------------------
 
-function add_supp_allocation($amount, $trans_type_from, $trans_no_from, 
+function add_supp_allocation($amount, $trans_type_from, $trans_no_from,
        $trans_type_to, $trans_no_to, $date_)
 {
        $date = date2sql($date_);
        $sql = "INSERT INTO ".TB_PREF."supp_allocations (
-               amt, date_alloc, 
-               trans_type_from, trans_no_from, trans_no_to, trans_type_to) 
+               amt, date_alloc,
+               trans_type_from, trans_no_from, trans_no_to, trans_type_to)
                VALUES ($amount, '$date', $trans_type_from, $trans_no_from, $trans_no_to, $trans_type_to)";
-                       
+
        db_query($sql, "A supplier allocation could not be added to the database");
 }
 
@@ -27,11 +27,11 @@ function delete_supp_allocation($trans_id)
 
 function get_supp_trans_allocation_balance($trans_type, $trans_no)
 {
-       $sql = "SELECT (ov_amount+ov_gst-ov_discount-alloc) AS BalToAllocate 
+       $sql = "SELECT (ov_amount+ov_gst-ov_discount-alloc) AS BalToAllocate
                FROM ".TB_PREF."supp_trans WHERE trans_no=$trans_no AND type=$trans_type";
        $result = db_query($sql,"calculate the allocation");
-       $myrow = db_fetch_row($result); 
-       
+       $myrow = db_fetch_row($result);
+
        return $myrow[0];
 }
 
@@ -46,38 +46,43 @@ function update_supp_trans_allocation($trans_type, $trans_no, $alloc)
 
 //-------------------------------------------------------------------------------------------------------------
 
-function void_supp_allocations($type, $type_no)
+function void_supp_allocations($type, $type_no, $date="")
 {
-       return clear_supp_alloctions($type, $type_no);
+       return clear_supp_alloctions($type, $type_no, $date);
 }
 
 //-------------------------------------------------------------------------------------------------------------
 
-function clear_supp_alloctions($type, $type_no)
+function clear_supp_alloctions($type, $type_no, $date="")
 {
        // clear any allocations for this transaction
-       $sql = "SELECT * FROM ".TB_PREF."supp_allocations 
-               WHERE (trans_type_from=$type AND trans_no_from=$type_no) 
+       $sql = "SELECT * FROM ".TB_PREF."supp_allocations
+               WHERE (trans_type_from=$type AND trans_no_from=$type_no)
                OR (trans_type_to=$type AND trans_no_to=$type_no)";
        $result = db_query($sql, "could not void supp transactions for type=$type and trans_no=$type_no");
-       
+
        while ($row = db_fetch($result))
        {
                $sql = "UPDATE ".TB_PREF."supp_trans SET alloc=alloc - " . $row['amt'] . "
-                       WHERE (type= " . $row['trans_type_from'] . " AND trans_no=" . $row['trans_no_from'] . ") 
+                       WHERE (type= " . $row['trans_type_from'] . " AND trans_no=" . $row['trans_no_from'] . ")
                        OR (type=" . $row['trans_type_to'] . " AND trans_no=" . $row['trans_no_to'] . ")";
                //$sql = "UPDATE ".TB_PREF."supp_trans SET alloc=alloc - " . $row['amt'] . "
                //      WHERE type=" . $row['trans_type_to'] . " AND trans_no=" . $row['trans_no_to'];
-               db_query($sql, "could not clear allocation");                                           
+               db_query($sql, "could not clear allocation");
+               // 2008-09-20 Joe Hunt
+               if ($date != "")
+                       exchange_variation($type, $type_no, $row['trans_type_to'], $row['trans_no_to'], $date,
+                               $row['amt'], payment_person_types::supplier(), true);
+               //////////////////////
        }
-                                               
+
 
        // remove any allocations for this transaction
-       $sql = "DELETE FROM ".TB_PREF."supp_allocations 
-               WHERE (trans_type_from=$type AND trans_no_from=$type_no) 
+       $sql = "DELETE FROM ".TB_PREF."supp_allocations
+               WHERE (trans_type_from=$type AND trans_no_from=$type_no)
                OR (trans_type_to=$type AND trans_no_to=$type_no)";
-                               
-       db_query($sql, "could not void supp transactions for type=$type and trans_no=$type_no");                                        
+
+       db_query($sql, "could not void supp transactions for type=$type and trans_no=$type_no");
 }
 
 //-------------------------------------------------------------------------------------------------------------
@@ -85,38 +90,38 @@ function clear_supp_alloctions($type, $type_no)
 function get_allocatable_from_supp_transactions($supplier_id, $settled)
 {
        $settled_sql = "";
-       if (!$settled) 
+       if (!$settled)
        {
                $settled_sql = "AND round(ABS(ov_amount+ov_gst+ov_discount)-alloc,6) > 0";
        }
-       
+
        $supp_sql = "";
        if ($supplier_id != null)
-               $supp_sql = " AND ".TB_PREF."supp_trans.supplier_id = $supplier_id";            
-       
-       return get_supplier_transactions("round(ABS(ov_amount+ov_gst+ov_discount)-alloc,6) <= 0 AS settled", 
-               "(type=22 OR type=21 OR type=1) AND (ov_amount < 0) " . $settled_sql . $supp_sql);      
+               $supp_sql = " AND ".TB_PREF."supp_trans.supplier_id = $supplier_id";
+
+       return get_supplier_transactions("round(ABS(ov_amount+ov_gst+ov_discount)-alloc,6) <= 0 AS settled",
+               "(type=22 OR type=21 OR type=1) AND (ov_amount < 0) " . $settled_sql . $supp_sql);
 }
 
 //-------------------------------------------------------------------------------------------------------------
 
 function get_allocatable_to_supp_transactions($supplier_id, $trans_no=null, $type=null)
-{      
-       if ($trans_no != null && $type!= null) 
+{
+       if ($trans_no != null && $type!= null)
        {
-               return get_supplier_transactions("amt", "".TB_PREF."supp_trans.trans_no = ".TB_PREF."supp_allocations.trans_no_to 
+               return get_supplier_transactions("amt", "".TB_PREF."supp_trans.trans_no = ".TB_PREF."supp_allocations.trans_no_to
                        AND ".TB_PREF."supp_trans.type = ".TB_PREF."supp_allocations.trans_type_to
                        AND ".TB_PREF."supp_allocations.trans_no_from=$trans_no
-                       AND ".TB_PREF."supp_allocations.trans_type_from=$type 
-                       AND ".TB_PREF."supp_trans.supplier_id=$supplier_id", 
-                       "".TB_PREF."supp_allocations");                                         
-       } 
-       else 
+                       AND ".TB_PREF."supp_allocations.trans_type_from=$type
+                       AND ".TB_PREF."supp_trans.supplier_id=$supplier_id",
+                       "".TB_PREF."supp_allocations");
+       }
+       else
        {
                return get_supplier_transactions(null, "round(ABS(ov_amount+ov_gst+ov_discount)-alloc,6) > 0
                        AND ".TB_PREF."supp_trans.type != 22
                        AND ".TB_PREF."supp_trans.supplier_id=$supplier_id");
-       }                                                                                                                       
+       }
 }
 
 
index 46ac9184477abd6f405f1224491c81b9deeef32a..35e69ddae362025a9eb374c063b3f493d68474c9 100644 (file)
@@ -2,9 +2,9 @@
 //============================================================+
 // File name   : tcpdf.php
 // Begin       : 2002-08-03
-// Last Update : 2008-09-17
+// Last Update : 2008-09-19
 // Author      : Nicola Asuni - info@tecnick.com - http://www.tcpdf.org
-// Version     : 4.0.026_PHP4
+// Version     : 4.0.027_PHP4
 // License     : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
 //     ----------------------------------------------------------------------------
 //  Copyright (C) 2002-2008  Nicola Asuni - Tecnick.com S.r.l.
  * @copyright 2004-2008 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  * @link http://www.tcpdf.org
  * @license http://www.gnu.org/copyleft/lesser.html LGPL
- * @version 4.0.026_PHP4
+ * @version 4.0.027_PHP4
  */
 
 /**
@@ -178,14 +178,14 @@ if (!class_exists('TCPDF')) {
        /**
         * define default PDF document producer
         */
-       define('PDF_PRODUCER','TCPDF 4.0.026_PHP4 (http://www.tcpdf.org)');
+       define('PDF_PRODUCER','TCPDF 4.0.027_PHP4 (http://www.tcpdf.org)');
 
        /**
        * This is a PHP class for generating PDF documents without requiring external extensions.<br>
        * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
        * @name TCPDF
        * @package com.tecnick.tcpdf
-       * @version 4.0.026_PHP4
+       * @version 4.0.027_PHP4
        * @author Nicola Asuni - info@tecnick.com
        * @link http://www.tcpdf.org
        * @license http://www.gnu.org/copyleft/lesser.html LGPL
@@ -7698,6 +7698,9 @@ if (!class_exists('TCPDF')) {
                        if (empty($this->javascript)) {
                                return;
                        }
+                       // the following two lines are uded to avoid form fields duplication after saving
+                       $js1 = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2f,%.2f,%.2f,%.2f]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
+                       $js2 = "getField('tcpdfdocsaved').value = 'saved';";
                        $this->_newobj();
                        $this->n_js = $this->n;
                        $this->_out('<<');
@@ -7707,7 +7710,7 @@ if (!class_exists('TCPDF')) {
                        $this->_newobj();
                        $this->_out('<<');
                        $this->_out('/S /JavaScript');
-                       $this->_out('/JS '.$this->_textstring($this->javascript));
+                       $this->_out('/JS '.$this->_textstring($js1."\n".$this->javascript."\n".$js2));
                        $this->_out('>>');
                        $this->_out('endobj');
                }
@@ -7744,6 +7747,8 @@ if (!class_exists('TCPDF')) {
                * @since 2.1.002 (2008-02-12)
                */
                function _addfield($type, $name, $x, $y, $w, $h, $prop) {
+                       // the followind avoid fields duplication after saving the document
+                       $this->javascript .= "if(getField('tcpdfdocsaved').value != 'saved') {";
                        $k = $this->k;
                        $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%d,[%.2f,%.2f,%.2f,%.2f]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n";
                        $this->javascript .= "f".$name.".textSize=".$this->FontSizePt.";\n";
@@ -7756,6 +7761,7 @@ if (!class_exists('TCPDF')) {
                                $this->javascript .= "f".$name.".".$key."=".$val.";\n";
                        }
                        $this->x += $w;
+                       $this->javascript .= "}";
                }
 
                /*
@@ -9456,12 +9462,12 @@ if (!class_exists('TCPDF')) {
                        $yshift = 0;
                        $startlinepage = $this->page;
                        $newline = true;
-                       if (isset($this->footerpos[$this->page])) {
+                       if (isset($this->footerlen[$this->page])) {
                                $this->footerpos[$this->page] = strlen($this->pages[$this->page]) - $this->footerlen[$this->page];
-                               $startlinepos = $this->footerpos[$this->page];
                        } else {
-                               $startlinepos = strlen($this->pages[$this->page]);
+                               $this->footerpos[$this->page] = strlen($this->pages[$this->page]);
                        }
+                       $startlinepos = $this->footerpos[$this->page];
                        $lalign = $align;
                        $plalign = $align;
                        if ($this->rtl) {
@@ -9547,12 +9553,12 @@ if (!class_exists('TCPDF')) {
                                                        // the last line must be shifted to be aligned as requested
                                                        $linew = abs($this->endlinex - $startlinex);
                                                        $pstart = substr($this->pages[$startlinepage], 0, $startlinepos);
-                                                       if (isset($opentagpos) AND isset($this->footerpos[$startlinepage])) {
+                                                       if (isset($opentagpos) AND isset($this->footerlen[$startlinepage])) {
                                                                $this->footerpos[$startlinepage] = strlen($this->pages[$startlinepage]) - $this->footerlen[$startlinepage];
                                                                $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
                                                        } elseif (isset($opentagpos)) {
                                                                $midpos = $opentagpos;
-                                                       } elseif (isset($this->footerpos[$startlinepage])) {
+                                                       } elseif (isset($this->footerlen[$startlinepage])) {
                                                                $this->footerpos[$startlinepage] = strlen($this->pages[$startlinepage]) - $this->footerlen[$startlinepage];
                                                                $midpos = $this->footerpos[$startlinepage];
                                                        } else {
@@ -9613,12 +9619,12 @@ if (!class_exists('TCPDF')) {
                                                $startlinepos = $endlinepos;
                                                unset($endlinepos);
                                        } else {
-                                               if (isset($this->footerpos[$this->page])) {
+                                               if (isset($this->footerlen[$this->page])) {
                                                        $this->footerpos[$this->page] = strlen($this->pages[$this->page]) - $this->footerlen[$this->page];
-                                                       $startlinepos = $this->footerpos[$this->page];
                                                } else {
-                                                       $startlinepos = strlen($this->pages[$this->page]);
+                                                       $this->footerpos[$this->page] = strlen($this->pages[$this->page]);
                                                }
+                                               $startlinepos = $this->footerpos[$this->page];
                                        }
                                        $plalign = $lalign;
                                        $this->newline = false;
@@ -9704,12 +9710,12 @@ if (!class_exists('TCPDF')) {
                                                        }
                                                        // add rowspan information to table element
                                                        if ($rowspan > 1) {
-                                                               if (isset($this->footerpos[$this->page])) {
+                                                               if (isset($this->footerlen[$this->page])) {
                                                                        $this->footerpos[$this->page] = strlen($this->pages[$this->page]) - $this->footerlen[$this->page];
-                                                                       $trintmrkpos = $this->footerpos[$this->page];
                                                                } else {
-                                                                       $trintmrkpos = strlen($this->pages[$this->page]);
+                                                                       $this->footerpos[$this->page] = strlen($this->pages[$this->page]);
                                                                }
+                                                               $trintmrkpos = $this->footerpos[$this->page];
                                                                $trsid = array_push($dom[$table_el]['rowspans'], array('rowspan' => $rowspan, 'colspan' => $colspan, 'startpage' => $this->page, 'startx' => $this->x, 'starty' => $this->y, 'intmrkpos' => $trintmrkpos));
                                                        }
                                                        $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
@@ -9769,12 +9775,12 @@ if (!class_exists('TCPDF')) {
                                                } else {
                                                        // opening tag (or self-closing tag)
                                                        if (!isset($opentagpos)) {
-                                                               if (isset($this->footerpos[$this->page])) {
+                                                               if (isset($this->footerlen[$this->page])) {
                                                                        $this->footerpos[$this->page] = strlen($this->pages[$this->page]) - $this->footerlen[$this->page];
-                                                                       $opentagpos = $this->footerpos[$this->page];
                                                                } else {
-                                                                       $opentagpos = strlen($this->pages[$this->page]);
+                                                                       $this->footerpos[$this->page] = strlen($this->pages[$this->page]);
                                                                }
+                                                               $opentagpos = $this->footerpos[$this->page];
                                                        }
                                                        $this->openHTMLTagHandler($dom, $key, $cell);
                                                }
@@ -9851,12 +9857,12 @@ if (!class_exists('TCPDF')) {
                                        // the last line must be shifted to be aligned as requested
                                        $linew = abs($this->endlinex - $startlinex);
                                        $pstart = substr($this->pages[$startlinepage], 0, $startlinepos);
-                                       if (isset($opentagpos) AND isset($this->footerpos[$startlinepage])) {
+                                       if (isset($opentagpos) AND isset($this->footerlen[$startlinepage])) {
                                                $this->footerpos[$startlinepage] = strlen($this->pages[$startlinepage]) - $this->footerlen[$startlinepage];
                                                $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
                                        } elseif (isset($opentagpos)) {
                                                $midpos = $opentagpos;
-                                       } elseif (isset($this->footerpos[$startlinepage])) {
+                                       } elseif (isset($this->footerlen[$startlinepage])) {
                                                $this->footerpos[$startlinepage] = strlen($this->pages[$startlinepage]) - $this->footerlen[$startlinepage];
                                                $midpos = $this->footerpos[$startlinepage];
                                        } else {
index d92cf39a1c562568a29c5a94aebe3ddf8fd4af76..39076ec19fce4b1b0342fac31fa0c8fbfddc29ca 100644 (file)
@@ -82,7 +82,7 @@ function handle_process()
        begin_transaction();
 
        // clear all the allocations for this payment/credit
-       clear_cust_alloctions($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no);
+       clear_cust_alloctions($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no, $_SESSION['alloc']->date_);
 
        // now add the new allocations
        $total_allocated = 0;
@@ -96,8 +96,15 @@ function handle_process()
 
                        update_debtor_trans_allocation($allocn_item->type, $allocn_item->type_no,
                                $allocn_item->current_allocated);
-                       $total_allocated += $allocn_item->current_allocated;
 
+                       // Exchange Variations Joe Hunt 2008-09-20 ////////////////////////////////////////
+
+                       exchange_variation($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no,
+                               $allocn_item->type, $allocn_item->type_no, $_SESSION['alloc']->date_,
+                               $allocn_item->current_allocated, payment_person_types::customer());
+
+                       ///////////////////////////////////////////////////////////////////////////
+                       $total_allocated += $allocn_item->current_allocated;
                }
 
        }  /*end of the loop through the array of allocations made */
@@ -242,7 +249,7 @@ function edit_allocations_for_transaction($type, $trans_no)
        else
        {
        display_note(_("There are no unsettled transactions to allocate."), 0, 1);
-               
+
                submit_center('Cancel', _("Back to Allocations"), true,
                        _('Abandon allocations and return to selection of allocatable amounts'), true);
     }
index 9dfae6e8fa0234d2a0360f0d07b1dbca60c2a82b..8062faf1be785b09da0cff4107d0df3509b440b4 100644 (file)
@@ -46,14 +46,14 @@ function update_debtor_trans_allocation($trans_type, $trans_no, $alloc)
 
 //-------------------------------------------------------------------------------------------------------------
 
-function void_cust_allocations($type, $type_no)
+function void_cust_allocations($type, $type_no, $date="")
 {
-       return clear_cust_alloctions($type, $type_no);
+       return clear_cust_alloctions($type, $type_no, $date);
 }
 
 //-------------------------------------------------------------------------------------------------------------
 
-function clear_cust_alloctions($type, $type_no)
+function clear_cust_alloctions($type, $type_no, $date="")
 {
        // clear any allocations for this transaction
        $sql = "SELECT * FROM ".TB_PREF."cust_allocations
@@ -67,6 +67,11 @@ function clear_cust_alloctions($type, $type_no)
                        WHERE (type= " . $row['trans_type_from'] . " AND trans_no=" . $row['trans_no_from'] . ")
                        OR (type=" . $row['trans_type_to'] . " AND trans_no=" . $row['trans_no_to'] . ")";
                db_query($sql, "could not clear allocation");
+               // 2008-09-20 Joe Hunt
+               if ($date != "")
+                       exchange_variation($type, $type_no, $row['trans_type_to'], $row['trans_no_to'], $date,
+                               $row['amt'], payment_person_types::customer(), true);
+               //////////////////////
        }
 
 
index 5197a9965064e2a2f9c1f2be240c7ba5bdbe88e9..74054b06965669e886c5e6389b6fa44a6286a4cd 100644 (file)
@@ -13,10 +13,10 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
            $customer_id, $branch_id, $date_, $ref, $amount, $discount);
 
        if ($trans_no != 0) {
-         delete_comments(12, $invoice_no);
-         void_bank_trans(12, $type_no, true);
+         delete_comments(12, $trans_no);
+         void_bank_trans(12, $trans_no, true);
          void_gl_trans(12, $trans_no, true);
-         void_cust_allocations(12, $trans_no);
+         void_cust_allocations(12, $trans_no, $date_);
        }
 
        /* Bank account entry first */
index 2b37e60ccce2811553623a3854df08e4bd8fee4c..40bea1914713bd2ad7ac108a1758849f5d629779 100644 (file)
@@ -68,7 +68,7 @@ function write_credit_note($credit_note, $write_off_acc)
                set_document_parent($credit_note);
        } else {
                delete_comments(11, $credit_no);
-               void_cust_allocations(11, $credit_no);
+               void_cust_allocations(11, $credit_no, $credit_date);
                void_gl_trans(11, $credit_no, true);
                void_stock_move(11, $credit_no);
                void_customer_trans_tax_details(11, $credit_no);