/** * 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())); } }
/** * Remove the specified customer from storage. * * @param int $id * @return Response */ public function destroy($id) { if ($pj = Penjualan::where('customer_id', '=', $id)->first()) { $pjid = $pj->id; DetailPenjualan::where('penjualan_id', '=', $pjid)->delete(); } Penjualan::where('customer_id', '=', $id)->delete(); Customer::destroy($id); return Redirect::to('admin/customer/tipe/1')->with('message', 'berhasil menghapus customer'); }
/** * 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; }
/** * 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); } } }
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 getInfoStruk() { return Penjualan::model()->find(['order' => 'id desc', 'condition' => 'status=' . Penjualan::STATUS_LUNAS . ' and TIMESTAMPDIFF(SECOND, tanggal, NOW()) <= 15']); }
<?php Login::restrictAdmin(); $objPenjualan = new Penjualan(); $id = Helper::encodeHTML($_GET['detailinvoice']); $header = $objPenjualan->getInvoice($id); $noinvoice = $header['noinvoice']; $tgl = Helper::dateFromMySqlSystem($header['tgl']); $sales = $header['sales']; $invoice = $objPenjualan->getPenjualanInvoice($noinvoice); ?> <html> <head> <title>XBook Control Panel</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="../css/bootstrap.min.css"> <link rel="stylesheet" href="../css/bootstrap-theme.min.css"> <link href="css/Core.css" rel="stylesheet" type="text/css" /> <link href="css/Menu.css" rel="stylesheet" type="text/css" /> <script src="../js/jquery.min.js"></script> <script src="../js/bootstrap.min.js"></script> <script src="../js/bootstrap-datepicker.js"></script> </head> <body> <div class="table-responsive">
<div class="tab-content"> <div class="active tab-pane" id="activity"> <table class="table table-striped"> <thead> <tr> <th>ID</th> <th>Tanggal Order</th> <th>Nominal</th> <th>Actions</th> </tr> </thead> <tbody> @foreach($penjualan as $pj) <?php $detail = Penjualan::find($pj->id)->DetailPenjualan; ?> <tr> <td>{{ link_to_route('admin.penjualan.show', $pj->id, $pj->id) }}</td> <td>{{ date('d F, Y', strtotime($pj->tgl_order)) }}</td> <td>{{ $pj->nominal }}</td> <td> {{ Form::open(array('route' => array('admin.penjualan.destroy', $pj->id), 'method' => 'delete','class'=>'delete')) }} {{Form::button('<i class="fa fa-trash-o"></i>', array('type' => 'submit', 'class' => 'btn btn-danger'))}} {{ Form::close() }} </td> </tr> @endforeach </tbody> </table>
<?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";
public function deleteDetail() { if (isset($_POST)) { $id = $_POST['id']; $det = DetailPenjualan::findOrFail($id); $penjualan = Penjualan::where('id', '=', $det->penjualan_id)->first(); // dd($penjualan->id); if (DetailPenjualan::destroy($id)) { $barangs = DetailPenjualan::where('penjualan_id', '=', $penjualan->id)->get(); $nominal = 0; foreach ($barangs as $key => $value) { $nominal += $value->total; } $penjualan->nominal = $nominal; $penjualan->save(); } } }
public function printChart() { $penjualans = Penjualan::orderBy('tgl_transfer', 'DESC')->take(7)->get(); $barangs = Barang::orderBy('id', 'DESC')->take(4)->get(); $customers = Penjualan::with('customer')->orderBy('tgl_transfer', 'DESC')->take(8)->get(); $baru = Penjualan::where('status', 1)->count(); $orders = Order::where('status', 1)->count(); $poBaru = Penjualan::where('tgl_transfer', '>=', '2015-11-01')->count(); $okt = Penjualan::whereBetween('tgl_transfer', ['2015-10-01', '2015-10-31'])->get(); $sep = Penjualan::whereBetween('tgl_transfer', ['2015-09-01', '2015-09-30'])->get(); $okts['dates'] = $okt->lists('tgl_transfer'); $okts['totals'] = $okt->lists('nominal'); $seps['dates'] = $sep->lists('tgl_transfer'); $seps['totals'] = $sep->lists('nominal'); $sumO = 0; foreach ($okts['totals'] as $t) { $sumO += $t; } $sumS = 0; foreach ($seps['totals'] as $t) { $sumS += $t; } $mar = Penjualan::whereBetween('tgl_transfer', ['2015-03-19', '2015-03-31'])->lists('nominal'); $apr = Penjualan::whereBetween('tgl_transfer', ['2015-04-01', '2015-04-31'])->lists('nominal'); $may = Penjualan::whereBetween('tgl_transfer', ['2015-05-01', '2015-05-31'])->lists('nominal'); $jun = Penjualan::whereBetween('tgl_transfer', ['2015-06-01', '2015-06-31'])->lists('nominal'); $jul = Penjualan::whereBetween('tgl_transfer', ['2015-07-01', '2015-07-31'])->lists('nominal'); $aug = Penjualan::whereBetween('tgl_transfer', ['2015-08-01', '2015-08-31'])->lists('nominal'); $nov = Penjualan::where('tgl_transfer', '>=', Carbon::now()->startOfMonth())->lists('nominal'); $lap['maret'] = 0; $lap['april'] = 0; $lap['mei'] = 0; $lap['juni'] = 0; $lap['juli'] = 0; $lap['agustus'] = 0; $lap['sept'] = $sumS; $lap['okt'] = $sumO; $lap['nov'] = 0; foreach ($mar as $m) { $lap['maret'] += $m; } foreach ($apr as $m) { $lap['april'] += $m; } foreach ($may as $m) { $lap['mei'] += $m; } foreach ($jun as $m) { $lap['juni'] += $m; } foreach ($jul as $m) { $lap['juli'] += $m; } foreach ($aug as $m) { $lap['agustus'] += $m; } foreach ($nov as $m) { $lap['nov'] += $m; } return View::make('admin/charts.linePoChart', compact('penjualans', 'barangs', 'customers', 'baru', 'poBaru', 'okts', 'seps', 'sumO', 'sumS', 'orders', 'lap')); }
public function actionImport() { if (isset($_POST['nomor'])) { $dbAhadPos2 = $_POST['database']; $nomor = $_POST['nomor']; $penjualanPos2 = Yii::app()->db->createCommand("\n SELECT t.tglTransaksiJual, c.namaCustomer\n FROM {$dbAhadPos2}.transaksijual t\n JOIN {$dbAhadPos2}.customer c on t.idCustomer=c.idCustomer\n WHERE idTransaksiJual = :nomor")->bindValue(':nomor', $nomor)->queryRow(); $profil = Profil::model()->find('nama=:nama', array('nama' => trim($penjualanPos2['namaCustomer']))); if (!is_null($profil)) { $penjualan = new Penjualan(); $penjualan->profil_id = $profil->id; if ($penjualan->save()) { $penjualanDetailPos2 = Yii::app()->db->createCommand("\n select d.barcode, d.jumBarang, d.hargaBeli, d.hargaJual, d.RRP, barang.id\n from {$dbAhadPos2}.detail_jual d\n join barang on d.barcode=barang.barcode\n where d.nomorStruk = :nomor\n ")->bindValue(':nomor', $nomor)->queryAll(); foreach ($penjualanDetailPos2 as $detailPos2) { $barangId = $detailPos2['id']; $detail = new PenjualanDetail(); $detail->barang_id = $barangId; $detail->penjualan_id = $penjualan->id; $detail->qty = $detailPos2['jumBarang']; $detail->harga_jual = $detailPos2['hargaJual']; $detail->harga_jual_rekomendasi = $detailPos2['RRP']; $detail->save(); } $this->redirect('index'); } } } $this->render('import'); }
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); }