Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CalculateStatisticCompound.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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::all());
  46. $dataS->total = count(Compound::whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal'])->get());
  47. $dataS->status = 'all';
  48. $dataS->department = 'all';
  49. $dataS->modul = 'all';
  50. $dataS->save();
  51. }
  52. //calculate compound [modul = 02, status = Belum Bayar]
  53. $n1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','02')->first();
  54. if(!empty($n1)){
  55. $n1->total = count(Compound::where('modul','02')->where('status','Belum Bayar')->get());
  56. $n1->save();
  57. }else {
  58. $dataB = new ReportOverallCompound;
  59. $dataB->total = count(Compound::where('modul','02')->where('status','Belum Bayar')->get());
  60. $dataB->status = 'Belum Bayar';
  61. $dataB->department = 'all';
  62. $dataB->modul = '02';
  63. $dataB->save();
  64. }
  65. //calculate compound [modul = 03, status = Belum Bayar]
  66. $b1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','03')->orWhere('modul','02')->first();
  67. if(!empty($b1)){
  68. $b1->total = count(Compound::where('modul','03')->orWhere('modul','02')->where('status','Belum Bayar')->get());
  69. $b1->save();
  70. }else {
  71. $dataB = new ReportOverallCompound;
  72. $dataB->total = count(Compound::where('modul','03')->orWhere('modul','02')->where('status','Belum Bayar')->get());
  73. $dataB->status = 'Belum Bayar';
  74. $dataB->department = 'all';
  75. $dataB->modul = '03';
  76. $dataB->save();
  77. }
  78. //calculate compound [modul = 04, status = Belum Bayar]
  79. $pk1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','04')->first();
  80. if(!empty($pk1)){
  81. $pk1->total = count(Compound::where('modul','04')->where('status','Belum Bayar')->get());
  82. $pk1->save();
  83. }else {
  84. $dataPK = new ReportOverallCompound;
  85. $dataPK->total = count(Compound::where('modul','04')->where('status','Belum Bayar')->get());
  86. $dataPK->status = 'Belum Bayar';
  87. $dataPK->department = 'all';
  88. $dataPK->modul = '04';
  89. $dataPK->save();
  90. }
  91. //calculate compound [modul = 05, status = Belum Bayar]
  92. $na1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','05')->first();
  93. if(!empty($na1)){
  94. $na1->total = count(Compound::where('modul','05')->where('status','Belum Bayar')->get());
  95. $na1->save();
  96. }else {
  97. $dataNA = new ReportOverallCompound;
  98. $dataNA->total = count(Compound::where('modul','05')->where('status','Belum Bayar')->get());
  99. $dataNA->status = 'Belum Bayar';
  100. $dataNA->department = 'all';
  101. $dataNA->modul = '05';
  102. $dataNA->save();
  103. }
  104. //calculate compound [modul = 06-07, status = Belum Bayar]
  105. $si1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','06-07')->first();
  106. if(!empty($si1)){
  107. $si1->total = count(Compound::where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get());
  108. $si1->save();
  109. }else {
  110. $dataSI = new ReportOverallCompound;
  111. $dataSI->total = count(Compound::where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get());
  112. $dataSI->status = 'Belum Bayar';
  113. $dataSI->department = 'all';
  114. $dataSI->modul = '06-07';
  115. $dataSI->save();
  116. }
  117. //calculate compound [modul = 08, status = Belum Bayar]
  118. $rb1 = ReportOverallCompound::where('status','Belum Bayar')->where('department','all')->where('modul','08')->first();
  119. if(!empty($rb1)){
  120. $rb1->total = count(Compound::where('modul','08')->where('status','Belum Bayar')->get());
  121. $rb1->save();
  122. }else {
  123. $dataRB = new ReportOverallCompound;
  124. $dataRB->total = count(Compound::where('modul','08')->where('status','Belum Bayar')->get());
  125. $dataRB->status = 'Belum Bayar';
  126. $dataRB->department = 'all';
  127. $dataRB->modul = '08';
  128. $dataRB->save();
  129. }
  130. //calculate compound [status = Berbayar]
  131. $by1 = ReportOverallCompound::where('status','Berbayar')->where('department','all')->first();
  132. if(!empty($by1)){
  133. $by1->total = count(Compound::where('status','Berbayar')->get());
  134. $by1->save();
  135. }else {
  136. $dataBy = new ReportOverallCompound;
  137. $dataBy->total = count(Compound::where('status','Berbayar')->get());
  138. $dataBy->status = 'Berbayar';
  139. $dataBy->department = 'all';
  140. $dataBy->modul = 'all';
  141. $dataBy->save();
  142. }
  143. //////////////////////////////////////////////////////////////////////////////////////////
  144. //calcculate compound by department
  145. $department = Department::all();
  146. foreach ($department as $key => $d) {
  147. //calcculate compound by department [status = all(Belum Bayar, Bayar, Batal), modul = all]
  148. $s2 = ReportOverallCompound::where('status','all')->where('department', $d->_id)->where('modul','all')->first();
  149. if(!empty($s2)){
  150. $s2->total = count(Compound::where('jbkod',$d->_id)->get());
  151. $s2->save();
  152. }else {
  153. $dataJS1 = new ReportOverallCompound;
  154. $dataJS1->total = count(Compound::where('jbkod',$d->_id)->get());
  155. $dataJS1->status = 'all';
  156. $dataJS1->department = $d->_id;
  157. $dataJS1->modul = 'all';
  158. $dataJS1->save();
  159. }
  160. //calcculate compound by department [status = Belum Bayar, modul = 02]
  161. $n2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','02')->orWhere('modul','02')->first();
  162. if(!empty($n2)){
  163. $n2->total = count(Compound::where('jbkod',$d->_id)->where('modul','02')->where('status','Belum Bayar')->get());
  164. $n2->save();
  165. }else {
  166. $dataJB1 = new ReportOverallCompound;
  167. $dataJB1->total = count(Compound::where('jbkod',$d->_id)->where('modul','02')->where('status','Belum Bayar')->get());
  168. $dataJB1->status = 'Belum Bayar';
  169. $dataJB1->department = $d->_id;
  170. $dataJB1->modul = '03';
  171. $dataJB1->save();
  172. }
  173. //calcculate compound by department [status = Belum Bayar, modul = 03]
  174. $b2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','03')->orWhere('modul','02')->first();
  175. if(!empty($b2)){
  176. $b2->total = count(Compound::where('jbkod',$d->_id)->where('modul','03')->where('status','Belum Bayar')->get());
  177. $b2->save();
  178. }else {
  179. $dataJB1 = new ReportOverallCompound;
  180. $dataJB1->total = count(Compound::where('jbkod',$d->_id)->where('modul','03')->where('status','Belum Bayar')->get());
  181. $dataJB1->status = 'Belum Bayar';
  182. $dataJB1->department = $d->_id;
  183. $dataJB1->modul = '03';
  184. $dataJB1->save();
  185. }
  186. //calcculate compound by department [status = Belum Bayar, modul = 04]
  187. $pk2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','04')->first();
  188. if(!empty($pk2)){
  189. $pk2->total = count(Compound::where('jbkod',$d->_id)->where('modul','04')->where('status','Belum Bayar')->get());
  190. $pk2->save();
  191. }else {
  192. $dataJPK1 = new ReportOverallCompound;
  193. $dataJPK1->total = count(Compound::where('jbkod',$d->_id)->where('modul','04')->where('status','Belum Bayar')->get());
  194. $dataJPK1->status = 'Belum Bayar';
  195. $dataJPK1->department = $d->_id;
  196. $dataJPK1->modul = '04';
  197. $dataJPK1->save();
  198. }
  199. //calcculate compound by department [status = Belum Bayar, modul = 05]
  200. $na2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','05')->first();
  201. if(!empty($na2)){
  202. $na2->total = count(Compound::where('jbkod',$d->_id)->where('modul','05')->where('status','Belum Bayar')->get());
  203. $na2->save();
  204. }else {
  205. $dataJNA1 = new ReportOverallCompound;
  206. $dataJNA1->total = count(Compound::where('jbkod',$d->_id)->where('modul','05')->where('status','Belum Bayar')->get());
  207. $dataJNA1->status = 'Belum Bayar';
  208. $dataJNA1->department = $d->_id;
  209. $dataJNA1->modul = '05';
  210. $dataJNA1->save();
  211. }
  212. //calcculate compound by department [status = Belum Bayar, modul = 06-07]
  213. $si2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','06-07')->first();
  214. if(!empty($si2)){
  215. $si2->total = count(Compound::where('jbkod',$d->_id)->where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get());
  216. $si2->save();
  217. }else {
  218. $dataJSI1 = new ReportOverallCompound;
  219. $dataJSI1->total = count(Compound::where('jbkod',$d->_id)->where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get());
  220. $dataJSI1->status = 'Belum Bayar';
  221. $dataJSI1->department = $d->_id;
  222. $dataJSI1->modul = '06-07';
  223. $dataJSI1->save();
  224. }
  225. //calcculate compound by department [status = Belum Bayar, modul = 08]
  226. $rb2 = ReportOverallCompound::where('status','Belum Bayar')->where('department',$d->_id)->where('modul','08')->first();
  227. if(!empty($rb2)){
  228. $rb2->total = count(Compound::where('jbkod',$d->_id)->where('modul','08')->where('status','Belum Bayar')->get());
  229. $rb2->save();
  230. }else {
  231. $dataJRB1 = new ReportOverallCompound;
  232. $dataJRB1->total = count(Compound::where('jbkod',$d->_id)->where('modul','08')->where('status','Belum Bayar')->get());
  233. $dataJRB1->status = 'Belum Bayar';
  234. $dataJRB1->department = $d->_id;
  235. $dataJRB1->modul = '08';
  236. $dataJRB1->save();
  237. }
  238. //calcculate compound by department [status = Berbayar]
  239. $by2 = ReportOverallCompound::where('status','Berbayar')->where('department',$d->_id)->first();
  240. if(!empty($by2)){
  241. $by2->total = count(Compound::where('jbkod',$d->_id)->where('status','Berbayar')->get());
  242. $by2->save();
  243. }else {
  244. $dataJBy1 = new ReportOverallCompound;
  245. $dataJBy1->total = count(Compound::where('jbkod',$d->_id)->where('status','Berbayar')->get());
  246. $dataJBy1->status = 'Berbayar';
  247. $dataJBy1->department = $d->_id;
  248. $dataJBy1->modul = 'all';
  249. $dataJBy1->save();
  250. }
  251. }
  252. Log::info('Overall Compound been saved');
  253. $this->info('Overall Compound been saved');
  254. }
  255. }