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; $building = $f->Subscriber->street; $address = $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(){ $dateS = Carbon::createFromFormat('Y-m-d', '2020-01-01'); $start = $dateS->copy()->startOfDay(); $dateE = Carbon::createFromFormat('Y-m-d', '2020-06-17'); $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); $labelD = $c->name; }else{ $labelD = ""; } $amount_claim= DealerClaim::where('wo',$f->WorkOrder->wo)->get(); 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; $building = $f->Subscriber->street; $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state; } $woD = '-'; $woId = 'none'; if(!empty($f->WorkOrder)){ $woId = $f->WorkOrder->wo; if(!empty($f->WorkOrder->Docket)){ $woD = $f->WorkOrder->Docket->end_job; // 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(), // "package_contract" => $f->PackageDetail->contract, // "package_name" => $f->PackageDetail->name, // 'dealer' => $labelD, // 'wo' => $woId, // 'activated_date' => $woD, // )); } } // 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(), // "package_contract" => $f->PackageDetail->contract, // "package_name" => $f->PackageDetail->name, // 'dealer' => $labelD, // 'wo' => $woId, // 'activated_date' => $woD, // )); array_push($result,array( 'Dealer Name' => $labelD, "Customer Name"=> $name, 'Completion Date' => $woD, "Form Type" => $f->type_service, "Package"=> $f->PackageDetail->contract, "WO No" => $woId, "DO No" => $f->WorkOrder->docket_id, "Service Type" => $f->WorkOrder->nature_work, "Building"=>$building, "Rating" => $f->WorkOrder->Docket->Rating1, "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'); } }