Beispiel #1
0
 /**
  * Simpan POS
  * 1. Simpan penjualan
  * 2. Proses penerimaan
  */
 public function simpanPOS($posData)
 {
     $transaction = $this->dbConnection->beginTransaction();
     $this->scenario = 'simpanPenjualan';
     try {
         $this->simpanPenjualan();
         $penerimaan = new Penerimaan();
         $penerimaan->tanggal = date('d-m-Y');
         //$penerimaan->referensi = '[POS]';
         //$penerimaan->tanggal_referensi = date('d-m-Y');
         $penerimaan->profil_id = $this->profil_id;
         $penerimaan->kas_bank_id = $posData['account'];
         $penerimaan->jenis_transaksi_id = $posData['jenistr'];
         $penerimaan->kategori_id = self::KATEGORI_TRX;
         $penerimaan->uang_dibayar = $posData['uang'];
         $penerimaan->save();
         $penjualan = Penjualan::model()->findByPk($this->id);
         $hutangPiutangId = $penjualan->hutang_piutang_id;
         $dokumen = HutangPiutang::model()->findByPk($hutangPiutangId);
         if (is_null($dokumen)) {
             die(serialize($penjualan->attributes));
         }
         $item = $dokumen->itemBayarHutang;
         $penerimaanDetail = new PenerimaanDetail();
         $penerimaanDetail->penerimaan_id = $penerimaan->id;
         $penerimaanDetail->item_id = $item['itemId'];
         $penerimaanDetail->hutang_piutang_id = $hutangPiutangId;
         $penerimaanDetail->keterangan = '[POS] ' . $dokumen->keterangan();
         $penerimaanDetail->jumlah = $dokumen->sisa;
         $penerimaanDetail->save();
         $penerimaanLoad = Penerimaan::model()->findByPk($penerimaan->id);
         if (!$penerimaanLoad->prosesP()) {
             throw new Exception("Gagal proses penerimaan", 500);
         }
         //            if (!$penerimaan->prosesP()) {
         //                throw new Exception("Gagal proses penerimaan", 500);
         //            }
         $transaction->commit();
         return array('sukses' => true);
     } catch (Exception $ex) {
         $transaction->rollback();
         return array('sukses' => false, 'error' => array('msg' => $ex->getMessage(), 'code' => $ex->getCode()));
     }
 }
Beispiel #2
0
 public function prosesP()
 {
     $this->scenario = 'proses';
     if ($this->save()) {
         // Ambil details yang hutang piutang untuk diproses lebih lanjut
         $details = PenerimaanDetail::model()->findAll('penerimaan_id=:penerimaanId and hutang_piutang_id is not null', array(':penerimaanId' => $this->id));
         foreach ($details as $detail) {
             $hutangPiutang = HutangPiutang::model()->findByPk($detail->hutang_piutang_id);
             // Bayar dan simpan
             if (!($hutangPiutang->bayar() && $hutangPiutang->save())) {
                 throw new Exception("Gagal proses bayar hutang piutang");
             }
         }
         return true;
     } else {
         throw new Exception("Gagal Proses");
     }
 }
 public function actionHapusDetail($id)
 {
     PenerimaanDetail::model()->findByPk($id)->delete();
 }