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

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