123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <?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\Staff;
- use App\Model\StaffDetail;
- use App\Model\Docket;
- use App\Model\WorkOrder;
- use App\Model\Company;
- Use App\Model\Form;
- Use App\Model\PackageDetail;
- Use App\Model\Subscriber;
-
- Use Hash;
- use Carbon\Carbon;
- use Crypt;
- use File;
- use Mail;
-
- class MynixController extends BaseController
- {
-
- public function workOrderStatistics(){
-
- $pc = count(WorkOrder::where('status','Pending Contractor')->get());
- $pi = count(WorkOrder::where('status','Pending Installer')->get());
- $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
- $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
- $rs = count(WorkOrder::where('status','Reschedule')->get());
- $ss = count(WorkOrder::where('status','Suspend')->get());
- $cm = count(WorkOrder::where('status','Completed')->get());
-
- $data = array();
- $data[] = array("status" => "Pending Contractor", "statistic" => $pc);
- $data[] = array("status" => "Pending Installer", "statistic" => $pi);
- $data[] = array("status" => "Pending Non Prelaid", "statistic" => $pp);
- $data[] = array("status" => "Success Non Prelaid", "statistic" => $sp);
- $data[] = array("status" => "Reschedule", "statistic" => $rs);
- $data[] = array("status" => "Suspend", "statistic" => $ss);
- $data[] = array("status" => "Completed", "statistic" => $cm);
-
- return $this->sendResponse($data, 'Get Statistic Successfully');
-
- }
-
- public function workOrderList(){
-
- $data = array();
- $installer = ''; $type = ''; $n1 = '';
- $curr = Carbon::now()->getTimestamp();
-
- $work_order = WorkOrder::orderBy('created_at', 'desc')->get();
- if(!empty($work_order)){
- foreach ($work_order as $key => $w) {
-
- $reg_time = $w->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }else{
- $n1 = "";
- }
-
- $form = Form::with('PackageDetail','Subscriber')->first();
- if(!empty($form)){
- $company = Company::where('_id',$w->contractor_id)->first();
-
- $staff = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
- if(!empty($staff)){
- $installer = $staff->StaffDetail->name;
- }else{
- $installer = '';
- }
-
- $address = '';
- if($form->type_application == 'R'){
- if($form->Subscriber->street != ''){
- $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
- }else {
- $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
- }
-
- }else if($form->type_application == 'B'){
-
- if($form->Subscriber->unit_no != ''){
- $unit = $form->Subscriber->unit_no;
- }else {
- $unit = ' ';
- }
-
- if ($form->Subscriber->building_name == null) {
- $address = $unit . ' , ' .$form->Subscriber->street . ' , ' .$form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
- } else {
- $address = $unit . ' , ' . $form->Subscriber->street . ' , ' .$form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
- }
-
- }
-
- if($form->type_application == 'R'){
- $type = 'Residential';
- }else if($form->type_application == 'B'){
- $type = 'Business';
- }
-
- array_push($data,array(
- "work_order_id" => $n1.$w->wo,
- "type" => $type,
- "contractor" => $company->name,
- "installer" => $installer,
- "title" => $w->nature_work,
- "appoint_date_time"=>date("m/d/Y H:i", strtotime($w->dateTimeStart)),
- "cus_name"=> $form->Subscriber->name,
- "contact_person" => $form->Subscriber->name,
- "contact_no"=> $form->Subscriber->phone1,
- "technical" => $form->Subscriber->name,
- "address"=> $address,
- "status" => $w->status,
- ));
- }
- }
-
- return $this->sendResponse($data, 'Get Work Order List Successfully');
- }
- }
-
-
- public function getCustomerList(){
-
- $data = array(); $i = 1;
- $n1 = ''; $address = ''; $building = ''; $status = '';
- $curr = Carbon::now()->getTimestamp();
-
- $form_submitted = Form::with('PackageDetail','Subscriber','WorkOrder')->withTrashed()->orderBy('created_at', 'desc')->get();
- if(!empty($form_submitted)){
- foreach ($form_submitted as $key => $v) {
-
- if(!empty($v->Subscriber)){
- if(empty($v->WorkOrder)){
-
- $i++;
- $reg_time = $v->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }else{
- $n1 = "";
- }
-
- if($v->type_application == 'R'){
- if($v->Subscriber->street != ''){
- $address = $v->Subscriber->unit_no. ' , '.$v->Subscriber->street. ' , '.$v->Subscriber->building_name. ' , '.$v->Subscriber->postcode. ' , '.$v->Subscriber->city. ' , '.$v->Subscriber->state;
- }else {
- $address = $v->Subscriber->unit_no. ' , '.$v->Subscriber->building_name. ' , '.$v->Subscriber->postcode. ' , '.$v->Subscriber->city. ' , '.$v->Subscriber->state;
- }
-
- }else if($v->type_application == 'B'){
-
- if ($v->Subscriber->unit_no != '') {
- $unit = $v->Subscriber->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($v->Subscriber->building_name == null) {
- $address = $unit . ' , ' . $v->Subscriber->street . ' , ' . $v->Subscriber->postcode . ' , ' . $v->Subscriber->city . ' , ' . $v->Subscriber->state;
- } else {
- $address = $unit . ' , ' . $v->Subscriber->street . ' , ' . $v->Subscriber->building_name . ' , ' . $v->Subscriber->postcode . ' , ' . $v->Subscriber->city . ' , ' . $v->Subscriber->state;
- }
-
- }
- }
-
- if(!empty($v->deleted_at)){
- $status = 'Rejected';
- }else if($v->status_email == 'unverified') {
- $status = 'New';
- }else if($v->status_email == 'verified') {
- $status = 'Accepted';
- }
-
- array_push($data, array(
- 'formT' => $n1.$i.$v->type_application,
- 'type' => $v->type_service,
- 'subscriber_id' => $v->Subscriber->subscriber_id,
- 'name' => $v->Subscriber->name,
- 'phone' => $v->Subscriber->phone1,
- 'email' => $v->Subscriber->email,
- 'address' => $address,
- 'postcode' => $v->Subscriber->postcode,
- 'city' => $v->Subscriber->city,
- 'status' => $status,
- 'date_submitted' => Carbon::parse($v->created_at)->toDateTimeString()
- ));
- }
- }
-
- return $this->sendResponse($data, 'Get Customer List Successfully');
-
- }else{
- return $this->sendError('', 'No Data Been Found!');
- }
- }
-
- public function customerStatistic(){
-
- $finalD1 = array(); $finalD2 = array(); $finalD3 = array(); $finalD4 = array();
- $form_submitted1 = Form::with('PackageDetail','Subscriber','WorkOrder')->withTrashed()->orderBy('created_at', 'desc')->get();
- if(!empty($form_submitted1)){
- foreach ($form_submitted1 as $key => $v) {
- if(!empty($v->Subscriber)){
- if(empty($v->WorkOrder)){
- $finalD1[] = $v;
- }
- }
- }
- }
-
- $form_submitted2= Form::onlyTrashed()->get();
- if(!empty($form_submitted2)){
- foreach ($form_submitted2 as $key => $v) {
- if(!empty($v->Subscriber)){
- if(empty($v->WorkOrder)){
- $finalD2[] = $v;
- }
- }
- }
- }
-
- $form_submitted3= Form::get();
- if(!empty($form_submitted3)){
- foreach ($form_submitted3 as $key => $v) {
- if(!empty($v->Subscriber)){
- if(empty($v->WorkOrder)){
- if($v->status_email == 'verified') {
- $finalD3[] = $v;
- }else if($v->status_email == 'unverified'){
- $finalD4[] = $v;
- }
- }
- }
- }
- }
-
- $total = count($finalD1);
- $new = count($finalD4);
- $reject = count($finalD2);
- $accepted = count($finalD3);
-
- $data = array();
- $data[] = array("status" => "New", "statistic" => $new);
- $data[] = array("status" => "Rejected", "statistic" => $reject);
- $data[] = array("status" => "Accepted", "statistic" => $accepted);
- $data[] = array("status" => "Total", "statistic" => $total);
-
- return $this->sendResponse($data, 'Get Registration Statistic Successfully');
-
- }
- }
|