/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $jumlah_before = $model->jumlah; $model = $this->loadModelUpdate($id); $model2 = new Beli(); $model3 = new Laporan(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Obat'])) { $model->attributes = $_POST['Obat']; $jumlah_after = $_POST['Obat']['jumlah']; $jumlah_total = $jumlah_after + $jumlah_before; $model->jumlah = $jumlah_total; $model2->id_obat = $id; $model2->tgltrans = date('Y-m-d'); $model2->no_faktur = $_POST['Beli']['no_faktur']; $model2->distributor = $_POST['Beli']['distributor']; $model2->jlh_beli = $jumlah_after; $model3->tgl = date('Y-m-d'); $model3->id_obat = $id; $model3->keluar = 0; $model3->masuk = $jumlah_after; $model3->sisa = $jumlah_total; $model3->untung = 0; $model3->save(); $model2->save(); if ($model->save()) { $this->redirect(array('pembelian')); } } $this->render('update', array('model' => $model, 'model2' => $model2)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Beli::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }