| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
-
- namespace App\Http\Controllers\v3\Api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\v3\Api\BaseController;
-
- use Carbon\Carbon;
-
- use App\SiteSetting;
- use App\LatestModel\Staff;
- use App\LatestModel\StaffDetail;
- use App\LatestModel\Module\Form;
- use App\LatestModel\Module\Subscriber;
- use App\LatestModel\Module\WorkOrder;
- use App\LatestModel\Module\PackageDetail;
- use App\LatestModel\Module\Docket;
-
- use App\LatestModel\Module\Coverage;
- use App\LatestModel\Module\DealerClaim;
- use App\LatestModel\Module\Company;
- use App\LatestModel\Module\Commission;
- use App\LatestModel\Module\Product;
-
- class StatisticController extends BaseController
- {
-
- /**
- * Return pie data overview
- *
- * @return json
- */
- public function getStatisticFormOverview(){
-
- $rejected = count(Form::onlyTrashed()->get());
- $rec = count(Form::where('type_service','Rectification')->get());
- $dealer = count(Form::whereNotNull('dealer_id')->get());
- $normal = count(Form::whereNull('dealer_id')->get());
-
- $data = array();
- array_push($data, $rec, $dealer, $normal, $rejected);
- return $this->sendResponse($data, '');
- }
-
- /**
- * Return pie data month
- *
- * @return json
- */
- public function getStatisticFormMonth()
- {
-
- $jan = array(); $feb = array(); $mac = array(); $april = array(); $may = array(); $jun = array();
- $july = array(); $august = array(); $sep = array(); $oct = array(); $nov = array(); $dec = array();
- $jan1 = array(); $feb1 = array(); $mac1 = array(); $april1 = array(); $may1 = array(); $jun1 = array();
- $july1 = array(); $august1 = array(); $sep1 = array(); $oct1 = array(); $nov1 = array(); $dec1 = array();
-
- $dealer_form = Form::whereNotNull('dealer_id')->where('type_service','!=','Rectification')->get();
- foreach ($dealer_form as $key => $d) {
- $mY = Carbon::parse($d->created_at)->format('m/Y');
- if($mY == '01/2019'){
- $jan[] = $d;
- }else if($mY == '02/2019'){
- $feb[] = $d;
- }else if($mY == '03/2019'){
- $mac[] = $d;
- }else if($mY == '04/2019'){
- $april[] = $d;
- }else if($mY == '05/2019'){
- $may[] = $d;
- }else if($mY == '06/2019'){
- $jun[] = $d;
- }else if($mY == '07/2019'){
- $july[] = $d;
- }else if($mY == '08/2019'){
- $august[] = $d;
- }else if($mY == '09/2019'){
- $sep[] = $d;
- }else if($mY == '10/2019'){
- $oct[] = $d;
- }else if($mY == '11/2019'){
- $nov[] = $d;
- }else if($mY == '12/2019'){
- $dec[] = $d;
- }
- }
-
- $total_dealer_form = array();
- 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));
-
- $normal_form = Form::whereNull('dealer_id')->where('type_service','!=','Rectification')->get();
- foreach ($normal_form as $key => $d) {
- $mY = Carbon::parse($d->created_at)->format('m/Y');
- if($mY == '01/2019'){
- $jan1[] = $d;
- }else if($mY == '02/2019'){
- $feb1[] = $d;
- }else if($mY == '03/2019'){
- $mac1[] = $d;
- }else if($mY == '04/2019'){
- $april1[] = $d;
- }else if($mY == '05/2019'){
- $may1[] = $d;
- }else if($mY == '06/2019'){
- $jun1[] = $d;
- }else if($mY == '07/2019'){
- $july1[] = $d;
- }else if($mY == '08/2019'){
- $august1[] = $d;
- }else if($mY == '09/2019'){
- $sep1[] = $d;
- }else if($mY == '10/2019'){
- $oct1[] = $d;
- }else if($mY == '11/2019'){
- $nov1[] = $d;
- }else if($mY == '12/2019'){
- $dec1[] = $d;
- }
- }
-
- $total_normal_form = array();
- 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));
-
- $data = array();
- array_push($data, $total_dealer_form, $total_normal_form);
- return $this->sendResponse($data, 'array');
- }
-
- /**
- * Return pie data month
- *
- * @return json
- */
- public function getStatisticFormDealer(){
-
- $company_label = array(); $total_form_company = array(); $color = array();
- $company = Company::where('team','Dealer')->get();
- if(!empty($company)){
- foreach ($company as $key => $c) {
- array_push($company_label, $c->name.'('.count(Form::where('company_id', $c->_id)->get()).')');
- array_push($color, $c->color);
- array_push($total_form_company, count(Form::where('company_id', $c->_id)->get()));
- }
- }
-
- $data = array();
- array_push($data, $company_label, $color, $total_form_company);
- return $this->sendResponse($data, 'array');
-
- }
-
- /**
- * Return pie data month
- *
- * @return json
- */
-
- public function getDealerStatisticFormFilter($start,$end,$company_id,$agent){
-
- $client1 = new \GuzzleHttp\Client();
- $request1 = $client1->get('https://cumas.swisslink.com.my/api/form/application/'.$start.'/'.$end.'/null/null/null/'.$company_id.'/'.$agent);
- $response1 = json_decode($request1->getBody()->getContents());
-
- $client2 = new \GuzzleHttp\Client();
- $request2 = $client2->get('https://cumas.swisslink.com.my/api/form/pending/'.$start.'/'.$end.'/null/null/null/'.$company_id.'/'.$agent);
- $response2 = json_decode($request2->getBody()->getContents());
-
- $client3 = new \GuzzleHttp\Client();
- $request3 = $client3->get('https://cumas.swisslink.com.my/api/form/activated/'.$start.'/'.$end.'/null/null/null/'.$company_id.'/'.$agent);
- $response3 = json_decode($request3->getBody()->getContents());
-
- $client4 = new \GuzzleHttp\Client();
- $request4 = $client4->get('https://cumas.swisslink.com.my/api/form/rejected/'.$start.'/'.$end.'/New/null/null/'.$company_id);
- $response4 = json_decode($request4->getBody()->getContents());
-
- $new = $response1->recordsTotal;
- $pending = $response2->recordsTotal;
- $completed = $response3->recordsTotal;
- $rejected = $response4->recordsTotal;
-
- $data = array();
- array_push($data, $new, $pending, $completed);
- $total = $new + $pending + $completed + $rejected;
- return $this->sendResponse($new, '');
- }
-
- /**
- * Return pie data Daily Dealer
- *
- * @return json
- */
- public function getStatisticFormDealerDaily(){
- $dateS = Carbon::createFromFormat('Y-m-d', date('Y-m-d'));
- $start = $dateS->copy()->startOfDay();
- $end = $dateS->copy()->endOfDay();
-
- $nested = array();
- $dealer_form = array();
- $color = array();
- $company = Company::where('team','Dealer')->get();
- if(!empty($company)){
- array_push($dealer_form, array('Task', 'Hours per Day'));
- foreach($company as $c){
- $form = Form::where('company_id',$c->_id)->whereBetween('created_at', array($start, $end))->count();
- array_push($color, $c->color);
- array_push($dealer_form, array($c->name, $form));
- }
- }
-
- array_push($nested, $color);
- array_push($nested, $dealer_form);
- return $this->sendResponse($nested, 'array');
- }
-
- /**
- * Return pie data month Dealer
- *
- * @return json
- */
- public function getStatisticFormDealerMontly($company_id,$dealer_id)
- {
-
- $jan = array(); $feb = array(); $mac = array(); $april = array(); $may = array(); $jun = array();
- $july = array(); $august = array(); $sep = array(); $oct = array(); $nov = array(); $dec = array();
-
- if($dealer_id == 'null'){
- $dealer_form = Form::where('company_id',$company_id)->get();
- }else{
- $dealer_form = Form::where('dealer_id',$dealer_id)->get();
- }
- foreach ($dealer_form as $key => $d) {
- $mY = Carbon::parse($d->created_at)->format('m/Y');
- if($mY == '01/2019'){
- $jan[] = $d;
- }else if($mY == '02/2019'){
- $feb[] = $d;
- }else if($mY == '03/2019'){
- $mac[] = $d;
- }else if($mY == '04/2019'){
- $april[] = $d;
- }else if($mY == '05/2019'){
- $may[] = $d;
- }else if($mY == '06/2019'){
- $jun[] = $d;
- }else if($mY == '07/2019'){
- $july[] = $d;
- }else if($mY == '08/2019'){
- $august[] = $d;
- }else if($mY == '09/2019'){
- $sep[] = $d;
- }else if($mY == '10/2019'){
- $oct[] = $d;
- }else if($mY == '11/2019'){
- $nov[] = $d;
- }else if($mY == '12/2019'){
- $dec[] = $d;
- }
- }
-
- $total_dealer_form = array();
- 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));
-
- $data = array();
- $label = Company::where('_id', $company_id)->first();
- $label = '# of Forms Submitted ('.$label->name.')';
- array_push($data, $label, $total_dealer_form);
- return $this->sendResponse($data, 'array');
- }
-
- }
|