/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'ubah' page. */ public function actionTambah() { $this->layout = '//layouts/box_kecil'; $model = new ReturPembelian(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['ReturPembelian'])) { $model->attributes = $_POST['ReturPembelian']; if ($model->save()) { $this->redirect(array('ubah', 'id' => $model->id)); } } $supplierList = Profil::model()->findAll(array('select' => 'id, nama', 'condition' => 'id>' . Profil::AWAL_ID . ' and tipe_id=' . Profil::TIPE_SUPPLIER, 'order' => 'nama')); $this->render('tambah', array('model' => $model, 'supplierList' => $supplierList)); }
/** * Retur Current Nota * @param int $id Pembelian ID */ public function retur() { $transaction = $this->dbConnection->beginTransaction(); try { $returBeli = new ReturPembelian(); $returBeli->profil_id = $this->profil_id; if (!$returBeli->save()) { throw new Exception("Gagal simpan Retur Pembelian"); } /* Insert semua yang ada di pembelian_detail ke retur_pembelian_detail */ $sql = "\n INSERT INTO retur_pembelian_detail \n (retur_pembelian_id, inventory_balance_id, qty, updated_by, created_at)\n SELECT \n :returPembelianId, ib.id, detail.qty, :user, now()\n FROM\n pembelian_detail detail\n JOIN\n inventory_balance ib ON detail.id = ib.pembelian_detail_id\n WHERE\n pembelian_id = :pembelianId \n "; $command = Yii::app()->db->createCommand($sql); $command->bindValues([':returPembelianId' => $returBeli->id, ':pembelianId' => $this->id, ':user' => Yii::app()->user->id]); $rows = $command->execute(); $transaction->commit(); return ['sukses' => true, 'data' => ['returPembelianId' => $returBeli->id, 'rows' => $rows]]; } catch (Exception $ex) { $transaction->rollback(); return ['sukses' => false, 'error' => ['msg' => $ex->getMessage(), 'code' => $ex->getCode()]]; } }