You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomerController.php 50KB

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