Lieferland UST CH, Reverse Charge
This commit is contained in:
parent
351a8f763c
commit
d46824a4ac
19 changed files with 455 additions and 41 deletions
|
|
@ -63,7 +63,12 @@ class AdminUserController extends Controller
|
|||
{
|
||||
$data = Request::all();
|
||||
$user = User::findOrFail($data['id']);
|
||||
|
||||
|
||||
if(isset($data['user-delete'])){
|
||||
if(isset($data['realy_delete_user'])){
|
||||
return redirect(route('admin_user_delete', [$user->id]));
|
||||
}
|
||||
}
|
||||
if(isset($data['save-admin'])){
|
||||
$user->admin = $data['admin'];
|
||||
SysLog::action('save-admin', 'admin_user', 3)
|
||||
|
|
|
|||
|
|
@ -52,10 +52,12 @@ class CountryController extends Controller
|
|||
|
||||
$data['active'] = isset($data['active']) ? true : false;
|
||||
$data['switch'] = isset($data['switch']) ? true : false;
|
||||
$data['eu_country'] = isset($data['eu_country']) ? true : false;
|
||||
$data['own_eur'] = isset($data['own_eur']) ? true : false;
|
||||
$data['currency'] = isset($data['currency']) ? true : false;
|
||||
$data['currency_faktor'] = $data['currency_faktor'] == "" ? null : reFormatNumber($data['currency_faktor']);
|
||||
|
||||
|
||||
if(!isset($data['attr'])){
|
||||
$data['attr'] = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,10 +80,12 @@ class DataTableController extends Controller
|
|||
return $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$user->getPaymentMethodsShort().'</span></a>';
|
||||
|
||||
})
|
||||
->addColumn('action_delete', function (User $user) {
|
||||
return '<span class="no-line-break"><a href="' . route('admin_user_delete', [$user->id]) . '" class="btn icon-btn btn-sm btn-danger" onclick="return confirm(\''.__('Really delete entry?').'\');"><span class="fa fa-trash"></span></a>
|
||||
<a href="' . route('admin_user_login_as', [$user->id]) . '" class="btn icon-btn btn-sm btn-warning" onclick="return confirm(\''.__('Login as User?').'\');"><span class="fa fa-sign-in-alt"></span></a></span>';
|
||||
->addColumn('action_login', function (User $user) {
|
||||
return '<a href="' . route('admin_user_login_as', [$user->id]) . '" class="btn icon-btn btn-sm btn-warning" onclick="return confirm(\''.__('Login as User?').'\');"><span class="fa fa-sign-in-alt"></span></a>';
|
||||
})
|
||||
->addColumn('action_delete', function (User $user) {
|
||||
return '<a class="btn icon-btn btn-sm btn-danger" href="#" data-toggle="modal" data-target="#modals-user-delete" data-id="'.$user->id.'" data-email="'.$user->email.'"><span class="fa fa-trash"></span></a>';
|
||||
})
|
||||
->addColumn('test_mode', function (User $user) {
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-test_mode" data-id="'.$user->id.'" data-email="'.$user->email.'" data-test_mode="'.$user->test_mode.'">';
|
||||
return $user->test_mode ? $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span></a>' : $link.'<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
|
|
@ -94,7 +96,7 @@ class DataTableController extends Controller
|
|||
->orderColumn('active', 'active $1')
|
||||
->orderColumn('shop', 'shop $1')
|
||||
->orderColumn('admin', 'active $1')
|
||||
->rawColumns(['id', 'admin', 'confirmed', 'active', 'account', 'shop', 'my_payment_methods', 'test_mode', 'action_delete'])
|
||||
->rawColumns(['id', 'admin', 'confirmed', 'active', 'account', 'shop', 'my_payment_methods', 'test_mode', 'action_login', 'action_delete'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Repositories\UserRepository;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Request;
|
||||
use App\User;
|
||||
use Validator;
|
||||
use App\Models\UserAccount;
|
||||
use App\Repositories\UserRepository;
|
||||
|
||||
|
||||
class UserDataController extends Controller
|
||||
|
|
@ -45,6 +46,44 @@ class UserDataController extends Controller
|
|||
$user->account = new UserAccount();
|
||||
}*/
|
||||
|
||||
$data = Request::all();
|
||||
if(isset($data['reverse_charge_validate'])){
|
||||
|
||||
$rules = array(
|
||||
'tax_identification_number' => 'required',
|
||||
'reverse_charge' => 'required',
|
||||
);
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return view('user.edit', $data)->withErrors($validator);
|
||||
}
|
||||
$ret = $this->userRepo->reverse_charge_activate(Request::all(), $user);
|
||||
if($ret === 'error'){
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
$validator->errors()->add('tax_identification_number', __('Die UST-ID konnte nicht validiert werden, Eingabe bitte prüfen.'));
|
||||
$data['reverse_charge'] = 0;
|
||||
return redirect(route('user_edit'))->withErrors($validator)->withInput($data);
|
||||
}
|
||||
if($ret === 'valid'){
|
||||
\Session()->flash('alert-success', 'UST-ID erfolgreich eingetragen.');
|
||||
return redirect('/user/edit');
|
||||
|
||||
}
|
||||
}
|
||||
if(isset($data['reverse_charge_delete'])){
|
||||
$user->account->tax_identification_number = '';
|
||||
$user->account->reverse_charge = 0;
|
||||
$user->account->reverse_charge_valid = null;
|
||||
$user->account->save();
|
||||
\Session()->flash('alert-success', 'Reverse Charge Verfahren und UST-ID gelöscht.');
|
||||
return redirect('/user/edit');
|
||||
|
||||
}
|
||||
|
||||
|
||||
$rules = array(
|
||||
'salutation' => 'required',
|
||||
'first_name'=>'required',
|
||||
|
|
@ -72,7 +111,6 @@ class UserDataController extends Controller
|
|||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
||||
return view('user.edit', $data)->withErrors($validator);
|
||||
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ class Country extends Model
|
|||
|
||||
protected $casts = [
|
||||
'switch' => 'bool',
|
||||
'supply_country' => 'bool',
|
||||
'eu_country' => 'bool',
|
||||
'own_eur' => 'bool',
|
||||
'currency' => 'bool',
|
||||
'currency_calc' => 'bool',
|
||||
|
|
@ -73,7 +75,7 @@ class Country extends Model
|
|||
|
||||
protected $fillable = [
|
||||
'code', 'phone', 'en', 'de', 'es', 'fr', 'it', 'ru',
|
||||
'switch', 'own_eur', 'currency', 'currency_unit', 'currency_calc', 'currency_faktor',
|
||||
'supply_country', 'eu_country', 'switch', 'own_eur', 'currency', 'currency_unit', 'currency_calc', 'currency_faktor',
|
||||
'active', 'trans_name', 'attr',
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -129,10 +129,12 @@ class UserAccount extends Model
|
|||
'shipping_salutation', 'shipping_company', 'shipping_firstname', 'shipping_lastname', 'shipping_address', 'shipping_address_2', 'shipping_zipcode', 'shipping_city', 'shipping_country_id', 'shipping_pre_phone_id', 'shipping_phone',
|
||||
'birthday', 'website', 'facebook', 'facebook_fanpage', 'instagram', 'notice'
|
||||
];
|
||||
//'reverse_charge', 'reverse_charge_valid'
|
||||
|
||||
protected $casts = [
|
||||
'payment_data' => 'array',
|
||||
'notice' => 'array',
|
||||
//'reverse_charge' => 'bool'
|
||||
];
|
||||
|
||||
use SoftDeletes;
|
||||
|
|
@ -191,6 +193,10 @@ class UserAccount extends Model
|
|||
return Carbon::parse($this->attributes['accept_contract'])->format(\Util::formatDateTimeDB());
|
||||
}
|
||||
|
||||
public function getReverseChargeValidFormat(){
|
||||
if(!$this->attributes['reverse_charge_valid']){ return ""; }
|
||||
return Carbon::parse($this->attributes['reverse_charge_valid'])->format(\Util::formatDateTimeDB());
|
||||
}
|
||||
|
||||
public function getCountryAttrAs($attr, $as = false){
|
||||
if($this->country){
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class UserRepository extends BaseRepository {
|
|||
|
||||
$data['same_as_billing'] = !isset($data['same_as_billing']) ? 0 : 1;
|
||||
|
||||
|
||||
$account->fill($data)->save();
|
||||
|
||||
if(!$this->model->account_id){
|
||||
|
|
@ -78,7 +79,75 @@ class UserRepository extends BaseRepository {
|
|||
|
||||
return $this->model;
|
||||
}
|
||||
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', */
|
||||
$countryCode = 'DE';
|
||||
|
||||
if($user->account->country_id){
|
||||
$countryCode = $user->account->country->code;
|
||||
}
|
||||
|
||||
$vatid = str_replace(array(' ', '.', '-', ',', ', '), '', trim($data['tax_identification_number']));
|
||||
$cc = substr($vatid, 0, 2);
|
||||
$vatNo = substr($vatid, 2);
|
||||
|
||||
$options = [
|
||||
'cache_wsdl' => WSDL_CACHE_NONE,
|
||||
'trace' => 1,
|
||||
'stream_context' => stream_context_create(
|
||||
[
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed' => true
|
||||
]
|
||||
]
|
||||
)
|
||||
];
|
||||
|
||||
$client = new \SoapClient("https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl", $options);
|
||||
$result = $client->checkVat(['countryCode' => $countryCode, 'vatNumber' => $vatNo]);
|
||||
|
||||
if($result->valid == true) {
|
||||
$user->account->tax_identification_number = $data['tax_identification_number'];
|
||||
$user->account->reverse_charge = 1;
|
||||
$user->account->reverse_charge_valid = now();
|
||||
$user->account->save();
|
||||
return 'valid';
|
||||
} else {
|
||||
return 'error';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public function deleteUser(User $user)
|
||||
{
|
||||
if($user->account){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue