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, "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'); } }