/**
  * Creates a new Receipt model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param integer $estimateId
  * @return mixed
  */
 public function actionCreate($estimateId)
 {
     $model = Receipt::findOne(['estimate_id' => $estimateId]);
     if ($model) {
         return $this->redirect(['view', 'id' => $model->id]);
     }
     $model = new Receipt();
     $model->estimate_id = $estimateId;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Beispiel #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = array('commodity' => 'required', 'quantity' => 'required', 'batch_no' => 'required', 'supplier' => 'required', 'expiry_date' => 'required|date');
     $validator = Validator::make(Input::all(), $rules);
     // process the login
     if ($validator->fails()) {
         return redirect()->to('receipt.index')->withErrors($validator);
     } else {
         $receipts = new Receipt();
         $receipts->commodity_id = Input::get('commodity');
         $receipts->supplier_id = Input::get('supplier');
         $receipts->quantity = Input::get('quantity');
         $receipts->batch_no = Input::get('batch_no');
         $receipts->expiry_date = Input::get('expiry_date');
         // todo: is this column neccessary ... it's not in the migrations
         // $receipts->user_id= Auth::user()->id;
         $receipts->save();
         return redirect()->to('receipt.index')->with('message', trans('messages.receipt-succesfully-added'));
     }
 }