From 60e2b6dfc0b71af9fae2712058bdfaeacf2a9fee Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Sat, 20 Sep 2008 15:23:51 +0000 Subject: [PATCH] Fix for exchange variation when allocating payments. re-inserted in System and GL Setup. --- CHANGELOG.txt | 15 +++ admin/db/company_db.inc | 6 +- admin/gl_setup.php | 18 ++-- includes/banking.inc | 104 +++++++++++++------ purchasing/allocations/supplier_allocate.php | 10 +- purchasing/includes/db/suppalloc_db.inc | 75 ++++++------- reporting/includes/tcpdf.php | 50 +++++---- sales/allocations/customer_allocate.php | 13 ++- sales/includes/db/custalloc_db.inc | 11 +- sales/includes/db/payment_db.inc | 6 +- sales/includes/db/sales_credit_db.inc | 2 +- 11 files changed, 198 insertions(+), 112 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 0400ed9c..85569f07 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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 diff --git a/admin/db/company_db.inc b/admin/db/company_db.inc index ea99d872..8a832211 100644 --- a/admin/db/company_db.inc +++ b/admin/db/company_db.inc @@ -1,8 +1,9 @@ 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
"; 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 diff --git a/purchasing/allocations/supplier_allocate.php b/purchasing/allocations/supplier_allocate.php index 995b2735..fd617a29 100644 --- a/purchasing/allocations/supplier_allocate.php +++ b/purchasing/allocations/supplier_allocate.php @@ -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; } diff --git a/purchasing/includes/db/suppalloc_db.inc b/purchasing/includes/db/suppalloc_db.inc index 24fab3ba..750bea5f 100644 --- a/purchasing/includes/db/suppalloc_db.inc +++ b/purchasing/includes/db/suppalloc_db.inc @@ -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"); - } + } } diff --git a/reporting/includes/tcpdf.php b/reporting/includes/tcpdf.php index 46ac9184..35e69dda 100644 --- a/reporting/includes/tcpdf.php +++ b/reporting/includes/tcpdf.php @@ -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. @@ -120,7 +120,7 @@ * @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.
* 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.
* @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 { diff --git a/sales/allocations/customer_allocate.php b/sales/allocations/customer_allocate.php index d92cf39a..39076ec1 100644 --- a/sales/allocations/customer_allocate.php +++ b/sales/allocations/customer_allocate.php @@ -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); } diff --git a/sales/includes/db/custalloc_db.inc b/sales/includes/db/custalloc_db.inc index 9dfae6e8..8062faf1 100644 --- a/sales/includes/db/custalloc_db.inc +++ b/sales/includes/db/custalloc_db.inc @@ -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); + ////////////////////// } diff --git a/sales/includes/db/payment_db.inc b/sales/includes/db/payment_db.inc index 5197a996..74054b06 100644 --- a/sales/includes/db/payment_db.inc +++ b/sales/includes/db/payment_db.inc @@ -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 */ diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index 2b37e60c..40bea191 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -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); -- 2.30.2