public function postDel(Request $req)
 {
     if ($req->ajax()) {
         ref_gudang::find($req->id)->update(['status' => 0]);
         return json_encode(['id' => $req->id]);
     }
 }
 public function getPrintexcel(Request $req)
 {
     $kd_barang = data_barang::where('id_barang', $req->barang)->select('kode')->first();
     $gudang = ref_gudang::find($req->gudang);
     \Excel::create('Kartu_Stok_' . str_replace('-', '_', str_slug($gudang->nm_gudang)) . '_' . $kd_barang->kode . '_' . date('d_F_Y'), function ($excel) use($req) {
         if ($req->barang == 0) {
             return redirect()->back()->withNotif(['label' => 'danger', 'err' => 'Item tidak ditemukan!']);
         }
         $items = [];
         // Data Barang
         $barang = data_item_gudang::join('data_barang', 'data_barang.id_barang', '=', 'data_item_gudang.id_barang')->join('ref_satuan', 'ref_satuan.id_satuan', '=', 'data_barang.id_satuan')->where('data_item_gudang.status', 1)->where('data_item_gudang.id_gudang', $req->gudang)->where('data_item_gudang.id_barang', $req->barang)->where('data_barang.tipe', $req->tipe)->select('data_barang.nm_barang', 'data_barang.kode', 'data_item_gudang.in', 'data_item_gudang.out', 'ref_satuan.nm_satuan')->first();
         if ($barang == null) {
             return redirect()->back()->withNotif(['label' => 'danger', 'err' => 'Item tidak ditemukan!']);
         }
         //Sisa per priode
         $sisapriode = data_log_barang::sisapriode($req->all())->get();
         //dd($sisapriode);
         $sisa = 0;
         foreach ($sisapriode as $sp) {
             if ($sp->kondisi == 1) {
                 $sisa += $sp->qty;
             } else {
                 $sisa -= $sp->qty;
             }
         }
         $lastsisa = $sisa;
         // Log stok
         $logs = data_log_barang::kartostokbyitem($req->all())->get();
         foreach ($logs as $item) {
             if ($item->tipe == 1) {
                 $parent = data_skb::find($item->id_parent);
             } else {
                 if ($item->tipe == 2) {
                     //$parent = data_spbm::find($item->id_parent);
                     $parent = data_spbm::join('data_spbm_item', 'data_spbm_item.id_spbm', '=', 'data_spbm.id_spbm')->where('data_spbm_item.id_barang', $req->barang)->where('data_spbm.id_spbm', $item->id_parent)->select('data_spbm.*', 'data_spbm_item.tgl_exp')->first();
                 } else {
                     if ($item->tipe == 3) {
                         $parent = data_penyesuaian_stok::find($item->id_parent);
                     } else {
                         if ($item->tipe == 4) {
                             $parent = data_retur::find($item->id_parent);
                         } else {
                             if ($item->tipe == 5) {
                                 $parent = data_retur::find($item->id_parent);
                             }
                         }
                     }
                 }
             }
             if ($item->kondisi == 1) {
                 $lastsisa += $item->qty;
             } else {
                 $lastsisa -= $item->qty;
             }
             $items[] = ['tipe' => $item->tipe, 'parent' => $parent, 'kondisi' => $item->kondisi, 'qty' => $item->qty, 'sisa' => $lastsisa, 'oleh' => $item->nm_depan . ' ' . $item->nm_belakang];
         }
         $jenis = [1 => 'SKB', 2 => 'Good Receive', 3 => 'Penyesuaian', 4 => 'Retur Gudang', 5 => 'Retur Pembelian'];
         // Parameters
         $params = '';
         foreach ($req->all() as $par => $val) {
             if ($par != '_token') {
                 $params .= $par . '=' . $val . '&';
             }
         }
         $param = rtrim($params, '&');
         $gudang = ref_gudang::find($req->gudang);
         $data = ['barang' => $barang, 'items' => $items, 'req' => $req, 'jenis' => $jenis, 'param' => $params, 'gudang' => $gudang];
         $excel->sheet('New sheet', function ($sheet) use($data) {
             $sheet->loadView('Print.Pengadaan.SubGudang.Excel', $data);
         });
     })->export('xlsx');
 }
 public function getCreate(Request $req, $tipe)
 {
     $akses = \Me::accessGudang();
     if (empty($tipe) || $tipe > 2 || !is_numeric($tipe)) {
         return redirect('/prq')->withNotif(['label' => 'danger', 'err' => 'Kesalahan, Silahkan buat pengajuan baru!']);
     }
     if (!in_array($tipe, $akses)) {
         return redirect('/prq')->withNotif(['label' => 'danger', 'err' => 'Maaf Bukan domain Anda!']);
     }
     if (count($this->ids) < 1) {
         return redirect('/prq/select')->withNotif(['label' => 'warning', 'err' => 'Maaf, Anda belum menentukan item Barang yang akan diproses.<br /> Silahkan pilih beberapa item di bawah ini']);
     }
     $items = data_barang::join('ref_satuan', 'ref_satuan.id_satuan', '=', 'data_barang.id_satuan')->whereIn('id_barang', $this->ids)->where('data_barang.tipe', $tipe)->select('data_barang.*', 'ref_satuan.nm_satuan')->get();
     if (count($items) == 0) {
         return redirect('/prq')->withNotif(['label' => 'danger', 'err' => 'Kesalahan, Silahkan buat pengajuan baru!']);
     }
     $gudangs = ref_gudang::all();
     $ids = [];
     foreach ($items as $id) {
         $ids[] = $id->id_barang;
     }
     $ids = json_encode($ids);
     return view('Pengadaan.PRQ.CreatePRQ', ['items' => $items, 'gudangs' => $gudangs, 'ids' => $ids, 'tipe' => $tipe]);
 }
 public function getEditspb($id)
 {
     $find = data_spb::join('data_karyawan', 'data_karyawan.id_karyawan', '=', 'data_spb.id_pemohon')->join('data_departemen', 'data_departemen.id_departemen', '=', 'data_spb.id_departemen')->where('data_spb.id_spb', $id)->where('data_spb.id_departemen', \Me::data()->id_departemen)->where('data_spb.status', 1)->select('data_spb.*', 'data_karyawan.nm_depan', 'data_karyawan.nm_belakang', 'data_departemen.nm_departemen');
     if ($find->count() == 0) {
         return redirect('/pmbumum');
     }
     $spb = $find->first();
     $items = data_spb_item::join('data_barang', 'data_barang.id_barang', '=', 'data_spb_item.id_item')->join('ref_satuan', 'ref_satuan.id_satuan', '=', 'data_spb_item.id_satuan')->where('data_spb_item.id_spb', $id)->where('data_spb_item.status', 1)->orderby('data_barang.nm_barang', 'asc')->select('data_spb_item.*', 'data_barang.id_barang', 'data_barang.in', 'data_barang.out', 'data_barang.nm_barang', 'data_barang.id_satuan AS satuan_default', 'data_barang.kode', 'ref_satuan.nm_satuan')->get();
     $obat = [];
     $id_gudang = '';
     foreach ($items as $item) {
         if ($item->tipe == 1) {
             $obat[] = $item->id_barang;
         }
         $id_gudang = $item->id_gudang;
     }
     $ids = [];
     $sels = [];
     foreach ($items as $id) {
         $ids[] = $id->id_barang;
         $sels[$id->id_barang] = $id->id_satuan;
     }
     $param['ids'] = $ids;
     $param['tipe'] = $spb->tipe;
     $param['sels'] = $sels;
     $param = json_encode($param);
     return view('Pengadaan.SPB.EditSPB', ['spb' => $spb, 'items' => $items, 'obat' => $obat, 'id_gudang' => $id_gudang, 'gudangs' => $gudangs = ref_gudang::all(), 'satuan' => ref_satuan::all(), 'param' => $param, 'tipe' => $spb->tipe]);
 }
 public function getLpb()
 {
     $items = ref_gudang::listgudang()->get();
     return view('Laporan.Logistik.Lpb', ['items' => $items]);
 }
 public function getPrintadj($id)
 {
     if (empty($id) || !is_numeric($id)) {
         return redirect('/stockadj');
     }
     $adj = data_penyesuaian_stok::byid($id)->first();
     if ($adj == null) {
         return redirect('/stockadj');
     }
     if ($adj->id_gudang == 0) {
         return redirect('/stockadj');
     }
     $gudang = ref_gudang::find($adj->id_gudang);
     $items = data_penyesuaian_stok_item::byhead($id)->get();
     return view('Print.Pengadaan.ADJ', ['adj' => $adj, 'items' => $items, 'gudang' => $gudang]);
 }