コード例 #1
0
ファイル: Pos.php プロジェクト: AbuMuhammad/ap3
 /**
  * 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()));
     }
 }
コード例 #2
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Penjualan the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Penjualan::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
コード例 #3
0
ファイル: Penjualan.php プロジェクト: AbuMuhammad/ap3
 /**
  * Proses simpan penjualan.
  * Jika piutang, terbit nota debit (gudang)
  *
  * Simpan penjualan:
  * 1. Update status dari draft menjadi piutang.
  * 2. Update stock
  * 3. Catat harga beli dan harga jual
  * 4. Jika stok minus harga beli adalah harga beli terakhir
  * 5. Buat nota debit (piutang)
  *
  */
 public function simpanPenjualan()
 {
     if (!$this->save()) {
         throw new Exception('Gagal simpan penjualan', 500);
     }
     $details = PenjualanDetail::model()->findAll('penjualan_id=:penjualanId', array(':penjualanId' => $this->id));
     foreach ($details as $detail) {
         $inventoryTerpakai = InventoryBalance::model()->jual($detail->barang_id, $detail->qty);
         $count = 1;
         foreach ($inventoryTerpakai as $layer) {
             $hpp = new HargaPokokPenjualan();
             $hpp->penjualan_detail_id = $detail->id;
             $hpp->pembelian_detail_id = $layer['pembelianDetailId'];
             $hpp->qty = $layer['qtyTerpakai'];
             $hpp->harga_beli = $layer['hargaBeli'];
             // Jika negatif simpan juga di harga_beli_temp
             // FIX ME, jika pembelian harga beli nya beda
             if (isset($layer['negatif']) && $layer['negatif']) {
                 $hpp->harga_beli_temp = $layer['hargaBeli'];
             }
             if (!$hpp->save()) {
                 throw new Exception("Gagal simpan HPP", 500);
             }
             /* Tambahan untuk transfer mode,
              * cek apakah harga jual masih sama dengan inventory
              * jika beda, maka tambahkan juga detail penjualannya
              * ctt: transfer mode, harga jual = harga beli, jadi
              * hpp = penjualan_detail
              */
             if ($this->transfer_mode && $count > 1) {
                 $this->tambahDetailTransferBarang($detail, HargaPokokPenjualan::model()->findByPk($hpp->id));
             }
             $count++;
         }
     }
     $jumlahPenjualan = $this->ambilTotal();
     // Buat Hutang Piutang
     $piutang = new HutangPiutang();
     $piutang->profil_id = $this->profil_id;
     $piutang->jumlah = $jumlahPenjualan;
     $piutang->tipe = HutangPiutang::TIPE_PIUTANG;
     $piutang->asal = HutangPiutang::DARI_PENJUALAN;
     $piutang->nomor_dokumen_asal = $this->nomor;
     if (!$piutang->save()) {
         throw new Exception("Gagal simpan piutang", 500);
     }
     /*
      * Piutang Detail
      */
     $piutangDetail = new HutangPiutangDetail();
     $piutangDetail->hutang_piutang_id = $piutang->id;
     $piutangDetail->keterangan = 'Pembelian: ' . $this->nomor;
     $piutangDetail->jumlah = $jumlahPenjualan;
     if (!$piutangDetail->save()) {
         throw new Exception("Gagal simpan piutang detail", 500);
     }
     /*
      * Simpan hutang_piutang_id ke penjualan
      */
     if (!Penjualan::model()->updateByPk($this->id, array('hutang_piutang_id' => $piutang->id)) > 1) {
         throw new Exception("Gagal simpan piutang_id", 500);
     }
     /* Simpan poin jika ada */
     if ($this->getCurPoin() > 0) {
         $penjualanMember = new PenjualanMember();
         $penjualanMember->penjualan_id = $this->id;
         $penjualanMember->profil_id = $this->profil_id;
         $penjualanMember->poin = $this->getCurPoin();
         if (!$penjualanMember->save()) {
             throw new Exception("Gagal simpan poin ke penjualan", 500);
         }
     }
 }
コード例 #4
0
ファイル: HutangPiutang.php プロジェクト: AbuMuhammad/ap3
 public function updateStatusDokumenAsal($status)
 {
     switch ($this->asal) {
         case HutangPiutang::DARI_PEMBELIAN:
             $model = Pembelian::model()->findByAttributes(array('hutang_piutang_id' => $this->id));
             $model->status = $status == HutangPiutang::STATUS_LUNAS ? Pembelian::STATUS_LUNAS : Pembelian::STATUS_HUTANG;
             $model->update(array('status'));
             break;
         case HutangPiutang::DARI_RETUR_BELI:
             $model = ReturPembelian::model()->findByAttributes(array('hutang_piutang_id' => $this->id));
             $model->status = $status == HutangPiutang::STATUS_LUNAS ? ReturPembelian::STATUS_LUNAS : ReturPembelian::STATUS_PIUTANG;
             $model->update(array('status'));
             break;
         case HutangPiutang::DARI_PENJUALAN:
             $model = Penjualan::model()->findByAttributes(array('hutang_piutang_id' => $this->id));
             $model->status = $status == HutangPiutang::STATUS_LUNAS ? Penjualan::STATUS_LUNAS : Penjualan::STATUS_PIUTANG;
             $model->update(array('status'));
             break;
         case HutangPiutang::DARI_RETUR_JUAL:
             $model = ReturPenjualan::model()->findByAttributes(array('hutang_piutang_id' => $this->id));
             $model->status = $status == HutangPiutang::STATUS_LUNAS ? ReturPenjualan::STATUS_LUNAS : ReturPenjualan::STATUS_HUTANG;
             $model->update(array('status'));
             break;
     }
 }
コード例 #5
0
 public function getInfoStruk()
 {
     return Penjualan::model()->find(['order' => 'id desc', 'condition' => 'status=' . Penjualan::STATUS_LUNAS . ' and TIMESTAMPDIFF(SECOND, tanggal, NOW()) <= 15']);
 }
コード例 #6
0
ファイル: PosController.php プロジェクト: AbuMuhammad/ap3
 public function actionUpdateHargaManual()
 {
     $return = array('sukses' => false, 'error' => array('code' => '500', 'msg' => 'Sempurnakan input!'));
     if (isset($_POST['pk'])) {
         $pk = $_POST['pk'];
         $hargaManual = $_POST['value'];
         $penjualanDetail = PenjualanDetail::model()->findByPk($pk);
         $penjualan = Penjualan::model()->findByPk($penjualanDetail->penjualan_id);
         $return = $penjualan->updateHargaManual($penjualanDetail, $hargaManual);
     }
     $this->renderJSON($return);
 }