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

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