Exemplo n.º 1
0
 /**
  * Creates a new InvoiceItem model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new InvoiceItem();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     try {
         $admin = \Auth::User();
         if (!$admin) {
             return $this->failResponse('admin not logged in');
         }
         $dataItems = $this->getRequestBody();
         Log::error("dataItems");
         Log::error($dataItems);
         Log::error(count($dataItems));
         foreach ($dataItems as $data) {
             Log::error("data");
             Log::error($data);
             $invoiceItemObj = new InvoiceItem();
             $invoiceItemObj->invoice_id = $data['invoice_id'];
             $invoiceItemObj->item = $data['item'];
             $invoiceItemObj->description = $data['description'];
             $invoiceItemObj->quantity = $data['quantity'];
             $invoiceItemObj->unitcost = $data['unitcost'];
             $invoiceItemObj->save();
         }
         /*if(!$invoiceItemObj->save()){
               Log::error("error in saving"); 
               $errors = $invoiceItemObj->getErrors();
               return $this->failResponse('Validation failed. Cannot save data.'.$errors);
           }
           else{
               return $this->successResponse('updated sucessfully');
           }*/
     } catch (\Exception $e) {
         Log::error($invoiceItemObj->getErrors());
         return $this->failResponse($e->getMessage());
     }
 }