update 20.10.2025

This commit is contained in:
Kevin Adametz 2025-10-20 17:42:08 +02:00
parent 8c11130b5d
commit a939cd51ef
616 changed files with 84821 additions and 4121 deletions

View file

@ -44,7 +44,7 @@ class Customer extends Authenticatable // Erbt von Authenticatable
use HasFactory, Notifiable;
protected $table = 'customers';
protected $fillable = [
'name',
'email',
@ -52,6 +52,7 @@ class Customer extends Authenticatable // Erbt von Authenticatable
'member_id',
'number',
'language',
'user_shop_domain',
'mode',
];

View file

@ -1,407 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Carbon;
/**
* DHL Shipment Model
*
* Represents a DHL shipment for a shopping order, including both outbound and return shipments.
*
* @property int $id
* @property int $shopping_order_id
* @property string|null $shipment_number DHL shipment number
* @property string|null $tracking_number DHL tracking number
* @property string $type Type: 'outbound' or 'return'
* @property int|null $related_shipment_id For returns: reference to original shipment
* @property float $weight Package weight in kg
* @property int|null $length Package length in cm
* @property int|null $width Package width in cm
* @property int|null $height Package height in cm
* @property string $product_code DHL product code (e.g., V01PAK)
* @property array|null $services Additional DHL services
* @property string|null $label_path Path to generated label file
* @property string $label_format Label format (PDF or ZPL)
* @property bool $label_printed Whether label has been printed
* @property string $status Shipment status
* @property string|null $tracking_status Current tracking status from DHL
* @property string|null $tracking_details Detailed tracking information (JSON)
* @property Carbon|null $last_tracked_at Last tracking update
* @property string $recipient_name Recipient name
* @property string|null $recipient_company Recipient company
* @property string $recipient_street Recipient street
* @property string $recipient_street_number Recipient street number
* @property string $recipient_postal_code Recipient postal code
* @property string $recipient_city Recipient city
* @property string|null $recipient_state Recipient state
* @property string $recipient_country Recipient country code
* @property string|null $recipient_email Recipient email
* @property string|null $recipient_phone Recipient phone
* @property array|null $api_request_data API request data for debugging
* @property array|null $api_response_data API response data for debugging
* @property string|null $api_errors API error messages
* @property float|null $shipping_cost Shipping cost
* @property string $currency Currency code
* @property string|null $notes Internal notes
* @property array|null $metadata Additional metadata
* @property Carbon|null $shipped_at When the package was shipped
* @property Carbon|null $delivered_at When the package was delivered
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property-read ShoppingOrder $shoppingOrder
* @property-read DhlShipment|null $relatedShipment
* @property-read DhlShipment|null $returnShipment
* @property-read string|null $dimensions
* @property-read string|null $label_url
* @property-read string $recipient_address
* @property-read string $status_label
* @property-read string $type_label
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment active()
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment outbound()
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment returns()
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment trackable()
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereApiErrors($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereApiRequestData($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereApiResponseData($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereCurrency($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereDeliveredAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereHeight($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereLabelFormat($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereLabelPath($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereLabelPrinted($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereLastTrackedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereLength($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereMetadata($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereNotes($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereProductCode($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientCity($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientCompany($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientCountry($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientName($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientPhone($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientPostalCode($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientState($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientStreet($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientStreetNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRelatedShipmentId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereServices($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereShipmentNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereShippedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereShippingCost($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereShoppingOrderId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereTrackingDetails($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereTrackingNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereTrackingStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereWeight($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereWidth($value)
* @mixin \Eloquent
*/
class DhlShipment extends Model
{
use HasFactory;
/**
* The table associated with the model.
*/
protected $table = 'dhl_shipments';
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'shopping_order_id',
'shipment_number',
'tracking_number',
'type',
'related_shipment_id',
'weight',
'length',
'width',
'height',
'product_code',
'services',
'label_path',
'label_format',
'label_printed',
'status',
'tracking_status',
'tracking_details',
'last_tracked_at',
'recipient_name',
'recipient_company',
'recipient_street',
'recipient_street_number',
'recipient_postal_code',
'recipient_city',
'recipient_state',
'recipient_country',
'recipient_email',
'recipient_phone',
'api_request_data',
'api_response_data',
'api_errors',
'shipping_cost',
'currency',
'notes',
'metadata',
'shipped_at',
'delivered_at',
];
/**
* The attributes that should be cast.
*/
protected $casts = [
'weight' => 'float',
'length' => 'integer',
'width' => 'integer',
'height' => 'integer',
'services' => 'array',
'label_printed' => 'boolean',
'tracking_details' => 'array',
'last_tracked_at' => 'datetime',
'api_request_data' => 'array',
'api_response_data' => 'array',
'shipping_cost' => 'decimal:2',
'metadata' => 'array',
'shipped_at' => 'datetime',
'delivered_at' => 'datetime',
];
/**
* Shipment types
*/
public const TYPE_OUTBOUND = 'outbound';
public const TYPE_RETURN = 'return';
/**
* Shipment statuses
*/
public const STATUS_CREATED = 'created';
public const STATUS_SUBMITTED = 'submitted';
public const STATUS_IN_TRANSIT = 'in_transit';
public const STATUS_DELIVERED = 'delivered';
public const STATUS_RETURNED = 'returned';
public const STATUS_CANCELLED = 'cancelled';
public const STATUS_FAILED = 'failed';
/**
* Get the shopping order that owns the shipment
*/
public function shoppingOrder(): BelongsTo
{
return $this->belongsTo(ShoppingOrder::class, 'shopping_order_id');
}
/**
* Get the related shipment (for returns)
*/
public function relatedShipment(): BelongsTo
{
return $this->belongsTo(DhlShipment::class, 'related_shipment_id');
}
/**
* Get the return shipment (for outbound shipments)
*/
public function returnShipment(): HasOne
{
return $this->hasOne(DhlShipment::class, 'related_shipment_id');
}
/**
* Scope for outbound shipments
*/
public function scopeOutbound($query)
{
return $query->where('type', self::TYPE_OUTBOUND);
}
/**
* Scope for return shipments
*/
public function scopeReturns($query)
{
return $query->where('type', self::TYPE_RETURN);
}
/**
* Scope for active shipments (not cancelled or failed)
*/
public function scopeActive($query)
{
return $query->whereNotIn('status', [self::STATUS_CANCELLED, self::STATUS_FAILED]);
}
/**
* Scope for trackable shipments (have tracking number)
*/
public function scopeTrackable($query)
{
return $query->whereNotNull('tracking_number');
}
/**
* Check if shipment is outbound
*/
public function isOutbound(): bool
{
return $this->type === self::TYPE_OUTBOUND;
}
/**
* Check if shipment is return
*/
public function isReturn(): bool
{
return $this->type === self::TYPE_RETURN;
}
/**
* Check if shipment can be cancelled
*/
public function canBeCancelled(): bool
{
return in_array($this->status, [
self::STATUS_CREATED,
self::STATUS_SUBMITTED,
]);
}
/**
* Check if shipment is delivered
*/
public function isDelivered(): bool
{
return $this->status === self::STATUS_DELIVERED;
}
/**
* Check if shipment has tracking information
*/
public function hasTracking(): bool
{
return !empty($this->tracking_number);
}
/**
* Check if label is available
*/
public function hasLabel(): bool
{
return !empty($this->label_path) && file_exists(storage_path('app/' . $this->label_path));
}
/**
* Get full recipient address as formatted string
*/
public function getRecipientAddressAttribute(): string
{
$address = $this->recipient_name;
if ($this->recipient_company) {
$address .= "\n" . $this->recipient_company;
}
$address .= "\n" . $this->recipient_street . ' ' . $this->recipient_street_number;
$address .= "\n" . $this->recipient_postal_code . ' ' . $this->recipient_city;
if ($this->recipient_state) {
$address .= "\n" . $this->recipient_state;
}
$address .= "\n" . $this->recipient_country;
return $address;
}
/**
* Get package dimensions as formatted string
*/
public function getDimensionsAttribute(): ?string
{
if (!$this->length || !$this->width || !$this->height) {
return null;
}
return $this->length . ' x ' . $this->width . ' x ' . $this->height . ' cm';
}
/**
* Get human-readable status
*/
public function getStatusLabelAttribute(): string
{
return match($this->status) {
self::STATUS_CREATED => 'Erstellt',
self::STATUS_SUBMITTED => 'Übertragen',
self::STATUS_IN_TRANSIT => 'Unterwegs',
self::STATUS_DELIVERED => 'Zugestellt',
self::STATUS_RETURNED => 'Zurückgeschickt',
self::STATUS_CANCELLED => 'Storniert',
self::STATUS_FAILED => 'Fehler',
default => 'Unbekannt',
};
}
/**
* Get human-readable type
*/
public function getTypeLabelAttribute(): string
{
return match($this->type) {
self::TYPE_OUTBOUND => 'Versand',
self::TYPE_RETURN => 'Retoure',
default => 'Unbekannt',
};
}
/**
* Get label file URL for download
*/
public function getLabelUrlAttribute(): ?string
{
if (!$this->hasLabel()) {
return null;
}
return route('admin.dhl.shipments.label', $this->id);
}
/**
* Boot the model
*/
protected static function boot()
{
parent::boot();
static::creating(function ($shipment) {
// Set default values
if (empty($shipment->currency)) {
$shipment->currency = config('dhl.defaults.currency', 'EUR');
}
if (empty($shipment->product_code)) {
$shipment->product_code = config('dhl.defaults.product', 'V01PAK');
}
if (empty($shipment->label_format)) {
$shipment->label_format = config('dhl.labels.format', 'PDF');
}
});
}
}

