Sammelbestellung von Extern

This commit is contained in:
Kevin Adametz 2022-07-18 18:07:31 +02:00
parent d01b4bd560
commit 582ca8299d
33 changed files with 3437 additions and 1466 deletions

View file

@ -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();
}

View file

@ -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').'"><span class="far fa-eye"></span></button>';
})
->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 '<a class="btn btn-sm btn-secondary btn-round" href="'.route('user_order_detail', [$shopping_oder_id]).'"><i class="fa fa-check fa-check-circle-o"> '.$shopping_oder_id.'</a>';
}
}
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getAPIStatusColor().'">'.$ShoppingOrder->getAPIStatusType().'</span>';
})
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
@ -161,7 +153,7 @@ class ShopApiController extends Controller
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>
';
})
->orderColumn('payment_for', 'payment_for $1')
->orderColumn('id', 'id $1')

View file

@ -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();
}

View file

@ -0,0 +1,137 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
use App\User;
/**
* Class ShoppingCollectOrder
*
* @property int $id
* @property int $user_id
* @property int|null $shopping_order_id
* @property float|null $shipping
* @property float|null $shipping_net
* @property float|null $shipping_tax
* @property float|null $price_total_net
* @property float|null $price_total
* @property float|null $tax_total
* @property int $qty_total
* @property int|null $points
* @property string|null $tax_split
* @property AsArrayObject|null $orders
* @property AsArrayObject|null $shop_items
* @property int $status
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property ShoppingOrder|null $shopping_order
* @property User $user
* @package App\Models
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder query()
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereOrders($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder wherePoints($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder wherePriceTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder wherePriceTotalNet($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereQtyTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereShipping($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereShippingNet($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereShippingTax($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereShopItems($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereShoppingOrderId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereTaxSplit($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereTaxTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereUserId($value)
* @mixin \Eloquent
*/
class ShoppingCollectOrder extends Model
{
protected $table = 'shopping_collect_orders';
protected $casts = [
'user_id' => '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;
}
}

View file

@ -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');

View file

@ -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',

View file

@ -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;
}

View file

@ -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()

View file

@ -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){

View file

@ -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);

View file

@ -1,39 +1,31 @@
<?php
namespace App\Services;
use App\Models\ShoppingCollectOrder;
use stdClass;
use App\Models\ShoppingOrder;
use Auth;
class ShopApiOrderCart
{
public $shipping;
public $shipping_net;
public $shipping_tax;
public $points;
public $points_total; //check
public $price_total_net;
public $price_total;
public $tax_total;
public $tax_split;
public $qty_total;
public $orders = [];
public $shop_items = [];
public $shoppingCollectOrder;
public function __construct()
{
$this->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();
}
}