| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786 |
- <?php
-
- namespace App\Http\Controllers\CustomerService;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
-
- use App\Mail\AssignWorkOrder;
- use App\Jobs\SendWorkOrder;
-
- 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\WorkOrder;
- use App\Model\PackageDetail;
- use App\Model\Company;
- use App\Model\Coverage;
- use App\Model\Product;
- use App\Model\Docket;
- use App\Model\FormStatus;
-
- class WorkOrderController extends Controller
- {
-
- function random_code($limit)
- {
- return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
- }
-
- function createWorkID()
- {
- $number = WorkOrder::select('id', 'wo')->orderBy('created_at', 'DESC')->first();
- $numberOnly = str_replace('WO-', '', $number->wo);
- info('before WO' . $numberOnly);
- $numberOnly++;
- info('after WO' . $numberOnly);
- return $numberOnly;
- }
-
- public function viewWorkOrder()
- {
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $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());
-
- $pc = count(WorkOrder::where('status', 'Pending Contractor')->get());
- $pi = count(WorkOrder::where('status', 'Pending Installer')->get());
- $cance = count(WorkOrder::where('status', 'Cancelled')->get());
-
- return view('customer-service.view_wo', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'pc', 'pi', 'cance'));
- }
-
- public function viewEditWorkOrder($wo)
- {
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $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());
-
- $w = WorkOrder::where('wo', $wo)->first();
- $form = Form::with('Subscriber', 'WorkOrder')->where('_id', $w->_id)->first();
- $coverage = Coverage::groupBy('building_name')->orderBy('building_name')->get();
-
- if ($w->contractor_id != '') {
- $company = Company::where('_id', $w->contractor_id)->first();
- } else {
- $company = '';
- }
-
- return view('customer-service.edit_work_order', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'pc', 'pi', 'form', 'coverage', 'company'));
- }
-
-
- public function viewAddNewSchedule($status, $wo, $subscriber_id)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $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());
-
- $company = Company::where('team', 'CBB')->get();
- $today = Carbon::today();
-
- $wo_status = '';
- if ($status == "non-prelaid") {
- $wo_status = 'Pending Non Prelaid';
- } else {
- $wo_status = 'Pending Contractor';
- }
-
- $subscriber = Subscriber::where('subscriber_id', $subscriber_id)->first();
- if (!empty($subscriber)) {
- $form = Form::with('WorkOrder')->where('_id', $subscriber->_id)->first();
- if (empty($form->WorkOrder)) {
-
- do {
- $woID = 'WO-' . $this->createWorkID();
- } while (WorkOrder::where("wo", "=", $woID)->first() instanceof WorkOrder);
-
- $work_order = new WorkOrder;
- $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
- $work_order->wo = $woID;
- $work_order->nature_work = '';
- $work_order->sub_category = '';
- $work_order->dateTimeStart = '';
- $work_order->dateTimeEnd = '';
- $work_order->contractor_id = '';
- $work_order->installer_id = '';
- $work_order->onu = '';
- $work_order->router = '';
- $work_order->need_phone = '';
- $work_order->no_phone = '';
- $work_order->pppoe_username = '';
- $work_order->pppoe_password = '';
- $work_order->docket_id = '';
- $work_order->remarks_custservice = '';
- $work_order->remarks_installer = '';
- $work_order->status = $wo_status;
- $work_order->created_by = '';
-
- $form->workorder()->save($work_order);
- } else {
- $work_order = WorkOrder::where('wo', $form->WorkOrder->wo)->first();
-
- $work_order->nature_work = '';
- $work_order->sub_category = '';
- $work_order->dateTimeStart = '';
- $work_order->dateTimeEnd = '';
- $work_order->contractor_id = '';
- $work_order->installer_id = '';
- $work_order->onu = '';
- $work_order->router = '';
- $work_order->need_phone = '';
- $work_order->no_phone = '';
- $work_order->pppoe_username = '';
- $work_order->pppoe_password = '';
- $work_order->docket_id = '';
- $work_order->remarks_custservice = '';
- $work_order->remarks_installer = '';
- $work_order->status = $wo_status;
- $work_order->created_by = '';
-
- $work_order->save();
- }
- }
- return view('customer-service.view_add_new_schedule', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'company', 'wo', 'today', 'subscriber_id', 'status'));
- }
-
- public function viewRescheduleCalendar($wo)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $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());
-
- $company = Company::where('team', 'CBB')->get();
- $today = Carbon::today();
-
- return view('customer-service.view_reschedule-work-order', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'company', 'wo', 'today'));
- }
-
- public function confirmWorkOrder($wo)
- {
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $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());
-
- $w = WorkOrder::where('wo', $wo)->first();
- $form = Form::with('Subscriber', 'WorkOrder')->where('_id', $w->_id)->first();
- $coverage = Coverage::groupBy('building_name')->orderBy('building_name')->get();
- $company = Company::where('_id', $w->contractor_id)->first();
-
- return view('customer-service.confirm_work_order', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'pc', 'pi', 'form', 'coverage', 'wo', 'company'));
- }
-
- public function viewCreateWorkOrderR()
- {
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $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());
-
- $coverage = Coverage::where('Type', 'R')->groupBy('building_name')->orderBy('building_name')->get();
- $product = Product::where('formT', 'R')->get();
-
- return view('customer-service.view_wo_formR', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'pc', 'pi', 'coverage', 'product'));
- }
-
- public function viewCreateWorkOrderB()
- {
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $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());
-
- $coverage = Coverage::where('Type', 'B')->get();
- $product = Product::where('formT', 'B')->get();
-
- return view('customer-service.view_wo_formB', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'pc', 'pi', 'coverage', 'product'));
- }
-
- public function getAllPendingContractor($year, $month, $day)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0;
- $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if ($month == 'null' && $day == 'null') {
- $wo = WorkOrder::with('Form')->where('status', 'Pending Contractor')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Pending Contractor')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Pending Contractor')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- if (!empty($wo)) {
- foreach ($wo as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
- $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
- $company = Company::where('_id', $w->contractor_id)->first();
-
- // info($w->installer_id);
- if ($w->installer_id != '') {
- $installer = Staff::with('StaffDetail')->where('_id', $w->installer_id)->first();
- $installer = $installer->StaffDetail->name;
- }
-
- $building = '';
- $unit = '-';
- $name = '';
-
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
-
- if ($form->type_application == 'R') {
- $name = $form->Subscriber->name;
- } else if ($form->type_application == 'B') {
- $name = $form->Subscriber->company_name;
- }
-
-
- if (empty($form->customer_category)) {
- $category = '';
- } else {
- $category = $form->customer_category;
- }
-
- if (empty($product)) {
- $product = 'R Mbps';
- } else {
- $product = $product->package_name;
- }
-
- if (empty($company)) {
- $company = ' ';
- } else {
- $company = $company->name;
- }
-
- if (empty($w->dateTimeStart)) {
- $date = '';
- $time = '';
- } else {
- $date = date("d/m/Y", strtotime($w->dateTimeStart));
- $time = date("h:i A", strtotime($w->dateTimeStart));
- }
-
- array_push($nested_data, array(
- 'formT' => $n1 . $i . $w->Form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->wo,
- 'category' => $category,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company,
- 'installer' => $installer,
- 'date' => $date,
- 'time' => $time,
- 'status' => $w->status,
- 'action' => $w->wo,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getAllPendingNonPrelaid($year, $month, $day)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0;
- $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if ($year == 'null' && $month == 'null' && $day == 'null') {
- $wo = WorkOrder::with('Form')->where('status', 'Pending Non Prelaid')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Pending Non Prelaid')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Pending Non Prelaid')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- if (!empty($wo)) {
- foreach ($wo as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
- $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
- $company = Company::where('_id', $w->contractor_id)->first();
-
- if ($w->installer_id != '') {
- $installer = Staff::with('StaffDetail')->where('_id', $w->installer_id)->first();
- $installer = $installer->StaffDetail->name;
- }
-
- $building = '';
- $unit = '-';
- $name = '';
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
-
- if ($form->type_application == 'R') {
- $name = $form->Subscriber->name;
- } else if ($form->type_application == 'B') {
- $name = $form->Subscriber->company_name;
- }
-
- if (empty($form->customer_category)) {
- $category = '';
- } else {
- $category = $form->customer_category;
- }
-
- if (empty($product)) {
- $product = 'R Mbps';
- } else {
- $product = $product->package_name;
- }
-
- if (empty($company)) {
- $company = ' ';
- } else {
- $company = $company->name;
- }
-
- if (empty($w->dateTimeStart)) {
- $date = '';
- $time = '';
- } else {
- $date = date("d/m/Y", strtotime($w->dateTimeStart));
- $time = date("h:i A", strtotime($w->dateTimeStart));
- }
-
- array_push($nested_data, array(
- 'formT' => $n1 . $i . $w->Form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->wo,
- 'category' => $category,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company,
- 'installer' => $installer,
- 'date' => $date,
- 'time' => $time,
- 'status' => $w->status,
- 'action' => $w->wo,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getAllSuccessNonPrelaid($year, $month, $day)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0;
- $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if ($year == 'null' && $month == 'null' && $day == 'null') {
- $wo = WorkOrder::with('Form')->where('status', 'Success Non Prelaid')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Success Non Prelaid')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Success Non Prelaid')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- if (!empty($wo)) {
- foreach ($wo as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
- $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
- $company = Company::where('_id', $w->contractor_id)->first();
-
- if ($w->installer_id != '') {
- $installer = Staff::with('StaffDetail')->where('_id', $w->installer_id)->withTrashed()->first();
- $installer = $installer->StaffDetail->name;
- }
-
- $building = '';
- $unit = '-';
- $name = '';
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
-
- if ($form->type_application == 'R') {
- $name = $form->Subscriber->name;
- } else if ($form->type_application == 'B') {
- $name = $form->Subscriber->company_name;
- }
-
- if (empty($form->customer_category)) {
- $category = '';
- } else {
- $category = $form->customer_category;
- }
-
- if (empty($product)) {
- $product = 'R Mbps';
- } else {
- $product = $product->package_name;
- }
-
- if (empty($company)) {
- $company = ' ';
- } else {
- $company = $company->name;
- }
-
- if (empty($w->dateTimeStart)) {
- $date = '';
- $time = '';
- } else {
- $date = date("d/m/Y", strtotime($w->dateTimeStart));
- $time = date("h:i A", strtotime($w->dateTimeStart));
- }
-
- array_push($nested_data, array(
- 'formT' => $n1 . $i . $w->Form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->wo,
- 'category' => $category,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company,
- 'installer' => $installer,
- 'date' => $date,
- 'time' => $time,
- 'status' => $w->status,
- 'action' => $w->wo,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getAllPendingInstaller($year, $month, $day)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0;
- $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if ($year == 'null' && $month == 'null' && $day == 'null') {
- $wo = WorkOrder::with('Form')->where('status', 'Pending Installer')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Pending Installer')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Pending Installer')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- if (!empty($wo)) {
- foreach ($wo as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
- $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
- $company = Company::where('_id', $w->contractor_id)->first();
-
- if ($w->installer_id != '') {
- $installer = Staff::with('StaffDetail')->where('_id', $w->installer_id)->first();
- if (!empty($installer)) {
- $installer = $installer->StaffDetail->name;
- }
- }
-
- $building = '';
- $unit = '-';
- $name = '';
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
-
- if ($form->type_application == 'R') {
- $name = $form->Subscriber->name;
- } else if ($form->type_application == 'B') {
- $name = $form->Subscriber->company_name;
- }
-
- if (empty($form->customer_category)) {
- $category = '';
- } else {
- $category = $form->customer_category;
- }
-
- if (empty($product)) {
- $product = 'R Mbps';
- } else {
- $product = $product->package_name;
- }
-
- if (empty($company)) {
- $company = ' ';
- } else {
- $company = $company->name;
- }
-
- if (empty($w->dateTimeStart)) {
- $date = '';
- $time = '';
- } else {
- $date = date("d/m/Y", strtotime($w->dateTimeStart));
- $time = date("h:i A", strtotime($w->dateTimeStart));
- }
-
- array_push($nested_data, array(
- 'formT' => $n1 . $i . $w->Form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->wo,
- 'category' => $category,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company,
- 'installer' => $installer,
- 'date' => $date,
- 'time' => $time,
- 'status' => $w->status,
- 'action' => $w->wo,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getAllReschedule($year, $month, $day)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0;
- $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if ($year == 'null' && $month == 'null' && $day == 'null') {
- $wo = WorkOrder::with('Form')->where('status', 'Reschedule')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Reschedule')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Reschedule')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- if (!empty($wo)) {
- foreach ($wo as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
- $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
- $company = Company::where('_id', $w->contractor_id)->first();
-
- if ($w->installer_id != '') {
- $installer = Staff::with('StaffDetail')->where('_id', $w->installer_id)->withTrashed()->first();
- $installer = $installer->StaffDetail->name;
- }
-
- $building = '';
- $unit = '-';
- $name = '';
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
-
- if ($form->type_application == 'R') {
- $name = $form->Subscriber->name;
- } else if ($form->type_application == 'B') {
- $name = $form->Subscriber->company_name;
- }
-
- if (empty($form->customer_category)) {
- $category = '';
- } else {
- $category = $form->customer_category;
- }
-
- if (empty($product)) {
- $product = 'R Mbps';
- } else {
- $product = $product->package_name;
- }
-
- if (empty($company)) {
- $company = ' ';
- } else {
- $company = $company->name;
- }
-
- if (empty($w->dateTimeStart)) {
- $date = '';
- $time = '';
- } else {
- $date = date("d/m/Y", strtotime($w->dateTimeStart));
- $time = date("h:i A", strtotime($w->dateTimeStart));
- }
-
-
- array_push($nested_data, array(
- 'formT' => $n1 . $i . $w->Form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->wo,
- 'category' => $category,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company,
- 'installer' => $installer,
- 'date' => $date,
- 'time' => $time,
- 'status' => $w->status . " (" . $w->remarks_installer . ")",
- 'action' => $w->wo,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getAllSuspend($year, $month, $day)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0;
- $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if ($year == 'null' && $month == 'null' && $day == 'null') {
- $wo = WorkOrder::with('Form')->where('status', 'Suspend')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Suspend')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Suspend')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- if (!empty($wo)) {
- foreach ($wo as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
- $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
- $company = Company::where('_id', $w->contractor_id)->first();
-
- if ($w->installer_id != '') {
- $installer = Staff::with('StaffDetail')->withTrashed()->where('_id', $w->installer_id)->first();
- $installer = $installer->StaffDetail->name;
- }
-
- $building = '';
- $unit = '-';
- $name = '';
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
-
- if ($form->type_application == 'R') {
- $name = $form->Subscriber->name;
- } else if ($form->type_application == 'B') {
- $name = $form->Subscriber->company_name;
- }
-
- if (empty($form->customer_category)) {
- $category = '';
- } else {
- $category = $form->customer_category;
- }
-
- if (empty($product)) {
- $product = 'R Mbps';
- } else {
- $product = $product->package_name;
- }
-
- if (empty($company)) {
- $company = ' ';
- } else {
- $company = $company->name;
- }
-
- if (empty($w->dateTimeStart)) {
- $date = '';
- $time = '';
- } else {
- $date = date("d/m/Y", strtotime($w->dateTimeStart));
- $time = date("h:i A", strtotime($w->dateTimeStart));
- }
-
- array_push($nested_data, array(
- 'formT' => $n1 . $i . $w->Form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->wo,
- 'category' => $category,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company,
- 'installer' => $installer,
- 'date' => $date,
- 'time' => $time,
- 'status' => $w->status . " (" . $w->remarks_installer . ")",
- 'action' => $w->wo,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getAllCancelled($year, $month, $day)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0;
- $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if ($year == 'null' && $month == 'null' && $day == 'null') {
- $wo = WorkOrder::with('Form')->where('status', 'Cancelled')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Suspend')->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();
-
- $wo = WorkOrder::with('Form')->where('status', 'Suspend')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- if (!empty($wo)) {
- foreach ($wo as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
- $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
- $company = Company::where('_id', $w->contractor_id)->first();
-
- if ($w->installer_id != '') {
- $installer = Staff::with('StaffDetail')->withTrashed()->where('_id', $w->installer_id)->first();
- $installer = $installer->StaffDetail->name;
- }
-
- $building = '';
- $unit = '-';
- $name = '';
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
-
- if ($form->type_application == 'R') {
- $name = $form->Subscriber->name;
- } else if ($form->type_application == 'B') {
- $name = $form->Subscriber->company_name;
- }
-
- if (empty($form->customer_category)) {
- $category = '';
- } else {
- $category = $form->customer_category;
- }
-
- if (empty($product)) {
- $product = 'R Mbps';
- } else {
- $product = $product->package_name;
- }
-
- if (empty($company)) {
- $company = ' ';
- } else {
- $company = $company->name;
- }
-
- if (empty($w->dateTimeStart)) {
- $date = '';
- $time = '';
- } else {
- $date = date("d/m/Y", strtotime($w->dateTimeStart));
- $time = date("h:i A", strtotime($w->dateTimeStart));
- }
-
- array_push($nested_data, array(
- 'formT' => $n1 . $i . $w->Form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->wo,
- 'category' => $category,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company,
- 'installer' => $installer,
- 'date' => $date,
- 'time' => $time,
- 'status' => $w->status,
- 'action' => $w->wo,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getAllCompleted($year, $month, $day)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0;
- $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if ($year == 'null' && $month == 'null' && $day == 'null') {
- $doc = Docket::with('WorkOrder')->orderBy('end_job', '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();
-
- $doc = Docket::with('WorkOrder')->orderBy('end_job', 'desc')->whereBetween('dateTimeStart', [$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();
-
- $doc = Docket::with('WorkOrder')->orderBy('end_job', 'desc')->whereBetween('dateTimeStart', [$go, $end_year])->get();
- }
-
- if (!empty($doc)) {
- foreach ($doc as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- if (!empty($w->WorkOrder->_id)) {
- $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->WorkOrder->_id)->first();
- $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $form->type_application)->first();
- $company = Company::where('_id', $w->WorkOrder->contractor_id)->first();
-
- if ($w->WorkOrder->installer_id != '') {
- $installer = Staff::with('StaffDetail')->withTrashed()->where('_id', $w->WorkOrder->installer_id)->first();
- $installer = $installer->StaffDetail->name;
- }
-
- $building = '';
- $unit = '-';
- $name = '';
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
-
- if ($form->type_application == 'R') {
- $name = $form->Subscriber->name;
- } else if ($form->type_application == 'B') {
- $name = $form->Subscriber->company_name;
- }
-
- if (empty($product)) {
- $product = 'R Mbps';
- } else {
- $product = $product->package_name;
- }
-
- if (empty($company)) {
- $company = ' ';
- } else {
- $company = $company->name;
- }
-
- if (empty($form->customer_category)) {
- $category = '';
- } else {
- $category = $form->customer_category;
- }
-
- array_push($nested_data, array(
- 'formT' => $n1 . $i . $form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->WorkOrder->wo,
- 'category' => $category,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company,
- 'installer' => $installer,
- 'date' => date("d/m/Y", strtotime($w->end_job)),
- 'time' => date("h:i A", strtotime($w->end_job)),
- 'status' => $w->WorkOrder->status,
- 'docket' => $w->docket_id,
- 'action' => $w->WorkOrder->wo,
- ));
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function generateWorkOrderPDF($wo)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $wo = WorkOrder::where('wo', $wo)->first();
- $form = Form::with('PackageDetail', 'Subscriber')->where('_id', $wo->_id)->first();
- $product = Product::where('formT', $form->type_application)->where('speed', $form->PackageDetail->name)->first();
-
- if (empty($form->customer_category)) {
- $category = '';
- } else {
- $category = $form->customer_category;
- }
-
- if (empty($product)) {
- if ($form->PackageDetail->name == "30") {
- $product = '30Mbps';
- } else {
- $product = 'RMbps';
- }
- } else {
- $product = $product->package_name;
- }
-
- $created_by = Staff::with('StaffDetail')->where("_id", $wo->created_by)->first();
- if (empty($created_by)) {
- $created_by = '';
- }
-
- $created_at = Carbon::parse($wo->created_at)->toDateTimeString();
-
- $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;
- }
- }
-
-
- $pdf = PDF::loadView('pdf.workorder-pdf', compact('wo', 'form', 'product', 'created_at', 'created_by', 'address', 'category'));
- $pdf->setPaper('A4', 'potrait');
- return $pdf->stream();
- }
-
- public function sendWorkOrders($work_order_id)
- {
-
- $work_order = WorkOrder::where('wo', $work_order_id)->first();
- $s = StaffDetail::where('company_id', $work_order->contractor_id)->where('position', 'Contractor')->get();
- $customer = Subscriber::where('_id', $work_order->_id)->first();
- if ($work_order->contractor_id == '5b42b935ee0dc2b707473b76') {
- $company = Company::where('_id', $work_order->contractor_id)->first();
- $staff = StaffDetail::where('company_id', $work_order->contractor_id)->where('email', 'mimi@jitech.com.my')->first();
- SendWorkOrder::dispatch($work_order, $staff, 'cbbinstallation@jitech.com.my', $customer, $company);
- } else {
- $company = Company::where('_id', $work_order->contractor_id)->first();
- foreach ($s as $staff) {
- SendWorkOrder::dispatch($work_order, $staff, $staff->email, $customer, $company);
- }
- }
- }
-
- public function updateWorkOrder(Request $request)
- {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $wo = WorkOrder::where('wo', $request->work_order)->first();
- if (!empty($wo)) {
-
- $number_phone = '';
- if ($request->n_phone == 'Yes') {
- $number_phone = $request->no_phone;
- }
-
- $wo->nature_work = $request->task;
- $wo->pppoe_username = $request->pppoe_username;
- $wo->onu = $request->onu_ont;
- $wo->router = $request->router;
- $wo->need_phone = $request->n_phone;
- $wo->no_phone = $number_phone;
- $wo->remarks_custservice = $request->remark;
- $wo->created_by = $user->_id;
- $wo->save();
-
- $form = Form::where('_id', $wo->_id)->first();
- $form->customer_category = $request->cust_category;
- $form->save();
- $contractor = Company::where('_id', $wo->contractor_id)->first();
-
- $status = '';
- $st_id = '';
- if ($wo->status == 'Pending Contractor') {
- $st_id = 4;
- $status = 'Pending Contractor';
- } else if ($wo->status == 'Pending Non Prelaid') {
- $st_id = 5;
- $status = 'Pending Non Prelaid';
- }
-
- $formH = new FormStatus;
- $formH->form_id = $form->_id;
- $formH->status_id = $st_id;
- $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
- $formH->status = $status;
- $formH->desc = 'This work order been assigned to particular contractor (' . $contractor->name . ')';
- $form->formstatus()->save($formH);
-
- $this->sendWorkOrders($request->work_order);
- return redirect('/customer-service/work-order/list');
- // return redirect()->back()->with('success_msg', 'Success! Update work order '.$request->get('work_order'));
- } else {
- return redirect()->back()->with('error_msg', 'Cant update work order ' . $request->get('work_order'));
- }
- }
-
- public function addSchedule(Request $request)
- {
-
- $subscriber = Subscriber::where('subscriber_id', $request->subscriber_id)->first();
- if (!empty($subscriber)) {
-
- $wod = WorkOrder::where('wo', $request->wo)->first();
- if (empty($wod)) {
-
- $status = '';
- if ($request->status == 'non-prelaid') {
- $status = 'Pending Non Prelaid';
- } else {
- $status = 'Pending Contractor';
- }
-
- $form = Form::where('_id', $subscriber->_id)->first();
- $work_order = new WorkOrder;
- $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
- $work_order->wo = $request->wo;
- $work_order->nature_work = '';
- $work_order->sub_category = '';
- $work_order->dateTimeStart = $request->start;
- $work_order->dateTimeEnd = $request->end;
- $work_order->contractor_id = $request->vendor;
- $work_order->installer_id = '';
- $work_order->onu = '';
- $work_order->router = '';
- $work_order->need_phone = '';
- $work_order->no_phone = '';
- $work_order->pppoe_username = '';
- $work_order->pppoe_password = '';
- $work_order->docket_id = '';
- $work_order->remarks_custservice = '';
- $work_order->remarks_installer = '';
- $work_order->status = $status;
- $work_order->created_by = $request->created_by;
-
- $form->workorder()->save($work_order);
-
- return 'success';
- } else {
-
- $wod->dateTimeStart = $request->start;
- $wod->dateTimeEnd = $request->end;
- $wod->contractor_id = $request->vendor;
- $wod->save();
- }
- } else {
- return 'false';
- }
- }
-
- public function rescheduleWorkOrder(Request $request)
- {
-
- $wod = WorkOrder::where('wo', $request->wo)->first();
- if (!empty($wod)) {
-
- $wod->dateTimeStart = $request->start;
- $wod->dateTimeEnd = $request->end;
- $wod->contractor_id = $request->vendor;
- $wod->status = 'Pending Contractor';
- $wod->save();
- return 'success';
- } else {
- return 'false';
- }
- }
-
- public function cancelCreateWorkOrder(Request $request)
- {
- $wod = WorkOrder::where('wo', $request->wo)->first();
- if (!empty($wod)) {
- $wod->delete();
- return 'true';
- } else {
- return 'false';
- }
- }
-
- public function deleteWorkOrder(Request $request)
- {
- $wod = WorkOrder::where('wo', $request->id)->first();
- if (!empty($wod)) {
- $wod->delete();
- $form = Form::where('_id', $wod->_id)->first();
- $formH = new FormStatus;
- $formH->form_id = $form->_id;
- $formH->status_id = 9;
- $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
- $formH->status = 'Delete Work Order';
- $formH->desc = 'This work order for this customer already been deleted!';
- $form->formstatus()->save($formH);
-
- return 'true';
- } else {
- return 'false';
- }
- }
-
- public function checkExistingWorkOrder(Request $request)
- {
- $data = array();
- $wod = WorkOrder::where('wo', $request->wo)->first();
- if (($wod->status == 'Pending Contractor' || $wod->status == '')) {
-
- array_push($data, array(
- 'result' => 'yes',
- ));
- } else {
- $wod->img_url = '/assets/img/activation_icon_nRead1.png';
- $wod->wo = $request->wo;
- $wod->nature_work = '';
- $wod->sub_category = '';
- $wod->dateTimeStart = '';
- $wod->dateTimeEnd = '';
- $wod->contractor_id = $request->vendor;
- $wod->installer_id = '';
- $wod->onu = '';
- $wod->router = '';
- $wod->need_phone = '';
- $wod->no_phone = '';
- $wod->pppoe_username = '';
- $wod->pppoe_password = '';
- $wod->docket_id = '';
- $wod->remarks_custservice = '';
- $wod->remarks_installer = '';
- $wod->status = 'Pending Non Prelaid';
- $wod->save();
-
- array_push($data, array(
- 'result' => 'yes',
- ));
- }
-
- return response()->json($data);
- }
-
- public function updateWorkOrderReschedule(Request $request)
- {
- $data = array();
- $wod = WorkOrder::where('wo', $request->wo)->first();
- $form = Form::where('_id', $wod->_id)->first();
- $contractor = Company::where('_id', $wod->contractor_id)->first();
-
- if (!empty($wod)) {
- $formH = new FormStatus;
- $formH->form_id = $form->_id;
- $formH->status_id = 4;
- $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
- $formH->status = 'Pending Contractor';
- $formH->desc = 'This work order been reassigned to particular contractor (' . $contractor->name . ')';
- $form->formstatus()->save($formH);
-
- $this->sendWorkOrders($request->wo);
- array_push($data, array(
- 'result' => 'yes',
- ));
- } else {
- array_push($data, array(
- 'result' => 'no',
- ));
- }
-
- return response()->json($data);
- }
-
- public function createRectification(Request $request)
- {
-
- $su_id = '';
- $pathIconF = '';
- $pathIconB = '';
-
- $sl = Form::create([
- 'type_service' => 'Rectification',
- 'type_application' => $request->formT,
- 'customer_category' => $request->cust_category,
- 'status_payment' => 'paid',
- 'status_email' => 'verified',
- 'remark_form' => ''
- ]);
-
-
- if ($request->formT == 'R') {
-
- do {
- $su_id = strtoupper('CBB-' . $this->random_code(6) . 'R');
- } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
-
- $coverage = Coverage::where('building_name', $request->buildingsss)->where('street', $request->street)->first();
-
- $sdl = new Subscriber();
- $sdl->subscriber_id = $su_id;
- $sdl->name = $request->name;
- $sdl->ic = '';
- $sdl->citizen = '';
- $sdl->gender = '';
- $sdl->race = '';
- $sdl->email = '';
- $sdl->phone1 = $request->phone1;
- $sdl->phone2 = $request->phone2;
- $sdl->unit_no = $request->unit_no;
- $sdl->building_name = $coverage->building_name;
- $sdl->street = $coverage->street;
- $sdl->postcode = $coverage->postcode;
- $sdl->city = $coverage->city;
- $sdl->state = $coverage->state;
- $sdl->front_ic = '';
- $sdl->back_ic = '';
- $sdl->signature = '';
-
- $packageD = new PackageDetail();
- $packageD->contract = '';
- $packageD->name = $request->package;
- $packageD->montly_fee = '';
- $packageD->voice_fee = '';
- $packageD->deposit = '';
- $packageD->upfront_payment = '';
- $packageD->rfs = '';
-
- $sl->subscriber()->save($sdl);
- $sl->packagedetail()->save($packageD);
-
- $subs = Subscriber::where('subscriber_id', $su_id)->first();
- $form = Form::where('_id', $subs->_id)->first();
- $formH = new FormStatus;
- $formH->form_id = $form->_id;
- $formH->status_id = 12;
- $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
- $formH->status = 'New Rectification';
- $formH->desc = 'Rectification form been submitted';
- $form->formstatus()->save($formH);
-
- do {
- $woID = 'WO-' . $this->createWorkID();
- } while (WorkOrder::where("wo", "=", $woID)->first() instanceof WorkOrder);
-
- $work_order = new WorkOrder;
- $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
- $work_order->wo = $woID;
- $work_order->nature_work = '';
- $work_order->sub_category = '';
- $work_order->dateTimeStart = '';
- $work_order->dateTimeEnd = '';
- $work_order->contractor_id = '';
- $work_order->installer_id = '';
- $work_order->onu = '';
- $work_order->router = '';
- $work_order->need_phone = '';
- $work_order->no_phone = '';
- $work_order->pppoe_username = '';
- $work_order->pppoe_password = '';
- $work_order->docket_id = '';
- $work_order->remarks_custservice = '';
- $work_order->remarks_installer = '';
- $work_order->status = 'Pending Contractor';
- $work_order->created_by = '';
-
- $form->workorder()->save($work_order);
-
- return redirect()->to('/customer-service/work-order/add/schedule/rectification/' . $woID . '/' . $su_id);
- } else if ($request->formT == 'B') {
-
- do {
- $su_id = strtoupper('CBB-' . $this->random_code(6) . 'B');
- } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
-
- $sdl = new Subscriber();
- $sdl->subscriber_id = $su_id;
- $sdl->company_name = $request->cname;
- $sdl->company_reg = '';
- $sdl->company_num = '';
- $sdl->company_fax = '';
- $sdl->name = $request->name;
- $sdl->ic = '';
- $sdl->designation = '';
- $sdl->email = '';
- $sdl->phone1 = $request->phone1;
- $sdl->phone2 = '';
- $sdl->unit_no = $request->unit_no;
- $sdl->street = $request->caddress;
- $sdl->postcode = '';
- $sdl->city = '';
- $sdl->state = '';
- $sdl->front_ic = '';
- $sdl->back_ic = '';
- $sdl->form24_49 = '';
- $sdl->form9_44 = '';
-
- $packageD = new PackageDetail();
- $packageD->contract = '';
- $packageD->name = $request->package;
- $packageD->montly_fee = '';
- $packageD->voice_fee = 'No';
- $packageD->deposit = '';
- $packageD->upfront_payment = '';
- $packageD->rfs = '';
-
- $sl->subscriber()->save($sdl);
- $sl->packagedetail()->save($packageD);
-
- $subs = Subscriber::where('subscriber_id', $su_id)->first();
- $form = Form::where('_id', $subs->_id)->first();
- $formH = new FormStatus;
- $formH->form_id = $form->_id;
- $formH->status_id = 12;
- $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
- $formH->status = 'New Rectification';
- $formH->desc = 'Rectification form been submitted';
- $form->formstatus()->save($formH);
-
- do {
- $woID = 'WO-' . $this->createWorkID();
- } while (WorkOrder::where("wo", "=", $woID)->first() instanceof WorkOrder);
-
- $work_order = new WorkOrder;
- $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
- $work_order->wo = $woID;
- $work_order->nature_work = '';
- $work_order->sub_category = '';
- $work_order->dateTimeStart = '';
- $work_order->dateTimeEnd = '';
- $work_order->contractor_id = '';
- $work_order->installer_id = '';
- $work_order->onu = '';
- $work_order->router = '';
- $work_order->need_phone = '';
- $work_order->no_phone = '';
- $work_order->pppoe_username = '';
- $work_order->pppoe_password = '';
- $work_order->docket_id = '';
- $work_order->remarks_custservice = '';
- $work_order->remarks_installer = '';
- $work_order->status = 'Pending Contractor';
- $work_order->created_by = '';
-
- $form->workorder()->save($work_order);
-
- return redirect()->to('/customer-service/work-order/add/schedule/rectification/' . $woID . '/' . $su_id);
- }
- }
-
- public function createSecuredDevelopement(Request $request)
- {
- $su_id = '';
- $pathIconF = '';
- $pathIconB = '';
-
- do {
- $su_id = strtoupper('CBB-' . $this->random_code(6) . 'R');
- } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
-
- if ($request->has('cust_category1')) {
- $category = $request->cust_category1;
- } else if ($request->has('cust_category2')) {
- $category = $request->cust_category2;
- }
-
- $sl = Form::create([
- 'type_service' => $request->app,
- 'customer_category' => $category,
- 'type_application' => 'R',
- 'status_payment' => 'paid',
- 'status_email' => 'verified',
- 'remark_form' => ''
- ]);
-
- $building = '-';
- $postcode = '-';
- $city = '-';
- $state = '-';
- if ($request->has('buildingsss')) {
- $coverage = Coverage::where('building_name', $request->buildingssss)->first(); $street = $request->streets;
- } else if ($request->has('buildingssss')) {
- $coverage = Coverage::where('building_name', $request->buildingsssss)->first();
- $street = $request->streetss;
- }
-
- dd($coverage);
-
- if (!empty($coverage)) {
- $building = $coverage->building_name;
- $street = $street;
- $postcode = $coverage->postcode;
- $city = $coverage->city;
- $state = $coverage->state;
- } else {
- $building = $request->buildingssss;
- $street = '-';
- $postcode = '-';
- $city = '-';
- $state = '-';
- }
-
- $sdl = new Subscriber();
- $sdl->subscriber_id = $su_id;
- $sdl->name = $request->name;
- $sdl->ic = '<b>Package Development</b>';
- $sdl->citizen = $request->citizensss;
- $sdl->gender = $request->gender;
- $sdl->race = $request->race;
- $sdl->email = '<b>Package Development</b>';
- $sdl->phone1 = $request->phone1;
- $sdl->phone2 = $request->phone2;
- $sdl->unit_no = $request->unit_no;
- $sdl->building_name = $building;
- $sdl->street = $street;
- $sdl->postcode = $postcode;
- $sdl->city = $city;
- $sdl->state = $state;
- $sdl->front_ic = '';
- $sdl->back_ic = '';
- $sdl->signature = '';
-
- $packageD = new PackageDetail();
- $packageD->contract = '24';
- $packageD->name = $request->package;
- $packageD->montly_fee = '';
- $packageD->voice_fee = 'No';
- $packageD->deposit = '';
- $packageD->upfront_payment = '';
- $packageD->rfs = '';
-
- $sl->subscriber()->save($sdl);
- $sl->packagedetail()->save($packageD);
-
- $subs = Subscriber::where('subscriber_id', $su_id)->first();
- $form = Form::where('_id', $subs->_id)->first();
- $formH = new FormStatus;
- $formH->form_id = $form->_id;
- $formH->status_id = 13;
- $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
- $formH->status = 'Secured Development';
- $formH->desc = 'Secured development form been submitted';
- $form->formstatus()->save($formH);
-
- do {
- $woID = 'WO-' . $this->createWorkID();
- } while (WorkOrder::where("wo", "=", $woID)->first() instanceof WorkOrder);
-
- $work_order = new WorkOrder;
- $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
- $work_order->wo = $woID;
- $work_order->nature_work = '';
- $work_order->sub_category = '';
- $work_order->dateTimeStart = '';
- $work_order->dateTimeEnd = '';
- $work_order->contractor_id = '';
- $work_order->installer_id = '';
- $work_order->onu = '';
- $work_order->router = '';
- $work_order->need_phone = '';
- $work_order->no_phone = '';
- $work_order->pppoe_username = '';
- $work_order->pppoe_password = '';
- $work_order->docket_id = '';
- $work_order->remarks_custservice = '';
- $work_order->remarks_installer = '';
- $work_order->status = 'Pending Contractor';
- $work_order->created_by = '';
-
- $form->workorder()->save($work_order);
-
- return redirect()->to('/customer-service/work-order/add/schedule/secured/' . $woID . '/' . $su_id);
- }
- }
|