Rechnungen + Gutschriften
This commit is contained in:
parent
39ef16686a
commit
35ae3da244
33 changed files with 2834 additions and 34 deletions
|
|
@ -5,6 +5,7 @@ use App\Mail\MailInvoice;
|
|||
use App\Services\Util;
|
||||
use App\Models\Setting;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserCredit;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class Invoice
|
||||
|
|
@ -30,27 +31,44 @@ class Invoice
|
|||
return "/invoice/".\Carbon::parse($invoice_date)->format('Y/m/');
|
||||
}
|
||||
|
||||
public static function getCreditStorageDir($invoice_date){
|
||||
return "/credit/".\Carbon::parse($invoice_date)->format('Y/m/');
|
||||
}
|
||||
|
||||
public static function makeInvoiceFilename($invoice_number){
|
||||
|
||||
return "Rechnung-".$invoice_number.".pdf";
|
||||
}
|
||||
|
||||
public static function makeCreditFilename($invoice_number){
|
||||
return "Gutschrift-".$invoice_number.".pdf";
|
||||
}
|
||||
|
||||
public static function isInvoice(ShoppingOrder $shopping_order){
|
||||
return isset($shopping_order->invoice['filename']) ? true : false;
|
||||
}
|
||||
public static function isCredit(UserCredit $user_credit){
|
||||
return isset($user_credit->credit['filename']) ? true : false;
|
||||
}
|
||||
|
||||
public static function getFilename(ShoppingOrder $shopping_order){
|
||||
return isset($shopping_order->invoice['filename']) ? $shopping_order->invoice['filename'] : false;
|
||||
}
|
||||
|
||||
public static function getCreditFilename(UserCredit $user_credit){
|
||||
return isset($user_credit->credit['filename']) ? $user_credit->credit['filename'] : false;
|
||||
}
|
||||
|
||||
public static function getDir(ShoppingOrder $shopping_order){
|
||||
return isset($shopping_order->invoice['dir']) ? $shopping_order->invoice['dir'] : false;
|
||||
}
|
||||
|
||||
public static function getCreditDir(UserCredit $user_credit){
|
||||
return isset($user_credit->credit['dir']) ? $user_credit->credit['dir'] : false;
|
||||
}
|
||||
|
||||
public static function getDownloadURL(ShoppingOrder $shopping_order, $do = false){
|
||||
return route('storage_file', [$shopping_order->id, 'cms_download_file', $do]);
|
||||
}
|
||||
|
||||
public static function getDownloadPath(ShoppingOrder $shopping_order, $full = false){
|
||||
$dir = self::getDir($shopping_order);
|
||||
$filename = self::getFilename($shopping_order);
|
||||
|
|
@ -60,6 +78,15 @@ class Invoice
|
|||
return \Storage::disk('public')->path($dir.$filename);
|
||||
}
|
||||
|
||||
public static function getCreditDownloadPath(UserCredit $user_credit, $full = false){
|
||||
$dir = self::getCreditDir($user_credit);
|
||||
$filename = self::getCreditFilename($user_credit);
|
||||
if(!$full){
|
||||
return $dir.$filename;
|
||||
}
|
||||
return \Storage::disk('public')->path($dir.$filename);
|
||||
}
|
||||
|
||||
public static function sendInvoiceMail($shopping_order){
|
||||
$bcc = [];
|
||||
$billing_email = $shopping_order->shopping_user->billing_email;
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ use Carbon;
|
|||
class UserMarign
|
||||
{
|
||||
|
||||
|
||||
|
||||
public static function getMontlyPrice(User $user, $date = null, $format = false){
|
||||
|
||||
$now = $date ? Carbon::parse($date) : Carbon::now();
|
||||
|
|
@ -50,7 +48,7 @@ class UserMarign
|
|||
$now = $date ? Carbon::parse($date) : Carbon::now();
|
||||
$startDay = $now->startOfMonth()->toDateString();
|
||||
$endDay = $now->endOfMonth()->toDateString();
|
||||
|
||||
|
||||
$sum_net_amount = ShoppingOrderMargin::whereUserId($user->id)
|
||||
->whereBetween('from', [$startDay, $endDay])
|
||||
->wherePaid(true)
|
||||
|
|
@ -64,12 +62,13 @@ class UserMarign
|
|||
}
|
||||
|
||||
|
||||
|
||||
public static function getMontlyPartnerCommission(User $user, $date = null, $format = false){
|
||||
|
||||
$now = $date ? Carbon::parse($date) : Carbon::now();
|
||||
$startDay = $now->startOfMonth()->toDateString();
|
||||
$endDay = $now->endOfMonth()->toDateString();
|
||||
//$now = $date ? Carbon::parse($date) : Carbon::now();
|
||||
$start = Carbon::parse('01.01.2021');
|
||||
$end = Carbon::now();
|
||||
$startDay = $start->startOfMonth()->toDateString();
|
||||
$endDay = $end->endOfMonth()->toDateString();
|
||||
|
||||
$sum_net_amount = ShoppingOrderMargin::whereMSponsorId($user->id)
|
||||
->whereBetween('from', [$startDay, $endDay])
|
||||
|
|
@ -82,6 +81,104 @@ class UserMarign
|
|||
|
||||
return $sum_net_amount;
|
||||
}
|
||||
//monthy amount, sum
|
||||
|
||||
|
||||
public static function getMontlyPartnerCommissionOpen(User $user, $date = null, $format = false){
|
||||
|
||||
//$now = $date ? Carbon::parse($date) : Carbon::now();
|
||||
$start = Carbon::parse('01.01.2021');
|
||||
$end = Carbon::now();
|
||||
$startDay = $start->startOfMonth()->toDateString();
|
||||
$endDay = $end->endOfMonth()->toDateString();
|
||||
|
||||
$sum_net_amount = ShoppingOrderMargin::whereMSponsorId($user->id)
|
||||
->whereBetween('from', [$startDay, $endDay])
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '<', Carbon::now())
|
||||
->sum('net_partner_commission');
|
||||
if($format){
|
||||
$sum_net_amount = Util::formatNumber($sum_net_amount);
|
||||
}
|
||||
|
||||
return $sum_net_amount;
|
||||
}
|
||||
|
||||
public static function getMontlyPartnerCommissionOpenByID($user_id, $date = null, $format = false){
|
||||
|
||||
$sum_net_amount = ShoppingOrderMargin::whereMSponsorId($user_id)
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '<', Carbon::now())
|
||||
->sum('net_partner_commission');
|
||||
if($format){
|
||||
$sum_net_amount = Util::formatNumber($sum_net_amount);
|
||||
}
|
||||
|
||||
return $sum_net_amount;
|
||||
}
|
||||
|
||||
public static function getMontlyPartnerCommissionPending(User $user, $date = null, $format = false){
|
||||
|
||||
//$now = $date ? Carbon::parse($date) : Carbon::now();
|
||||
$start = Carbon::parse('01.01.2021');
|
||||
$end = Carbon::now();
|
||||
$startDay = $start->startOfMonth()->toDateString();
|
||||
$endDay = $end->endOfMonth()->toDateString();
|
||||
|
||||
$sum_net_amount = ShoppingOrderMargin::whereMSponsorId($user->id)
|
||||
->whereBetween('from', [$startDay, $endDay])
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '>=', Carbon::now())
|
||||
->sum('net_partner_commission');
|
||||
if($format){
|
||||
$sum_net_amount = Util::formatNumber($sum_net_amount);
|
||||
}
|
||||
|
||||
return $sum_net_amount;
|
||||
}
|
||||
|
||||
public static function getMontlyPartnerCommissionPendingByID($user_id, $date = null, $format = false){
|
||||
|
||||
$sum_net_amount = ShoppingOrderMargin::whereMSponsorId($user_id)
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '>=', Carbon::now())
|
||||
->sum('net_partner_commission');
|
||||
if($format){
|
||||
$sum_net_amount = Util::formatNumber($sum_net_amount);
|
||||
}
|
||||
|
||||
return $sum_net_amount;
|
||||
}
|
||||
|
||||
|
||||
public static function getOrderFromPartnerCommissionByID($user_id){
|
||||
|
||||
$ShoppingOrderMargins = ShoppingOrderMargin::whereMSponsorId($user_id)
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '<', Carbon::now())
|
||||
->get();
|
||||
|
||||
return $ShoppingOrderMargins;
|
||||
}
|
||||
|
||||
public static function getOrderFromPartnerCommissionPendingByID($user_id){
|
||||
|
||||
$ShoppingOrderMargins = ShoppingOrderMargin::whereMSponsorId($user_id)
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '>=', Carbon::now())
|
||||
->get();
|
||||
|
||||
return $ShoppingOrderMargins;
|
||||
}
|
||||
}
|
||||
|
|
@ -168,6 +168,7 @@ class Yard extends Cart
|
|||
$yard_commission = new Commission();
|
||||
$yard_commission = $content->reduce(function ($yard_commission, CartItem $cartItem) {
|
||||
$price_net = $cartItem->price / ((100 + $cartItem->taxRate) / 100);
|
||||
//nicht vom Staffelrabatt -> extra Rabatt / Provision
|
||||
if($cartItem->options->single_commission){
|
||||
$value_commission = $price_net / 100 * $cartItem->options->value_commission;
|
||||
$partner_commission = $price_net / 100 * $cartItem->options->partner_commission;
|
||||
|
|
@ -175,7 +176,7 @@ class Yard extends Cart
|
|||
$price_net_commission = ($cartItem->qty * $price_net) - ($cartItem->qty * $value_commission);
|
||||
$yard_commission->single_price_net += ($cartItem->qty * $price_net);
|
||||
$yard_commission->single_value_commission += ($cartItem->qty * $value_commission);
|
||||
if($this->user->user_level->partner_provision){
|
||||
if($this->user->sponsorHasCommisson()){
|
||||
$yard_commission->single_partner_commission += ($cartItem->qty * $partner_commission);
|
||||
}
|
||||
$yard_commission->single_price_net_commission += $price_net_commission;
|
||||
|
|
@ -227,13 +228,17 @@ class Yard extends Cart
|
|||
}
|
||||
$last_limit = $user_level_margin->price_from;
|
||||
if($balance != 0){
|
||||
$commission = 0;
|
||||
if($this->user->sponsorHasCommisson()){
|
||||
$commission = $user_level_margin->commission;
|
||||
}
|
||||
$margin->add($user_level_margin->price_from, [
|
||||
'price_net' => $price_net,
|
||||
'range' => $range,
|
||||
'rest_amount' => $rest_amount,
|
||||
'balance' => $balance,
|
||||
'trading_margin'=> $user_level_margin->trading_margin,
|
||||
'commission'=> $user_level_margin->commission,
|
||||
'commission'=> $commission,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue