Exemplo n.º 1
0
 /**
  * Finds the GoodsMovement model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return GoodsMovement the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = GoodsMovement::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 /**
  * Deletes an existing Sales model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     if ($model->status == Sales::STATUS_DRAFT) {
         $model->delete();
         return $this->redirect(['index']);
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         // gl
         $gl = GlHeader::findOne(['reff_type' => GlHeader::REFF_SALES, 'reff_id' => $id]);
         // movement
         $movement = $gl != null ? GoodsMovement::findOne(['reff_type' => GoodsMovement::REFF_SALES, 'reff_id' => $id]) : null;
         // invoice from movement
         $invoice = $movement != null ? Invoice::findOne(['reff_type' => Invoice::REFF_GOODS_MOVEMENT, 'reff_id' => $movement->id]) : null;
         // payment invoive
         $payments = $invoice != null ? $invoice->payments : [];
         foreach ($payments as $payment) {
             if (!$payment->delete()) {
                 throw new UserException('Cannot delete payment');
             }
         }
         if (count($payments) > 0 && $invoice->delete() && $movement->delete() && $gl->reserve() && $model->delete()) {
             //do nothing
             $transaction->commit();
             return $this->redirect(['index']);
         } else {
             throw new UserException('Something error');
         }
     } catch (\Exception $exc) {
         $transaction->rollBack();
         throw $exc;
     }
 }
Exemplo n.º 3
0
 public function revertAdjust()
 {
     $gm = GoodsMovement::findOne(['reff_type' => self::REFF_SELF, 'reff_id' => $this->id]);
     $gm->status = GoodsMovement::STATUS_CANCELED;
     return $gm->save();
 }