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

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