first commit

This commit is contained in:
Kevin Adametz 2021-01-08 17:48:20 +01:00
commit 0baac018a2
1011 changed files with 145854 additions and 0 deletions

View file

@ -0,0 +1,68 @@
<?php
namespace App\Repositories;
abstract class BaseRepository {
/**
* The Model instance.
*
* @var Illuminate\Database\Eloquent\Model
*/
protected $model;
/**
* Get number of records.
*
* @return array
*/
public function getNumber()
{
$total = $this->model->count();
$new = $this->model->whereSeen(0)->count();
return compact('total', 'new');
}
/**
* Destroy a model.
*
* @param int $id
* @return void
*/
public function destroy($id)
{
$this->getById($id)->delete();
}
/**
* Get Model by id.
*
* @param int $id
* @return App\Models\Model
*/
public function getById($id)
{
return $this->model->findOrFail($id);
}
/**
* Get Model by id.
*
* @param int $id
* @return App\Models\Model
*/
public function getAll()
{
return $this->model->all();
}
/**
* @return Illuminate\Database\Eloquent\Model
*/
public function getModel()
{
return $this->model;
}
}

View file

@ -0,0 +1,150 @@
<?php
namespace App\Repositories;
use App\Libraries\ContractPDF;
use App\Models\File;
use App\User;
use Request;
use Response;
use Storage;
use Util;
use Validator;
class ContractPDFRepository extends BaseRepository {
protected $disk;
protected $dir;
protected $user_id;
protected $identifier;
public function __construct(User $model){
$this->model = $model;
}
public function _set($name, $value){
$this->{$name} = $value;
}
private function convert($str){
return iconv('UTF-8', 'windows-1252', $str);
}
public function createContractPDF() {
$pdf = new ContractPDF();
$pdf->AddPage('P', array(210, 297));
$pdf->SetFont('Helvetica', '', 11);
$pdf->SetDrawColor(160, 160, 160);
$x1 = 16.5;
$x2 = 109;
$y = 70;
$nl = 17.5;
$pdf->SetXY($x1, $y);
$pdf->Write(0, $this->convert($this->model->account->m_account));
$pdf->SetXY($x2, $y);
$pdf->Write(0, now()->format("d.m.Y"));
$y += $nl;
$pdf->SetXY($x1, $y);
$pdf->Write(0, $this->convert($this->model->account->company));
$pdf->SetXY($x2, $y);
$pre = $this->model->account->pre_phone_id != "" ? $this->convert($this->model->account->pre_phone->phone)." " : "";
$pdf->Write(0, $pre.$this->convert($this->model->account->phone));
$y += $nl;
$pdf->SetXY($x1, $y);
$pdf->Write(0, $this->convert($this->model->account->m_first_name));
$pdf->SetXY($x2, $y);
$pre = $this->model->account->pre_mobil_id != "" ? $this->convert($this->model->account->pre_mobil->phone)." " : "";
$pdf->Write(0, $pre.$this->convert($this->model->account->mobil));
$y += $nl;
$pdf->SetXY($x1, $y);
$pdf->Write(0, $this->convert($this->model->account->m_last_name));
$pdf->SetXY($x2, $y);
$pdf->Write(0, $this->convert($this->model->email));
$y += $nl;
$pdf->SetXY($x1, $y);
$pdf->Write(0, $this->convert($this->model->account->address));
$pdf->SetXY($x2, $y);
$pdf->Write(0, $this->convert($this->model->account->birthday));
$y += $nl;
$pdf->SetXY($x1, $y);
$pdf->Write(0, $this->convert($this->model->account->zipcode)." ".$this->convert($this->model->account->city));
$y += $nl;
$pdf->SetXY($x1, $y);
$pre = $this->model->account->country_id ? $this->convert($this->model->account->country->de)." " : "";
$pdf->Write(0, $pre);
if($this->model->m_sponsor){
$y += 48;
$pdf->SetXY($x1, $y);
$pdf->Write(0, $this->convert($this->model->user_sponsor->account->company));
$pdf->SetXY($x2, $y);
$pdf->Write(0, $this->convert($this->model->user_sponsor->account->m_account));
$y += $nl;
$pdf->SetXY($x1, $y);
$pdf->Write(0, $this->convert($this->model->user_sponsor->account->m_first_name)." ".$this->convert($this->model->user_sponsor->account->m_last_name));
$website = $this->model->user_sponsor->shop()->count() ? $this->model->user_sponsor->shop->getSubdomain(false) : "www.mivita.care";
}else{
$website = "www.mivita.care";
}
$pdf->AddPage('P', array(210, 297));
$pdf->SetFont('Helvetica', '', 10);
$pdf->SetDrawColor(160, 160, 160);
$pdf->SetXY(52, 56);
$pdf->Write(0, $website);
$pdf->SetXY($x1, 65);
$pdf->Write(0, $this->convert($this->model->account->m_first_name)." ".$this->convert($this->model->account->m_last_name));
$pdf->SetXY($x2, 65);
$pdf->Write(0, $this->convert($this->model->account->m_account));
$pdf->AddPage('P', array(210, 297));
if(!Storage::disk($this->disk)->exists( $this->dir )){
Storage::disk($this->disk)->makeDirectory($this->dir); //creates directory
}
$filename = "MIVITA_Beratervertrag.pdf";
Storage::disk($this->disk)->put($this->dir.$filename, $pdf->Output('S'));
$size = Storage::disk($this->disk)->size($this->dir.$filename);
$mine = Storage::disk($this->disk)->getMimeType($this->dir.$filename);
File::create([
'user_id' => $this->model->id,
'identifier' => $this->identifier,
'filename' => $filename,
'dir' => $this->dir,
'original_name' => $filename,
'ext' => "pdf",
'mine' => $mine,
'size' => $size
]);
return true;
}
}

