/** * 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); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['MasterTransaksi'])) { $model->attributes = $_POST['MasterTransaksi']; $model->updated_at = date('Y-m-d H:i:s'); if ($model->save()) { //delete dokter $this->loadModelDeleteDokter($id); //save dokter $model_dokter = json_decode($_POST['MasterTransaksi']['dokter'], true); for ($a = 0; $a < count($model_dokter); $a++) { $m_dokter = new TransaksiDokter(); $m_dokter->id_master_transaksi = $model->id_master_transaksi; $m_dokter->id_dokter = $model_dokter[$a]['id_dokter']; $m_dokter->created_at = date('Y-m-d H:i:s'); $m_dokter->save(); } //delete perawat $this->loadModelDeletePerawat($id); //save perawat $model_perawat = json_decode($_POST['MasterTransaksi']['perawat'], true); for ($a = 0; $a < count($model_perawat); $a++) { $m_perawat = new TransaksiPerawat(); $m_perawat->id_master_transaksi = $model->id_master_transaksi; $m_perawat->id_perawat = $model_perawat[$a]['id_perawat']; $m_perawat->created_at = date('Y-m-d H:i:s'); $m_perawat->save(); } //delete obat $this->loadModelDeleteObat($id); //save obat $model_obat = json_decode($_POST['MasterTransaksi']['obat'], true); for ($a = 0; $a < count($model_obat); $a++) { $m_obat = new TransaksiObat(); $m_obat->id_master_transaksi = $model->id_master_transaksi; $m_obat->id_obat = $model_obat[$a]['id_obat']; $m_obat->jumlah = $model_obat[$a]['jumlah']; $m_obat->created_at = date('Y-m-d H:i:s'); $m_obat->save(); //update stok barang Yii::app()->db->createCommand("update tbl_barang set stok=stok-" . $m_obat->jumlah . " where id_barang='" . $m_obat->id_obat . "'")->execute(); } //delete perawatan $this->loadModelDeletePerawatan($id); //save perawatan $model_perawatan = json_decode($_POST['MasterTransaksi']['perawatan'], true); for ($a = 0; $a < count($model_perawatan); $a++) { $m_perawatan = new TransaksiPerawatan(); $m_perawatan->id_master_transaksi = $model->id_master_transaksi; $m_perawatan->id_perawatan = $model_perawatan[$a]['id']; $m_perawatan->created_at = date('Y-m-d H:i:s'); $m_perawatan->save(); $model_obat_perawatan = $model_perawatan[$a]['obat']; for ($b = 0; $b < count($model_obat_perawatan); $b++) { $m_obat_perawatan = new TransaksiObatDalam(); $m_obat_perawatan->id_transaksi_perawatan = $m_perawatan->id_transaksi_perawatan; $m_obat_perawatan->id_obat = $model_obat_perawatan[$b]['id_obat']; $m_obat_perawatan->jumlah = $model_obat_perawatan[$b]['jumlah']; $m_obat_perawatan->created_at = date('Y-m-d H:i:s'); $m_obat_perawatan->save(); //update stok barang Yii::app()->db->createCommand("update tbl_barang_dalam set stok=stok-" . $m_obat_perawatan->jumlah . " where id_barang_dalam='" . $m_obat_perawatan->id_obat . "'")->execute(); } } $this->redirect(array('view', 'id' => $model->id_master_transaksi)); } } $m_dokter = $this->loadModelDetailDokter($id); $arr_dokter = array(); foreach ($m_dokter as $md) { $d['id_dokter'] = $md->id_dokter; array_push($arr_dokter, $d); } $m_perawat = $this->loadModelDetailPerawat($id); $arr_perawat = array(); foreach ($m_perawat as $mp) { $d['id_perawat'] = $mp->id_perawat; array_push($arr_perawat, $d); } $m_obat = $this->loadModelDetailObat($id); $arr_obat = array(); foreach ($m_obat as $mo) { $d['id_obat'] = $mo->id_obat; $d['harga'] = $mo->Barang->harga_jual - $mo->Barang->harga_jual * $mo->Barang->diskon / 100; $d['diskon'] = $mo->Barang->diskon . '%'; $d['jumlah'] = $mo->jumlah; array_push($arr_obat, $d); } $m_perawatan = $this->loadModelDetailPerawatan($id); $arr_perawatan = array(); $member = $model->Pasien->member; $diskon = 0; foreach ($m_perawatan as $mp) { $perawatan = Perawatan::model()->findByPk($mp->id_perawatan); if ($member === 'Tidak') { $diskon = $perawatan->diskon_umum; } else { if ($perawatan->diskon_umum > $perawatan->diskon_member) { $diskon = $perawatan->diskon_umum; } else { $diskon = $perawatan->diskon_member; } } $d['id'] = $mp->id_perawatan; $d['diskon'] = $diskon; $d['harga'] = $perawatan->harga - $perawatan->harga / 100 * $diskon; $d['komisi_dokter'] = $mp->Perawatan->komisi_dokter; $d['komisi_perawat'] = $mp->Perawatan->komisi_perawat; $d['obat'] = array(); $criteria = new CDbCriteria(); $criteria->condition = "id_perawatan = '" . $mp->id_perawatan . "'"; $m_obat_perawatan = ObatPerawatan::model()->findAll($criteria); foreach ($m_obat_perawatan as $key => $op) { $d_op['id_obat'] = $op->id_obat; $d_op['jumlah'] = $op->jumlah; $d_op['nama_barang'] = $op->BarangDalam->nama_barang; $d_op['harga'] = ($op->BarangDalam->harga_jual - $op->BarangDalam->harga_jual * $op->BarangDalam->diskon / 100) * $op->jumlah; array_push($d['obat'], $d_op); } array_push($arr_perawatan, $d); } $fetch_detail['biaya'] = $model->biaya; $fetch_detail['hutang'] = $model->hutang; $fetch_detail['total'] = $model->total; $fetch_detail['total_bayar'] = $model->total_bayar; $fetch_detail['id_pasien'] = $model->id_pasien; $this->render('update', array('model' => $model, 'arr_dokter' => $arr_dokter, 'arr_perawat' => $arr_perawat, 'arr_obat' => $arr_obat, 'arr_perawatan' => $arr_perawatan, 'm_array' => $fetch_detail)); }
public function loadModelDeleteObat($id) { $model = $this->loadModelDetailObat($id); foreach ($model as $md) { $m_transaksi_obat = ObatPerawatan::model()->findByPk($md->id_obat_perawatan); $this->updateObatBeforeDelete($md->id_obat, $md->jumlah); $m_transaksi_obat->delete(); } return; }
} else { if ($m_perawatan->diskon_umum > $m_perawatan->diskon_member) { $data['diskon'] = $m_perawatan->diskon_umum; } else { $data['diskon'] = $m_perawatan->diskon_member; } } echo "<tr>"; echo "<td>" . $no . "</td>"; echo "<td>" . $o->Perawatan->nama_perawatan . "</td>"; echo "<td>" . ($m_perawatan->harga - $m_perawatan->harga / 100 * $data['diskon']) . "</td>"; echo "<td>" . $data['diskon'] . "</td>"; echo "<td>"; $criteria = new CDbCriteria(); $criteria->condition = "id_perawatan = '" . $o->id_perawatan . "'"; $m_obat_perawatan = ObatPerawatan::model()->findAll($criteria); ?> <table> <tr ng-repeat="obatPerawatan in perawatan.obat"> <td> <?php $obat = BarangDalam::model()->findAll(); ?> <select ng-change="updateObatPerawatan(indexPerawatan,$index, obatPerawatan.id_obat, obatPerawatan.jumlah)" ng-model="obatPerawatan.id_obat"> <?php for ($i = 0; $i < count($obat); $i++) { echo '<option value="' . $obat[$i]['id_barang_dalam'] . '">' . $obat[$i]['nama_barang'] . ' - Rp. ' . number_format($obat[$i]['harga_jual'] - $obat[$i]['harga_jual'] * $obat[$i]['diskon'] / 100, 2, ',', '.') . '</option>'; } ?> </select>