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.

ResidentialController.php 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. <?php
  2. namespace App\Http\Controllers\Form;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use App\Mail\CustomerInvoice;
  7. use App\Jobs\SendCustomerInvoice;
  8. use Carbon\Carbon;
  9. use Validator;
  10. use File;
  11. use App\Model\Coverage;
  12. use App\Model\Product;
  13. use App\Model\Form;
  14. use App\Model\WorkOrder;
  15. use App\Model\Subscriber;
  16. use App\Model\PackageDetail;
  17. use App\Model\FormStatus;
  18. use App\Staff;
  19. use App\Model\StaffDetail;
  20. class ResidentialController extends Controller
  21. {
  22. public function successSubmit(){
  23. return view('sales.form.after_submit_form');
  24. }
  25. public function successVerified(){
  26. return view('sales.form.success_verify');
  27. }
  28. public function sendInvoice($subscriber_id) {
  29. $subscriber = Subscriber::with('Form')->where('subscriber_id',$subscriber_id)->first();
  30. $form = Form::with('Subscriber','PackageDetail')->where('_id',$subscriber->_id)->first();
  31. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$form->type_application)->first();
  32. SendCustomerInvoice::dispatch($form, $product, $form->Subscriber->email);
  33. return $form->_id;
  34. }
  35. public function sendInvoice1($subscriber_id) {
  36. $subscriber = Subscriber::with('Form')->where('subscriber_id',$subscriber_id)->first();
  37. $form = Form::with('Subscriber','PackageDetail')->where('_id',$subscriber->_id)->first();
  38. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$form->type_application)->first();
  39. SendCustomerInvoice::dispatch($form, $product, 'nsakinahs1991@gmail.com');
  40. return $form->_id;
  41. }
  42. function random_code($limit) {
  43. return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
  44. }
  45. public function viewFormAddress($package) {
  46. $dealer_id = '';
  47. $coverage = Coverage::where('Type','R')->orderBy('building_name')->get();
  48. return view('sales.form.residential_address', compact('coverage','package','dealer_id'));
  49. }
  50. public function viewFormApplication(Request $request) {
  51. $data = array();
  52. array_push($data, array(
  53. 'coverage' => $request->coverage,
  54. 'unit' => $request->unit,
  55. 'street' => $request->street,
  56. 'package' => $request->package
  57. ));
  58. return view('sales.form.residential_application_information', compact('data'));
  59. }
  60. public function viewFormPackage(Request $request) {
  61. $data = array();
  62. $citizen = ''; $street = '';
  63. if($request->citizenship == "Malaysian"){
  64. $citizen = $request->citizenship;
  65. }
  66. else {
  67. $citizen = $request->citizenlist;
  68. }
  69. if($request->street != null){
  70. $street = $request->street;
  71. }
  72. if (!empty($request->nric_passport1)){
  73. $nokp = $request->nric_passport1;
  74. }else {
  75. $nokp = $request->nric_passport2;
  76. }
  77. array_push($data, array(
  78. 'coverage' => $request->coverage,
  79. 'unit' => $request->unit,
  80. 'street' => $street,
  81. 'package' => $request->package,
  82. 'application' => $request->application,
  83. 'name' => $request->name,
  84. 'nric_passport' => $nokp,
  85. 'gender' => $request->gender,
  86. 'race' => $request->race,
  87. 'contact_primary' => $request->contact_primary,
  88. 'contact_secondary' => $request->contact_secondary,
  89. 'citizenship' => $citizen,
  90. 'email' => $request->email
  91. ));
  92. $product = Product::where('formT','R')->where('package_name',$request->package)->first();
  93. return view('sales.form.residential_package', compact('data','product','citizen'));
  94. }
  95. public function viewFormPreview(Request $request){
  96. $data = array();
  97. $coverage = Coverage::where('_id',$request->coverage)->first();
  98. $product = Product::where('formT','R')->where('package_name',$request->package)->first();
  99. $otc = 0.0; $deposit = 0.0;
  100. $voice = "No";
  101. if($request->voice == "Yes"){
  102. $voice = $request->voice;
  103. $voice_price = 20;
  104. }else {
  105. $voice = "No";
  106. $voice_price = 0;
  107. }
  108. $total_monthly = 0;
  109. $gst ='';
  110. // $promo_st = '';
  111. // if ($request->package != "1Gbps" && $request->subscription == '24'){
  112. // $promo_price = number_format(floatval($product->retail_price) - 10);
  113. // $promo_st = number_format(floatval($promo_price) * 1.06,2);
  114. // $total_monthly = number_format($promo_st + ($voice_price * 1.06), 2);
  115. // }
  116. // else{
  117. $gst = number_format(floatval($product->retail_price) * 1.06,2);
  118. $total_monthly = number_format($gst + ($voice_price * 1.06), 2);
  119. // }
  120. if($request->citizenship != 'Malaysian' && $request->subscription == '12' && $voice == 'No'){
  121. $otc = 300;
  122. $deposit = 0;
  123. }else if($request->citizenship != 'Malaysian' && $request->subscription == '12' && $voice == 'Yes'){
  124. $otc = 300 + 100;
  125. $deposit = 0;
  126. }else if($request->citizenship != 'Malaysian' && $request->subscription == '24' && ($voice == 'No' || $voice == 'Yes')){
  127. $otc = 0.0;
  128. $deposit = 300;
  129. }else if($request->citizenship == 'Malaysian' && $request->subscription == '24' && ($voice == 'No' || $voice == 'Yes')){
  130. $otc = 0.0;
  131. $deposit = $product->deposit;
  132. }else if($request->citizenship == 'Malaysian' && $request->subscription == '12' && $voice == 'No'){
  133. $otc = 300;
  134. $deposit = $product->deposit;
  135. }else if($request->citizenship == 'Malaysian' && $request->subscription == '12' && $voice == 'Yes'){
  136. $otc = 300 + 100;
  137. $deposit = $product->deposit;
  138. }
  139. $otc_st = number_format(floatval($otc) * 1.06,2);
  140. $upfront_total = number_format(floatval($otc_st) + $deposit,2);
  141. array_push($data, array(
  142. 'coverage' => $request->coverage,
  143. 'unit' => $request->unit,
  144. 'street' => $request->street,
  145. 'package' => $request->package,
  146. 'application' => $request->application,
  147. 'name' => $request->name,
  148. 'nric_passport' => $request->nric_passport,
  149. 'gender' => $request->gender,
  150. 'race' => $request->race,
  151. 'contact_primary' => $request->contact_primary,
  152. 'contact_secondary' => $request->contact_secondary,
  153. 'citizenship' => $request->citizenship,
  154. 'email' => $request->email,
  155. 'subscription' => $request->subscription,
  156. 'billing' => $request->billing,
  157. 'voice' => $voice,
  158. 'thedate' => $request->thedate,
  159. ));
  160. return view('sales.form.residential_preview', compact('data','coverage','product','deposit','otc', 'otc_st','gst','total_monthly', 'upfront_total'));
  161. }
  162. public function storeFormData(Request $request){
  163. $su_id = ''; $pathIconF = ''; $pathIconB = ''; $pathVisaF = ''; $pathVisaB = '';
  164. do {
  165. $su_id = strtoupper('CBB-'.$this->random_code(6).'R');
  166. } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
  167. $destinationPath = 'document/'.$su_id;
  168. // create folder/dir if not exist
  169. if(!File::exists(public_path().'/'.$destinationPath)){
  170. File::makeDirectory(public_path().'/'.$destinationPath,0777,true);
  171. }
  172. $uploaded = public_path().'/'.$destinationPath;
  173. // Signature
  174. $signature_form = $request->cuss_signature;
  175. $signature_form = str_replace('data:image/jpeg;base64,','',$signature_form);
  176. $signature_form = str_replace('','+',$signature_form);
  177. //convert signature_form
  178. $data = base64_decode($signature_form);
  179. $file = $uploaded."/signature_form.jpg";
  180. $savetoServer = file_put_contents($file,$data);
  181. if (($savetoServer === false) || ($savetoServer == -1)) {
  182. print "Couldn't save signature to jpeg";
  183. }else {
  184. if($request->hasfile('front_ic')){
  185. $icon = $request->file('front_ic');
  186. $icon->move($destinationPath,'frontic.'.strtolower($icon->getClientOriginalExtension()));
  187. $pathIconF = '/'.$destinationPath.'/frontic.'.strtolower($icon->getClientOriginalExtension());
  188. }
  189. if($request->hasfile('back_ic')){
  190. $icon = $request->file('back_ic');
  191. $icon->move($destinationPath,'backic.'.strtolower($icon->getClientOriginalExtension()));
  192. $pathIconB = '/'.$destinationPath.'/backic.'.strtolower($icon->getClientOriginalExtension());
  193. }
  194. if($request->hasfile('visaF')){
  195. $icon = $request->file('visaF');
  196. $icon->move($destinationPath,'visaF.'.strtolower($icon->getClientOriginalExtension()));
  197. $pathVisaF = '/'.$destinationPath.'/visaF.'.strtolower($icon->getClientOriginalExtension());
  198. }
  199. if($request->hasfile('visaB')){
  200. $icon = $request->file('visaB');
  201. $icon->move($destinationPath,'visaB.'.strtolower($icon->getClientOriginalExtension()));
  202. $pathVisaB = '/'.$destinationPath.'/visaB.'.strtolower($icon->getClientOriginalExtension());
  203. }
  204. $coverage = Coverage::where('_id',$request->coverage)->first();
  205. $product = Product::where('formT','R')->where('package_name',$request->package)->first();
  206. $sl = Form::create([
  207. 'type_service' => $request->application,
  208. 'type_application' => 'R',
  209. 'project_type' => $coverage->project_type,
  210. 'status_payment' => 'paid',
  211. 'status_email' => 'unverified',
  212. 'customer_category' => 'Allo',
  213. 'remark_form' => ''
  214. ]);
  215. $sdl = new Subscriber();
  216. $sdl->subscriber_id = $su_id;
  217. $sdl->name = $request->name;
  218. $sdl->ic = $request->nric_passport;
  219. $sdl->citizen = $request->citizenship;
  220. $sdl->gender = $request->gender;
  221. $sdl->race = $request->race;
  222. $sdl->email = $request->email;
  223. $sdl->phone1 = $request->contact_primary;
  224. $sdl->phone2 = $request->contact_secondary;
  225. $sdl->unit_no = $request->unit;
  226. $sdl->building_name = $coverage->building_name;
  227. $sdl->street = $request->street;
  228. $sdl->postcode = $coverage->postcode;
  229. $sdl->city = $coverage->city;
  230. $sdl->state = $coverage->state;
  231. $sdl->front_ic = $pathIconF;
  232. $sdl->back_ic = $pathIconB;
  233. $sdl->visaF = $pathVisaF;
  234. $sdl->visaB = $pathVisaB;
  235. $sdl->signature = '/'.$destinationPath.'/signature_form.jpg';
  236. $packageD = new PackageDetail();
  237. $packageD->contract = $request->subscription;
  238. $packageD->name = $product->speed;
  239. if ($request->gst != null){
  240. $packageD->montly_fee = $request->gst;
  241. }else {
  242. $packageD->montly_fee = $request->promo_st;
  243. }
  244. $packageD->voice_fee = $request->voice;
  245. $packageD->deposit = $request->deposit;
  246. $packageD->upfront_payment = $request->otc;
  247. $packageD->rfs = $request->rfs;
  248. $sl->subscriber()->save($sdl);
  249. $sl->packagedetail()->save($packageD);
  250. $f_id = $this->sendInvoice($su_id);
  251. $stat = new FormStatus();
  252. $stat->form_id = $f_id;
  253. $stat->status_id = 1;
  254. $stat->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
  255. $stat->status = 'Submitted';
  256. $stat->desc = 'The form already been submit';
  257. $sl->formstatus()->save($stat);
  258. return redirect('http://db.citybroadband.my/residential/application-form/success-submit');
  259. }
  260. }
  261. /**
  262. ** Dealer
  263. **/
  264. public function viewFormAddressD($package,$dealer_id) {
  265. $coverage = Coverage::where('Type','R')->orderBy('building_name')->get();
  266. $dealer = Staff::where('_id',$dealer_id)->first();
  267. return view('sales.form.dealer.residential_address', compact('coverage','package','dealer_id'));
  268. }
  269. public function viewFormApplicationD(Request $request) {
  270. $data = array();
  271. array_push($data, array(
  272. 'coverage' => $request->coverage,
  273. 'unit' => $request->unit,
  274. 'street' => $request->street,
  275. 'package' => $request->package,
  276. 'dealer_id' => $request->dealer_id
  277. ));
  278. return view('sales.form.dealer.residential_application_information', compact('data'));
  279. }
  280. public function viewFormPackageD(Request $request) {
  281. $data = array();
  282. $citizen = ''; $street = '';
  283. if($request->citizenship == "Malaysian"){
  284. $citizen = $request->citizenship;
  285. }
  286. else {
  287. $citizen = $request->citizenlist;
  288. }
  289. if($request->street != null){
  290. $street = $request->street;
  291. }
  292. if (!empty($request->nric_passport1)){
  293. $nokp = $request->nric_passport1;
  294. }else {
  295. $nokp = $request->nric_passport2;
  296. }
  297. array_push($data, array(
  298. 'dealer_id' => $request->dealer_id,
  299. 'coverage' => $request->coverage,
  300. 'unit' => $request->unit,
  301. 'street' => $street,
  302. 'package' => $request->package,
  303. 'application' => $request->application,
  304. 'name' => $request->name,
  305. 'nric_passport' => $nokp,
  306. 'ip' => $request->ip,
  307. 'gender' => $request->gender,
  308. 'race' => $request->race,
  309. 'contact_primary' => $request->contact_primary,
  310. 'contact_secondary' => $request->contact_secondary,
  311. 'citizenship' => $citizen,
  312. 'email' => $request->email
  313. ));
  314. $product = Product::where('formT','R')->where('package_name',$request->package)->first();
  315. return view('sales.form.dealer.residential_package', compact('data','product','citizen'));
  316. }
  317. public function viewFormPreviewD(Request $request){
  318. $data = array();
  319. $coverage = Coverage::where('_id',$request->coverage)->first();
  320. $product = Product::where('formT','R')->where('package_name',$request->package)->first();
  321. $otc = 0.0; $deposit = 0.0;
  322. $voice = "No";
  323. if($request->voice == "Yes"){
  324. $voice = $request->voice;
  325. $voice_price = 20;
  326. }else {
  327. $voice = "No";
  328. $voice_price = 0;
  329. }
  330. $total_monthly = 0;
  331. $gst ='';
  332. // $promo_st = '';
  333. // if ($request->package != "1Gbps" && $request->subscription == '24'){
  334. // $promo_price = number_format(floatval($product->retail_price) - 10);
  335. // $promo_st = number_format(floatval($promo_price) * 1.06,2);
  336. // $total_monthly = number_format($promo_st + ($voice_price * 1.06), 2);
  337. // }
  338. // else{
  339. $gst = number_format(floatval($product->retail_price) * 1.06,2);
  340. $total_monthly = number_format($gst + ($voice_price * 1.06), 2);
  341. // }
  342. if($request->citizenship != 'Malaysian' && $request->subscription == '12' && $voice == 'No'){
  343. $otc = 300;
  344. $deposit = 0;
  345. }else if($request->citizenship != 'Malaysian' && $request->subscription == '12' && $voice == 'Yes'){
  346. $otc = 300 + 100;
  347. $deposit = 0;
  348. }else if($request->citizenship != 'Malaysian' && $request->subscription == '24' && ($voice == 'No' || $voice == 'Yes')){
  349. $otc = 0.0;
  350. $deposit = 300;
  351. }else if($request->citizenship == 'Malaysian' && $request->subscription == '24' && ($voice == 'No' || $voice == 'Yes')){
  352. $otc = 0.0;
  353. $deposit = $product->deposit;
  354. }else if($request->citizenship == 'Malaysian' && $request->subscription == '12' && $voice == 'No'){
  355. $otc = 300;
  356. $deposit = $product->deposit;
  357. }else if($request->citizenship == 'Malaysian' && $request->subscription == '12' && $voice == 'Yes'){
  358. $otc = 300 + 100;
  359. $deposit = $product->deposit;
  360. }
  361. $otc_st = number_format(floatval($otc) * 1.06,2);
  362. $upfront_total = number_format(floatval($otc_st) + $deposit,2);
  363. array_push($data, array(
  364. 'dealer_id' => $request->dealer_id,
  365. 'coverage' => $request->coverage,
  366. 'unit' => $request->unit,
  367. 'street' => $request->street,
  368. 'package' => $request->package,
  369. 'application' => $request->application,
  370. 'name' => $request->name,
  371. 'nric_passport' => $request->nric_passport,
  372. 'gender' => $request->gender,
  373. 'race' => $request->race,
  374. 'contact_primary' => $request->contact_primary,
  375. 'contact_secondary' => $request->contact_secondary,
  376. 'citizenship' => $request->citizenship,
  377. 'email' => $request->email,
  378. 'subscription' => $request->subscription,
  379. 'billing' => $request->billing,
  380. 'voice' => $voice,
  381. 'ip' => $request->ip,
  382. 'thedate' => $request->thedate,
  383. ));
  384. return view('sales.form.dealer.residential_preview', compact('data','coverage','product','deposit','otc', 'otc_st','gst','total_monthly', 'upfront_total'));
  385. }
  386. public function storeFormDataD(Request $request){
  387. $su_id = ''; $pathIconF = ''; $pathIconB = ''; $pathVisaF = ''; $pathVisaB = ''; $pathPaymentReceipt=''; $pathSOForm='';
  388. do {
  389. $su_id = strtoupper('CBB-'.$this->random_code(6).'R');
  390. } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
  391. $destinationPath = 'document/'.$su_id;
  392. // create folder/dir if not exist
  393. if(!File::exists(public_path().'/'.$destinationPath)){
  394. File::makeDirectory(public_path().'/'.$destinationPath,0777,true);
  395. }
  396. $uploaded = public_path().'/'.$destinationPath;
  397. // Signature
  398. $signature_form = $request->cuss_signature;
  399. $signature_form = str_replace('data:image/jpeg;base64,','',$signature_form);
  400. $signature_form = str_replace('','+',$signature_form);
  401. //convert signature_form
  402. $data = base64_decode($signature_form);
  403. $file = $uploaded."/signature_form.jpg";
  404. $savetoServer = file_put_contents($file,$data);
  405. if (($savetoServer === false) || ($savetoServer == -1)) {
  406. print "Couldn't save signature to jpeg";
  407. }else {
  408. if($request->hasfile('front_ic')){
  409. $icon = $request->file('front_ic');
  410. $icon->move($destinationPath,'frontic.'.strtolower($icon->getClientOriginalExtension()));
  411. $pathIconF = '/'.$destinationPath.'/frontic.'.strtolower($icon->getClientOriginalExtension());
  412. }
  413. if($request->hasfile('back_ic')){
  414. $icon = $request->file('back_ic');
  415. $icon->move($destinationPath,'backic.'.strtolower($icon->getClientOriginalExtension()));
  416. $pathIconB = '/'.$destinationPath.'/backic.'.strtolower($icon->getClientOriginalExtension());
  417. }
  418. if($request->hasfile('visaF')){
  419. $icon = $request->file('visaF');
  420. $icon->move($destinationPath,'visaF.'.strtolower($icon->getClientOriginalExtension()));
  421. $pathVisaF = '/'.$destinationPath.'/visaF.'.strtolower($icon->getClientOriginalExtension());
  422. }
  423. if($request->hasfile('visaB')){
  424. $icon = $request->file('visaB');
  425. $icon->move($destinationPath,'visaB.'.strtolower($icon->getClientOriginalExtension()));
  426. $pathVisaB = '/'.$destinationPath.'/visaB.'.strtolower($icon->getClientOriginalExtension());
  427. }
  428. if($request->hasfile('payment_receipt')){
  429. $icon = $request->file('payment_receipt');
  430. $icon->move($destinationPath,'payment_receipt.'.strtolower($icon->getClientOriginalExtension()));
  431. $pathPaymentReceipt = '/'.$destinationPath.'/payment_receipt.'.strtolower($icon->getClientOriginalExtension());
  432. }
  433. if($request->hasfile('so_form')){
  434. $icon = $request->file('so_form');
  435. $icon->move($destinationPath,'so_form.'.strtolower($icon->getClientOriginalExtension()));
  436. $pathSOForm = '/'.$destinationPath.'/so_form.'.strtolower($icon->getClientOriginalExtension());
  437. }
  438. // staff
  439. $staff = Staff::with('StaffDetail')->where('_id',$request->dealer_id)->first();
  440. if(!empty($staff)){
  441. $coverage = Coverage::where('_id',$request->coverage)->first();
  442. $product = Product::where('formT','R')->where('package_name',$request->package)->first();
  443. $sl = new Form();
  444. $sl->type_service = $request->application;
  445. $sl->type_application = 'R';
  446. $sl->project_type = $coverage->project_type;
  447. $sl->status_payment = 'paid';
  448. $sl->status_email = 'unverified';
  449. $sl->customer_category = 'Allo';
  450. $sl->remark_form = '';
  451. $sl->dealer_id = $request->dealer_id;
  452. $sl->company_id = $staff->StaffDetail->company_id;
  453. $staff->form()->save($sl);
  454. $sdl = new Subscriber();
  455. $sdl->subscriber_id = $su_id;
  456. $sdl->name = $request->name;
  457. $sdl->ic = $request->nric_passport;
  458. $sdl->citizen = $request->citizenship;
  459. $sdl->gender = $request->gender;
  460. $sdl->race = $request->race;
  461. $sdl->email = $request->email;
  462. $sdl->phone1 = $request->contact_primary;
  463. $sdl->phone2 = $request->contact_secondary;
  464. $sdl->unit_no = $request->unit;
  465. $sdl->building_name = $coverage->building_name;
  466. $sdl->street = $request->street;
  467. $sdl->postcode = $coverage->postcode;
  468. $sdl->city = $coverage->city;
  469. $sdl->state = $coverage->state;
  470. $sdl->front_ic = $pathIconF;
  471. $sdl->back_ic = $pathIconB;
  472. $sdl->visaF = $pathVisaF;
  473. $sdl->visaB = $pathVisaB;
  474. $sdl->paymentReceipt = $pathPaymentReceipt;
  475. $sdl->soForm = $pathSOForm;
  476. $sdl->signature = '/'.$destinationPath.'/signature_form.jpg';
  477. $packageD = new PackageDetail();
  478. $packageD->contract = $request->subscription;
  479. $packageD->name = $product->speed;
  480. if ($request->gst != null){
  481. $packageD->montly_fee = $request->gst;
  482. }else {
  483. $packageD->montly_fee = $request->promo_st;
  484. }
  485. $packageD->voice_fee = $request->voice;
  486. $packageD->deposit = $request->deposit;
  487. $packageD->upfront_payment = $request->otc;
  488. $packageD->rfs = $request->rfs;
  489. $sl->subscriber()->save($sdl);
  490. $sl->packagedetail()->save($packageD);
  491. $f_id = $this->sendInvoice($su_id);
  492. $stat = new FormStatus();
  493. $stat->form_id = $f_id;
  494. $stat->status_id = 1;
  495. $stat->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
  496. $stat->status = 'Submitted';
  497. $stat->desc = 'The form already been submit';
  498. $sl->formstatus()->save($stat);
  499. return redirect('http://db.citybroadband.my/residential/application-form/success-submit');
  500. }
  501. }
  502. }
  503. function createWorkID(){
  504. $number = WorkOrder::select('id','wo')->orderBy('created_at','DESC')->first();
  505. $numberOnly = str_replace('WO-','',$number->wo);
  506. info('before WO'.$numberOnly);
  507. $numberOnly++;
  508. info('after WO'.$numberOnly);
  509. return $numberOnly;
  510. }
  511. public function verifyEmail($subscriber_id){
  512. $subscriber = Subscriber::where('subscriber_id',$subscriber_id)->first();
  513. if(!empty($subscriber)){
  514. $form = Form::where('_id',$subscriber->_id)->first();
  515. if(!empty($form)){
  516. if($form->status_email == 'unverified'){
  517. $form->status_email = 'verified';
  518. $form->save();
  519. $stat = new FormStatus();
  520. $stat->form_id = $form->_id;
  521. $stat->status_id = 2;
  522. $stat->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
  523. $stat->status = 'Verified';
  524. $stat->desc = 'Email already been verified by customer';
  525. $form->formstatus()->save($stat);
  526. do {
  527. $woID = 'WO-'.$this->createWorkID();
  528. } while (WorkOrder::where("wo", "=", $woID)->first() instanceof WorkOrder);
  529. $work_order = new WorkOrder;
  530. $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
  531. $work_order->wo = $woID;
  532. $work_order->nature_work = '';
  533. $work_order->sub_category = '';
  534. $work_order->dateTimeStart = '';
  535. $work_order->dateTimeEnd = '';
  536. $work_order->contractor_id = '';
  537. $work_order->installer_id = '';
  538. $work_order->onu = '';
  539. $work_order->router = '';
  540. $work_order->need_phone = '';
  541. $work_order->no_phone = '';
  542. $work_order->pppoe_username = '';
  543. $work_order->pppoe_password = '';
  544. $work_order->docket_id = '';
  545. $work_order->remarks_custservice = '';
  546. $work_order->remarks_installer = '';
  547. $work_order->status = '';
  548. $work_order->created_by = '';
  549. $form->workorder()->save($work_order);
  550. return redirect('http://db.citybroadband.my/residential/application-form/success-verified');
  551. }
  552. }
  553. }
  554. }
  555. public function resendEmail($subscriber_id){
  556. $f_id = $this->sendInvoice($subscriber_id);
  557. return $f_id;
  558. }
  559. public function checkEmailTemplate($subscriber_id){
  560. $subscriber = Subscriber::where('subscriber_id',$subscriber_id)->first();
  561. if(!empty($subscriber)){
  562. $form = Form::where('_id',$subscriber->_id)->first();
  563. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$form->type_application)->first();
  564. }
  565. return view('email.invoice', compact ('form', 'product'));
  566. }
  567. }