Skip to content

Commit

Permalink
PordersController::createinvoice, do not allow multiple supplier GRN …
Browse files Browse the repository at this point in the history
…selections

- Clear saved selections between purchase orders
- Check that GRNs match the supplier on save

Bug: Purchase invoice created for one supplier contains lines from another suppliers order

To reproduce:

- Create invoice from an order and select some lines. Don't save.
- Go to another order for a different supplier, create invoice and select some lines. Save.
- The order for the second supplier now has all the lines selected from both suppliers.

Cancelling or deleting lines will have now impact on the order at this point. Invoiced lines will remain invoiced.

closes #271
  • Loading branch information
steveblamey committed May 8, 2024
1 parent ccc46bf commit 6d59876
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1827,9 +1827,14 @@ public function createinvoice()
$this->view->set('invoicedate', date(DATE_FORMAT));

// get data from persistent selection session

$key = 'purchase_order-porders-createinvoice';

// Clear any existing selections if the user is coming directly
// from the purchase order sidebar.
if (isset($this->_data['order_number'])) {
unset($_SESSION['persistent_selection'][$key]);
}

$selected_rows = array();
$net_total = 0; // this should be a number... not a string

Expand Down Expand Up @@ -1892,11 +1897,19 @@ public function saveinvoice()

$rows = $poreceivedlines->load($sh, null, RETURN_ROWS);

$order_supplier = $this->_data['plmaster_id'];

if ($rows) {

foreach ($rows as $received_line) {
// Create an invoice line for each selected GRN line
$supplier = $received_line['plmaster_id'];

// Guard against UI bugs that result in GRNs from multiple suppliers being selected
if ($supplier !== $order_supplier) {
$errors[] = "GRN {$received_line['gr_number']} does not belong to this supplier";
}

$porderline = DataObjectFactory::Factory('POrderLine');
$porderline->load($received_line['orderline_id']);

Expand Down

0 comments on commit 6d59876

Please sign in to comment.