diff --git a/app/Http/Controllers/ModalController.php b/app/Http/Controllers/ModalController.php index 8ec5c9f..ccf72a6 100644 --- a/app/Http/Controllers/ModalController.php +++ b/app/Http/Controllers/ModalController.php @@ -59,13 +59,12 @@ class ModalController extends Controller } if($data['action'] === 'shop-user-order-detail'){ - $user = \Auth::user(); $shopping_order = ShoppingOrder::findOrFail($data['id']); - if($shopping_order->member_id !== $user->id){ + if(!$user->isAdmin() || $shopping_order->member_id !== $user->id){ abort(404); } - $isAdmin = false; + $isAdmin = false ; $ret = view("user.shop.sales.modal_api_order_detail", compact('shopping_order', 'isAdmin', 'data'))->render(); } diff --git a/app/Http/Controllers/User/ShopApiController.php b/app/Http/Controllers/User/ShopApiController.php index bfb1cd7..cc010d1 100644 --- a/app/Http/Controllers/User/ShopApiController.php +++ b/app/Http/Controllers/User/ShopApiController.php @@ -6,13 +6,12 @@ use Request; use App\User; use App\Services\Payment; use App\Models\ShoppingOrder; -use App\Services\UserService; -use App\Models\ShippingCountry; use App\Http\Controllers\Controller; -use Illuminate\Support\Facades\Auth; use App\Repositories\ShopApiRepository; + + class ShopApiController extends Controller { @@ -44,12 +43,6 @@ class ShopApiController extends Controller switch($data['user_shop_api_orders_action']){ case 'order': $shopApiOrderCart = $this->shopApiRepository->order($data); - - /*$user = User::find(Auth::user()->id); - $shipping_country = ShippingCountry::whereCountryId($user->account->country_id)->first(); - UserService::checkUserTaxShippingCountry($user, $shipping_country->id);*/ - - //card_info = UserService::getYardInfo(); return view('user.shop.sales.api_order_list', compact('shopApiOrderCart', 'data')); break; case 'remove': @@ -66,15 +59,8 @@ class ShopApiController extends Controller public function checkout(){ - $data = Request::all(); - $shopApiOrderCart = $this->shopApiRepository->checkout($data); - //TODO store in ShopApiOrderCart - //TO checkout - dd($shopApiOrderCart); - - - return redirect(route('user_shop_api_orders')); - + $data = Request::all(); + return $this->shopApiRepository->checkout($data); } @@ -130,6 +116,12 @@ class ShopApiController extends Controller data-route="'.route('modal_load').'">'; }) ->addColumn('api_status', function (ShoppingOrder $ShoppingOrder) { + if($ShoppingOrder->api_status === 2){ + $shopping_oder_id = isset($ShoppingOrder->api_notice['shopping_order_id']) ? $ShoppingOrder->api_notice['shopping_order_id'] : null; + if($shopping_oder_id){ + return ' '.$shopping_oder_id.''; + } + } return ''.$ShoppingOrder->getAPIStatusType().''; }) ->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) { @@ -161,7 +153,7 @@ class ShopApiController extends Controller return ''.$ShoppingOrder->getShippedType().' '; }) - + ->orderColumn('payment_for', 'payment_for $1') ->orderColumn('id', 'id $1') diff --git a/app/Http/Controllers/Web/CheckoutController.php b/app/Http/Controllers/Web/CheckoutController.php index 276da26..29da08a 100755 --- a/app/Http/Controllers/Web/CheckoutController.php +++ b/app/Http/Controllers/Web/CheckoutController.php @@ -3,26 +3,27 @@ namespace App\Http\Controllers\Web; -use App\Http\Controllers\Controller; -use App\Http\Controllers\Pay\PayoneController; -use App\Models\Homeparty; -use App\Models\PaymentMethod; -use App\Models\PaymentTransaction; -use App\Models\ShippingCountry; -use App\Models\ShoppingOrder; -use App\Models\ShoppingOrderItem; -use App\Models\ShoppingPayment; -use App\Models\ShoppingUser; -use App\Services\CustomerPriority; -use App\Services\Payment; -use App\Services\Shop; -use App\User; -use Illuminate\Session\SessionManager; -use Illuminate\Support\Collection; -use Validator; -use App\Services\Util; use Yard; use Request; +use App\User; +use Validator; +use App\Services\Shop; +use App\Services\Util; +use App\Models\Homeparty; +use App\Services\Payment; +use App\Models\ShoppingUser; +use App\Models\PaymentMethod; +use App\Models\ShoppingOrder; +use App\Models\ShippingCountry; +use App\Models\ShoppingPayment; +use App\Models\ShoppingOrderItem; +use App\Models\PaymentTransaction; +use App\Services\CustomerPriority; +use Illuminate\Support\Collection; +use App\Http\Controllers\Controller; +use App\Models\ShoppingCollectOrder; +use Illuminate\Session\SessionManager; +use App\Http\Controllers\Pay\PayoneController; class CheckoutController extends Controller { @@ -67,7 +68,7 @@ class CheckoutController extends Controller if(!$this->getPayments('shopping_user_id')){ if($shopping_data && $is_from !== 'shopping'){ - //can wizard membership user_order + //can wizard membership user_order //$shopping_user_id = isset($shopping_data['shopping_user_id']) ? $shopping_data['shopping_user_id'] : false; $shopping_user = $this->shoppingUserAuthData($is_from, $is_for, $shopping_data); $shopping_user->save(); @@ -177,6 +178,7 @@ class CheckoutController extends Controller $shopping_user->is_for = $is_for; $shopping_user->is_from = $is_from; $shopping_user->homeparty_id = isset($data['homeparty_id']) ? $data['homeparty_id'] : null; + $shopping_user->shopping_collect_order_id = isset($data['shopping_collect_order_id']) ? $data['shopping_collect_order_id'] : null; //Lieferadresse if($is_from === 'user_order'){ @@ -508,6 +510,30 @@ class CheckoutController extends Controller 'txaction' => 'prev', 'mode' => Util::getUserShoppingMode(), ]; + }elseif($shopping_user->is_from === 'collection'){ + //get data + $ShoppingCollectOrder = ShoppingCollectOrder::find($shopping_user->shopping_collect_order_id); + //set Data! + $total = Yard::instance('shopping')->total(2, '.', ''); //ek_price + $data = [ + 'shopping_user_id' => $shopping_user->id, + 'auth_user_id' => $shopping_user->auth_user_id, + 'country_id' => Yard::instance('shopping')->getShippingCountryId(), + 'user_shop_id' => $user_shop->id, + 'payment_for' => $shopping_user->getOrderPaymentFor(), + 'total' => $total, + 'subtotal' => $ShoppingCollectOrder->price_total_net, + 'shipping' => 0, + 'shipping_net' => 0, + 'subtotal_ws' => $ShoppingCollectOrder->price_total_net, + 'tax' => $ShoppingCollectOrder->tax_total, + 'tax_split' => $ShoppingCollectOrder->tax_split, + 'total_shipping' => Yard::instance('shopping')->totalWithShipping(2, '.', ''), + 'points' => $ShoppingCollectOrder->points, + 'weight' => 0, + 'txaction' => 'prev', + 'mode' => Util::getUserShoppingMode(), + ]; }else{ $data = [ 'shopping_user_id' => $shopping_user->id, @@ -539,6 +565,10 @@ class CheckoutController extends Controller } if(!$shopping_order){ $shopping_order = ShoppingOrder::create($data); + if($shopping_user->is_from === 'collection' && $ShoppingCollectOrder){ + $ShoppingCollectOrder->shopping_order_id = $shopping_order->id; + $ShoppingCollectOrder->save(); + } } $this->putPayments('shopping_order_id', $shopping_order->id); @@ -567,6 +597,10 @@ class CheckoutController extends Controller $data['homeparty_id'] = (int) $shopping_user->homeparty_id; $data['product_id'] = null; } + if($shopping_user->is_from === 'collection'){ + $data['shopping_collect_order_id'] = (int) $shopping_user->shopping_collect_order_id; + $data['product_id'] = null; + } $model->fill($data)->save(); return false; } @@ -597,14 +631,21 @@ class CheckoutController extends Controller if($shopping_user->is_from === 'homeparty'){ $data['homeparty_id'] = (int) $shopping_user->homeparty_id; + $data['price_vk_net'] = 0; + $data['product_id'] = null; + } + if($shopping_user->is_from === 'collection'){ + $data['price_vk_net'] = 0; + $data['shopping_collect_order_id'] = (int) $shopping_user->shopping_collect_order_id; $data['product_id'] = null; } - $shopping_order_item = ShoppingOrderItem::create($data); } } if($shopping_user->is_from === 'homeparty'){ $shopping_order->makeHomepartyTaxSplit(); + }elseif($shopping_user->is_from === 'collection'){ + //is set on create / filll. }else{ $shopping_order->makeTaxSplit(); } diff --git a/app/Models/ShoppingCollectOrder.php b/app/Models/ShoppingCollectOrder.php new file mode 100644 index 0000000..8ec5715 --- /dev/null +++ b/app/Models/ShoppingCollectOrder.php @@ -0,0 +1,137 @@ + 'int', + 'shopping_order_id' => 'int', + 'shipping' => 'float', + 'shipping_net' => 'float', + 'shipping_tax' => 'float', + 'price_total_net' => 'float', + 'price_total' => 'float', + 'tax_total' => 'float', + 'qty_total' => 'int', + 'points' => 'int', + 'status' => 'int', + 'tax_split' => 'array', + 'orders' => AsArrayObject::class, + 'shop_items' => AsArrayObject::class, + ]; + + protected $fillable = [ + 'user_id', + 'shopping_order_id', + //'identifier', + 'shipping', + 'shipping_net', + 'shipping_tax', + 'price_total_net', + 'price_total', + 'tax_total', + 'qty_total', + 'points', + 'tax_split', + 'orders', + 'shop_items', + 'status' + ]; + + public static $statusTypes = [ + 0 => '', + 1 => 'store / pre', + 2 => 'order', + ]; + + public function shopping_order() + { + return $this->belongsTo(ShoppingOrder::class); + } + + public function user() + { + return $this->belongsTo(User::class); + } + + public function addTaxToSplit($tax_rate, $add_tax) + { + $tax_split = $this->tax_split; + $tax_split[$tax_rate] = isset($tax_split[$tax_rate]) ? round($tax_split[$tax_rate] += $add_tax, 2) : $add_tax; + $this->tax_split = $tax_split; + } + + public function addShopItem($shop_item_id, $shop_item) + { + $this->shop_items[$shop_item_id] = $shop_item; + + } + + public function addOrder($order) + { + $this->orders[] = $order; + } + + public function initShoppingOrder($order) + { + $order['shopping_order'] = ShoppingOrder::findOrFail($order['order_id']); + return $order; + } +} diff --git a/app/Models/ShoppingOrder.php b/app/Models/ShoppingOrder.php index a78034e..31d220b 100644 --- a/app/Models/ShoppingOrder.php +++ b/app/Models/ShoppingOrder.php @@ -91,6 +91,9 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserSalesVolume[] $user_sales_volume * @property-read int|null $user_sales_volume_count * @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereTaxSplit($value) + * @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereApiNotice($value) + * @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereApiStatus($value) + * @property-read \App\Models\ShoppingCollectOrder|null $shopping_collect_order */ class ShoppingOrder extends Model { @@ -148,7 +151,6 @@ class ShoppingOrder extends Model 10 => 'cancel' ]; - public static $apiStatusTypes = [ 0 => 'offen', 1 => 'offen / pre', @@ -178,6 +180,7 @@ class ShoppingOrder extends Model 5 => 'Homeparty', 6 => 'Shop', 7 => 'extern', + 8 => 'Sammelbestellung', 10 => '', ]; @@ -242,6 +245,10 @@ class ShoppingOrder extends Model public function user_invoice(){ return $this->hasOne('App\Models\UserInvoice', 'shopping_order_id', ''); } + + public function shopping_collect_order(){ + return $this->hasOne('App\Models\ShoppingCollectOrder', 'shopping_order_id', ''); + } public function shopping_order_items(){ return $this->hasMany('App\Models\ShoppingOrderItem', 'shopping_order_id'); diff --git a/app/Models/ShoppingOrderItem.php b/app/Models/ShoppingOrderItem.php index 388b04d..173e7f3 100644 --- a/app/Models/ShoppingOrderItem.php +++ b/app/Models/ShoppingOrderItem.php @@ -56,6 +56,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem wherePoints($value) * @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem wherePriceVkNet($value) * @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem whereTax($value) + * @property int|null $shopping_collect_order_id + * @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem whereShoppingCollectOrderId($value) */ class ShoppingOrderItem extends Model { @@ -69,6 +71,7 @@ class ShoppingOrderItem extends Model 'row_id', 'product_id', 'homeparty_id', + 'shopping_collect_order_id', 'comp', 'qty', 'price', diff --git a/app/Models/ShoppingUser.php b/app/Models/ShoppingUser.php index 78dba8d..a2d7e64 100644 --- a/app/Models/ShoppingUser.php +++ b/app/Models/ShoppingUser.php @@ -163,6 +163,7 @@ class ShoppingUser extends Model 'is_from', 'shopping_user_id', 'homeparty_id', + 'shopping_collect_order_id', 'wp_order_number', 'wp_order_date', ]; @@ -263,6 +264,8 @@ class ShoppingUser extends Model return 6; case 'extern': return 7; + case 'collection': + return 8; } return 0; } diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index 1580939..8c5d5b9 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -133,13 +133,14 @@ class InvoiceRepository extends BaseRepository { $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_invoice_de'); - Storage::disk('public')->put($this->delivery_dir.$this->delivery_filename, $file); + if(!$this->model->shopping_collect_order){ + $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_invoice_de'); + Storage::disk('public')->put($this->delivery_dir.$this->delivery_filename, $file); + } } public function userSalesVolume() diff --git a/app/Repositories/ShopApiRepository.php b/app/Repositories/ShopApiRepository.php index add6d76..450b7d2 100644 --- a/app/Repositories/ShopApiRepository.php +++ b/app/Repositories/ShopApiRepository.php @@ -4,6 +4,16 @@ namespace App\Repositories; use App\Models\ShoppingOrder; use App\Services\ShopApiOrderCart; +use App\Services\UserService; +use App\Services\Util; +use App\Models\UserHistory; +use App\Models\ShippingCountry; +use App\Models\ShoppingInstance; +use Auth; +use Yard; +use App\User; + + class ShopApiRepository extends BaseRepository { @@ -34,12 +44,62 @@ class ShopApiRepository extends BaseRepository { return true; } - public function checkout($data){ + + public function checkout($data) + { + $user = User::find(Auth::user()->id); + $shopApiOrderCart = $this->performCheckout($data); + $time = time(); + $date = date('d.m.Y H:i:s', $time); + Yard::instance('shopping')->destroy(); + $cartItem = Yard::instance('shopping')->add($shopApiOrderCart->id, 'Sammelbestellung Extern '.$date, 1, $shopApiOrderCart->price_total, false, false, ['image' => "", 'slug' => $time, 'weight' => 0]); + Yard::setTax($cartItem->rowId, 0); + do { + $identifier = Util::getToken(); + } while( ShoppingInstance::where('identifier', $identifier)->count() ); + + $shipping_country = ShippingCountry::whereCountryId($user->account->country_id)->first(); + UserService::checkUserTaxShippingCountry($user, $shipping_country->id); + + $data = []; + $data['is_from'] = 'collection'; + + $data['shop_price'] = $shopApiOrderCart->price_total; + $data['shop_price_net'] = $shopApiOrderCart->price_total_net; + $data['shop_price_tax'] = $shopApiOrderCart->tax_total; + $data['user_tax_free'] = false; + $data['shopping_collect_order_id'] = $shopApiOrderCart->id; + $data['is_for'] = 'co'; //colection + $data['user_price_infos'] = UserService::getYardInfo(); + + ShoppingInstance::create([ + 'identifier' => $identifier, + 'user_shop_id' => 1, //is first faker shop for nuy intern + 'auth_user_id' => $user->id, + 'payment' => 2, //Berater Shop + 'subdomain' => url('/'), + 'country_id' => Yard::instance('shopping')->getShippingCountryId(), + 'shopping_data' => $data, + 'back' => route('user_shop_api_orders'), + + ]); + + Yard::instance('shopping')->store($identifier); + + $path = route('checkout.checkout_card', ['identifier'=>$identifier]); + UserHistory::create(['user_id' => $user->id, 'action'=>'payment_collection', 'status'=>1, 'referenz'=>$shopApiOrderCart->id, 'identifier'=>$identifier]); + //$path = str_replace('http', 'https', $path); + return redirect()->secure($path); + } + + + private function performCheckout($data){ $this->shopApiOrderCart = new ShopApiOrderCart(); $this->performOrderCheckoutList($data, 1); return $this->shopApiOrderCart; } + private function performActionList($data, $status){ if(isset($data['api_action_list'])){ foreach($data['api_action_list'] as $orderItemId=>$v){ diff --git a/app/Services/Payment.php b/app/Services/Payment.php index 6579aa3..706c75b 100644 --- a/app/Services/Payment.php +++ b/app/Services/Payment.php @@ -6,6 +6,7 @@ use App\User; use App\Mail\MailCheckout; use App\Models\ShoppingOrder; use App\Models\ShoppingPayment; +use App\Services\ShopApiOrderCart; use Illuminate\Support\Facades\Mail; use App\Repositories\InvoiceRepository; @@ -134,6 +135,12 @@ class Payment $shopping_order->homeparty->completed = 1; $shopping_order->homeparty->save(); } + + if($shopping_order->shopping_collect_order){ + $shopping_order->setUserHistoryValue(['status' => 9]); + ShopApiOrderCart::finishOrder($shopping_order->shopping_collect_order); + } + //make Invoice and $invoice_repo = new InvoiceRepository($shopping_order); diff --git a/app/Services/ShopApiOrderCart.php b/app/Services/ShopApiOrderCart.php index e038f77..e93783b 100644 --- a/app/Services/ShopApiOrderCart.php +++ b/app/Services/ShopApiOrderCart.php @@ -1,39 +1,31 @@ shipping = 0; - $this->shipping_net = 0; - $this->shipping_tax = 0; - $this->points_total = 0; - $this->price_total_net = 0; - $this->price_total = 0; - $this->tax_total = 0; - $this->tax_split = []; - $this->qty_total = 0; + $this->shoppingCollectOrder = new ShoppingCollectOrder(); + $this->shoppingCollectOrder->shipping = 0; + $this->shoppingCollectOrder->shipping_net = 0; + $this->shoppingCollectOrder->shipping_tax = 0; + $this->shoppingCollectOrder->points = 0; + $this->shoppingCollectOrder->price_total_net = 0; + $this->shoppingCollectOrder->price_total = 0; + $this->shoppingCollectOrder->tax_total = 0; + $this->shoppingCollectOrder->qty_total = 0; - $this->shop_items = []; + $this->shoppingCollectOrder->tax_split = []; + $this->shoppingCollectOrder->orders = []; + $this->shoppingCollectOrder->shop_items = []; } @@ -46,8 +38,8 @@ class ShopApiOrderCart $order->shipping_address = $this->setOrderAdress('shipping', $shopping_order->shopping_user); $order->shopping_order = $shopping_order; - $this->shipping += $shopping_order->shipping; - $this->shipping_net += $shopping_order->shipping_net; + $this->shoppingCollectOrder->shipping += $shopping_order->shipping; + $this->shoppingCollectOrder->shipping_net += $shopping_order->shipping_net; foreach ($shopping_order->shopping_order_items as $item){ @@ -59,65 +51,67 @@ class ShopApiOrderCart $shop_item_id = $item->product->id.'-'.$item->price; //set to item - if(isset($this->shop_items[$shop_item_id])){ - $shop_item = $this->shop_items[$shop_item_id]; - $shop_item->user_price_total_net += $user_price_net_qty; - $shop_item->user_tax_total += $user_tax_qty; - $shop_item->points_total += ($item->points * $item->qty); - $shop_item->qty += $item->qty; + if(isset($this->shoppingCollectOrder->shop_items[$shop_item_id])){ + $shop_item = $this->shoppingCollectOrder->shop_items[$shop_item_id]; + if ($shop_item instanceof stdClass) { + $shop_item->user_price_total_net += $user_price_net_qty; + $shop_item->user_tax_total += $user_tax_qty; + $shop_item->points_total += ($item->points * $item->qty); + $shop_item->qty += $item->qty; + } }else{ $shop_item = new stdClass(); - $shop_item->pid = $item->product->id; + $shop_item->pid = $item->product->id; - $shop_item->article = $item->product->wp_number; - $shop_item->number = $item->product->number; - $shop_item->name = $item->product->name; - $shop_item->qty = $item->qty; + $shop_item->article = $item->product->wp_number; + $shop_item->number = $item->product->number; + $shop_item->name = $item->product->name; + $shop_item->qty = $item->qty; - $shop_item->tax_rate = $tax_rate; - $shop_item->points = $item->points; - $shop_item->user_price_net = $user_price_net; - $shop_item->user_price_total_net = $user_price_net_qty; - $shop_item->user_tax = $user_tax; - $shop_item->user_tax_total = $user_tax_qty; - $shop_item->points_total = ($item->points * $item->qty); + $shop_item->tax_rate = $tax_rate; + $shop_item->points = $item->points; + $shop_item->user_price_net = $user_price_net; + $shop_item->user_price_total_net = $user_price_net_qty; + $shop_item->user_tax = $user_tax; + $shop_item->user_tax_total = $user_tax_qty; + $shop_item->points_total = ($item->points * $item->qty); } //only for tax split / tax and price on calculate function - $tax = isset($this->tax_split[$tax_rate]) ? $this->tax_split[$tax_rate] : 0; - $tax += $user_tax_qty; - $this->tax_split[$tax_rate] = $tax; - $this->tax_total += $user_tax_qty; + $this->shoppingCollectOrder->addTaxToSplit($tax_rate, $user_tax_qty); + $this->shoppingCollectOrder->tax_total += $user_tax_qty; + $this->shoppingCollectOrder->price_total_net += $user_price_net_qty; + $this->shoppingCollectOrder->points += ($item->points * $item->qty); + $this->shoppingCollectOrder->qty_total += $item->qty; - $this->price_total_net += $user_price_net_qty; - $this->points_total += ($item->points * $item->qty); - $this->qty_total += $item->qty; - - $this->shop_items[$shop_item_id] = $shop_item; + $this->shoppingCollectOrder->addShopItem($shop_item_id, $shop_item); } - $this->orders[] = $order; + $this->shoppingCollectOrder->addOrder($order); } public function calculate(){ - $this->shipping_tax = round($this->shipping - $this->shipping_net, 2); - $this->tax_total += $this->shipping_tax; + $this->shoppingCollectOrder->shipping_tax = round($this->shoppingCollectOrder->shipping - $this->shoppingCollectOrder->shipping_net, 2); + $this->shoppingCollectOrder->tax_total += $this->shoppingCollectOrder->shipping_tax; //add shipping tax to split - $tax = isset($this->tax_split[config('app.shipping_tax')]) ? $this->tax_split[config('app.shipping_tax')] : 0; - $tax += $this->shipping_tax; - $this->tax_split[config('app.shipping_tax')] = $tax; + $this->shoppingCollectOrder->addTaxToSplit(config('app.shipping_tax'), $this->shoppingCollectOrder->shipping_tax); - $this->price_total_net += $this->shipping_net; - $this->price_total = round($this->tax_total + $this->price_total_net, 2); - - //$this->price_total += round($user_price * $item->qty, 2); - - + $this->shoppingCollectOrder->price_total_net += $this->shoppingCollectOrder->shipping_net; + $this->shoppingCollectOrder->price_total = round($this->shoppingCollectOrder->tax_total + $this->shoppingCollectOrder->price_total_net, 2); } public function store(){ - //TODO + $this->shoppingCollectOrder->user_id = \Auth::user()->id; + $this->shoppingCollectOrder->status = 1; + //remove shopping_order + $temp = []; + foreach($this->orders as $order){ + $order->shopping_order = null; + $temp[] = $order; + } + $this->shoppingCollectOrder->orders = $temp; + $this->shoppingCollectOrder->save(); } //price brutto calu with @@ -166,26 +160,49 @@ class ShopApiOrderCart return $ret; } - + + public function __get($property) { + if (property_exists($this->shoppingCollectOrder, $property)) { + return $this->shoppingCollectOrder->$property; + } + if (isset($this->shoppingCollectOrder->{$property})) { + return $this->shoppingCollectOrder->{$property}; + } + } public function getTotalTax() { - return $this->tax_total; + return $this->shoppingCollectOrder->tax_total; } public function getTotalPriceNetto() { - return $this->price_total_net; + return $this->shoppingCollectOrder->price_total_net; } public function getTotalPrice() { - return $this->price_total; + return $this->shoppingCollectOrder->price_total; } - public function getTaxSplit() { return 0; } + + public static function finishOrder(ShoppingCollectOrder $shoppingCollectOrder){ + + //get orders an set + foreach($shoppingCollectOrder->orders as $order){ + $ShoppingOrder = ShoppingOrder::findOrFail($order['order_id']); + $ShoppingOrder->api_status = 2; //bestellt + $api_notice = $ShoppingOrder->api_notice; + $api_notice['shopping_order_id'] = $shoppingCollectOrder->shopping_order_id; + $ShoppingOrder->api_notice = $api_notice; + $ShoppingOrder->save(); + } + $shoppingCollectOrder->status = 2; //order + $shoppingCollectOrder->save(); + } + } \ No newline at end of file diff --git a/database/migrations/2019_02_23_161530_create_shopping_users_table.php b/database/migrations/2019_02_23_161530_create_shopping_users_table.php index 740ece0..56f0134 100644 --- a/database/migrations/2019_02_23_161530_create_shopping_users_table.php +++ b/database/migrations/2019_02_23_161530_create_shopping_users_table.php @@ -59,7 +59,8 @@ class CreateShoppingUsersTable extends Migration $table->text('notice')->default(false); $table->unsignedInteger('homeparty_id')->nullable(); - + $table->unsignedInteger('shopping_collect_order_id')->nullable(); + $table->char('mode', 4)->nullable(); $table->char('is_for', 2)->nullable(); diff --git a/database/migrations/2019_02_23_163724_create_shopping_order_items_table.php b/database/migrations/2019_02_23_163724_create_shopping_order_items_table.php index 41a6ceb..ea550b8 100644 --- a/database/migrations/2019_02_23_163724_create_shopping_order_items_table.php +++ b/database/migrations/2019_02_23_163724_create_shopping_order_items_table.php @@ -20,6 +20,8 @@ class CreateShoppingOrderItemsTable extends Migration $table->string('row_id', 40)->nullable(); $table->unsignedInteger('product_id'); $table->unsignedInteger('homeparty_id')->nullable(); + $table->unsignedInteger('shopping_collect_order_id')->nullable(); + $table->unsignedTinyInteger('comp')->nullable(); diff --git a/database/migrations/2022_07_18_103813_create_shopping_collect_orders_table.php b/database/migrations/2022_07_18_103813_create_shopping_collect_orders_table.php new file mode 100644 index 0000000..28988b5 --- /dev/null +++ b/database/migrations/2022_07_18_103813_create_shopping_collect_orders_table.php @@ -0,0 +1,62 @@ +increments('id'); + + $table->unsignedInteger('user_id'); + $table->unsignedInteger('shopping_order_id')->index()->nullable(); + + $table->decimal('shipping', 8, 2)->nullable(); + $table->decimal('shipping_net', 8, 2)->nullable(); + $table->decimal('shipping_tax', 5, 2)->nullable(); + + $table->decimal('price_total_net', 8, 2)->nullable(); + $table->decimal('price_total', 8, 2)->nullable(); + $table->decimal('tax_total', 8, 2)->nullable(); + + $table->unsignedInteger('qty_total'); + $table->unsignedInteger('points')->nullable(); + + $table->string('tax_split')->nullable(); + + $table->text('orders')->nullable(); + $table->text('shop_items')->nullable(); + + $table->unsignedTinyInteger('status')->index()->default(0); + + $table->timestamps(); + + $table->foreign('user_id') + ->references('id') + ->on('users'); + + $table->foreign('shopping_order_id') + ->references('id') + ->on('shopping_orders'); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('shopping_collect_orders'); + } +} diff --git a/resources/views/admin/sales/_detail.blade.php b/resources/views/admin/sales/_detail.blade.php index bfe9b41..b5bc62d 100644 --- a/resources/views/admin/sales/_detail.blade.php +++ b/resources/views/admin/sales/_detail.blade.php @@ -1,116 +1,117 @@ +
| Produkt | -- @if($shopping_order->shopping_user->is_from === 'user_order') - Netto-Preis - @else - Preis - @endif - | -Anzahl | -Summe | -
|---|---|---|---|
|
-
- @if($shopping_order_item->product)
- @if($shopping_order_item->product->images)
- @if($image = $shopping_order_item->product->images->first())
-
-
- {{ $shopping_order_item->product->name }}
- #{{ $shopping_order_item->product->number }}
-
- Inhalt: {{ $shopping_order_item->product->contents }}
- @endif
- - Gewicht: {{ $shopping_order_item->product->weight }} g - Points: {{ $shopping_order_item->product->points }} - - |
- - @if($shopping_order->shopping_user->is_from === 'user_order') - {{ $shopping_order_item->getFormattedPriceNet() }} € - @else - {{ $shopping_order_item->getFormattedPrice() }} € - @endif - | - -- {{ $shopping_order_item->qty }} - | - -- @if($shopping_order->shopping_user->is_from === 'user_order') - {{ $shopping_order_item->getFormattedTotalPriceNet() }} € - @else - {{ $shopping_order_item->getFormattedTotalPrice() }} € - @endif - | -
| - {{__('email.checkout_mail_shipping')}} - | -- @if($shopping_order->tax > 0) - {{ $shopping_order->getFormattedShipping() }} € - @else - {{ $shopping_order->getFormattedShippingNet() }} € - @endif - | -||
| - {{__('email.checkout_mail_subtotal_ws')}} - | -- {{ $shopping_order->getFormattedSubtotalWs() }} € - | -||
| - {{__('email.checkout_mail_tax')}} - | -- {{ $shopping_order->getFormattedTax() }} € - | -||
| - {{__('email.checkout_mail_total')}} - | -
- {{ $shopping_order->getFormattedTotalShipping() }} €
- - {{__('email.checkout_mail_tax_info')}} - |
- ||
Bestellung Gastgeber/in {{$homeparty->homeparty_host->billing_firstname}} {{$homeparty->homeparty_host->billing_lastname}}
- @include('admin.sales._detail_homparty', ['homeparty'=>$shopping_order->homeparty, 'homeparty_guest' => $homeparty->homeparty_host]) - @endif - - @if($homeparty->homeparty_guests) - @php($g_count = 1) - @foreach($homeparty->homeparty_guests as $homeparty_guest) -Bestellung {!! $g_count++ !!}. Gast {{$homeparty_guest->billing_firstname}} {{$homeparty_guest->billing_lastname}}
- @include('admin.sales._detail_homparty', ['homeparty'=>$shopping_order->homeparty, 'homeparty_guest' => $homeparty_guest]) - @endforeach - @endif -| # | -Zahlungsart | -Gesamt | -Status | -Datum | -Referenznummer | -||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{++$count}} | -{{$shopping_payment->getPaymentType()}} | -{{$shopping_payment->getPaymentAmount()}} | -
- @if($isAdmin && $shopping_payment->clearingtype === 'fnc' && $shopping_payment->onlinebanktransfertype === 'MIV')
- |
- {{$shopping_payment->created_at->format("d.m.Y H:i")}} | -{{$shopping_payment->reference}} | -||||||||||||||
| {{$count}}.{{++$ccount}} | -
-
|
+ # | +Zahlungsart | +Gesamt | +Status | +Datum | +Referenznummer | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Request | +Status | +TX-Action | +Datum | +
|---|---|---|---|
| {{ $payment_transaction->request }} | +{{ $payment_transaction->status }} | +{{ $payment_transaction->txaction }} + {{ $payment_transaction->errormessage }} | +{{ $payment_transaction->created_at->format('d.m.Y H:i') }} + | +