View file

@ -101,11 +101,11 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property int|null $abo_interval
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereAboInterval($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereIsAbo($value)
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DhlShipment> $dhlOutboundShipments
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Acme\Dhl\Models\DhlShipment> $dhlOutboundShipments
* @property-read int|null $dhl_outbound_shipments_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DhlShipment> $dhlReturnShipments
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Acme\Dhl\Models\DhlShipment> $dhlReturnShipments
* @property-read int|null $dhl_return_shipments_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DhlShipment> $dhlShipments
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Acme\Dhl\Models\DhlShipment> $dhlShipments
* @property-read int|null $dhl_shipments_count
* @mixin \Eloquent
*/
@ -138,7 +138,7 @@ class ShoppingOrder extends Model
'weight',
'paid',
'is_abo',
'abo_interval',
'abo_interval',
'txaction',
'wp_invoice_path',
'api_notice',
@ -175,9 +175,9 @@ class ShoppingOrder extends Model
];
public static $apiStatusTypes = [
0 => 'ordered',
1 => 'in_process',
2 => 'paid',
0 => 'ordered',
1 => 'in_process',
2 => 'paid',
5 => 'removed',
];
public static $apiStatusColors = [
@ -227,110 +227,120 @@ class ShoppingOrder extends Model
public function shopping_user()
{
return $this->belongsTo('App\Models\ShoppingUser','shopping_user_id');
return $this->belongsTo('App\Models\ShoppingUser', 'shopping_user_id');
}
public function country()
{
return $this->belongsTo('App\Models\ShippingCountry','country_id');
return $this->belongsTo('App\Models\ShippingCountry', 'country_id');
}
public function shipping_country()
{
return $this->belongsTo('App\Models\ShippingCountry','country_id');
return $this->belongsTo('App\Models\ShippingCountry', 'country_id');
}
public function homeparty()
{
return $this->belongsTo('App\Models\Homeparty','homeparty_id');
return $this->belongsTo('App\Models\Homeparty', 'homeparty_id');
}
public function user_shop()
{
return $this->belongsTo('App\Models\UserShop','user_shop_id');
return $this->belongsTo('App\Models\UserShop', 'user_shop_id');
}
//can null
public function member()
{
return $this->belongsTo('App\User','member_id');
return $this->belongsTo('App\User', 'member_id');
}
//can null
public function auth_user()
{
return $this->belongsTo('App\User','auth_user_id');
return $this->belongsTo('App\User', 'auth_user_id');
}
public function user_history()
{
return $this->hasOne('App\Models\UserHistory','shopping_order_id')->latest();
return $this->hasOne('App\Models\UserHistory', 'shopping_order_id')->latest();
}
public function user_invoice(){
public function user_invoice()
{
return $this->hasOne('App\Models\UserInvoice', 'shopping_order_id', '');
}
public function shopping_collect_order(){
public function shopping_collect_order()
{
return $this->hasOne('App\Models\ShoppingCollectOrder', 'shopping_order_id', '');
}
public function shopping_order_items(){
public function shopping_order_items()
{
return $this->hasMany('App\Models\ShoppingOrderItem', 'shopping_order_id');
}
public function shopping_payments(){
public function shopping_payments()
{
return $this->hasMany('App\Models\ShoppingPayment', 'shopping_order_id');
}
public function user_sales_volume(){
public function user_sales_volume()
{
return $this->hasOne('App\Models\UserSalesVolume', 'shopping_order_id');
}
public function user_sales_volume_no_userid(){
public function user_sales_volume_no_userid()
{
return $this->hasOne('App\Models\UserSalesVolume', 'shopping_order_id')->where('user_id', '=', NULL)->first();
}
public function getUserAbo(){
public function getUserAbo()
{
$UserAboOrder = UserAboOrder::where('shopping_order_id', $this->id)->first();
if($UserAboOrder && $UserAboOrder->user_abo){
return $UserAboOrder->user_abo;
}
if ($UserAboOrder && $UserAboOrder->user_abo) {
return $UserAboOrder->user_abo;
}
return null;
}
public function getLocale(){
public function getLocale()
{
return $this->language ? $this->language : \App::getLocale();
}
public function setUserHistoryValue($values = []){
if($user_history = $this->user_history){
foreach ($values as $key=>$val){
public function setUserHistoryValue($values = [])
{
if ($user_history = $this->user_history) {
foreach ($values as $key => $val) {
$user_history->{$key} = $val;
}
$user_history->save();
}
}
public function getLastShoppingPayment($key=false){
public function getLastShoppingPayment($key = false)
{
$shopping_payment = $this->shopping_payments->last();
if($shopping_payment){
if($key === 'getPaymentType'){
if ($shopping_payment) {
if ($key === 'getPaymentType') {
return $shopping_payment->getPaymentType();
}
if($key === 'reference'){
if ($key === 'reference') {
return $shopping_payment->reference;
}
}
return "";
}
public function getLastShoppingPaymentTransaction(){
if($this->shopping_payments){
public function getLastShoppingPaymentTransaction()
{
if ($this->shopping_payments) {
$shopping_payment = $this->shopping_payments->last();
if($shopping_payment){
if ($shopping_payment) {
$payt = $shopping_payment->payment_transactions->last();
if($payt){
if ($payt) {
return $payt;
}
}
@ -338,30 +348,36 @@ class ShoppingOrder extends Model
return false;
}
public function getShippedType(){
return isset(self::$shippedTypes[$this->shipped]) ? __('payment.'.self::$shippedTypes[$this->shipped]) : "";
public function getShippedType()
{
return isset(self::$shippedTypes[$this->shipped]) ? __('payment.' . self::$shippedTypes[$this->shipped]) : "";
}
public static function getTransShippedType(){
$ret = [];
foreach(self::$shippedTypes as $key=>$val){
$ret[$key] = trans('payment.'.$val);
}
return $ret;
public static function getTransShippedType()
{
$ret = [];
foreach (self::$shippedTypes as $key => $val) {
$ret[$key] = trans('payment.' . $val);
}
return $ret;
}
public function getAPIShippedType(){
public function getAPIShippedType()
{
return isset(self::$apiShippedTypes[$this->shipped]) ? self::$apiShippedTypes[$this->shipped] : "free";
}
public function getShippedColor(){
public function getShippedColor()
{
return isset(self::$shippedColors[$this->shipped]) ? self::$shippedColors[$this->shipped] : "default";
}
public function getAPIStatusType(){
return isset(self::$apiStatusTypes[$this->api_status]) ? __('payment.'.self::$apiStatusTypes[$this->api_status]) : "bestellt";
public function getAPIStatusType()
{
return isset(self::$apiStatusTypes[$this->api_status]) ? __('payment.' . self::$apiStatusTypes[$this->api_status]) : "bestellt";
}
public function getAPIStatusColor(){
public function getAPIStatusColor()
{
return isset(self::$apiStatusColors[$this->api_status]) ? self::$apiStatusColors[$this->api_status] : "warning";
}
@ -389,7 +405,7 @@ class ShoppingOrder extends Model
{
return formatNumber($this->attributes['subtotal_ws']);
}
public function getFormattedSubtotalShipping()
{
return formatNumber($this->attributes['subtotal_shipping']);
@ -407,79 +423,84 @@ class ShoppingOrder extends Model
public function getPriceVkNetBy($product_id)
{
if($product = Product::find($product_id)){
if($this->shipping_country && $this->shipping_country->country){
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]) ? __('payment.'.self::$paymentForTypes[$this->payment_for]) : "";
public function getPaymentForType()
{
return isset(self::$paymentForTypes[$this->payment_for]) ? __('payment.' . self::$paymentForTypes[$this->payment_for]) : "";
}
public function getPaymentForColor(){
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){
if ($this->auth_user && $this->auth_user->user_level) {
return $this->auth_user->user_level->getFormattedMargin();
}
if($this->member && $this->member->user_level){
}
if ($this->member && $this->member->user_level) {
return $this->member->user_level->getFormattedMargin();
}
}
return 0;
}
public function getItemsCount(){
public function getItemsCount()
{
$count = 0;
if($this->shopping_order_items){
foreach ($this->shopping_order_items as $shopping_order_item){
if ($this->shopping_order_items) {
foreach ($this->shopping_order_items as $shopping_order_item) {
$count += $shopping_order_item->qty;
}
}
return $count;
}
public function isInvoice(){
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 getStatusByOrder()
{
if ($this->payment_for) {
if ($this->payment_for === 6) { //Kunde-Shop
return 2;
}
return 1;
}
return 0;
}
public function makeHomepartyTaxSplit()
{
$tax_split = [];
$net_split = [];
if($this->homeparty){
foreach($this->homeparty->homeparty_order_items as $item){
if ($this->homeparty) {
foreach ($this->homeparty->homeparty_order_items as $item) {
$tax_rate = intval($item->tax_rate);
if($tax_rate > 0){
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);
$vk_net = round(($item->price_net * $item->qty), 2);
$ek_net = round(($item->ek_price_net * $item->qty), 2);
if(isset($tax_split[$tax_rate])){
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);
$net_split[$tax_rate]['vk_net'] = round($net_split[$tax_rate]['vk_net'] + $vk_net, 2);
$net_split[$tax_rate]['ek_net'] = round($net_split[$tax_rate]['ek_net'] + $ek_net, 2);
}else{
} else {
$tax_split[$tax_rate] = ['vk_tax' => $vk_tax, 'ek_tax' => $ek_tax];
$net_split[$tax_rate] = ['vk_net' => $vk_net, 'ek_net' => $ek_net];
}
}
}
}
$order_vk_tax = 0;
@ -487,26 +508,26 @@ class ShoppingOrder extends Model
$order_vk_net = 0;
$order_ek_net = 0;
if($this->homeparty->order){
if(isset($this->homeparty->order['ek_price_net'])){
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);
$order_vk_net = $this->homeparty->order['price_net'];
$order_ek_net = $this->homeparty->order['ek_price_net'];
}
}
if(isset($tax_split[16])){
if (isset($tax_split[16])) {
$tax_split[16] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
$net_split[16] = ['vk_net' => $order_vk_net, 'ek_net' => $order_ek_net];
}
if(isset($tax_split[19])){
if (isset($tax_split[19])) {
$tax_split[19] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
$net_split[19] = ['vk_net' => $order_vk_net, 'ek_net' => $order_ek_net];
}
if(isset($tax_split[5])){
if(!isset($tax_split[16])){
if (isset($tax_split[5])) {
if (!isset($tax_split[16])) {
$tax_split[16] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
$net_split[16] = ['vk_net' => $order_vk_net, 'ek_net' => $order_ek_net];
}
@ -514,9 +535,9 @@ class ShoppingOrder extends Model
$tax_split[16]['ek_tax'] = round($tax_split[16]['ek_tax'] - $tax_split[5]['ek_tax'], 2);
$net_split[16]['vk_net'] = round($net_split[16]['vk_net'] - $net_split[5]['vk_net'], 2);
$net_split[16]['ek_net'] = round($net_split[16]['ek_net'] - $net_split[5]['ek_net'], 2);
}
if(isset($tax_split[7])){
if(!isset($tax_split[19])){
}
if (isset($tax_split[7])) {
if (!isset($tax_split[19])) {
$tax_split[19] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
$net_split[19] = ['vk_net' => $order_vk_net, 'ek_net' => $order_ek_net];
}
@ -524,30 +545,30 @@ class ShoppingOrder extends Model
$tax_split[19]['ek_tax'] = round($tax_split[19]['ek_tax'] - $tax_split[7]['ek_tax'], 2);
$net_split[19]['vk_net'] = round($net_split[19]['vk_net'] - $net_split[7]['vk_net'], 2);
$net_split[19]['ek_net'] = round($net_split[19]['ek_net'] - $net_split[7]['ek_net'], 2);
}
}
foreach($tax_split as $key=>$value){
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);
}
}
foreach($net_split as $key=>$value){
foreach ($net_split as $key => $value) {
$net_split[$key]['vk_net'] = number_format($value['vk_net'], 2);
$net_split[$key]['ek_net'] = number_format($value['ek_net'], 2);
}
}
}
if(!isset($tax_split[16]) && !isset($tax_split[19])){
if (!isset($tax_split[16]) && !isset($tax_split[19])) {
$tax_split = NULL;
}
if(!isset($net_split[16]) && !isset($net_split[19])){
if (!isset($net_split[16]) && !isset($net_split[19])) {
$net_split = NULL;
}
$this->tax_split = $tax_split;
$this->net_split = $net_split;
$this->save();
$this->save();
}
public function makeTaxSplit()
@ -555,75 +576,72 @@ class ShoppingOrder extends Model
$tax_split = NULL;
$net_split = NULL;
if($this->tax > 0){
if ($this->tax > 0) {
$tax_split = [];
$net_split = [];
foreach($this->shopping_order_items as $item){
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 ($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);
$net_split[$tax_rate] = isset($net_split[$tax_rate]) ?
round($net_split[$tax_rate] + ($item->price_net * $item->qty), 2) :
round(($item->price_net * $item->qty), 2);
$net_split[$tax_rate] = isset($net_split[$tax_rate]) ?
round($net_split[$tax_rate] + ($item->price_net * $item->qty), 2) :
round(($item->price_net * $item->qty), 2);
}
}
if(isset($tax_split[16])){
}
if (isset($tax_split[16])) {
$tax_split[16] = $this->tax;
$net_split[16] = $this->subtotal_ws;
}
if(isset($tax_split[19])){
if (isset($tax_split[19])) {
$tax_split[19] = $this->tax;
$net_split[19] = $this->subtotal_ws;
}
if(isset($tax_split[5])){
if(!isset($tax_split[16])){
if (isset($tax_split[5])) {
if (!isset($tax_split[16])) {
$tax_split[16] = $this->tax;
$net_split[16] = $this->subtotal_ws;
}
$tax_split[16] = round($tax_split[16] - $tax_split[5], 2);
$net_split[16] = round($net_split[16] - $net_split[5], 2);
}
if(isset($tax_split[7])){
if(!isset($tax_split[19])){
}
if (isset($tax_split[7])) {
if (!isset($tax_split[19])) {
$tax_split[19] = $this->tax;
$net_split[19] = $this->subtotal_ws;
}
$tax_split[19] = round($tax_split[19] - $tax_split[7], 2);
$net_split[19] = round($net_split[19] - $net_split[7], 2);
}
}
foreach($tax_split as $key=>$value){
foreach ($tax_split as $key => $value) {
$tax_split[$key] = number_format($value, 2);
}
foreach($net_split as $key=>$value){
}
foreach ($net_split as $key => $value) {
$net_split[$key] = number_format($value, 2);
}
}
}
$this->tax_split = $tax_split;
$this->net_split = $net_split;
$this->save();
$this->save();
}
public function getShoppingUserFullName(){
if($this->shopping_user){
public function getShoppingUserFullName()
{
if ($this->shopping_user) {
$fullname = $this->shopping_user->getFullNameAsArray();
$ret = "";
$ret .= $fullname['company'] ? $fullname['company'].' | ' : '';
$ret .= $fullname['salutation'] ? \App\Services\HTMLHelper::getSalutationLang($fullname['salutation']).' ' : '';
$ret .= $fullname['firstname'] ? $fullname['firstname'].' ' : '';
$ret .= $fullname['company'] ? $fullname['company'] . ' | ' : '';
$ret .= $fullname['salutation'] ? \App\Services\HTMLHelper::getSalutationLang($fullname['salutation']) . ' ' : '';
$ret .= $fullname['firstname'] ? $fullname['firstname'] . ' ' : '';
$ret .= $fullname['lastname'] ? $fullname['lastname'] : '';
$ret .= $fullname['email'] ? ' | '.$fullname['email'].'' : '';
$ret .= $fullname['email'] ? ' | ' . $fullname['email'] . '' : '';
}
return $ret;
@ -634,7 +652,7 @@ class ShoppingOrder extends Model
*/
public function dhlShipments()
{
return $this->hasMany('App\Models\DhlShipment', 'shopping_order_id');
return $this->hasMany('Acme\Dhl\Models\DhlShipment', 'order_id');
}
/**
@ -642,7 +660,7 @@ class ShoppingOrder extends Model
*/
public function dhlOutboundShipments()
{
return $this->hasMany('App\Models\DhlShipment', 'shopping_order_id')->where('type', 'outbound');
return $this->hasMany('Acme\Dhl\Models\DhlShipment', 'order_id')->where('type', 'outbound');
}
/**
@ -650,7 +668,7 @@ class ShoppingOrder extends Model
*/
public function dhlReturnShipments()
{
return $this->hasMany('App\Models\DhlShipment', 'shopping_order_id')->where('type', 'return');
return $this->hasMany('Acme\Dhl\Models\DhlShipment', 'order_id')->where('type', 'return');
}
/**
@ -668,5 +686,4 @@ class ShoppingOrder extends Model
{
return $this->dhlShipments()->latest()->first();
}
}