Incorrect Journal Balance (sales invoice) when many decimals in tax and price.
[fa-stable.git] / purchasing / supplier_payment.php
index c7bedf4dcd16502bd153c201a98e839283b28335..8202016bc6fa32f73a034e9d3c9e44ef71d442d4 100644 (file)
@@ -57,21 +57,15 @@ if (isset($_POST['_DatePaid_changed'])) {
   $Ajax->activate('_ex_rate');
 }
 
-if (list_updated('supplier_id')) {
-       $_POST['amount'] = price_format(0);
-       $_SESSION['alloc']->person_id = get_post('supplier_id');
-       $Ajax->activate('amount');
-} elseif (list_updated('bank_account'))
-       $Ajax->activate('alloc_tbl');
-
 //----------------------------------------------------------------------------------------
 
 if (!isset($_POST['bank_account'])) { // first page call
        $_SESSION['alloc'] = new allocation(ST_SUPPAYMENT, 0, get_post('supplier_id'));
 
        if (isset($_GET['PInvoice'])) {
+               $supp = isset($_POST['supplier_id']) ? $_POST['supplier_id'] : null;
                //  get date and supplier
-               $inv = get_supp_trans($_GET['PInvoice'], $_GET['trans_type']);
+               $inv = get_supp_trans($_GET['PInvoice'], $_GET['trans_type'], $supp);
                if ($inv) {
                        $_SESSION['alloc']->person_id = $_POST['supplier_id'] = $inv['supplier_id'];
                        $_SESSION['alloc']->read();
@@ -102,6 +96,9 @@ if (isset($_GET['AddedID'])) {
     display_note(get_gl_view_str(ST_SUPPAYMENT, $payment_id, _("View the GL &Journal Entries for this Payment")), 0, 1);
 
        submenu_option(_("Enter another supplier &payment"), "/purchasing/supplier_payment.php?supplier_id=".$_POST['supplier_id']);
+
+       submenu_option(_("Enter direct &Invoice"), "/purchasing/po_entry_items.php?NewInvoice=Yes");
+
        submenu_option(_("Enter Other &Payment"), "/gl/gl_bank.php?NewPayment=Yes");
        submenu_option(_("Enter &Customer Payment"), "/sales/customer_payments.php");
        submenu_option(_("Enter Other &Deposit"), "/gl/gl_bank.php?NewDeposit=Yes");
@@ -234,7 +231,7 @@ function handle_add_payment()
 {
        $payment_id = write_supp_payment(0, $_POST['supplier_id'], $_POST['bank_account'],
                $_POST['DatePaid'], $_POST['ref'], input_num('amount'), input_num('discount'), $_POST['memo_'], 
-               input_num('charge'), input_num('bank_amount', input_num('amount')));
+               input_num('charge'), input_num('bank_amount', input_num('amount')), $_POST['dimension_id'], $_POST['dimension2_id']);
        new_doc_date($_POST['DatePaid']);
 
        $_SESSION['alloc']->trans_no = $payment_id;
@@ -275,6 +272,13 @@ start_form();
 
     supplier_list_row(_("Payment To:"), 'supplier_id', null, false, true);
 
+       if (list_updated('supplier_id')) {
+               $_POST['amount'] = price_format(0);
+               $_SESSION['alloc']->person_id = get_post('supplier_id');
+               $Ajax->activate('amount');
+       } elseif (list_updated('bank_account'))
+               $Ajax->activate('alloc_tbl');
+
        if (list_updated('supplier_id') || list_updated('bank_account')) {
          $_SESSION['alloc']->read();
          $_POST['memo_'] = $_POST['amount'] = '';
@@ -318,6 +322,20 @@ start_form();
 
        amount_row(_("Bank Charge:"), 'charge', null, '', $bank_currency);
 
+       $row = get_supplier($_POST['supplier_id']);
+       $_POST['dimension_id'] = @$row['dimension_id'];
+       $_POST['dimension2_id'] = @$row['dimension2_id'];
+       $dim = get_company_pref('use_dimension');
+       if ($dim > 0)
+               dimensions_list_row(_("Dimension").":", 'dimension_id',
+                       null, true, ' ', false, 1, false);
+       else
+               hidden('dimension_id', 0);
+       if ($dim > 1)
+               dimensions_list_row(_("Dimension")." 2:", 'dimension2_id',
+                       null, true, ' ', false, 2, false);
+       else
+               hidden('dimension2_id', 0);
 
        end_outer_table(1);