| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648 |
- <?php
-
- namespace App\Http\Controllers\Form;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
-
- use App\Mail\CustomerBInvoice;
- use App\Jobs\SendCustomerInvoiceB;
-
- use Carbon\Carbon;
- use Validator;
- use File;
-
- use App\Model\Coverage;
- use App\Model\Product;
-
- use App\Model\Form;
- use App\Model\Subscriber;
- use App\Model\PackageDetail;
- use App\Model\FormStatus;
-
- use App\Staff;
- use App\Model\StaffDetail;
-
- class BusinessController extends Controller
- {
- public function successSubmit()
- {
- return view('sales.form.after_submit_form');
- }
-
- public function successVerified()
- {
- return view('sales.form.success_verify');
- }
-
- public function sendInvoice($subscriber_id)
- {
-
- $subscriber = Subscriber::with('Form')->where('subscriber_id', $subscriber_id)->first();
- $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $subscriber->_id)->first();
- $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $form->type_application)->first();
- SendCustomerInvoiceB::dispatch($form, $product, $form->Subscriber->email);
-
- return $form->_id;
- }
-
- function random_code($limit)
- {
- return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
- }
-
-
- public function viewFormAddress($package)
- {
-
- $dealer_id = '';
- $coverage = Coverage::where('Type', 'B')->groupBy('building_name')->orderBy('building_name')->get();
- // dd($coverage);
- return view('sales.form.business_address', compact('coverage', 'package', 'dealer_id'));
- }
-
- public function viewFormApplication(Request $request)
- {
- $data = array();
-
- $coverage = Coverage::where('building_name', $request->coverage)->where('street', $request->street)->get();
-
- array_push($data, array(
- 'coverage' => $coverage[0]['_id'],
- 'unit' => $request->unit,
- 'street' => $request->street,
- 'package' => $request->package
- ));
-
- return view('sales.form.business_application_information', compact('data'));
- }
-
- public function viewFormPackage(Request $request)
- {
- $data = array();
- array_push($data, array(
- 'coverage' => $request->coverage,
- 'unit' => $request->unit,
- 'street' => $request->street,
- 'package' => $request->package,
- 'application' => $request->application,
- 'company_name' => $request->company_name,
- 'company_register' => $request->company_register,
- 'company_number' => $request->company_number,
- 'company_fax' => $request->company_fax,
- 'full_name' => $request->full_name,
- 'nric_passport' => $request->nric_passport,
- 'designation' => $request->designation,
- 'contact_primary' => $request->contact_primary,
- 'contact_secondary' => $request->contact_secondary,
- 'email' => $request->email,
- ));
-
- $pg = $request->package;
-
- $coverage = Coverage::where('_id', $request->coverage)->first();
- $city = $coverage->city;
-
- return view('sales.form.business_package', compact('data', 'pg', 'city'));
- }
-
- public function viewFormPreview(Request $request)
- {
-
- $data = array();
-
- $coverage = Coverage::where('_id', $request->coverage)->first();
- $product = Product::where('formT', 'B')->where('package_name', $request->package)->first();
- $otc = 0.0;
-
- $total_monthly = 0;
- $gst = '';
- $promo_st = '';
-
- $voice = "No";
- if ($request->voice == "Yes") {
- $voice = $request->voice;
- $voice_price = 20;
- } else {
- $voice = "No";
- $voice_price = 0;
- }
-
- $ip_fee = 0;
- $ip_tax = 0;
- if ($request->ip == "1 Fixed IP RM200/1P/Month") {
- $ip_fee = 200;
- $ip_tax = number_format((floatval($ip_fee) * 1.06), 2);
- } elseif ($request->ip == "5 Fixed IP RM400/1P/Month") {
- $ip_fee = 400;
- $ip_tax = number_format((floatval($ip_fee) * 1.06), 2);
- }
-
- if ($request->package != "1Gbps" && $request->subscription == '24') {
- $promo_price = number_format(floatval($product->retail_price) - 10);
- $promo_st = number_format(floatval($promo_price) * 1.06, 2);
- $total_monthly = number_format($promo_st + ($voice_price * 1.06) + $ip_tax, 2);
- } else if ($request->package == "1Gbps") {
- if ($request->subscription == '24' && $coverage->city == 'CYBERJAYA') {
- $gst = 1058.94;
- $total_monthly = 1058.94;
- } else {
- $gst = 3708.94;
- $total_monthly = 3708.94;
- }
- } else {
- $gst = number_format(floatval($product->retail_price) * 1.06, 2);
- $total_monthly = number_format($gst + ($voice_price * 1.06) + $ip_tax, 2);
- }
-
-
- if ($request->subscription == '12' && $voice == 'No') {
- if ($request->package != '50Mbps') {
- $otc = 400;
- } else {
- $otc = 300;
- }
- $deposit = $product->deposit;
- } else if ($request->subscription == '12' && $voice == 'Yes') {
- $otc = 300 + 100;
- $deposit = $product->deposit;
- } else {
- $otc = 0.0;
- $deposit = $product->deposit;
- }
-
- $otc_st = number_format(floatval($otc) * 1.06, 2);
- $upfront_total = number_format(floatval($otc_st) + $deposit, 2);
-
- $total = number_format((floatval($product->retail_price) * 1.06) + ($otc * 1.06) + $deposit + $ip_tax, 2);
-
- array_push($data, array(
- 'coverage' => $request->coverage,
- 'unit' => $request->unit,
- 'street' => $request->street,
- 'package' => $request->package,
- 'application' => $request->application,
- 'company_name' => $request->company_name,
- 'company_register' => $request->company_register,
- 'company_number' => $request->company_number,
- 'company_fax' => $request->company_fax,
- 'full_name' => $request->full_name,
- 'nric_passport' => $request->nric_passport,
- 'designation' => $request->designation,
- 'contact_primary' => $request->contact_primary,
- 'contact_secondary' => $request->contact_secondary,
- 'email' => $request->email,
- 'subscription' => $request->subscription,
- 'billing' => $request->billing,
- 'voice' => $voice,
- 'ip' => $request->ip,
- 'ip_fee' => $ip_fee,
- 'ip_tax' => $ip_tax,
- 'thedate' => $request->thedate,
- ));
-
- return view('sales.form.business_preview', compact('data', 'coverage', 'product', 'deposit', 'otc', 'otc_st', 'gst', 'promo_price', 'promo_st', 'total_monthly', 'upfront_total'));
- }
-
- public function storeFormData(Request $request)
- {
-
- $su_id = '';
- $pathIconF = '';
- $pathIconB = '';
- $pathForm9 = '';
-
- do {
- $su_id = strtoupper('CBB-' . $this->random_code(6) . 'B');
- } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
-
-
- $destinationPath = 'document/' . $su_id;
- // create folder/dir if not exist
-
- if (!File::exists(public_path() . '/' . $destinationPath)) {
- File::makeDirectory(public_path() . '/' . $destinationPath, 0777, true);
- }
-
- if ($request->hasfile('front_ic')) {
-
- $icon = $request->file('front_ic');
- $icon->move($destinationPath, 'frontic.' . $icon->getClientOriginalExtension());
- $pathIconF = '/' . $destinationPath . '/frontic.' . $icon->getClientOriginalExtension();
- }
-
- if ($request->hasfile('back_ic')) {
-
- $icon = $request->file('back_ic');
- $icon->move($destinationPath, 'backic.' . $icon->getClientOriginalExtension());
- $pathIconB = '/' . $destinationPath . '/backic.' . $icon->getClientOriginalExtension();
- }
-
- if ($request->hasfile('form9')) {
-
- $icon = $request->file('form9');
- $icon->move($destinationPath, 'formD.' . $icon->getClientOriginalExtension());
- $pathForm9 = '/' . $destinationPath . '/formD.' . $icon->getClientOriginalExtension();
- }
-
- if ($pathForm9 != '' && $pathIconB != '' && $pathIconF != '') {
-
- $coverage = Coverage::where('_id', $request->coverage)->first();
- $product = Product::where('formT', 'B')->where('package_name', $request->package)->first();
-
- $sl = Form::create([
- 'type_service' => $request->application,
- 'type_application' => 'B',
- 'project_type' => $coverage->project_type,
- 'status_payment' => 'paid',
- 'status_email' => 'unverified',
- 'customer_category' => 'Allo',
- 'remark_form' => ''
- ]);
-
- $sdl = new Subscriber();
- $sdl->subscriber_id = $su_id;
- $sdl->name = $request->full_name;
- $sdl->ic = $request->nric_passport;
- $sdl->company_name = $request->company_name;
- $sdl->company_reg = $request->company_register;
- $sdl->company_num = $request->company_number;
- $sdl->company_fax = $request->company_fax;
- $sdl->designation = $request->designation;
- $sdl->email = $request->email;
- $sdl->phone1 = $request->contact_primary;
- $sdl->phone2 = $request->contact_secondary;
- $sdl->unit_no = $request->unit;
- $sdl->building_name = $coverage->building_name;
- $sdl->street = $request->street;
- $sdl->postcode = $coverage->postcode;
- $sdl->city = $coverage->city;
- $sdl->state = $coverage->state;
- $sdl->front_ic = $pathIconF;
- $sdl->back_ic = $pathIconB;
- $sdl->form9_44 = $pathForm9;
-
- $packageD = new PackageDetail();
- $packageD->contract = $request->subscription;
- $packageD->name = $product->speed;
- if ($request->gst != null) {
- $packageD->montly_fee = $request->gst;
- } else {
- $packageD->montly_fee = $request->promo_st;
- }
- $packageD->voice_fee = $request->voice;
- $packageD->ip = $request->ip;
- $packageD->deposit = $request->deposit;
- $packageD->upfront_payment = $request->otc;
- $packageD->ip_tax = $request->ip_tax;
- $packageD->rfs = $request->rfs;
-
- $sl->subscriber()->save($sdl);
- $sl->packagedetail()->save($packageD);
-
- $f_id = $this->sendInvoice($su_id);
- $stat = new FormStatus();
- $stat->form_id = $f_id;
- $stat->status_id = 1;
- $stat->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
- $stat->status = 'Submitted';
- $stat->desc = 'The form already been submit';
- $sl->formstatus()->save($stat);
-
- return redirect('http://db.citybroadband.my/business/application-form/success-submit');
- }
- }
-
- /***
- ** Dealer
- ***/
-
- public function viewFormAddressD($package, $dealer_id)
- {
- $coverage = Coverage::where('Type', 'B')->groupBy('building_name')->orderBy('building_name')->get();
- return view('sales.form.dealer.business_address', compact('coverage', 'package', 'dealer_id'));
- }
-
- public function viewFormApplicationD(Request $request)
- {
- $data = array();
-
- $coverage = Coverage::where('building_name', $request->coverage)->where('street', $request->street)->get();
-
- array_push($data, array(
- 'coverage' => $coverage[0]['_id'],
- 'unit' => $request->unit,
- 'street' => $request->street,
- 'package' => $request->package,
- 'dealer_id' => $request->dealer_id,
- ));
- return view('sales.form.dealer.business_application_information', compact('data'));
- }
-
- public function viewFormPackageD(Request $request)
- {
- $data = array();
- array_push($data, array(
- 'coverage' => $request->coverage,
- 'unit' => $request->unit,
- 'street' => $request->street,
- 'package' => $request->package,
- 'application' => $request->application,
- 'company_name' => $request->company_name,
- 'company_register' => $request->company_register,
- 'company_number' => $request->company_number,
- 'company_fax' => $request->company_fax,
- 'full_name' => $request->full_name,
- 'nric_passport' => $request->nric_passport,
- 'ip' => $request->ip,
- 'designation' => $request->designation,
- 'contact_primary' => $request->contact_primary,
- 'contact_secondary' => $request->contact_secondary,
- 'email' => $request->email,
- 'dealer_id' => $request->dealer_id,
- ));
-
- $pg = $request->package;
-
- $coverage = Coverage::where('_id', $request->coverage)->first();
- $city = $coverage->city;
-
- return view('sales.form.dealer.business_package', compact('data', 'pg', 'city'));
- }
-
- public function viewFormPreviewD(Request $request)
- {
- $data = array();
-
- $coverage = Coverage::where('_id', $request->coverage)->first();
- $product = Product::where('formT', 'B')->where('package_name', $request->package)->first();
- $otc = 0.0;
-
- $total_monthly = 0;
- $gst = '';
- $promo_st = '';
-
- $voice = "No";
- if ($request->voice == "Yes") {
- $voice = $request->voice;
- $voice_price = 20;
- } else {
- $voice = "No";
- $voice_price = 0;
- }
-
- $ip_fee = 0;
- $ip_tax = 0;
- if ($request->ip == "1 Fixed IP RM200/1P/Month") {
- $ip_fee = 200;
- $ip_tax = number_format((floatval($ip_fee) * 1.06), 2);
- } elseif ($request->ip == "5 Fixed IP RM400/1P/Month") {
- $ip_fee = 400;
- $ip_tax = number_format((floatval($ip_fee) * 1.06), 2);
- }
-
- if ($request->package != "1Gbps" && $request->subscription == '24') {
- $promo_price = number_format(floatval($product->retail_price) - 10);
- $promo_st = number_format(floatval($promo_price) * 1.06, 2);
- $total_monthly = number_format($promo_st + ($voice_price * 1.06) + $ip_tax, 2);
- } else if ($request->package == "1Gbps") {
- if ($request->subscription == '24' && $coverage->city == 'CYBERJAYA') {
- $gst = 1058.94;
- $total_monthly = 1058.94;
- } else {
- $gst = 3708.94;
- $total_monthly = 3708.94;
- }
- } else {
- $gst = number_format(floatval($product->retail_price) * 1.06, 2);
- $total_monthly = number_format($gst + ($voice_price * 1.06) + $ip_tax, 2);
- }
-
-
- if ($request->subscription == '12' && $voice == 'No') {
- if ($request->package != '50Mbps') {
- $otc = 400;
- } else {
- $otc = 300;
- }
- $deposit = $product->deposit;
- } else if ($request->subscription == '12' && $voice == 'Yes') {
- $otc = 300 + 100;
- $deposit = $product->deposit;
- } else if ($request->subscription == '12' && $request->package != '50Mbps') {
- $otc = 400;
- $deposit = $product->deposit;
- } else {
- $otc = 0.0;
- $deposit = $product->deposit;
- }
-
- $otc_st = number_format(floatval($otc) * 1.06, 2);
- $upfront_total = number_format(floatval($otc_st) + $deposit, 2);
-
- $total = number_format((floatval($product->retail_price) * 1.06) + ($otc * 1.06) + $deposit + $ip_tax, 2);
-
- array_push($data, array(
- 'coverage' => $request->coverage,
- 'unit' => $request->unit,
- 'street' => $request->street,
- 'package' => $request->package,
- 'application' => $request->application,
- 'company_name' => $request->company_name,
- 'company_register' => $request->company_register,
- 'company_number' => $request->company_number,
- 'company_fax' => $request->company_fax,
- 'full_name' => $request->full_name,
- 'nric_passport' => $request->nric_passport,
- 'designation' => $request->designation,
- 'contact_primary' => $request->contact_primary,
- 'contact_secondary' => $request->contact_secondary,
- 'email' => $request->email,
- 'subscription' => $request->subscription,
- 'billing' => $request->billing,
- 'voice' => $voice,
- 'ip' => $request->ip,
- 'ip_fee' => $ip_fee,
- 'ip_tax' => $ip_tax,
- 'thedate' => $request->thedate,
- 'dealer_id' => $request->dealer_id,
- ));
-
- return view('sales.form.dealer.business_preview', compact('data', 'coverage', 'product', 'deposit', 'otc', 'otc_st', 'gst', 'promo_price', 'promo_st', 'total_monthly', 'upfront_total'));
- }
-
- public function storeFormDataD(Request $request)
- {
-
- $su_id = '';
- $pathIconF = '';
- $pathIconB = '';
- $pathForm9 = '';
- $pathPaymentReceipt = '';
- $pathSoForm = '';
-
- do {
- $su_id = strtoupper('CBB-' . $this->random_code(6) . 'B');
- } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
-
-
- $destinationPath = 'document/' . $su_id;
- // create folder/dir if not exist
- if (!File::exists(public_path() . '/' . $destinationPath)) {
- File::makeDirectory(public_path() . '/' . $destinationPath, 0777, true);
- }
-
-
- if ($request->hasfile('front_ic')) {
-
- $icon = $request->file('front_ic');
- $icon->move($destinationPath, 'frontic.' . $icon->getClientOriginalExtension());
- $pathIconF = '/' . $destinationPath . '/frontic.' . $icon->getClientOriginalExtension();
- }
-
- if ($request->hasfile('back_ic')) {
-
- $icon = $request->file('back_ic');
- $icon->move($destinationPath, 'backic.' . $icon->getClientOriginalExtension());
- $pathIconB = '/' . $destinationPath . '/backic.' . $icon->getClientOriginalExtension();
- }
-
- if ($request->hasfile('form9')) {
-
- $icon = $request->file('form9');
- $icon->move($destinationPath, 'formD.' . $icon->getClientOriginalExtension());
- $pathForm9 = '/' . $destinationPath . '/formD.' . $icon->getClientOriginalExtension();
- }
-
- if ($request->hasfile('paymentReceipt')) {
-
- $icon = $request->file('paymentReceipt');
- $icon->move($destinationPath, 'paymentReceipt.' . $icon->getClientOriginalExtension());
- $pathPaymentReceipt = '/' . $destinationPath . '/paymentReceipt.' . $icon->getClientOriginalExtension();
- }
-
- if ($request->hasfile('soForm')) {
-
- $icon = $request->file('soForm');
- $icon->move($destinationPath, 'soForm.' . $icon->getClientOriginalExtension());
- $pathSoForm = '/' . $destinationPath . '/soForm.' . $icon->getClientOriginalExtension();
- }
-
- if ($pathForm9 != '' && $pathIconB != '' && $pathIconF != '') {
-
- $staff = Staff::with('StaffDetail')->where('_id', $request->dealer_id)->first();
- if (!empty($staff)) {
- $coverage = Coverage::where('_id', $request->coverage)->first();
- $product = Product::where('formT', 'B')->where('package_name', $request->package)->first();
-
- $sl = new Form();
- $sl->type_service = $request->application;
- $sl->type_application = 'B';
- $sl->project_type = $coverage->project_type;
- $sl->status_payment = 'paid';
- $sl->status_email = 'unverified';
- $sl->customer_category = 'Allo';
- $sl->remark_form = '';
- $sl->dealer_id = $request->dealer_id;
- $sl->company_id = $staff->StaffDetail->company_id;
-
- $staff->form()->save($sl);
-
- $sdl = new Subscriber();
- $sdl->subscriber_id = $su_id;
- $sdl->name = $request->full_name;
- $sdl->ic = $request->nric_passport;
- $sdl->company_name = $request->company_name;
- $sdl->company_reg = $request->company_register;
- $sdl->company_num = $request->company_number;
- $sdl->company_fax = $request->company_fax;
- $sdl->designation = $request->designation;
- $sdl->email = $request->email;
- $sdl->phone1 = $request->contact_primary;
- $sdl->phone2 = $request->contact_secondary;
- $sdl->unit_no = $request->unit;
- $sdl->building_name = $coverage->building_name;
- $sdl->street = $request->street;
- $sdl->postcode = $coverage->postcode;
- $sdl->city = $coverage->city;
- $sdl->state = $coverage->state;
- $sdl->front_ic = $pathIconF;
- $sdl->back_ic = $pathIconB;
- $sdl->form9_44 = $pathForm9;
- $sdl->paymentReceipt = $pathPaymentReceipt;
- $sdl->soForm = $pathSoForm;
-
- $packageD = new PackageDetail();
- $packageD->contract = $request->subscription;
- $packageD->name = $product->speed;
- if ($request->gst != null) {
- $packageD->montly_fee = $request->gst;
- } else {
- $packageD->montly_fee = $request->promo_st;
- }
- $packageD->voice_fee = $request->voice;
- $packageD->ip = $request->ip;
- $packageD->ip_tax = $request->ip_tax;
- $packageD->deposit = $request->deposit;
- $packageD->upfront_payment = $request->otc;
- $packageD->rfs = $request->rfs;
-
- $sl->subscriber()->save($sdl);
- $sl->packagedetail()->save($packageD);
-
- $f_id = $this->sendInvoice($su_id);
- $stat = new FormStatus();
- $stat->form_id = $f_id;
- $stat->status_id = 1;
- $stat->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
- $stat->status = 'Submitted';
- $stat->desc = 'The form already been submit';
- $sl->formstatus()->save($stat);
-
- return redirect('http://db.citybroadband.my/business/application-form/success-submit');
- }
- }
- }
-
- public function verifyEmail($subscriber_id)
- {
- $subscriber = Subscriber::where('subscriber_id', $subscriber_id)->first();
- if (!empty($subscriber)) {
- $form = Form::where('_id', $subscriber->_id)->first();
- if (!empty($form)) {
- if ($form->status_email == 'unverified') {
- $form->status_email = 'verified';
- $form->save();
-
- $stat = new FormStatus();
- $stat->form_id = $form->_id;
- $stat->status_id = 2;
- $stat->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
- $stat->status = 'Verified';
- $stat->desc = 'Email already been verified by customer';
- $form->formstatus()->save($stat);
-
- return redirect('http://db.citybroadband.my/business/application-form/success-verified');
- }
- }
- }
- }
-
- public function resendEmail($subscriber_id)
- {
- $f_id = $this->sendInvoice($subscriber_id);
- return $f_id;
- }
-
-
- public function checkEmailTemplate($subscriber_id)
- {
- $subscriber = Subscriber::where('subscriber_id', $subscriber_id)->first();
- if (!empty($subscriber)) {
- $form = Form::where('_id', $subscriber->_id)->first();
- $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $form->type_application)->first();
- }
- return view('email.invoiceb', compact('form', 'product'));
- }
- }
|