154 lines
No EOL
6 KiB
PHP
154 lines
No EOL
6 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
use Carbon;
|
|
use Request;
|
|
use App\User;
|
|
use App\Services\Credit;
|
|
use App\Models\UserCredit;
|
|
use App\Models\ShoppingOrderMargin;
|
|
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['action'])){
|
|
if($data['action'] === 'create_credit'){
|
|
if(!isset($data['userid'])){
|
|
abort(404);
|
|
}
|
|
$user = User::findOrFail($data['userid']);
|
|
$invoice_repo = new CreditRepository($user);
|
|
$invoice_repo->create($data);
|
|
\Session()->flash('alert-success', "Gutschrift erstellt");
|
|
return redirect($data['back']);
|
|
}
|
|
if($data['action'] === 'user-credit-status'){
|
|
$UserCredit = UserCredit::findOrFail($data['id']);
|
|
$UserCredit->status = $data['status'];
|
|
$UserCredit->save();
|
|
\Session()->flash('alert-success', "Status gespeichert");
|
|
return 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(Credit::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;
|
|
})
|
|
|
|
->addColumn('status', function (UserCredit $UserCredit) {
|
|
return '<a href="#" data-toggle="modal" data-target="#modals-load-content" data-modal="modal-lg"
|
|
data-id="'.$UserCredit->id.'" data-route="'.route('modal_load').'" data-action="user-credit-status" data-view="">
|
|
<span class="badge badge-pill badge-'.$UserCredit->getStatusColor().'">'.$UserCredit->getStatusType().' <span class="ion ion-md-cash"></span></span>
|
|
</a>';
|
|
})
|
|
|
|
|
|
->orderColumn('id', 'id $1')
|
|
->orderColumn('status', 'status $1')
|
|
->orderColumn('total', 'total $1')
|
|
->rawColumns(['shipping_order', 'total', 'credit', 'status', 'user_margins'])
|
|
->make(true);
|
|
}
|
|
} |