示例#1
0
 public function simpan()
 {
     $this->scenario = 'simpan';
     $transaction = $this->dbConnection->beginTransaction();
     try {
         /*
          * Save sekaligus mengubah status dari draft jadi piutang
          */
         if ($this->save()) {
             $details = ReturPenjualanDetail::model()->findAll("retur_penjualan_id={$this->id}");
             foreach ($details as $detail) {
                 /*
                  * Untuk setiap item, tambahkan qty ke inventory baru
                  */
                 InventoryBalance::model()->returJual($detail);
             }
             // Total dari retur penjualan
             // Jika nanti ada item lain, misal: Transport, pajak, dll
             // ditambahkan di sini
             $jumlahReturJual = $this->ambilTotal();
             /*
              * Create hutang
              */
             $hutang = new HutangPiutang();
             $hutang->profil_id = $this->profil_id;
             $hutang->jumlah = $jumlahReturJual;
             $hutang->tipe = HutangPiutang::TIPE_HUTANG;
             $hutang->asal = HutangPiutang::DARI_RETUR_JUAL;
             $hutang->nomor_dokumen_asal = $this->nomor;
             if (!$hutang->save()) {
                 throw new Exception("Gagal simpan hutang");
             }
             /*
              * Hutang Detail
              */
             $hutangDetail = new HutangPiutangDetail();
             $hutangDetail->hutang_piutang_id = $hutang->id;
             $hutangDetail->keterangan = 'Retur Jual: ' . $this->nomor;
             $hutangDetail->jumlah = $jumlahReturJual;
             if (!$hutangDetail->save()) {
                 throw new Exception("Gagal simpan hutang detail");
             }
             /*
              * Simpan hutang_id ke pembelian
              */
             if (!ReturPenjualan::model()->updateByPk($this->id, array('hutang_piutang_id' => $hutang->id)) > 1) {
                 throw new Exception("Gagal simpan hutang_id");
             }
             $transaction->commit();
             return true;
         } else {
             throw new Exception("Gagal Simpan Retur Penjualan");
         }
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
 }
示例#2
0
 public function modelAsal()
 {
     switch ($this->asal) {
         case InventoryBalance::ASAL_PEMBELIAN:
             return Pembelian::model()->find("nomor={$this->nomor_dokumen}");
         case InventoryBalance::ASAL_RETURJUAL:
             return ReturPenjualan::model()->find("nomor={$this->nomor_dokumen}");
         case InventoryBalance::ASAL_SO:
             return StockOpname::model()->find("nomor={$this->nomor_dokumen}");
     }
 }
示例#3
0
 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;
     }
 }
 public function exportPdf($id, $kertas = ReturPenjualan::KERTAS_A4, $draft = false)
 {
     $modelHeader = $this->loadModel($id);
     $configs = Config::model()->findAll();
     /*
      * Ubah config (object) jadi array
      */
     $branchConfig = array();
     foreach ($configs as $config) {
         $branchConfig[$config->nama] = $config->nilai;
     }
     /*
      * Data Supplier
      */
     $profil = Profil::model()->findByPk($modelHeader->profil_id);
     /*
      * Retur Penjualan Detail
      */
     $returPenjualanDetail = ReturPenjualanDetail::model()->with('penjualanDetail', 'penjualanDetail.barang')->findAll(array('condition' => "retur_penjualan_id={$id}", 'order' => 'barang.nama'));
     /*
      * Persiapan render PDF
      */
     $listNamaKertas = ReturPenjualan::listNamaKertas();
     $mPDF1 = Yii::app()->ePdf->mpdf('', $listNamaKertas[$kertas]);
     $viewCetak = '_pdf';
     if ($draft) {
         $viewCetak = '_pdf_draft';
     }
     $mPDF1->WriteHTML($this->renderPartial($viewCetak, array('modelHeader' => $modelHeader, 'branchConfig' => $branchConfig, 'profil' => $profil, 'returPenjualanDetail' => $returPenjualanDetail), true));
     $mPDF1->SetDisplayMode('fullpage');
     $mPDF1->pagenumSuffix = ' dari ';
     $mPDF1->pagenumPrefix = 'Halaman ';
     // Render PDF
     $mPDF1->Output("{$modelHeader->nomor}.pdf", 'I');
 }