Example #1
0
 public function ambilDataPoinMember()
 {
     $periode = MemberPeriodePoin::model()->findByPk($this->periodeId);
     $command = Yii::app()->db->createCommand()->select('profil_id, p.nomor, p.nama, sum(poin) poin, p.alamat1, p.alamat2, p.alamat3, p.telp, p.hp, p.surel, p.identitas, p.tanggal_lahir')->from(PenjualanMember::model()->tableName() . ' t')->join(Profil::model()->tableName() . ' p', 't.profil_id = p.id')->where('year(t.updated_at)=:tahun and month(t.updated_at) between :awal and :akhir')->group('profil_id');
     if ($this->sortBy == self::SORT_BY_POIN_ASC) {
         $command->order('sum(poin), p.nama');
     } elseif ($this->sortBy == self::SORT_BY_POIN_DSC) {
         $command->order('sum(poin) desc, p.nama');
     }
     $command->bindValues([':tahun' => $this->tahun, ':awal' => $periode->awal, ':akhir' => $periode->akhir]);
     return $command->queryAll();
 }
 public function actionPilihProfil($id)
 {
     $profil = Profil::model()->findByPk($id);
     $return = array('id' => $id, 'nama' => $profil->nama, 'alamat1' => $profil->alamat1);
     $this->renderJSON($return);
 }
Example #3
0
 public function getNamaProfil()
 {
     $profil = Profil::model()->findByPk($this->profilId);
     return $profil->nama;
 }
Example #4
0
 public function _listBukanSupplier($id)
 {
     return Profil::model()->listSupplierYangBukan($id);
 }
Example #5
0
 /**
  * Ambil total poin yang sudah didapat
  * @return int total Poin Periode Berjalan
  */
 public function getTotalPoinPeriodeBerjalan()
 {
     $profil = Profil::model()->findByPk($this->profil_id);
     if ($profil->isMember()) {
         $periodePoin = MemberPeriodePoin::model()->find('awal<=month(now()) and month(now())<=akhir');
         $poin = false;
         if (!is_null($periodePoin)) {
             $poin = Yii::app()->db->createCommand()->select('sum(poin) total')->from(PenjualanMember::model()->tableName() . ' tpm')->where('YEAR(updated_at) = YEAR(NOW()) AND MONTH(updated_at) BETWEEN :awal AND :akhir
                             AND profil_id=:profilId')->bindValues(array(':awal' => $periodePoin->awal, ':akhir' => $periodePoin->akhir, ':profilId' => $profil->id))->queryRow();
         } else {
             /* Berarti periode lintas tahun (awal > akhir ) */
             $periodePoinL = MemberPeriodePoin::model()->find('awal <= month(now()) OR month(now()) <= akhir AND awal > akhir');
             if (!is_null($periodePoinL)) {
                 $queryPoin = Yii::app()->db->createCommand()->select('sum(poin) total')->from(PenjualanMember::model()->tableName() . ' tpm')->where('profil_id=:profilId');
                 $curMonth = date('n');
                 if ($curMonth >= $periodePoinL->akhir) {
                     $queryPoin->andWhere('YEAR(updated_at) = YEAR(NOW()) AND MONTH(updated_at) BETWEEN :awal AND :akhir');
                     $queryPoin->bindValues([]);
                 }
                 $queryPoin->bindValues(array(':awal' => $periodePoinL->awal, ':akhir' => $periodePoinL->akhir, ':profilId' => $profil->id));
                 $poin = $queryPoin->queryRow();
             }
         }
         return $poin ? $poin['total'] : 0;
     } else {
         return 0;
     }
 }
 public function exportPdf($id, $kertas = ReturPembelian::KERTAS_A4, $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 Supplier
      */
     $profil = Profil::model()->findByPk($modelHeader->profil_id);
     /*
      * Retur Pembelian Detail
      */
     $returPembelianDetail = ReturPembelianDetail::model()->with('inventoryBalance', 'inventoryBalance.barang')->findAll(array('condition' => "retur_pembelian_id={$id}", 'order' => 'barang.nama'));
     /*
      * Persiapan render PDF
      */
     $listNamaKertas = ReturPembelian::listNamaKertas();
     $mPDF1 = Yii::app()->ePdf->mpdf('', $listNamaKertas[$kertas]);
     $viewCetak = '_pdf';
     if ($draft) {
         $viewCetak = '_pdf_draft';
     }
     $mPDF1->WriteHTML($this->renderPartial($viewCetak, array('modelHeader' => $modelHeader, 'branchConfig' => $branchConfig, 'profil' => $profil, 'returPembelianDetail' => $returPembelianDetail), true));
     $mPDF1->SetDisplayMode('fullpage');
     $mPDF1->pagenumSuffix = ' dari ';
     $mPDF1->pagenumPrefix = 'Halaman ';
     // Render PDF
     $mPDF1->Output("{$modelHeader->nomor}.pdf", 'I');
 }
Example #7
0
 public function hutangPiutangCsv($profilId, $showDetail, $pilihCetak)
 {
     $model = new ReportHutangPiutangForm();
     $csv = null;
     if (isset($profilId)) {
         $model->profilId = $profilId;
         $model->showDetail = $showDetail;
         $model->pilihCetak = $pilihCetak;
         $csv = $model->reportHutangPiutangCsv();
     } else {
         throw new Exception("Tidak ada data", 500);
     }
     $profil = Profil::model()->findByPk($profilId);
     $namaToko = Config::model()->find("nama = 'toko.nama'");
     $timeStamp = date("Y-m-d-H-i");
     $namaFile = "HP {$namaToko->nilai} {$profil->nama} {$timeStamp}";
     $this->renderPartial('_csv', array('namaFile' => $namaFile, 'csv' => $csv));
 }
Example #8
0
 /**
  * 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 Profil the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Profil::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #9
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');
 }
Example #10
0
 /**
  * Ganti Customer
  * @param int $id ID Penjualan
  * @return JSON boolean sukses, array error[code, msg]
  */
 public function actionGantiCustomer($id)
 {
     $return = array('sukses' => false, 'error' => array('code' => '500', 'msg' => 'Sempurnakan input!'));
     if (isset($_POST['nomor'])) {
         if (trim($_POST['nomor']) == '') {
             /* Jika tidak diinput nomornya, maka set ke customer Umum */
             $customer = Profil::model()->findByPk(Profil::PROFIL_UMUM);
         } else {
             $customer = Profil::model()->find('nomor=:nomor', array(':nomor' => $_POST['nomor']));
         }
         if (!is_null($customer)) {
             $penjualan = $this->loadModel($id);
             /* Simpan profil ID ke penjualan
              * dan sesuaikan diskon
              */
             $return = $penjualan->gantiCustomer($customer);
         } else {
             $return = array('sukses' => false, 'error' => array('code' => '500', 'msg' => 'Data Customer tidak ditemukan'));
         }
     }
     $this->renderJSON($return);
 }