/**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     MutasiStokBahan::where('tanggal', $this->tanggal)->delete();
     $bahans = \App\Bahan::MutasiStok($this->tanggal);
     $inserts = [];
     foreach ($bahans as $bahan) {
         array_push($inserts, ['bahan_id' => $bahan['id'], 'before' => $bahan['before'], 'pembelian' => $bahan['pembelian'], 'penjualan' => $bahan['penjualan'], 'adjustment_increase' => $bahan['adjustment_increase'], 'adjustment_reduction' => $bahan['adjustment_reduction'], 'sisa' => $bahan['sisa'], 'tanggal' => $this->tanggal]);
     }
     MutasiStokBahan::insert($inserts);
 }
 protected function _stokBahanPeriode(Request $request)
 {
     $tanggal = $request->get('tanggal') ? $request->get('tanggal') : date('Y-m-d');
     $to_tanggal = $request->get('to_tanggal') ? $request->get('to_tanggal') : $tanggal;
     $bahans = \App\MutasiStokBahan::with('bahan')->select(['id', 'bahan_id', 'before', DB::raw("SUM(pembelian)pembelian"), DB::raw("SUM(pembelian)pembelian"), DB::raw("SUM(adjustment_increase)adjustment_increase"), DB::raw("SUM(adjustment_reduction)adjustment_reduction"), DB::raw("(((((`before`)+SUM(pembelian))-SUM(penjualan))+SUM(adjustment_increase))-SUM(adjustment_reduction))sisa")])->whereBetween('tanggal', [$tanggal, $to_tanggal])->groupBy('bahan_id')->get();
     return ['tanggal' => Carbon::createFromFormat('Y-m-d', $tanggal), 'to_tanggal' => Carbon::createFromFormat('Y-m-d', $to_tanggal), 'bahans' => $bahans];
 }