/** * 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 $id the ID of the model to be loaded * @return Pengadaan the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Pengadaan::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionIsi($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['RelasiPengadaanSparepart'])) { $model->attributes = $_POST['RelasiPengadaanSparepart']; $harga_satuan = Yii::app()->db->createCommand()->select('HARGA_SATUAN')->from('sparepart')->where('ID_SPAREPART=:ID_SPAREPART', array(':ID_SPAREPART' => $model->ID_SPAREPART))->queryScalar(); if ($model->save()) { $hargasem = $harga_satuan * $model->JUMLAH; RelasiPengadaanSparepart::model()->updateByPk($id, array('HARGA_SEMENTARA' => $hargasem)); $total = Yii::app()->db->createCommand()->select('HARGA_TOTAL')->from('pengadaan')->where('ID_PENGADAAN=:ID_PENGADAAN', array(':ID_PENGADAAN' => $model->ID_PENGADAAN))->queryScalar(); if ($total == NULL) { $total = $hargasem; } else { if ($total != NULL) { $total = $total + $hargasem; } } Pengadaan::model()->updateByPk($model->ID_PENGADAAN, array('HARGA_TOTAL' => $total)); $this->redirect(array('pengadaan/create2', 'id' => $model->ID_PENGADAAN)); } } $this->render('isi', array('model' => $model)); }
public function actionInsert($id, $peng) { $isi = Yii::app()->db->createCommand()->select('COUNT(*)')->from('relasi_pengadaan_sparepart')->where('ID_PENGADAAN=:ID_PENGADAAN AND ID_SPAREPART=:ID_SPAREPART', array(':ID_PENGADAAN' => $peng, ':ID_SPAREPART' => $id))->queryScalar(); $idrel = Yii::app()->db->createCommand()->select('ID_RELASI')->from('relasi_pengadaan_sparepart')->where('ID_PENGADAAN=:ID_PENGADAAN AND ID_SPAREPART=:ID_SPAREPART', array(':ID_PENGADAAN' => $peng, ':ID_SPAREPART' => $id))->queryScalar(); $total = Yii::app()->db->createCommand()->select('HARGA_TOTAL')->from('pengadaan')->where('ID_PENGADAAN=:ID_PENGADAAN', array(':ID_PENGADAAN' => $peng))->queryScalar(); if ($isi == 0) { Yii::app()->db->createCommand()->insert('relasi_pengadaan_sparepart', array('ID_PENGADAAN' => $peng, 'ID_SPAREPART' => $id)); $harga = Yii::app()->db->createCommand()->select('HARGA_SEMENTARA')->from('relasi_pengadaan_sparepart')->where('ID_PENGADAAN=:ID_PENGADAAN', array(':ID_PENGADAAN' => $peng))->queryScalar(); if ($total == NULL) { $total = $harga; } else { if ($total != NULL) { $total = $total + $harga; } } } else { if ($isi > 0) { RelasiPengadaanSparepart::model()->updateByPk($idrel, array('ID_PENGADAAN' => $peng, 'ID_SPAREPART' => $id)); } } Pengadaan::model()->updateByPk($peng, array("HARGA_TOTAL" => $total)); $this->redirect(array('sparepart/admin', 'id' => $peng)); }