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

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