Merged all main trunk bugfixes up to release 2.0.5
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 25 Nov 2008 10:26:54 +0000 (10:26 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 25 Nov 2008 10:26:54 +0000 (10:26 +0000)
33 files changed:
CHANGELOG.txt
admin/db/voiding_db.inc
admin/void_transaction.php
gl/includes/db/gl_db_trans.inc
gl/inquiry/gl_trial_balance.php
includes/banking.inc
includes/ui/ui_input.inc
includes/ui/ui_view.inc
manufacturing/manage/bom_edit.php
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/supp_payment_db.inc
purchasing/includes/db/supp_trans_db.inc
purchasing/includes/purchasing_db.inc
purchasing/includes/ui/invoice_ui.inc
purchasing/po_receive_items.php
purchasing/supplier_credit.php
purchasing/supplier_invoice.php
purchasing/supplier_payment.php
reporting/includes/class.pdf.inc
reporting/rep101.php
reporting/rep106.php
reporting/rep201.php
reporting/rep203.php
reporting/rep209.php
reporting/rep708.php
reporting/reports_main.php
sales/allocations/customer_allocate.php
sales/customer_payments.php
sales/includes/db/cust_trans_db.inc
sales/includes/db/payment_db.inc
sales/includes/sales_db.inc
sales/view/view_receipt.php
update.html

index f90bd18029cbd031b5929a640b038faec896c102..d853edd117d8afce691e2f4d7a75557fcd482cad 100644 (file)
@@ -19,6 +19,135 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+25-Nov-2008 Janusz Dobrowolski
+! Merged all changes from main trunk up to 2.0.5 (see details below)
+$ /CHANGELOG.txt
+  /update.html
+  /admin/void_transaction.php
+  /admin/db/voiding_db.inc
+  /gl/includes/db/gl_db_trans.inc
+  /gl/inquiry/gl_trial_balance.php
+  /includes/banking.inc
+  /includes/ui/ui_input.inc
+  /includes/ui/ui_view.inc
+  /manufacturing/manage/bom_edit.php
+  /purchasing/po_receive_items.php
+  /purchasing/supplier_credit.php
+  /purchasing/supplier_invoice.php
+  /purchasing/supplier_payment.php
+  /purchasing/includes/purchasing_db.inc
+  /purchasing/includes/db/invoice_db.inc
+  /purchasing/includes/db/supp_payment_db.inc
+  /purchasing/includes/db/supp_trans_db.inc
+  /purchasing/includes/ui/invoice_ui.inc
+  /reporting/rep101.php
+  /reporting/rep106.php
+  /reporting/rep201.php
+  /reporting/rep203.php
+  /reporting/rep209.php
+  /reporting/rep708.php
+  /reporting/reports_main.php
+  /reporting/includes/class.pdf.inc
+  /sales/customer_payments.php
+  /sales/allocations/customer_allocate.php
+  /sales/includes/sales_db.inc
+  /sales/includes/db/cust_trans_db.inc
+  /sales/includes/db/payment_db.inc
+  /sales/view/view_receipt.php
+------------------------------- Release 2.0.5 --------------------------------------------
+24-Nov.2008 Joe Hunt
+! Release 2.0.5
+$ config.php
+! Changed update.html
+$ update.html
+# Small bug fixes
+$ /reporting/includes/header2.inc
+  /sales/view/view_receipt.php
+
+20-Nov-2008 Janusz Dobrowolski
+# [0000082] Bad js allocation on All/None button press.
+$ /sales/allocations/customer_allocate.php
+
+20-Nov-2008 Joe Hunt
+# Do not allow editing invoice if allocated > 0
+$ /sales/inquiry/customer_inquiry.php
+
+19-Nov-2008 Joe Hunt
++ Possibility to view a transaction before final voiding.
+$ /admin/void_transaction.php
+
+11-Nov-2008 Janusz Dobrowolski
+# Fixed right alignment of amount cells.
+$ /includes/ui/ui_input.inc
+# Fixed display bug for fully received items and false modify conflicts.
+$ /purchasing/po_receive_items.php
+
+10-Nov-2008 Joe Hunt
+! [0000081] Trial Balance again minor changes.
+$ /gl/inquiry/gl_trial_balance.php
+  /reporting/rep708.php
+
+07-Nov-2008 Joe Hunt
+! [0000081] Changed Trial Balance to show all debits and credits (option to only show balances)
+$ /gl/inquiry/gl_trial_balance.php
+  /reporting/reports_main.php
+  /reporting/rep708.php
+  
+03-Nov-2008 Janusz Dobrowolski
+# Fixed price priority in automatic calculations.
+$ sales/includes/sales_db.inc
+
+30-Oct-2008 Janusz Dobrowolski
+# [0000080] BOM elements was not editable after entry.
+$ /manufacturing/manage/bom_edit.php
+
+29-Oct-2008 Joe Hunt
+# Voiding a supplier invoice/credit note with GL Postings creates a database error
+$ /purchasing/includes/db/invoice_db.inc
+
+28-Oct-2008 Joe Hunt
+# [0000079] Delivery Note/Sales Invoice should not be editable after it has been voided.
+$ /admin/db/voiding_db.inc
+  /sales/inquiry/sales_deliveries_view.php
+  /sales/inquiry/customer_inquiry.php
+  
+27-Oct-2008 Joe Hunt
+! [0000078] Opened Exchange rate for editing (without storing) in sales/purchasing module payment
+# Fixed exchange rate display bugs in Supplier Payment (earlier dates).
+$ /gl/includes/db/gl_db_trans.inc
+  /includes/banking.inc
+  /includes/ui/ui_view.inc
+  /purchasing/supplier_payment.php
+  /purchasing/includes/purchasing_db.inc
+  /purchasing/includes/db/supp_payment_db.inc
+  /purchasing/includes/db/supp_trans_db.inc
+  /sales/customer_payments.php
+  /sales/includes/sales_db.inc
+  /sales/includes/db/cust_trans_db.inc
+  /sales/includes/db/payment_db.inc
+# [0000078] Fixed some reports with wrong exchange rates.
+$ /reporting/rep101.php
+  /reporting/rep106.php
+  /reporting/rep201.php
+  /reporting/rep203.php
+  /reporting/rep209.php
++ Added confirm box when admins are about to remove PO GRNs from Supplier Invoice
+$ /purchasing/supplier_invoice.php
+
+24-Oct-2008 Joe Hunt
+! [0000077] Added a total before ending balance in trial balance (also in report)
+$ /gl/inquiry/gl_trial_balance.php
+  /reporting/rep708.php
+! Increased memory limit if reports in unicode (48M) as suggested in forum.
+  /reporting/includes/class.pdf.inc
+! Improved layout of Supplier Invoice/Credit. All Items can now be added in one sweep.
+$ /purchasing/supplier_invoice.php
+  /purchasing/supplier_credit.php
+  /purchasing/includes/ui/invoice_ui.inc
+  
+------------------------------- Release 2.0.4 --------------------------------------------
+23-Oct-2008 Joe Hunt
+! Release 2.0.4
 25-Nov-2008 Joe Hunt
 ! Inserted Copyright Notice and fixed graphic items
 $ /access/login.php
index 96e46a26bbd545b43adfc7950773e4e42ae3f313..0f77cb20cec7104265024f39da6ead7d2547a193 100644 (file)
@@ -49,9 +49,7 @@ function void_transaction($type, $type_no, $date_, $memo_)
                                $delivery = get_customer_trans($type_no, $type);
                                if ($delivery['trans_link'] != 0)
                                {
-                                       $inv = get_customer_trans($delivery['trans_link'], 10);
-                                       if ($inv['ov_amount'] != 0 || $inv['ov_discount'] != 0 || $inv['ov_gst'] != 0 || 
-                                               $inv['ov_freight'] != 0 || $inv['ov_freight_tax'] != 0 || $inv['alloc'] != 0)
+                                       if (get_voided_entry(10, $delivery['trans_link']) === false)
                                                return false;
                                }
                        }       
index 0e116ab96eed9b1c7c41f43edc142dba33ab99d3..e93af71a44af859ccebc44ab03d051aa471a22fb 100644 (file)
@@ -21,9 +21,82 @@ include_once($path_to_root . "/admin/db/voiding_db.inc");
 $js = "";
 if ($use_date_picker)
        $js .= get_js_date_picker();
+if ($use_popup_windows)
+       $js .= get_js_open_window(800, 500);
+       
 page(_("Void a Transaction"), false, false, "", $js);
 
 //----------------------------------------------------------------------------------------
