| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
-
- namespace App\Http\Controllers\v3\Dealer;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
- use LynX39\LaraPdfMerger\Facades\PdfMerger;
-
- use Carbon\Carbon;
- use Validator;
- use Hash;
-
- use App\SiteSetting;
- use App\LatestModel\Staff;
- use App\LatestModel\StaffDetail;
- use App\LatestModel\Module\Form;
- use App\LatestModel\Module\Subscriber;
- use App\LatestModel\Module\WorkOrder;
- use App\LatestModel\Module\PackageDetail;
- use App\LatestModel\Module\Company;
- use App\LatestModel\Module\Coverage;
- use App\LatestModel\Module\Product;
- use App\LatestModel\Module\Docket;
-
- class TeamController extends Controller
- {
- function viewTeamList()
- {
- $id = Auth::guard('dealer')->id();
- $user = Staff::with('StaffDetail')->find($id);
- $site = SiteSetting::first();
-
- return view('v3.main-dealer.team.sales_list',compact('user','site'));
- }
-
- public function viewStaffForm()
- {
- $id = Auth::guard('dealer')->id();
- $user = Staff::with('StaffDetail')->find($id);
- $site = SiteSetting::first();
- return view('v3.main-dealer.team.add_new_staff', compact('user','site'));
- }
-
- public function encryptPassword($action, $string) {
- $output = false;
- $encrypt_method = "AES-256-CBC";
- $secret_key = '28472B4B6250655368566D5970337336';
- $secret_iv = md5(md5($string)); //'This is my secret iv';
-
- // hash
- $key = hash('sha256', $secret_key);
-
- $iv = substr(hash('sha256', $secret_iv), 0, 16);
- if ( $action == 'encrypt' ) {
- $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
- $output = base64_encode($output);
- } else if( $action == 'decrypt' ) {
- $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
- }
- return $output;
- }
-
- public function requestAddSales(Request $request){
-
- $validator = Validator::make($request->all(), [
- 'password' => 'min:6|confirmed',
- ]);
-
- if ($validator->fails()) {
- return redirect()->back()->withInput()->withErrors($validator);
- }
-
- $encrP = $this->encryptPassword('encrypt', $request->password);
- $encrP2 = Hash::make($request->get('password'));
- $company = Company::where('_id',$request->vendor)->first();
- if(!empty($company)){
- $exist = Staff::with('StaffDetail')->where('email',$request->email)->where('roles_access','Sales')->first();
- if(empty($exist)){
- $sl = Staff::create([
- 'email' => $request->email,
- 'password' => $encrP,
- 'password2' => $encrP2,
- 'roles_access' => 'Sales',
- 'company_id' => $request->vendor,
- 'last_login_at' => '',
- 'last_login_ip'=> '',
- 'company_id' => $request->vendor,
- 'authorized' => false,
- 'token_firebase' => '',
- ]);
-
- $sdl = new StaffDetail();
- $sdl->name = $request->name;
- $sdl->ic = $request->ic;
- $sdl->email = $request->email;
- $sdl->phone = $request->phone;
- $sdl->company_id = $request->vendor;
- $sdl->color = $company->color;
- $sdl->position = 'Sales';
- $sdl->password = $encrP;
- $sdl->password2 = $encrP2;
- $sdl->user_pic = 'uploads/profile/user.png';
-
- $company->staff()->save($sl);
- $company->save();
- $sl->staffdetail()->save($sdl);
-
- return redirect()->back()->with('success_msg', '<strong>Success!</strong> add <strong>'.$request->get('aname').'</strong> as new sales');
-
- }else {
- return redirect()->back()->withInput()->with('error_msg', 'Staff sales with '.$request->email.' already exist!');
- }
-
- }else {
- return redirect()->back()->withInput()->with('error_msg', 'Record company not found!');
- }
- }
-
- public function editStaffDetail($_id)
- {
- $id = Auth::guard('dealer')->id();
- $user = Staff::with('StaffDetail')->find($id);
- $site = SiteSetting::first();
-
- $staff = Staff::with('StaffDetail')->where('_id', $_id)->first();
- $current_company = Company::where('_id',$user->company_id)->first();
- return view('v3.main-dealer.team.edit_staff_detail',compact('user','site','staff','current_company'));
- }
-
- public function requestEditStaff(Request $request){
-
- $exist = Staff::with('StaffDetail')->where('_id',$request->_id)->first();
- if(empty($exist)){
- return redirect()->back()->withInput()->withErrors('staff not found');
- }else {
-
- $exist->email = $request->email;
- $exist->save();
-
- $exist->StaffDetail->name = $request->name;
- $exist->StaffDetail->ic = $request->ic;
- $exist->StaffDetail->email = $request->email;
- $exist->StaffDetail->phone = $request->phone;
- $exist->StaffDetail->save();
-
- return redirect()->back()->with('success_msg', '<strong>Success!</strong> update detail staff <strong>'.$request->get('name').'</strong>');
-
- }
- }
- }
|