| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612 |
- <?php
-
- namespace App\Http\Controllers\v3\Api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\v3\Api\BaseController;
-
- use Config;
- use File;
- use Carbon\Carbon;
-
- use App\LatestModel\Staff;
- use App\LatestModel\StaffDetail;
- use App\LatestModel\Dealer;
- use App\LatestModel\DealerDetail;
- use App\LatestModel\Module\Form;
- use App\LatestModel\Module\FormStatus;
- use App\LatestModel\Module\Subscriber;
- use App\LatestModel\Module\WorkOrder;
- use App\LatestModel\Module\Docket;
- use App\LatestModel\Module\PackageDetail;
- use App\LatestModel\Module\Company;
- use App\LatestModel\Module\Coverage;
- use App\LatestModel\Module\Product;
-
- class ApplicationController extends BaseController
- {
- /**
- * Create work order number controller.
- *
- * @return json
- */
- public function createWorkID($limit){
- $allowedNumbers = range(0, 9);
- shuffle($allowedNumbers);
- $digits = array_rand($allowedNumbers, $limit);
- $number = '';
-
- foreach($digits as $d){
- $number .= $allowedNumbers[$d];
- }
- $unique_id = $number;
- return $unique_id;
- }
-
- /**
- * Create Application Form controller.
- *
- * @return json
- */
- public function getApplicationData($startdate,$enddate,$type,$package,$building,$dealer,$agent){
-
- if($startdate == '-' && $enddate == '-'){
- if($package == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
- }else if($package == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('company_id', $dealer)->get();
- }else if($package == 'R' && $building == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->get();
- }else if($package == 'R' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->where('company_id', $dealer)->get();
- }else if($package == 'R' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use($building) {
- $q->where('building_name', $building);
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->get();
- }else if($package == 'R' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use($building) {
- $q->where('building_name', $building);
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->where('company_id', $dealer)->get();
- }else if($package == 'B' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->get();
- }else if($package == 'B' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->where('company_id', $dealer)->get();
- }
- }else if($startdate != '-'){
- $dateS = Carbon::createFromFormat('Y-m-d', $startdate);
- $start = $dateS->copy()->startOfDay();
-
- if($enddate != '-'){
- $dateE = Carbon::createFromFormat('Y-m-d', $enddate);
- $end = $dateE->copy()->endOfDay();
-
- }else{
- $end = $dateS->copy()->endOfDay();
- }
-
- if($package == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->whereBetween('created_at', array($start, $end))->get();
- }else if($package == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('company_id', $dealer)->whereBetween('created_at',[$start, $end])->get();
- }else if($package == 'R' && $building == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->whereBetween('created_at',[$start, $end])->get();
- }else if($package == 'R' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->whereBetween('created_at',[$start, $end])->where('company_id', $dealer)->get();
- }else if($package == 'R' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use($building) {
- $q->where('building_name', $building);
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->whereBetween('created_at',[$start, $end])->get();
- }else if($package == 'R' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use($building) {
- $q->where('building_name', $building);
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->where('company_id', $dealer)->whereBetween('created_at',[$start, $end])->get();
- }else if($package == 'B' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->whereBetween('created_at',[$start, $end])->get();
- }else if($package == 'B' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->whereBetween('created_at',[$start, $end])->where('company_id', $dealer)->get();
- }
- }
-
- return $form;
- }
-
- public function displayApplicationData($startdate,$enddate,$type,$package,$building,$dealer,$agent){
-
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- $form = $this->getApplicationData($startdate,$enddate,$type,$package,$building,$dealer,$agent);
-
- if(!empty($form)){
- foreach ($form as $key => $f) {
- if($f->type_service != 'Rectification'){
- if($f->status_form != 'Draft' || empty($f->status_form)){
- $nP = ''; $n1 = ''; $labelD = ''; $agentN = '';
- $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->WorkOrder) && !empty($f->Subscriber) && !empty($f->PackageDetail) && !$f->trashed()){
-
- $wo = ''; $work_order = ''; $building = ''; $unit = '-'; $address = '';
- /*** Package ***/
- if($f->PackageDetail->voice_fee == 'Yes' || $f->PackageDetail->voice_fee == 'YES'){
- $nP = 'Yes';
- }else if($f->PackageDetail->voice_fee == 'No' || $f->PackageDetail->voice_fee == 'NO'){
- $nP = 'No';
- }else if($f->PackageDetail->voice_fee == ''){
- $nP = '-';
- }
-
- /*** Generate Work Order ID ***/
- do {
- $work_order = 'WO-'.$this->createWorkID(4);
- if($f->status_email == 'verified'){
- $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
- }else{
- $wo = '';
- }
-
- } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
-
- if($f->type_application == 'R'){
- $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;
- }
-
- $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','R')->first();
- if(!empty($cov)){
- if($cov->status_building == 'non prelaid'){
- $wo = 'Non/'.$wo;
- }
- }
- }else if($f->type_application == 'B'){
-
- if($f->Subscriber->unit_no == ''){
- $unit = '-';
- }else {
- $unit = $f->Subscriber->unit_no;
- }
-
- $building = $f->Subscriber->company_name;
- $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
-
- $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','B')->first();
- if(!empty($cov)){
- if($cov->status_building == 'non prelaid'){
- $wo = 'Non/'.$wo;
- }
- }
- }
-
- if(!empty($f->dealer_id)){
- $company = Company::where('_id', $f->company_id)->first();
- $com = explode(' ',trim($company->name));
- $labelD = 'D/'.$com[0].'.';
- $agentN = Staff::with('StaffDetail')->where('_id', $f->dealer_id)->first();
- $agentN = $agentN->StaffDetail->name;
- }else{
- $labelD = '';
- $agentN = '';
- }
-
- if($f->type_service == $type){
- if($agent == 'null'){
- $i++;
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'date' => $f->created_at->toDateTimeString(),
- 'type' => $f->type_service,
- 'name' => $labelD.$f->Subscriber->name,
- 'phone' => $f->Subscriber->phone1,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'unit' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'need_phone' => $nP,
- 'email' => $f->status_email,
- 'action1' => $wo,
- 'action2' => $f->_id,
- 'agent' => $agentN
- ));
- }else if($f->dealer_id == $agent){
- $i++;
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'date' => $f->created_at->toDateTimeString(),
- 'type' => $f->type_service,
- 'name' => $labelD.$f->Subscriber->name,
- 'phone' => $f->Subscriber->phone1,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'unit' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'need_phone' => $nP,
- 'email' => $f->status_email,
- 'action1' => $wo,
- 'action2' => $f->_id,
- 'agent' => $agentN
- ));
- }
- }else if($type == 'null'){
- if($agent == 'null'){
- $i++;
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'date' => $f->created_at->toDateTimeString(),
- 'type' => $f->type_service,
- 'name' => $labelD.$f->Subscriber->name,
- 'phone' => $f->Subscriber->phone1,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'unit' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'need_phone' => $nP,
- 'email' => $f->status_email,
- 'action1' => $wo,
- 'action2' => $f->_id,
- 'agent' => $agentN
- ));
- }else if($f->dealer_id == $agent){
- $i++;
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'date' => $f->created_at->toDateTimeString(),
- 'type' => $f->type_service,
- 'name' => $labelD.$f->Subscriber->name,
- 'phone' => $f->Subscriber->phone1,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'unit' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'need_phone' => $nP,
- 'email' => $f->status_email,
- 'action1' => $wo,
- 'action2' => $f->_id,
- 'agent' => $agentN
- ));
- }
- }
- }
- }
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
-
- }
-
- public function displayRectificationData($startdate,$enddate,$type,$package,$building,$dealer,$agent){
-
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- $form = $this->getApplicationData($startdate,$enddate,$type,$package,$building,$dealer,$agent);
-
- if(!empty($form)){
- foreach ($form as $key => $f) {
- if($f->type_service == $type){
-
- $wo = ''; $n1 = ''; $do = '';
- $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->Subscriber) && !empty($f->PackageDetail)){
- 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{
- $do = "";
- }
- }
-
- if($f->type_application == 'R'){
- $building = $f->Subscriber->building_name;
- $unit = $f->Subscriber->unit_no;
-
- if($f->Subscriber->street != ''){
- $address = $f->Subscriber->street;
- }else {
- $address = '-';
- }
-
- }else if($f->type_application == 'B'){
-
- if($f->Subscriber->unit_no == ''){
- $unit = '-';
- }else {
- $unit = $f->Subscriber->unit_no;
- }
-
- $building = $f->Subscriber->company_name;
- $address = $f->Subscriber->street;
- }
-
- $i++;
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'submittion' => Carbon::parse($f->created_at)->toDateString(),
- 'type' => $f->type_service,
- 'name' => $f->Subscriber->name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'action3' => $do
- ));
-
- }
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
-
- }
-
-
- public function displayPendingData($startdate,$enddate,$type,$package,$building,$dealer,$agent){
-
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- $form = $this->getApplicationData($startdate,$enddate,$type,$package,$building,$dealer,$agent);
-
- if(!empty($form)){
- foreach ($form as $key => $f) {
- if($f->type_service != 'Rectification'){
- $wo = ''; $n1 = ''; $do = ''; $agentN = '';
- $reg_time = $f->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
-
- if(!empty($f->Subscriber) && !empty($f->PackageDetail) && !empty($f->WorkOrder)){
- if($f->WorkOrder->status != "Completed"){
- $wo = $f->WorkOrder->wo;
-
- if($f->type_application == 'R'){
- $building = $f->Subscriber->building_name;
- $unit = $f->Subscriber->unit_no;
-
- if($f->Subscriber->street != ''){
- $address = $f->Subscriber->street;
- }else {
- $address = '-';
- }
-
- }else if($f->type_application == 'B'){
-
- if($f->Subscriber->unit_no == ''){
- $unit = '-';
- }else {
- $unit = $f->Subscriber->unit_no;
- }
-
- $building = $f->Subscriber->company_name;
- $address = $f->Subscriber->street;
- }
-
- if(!empty($f->dealer_id)){
- $company = Company::where('_id', $f->company_id)->first();
- $com = explode(' ',trim($company->name));
- $labelD = 'D/'.$com[0].'.';
- $agentN = Staff::with('StaffDetail')->where('_id', $f->dealer_id)->first();
- $agentN = $agentN->StaffDetail->name;
- }else{
- $labelD = '';
- $agentN = '';
- }
-
- if($f->type_service == $type){
-
- if($agent == 'null'){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'agent' => $agentN
- ));
- }else if($f->dealer_id == $agent){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'agent' => $agentN
- ));
- }
- }else if($type == 'null'){
- if($agent == 'null'){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'agent' => $agentN
- ));
- }else if($f->dealer_id == $agent){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'agent' => $agentN
- ));
- }
- }
- }
- }
- }
-
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
-
- }
-
- public function displayActivatedData($startdate,$enddate,$type,$package,$building,$dealer,$agent){
-
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- $form = $this->getApplicationData($startdate,$enddate,$type,$package,$building,$dealer,$agent);
-
- if(!empty($form)){
- foreach ($form as $key => $f) {
- if($f->type_service != 'Rectification'){
- $wo = ''; $n1 = ''; $do = ''; $agentN = '';
- $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->Subscriber) && !empty($f->PackageDetail) && !empty($f->WorkOrder)){
- if($f->WorkOrder->status == "Completed"){
- $wo = $f->WorkOrder->wo;
-
- $doc = Docket::where('work_order_id',$wo)->first();
- if(!empty($doc)){
- $do = $doc->docket_id;
- if($f->type_application == 'R'){
- $building = $f->Subscriber->building_name;
- $unit = $f->Subscriber->unit_no;
-
- if($f->Subscriber->street != ''){
- $address = $f->Subscriber->street;
- }else {
- $address = '-';
- }
-
- }else if($f->type_application == 'B'){
-
- if($f->Subscriber->unit_no == ''){
- $unit = '-';
- }else {
- $unit = $f->Subscriber->unit_no;
- }
-
- $building = $f->Subscriber->company_name;
- $address = $f->Subscriber->street;
- }
-
- if(!empty($f->dealer_id)){
- $company = Company::where('_id', $f->company_id)->first();
- $com = explode(' ',trim($company->name));
- $labelD = 'D/'.$com[0].'.';
- $agentN = Staff::with('StaffDetail')->where('_id', $f->dealer_id)->first();
- $agentN = $agentN->StaffDetail->name;
- }else{
- $labelD = '';
- $agentN = '';
- }
-
- if($f->type_service == $type){
- if($agent == 'null'){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'action3' => $do,
- 'action4' => $wo,
- 'agent' => $agentN
- ));
- }else if($f->dealer_id == $agent){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'action3' => $do,
- 'action4' => $wo,
- 'agent' => $agentN
- ));
- }
- }else if($type == 'null'){
- if($agent == 'null'){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'action3' => $do,
- 'action4' => $wo,
- 'agent' => $agentN
- ));
- }else if($f->dealer_id == $agent){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'action3' => $do,
- 'action4' => $wo,
- 'agent' => $agentN
- ));
- }
- }
- }
- }
- }
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
-
- }
-
- public function getDealerForm($startdate,$enddate,$type,$package,$building,$dealer,$agent){
-
- if($startdate == '-' && $enddate == '-'){
- if($package == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereNotNull('dealer_id')->orderBy('created_at', 'desc')->get();
- }else if($package == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('company_id', $dealer)->get();
- }else if($package == 'R' && $building == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereNotNull('dealer_id')->orderBy('created_at', 'desc')->where('type_application', $package)->get();
- }else if($package == 'R' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->where('company_id', $dealer)->get();
- }else if($package == 'R' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use($building) {
- $q->where('building_name', $building);
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->whereNotNull('dealer_id')->where('type_application', $package)->get();
- }else if($package == 'R' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use($building) {
- $q->where('building_name', $building);
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->where('company_id', $dealer)->get();
- }else if($package == 'B' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereNotNull('dealer_id')->orderBy('created_at', 'desc')->where('type_application', $package)->get();
- }else if($package == 'B' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->where('company_id', $dealer)->get();
- }
- }else if($startdate != '-'){
- $dateS = Carbon::createFromFormat('Y-m-d', $startdate);
- $start = $dateS->copy()->startOfDay();
-
- if($enddate != '-'){
- $dateE = Carbon::createFromFormat('Y-m-d', $enddate);
- $end = $dateE->copy()->endOfDay();
-
- }else{
- $end = $dateS->copy()->endOfDay();
- }
-
- if($package == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereNotNull('dealer_id')->orderBy('created_at', 'desc')->whereBetween('created_at', array($start, $end))->get();
- }else if($package == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('company_id', $dealer)->whereBetween('created_at',[$start, $end])->get();
- }else if($package == 'R' && $building == 'null' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereNotNull('dealer_id')->orderBy('created_at', 'desc')->where('type_application', $package)->whereBetween('created_at',[$start, $end])->get();
- }else if($package == 'R' && $building == 'null' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->whereBetween('created_at',[$start, $end])->where('company_id', $dealer)->get();
- }else if($package == 'R' && $building != 'null' && $dealer == 'null'){
- $form = Form::with(['Subscriber' => function($q) use($building) {
- $q->where('building_name', $building);
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->whereNotNull('dealer_id')->where('type_application', $package)->whereBetween('created_at',[$start, $end])->get();
- }else if($package == 'R' && $building != 'null' && $dealer != 'null'){
- $form = Form::with(['Subscriber' => function($q) use($building) {
- $q->where('building_name', $building);
- }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->where('company_id', $dealer)->whereBetween('created_at',[$start, $end])->get();
- }else if($package == 'B' && $dealer == 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereNotNull('dealer_id')->orderBy('created_at', 'desc')->where('type_application', $package)->whereBetween('created_at',[$start, $end])->get();
- }else if($package == 'B' && $dealer != 'null'){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->where('type_application', $package)->whereBetween('created_at',[$start, $end])->where('company_id', $dealer)->get();
- }
- }
-
- return $form;
- }
-
- public function displayDealerForm($startdate,$enddate,$type,$package,$building,$dealer,$agent){
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- $form = $this->getDealerForm($startdate,$enddate,$type,$package,$building,$dealer,$agent);
-
- if(!empty($form)){
- foreach ($form as $key => $f) {
- $wo = ''; $n1 = ''; $do = ''; $agentN = '';
- $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)){
-
- $company = Company::where('_id', $f->company_id)->first();
- $com = explode(' ',trim($company->name));
- $labelD = 'D/'.$com[0].'.';
- $agentN = Staff::with('StaffDetail')->where('_id', $f->dealer_id)->first();
- $agentN = $agentN->StaffDetail->name;
-
- if(!empty($f->Subscriber) && !empty($f->PackageDetail)){
-
- if(!empty($f->WorkOrder)){
- $wo = $f->WorkOrder->wo;
-
- if($f->WorkOrder->status == "Completed"){
- $doc = Docket::where('work_order_id',$wo)->first();
- if(!empty($doc)){ $do = $doc->docket_id; }
- }
- }
-
- if($f->type_application == 'R'){
- $building = $f->Subscriber->building_name;
- $unit = $f->Subscriber->unit_no;
-
- if($f->Subscriber->street != ''){
- $address = $f->Subscriber->street;
- }else {
- $address = '-';
- }
-
- }else if($f->type_application == 'B'){
- if($f->Subscriber->unit_no == ''){
- $unit = '-';
- }else {
- $unit = $f->Subscriber->unit_no;
- }
-
- $building = $f->Subscriber->company_name;
- $address = $f->Subscriber->street;
- }
-
- if($f->type_service == $type){
- if($agent == 'null'){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'action3' => $do,
- 'action4' => $wo,
- 'agent' => $agentN
- ));
- }else if($f->dealer_id == $agent){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'action3' => $do,
- 'action4' => $wo,
- 'agent' => $agentN
- ));
- }
- }else if($type == 'null'){
- if($agent == 'null'){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'action3' => $do,
- 'action4' => $wo,
- 'agent' => $agentN
- ));
- }else if($f->dealer_id == $agent){
- $i++;
- 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' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'action1' => $f->_id,
- 'action2' => $wo,
- 'action3' => $do,
- 'action4' => $wo,
- 'agent' => $agentN
- ));
- }
- }
- }
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- /**
- * Create Data Form controller.
- *
- * @return json
- */
- public function filterByTypeADate($type, $startdate, $enddate){
- if($type == 'All' && $startdate == 'null'){
- $form = Form::with('Subscriber','PackageDetail')->orderBy('created_at', 'desc');
- return $form;
- }else if($type == 'All' && $startdate != 'null'){
-
- $dateS = Carbon::createFromFormat('Y-m-d', $startdate);
- $start = $dateS->copy()->startOfDay();
-
- $dateE = Carbon::createFromFormat('Y-m-d', $enddate);
- $end = $dateE->copy()->endOfDay();
-
- $form = Form::with('Subscriber','PackageDetail')->orderBy('created_at', 'desc')->whereBetween('created_at', array($start, $end));
- return $form;
- }else if($type != 'All' && $startdate == 'null'){
- $form = Form::with('Subscriber','PackageDetail')->where('type_service',$type)->orderBy('created_at', 'desc');
- return $form;
- }else if($type != 'All' && $startdate == 'null'){
- $dateS = Carbon::createFromFormat('Y-m-d', $startdate);
- $start = $dateS->copy()->startOfDay();
-
- $dateE = Carbon::createFromFormat('Y-m-d', $enddate);
- $end = $dateE->copy()->endOfDay();
-
- $form = Form::with('Subscriber','PackageDetail')->where('type_service',$type)->orderBy('created_at', 'desc')->whereBetween('created_at', array($start, $end));
- return $form;
- }
- }
-
- public function filterByPackage($type,$startdate,$enddate,$package){
- $form = $this->filterByTypeADate($type,$startdate,$enddate);
- if($package == 'All'){
- return $form;
- }else{
- $form = $form->where('type_application', $package);
- return $form;
- }
- }
-
- public function filterByBuilding($type,$startdate,$enddate,$package,$building){
- $form = $this->filterByPackage($type,$startdate,$enddate,$package);
- if($building == 'null'){
- return $form->with('Subscriber');
- }else{
- return $form->with(['Subscriber' => function($q) use($building) {
- $q->where('building_name', $building);
- }]);
- }
- }
-
- public function filterByDealer($type,$startdate,$enddate,$package,$building,$dealer){
- $form = $this->filterByBuilding($type,$startdate,$enddate,$package,$building);
- if($dealer != 'null'){
- $form = $form->where('company_id', $dealer);
- return $form;
- }else{
- return $form;
- }
- }
-
- public function filterByAgent($type,$startdate,$enddate,$package,$building,$dealer,$agent){
- $form = $this->filterByDealer($type,$startdate,$enddate,$package,$building,$dealer);
- if($agent == 'null'){
- return $form;
- }else{
- $form = $form->where('dealer_id', $agent);
- return $form;
- }
- }
-
- public function displayNewData($type,$startdate,$enddate,$package,$building,$dealer,$agent,$subcriber){
- if($dealer != 'null' && $agent != 'null'){
- $form = $this->filterByAgent($type,$startdate,$enddate,$package,$building,$dealer,$agent);
- }else if($dealer != 'null' && $agent == 'null'){
- $form = $this->filterByDealer($type,$startdate,$enddate,$package,$building,$dealer);
- }else if($dealer == 'null' && $agent == 'null'){
- $form = $this->filterByDealer($type,$startdate,$enddate,$package,$building,$dealer);
- }
-
- if($subcriber != 'null'){
- $form = $form->with(['Subscriber' => function($q) use($subcriber) {
- $q->where('subscriber_id', 'CBB-'.$subcriber);
- }],'PackageDetail','WorkOrder')->get();
- }else{
- $form = $form->with('PackageDetail','WorkOrder')->get();
- }
-
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if(!empty($form)){
- foreach ($form as $key => $f) {
-
- $n1 = ''; $labelD = ''; $agent = ''; $name = '';
-
- $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)){
- $company = Company::where('_id', $f->company_id)->first();
- $com = explode(' ',trim($company->name));
- $labelD = 'D/'.$com[0].'.';
- $agent = Staff::with('StaffDetail')->where('_id', $f->dealer_id)->first();
- $agent = $agent->StaffDetail->name;
- }else{ $labelD = ''; }
-
- if(!empty($f->Subscriber) && !empty($f->PackageDetail) && empty($f->WorkOrder) && $f->type_service != "Rectification"){
-
- $wo = ''; $work_order = ''; $building = ''; $unit = '-'; $address = '';
- /*** Package ***/
- if($f->PackageDetail->voice_fee == 'Yes' || $f->PackageDetail->voice_fee == 'YES'){
- $nP = 'Yes';
- }else if($f->PackageDetail->voice_fee == 'No' || $f->PackageDetail->voice_fee == 'NO'){
- $nP = 'No';
- }else if($f->PackageDetail->voice_fee == ''){
- $nP = '-';
- }
-
- /*** Generate Work Order ID ***/
- do {
- $work_order = 'WO-'.$this->createWorkID(4);
- if($f->status_email == 'verified'){
- $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
- }else{
- $wo = '';
- }
- } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
-
- 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'){
-
- if($f->Subscriber->unit_no == ''){
- $unit = '-';
- }else {
- $unit = $f->Subscriber->unit_no;
- }
-
- $name = $f->Subscriber->company_name;
- $building = $f->Subscriber->building_name;
- $address = $f->Subscriber->street. ', '.$f->Subscriber->postcode. ', '.$f->Subscriber->city. ', '.$f->Subscriber->state;
- }
-
- $i++;
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'date' => $f->created_at->toDateString(),
- 'id' => str_replace("CBB-","",$f->Subscriber->subscriber_id),
- 'type' => $f->type_service,
- 'name' => $labelD.$f->Subscriber->name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'agent' => $agent,
- 'type' => $f->type_service,
- 'need_phone' => $nP,
- 'email' => $f->status_email,
- 'action' => $f->_id,
- 'action1' => $wo,
- ));
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function displayProcessData($type,$startdate,$enddate,$package,$building,$dealer,$agent,$subcriber){
- if($dealer != 'null' && $agent != 'null'){
- $form = $this->filterByAgent($type,$startdate,$enddate,$package,$building,$dealer,$agent);
- }else if($dealer != 'null' && $agent == 'null'){
- $form = $this->filterByDealer($type,$startdate,$enddate,$package,$building,$dealer);
- }
-
- if($subcriber != 'null'){
- $form = $form->with(['Subscriber' => function($q) use($subcriber) {
- $q->where('subscriber_id', 'CBB-'.$subcriber);
- }],'PackageDetail','WorkOrder')->get();
- }else{
- $form = $form->with('PackageDetail','WorkOrder')->get();
- }
-
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if(!empty($form)){
- foreach ($form as $key => $f) {
-
- $n1 = ''; $labelD = ''; $agent = ''; $name = '';
-
- $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)){
- $company = Company::where('_id', $f->company_id)->first();
- $com = explode(' ',trim($company->name));
- $labelD = 'D/'.$com[0].'.';
- $agent = Staff::with('StaffDetail')->where('_id', $f->dealer_id)->first();
- $agent = $agent->StaffDetail->name;
- }else{ $labelD = ''; }
-
- if(!empty($f->Subscriber) && !empty($f->PackageDetail) && !empty($f->WorkOrder)){
- 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'){
-
- if($f->Subscriber->unit_no == ''){
- $unit = '-';
- }else {
- $unit = $f->Subscriber->unit_no;
- }
-
- $name = $f->Subscriber->company_name;
- $building = $f->Subscriber->building_name;
- $address = $f->Subscriber->street. ', '.$f->Subscriber->postcode. ', '.$f->Subscriber->city. ', '.$f->Subscriber->state;
- }
-
- $i++;
- if($f->WorkOrder->status != 'Completed'){
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'wo' => $f->WorkOrder->wo,
- 'date' => $f->created_at->toDateString(),
- 'id' => str_replace("CBB-","",$f->Subscriber->subscriber_id),
- 'type' => $f->type_service,
- 'name' => $labelD.$f->Subscriber->name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'agent' => $agent,
- 'action' => $f->_id,
- ));
- }
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function displayCompletedData($type,$startdate,$enddate,$package,$building,$dealer,$agent,$subcriber){
- if($dealer != 'null' && $agent != 'null'){
- $form = $this->filterByAgent($type,$startdate,$enddate,$package,$building,$dealer,$agent);
- }else if($dealer != 'null' && $agent == 'null'){
- $form = $this->filterByDealer($type,$startdate,$enddate,$package,$building,$dealer);
- }
-
- if($subcriber != 'null'){
- $form = $form->with(['Subscriber' => function($q) use($subcriber) {
- $q->where('subscriber_id', 'CBB-'.$subcriber);
- }],'PackageDetail','WorkOrder')->get();
- }else{
- $form = $form->with('PackageDetail','WorkOrder')->get();
- }
-
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if(!empty($form)){
- foreach ($form as $key => $f) {
-
- $n1 = ''; $labelD = ''; $agent = ''; $name = '';
-
- $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)){
- $company = Company::where('_id', $f->company_id)->first();
- $com = explode(' ',trim($company->name));
- $labelD = 'D/'.$com[0].'.';
- $agent = Staff::with('StaffDetail')->where('_id', $f->dealer_id)->first();
- $agent = $agent->StaffDetail->name;
- }else{ $labelD = ''; }
-
- if(!empty($f->Subscriber) && !empty($f->PackageDetail) && !empty($f->WorkOrder)){
- 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'){
-
- if($f->Subscriber->unit_no == ''){
- $unit = '-';
- }else {
- $unit = $f->Subscriber->unit_no;
- }
-
- $name = $f->Subscriber->company_name;
- $building = $f->Subscriber->building_name;
- $address = $f->Subscriber->street. ', '.$f->Subscriber->postcode. ', '.$f->Subscriber->city. ', '.$f->Subscriber->state;
- }
-
- $i++;
- if($f->WorkOrder->status == 'Completed'){
-
- $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
- $activated = '-'; $do = '-';
- if(!empty($doc)){
- $do = $doc->docket_id;
- $activated = $doc->end_job;
- }
-
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'wo' => $f->WorkOrder->wo,
- 'do' => $do,
- 'active' => $activated,
- 'id' => str_replace("CBB-","",$f->Subscriber->subscriber_id),
- 'type' => $f->type_service,
- 'name' => $labelD.$f->Subscriber->name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'agent' => $agent,
- 'action' => $f->_id,
- ));
- }
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- /**
- * Create Trashed Data Form controller.
- *
- * @return json
- */
- public function filterTrashedByTypeADate($type, $startdate, $enddate){
- if($type == 'All' && $startdate == 'null'){
- $form = Form::with('subscribetrashed','packagedetailtrashed')->orderBy('created_at', 'desc')->onlyTrashed();
- return $form;
- }else if($type == 'All' && $startdate != 'null'){
-
- $dateS = Carbon::createFromFormat('Y-m-d', $startdate);
- $start = $dateS->copy()->startOfDay();
-
- $dateE = Carbon::createFromFormat('Y-m-d', $enddate);
- $end = $dateE->copy()->endOfDay();
-
- $form = Form::with('subscribetrashed','packagedetailtrashed')->orderBy('created_at', 'desc')->whereBetween('created_at', array($start, $end))->onlyTrashed();
-
- return $form;
- }
- }
-
- public function filterTrashedByPackage($type,$startdate,$enddate,$package){
- $form = $this->filterTrashedByTypeADate($type,$startdate,$enddate);
- if($package == 'All'){
- return $form;
- }else{
- $form = $form->where('type_application', $package);
- return $form;
- }
- }
-
- public function filterTrashedByBuilding($type,$startdate,$enddate,$package,$building){
- $form = $this->filterTrashedByPackage($type,$startdate,$enddate,$package);
- if($building == 'null'){
- return $form->with('subscribetrashed');
- }else{
- return $form->with(['subscribetrashed' => function($q) use($building) {
- $q->where('building_name', $building);
- }]);
- }
- }
-
- public function filterTrashedByDealer($type,$startdate,$enddate,$package,$building,$dealer){
- $form = $this->filterTrashedByBuilding($type,$startdate,$enddate,$package,$building);
- if($dealer != 'null'){
- $form = $form->where('company_id', $dealer);
- return $form;
- }else{
- return $form;
- }
- }
-
- public function filterTrashedByAgent($type,$startdate,$enddate,$package,$building,$dealer,$agent){
- $form = $this->filterTrashedByDealer($type,$startdate,$enddate,$package,$building,$dealer);
- if($agent == 'null'){
- return $form;
- }else{
- $form = $form->where('dealer_id', $agent);
- return $form;
- }
- }
-
- public function displayTrashedData($type,$startdate,$enddate,$package,$building,$dealer,$agent,$subcriber){
-
- if($dealer != 'null' && $agent != 'null'){
- $form = $this->filterTrashedByAgent($type,$startdate,$enddate,$package,$building,$dealer,$agent);
- }else if($dealer != 'null' && $agent == 'null'){
- $form = $this->filterTrashedByDealer($type,$startdate,$enddate,$package,$building,$dealer);
- }else if($dealer == 'null' && $agent == 'null'){
- $form = $this->filterTrashedByDealer($type,$startdate,$enddate,$package,$building,$dealer);
- }
-
- if($subcriber != 'null'){
- $form = $form->with(['subscribetrashed' => function($q) use($subcriber) {
- $q->where('subscriber_id', 'CBB-'.$subcriber);
- }],'packagedetailtrashed')->get();
- }else{
- $form = $form->with('packagedetailtrashed')->get();
- }
-
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if(!empty($form)){
- foreach ($form as $key => $f) {
-
- $n1 = ''; $labelD = ''; $agent = ''; $name = '';
-
- $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)){
- $company = Company::where('_id', $f->company_id)->first();
- $com = explode(' ',trim($company->name));
- $labelD = 'D/'.$com[0].'.';
- $agent = Staff::with('StaffDetail')->where('_id', $f->dealer_id)->first();
- $agent = $agent->StaffDetail->name;
- }else{ $labelD = ''; }
-
- if(!empty($f->subscribetrashed) && !empty($f->packagedetailtrashed)){
- if($f->type_application == 'R'){
-
- $name = $f->subscribetrashed->name;
- $building = $f->subscribetrashed->building_name;
- $unit = $f->subscribetrashed->unit_no;
-
- if($f->subscribetrashed->street != ''){
- $address = $f->subscribetrashed->street. ', '.$f->subscribetrashed->postcode. ' , '.$f->subscribetrashed->city. ', '.$f->subscribetrashed->state;
- }else {
- $address = $f->subscribetrashed->postcode. ', '.$f->subscribetrashed->city. ', '.$f->subscribetrashed->state;
- }
- }else if($f->type_application == 'B'){
-
- if($f->subscribetrashed->unit_no == ''){
- $unit = '-';
- }else {
- $unit = $f->subscribetrashed->unit_no;
- }
-
- $name = $f->subscribetrashed->company_name;
- $building = $f->subscribetrashed->building_name;
- $address = $f->subscribetrashed->street. ', '.$f->subscribetrashed->postcode. ', '.$f->subscribetrashed->city. ', '.$f->subscribetrashed->state;
- }
-
- $i++;
- array_push($nested_data, array(
- 'formT' => $n1.$i.$f->type_application,
- 'date' => $f->created_at->toDateString(),
- 'id' => str_replace("CBB-","",$f->subscribetrashed->subscriber_id),
- 'type' => $f->type_service,
- 'name' => $labelD.$f->subscribetrashed->name,
- 'phone' => $f->subscribetrashed->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'street' => $address,
- 'agent' => $agent,
- 'remark' => $f->remark_reject,
- 'action' => $f->_id,
- ));
- }
- }
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- /**
- * Delete / Reject Form controller
- *
- * @return json
- */
- public function rejectForm(Request $request) {
- $form = Form::with('Subscriber','PackageDetail')->where('_id', $request->id)->first();
- if(!empty($form)){
- $form->remark_reject = $request->reason;
- $saved = $form->save();
-
- if($saved){
- if(!empty($form->Subscriber)){
- $form->subscriber()->delete();
- }
- if(!empty($form->PackageDetail)){
- $form->packagedetail()->delete();
- }
- $form->delete();
- return $this->sendResponse($form, 'The form success been rejected. You can see the form in rejected category');
- }else{
- return $this->sendError('Cant Reject the form!', '');
- }
-
- }else {
- return $this->sendError('Form not exist!', '');
- }
- }
- /**
- * Restore Form controller
- *
- * @return json
- */
- public function restoreForm(Request $request) {
- $form = Form::with('subscribetrashed','packagedetailtrashed')->where('_id', $request->id)->withTrashed()->first();
- if(!empty($form)){
- if(!empty($form->subscribetrashed)){
- $form->subscribetrashed()->restore();
- }
- if(!empty($form->packagedetailtrashed)){
- $form->packagedetailtrashed()->restore();
- }
- $form->restore();
- return $this->sendResponse($form, 'The form success been restore. You can see the form in application category');
- }else {
- return $this->sendError('Form not exist!', '');
- }
- }
- /**
- * Update Status Email Form controller
- *
- * @return json
- */
- public function forceVerifyform(Request $request) {
- $form = Form::where('_id', $request->id)->first();
- if(!empty($form)){
- if($form->status_email == 'unverified'){
- $form->status_email = 'verified';
- $form->save();
-
- $stat = new FormStatus();
- $stat->form_id = $form->_id;
- $stat->status_id = 2;
- $stat->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
- $stat->status = 'Verified';
- $stat->desc = 'Email already been verified by Customer Service';
- $form->formstatus()->save($stat);
-
- return $this->sendResponse($form, 'Email already been verified by SHTECH');
- }else{
- return $this->sendError('Email already been verified!', '');
- }
- }else {
- return $this->sendError('Form not exist!', '');
- }
- }
-
- /**
- * View PDF
- *
- * @return json
- */
- public function viewFormPDF(Request $request){
- $form = Form::with('Subscriber','subscribetrashed')->where('_id', $request->id)->withTrashed()->first();
- if(!empty($form)){
- if(!empty($form->Subscriber) || !empty($form->subscribetrashed)){
- if(!empty($form->Subscriber)){
- if($form->type_application == 'R'){
- return $this->sendResponse($form, '/residential/generate-pdf/'.$form->Subscriber->subscriber_id);
- }else if($form->type_application == 'B'){
- return $this->sendResponse($form, '/business/generate-pdf/'.$form->Subscriber->subscriber_id);
- }
- }else{
- if($form->type_application == 'R'){
- return $this->sendResponse($form, '/residential/generate-pdf/'.$form->subscribetrashed->subscriber_id);
- }else if($form->type_application == 'B'){
- return $this->sendResponse($form, '/business/generate-pdf/'.$form->subscribetrashed->subscriber_id);
- }
- }
- }else {
- return $this->sendError('Data subscriber not exist!', '');
- }
- }else {
- return $this->sendError('Form not exist!', '');
- }
- }
-
- /**
- * View PDF
- *
- * @return json
- */
- public function viewCustomerForm(Request $request){
- $form = Form::with('Subscriber','PackageDetail')->where('_id', $request->id)->first();
- if(!empty($form)){
- if(!empty($form->Subscriber) && !empty($form->PackageDetail)){
- return $this->sendResponse($form, '/edit/form/customer/'.$form->Subscriber->subscriber_id);
- }else {
- return $this->sendError('Data subscriber or package not exist!', '');
- }
- }else {
- return $this->sendError('Form not exist!', '');
- }
- }
-
- public function viewCustomerFormTrashed(Request $request){
- $form = Form::with('subscribetrashed','packagedetailtrashed')->where('_id', $request->id)->withTrashed()->first();
- if(!empty($form)){
- if(!empty($form->subscribetrashed) && !empty($form->packagedetailtrashed)){
- return $this->sendResponse($form, '/edit/form/customer/'.$form->subscribetrashed->subscriber_id);
- }else {
- return $this->sendError('Data subscriber or package not exist!', '');
- }
- }else {
- return $this->sendError('Form not exist!', '');
- }
- }
-
- /**
- * View Form History
- *
- * @return json
- */
- public function getOrderHistory($id){
-
- $data = array();
- $order_history = FormStatus::where('form_id', $id)->get();
- foreach($order_history as $oh){
- $utcdatetime = new \MongoDB\BSON\UTCDateTime((string) $oh->date);
- $datetime = $utcdatetime->toDateTime();
- $time = $datetime->format(DATE_RSS);
- $time = strtotime($time.' UTC');
- $dateInLocal = date("d/m/Y h:i a", $time);
- $data[] = array(
- 'date' => $dateInLocal,
- 'status' => $oh->status,
- 'desc' => $oh->desc
- );
- }
- return response()->json($data);
- }
-
- public function getDeleteformHoho(){
- $form = Form::onlyTrashed()->get();
- foreach($form as $f){
- $package = PackageDetail::where('_id', $f->_id)->first();
- if(!empty($package)){
- $package->deleted_at = $f->deleted_at;
- $package->save();
- }
- $subsc = Subscriber::where('_id', $f->_id)->first();
- if(!empty($subsc)){
- $subsc->deleted_at = $f->deleted_at;
- $subsc->save();
- }
- }
-
- return response()->json($form);
- }
-
-
- public function getSubscriberId(Request $request){
- $subscriber = Subscriber::where('_id', $request->id)->first();
- if(!empty($subscriber)){
- $data = [
- '_id' => $subscriber->_id,
- 'email' => $subscriber->email,
- 'subscriber_id' => $subscriber->subscriber_id
- ];
- return response()->json(['status' => 'true', 'desc' => $data]);
- }else{
- return response()->json(['status' => 'false', 'desc' => 'Rekod ini tidak ditemui']);
- }
- }
-
- public function savedAndSendEmail(Request $request){
- $subscriber = Subscriber::where('_id', $request->_id)->first();
- if(!empty($subscriber)){
- $subscriber->email = $request->email;
- $subscriber->save();
-
- $client1 = new \GuzzleHttp\Client();
- $request1 = $client1->get('https://cumas.swisslink.com.my/resend-email/'.$subscriber->subscriber_id);
- $response1 = json_decode($request1->getBody()->getContents());
-
- if($response1 == $subscriber->_id){
- return redirect()->back()->with('success_msg', 'Successfully update and send email!');
- }else{
- return redirect()->back()->with('error_msg', 'Cant send Email!');
- }
-
- }else{
- return redirect()->back()->with('error_msg', 'Subscriber detail cant been found!');
- }
- }
- }
|