! -> 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
$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;
}
}
$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()
{
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();
// 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)
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();
//----------------------------------------------------------------------------------------------------
-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);
}
//----------------------------------------------------------------------------------------------------
$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);
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'];
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'];
}
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;
$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);
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]. "\">";
// 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;
}
}
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);
}
}
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"));
if ($Mode == 'RESET')
{
- $selected_component = -1;
+ $selected_id = -1;
unset($_POST['quantity']);
}
{ //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();
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");
$_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
{
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();
}
// ----------------------------------------------------------------------------------
$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"],
<?php
function add_supp_payment($supplier_id, $date_, $bank_account,
- $amount, $discount, $ref, $memo_)
+ $amount, $discount, $ref, $memo_, $rate=0)
{
begin_transaction();
$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 */
//-------------------------------------------------------------------------------------------------------------
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 == "")
$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,
// $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);
}
//----------------------------------------------------------------------------------------
$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);
}
//--------------------------------------------------------------------------------------------------
-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');
submit_cells('ClearFields', _("Reset"), "",
_("Clear all GL entry fields"), true);
end_row();
- div_end();
}
// $mode = 0 none at the moment
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)
}
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");
//--------------//-----------------------------------------------------------------------------------------
-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
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;
end_row();
}
}
-
- div_end();
+ return true;
}
//------------------------------------------------------------------------------------
{
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;
}
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>";
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("");
}
}
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>";
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);
// 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);
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)
return true;
}
}
- $line_no++;
+ $line_no++;
} /*loop through all line items of the order to ensure none have been invoiced */
return false;
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'],
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));
{
$_SESSION['PO']->line_items[$line->line_no]->item_description = $_POST[$line->stock_id . "Desc"];
}
+ }
}
$Ajax->activate('grn_items');
}
unset($_POST['amount']);
unset($_POST['memo_']);
unset($_POST['AddGLCodeToTrans']);
- $Ajax->activate('gl_ctrls');
+ $Ajax->activate('gl_items');
set_focus('gl_code');
}
//------------------------------------------------------------------------------------------------
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');
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');
}
unset($_POST['amount']);
unset($_POST['memo_']);
unset($_POST['AddGLCodeToTrans']);
- $Ajax->activate('gl_ctrls');
+ $Ajax->activate('gl_items');
set_focus('gl_code');
}
//------------------------------------------------------------------------------------------------
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;
}
$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);
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');
}
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>";
$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));
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 (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;
}
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']);
$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);
$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)
$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;
$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)
$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";
$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);
$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));
$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);
// 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()
$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'),
$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)
$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);
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')));
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')));
}
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'),
/*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];
}
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);
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');
//----------------------------------------------------------------------------------------------
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");
}
$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);
{
$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 == "")
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);
/* 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()) {
/* 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 */
// $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);
}
//----------------------------------------------------------------------------------------
{
$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;
}
$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"];
do this, before entering FrontAccounting!
Enter the database user and the password and choose the alter.sql
script. 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> </p>