示例#1
0
 /**
  * Overrides the models boot function to set the user
  * ID automatically to every new record.
  */
 public static function bootInventoryTrait()
 {
     /*
      * Assign the current users ID while the item
      * is being created
      */
     static::creating(function (Model $record) {
         $record->setAttribute('user_id', Helper::getCurrentUserId());
     });
     /*
      * Generate the items SKU once it's created
      */
     static::created(function (Model $record) {
         $record->generateSku();
     });
     /*
      * Generate an SKU if the item has been assigned a category,
      * this will not overwrite any SKU the item had previously
      */
     static::updated(function (Model $record) {
         if ($record->category_id !== null) {
             $record->generateSku();
         }
     });
 }
 /**
  * Overrides the models boot function to set
  * the user ID automatically to every new record.
  */
 public static function bootInventoryStockTrait()
 {
     static::creating(function (Model $model) {
         $model->setAttribute('user_id', Helper::getCurrentUserId());
         // Check if a reason has been set, if not let's
         // retrieve the default first entry reason.
         if (!$model->reason) {
             $model->reason = Lang::get('inventory::reasons.first_record');
         }
     });
     static::created(function (Model $model) {
         $model->postCreate();
     });
     static::updating(function (Model $model) {
         // Retrieve the original quantity before it was updated,
         // so we can create generate an update with it.
         $model->beforeQuantity = $model->getOriginal('quantity');
         // Check if a reason has been set, if not let's
         // retrieve the default change reason.
         if (!$model->reason) {
             $model->reason = Lang::get('inventory::reasons.change');
         }
     });
     static::updated(function (Model $model) {
         $model->postUpdate();
     });
 }
 /**
  * Overrides the models boot function to generate a new transaction history
  * record when it is created and updated.
  */
 public static function bootInventoryTransactionTrait()
 {
     static::creating(function (Model $model) {
         $model->setAttribute('user_id', Helper::getCurrentUserId());
         if (!$model->beforeState) {
             $model->beforeState = $model::STATE_OPENED;
         }
     });
     static::created(function (Model $model) {
         $model->postCreate();
     });
     static::updating(function (Model $model) {
         /*
          * Retrieve the original quantity before it was updated,
          * so we can create generate an update with it
          */
         $model->beforeState = $model->getOriginal('state');
         $model->beforeQuantity = $model->getOriginal('quantity');
     });
     static::updated(function (Model $model) {
         $model->postUpdate();
     });
 }
 /**
  * Overrides the models boot function to set
  * the user ID automatically to every new record.
  */
 public static function bootInventoryStockMovementTrait()
 {
     static::creating(function (Model $record) {
         $record->setAttribute('user_id', Helper::getCurrentUserId());
     });
 }
 /**
  * Make sure we try and assign the current user if enabled.
  *
  * @return void
  */
 public static function bootInventoryTransactionHistoryTrait()
 {
     static::creating(function (Model $model) {
         $model->setAttribute('user_id', Helper::getCurrentUserId());
     });
 }