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

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