View file

@ -0,0 +1,71 @@
<?php
namespace App\Repositories;
class CustomerRepository extends BaseRepository {
public function __construct()
{
//$this->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'),
]);
}
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 = User::create([
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$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->save();
return $this->model;*/
}
}

View file

@ -0,0 +1,135 @@
<?php
namespace App\Repositories;
use App\Models\File;
use Request;
use Response;
use Storage;
use Util;
use Validator;
class FileRepository extends BaseRepository {
protected $rules;
protected $messages;
protected $disk;
protected $dir;
protected $user_id;
protected $identifier;
public function __construct(File $model){
$this->model = $model;
$this->rules = [
'file' => 'required|mimes:pdf,jpeg,png|max:32768'
];
$this->messages = [
'file.mimes' => 'Datei ist kein PDF Format',
'file.required' => 'PDF-Datei wird benötigt'
];
}
public function _set($name, $value){
$this->{$name} = $value;
}
public function uploadFile( $form_data )
{
$validator = Validator::make($form_data, $this->rules, $this->messages);
if ($validator->fails()) {
return Response::json([
'error' => true,
'message' => $validator->messages()->first(),
'code' => 400
], 400);
}
$file = $form_data['file'];
$originalName = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$mine = $file->getClientMimeType();
$size = $file->getSize();
$originalNameWithoutExt = substr($originalName, 0, strlen($originalName) - strlen($extension) - 1);
$filename = Util::sanitize($originalNameWithoutExt, true, false, true);
$allowed_filename = uniqid() . '_' . $filename.".".$extension;
//$dir = $this->model->getInvoiceStorageAttDir();
if(!Storage::disk($this->disk)->exists( $this->dir )){
Storage::disk($this->disk)->makeDirectory($this->dir); //creates directory
}
Storage::disk($this->disk)->put($this->dir.$allowed_filename, file_get_contents($file->getRealPath()));
File::create([
'user_id' => $this->user_id,
'identifier' => $this->identifier,
'filename' => $allowed_filename,
'dir' => $this->dir,
'original_name' => $originalName,
'ext' => $extension,
'mine' => $mine,
'size' => $size
]);
return Response::json([
'error' => false,
'filename' => $allowed_filename,
'filedata' => 'pdf',
'redirect' => route('wizard_register'),
'code' => 200
], 200);
}
/* public function createFile(Request $request)
{
$locale = \App::getLocale();
$data = [
'step' => 2,
'locale' => $locale,
];
$rules = array(
'network_name' => 'required|max:255',
'input_file_now' => 'required|mimes:png,pdf,jpg,jpeg|max:30000'
);
$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
// get the error messages from the validator
$messages = $validator->messages();
// redirect our user back to the form with the errors from the validator
return view('user.register_complete', $data)->withErrors($validator);
} else {
$user = \Auth::user();
if(!$user->account->network_name){
$file = request()->file('input_file_now');
//$ext = $file->guessClientExtension();
//$file->storeAs('user/' . $user->id .'/verification');
$data = $file->store('user/' . $user->id .'/verification');
$account = $user->account;
$account->network_name = Input::get('network_name');
$account->network_verification = basename($data);
$account->save();
$user->role_id = 2; //set as User by default!
$user->save();
}
return redirect('complete_register');
//return view('user.register_complete', $data);
}
}*/
}

View file

