Esempio n. 1
0
 public function reportPembelian()
 {
     $dari = date_format(date_create_from_format('d-m-Y', $this->dari), 'Y-m-d');
     $sampai = date_format(date_create_from_format('d-m-Y', $this->sampai), 'Y-m-d');
     // echo $dari.' sampai '.$sampai;
     $criteria = new CDbCriteria();
     $criteria->addBetweenCondition("date_format(tanggal,'%Y-%m-%d')", $dari, $sampai);
     //      if (!empty($this->profilId)) {
     //         $criteria->addCondition('profil_id=:profilId', array(':profilId' => $this->profilId));
     //      }
     $pembelian = Pembelian::model()->findAll($criteria);
     return $pembelian;
 }
Esempio n. 2
0
 /**
  * Ambil nomor referensi untuk pembelian
  * @return text nomor referensi, null jika selain pembelian
  */
 public function getNoref()
 {
     switch ($this->asal) {
         case HutangPiutang::DARI_PEMBELIAN:
             $model = Pembelian::model()->find('hutang_piutang_id =' . $this->id);
             return $model->referensi;
         default:
             return null;
     }
 }
Esempio n. 3
0
 /**
  * Simpan pembelian:
  * 1. update status dari draft menjadi pembelian.
  * 2. update stock.
  * 3. update harga jual & rrp
  * 4. create hutang.
  * 5. update stok minus. BELUM !!
  * @return boolean True jika proses berhasil
  * @throws Exception
  */
 public function simpanPembelian()
 {
     $this->scenario = 'simpanPembelian';
     $transaction = $this->dbConnection->beginTransaction();
     /* Untuk jumlah pembelian yang sangat banyak, misal: init data */
     if ($this->profil_id == 1) {
         ini_set('memory_limit', '-1');
         set_time_limit(0);
     }
     try {
         if ($this->save()) {
             /*
              * Ambil data barang, dan data inventory terakhir/terbaru nya
              * Jika inventory tidak ada, maka ib.* nilainya null
              */
             $details = PembelianDetail::model()->findAll('pembelian_id=:pembelianId', array(':pembelianId' => $this->id));
             foreach ($details as $detail) {
                 /* Untuk setiap barang yang dibeli */
                 /* Sesuaikan inventory */
                 $inventoryBalance = new InventoryBalance();
                 $inventoryBalance->beli(InventoryBalance::ASAL_PEMBELIAN, $this->nomor, $detail->id, $detail->barang_id, $detail->harga_beli, $detail->qty);
                 /*
                  * Update harga jual
                  */
                 if (!HargaJual::model()->updateHarga($detail->barang_id, $detail->harga_jual)) {
                     throw new Exception("Gagal Update Harga Jual");
                 }
                 /*
                  * Update Rrp
                  */
                 if (!HargaJualRekomendasi::model()->updateHarga($detail->barang_id, $detail->harga_jual_rekomendasi)) {
                     throw new Exception("Gagal Update RRP");
                 }
                 /* Tambahkan supplier ke barang ini, jika belum ada */
                 $supplierBarangAda = SupplierBarang::model()->find("supplier_id={$this->profil_id} and barang_id = {$detail->barang_id}");
                 if (is_null($supplierBarangAda)) {
                     $supplierBarang = new SupplierBarang();
                     $supplierBarang->barang_id = $detail->barang_id;
                     $supplierBarang->supplier_id = $this->profil_id;
                     if (!$supplierBarang->save()) {
                         throw new Exception("Gagal simpan supplier barang");
                     }
                 }
             }
             // Total dari pembelian barang
             // Jika nanti ada item lain, misal: Transport, pajak, dll
             // ditambahkan di sini
             $jumlahPembelian = $this->ambilTotal();
             /*
              * Create (hutang)
              */
             $hutang = new HutangPiutang();
             $hutang->profil_id = $this->profil_id;
             $hutang->jumlah = $jumlahPembelian;
             $hutang->tipe = HutangPiutang::TIPE_HUTANG;
             $hutang->asal = HutangPiutang::DARI_PEMBELIAN;
             $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 = 'Pembelian: ' . $this->nomor;
             $hutangDetail->jumlah = $jumlahPembelian;
             if (!$hutangDetail->save()) {
                 throw new Exception("Gagal simpan hutang detail");
             }
             /*
              * Simpan hutang_id ke pembelian
              */
             if (!Pembelian::model()->updateByPk($this->id, array('hutang_piutang_id' => $hutang->id)) > 1) {
                 throw new Exception("Gagal simpan hutang_id");
             }
             $transaction->commit();
             return array('sukses' => true);
         } else {
             throw new Exception("Gagal Simpan Pembelian");
         }
     } catch (Exception $ex) {
         $transaction->rollback();
         // throw $up;
         return array('sukses' => false, 'error' => array('msg' => $ex->getMessage(), 'code' => $ex->getCode()));
     }
 }
