/** 
  * observe transaction log event saved
  * 1. Check if transaction is sale
  * 2. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function saved($model)
 {
     $errors = new MessageBag();
     //A. Check if transaction is sale
     if ($model->sale()->count()) {
         /**
          * Switch scheme
          * 1. current status = cart, save audit abandoned
          * 2. current status = wait, credit point, if full-paid-points,  change status to paid
          * 3. current status = paid, add quota and point for upline, then save audit payment
          * 4. current status = shipping, save audit shipping
          * 5. current status = delivered, save audit delivered
          * 6. current status = canceled, revert point paid, save audit canceled
          */
         switch ($model->status) {
             case 'cart':
                 $prev_sale = \App\Models\Sale::notid($model->sale_id)->userid($model->sale->user_id)->status('cart')->first();
                 if ($prev_sale) {
                     $result = $model->ChangeStatus($prev_sale, 'abandoned');
                 }
                 break;
             case 'wait':
                 $result = $model->CreditPoint($model->sale);
                 if (!$result && count($model['errors'])) {
                     return false;
                 }
                 if ($result == 0) {
                     $result = $model->ChangeStatus($model->sale, 'paid', 'Full Point', ' + 1 second ');
                 }
                 break;
             case 'paid':
                 $result = $model->AddQuotaForUpline($model->sale);
                 if (!$result) {
                     return false;
                 }
                 $result = $model->AddPointForUpline($model->sale);
                 break;
             case 'shipping':
                 break;
             case 'delivered':
                 break;
             case 'canceled':
                 $result = $model->RevertPoint($model->sale);
                 break;
         }
         if (isset($result) && !$result) {
             return false;
         }
     }
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }