123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
-
- namespace App\Console\Commands;
-
- use Illuminate\Console\Command;
- use Log;
- use App\Model\Module\Compound;
- use App\Model\Module\Department;
- use App\Model\Module\ReportOverallCompound;
-
- class CalculateStatisticCompound extends Command
- {
- /**
- * The name and signature of the console command
- *
- * @var string
- */
- protected $signature = 'update:statistic__overall_compound';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Store and calculate statistic overall compound';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- //calculate all compound [status = Belum Bayar, Bayar & Batal]
- $s1 = ReportOverallCompound::where('status','all')->where('department','all')->where('modul','all')->first();
- if(!empty($s1)){
- $s1->total = count(Compound::whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal'])->get());
- $s1->save();
- }else {
- $dataS = new ReportOverallCompound;
- // $dataS->total = count(Compound::all());
- $dataS->total = count(Compound::whereIn('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');
- }
- }
|