[0004212] Work Order Entry: fixed error when voided WO refence is reused.
[fa-stable.git] / purchasing / po_entry_items.php
index 17e123f9c6f891a54bd3c4e85e134d686de29792..22f383819b0f0ab0980f6a23b11fa808df88032d 100644 (file)
@@ -53,9 +53,14 @@ if (isset($_GET['ModifyOrderNumber']) && is_numeric($_GET['ModifyOrderNumber']))
        copy_from_cart();
 } elseif (isset($_GET['NewInvoice'])) {
 
-       $_SESSION['page_title'] = _($help_context = "Direct Purchase Invoice Entry");
        create_new_po(ST_SUPPINVOICE, 0);
        copy_from_cart();
+
+       if (isset($_GET['FixedAsset'])) {
+               $_SESSION['page_title'] = _($help_context = "Fixed Asset Purchase Invoice Entry");
+               $_SESSION['PO']->fixed_asset = true;
+       } else
+               $_SESSION['page_title'] = _($help_context = "Direct Purchase Invoice Entry");
 }
 
 page($_SESSION['page_title'], false, false, "", $js);
@@ -67,8 +72,6 @@ if (isset($_GET['ModifyOrderNumber']))
 
 check_db_has_suppliers(_("There are no suppliers defined in the system."));
 
-check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system."));
-
 //---------------------------------------------------------------------------------------------------------------
 
 if (isset($_GET['AddedID'])) 
@@ -88,6 +91,7 @@ if (isset($_GET['AddedID']))
 
        hyperlink_params($path_to_root . "/purchasing/po_receive_items.php", _("&Receive Items on this Purchase Order"), "PONumber=$order_no");
 
+  // TODO, for fixed asset
        hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another Purchase Order"), "NewOrder=yes");
        
        hyperlink_no_params($path_to_root."/purchasing/inquiry/po_search.php", _("Select An &Outstanding Purchase Order"));
@@ -106,8 +110,6 @@ if (isset($_GET['AddedID']))
     $clearing_act = get_company_pref('grn_clearing_act');
        if ($clearing_act)      
                display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Journal Entries for this Delivery")), 1);
-// not yet
-//     display_note(print_document_link($trans_no, _("&Print This GRN"), true, $trans_type), 0, 1);
 
        hyperlink_params("$path_to_root/purchasing/supplier_invoice.php",
                _("Entry purchase &invoice for this receival"), "New=1");
@@ -128,11 +130,11 @@ if (isset($_GET['AddedID']))
 
        display_note(get_trans_view_str($trans_type, $trans_no, _("&View this Invoice")), 0);
 
-// not yet
-//     display_note(print_document_link($trans_no, _("&Print This Invoice"), true, $trans_type), 0, 1);
-
        display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Journal Entries for this Invoice")), 1);
 
+       hyperlink_params("$path_to_root/purchasing/supplier_payment.php", _("Entry supplier &payment for this invoice"),
+               "trans_type=$trans_type&PInvoice=".$trans_no);
+
        hyperlink_params("$path_to_root/admin/attachments.php", _("Add an Attachment"), 
                "filterType=$trans_type&trans_no=$trans_no");
 
@@ -140,6 +142,11 @@ if (isset($_GET['AddedID']))
        
        display_footer_exit();  
 }
+
+if ($_SESSION['PO']->fixed_asset)
+  check_db_has_purchasable_fixed_assets(_("There are no purchasable fixed assets defined in the system."));
+else
+  check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system."));
 //--------------------------------------------------------------------------------------------------
 
 function line_start_focus() {
@@ -187,13 +194,18 @@ function handle_cancel_po()
                        . "<br>" . _("The line item quantities may be modified to quantities more than already received. prices cannot be altered for lines that have already been received and quantities cannot be reduced below the quantity already received."));
                return;
        }
-       
+
+       $fixed_asset = $_SESSION['PO']->fixed_asset;
+
        if($_SESSION['PO']->order_no != 0)
-       {
                delete_po($_SESSION['PO']->order_no);
-       else {
+       else {
                unset($_SESSION['PO']);
-               meta_forward($path_to_root.'/index.php','application=AP');
+
+       if ($fixed_asset)
+                       meta_forward($path_to_root.'/index.php','application=assets');
+               else
+                       meta_forward($path_to_root.'/index.php','application=AP');
        }
 
        $_SESSION['PO']->clear_items();
@@ -299,7 +311,6 @@ function handle_add_new_item()
 
                        if ($allow_update)
                        {
-                               $myrow = db_fetch($result);
                                $_SESSION['PO']->add_to_order (count($_SESSION['PO']->line_items), $_POST['stock_id'], input_num('qty'), 
                                        get_post('stock_id_text'), //$myrow["description"], 
                                        input_num('price'), '', // $myrow["units"], (retrived in cart)
@@ -322,8 +333,6 @@ function handle_add_new_item()
 
 function can_commit()
 {
-       global $Refs;
-
        if (!get_post('supplier_id')) 
        {
                display_error(_("There is no supplier selected."));
@@ -353,22 +362,14 @@ function can_commit()
 
        if (!$_SESSION['PO']->order_no) 
        {
-       if (!$Refs->is_valid(get_post('ref'))) 
+       if (!check_reference(get_post('ref'), $_SESSION['PO']->trans_type))
        {
-               display_error(_("There is no reference entered for this purchase order."));
-                       set_focus('ref');
-               return false;
-       } 
-
-       if (!is_new_reference(get_post('ref'), $_SESSION['PO']->trans_type)) 
-       {
-               display_error(_("The entered reference is already in use."));
                        set_focus('ref');
                return false;
        }
        }
 
-       if ($_SESSION['PO']->trans_type == ST_SUPPINVOICE && !$Refs->is_valid(get_post('supp_ref'))) 
+       if ($_SESSION['PO']->trans_type == ST_SUPPINVOICE && trim(get_post('supp_ref')) == false)
        {
                display_error(_("You must enter a supplier's invoice reference."));
                set_focus('supp_ref');
@@ -393,7 +394,7 @@ function can_commit()
                set_focus('StkLocation');
                return false;
        } 
-       if (!db_has_currency_rates($_SESSION['PO']->curr_code, $_POST['OrderDate']))
+       if (!db_has_currency_rates($_SESSION['PO']->curr_code, $_POST['OrderDate'], true))
                return false;
        if ($_SESSION['PO']->order_has_items() == false)
        {
@@ -437,6 +438,11 @@ function handle_commit_order()
        }
 }
 //---------------------------------------------------------------------------------------------------
+if (isset($_POST['update'])) {
+       copy_to_cart();
+       $Ajax->activate('items_table');
+}
+
 $id = find_submit('Delete');
 if ($id != -1)
        handle_delete_item($id);