您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CustomerController.php 53KB

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