@ -0,0 +1,156 @@
<?php
namespace App\Repositories;
use App\Models\Country;
use App\Models\ShoppingUser;
use Validator;
use Response;
use Excel;
use Storage;
use App\Models\Import;
class ImportRepository extends BaseRepository {
public function __construct(){
}
public function upload( $form_data )
{
$validator = Validator::make($form_data, Import::$rules, Import::$messages);
if ($validator->fails()) {
return Response::json([
'error' => true,
'message' => $validator->messages()->first(),
'code' => 400
], 400);
}
$file = $form_data['file'];
$originalName = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$originalNameWithoutExt = substr($originalName, 0, strlen($originalName) - strlen($extension) - 1);
$filename = $this->sanitize($originalNameWithoutExt);
$allowed_filename = $filename.".".$extension;
Storage::disk('import')->put($allowed_filename, file_get_contents($file->getRealPath()));
return Response::json([
'error' => false,
'filename' => $allowed_filename,
'filedata' => 'xls',
'redirect' => url(route('sysadmin_import_show', ['xls', $allowed_filename])),
'code' => 200
], 200);
}
public function read($type, $file, $skip, $limit)
{
if(!Storage::disk('import')->has($file)){
return false;
}
return $this->import(storage_path("app/import/").$file, $file, $skip, $limit);
}
protected function import($file_path, $file, $skip, $limit){
$salutation = array(1 => 'mr', 2 => 'ms', 3=>null);
$ret = [
'count' => 0,
'not' => 0,
'imported' => [],
'has_imported' => [],
];
/*
* wp_order_number
wp_order_date
billing_company
billing_salutation
billing_firstname
billing_lastname
billing_address
billing_address_2
billing_zipcode
billing_city
billing_country_code
billing_country
billing_email
billing_phone
shipping_salutation
shipping_company
shipping_firstname
shipping_lastname
shipping_address
shipping_address_2
shipping_zipcode
shipping_city
shipping_country_code
shipping_country
*/
$rows = Excel::toArray(new \App\Imports\ImportCollection(), $file_path);
foreach ($rows[0] as $row){
$ret['count']++;
if(isset($row['billing_email'])){
if(ShoppingUser::where('billing_email', '=', $row['billing_email'])->count() > 0){
$ssuser = ShoppingUser::where('billing_email', '=', $row['billing_email'])->first();
if($ssuser->member_id){
$ret['has_imported'][] = $row['billing_email']." - ".$ssuser->member->email;
continue;
}
}
$row['billing_salutation'] = $salutation[$row['billing_salutation']];
$row['billing_country_id'] = Country::getCountryIdByCodeOrOne($row['billing_country_code']);
$row['billing_phone'] = strlen($row['billing_phone']) <= 3 ? '' : $row['billing_phone'];
$row['same_as_billing'] = true;
if(isset($row['shipping_salutation']) && $row['shipping_salutation'] > 0){
$row['shipping_salutation'] = $salutation[$row['shipping_salutation']];
$row['shipping_country_id'] = Country::getCountryIdByCodeOrOne($row['shipping_country_code']);
$row['same_as_billing'] = false;
}
$row['member_id'] = 3;
$row['number'] = ShoppingUser::max('number') + 1;
$row['has_buyed'] = true;
$row['subscribed'] = false;
$ret['imported'][] = $row['billing_email'];
ShoppingUser::create($row);
}else{
$ret['not']++;
}
}
return $ret;
}
public function sanitize($string, $force_lowercase = true, $anal = false)
{
$strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]",
"}", "\\", "|", ";", ":", "\"", "'", "&#8216;", "&#8217;", "&#8220;", "&#8221;", "&#8211;", "&#8212;",
"—", "–", ",", "<", ".", ">", "/", "?");
$clean = trim(str_replace($strip, "", strip_tags($string)));
$clean = preg_replace('/\s+/', "-", $clean);
$clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean ;
return ($force_lowercase) ?
(function_exists('mb_strtolower')) ?
mb_strtolower($clean, 'UTF-8') :
strtolower($clean) :
$clean;
}
}

View file

