Rechnungen + Gutschriften
This commit is contained in:
parent
39ef16686a
commit
35ae3da244
33 changed files with 2834 additions and 34 deletions
|
|
@ -61,6 +61,34 @@ class FileController extends Controller
|
|||
|
||||
}
|
||||
|
||||
if ($disk === 'credit'){
|
||||
$UserCredit = \App\Models\UserCredit::findOrFail($id);
|
||||
$filename = Invoice::getCreditFilename($UserCredit);
|
||||
$path = Invoice::getCreditDownloadPath($UserCredit);
|
||||
if (!Storage::disk('public')->exists($path)) {
|
||||
return Response::make('File no found.', 404);
|
||||
}
|
||||
$file = Storage::disk('public')->get($path);
|
||||
$type = Storage::disk('public')->mimeType($path);
|
||||
|
||||
if($do === 'download'){
|
||||
return Response::make($file, 200)
|
||||
->header("Content-Type", $type)
|
||||
->header('Content-disposition', 'attachment; filename="'.$filename.'"');
|
||||
/* $full_path = Invoice::getDownloadPath($shopping_order, true);
|
||||
$he
|
||||
if (file_exists($full_path)) {
|
||||
return Response::download($full_path, $filename);
|
||||
}*/
|
||||
}
|
||||
if($do === 'stream'){
|
||||
return Response::make($file, 200)
|
||||
->header("Content-Type", $type)
|
||||
->header('Content-disposition','filename="'.$filename.'"');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
138
app/Http/Controllers/PaymentCreditController.php
Normal file
138
app/Http/Controllers/PaymentCreditController.php
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\Invoice;
|
||||
use App\Services\Payment;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingOrderMargin;
|
||||
use App\Models\UserCredit;
|
||||
use App\Repositories\CreditRepository;
|
||||
|
||||
class PaymentCreditController extends Controller
|
||||
{
|
||||
|
||||
private $startYear;
|
||||
private $endYear;
|
||||
private $rangeYears;
|
||||
private $activeYear;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->startYear = 2021;
|
||||
$this->endYear = date('Y');
|
||||
$this->rangeYears = range($this->startYear, $this->endYear);
|
||||
$this->activeYear = $this->endYear;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->setActiveYears();
|
||||
$date1 = Carbon::parse('01.01.'.$this->activeYear." 00:00:00")->format('Y-m-d H:i:s');
|
||||
$date2 = Carbon::parse('31.12.'.$this->activeYear." 23:59:59")->toDateString();
|
||||
|
||||
|
||||
$ShoppingOrderMargins = ShoppingOrderMargin::join('users', 'm_sponsor_id', '=', 'users.id')
|
||||
->groupBy('m_sponsor_id')
|
||||
->join('user_accounts', 'account_id', '=', 'user_accounts.id')
|
||||
->select('users.id as user_id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '<', Carbon::now())
|
||||
->get();
|
||||
|
||||
$ShoppingOrderMarginPendings = ShoppingOrderMargin::join('users', 'm_sponsor_id', '=', 'users.id')
|
||||
->groupBy('m_sponsor_id')
|
||||
->join('user_accounts', 'account_id', '=', 'user_accounts.id')
|
||||
->select('users.id as user_id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '>=', Carbon::now())
|
||||
->get();
|
||||
|
||||
|
||||
$data = [
|
||||
'years' => $this->rangeYears,
|
||||
'active_year' => $this->activeYear,
|
||||
'ShoppingOrderMargins' => $ShoppingOrderMargins,
|
||||
'ShoppingOrderMarginPendings' => $ShoppingOrderMarginPendings,
|
||||
];
|
||||
return view('admin.payment.credit.index', $data);
|
||||
}
|
||||
|
||||
public function create(){
|
||||
$data = Request::all();
|
||||
if(!isset($data['userid'])){
|
||||
abort(404);
|
||||
}
|
||||
if(isset($data['action'])){
|
||||
if($data['action'] === 'create_credit'){
|
||||
$user = User::findOrFail($data['userid']);
|
||||
$invoice_repo = new CreditRepository($user);
|
||||
$invoice_repo->create($data);
|
||||
return redirect($data['back']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function setActiveYears(){
|
||||
if(Request::get('filter_sales_year')){
|
||||
$this->activeYear = Request::get('filter_sales_year');
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable(){
|
||||
|
||||
$this->setActiveYears();
|
||||
$date1 = Carbon::parse('01.01.'.$this->activeYear)->format('Y-m-d');
|
||||
$date2 = Carbon::parse('31.12.'.$this->activeYear)->format('Y-m-d');
|
||||
|
||||
$query = UserCredit::with('user', 'user.account')->select('user_credits.*')
|
||||
//::with('shopping_user', )->select('shopping_orders.*')
|
||||
//->where('paid', '=', 1)
|
||||
->whereBetween('date', [$date1, $date2]);
|
||||
//->orderBy('created_at', 'DESC');
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
|
||||
->addColumn('total', function (UserCredit $UserCredit) {
|
||||
return $UserCredit->getFormattedTotal();
|
||||
})
|
||||
->addColumn('user_margins', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
if($UserCredit->user_margins){
|
||||
foreach($UserCredit->user_margins as $user_margin){
|
||||
$ret .= $user_margin->firstname."/".$user_margin->lastname."/".$user_margin->reference."/".$user_margin->created_at."<br>";
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
})
|
||||
/* ->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})*/
|
||||
->addColumn('credit', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
if(Invoice::isCredit($UserCredit)){
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a>';
|
||||
}else{
|
||||
$ret = "-";
|
||||
}
|
||||
return $ret;
|
||||
})
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('status', 'status $1')
|
||||
->orderColumn('total', 'total $1')
|
||||
->rawColumns(['shipping_order', 'total', 'credit', 'user_margins'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
101
app/Http/Controllers/PaymentInvoiceController.php
Normal file
101
app/Http/Controllers/PaymentInvoiceController.php
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\Invoice;
|
||||
use App\Services\Payment;
|
||||
use App\Models\ShoppingOrder;
|
||||
|
||||
|
||||
class PaymentInvoiceController extends Controller
|
||||
{
|
||||
|
||||
private $startYear;
|
||||
private $endYear;
|
||||
private $rangeYears;
|
||||
private $activeYear;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->startYear = 2021;
|
||||
$this->endYear = date('Y');
|
||||
$this->rangeYears = range($this->startYear, $this->endYear);
|
||||
$this->activeYear = $this->endYear;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->setActiveYears();
|
||||
$date1 = Carbon::parse('01.01.'.$this->activeYear." 00:00:00")->format('Y-m-d H:i:s');
|
||||
$date2 = Carbon::parse('31.12.'.$this->activeYear." 23:59:59")->toDateString();
|
||||
|
||||
$data = [
|
||||
'years' => $this->rangeYears,
|
||||
'active_year' => $this->activeYear,
|
||||
];
|
||||
return view('admin.payment.invoice.index', $data);
|
||||
}
|
||||
|
||||
private function setActiveYears(){
|
||||
if(Request::get('filter_sales_year')){
|
||||
$this->activeYear = Request::get('filter_sales_year');
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable(){
|
||||
|
||||
$this->setActiveYears();
|
||||
$date1 = Carbon::parse('01.01.'.$this->activeYear." 00:00:00")->format('Y-m-d H:i:s');
|
||||
$date2 = Carbon::parse('31.12.'.$this->activeYear." 23:59:59")->toDateString();
|
||||
|
||||
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')
|
||||
->where('shopping_orders.auth_user_id', '!=', NULL) //::with('shopping_user', )->select('shopping_orders.*')
|
||||
->where('mode', '=', 'live')
|
||||
//->where('paid', '=', 1)
|
||||
->whereBetween('created_at', [$date1, $date2]);
|
||||
//->orderBy('created_at', 'DESC');
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<a href="' . route('admin_sales_customers_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getFormattedTotalShipping()." €";
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->created_at->format("d.m.Y");
|
||||
})
|
||||
->addColumn('shipping_order', function (ShoppingOrder $ShoppingOrder) {
|
||||
$ret = "";
|
||||
foreach($ShoppingOrder->shopping_order_items as $shopping_order_item){
|
||||
$ret .= $shopping_order_item->product->name."<br>";
|
||||
}
|
||||
return $ret;
|
||||
})
|
||||
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
|
||||
$ret = "";
|
||||
if(Invoice::isInvoice($ShoppingOrder)){
|
||||
$ret .= '<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a>';
|
||||
}else{
|
||||
$ret = "-";
|
||||
}
|
||||
return $ret;
|
||||
})
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->orderColumn('shipped', 'shipped $1')
|
||||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
->rawColumns(['id', 'shipping_order', 'txaction', 'invoice'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Models\Setting;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Models\ShoppingUser;
|
||||
|
|
@ -245,9 +246,7 @@ class SalesController extends Controller
|
|||
return '';
|
||||
})
|
||||
|
||||
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->orderColumn('member_id', 'member_id $1')
|
||||
->orderColumn('shipped', 'shipped $1')
|
||||
|
|
@ -266,6 +265,42 @@ class SalesController extends Controller
|
|||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
$shopping_order->shipped = $data['shipped'];
|
||||
$shopping_order->save();
|
||||
|
||||
if($shopping_order->getAPIShippedType() === 'sent' || $shopping_order->getAPIShippedType() === 'close'){
|
||||
if(!$shopping_order->shipped_at){
|
||||
$shopping_order->shipped_at = now();
|
||||
$shopping_order->save();
|
||||
//set to oder_margin
|
||||
if($shopping_order->shopping_order_margin && $shopping_order->shopping_order_margin->hasPartnerCommission()){
|
||||
$days = Setting::getContentBySlug('pending_partner_commissions_in_days');
|
||||
$days = $days ? $days : 20;
|
||||
$partner_commission_pending_to = $shopping_order->shipped_at;
|
||||
$partner_commission_pending_to->addDays($days);
|
||||
$shopping_order->shopping_order_margin->partner_commission_pending_to = $partner_commission_pending_to;
|
||||
$shopping_order->shopping_order_margin->save();
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$shopping_order->shipped_at = null;
|
||||
$shopping_order->save();
|
||||
if($shopping_order->shopping_order_margin && $shopping_order->shopping_order_margin->hasPartnerCommission()){
|
||||
$shopping_order->shopping_order_margin->partner_commission_pending_to = null;
|
||||
$shopping_order->shopping_order_margin->save();
|
||||
}
|
||||
}
|
||||
if($shopping_order->getAPIShippedType() === 'cancel'){
|
||||
if($shopping_order->shopping_order_margin){
|
||||
$shopping_order->shopping_order_margin->cancellation = true;
|
||||
$shopping_order->shopping_order_margin->save();
|
||||
}
|
||||
}else{
|
||||
if($shopping_order->shopping_order_margin && $shopping_order->shopping_order_margin->cancellation){
|
||||
$shopping_order->shopping_order_margin->cancellation = false;
|
||||
$shopping_order->shopping_order_margin->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if($data['action'] === 'store_txaction' && isset($data['txaction']) && isset($data['payment_id'])){
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ class OrderController extends Controller
|
|||
|
||||
public function list($for, $id=null)
|
||||
{
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$shopping_user = null;
|
||||
$delivery_id = null;
|
||||
|
|
|
|||
53
app/Http/Controllers/User/RevenueController.php
Normal file
53
app/Http/Controllers/User/RevenueController.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\User;
|
||||
use Request;
|
||||
use Carbon;
|
||||
use App\Models\ShoppingOrder;
|
||||
|
||||
|
||||
class RevenueController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$start = 2021;
|
||||
$end = date('Y');
|
||||
$years = range($start, $end);
|
||||
|
||||
if(Request::get('filter_sales_year')){
|
||||
$active_year = Request::get('filter_sales_year');
|
||||
}else{
|
||||
$active_year = $end;
|
||||
}
|
||||
|
||||
$date1 = Carbon::parse('01.01.'.$active_year." 00:00:00")->format('Y-m-d H:i:s');
|
||||
$date2 = Carbon::parse('31.12.'.$active_year." 23:59:59")->toDateString();
|
||||
|
||||
|
||||
$values = ShoppingOrder::where('shopping_orders.auth_user_id', '!=', NULL) //::with('shopping_user', )->select('shopping_orders.*')
|
||||
->where('mode', '=', 'live')
|
||||
->where('paid', '=', 1)
|
||||
->whereHas('shopping_order_items', function($q) {
|
||||
|
||||
$q->where('product_id', 34)->OrWhere('product_id', 35)->OrWhere('product_id', 36)->OrWhere('product_id', 67)->OrWhere('product_id', 69);
|
||||
})
|
||||
->whereBetween('created_at', [$date1, $date2])
|
||||
->get();
|
||||
|
||||
$data = [
|
||||
'years' => $years,
|
||||
'active_year' => $active_year,
|
||||
'values' => $values,
|
||||
];
|
||||
return view('user.revenue.index', $data);
|
||||
}
|
||||
}
|
||||
|
|
@ -93,6 +93,10 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereSubtotalShipping($value)
|
||||
* @property string|null $total_without_credit
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereTotalWithoutCredit($value)
|
||||
* @property array|null $invoice
|
||||
* @property \Illuminate\Support\Carbon|null $shipped_at
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereInvoice($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereShippedAt($value)
|
||||
*/
|
||||
class ShoppingOrder extends Model
|
||||
{
|
||||
|
|
@ -127,12 +131,14 @@ class ShoppingOrder extends Model
|
|||
'wp_notice',
|
||||
'mode',
|
||||
'shipped',
|
||||
'shipped_at',
|
||||
'tracking'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'wp_notice' => 'array',
|
||||
'invoice' => 'array',
|
||||
'shipped_at' => 'datetime',
|
||||
];
|
||||
|
||||
public static $shippedTypes = [
|
||||
|
|
@ -159,9 +165,6 @@ class ShoppingOrder extends Model
|
|||
10 => 'danger',
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
public function shopping_user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ShoppingUser','shopping_user_id');
|
||||
|
|
@ -298,9 +301,6 @@ class ShoppingOrder extends Model
|
|||
return formatNumber($this->attributes['total_shipping']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function getItemsCount(){
|
||||
$count = 0;
|
||||
if($this->shopping_order_items){
|
||||
|
|
|
|||
|
|
@ -52,6 +52,11 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereUserId($value)
|
||||
* @mixin \Eloquent
|
||||
* @property \Illuminate\Support\Carbon|null $partner_commission_pending_to
|
||||
* @property bool|null $partner_commission_paid
|
||||
* @property-read User|null $m_sponsor
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin wherePartnerCommissionPaid($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin wherePartnerCommissionPendingTo($value)
|
||||
*/
|
||||
class ShoppingOrderMargin extends Model
|
||||
{
|
||||
|
|
@ -68,7 +73,9 @@ class ShoppingOrderMargin extends Model
|
|||
'net_partner_commission' => 'float',
|
||||
'paid' => 'bool',
|
||||
'cancellation' => 'bool',
|
||||
'status' => 'int'
|
||||
'status' => 'int',
|
||||
'partner_commission_pending_to' => 'datetime',
|
||||
'partner_commission_paid' => 'bool',
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
|
|
@ -88,6 +95,8 @@ class ShoppingOrderMargin extends Model
|
|||
'paid',
|
||||
'cancellation',
|
||||
'status',
|
||||
'partner_commission_pending_to',
|
||||
'partner_commission_paid',
|
||||
'content'
|
||||
];
|
||||
|
||||
|
|
@ -105,4 +114,17 @@ class ShoppingOrderMargin extends Model
|
|||
{
|
||||
return $this->belongsTo(User::class, 'm_sponsor_id');
|
||||
}
|
||||
|
||||
|
||||
public function m_sponsor()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'm_sponsor_id');
|
||||
}
|
||||
|
||||
public function hasPartnerCommission(){
|
||||
if($this->m_sponsor_id || $this->net_partner_commission > 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
116
app/Models/UserCredit.php
Normal file
116
app/Models/UserCredit.php
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Class UserCredit
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $auth_user_id
|
||||
* @property float|null $net
|
||||
* @property float|null $tax_rate
|
||||
* @property float|null $tax
|
||||
* @property float|null $total
|
||||
* @property string|null $credit
|
||||
* @property string|null $user_margins
|
||||
* @property bool $paid_out
|
||||
* @property bool $cancellation
|
||||
* @property int $status
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property User $user
|
||||
* @package App\Models
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereAuthUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereCancellation($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereCredit($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereNet($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit wherePaidOut($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereStatus($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereTax($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereTaxRate($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereTotal($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereUserMargins($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class UserCredit extends Model
|
||||
{
|
||||
protected $table = 'user_credits';
|
||||
|
||||
protected $casts = [
|
||||
'auth_user_id' => 'int',
|
||||
'net' => 'float',
|
||||
'tax_rate' => 'float',
|
||||
'tax' => 'float',
|
||||
'total' => 'float',
|
||||
'paid_out' => 'bool',
|
||||
'cancellation' => 'bool',
|
||||
'status' => 'int',
|
||||
'credit' => 'array',
|
||||
'user_margins' => 'object'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'auth_user_id',
|
||||
'net',
|
||||
'tax_rate',
|
||||
'tax',
|
||||
'total',
|
||||
'date',
|
||||
'credit',
|
||||
'user_margins',
|
||||
'paid_out',
|
||||
'cancellation',
|
||||
'status'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(\App\User::class, 'auth_user_id');
|
||||
}
|
||||
|
||||
public function getDateAttribute($value)
|
||||
{
|
||||
if(!$value){
|
||||
return "";
|
||||
}
|
||||
return Carbon::parse($value)->format(\Util::formatDateDB());
|
||||
}
|
||||
|
||||
|
||||
public function setDateAttribute( $value ) {
|
||||
$this->attributes['date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
||||
}
|
||||
public function getDateRaw(){
|
||||
return isset($this->attributes['date']) ? $this->attributes['date'] : NULL;
|
||||
}
|
||||
|
||||
public function getFormattedTax()
|
||||
{
|
||||
return formatNumber($this->attributes['tax']);
|
||||
}
|
||||
|
||||
public function getFormattedNet()
|
||||
{
|
||||
return formatNumber($this->attributes['net']);
|
||||
}
|
||||
|
||||
public function getFormattedTotal()
|
||||
{
|
||||
return formatNumber($this->attributes['total']);
|
||||
}
|
||||
|
||||
}
|
||||
122
app/Repositories/CreditRepository.php
Normal file
122
app/Repositories/CreditRepository.php
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use PDF;
|
||||
use Storage;
|
||||
use App\Services\Invoice;
|
||||
use App\Services\MyPDFMerger;
|
||||
use App\Services\UserMarign;
|
||||
use App\Models\UserCredit;
|
||||
|
||||
use App\User;
|
||||
|
||||
class CreditRepository extends BaseRepository {
|
||||
|
||||
public function __construct(User $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function create($request = [])
|
||||
{
|
||||
//need invoice $data
|
||||
$credit_number = isset($request['credit_number']) ? $request['credit_number'] : Invoice::getInvoiceNumber();
|
||||
$credit_date = isset($request['credit_date']) ? $request['credit_date'] : \Carbon::now()->format("d.m.Y");
|
||||
$credit_send_mail = isset($request['credit_send_mail']) ? true: false;
|
||||
$credit_number = Invoice::createInvoiceNumber($credit_number, $credit_date);
|
||||
|
||||
$user_credits = $this->makeUserCredit();
|
||||
|
||||
$data = [
|
||||
'user' => $this->model,
|
||||
'credit_date' => $credit_date,
|
||||
'credit_number' => $credit_number,
|
||||
'user_credits' => $user_credits,
|
||||
];
|
||||
|
||||
$pdf = PDF::loadView('pdf.credit', $data);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
|
||||
$dir = Invoice::getCreditStorageDir($credit_date);
|
||||
|
||||
if(!Storage::disk('public')->exists( $dir )){
|
||||
Storage::disk('public')->makeDirectory($dir); //creates directory
|
||||
}
|
||||
$path = Storage::disk('public')->getAdapter()->getPathPrefix();
|
||||
$filename = Invoice::makeCreditFilename($credit_number);
|
||||
|
||||
$pdf->save($path.$dir.$filename);
|
||||
|
||||
$pdfMerger = new MyPDFMerger();
|
||||
$pdfMerger->addPDF($path.$dir.$filename);
|
||||
$file = $pdfMerger->myMerge('string', $filename, 'template_invoice_de');
|
||||
Storage::disk('public')->put($dir.$filename, $file);
|
||||
|
||||
|
||||
$credit_file = [
|
||||
'filename' => $filename,
|
||||
'dir' => $dir,
|
||||
'disk' => 'public',
|
||||
'invoice_number' => $credit_number,
|
||||
'credit_date' => $credit_date,
|
||||
];
|
||||
UserCredit::create([
|
||||
'auth_user_id' => $this->model->id,
|
||||
'net' => $user_credits->net,
|
||||
'tax_rate' => $user_credits->tax_rate,
|
||||
'tax' => $user_credits->tax,
|
||||
'total' => $user_credits->total,
|
||||
'date' => $credit_date,
|
||||
'credit' => $credit_file,
|
||||
'user_margins' => $user_credits->margins,
|
||||
]);
|
||||
|
||||
|
||||
if($credit_send_mail){
|
||||
//Invoice::sendInvoiceMail($this->model);
|
||||
}
|
||||
//Invoice::makeNextInvoiceNumber();
|
||||
return true;
|
||||
//return $pdf->stream('invoice.pdf');
|
||||
//return $this->output($path.$dir, $filename);
|
||||
}
|
||||
|
||||
private function makeUserCredit(){
|
||||
|
||||
$ret = new \stdClass();
|
||||
$ret->net = 0;
|
||||
$UserMarigns = UserMarign::getOrderFromPartnerCommissionByID($this->model->id);
|
||||
foreach($UserMarigns as $UserMarign){
|
||||
$margin = new \stdClass();
|
||||
$margin->id = $UserMarign->id;
|
||||
$margin->net = $UserMarign->net_partner_commission;
|
||||
$margin->reference = $UserMarign->shopping_order->getLastShoppingPayment('reference');
|
||||
$margin->firstname = $UserMarign->shopping_order->shopping_user->billing_firstname;
|
||||
$margin->lastname = $UserMarign->shopping_order->shopping_user->billing_lastname;
|
||||
$margin->created_at = $UserMarign->shopping_order->created_at->format("d.m.Y");
|
||||
$ret->margins[] = $margin;
|
||||
$ret->net += $UserMarign->net_partner_commission;
|
||||
}
|
||||
/* taxable_sales //user tax
|
||||
1 //umsatzsteuerpflichtig
|
||||
2 // nicht umsatzsteuerpflichtig
|
||||
*/
|
||||
if($this->model->account){
|
||||
$ret->taxable = $this->model->account->taxable_sales == 2 ? false : false;
|
||||
if($ret->taxable){
|
||||
$ret->tax_rate = config('app.main_tax_number');
|
||||
$ret->total = round($ret->net * config('app.main_tax'), 2);
|
||||
$ret->tax = $ret->total - $ret->net;
|
||||
|
||||
}else{
|
||||
$ret->tax_rate = 0;
|
||||
$ret->total = $ret->net;
|
||||
$ret->tax = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,6 +148,12 @@ class User extends Authenticatable
|
|||
return $this->belongsTo('App\User', 'm_sponsor');
|
||||
}
|
||||
|
||||
public function sponsorHasCommisson(){
|
||||
if($this->user_sponsor && $this->user_sponsor->user_level && $this->user_sponsor->user_level->partner_provision){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function files(){
|
||||
return $this->hasMany('App\Models\File', 'user_id', '');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue