Implemented the option to automatically consume a product on tracking a chore execution (closes #279)

This commit is contained in:
Bernd Bestel
2019-09-18 10:02:52 +02:00
parent e326e69d49
commit 3df44697bf
7 changed files with 122 additions and 36 deletions

View File

@@ -2,6 +2,8 @@
namespace Grocy\Services;
use \Grocy\Services\StockService;
class ChoresService extends BaseService
{
const CHORE_PERIOD_TYPE_MANUALLY = 'manually';
@@ -15,6 +17,14 @@ class ChoresService extends BaseService
const CHORE_ASSIGNMENT_TYPE_RANDOM = 'random';
const CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER = 'in-alphabetical-order';
public function __construct()
{
parent::__construct();
$this->StockService = new StockService();
}
protected $StockService;
public function GetCurrent()
{
$sql = 'SELECT * from chores_current';
@@ -84,9 +94,15 @@ class ChoresService extends BaseService
'done_by_user_id' => $doneBy
));
$logRow->save();
$lastInsertId = $this->Database->lastInsertId();
$this->CalculateNextExecutionAssignment($choreId);
if ($chore->consume_product_on_execution == 1 && !empty($chore->product_id))
{
$this->StockService->ConsumeProduct($chore->product_id, $chore->product_amount, false, StockService::TRANSACTION_TYPE_CONSUME);
}
return $lastInsertId;
}