Dashboard sipadu mbip
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

CalculateStatisticCompound.php 11KB

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