@@ -67,15 +67,6 @@ public function ConsumeRecipe($recipeId)
67
67
throw new \Exception ('Recipe does not exist ' );
68
68
}
69
69
70
- $ recipeRow = $ this ->Database ->recipes ()->where ('id = :1 ' , $ recipeId )->fetch ();
71
- if ($ recipeRow ->product_id != null )
72
- {
73
- $ recipeResolvedRow = $ this ->Database ->recipes_resolved ()->where ('recipe_id = :1 ' , $ recipeId )->fetch ();
74
- $ price = number_format ($ recipeResolvedRow ->costs , 2 );
75
- $ bookingAmount = floatval ($ recipeRow ->desired_servings );
76
- $ this ->StockService ->AddProduct ($ recipeRow ->product_id , $ bookingAmount , null , StockService::TRANSACTION_TYPE_PURCHASE , date ('Y-m-d ' ), $ price );
77
- }
78
-
79
70
$ recipePositions = $ this ->Database ->recipes_pos_resolved ()->where ('recipe_id ' , $ recipeId )->fetchAll ();
80
71
foreach ($ recipePositions as $ recipePosition )
81
72
{
@@ -84,6 +75,13 @@ public function ConsumeRecipe($recipeId)
84
75
$ this ->StockService ->ConsumeProduct ($ recipePosition ->product_id , $ recipePosition ->recipe_amount , false , StockService::TRANSACTION_TYPE_CONSUME , 'default ' , $ recipeId );
85
76
}
86
77
}
78
+
79
+ $ recipeRow = $ this ->Database ->recipes ()->where ('id = :1 ' , $ recipeId )->fetch ();
80
+ if (!empty ($ recipeRow ->product_id ))
81
+ {
82
+ $ recipeResolvedRow = $ this ->Database ->recipes_resolved ()->where ('recipe_id = :1 ' , $ recipeId )->fetch ();
83
+ $ this ->StockService ->AddProduct ($ recipeRow ->product_id , floatval ($ recipeRow ->desired_servings ), null , StockService::TRANSACTION_TYPE_SELF_PRODUCTION , date ('Y-m-d ' ), floatval ($ recipeResolvedRow ->costs ));
84
+ }
87
85
}
88
86
89
87
private function RecipeExists ($ recipeId )
0 commit comments