예제 #1
0
 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);
 }
예제 #2
0
 /**
  * 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'];
     *
     */
 }
예제 #3
0
 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()));
     }
 }
예제 #4
0
 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');
 }
예제 #5
0
 /**
  * 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);
     }
 }
예제 #6
0
 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);
 }