public function getInfoScan() { $criteria = new CDbCriteria(); $criteria->alias = 'detail'; $criteria->join = 'JOIN penjualan pj on detail.penjualan_id = pj.id and pj.status=' . Penjualan::STATUS_DRAFT; $criteria->order = 'detail.id desc'; $criteria->condition = 'detail.updated_by =' . Yii::app()->user->id; return PenjualanDetail::model()->find($criteria); }
/** * Total Retur Penjualan * @return int total dalam bentuk raw (belum terformat) */ public function ambilTotal() { $detail = Yii::app()->db->createCommand()->select('sum(pd.harga_jual * rpd.qty) total')->from(ReturPenjualanDetail::model()->tableName() . ' as rpd')->join(PenjualanDetail::model()->tableName() . ' as pd', 'rpd.penjualan_detail_id=pd.id')->where('retur_penjualan_id=:returPenjualanId', array(':returPenjualanId' => $this->id))->queryRow(); return $detail['total']; /* $pembelian = Yii::app()->db->createCommand("select sum(rpd.qty * pd.harga_jual) total from retur_penjualan_detail rpd join penjualan_detail pd on pd.id = rpd.penjualan_detail_id where retur_penjualan_id = :penjualanId") ->bindValue(':penjualanId', $this->id) ->queryRow(); return $pembelian['total']; * */ }
public function gantiCustomer($customer) { $transaction = $this->dbConnection->beginTransaction(); try { if (!$this->saveAttributes(array('profil_id' => $customer->id))) { throw new Exception('Gagal ubah customer', 500); } $alamat1 = !empty($customer->alamat1) ? $customer->alamat1 : ''; $alamat2 = !empty($customer->alamat2) ? '<br>' . $customer->alamat2 : ''; $alamat3 = !empty($customer->alamat3) ? '<br>' . $customer->alamat3 : ''; /* Ambil data detail */ $penjualanDetails = PenjualanDetail::model()->findAll('penjualan_id=:penjualanId', array('penjualanId' => $this->id)); /* Hapus dan re-insert */ $tabelPenjualanDiskon = PenjualanDiskon::model()->tableName(); $tabelPenjualanDetail = PenjualanDetail::model()->tableName(); Yii::app()->db->createCommand("\n DELETE {$tabelPenjualanDiskon}\n FROM {$tabelPenjualanDiskon}\n INNER JOIN {$tabelPenjualanDetail} ON {$tabelPenjualanDiskon}.penjualan_detail_id = {$tabelPenjualanDetail}.id\n WHERE {$tabelPenjualanDetail}.penjualan_id=:penjualanId\n ")->bindValues(array(':penjualanId' => $this->id))->execute(); PenjualanDetail::model()->deleteAll('penjualan_id=:penjualanId', array('penjualanId' => $this->id)); foreach ($penjualanDetails as $detail) { $barang = Barang::model()->findByPk($detail->barang_id); $this->tambahBarangProc($barang, $detail->qty); } $transaction->commit(); return array('sukses' => true, 'nama' => $customer->nama, 'nomor' => $customer->nomor, 'address' => $alamat1 . $alamat2 . $alamat3); } catch (Exception $ex) { $transaction->rollback(); return array('sukses' => false, 'error' => array('msg' => $ex->getMessage(), 'code' => $ex->getCode())); } }
/** * Render Faktur/Invoice dalam format PDF * @param int $id penjualan ID */ public function exportPdf($id, $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 Customer */ $customer = Profil::model()->findByPk($modelHeader->profil_id); /* * Penjualan Detail */ $penjualanDetail = PenjualanDetail::model()->with('barang')->findAll(array('condition' => "penjualan_id={$id}", 'order' => 'barang.nama')); /* * Persiapan render PDF */ $mPDF1 = Yii::app()->ePdf->mpdf('', 'A4'); $viewInvoice = '_invoice'; if ($draft) { $viewInvoice = '_invoice_draft'; } $mPDF1->WriteHTML($this->renderPartial($viewInvoice, array('modelHeader' => $modelHeader, 'branchConfig' => $branchConfig, 'customer' => $customer, 'penjualanDetail' => $penjualanDetail), true)); $mPDF1->SetDisplayMode('fullpage'); $mPDF1->pagenumSuffix = ' dari '; $mPDF1->pagenumPrefix = 'Halaman '; // Render PDF $mPDF1->Output("{$modelHeader->nomor}.pdf", 'I'); }
/** * Menyimpan semua detail yang ada di penjualan yang akan dihapus * @param int $penjualanId ID Penjualan */ public function simpanHapus($penjualanId) { $details = PenjualanDetail::model()->findAll('penjualan_id = :penjualanId', [':penjualanId' => $penjualanId]); foreach ($details as $detail) { $this->simpanHapusDetail($detail, PenjualanDetailHapus::JENIS_PER_NOTA); } }
public function actionTambahDetail($id) { $return = array('sukses' => false); if (isset($_POST['penjualanDetailId'])) { $penjualanDetailId = $_POST['penjualanDetailId']; $qty = $_POST['qty']; $penjualanDetail = PenjualanDetail::model()->findByPk($penjualanDetailId); $returPenjualanDetail = new ReturPenjualanDetail(); $returPenjualanDetail->retur_penjualan_id = $id; $returPenjualanDetail->penjualan_detail_id = $penjualanDetailId; $returPenjualanDetail->qty = $qty; $returPenjualanDetail->harga_jual = $penjualanDetail->harga_jual; if ($returPenjualanDetail->save()) { $return = array('sukses' => true); } } $this->renderJSON($return); }