Dashboard sipadu mbip
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CalculateStatisticCompound.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Log;
  5. use App\Model\Module\Compound;
  6. use App\Model\Module\Department;
  7. use App\Model\Module\ReportOverallCompound;
  8. class CalculateStatisticCompound extends Command
  9. {
  10. /**
  11. * The name and signature of the console command
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'update:statistic__overall_compound';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Store and calculate statistic overall compound';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. //calculate all compound [status = Belum Bayar, Bayar & Batal]
  39. $s1 = ReportOverallCompound::where('status','all')->where('department','all')->where('modul','all')->first();
  40. if(!empty($s1)){
  41. $s1->total = count(Compound::whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal'])->get());
  42. $s1->save();
  43. }else {
  44. $dataS = new ReportOverallCompound;
  45. $dataS->total = count(Compound::whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal'])->get());
  46. $dataS->status = 'all';
  47. $dataS->department = 'all';
  48. $dataS->modul = 'all';
  49. $dataS->save();
  50. }
  51. //calculate compound [modul = 02, status = Belum Bayar]
  52. $n1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','02')->first();
  53. if(!empty($n1)){
  54. $n1->total = count(Compound::where('modul','02')->where('status','Belum Bayar')->get());
  55. $n1->save();
  56. }else {
  57. $dataB = new ReportOverallCompound;
  58. $dataB->total = count(Compound::where('modul','02')->where('status','Belum Bayar')->get());
  59. $dataB->status = 'Belum Bayar';
  60. $dataB->department = 'all';
  61. $dataB->modul = '02';
  62. $dataB->save();
  63. }
  64. //calculate compound [modul = 03, status = Belum Bayar]
  65. $b1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','03')->orWhere('modul','02')->first();
  66. if(!empty($b1)){
  67. $b1->total = count(Compound::where('modul','03')->orWhere('modul','02')->where('status','Belum Bayar')->get());
  68. $b1->save();
  69. }else {
  70. $dataB = new ReportOverallCompound;
  71. $dataB->total = count(Compound::where('modul','03')->orWhere('modul','02')->where('status','Belum Bayar')->get());
  72. $dataB->status = 'Belum Bayar';
  73. $dataB->department = 'all';
  74. $dataB->modul = '03';
  75. $dataB->save();
  76. }
  77. //calculate compound [modul = 04, status = Belum Bayar]
  78. $pk1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','04')->first();
  79. if(!empty($pk1)){
  80. $pk1->total = count(Compound::where('modul','04')->where('status','Belum Bayar')->get());
  81. $pk1->save();
  82. }else {
  83. $dataPK = new ReportOverallCompound;
  84. $dataPK->total = count(Compound::where('modul','04')->where('status','Belum Bayar')->get());
  85. $dataPK->status = 'Belum Bayar';
  86. $dataPK->department = 'all';
  87. $dataPK->modul = '04';
  88. $dataPK->save();
  89. }
  90. //calculate compound [modul = 05, status = Belum Bayar]
  91. $na1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','05')->first();
  92. if(!empty($na1)){
  93. $na1->total = count(Compound::where('modul','05')->where('status','Belum Bayar')->get());
  94. $na1->save();
  95. }else {
  96. $dataNA = new ReportOverallCompound;
  97. $dataNA->total = count(Compound::where('modul','05')->where('status','Belum Bayar')->get());
  98. $dataNA->status = 'Belum Bayar';
  99. $dataNA->department = 'all';
  100. $dataNA->modul = '05';
  101. $dataNA->save();
  102. }
  103. //calculate compound [modul = 06-07, status = Belum Bayar]
  104. $si1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','06-07')->first();
  105. if(!empty($si1)){
  106. $si1->total = count(Compound::where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get());
  107. $si1->save();
  108. }else {
  109. $dataSI = new ReportOverallCompound;
  110. $dataSI->total = count(Compound::where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get());
  111. $dataSI->status = 'Belum Bayar';
  112. $dataSI->department = 'all';
  113. $dataSI->modul = '06-07';
  114. $dataSI->save();
  115. }
  116. //calculate compound [modul = 08, status = Belum Bayar]
  117. $rb1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','08')->first();
  118. if(!empty($rb1)){
  119. $rb1->total = count(Compound::where('modul','08')->where('status','Belum Bayar')->get());
  120. $rb1->save();
  121. }else {
  122. $dataRB = new ReportOverallCompound;
  123. $dataRB->total = count(Compound::where('modul','08')->where('status','Belum Bayar')->get());
  124. $dataRB->status = 'Belum Bayar';
  125. $dataRB->department = 'all';
  126. $dataRB->modul = '08';
  127. $dataRB->save();
  128. }
  129. //calculate compound [status = Berbayar]
  130. $by1 = ReportOverallCompound::where('status','Berbayar')->where('department','all')->first();
  131. if(!empty($by1)){
  132. $by1->total = count(Compound::where('status','Berbayar')->get());
  133. $by1->save();
  134. }else {
  135. $dataBy = new ReportOverallCompound;
  136. $dataBy->total = count(Compound::where('status','Berbayar')->get());
  137. $dataBy->status = 'Berbayar';
  138. $dataBy->department = 'all';
  139. $dataBy->modul = 'all';
  140. $dataBy->save();
  141. }
  142. //////////////////////////////////////////////////////////////////////////////////////////
  143. //calcculate compound by department
  144. $department = Department::all();
  145. foreach ($department as $key => $d) {
  146. //calcculate compound by department [status = all(Belum Bayar, Bayar, Batal), modul = all]
  147. $s2 = ReportOverallCompound::where('status','all')->where('department', $d->_id)->where('modul','all')->first();
  148. if(!empty($s2)){
  149. $s2->total = count(Compound::where('jbkod',$d->_id)->get());
  150. $s2->save();
  151. }else {
  152. $dataJS1 = new ReportOverallCompound;
  153. $dataJS1->total = count(Compound::where('jbkod',$d->_id)->get());
  154. $dataJS1->status = 'all';
  155. $dataJS1->department = $d->_id;
  156. $dataJS1->modul = 'all';
  157. $dataJS1->save();
  158. }
  159. //calcculate compound by department [status = Belum Bayar, modul = 02]
  160. $n2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','02')->orWhere('modul','02')->first();
  161. if(!empty($n2)){
  162. $n2->total = count(Compound::where('jbkod',$d->_id)->where('modul','02')->where('status','Belum Bayar')->get());
  163. $n2->save();
  164. }else {
  165. $dataJB1 = new ReportOverallCompound;
  166. $dataJB1->total = count(Compound::where('jbkod',$d->_id)->where('modul','02')->where('status','Belum Bayar')->get());
  167. $dataJB1->status = 'Belum Bayar';
  168. $dataJB1->department = $d->_id;
  169. $dataJB1->modul = '03';
  170. $dataJB1->save();
  171. }
  172. //calcculate compound by department [status = Belum Bayar, modul = 03]
  173. $b2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','03')->orWhere('modul','02')->first();
  174. if(!empty($b2)){
  175. $b2->total = count(Compound::where('jbkod',$d->_id)->where('modul','03')->where('status','Belum Bayar')->get());
  176. $b2->save();
  177. }else {
  178. $dataJB1 = new ReportOverallCompound;
  179. $dataJB1->total = count(Compound::where('jbkod',$d->_id)->where('modul','03')->where('status','Belum Bayar')->get());
  180. $dataJB1->status = 'Belum Bayar';
  181. $dataJB1->department = $d->_id;
  182. $dataJB1->modul = '03';
  183. $dataJB1->save();
  184. }
  185. //calcculate compound by department [status = Belum Bayar, modul = 04]
  186. $pk2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','04')->first();
  187. if(!empty($pk2)){
  188. $pk2->total = count(Compound::where('jbkod',$d->_id)->where('modul','04')->where('status','Belum Bayar')->get());
  189. $pk2->save();
  190. }else {
  191. $dataJPK1 = new ReportOverallCompound;
  192. $dataJPK1->total = count(Compound::where('jbkod',$d->_id)->where('modul','04')->where('status','Belum Bayar')->get());
  193. $dataJPK1->status = 'Belum Bayar';
  194. $dataJPK1->department = $d->_id;
  195. $dataJPK1->modul = '04';
  196. $dataJPK1->save();
  197. }
  198. //calcculate compound by department [status = Belum Bayar, modul = 05]
  199. $na2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','05')->first();
  200. if(!empty($na2)){
  201. $na2->total = count(Compound::where('jbkod',$d->_id)->where('modul','05')->where('status','Belum Bayar')->get());
  202. $na2->save();
  203. }else {
  204. $dataJNA1 = new ReportOverallCompound;
  205. $dataJNA1->total = count(Compound::where('jbkod',$d->_id)->where('modul','05')->where('status','Belum Bayar')->get());
  206. $dataJNA1->status = 'Belum Bayar';
  207. $dataJNA1->department = $d->_id;
  208. $dataJNA1->modul = '05';
  209. $dataJNA1->save();
  210. }
  211. //calcculate compound by department [status = Belum Bayar, modul = 06-07]
  212. $si2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','06-07')->first();
  213. if(!empty($si2)){
  214. $si2->total = count(Compound::where('jbkod',$d->_id)->where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get());
  215. $si2->save();
  216. }else {
  217. $dataJSI1 = new ReportOverallCompound;
  218. $dataJSI1->total = count(Compound::where('jbkod',$d->_id)->where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get());
  219. $dataJSI1->status = 'Belum Bayar';
  220. $dataJSI1->department = $d->_id;
  221. $dataJSI1->modul = '06-07';
  222. $dataJSI1->save();
  223. }
  224. //calcculate compound by department [status = Belum Bayar, modul = 08]
  225. $rb2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','08')->first();
  226. if(!empty($rb2)){
  227. $rb2->total = count(Compound::where('jbkod',$d->_id)->where('modul','08')->where('status','Belum Bayar')->get());
  228. $rb2->save();
  229. }else {
  230. $dataJRB1 = new ReportOverallCompound;
  231. $dataJRB1->total = count(Compound::where('jbkod',$d->_id)->where('modul','08')->where('status','Belum Bayar')->get());
  232. $dataJRB1->status = 'Belum Bayar';
  233. $dataJRB1->department = $d->_id;
  234. $dataJRB1->modul = '08';
  235. $dataJRB1->save();
  236. }
  237. //calcculate compound by department [status = Berbayar]
  238. $by2 = ReportOverallCompound::where('status','Berbayar')->where('department',$d->_id)->first();
  239. if(!empty($by2)){
  240. $by2->total = count(Compound::where('jbkod',$d->_id)->where('status','Berbayar')->get());
  241. $by2->save();
  242. }else {
  243. $dataJBy1 = new ReportOverallCompound;
  244. $dataJBy1->total = count(Compound::where('jbkod',$d->_id)->where('status','Berbayar')->get());
  245. $dataJBy1->status = 'Berbayar';
  246. $dataJBy1->department = $d->_id;
  247. $dataJBy1->modul = 'all';
  248. $dataJBy1->save();
  249. }
  250. }
  251. Log::info('Overall Compound been saved');
  252. $this->info('Overall Compound been saved');
  253. }
  254. }