Sammelbestellung von Extern
This commit is contained in:
parent
d01b4bd560
commit
582ca8299d
33 changed files with 3437 additions and 1466 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue