recipes can create products (#501)

This commit is contained in:
kriddles
2020-01-21 13:20:26 -06:00
committed by Bernd Bestel
parent c22496ca7c
commit 3a36bdaf45
5 changed files with 56 additions and 2 deletions

View File

@@ -67,6 +67,15 @@ class RecipesService extends BaseService
throw new \Exception('Recipe does not exist');
}
$recipeRow = $this->Database->recipes()->where('id = :1', $recipeId)->fetch();
if ($recipeRow->product_id != null)
{
$recipeResolvedRow = $this->Database->recipes_resolved()->where('recipe_id = :1', $recipeId)->fetch();
$price = number_format($recipeResolvedRow->costs, 2);
$bookingAmount = floatval($recipeRow->desired_servings);
$this->StockService->AddProduct($recipeRow->product_id, $bookingAmount, null, StockService::TRANSACTION_TYPE_PURCHASE, date('Y-m-d'), $price);
}
$recipePositions = $this->Database->recipes_pos_resolved()->where('recipe_id', $recipeId)->fetchAll();
foreach ($recipePositions as $recipePosition)
{