mirror of
https://github.com/grocy/grocy.git
synced 2025-08-19 20:11:16 +00:00
Implemented the option to automatically consume a product on tracking a chore execution (closes #279)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user