Example #1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     try {
         \DB::begintransaction();
         $id_karyawan = \Me::data()->id_karyawan;
         $barang = data_barang::find($this->req['id']);
         $barang->update(['nm_barang' => $this->req['nm_barang'], 'id_kategori' => $this->req['id_kategori'], 'id_satuan' => $this->req['id_satuan'], 'stok_minimal' => $this->req['stok_minimal'], 'keterangan' => $this->req['keterangan'], 'tipe' => $this->req['tipe'], 'ppn' => $this->req['ppn'], 'harga_beli' => $this->req['harga_beli'], 'harga_jual' => $this->req['harga_jual'], 'id_klasifikasi' => $this->req['id_klasifikasi']]);
         data_barang_detail::where('id_barang', $this->req['id'])->delete();
         if (isset($this->req['labels']) && count($this->req['labels']) > 0) {
             foreach ($this->req['labels'] as $i => $val) {
                 if (strlen($val) > 0 && strlen($this->req['values'][$i]) > 0) {
                     data_barang_detail::create(['id_barang' => $this->req['id'], 'label' => ucwords($val), 'nm_detail' => $this->req['values'][$i]]);
                 }
             }
         }
         ref_konversi_satuan::where('id_barang', $this->req['id'])->delete();
         ref_konversi_satuan::create(['id_barang' => $barang->id_barang, 'id_satuan_max' => $this->req['id_satuan'], 'id_satuan_min' => $this->req['id_satuan'], 'qty' => 1]);
         if (isset($this->req['koversi_satuan']) && count($this->req['koversi_satuan']) > 0) {
             foreach ($this->req['koversi_satuan'] as $i => $id_satuan) {
                 if ($id_satuan > 0) {
                     ref_konversi_satuan::create(['id_barang' => $barang->id_barang, 'id_satuan_max' => $id_satuan, 'id_satuan_min' => $this->req['id_satuan'], 'qty' => $this->req['koversi_qty'][$i]]);
                 }
             }
         }
         if ($this->req['harga_beli'] != $this->req['last_harga']) {
             data_harga::create(['id_barang' => $barang->id_barang, 'harga' => $this->req['harga_beli'], 'keterangan' => 'Update harga dari ' . number_format($this->req['last_harga'], 0, ',', '.'), 'id_karyawan' => $id_karyawan, 'tipe' => 1]);
         }
         if ($this->req['harga_jual'] != $this->req['last_harga_jual']) {
             data_harga::create(['id_barang' => $barang->id_barang, 'harga' => $this->req['harga_jual'], 'keterangan' => 'Update harga dari ' . number_format($this->req['last_harga_jual'], 0, ',', '.'), 'id_karyawan' => $id_karyawan, 'tipe' => 2]);
         }
         // Pengkodean
         $tipe = $this->req['tipe'] == 1 ? 'O-' : 'B-';
         $kat = ref_kategori::find($this->req['id_kategori']);
         $kats = $kat->alias . '-';
         $urut = \Format::code($barang->id_barang);
         $jj = '';
         if ($this->req['tipe'] == 1) {
             $kls = ref_klasifikasi::find($this->req['id_klasifikasi']);
             $jj = '-' . $kls->kode;
         }
         $kode = $tipe . $kats . $urut . $jj;
         $barang->kode = $kode;
         $barang->save();
         \Loguser::create('Melakukan perubahan terhada data master gudang Kode. ' . $barang->kode);
         \DB::commit();
         return ['label' => 'success', 'err' => $this->req['nm_barang'] . ' Berhasil diperbaharui'];
     } catch (\Exception $e) {
         \DB::rollback();
         return ['label' => 'danger', 'err' => $e->getMessage()];
     }
 }
 public function getAllitems(Request $req)
 {
     if ($req->ajax()) {
         $res = [];
         $items = ref_klasifikasi::where('kode', $req->src)->orWhere('nm_klasifikasi', $req->src)->paginate(10);
         $out = '';
         if ($items->total() > 0) {
             $no = $items->currentPage() == 1 ? 1 : $items->perPage() * $items->currentPage() - $items->perPage() + 1;
             foreach ($items as $item) {
                 $out .= '
         <tr class="item_' . $item->id . ' items">
           <td>' . $no . '</td>
           <td>' . $item->kode . '</td>
           <td>
             <a href="javascript:;" title="' . $item->id_klasifikasi . '" data-toggle="tooltip" data-placement="bottom">' . $item->nm_klasifikasi . '</a>
           </td>           
           <td>
             <div>
               ' . \Format::indoDate($item->created_at) . '
             </div>
             <small class="text-muted">' . \Format::hari($item->created_at) . ', ' . \Format::jam($item->created_at) . '</small>
           </td>
         </tr>
       ';
                 $no++;
             }
         } else {
             $out = '
       <tr>
         <td colspan="4">Tidak ditemukan</td>
       </tr>
     ';
         }
         $res['data'] = $out;
         $res['pagin'] = $items->render();
         return json_encode($res);
     }
 }
 /**
  * Edit barang
  * @access Admin Logistik
  * @author @hexters
  */
 public function getUpdate($id)
 {
     $item = data_barang::find($id);
     if ($item == null) {
         return redirect('/logistik')->withNotif(['label' => 'danger', 'err' => 'Maaf, Tidak ditemukan !']);
     }
     if (!in_array($item->tipe, \Me::accessGudang())) {
         return redirect('/logistik')->withNotif(['label' => 'danger', 'err' => 'Maaf Bukan domain anda!']);
     }
     $user = data_karyawan::find($item->id_karyawan);
     $details = data_barang_detail::where('id_barang', $item->id_barang)->get();
     $konversi = ref_konversi_satuan::where('ref_konversi_satuan.id_barang', $id)->whereNotIn('ref_konversi_satuan.id_satuan_max', [$item->id_satuan])->get();
     return view('Pengadaan.Update', ['kategoris' => ref_kategori::all(), 'satuan' => ref_satuan::all(), 'item' => $item, 'oleh' => $user->nm_depan . ' ' . $user->nm_belakang, 'details' => $details, 'klasifikasi' => ref_klasifikasi::all(), 'konversi' => $konversi]);
 }
 public function getLaporanstok()
 {
     $klasifikasis = ref_klasifikasi::all();
     $kategoris = ref_kategori::all();
     return view('Laporan.Logistik.LaporanStok', ['klasifikasis' => $klasifikasis, 'kategoris' => $kategoris]);
 }