/** * Insert Penjualan Detail * @param int $barangId * @param int $qty * @param decimal $hargaJual * @param decimal $diskon * @param int $tipeDiskonId * @throws Exception */ public function insertBarang($barangId, $qty, $hargaJual, $diskon = 0, $tipeDiskonId = null) { $detail = new PenjualanDetail(); $detail->penjualan_id = $this->id; $detail->barang_id = $barangId; $detail->qty = $qty; $detail->harga_jual = $hargaJual; $detail->harga_jual_rekomendasi = HargaJualRekomendasi::model()->terkini($barangId); if ($diskon > 0) { $detail->diskon = $diskon; } if (!$detail->save()) { throw new Exception("Gagal simpan penjualan detail: penjualanId:{$this->id}, barangId:{$barangId}, qty:{$qty}", 500); } if ($diskon > 0) { $this->insertDiskon($detail, $tipeDiskonId); } }
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'); }