123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791 |
- <?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 WC WO' . $numberOnly);
- $numberOnly++;
- info('after WC 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);
-
- $sl->project_type = $coverage->project_type;
- $sl->save();
-
- $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->building1 != '') {
- $coverage = Coverage::where('building_name', $request->building1)->first();
- $street = $request->streets;
- } else if ($request->building2 != '') {
- $coverage = Coverage::where('building_name', $request->building2)->first();
- $street = $request->streetss;
- }
-
- if (!empty($coverage)) {
- $building = $coverage->building_name;
- $street = $street;
- $postcode = $coverage->postcode;
- $city = $coverage->city;
- $state = $coverage->state;
- } else {
- $building = $request->building1;
- $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);
-
- $sl->project_type = $coverage->project_type;
- $sl->save();
-
- $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);
- }
- }
|