+function exist_transaction($type, $type_no)
+{
+       $void_entry = get_voided_entry($type, $type_no);
+
+       if ($void_entry != null)
+               return false;
+
+       switch ($type) 
+       {
+               case 0 : // it's a journal entry
+                       if (!exists_gl_trans($type, $type_no))
+                               return false;
+                       break;
+
+               case 1 : // it's a payment
+               case 2 : // it's a deposit
+               case 4 : // it's a transfer
+                       if (!exists_bank_trans($type, $type_no))
+                               return false;
+                       break;
+
+               case 10 : // it's a customer invoice
+               case 11 : // it's a customer credit note
+               case 12 : // it's a customer payment
+               case 13 : // it's a customer dispatch
+                       if (!exists_customer_trans($type, $type_no))
+                               return false;
+                       break;
+
+               case systypes::location_transfer() : // it's a stock transfer
+                       if (get_stock_transfer_items($type_no) == null)
+                               return false;
+                       break;
+
+               case systypes::inventory_adjustment() : // it's a stock adjustment
+                       if (get_stock_adjustment_items($type_no) == null)
+                               return false;
+                       break;
+
+               case 25 : // it's a GRN
+                       return false;
+               case 20 : // it's a suppler invoice
+               case 21 : // it's a supplier credit note
+               case 22 : // it's a supplier payment
+                       if (!exists_supp_trans($type, $type_no))
+                               return false;
+                       break;
+
+               case systypes::work_order() : // it's a work order
+                       if (!get_work_order($type_no, true))
+                               return false;
+                       break;
+
+               case 28 : // it's a work order issue
+                       if (!exists_work_order_issue($type_no))
+                               return false;
+                       break;
+
+               case 29 : // it's a work order production
+                       if (!exists_work_order_produce($type_no))
+                               return false;
+                       break;
+
+               case systypes::cost_update() : // it's a stock cost update
+                       return false;
+                       break;
+       }
+
+       return true;
+}
 
 function voiding_controls()
 {
@@ -47,10 +120,26 @@ function voiding_controls()
        submit_center('ProcessVoiding', _("Void Transaction"), true, '', true);
     else 
     {
-       
-       display_note(_("Are you sure you want to void this transaction ? This action cannot be undone."), 0, 1);
-       submit_center_first('ConfirmVoiding', _("Proceed"), '', true);
-       submit_center_last('CancelVoiding', _("Cancel"), '', true);
+               if (!exist_transaction($_POST['filterType'],$_POST['trans_no']))
+               {
+                       display_error(_("The entered transaction does not exist or cannot be voided."));
+                       unset($_POST['trans_no']);
+                       unset($_POST['memo_']);
+                       unset($_POST['date_']);
+               submit_center('ProcessVoiding', _("Void Transaction"), true, '', true);
+               }       
+               else
+               {
+               display_notification_centered(_("Are you sure you want to void this transaction ? This action cannot be undone."), 0, 1);
+               if ($_POST['filterType'] == 0) // GL transaction are not included in get_trans_view_str
+                       $view_str = get_gl_view_str($_POST['filterType'],$_POST['trans_no'], _("View Transaction"));
+               else
+                       $view_str = get_trans_view_str($_POST['filterType'],$_POST['trans_no'], _("View Transaction"));
+               display_note($view_str);
+                       br();
+               submit_center_first('ConfirmVoiding', _("Proceed"), '', true);
+               submit_center_last('CancelVoiding', _("Cancel"), '', true);
+       }       
     }
 
        end_form();
index d44e8eac04578de6928b2d56425ea5ec5f81a4bc..30750bbbd4fb4042b1cf0276b402fef7e19a2109 100644 (file)
@@ -8,13 +8,18 @@
 // if $currency is not set, then defaults to no conversion
 
 function add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension2, $memo_,
-       $amount, $currency=null, $person_type_id=null, $person_id=null, $err_msg="")
+       $amount, $currency=null, $person_type_id=null, $person_id=null, $err_msg="", $rate=0)
 {
        global $use_audit_trail;
 
        $date = date2sql($date_);
        if ($currency != null)
-               $amount_in_home_currency = to_home_currency($amount, $currency, $date_);
+       {
+               if ($rate == 0)
+                       $amount_in_home_currency = to_home_currency($amount, $currency, $date_);
+               else
+                       $amount_in_home_currency = round($amount * $rate,  user_price_dec());
+       }               
        else
                $amount_in_home_currency = $amount;
        if ($dimension == null || $dimension < 0)
index 969cfcca0dd6c8030c6877e3afe950de87456d16..8d1ad8bcba2d79aae5827baa231e750b244c2ba7 100644 (file)
@@ -35,6 +35,7 @@ function gl_inquiry_controls()
     date_cells(_("From:"), 'TransFromDate', '', null, -30);
        date_cells(_("To:"), 'TransToDate');
        check_cells(_("No zero values"), 'NoZero', null);
+       check_cells(_("Only balances"), 'Balance', null);
 
        submit_cells('Show',_("Show"),'','', true);
     end_table();
@@ -43,33 +44,29 @@ function gl_inquiry_controls()
 
 //----------------------------------------------------------------------------------------------------
 
-function get_balance($account, $from, $to, $from_incl=true, $to_incl=true) {
-
-       $sql = "SELECT SUM(amount) As TransactionSum FROM ".TB_PREF."gl_trans
-               WHERE account='$account'";
-
-       if ($from)
-       {
-               $from_date = date2sql($from);
-               if ($from_incl)
-                       $sql .= " AND tran_date >= '$from_date'";
-               else
-                       $sql .= " AND tran_date > '$from_date'";
-       }
-
-       if ($to)
-       {
-               $to_date = date2sql($to);
-               if ($to_incl)
-                       $sql .= " AND tran_date <= '$to_date' ";
-               else
-                       $sql .= " AND tran_date < '$to_date' ";
-       }
+function get_balance($account, $from, $to, $from_incl=true, $to_incl=true) 
+{
+       $sql = "SELECT SUM(IF(amount >= 0, amount, 0)) as debit, SUM(IF(amount < 0, -amount, 0)) as credit, SUM(amount) as balance 
+               FROM ".TB_PREF."gl_trans,".TB_PREF."chart_master,".TB_PREF."chart_types, ".TB_PREF."chart_class 
+               WHERE ".TB_PREF."gl_trans.account=".TB_PREF."chart_master.account_code AND ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id 
+               AND ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid AND";
+               
+       if ($account != null)
+               $sql .= " account='$account' AND";
+       $from_date = date2sql($from);
+       if ($from_incl)
+               $sql .= " tran_date >= '$from_date'  AND";
+       else
+               $sql .= " tran_date > IF(".TB_PREF."chart_class.balance_sheet=1, '0000-00-00', '$from_date') AND";
+       $to_date = date2sql($to);
+       if ($to_incl)
+               $sql .= " tran_date <= '$to_date' ";
+       else
+               $sql .= " tran_date < '$to_date' ";
 
        $result = db_query($sql,"No general ledger accounts were returned");
 
-       $row = db_fetch_row($result);
-       return $row[0];
+       return db_fetch($result);
 }
 
 //----------------------------------------------------------------------------------------------------
@@ -99,44 +96,74 @@ function display_trial_balance()
 
        $k = 0;
 
-       $totprev = $totcurr = 0.0;
        $accounts = get_gl_accounts();
-
+       $pdeb = $pcre = $cdeb = $ccre = $tdeb = $tcre = $pbal = $cbal = $tbal = 0;
+       $begin = begin_fiscalyear();
+       if (date1_greater_date2($begin, $_POST['TransFromDate']))
+               $begin = $_POST['TransFromDate'];
+       $begin = add_days($begin, -1);
+       
        while ($account = db_fetch($accounts))
        {
-               if (is_account_balancesheet($account["account_code"]))
-                       $begin = null;
-               else
-               {
-                       $begin = begin_fiscalyear();
-                       if (date1_greater_date2($begin, $_POST['TransFromDate']))
-                               $begin = $_POST['TransFromDate'];
-                       $begin = add_days($begin, -1);
-               }
-               $prev_balance = get_balance($account["account_code"], $begin, $_POST['TransFromDate'], false, false);
-
-               $curr_balance = get_balance($account["account_code"], $_POST['TransFromDate'], $_POST['TransToDate']);
-               if (check_value("NoZero") && !$prev_balance && !$curr_balance)
+               $prev = get_balance($account["account_code"], $begin, $_POST['TransFromDate'], false, false);
+               $curr = get_balance($account["account_code"], $_POST['TransFromDate'], $_POST['TransToDate'], true, true);
+               $tot = get_balance($account["account_code"], $begin, $_POST['TransToDate'], false, true);
+               if (check_value("NoZero") && !$prev['balance'] && !$curr['balance'] && !$tot['balance'])
                        continue;
-               $totprev += $prev_balance;
-               $totcurr += $curr_balance;
                alt_table_row_color($k);
 
                $url = "<a href='$path_to_root/gl/inquiry/gl_account_inquiry.php?" . SID . "TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "'>" . $account["account_code"] . "</a>";
 
                label_cell($url);
                label_cell($account["account_name"]);
-
-               display_debit_or_credit_cells($prev_balance);
-               display_debit_or_credit_cells($curr_balance);
-               display_debit_or_credit_cells($prev_balance + $curr_balance);
+               if (check_value('Balance'))
+               {
+                       display_debit_or_credit_cells($prev['balance']);
+                       display_debit_or_credit_cells($curr['balance']);
+                       display_debit_or_credit_cells($tot['balance']);
+                       
+               }
+               else
+               {
+                       amount_cell($prev['debit']);
+                       amount_cell($prev['credit']);
+                       amount_cell($curr['debit']);
+                       amount_cell($curr['credit']);
+                       amount_cell($tot['debit']);
+                       amount_cell($tot['credit']);
+                       $pdeb += $prev['debit'];
+                       $pcre += $prev['credit'];
+                       $cdeb += $curr['debit'];
+                       $ccre += $curr['credit'];
+                       $tdeb += $tot['debit'];
+                       $tcre += $tot['credit'];
+               }       
+               $pbal += $prev['balance'];
+               $cbal += $curr['balance'];
+               $tbal += $tot['balance'];
                end_row();
        }
-       start_row("class='inquirybg'");
-       label_cell("<b>" . _("Ending Balance") ." - ".$_POST['TransToDate']. "</b>", "colspan=2");
-       display_debit_or_credit_cells($totprev);
-       display_debit_or_credit_cells($totcurr);
-       display_debit_or_credit_cells($totprev + $totcurr);
+
+       //$prev = get_balance(null, $begin, $_POST['TransFromDate'], false, false);
+       //$curr = get_balance(null, $_POST['TransFromDate'], $_POST['TransToDate'], true, true);
+       //$tot = get_balance(null, $begin, $_POST['TransToDate'], false, true);
+       if (!check_value('Balance'))
+       {
+               start_row("class='inquirybg' style='font-weight:bold'");
+               label_cell(_("Total") ." - ".$_POST['TransToDate'], "colspan=2");
+               amount_cell($pdeb);
+               amount_cell($pcre);
+               amount_cell($cdeb);
+               amount_cell($ccre);
+               amount_cell($tdeb);
+               amount_cell($tcre);
+               end_row();
+       }       
+       start_row("class='inquirybg' style='font-weight:bold'");
+       label_cell(_("Ending Balance") ." - ".$_POST['TransToDate'], "colspan=2");
+       display_debit_or_credit_cells($pbal);
+       display_debit_or_credit_cells($cbal);
+       display_debit_or_credit_cells($tbal);
        end_row();
 
        end_table(1);
index 54345259c889ffb9c573a96e2dbfd3ecb69431f1..39b904c8b43b3c63515e11b886c478532f57e30c 100644 (file)
@@ -158,6 +158,7 @@ function exchange_variation($pyt_type, $pyt_no, $type, $trans_no, $pyt_date, $am
        if ($person_type == payment_person_types::customer())
        {
                $trans = get_customer_trans($trans_no, $type);
+               $pyt_trans = get_customer_trans($pyt_no, $pyt_type);
                $ar_ap_act = $trans['receivables_account'];
                $person_id = $trans['debtor_no'];
                $curr = $trans['curr_code'];
@@ -165,6 +166,7 @@ function exchange_variation($pyt_type, $pyt_no, $type, $trans_no, $pyt_date, $am
        else
        {
                $trans = get_supp_trans($trans_no, $type);
+               $pyt_trans = get_supp_trans($pyt_no, $pyt_type);
                $supp_accs = get_supplier_accounts($trans['supplier_id']);
                $ar_ap_act = $supp_accs['payable_account'];
                $person_id = $trans['supplier_id'];
@@ -172,9 +174,8 @@ function exchange_variation($pyt_type, $pyt_no, $type, $trans_no, $pyt_date, $am
        }
        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);
+       $inv_amt = round($amount * $trans['rate'], user_price_dec()); 
+       $pay_amt = round($amount * $pyt_trans['rate'], user_price_dec());
        if ($inv_amt != $pay_amt)
        {
                $diff = $inv_amt - $pay_amt;
@@ -182,6 +183,7 @@ function exchange_variation($pyt_type, $pyt_no, $type, $trans_no, $pyt_date, $am
                        $diff = -$diff;
                if ($neg)
                        $diff = -$diff;
+               $exc_var_act = get_company_pref('exchange_diff_act');
                $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);
index 59064f82de031820d3c698b0995031687840cfad..951bbccd018b25b025e3704547cd347b25987d73 100644 (file)
@@ -494,7 +494,7 @@ function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=nu
        if (!isset($max))
                $max = $size;
 
-       echo "<td>";
+       echo "<td align='right'>";
 
        echo "<input class='amount' type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" dec=\"$dec\" value=\"" . $_POST[$name]. "\">";
 
index 221ba624f3e3d64a1365615d1e6ba17040e0ef78..a757baccd6b060a1cf582ffa34258c251e2f4071 100644 (file)
@@ -288,7 +288,7 @@ function get_trans_view_str($type, $trans_no, $label="", $icon=false)
 // When there is no exrate for today, 
 // gets it form ECB and stores in local database.
 //
-function exchange_rate_display($from_currency, $to_currency, $date_)
+function exchange_rate_display($from_currency, $to_currency, $date_, $edit_rate=false)
 {
     global $Ajax;
 
@@ -309,15 +309,16 @@ function exchange_rate_display($from_currency, $to_currency, $date_)
                        }
                }
                if (!$rate)
-                       $rate = get_exchange_rate_from_to($to_currency, $from_currency, $date_);
-                       
-               if ($from_currency == $comp_currency)
-                       $rate = 1 / $rate;
+                       $rate = get_exchange_rate_from_home_currency($currency, $date_);
+               if ($from_currency != $comp_currency)
+                       $rate = 1 / ($rate / get_exchange_rate_from_home_currency($to_currency, $date_));
 
                $rate = number_format2($rate, user_exrate_dec());
-       label_row(_("Exchange Rate:"),"1 " . $from_currency 
-                       . " = <span id='_ex_rate'>" . $rate . "</span> " . $to_currency );
-                 $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
+               if ($edit_rate)
+                       text_row(_("Exchange Rate:"), '_ex_rate', $rate, 8, 8, null, "", " $from_currency = 1 $to_currency"); 
+               else
+               label_row(_("Exchange Rate:"),"<span id='_ex_rate'>$rate</span> $from_currency = 1 $to_currency" );
+               $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
        }
 }
 
index 8b978c7d8c4a57ec16ff496cacae2fca8ad4cd39..2ffb0b5f2731092200b045a2c2df638f6c9b5f60 100644 (file)
@@ -189,7 +189,7 @@ function on_submit($selected_parent, $selected_component=-1)
 
 if ($Mode == 'Delete')
 {
-       $sql = "DELETE FROM ".TB_PREF."bom WHERE id='" . $selected_component. "'";
+       $sql = "DELETE FROM ".TB_PREF."bom WHERE id='" . $selected_id. "'";
        db_query($sql,"Could not delete this bom components");
 
        display_notification(_("The component item has been deleted from this bom"));
@@ -198,7 +198,7 @@ if ($Mode == 'Delete')
 
 if ($Mode == 'RESET')
 {
-       $selected_component = -1;
+       $selected_id = -1;
        unset($_POST['quantity']);
 }
 
@@ -219,7 +219,7 @@ if (get_post('stock_id') != '')
 { //Parent Item selected so display bom or edit component
        $selected_parent = $_POST['stock_id'];
        if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
-               on_submit($selected_parent, $selected_component);
+               on_submit($selected_parent, $selected_id);
        //--------------------------------------------------------------------------------------
 
 start_form();
@@ -231,12 +231,12 @@ start_form();
 
        start_table($table_style2);
 
-       if ($selected_component != -1)
+       if ($selected_id != -1)
        {
                if ($Mode == 'Edit') {
                        //editing a selected component from the link to the line item
                        $sql = "SELECT ".TB_PREF."bom.*,".TB_PREF."stock_master.description FROM ".TB_PREF."bom,".TB_PREF."stock_master
-                               WHERE id='$selected_component'
+                               WHERE id='$selected_id'
                                AND ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.component";
 
                        $result = db_query($sql, "could not get bom");
@@ -245,9 +245,9 @@ start_form();
                        $_POST['loc_code'] = $myrow["loc_code"];
                        $_POST['workcentre_added']  = $myrow["workcentre_added"];
                        $_POST['quantity'] = number_format2($myrow["quantity"], get_qty_dec($myrow["component"]));
-               }
-               hidden('component', $selected_component);
                label_row(_("Component:"), $myrow["component"] . " - " . $myrow["description"]);
+               }
+               hidden('selected_id', $selected_id);
        }
        else
        {
@@ -272,7 +272,7 @@ start_form();
        qty_row(_("Quantity:"), 'quantity', null, null, null, $dec);
 
        end_table(1);
-       submit_add_or_update_center($selected_component == -1, '', true);
+       submit_add_or_update_center($selected_id == -1, '', true);
        end_form();
 }
 // ----------------------------------------------------------------------------------
index 33ec2b57205f662e7f599d4a9337fbf8c860c0f1..ec22b1cb2cdde221fff4f02df3c73ad3e5559fb3 100644 (file)
@@ -362,7 +362,7 @@ function void_supp_invoice($type, $type_no)
                $date_ = Today();
         while ($details_row = db_fetch($result))
         {
-               if (strlen($details_row["grn_item_id"]) > 0) // it can be empty for GL items
+               if ((int)$details_row["grn_item_id"] > 0) // it can be empty for GL items
                {
                        // Changed 2008-10-17 by Joe Hunt to get the avg. material cost updated
                                $old = update_supp_received_items_for_invoice($details_row["grn_item_id"],
index b82ab8889b818689efd006f2e7c4f6308d391b56..d15deb80930d789fa22a8608c47f4e37554a8cda 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 function add_supp_payment($supplier_id, $date_, $bank_account,
-       $amount, $discount, $ref, $memo_)
+       $amount, $discount, $ref, $memo_, $rate=0)
 {
        begin_transaction();
 
@@ -9,34 +9,43 @@ function add_supp_payment($supplier_id, $date_, $bank_account,
     $bank_account_currency = get_bank_account_currency($bank_account);
        $bank_gl_account = get_bank_gl_account($bank_account);
 
-       $supp_amount = exchange_from_to($amount, $bank_account_currency, $supplier_currency, $date_);
-       $supp_discount = exchange_from_to($discount, $bank_account_currency, $supplier_currency, $date_);
+       if ($rate == 0)
+       {
+               $supp_amount = exchange_from_to($amount, $bank_account_currency, $supplier_currency, $date_);
+               $supp_discount = exchange_from_to($discount, $bank_account_currency, $supplier_currency, $date_);
+       }
+       else
+       {
+               $supp_amount = $amount / $rate;
+               $supp_discount = $discount / $rate;
+       }
+       
 
        // it's a supplier payment
        $trans_type = 22;
 
        /* Create a supp_trans entry for the supplier payment */
        $payment_id = add_supp_trans($trans_type, $supplier_id, $date_, $date_,
-               $ref, "", -$supp_amount, 0, -$supp_discount);
+               $ref, "", -$supp_amount, 0, -$supp_discount, "", $rate);
 
        // Now debit creditors account with payment + discount
 
     $supplier_accounts = get_supplier_accounts($supplier_id);
 
        add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0,
-               $supp_amount + $supp_discount, $supplier_id);
+               $supp_amount + $supp_discount, $supplier_id, "", $rate);
 
        // Now credit discount received account with discounts
        if ($supp_discount != 0)
        {
                add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
-                       -$supp_discount, $supplier_id);
+                       -$supp_discount, $supplier_id, "", $rate);
        }
 
        if ($supp_amount != 0)
        {
                add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_gl_account, 0, 0,
-                       -$supp_amount, $supplier_id);
+                       -$supp_amount, $supplier_id, "", $rate);
        }
 
    /*now enter the bank_trans entry */
index 991fe7ddbbde383f8b58e10af502e2b3990e4f3c..716929c8699ab34cc4525b4c224d18cecabec034 100644 (file)
@@ -3,7 +3,7 @@
 //-------------------------------------------------------------------------------------------------------------
 
 function add_supp_trans($type, $supplier_id, $date_, $due_date, $reference, $supp_reference,
-       $amount, $amount_tax, $discount, $err_msg="")
+       $amount, $amount_tax, $discount, $err_msg="", $rate=0)
 {
        $date = date2sql($date_);
        if ($due_date == "")
@@ -14,7 +14,9 @@ function add_supp_trans($type, $supplier_id, $date_, $due_date, $reference, $sup
        $trans_no = get_next_trans_no($type);
 
        $curr = get_supplier_currency($supplier_id);
-       $rate = get_exchange_rate_from_home_currency($curr, $date_);
+       
+       if ($rate == 0)
+               $rate = get_exchange_rate_from_home_currency($curr, $date_);
 
 
        $sql = "INSERT INTO ".TB_PREF."supp_trans (trans_no, type, supplier_id, tran_date, due_date,
index 9ab331fe819bf33e0969f66eb4d0059013f1b0b0..a33c81b82fff13e404453b4e00888e608f651d2e 100644 (file)
@@ -23,14 +23,14 @@ include_once($path_to_root . "/purchasing/includes/db/suppliers_db.inc");
 // $amount is in SUPPLIERS'S currency
 
 function add_gl_trans_supplier($type, $type_no, $date_, $account, $dimension, $dimension2,  
-       $amount, $supplier_id, $err_msg="")
+       $amount, $supplier_id, $err_msg="", $rate=0)
 {
        if ($err_msg == "")
                $err_msg = "The supplier GL transaction could not be inserted"; 
                
        return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, "", 
                $amount, get_supplier_currency($supplier_id), 
-               payment_person_types::supplier(), $supplier_id, $err_msg);
+               payment_person_types::supplier(), $supplier_id, $err_msg, $rate);
 }
 
 //----------------------------------------------------------------------------------------
