Updates to 03-2025
This commit is contained in:
parent
6167273a48
commit
9b54eb0512
348 changed files with 34535 additions and 5774 deletions
|
|
@ -5,21 +5,24 @@ namespace App\Repositories;
|
|||
use Yard;
|
||||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
use App\Models\UserShop;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingOrderItem;
|
||||
use App\Services\CustomerPriority;
|
||||
use Illuminate\Support\Collection;
|
||||
use App\Models\ShoppingOrderMargin;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use App\Http\Controllers\Pay\PayController;
|
||||
|
||||
|
||||
|
||||
class CheckoutRepository {
|
||||
|
||||
private $payment_for;
|
||||
private $PromotionUser;
|
||||
private $UserShop;
|
||||
|
||||
private $is_for;
|
||||
private $session;
|
||||
private $instance;
|
||||
private $shopping_user;
|
||||
|
|
@ -38,6 +41,14 @@ class CheckoutRepository {
|
|||
{
|
||||
$this->payment_for = $payment_for;
|
||||
$this->PromotionUser = $PromotionUser;
|
||||
$this->is_for = 'pr';
|
||||
}
|
||||
|
||||
public function setUserShop($payment_for, UserShop $UserShop)
|
||||
{
|
||||
$this->payment_for = $payment_for;
|
||||
$this->UserShop = $UserShop;
|
||||
$this->is_for = 'shop';
|
||||
}
|
||||
|
||||
public function init($identifier, $data)
|
||||
|
|
@ -51,7 +62,7 @@ class CheckoutRepository {
|
|||
|
||||
$shopping_data = Yard::instance('shopping')->getYardExtra('shopping_data');
|
||||
$this->data['is_from'] = isset($shopping_data['is_from']) ? $shopping_data['is_from'] : 'shopping'; //shopping
|
||||
$this->data['is_from'] = isset($shopping_data['is_for']) ? $shopping_data['is_for'] : 'pr'; //promotion
|
||||
$this->data['is_for'] = isset($shopping_data['is_for']) ? $shopping_data['is_for'] : 'pr'; //promotion //us shop
|
||||
|
||||
$this->shopping_user = $this->makeShoppingUser($data);
|
||||
$this->shopping_order = $this->makeShoppingOrder($this->shopping_user);
|
||||
|
|
@ -94,7 +105,7 @@ class CheckoutRepository {
|
|||
$data['accepted_data'] = isset($data['accepted_data']) ? true : false;
|
||||
$data['billing_country_id'] = Shop::getShippingCountryCountryId($data['billing_state']);
|
||||
$data['shipping_country_id'] = $data['billing_country_id'];
|
||||
$data['member_id'] = $this->PromotionUser->user_id;
|
||||
$data['member_id'] = $this->is_for === 'shop' ? $this->UserShop->user_id : $this->PromotionUser->user_id; //pr
|
||||
|
||||
if(isset($data['shipping_state'])){
|
||||
$data['shipping_country_id'] = Shop::getShippingCountryCountryId($data['shipping_state']);
|
||||
|
|
@ -119,7 +130,8 @@ class CheckoutRepository {
|
|||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'auth_user_id' => $shopping_user->auth_user_id,
|
||||
'promotion_user_id' => $this->PromotionUser->id,
|
||||
'promotion_user_id' => $this->is_for === 'pr' ? $this->PromotionUser->id : null,
|
||||
'user_shop_id' => $this->is_for === 'shop' ? $this->UserShop->id : null,
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'payment_for' => $this->payment_for,
|
||||
'total' => Yard::instance('shopping')->total(2, '.', ''),
|
||||
|
|
@ -152,7 +164,7 @@ class CheckoutRepository {
|
|||
if(!$shopping_order){
|
||||
$shopping_order = ShoppingOrder::create($data);
|
||||
}
|
||||
//$this->makeOrderMargin($shopping_order);
|
||||
$this->makeOrderMargin($shopping_order);
|
||||
|
||||
$this->putPayments('shopping_order_id', $shopping_order->id);
|
||||
$items = Yard::instance('shopping')->getContentByOrder();
|
||||
|
|
@ -197,6 +209,43 @@ class CheckoutRepository {
|
|||
return $shopping_order;
|
||||
}
|
||||
|
||||
private function makeOrderMargin(ShoppingOrder $shopping_order)
|
||||
{
|
||||
if ($this->is_for === 'pr' || $this->is_for === 'shop' ) {
|
||||
|
||||
$userMargin = Shop::calculateUserShopMargins($this->UserShop, $this->PromotionUser);
|
||||
$data = [
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'user_id' => $shopping_order->shopping_user->member_id,
|
||||
'net_price' => $userMargin->yard_margin->net_price,
|
||||
'net_discount' => $userMargin->yard_margin->net_discount,
|
||||
'net_amount' => $userMargin->yard_margin->net_amount,
|
||||
'from_payment_credit' =>0,
|
||||
'from' => now(),
|
||||
'status' => $this->payment_for, //7 => 'from promotion', 8 => 'from shop',
|
||||
'content' => serialize($userMargin->yard_margin->toArray())
|
||||
];
|
||||
if($userMargin->yard_margin->net_partner_commission > 0){
|
||||
if(isset($shopping_order->auth_user->m_sponsor)){
|
||||
if($shopping_order->auth_user->user_sponsor && $shopping_order->auth_user->user_sponsor->isActiveAccount())
|
||||
$data['m_sponsor_id'] = $shopping_order->auth_user->m_sponsor;
|
||||
$data['net_partner_commission'] = $userMargin->yard_margin->net_partner_commission;
|
||||
}
|
||||
}
|
||||
$shopping_order_margin = false;
|
||||
if ($this->getPayments('shopping_order_margin_id')) {
|
||||
$shopping_order_margin = ShoppingOrderMargin::find($this->getPayments('shopping_order_margin_id'));
|
||||
if ($shopping_order_margin) {
|
||||
$shopping_order_margin->fill($data);
|
||||
$shopping_order_margin->save();}
|
||||
}
|
||||
if (!$shopping_order_margin) {
|
||||
$shopping_order_margin = ShoppingOrderMargin::create($data);
|
||||
}
|
||||
$this->putPayments('shopping_order_margin_id', $shopping_order_margin->id);
|
||||
}
|
||||
}
|
||||
|
||||
private function putPayments($key, $value){
|
||||
$content = $this->getContent();
|
||||
$content->put($key, $value);
|
||||
|
|
|
|||
|
|
@ -80,8 +80,10 @@ class ContractPDFRepository extends BaseRepository {
|
|||
$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));
|
||||
if($this->model->account->birthday){
|
||||
$pdf->SetXY($x2, $y);
|
||||
$pdf->Write(0, $this->convert($this->model->account->birthday));
|
||||
}
|
||||
|
||||
$y += $nl;
|
||||
$pdf->SetXY($x1, $y);
|
||||
|
|
|
|||
|
|
@ -83,31 +83,47 @@ class CreditRepository extends BaseRepository {
|
|||
return true;
|
||||
}
|
||||
|
||||
//beendet die Gutschrift
|
||||
private function finishUserCredit($user_credit){
|
||||
//next number
|
||||
Credit::makeNextCreditNumber();
|
||||
//mark as payed
|
||||
$ShoppingOrderMargins = UserMarign::getOrderFromPartnerCommissionByID($this->model->id);
|
||||
//Partner Provision
|
||||
$ShoppingOrderMargins = UserMarign::getPartnerCommissionItems($this->model->id, false);
|
||||
foreach($ShoppingOrderMargins as $ShoppingOrderMargin){
|
||||
$ShoppingOrderMargin->partner_commission_paid = true;
|
||||
$ShoppingOrderMargin->out_paid = true;
|
||||
$ShoppingOrderMargin->user_credit_id = $user_credit->id;
|
||||
$ShoppingOrderMargin->save();
|
||||
}
|
||||
|
||||
$UserCreditMargins = UserMarign::getUserCreditMarginByID($this->model->id);
|
||||
//Shop Provision
|
||||
$ShoppingOrderMargins = UserMarign::getShopCommissionItems($this->model->id, false);
|
||||
foreach($ShoppingOrderMargins as $ShoppingOrderMargin){
|
||||
$ShoppingOrderMargin->margin_paid = true;
|
||||
$ShoppingOrderMargin->out_paid = true;
|
||||
$ShoppingOrderMargin->user_credit_id = $user_credit->id;
|
||||
$ShoppingOrderMargin->save();
|
||||
}
|
||||
|
||||
//Hinzugefügte Provision
|
||||
$UserCreditMargins = UserMarign::getUserCreditMarginByUserID($this->model->id);
|
||||
foreach($UserCreditMargins as $UserCreditMargin){
|
||||
$UserCreditMargin->paid = true;
|
||||
$UserCreditMargin->paid = true; //wurde ausgezahlt
|
||||
$UserCreditMargin->user_credit_id = $user_credit->id;
|
||||
$UserCreditMargin->save();
|
||||
}
|
||||
}
|
||||
|
||||
//erstellt der Gutschrift
|
||||
private function makeUserCredit(){
|
||||
|
||||
$ret = new \stdClass();
|
||||
$ret->net = 0;
|
||||
$ret->margins = [];
|
||||
$ret->credits = [];
|
||||
$ShoppingOrderMargins = UserMarign::getOrderFromPartnerCommissionByID($this->model->id);
|
||||
|
||||
//Partner Provision
|
||||
$ShoppingOrderMargins = UserMarign::getPartnerCommissionItems($this->model->id, false);
|
||||
foreach($ShoppingOrderMargins as $ShoppingOrderMargin){
|
||||
$margin = new \stdClass();
|
||||
$margin->id = $ShoppingOrderMargin->id;
|
||||
|
|
@ -120,7 +136,22 @@ class CreditRepository extends BaseRepository {
|
|||
$ret->net += $ShoppingOrderMargin->net_partner_commission;
|
||||
}
|
||||
|
||||
$UserCreditMargins = UserMarign::getUserCreditMarginByID($this->model->id);
|
||||
//Shop Provision
|
||||
$ShoppingOrderMargins = UserMarign::getShopCommissionItems($this->model->id, false);
|
||||
foreach($ShoppingOrderMargins as $ShoppingOrderMargin){
|
||||
$margin = new \stdClass();
|
||||
$margin->id = $ShoppingOrderMargin->id;
|
||||
$margin->net = $ShoppingOrderMargin->net_discount;
|
||||
$margin->reference = $ShoppingOrderMargin->shopping_order->getLastShoppingPayment('reference');
|
||||
$margin->firstname = $ShoppingOrderMargin->shopping_order->shopping_user->billing_firstname;
|
||||
$margin->lastname = $ShoppingOrderMargin->shopping_order->shopping_user->billing_lastname;
|
||||
$margin->created_at = $ShoppingOrderMargin->shopping_order->created_at->format("d.m.Y");
|
||||
$ret->margins[] = $margin;
|
||||
$ret->net += $ShoppingOrderMargin->net_discount;
|
||||
}
|
||||
|
||||
//Hinzugefügte Provision
|
||||
$UserCreditMargins = UserMarign::getUserCreditMarginByUserID($this->model->id);
|
||||
foreach($UserCreditMargins as $UserCreditMargin){
|
||||
$credit = new \stdClass();
|
||||
$credit->id = $UserCreditMargin->id;
|
||||
|
|
@ -138,7 +169,7 @@ class CreditRepository extends BaseRepository {
|
|||
if($this->model->account){
|
||||
$ret->taxable = $this->model->account->taxable_sales == 2 ? false : true;
|
||||
if($ret->taxable){
|
||||
$ret->tax_rate = config('app.main_tax_number');
|
||||
$ret->tax_rate = config('app.main_tax_rate');
|
||||
$ret->total = round($ret->net * config('app.main_tax'), 2);
|
||||
$ret->tax = $ret->total - $ret->net;
|
||||
|
||||
|
|
@ -146,7 +177,6 @@ class CreditRepository extends BaseRepository {
|
|||
$ret->tax_rate = 0;
|
||||
$ret->total = $ret->net;
|
||||
$ret->tax = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,13 @@ namespace App\Repositories;
|
|||
|
||||
use PDF;
|
||||
use Storage;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\Attribute;
|
||||
use App\Services\Invoice;
|
||||
use App\Libraries\InvoicePDF;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\MyPDFMerger;
|
||||
use App\Services\UserService;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class InvoiceRepository extends BaseRepository {
|
||||
|
||||
|
|
@ -15,6 +19,9 @@ class InvoiceRepository extends BaseRepository {
|
|||
private $filename;
|
||||
private $dir;
|
||||
|
||||
private $delivery_dir;
|
||||
private $delivery_filename;
|
||||
|
||||
public function __construct(ShoppingOrder $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
|
|
@ -29,17 +36,28 @@ class InvoiceRepository extends BaseRepository {
|
|||
$this->invoice_number = Invoice::createInvoiceNumber($number, $this->invoice_date);
|
||||
$this->dir = Invoice::getInvoiceStorageDir($this->invoice_date);
|
||||
$this->filename = Invoice::makeInvoiceFilename($this->invoice_number);
|
||||
$this->delivery_dir = Invoice::getDeliveryStorageDir($this->invoice_date);
|
||||
$this->delivery_filename = Invoice::makeDeliveryFilename($this->invoice_number);
|
||||
|
||||
$this->makePDF();
|
||||
|
||||
$data_file = [
|
||||
$invoice_file = [
|
||||
'filename' => $this->filename,
|
||||
'dir' => $this->dir,
|
||||
'disk' => 'public',
|
||||
'invoice_number' => $this->invoice_number,
|
||||
'invoice_date' => $this->invoice_date,
|
||||
];
|
||||
$this->model->invoice = $data_file;
|
||||
|
||||
$delivery_file = [
|
||||
'filename' => $this->delivery_filename,
|
||||
'dir' => $this->delivery_dir,
|
||||
'disk' => 'public',
|
||||
'number' => $this->invoice_number,
|
||||
'date' => $this->invoice_date,
|
||||
];
|
||||
$this->model->invoice = $invoice_file;
|
||||
$this->model->delivery = $delivery_file;
|
||||
$this->model->invoice_number = $this->invoice_number;
|
||||
$this->model->save();
|
||||
Invoice::makeNextInvoiceNumber();
|
||||
|
|
@ -58,16 +76,29 @@ class InvoiceRepository extends BaseRepository {
|
|||
$this->dir = Invoice::getDir($this->model);
|
||||
$this->filename = Invoice::getFilename($this->model);
|
||||
|
||||
|
||||
$this->delivery_dir = Invoice::getDeliveryDir($this->model);
|
||||
$this->delivery_filename = Invoice::getDeliveryFilename($this->model);
|
||||
|
||||
$this->makePDF();
|
||||
|
||||
$data_file = [
|
||||
$invoice_file = [
|
||||
'filename' => $this->filename,
|
||||
'dir' => $this->dir,
|
||||
'disk' => 'public',
|
||||
'invoice_number' => $this->invoice_number,
|
||||
'invoice_date' => $this->invoice_date,
|
||||
];
|
||||
$this->model->invoice = $data_file;
|
||||
$delivery_file = [
|
||||
'filename' => $this->delivery_filename,
|
||||
'dir' => $this->delivery_dir,
|
||||
'disk' => 'public',
|
||||
'number' => $this->invoice_number,
|
||||
'date' => $this->invoice_date,
|
||||
];
|
||||
|
||||
$this->model->invoice = $invoice_file;
|
||||
$this->model->delivery = $delivery_file;
|
||||
$this->model->invoice_number = $this->invoice_number;
|
||||
$this->model->save();
|
||||
|
||||
|
|
@ -85,19 +116,123 @@ class InvoiceRepository extends BaseRepository {
|
|||
'invoice_date' => $this->invoice_date,
|
||||
'invoice_number' => $this->invoice_number,
|
||||
];
|
||||
$pdf = PDF::loadView('pdf.invoice', $data);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
|
||||
if($this->model->auth_user_id){
|
||||
UserService::checkUserTaxShippingCountry($this->model->auth_user, $this->model->country_id);
|
||||
$data = array_merge($data, UserService::getYardInfo());
|
||||
}
|
||||
|
||||
$data['delivery_items'] = $this->prepairForDelivery();
|
||||
|
||||
if(!Storage::disk('public')->exists( $this->dir )){
|
||||
Storage::disk('public')->makeDirectory($this->dir); //creates directory
|
||||
}
|
||||
if(!Storage::disk('public')->exists( $this->delivery_dir )){
|
||||
Storage::disk('public')->makeDirectory($this->delivery_dir); //creates directory
|
||||
}
|
||||
$path = Storage::disk('public')->getAdapter()->getPathPrefix();
|
||||
|
||||
$pdf->save($path.$this->dir.$this->filename);
|
||||
|
||||
$pdf_file = new InvoicePDF('pdf.invoice');
|
||||
$pdf_file->create($data, $this->filename, 'save', $path.$this->dir);
|
||||
$pdfMerger = new MyPDFMerger();
|
||||
$pdfMerger->addPDF($path.$this->dir.$this->filename);
|
||||
$file = $pdfMerger->myMerge('string', $this->filename, 'template_invoice_de');
|
||||
Storage::disk('public')->put($this->dir.$this->filename, $file);
|
||||
|
||||
$pdf_file = new InvoicePDF('pdf.delivery');
|
||||
$pdf_file->create($data, $this->delivery_filename, 'save', $path.$this->delivery_dir);
|
||||
$pdfMerger = new MyPDFMerger();
|
||||
$pdfMerger->addPDF($path.$this->delivery_dir.$this->delivery_filename);
|
||||
$file = $pdfMerger->myMerge('string', $this->delivery_filename, 'template_delivery_de');
|
||||
Storage::disk('public')->put($this->delivery_dir.$this->delivery_filename, $file);
|
||||
|
||||
}
|
||||
//sort white label products
|
||||
private function prepairForDelivery(){
|
||||
$shopping_order = $this->model;
|
||||
$wl_items = [];
|
||||
$items = [];
|
||||
$counter = 1;
|
||||
$count = 10000;
|
||||
foreach($shopping_order->shopping_order_items as $shopping_order_item){
|
||||
$labels = [];
|
||||
$sorter = 0;
|
||||
if($shopping_order_item->product->whitelabel){
|
||||
|
||||
//get white label default etikett (s)
|
||||
//ist ausschlaggebend für die etikettierung, ob 1 oder mehr etiketten
|
||||
if($shopping_order_item->product->whitelabel_images){
|
||||
foreach($shopping_order_item->product->whitelabel_images as $whitelabel_image){
|
||||
$labels[] = $whitelabel_image;
|
||||
}
|
||||
}
|
||||
//has white label user etikett
|
||||
if($shopping_order->auth_user){
|
||||
$whitelabel_product = $shopping_order->auth_user->whitelabel_products()->where('product_id', '=', $shopping_order_item->product->id)->first();
|
||||
if($whitelabel_product && $whitelabel_product->whitelabel_images){
|
||||
foreach($whitelabel_product->whitelabel_images as $whitelabel_image){
|
||||
if($whitelabel_image->attributes && is_array($whitelabel_image->attributes)){
|
||||
foreach($labels as $key => $label){
|
||||
foreach($whitelabel_image->attributes as $attribute){
|
||||
if(in_array($attribute, $label->attributes)){
|
||||
//found and overwrite
|
||||
$labels[$key] = $whitelabel_image;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($labels as $key=>$label){
|
||||
//label hat attribue
|
||||
$varinats = [];
|
||||
if($label->attributes && is_array($label->attributes)){
|
||||
foreach($label->attributes as $attribute){
|
||||
if($attribute = Attribute::find($attribute)){
|
||||
if(!isset($varinats[$attribute->value])){
|
||||
$temp = explode('#', $attribute->value);
|
||||
$sorter = $temp[1] > $sorter ? $temp[1] : $sorter;
|
||||
$label->varinat = [
|
||||
'key' => $attribute->value,
|
||||
'id' => $attribute->id,
|
||||
'vol' => (float) $temp[0],
|
||||
'size' => (float) $temp[1],
|
||||
'name' => $label->product_id ? 'Standard' : $attribute->name,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//sonst auf standard zurückgreifen
|
||||
if($shopping_order_item->product->attribute_variants){
|
||||
foreach($shopping_order_item->product->attribute_variants as $attribute_variant){
|
||||
if(!isset($varinats[$attribute_variant->attribute->value])){
|
||||
$temp = explode('#', $attribute_variant->attribute->value);
|
||||
$sorter = $temp[1] > $sorter ? $temp[1] : $sorter;
|
||||
$label->varinat = [
|
||||
'key' => $attribute_variant->attribute->value,
|
||||
'id' => $attribute_variant->attribute->id,
|
||||
'vol' => (float) $temp[0],
|
||||
'size' => (float) $temp[1],
|
||||
'name' => 'Standard',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//sorten of white label products
|
||||
$sorter = intval((float) $sorter * 100 + $counter++);
|
||||
$shopping_order_item->labels = $labels;
|
||||
$wl_items[$sorter] = $shopping_order_item;
|
||||
}else{
|
||||
$items[$count++] = $shopping_order_item;
|
||||
}
|
||||
}
|
||||
//kleine zuerst
|
||||
ksort($wl_items);
|
||||
return array_merge($wl_items, $items);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,12 +5,14 @@ namespace App\Repositories;
|
|||
|
||||
|
||||
use App\Models\CountryPrice;
|
||||
use App\Models\Attribute;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductAttribute;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\ProductImage;
|
||||
use App\Models\ProductIngredient;
|
||||
|
||||
|
||||
class ProductRepository extends BaseRepository {
|
||||
|
||||
|
||||
|
|
@ -29,10 +31,12 @@ class ProductRepository extends BaseRepository {
|
|||
$data['active'] = isset($data['active']) ? 1 : 0;
|
||||
$data['single_commission'] = isset($data['single_commission']) ? 1 : 0;
|
||||
$data['amount_commission'] = isset($data['amount_commission']) ? 1 : 0;
|
||||
$data['exclude_stats_sales'] = isset($data['exclude_stats_sales']) ? 1 : 0;
|
||||
$data['whitelabel'] = isset($data['whitelabel']) ? 1 : 0;
|
||||
$data['shipping_addon'] = isset($data['shipping_addon']) ? 1 : 0;
|
||||
$data['max_buy'] = isset($data['max_buy']) ? 1 : 0;
|
||||
$data['show_on'] = isset($data['show_on']) ? $data['show_on'] : null;
|
||||
|
||||
|
||||
if($data['id'] === "new"){
|
||||
$this->model = Product::create($data);
|
||||
}
|
||||
|
|
@ -42,9 +46,14 @@ class ProductRepository extends BaseRepository {
|
|||
$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->updateCategories(isset($data['categories']) ? $data['categories'] : []);
|
||||
$this->updateAttributes(isset($data['attributes']) ? $data['attributes'] : []);
|
||||
|
||||
$this->updateWLVariants(isset($data['whitelabel_variants']) ? $data['whitelabel_variants'] : []);
|
||||
$this->updateWLImageAttributs(isset($data['image_wl_attributes']) ? $data['image_wl_attributes'] : [] , isset($data['whitelabel_variants']) ? $data['whitelabel_variants'] : []);
|
||||
|
||||
$this->updateIngredients(isset($data['product_ingredients']) ? $data['product_ingredients'] : []);
|
||||
$this->updateCountryPrices($data);
|
||||
|
||||
|
||||
|
|
@ -103,15 +112,62 @@ class ProductRepository extends BaseRepository {
|
|||
//set attr
|
||||
if(is_array($data)){
|
||||
foreach ($data as $id) {
|
||||
$attribute = Attribute::findOrFail($id);
|
||||
ProductAttribute::create([
|
||||
'product_id' => $this->model->id,
|
||||
'attribute_id' => $id,
|
||||
'type_id' => $attribute->attribute_type_id,
|
||||
'attribute_id' => $attribute->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateWLVariants($data = array())
|
||||
{
|
||||
foreach ($this->model->attribute_variants as $variant) {
|
||||
if(($pos = array_search($variant->attribute_id, $data)) !== FALSE){
|
||||
unset($data[$pos]);
|
||||
}else{
|
||||
$variant->delete();
|
||||
}
|
||||
}
|
||||
//set attr
|
||||
if(is_array($data)){
|
||||
foreach ($data as $id) {
|
||||
$attribute = Attribute::findOrFail($id);
|
||||
ProductAttribute::create([
|
||||
'product_id' => $this->model->id,
|
||||
'type_id' => $attribute->attribute_type_id,
|
||||
'attribute_id' => $attribute->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateWLImageAttributs($attributes = [], $variants = [])
|
||||
{
|
||||
//abgleich der attributes gegen die variants
|
||||
foreach ($attributes as $image => $value) {
|
||||
foreach ($value as $k => $val) {
|
||||
if(!is_array($variants) || !in_array($val, $variants)){
|
||||
unset($attributes[$image][$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($this->model->whitelabel_images as $image) {
|
||||
$image->update([
|
||||
'attributes' => isset($attributes[$image->id]) ? $attributes[$image->id] : NULL,
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function updateCountryPrices($data)
|
||||
{
|
||||
if(!isset($data['country_prices']) || !is_array($data['country_prices'])){
|
||||
|
|
@ -128,7 +184,6 @@ class ProductRepository extends BaseRepository {
|
|||
'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,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -156,6 +211,7 @@ class ProductRepository extends BaseRepository {
|
|||
foreach ($model->attributes as $attribute){
|
||||
ProductAttribute::create([
|
||||
'product_id' => $this->model->id,
|
||||
'type_id' => $this->model->attribute_type_id,
|
||||
'attribute_id' => $attribute->attribute_id,
|
||||
]);
|
||||
}
|
||||
|
|
@ -182,30 +238,26 @@ class ProductRepository extends BaseRepository {
|
|||
'images/product/'.$this->model->id.'/'.$name
|
||||
);
|
||||
|
||||
|
||||
ProductImage::create([
|
||||
'product_id' => $this->model->id,
|
||||
'type' => $image->type,
|
||||
'filename' => $name,
|
||||
'original_name' => $image->original_name,
|
||||
'ext' => $image->ext,
|
||||
'mine' => $image->mine,
|
||||
'size' => $image->size
|
||||
'size' => $image->size,
|
||||
'attributes' => $image->attributes
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -2,13 +2,17 @@
|
|||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\PaymentMethod;
|
||||
use App\Models\UserAccount;
|
||||
use Str;
|
||||
use App\User;
|
||||
use stdClass;
|
||||
use Validator;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\UserAccount;
|
||||
use App\Models\UserRegister;
|
||||
use App\Models\PaymentMethod;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
|
||||
|
||||
class UserRepository extends BaseRepository {
|
||||
|
||||
|
||||
|
|
@ -30,8 +34,6 @@ class UserRepository extends BaseRepository {
|
|||
]);
|
||||
$this->model->payment_methods = PaymentMethod::getDefaultAsArray();
|
||||
$this->model->save();
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
$this->model = $this->getById($data['user_id']);
|
||||
|
|
@ -47,8 +49,9 @@ class UserRepository extends BaseRepository {
|
|||
|
||||
$data['birthday_day'] = isset($data['birthday_day']) ? $data['birthday_day'] : 1;
|
||||
$data['birthday_month'] = isset($data['birthday_month']) ? $data['birthday_month'] : 1;
|
||||
$data['birthday_year'] = isset($data['birthday_year']) ? $data['birthday_year'] : 1970;
|
||||
$data['birthday'] = $data['birthday_day'].".".$data['birthday_month'].".".$data['birthday_year'];
|
||||
$data['birthday_year'] = isset($data['birthday_year']) ? $data['birthday_year'] : 1900;
|
||||
$data['birthday'] = $data['birthday_day'].".".$data['birthday_month'].".".$data['birthday_year'];
|
||||
$data['birthday'] = $data['birthday'] == "1.1.1900" ? null : $data['birthday'];
|
||||
|
||||
$account->fill($data)->save();
|
||||
|
||||
|
|
@ -60,29 +63,80 @@ class UserRepository extends BaseRepository {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function create($data){
|
||||
public function createUserRegister($data){
|
||||
|
||||
$this->model = User::create([
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
$obj = new stdClass();
|
||||
|
||||
$obj->email = $data['email'];
|
||||
$obj->password = Hash::make($data['password']);
|
||||
$obj->m_salutation = $data['salutation'];
|
||||
$obj->m_first_name = $data['first_name'];
|
||||
$obj->m_last_name = $data['last_name'];
|
||||
$obj->salutation = $data['salutation'];
|
||||
$obj->first_name = $data['first_name'];
|
||||
$obj->last_name = $data['last_name'];
|
||||
$obj->data_protection = now()->toDateTimeString();
|
||||
|
||||
$obj->confirmation_code_to = date('Y-m-d H:i:s', strtotime('+1 week'));
|
||||
$obj->confirmation_code_remider = 0;
|
||||
$obj->m_sponsor = config('app.main_user_id');
|
||||
if(isset($data['from_member_id'])){
|
||||
$obj->m_sponsor = (int) str_replace('gs', '', $data['from_member_id']) - config('main.add_number_id');
|
||||
}
|
||||
$confirmation_code = UserService::createConfirmationCode();
|
||||
$obj->confirmation_code = $confirmation_code;
|
||||
UserRegister::create([
|
||||
'identifier' => $data['email'],
|
||||
'instance' => $confirmation_code,
|
||||
'content' => $obj
|
||||
]);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function clearUserRegister(){
|
||||
$cleartime = date('Y-m-d H:i:s', strtotime('-1 day')); //gestern -24h
|
||||
UserRegister::where('created_at', '<', $cleartime)->delete();
|
||||
}
|
||||
|
||||
public function create($UserRegister){
|
||||
|
||||
|
||||
$userObj = $UserRegister->content;
|
||||
|
||||
$user = User::create([
|
||||
'email' => $userObj->email,
|
||||
'password' =>$userObj->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(),
|
||||
'm_salutation' => $userObj->salutation,
|
||||
'm_first_name' => $userObj->first_name,
|
||||
'm_last_name' => $userObj->last_name,
|
||||
'salutation' => $userObj->salutation,
|
||||
'first_name' => $userObj->first_name,
|
||||
'last_name' => $userObj->last_name,
|
||||
'data_protection' => $userObj->data_protection,
|
||||
]);
|
||||
$user->confirmed = 1;
|
||||
$user->confirmation_code = null;
|
||||
$user->confirmation_code_to = null;
|
||||
$user->confirmation_code_remider = 0;
|
||||
$user->confirmation_date = now();
|
||||
$user->lang = !empty(\App::getLocale()) ? \App::getLocale() : "de";
|
||||
$user->m_sponsor = $userObj->m_sponsor;
|
||||
|
||||
$this->model->account_id = $account->id;
|
||||
$this->model->payment_methods = PaymentMethod::getDefaultAsArray();
|
||||
$this->model->save();
|
||||
$user->account_id = $account->id;
|
||||
$user->payment_methods = PaymentMethod::getDefaultAsArray();
|
||||
|
||||
$user->save();
|
||||
|
||||
$user = User::find($user->id);
|
||||
|
||||
return $this->model;
|
||||
//clear
|
||||
$identifier = $UserRegister->identifier;
|
||||
UserRegister::where('identifier', $identifier)->delete();
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function deleteUser(User $user)
|
||||
|
|
@ -108,5 +162,119 @@ class UserRepository extends BaseRepository {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function reverse_charge_validate($data, $user, $route){
|
||||
|
||||
if(isset($data['action']) && $data['action'] == 'reverse_charge_validate'){
|
||||
$rules = array(
|
||||
'tax_identification_number' => 'required',
|
||||
);
|
||||
$validator = Validator::make($data, $rules);
|
||||
if ($validator->fails()) {
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return redirect($route)->withErrors($validator)->withInput($data);
|
||||
}
|
||||
$ret = $this->reverse_charge_activate($data, $user);
|
||||
if($ret === 'error'){
|
||||
$validator = Validator::make($data, []);
|
||||
$validator->errors()->add('tax_identification_number_validated', __('msg.VATID_could_not_be_validated'));
|
||||
$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', */
|
||||
$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_code = $countryCode;
|
||||
$user->account->reverse_charge_valid = now();
|
||||
$user->account->save();
|
||||
return 'valid';
|
||||
} else {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
71
app/Repositories/UserShopRepository.php
Normal file
71
app/Repositories/UserShopRepository.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\User;
|
||||
use App\Services\Util;
|
||||
use App\Models\UserShop;
|
||||
use App\Models\PromotionUserProduct;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\PromotionAdminProduct;
|
||||
|
||||
class UserShopRepository extends BaseRepository {
|
||||
|
||||
|
||||
public function __construct(UserShop $model){
|
||||
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function update($id, $data)
|
||||
{
|
||||
|
||||
$data['active'] = isset($data['active']) ? 1 : 0;
|
||||
$data['pick_up'] = isset($data['pick_up']) ? 1 : 0;
|
||||
$data['url'] = Util::sanitize($data['user_shop_url'], true, false, true, true);
|
||||
|
||||
$this->model = $this->getById($id);
|
||||
$this->model->fill($data);
|
||||
$this->model->save();
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function create(User $user){
|
||||
|
||||
$user_name = $user->getFullName(false);
|
||||
$url = Util::sanitize($user_name, true, false, true, true);
|
||||
$url = $this->makeUniqueURL($url);
|
||||
UserShop::create([
|
||||
'user_id' => $user->id,
|
||||
'url' => $url,
|
||||
'name' => __('shop.greetings')." ".$user_name,
|
||||
'description' => __('shop.default_description'),
|
||||
'about_you' => $user->account->about_you,
|
||||
'user_address' => Auth::user()->getFullAddress()."\n".__('shop.default_user_open'),
|
||||
'pick_up' => false,
|
||||
'active' => true,
|
||||
'active_date' => now(),
|
||||
|
||||
]);
|
||||
return User::find($user->id);
|
||||
}
|
||||
|
||||
public function makeUniqueURL($url){
|
||||
|
||||
$bool = true;
|
||||
$count = 1;
|
||||
$unique_url = $url;
|
||||
while($bool){
|
||||
if(UserShop::where('url', $unique_url)->count()){
|
||||
$unique_url = $url."_".$count;
|
||||
$count ++;
|
||||
}else{
|
||||
$bool = false;
|
||||
}
|
||||
}
|
||||
return $unique_url;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue