123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <?php
-
- namespace App\Http\Controllers\API;
-
- use Illuminate\Http\Request;
- use App\Http\Requests\RegisterRequest;
- use App\Http\Controllers\Api\BaseController;
- use Illuminate\Support\Facades\Auth;
-
- Use App\Model\Form;
- Use App\Model\DealerClaim;
- Use App\Model\Docket;
- Use App\Model\PackageDetail;
- Use App\Model\Subscriber;
- Use App\Model\WorkOrder;
- use App\Staff;
- use App\Model\StaffDetail;
- use App\Model\Company;
-
- use Carbon\Carbon;
-
- class FormController extends BaseController
- {
- /**
- /* Schedule Function
- **/
- public function getFormStatistic(Request $request)
- {
- $dateS = Carbon::createFromFormat('Y-m-d', '2019-12-12');
- $start = $dateS->copy()->startOfDay();
- $dateE = Carbon::createFromFormat('Y-m-d', '2020-02-11');
- $end = $dateE->copy()->endOfDay();
-
- $result = array();
- $data = Form::with('PackageDetail', 'Subscriber')->whereBetween('created_at', array($start, $end))->get();
- if(count($data) > 0) {
- foreach($data as $f) {
-
- $name = ''; $contact_no = '';
- $address = ''; $building = '';
- $labelD = '';
-
- if(!empty($f->dealer_id)){
- $c = Company::find($f->company_id);
- $labelD = $c->name;
- }else{
- $labelD = "";
- }
-
- if(!empty($f->Subscriber) && !empty($f->PackageDetail)){
- if($f->type_application == 'R'){
- $name = $f->Subscriber->name;
- $contact_no = $f->Subscriber->phone1;
- $building = $f->Subscriber->building_name;
- if($f->Subscriber->street != ''){
- $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
- }else {
- $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
- }
- }else if($f->type_application == 'B'){
- $name = $f->Subscriber->company_name;
- $contact_no = $f->Subscriber->company_num;
- if ($f->Subscriber->building_name == null) {
- $building = $f->Subscriber->street;
- $address = $f->Subscriber->postcode . ' , ' . $f->Subscriber->city . ' , ' . $f->Subscriber->state;
- } else {
- $building = $f->Subscriber->building_name;
- $address = $f->Subscriber->street . ' , ' . $f->Subscriber->postcode . ' , ' . $f->Subscriber->city . ' , ' . $f->Subscriber->state;
- }
- }
-
- if($f->Subscriber->city == 'Jasin'){
- array_push($result,array(
- 'type_application' => $f->type_application,
- "type_service" => $f->type_service,
- "customer_name"=> $name,
- "contact_no"=> $contact_no,
- "unit_no"=>$f->Subscriber->unit_no,
- "building"=>$building,
- "street"=>$address,
- "submitted_date" => $f->created_at->toDateTimeString(),
- 'dealer' => $labelD,
- ));
- }
-
- }
-
- }
-
- return json_encode($result);
- // return $this->sendResponse($result, 'Get Schedule Successfully');
- }else {
- return $this->sendError('Invalid User', 'User Not Exist!');
- }
- }
-
-
- public function get_data_form(Request $request){
-
- $dateS = Carbon::createFromFormat('Y-m-d', '2020-01-01');
- $start = $dateS->copy()->startOfDay();
- $dateE = Carbon::createFromFormat('Y-m-d', '2021-12-31');
- $end = $dateE->copy()->endOfDay();
-
- $result = array();
- // $data = Form::with('PackageDetail', 'Subscriber')->where('dealer_id', 'exists', false)->whereBetween('created_at', array($start, $end))->get();
-
- // $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->where('type_service', '!=', 'Rectification')->whereBetween('created_at', array($start, $end))->get();
-
- // $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->where('type_service','New')->whereBetween('created_at', array($start, $end))->get();
- // $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->withTrashed()->get();
- $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->whereBetween('created_at', array($start, $end))->get();
-
- if(count($data) > 0) {
- foreach($data as $f) {
-
- $name = ''; $contact_no = '';
- $address = ''; $building = '';
- $labelD = '';
-
- if(!empty($f->dealer_id)){
- $c = Company::find($f->company_id);
- if(!empty($c->name)){
- $labelD = $c->name;
- }
- }else{
- $labelD = "";
- }
-
- // $amount_claim="";
- // if(!empty($f->Subscriber->DealerClaim)){
- // $amount_claim = $f->Subscriber->DealerClaim->total_claim;
- // }
- $subscriber_id=''; $ic=''; $company_reg='';
- if(!empty($f->Subscriber) && !empty($f->PackageDetail)){
- if($f->type_application == 'R'){
- $name = $f->Subscriber->name;
- $ic = $f->Subscriber->ic;
- $subscriber_id = $f->Subscriber->subscriber_id;
- $contact_no = $f->Subscriber->phone1;
- $building = $f->Subscriber->building_name;
- if($f->Subscriber->street != ''){
- $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
- }else {
- $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
- }
- }else if($f->type_application == 'B'){
- $name = $f->Subscriber->company_name;
- $ic = $f->Subscriber->ic;
- $company_reg = $f->Subscriber->company_reg;
- $subscriber_id = $f->Subscriber->subscriber_id;
- $contact_no = $f->Subscriber->company_num;
- if ($f->Subscriber->building_name == null) {
- $building = $f->Subscriber->street;
- $address = $f->Subscriber->postcode . ' , ' . $f->Subscriber->city . ' , ' . $f->Subscriber->state;
- } else {
- $building = $f->Subscriber->building_name;
- $address = $f->Subscriber->street . ' , ' . $f->Subscriber->postcode . ' , ' . $f->Subscriber->city . ' , ' . $f->Subscriber->state;
- }
- }
-
- $woD = '-'; $woId = 'none'; $natureWork = ''; $doId = ''; $woRate=""; $installer_name=""; $contractor_name="";
- if(!empty($f->WorkOrder)){
- $woId = $f->WorkOrder->wo;
- $natureWork = $f->WorkOrder->nature_work;
- $doId = $f->WorkOrder->docket_id;
- $installer = StaffDetail::where('_id',$f->WorkOrder->installer_id)->get();
- foreach($installer as $installer) {
- $installer_name = $installer->name;
- }
- $contractor = Company::where('_id',$f->WorkOrder->contractor_id)->get();
- foreach($contractor as $contractor) {
- $contractor_name = $contractor->name;
- }
- if(!empty($f->WorkOrder->Docket)){
- $woD = $f->WorkOrder->Docket->end_job;
- $woRate = $f->WorkOrder->Docket->Rating1;
- }
- }
-
- array_push($result,array(
- 'type_application' => $f->type_application,
- 'customer_category' => $f->customer_category,
- "type_service" => $f->type_service,
- "customer_name"=> $name,
- "ic" => $ic,
- //"company_reg" => $company_reg,
- "subscriber_id" => $subscriber_id,
- "contact_no"=> $contact_no,
- "unit_no"=>$f->Subscriber->unit_no,
- "building"=>$building,
- "street"=>$address,
- "submitted_date" => $f->created_at->toDateTimeString(),
- "package_contract" => $f->PackageDetail->contract,
- "package_name" => $f->PackageDetail->name,
- 'dealer' => $labelD,
- 'wo' => $woId,
- 'activated_date' => $woD,
- 'installer_name' => $installer_name,
- 'contractor_name' => $contractor_name,
- ));
- // array_push($result,array(
- // // 'Installer' => $installerId,
- // 'Dealer Name' => $labelD,
- // "Customer Name"=> $name,
- // "Contact Number"=> $contact_no,
- // 'Completion Date' => $woD,
- // 'Type Application' => $f->type_application,
- // "Form Type" => $f->type_service,
- // "Package"=> $f->PackageDetail->contract,
- // "WO No" => $woId,
- // "DO No" => $doId,
- // "Service Type" => $f->PackageDetail->name,
- // "Building"=>$building,
- // "Rating" => $woRate,
- // // "Claim Amount" => $amount_claim,
- // ));
- }
-
- }
- }
-
- // return json_encode(count($result));
- return json_encode($result);
- }
-
- /***********************************
- /* Form Deleted by Company
- ***********************************/
- public function get_deleted_by_company($company_id)
- {
-
- $data = Form::with('PackageDetail', 'Subscriber')->withTrashed()->where('company_id', $company_id)->get();
-
-
- return $this->sendResponse($data, 'Form deleted by specific company');
- }
- }
|