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

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