コード例 #1
0
 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');
 }
コード例 #2
0
 public function getPrintpdf(Request $req)
 {
     $day = \Format::selisih_hari($req->dari, $req->sampai);
     if ($day > 31) {
         return redirect()->back()->withNotif(['label' => 'danger', 'err' => 'Pencarian tidak boleh lebih dari 30 hari!']);
     }
     if ($req->barang == 0) {
         return redirect()->back()->withNotif(['label' => 'danger', 'err' => 'Item tidak ditemukan!']);
     }
     $items = [];
     // Data Barang
     $barang = data_barang::join('ref_satuan', 'ref_satuan.id_satuan', '=', 'data_barang.id_satuan')->where('id_barang', $req->barang)->select('data_barang.*', 'ref_satuan.nm_satuan')->first();
     //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 = $barang->stok_awal + $sisa;
     $aftersisa = $lastsisa;
     // 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);
             } 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'];
     $r = array('barang' => $barang, 'items' => $items, 'req' => $req, 'lastsisa' => $aftersisa, 'jenis' => $jenis);
     $pdf = PDF::loadView('Print.Pengadaan.KartuStok.pdfKS', $r);
     return $pdf->stream();
     //$file = 'KartuStok-'.date('Y-m-d').'.pdf';
     //return $pdf->download($file);
 }