index 1162329be38ad0514102939c806425884cb2db9e..d72b0dcb95ec4d6697b325dab191bab0dc7a6ebf 100644 (file)
@@ -138,10 +138,10 @@ function invoice_totals(&$supp_trans)
     $display_total = price_format($supp_trans->ov_amount + $tax_total);
 
        if ($supp_trans->is_invoice)
-       label_row(_("Invoice Total:"), $display_total, "align=right", "align=right");
+       label_row(_("Invoice Total:"), $display_total, "align=right style='font-weight:bold;'", "align=right style='font-weight:bold;'");
     else
-               label_row("<font color=red>" . _("Credit Note Total:") . "</font>",
-                       "<font color=red><b>$display_total</b></font>", "align=right", "nowrap align=right");
+               label_row(_("Credit Note Total"),
+                       $display_total, "align=right style='font-weight:bold;color:red;'", "nowrap align=right style='font-weight:bold;color:red;'");
 
     end_table();
        br(1);
@@ -152,15 +152,13 @@ function invoice_totals(&$supp_trans)
 }
 
 //--------------------------------------------------------------------------------------------------
-function display_gl_controls(&$supp_trans)
+function display_gl_controls(&$supp_trans, $k)
 {
-       global $table_style, $Ajax;
-
-       div_start('gl_ctrls'); // 2008-10-18 Joe Hunt Moved up a bit to compute num-rows = 0
+       global $table_style;
 
        $accs = get_supplier_accounts($supp_trans->supplier_id);
        $_POST['gl_code'] = $accs['purchase_account'];
-       $k = 0;
+
        alt_table_row_color($k);
        gl_all_accounts_list('gl_code', null, true, false, true);
        $dim = get_company_pref('use_dimension');
@@ -180,7 +178,6 @@ function display_gl_controls(&$supp_trans)
        submit_cells('ClearFields', _("Reset"), "",
                    _("Clear all GL entry fields"), true);
        end_row();      
-       div_end();
 }
 
 // $mode = 0 none at the moment
