Consume opened products first (closes #1183)

This commit is contained in:
Bernd Bestel
2020-12-19 10:28:35 +01:00
parent 44cdd42062
commit eb4a748da3
8 changed files with 13 additions and 11 deletions

View File

@@ -691,10 +691,10 @@ class StockService extends BaseService
$result = $this->getDatabase()->stock()->where($sqlWhereProductId . ' ' . $sqlWhereAndOpen);
// In order of next use:
// First due first, then first in first out
// Opened first, then first due first, then first in first out
if ($ordered)
{
return $result->orderBy('best_before_date', 'ASC')->orderBy('purchased_date', 'ASC');
return $result->orderBy('open', 'DESC')->orderBy('best_before_date', 'ASC')->orderBy('purchased_date', 'ASC');
}
return $result;
@@ -702,7 +702,7 @@ class StockService extends BaseService
public function GetProductStockEntriesForLocation($productId, $locationId, $excludeOpened = false, $allowSubproductSubstitution = false)
{
$stockEntries = $this->GetProductStockEntries($productId, $excludeOpened, $allowSubproductSubstitution);
$stockEntries = $this->GetProductStockEntries($productId, $excludeOpened, $allowSubproductSubstitution, true);
return FindAllObjectsInArrayByPropertyValue($stockEntries, 'location_id', $locationId);
}