public function actionCreate() { if (!Yii::app()->request->isAjaxRequest) { return; } if (isset($_POST) && !empty($_POST)) { $status = false; $msg = 'Anggaran berhasil disimpan.'; $bulanStr = $_POST['bulanStr']; $bulan = $_POST['periode_bulan']; $tahun = $_POST['periode_tahun']; $detils = CJSON::decode($_POST['detil']); //require_once(Yii::app()->basePath . '/vendors/frontaccounting/ui.inc'); app()->db->autoCommit = false; $transaction = app()->db->beginTransaction(); try { $anggaran = new PahAnggaran(); $ref = new PahReferenceCom(); $docref = $ref->get_next_reference(ANGGARAN); $_POST['PahAnggaran']['doc_ref'] = $docref; $_POST['PahAnggaran']['periode_bulan'] = $bulan; $_POST['PahAnggaran']['periode_tahun'] = $tahun; $_POST['PahAnggaran']['lock'] = 0; $_POST['PahAnggaran']['trans_date'] = Yii::app()->dateFormatter->format('yyyy-MM-dd', time()); $_POST['PahAnggaran']['users_id'] = Yii::app()->user->getId(); $anggaran->attributes = $_POST['PahAnggaran']; if (!$anggaran->save()) { throw new Exception("Gagal menyimpan anggaran."); } foreach ($detils as $detil) { $anggaran_detil = new PahAnggaranDetil(); $_POST['PahAnggaranDetil']['pah_chart_master_account_code'] = $detil['pah_chart_master_account_code']; $_POST['PahAnggaranDetil']['amount'] = $detil['amount']; $_POST['PahAnggaranDetil']['pah_anggaran_id'] = $anggaran->id; $anggaran_detil->attributes = $_POST['PahAnggaranDetil']; if (!$anggaran_detil->save()) { throw new Exception("Gagal menyimpan detil anggaran."); } } //$anggaran->pahAnggaranDetils = $ag_detil; $ref->save(ANGGARAN, $anggaran->id, $docref); $transaction->commit(); $status = true; } catch (Exception $ex) { $transaction->rollback(); $status = false; $msg = $ex; } echo CJSON::encode(array('success' => $status, 'bulan' => $bulanStr, 'tahun' => $tahun, 'id' => $docref, 'msg' => $msg)); Yii::app()->end(); } }
public function actionCreate() { if (!Yii::app()->request->isAjaxRequest) { return; } if (isset($_POST) && !empty($_POST)) { $gl = new GlPah(); $status = false; $msg = 'Kas masuk berhasil disimpan.'; $user = Yii::app()->user->getId(); $id = -1; //require_once(Yii::app()->basePath . '/vendors/frontaccounting/ui.inc'); app()->db->autoCommit = false; $transaction = app()->db->beginTransaction(); try { $ref = new PahReferenceCom(); $docref = $ref->get_next_reference(KAS_MASUK); $kas_masuk = new PahKasMasuk(); foreach ($_POST as $k => $v) { if ($k == 'amount') { $v = get_number($v); } $_POST['PahKasMasuk'][$k] = $v; } $date = $_POST['PahKasMasuk']['trans_date']; $_POST['PahKasMasuk']['entry_time'] = Now(); $_POST['PahKasMasuk']['users_id'] = $user; $_POST['PahKasMasuk']['doc_ref'] = $docref; $kas_masuk->attributes = $_POST['PahKasMasuk']; if (!$kas_masuk->save()) { throw new Exception("Gagal menyimpan kas masuk."); } $id = $docref; $ref->save(KAS_MASUK, $kas_masuk->kas_masuk_id, $docref); $bank_account = Pah::get_act_code_from_bank_act($kas_masuk->pah_bank_accounts_id); $act_donatur = $kas_masuk->pahDonatur->pah_chart_master_account_code; //debet kode kas/bank - kredit pendapatan $gl->add_gl(KAS_MASUK, $kas_masuk->kas_masuk_id, $date, $docref, $bank_account, '-', $kas_masuk->amount, $user); $gl->add_gl(KAS_MASUK, $kas_masuk->kas_masuk_id, $date, $docref, $act_donatur, $kas_masuk->note, -$kas_masuk->amount, $user); $gl->validate(); $transaction->commit(); $status = true; } catch (Exception $ex) { $transaction->rollback(); $status = false; $msg = $ex; } } echo CJSON::encode(array('success' => $status, 'id' => $id, 'msg' => $msg)); Yii::app()->end(); }
public function actionCreate() { if (!Yii::app()->request->isAjaxRequest) { return; } if (isset($_POST) && !empty($_POST)) { $gl = new GlPah(); $status = false; $msg = 'Anggaran berhasil disimpan.'; $user = Yii::app()->user->getId(); $id = -1; //require_once(Yii::app()->basePath . '/vendors/frontaccounting/ui.inc'); app()->db->autoCommit = false; $transaction = app()->db->beginTransaction(); try { $ref = new PahReferenceCom(); $docref = $ref->get_next_reference(AKTIVITAS); $aktivitas = new PahAktivitas(); foreach ($_POST as $k => $v) { if ($k == 'amount') { $v = get_number($v); } $_POST['PahAktivitas'][$k] = $v; } $date = $_POST['PahAktivitas']['trans_date']; $_POST['PahAktivitas']['entry_time'] = Now(); $_POST['PahAktivitas']['users_id'] = $user; $_POST['PahAktivitas']['doc_ref'] = $docref; $aktivitas->attributes = $_POST['PahAktivitas']; if (!$aktivitas->save()) { throw new Exception("Gagal menyimpan aktivitas."); } $id = $docref; $ref->save(AKTIVITAS, $aktivitas->aktivitas_id, $docref); $bank_account = Pah::get_act_code_from_bank_act($aktivitas->pah_bank_accounts_id); $act_sub = $aktivitas->pahSubAktivitas->account_code; //debet kode beban - kredit kas bank $gl->add_gl(AKTIVITAS, $aktivitas->aktivitas_id, $date, $docref, $act_sub, $aktivitas->note, $aktivitas->amount, $user); $gl->add_gl(AKTIVITAS, $aktivitas->aktivitas_id, $date, $docref, $bank_account, '-', -$aktivitas->amount, $user); $gl->validate(); $transaction->commit(); $status = true; } catch (Exception $ex) { $transaction->rollback(); $status = false; $msg = $ex; } echo CJSON::encode(array('success' => $status, 'id' => $id, 'msg' => $msg)); Yii::app()->end(); } }
public function actionCreateTransfer() { if (!Yii::app()->request->isAjaxRequest) { return; } if (isset($_POST) && !empty($_POST)) { $gl = new GlPah(); //require_once(Yii::app()->basePath . '/vendors/frontaccounting/ui.inc'); $status = false; $msg = 'Transfer antar kas berhasil diproses.'; $id = -1; $bank_asal = $_POST['bank_act_asal']; $bank_tujuan = $_POST['bank_act_tujuan']; $trans_date = $_POST['trans_date']; $memo = $_POST['memo']; $amount = get_number($_POST['amount']); if ($bank_asal == $bank_tujuan) { echo CJSON::encode(array('success' => false, 'id' => -1, 'msg' => 'Bank asal dan bank tujuan tidak boleh sama.')); Yii::app()->end(); } if ($amount <= 0) { echo CJSON::encode(array('success' => false, 'id' => -1, 'msg' => 'Jumlah yang akan ditransfer harus lebih dari nol.')); Yii::app()->end(); } app()->db->autoCommit = false; $transaction = app()->db->beginTransaction(); try { $ref = new PahReferenceCom(); $docref = $ref->get_next_reference(BANKTRANSFER); $bank_account_asal = Pah::get_act_code_from_bank_act($bank_asal); $bank_account_tujuan = Pah::get_act_code_from_bank_act($bank_tujuan); $trans_no = Pah::get_next_trans_no_bank_trans(); $user = Yii::app()->user->getId(); //debet kode bank tujuan - kredit kode bank asal $gl->add_gl(BANKTRANSFER, $trans_no, $trans_date, $docref, $bank_account_tujuan, $memo, $amount, $user); $gl->add_gl(BANKTRANSFER, $trans_no, $trans_date, $docref, $bank_account_asal, $memo, -$amount, $user); $ref->save(BANKTRANSFER, $trans_no, $docref); $id = $docref; $gl->validate(); $transaction->commit(); $status = true; } catch (Exception $ex) { $transaction->rollback(); $status = false; $msg = $ex; } echo CJSON::encode(array('success' => $status, 'id' => $id, 'msg' => $msg)); Yii::app()->end(); } }