Ejemplo n.º 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()));
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'ubah' page.
  */
 public function actionTambah()
 {
     $model = new Penerimaan();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Penerimaan'])) {
         $model->attributes = $_POST['Penerimaan'];
         if ($model->save()) {
             $this->redirect(array('ubah', 'id' => $model->id));
         }
     }
     $profil = new Profil('search');
     $profil->unsetAttributes();
     // clear any default values
     if (isset($_GET['Profil'])) {
         $profil->attributes = $_GET['Profil'];
     }
     $this->render('tambah', array('model' => $model, 'profil' => $profil));
 }