@@ -251,7 +248,7 @@ function display_gl_items(&$supp_trans, $mode=0)
                        if ($dim > 1)
                                label_cell(get_dimension_string($entered_gl_code->gl_dim2, true));
 
-                       amount_cell($entered_gl_code->amount);
+                       amount_cell($entered_gl_code->amount, true);
                        label_cell($entered_gl_code->memo_);
 
                        if ($mode == 1)
@@ -274,7 +271,7 @@ function display_gl_items(&$supp_trans, $mode=0)
 
        }
        if ($mode == 1)
-               display_gl_controls($supp_trans);
+               display_gl_controls($supp_trans, $k);
        $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
        label_row(_("Total"), price_format($total_gl_value),
                "colspan=".$colspan." align=right", "nowrap align=right");
@@ -290,11 +287,10 @@ function display_gl_items(&$supp_trans, $mode=0)
 
 //--------------//-----------------------------------------------------------------------------------------
 
-function display_grn_items_for_selection(&$supp_trans)
+function display_grn_items_for_selection(&$supp_trans, $k)
 {
        global $table_style;
 
-       div_start('grn_table'); // 2008-10-18 Joe Hunt Moved up a bit to compute num-rows = 0
        if ($supp_trans->is_invoice)
                $result = get_grn_items(0, $supp_trans->supplier_id, true);
        else    
@@ -302,21 +298,11 @@ function display_grn_items_for_selection(&$supp_trans)
 
     if (db_num_rows($result) == 0)
     {
-               if ($supp_trans->is_invoice)
-               display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 1);
-       else
-       {
-                       display_note(_("There are no received items for the selected supplier that have been invoiced."));
-                       display_note(_("Credits can only be applied to invoiced items."), 0, 1);
-       }
-               div_end(); // Changed 2008-10-18 Joe Hunt
-       return;
+       return false;
     }
     
     /*Set up a table to show the outstanding GRN items for selection */
 
-    $k = 0;
-
     while ($myrow = db_fetch($result))
     {
                $grn_already_on_invoice = false;
@@ -370,8 +356,7 @@ function display_grn_items_for_selection(&$supp_trans)
                        end_row();
        }
     }
-
-       div_end();
+    return true;
 }
 
 //------------------------------------------------------------------------------------
@@ -385,6 +370,7 @@ function display_grn_items(&$supp_trans, $mode=0)
 {
        global $table_style, $path_to_root;
 
+    $ret = true;
     // if displaying in form, and no items, exit
     if (($mode == 2  || $mode == 3) && count($supp_trans->grn_items) == 0)
        return 0;
@@ -412,11 +398,15 @@ function display_grn_items(&$supp_trans, $mode=0)
        }               
        echo "<table width=100% >";
        echo "<tr><td align=center><span class='headingtext'>$heading</span></td>";
-       if ($mode == 1 && $heading2 != "")
+       if ($mode == 1)
        {
-               echo "</tr><td>";
-               display_note($heading2, 0, 0, "class='overduefg'");
-               echo "</td>\n";
+               submit_cells('InvGRNAll', _("Add All Items"), "align=right",false,true);
+               if ($heading2 != "")
+               {
+                       echo "</tr><td>";
+                       display_note($heading2, 0, 0, "class='overduefg'");
+                       echo "</td>\n";
+               }
        }       
        echo "</tr></table>";
 
@@ -468,14 +458,13 @@ function display_grn_items(&$supp_trans, $mode=0)
                                qty_cell($entered_grn->qty_recd, false, $dec);
                                qty_cell($entered_grn->prev_quantity_inv, false, $dec);
             }
-                       qty_cell(abs($entered_grn->this_quantity_inv), false, $dec);
+                       qty_cell(abs($entered_grn->this_quantity_inv), true, $dec);
                        amount_cell($entered_grn->chg_price);
-                       amount_cell( round($entered_grn->chg_price * abs($entered_grn->this_quantity_inv)), user_price_dec());
+                       amount_cell( round($entered_grn->chg_price * abs($entered_grn->this_quantity_inv), user_price_dec()), true);
 
                        if ($mode == 1)
                        {
-                               edit_button_cell("Delete" . $entered_grn->id, _("Delete"),
-                                         _('Remove item from document'));
+                               edit_button_cell("Delete" . $entered_grn->id, _("Edit"), _('Edit document line'));
                                if ($supp_trans->is_invoice && $_SESSION["wa_current_user"]->access == 2)         
                                        label_cell("");
                        }       
@@ -494,14 +483,24 @@ function display_grn_items(&$supp_trans, $mode=0)
     }
        if ($mode == 1)
        {
-               display_grn_items_for_selection($supp_trans);
-               $colspan = 10;
+               $ret = display_grn_items_for_selection($supp_trans, $k);
+       $colspan = 10;
        }
        else
                $colspan = 5;
        label_row(_("Total"), price_format($total_grn_value),
                "colspan=$colspan align=right", "nowrap align=right");
     echo "</table>";
+       if (!$ret)
+       {
+               if ($supp_trans->is_invoice)
+                       display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 1);
+               else
+               {
+                       display_note(_("There are no received items for the selected supplier that have been invoiced."));
+                       display_note(_("Credits can only be applied to invoiced items."), 0, 1);
+               }
+       }       
     div_end();
     echo "</td></tr>";
 
index d58e2aabfaca8a6e6972b44693709d4d2e1fb132..14a017be94d95278fee23d703bb623e8682e1a26 100644 (file)
@@ -90,8 +90,7 @@ function display_po_receive_items()
                        if ($qty_outstanding > 0)
                                qty_cells(null, $ln_itm->line_no, number_format2($ln_itm->receive_qty, $dec), "align=right", null, $dec);
                        else
-                               qty_cells(null, $ln_itm->line_no, number_format2($ln_itm->receive_qty, $dec), "align=right",
-                                       "disabled", $dec);
+                               label_cell(number_format2($ln_itm->receive_qty, $dec), "align=right");
 
                        amount_cell($ln_itm->price);
                        amount_cell($line_total);
@@ -115,9 +114,8 @@ function check_po_changed()
        // Otherwise if you try to fullfill item quantities separately will give error.
        $sql = "SELECT item_code, quantity_ordered, quantity_received, qty_invoiced
                FROM ".TB_PREF."purch_order_details
-               WHERE order_no=" . $_SESSION['PO']->order_no . "
-               AND (quantity_ordered > quantity_received)
-               ORDER BY po_detail_item";
+               WHERE order_no=" . $_SESSION['PO']->order_no 
+               ." ORDER BY po_detail_item";
 
        $result = db_query($sql, "could not query purch order details");
     check_db_error("Could not check that the details of the purchase order had not been changed by another user ", $sql);
@@ -126,7 +124,6 @@ function check_po_changed()
        while ($myrow = db_fetch($result))
        {
                $ln_item = $_SESSION['PO']->line_items[$line_no];
-
                // only compare against items that are outstanding
                $qty_outstanding = $ln_item->quantity - $ln_item->qty_received;
                if ($qty_outstanding > 0)
@@ -139,7 +136,7 @@ function check_po_changed()
                        return true;
                }
                }
-               $line_no++;
+               $line_no++;
        } /*loop through all line items of the order to ensure none have been invoiced */
 
        return false;
@@ -225,15 +222,17 @@ function process_receive_po()
 
        if (check_po_changed())
        {
-               echo "<br> " . _("This order has been changed or invoiced since this delivery was started to be actioned. Processing halted. To enter a delivery against this purchase order, it must be re-selected and re-read again to update the changes made by the other user.") . "<BR>";
-
-               echo "<center><a href='$path_to_root/purchasing/inquiry/po_search.php?" . SID . "'>" . _("Select a different purchase order for receiving goods against") . "</a></center>";
-               echo "<center><a href='$path_to_root/po_receive_items.php?" . SID . "PONumber=" . $_SESSION['PO']->OrderNumber . "'>" . _("Re-Read the updated purchase order for receiving goods against") . "</a></center>";
+               display_error(_("This order has been changed or invoiced since this delivery was started to be actioned. Processing halted. To enter a delivery against this purchase order, it must be re-selected and re-read again to update the changes made by the other user."));
+               hyperlink_no_params("$path_to_root/purchasing/inquiry/po_search.php",
+                _("Select a different purchase order for receiving goods against"));
+               hyperlink_params("$path_to_root/purchasing/po_receive_items.php", 
+                        _("Re-Read the updated purchase order for receiving goods against"),
+                        "PONumber=" . $_SESSION['PO']->order_no);
                unset($_SESSION['PO']->line_items);
                unset($_SESSION['PO']);
                unset($_POST['ProcessGoodsReceived']);
                $Ajax->activate('_page_body');
-               exit;
+               display_footer_exit();
        }
 
        $grn = add_grn($_SESSION['PO'], $_POST['DefaultReceivedDate'],
@@ -265,7 +264,7 @@ if (isset($_POST['Update']) || isset($_POST['ProcessGoodsReceived']))
        set from the post to the quantity to be received in this receival*/
        foreach ($_SESSION['PO']->line_items as $line)
        {
-
+        if( ($line->quantity - $line->qty_received)>0) {
                $_POST[$line->line_no] = max($_POST[$line->line_no], 0);
                if (!check_num($line->line_no))
                        $_POST[$line->line_no] = number_format2(0, get_qty_dec($line->stock_id));
@@ -279,6 +278,7 @@ if (isset($_POST['Update']) || isset($_POST['ProcessGoodsReceived']))
                {
                        $_SESSION['PO']->line_items[$line->line_no]->item_description = $_POST[$line->stock_id . "Desc"];
                }
+        }
        }
        $Ajax->activate('grn_items');
 }
