예제 #1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     try {
         \DB::begintransaction();
         $me = \Me::data()->id_karyawan;
         $retur = data_retur::create(['tipe' => 2, 'id_po' => $this->req['id_po'], 'id_vendor' => $this->req['id_vendor'], 'id_karyawan' => $me]);
         data_po::find($this->req['id_po'])->update(['status' => 2]);
         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' => 2, 'tipe' => 5, 'id_parent' => $retur->id_retur, 'id_karyawan' => $me]);
                 // Update stok
                 $barang = data_barang::find($id_barang);
                 $barang->out = $barang->out + $this->req['qty'][$i];
                 $barang->save();
                 // Update data PO items
                 $itm = data_po_item::where('id_po', $this->req['id_po'])->where('id_item', $id_barang)->first();
                 $qpo = $itm->qty + $this->req['qty'][$i];
                 data_po_item::where('id_po', $this->req['id_po'])->where('id_item', $id_barang)->update(['qty' => $qpo, 'status' => 1]);
             }
         }
         $format = 'EX-RTN-';
         $kode = $format . \Format::code($retur->id_retur);
         $retur->no_retur = $kode;
         $retur->save();
         \Loguser::create('Membuat Retur Pembelian dengan No. ' . $kode);
         \DB::commit();
         return ['result' => true, 'label' => 'success', 'err' => 'Return Pembelian berhasil dibuat dengan No. ' . $kode];
     } catch (\Exception $e) {
         \DB::rollback();
         return ['result' => false, 'label' => 'danger', 'err' => $e->getMessage()];
     }
 }
예제 #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()];
     }
 }
 public function getPrint($id)
 {
     if (empty($id) || !is_numeric($id)) {
         return redirect('/returgudang')->withNotif(['label' => 'danger', 'err' => 'Tidak ditemukan!']);
     }
     $retur = data_retur::join('ref_gudang', 'ref_gudang.id_gudang', '=', 'data_retur.id_gudang_asal')->where('id_retur', $id)->first();
     $items = data_retur_item::join('data_barang', 'data_retur_item.id_barang', '=', 'data_barang.id_barang')->join('ref_satuan', 'ref_satuan.id_satuan', '=', 'data_retur_item.id_satuan')->where('data_retur_item.id_retur', $id)->get();
     return view('Print.Pengadaan.Retur.printRetur', ['retur' => $retur, 'items' => $items]);
 }