info('Cek cron job'); $cek_data = StockRelease::where('expired_date', '<', Carbon::now()) ->get(); foreach($cek_data as $key => $value){ $cek_stock_release[$key] = StockRelease::where('id', $value->id)->first(); $data_stock_release[$key] = [ 'status_id' => 3, ]; DB::table('stock_releases')->where('id', $value->id) ->update($data_stock_release[$key]); $cek_stock[$key] = Stocks::where('golongan_darah_id', $value->golongan_darah_id) ->where('rhesus_id', $value->rhesus_id) ->where('produk_id', $value->produk_id) ->where('unit_donor_darah_id', $value->unit_donor_darah_id) ->first(); if($cek_stock[$key]->quantity_kantong != 0){ $data_stock[$key] = [ 'quantity_kantong' => $cek_stock[$key]['quantity_kantong'] - 1, ]; DB::table('stocks')->where('golongan_darah_id', $value->golongan_darah_id) ->where('produk_id', $value->produk_id) ->where('rhesus_id', $value->rhesus_id) ->where('unit_donor_darah_id', $value->unit_donor_darah_id) ->update($data_stock[$key]); } $data_log[$key] = [ 'log' => 'Pemusnahan Darah dengan no kantong : ' . $value->no_kantong, 'user_id' => 1, 'quantity_kantong' => 1, 'is_stock_in' => 1, 'is_stock_out' => 0, 'created_at' => NOW(), 'updated_at' => NOW(), ]; $data_pemusnahan[$key] = [ 'release_id' => $value->id, 'keterangan' => 'Darah Sudah Expired', 'petugas_id' => 1, 'created_at' => NOW(), 'updated_at' => NOW(), ]; } $update_log = StockLogs::insert($data_log); $insert_data_pemusnahan = Pemusnahan::insert($data_pemusnahan); } }