index e7ddde0752131a789dd7cef8ef0d92d660f10f8e..3854b5ae0ad14dde15840463e23d686c0c8bcb5b 100644 (file)
@@ -80,7 +80,7 @@ function clear_fields()
        unset($_POST['amount']);
        unset($_POST['memo_']);
        unset($_POST['AddGLCodeToTrans']);
-       $Ajax->activate('gl_ctrls');
+       $Ajax->activate('gl_items');
        set_focus('gl_code');
 }
 //------------------------------------------------------------------------------------------------
@@ -232,44 +232,56 @@ function check_item_data($n)
        return true;
 }
 
-//-----------------------------------------------------------------------------------------
-
-$id = find_submit('grn_item_id');
-if ($id != -1)
+function commit_item_data($n)
 {
-       if (check_item_data($id))
+       if (check_item_data($n))
        {
                $complete = False;
 
-               //$_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'],
-       //      $_POST['po_detail_item'], $_POST['item_code'],
-       //      $_POST['item_description'], $_POST['qty_recd'],
-       //      $_POST['prev_quantity_inv'], $_POST['This_QuantityCredited'],
-       //      $_POST['order_price'], $_POST['ChgPrice'], $complete,
-       //      $_POST['std_cost_unit'], $_POST['gl_code']);
-               $_SESSION['supp_trans']->add_grn_to_trans($id,
-               $_POST['po_detail_item'.$id], $_POST['item_code'.$id],
-               $_POST['item_description'.$id], $_POST['qty_recd'.$id],
-               $_POST['prev_quantity_inv'.$id], input_num('This_QuantityCredited'.$id),
-               $_POST['order_price'.$id], input_num('ChgPrice'.$id), $complete,
-               $_POST['std_cost_unit'.$id], "");
+               $_SESSION['supp_trans']->add_grn_to_trans($n,
+               $_POST['po_detail_item'.$n], $_POST['item_code'.$n],
+               $_POST['item_description'.$n], $_POST['qty_recd'.$n],
+               $_POST['prev_quantity_inv'.$n], input_num('This_QuantityCredited'.$n),
+               $_POST['order_price'.$n], input_num('ChgPrice'.$n), $complete,
+               $_POST['std_cost_unit'.$n], "");
        }
 }
 
-//--------------------------------------------------------------------------------------------------
-$id = find_submit('Delete');
+//-----------------------------------------------------------------------------------------
+
+$id = find_submit('grn_item_id');
 if ($id != -1)
 {
-       $_SESSION['supp_trans']->remove_grn_from_trans($id);
+       commit_item_data($id);
+}
+
+if (isset($_POST['InvGRNAll']))
+{
+       foreach($_POST as $postkey=>$postval )
+    {
+               if (strpos($postkey, "qty_recd") === 0)
+               {
+                       $id = substr($postkey, strlen("qty_recd"));
+                       $id = (int)$id;
+                       commit_item_data($id);
+               }
+    }
+}      
+
+
+//--------------------------------------------------------------------------------------------------
+$id3 = find_submit('Delete');
+if ($id3 != -1)
+{
+       $_SESSION['supp_trans']->remove_grn_from_trans($id3);
        $Ajax->activate('grn_items');
-       $Ajax->activate('grn_table');
        $Ajax->activate('inv_tot');
 }
 
-$id = find_submit('Delete2');
-if ($id != -1)
+$id4 = find_submit('Delete2');
+if ($id4 != -1)
 {
-       $_SESSION['supp_trans']->remove_gl_codes_from_trans($id);
+       $_SESSION['supp_trans']->remove_gl_codes_from_trans($id4);
        clear_fields();
        $Ajax->activate('gl_items');
        $Ajax->activate('inv_tot');
@@ -304,10 +316,8 @@ echo "</td></tr>";
 
 end_table(1); // outer table
 
-$id = find_submit('grn_item_id');
 if ($id != -1)
 {
-       $Ajax->activate('grn_table');
        $Ajax->activate('grn_items');
        $Ajax->activate('inv_tot');
 }
index 28f7f33b982c9846f6e4f2e1759e751b901e1532..b78505180184a76b7ccdae60e3a6dd62299e5e64 100644 (file)
@@ -84,7 +84,7 @@ function clear_fields()
        unset($_POST['amount']);
        unset($_POST['memo_']);
        unset($_POST['AddGLCodeToTrans']);
-       $Ajax->activate('gl_ctrls');
+       $Ajax->activate('gl_items');
        set_focus('gl_code');
 }
 //------------------------------------------------------------------------------------------------
@@ -265,12 +265,11 @@ function check_item_data($n)
        return true;
 }
 
-$id = find_submit('grn_item_id');
-if ($id != -1)
+function commit_item_data($n)
 {
-       if (check_item_data($id))
+       if (check_item_data($n))
        {
-       if (input_num('this_quantity_inv'.$id) >= ($_POST['qty_recd'.$id] - $_POST['prev_quantity_inv'.$id]))
+       if (input_num('this_quantity_inv'.$n) >= ($_POST['qty_recd'.$n] - $_POST['prev_quantity_inv'.$n]))
        {
                $complete = true;
        }
@@ -279,33 +278,94 @@ if ($id != -1)
                $complete = false;
        }
 
-               $_SESSION['supp_trans']->add_grn_to_trans($id, $_POST['po_detail_item'.$id],
-                       $_POST['item_code'.$id], $_POST['item_description'.$id], $_POST['qty_recd'.$id],
-                       $_POST['prev_quantity_inv'.$id], input_num('this_quantity_inv'.$id),
-                       $_POST['order_price'.$id], input_num('ChgPrice'.$id), $complete,
-                       $_POST['std_cost_unit'.$id], "");
+               $_SESSION['supp_trans']->add_grn_to_trans($n, $_POST['po_detail_item'.$n],
+                       $_POST['item_code'.$n], $_POST['item_description'.$n], $_POST['qty_recd'.$n],
+                       $_POST['prev_quantity_inv'.$n], input_num('this_quantity_inv'.$n),
+                       $_POST['order_price'.$n], input_num('ChgPrice'.$n), $complete,
+                       $_POST['std_cost_unit'.$n], "");
        }
 }
 
-//--------------------------------------------------------------------------------------------------
-$id = find_submit('Delete');
+//-----------------------------------------------------------------------------------------
+
+$id = find_submit('grn_item_id');
 if ($id != -1)
 {
-       $_SESSION['supp_trans']->remove_grn_from_trans($id);
+       commit_item_data($id);
+}
+
+if (isset($_POST['InvGRNAll']))
+{
+       foreach($_POST as $postkey=>$postval )
+    {
+               if (strpos($postkey, "qty_recd") === 0)
+               {
+                       $id = substr($postkey, strlen("qty_recd"));
+                       $id = (int)$id;
+                       commit_item_data($id);
+               }
+    }
+}      
+
+//--------------------------------------------------------------------------------------------------
+$id3 = find_submit('Delete');
+if ($id3 != -1)
+{
+       $_SESSION['supp_trans']->remove_grn_from_trans($id3);
        $Ajax->activate('grn_items');
-       $Ajax->activate('grn_table');
        $Ajax->activate('inv_tot');
 }
 
-$id = find_submit('Delete2');
-if ($id != -1)
+$id4 = find_submit('Delete2');
+if ($id4 != -1)
 {
-       $_SESSION['supp_trans']->remove_gl_codes_from_trans($id);
+       $_SESSION['supp_trans']->remove_gl_codes_from_trans($id4);
        clear_fields();
        $Ajax->activate('gl_items');
        $Ajax->activate('inv_tot');
 }
 
