protected function processStockTakeAndSave($quantity, $event = '', $reason = '', $cost = 0)
{
$stock = $this->getStockRecord();
$stock->isValidQuantity($quantity);
$stock->hasEnoughStock($this->getAttribute('quantity'));
$this->dbStartTransaction();
try {
if ($stock->take(floatval($quantity), $reason, $cost) && $this->save()) {
$this->dbCommitTransaction();
if ($event) {
$this->fireEvent($event, ['transaction' => $this]);
}
return $this;
}
} catch (\Exception $e) {
$this->dbRollbackTransaction();
}
return false;
}