/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { //inisialisasi model Order $order = new Order('search'); $order->unsetAttributes(); // clear any default values if (isset($_GET['Order'])) { $order->attributes = $_GET['Order']; } $orderbaru = new Order('baru'); $orderbaru->RESEP = 1; $orderbaru->orderdetail = new OrderDetail('baru'); //inisialisasi model OrderDetail $order_detail = new OrderDetail(); //inisialisasi model Pelanggan $pelanggan = new Pasien('search'); $pelanggan->unsetAttributes(); // clear any default values if (isset($_GET['Pasien'])) { $pelanggan->attributes = $_GET['Pasien']; } $newpl = new Pasien('baru'); $newpl->ID_LAYANAN = 1; if (isset($_POST['Pasien'])) { $newpl->attributes = $_POST['Pasien']; $newpl->BIAYA_REGISTRASI = 5000; $newpl->TANGGAL_REGISTRASI = date('Y-m-d H:i:s'); if ($newpl->save()) { Yii::app()->user->setFlash('info', MyFormatter::alertSuccess('<strong>Selamat!</strong> Data telah berhasil disimpan.')); $this->redirect(array('/site')); } } if (isset($_POST['Order'])) { $orderbaru->attributes = $_POST['Order']; $orderbaru->TANGGAL_ORDER = date('Y-m-d H:i:s'); $orderbaru->USER_PEMBUAT = Yii::app()->user->nama; if ($orderbaru->validate()) { $transaction = Yii::app()->db->beginTransaction(); try { if (!$orderbaru->save()) { throw new Exception(); } $subtotal = 0; foreach ($_POST['OrderDetail'] as $kd => $detail) { if (!empty($detail['JUMLAH'])) { $od = new OrderDetail('baru'); $od->ID_ITEM = $kd; $od->KODE_ORDER = $orderbaru->KODE_ORDER; //proses harga by resep $od->HARGA = Item::getHargaByResep($kd, $orderbaru->RESEP); $od->JUMLAH = $detail['JUMLAH']; $od->DISKON = $detail['DISKON']; //$od->DISKON = Barang::getDiskonById($kd); //update stok barang Item::updateStokItem($kd, $detail['JUMLAH']); $subtotal += $od->JUMLAH * $od->HARGA; if (!$od->save()) { throw new Exception(); } } } $transaction->commit(); Yii::app()->user->setFlash('info', MyFormatter::alertSuccess('<strong>Selamat!</strong> Data telah berhasil disimpan.')); $this->redirect(array('/order/view', 'id' => $orderbaru->KODE_ORDER)); } catch (Exception $ex) { $transaction->rollback(); echo $ex->getMessage(); exit; } } } // $dataProvider=new CActiveDataProvider('Pasien',array( // 'pagination'=>false, // )); $this->render('create', array('order' => $order, 'order_detail' => $order_detail, 'pelanggan' => $pelanggan, 'pelanggan_baru' => $newpl, 'orderbaru' => $orderbaru)); }
/** * Manages all models. */ public function actionAdmin() { $model = new Pasien('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['Pasien'])) { $model->attributes = $_GET['Pasien']; } $this->render('admin', array('model' => $model)); }
public function actionAdmin() { $model = new Pasien('search'); $model->unsetAttributes(); // clear any default values if (isset($_POST['Pasien'])) { $id_pasien = $_POST['Pasien']["nama"]; $this->redirect(array('admin2', 'nama' => $id_pasien)); } else { $id_pasien = ""; } if (isset($_GET['Pasien'])) { $model->attributes = $_GET['Pasien']; } $criteria = new CDbCriteria(); $criteria->compare('nama', $id_pasien, true); $dataProvider = new CActiveDataProvider(new Pasien(), array('criteria' => $criteria)); $this->render('admin', array('model' => $model, 'dataProvider' => $dataProvider)); }
public function actionIndex() { if (!WebUser::isGuest() && WebUser::isAdmin()) { $this->render('index'); } elseif (!WebUser::isGuest() && WebUser::isKasir()) { //inisialisasi model Order $order = new Order('search'); $order->unsetAttributes(); // clear any default values if (isset($_GET['Order'])) { $order->attributes = $_GET['Order']; } $orderbaru = new Order('baru'); $orderbaru->RESEP = 1; $orderbaru->orderdetail = new OrderDetail('baru'); //inisialisasi model OrderDetail $order_detail = new OrderDetail(); //inisialisasi model Pelanggan $pelanggan = new Pasien('search'); $pelanggan->unsetAttributes(); // clear any default values if (isset($_GET['Pasien'])) { $pelanggan->attributes = $_GET['Pasien']; } $newpl = new Pasien('baru'); // $newpl->ID_LAYANAN = 1; if (isset($_POST['Pasien'])) { $newpl->attributes = $_POST['Pasien']; //$newpl->BIAYA_REGISTRASI = 5000; $newpl->TANGGAL_REGISTRASI = date('Y-m-d H:i:s'); if ($newpl->save()) { Yii::app()->user->setFlash('info', MyFormatter::alertSuccess('<strong>Selamat!</strong> Data telah berhasil disimpan.')); $this->redirect(array('/site')); } } if (isset($_POST['Order'])) { //var_dump($_POST['Order']); //die(); $orderbaru->attributes = $_POST['Order']; $orderbaru->TANGGAL_ORDER = date('Y-m-d H:i:s'); $orderbaru->USER_PEMBUAT = Yii::app()->user->nama; if ($orderbaru->save()) { $subtotal = 0; foreach ($_POST['OrderDetail'] as $detail) { //var_dump($_POST['OrderDetail']); //die(); $od = new OrderDetail('baru'); $od->ID_ITEM = $detail['ID_ITEM']; $od->KODE_ORDER = $orderbaru->KODE_ORDER; //proses harga by resep $od->HARGA = Item::getHargaByResep($detail['ID_ITEM'], $orderbaru->RESEP); $od->JUMLAH = $detail['JUMLAH']; $od->DISKON = $detail['DISKON']; $od->save(); Item::updateStokItem($detail['ID_ITEM'], $detail['JUMLAH']); $subtotal += $od->JUMLAH * $od->HARGA; } Yii::app()->user->setFlash('info', MyFormatter::alertSuccess('<strong>Selamat!</strong> Data telah berhasil disimpan.')); $this->redirect(array('/order/view', 'id' => $orderbaru->KODE_ORDER)); } // if ($orderbaru->validate()) { // $transaction = Yii::app()->db->beginTransaction(); // try { // if (!$orderbaru->save()) // throw new Exception; // $subtotal = 0; // foreach ($_POST['OrderDetail'] as $kd => $detail) { // if (!empty($detail['JUMLAH'])) { // $od = new OrderDetail('baru'); // $od->ID_ITEM = $kd; // $od->KODE_ORDER = $orderbaru->KODE_ORDER; // //proses harga by resep // $od->HARGA = Item::getHargaByResep($kd, $orderbaru->RESEP); // $od->JUMLAH = $detail['JUMLAH']; // //$od->DISKON = $detail['DISKON']; // //$od->DISKON = Barang::getDiskonById($kd); // //var_dump($_POST['OrderDetail']); // //die(); // //update stok barang // Item::updateStokItem($kd, $detail['JUMLAH']); // $subtotal += $od->JUMLAH * $od->HARGA; // if (!$od->save()) // throw new Exception; // } // } // $transaction->commit(); // Yii::app()->user->setFlash('info', MyFormatter::alertSuccess('<strong>Selamat!</strong> Data telah berhasil disimpan.')); // $this->redirect(array('/order/view', 'id' => $orderbaru->KODE_ORDER)); // } catch (Exception $ex) { // $transaction->rollback(); // echo $ex->getMessage(); exit(); // } // } } $criteria = new CDbCriteria(); $criteria->order = 'TANGGAL_REGISTRASI DESC'; $dataProvider = new CActiveDataProvider('Pasien', array('criteria' => $criteria, 'pagination' => false)); $pasien_today = Pasien::listRegisterToday(); $this->render('index3', array('dataProvider' => $dataProvider, 'order' => $order, 'order_detail' => $order_detail, 'pelanggan' => $pelanggan, 'pelanggan_baru' => $newpl, 'orderbaru' => $orderbaru, 'pasien_today' => $pasien_today)); } else { $this->redirect(array('login')); } }