+if ($_SESSION["wa_current_user"]->access == 2)
+{
+       $id3 = find_submit('void_item_id');
+       if ($id3 != -1) 
+       {
+               $js = "if(confirm(\""
+               .sprintf(_('You are about to remove all yet non-invoiced items from delivery line #%d. This operation also irreversibly changes related order line. Do you want to continue ?'), $id3)
+               ."\")) {
+                       JsHttpRequest.request(\"void_confirm".$id3."\");
+               }";
+               $Ajax->addScript(true,$js);
+       }
+       $id2 = find_submit('void_confirm');
+       if ($id2 != -1) // Added section 2008-10-18 Joe Hunt for voiding delivery lines
+       {
+               begin_transaction();
+               
+               $myrow = get_grn_item_detail($id2);
+
+               $grn = get_grn_batch($myrow['grn_batch_id']);
+
+           $sql = "UPDATE ".TB_PREF."purch_order_details
+                       SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"];
+           db_query($sql, "The quantity invoiced of the purchase order line could not be updated");
+
+           $sql = "UPDATE ".TB_PREF."grn_items
+               SET qty_recd = quantity_inv WHERE id = ".$myrow["id"];
+               db_query($sql, "The quantity invoiced off the items received record could not be updated");
+       
+               update_average_material_cost($grn["supplier_id"], $myrow["item_code"],
+                       $myrow["unit_price"], -$myrow["QtyOstdg"], Today());
+
+               add_stock_move(25, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
+                       -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']);
+                       
+               commit_transaction();
+               display_notification(sprintf(_('All yet non-invoiced items on delivery line # %d has been removed.'), $id2));
+
+       }               
+}
+
 start_form(false, true);
 
 start_table("$table_style2 width=98%", 8);
@@ -337,11 +397,10 @@ echo "</td></tr>";
 end_table(); // outer table
 
 //-----------------------------------------------------------------------------------------
-$id = find_submit('grn_item_id');
-$id2 = find_submit('void_item_id');
+
+
 if ($id != -1 || $id2 != -1)
 {
-       $Ajax->activate('grn_table');
        $Ajax->activate('grn_items');
        $Ajax->activate('inv_tot');
 }
@@ -349,34 +408,6 @@ if ($id != -1 || $id2 != -1)
 if (get_post('AddGLCodeToTrans'))
        $Ajax->activate('inv_tot');
 
-if ($_SESSION["wa_current_user"]->access == 2)
-{
-       if ($id2 != -1) // Added section 2008-10-18 Joe Hunt for voiding delivery lines
-       {
-               begin_transaction();
-               
-               $myrow = get_grn_item_detail($id2);
-
-               $grn = get_grn_batch($myrow['grn_batch_id']);
-
-           $sql = "UPDATE ".TB_PREF."purch_order_details
-                       SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"];
-           db_query($sql, "The quantity invoiced of the purchase order line could not be updated");
-
-           $sql = "UPDATE ".TB_PREF."grn_items
-               SET qty_recd = quantity_inv WHERE id = ".$myrow["id"];
-               db_query($sql, "The quantity invoiced off the items received record could not be updated");
-       
-               update_average_material_cost($grn["supplier_id"], $myrow["item_code"],
-                       $myrow["unit_price"], -$myrow["QtyOstdg"], Today());
-
-               add_stock_move(25, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
-                       -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']);
-                       
-               commit_transaction();
-       }               
-}
-
 echo "<br>";
 submit_center('PostInvoice', _("Enter Invoice"), true, '', true);
 echo "<br>";
index a530ecb4d8863134066d557f8b266af0c47c72ca..8f997c8888cb92052b1356d297a6c167fe86b5d6 100644 (file)
@@ -98,7 +98,7 @@ function display_controls()
        $bank_currency = get_bank_account_currency($_POST['bank_account']);
        if ($bank_currency != $supplier_currency) 
        {
-               exchange_rate_display($bank_currency, $supplier_currency, $_POST['DatePaid']);
+               exchange_rate_display($bank_currency, $supplier_currency, $_POST['DatePaid'], true);
        }
 
     ref_row(_("Reference:"), 'ref', '', references::get_next(22));
@@ -136,6 +136,13 @@ function check_inputs()
                return false;
        }
 
+       if (isset($_POST['_ex_rate']) && !check_num('_ex_rate', 0.000001))
+       {
+               display_error(_("The exchange rate must be numeric and greater than zero."));
+               set_focus('_ex_rate');
+               return false;
+       }
+
        if ($_POST['discount'] == "") 
        {
                $_POST['discount'] = 0;
@@ -150,7 +157,7 @@ function check_inputs()
 
        if (input_num('amount') - input_num('discount') <= 0) 
        {
-               display_error(_("The total of the amount and the discount negative. Please enter positive values."));
+               display_error(_("The total of the amount and the discount is zero or negative. Please enter positive values."));
                set_focus('amount');
                return false;
        }
@@ -188,9 +195,17 @@ function check_inputs()
 
 function handle_add_payment()
 {
+       $supp_currency = get_supplier_currency($_POST['supplier_id']);
+       $bank_currency = get_bank_account_currency($_POST['bank_account']);
+       $comp_currency = get_company_currency();
+       if ($comp_currency != $bank_currency && $bank_currency != $supp_currency)
+               $rate = 0;
+       else
+               $rate = input_num('_ex_rate');
+
        $payment_id = add_supp_payment($_POST['supplier_id'], $_POST['DatePaid'],
                $_POST['bank_account'], input_num('amount'), input_num('discount'), 
-               $_POST['ref'], $_POST['memo_']);
+               $_POST['ref'], $_POST['memo_'], $rate);
 
        //unset($_POST['supplier_id']);
        unset($_POST['bank_account']);
index fe6011e1b450f3ed57cb2aad7caa95ce83d8d8d3..856a7994ea49b1214d707fd41f69b08c6ed25c8b 100644 (file)
@@ -58,8 +58,8 @@ class Cpdf extends TCPDF {
                        $l = array('a_meta_charset' => 'ISO-8859-1', 'a_meta_dir' => 'ltr', 'a_meta_language' => 'en_GB', 'w_page' => 'page');
                $enc = $l['a_meta_charset'];
                $uni = ($enc == 'UTF-8' || $enc == 'GB2312' ? true : false);
-               if ($enc == "GB2312")
-                       ini_set("memory_limit", "25M");
+               if ($uni)
+                       ini_set("memory_limit", "48M");
                $this->TCPDF('P', 'pt', $pageSize, $uni, $enc);
                $this->setLanguageArray($l);
                $this->setPrintHeader(false);
index c98253f2ce46e94887ec38f3b8c9acf80d83bc9f..a206239a7ba82ef0c388109d2b957371399eaebc 100644 (file)
@@ -118,7 +118,7 @@ function print_customer_balances()
                                $rep->TextCol(3, 4,     sql2date($trans['due_date']));
                        $item[0] = $item[1] = 0.0;
                        if ($convert)
-                               $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
+                               $rate = $trans['rate'];
                        else
                                $rate = 1.0;
                        if ($trans['type'] == 11 || $trans['type'] == 12 || $trans['type'] == 2)
index 00e4046109de5d3633dfc102ddcc1c3a70ba96b7..ad26d7dd4ff177c9d1df5b6997448e1ae4d1da6c 100644 (file)
@@ -127,7 +127,7 @@ function print_salesman_list()
                        $subprov = 0;
                }
                $date = sql2date($myrow['tran_date']);
-               $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
+               $rate = $myrow['rate'];
                $amt = $myrow['InvoiceTotal'] * $rate;
                if ($subprov > $myrow['break_pt'] && $myrow['provision2'] != 0)
                        $prov = $myrow['provision2'] * $amt / 100;
index 92e85c0461c9be2c144bf4eb2bbe818a3bf4d087..89169ce0567eb011cdebc0a9627e00f3b8b6fa91 100644 (file)
@@ -118,7 +118,8 @@ function print_supplier_balances()
                                $rep->TextCol(3, 4,     sql2date($trans['due_date']));
                        $item[0] = $item[1] = 0.0;
                        if ($convert)
-                               $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
+                               //$rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
+                               $rate = $trans['rate'];
                        else
                                $rate = 1.0;
                        if ($trans['TotalAmount'] > 0.0)
index 625e3ce15bf85576f5038930d5d10e1376d4beeb..d69bf519dcb8024f66ae1bf9d4b8017ab03d864c 100644 (file)
@@ -25,17 +25,19 @@ function getTransactions($supplier, $date)
 
        $sql = "SELECT ".TB_PREF."sys_types.type_name,
                        ".TB_PREF."supp_trans.supp_reference,
+                       ".TB_PREF."supp_trans.tran_date,
                        ".TB_PREF."supp_trans.due_date,
                        ".TB_PREF."supp_trans.trans_no,
                        ".TB_PREF."supp_trans.type,
-                       (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst - ".TB_PREF."supp_trans.alloc) AS Balance,
-                       (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst ) AS TranTotal
+                       ".TB_PREF."supp_trans.rate,
+                       (ABS(".TB_PREF."supp_trans.ov_amount) + ABS(".TB_PREF."supp_trans.ov_gst) - ".TB_PREF."supp_trans.alloc) AS Balance,
+                       (ABS(".TB_PREF."supp_trans.ov_amount) + ABS(".TB_PREF."supp_trans.ov_gst) ) AS TranTotal
                FROM ".TB_PREF."supp_trans,
                        ".TB_PREF."sys_types
                WHERE ".TB_PREF."sys_types.type_id = ".TB_PREF."supp_trans.type
                AND ".TB_PREF."supp_trans.supplier_id = '" . $supplier . "'
-               AND ".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst - ".TB_PREF."supp_trans.alloc != 0
-               AND ".TB_PREF."supp_trans.due_date <='" . $date . "'
+               AND ABS(".TB_PREF."supp_trans.ov_amount) + ABS(".TB_PREF."supp_trans.ov_gst) - ".TB_PREF."supp_trans.alloc != 0
+               AND ".TB_PREF."supp_trans.tran_date <='" . $date . "'
                ORDER BY ".TB_PREF."supp_trans.type,
                        ".TB_PREF."supp_trans.trans_no";
 
@@ -106,12 +108,7 @@ function print_payment_report()
                $rep->fontSize += 2;
                $rep->TextCol(0, 6, $myrow['name'] . " - " . $myrow['terms']);
                if ($convert)
-               {
-                       $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $to);
                        $rep->TextCol(6, 7,     $myrow['curr_code']);
-               }
-               else
-                       $rate = 1.0;
                $rep->fontSize -= 2;
                $rep->NewLine(1, 2);
                $res = getTransactions($myrow['supplier_id'], $to);
@@ -121,11 +118,23 @@ function print_payment_report()
                $total[0] = $total[1] = 0.0;
                while ($trans=db_fetch($res))
                {
+                       if ($convert)
+                               $rate = $trans['rate'];
+                       else
+                               $rate = 1.0;
                        $rep->NewLine(1, 2);
                        $rep->TextCol(0, 1,     $trans['type_name']);
                        $rep->TextCol(1, 2,     $trans['supp_reference']);
-                       $rep->TextCol(2, 3,     sql2date($trans['due_date']));
-                       $item[0] = Abs($trans['TranTotal']) * $rate;
+                       if ($trans['type'] == 20)
+                               $rep->TextCol(2, 3,     sql2date($trans['due_date']));
+                       else    
+                               $rep->TextCol(2, 3,     sql2date($trans['tran_date']));
+                       if ($trans['type'] != 20)
+                       {
+                               $trans['TranTotal'] = -$trans['TranTotal'];
+                               $trans['Balance'] = -$trans['Balance'];
+                       }
+                       $item[0] = $trans['TranTotal'] * $rate;
                        $rep->TextCol(6, 7,     number_format2($item[0], $dec));
                        $item[1] = $trans['Balance'] * $rate;
                        $rep->TextCol(7, 8,     number_format2($item[1], $dec));
index 6ae258303147d1c9e62b557c352930eaa966237d..c6e0240f2289033aa1be1a934e4c01e6eb6adaef 100644 (file)
@@ -111,7 +111,7 @@ function print_po()
                        $DisplayNet = number_format2($Net,$dec);
                        //$rep->TextCol(0, 1,   $myrow2['item_code'], -2);
                        $rep->TextCol(0, 2,     $myrow2['description'], -2);
-                       $rep->TextCol(2, 3,     $myrow2['delivery_date'], -2);
+                       $rep->TextCol(2, 3,     sql2date($myrow2['delivery_date']), -2);
                        $rep->TextCol(3, 4,     $DisplayQty, -2);
                        $rep->TextCol(4, 5,     $myrow2['units'], -2);
                        $rep->TextCol(5, 6,     $DisplayPrice, -2);
index fc71d67318d84720f01c736f5fb8d48f9815d8a0..97d2d95d73d4b928ea55c4ffe4c6f2effaa44eaa 100644 (file)
@@ -19,6 +19,36 @@ include_once($path_to_root . "gl/includes/gl_db.inc");
 // trial_inquiry_controls();
 print_trial_balance();
 
+//----------------------------------------------------------------------------------------------------
+function get_balance($account, $dimension, $dimension2, $from, $to, $from_incl=true, $to_incl=true) 
+{
+       $sql = "SELECT SUM(IF(amount >= 0, amount, 0)) as debit, SUM(IF(amount < 0, -amount, 0)) as credit, SUM(amount) as balance 
+               FROM ".TB_PREF."gl_trans,".TB_PREF."chart_master,".TB_PREF."chart_types, ".TB_PREF."chart_class 
+               WHERE ".TB_PREF."gl_trans.account=".TB_PREF."chart_master.account_code AND ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id 
+               AND ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid AND";
+               
+       if ($account != null)
+               $sql .= " account='$account' AND";
+       if ($dimension > 0)
+               $sql .= " dimension_id=$dimension AND";
+       if ($dimension2 > 0)
+               $sql .= " dimension2_id=$dimension2 AND";
+       $from_date = date2sql($from);
+       if ($from_incl)
+               $sql .= " tran_date >= '$from_date'  AND";
+       else
+               $sql .= " tran_date > IF(".TB_PREF."chart_class.balance_sheet=1, '0000-00-00', '$from_date') AND";
+       $to_date = date2sql($to);
+       if ($to_incl)
+               $sql .= " tran_date <= '$to_date' ";
+       else
+               $sql .= " tran_date < '$to_date' ";
+
+       $result = db_query($sql,"No general ledger accounts were returned");
+
+       return db_fetch($result);
+}
+
 //----------------------------------------------------------------------------------------------------
 
 function print_trial_balance()
@@ -32,31 +62,34 @@ function print_trial_balance()
        $from = $_POST['PARAM_0'];
        $to = $_POST['PARAM_1'];
        $zero = $_POST['PARAM_2'];
+       $balances = $_POST['PARAM_3'];
        if ($dim == 2)
        {
-               $dimension = $_POST['PARAM_3'];
-               $dimension2 = $_POST['PARAM_4'];
-               $comments = $_POST['PARAM_5'];
+               $dimension = $_POST['PARAM_4'];
+               $dimension2 = $_POST['PARAM_5'];
+               $comments = $_POST['PARAM_6'];
        }
        else if ($dim == 1)
        {
-               $dimension = $_POST['PARAM_3'];
-               $comments = $_POST['PARAM_4'];
+               $dimension = $_POST['PARAM_4'];
+               $comments = $_POST['PARAM_5'];
        }
        else
        {
-               $comments = $_POST['PARAM_3'];
+               $comments = $_POST['PARAM_4'];
        }
        $dec = user_price_dec();
 
-       $cols2 = array(0, 50, 230, 330, 430, 530);
+       //$cols2 = array(0, 50, 230, 330, 430, 530);
+       $cols2 = array(0, 50, 190, 310, 430, 530);
        //-------------0--1---2----3----4----5--
 
        $headers2 = array('', '', _('Brought Forward'), _('This Period'), _('Balance'));
 
        $aligns2 = array('left', 'left', 'left', 'left', 'left');
 
-       $cols = array(0, 50, 200, 250, 300,     350, 400, 450, 500,     550);
+       //$cols = array(0, 50, 200, 250, 300,   350, 400, 450, 500,     550);
+       $cols = array(0, 50, 150, 210, 270,     330, 390, 450, 510,     570);
        //------------0--1---2----3----4----5----6----7----8----9--
 
        $headers = array(_('Account'), _('Account Name'), _('Debit'), _('Credit'), _('Debit'),
@@ -91,47 +124,58 @@ function print_trial_balance()
        $rep->Font();
        $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
        $rep->Header();
-       $totprev = $totcurr = 0.0;
 
        $accounts = get_gl_accounts();
 
+       $pdeb = $pcre = $cdeb = $ccre = $tdeb = $tcre = $pbal = $cbal = $tbal = 0;
+       $begin = begin_fiscalyear();
+       if (date1_greater_date2($begin, $from))
+               $begin = $from;
+       $begin = add_days($begin, -1);
        while ($account=db_fetch($accounts))
        {
+               $prev = get_balance($account["account_code"], $dimension, $dimension2, $begin, $from, false, false);
+               $curr = get_balance($account["account_code"], $dimension, $dimension2, $from, $to, true, true);
+               $tot = get_balance($account["account_code"], $dimension, $dimension2, $begin, $to, false, true);
 
-               if (is_account_balancesheet($account["account_code"]))
-                       $begin = "";
-               else
-               {
-                       $begin = begin_fiscalyear();
-                       if (date1_greater_date2($begin, $from))
-                               $begin = $from;
-                       $begin = add_days($begin, -1);
-               }
-
-               $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
-
-               $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
-
-               if ($zero == 0 && !$prev_balance && !$curr_balance)
+               if ($zero == 0 && !$prev['balance'] && !$curr['balance'] && !$tot['balance'])
                        continue;
-               $totprev += $prev_balance;
-               $totcurr += $curr_balance;
                $rep->TextCol(0, 1, $account['account_code']);
                $rep->TextCol(1, 2,     $account['account_name']);
-
-               if ($prev_balance >= 0.0)
-                       $rep->TextCol(2, 3,     number_format2(abs($prev_balance), $dec));
-               else
-                       $rep->TextCol(3, 4,     number_format2(abs($prev_balance), $dec));
-               if ($curr_balance >= 0.0)
-                       $rep->TextCol(4, 5,     number_format2(abs($curr_balance), $dec));
-               else
-                       $rep->TextCol(5, 6,     number_format2(abs($curr_balance), $dec));
-               if ($curr_balance + $prev_balance >= 0.0)
-                       $rep->TextCol(6, 7,     number_format2(abs($curr_balance + $prev_balance), $dec));
+               if ($balances != 0)
+               {
+                       if ($prev['balance'] >= 0.0)
+                               $rep->TextCol(2, 3,     number_format2($prev['balance'], $dec));
+                       else
+                               $rep->TextCol(3, 4,     number_format2(abs($prev['balance']), $dec));
+                       if ($curr['balance'] >= 0.0)
+                               $rep->TextCol(4, 5,     number_format2($curr['balance'], $dec));
+                       else
+                               $rep->TextCol(5, 6,     number_format2(abs($curr['balance']), $dec));
+                       if ($tot['balance'] >= 0.0)
+                               $rep->TextCol(6, 7,     number_format2($tot['balance'], $dec));
+                       else
+                               $rep->TextCol(7, 8,     number_format2(abs($tot['balance']), $dec));
+               }
                else
-                       $rep->TextCol(7, 8,     number_format2(abs($curr_balance + $prev_balance), $dec));
-
+               {
+                       $rep->TextCol(2, 3,     number_format2($prev['debit'], $dec));
+                       $rep->TextCol(3, 4,     number_format2($prev['credit'], $dec));
+                       $rep->TextCol(4, 5,     number_format2($curr['debit'], $dec));
+                       $rep->TextCol(5, 6,     number_format2($curr['credit'], $dec));
+                       $rep->TextCol(6, 7,     number_format2($tot['debit'], $dec));
+                       $rep->TextCol(7, 8,     number_format2($tot['credit'], $dec));
+                       $pdeb += $prev['debit'];
+                       $pcre += $prev['credit'];
+                       $cdeb += $curr['debit'];
+                       $ccre += $curr['credit'];
+                       $tdeb += $tot['debit'];
+                       $tcre += $tot['credit'];
+                       
+               }       
+               $pbal += $prev['balance'];
+               $cbal += $curr['balance'];
+               $tbal += $tot['balance'];
                $rep->NewLine();
 
                if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
@@ -144,20 +188,35 @@ function print_trial_balance()
        $rep->NewLine();
        $rep->Font('bold');
 
+       //$prev = get_balance(null, $dimension, $dimension2, $begin, $from, false, false);
+       //$curr = get_balance(null, $dimension, $dimension2, $from, $to, true, true);
+       //$tot = get_balance(null, $dimension, $dimension2, $begin, $to, false, true);
+
+       if ($balances == 0)
+       {
+               $rep->TextCol(0, 2, _("Total"));
+               $rep->TextCol(2, 3,     number_format2($pdeb, $dec));
+               $rep->TextCol(3, 4,     number_format2($pcre, $dec));
+               $rep->TextCol(4, 5,     number_format2($cdeb, $dec));
+               $rep->TextCol(5, 6,     number_format2($ccre, $dec));
+               $rep->TextCol(6, 7,     number_format2($tdeb, $dec));
+               $rep->TextCol(7, 8,     number_format2($tcre, $dec));
+               $rep->NewLine();
+       }       
        $rep->TextCol(0, 2, _("Ending Balance"));
 
-       if ($totprev >= 0.0)
-               $rep->TextCol(2, 3,     number_format2(abs($totprev), $dec));
+       if ($pbal >= 0.0)
+               $rep->TextCol(2, 3,     number_format2($pbal, $dec));
        else
-               $rep->TextCol(3, 4,     number_format2(abs($totprev), $dec));
-       if ($totcurr >= 0.0)
-               $rep->TextCol(4, 5,     number_format2(abs($totcurr), $dec));
+               $rep->TextCol(3, 4,     number_format2(abs($pbal), $dec));
+       if ($cbal >= 0.0)
+               $rep->TextCol(4, 5,     number_format2($cbal, $dec));
        else
-               $rep->TextCol(5, 6,     number_format2(abs($totcurr), $dec));
-       if ($totcurr + $totprev >= 0.0)
-               $rep->TextCol(6, 7,     number_format2(abs($totcurr + $totprev), $dec));
+               $rep->TextCol(5, 6,     number_format2(abs($cbal), $dec));
+       if ($tbal >= 0.0)
+               $rep->TextCol(6, 7,     number_format2($tbal, $dec));
        else
-               $rep->TextCol(7, 8,     number_format2(abs($totcurr + $totprev), $dec));
+               $rep->TextCol(7, 8,     number_format2(abs($tbal), $dec));
        
        $rep->Line($rep->row - 6);
        
index 42b1ad5901f95f7ddd25af126ae9fbcd6dfcb3cb..6e215c4683dab944caa3bd45d229d5d91e0069b8 100644 (file)
@@ -203,6 +203,7 @@ if ($dim == 2)
        array(  new ReportParam(_('Start Date'),'DATEBEGINM'),
                        new ReportParam(_('End Date'),'DATEENDM'),
                        new ReportParam(_('Zero values'),'YES_NO'),
+                       new ReportParam(_('Only balances'),'YES_NO'),
                        new ReportParam(_('Dimension')." 1", 'DIMENSIONS1'),
                        new ReportParam(_('Dimension')." 2", 'DIMENSIONS2'),
                        new ReportParam(_('Comments'),'TEXTBOX')));
@@ -237,6 +238,7 @@ else if ($dim == 1)
        array(  new ReportParam(_('Start Date'),'DATEBEGINM'),
                        new ReportParam(_('End Date'),'DATEENDM'),
                        new ReportParam(_('Zero values'),'YES_NO'),
+                       new ReportParam(_('Only balances'),'YES_NO'),
                        new ReportParam(_('Dimension'), 'DIMENSIONS1'),
                        new ReportParam(_('Comments'),'TEXTBOX')));
 }
@@ -266,6 +268,7 @@ else
        array(  new ReportParam(_('Start Date'),'DATEBEGINM'),
                        new ReportParam(_('End Date'),'DATEENDM'),
                        new ReportParam(_('Zero values'),'YES_NO'),
+                       new ReportParam(_('Only balances'),'YES_NO'),
                        new ReportParam(_('Comments'),'TEXTBOX')));
 }
 $reports->addReport(_('General Ledger'),709,_('Ta&x Report'),
index 39076ec19fce4b1b0342fac31fa0c8fbfddc29ca..5f30f66cf2a54d36c9aa5a52fd419bb7d5a4f0d5 100644 (file)
@@ -54,7 +54,7 @@ function check_data()
 
                  /*Now check to see that the AllocAmt is no greater than the
                amount left to be allocated against the transaction under review */
-               if (input_num('amount' . $counter) > $_POST['un_allocated' . $counter])
+               if (input_num('amount' . $counter) > input_num('un_allocated' . $counter))
                {
                    //$_POST['amount' . $counter] = $_POST['un_allocated' . $counter];
                }
@@ -219,7 +219,7 @@ function edit_allocations_for_transaction($type, $trans_no)
                        label_cell("<a href='#' name='Alloc$counter' onclick='allocate_all(this.name.substr(5));return true;'>"
                                         . _("All") . "</a>");
                        label_cell("<a href='#' name='DeAll$counter' onclick='allocate_none(this.name.substr(5));return true;'>"
-                                        . _("None") . "</a>".hidden("un_allocated" . $counter, $un_allocated, false));
+                                        . _("None") . "</a>".hidden("un_allocated" . $counter, price_format($un_allocated), false));
                        end_row();
 
            $total_allocated += input_num('amount' . $counter);
