Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CustomerController.php 43KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. <?php
  2. namespace App\Http\Controllers\CustomerService;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use LynX39\LaraPdfMerger\Facades\PdfMerger;
  7. use Carbon\Carbon;
  8. use Validator;
  9. use PDF;
  10. use App\Staff;
  11. use App\Model\StaffDetail;
  12. use App\Model\Form;
  13. use App\Model\Subscriber;
  14. use App\Model\WorkOrder;
  15. use App\Model\PackageDetail;
  16. use App\Model\Company;
  17. use App\Model\Coverage;
  18. use App\Model\Product;
  19. use App\Model\Docket;
  20. class CustomerController extends Controller
  21. {
  22. function random_code($limit) {
  23. return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
  24. }
  25. function createWorkID($limit){
  26. $number = WorkOrder::select('id','wo')->orderBy('created_at','DESC')->first();
  27. $numberOnly = str_replace('WO-','',$number->wo);
  28. $numberOnly++;
  29. return $numberOnly;
  30. $allowedNumbers = range(0, 9);
  31. shuffle($allowedNumbers);
  32. $digits = array_rand($allowedNumbers, $limit);
  33. $number = '';
  34. foreach($digits as $d){
  35. $number .= $allowedNumbers[$d];
  36. }
  37. $unique_id = $number;
  38. return $unique_id;
  39. }
  40. public function viewCustomer()
  41. {
  42. $id = Auth::guard('cs')->id();
  43. $user = Staff::with('StaffDetail')->find($id);
  44. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
  45. $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
  46. $rs = count(WorkOrder::where('status','Reschedule')->get());
  47. $ss = count(WorkOrder::where('status','Suspend')->get());
  48. $cm = count(WorkOrder::where('status','Completed')->get());
  49. $coverage = Coverage::all();
  50. $company = Company::where('team','Dealer')->get();
  51. return view('customer-service.view_customer',compact('user','pp','sp','rs','ss','cm','coverage','company'));
  52. }
  53. public function getAllNewCustomer($type,$building,$dealer){
  54. $id = Auth::guard('cs')->id();
  55. $user = Staff::with('StaffDetail')->find($id);
  56. $i = 0; $n1 = ''; $street = ''; $labelD = '';
  57. $curr = Carbon::now()->getTimestamp();
  58. $nested_data = array();
  59. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  60. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->take(1000)->get();
  61. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  62. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  63. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  64. $form = Form::with(['Subscriber' => function($q) use ($building)
  65. {
  66. $q->where('building_name', $building)->get();
  67. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  68. }
  69. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  70. $form = Form::with(['Subscriber' => function($q) use ($building)
  71. {
  72. $q->where('building_name', $building)->get();
  73. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  74. }
  75. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  76. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  77. }
  78. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  79. $form = Form::with(['Subscriber' => function($q) use ($building)
  80. {
  81. $q->where('building_name', $building)->get();
  82. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  83. }
  84. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  85. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  86. }
  87. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  88. $form = Form::with(['Subscriber' => function($q) use ($building)
  89. {
  90. $q->where('building_name', $building)->get();
  91. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  92. }
  93. if(!empty($form)){
  94. foreach ($form as $key => $f) {
  95. if(empty($f->WorkOrder)){
  96. $i++;
  97. $n1 = '';
  98. $reg_time = $f->created_at;
  99. $expiry_date = $reg_time->addDays(3);
  100. $expiry_date = $expiry_date->getTimestamp();
  101. if($curr < $expiry_date) {
  102. $n1 = "New/";
  103. }else{
  104. $n1 = "";
  105. }
  106. if(!empty($f->dealer_id)){
  107. $labelD = "D/";
  108. }else{
  109. $labelD = "";
  110. }
  111. if(!empty($f->Subscriber)){
  112. if($f->Subscriber->street != ''){
  113. $street = $f->Subscriber->street;
  114. }
  115. $wo = '';
  116. if($f->status_email == 'verified'){
  117. $work_order = '';
  118. if($f->type_application == 'R'){
  119. do {
  120. $work_order = 'WO-'.$this->createWorkID(4);
  121. } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
  122. $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
  123. $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','R')->first();
  124. if(!empty($cov)){
  125. if($cov->status_building == 'non prelaid'){
  126. $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
  127. }
  128. }
  129. }else if($f->type_application == 'B'){
  130. do {
  131. $work_order = 'WO-'.$this->createWorkID(4);
  132. } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
  133. $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
  134. $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','B')->first();
  135. if(!empty($cov)){
  136. if($cov->status_building == 'non prelaid'){
  137. $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
  138. }
  139. }
  140. }
  141. }else if($f->status_email == 'unverified'){
  142. $wo = '';
  143. }
  144. $building = ''; $unit = '-'; $address = ''; $name = '';
  145. if($f->type_application == 'R'){
  146. $name = $f->Subscriber->name;
  147. $building = $f->Subscriber->building_name;
  148. $unit = $f->Subscriber->unit_no;
  149. if($f->Subscriber->street != ''){
  150. $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  151. }else {
  152. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  153. }
  154. }else if($f->type_application == 'B'){
  155. $name = $f->Subscriber->company_name;
  156. if($f->Subscriber->unit_no == ''){
  157. $unit = '-';
  158. }else {
  159. $unit = $f->Subscriber->unit_no;
  160. }
  161. $building = $f->Subscriber->street;
  162. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  163. }
  164. $nP = '';
  165. array_push($nested_data, array(
  166. 'formT' => $n1.$i.$f->type_application,
  167. 'type' => $f->type_service,
  168. 'name' => $labelD.$name,
  169. 'phone' => $f->Subscriber->phone1,
  170. 'unit' => $unit,
  171. 'building' => $building,
  172. 'street' => $address,
  173. // 'postcode' => $f->Subscriber->postcode,
  174. // 'city' => $f->Subscriber->city,
  175. 'need_phone' => $nP,
  176. 'email' => $f->status_email,
  177. 'action1' => $wo,
  178. 'action2' => $f->_id
  179. ));
  180. }
  181. }
  182. }
  183. }
  184. return \DataTables::of($nested_data)->make(true);
  185. }
  186. public function getAllNewCustomerss($type,$building,$dealer){
  187. $id = Auth::guard('cs')->id();
  188. $user = Staff::with('StaffDetail')->find($id);
  189. $i = 0; $n1 = ''; $street = ''; $labelD = '';
  190. $curr = Carbon::now()->getTimestamp();
  191. $nested_data = array();
  192. $customer = Subscriber::where('_id','5cb5444ecfe8c571a302d054')->first();
  193. $package = PackageDetail::where('_id','5cb5444ecfe8c571a302d054')->first();
  194. $wo = WorkOrder::where('_id','5cb5444ecfe8c571a302d054')->first();
  195. $f = Form::where('test','ayaya')->first();
  196. dd($f);
  197. $form = Form::with('PackageDetail','WorkOrder','Subscriber')->orderBy('created_at', 'desc')->where('_id','5cb5444ecfe8c571a302d054')->first();
  198. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  199. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  200. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  201. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  202. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  203. $form = Form::with(['Subscriber' => function($q) use ($building)
  204. {
  205. $q->where('building_name', $building)->get();
  206. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  207. }
  208. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  209. $form = Form::with(['Subscriber' => function($q) use ($building)
  210. {
  211. $q->where('building_name', $building)->get();
  212. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  213. }
  214. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  215. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  216. }
  217. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  218. $form = Form::with(['Subscriber' => function($q) use ($building)
  219. {
  220. $q->where('building_name', $building)->get();
  221. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  222. }
  223. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  224. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  225. }
  226. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  227. $form = Form::with(['Subscriber' => function($q) use ($building)
  228. {
  229. $q->where('building_name', $building)->get();
  230. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  231. }
  232. if(!empty($form)){
  233. foreach ($form as $key => $f) {
  234. // if(empty($f->WorkOrder)){
  235. $i++;
  236. $n1 = '';
  237. $reg_time = $f->created_at;
  238. $expiry_date = $reg_time->addDays(3);
  239. $expiry_date = $expiry_date->getTimestamp();
  240. if($curr < $expiry_date) {
  241. $n1 = "New/";
  242. }else{
  243. $n1 = "";
  244. }
  245. if(!empty($f->dealer_id)){
  246. $labelD = "D/";
  247. }else{
  248. $labelD = "";
  249. }
  250. if(!empty($f->Subscriber)){
  251. if($f->Subscriber->street != ''){
  252. $street = $f->Subscriber->street;
  253. }
  254. $wo = '';
  255. if($f->status_email == 'verified'){
  256. $work_order = '';
  257. if($f->type_application == 'R'){
  258. do {
  259. $work_order = 'WO-'.$this->createWorkID(4);
  260. } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
  261. $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
  262. $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','R')->first();
  263. if(!empty($cov)){
  264. if($cov->status_building == 'non prelaid'){
  265. $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
  266. }
  267. }
  268. }else if($f->type_application == 'B'){
  269. do {
  270. $work_order = 'WO-'.$this->createWorkID(4);
  271. } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
  272. $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
  273. $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','B')->first();
  274. if(!empty($cov)){
  275. if($cov->status_building == 'non prelaid'){
  276. $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
  277. }
  278. }
  279. }
  280. }else if($f->status_email == 'unverified'){
  281. $wo = '';
  282. }
  283. array_push($nested_data, array(
  284. $f->_id,
  285. // 'formT' => $n1.$i.$f->type_application,
  286. // 'type' => $f->type_service,
  287. // 'name' => $labelD.$f->Subscriber->name,
  288. // 'phone' => $f->Subscriber->phone1,
  289. // 'unit' => $f->Subscriber->unit_no,
  290. // 'building' => $f->Subscriber->building_name,
  291. // 'street' => $street,
  292. // 'postcode' => $f->Subscriber->postcode,
  293. // 'city' => $f->Subscriber->city,
  294. // 'email' => $f->status_email,
  295. // 'action1' => $wo,
  296. // 'action2' => $f->_id
  297. ));
  298. }
  299. // }
  300. }
  301. }
  302. dd($nested_data);
  303. return \DataTables::of($nested_data)->make(true);
  304. }
  305. public function deleteFormCustomer(Request $request){
  306. $form = Form::where('_id',$request->id)->first();
  307. if(!empty($form)){
  308. $form->delete();
  309. return 'true';
  310. }else {
  311. return 'false';
  312. }
  313. }
  314. public function editSubscriber($subscriber_id){
  315. $id = Auth::guard('cs')->id();
  316. $user = Staff::with('StaffDetail')->find($id);
  317. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
  318. $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
  319. $rs = count(WorkOrder::where('status','Reschedule')->get());
  320. $ss = count(WorkOrder::where('status','Suspend')->get());
  321. $cm = count(WorkOrder::where('status','Completed')->get());
  322. $coverage = Coverage::all();
  323. $form = Subscriber::with('Form')->where('_id',$subscriber_id)->first();
  324. return view('customer-service.edit_subscriber',compact('user','pp','sp','rs','ss','cm','form','coverage'));
  325. }
  326. public function updateCustomerDetail(Request $request){
  327. $form = Subscriber::with('Form')->where('subscriber_id',$request->subscriber_id)->first();
  328. $phone = ''; $street = ''; $fax = '';
  329. if($request->phone2 != null){
  330. $phone = $request->phone2;
  331. }
  332. if($form->Form->type_application == 'R'){
  333. if($request->street != null){
  334. $street = $request->street;
  335. }
  336. $cov = Coverage::where('building_name',$request->building)->first();
  337. if(!empty($cov)){
  338. $building = $cov->building_name;
  339. $postcode = $cov->postcode;
  340. $city = $cov->city;
  341. $state = $cov->state;
  342. }else {
  343. $building = $request->building;
  344. $postcode = '-';
  345. $city = '-';
  346. $state = '-';
  347. }
  348. $form->name = $request->name;
  349. $form->ic = $request->ic;
  350. $form->email = $request->email;
  351. $form->phone1 = $request->phone1;
  352. $form->phone2 = $phone;
  353. $form->unit_no = $request->unit_no;
  354. $form->building_name = $building;
  355. $form->street = $street;
  356. $form->city = $city;
  357. $form->postcode = $postcode;
  358. $form->state = $state;
  359. $form->save();
  360. return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
  361. }else if($form->Form->type_application == 'B'){
  362. if($request->company_fax != null){
  363. $fax = $request->company_fax;
  364. }
  365. $form->company_reg = $request->company_reg;
  366. $form->company_num = $request->company_num;
  367. $form->company_fax = $fax;
  368. $form->company_name = $request->company_name;
  369. $form->unit_no = $request->unit_no;
  370. $form->street = $request->address;
  371. $form->city = $request->city;
  372. $form->postcode = $request->postcode;
  373. $form->state = $request->state;
  374. $form->name = $request->name;
  375. $form->ic = $request->ic;
  376. $form->designation = $request->designation;
  377. $form->email = $request->email;
  378. $form->phone1 = $request->phone1;
  379. $form->phone2 = $phone;
  380. $form->save();
  381. return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
  382. }
  383. }
  384. public function generateRPDF($subscriber_id) {
  385. $id = Auth::guard('cs')->id();
  386. $user = Staff::with('StaffDetail')->find($id);
  387. $product = Product::where('formT','R')->orderBy('created_at','asc')->get();
  388. $form = Subscriber::with('Form')->where('subscriber_id',$subscriber_id)->first();
  389. $package = PackageDetail::where('_id',$form->_id)->first();
  390. $created_at = Carbon::parse($form->created_at)->toDateTimeString();
  391. $ext1 = pathinfo(public_path().$form->front_ic, PATHINFO_EXTENSION);
  392. $ext2 = pathinfo(public_path().$form->back_ic, PATHINFO_EXTENSION);
  393. $ext3 = pathinfo(public_path().$form->visaF, PATHINFO_EXTENSION);
  394. $ext4 = pathinfo(public_path().$form->visaB, PATHINFO_EXTENSION);
  395. $ext5 = pathinfo(public_path().$form->paymentReceipt, PATHINFO_EXTENSION);
  396. $ext6 = pathinfo(public_path().$form->soForm, PATHINFO_EXTENSION);
  397. $documentPath = 'document/'.$subscriber_id;
  398. $created = $form->Form->created_at->toDateString();
  399. // dd($created . $created_at);
  400. $total = floatval($package->montly_fee) + floatval($package->deposit) + floatval($package->voice_fee) + floatval($package->upfront_payment);
  401. // dd($total);
  402. $pdf = PDF::loadView('pdf.residential-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','created_at','created'));
  403. $pdf->setPaper('A4', 'potrait');
  404. if($ext1 == "pdf" || $ext2 == "pdf" || $ext3 == "pdf" || $ext4 == "pdf" || $ext5 == "pdf" || $ext6 == "pdf" ){
  405. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  406. $merges = PDFMerger::init();
  407. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  408. if($ext1 == "pdf"){
  409. $merges->addPDF(public_path().$form->front_ic,'all');
  410. }
  411. if($ext2 == "pdf"){
  412. $merges->addPDF(public_path().$form->back_ic,'all');
  413. }
  414. if($ext3 == "pdf"){
  415. $merges->addPDF(public_path().$form->visaF,'all');
  416. }
  417. if($ext4 == "pdf"){
  418. $merges->addPDF(public_path().$form->visaB,'all');
  419. }
  420. if($ext5 == "pdf"){
  421. $merges->addPDF(public_path().$form->paymentReceipt,'all');
  422. }
  423. if($ext6 == "pdf"){
  424. $merges->addPDF(public_path().$form->soForm,'all');
  425. }
  426. $merges->merge();
  427. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  428. }else if(($ext1 == "jpeg" || $ext1 == "jpg" || $ext1 == "png" ) || ($ext2 == "jpeg" || $ext2 == "jpg" || $ext2 == "png" ) ||
  429. ($ext3 == "jpeg" || $ext3 == "jpg" || $ext3 == "png" ) ||($ext4 == "jpeg" || $ext4 == "jpg" || $ext4 == "png" ) ||
  430. ($ext5 == "jpeg" || $ext5 == "jpg" || $ext5 == "png" ) ||($ext6 == "jpeg" || $ext6 == "jpg" || $ext6 == "png" )){
  431. return $pdf->stream();
  432. }else{
  433. return $pdf->stream();
  434. }
  435. }
  436. public function redirectPDF($sid){
  437. $form = Subscriber::with('Form')->where('_id',$sid)->first();
  438. if($form->Form->type_application == 'R'){
  439. return redirect('/customer-service/residential/generate-pdf/'.$form->subscriber_id);
  440. }else if($form->Form->type_application == 'B'){
  441. return redirect('/customer-service/business/generate-pdf/'.$form->subscriber_id);
  442. }
  443. }
  444. public function generateBPDF($subscriber_id) {
  445. $id = Auth::guard('cs')->id();
  446. $user = Staff::with('StaffDetail')->find($id);
  447. $product = Product::where('formT','B')->get();
  448. $form = Subscriber::with('Form')->where('subscriber_id',$subscriber_id)->first();
  449. $package = PackageDetail::where('_id',$form->_id)->first();
  450. $dateSubmittion = date('d/m/Y', strtotime($form->created_at));
  451. $ext1 = pathinfo(public_path().$form->front_ic, PATHINFO_EXTENSION);
  452. $ext2 = pathinfo(public_path().$form->back_ic, PATHINFO_EXTENSION);
  453. $ext3 = pathinfo(public_path().$form->form9_44, PATHINFO_EXTENSION);
  454. $ext4 = pathinfo(public_path().$form->paymentReceipt, PATHINFO_EXTENSION);
  455. $ext5 = pathinfo(public_path().$form->soForm, PATHINFO_EXTENSION);
  456. $documentPath = 'document/'.$subscriber_id;
  457. // $pdf = PDF::loadView('pdf.business-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','dateSubmittion'));
  458. if(strtotime($form->created_at) >= 1580774399){
  459. $pdf = PDF::loadView('pdf.newBusiness-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','dateSubmittion'));
  460. }else {
  461. $pdf = PDF::loadView('pdf.oldBusiness-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','dateSubmittion'));
  462. }
  463. $pdf->setPaper('A4', 'potrait');
  464. if($ext1 == "pdf" || $ext2 == "pdf" || $ext3 == "pdf" || $ext4 == "pdf" || $ext5 == "pdf" ){
  465. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  466. $merges = PDFMerger::init();
  467. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  468. if($ext1 == "pdf"){
  469. $merges->addPDF(public_path().$form->front_ic,'all');
  470. }
  471. if($ext2 == "pdf"){
  472. $merges->addPDF(public_path().$form->back_ic,'all');
  473. }
  474. if($ext3 == "pdf"){
  475. $merges->addPDF(public_path().$form->form9_44,'all');
  476. }
  477. if($ext4 == "pdf"){
  478. $merges->addPDF(public_path().$form->paymentReceipt,'all');
  479. }
  480. if($ext5 == "pdf"){
  481. $merges->addPDF(public_path().$form->soForm,'all');
  482. }
  483. $merges->merge();
  484. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  485. }else if(($ext1 == "jpeg" || $ext1 == "jpg" || $ext1 == "png" ) || ($ext2 == "jpeg" || $ext2 == "jpg" || $ext2 == "png" ) ||
  486. ($ext3 == "jpeg" || $ext3 == "jpg" || $ext3 == "png" ) ||($ext4 == "jpeg" || $ext4 == "jpg" || $ext4 == "png" ) ||
  487. ($ext5 == "jpeg" || $ext5 == "jpg" || $ext5 == "png" )){
  488. return $pdf->stream();
  489. }else {
  490. return $pdf->stream();
  491. }
  492. }
  493. public function viewSubscriber()
  494. {
  495. $id = Auth::guard('cs')->id();
  496. $user = Staff::with('StaffDetail')->find($id);
  497. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
  498. $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
  499. $rs = count(WorkOrder::where('status','Reschedule')->get());
  500. $ss = count(WorkOrder::where('status','Suspend')->get());
  501. $cm = count(WorkOrder::where('status','Completed')->get());
  502. $rec = count(WorkOrder::where('nature_work','Rectification')->get());
  503. $re = count(Form::where('type_application','R')->get());
  504. $bu = count(Form::where('type_application','B')->get());
  505. $coverage = Coverage::all();
  506. $company = Company::where('team','Dealer')->get();
  507. return view('customer-service.view_subscriber', compact('user','pp','sp','rs','ss','cm','rec','re','bu','coverage','company'));
  508. }
  509. public function getAllRectification($type,$building,$dealer){
  510. $id = Auth::guard('cs')->id();
  511. $user = Staff::with('StaffDetail')->find($id);
  512. $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
  513. $curr = Carbon::now()->getTimestamp();
  514. $nested_data = array();
  515. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  516. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  517. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  518. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  519. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  520. $form = Form::with(['Subscriber' => function($q) use ($building)
  521. {
  522. $q->where('building_name', $building)->get();
  523. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  524. }
  525. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  526. $form = Form::with(['Subscriber' => function($q) use ($building)
  527. {
  528. $q->where('building_name', $building)->get();
  529. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  530. }
  531. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  532. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  533. }
  534. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  535. $form = Form::with(['Subscriber' => function($q) use ($building)
  536. {
  537. $q->where('building_name', $building)->get();
  538. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  539. }
  540. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  541. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  542. }
  543. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  544. $form = Form::with(['Subscriber' => function($q) use ($building)
  545. {
  546. $q->where('building_name', $building)->get();
  547. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  548. }
  549. $wo = 'null'; $do = 'null';
  550. if(!empty($form)){
  551. foreach ($form as $key => $f) {
  552. if(!empty($f->WorkOrder)){
  553. if($f->WorkOrder->nature_work == "Rectification" || $f->type_service == "Rectification") {
  554. $wo = $f->WorkOrder->wo;
  555. if($f->WorkOrder->status == "Completed"){
  556. $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
  557. if(!empty($doc)){
  558. $do = $doc->docket_id;
  559. }
  560. }else{
  561. $wo = $f->WorkOrder->wo;
  562. $do = "null";
  563. }
  564. $i++;
  565. $n1 = '';
  566. $reg_time = $f->created_at;
  567. $expiry_date = $reg_time->addDays(3);
  568. $expiry_date = $expiry_date->getTimestamp();
  569. if($curr < $expiry_date) {
  570. $n1 = "New/";
  571. }
  572. if(!empty($f->dealer_id)){
  573. $labelD = "D/";
  574. }
  575. if(!empty($f->Subscriber)){
  576. if($f->Subscriber->street != ''){
  577. $street = $f->Subscriber->street;
  578. }
  579. $name = '';
  580. if($f->type_application == 'R'){
  581. $name = $f->Subscriber->name;
  582. }else if($f->type_application == 'B'){
  583. $name = $f->Subscriber->building_name;
  584. }
  585. array_push($nested_data, array(
  586. 'formT' => $n1.$i.$f->type_application,
  587. 'submittion' => Carbon::parse($f->created_at)->toDateString(),
  588. 'type' => $f->type_service,
  589. 'name' => $labelD.$name,
  590. 'phone' => $f->Subscriber->phone1,
  591. 'unit' => $f->Subscriber->unit_no,
  592. 'building' => $f->Subscriber->building_name,
  593. 'street' => $street,
  594. 'postcode' => $f->Subscriber->postcode,
  595. 'city' => $f->Subscriber->city,
  596. 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
  597. 'action2' => $wo,
  598. 'action3' => $do
  599. ));
  600. }
  601. }
  602. }
  603. }
  604. }
  605. return \DataTables::of($nested_data)->make(true);
  606. }
  607. public function getAllResidential($type,$building,$dealer){
  608. $id = Auth::guard('cs')->id();
  609. $user = Staff::with('StaffDetail')->find($id);
  610. $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
  611. $curr = Carbon::now()->getTimestamp();
  612. $nested_data = array();
  613. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  614. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  615. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  616. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  617. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  618. $form = Form::with(['Subscriber' => function($q) use ($building)
  619. {
  620. $q->where('building_name', $building)->get();
  621. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  622. }
  623. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  624. $form = Form::with(['Subscriber' => function($q) use ($building)
  625. {
  626. $q->where('building_name', $building)->get();
  627. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  628. }
  629. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  630. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  631. }
  632. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  633. $form = Form::with(['Subscriber' => function($q) use ($building)
  634. {
  635. $q->where('building_name', $building)->get();
  636. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  637. }
  638. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  639. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  640. }
  641. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  642. $form = Form::with(['Subscriber' => function($q) use ($building)
  643. {
  644. $q->where('building_name', $building)->get();
  645. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  646. }
  647. $wo = 'null'; $do = 'null';
  648. if(!empty($form)){
  649. foreach ($form as $key => $f) {
  650. if(!empty($f->WorkOrder)){
  651. $wo = $f->WorkOrder->wo;
  652. if($f->WorkOrder->status == "Completed"){
  653. $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
  654. if(!empty($doc)){
  655. $do = $doc->docket_id;
  656. }
  657. }else{
  658. $wo = $f->WorkOrder->wo;
  659. $do = "null";
  660. }
  661. }else {
  662. $wo = "null";
  663. $do = "null";
  664. }
  665. if($f->type_application == 'R' && $f->type_service != "Rectification"){
  666. $i++;
  667. $n1 = '';
  668. $reg_time = $f->created_at;
  669. $expiry_date = $reg_time->addDays(3);
  670. $expiry_date = $expiry_date->getTimestamp();
  671. if($curr < $expiry_date) {
  672. $n1 = "New/";
  673. }else{
  674. $n1 = "";
  675. }
  676. if(!empty($f->dealer_id)){
  677. $labelD = "D/";
  678. }else {
  679. $labelD = "";
  680. }
  681. if(!empty($f->Subscriber)){
  682. if($f->Subscriber->street != ''){
  683. $street = $f->Subscriber->street;
  684. }
  685. array_push($nested_data, array(
  686. 'formT' => $n1.$i.$f->type_application,
  687. 'submittion' => Carbon::parse($f->created_at)->toDateString(),
  688. 'type' => $f->type_service,
  689. 'name' => $labelD.$f->Subscriber->name,
  690. 'phone' => $f->Subscriber->phone1,
  691. 'unit' => $f->Subscriber->unit_no,
  692. 'building' => $f->Subscriber->building_name,
  693. 'street' => $street,
  694. 'postcode' => $f->Subscriber->postcode,
  695. 'city' => $f->Subscriber->city,
  696. 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
  697. 'action2' => $wo,
  698. 'action3' => $do
  699. ));
  700. }
  701. }
  702. }
  703. }
  704. return \DataTables::of($nested_data)->make(true);
  705. }
  706. public function getAllBusiness($type,$building,$dealer){
  707. $id = Auth::guard('cs')->id();
  708. $user = Staff::with('StaffDetail')->find($id);
  709. $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
  710. $curr = Carbon::now()->getTimestamp();
  711. $nested_data = array();
  712. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  713. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  714. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  715. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  716. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  717. $form = Form::with(['Subscriber' => function($q) use ($building)
  718. {
  719. $q->where('building_name', $building)->get();
  720. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  721. }
  722. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  723. $form = Form::with(['Subscriber' => function($q) use ($building)
  724. {
  725. $q->where('building_name', $building)->get();
  726. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  727. }
  728. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  729. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  730. }
  731. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  732. $form = Form::with(['Subscriber' => function($q) use ($building)
  733. {
  734. $q->where('building_name', $building)->get();
  735. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  736. }
  737. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  738. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  739. }
  740. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  741. $form = Form::with(['Subscriber' => function($q) use ($building)
  742. {
  743. $q->where('building_name', $building)->get();
  744. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  745. }
  746. $wo = 'null'; $do = 'null';
  747. if(!empty($form)){
  748. foreach ($form as $key => $f) {
  749. if(!empty($f->WorkOrder)){
  750. $wo = $f->WorkOrder->wo;
  751. if($f->WorkOrder->status == "Completed"){
  752. $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
  753. if(!empty($doc)){
  754. $do = $doc->docket_id;
  755. }
  756. }else{
  757. $wo = $f->WorkOrder->wo;
  758. $do = "null";
  759. }
  760. }else {
  761. $wo = "null";
  762. $do = "null";
  763. }
  764. if($f->type_application == 'B' && $f->type_service != "Rectification"){
  765. $i++;
  766. $n1 = '';
  767. $reg_time = $f->created_at;
  768. $expiry_date = $reg_time->addDays(3);
  769. $expiry_date = $expiry_date->getTimestamp();
  770. if($curr < $expiry_date) {
  771. $n1 = "New/";
  772. }else{
  773. $n1 = "";
  774. }
  775. if(!empty($f->dealer_id)){
  776. $labelD = "D/";
  777. }else {
  778. $labelD = "";
  779. }
  780. if(!empty($f->Subscriber)){
  781. if($f->Subscriber->street != ''){
  782. $street = $f->Subscriber->street;
  783. }
  784. array_push($nested_data, array(
  785. 'formT' => $n1.$i.$f->type_application,
  786. 'submittion' => Carbon::parse($f->created_at)->toDateString(),
  787. 'type' => $f->type_service,
  788. 'name' => $labelD.$f->Subscriber->company_name,
  789. 'phone' => $f->Subscriber->phone1,
  790. 'unit' => $f->Subscriber->unit_no,
  791. 'building' => $f->Subscriber->building_name,
  792. 'street' => $street,
  793. 'postcode' => $f->Subscriber->postcode,
  794. 'city' => $f->Subscriber->city,
  795. 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
  796. 'action2' => $wo,
  797. 'action3' => $do
  798. ));
  799. }
  800. }
  801. }
  802. }
  803. return \DataTables::of($nested_data)->make(true);
  804. }
  805. public function getCustomerWo()
  806. {
  807. $curr = Carbon::now()->getTimestamp();
  808. $work_detail= WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->get();
  809. $i = 0;
  810. $nested_data = array();
  811. if(!empty($work_detail)){
  812. foreach ($work_detail as $a)
  813. {
  814. $i++; $y = ''; $n1 = '';
  815. $reg_time = $a->created_at;
  816. $expiry_date = $reg_time->addDays(3);
  817. $expiry_date = $expiry_date->getTimestamp();
  818. if($curr < $expiry_date) {
  819. $n1 = "New/";
  820. }
  821. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  822. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  823. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  824. $inst_name = '';
  825. if(!empty($installer)){
  826. $inst_name = $installer->name;
  827. }
  828. array_push($nested_data, array(
  829. 'index' => $i.$n1,
  830. 'nature_work' => $a->nature_work,
  831. 'wo'=>$a->wo,
  832. 'customer_name' => $formDetail->SubscribersLaravel->name,
  833. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  834. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  835. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  836. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  837. 'customer_city' => $formDetail->SubscribersLaravel->city,
  838. 'contractor_id' => $contractor->name,
  839. 'installer_id' => $inst_name,
  840. 'dateTimeEnd' => $a->dateTimeEnd,
  841. 'status' => $a->status,
  842. 'action' => $a->id,
  843. ));
  844. }
  845. }
  846. return \DataTables::of($nested_data)->make(true);
  847. }
  848. public function filterCustomerWo($year, $month, $status)
  849. {
  850. $curr = Carbon::now()->getTimestamp();
  851. if($year == 'null' && $month == 'null' & $status !='null')
  852. {
  853. $nested_data = array();
  854. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->where('status', $status)->get();
  855. $i = 0;
  856. $nested_data = array();
  857. if(!empty($work_detail)){
  858. foreach ($work_detail as $a)
  859. {
  860. $i++; $y = ''; $n1 = '';
  861. $reg_time = $a->created_at;
  862. $expiry_date = $reg_time->addDays(3);
  863. $expiry_date = $expiry_date->getTimestamp();
  864. if($curr < $expiry_date) {
  865. $n1 = "New/";
  866. }else {
  867. $n1 = "";
  868. }
  869. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  870. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  871. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  872. $inst_name = '';
  873. if(!empty($installer)){
  874. $inst_name = $installer->name;
  875. }
  876. array_push($nested_data, array(
  877. 'index' => $i.$n1,
  878. 'nature_work' => $a->nature_work,
  879. 'wo'=>$a->wo,
  880. 'customer_name' => $formDetail->SubscribersLaravel->name,
  881. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  882. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  883. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  884. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  885. 'customer_city' => $formDetail->SubscribersLaravel->city,
  886. 'contractor_id' => $contractor->name,
  887. 'installer_id' => $inst_name,
  888. 'dateTimeEnd' => $a->dateTimeEnd,
  889. 'status' => $a->status,
  890. 'action' => $a->id,
  891. ));
  892. }
  893. }
  894. }
  895. if($year=='null' && $month == 'null' & $status == 'null')
  896. {
  897. $nested_data = array();
  898. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->get();
  899. $i = 0;
  900. $nested_data = array();
  901. if(!empty($work_detail)){
  902. foreach ($work_detail as $a)
  903. {
  904. $i++; $y = ''; $n1 = '';
  905. $reg_time = $a->created_at;
  906. $expiry_date = $reg_time->addDays(3);
  907. $expiry_date = $expiry_date->getTimestamp();
  908. if($curr < $expiry_date) {
  909. $n1 = "New/";
  910. }else {
  911. $n1 = "";
  912. }
  913. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  914. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  915. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  916. $inst_name = '';
  917. if(!empty($installer)){
  918. $inst_name = $installer->name;
  919. }
  920. array_push($nested_data, array(
  921. 'index' => $i.$n1,
  922. 'nature_work' => $a->nature_work,
  923. 'wo'=>$a->wo,
  924. 'customer_name' => $formDetail->SubscribersLaravel->name,
  925. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  926. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  927. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  928. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  929. 'customer_city' => $formDetail->SubscribersLaravel->city,
  930. 'contractor_id' => $contractor->name,
  931. 'installer_id' => $inst_name,
  932. 'dateTimeEnd' => $a->dateTimeEnd,
  933. 'status' => $a->status,
  934. 'action' => $a->id,
  935. ));
  936. }
  937. }
  938. }
  939. if($year!='null' && $month!='nulll' && $status !='null')
  940. {
  941. $nested_data = array();
  942. $start_month = $year."-".$month."-01 00:00:00";
  943. $end_month = $year."-".$month."-32 23:59:59";
  944. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->where('status',$status)->get();
  945. $i = 0;
  946. $nested_data = array();
  947. if(!empty($work_detail)){
  948. foreach ($work_detail as $a)
  949. {
  950. $i++; $y = ''; $n1 = '';
  951. $reg_time = $a->created_at;
  952. $expiry_date = $reg_time->addDays(3);
  953. $expiry_date = $expiry_date->getTimestamp();
  954. if($curr < $expiry_date) {
  955. $n1 = "New/";
  956. }else {
  957. $n1 = "";
  958. }
  959. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  960. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  961. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  962. $inst_name = '';
  963. if(!empty($installer)){
  964. $inst_name = $installer->name;
  965. }
  966. array_push($nested_data, array(
  967. 'index' => $i.$n1,
  968. 'nature_work' => $a->nature_work,
  969. 'wo'=>$a->wo,
  970. 'customer_name' => $formDetail->SubscribersLaravel->name,
  971. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  972. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  973. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  974. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  975. 'customer_city' => $formDetail->SubscribersLaravel->city,
  976. 'contractor_id' => $contractor->name,
  977. 'installer_id' => $inst_name,
  978. 'dateTimeEnd' => $a->dateTimeEnd,
  979. 'status' => $a->status,
  980. 'action' => $a->id,
  981. ));
  982. }
  983. }
  984. }
  985. if($year!='null' && $month!='null' && $status =='null')
  986. {
  987. $nested_data = array();
  988. $start_month = $year."-".$month."-01 00:00:00";
  989. $end_month = $year."-".$month."-32 23:59:59";
  990. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->get();
  991. $i = 0;
  992. $nested_data = array();
  993. if(!empty($work_detail)){
  994. foreach ($work_detail as $a)
  995. {
  996. $i++; $y = ''; $n1 = '';
  997. $reg_time = $a->created_at;
  998. $expiry_date = $reg_time->addDays(3);
  999. $expiry_date = $expiry_date->getTimestamp();
  1000. if($curr < $expiry_date) {
  1001. $n1 = "New/";
  1002. }else {
  1003. $n1 = "";
  1004. }
  1005. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  1006. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  1007. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  1008. $inst_name = '';
  1009. if(!empty($installer)){
  1010. $inst_name = $installer->name;
  1011. }
  1012. array_push($nested_data, array(
  1013. 'index' => $i.$n1,
  1014. 'nature_work' => $a->nature_work,
  1015. 'wo'=>$a->wo,
  1016. 'customer_name' => $formDetail->SubscribersLaravel->name,
  1017. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  1018. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  1019. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  1020. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  1021. 'customer_city' => $formDetail->SubscribersLaravel->city,
  1022. 'contractor_id' => $contractor->name,
  1023. 'installer_id' => $inst_name,
  1024. 'dateTimeEnd' => $a->dateTimeEnd,
  1025. 'status' => $a->status,
  1026. 'action' => $a->id,
  1027. ));
  1028. }
  1029. }
  1030. }
  1031. return \DataTables::of($nested_data)->make(true);
  1032. }
  1033. public function deleteCustomerWo(Request $request)
  1034. {
  1035. $wo = WorkOrderLaravel::where('_id',$request->id)->first();
  1036. if(!empty($wo)){
  1037. $wo->delete();
  1038. return 'true';
  1039. }else {
  1040. return 'false';
  1041. }
  1042. }
  1043. public function getCountry()
  1044. {
  1045. $jsonString = file_get_contents(base_path('resources/views/customer-service/country.json'));
  1046. $data = json_decode($jsonString, true);
  1047. return $jsonString;
  1048. }
  1049. public function getBuilding()
  1050. {
  1051. $wK = Coverage::all();
  1052. $data = array();
  1053. foreach ($wK as $key=>$w) {
  1054. array_push($data, array(
  1055. 'name' => $w->address,
  1056. ));
  1057. }
  1058. // Read and parse our events JSON file into an array of event data arrays.
  1059. $json = json_encode($data);
  1060. // Send JSON to the client.
  1061. echo $json;
  1062. }
  1063. }