| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487 |
- <?php
-
- namespace App\Http\Controllers\CustomerService;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
- use LynX39\LaraPdfMerger\Facades\PdfMerger;
-
- use Carbon\Carbon;
- use Validator;
- use PDF;
-
- use App\Staff;
- use App\Model\StaffDetail;
- use App\Model\Form;
- use App\Model\FormStatus;
- 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;
-
- class CustomerController 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 viewCustomer()
- {
- $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::all();
- $company = Company::where('team','Dealer')->get();
-
- return view('customer-service.view_customer',compact('user','pp','sp','rs','ss','cm','coverage','company'));
- }
-
- public function getAllNewCustomer(Request $request, $type,$building,$dealer){
-
- ## Read value
- $draw = $request->get('draw');
- $start = $request->get("start");
- $rowperpage = $request->get("length"); // Rows display per page
-
- // $columnIndex_arr = $request->get('order');
- // $columnName_arr = $request->get('columns');
- // $order_arr = $request->get('order');
- $search_arr = $request->get('search');
-
- // $columnIndex = $columnIndex_arr[0]['column']; // Column index
- // $columnName = $columnName_arr[$columnIndex]['data']; // Column name
- // $columnSortOrder = $order_arr[0]['dir']; // asc or desc
- $searchValue = $search_arr['value']; // Search value
-
- // Total records
- $totalRecords = Form::with('Subscriber','PackageDetail','WorkOrder')->select('count(*) as allcount')->count();
- if ($searchValue==!null){
- $totalRecordswithFilter = Form::whereHas('subscriber',function($q) use($searchValue){
- $q->where('name', 'like', '%' .$searchValue . '%')->orWhere('company_name', 'like', '%' .$searchValue . '%')
- ->orWhere('unit_no', 'like', '%' .$searchValue . '%')->orWhere('building_name', 'like', '%' .$searchValue . '%')
- ->orWhere('street', 'like', '%' .$searchValue . '%')->orWhere('city', 'like', '%' .$searchValue . '%');
- })->select('count(*) as allcount')->count();
- }else{
- $totalRecordswithFilter = Form::with('Subscriber','PackageDetail','WorkOrder')->select('count(*) as allcount')->count();
- }
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0; $n1 = ''; $street = ''; $labelD = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if($type == 'null' && $building == 'null' && $dealer == 'null'){
- if ($searchValue==!null){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereHas('subscriber',function($q) use($searchValue){
- $q->where('name', 'like', '%' .$searchValue . '%')->orWhere('company_name', 'like', '%' .$searchValue . '%')
- ->orWhere('unit_no', 'like', '%' .$searchValue . '%')->orWhere('building_name', 'like', '%' .$searchValue . '%')
- ->orWhere('street', 'like', '%' .$searchValue . '%')->orWhere('city', 'like', '%' .$searchValue . '%');
- })->orderBy('created_at', 'desc')->skip(intval($start))->take(intval($rowperpage))->get();
- }else{
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->skip(intval($start))->take(intval($rowperpage))->get();
- }
-
-
- }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
- }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type != 'null' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type != 'null' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- if(!empty($form)){
- foreach ($form as $key => $f) {
- if(empty($f->WorkOrder->nature_work)){
- $i++;
-
- $n1 = '';
- $reg_time = $f->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }else{
- $n1 = "";
- }
-
-
- if(!empty($f->dealer_id)){
- $labelD = "D/";
- }else{
- $labelD = "";
- }
- if(!empty($f->Subscriber)){
- if($f->Subscriber->street != ''){
- $street = $f->Subscriber->street;
- }
-
- $wo = '';
- if($f->status_email == 'verified'){
- $work_order = '';
- if($f->type_application == 'R'){
- if(!empty($f->WorkOrder->wo)){
- $work_order = $f->WorkOrder->wo;
- }else{
- do {
- $work_order = 'WO-'.$this->createWorkID();
- } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
-
- }
-
- $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
- $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','R')->first();
- if(!empty($cov)){
- if($cov->status_building == 'non prelaid'){
- $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
- }
- }
-
- }else if($f->type_application == 'B'){
- if(!empty($f->WorkOrder->wo)){
- $work_order = $f->WorkOrder->wo;
- }else{
- do {
- $work_order = 'WO-'.$this->createWorkID();
- } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
- }
-
- $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
- $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','B')->first();
- if(!empty($cov)){
- if($cov->status_building == 'non prelaid'){
- $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
- }
- }
-
- }
-
- }else if($f->status_email == 'unverified'){
- $wo = '';
- }
-
- $building = ''; $unit = '-'; $address = ''; $name = '';
- if($f->type_application == 'R'){
- $name = $f->Subscriber->name;
- $building = $f->Subscriber->building_name;
- $unit = $f->Subscriber->unit_no;
-
- if($f->Subscriber->street != ''){
- $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
- }else {
- $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
- }
-
- }else if($f->type_application == 'B'){
-
- $name = $f->Subscriber->company_name;
- if($f->Subscriber->unit_no == ''){
- $unit = '-';
- }else {
- $unit = $f->Subscriber->unit_no;
- }
-
- $building = $f->Subscriber->street;
-
- $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
- }
-
- $nP = '';
- $ptype = '';
- if(!empty($f->project_type)){
- $ptype = $f->project_type;
- }
-
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'type' => $f->type_service,
- 'name' => $labelD.$name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'projectT' => $ptype,
- 'street' => $address,
- // 'postcode' => $f->Subscriber->postcode,
- // 'city' => $f->Subscriber->city,
- 'need_phone' => $nP,
- 'email' => $f->status_email,
- 'action1' => $wo,
- 'action2' => $f->_id
- ));
- }
- }
- }
- }
-
- $response = array(
- "draw" => intval($draw),
- "recordsTotal" => $totalRecords,
- "recordsFiltered" => $totalRecordswithFilter,
- "data" => $nested_data
- );
-
- return json_encode($response);
- }
-
- public function getAllNewCustomerss($type,$building,$dealer){
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0; $n1 = ''; $street = ''; $labelD = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- $customer = Subscriber::where('_id','5cb5444ecfe8c571a302d054')->first();
- $package = PackageDetail::where('_id','5cb5444ecfe8c571a302d054')->first();
- $wo = WorkOrder::where('_id','5cb5444ecfe8c571a302d054')->first();
-
- $f = Form::where('test','ayaya')->first();
- dd($f);
-
- $form = Form::with('PackageDetail','WorkOrder','Subscriber')->orderBy('created_at', 'desc')->where('_id','5cb5444ecfe8c571a302d054')->first();
-
-
- if($type == 'null' && $building == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
- }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
- }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type != 'null' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type != 'null' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
-
- if(!empty($form)){
- foreach ($form as $key => $f) {
- // if(empty($f->WorkOrder)){
- $i++;
-
- $n1 = '';
- $reg_time = $f->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }else{
- $n1 = "";
- }
-
-
- if(!empty($f->dealer_id)){
- $labelD = "D/";
- }else{
- $labelD = "";
- }
-
- if(!empty($f->Subscriber)){
- if($f->Subscriber->street != ''){
- $street = $f->Subscriber->street;
- }
-
- $wo = '';
- if($f->status_email == 'verified'){
-
- $work_order = '';
- if($f->type_application == 'R'){
-
- do {
- $work_order = 'WO-'.$this->createWorkID(4);
- } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
-
- $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
- $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','R')->first();
- if(!empty($cov)){
- if($cov->status_building == 'non prelaid'){
- $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
- }
- }
-
- }else if($f->type_application == 'B'){
-
- do {
- $work_order = 'WO-'.$this->createWorkID(4);
- } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
-
- $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
- $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','B')->first();
- if(!empty($cov)){
- if($cov->status_building == 'non prelaid'){
- $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
- }
- }
-
- }
-
- }else if($f->status_email == 'unverified'){
- $wo = '';
- }
-
- array_push($nested_data, array(
- $f->_id,
- // 'formT' => $n1.$i.$f->type_application,
- // 'type' => $f->type_service,
- // 'name' => $labelD.$f->Subscriber->name,
- // 'phone' => $f->Subscriber->phone1,
- // 'unit' => $f->Subscriber->unit_no,
- // 'building' => $f->Subscriber->building_name,
- // 'street' => $street,
- // 'postcode' => $f->Subscriber->postcode,
- // 'city' => $f->Subscriber->city,
- // 'email' => $f->status_email,
- // 'action1' => $wo,
- // 'action2' => $f->_id
- ));
- }
- // }
- }
- }
- dd($nested_data);
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function deleteFormCustomer(Request $request){
-
- $form = Form::where('_id',$request->id)->first();
- $wod = WorkOrder::where('_id',$request->id)->first();
-
- if(!empty($wod)){
- $wod->delete();
-
- $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);
- }
-
- if(!empty($form)){
- $form->delete();
- return 'true';
- }else {
- return 'false';
- }
- }
-
- public function editSubscriber($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());
-
- $coverage = Coverage::all();
- $form = Subscriber::with('Form')->where('_id',$subscriber_id)->first();
- return view('customer-service.edit_subscriber',compact('user','pp','sp','rs','ss','cm','form','coverage'));
- }
-
- public function updateCustomerDetail(Request $request){
- $form = Subscriber::with('Form')->where('subscriber_id',$request->subscriber_id)->first();
- $form_submitted = Form::where('_id',$form->_id)->first();
-
- $phone = ''; $street = ''; $fax = '';
- if($request->phone2 != null){
- $phone = $request->phone2;
- }
-
- if($form->Form->type_application == 'R'){
-
- if($request->street != null){
- $street = $request->street;
- }
-
- $cov = Coverage::where('building_name',$request->building)->first();
-
- if(!empty($cov)){
- $building = $cov->building_name;
- $postcode = $cov->postcode;
- $city = $cov->city;
- $state = $cov->state;
- }else {
- $building = $request->building;
- $postcode = '-';
- $city = '-';
- $state = '-';
- }
-
- $form->name = $request->name;
- $form->ic = $request->ic;
- $form->email = $request->email;
- $form->phone1 = $request->phone1;
- $form->phone2 = $phone;
- $form->unit_no = $request->unit_no;
- $form->building_name = $building;
- $form->street = $street;
- $form->city = $city;
- $form->postcode = $postcode;
- $form->state = $state;
- $form->save();
-
- $form_submitted->project_type = $request->ptype;
- $form_submitted->save();
-
- return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
-
- }else if($form->Form->type_application == 'B'){
-
- if($request->company_fax != null){
- $fax = $request->company_fax;
- }
-
- $cov = Coverage::where('building_name',$request->building)->first();
-
- if(!empty($cov)){
- $building = $cov->building_name;
- $postcode = $cov->postcode;
- $city = $cov->city;
- $state = $cov->state;
- }else {
- $building = $request->building;
- $postcode = '-';
- $city = '-';
- $state = '-';
- }
-
- $form->company_reg = $request->company_reg;
- $form->company_num = $request->company_num;
- $form->company_fax = $fax;
- $form->company_name = $request->company_name;
- $form->building_name = $building;
- $form->street = $street;
- $form->city = $city;
- $form->postcode = $postcode;
- $form->state = $state;
- $form->name = $request->name;
- $form->ic = $request->ic;
- $form->designation = $request->designation;
- $form->email = $request->email;
- $form->phone1 = $request->phone1;
- $form->phone2 = $phone;
- $form->save();
-
- $form_submitted->project_type = $request->ptype;
- $form_submitted->save();
-
- return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
- }
-
- }
-
- public function generateRPDF($subscriber_id) {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $product = Product::where('formT','R')->orderBy('created_at','asc')->get();
- $form = Subscriber::with('Form')->where('subscriber_id',$subscriber_id)->first();
-
- $package = PackageDetail::where('_id',$form->_id)->first();
- $created_at = Carbon::parse($form->created_at)->toDateTimeString();
-
- $ext1 = pathinfo(public_path().$form->front_ic, PATHINFO_EXTENSION);
- $ext2 = pathinfo(public_path().$form->back_ic, PATHINFO_EXTENSION);
-
- $ext3 = pathinfo(public_path().$form->visaF, PATHINFO_EXTENSION);
- $ext4 = pathinfo(public_path().$form->visaB, PATHINFO_EXTENSION);
-
- $ext5 = pathinfo(public_path().$form->paymentReceipt, PATHINFO_EXTENSION);
- $ext6 = pathinfo(public_path().$form->soForm, PATHINFO_EXTENSION);
-
- $documentPath = 'document/'.$subscriber_id;
-
- $created = $form->Form->created_at->toDateString();
- // dd($created . $created_at);
-
- $total = floatval($package->montly_fee) + floatval($package->deposit) + floatval($package->voice_fee) + floatval($package->upfront_payment);
- // dd($total);
- $pdf = PDF::loadView('pdf.residential-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','created_at','created'));
- $pdf->setPaper('A4', 'potrait');
-
- if($ext1 == "pdf" || $ext2 == "pdf" || $ext3 == "pdf" || $ext4 == "pdf" || $ext5 == "pdf" || $ext6 == "pdf" ){
- $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
- $merges = PDFMerger::init();
- $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
- if($ext1 == "pdf"){
- $merges->addPDF(public_path().$form->front_ic,'all');
- }
- if($ext2 == "pdf"){
- $merges->addPDF(public_path().$form->back_ic,'all');
- }
- if($ext3 == "pdf"){
- $merges->addPDF(public_path().$form->visaF,'all');
- }
- if($ext4 == "pdf"){
- $merges->addPDF(public_path().$form->visaB,'all');
- }
- if($ext5 == "pdf"){
- $merges->addPDF(public_path().$form->paymentReceipt,'all');
- }
- if($ext6 == "pdf"){
- $merges->addPDF(public_path().$form->soForm,'all');
- }
- $merges->merge();
- $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
-
- }else if(($ext1 == "jpeg" || $ext1 == "jpg" || $ext1 == "png" ) || ($ext2 == "jpeg" || $ext2 == "jpg" || $ext2 == "png" ) ||
- ($ext3 == "jpeg" || $ext3 == "jpg" || $ext3 == "png" ) ||($ext4 == "jpeg" || $ext4 == "jpg" || $ext4 == "png" ) ||
- ($ext5 == "jpeg" || $ext5 == "jpg" || $ext5 == "png" ) ||($ext6 == "jpeg" || $ext6 == "jpg" || $ext6 == "png" )){
- return $pdf->stream();
- }else{
- return $pdf->stream();
- }
-
- }
-
- public function redirectPDF($sid){
- $form = Subscriber::with('Form')->where('_id',$sid)->first();
- if($form->Form->type_application == 'R'){
- return redirect('/customer-service/residential/generate-pdf/'.$form->subscriber_id);
- }else if($form->Form->type_application == 'B'){
- return redirect('/customer-service/business/generate-pdf/'.$form->subscriber_id);
- }
- }
-
- public function generateBPDF($subscriber_id) {
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $product = Product::where('formT','B')->get();
- $form = Subscriber::with('Form')->where('subscriber_id',$subscriber_id)->first();
- $package = PackageDetail::where('_id',$form->_id)->first();
- $dateSubmittion = date('d/m/Y', strtotime($form->created_at));
-
- $ext1 = pathinfo(public_path().$form->front_ic, PATHINFO_EXTENSION);
- $ext2 = pathinfo(public_path().$form->back_ic, PATHINFO_EXTENSION);
-
- $ext3 = pathinfo(public_path().$form->form9_44, PATHINFO_EXTENSION);
-
- $ext4 = pathinfo(public_path().$form->paymentReceipt, PATHINFO_EXTENSION);
- $ext5 = pathinfo(public_path().$form->soForm, PATHINFO_EXTENSION);
-
- $documentPath = 'document/'.$subscriber_id;
-
- // $pdf = PDF::loadView('pdf.business-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','dateSubmittion'));
- if(strtotime($form->created_at) >= 1580774399){
- $pdf = PDF::loadView('pdf.newBusiness-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','dateSubmittion'));
- }else {
- $pdf = PDF::loadView('pdf.oldBusiness-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','dateSubmittion'));
- }
-
- $pdf->setPaper('A4', 'potrait');
-
-
- if($ext1 == "pdf" || $ext2 == "pdf" || $ext3 == "pdf" || $ext4 == "pdf" || $ext5 == "pdf" ){
- $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
- $merges = PDFMerger::init();
- $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
- if($ext1 == "pdf"){
- $merges->addPDF(public_path().$form->front_ic,'all');
- }
- if($ext2 == "pdf"){
- $merges->addPDF(public_path().$form->back_ic,'all');
- }
- if($ext3 == "pdf"){
- $merges->addPDF(public_path().$form->form9_44,'all');
- }
- if($ext4 == "pdf"){
- $merges->addPDF(public_path().$form->paymentReceipt,'all');
- }
- if($ext5 == "pdf"){
- $merges->addPDF(public_path().$form->soForm,'all');
- }
- $merges->merge();
- $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
-
- }else if(($ext1 == "jpeg" || $ext1 == "jpg" || $ext1 == "png" ) || ($ext2 == "jpeg" || $ext2 == "jpg" || $ext2 == "png" ) ||
- ($ext3 == "jpeg" || $ext3 == "jpg" || $ext3 == "png" ) ||($ext4 == "jpeg" || $ext4 == "jpg" || $ext4 == "png" ) ||
- ($ext5 == "jpeg" || $ext5 == "jpg" || $ext5 == "png" )){
- return $pdf->stream();
- }else {
- return $pdf->stream();
- }
- }
-
- public function viewSubscriber()
- {
- $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());
-
- $rec = count(WorkOrder::where('nature_work','Rectification')->get());
- $re = count(Form::where('type_application','R')->get());
- $bu = count(Form::where('type_application','B')->get());
-
- $coverage = Coverage::all();
- $company = Company::where('team','Dealer')->get();
-
- return view('customer-service.view_subscriber', compact('user','pp','sp','rs','ss','cm','rec','re','bu','coverage','company'));
- }
-
- public function getAllRectification(Request $request,$type,$building,$dealer){
- ## Read value
- $draw = $request->get('draw');
- $start = $request->get("start");
- $rowperpage = $request->get("length"); // Rows display per page
-
- // $columnIndex_arr = $request->get('order');
- // $columnName_arr = $request->get('columns');
- // $order_arr = $request->get('order');
- $search_arr = $request->get('search');
-
- // $columnIndex = $columnIndex_arr[0]['column']; // Column index
- // $columnName = $columnName_arr[$columnIndex]['data']; // Column name
- // $columnSortOrder = $order_arr[0]['dir']; // asc or desc
- $searchValue = $search_arr['value']; // Search value
-
- // Total records
- $totalRecords = Form::with('Subscriber','PackageDetail','WorkOrder')->whereHas('workorder',function($q){
- $q->where('nature_work','Rectification');
- })->select('count(*) as allcount')->count();
- if ($searchValue==!null){
- $totalRecordswithFilter = Form::whereHas('subscriber',function($q) use($searchValue){
- $q->where('name', 'like', '%' .$searchValue . '%')->orWhere('company_name', 'like', '%' .$searchValue . '%')
- ->orWhere('unit_no', 'like', '%' .$searchValue . '%')->orWhere('building_name', 'like', '%' .$searchValue . '%')
- ->orWhere('street', 'like', '%' .$searchValue . '%')->orWhere('city', 'like', '%' .$searchValue . '%');
- })->whereHas('workorder',function($q){
- $q->where('nature_work','Rectification');
- })->select('count(*) as allcount')->count();
- }else{
- $totalRecordswithFilter = Form::with('Subscriber','PackageDetail','WorkOrder')->whereHas('workorder',function($q){
- $q->where('nature_work','Rectification');
- })->select('count(*) as allcount')->count();
- }
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if($type == 'null' && $building == 'null' && $dealer == 'null'){
- if ($searchValue==!null){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereHas('subscriber',function($q) use($searchValue){
- $q->where('name', 'like', '%' .$searchValue . '%')->orWhere('company_name', 'like', '%' .$searchValue . '%')
- ->orWhere('unit_no', 'like', '%' .$searchValue . '%')->orWhere('building_name', 'like', '%' .$searchValue . '%')
- ->orWhere('street', 'like', '%' .$searchValue . '%')->orWhere('city', 'like', '%' .$searchValue . '%');
- })->whereHas('workorder',function($q){
- $q->where('nature_work','Rectification');
- })->orderBy('created_at', 'desc')->skip(intval($start))->take(intval($rowperpage))->get();
- }else{
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereHas('workorder',function($q){
- $q->where('nature_work','Rectification');
- })->orderBy('created_at', 'desc')->skip(intval($start))->take(intval($rowperpage))->get();
- }
- }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
- }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type != 'null' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type != 'null' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
-
- $wo = 'null'; $do = 'null';
- if(!empty($form)){
- foreach ($form as $key => $f) {
-
- if(!empty($f->WorkOrder)){
-
- if($f->WorkOrder->nature_work == "Rectification" || $f->type_service == "Rectification") {
- $wo = $f->WorkOrder->wo;
-
- if($f->WorkOrder->status == "Completed"){
- $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
- if(!empty($doc)){
- $do = $doc->docket_id;
- }
- }else{
- $wo = $f->WorkOrder->wo;
- $do = "null";
- }
-
- $i++;
-
- $n1 = '';
- $reg_time = $f->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
-
- if(!empty($f->dealer_id)){
- $labelD = "D/";
- }
-
- if(!empty($f->Subscriber)){
- if($f->Subscriber->street != ''){
- $street = $f->Subscriber->street;
- }
-
- $name = '';
- if($f->type_application == 'R'){
- $name = $f->Subscriber->name;
- }else if($f->type_application == 'B'){
- $name = $f->Subscriber->building_name;
- }
-
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'submittion' => Carbon::parse($f->created_at)->toDateString(),
- 'type' => $f->type_service,
- 'name' => $labelD.$name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $f->Subscriber->unit_no,
- 'building' => $f->Subscriber->building_name,
- 'street' => $street,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
- 'action2' => $wo,
- 'action3' => $do
- ));
- }
- }
- }
- }
- }
-
- $response = array(
- "draw" => intval($draw),
- "recordsTotal" => $totalRecords,
- "recordsFiltered" => $totalRecordswithFilter,
- "data" => $nested_data
- );
-
- return json_encode($response);
- }
-
- public function getAllResidential(Request $request,$type,$building,$dealer){
-
- ## Read value
- $draw = $request->get('draw');
- $start = $request->get("start");
- $rowperpage = $request->get("length"); // Rows display per page
-
- // $columnIndex_arr = $request->get('order');
- // $columnName_arr = $request->get('columns');
- // $order_arr = $request->get('order');
- $search_arr = $request->get('search');
-
- // $columnIndex = $columnIndex_arr[0]['column']; // Column index
- // $columnName = $columnName_arr[$columnIndex]['data']; // Column name
- // $columnSortOrder = $order_arr[0]['dir']; // asc or desc
- $searchValue = $search_arr['value']; // Search value
-
- // Total records
- $totalRecords = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_application','R')->select('count(*) as allcount')->count();
- if ($searchValue==!null){
- $totalRecordswithFilter = Form::whereHas('subscriber',function($q) use($searchValue){
- $q->where('name', 'like', '%' .$searchValue . '%')->orWhere('company_name', 'like', '%' .$searchValue . '%')
- ->orWhere('unit_no', 'like', '%' .$searchValue . '%')->orWhere('building_name', 'like', '%' .$searchValue . '%')
- ->orWhere('street', 'like', '%' .$searchValue . '%')->orWhere('city', 'like', '%' .$searchValue . '%');
- })->where('type_application','R')->select('count(*) as allcount')->count();
- }else{
- $totalRecordswithFilter = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_application','R')->select('count(*) as allcount')->count();
- }
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if($type == 'null' && $building == 'null' && $dealer == 'null'){
- if ($searchValue==!null){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereHas('subscriber',function($q) use($searchValue){
- $q->where('name', 'like', '%' .$searchValue . '%')->orWhere('company_name', 'like', '%' .$searchValue . '%')
- ->orWhere('unit_no', 'like', '%' .$searchValue . '%')->orWhere('building_name', 'like', '%' .$searchValue . '%')
- ->orWhere('street', 'like', '%' .$searchValue . '%')->orWhere('city', 'like', '%' .$searchValue . '%');
- })->where('type_application','R')->orderBy('created_at', 'desc')->skip(intval($start))->take(intval($rowperpage))->get();
- }else{
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_application','R')->orderBy('created_at', 'desc')->skip(intval($start))->take(intval($rowperpage))->get();
- }
- }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
- }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type != 'null' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type != 'null' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
-
- $wo = 'null'; $do = 'null';
- if(!empty($form)){
- foreach ($form as $key => $f) {
-
-
-
- if(!empty($f->WorkOrder)){
- $wo = $f->WorkOrder->wo;
-
- if($f->WorkOrder->status == "Completed"){
- $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
- if(!empty($doc)){
- $do = $doc->docket_id;
- }
- }else{
- $wo = $f->WorkOrder->wo;
- $do = "null";
- }
- }else {
- $wo = "null";
- $do = "null";
- }
-
-
- if($f->type_application == 'R' && $f->type_service != "Rectification"){
- $i++;
-
- $n1 = '';
- $reg_time = $f->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }else{
- $n1 = "";
- }
-
-
- if(!empty($f->dealer_id)){
- $labelD = "D/";
- }else {
- $labelD = "";
- }
-
- if(!empty($f->Subscriber)){
- if($f->Subscriber->street != ''){
- $street = $f->Subscriber->street;
- }
-
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'submittion' => Carbon::parse($f->created_at)->toDateString(),
- 'type' => $f->type_service,
- 'name' => $labelD.$f->Subscriber->name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $f->Subscriber->unit_no,
- 'building' => $f->Subscriber->building_name,
- 'street' => $street,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
- 'action2' => $wo,
- 'action3' => $do
- ));
- }
- }
- }
- }
-
- $response = array(
- "draw" => intval($draw),
- "recordsTotal" => $totalRecords,
- "recordsFiltered" => $totalRecordswithFilter,
- "data" => $nested_data
- );
-
- return json_encode($response);
- }
-
- public function getAllBusiness(Request $request, $type,$building,$dealer){
-
- ## Read value
- $draw = $request->get('draw');
- $start = $request->get("start");
- $rowperpage = $request->get("length"); // Rows display per page
-
- // $columnIndex_arr = $request->get('order');
- // $columnName_arr = $request->get('columns');
- // $order_arr = $request->get('order');
- $search_arr = $request->get('search');
-
- // $columnIndex = $columnIndex_arr[0]['column']; // Column index
- // $columnName = $columnName_arr[$columnIndex]['data']; // Column name
- // $columnSortOrder = $order_arr[0]['dir']; // asc or desc
- $searchValue = $search_arr['value']; // Search value
-
- // Total records
- $totalRecords = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_application','B')->select('count(*) as allcount')->count();
- if ($searchValue==!null){
- $totalRecordswithFilter = Form::whereHas('subscriber',function($q) use($searchValue){
- $q->where('name', 'like', '%' .$searchValue . '%')->orWhere('company_name', 'like', '%' .$searchValue . '%')
- ->orWhere('unit_no', 'like', '%' .$searchValue . '%')->orWhere('building_name', 'like', '%' .$searchValue . '%')
- ->orWhere('street', 'like', '%' .$searchValue . '%')->orWhere('city', 'like', '%' .$searchValue . '%');
- })->where('type_application','B')->select('count(*) as allcount')->count();
- }else{
- $totalRecordswithFilter = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_application','B')->select('count(*) as allcount')->count();
- }
-
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if($type == 'null' && $building == 'null' && $dealer == 'null'){
- if ($searchValue==!null){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereHas('subscriber',function($q) use($searchValue){
- $q->where('name', 'like', '%' .$searchValue . '%')->orWhere('company_name', 'like', '%' .$searchValue . '%')
- ->orWhere('unit_no', 'like', '%' .$searchValue . '%')->orWhere('building_name', 'like', '%' .$searchValue . '%')
- ->orWhere('street', 'like', '%' .$searchValue . '%')->orWhere('city', 'like', '%' .$searchValue . '%');
- })->where('type_application','B')->orderBy('created_at', 'desc')->skip(intval($start))->take(intval($rowperpage))->get();
- }else{
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_application','B')->orderBy('created_at', 'desc')->skip(intval($start))->take(intval($rowperpage))->get();
- }
- }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
- }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type == 'null' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type != 'null' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
- else if($type != 'null' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use ($building)
- {
- $q->where('building_name', $building)->get();
- }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
- }
-
- $wo = 'null'; $do = 'null';
- if(!empty($form)){
- foreach ($form as $key => $f) {
- if(!empty($f->WorkOrder)){
- $wo = $f->WorkOrder->wo;
-
- if($f->WorkOrder->status == "Completed"){
- $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
- if(!empty($doc)){
- $do = $doc->docket_id;
- }
- }else{
- $wo = $f->WorkOrder->wo;
- $do = "null";
- }
- }else {
- $wo = "null";
- $do = "null";
- }
-
-
- if($f->type_application == 'B' && $f->type_service != "Rectification"){
- $i++;
-
- $n1 = '';
- $reg_time = $f->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }else{
- $n1 = "";
- }
-
-
- if(!empty($f->dealer_id)){
- $labelD = "D/";
- }else {
- $labelD = "";
- }
-
- if(!empty($f->Subscriber)){
- if($f->Subscriber->street != ''){
- $street = $f->Subscriber->street;
- }
-
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'submittion' => Carbon::parse($f->created_at)->toDateString(),
- 'type' => $f->type_service,
- 'name' => $labelD.$f->Subscriber->company_name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $f->Subscriber->unit_no,
- 'building' => $f->Subscriber->building_name,
- 'street' => $street,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
- 'action2' => $wo,
- 'action3' => $do
- ));
- }
- }
- }
- }
-
- $response = array(
- "draw" => intval($draw),
- "recordsTotal" => $totalRecords,
- "recordsFiltered" => $totalRecordswithFilter,
- "data" => $nested_data
- );
-
- return json_encode($response);
- }
-
-
- public function getCustomerWo()
- {
- $curr = Carbon::now()->getTimestamp();
- $work_detail= WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->get();
-
- $i = 0;
- $nested_data = array();
- if(!empty($work_detail)){
- foreach ($work_detail as $a)
- {
- $i++; $y = ''; $n1 = '';
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
- $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
- $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
-
- $inst_name = '';
- if(!empty($installer)){
- $inst_name = $installer->name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$n1,
- 'nature_work' => $a->nature_work,
- 'wo'=>$a->wo,
- 'customer_name' => $formDetail->SubscribersLaravel->name,
- 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
- 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
- 'customer_building' => $formDetail->SubscribersLaravel->building_name,
- 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
- 'customer_city' => $formDetail->SubscribersLaravel->city,
- 'contractor_id' => $contractor->name,
- 'installer_id' => $inst_name,
- 'dateTimeEnd' => $a->dateTimeEnd,
- 'status' => $a->status,
- 'action' => $a->id,
- ));
- }
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function filterCustomerWo($year, $month, $status)
- {
- $curr = Carbon::now()->getTimestamp();
-
- if($year == 'null' && $month == 'null' & $status !='null')
- {
- $nested_data = array();
- $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->where('status', $status)->get();
- $i = 0;
- $nested_data = array();
- if(!empty($work_detail)){
- foreach ($work_detail as $a)
- {
- $i++; $y = ''; $n1 = '';
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }else {
- $n1 = "";
- }
-
- $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
- $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
- $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
-
- $inst_name = '';
- if(!empty($installer)){
- $inst_name = $installer->name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$n1,
- 'nature_work' => $a->nature_work,
- 'wo'=>$a->wo,
- 'customer_name' => $formDetail->SubscribersLaravel->name,
- 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
- 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
- 'customer_building' => $formDetail->SubscribersLaravel->building_name,
- 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
- 'customer_city' => $formDetail->SubscribersLaravel->city,
- 'contractor_id' => $contractor->name,
- 'installer_id' => $inst_name,
- 'dateTimeEnd' => $a->dateTimeEnd,
- 'status' => $a->status,
- 'action' => $a->id,
- ));
- }
- }
- }
-
- if($year=='null' && $month == 'null' & $status == 'null')
- {
- $nested_data = array();
- $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->get();
- $i = 0;
- $nested_data = array();
- if(!empty($work_detail)){
- foreach ($work_detail as $a)
- {
- $i++; $y = ''; $n1 = '';
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }else {
- $n1 = "";
- }
-
- $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
- $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
- $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
-
- $inst_name = '';
- if(!empty($installer)){
- $inst_name = $installer->name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$n1,
- 'nature_work' => $a->nature_work,
- 'wo'=>$a->wo,
- 'customer_name' => $formDetail->SubscribersLaravel->name,
- 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
- 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
- 'customer_building' => $formDetail->SubscribersLaravel->building_name,
- 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
- 'customer_city' => $formDetail->SubscribersLaravel->city,
- 'contractor_id' => $contractor->name,
- 'installer_id' => $inst_name,
- 'dateTimeEnd' => $a->dateTimeEnd,
- 'status' => $a->status,
- 'action' => $a->id,
- ));
- }
- }
- }
-
- if($year!='null' && $month!='nulll' && $status !='null')
- {
- $nested_data = array();
- $start_month = $year."-".$month."-01 00:00:00";
- $end_month = $year."-".$month."-32 23:59:59";
-
- $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->where('status',$status)->get();
- $i = 0;
- $nested_data = array();
- if(!empty($work_detail)){
- foreach ($work_detail as $a)
- {
- $i++; $y = ''; $n1 = '';
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }else {
- $n1 = "";
- }
-
- $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
- $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
- $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
-
- $inst_name = '';
- if(!empty($installer)){
- $inst_name = $installer->name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$n1,
- 'nature_work' => $a->nature_work,
- 'wo'=>$a->wo,
- 'customer_name' => $formDetail->SubscribersLaravel->name,
- 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
- 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
- 'customer_building' => $formDetail->SubscribersLaravel->building_name,
- 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
- 'customer_city' => $formDetail->SubscribersLaravel->city,
- 'contractor_id' => $contractor->name,
- 'installer_id' => $inst_name,
- 'dateTimeEnd' => $a->dateTimeEnd,
- 'status' => $a->status,
- 'action' => $a->id,
- ));
- }
- }
- }
-
- if($year!='null' && $month!='null' && $status =='null')
- {
- $nested_data = array();
- $start_month = $year."-".$month."-01 00:00:00";
- $end_month = $year."-".$month."-32 23:59:59";
-
- $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->get();
- $i = 0;
- $nested_data = array();
- if(!empty($work_detail)){
- foreach ($work_detail as $a)
- {
- $i++; $y = ''; $n1 = '';
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }else {
- $n1 = "";
- }
-
- $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
- $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
- $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
-
- $inst_name = '';
- if(!empty($installer)){
- $inst_name = $installer->name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$n1,
- 'nature_work' => $a->nature_work,
- 'wo'=>$a->wo,
- 'customer_name' => $formDetail->SubscribersLaravel->name,
- 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
- 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
- 'customer_building' => $formDetail->SubscribersLaravel->building_name,
- 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
- 'customer_city' => $formDetail->SubscribersLaravel->city,
- 'contractor_id' => $contractor->name,
- 'installer_id' => $inst_name,
- 'dateTimeEnd' => $a->dateTimeEnd,
- 'status' => $a->status,
- 'action' => $a->id,
- ));
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function deleteCustomerWo(Request $request)
- {
- $wo = WorkOrderLaravel::where('_id',$request->id)->first();
-
- if(!empty($wo)){
- $wo->delete();
- return 'true';
- }else {
- return 'false';
- }
- }
-
- public function getCountry()
- {
- $jsonString = file_get_contents(base_path('resources/views/customer-service/country.json'));
- $data = json_decode($jsonString, true);
-
- return $jsonString;
- }
-
- public function getBuilding()
- {
- $wK = Coverage::all();
-
- $data = array();
- foreach ($wK as $key=>$w) {
- array_push($data, array(
- 'name' => $w->address,
- ));
- }
-
- // Read and parse our events JSON file into an array of event data arrays.
- $json = json_encode($data);
-
- // Send JSON to the client.
- echo $json;
- }
- }
|