model = $model; } public function update($data) { if ($data['user_id'] === 'new' || $data['user_id'] == 0) { $this->model = User::create([ 'email' => $data['email'], 'password' => env('APP_KEY'), ]); $this->model->payment_methods = PaymentMethod::getDefaultAsArray(); $this->model->save(); } else { $this->model = $this->getById($data['user_id']); } if (! $this->model->account_id) { $account = new UserAccount; } else { $account = $this->model->account; } $data['same_as_billing'] = ! isset($data['same_as_billing']) ? 0 : 1; $account->fill($data)->save(); if (! $this->model->account_id) { $this->model->account_id = $account->id; $this->model->save(); } return true; } public function create($data) { $this->model = new User([ 'email' => $data['email'], 'password' => Hash::make($data['password']), ]); $this->model->lang = $data['lang'] ?? 'de'; $this->model->save(); $account = UserAccount::create([ 'm_salutation' => $data['salutation'], 'm_first_name' => $data['first_name'], 'm_last_name' => $data['last_name'], 'salutation' => $data['salutation'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], ]); $this->model->account_id = $account->id; $this->model->payment_methods = PaymentMethod::getDefaultAsArray(); $this->model->save(); return $this->model; } public function deleteUser(User $user, $complete = false) { $active_sponsor = UserUtil::findNextActiveSponsor($user->id); if ($active_sponsor) { UserUtil::setNewSponsorToChilds($user->id, $active_sponsor->id); UserUtil::setShoppingUserToNewMember($user->id, $active_sponsor->id); } UserUtil::deleteUser($user, $complete); } public function reverse_charge_validate($data, $user, $route) { if (isset($data['action']) && $data['action'] == 'reverse_charge_validate') { $rules = [ 'tax_identification_number' => 'required', ]; $validator = Validator::make($data, $rules); if ($validator->fails()) { $data = [ 'user' => $user, ]; return redirect($route.'#user-vat-validation')->withErrors($validator)->withInput($data); } $ret = $this->reverse_charge_activate($data, $user); if ($ret === 'error' || $ret === 'error_german') { $validator = Validator::make($data, []); $message = $ret === 'error_german' ? __('msg.VATID_german_not_allowed') : __('msg.VATID_could_not_be_validated'); $validator->errors()->add('tax_identification_number_validated', $message); $data['reverse_charge'] = 0; $data = [ 'user' => $user, ]; return redirect($route.'#user-vat-validation')->withErrors($validator)->withInput($data); } if ($ret === 'valid') { \Session()->flash('alert-success', __('msg.VATID_successfully_entered')); return redirect($route.'#user-vat-validation')->withInput($data); return redirect($route.'#user-vat-validation')->withInput($data); } } } public function reverse_charge_delete($data, $user, $route) { if (isset($data['action']) && $data['action'] == 'reverse_charge_delete') { $user->account->tax_identification_number = ''; $user->account->reverse_charge = 0; $user->account->reverse_charge_code = null; $user->account->reverse_charge_valid = null; $user->account->save(); $data['tax_identification_number'] = ''; \Session()->flash('alert-success', __('msg.reverse_charge_procedure_and_VATID_deleted')); return redirect($route.'#user-vat-validation')->withInput($data); } } public function reverse_charge_activate($data, $user) { /* 'AT' => 'AT-Oesterreich', 'BE' => 'BE-Belgien', 'BG' => 'BG-Bulgarien', 'CY' => 'CY-Zypern', 'CZ' => 'CZ-Tschechische Republik', 'DE' => 'DE-Deutschland', 'DK' => 'DK-Dänemark', 'EE' => 'EE-Estland', 'EL' => 'EL-Griechenland', 'ES' => 'ES-Spanien', 'FI' => 'FI-Finnland', 'FR' => 'FR-Frankreich ', 'HR' => 'HR-Kroatien ', 'HU' => 'HU-Ungarn', 'IE' => 'IE-Irland', 'IT' => 'IT-Italien', 'LT' => 'LT-Litauen', 'LU' => 'LU-Luxemburg', 'LV' => 'LV-Lettland', 'MT' => 'MT-Malta', 'NL' => 'NL-Niederlande', 'PL' => 'PL-Polen', 'PT' => 'PT-Portugal', 'RO' => 'RO-Rumänien', 'SE' => 'SE-Schweden', 'SI' => 'SI-Slowenien', 'SK' => 'SK-Slowakei', 'XI' => 'XI-Nordirland', */ $accountCountryCode = 'DE'; if ($user->account->country_id) { $accountCountryCode = $user->account->country->code; } $vatService = app(VatIdService::class); $vatid = $vatService->normalize($data['tax_identification_number']); $countryCode = $vatService->extractCountryCode($vatid, $accountCountryCode); if ($vatService->isGermanVatId($vatid) || $countryCode === 'DE') { return 'error_german'; } if ($vatService->checkVies($vatid, $accountCountryCode) === VatIdService::CHECK_VALID) { $user->account->tax_identification_number = $data['tax_identification_number']; $user->account->reverse_charge = 1; $user->account->reverse_charge_code = $countryCode; $user->account->reverse_charge_valid = now(); $user->account->save(); return 'valid'; } return 'error'; } }