Example #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionTambah()
 {
     $model = new Penjualan();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $model->profil_id = Profil::PROFIL_UMUM;
     if ($model->save()) {
         $this->redirect(array('ubah', 'id' => $model->id));
     }
     $this->render('tambah', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Penjualan();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Penjualan'])) {
         $model->attributes = $_POST['Penjualan'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Penjualan();
     $user = Datauser::model()->findByAttributes(array('username' => Yii::app()->user->name));
     $iduser = $user->iddatauser;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Penjualan'])) {
         $model->attributes = $_POST['Penjualan'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->idpenjualan));
         }
     }
     $this->render('create', array('model' => $model, 'iduser' => $iduser));
 }
 /**
  * Store a newly created penjualan in storage.
  *
  * @return Response
  */
 public function store()
 {
     $penjualan = new Penjualan();
     $pj = Input::get('pj');
     $idd = Input::get('customer_id');
     // dd(Input::get('alamatt'));
     if (empty($idd)) {
         $customer = new Customer();
         $customer->nama = Input::get('nama');
         $customer->alamat = Input::get('alamat');
         $customer->telp = Input::get('telp');
         $customer->tipe = Input::get('tipee');
         $customer->save();
         $penjualan->customer_id = $customer->id;
         $penjualan->alamat = Input::get('alamat');
     } else {
         $penjualan->customer_id = Input::get('customer_id');
         $penjualan->alamat = Input::get('alamatt');
     }
     $penjualan->nama = Input::get('nama');
     $penjualan->telp = Input::get('telp');
     $penjualan->tgl_order = Input::get('tgl_order');
     $penjualan->tgl_transfer = Input::get('tgl_transfer');
     $penjualan->tgl_kirim = Input::get('tgl_kirim');
     $penjualan->tgl_estimasi = Input::get('tgl_estimasi');
     $penjualan->transfer_via = Input::get('transfer_via');
     $penjualan->ongkir = Input::get('ongkir');
     $penjualan->packing = Input::get('packing');
     $penjualan->resi = Input::get('resi');
     $penjualan->ekspedisi = Input::get('ekspedisi');
     $penjualan->ket = Input::get('ket');
     $penjualan->diskon = Input::get('diskon');
     $penjualan->status = 1;
     $total = 0;
     $chemical = 0;
     $perlengkapan = 0;
     $tChemical = [1, 2, 3, 4, 6, 7, 8];
     foreach ($pj as $key => $order) {
         if ($order['barang_id'] != '') {
             $total += $order['total'];
         }
     }
     $penjualan->nominal = $total;
     $simpanpen = $penjualan->save();
     if ($simpanpen) {
     } else {
         return Redirect::route('admin.penjualan.index')->with('message', 'ggl pen');
     }
     foreach ($pj as $key => $order) {
         if ($order['barang_id'] != '') {
             $det = new DetailPenjualan();
             $det->barang_id = $order['barang_id'];
             $det->harga = $order['harga'];
             $det->jumlah = $order['jumlah'];
             $det->total = $order['total'];
             $det->berat = $order['berat'];
             $det->keterangan = $order['keterangan'];
             $det->penjualan_id = $penjualan->id;
             if ($det->save()) {
             } else {
                 return Redirect::route('admin.penjualan.index')->with('message', 'ggl detail');
             }
         }
     }
     return Redirect::to('admin/penjualan/' . $penjualan->id)->with('message', 'Penjualan berhasil ditambahkan');
 }
Example #5
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');
 }