123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479 |
- <?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 CC WO'.$numberOnly);
- $numberOnly++;
- info('after CC 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::groupBy('building_name')->orderBy('building_name')->get();
- $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 = '';
- $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;
- }
-
- if($f->type_application == 'R'){
- $name = $f->Subscriber->name;
-
- }else if($f->type_application == 'B'){
-
- $name = $f->Subscriber->company_name;
- }
-
- $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::groupBy('building_name')->orderBy('building_name')->get();
- $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'){
-
- $cov = Coverage::where('building_name',$request->building)->where('street',$request->street)->first();
-
- if(!empty($cov)){
- $building = $cov->building_name;
- $street = $cov->street;
- $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)->where('street', $request->street)->first();
-
- if(!empty($cov)){
- $building = $cov->building_name;
- $street = $cov->street;
- $postcode = $cov->postcode;
- $city = $cov->city;
- $state = $cov->state;
- }else {
- $building = $request->building;
- $street = $request->address;
- $postcode = $request->postcode;
- $city = $request->city;
- $state = $request->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));
- $created = $form->Form->created_at->toDateString();
-
- $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', 'created'));
- }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::groupBy('building_name')->orderBy('building_name')->get();
- $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;
- }
- }
|