123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837 |
- <?php
-
- namespace App\Http\Controllers\Contractor;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Log;
-
- use Carbon\Carbon;
- use Validator;
- use PDF;
-
- use App\Staff;
- use App\Model\StaffDetail;
- use App\Model\Form;
- use App\Model\Subscriber;
- use App\Model\Coverage;
- use App\Model\FormStatus;
- use App\Model\WorkOrder;
- use App\Model\Docket;
- Use App\Model\DealerClaim;
- use App\Model\Commission;
- use App\Model\Company;
- use App\Model\Product;
-
- class DocketController extends Controller
- {
-
- public function encryptPassword($action, $string) {
- $output = false;
- $encrypt_method = "AES-256-CBC";
- $secret_key = '28472B4B6250655368566D5970337336';
- $secret_iv = md5(md5($string)); //'This is my secret iv';
-
- // hash
- $key = hash('sha256', $secret_key);
-
- $iv = substr(hash('sha256', $secret_iv), 0, 16);
- if ( $action == 'encrypt' ) {
- $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
- $output = base64_encode($output);
- } else if( $action == 'decrypt' ) {
- $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
- }
- return $output;
- }
-
- /************************************************************************************* Next Step *************************************************************************************/
-
-
-
- public function viewContractorDocket()
- {
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $pp = count(WorkOrder::where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $sp = count(WorkOrder::where('status','Success Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $rs = count(WorkOrder::where('status','Reschedule')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $ss = count(WorkOrder::where('status','Suspend')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $cm = count(WorkOrder::where('status','Completed')->where('contractor_id',$user->StaffDetail->company_id)->get());
-
- $installer = StaffDetail::where('company_id',$user->StaffDetail->company_id)->get();
-
- return view('contractor.view_docket',compact('user','pp','sp','rs','ss','cm'));
- }
-
- public function viewContractorTeam()
- {
- $id = Auth::guard('contractor')->id();
- $user = StaffLaravel::with('StaffDetailLaravel')->find($id);
-
- return view('contractor.view_team',compact('user'));
- }
-
- public function getContractorWork()
- {
-
- $id = Auth::guard('contractor')->id();
- $user = StaffLaravel::with('StaffDetailLaravel')->find($id);
- $curr = Carbon::now()->getTimestamp();
-
- $work_detail= WorkOrderLaravel::with('FormLaravel')->where('contractor_id',$user->StaffDetailLaravel->company_id)->orderBy('dateTimeStart', 'desc')->get();
-
- $i = 0;
- $nested_data = array();
- if(!empty($work_detail)){
- foreach ($work_detail as $a)
- {
- $i++; $y = ''; $n1 = '';
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
- $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
- $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
-
- $inst_name = '';
- if(!empty($installer)){
- $inst_name = $installer->name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$n1,
- 'nature_work' => $a->nature_work,
- 'wo'=>$a->wo,
- 'customer_name' => $formDetail->SubscribersLaravel->name,
- 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
- 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
- 'customer_building' => $formDetail->SubscribersLaravel->building_name,
- 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
- 'customer_city' => $formDetail->SubscribersLaravel->city,
- 'contractor_id' => $contractor->name,
- 'installer_id' => $inst_name,
- 'dateTimeEnd' => $a->dateTimeEnd,
- 'status' => $a->status,
- 'action' => $a->id,
- ));
- }
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function filterContractorWork($year, $month, $status)
- {
-
- $id = Auth::guard('contractor')->id();
- $user = StaffLaravel::with('StaffDetailLaravel')->find($id);
- $curr = Carbon::now()->getTimestamp();
-
- if($year == 'null' && $month == 'null' & $status !='null')
- {
- $nested_data = array();
- $work_detail = WorkOrderLaravel::with('FormLaravel')->where('contractor_id',$user->StaffDetailLaravel->company_id)->orderBy('dateTimeStart', 'desc')->where('status', $status)->get();
- $i = 0;
- $nested_data = array();
- if(!empty($work_detail)){
- foreach ($work_detail as $a)
- {
- $i++; $y = ''; $n1 = '';
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
- $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
- $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
-
- $inst_name = '';
- if(!empty($installer)){
- $inst_name = $installer->name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$n1,
- 'nature_work' => $a->nature_work,
- 'wo'=>$a->wo,
- 'customer_name' => $formDetail->SubscribersLaravel->name,
- 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
- 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
- 'customer_building' => $formDetail->SubscribersLaravel->building_name,
- 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
- 'customer_city' => $formDetail->SubscribersLaravel->city,
- 'contractor_id' => $contractor->name,
- 'installer_id' => $inst_name,
- 'dateTimeEnd' => $a->dateTimeEnd,
- 'status' => $a->status,
- 'action' => $a->id,
- ));
- }
- }
- }
-
- if($year=='null' && $month == 'null' & $status == 'null')
- {
- $nested_data = array();
- $work_detail = WorkOrderLaravel::with('FormLaravel')->where('contractor_id',$user->StaffDetailLaravel->company_id)->orderBy('dateTimeStart', 'desc')->get();
- $i = 0;
- $nested_data = array();
- if(!empty($work_detail)){
- foreach ($work_detail as $a)
- {
- $i++; $y = ''; $n1 = '';
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
- $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
- $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
-
- $inst_name = '';
- if(!empty($installer)){
- $inst_name = $installer->name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$n1,
- 'nature_work' => $a->nature_work,
- 'wo'=>$a->wo,
- 'customer_name' => $formDetail->SubscribersLaravel->name,
- 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
- 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
- 'customer_building' => $formDetail->SubscribersLaravel->building_name,
- 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
- 'customer_city' => $formDetail->SubscribersLaravel->city,
- 'contractor_id' => $contractor->name,
- 'installer_id' => $inst_name,
- 'dateTimeEnd' => $a->dateTimeEnd,
- 'status' => $a->status,
- 'action' => $a->id,
- ));
- }
- }
- }
-
- if($year!='null' && $month!='nulll' && $status !='null')
- {
- $nested_data = array();
- $start_month = $year."-".$month."-01 00:00:00";
- $end_month = $year."-".$month."-32 23:59:59";
-
- $work_detail = WorkOrderLaravel::with('FormLaravel')->where('contractor_id',$user->StaffDetailLaravel->company_id)->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->where('status',$status)->get();
- $i = 0;
- $nested_data = array();
- if(!empty($work_detail)){
- foreach ($work_detail as $a)
- {
- $i++; $y = ''; $n1 = '';
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
- $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
- $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
-
- $inst_name = '';
- if(!empty($installer)){
- $inst_name = $installer->name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$n1,
- 'nature_work' => $a->nature_work,
- 'wo'=>$a->wo,
- 'customer_name' => $formDetail->SubscribersLaravel->name,
- 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
- 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
- 'customer_building' => $formDetail->SubscribersLaravel->building_name,
- 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
- 'customer_city' => $formDetail->SubscribersLaravel->city,
- 'contractor_id' => $contractor->name,
- 'installer_id' => $inst_name,
- 'dateTimeEnd' => $a->dateTimeEnd,
- 'status' => $a->status,
- 'action' => $a->id,
- ));
- }
- }
- }
-
- if($year!='null' && $month!='null' && $status =='null')
- {
- $nested_data = array();
- $start_month = $year."-".$month."-01 00:00:00";
- $end_month = $year."-".$month."-32 23:59:59";
-
- $work_detail = WorkOrderLaravel::with('FormLaravel')->where('contractor_id',$user->StaffDetailLaravel->company_id)->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->get();
- $i = 0;
- $nested_data = array();
- if(!empty($work_detail)){
- foreach ($work_detail as $a)
- {
- $i++; $y = ''; $n1 = '';
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
- $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
- $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
-
- $inst_name = '';
- if(!empty($installer)){
- $inst_name = $installer->name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$n1,
- 'nature_work' => $a->nature_work,
- 'wo'=>$a->wo,
- 'customer_name' => $formDetail->SubscribersLaravel->name,
- 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
- 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
- 'customer_building' => $formDetail->SubscribersLaravel->building_name,
- 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
- 'customer_city' => $formDetail->SubscribersLaravel->city,
- 'contractor_id' => $contractor->name,
- 'installer_id' => $inst_name,
- 'dateTimeEnd' => $a->dateTimeEnd,
- 'status' => $a->status,
- 'action' => $a->id,
- ));
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getContractorDocket($year,$month,$day)
- {
-
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- if($year == 'null' && $month == 'null' && $day == 'null'){
- $docket= Docket::with('WorkOrder')->orderBy('created_at', 'desc')->get();
- }else if($year != 'null' && $month == 'null' && $day == 'null'){
-
- $timestamp = $year."-01-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfYear();
-
- $docket = Docket::with('WorkOrder')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
-
- }else if($year != 'null' && $month != 'null' && $day == 'null'){
-
- $timestamp = $year."-".$month."-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfMonth();
-
- $docket = Docket::with('WorkOrder')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- $i = 0; $n1 = ''; $building = '';
- $curr = Carbon::now()->getTimestamp();
- $tempD = array();
- $nested_data = array();
- if(!empty($docket)){
- foreach($docket as $d){
-
- if(!empty($d->WorkOrder->_id)){
- if($d->WorkOrder->contractor_id == $user->StaffDetail->company_id){
- $i++;
- $form = Form::with('Subscriber','PackageDetail')->where('_id',$d->WorkOrder->_id)->first();
- $company = Company::where('_id', $d->WorkOrder->contractor_id)->first();
- $installer = Staff::with('StaffDetail')->withTrashed()->where('_id', $d->installer_id)->first();
-
- if($form->type_application == 'R'){
- $building = $form->Subscriber->building_name;
- }else if($form->type_application == 'B'){
- if ($form->Subscriber->building_name != null) {
- $building = $form->Subscriber->building_name;
- } else {
- $building = $form->Subscriber->company_name;
- }
- }
-
- $reg_time = $d->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- array_push($tempD, array(
- 'index' => $n1.$i,
- 'docket_id' => $d->docket_id,
- 'work_order_id' => $d->work_order_id,
- 'nature_work' => $d->nature_work,
- 'contractor_id' => $company->name,
- 'installer_name' => $installer->StaffDetail->name,
- 'customer_id' => $building,
- 'installer_id' => $installer->StaffDetail->phone,
- 'end_job' => date('d/m/Y H:i', strtotime($d->end_job)),
- 'rating' => round((($d->Rating1 + $d->Rating2 + $d->Rating3)/15) * 100)."%",
- 'action' => $d->docket_id.'/'.$d->work_order_id
- ));
- }
- }
- }
- }
-
- foreach($tempD as $t){
- array_push($nested_data, array(
- 'index' => $t['index'],
- 'docket_id' => $t['docket_id'],
- 'work_order_id' => $t['work_order_id'],
- 'nature_work' => $t['nature_work'],
- 'contractor_id' => $t['contractor_id'],
- 'installer_name' => $t['installer_name'],
- 'customer_id' => $t['customer_id'],
- 'installer_id' => $t['installer_id'],
- 'end_job' => $t['end_job'],
- 'rating' =>$t['rating'],
- 'action' =>$t['action'],
- ));
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function filterContractorDocket($year, $month)
- {
- $year = $year;
- $month = $month;
- $nested_data = array();
- $arr = array();
- $i=0;
-
- if($year=='null' && $month=='null')
- {
- $docket= DocketLaravel::orderBy('created_at', 'desc')->get();
-
- if(!empty($docket))
- {
- foreach ($docket as $a)
- {
- $customer = Subscriber::where('_id', $a->customer_id)->first();
- $business = Business::where('_id', $a->customer_id)->first();
-
- if(!empty($customer))
- {
- $arr[]=$a;
- }
-
- if(!empty($business))
- {
- $arr[]=$a;
- }
- }
- }
-
- foreach($arr as $b)
- {
- $i++; $n1 = '';
-
- $tempContractor = CompanyLaravel::where('_id', $b->contractor_id)->first();
- $contractor = $tempContractor->name;
-
- $tempInstaller = StaffDetailLaravel::where('_id', $b->installer_id)->first();
-
- $tempCustomer = Subscriber::where('_id', $b->customer_id)->first();
- $tempBusiness = Business::where('_id', $b->customer_id)->first();
-
- if(!empty($tempCustomer))
- {
- $building = $tempCustomer->building;
- }
- else
- {
- $building = $tempBusiness->company_name;
- }
-
- if(!empty($tempInstaller))
- {
- array_push($nested_data, array(
- 'index' => $n1.$i,
- 'docket_id' => $b->docket_id,
- 'work_order_id' => $b->work_order_id,
- 'nature_work' => $b->nature_work,
- 'contractor_id' => $contractor,
- 'installer_name' => $tempInstaller->name,
- 'customer_id' => $building,
- 'installer_id' => $tempInstaller->phone,
- 'end_job' => $b->end_job,
- 'rating' => $b->Rating1
- ));
- }
- else
- {
- array_push($nested_data, array(
- 'index' => $n1.$i,
- 'docket_id' => $a->docket_id,
- 'work_order_id' => $a->work_order_id,
- 'nature_work' => $a->nature_work,
- 'contractor_id' => $contractor,
- 'installer_name' => '',
- 'customer_id' => $building,
- 'installer_id' => '',
- 'end_job' => $a->end_job,
- 'rating' => $a->Rating1
- ));
- }
- }
- }
-
- elseif($year!='' && $month=='null')
- {
- $timestamp = $year."-01-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfYear();
- // $time = Carbon::createFromTimeString($timestamp);
- // echo $month;
-
- $docket = DocketLaravel::whereBetween('created_at', [$go, $end_year])->get();
- if(!empty($docket))
- {
- foreach ($docket as $a)
- {
- $customer = Subscriber::where('_id', $a->customer_id)->first();
- $business = Business::where('_id', $a->customer_id)->first();
-
- if(!empty($customer))
- {
- $arr[]=$a;
- }
-
- if(!empty($business))
- {
- $arr[]=$a;
- }
- }
- }
-
- foreach($arr as $b)
- {
- $i++; $n1 = '';
-
- $tempContractor = CompanyLaravel::where('_id', $b->contractor_id)->first();
- $contractor = $tempContractor->name;
-
- $tempInstaller = StaffDetailLaravel::where('_id', $b->installer_id)->first();
-
- $tempCustomer = Subscriber::where('_id', $b->customer_id)->first();
- $tempBusiness = Business::where('_id', $b->customer_id)->first();
-
- if(!empty($tempCustomer))
- {
- $building = $tempCustomer->building;
- }
- else
- {
- $building = $tempBusiness->company_name;
- }
-
- if(!empty($tempInstaller))
- {
- array_push($nested_data, array(
- 'index' => $n1.$i,
- 'docket_id' => $b->docket_id,
- 'work_order_id' => $b->work_order_id,
- 'nature_work' => $b->nature_work,
- 'contractor_id' => $contractor,
- 'installer_name' => $tempInstaller->name,
- 'customer_id' => $building,
- 'installer_id' => $tempInstaller->phone,
- 'end_job' => $b->end_job,
- 'rating' => $b->Rating1
- ));
- }
- else
- {
- array_push($nested_data, array(
- 'index' => $n1.$i,
- 'docket_id' => $a->docket_id,
- 'work_order_id' => $a->work_order_id,
- 'nature_work' => $a->nature_work,
- 'contractor_id' => $contractor,
- 'installer_name' => '',
- 'customer_id' => $building,
- 'installer_id' => '',
- 'end_job' => $a->end_job,
- 'rating' => $a->Rating1
- ));
- }
- }
- }
-
- elseif($year!='' && $month !='')
- {
- $timestamp = $year."-".$month."-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfMonth();
- // $time = Carbon::createFromTimeString($timestamp);
-
- $docket = DocketLaravel::whereBetween('created_at', [$go, $end_year])->get();
- if(!empty($docket))
- {
- foreach ($docket as $a)
- {
- $customer = Subscriber::where('_id', $a->customer_id)->first();
- $business = Business::where('_id', $a->customer_id)->first();
-
- if(!empty($customer))
- {
- $arr[]=$a;
- }
-
- if(!empty($business))
- {
- $arr[]=$a;
- }
- }
- }
-
- foreach($arr as $b)
- {
- $i++; $n1 = '';
-
- $tempContractor = CompanyLaravel::where('_id', $b->contractor_id)->first();
- $contractor = $tempContractor->name;
-
- $tempInstaller = StaffDetailLaravel::where('_id', $b->installer_id)->first();
-
- $tempCustomer = Subscriber::where('_id', $b->customer_id)->first();
- $tempBusiness = Business::where('_id', $b->customer_id)->first();
-
- if(!empty($tempCustomer))
- {
- $building = $tempCustomer->building;
- }
- else
- {
- $building = $tempBusiness->company_name;
- }
-
- if(!empty($tempInstaller))
- {
- array_push($nested_data, array(
- 'index' => $n1.$i,
- 'docket_id' => $b->docket_id,
- 'work_order_id' => $b->work_order_id,
- 'nature_work' => $b->nature_work,
- 'contractor_id' => $contractor,
- 'installer_name' => $tempInstaller->name,
- 'customer_id' => $building,
- 'installer_id' => $tempInstaller->phone,
- 'end_job' => $b->end_job,
- 'rating' => $b->Rating1
- ));
- }
- // else
- // {
- // array_push($nested_data, array(
- // 'index' => $n1.$i,
- // 'docket_id' => $a->docket_id,
- // 'work_order_id' => $a->work_order_id,
- // 'nature_work' => $a->nature_work,
- // 'contractor_id' => $contractor,
- // 'installer_name' => '',
- // 'customer_id' => $building,
- // 'installer_id' => '',
- // 'end_job' => $a->end_job,
- // 'rating' => $a->Rating1
- // ));
- // }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getContractorTeam()
- {
- $id = Auth::guard('contractor')->id();
- $user = StaffLaravel::with('StaffDetailLaravel')->find($id);
- $agent = StaffLaravel::with('CompanyLaravel','StaffDetailLaravel')->where('roles_access','Installer')->get();
-
- $i = 0;
- $nested_data = array();
- foreach ($agent as $a)
- {
- $i++; $n1 = '';
-
- if($a->company_id == $user->StaffDetailLaravel->company_id){
- array_push($nested_data, array(
- 'index' => $n1.$i,
- 'user_pic' => $a->StaffDetailLaravel->user_pic,
- 'name' => $a->StaffDetailLaravel->name,
- 'ic' => $a->StaffDetailLaravel->ic,
- 'email' => $a->StaffDetailLaravel->email,
- 'phone' => $a->StaffDetailLaravel->phone,
- 'company_id' => $a->CompanyLaravel->name,
- 'position' => $a->StaffDetailLaravel->position,
- 'action' => $a->_id
- ));
-
- }
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function addContractorTeam()
- {
- return view('contractor.add_contractor');
- }
-
- public function requestAddContractorTeam(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'password' => 'min:8|confirmed',
- ]);
-
- if ($validator->fails()) {
- return redirect()->back()->withInput()->withErrors($validator);
- }
-
- $user = StaffLaravel::where('email', $request->get('email'))->first();
- if(empty($user))
- {
- $pass = $this->encryptPassword('encrypt', $request->get('password'));
-
- $dealerD = new StaffDetailLaravel;
- $dealerD->name = $request->get('aname');
- $dealerD->ic = $request->get('ic');
- $dealerD->email = $request->get('email');
- $dealerD->phone = $request->get('phone');
- $dealerD->company_id = $request->get('vendor');
- $dealerD->color = '';
- $dealerD->position = 'Installer';
- $dealerD->password = $pass;
- $dealerD->user_pic = 'assets/avatar/user.png';
-
- // Save Login Dealer
- $loginD = new StaffLaravel;
- $loginD->email = $request->get('email');
- $loginD->password = $pass;
- $loginD->roles_access = 'Installer';
- $loginD->company_id = $request->get('vendor');
- $loginD->last_login_at = '';
- $loginD->last_login_ip = '';
-
- // $loginData = [
- // 'email' => $request->get('email'),
- // 'password' => $pass,
- // 'roles_access' => 'Sales',
- // 'last_login_at' => '',
- // 'last_login_ip' => '',
- // ];
-
- $company = CompanyLaravel::where('_id', $request->get('vendor'))->first();
- $company->stafflaravel()->save($loginD);
- $loginD->staffdetaillaravel()->save($dealerD);
-
- return redirect()->back()->with('success_msg', '<strong>Success!</strong> register <strong>'.$request->get('email').'</strong>');
- }
- else
- {
- return redirect()->back()->withInput()->withErrors('Email already exist!');
- }
- }
-
- public function generateDocketPDF($do)
- {
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
- $docket = Docket::with('WorkOrder')->where('docket_id',$do)->first();
- if(!empty($docket)){
- $form = Form::with('Subscriber','PackageDetail')->where('_id',$docket->WorkOrder->_id)->first();
-
- $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 (empty($form->customer_category)){
- $category = '';
- }else {
- $category = $form->customer_category;
- }
-
- $product = Product::where('formT',$form->type_application)->where('speed',$form->PackageDetail->name)->first();
- $installer = Staff::with('StaffDetail')->where('_id',$docket->installer_id)->withTrashed()->first();
-
- if(empty($product)){
- $product = 'RMbps';
- }else {
- $product = $product->package_name;
- }
-
- $dateTime = Carbon::parse($docket->WorkOrder->dateTimeStart)->toDateTimeString();
- $edateTime = Carbon::parse($docket->end_job)->toDateTimeString();
-
- $pdf = PDF::loadView('pdf.docket-pdf',compact('docket','form','address','product','installer','dateTime','edateTime', 'category'));
- $pdf->setPaper('A4', 'potrait');
- return $pdf->stream();
- }
- }
- }
|