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 51KB

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