Rechnungen + Gutschriften
This commit is contained in:
parent
39ef16686a
commit
35ae3da244
33 changed files with 2834 additions and 34 deletions
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue