public function actionDelete() { if (Yii::app()->request->isPostRequest) { if (isset($_POST) && !empty($_POST)) { $msg = 'Data berhasil divoid.'; $status = true; $id = $_POST['id']; $memo_ = $_POST['memo_']; $transaction = app()->db->beginTransaction(); try { $user = app()->user->getId(); $model = $this->loadModel($id, 'MtKembaliKendaraan'); $date = $model->trans_date; $docref = $model->doc_ref_kembali; $msg = "Pengembalian kendaraan dengan referensi {$docref} berhasil divoid."; $void = new MtVoided(); $void->type = KEMBALI_KENDARAAN; $void->id = $id; $void->date_ = $date; $void->memo_ = $memo_; $void->save(); if ($model->pelunasan > 0) { if ($model->trans_via == "Tunai") { $bank_account = Mt::get_act_code_from_bank_act(Mt::get_prefs('akun_kas_ditangan')); } else { $bank_account = Mt::get_act_code_from_bank_act(Mt::get_prefs('akun_kas_dibank')); } // void gl // debit penjualan , kredit kas Mt::add_gl(VOID, $void->id_voided, $date, $docref, $bank_account, "VOID Pengembalian Kendaraan {$docref}", -$model->pelunasan, $user, $model->idPinjam->id_mobil); Mt::add_gl(VOID, $void->id_voided, $date, $docref, Mt::get_prefs('akun_uang_muka'), "VOID Pengembalian Kendaraan {$docref}", -$model->dp, $user, $model->idPinjam->id_mobil); Mt::add_gl(VOID, $void->id_voided, $date, $docref, Mt::get_prefs('akun_pendapatan_sewa'), "VOID Pengembalian Kendaraan {$docref}", $model->total, $user, $model->idPinjam->id_mobil); if ($model->disc > 0) { Mt::add_gl(VOID, $void->id_voided, $date, $docref, Mt::get_prefs('akun_diskon'), "VOID Pengembalian Kendaraan {$docref}", -$model->disc, $user, $model->idPinjam->id_mobil); } } $pinjam = $this->loadModel($model->id_pinjam, 'MtPinjamKendaraan'); $pinjam->is_back = 0; $pinjam->id_driver = null; $pinjam->save(); $status = true; $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); $status = false; $msg = $ex; } echo CJSON::encode(array('success' => $status, 'msg' => $msg)); Yii::app()->end(); } } else { throw new CHttpException(400, Yii::t('app', 'Invalid request. Please do not repeat this request again.')); } }
public function actionDelete() { if (!app()->request->isAjaxRequest) { return; } if (isset($_POST) && !empty($_POST)) { $id = $_POST['id']; $memo_ = $_POST['memo_']; $status = false; $msg = 'Kas masuk berhasil divoid.'; $user = app()->user->getId(); $transaction = app()->db->beginTransaction(); try { $kas_masuk = MtKasMasuk::model()->findByPk($id); $date = $kas_masuk->trans_date; $docref = $kas_masuk->doc_ref; $void = new MtVoided(); $void->type = KAS_MASUK; $void->id = $id; $void->date_ = $date; $void->memo_ = $memo_; $void->save(); $bank = MtBankAccounts::model()->findByPk($kas_masuk->mt_bank_accounts_id); $act_donatur = $kas_masuk->account_code; //void gl Mt::add_gl(VOID, $void->id_voided, $date, $docref, $act_donatur, "VOID Kas Masuk {$docref}", $kas_masuk->amount, $user, $kas_masuk->id_mobil); Mt::add_gl(VOID, $void->id_voided, $date, $docref, $bank->account_code, "VOID Kas Masuk {$docref}", -$kas_masuk->amount, $user, $kas_masuk->id_mobil); $transaction->commit(); $status = true; } catch (Exception $ex) { $transaction->rollback(); $status = false; $msg = $ex; } } echo CJSON::encode(array('success' => $status, 'msg' => $msg)); app()->end(); }