Little changes for pull request #338

This commit is contained in:
Bernd Bestel
2019-08-10 08:20:52 +02:00
parent c757ee3874
commit cc1c6a6442
4 changed files with 27 additions and 16 deletions

View File

@@ -146,7 +146,7 @@ class StockService extends BaseService
}
}
public function AddProduct(int $productId, float $amount, string $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null)
public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null)
{
if (!$this->ProductExists($productId))
{
@@ -170,10 +170,17 @@ class StockService extends BaseService
//Sets the default best before date, if none is supplied
if ($bestBeforeDate == null)
{
if ($productDetails->product->default_best_before_days == -1) {
if (intval($productDetails->product->default_best_before_days) == -1)
{
$bestBeforeDate = date('2999-12-31');
} else {
$bestBeforeDate = date('Y-m-d', strtotime(date('Y-m-d') . ' + '.$productDetails->product->default_best_before_days.' days'));
}
else if (intval($productDetails->product->default_best_before_days) > 0)
{
$bestBeforeDate = date('Y-m-d', strtotime(date('Y-m-d') . ' + '.$productDetails->product->default_best_before_days.' days'));
}
else
{
$bestBeforeDate = date('Y-m-d');
}
}
@@ -313,7 +320,7 @@ class StockService extends BaseService
}
}
public function InventoryProduct(int $productId, int $newAmount, string $bestBeforeDate, $locationId = null, $price = null)
public function InventoryProduct(int $productId, int $newAmount, $bestBeforeDate, $locationId = null, $price = null)
{
if (!$this->ProductExists($productId))
{
@@ -513,7 +520,9 @@ class StockService extends BaseService
{
throw new \Exception('Shopping list does not exist');
}
$productRow = $this->Database->shopping_list()->where('product_id = :1', $productId)->fetch();
//If no entry was found with for this product, we return gracefully
if ($productRow != null && !empty($productRow))
{
@@ -521,7 +530,9 @@ class StockService extends BaseService
if ($newAmount < 1)
{
$productRow->delete();
} else {
}
else
{
$productRow->update(array('amount' => $newAmount));
}