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.

StatisticController.php 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. namespace App\Http\Controllers\v3\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\v3\Api\BaseController;
  5. use Carbon\Carbon;
  6. use App\SiteSetting;
  7. use App\LatestModel\Staff;
  8. use App\LatestModel\StaffDetail;
  9. use App\LatestModel\Module\Form;
  10. use App\LatestModel\Module\Subscriber;
  11. use App\LatestModel\Module\WorkOrder;
  12. use App\LatestModel\Module\PackageDetail;
  13. use App\LatestModel\Module\Docket;
  14. use App\LatestModel\Module\Coverage;
  15. use App\LatestModel\Module\DealerClaim;
  16. use App\LatestModel\Module\Company;
  17. use App\LatestModel\Module\Commission;
  18. use App\LatestModel\Module\Product;
  19. class StatisticController extends BaseController
  20. {
  21. /**
  22. * Return pie data overview
  23. *
  24. * @return json
  25. */
  26. public function getStatisticFormOverview(){
  27. $rejected = count(Form::onlyTrashed()->get());
  28. $rec = count(Form::where('type_service','Rectification')->get());
  29. $dealer = count(Form::whereNotNull('dealer_id')->get());
  30. $normal = count(Form::whereNull('dealer_id')->get());
  31. $data = array();
  32. array_push($data, $rec, $dealer, $normal, $rejected);
  33. return $this->sendResponse($data, '');
  34. }
  35. /**
  36. * Return pie data month
  37. *
  38. * @return json
  39. */
  40. public function getStatisticFormMonth()
  41. {
  42. $jan = array(); $feb = array(); $mac = array(); $april = array(); $may = array(); $jun = array();
  43. $july = array(); $august = array(); $sep = array(); $oct = array(); $nov = array(); $dec = array();
  44. $jan1 = array(); $feb1 = array(); $mac1 = array(); $april1 = array(); $may1 = array(); $jun1 = array();
  45. $july1 = array(); $august1 = array(); $sep1 = array(); $oct1 = array(); $nov1 = array(); $dec1 = array();
  46. $dealer_form = Form::whereNotNull('dealer_id')->where('type_service','!=','Rectification')->get();
  47. foreach ($dealer_form as $key => $d) {
  48. $mY = Carbon::parse($d->created_at)->format('m/Y');
  49. if($mY == '01/2019'){
  50. $jan[] = $d;
  51. }else if($mY == '02/2019'){
  52. $feb[] = $d;
  53. }else if($mY == '03/2019'){
  54. $mac[] = $d;
  55. }else if($mY == '04/2019'){
  56. $april[] = $d;
  57. }else if($mY == '05/2019'){
  58. $may[] = $d;
  59. }else if($mY == '06/2019'){
  60. $jun[] = $d;
  61. }else if($mY == '07/2019'){
  62. $july[] = $d;
  63. }else if($mY == '08/2019'){
  64. $august[] = $d;
  65. }else if($mY == '09/2019'){
  66. $sep[] = $d;
  67. }else if($mY == '10/2019'){
  68. $oct[] = $d;
  69. }else if($mY == '11/2019'){
  70. $nov[] = $d;
  71. }else if($mY == '12/2019'){
  72. $dec[] = $d;
  73. }
  74. }
  75. $total_dealer_form = array();
  76. array_push($total_dealer_form, count($jan),count($feb),count($mac),count($april),count($may),count($jun),count($july),count($august),count($sep),count($oct),count($nov),count($dec));
  77. $normal_form = Form::whereNull('dealer_id')->where('type_service','!=','Rectification')->get();
  78. foreach ($normal_form as $key => $d) {
  79. $mY = Carbon::parse($d->created_at)->format('m/Y');
  80. if($mY == '01/2019'){
  81. $jan1[] = $d;
  82. }else if($mY == '02/2019'){
  83. $feb1[] = $d;
  84. }else if($mY == '03/2019'){
  85. $mac1[] = $d;
  86. }else if($mY == '04/2019'){
  87. $april1[] = $d;
  88. }else if($mY == '05/2019'){
  89. $may1[] = $d;
  90. }else if($mY == '06/2019'){
  91. $jun1[] = $d;
  92. }else if($mY == '07/2019'){
  93. $july1[] = $d;
  94. }else if($mY == '08/2019'){
  95. $august1[] = $d;
  96. }else if($mY == '09/2019'){
  97. $sep1[] = $d;
  98. }else if($mY == '10/2019'){
  99. $oct1[] = $d;
  100. }else if($mY == '11/2019'){
  101. $nov1[] = $d;
  102. }else if($mY == '12/2019'){
  103. $dec1[] = $d;
  104. }
  105. }
  106. $total_normal_form = array();
  107. array_push($total_normal_form,count($jan1),count($feb1),count($mac1),count($april1),count($may1),count($jun1),count($july1),count($august1),count($sep1),count($oct1),count($nov1),count($dec1));
  108. $data = array();
  109. array_push($data, $total_dealer_form, $total_normal_form);
  110. return $this->sendResponse($data, 'array');
  111. }
  112. /**
  113. * Return pie data month
  114. *
  115. * @return json
  116. */
  117. public function getStatisticFormDealer(){
  118. $company_label = array(); $total_form_company = array(); $color = array();
  119. $company = Company::where('team','Dealer')->get();
  120. if(!empty($company)){
  121. foreach ($company as $key => $c) {
  122. array_push($company_label, $c->name.'('.count(Form::where('company_id', $c->_id)->get()).')');
  123. array_push($color, $c->color);
  124. array_push($total_form_company, count(Form::where('company_id', $c->_id)->get()));
  125. }
  126. }
  127. $data = array();
  128. array_push($data, $company_label, $color, $total_form_company);
  129. return $this->sendResponse($data, 'array');
  130. }
  131. /**
  132. * Return pie data month
  133. *
  134. * @return json
  135. */
  136. public function getDealerStatisticFormFilter($start,$end,$company_id,$agent){
  137. $client1 = new \GuzzleHttp\Client();
  138. $request1 = $client1->get('https://cumas.swisslink.com.my/api/form/application/'.$start.'/'.$end.'/null/null/null/'.$company_id.'/'.$agent);
  139. $response1 = json_decode($request1->getBody()->getContents());
  140. $client2 = new \GuzzleHttp\Client();
  141. $request2 = $client2->get('https://cumas.swisslink.com.my/api/form/pending/'.$start.'/'.$end.'/null/null/null/'.$company_id.'/'.$agent);
  142. $response2 = json_decode($request2->getBody()->getContents());
  143. $client3 = new \GuzzleHttp\Client();
  144. $request3 = $client3->get('https://cumas.swisslink.com.my/api/form/activated/'.$start.'/'.$end.'/null/null/null/'.$company_id.'/'.$agent);
  145. $response3 = json_decode($request3->getBody()->getContents());
  146. $client4 = new \GuzzleHttp\Client();
  147. $request4 = $client4->get('https://cumas.swisslink.com.my/api/form/rejected/'.$start.'/'.$end.'/New/null/null/'.$company_id);
  148. $response4 = json_decode($request4->getBody()->getContents());
  149. $new = $response1->recordsTotal;
  150. $pending = $response2->recordsTotal;
  151. $completed = $response3->recordsTotal;
  152. $rejected = $response4->recordsTotal;
  153. $data = array();
  154. array_push($data, $new, $pending, $completed);
  155. $total = $new + $pending + $completed + $rejected;
  156. return $this->sendResponse($new, '');
  157. }
  158. /**
  159. * Return pie data Daily Dealer
  160. *
  161. * @return json
  162. */
  163. public function getStatisticFormDealerDaily(){
  164. $dateS = Carbon::createFromFormat('Y-m-d', date('Y-m-d'));
  165. $start = $dateS->copy()->startOfDay();
  166. $end = $dateS->copy()->endOfDay();
  167. $nested = array();
  168. $dealer_form = array();
  169. $color = array();
  170. $company = Company::where('team','Dealer')->get();
  171. if(!empty($company)){
  172. array_push($dealer_form, array('Task', 'Hours per Day'));
  173. foreach($company as $c){
  174. $form = Form::where('company_id',$c->_id)->whereBetween('created_at', array($start, $end))->count();
  175. array_push($color, $c->color);
  176. array_push($dealer_form, array($c->name, $form));
  177. }
  178. }
  179. array_push($nested, $color);
  180. array_push($nested, $dealer_form);
  181. return $this->sendResponse($nested, 'array');
  182. }
  183. /**
  184. * Return pie data month Dealer
  185. *
  186. * @return json
  187. */
  188. public function getStatisticFormDealerMontly($company_id,$dealer_id)
  189. {
  190. $jan = array(); $feb = array(); $mac = array(); $april = array(); $may = array(); $jun = array();
  191. $july = array(); $august = array(); $sep = array(); $oct = array(); $nov = array(); $dec = array();
  192. if($dealer_id == 'null'){
  193. $dealer_form = Form::where('company_id',$company_id)->get();
  194. }else{
  195. $dealer_form = Form::where('dealer_id',$dealer_id)->get();
  196. }
  197. foreach ($dealer_form as $key => $d) {
  198. $mY = Carbon::parse($d->created_at)->format('m/Y');
  199. if($mY == '01/2019'){
  200. $jan[] = $d;
  201. }else if($mY == '02/2019'){
  202. $feb[] = $d;
  203. }else if($mY == '03/2019'){
  204. $mac[] = $d;
  205. }else if($mY == '04/2019'){
  206. $april[] = $d;
  207. }else if($mY == '05/2019'){
  208. $may[] = $d;
  209. }else if($mY == '06/2019'){
  210. $jun[] = $d;
  211. }else if($mY == '07/2019'){
  212. $july[] = $d;
  213. }else if($mY == '08/2019'){
  214. $august[] = $d;
  215. }else if($mY == '09/2019'){
  216. $sep[] = $d;
  217. }else if($mY == '10/2019'){
  218. $oct[] = $d;
  219. }else if($mY == '11/2019'){
  220. $nov[] = $d;
  221. }else if($mY == '12/2019'){
  222. $dec[] = $d;
  223. }
  224. }
  225. $total_dealer_form = array();
  226. array_push($total_dealer_form,count($jan),count($feb),count($mac),count($april),count($may),count($jun),count($july),count($august),count($sep),count($oct),count($nov),count($dec));
  227. $data = array();
  228. $label = Company::where('_id', $company_id)->first();
  229. $label = '# of Forms Submitted ('.$label->name.')';
  230. array_push($data, $label, $total_dealer_form);
  231. return $this->sendResponse($data, 'array');
  232. }
  233. }