mirror of
https://github.com/grocy/grocy.git
synced 2025-10-14 17:24:07 +00:00
More or less finalize recipes feature
This commit is contained in:
@@ -3,14 +3,19 @@
|
||||
namespace Grocy\Services;
|
||||
|
||||
use \Grocy\Services\DatabaseService;
|
||||
use \Grocy\Services\LocalizationService;
|
||||
|
||||
class BaseService
|
||||
{
|
||||
public function __construct() {
|
||||
$this->DatabaseService = new DatabaseService();
|
||||
$this->Database = $this->DatabaseService->GetDbConnection();
|
||||
|
||||
$localizationService = new LocalizationService(CULTURE);
|
||||
$this->LocalizationService = $localizationService;
|
||||
}
|
||||
|
||||
protected $DatabaseService;
|
||||
protected $Database;
|
||||
protected $LocalizationService;
|
||||
}
|
||||
|
@@ -2,14 +2,12 @@
|
||||
|
||||
namespace Grocy\Services;
|
||||
|
||||
class LocalizationService extends BaseService
|
||||
class LocalizationService
|
||||
{
|
||||
const DEFAULT_CULTURE = 'en';
|
||||
|
||||
public function __construct(string $culture)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->Culture = $culture;
|
||||
|
||||
$this->StringsDefaultCulture = $this->LoadLocalizationFile(self::DEFAULT_CULTURE);
|
||||
|
@@ -15,4 +15,27 @@ class RecipesService extends BaseService
|
||||
$sql = 'SELECT * from recipes_fulfillment_sum';
|
||||
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||
}
|
||||
|
||||
public function AddNotFulfilledProductsToShoppingList($recipeId)
|
||||
{
|
||||
$recipe = $this->Database->recipes($recipeId);
|
||||
|
||||
$recipePositions = $this->GetRecipesFulfillment();
|
||||
foreach ($recipePositions as $recipePosition)
|
||||
{
|
||||
if($recipePosition->recipe_id == $recipeId)
|
||||
{
|
||||
$toOrderAmount = $recipePosition->missing_amount - $recipePosition->amount_on_shopping_list;
|
||||
if($toOrderAmount > 0)
|
||||
{
|
||||
$shoppinglistRow = $this->Database->shopping_list()->createRow(array(
|
||||
'product_id' => $recipePosition->product_id,
|
||||
'amount' => $toOrderAmount,
|
||||
'note' => $this->LocalizationService->Localize('Added for recipe #1', $recipe->name)
|
||||
));
|
||||
$shoppinglistRow->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user