@ -0,0 +1,197 @@
<?php
namespace App\Repositories;
use App\Models\CountryPrice;
use App\Models\Product;
use App\Models\ProductAttribute;
use App\Models\ProductCategory;
use App\Models\ProductImage;
use App\Models\ProductIngredient;
class ProductRepository extends BaseRepository {
public function __construct(Product $model)
{
$this->model = $model;
}
/**
* refresh.
*/
public function update($data)
{
$data['active'] = isset($data['active']) ? 1 : 0;
$data['shipping_addon'] = isset($data['shipping_addon']) ? 1 : 0;
if($data['id'] === "new"){
$this->model = Product::create($data);
}
else{
$this->model = $this->getById($data['id']);
$this->model->fill($data);
$this->model->save();
}
$this->updateCategories(isset($data['categories']) ? $data['categories'] : array());
$this->updateAttributes(isset($data['attributes']) ? $data['attributes'] : array());
$this->updateIngredients(isset($data['product_ingredients']) ? $data['product_ingredients'] : array());
$this->updateCountryPrices($data);
return $this->model;
}
public function updateIngredients($data = array())
{
$ProductIngredient = $this->model->p_ingredients()->pluck('ingredient_id')->toArray();
//set attr
if(is_array($data)){
foreach ($data as $id) {
//not use
if(!in_array($id, $ProductIngredient)){
ProductIngredient::create([
'product_id' => $this->model->id,
'ingredient_id' => $id,
]);
}
}
}
return true;
}
public function updateCategories($data = array())
{
foreach ($this->model->categories as $category) {
if(($pos = array_search($category->category_id, $data)) !== FALSE){
unset($data[$pos]);
}else{
$category->delete();
}
}
//set attr
if(is_array($data)){
foreach ($data as $id) {
ProductCategory::create([
'product_id' => $this->model->id,
'category_id' => $id,
]);
}
}
return true;
}
public function updateAttributes($data = array())
{
foreach ($this->model->attributes as $attribute) {
if(($pos = array_search($attribute->attribute_id, $data)) !== FALSE){
unset($data[$pos]);
}else{
$attribute->delete();
}
}
//set attr
if(is_array($data)){
foreach ($data as $id) {
ProductAttribute::create([
'product_id' => $this->model->id,
'attribute_id' => $id,
]);
}
}
return true;
}
public function updateCountryPrices($data)
{
if(!isset($data['country_prices']) || !is_array($data['country_prices'])){
return false;
}
foreach ($data['country_prices'] as $k => $country_id) {
$cp = CountryPrice::updateOrCreate([
'country_id' => $country_id,
'product_id' => $this->model->id,
],
[
'c_price' => isset($data['c_price'][$country_id]) ? reFormatNumber($data['c_price'][$country_id]) : null,
'c_tax' => isset($data['c_tax'][$country_id]) ? reFormatNumber($data['c_tax'][$country_id]) : null,
'c_price_old' => isset($data['c_price_old'][$country_id]) ? reFormatNumber($data['c_price_old'][$country_id]) : null,
'c_currency' => isset($data['c_currency'][$country_id]) ? reFormatNumber($data['c_currency'][$country_id]) : null,
]);
}
return true;
}
public function copy($model)
{
$this->model = $model->replicate();
$this->model->name = "Kopie: ".$this->model->name;
$this->model->wp_number = null;
$this->model->save();
//categories
foreach ($model->categories as $category){
ProductCategory::create([
'product_id' => $this->model->id,
'category_id' => $category->category_id,
]);
}
//attributes
foreach ($model->attributes as $attribute){
ProductAttribute::create([
'product_id' => $this->model->id,
'attribute_id' => $attribute->attribute_id,
]);
}
//images
foreach ($model->images as $image){
$name = \App\Services\Slim::sanitizeFileName($image->original_name);
$name = uniqid() . '_' . $name;
//copy
$data = \Storage::disk('public')->copy(
'images/product/'.$image->product_id.'/'.$image->filename,
'images/product/'.$this->model->id.'/'.$name
);
ProductImage::create([
'product_id' => $this->model->id,
'filename' => $name,
'original_name' => $image->original_name,
'ext' => $image->ext,
'mine' => $image->mine,
'size' => $image->size
]);
}
return $this->model;
}
public function delete()
{
}
}

View file

@ -0,0 +1,107 @@
<?php
namespace App\Repositories;
use App\Models\PaymentMethod;
use App\Models\UserAccount;
use App\User;
use Illuminate\Support\Facades\Hash;
class UserRepository extends BaseRepository {
public function __construct(User $model)
{
$this->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 = User::create([
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$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'],
'data_protection' => now(),
]);
$this->model->account_id = $account->id;
$this->model->payment_methods = PaymentMethod::getDefaultAsArray();
$this->model->save();
return $this->model;
}
public function deleteUser(User $user)
{
if($user->account){
$user->account->delete();
}
$user->email = "delete".time();
$user->password = "delete".time();
$user->confirmed = 0;
$user->confirmation_code = "delete".time();
$user->confirmation_date = null;
$user->confirmation_code_to = null;
$user->confirmation_code_remider = 2;
$user->agreement = null;
$user->active = 0;
$user->remember_token = '';
$user->active_date = null;
$user->admin = 0;
$user->deleted_at = now();
$user->save();
return true;
}
}