index 03639e75482a03983bf9c3c89b23af3a34b7a138..9f8b79027a8ef4e6252d596914bfe32ec4bfa521 100644 (file)
@@ -84,6 +84,18 @@ function can_process()
                return false;
        }
 
+       if (isset($_POST['_ex_rate']) && !check_num('_ex_rate', 0.000001))
+       {
+               display_error(_("The exchange rate must be numeric and greater than zero."));
+               set_focus('_ex_rate');
+               return false;
+       }
+
+       if ($_POST['discount'] == "") 
+       {
+               $_POST['discount'] = 0;
+       }
+
        if (!check_num('discount')) {
                display_error(_("The entered discount is not a valid number."));
                set_focus('discount');
@@ -118,9 +130,18 @@ if (isset($_POST['_DateBanked_changed'])) {
 //----------------------------------------------------------------------------------------------
 
 if (isset($_POST['AddPaymentItem'])) {
+       
+       $cust_currency = get_customer_currency($_POST['customer_id']);
+       $bank_currency = get_bank_account_currency($_POST['bank_account']);
+       $comp_currency = get_company_currency();
+       if ($comp_currency != $bank_currency && $bank_currency != $cust_currency)
+               $rate = 0;
+       else
+               $rate = input_num('_ex_rate');
+
        $payment_no = write_customer_payment(0, $_POST['customer_id'], $_POST['BranchID'],
                $_POST['bank_account'], $_POST['DateBanked'], $_POST['ref'],
-               input_num('amount'), input_num('discount'), $_POST['memo_']);
+               input_num('amount'), input_num('discount'), $_POST['memo_'], $rate);
        meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_no");
 }
 
@@ -195,7 +216,7 @@ function display_item_form()
                $bank_currency = get_bank_account_currency($_POST['bank_account']);
 
                if ($cust_currency != $bank_currency) {
-                       exchange_rate_display($cust_currency, $bank_currency, $_POST['DateBanked']);
+                       exchange_rate_display($bank_currency, $cust_currency, $_POST['DateBanked'], true);
                }
 
                text_row(_("Reference:"), 'ref', null, 20, 40);
index 709657d440c376432d403d3305897e337556ec97..6f536ca0cd150b5c43dec60e145ffb09bcc2c535 100644 (file)
@@ -83,7 +83,8 @@ function write_customer_trans($trans_type, $trans_no, $debtor_no, $BranchNo,
 {
 
        $curr = get_customer_currency($debtor_no);
-       $rate = get_exchange_rate_from_home_currency($curr, $date_);
+       if ($rate == 0)
+               $rate = get_exchange_rate_from_home_currency($curr, $date_);
 
        $SQLDate = date2sql($date_);
        if ($due_date == "")
index e1147b1c856465ed1643e32f475a12bb6ed56596..15ec358461e68cf139c0df01b10c7750a7969b1e 100644 (file)
@@ -3,14 +3,14 @@
   Write/update customer payment.
 */
 function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_account,
-       $date_, $ref, $amount, $discount, $memo_)
+       $date_, $ref, $amount, $discount, $memo_, $rate=0)
 {
        begin_transaction();
 
        $company_record = get_company_prefs();
 
-       $payment_no = write_customer_trans(12, $trans_no,
-           $customer_id, $branch_id, $date_, $ref, $amount, $discount);
+       $payment_no = write_customer_trans(12, $trans_no, $customer_id, $branch_id, 
+               $date_, $ref, $amount, $discount, 0, 0, 0, 0, 0, 0, 0, "", 0, $rate);
 
        $bank_gl_account = get_bank_gl_account($bank_account);
 
@@ -24,7 +24,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
        /* Bank account entry first */
        add_gl_trans_customer(12, $payment_no, $date_,
                $bank_gl_account, 0, 0, $amount,  $customer_id,
-               "Cannot insert a GL transaction for the bank account debit");
+               "Cannot insert a GL transaction for the bank account debit", $rate);
 
        if ($branch_id != reserved_words::get_any_numeric()) {
 
@@ -42,14 +42,14 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
                /* Now Credit Debtors account with receipts + discounts */
                add_gl_trans_customer(12, $payment_no, $date_,
                        $debtors_account, 0, 0, -($discount + $amount), $customer_id,
-                       "Cannot insert a GL transaction for the debtors account credit");
+                       "Cannot insert a GL transaction for the debtors account credit", $rate);
        }
 
        if ($discount != 0)     {
                /* Now Debit discount account with discounts allowed*/
                add_gl_trans_customer(12, $payment_no, $date_,
                        $discount_account, 0, 0, $discount, $customer_id,
-                       "Cannot insert a GL transaction for the payment discount debit");
+                       "Cannot insert a GL transaction for the payment discount debit", $rate);
        }
 
        /*now enter the bank_trans entry */
