"; // outer table
echo "";
bank_accounts_list_row(_("From Bank Account:"), 'bank_account', null, true);
amount_row(_("Amount of Payment:"), 'amount');
amount_row(_("Amount of Discount:"), 'discount');
date_row(_("Date Paid") . ":", 'DatePaid');
echo " ";
echo " | "; // outer table
echo "";
supplier_list_row(_("Payment To:"), 'supplier_id', null, false, true);
set_global_supplier($_POST['supplier_id']);
$supplier_currency = get_supplier_currency($_POST['supplier_id']);
$bank_currency = get_bank_account_currency($_POST['bank_account']);
if ($bank_currency != $supplier_currency)
{
exchange_rate_display($bank_currency, $supplier_currency, $_POST['DatePaid']);
}
bank_trans_types_list_row(_("Payment Type:"), 'PaymentType', null);
ref_row(_("Reference:"), 'ref', '', references::get_next(22));
text_row(_("Memo:"), 'memo_', null, 52,50);
echo " ";
echo " | ";
end_table(1); // outer table
submit_center('ProcessSuppPayment',_("Enter Payment"));
if ($bank_currency != $supplier_currency)
{
display_note(_("The amount and discount are in the bank account's currency."), 2, 0);
}
end_form();
}
//----------------------------------------------------------------------------------------
function check_inputs()
{
if ($_POST['amount'] == "")
{
$_POST['amount'] = price_format(0);
}
if (!check_num('amount', 0))
{
display_error(_("The entered amount is invalid or less than zero."));
set_focus('amount');
return false;
}
if ($_POST['discount'] == "")
{
$_POST['discount'] = 0;
}
if (!check_num('discount', 0))
{
display_error(_("The entered discount is invalid or less than zero."));
set_focus('amount');
return false;
}
if (input_num('amount') - input_num('discount') <= 0)
{
display_error(_("The total of the amount and the discount negative. Please enter positive values."));
set_focus('amount');
return false;
}
if (!is_date($_POST['DatePaid']))
{
display_error(_("The entered date is invalid."));
set_focus('DatePaid');
return false;
}
elseif (!is_date_in_fiscalyear($_POST['DatePaid']))
{
display_error(_("The entered date is not in fiscal year."));
set_focus('DatePaid');
return false;
}
if (!references::is_valid($_POST['ref']))
{
display_error(_("You must enter a reference."));
set_focus('ref');
return false;
}
if (!is_new_reference($_POST['ref'], 22))
{
display_error(_("The entered reference is already in use."));
set_focus('ref');
return false;
}
return true;
}
//----------------------------------------------------------------------------------------
function handle_add_payment()
{
$payment_id = add_supp_payment($_POST['supplier_id'], $_POST['DatePaid'],
$_POST['PaymentType'], $_POST['bank_account'],
input_num('amount'), input_num('discount'), $_POST['ref'], $_POST['memo_']);
//unset($_POST['supplier_id']);
unset($_POST['bank_account']);
unset($_POST['DatePaid']);
unset($_POST['PaymentType']);
unset($_POST['currency']);
unset($_POST['memo_']);
unset($_POST['amount']);
unset($_POST['discount']);
unset($_POST['ProcessSuppPayment']);
meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_id&supplier_id=".$_POST['supplier_id']);
}
//----------------------------------------------------------------------------------------
if (isset($_POST['ProcessSuppPayment']))
{
/*First off check for valid inputs */
if (check_inputs() == true)
{
handle_add_payment();
end_page();
exit;
}
}
display_controls();
end_page();
?>