where('department','all')->where('modul','all')->first(); if(!empty($s1)){ $s1->total = count(Compound::where('status', ['Belum Bayar', 'Berbayar', 'Batal'])->get(); $s1->save(); }else { $dataS = new ReportOverallCompound; // $dataS->total = count(Compound::all()); $dataS->total = count(Compound::where('status', ['Belum Bayar', 'Berbayar', 'Batal'])->get(); $dataS->status = 'all'; $dataS->department = 'all'; $dataS->modul = 'all'; $dataS->save(); } //calculate compound [modul = 03, status = Belum Bayar] $b1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','03')->first(); if(!empty($b1)){ $b1->total = count(Compound::where('modul','03')->where('status','Belum Bayar')->get()); $b1->save(); }else { $dataB = new ReportOverallCompound; $dataB->total = count(Compound::where('modul','03')->where('status','Belum Bayar')->get()); $dataB->status = 'Belum Bayar'; $dataB->department = 'all'; $dataB->modul = '03'; $dataB->save(); } //calculate compound [modul = 04, status = Belum Bayar] $pk1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','04')->first(); if(!empty($pk1)){ $pk1->total = count(Compound::where('modul','04')->where('status','Belum Bayar')->get()); $pk1->save(); }else { $dataPK = new ReportOverallCompound; $dataPK->total = count(Compound::where('modul','04')->where('status','Belum Bayar')->get()); $dataPK->status = 'Belum Bayar'; $dataPK->department = 'all'; $dataPK->modul = '04'; $dataPK->save(); } //calculate compound [modul = 05, status = Belum Bayar] $na1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','05')->first(); if(!empty($na1)){ $na1->total = count(Compound::where('modul','05')->where('status','Belum Bayar')->get()); $na1->save(); }else { $dataNA = new ReportOverallCompound; $dataNA->total = count(Compound::where('modul','05')->where('status','Belum Bayar')->get()); $dataNA->status = 'Belum Bayar'; $dataNA->department = 'all'; $dataNA->modul = '05'; $dataNA->save(); } //calculate compound [modul = 06-07, status = Belum Bayar] $si1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','06-07')->first(); if(!empty($si1)){ $si1->total = count(Compound::where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get()); $si1->save(); }else { $dataSI = new ReportOverallCompound; $dataSI->total = count(Compound::where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get()); $dataSI->status = 'Belum Bayar'; $dataSI->department = 'all'; $dataSI->modul = '06-07'; $dataSI->save(); } //calculate compound [modul = 08, status = Belum Bayar] $rb1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','08')->first(); if(!empty($rb1)){ $rb1->total = count(Compound::where('modul','08')->where('status','Belum Bayar')->get()); $rb1->save(); }else { $dataRB = new ReportOverallCompound; $dataRB->total = count(Compound::where('modul','08')->where('status','Belum Bayar')->get()); $dataRB->status = 'Belum Bayar'; $dataRB->department = 'all'; $dataRB->modul = '08'; $dataRB->save(); } //calculate compound [status = Berbayar] $by1 = ReportOverallCompound::where('status','Berbayar')->where('department','all')->first(); if(!empty($by1)){ $by1->total = count(Compound::where('status','Berbayar')->get()); $by1->save(); }else { $dataBy = new ReportOverallCompound; $dataBy->total = count(Compound::where('status','Berbayar')->get()); $dataBy->status = 'Berbayar'; $dataBy->department = 'all'; $dataBy->modul = 'all'; $dataBy->save(); } ////////////////////////////////////////////////////////////////////////////////////////// //calcculate compound by department $department = Department::all(); foreach ($department as $key => $d) { //calcculate compound by department [status = all(Belum Bayar, Bayar, Batal), modul = all] $s2 = ReportOverallCompound::where('status','all')->where('department', $d->_id)->where('modul','all')->first(); if(!empty($s2)){ $s2->total = count(Compound::where('jbkod',$d->_id)->get()); $s2->save(); }else { $dataJS1 = new ReportOverallCompound; $dataJS1->total = count(Compound::where('jbkod',$d->_id)->get()); $dataJS1->status = 'all'; $dataJS1->department = $d->_id; $dataJS1->modul = 'all'; $dataJS1->save(); } //calcculate compound by department [status = Belum Bayar, modul = 03] $b2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','03')->first(); if(!empty($b2)){ $b2->total = count(Compound::where('jbkod',$d->_id)->where('modul','03')->where('status','Belum Bayar')->get()); $b2->save(); }else { $dataJB1 = new ReportOverallCompound; $dataJB1->total = count(Compound::where('jbkod',$d->_id)->where('modul','03')->where('status','Belum Bayar')->get()); $dataJB1->status = 'Belum Bayar'; $dataJB1->department = $d->_id; $dataJB1->modul = '03'; $dataJB1->save(); } //calcculate compound by department [status = Belum Bayar, modul = 04] $pk2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','04')->first(); if(!empty($pk2)){ $pk2->total = count(Compound::where('jbkod',$d->_id)->where('modul','04')->where('status','Belum Bayar')->get()); $pk2->save(); }else { $dataJPK1 = new ReportOverallCompound; $dataJPK1->total = count(Compound::where('jbkod',$d->_id)->where('modul','04')->where('status','Belum Bayar')->get()); $dataJPK1->status = 'Belum Bayar'; $dataJPK1->department = $d->_id; $dataJPK1->modul = '04'; $dataJPK1->save(); } //calcculate compound by department [status = Belum Bayar, modul = 05] $na2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','05')->first(); if(!empty($na2)){ $na2->total = count(Compound::where('jbkod',$d->_id)->where('modul','05')->where('status','Belum Bayar')->get()); $na2->save(); }else { $dataJNA1 = new ReportOverallCompound; $dataJNA1->total = count(Compound::where('jbkod',$d->_id)->where('modul','05')->where('status','Belum Bayar')->get()); $dataJNA1->status = 'Belum Bayar'; $dataJNA1->department = $d->_id; $dataJNA1->modul = '05'; $dataJNA1->save(); } //calcculate compound by department [status = Belum Bayar, modul = 06-07] $si2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','06-07')->first(); if(!empty($si2)){ $si2->total = count(Compound::where('jbkod',$d->_id)->where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get()); $si2->save(); }else { $dataJSI1 = new ReportOverallCompound; $dataJSI1->total = count(Compound::where('jbkod',$d->_id)->where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get()); $dataJSI1->status = 'Belum Bayar'; $dataJSI1->department = $d->_id; $dataJSI1->modul = '06-07'; $dataJSI1->save(); } //calcculate compound by department [status = Belum Bayar, modul = 08] $rb2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','08')->first(); if(!empty($rb2)){ $rb2->total = count(Compound::where('jbkod',$d->_id)->where('modul','08')->where('status','Belum Bayar')->get()); $rb2->save(); }else { $dataJRB1 = new ReportOverallCompound; $dataJRB1->total = count(Compound::where('jbkod',$d->_id)->where('modul','08')->where('status','Belum Bayar')->get()); $dataJRB1->status = 'Belum Bayar'; $dataJRB1->department = $d->_id; $dataJRB1->modul = '08'; $dataJRB1->save(); } //calcculate compound by department [status = Berbayar] $by2 = ReportOverallCompound::where('status','Berbayar')->where('department',$d->_id)->first(); if(!empty($by2)){ $by2->total = count(Compound::where('jbkod',$d->_id)->where('status','Berbayar')->get()); $by2->save(); }else { $dataJBy1 = new ReportOverallCompound; $dataJBy1->total = count(Compound::where('jbkod',$d->_id)->where('status','Berbayar')->get()); $dataJBy1->status = 'Berbayar'; $dataJBy1->department = $d->_id; $dataJBy1->modul = 'all'; $dataJBy1->save(); } } Log::info('Overall Compound been saved'); $this->info('Overall Compound been saved'); } }