index 8c74c9bfbe597194168cea6667c6725552f67c3d..a537894bb7c8bd0929a8fb8eec08e5f41f75e36d 100644 (file)
@@ -36,14 +36,14 @@ function add_stock_move_customer($type, $stock_id, $trans_id, $location, $date_,
 // $amount is in CUSTOMER'S currency
 
 function add_gl_trans_customer($type, $type_no, $date_, $account, $dimension, $dimension2,
-       $amount, $customer_id, $err_msg="")
+       $amount, $customer_id, $err_msg="", $rate=0)
 {
        if ($err_msg == "")
                $err_msg = "The customer GL transaction could not be inserted";
 
        return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, "", $amount,
                get_customer_currency($customer_id),
-               payment_person_types::customer(), $customer_id, $err_msg);
+               payment_person_types::customer(), $customer_id, $err_msg, $rate);
 }
 
 //----------------------------------------------------------------------------------------
@@ -104,11 +104,11 @@ function get_price ($stock_id, $currency, $sales_type_id, $factor=null, $date=nu
        {
            $price = $prices[$sales_type_id][$home_curr] / $rate;
        }
-       if (isset($prices[$base_id][$currency])) 
+       elseif (isset($prices[$base_id][$currency])) 
        {
            $price = $prices[$base_id][$currency] * $factor;
        }
-       if (isset($prices[$base_id][$home_curr])) 
+       elseif (isset($prices[$base_id][$home_curr])) 
        {
            $price = $prices[$base_id][$home_curr] * $factor / $rate;
        }
index cf0ae3f865a4b2fa596c1a544c3810b01a83268f..51e79dc7850063c2515898412b7dbcbdb376ebc2 100644 (file)
@@ -4,12 +4,16 @@ $page_security = 1;
 $path_to_root="../..";
 include_once($path_to_root . "/includes/session.inc");
 
-page(_("View Customer Payment"), true);
-
 include_once($path_to_root . "/includes/date_functions.inc");
 include_once($path_to_root . "/includes/ui.inc");
 include_once($path_to_root . "/sales/includes/sales_db.inc");
 
+$js = "";
+if ($use_popup_windows)
+       $js .= get_js_open_window(900, 600);
+
+page(_("View Customer Payment"), true, false, "", $js);
+
 if (isset($_GET["trans_no"]))
 {
        $trans_id = $_GET["trans_no"];
index 2c0702043f4f659774f407a79e3ba919a8874690..cc0bb64d2f8530852bd3e2d7e5ff045c516ce658 100644 (file)
@@ -53,7 +53,7 @@ password and choose the update script from the local harddisk.</li>
 do this, before entering FrontAccounting!
 Enter the database user and the password and choose the alter.sql
 script. &nbsp;Do the same for the alter2.sql script. If you have
-already updated release 2.0 Beta, you can just run the alter2.sql script.<br />You must also manuelly ensure that you have write permission to the new folder /company/0.</strong></li>
+already updated release 2.0 Beta, you can just run the alter2.sql script.<br />You must also manuelly ensure that you have write permission to the new folder /company/0.<br /></strong><strong>There are no database changes during a major and minor release. Like from 2.0 to 2.0.1 - 2.0.5 .</strong></li>
 </ul>
 
 <p>&nbsp;</p>