Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ApplicationController.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. namespace App\Http\Controllers\v3\Main;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Carbon\Carbon;
  7. use App\SiteSetting;
  8. use App\LatestModel\Staff;
  9. use App\LatestModel\StaffDetail;
  10. use App\LatestModel\Module\Form;
  11. use App\LatestModel\Module\Subscriber;
  12. use App\LatestModel\Module\WorkOrder;
  13. use App\LatestModel\Module\PackageDetail;
  14. use App\LatestModel\Module\Company;
  15. use App\LatestModel\Module\Coverage;
  16. use App\LatestModel\Module\Product;
  17. use App\LatestModel\Module\Docket;
  18. class ApplicationController extends Controller
  19. {
  20. /***
  21. /* Application Form
  22. **/
  23. public function applicationForm(){
  24. $id = Auth::guard('main')->id();
  25. $user = Staff::with('StaffDetail')->find($id);
  26. $site = SiteSetting::first();
  27. $company = Company::where('team','Dealer')->get();
  28. $coverage = Coverage::where('Type','R')->orderBy('building_name')->get();
  29. $c1 = 0; $c2 = 0; $c3 = 0; $c3_r = 0; $c3_b = 0;$c4 = 0; $c5 = 0;
  30. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->withTrashed()->get();
  31. foreach ($form as $key => $f) {
  32. if(empty($f->WorkOrder) && !empty($f->Subscriber) && $f->type_service != "Rectification" && !$f->trashed()){
  33. $c1++;
  34. }else if(!empty($f->WorkOrder) && $f->type_service != "Rectification"){
  35. if($f->WorkOrder->status == 'Completed') {
  36. $c3++;
  37. if($f->type_application == 'R'){
  38. $c3_r++;
  39. }else if($f->type_application == 'B'){
  40. $c3_b++;
  41. }
  42. }else{
  43. $c2++;
  44. }
  45. }else if(empty($f->WorkOrder) && $f->trashed()){
  46. $c4++;
  47. }else if($f->type_service == "Rectification"){
  48. $c5++;
  49. }
  50. }
  51. return view('v3.main-dashboard.form.application_form', compact('user','site','company','coverage','c1','c2','c3','c3_r','c3_b','c4','c5'));
  52. }
  53. /***
  54. /* Rectification Form
  55. **/
  56. public function rectificationForm(){
  57. $id = Auth::guard('main')->id();
  58. $user = Staff::with('StaffDetail')->find($id);
  59. $site = SiteSetting::first();
  60. $coverage = Coverage::where('Type','R')->orderBy('building_name')->get();
  61. $c1 = 0; $c2 = 0; $c3 = 0; $c3_r = 0; $c3_b = 0;$c4 = 0; $c5 = 0;
  62. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->withTrashed()->get();
  63. foreach ($form as $key => $f) {
  64. if(empty($f->WorkOrder) && $f->type_service != "Rectification" && !$f->trashed()){
  65. $c1++;
  66. }else if(!empty($f->WorkOrder) && $f->type_service != "Rectification"){
  67. if($f->WorkOrder->status == 'Completed') {
  68. $c3++;
  69. if($f->type_application == 'R'){
  70. $c3_r++;
  71. }else if($f->type_application == 'B'){
  72. $c3_b++;
  73. }
  74. }else{
  75. $c2++;
  76. }
  77. }else if(empty($f->WorkOrder) && $f->trashed()){
  78. $c4++;
  79. }else if($f->type_service == "Rectification"){
  80. $c5++;
  81. }
  82. }
  83. return view('v3.main-dashboard.form.rectification_form', compact('user','site','coverage','c1','c2','c3','c3_r','c3_b','c4','c5'));
  84. }
  85. /***
  86. /* Pending Form
  87. **/
  88. public function pendingForm(){
  89. $id = Auth::guard('main')->id();
  90. $user = Staff::with('StaffDetail')->find($id);
  91. $site = SiteSetting::first();
  92. $company = Company::where('team','Dealer')->get();
  93. $coverage = Coverage::where('Type','R')->orderBy('building_name')->get();
  94. $c1 = 0; $c2 = 0; $c3 = 0; $c3_r = 0; $c3_b = 0;$c4 = 0; $c5 = 0;
  95. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->withTrashed()->get();
  96. foreach ($form as $key => $f) {
  97. if(empty($f->WorkOrder) && $f->type_service != "Rectification" && !$f->trashed()){
  98. $c1++;
  99. }else if(!empty($f->WorkOrder) && $f->type_service != "Rectification"){
  100. if($f->WorkOrder->status == 'Completed') {
  101. $c3++;
  102. if($f->type_application == 'R'){
  103. $c3_r++;
  104. }else if($f->type_application == 'B'){
  105. $c3_b++;
  106. }
  107. }else{
  108. $c2++;
  109. }
  110. }else if(empty($f->WorkOrder) && $f->trashed()){
  111. $c4++;
  112. }else if($f->type_service == "Rectification"){
  113. $c5++;
  114. }
  115. }
  116. return view('v3.main-dashboard.form.pending_form', compact('user','site','company','coverage','c1','c2','c3','c3_r','c3_b','c4','c5'));
  117. }
  118. /***
  119. /* Activated Form
  120. **/
  121. public function activatedFormResidential(){
  122. $id = Auth::guard('main')->id();
  123. $user = Staff::with('StaffDetail')->find($id);
  124. $site = SiteSetting::first();
  125. $company = Company::where('team','Dealer')->get();
  126. $coverage = Coverage::where('Type','R')->orderBy('building_name')->get();
  127. $c1 = 0; $c2 = 0; $c3 = 0; $c3_r = 0; $c3_b = 0;$c4 = 0; $c5 = 0;
  128. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->withTrashed()->get();
  129. foreach ($form as $key => $f) {
  130. if(empty($f->WorkOrder) && $f->type_service != "Rectification" && !$f->trashed()){
  131. $c1++;
  132. }else if(!empty($f->WorkOrder) && $f->type_service != "Rectification"){
  133. if($f->WorkOrder->status == 'Completed') {
  134. $c3++;
  135. if($f->type_application == 'R'){
  136. $c3_r++;
  137. }else if($f->type_application == 'B'){
  138. $c3_b++;
  139. }
  140. }else{
  141. $c2++;
  142. }
  143. }else if(empty($f->WorkOrder) && $f->trashed()){
  144. $c4++;
  145. }else if($f->type_service == "Rectification"){
  146. $c5++;
  147. }
  148. }
  149. return view('v3.main-dashboard.form.activated_form_residential', compact('user','site','company','coverage','c1','c2','c3','c3_r','c3_b','c4','c5'));
  150. }
  151. public function activatedFormBusiness(){
  152. $id = Auth::guard('main')->id();
  153. $user = Staff::with('StaffDetail')->find($id);
  154. $site = SiteSetting::first();
  155. $company = Company::where('team','Dealer')->get();
  156. $coverage = Coverage::where('Type','B')->orderBy('building_name')->get();
  157. $c1 = 0; $c2 = 0; $c3 = 0; $c3_r = 0; $c3_b = 0;$c4 = 0; $c5 = 0;
  158. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->withTrashed()->get();
  159. foreach ($form as $key => $f) {
  160. if(empty($f->WorkOrder) && $f->type_service != "Rectification" && !$f->trashed()){
  161. $c1++;
  162. }else if(!empty($f->WorkOrder) && $f->type_service != "Rectification"){
  163. if($f->WorkOrder->status == 'Completed') {
  164. $c3++;
  165. if($f->type_application == 'R'){
  166. $c3_r++;
  167. }else if($f->type_application == 'B'){
  168. $c3_b++;
  169. }
  170. }else{
  171. $c2++;
  172. }
  173. }else if(empty($f->WorkOrder) && $f->trashed()){
  174. $c4++;
  175. }else if($f->type_service == "Rectification"){
  176. $c5++;
  177. }
  178. }
  179. return view('v3.main-dashboard.form.activated_form_business', compact('user','site','company','coverage','c1','c2','c3','c3_r','c3_b','c4','c5'));
  180. }
  181. /***
  182. /* Rejected Form
  183. **/
  184. public function rejectedForm(){
  185. $id = Auth::guard('main')->id();
  186. $user = Staff::with('StaffDetail')->find($id);
  187. $site = SiteSetting::first();
  188. $company = Company::where('team','Dealer')->get();
  189. $coverage = Coverage::where('Type','R')->orderBy('building_name')->get();
  190. $c1 = 0; $c2 = 0; $c3 = 0; $c3_r = 0; $c3_b = 0;$c4 = 0; $c5 = 0;
  191. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->withTrashed()->get();
  192. foreach ($form as $key => $f) {
  193. if(empty($f->WorkOrder) && $f->type_service != "Rectification" && !$f->trashed()){
  194. $c1++;
  195. }else if(!empty($f->WorkOrder) && $f->type_service != "Rectification"){
  196. if($f->WorkOrder->status == 'Completed') {
  197. $c3++;
  198. if($f->type_application == 'R'){
  199. $c3_r++;
  200. }else if($f->type_application == 'B'){
  201. $c3_b++;
  202. }
  203. }else{
  204. $c2++;
  205. }
  206. }else if(empty($f->WorkOrder) && $f->trashed()){
  207. $c4++;
  208. }else if($f->type_service == "Rectification"){
  209. $c5++;
  210. }
  211. }
  212. return view('v3.main-dashboard.form.rejected_form', compact('user','site','company','coverage','c1','c2','c3','c3_r','c3_b','c4','c5'));
  213. }
  214. /* Dealer Form List
  215. **/
  216. public function dealerFormList(){
  217. $id = Auth::guard('main')->id();
  218. $user = Staff::with('StaffDetail')->find($id);
  219. $site = SiteSetting::first();
  220. $company = Company::where('team','Dealer')->get();
  221. $coverage = Coverage::where('Type','R')->orderBy('building_name')->get();
  222. $c1 = 0; $c2 = 0; $c3 = 0; $c3_r = 0; $c3_b = 0;$c4 = 0; $c5 = 0;
  223. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->withTrashed()->get();
  224. foreach ($form as $key => $f) {
  225. if(empty($f->WorkOrder) && $f->type_service != "Rectification" && !$f->trashed()){
  226. $c1++;
  227. }else if(!empty($f->WorkOrder) && $f->type_service != "Rectification"){
  228. if($f->WorkOrder->status == 'Completed') {
  229. $c3++;
  230. if($f->type_application == 'R'){
  231. $c3_r++;
  232. }else if($f->type_application == 'B'){
  233. $c3_b++;
  234. }
  235. }else{
  236. $c2++;
  237. }
  238. }else if(empty($f->WorkOrder) && $f->trashed()){
  239. $c4++;
  240. }else if($f->type_service == "Rectification"){
  241. $c5++;
  242. }
  243. }
  244. return view('v3.main-dashboard.form.view_dealer_form', compact('user','site','company','coverage','c1','c2','c3','c3_r','c3_b','c4','c5'));
  245. }
  246. /***
  247. /* Form Details
  248. **/
  249. public function viewFormDetail($subscriber){
  250. $id = Auth::guard('main')->id();
  251. $user = Staff::with('StaffDetail')->find($id);
  252. $site = SiteSetting::first();
  253. $subsc = Subscriber::where('subscriber_id',$subscriber)->first();
  254. $form = Form::with('Subscriber','PackageDetail')->where('_id',$subsc->_id)->first();
  255. if($form->type_application == 'R'){
  256. $coverage = Coverage::where('Type','R')->get();
  257. if(empty($coverage)){ $coverage = 'null'; }
  258. }else if($form->type_application == 'B'){
  259. $coverage = Coverage::where('Type','B')->get();
  260. if(empty($coverage)){ $coverage = 'null'; }
  261. }
  262. if(isset($form->company_id)){
  263. $company = Company::where('_id', $form->company_id)->first();
  264. $company = $company->name;
  265. $agent = Staff::with('StaffDetail')->where('_id', $form->dealer_id)->first();
  266. $agent = $agent->StaffDetail->name;
  267. }else{
  268. $company = 'null';
  269. $agent = 'null';
  270. }
  271. return view('v3.main-dashboard.view_customer_detail', compact('user','site','form','company','agent','coverage'));
  272. }
  273. public function updateFormDetail(Request $request){
  274. $id = Auth::guard('main')->id();
  275. $user = Staff::with('StaffDetail')->find($id);
  276. $subscriber = Subscriber::with('Form')->where('subscriber_id',$request->subscriber_id)->first();
  277. if(!empty($subscriber)){
  278. if($subscriber->Form->type_application == 'R'){
  279. if($request->street != null){
  280. $street = $request->street;
  281. }
  282. $cov = Coverage::where('building_name',$request->building)->where('Type','R')->first();
  283. $subscriber->name = $request->name;
  284. $subscriber->ic = $request->ic;
  285. $subscriber->email = $request->email;
  286. $subscriber->phone1 = $request->phone1;
  287. $subscriber->phone2 = $request->phone2;
  288. $subscriber->unit_no = $request->unit_no;
  289. $subscriber->building_name = $cov->building_name;
  290. $subscriber->street = $request->street;
  291. $subscriber->city = $cov->city;
  292. $subscriber->postcode = $cov->postcode;
  293. $subscriber->state = $cov->state;
  294. $subscriber->save();
  295. return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
  296. }else if($subscriber->Form->type_application == 'B'){
  297. if($request->company_fax != null){
  298. $fax = $request->company_fax;
  299. }
  300. $cov = Coverage::where('building_name',$request->building)->where('Type','B')->first();
  301. if(empty($cov)){
  302. }
  303. $subscriber->company_reg = $request->company_reg;
  304. $subscriber->company_num = $request->company_num;
  305. $subscriber->company_fax = $fax;
  306. $subscriber->company_name = $request->company_name;
  307. $subscriber->unit_no = $request->unit_no;
  308. $subscriber->street = $request->address;
  309. $subscriber->city = $request->city;
  310. $subscriber->postcode = $request->postcode;
  311. $subscriber->state = $request->state;
  312. $subscriber->name = $request->name;
  313. $subscriber->ic = $request->ic;
  314. $subscriber->designation = $request->designation;
  315. $subscriber->email = $request->email;
  316. $subscriber->phone1 = $request->phone1;
  317. $subscriber->phone2 = $request->phone2;
  318. $subscriber->save();
  319. return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
  320. }
  321. }
  322. }
  323. }