Gutschriften manuell hinzufügen, Yard 0& tax
This commit is contained in:
parent
e670b92f5d
commit
c02fffd883
24 changed files with 497 additions and 68 deletions
|
|
@ -2,13 +2,19 @@
|
|||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Models\UserCreditMargin as ModelsUserCreditMargin;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\Util;
|
||||
use App\Services\Credit;
|
||||
use App\Services\Payment;
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\ShoppingOrderMargin;
|
||||
use App\Models\UserCreditMargin;
|
||||
use App\Repositories\CreditRepository;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PaymentCreditController extends Controller
|
||||
{
|
||||
|
|
@ -30,39 +36,40 @@ class PaymentCreditController extends Controller
|
|||
|
||||
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 = $this->makeData();
|
||||
return view('admin.payment.credit.index', $data);
|
||||
}
|
||||
|
||||
$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 store(){
|
||||
$data = Request::all();
|
||||
|
||||
if(isset($data['action']) && $data['action'] === 'add-user-credit'){
|
||||
$add_credit_error = false;
|
||||
if(!isset($data['member_id']) || !$user = User::find($data['member_id'])){
|
||||
$add_credit_error = 'Vertriebspartner nicht gefunden';
|
||||
}
|
||||
if(!isset($data['credit'])){
|
||||
$add_credit_error = 'Bitte Betrag eingeben';
|
||||
}
|
||||
if(!isset($data['message'])){
|
||||
$add_credit_error = 'Bitte Mitteilung eingeben';
|
||||
}
|
||||
if($add_credit_error){
|
||||
$data = $this->makeData();
|
||||
$data['add_credit_error'] = $add_credit_error;
|
||||
return view('admin.payment.credit.index', $data);
|
||||
}
|
||||
|
||||
$credit = Util::reFormatNumber($data['credit']);
|
||||
$credit = number_format($credit, 2, '.', '');
|
||||
|
||||
Payment::addUserCreditMargin($user, $credit, 3, $data['message']);
|
||||
\Session()->flash('alert-success', "Guthaben hinzugefügt");
|
||||
}
|
||||
|
||||
return redirect(route('admin_payments_credit'));
|
||||
}
|
||||
|
||||
public function create(){
|
||||
|
|
@ -86,8 +93,67 @@ class PaymentCreditController extends Controller
|
|||
return back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function makeData(){
|
||||
$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();
|
||||
|
||||
$UserCreditMargins = UserCreditMargin::wherePaid(false)->get();
|
||||
$ShoppingOrderMarginUserIds = ShoppingOrderMargin::select('m_sponsor_id')->groupBy('m_sponsor_id')
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '<', Carbon::now())
|
||||
->get()->pluck('m_sponsor_id')->toArray();
|
||||
|
||||
$onlyUserCreditMargins = [];
|
||||
foreach($UserCreditMargins as $key => $UserCreditMargin){
|
||||
if(!in_array($UserCreditMargin->user_id, $ShoppingOrderMarginUserIds)){
|
||||
if(isset($onlyUserCreditMargins[$UserCreditMargin->user_id])){
|
||||
$onlyUserCreditMargins[$UserCreditMargin->user_id]['sum'] += $UserCreditMargin->credit;
|
||||
$onlyUserCreditMargins[$UserCreditMargin->user_id]['entries'][$UserCreditMargin->id] = $UserCreditMargin;
|
||||
}else{
|
||||
$onlyUserCreditMargins[$UserCreditMargin->user_id] = [
|
||||
'user_id' => $UserCreditMargin->user->id,
|
||||
'first_name' => $UserCreditMargin->user->account->first_name,
|
||||
'last_name' => $UserCreditMargin->user->account->last_name,
|
||||
'email' => $UserCreditMargin->user->email,
|
||||
'sum' => $UserCreditMargin->credit,
|
||||
'entries' => [$UserCreditMargin->id => $UserCreditMargin],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'years' => $this->rangeYears,
|
||||
'active_year' => $this->activeYear,
|
||||
'ShoppingOrderMargins' => $ShoppingOrderMargins,
|
||||
'ShoppingOrderMarginPendings' => $ShoppingOrderMarginPendings,
|
||||
'onlyUserCreditMargins' => $onlyUserCreditMargins,
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function setActiveYears(){
|
||||
|
|
@ -96,6 +162,20 @@ class PaymentCreditController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
public function delete($id, $del){
|
||||
|
||||
if($del === 'user_credit_margin'){
|
||||
$UserCreditMargin = UserCreditMargin::findOrFail($id);
|
||||
if($deleteTime = $UserCreditMargin->deleteTime()){
|
||||
$UserCreditMargin->delete();
|
||||
\Session()->flash('alert-success', "Guthaben ist gelöscht");
|
||||
}else{
|
||||
\Session()->flash('alert-error', "Guthaben kann nicht gelöscht werden");
|
||||
}
|
||||
}
|
||||
return redirect(route('admin_payments_credit'));
|
||||
}
|
||||
|
||||
public function datatable(){
|
||||
|
||||
$this->setActiveYears();
|
||||
|
|
@ -121,6 +201,12 @@ class PaymentCreditController extends Controller
|
|||
$ret .= $user_margin->firstname."/".$user_margin->lastname."/".$user_margin->reference."/".$user_margin->created_at."<br>";
|
||||
}
|
||||
}
|
||||
if($UserCredit->user_credits){
|
||||
foreach($UserCredit->user_credits as $user_credit){
|
||||
$ret .= nl2br($user_credit->message)." / ".$user_credit->created_at."<br>";
|
||||
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
})
|
||||
/* ->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue