Exemplo n.º 1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     try {
         \DB::begintransaction();
         $me = \Me::data()->id_karyawan;
         $stok = data_penyesuaian_stok::create(['tipe' => $this->req['tipe'], 'id_karyawan' => $me, 'keterangan' => $this->req['ket'], 'tanggal' => $this->req['tanggal'], 'id_gudang' => $this->req['id_gudang']]);
         if (count($this->req['id_barang']) == 0) {
             throw new \Exception("Barang/Obat tidak ditemukan!", 1);
         }
         $notempty = [];
         foreach ($this->req['id_barang'] as $i => $id_barang) {
             if (!empty($this->req['qty'][$i])) {
                 $notempty[] = 1;
                 $qty = \Format::convertSatuan($id_barang, $this->req['satuan'][$i], $this->req['satuan_default'][$i]) * $this->req['qty'][$i];
                 data_penyesuaian_stok_item::create(['id_penyesuaian_stok' => $stok->id_penyesuaian_stok, 'id_barang' => $id_barang, 'id_satuan' => $this->req['satuan'][$i], 'qty_lg' => $this->req['qty'][$i], 'current_qty' => $this->req['current_qty'][$i], 'new_qty' => $qty, 'keterangan' => $this->req['kets'][$i]]);
             }
             if (count($notempty) == 0) {
                 throw new \Exception("Barang/Obat tidak ditemukan!", 1);
             }
             // Log Stok
             $kondisi = $qty >= $this->req['current_qty'][$i] ? 1 : 2;
             $stok_qty = $this->req['current_qty'][$i] - $qty;
             data_log_barang::create(['id_barang' => $id_barang, 'qty' => abs($stok_qty), 'keterangan' => 'Penyesuaian Stok', 'id_gudang' => $this->req['id_gudang'], 'kondisi' => $kondisi, 'tipe' => 3, 'id_parent' => $stok->id_penyesuaian_stok, 'id_karyawan' => $me]);
             // Stok gudang
             $barang = data_item_gudang::where('id_barang', $id_barang)->where('id_gudang', $this->req['id_gudang'])->first();
             $brg = data_item_gudang::find($barang->id_item_gudang);
             if ($kondisi == 1) {
                 $brg->in = $barang->in + abs($stok_qty);
             } else {
                 $brg->out = $barang->out + abs($stok_qty);
             }
             $brg->save();
         }
         // Code
         $tipe = 'O-';
         $format = $tipe . 'ADJ-SG-' . \Format::code($stok->id_penyesuaian_stok);
         $stok->no_penyesuaian_stok = $format;
         $stok->save();
         \Loguser::create('Melakukan penyesuaian Stok dengan No. ' . $stok->no_penyesuaian_stok);
         \DB::commit();
         return ['result' => true, 'label' => 'success', 'err' => 'Penyesuaian berhasil di buat dengan No. ' . $stok->no_penyesuaian_stok];
     } catch (\Exception $e) {
         \DB::rollback();
         return ['result' => false, 'label' => 'danger', 'err' => $e->getMessage()];
     }
 }
Exemplo n.º 2
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     try {
         \DB::begintransaction();
         $me = \Me::data()->id_karyawan;
         $retur = data_retur::create(['tipe' => 1, 'id_gudang_asal' => $this->req['id_gudang'], 'id_karyawan' => $me]);
         foreach ($this->req['id_barang'] as $i => $id_barang) {
             if (!empty($this->req['qty'][$i])) {
                 data_retur_item::create(['id_retur' => $retur->id_retur, 'id_barang' => $id_barang, 'id_satuan' => $this->req['id_satuan'][$i], 'qty' => $this->req['qty'][$i], 'qty_lg' => $this->req['qty'][$i]]);
                 // Log Stok
                 data_log_barang::create(['id_barang' => $id_barang, 'qty' => $this->req['qty'][$i], 'id_gudang' => 0, 'kondisi' => 1, 'tipe' => 4, 'id_parent' => $retur->id_retur, 'id_karyawan' => $me]);
                 // Log Stok
                 data_log_barang::create(['id_barang' => $id_barang, 'qty' => $this->req['qty'][$i], 'id_gudang' => $this->req['id_gudang'], 'kondisi' => 2, 'tipe' => 4, 'id_parent' => $retur->id_retur, 'id_karyawan' => $me]);
                 // Update stok Gudang besat
                 $barang = data_barang::find($id_barang);
                 $barang->in = $barang->in + $this->req['qty'][$i];
                 $barang->save();
                 // Update Stok sub gudang
                 $gudang = data_item_gudang::where('id_barang', $id_barang)->where('id_gudang', $this->req['id_gudang'])->first();
                 $gd = data_item_gudang::find($gudang->id_item_gudang);
                 $gd->out = $gudang->out + $this->req['qty'][$i];
                 $gd->save();
             }
         }
         $format = 'IN-RTN-';
         $kode = $format . \Format::code($retur->id_retur);
         $retur->no_retur = $kode;
         $retur->save();
         \Loguser::create('Membuat Retur Gudang dengan No. ' . $kode);
         \DB::commit();
         return ['result' => true, 'label' => 'success', 'err' => 'Return Gudang berhasil dibuat dengan No. ' . $kode];
     } catch (\Exception $e) {
         \DB::rollback();
         return ['result' => false, 'label' => 'danger', 'err' => $e->getMessage()];
     }
 }
Exemplo n.º 3
0
    /**
     * Mengambil data stok berdasarkan Poli
     * @access Ajax
     */
    public function postPoli(Request $req)
    {
        $result = [];
        if ($req->ajax()) {
            $result['result'] = true;
            $items = data_item_gudang::byidbarang($req->id);
            $html = '';
            if (count($items) > 0) {
                foreach ($items as $item) {
                    $stok = $item->in - $item->out;
                    $html .= '
						<tr>
							<td>' . $item->nm_gudang . '</td>
							<td class="text-right">' . number_format($stok, 0, ',', '.') . ' ' . $item->nm_satuan . '</td>
						</tr>
					';
                }
            } else {
                $html = '
					<tr>
						<td colspan="2">Tidak ditemukan</td>
					</tr>
				';
            }
            $result['content'] = $html;
        } else {
            $result['result'] = false;
            $result['err'] = 'restrict';
        }
        return json_encode($result);
    }
 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');
 }
Exemplo n.º 5
0
 public function getCreateadj()
 {
     $me = \Me::subgudang();
     if (!$me->access) {
         return redirect('/subgudang/adjustment')->withNotif(['label' => 'warning', 'err' => 'Penyesuaian stok hanya bisa dilakukan oleh user yang memiliki akses terhadap sub gudang']);
     }
     if (count($this->ids) < 1) {
         return redirect('/subgudang/select')->withNotif(['label' => 'warning', 'err' => 'Maaf, Anda belum menentukan item Barang yang akan diproses.<br /> Silahkan pilih beberapa item di bawah ini']);
     }
     $items = 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')->whereIn('data_item_gudang.id_barang', $this->ids)->where('data_barang.tipe', 1)->select('data_barang.nm_barang', 'data_barang.kode', 'data_item_gudang.*', 'ref_satuan.nm_satuan')->get();
     if (count($items) == 0) {
         return redirect('/subgudang')->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.SubGudang.CreateAdjustment', ['items' => $items, 'gudangs' => $gudangs, 'ids' => $ids, 'tipe' => 1, 'me' => $me]);
 }