Esempio n. 4
0
                        <th class="rata-kanan">No</th>
                        <th>Tanggal</th>
                        <th>Dokumen</th>
                        <th class="rata-kanan">Jumlah</th>
                        <th class="rata-kanan">Bayar</th>
                        <th class="rata-kanan">Sisa</th>
                    </tr>
                </thead>
                <?php
                $i = 1;
                foreach ($report['dataHutang'] as $baris):
                    /* Tambahan untuk pembelian mencari nomor referensi
                     * untuk ditampilkan
                     */
                    if ($baris['asal'] == HutangPiutang::DARI_PEMBELIAN) {
                        $pembelian = Pembelian::model()->find("hutang_piutang_id={$baris['id']}");
                    }
                    ?>
                    <tr class="<?php echo $i % 2 === 0 ? '' : 'alt'; ?>">
                        <td class="rata-kanan"><?= $i; ?></td>
                        <td><?= date_format(date_create_from_format('Y-m-d H:i:s', $baris['created_at']), 'd-m-Y H:i:s'); ?></td>
                        <td><?= $listAsalHP[$baris['asal']] . ': ' . $baris['nomor_dokumen_asal'] . ' | R: ' . $pembelian->referensi; ?></td>
                        <td class="rata-kanan"><?= number_format($baris['jumlah'], 0, ',', '.'); ?></td>
                        <td class="rata-kanan"><?= number_format($baris['jumlah_bayar'], 0, ',', '.'); ?></td>
                        <td class="rata-kanan"><?= number_format($baris['jumlah'] - $baris['jumlah_bayar'], 0, ',', '.'); ?></td>
                    </tr>

                    <?php
                    $i++;
                endforeach;
                ?>                
Esempio n. 5
0
<?php

Login::restrictAdmin();
$objCabang = new Cabang();
$cabang = $objCabang->getData();
$objBank = new Bank();
$listBank = $objBank->getData();
$objForm = new Form();
$objValidation = new Validation($objForm);
//Penjualan
$objPenjualan = new Penjualan();
$tglPenjualan = $objPenjualan->getTanggalPenjualan();
//Pembelian
$objPembelian = new Pembelian();
$tglPembelian = $objPembelian->getTanggalPembelian();
//Laba Rugi
$labarugi = new LabaRugi();
//Cash Flow
$objCashFlow = new CashFlow();
$objCashFlow->getTanggal();
//Biaya Operasional
$objBiayaOperasional = new BiayaOperasional();
$objBiayaOperasional->getTanggal();
if (isset($_GET['detailinvoice'])) {
    $noinvoice = $_GET['detailinvoice'];
    $invoice = $objPenjualan->getPenjualanInvoice($noinvoice);
}
if ($objForm->isPost('dafcabang')) {
    $admin = new Admin();
    //if($objForm->getPost("dafcabang")!='cashflow'){
    //    $nmcabang = $objCabang->getNama($objForm->getPost("dafcabang"))?$objCabang->getNama($objForm->getPost("dafcabang")):"Semua Cabang";
Esempio n. 6
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}");
     }
 }
Esempio n. 7
0
 public function actionCariByRef($profilId, $nomorRef, $nominal)
 {
     $pembelian = Pembelian::model()->cariByRef($profilId, $nomorRef, $nominal);
     empty($pembelian) ? $this->renderJSON(['ada' => false]) : $this->renderJSON(['ada' => true, 'pembelian' => $this->renderPartial('_import_sudah_ada', ['pembelian' => $pembelian], true)]);
 }
