/** * 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()]; } }
/** * 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()]; } }