Update Framework, Invoices

This commit is contained in:
Kevin Adametz 2022-04-14 13:14:36 +02:00
parent cc5c147c27
commit 9b0b5feb7e
174 changed files with 28356 additions and 8093 deletions

View file

@ -80,6 +80,11 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrder whereSubtotalWs($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrder whereTracking($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrder whereWpInvoicePath($value)
* @property int|null $homeparty_id
* @property array|null $wp_notice
* @property-read \App\Models\Homeparty|null $homeparty
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereHomepartyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereWpNotice($value)
*/
class ShoppingOrder extends Model
{
@ -93,6 +98,7 @@ class ShoppingOrder extends Model
'auth_user_id',
'member_id',
'homeparty_id',
'payment_for',
'country_id',
'user_shop_id',
'total',
@ -101,6 +107,7 @@ class ShoppingOrder extends Model
'shipping_net',
'subtotal_ws',
'tax',
'tax_split',
'total_shipping',
'points',
'weight',
@ -115,6 +122,7 @@ class ShoppingOrder extends Model
protected $casts = [
'wp_notice' => 'array',
'tax_split' => 'array',
];
public static $shippedTypes = [
@ -141,6 +149,34 @@ class ShoppingOrder extends Model
10 => 'danger',
];
public static $paymentForTypes = [
0 => '',
1 => 'Registrierung',
2 => 'Mitgliedschaft',
3 => 'Bestellung',
4 => 'Kundenbestellung',
5 => 'Homeparty',
6 => 'Shop',
7 => 'extern',
10 => '',
];
public static $paymentForColors = [
0 => 'default',
1 => 'warning',
2 => 'warning',
3 => 'secondary',
4 => 'info',
5 => 'dark',
6 => 'secondary',
7 => 'dark',
8 => 'info',
9 => 'default',
10 => 'info',
11 => 'default'
];
public function shopping_user()
{
@ -183,7 +219,10 @@ class ShoppingOrder extends Model
return $this->hasOne('App\Models\UserHistory','shopping_order_id')->latest();
}
public function user_invoice(){
return $this->hasOne('App\Models\UserInvoice', 'shopping_order_id', '');
}
public function shopping_order_items(){
return $this->hasMany('App\Models\ShoppingOrderItem', 'shopping_order_id');
}
@ -192,6 +231,18 @@ class ShoppingOrder extends Model
return $this->hasMany('App\Models\ShoppingPayment', 'shopping_order_id');
}
public function user_sales_volume(){
return $this->hasMany('App\Models\UserSalesVolume', 'shopping_order_id');
}
public function user_sales_volume_no_userid(){
return $this->hasMany('App\Models\UserSalesVolume', 'shopping_order_id')->where('user_id', '=', NULL)->first();
}
public function setUserHistoryValue($values = []){
if($user_history = $this->user_history){
foreach ($values as $key=>$val){
@ -250,6 +301,11 @@ class ShoppingOrder extends Model
{
return formatNumber($this->attributes['subtotal_ws']);
}
public function getFormattedSubtotalShipping()
{
return formatNumber($this->attributes['subtotal_shipping']);
}
public function getFormattedTax()
{
@ -261,8 +317,33 @@ class ShoppingOrder extends Model
return formatNumber($this->attributes['total_shipping']);
}
public function getPriceVkNetBy($product_id)
{
if($product = Product::find($product_id)){
if($this->shipping_country && $this->shipping_country->country){
return $product->getPriceWith(true, false, $this->shipping_country->country);
}
}
return 0;
}
public function getPaymentForType(){
return isset(self::$paymentForTypes[$this->payment_for]) ? self::$paymentForTypes[$this->payment_for] : "";
}
public function getPaymentForColor(){
return isset(self::$paymentForColors[$this->payment_for]) ? self::$paymentForColors[$this->payment_for] : "";
}
public function getUserDiscount()
{
if($this->auth_user && $this->auth_user->user_level){
return $this->auth_user->user_level->getFormattedMargin();
}
if($this->member && $this->member->user_level){
return $this->member->user_level->getFormattedMargin();
}
return 0;
}
public function getItemsCount(){
$count = 0;
@ -271,9 +352,128 @@ class ShoppingOrder extends Model
$count += $shopping_order_item->qty;
}
}
return $count;
}
public function isInvoice(){
return $this->user_invoice ? true : false;
}
public function getStatusByOrder(){
if($this->payment_for){
if($this->payment_for === 6){ //Kunde-Shop
return 2;
}
return 1;
}
return 0;
}
public function makeHomepartyTaxSplit()
{
$tax_split = [];
if($this->homeparty){
foreach($this->homeparty->homeparty_order_items as $item){
$tax_rate = intval($item->tax_rate);
if($tax_rate > 0){
$vk_tax = round((($item->price - $item->price_net) * $item->qty), 2);
$ek_tax = round((($item->ek_price - $item->ek_price_net) * $item->qty), 2);
if(isset($tax_split[$tax_rate])){
$tax_split[$tax_rate]['vk_tax'] = round($tax_split[$tax_rate]['vk_tax'] + $vk_tax, 2);
$tax_split[$tax_rate]['ek_tax'] = round($tax_split[$tax_rate]['ek_tax'] + $ek_tax, 2);
}else{
$tax_split[$tax_rate] = ['vk_tax' => $vk_tax, 'ek_tax' => $ek_tax];
}
}
}
$order_vk_tax = 0;
$order_ek_tax = 0;
if($this->homeparty->order){
if(isset($this->homeparty->order['ek_price_net'])){
$order_vk_tax = round((($this->homeparty->order['price'] - $this->homeparty->order['price_net'])), 2);
$order_ek_tax = round((($this->homeparty->order['ek_price'] - $this->homeparty->order['ek_price_net'])), 2);
}
}
if(isset($tax_split[16])){
$tax_split[16] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
}
if(isset($tax_split[19])){
$tax_split[19] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
}
if(isset($tax_split[5])){
if(!isset($tax_split[16])){
$tax_split[16] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
}
$tax_split[16]['vk_tax'] = round($tax_split[16]['vk_tax'] - $tax_split[5]['vk_tax'], 2);
$tax_split[16]['ek_tax'] = round($tax_split[16]['ek_tax'] - $tax_split[5]['ek_tax'], 2);
}
if(isset($tax_split[7])){
if(!isset($tax_split[19])){
$tax_split[19] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
}
$tax_split[19]['vk_tax'] = round($tax_split[19]['vk_tax'] - $tax_split[7]['vk_tax'], 2);
$tax_split[19]['ek_tax'] = round($tax_split[19]['ek_tax'] - $tax_split[7]['ek_tax'], 2);
}
foreach($tax_split as $key=>$value){
$tax_split[$key]['vk_tax'] = number_format($value['vk_tax'], 2);
$tax_split[$key]['ek_tax'] = number_format($value['ek_tax'], 2);
}
}
if(!isset($tax_split[16]) && !isset($tax_split[19])){
$tax_split = NULL;
}
$this->tax_split = $tax_split;
$this->save();
}
public function makeTaxSplit()
{
$tax_split = NULL;
if($this->tax > 0){
$tax_split = [];
foreach($this->shopping_order_items as $item){
$tax_rate = intval($item->tax_rate);
if($tax_rate > 0){
$tax_split[$tax_rate] = isset($tax_split[$tax_rate]) ?
round($tax_split[$tax_rate] + ($item->tax * $item->qty), 2) :
round(($item->tax * $item->qty), 2);
}
}
if(isset($tax_split[16])){
$tax_split[16] = $this->tax;
}
if(isset($tax_split[19])){
$tax_split[19] = $this->tax;
}
if(isset($tax_split[5])){
if(!isset($tax_split[16])){
$tax_split[16] = $this->tax;
}
$tax_split[16] = round($tax_split[16] - $tax_split[5], 2);
}
if(isset($tax_split[7])){
if(!isset($tax_split[19])){
$tax_split[19] = $this->tax;
}
$tax_split[19] = round($tax_split[19] - $tax_split[7], 2);
}
foreach($tax_split as $key=>$value){
$tax_split[$key] = number_format($value, 2);
}
}
$this->tax_split = $tax_split;
$this->save();
}