Esempio n. 8
0
 public function simpanCsvKePembelian()
 {
     $csvFileName = $this->csvFile->name;
     $namaFile = explode('-', $csvFileName);
     $refNo = $namaFile[0];
     $refTgl = "{$namaFile[4]}-{$namaFile[3]}-{$namaFile[2]}";
     $profilId = $this->profilId;
     $transaction = Yii::app()->db->beginTransaction();
     $pembelian = new Pembelian();
     $pembelian->profil_id = $profilId;
     $pembelian->referensi = $refNo;
     $pembelian->tanggal_referensi = $refTgl;
     try {
         if ($pembelian->save()) {
             $fp = fopen($this->csvFile->tempName, 'r');
             if ($fp) {
                 $line = fgetcsv($fp, 1000, ",");
                 //  print_r($line); exit;
                 do {
                     if ($line[0] == 'barcode') {
                         continue;
                     }
                     /* field csv
                      * "barcode","idBarang","namaBarang","jumBarang","hargaBeli","hargaJual","RRP","SatuanBarang","KategoriBarang","Supplier","kasir"
                      *  0         1          2            3           4           5           6     7              8                9
                      */
                     $barangAda = Barang::model()->find('barcode=:barcode', array(':barcode' => $line[0]));
                     $barangId = null;
                     if (is_null($barangAda)) {
                         /* Jika belum ada barcode nya, maka buat barang baru */
                         /* Jika belum ada kategori dan satuan, buat baru */
                         $kategoriAda = KategoriBarang::model()->find('nama=:nama', array(':nama' => $line[8]));
                         if (is_null($kategoriAda)) {
                             $kategoriBaru = new KategoriBarang();
                             $kategoriBaru->nama = $line[8];
                             if (!$kategoriBaru->save()) {
                                 throw new Exception("Gagal simpan kategori baru", 500);
                             }
                             $kategoriId = $kategoriBaru->id;
                         } else {
                             $kategoriId = $kategoriAda->id;
                         }
                         $satuanAda = SatuanBarang::model()->find('nama=:nama', array(':nama' => $line[7]));
                         if (is_null($satuanAda)) {
                             $satuanBaru = new SatuanBarang();
                             $satuanBaru->nama = $line[7];
                             if (!$satuanBaru->save()) {
                                 throw new Exception("Gagal simpan satuan baru", 500);
                             }
                             $satuanId = $satuanBaru->id;
                         } else {
                             $satuanId = $satuanAda->id;
                         }
                         $barangBaru = new Barang();
                         $barangBaru->barcode = $line[0];
                         $barangBaru->nama = $line[2];
                         $barangBaru->kategori_id = $kategoriId;
                         $barangBaru->satuan_id = $satuanId;
                         if (!$barangBaru->save()) {
                             throw new Exception("Gagal simpan barang baru", 500);
                         }
                         $barangId = $barangBaru->id;
                         /* Jadikan supplier default ke profil ini */
                         $supplierBarang = new SupplierBarang();
                         $supplierBarang->barang_id = $barangId;
                         $supplierBarang->supplier_id = $profilId;
                         $supplierBarang->default = SupplierBarang::SUPPLIER_DEFAULT;
                         if (!$supplierBarang->save()) {
                             throw new Exception("Gagal simpan Supplier Barang", 500);
                         }
                     } else {
                         $barangId = $barangAda->id;
                     }
                     $detail = new PembelianDetail();
                     $detail->pembelian_id = $pembelian->id;
                     $detail->barang_id = $barangId;
                     $detail->qty = $line[3];
                     $detail->harga_beli = $line[5];
                     $detail->harga_jual = $line[6];
                     if (!$detail->save()) {
                         throw new Exception('Gagal simpan detail pembelian', 500);
                     }
                 } while (($line = fgetcsv($fp, 2000)) != FALSE);
             }
             $transaction->commit();
             return array('sukses' => true, 'pembelianId' => $pembelian->id);
         } else {
             throw new Exception("Gagal Simpan Pembelian");
         }
     } catch (Exception $ex) {
         $transaction->rollback();
         return array('sukses' => false, 'error' => array('msg' => $ex->getMessage(), 'code' => $ex->getCode()));
     }
 }