Move charge to under service
This commit is contained in:
@@ -30,58 +30,6 @@ class AdminController extends Controller
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
// @todo Move to reseller
|
||||
public function charge_addedit(Request $request,Charge $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
$request->validate([
|
||||
'account_id' => 'required|exists:accounts,id',
|
||||
'charge_at' => 'required|date',
|
||||
'service_id' => 'required|exists:services,id',
|
||||
'quantity' => 'required|numeric|not_in:0',
|
||||
'amount' => 'required|numeric|min:0.01',
|
||||
'sweep_type' => 'required|numeric|in:'.implode(',',array_keys(Charge::sweep)),
|
||||
'type' => 'required|numeric|in:'.implode(',',array_keys(InvoiceItem::type)),
|
||||
'taxable' => 'nullable|boolean',
|
||||
'description' => 'nullable|string|max:128',
|
||||
]);
|
||||
|
||||
if (! $o->exists) {
|
||||
$o->site_id = config('site')->site_id;
|
||||
$o->user_id = Auth::id();
|
||||
$o->active = TRUE;
|
||||
}
|
||||
|
||||
$o->forceFill($request->only(['account_id','charge_at','service_id','quantity','amount','sweep_type','type','taxable','description']));
|
||||
$o->save();
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success','Charge recorded: '.$o->id);
|
||||
}
|
||||
|
||||
return view('theme.backend.adminlte.a.charge.addedit')
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
// @todo Move to reseller
|
||||
public function charge_pending_account(Request $request,Account $o)
|
||||
{
|
||||
return view('theme.backend.adminlte.a.charge.widgets.pending')
|
||||
->with('list',$o->charges->where('active',TRUE)->where('processed',NULL)->except($request->exclude));
|
||||
}
|
||||
|
||||
/**
|
||||
* List unprocessed charges
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
// @todo Move to reseller
|
||||
public function charge_unprocessed()
|
||||
{
|
||||
return view('theme.backend.adminlte.a.charge.unprocessed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Record payments on an account.
|
||||
*
|
||||
|
@@ -8,6 +8,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
@@ -17,7 +18,7 @@ use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
use App\Http\Requests\ServiceChangeRequest;
|
||||
use App\Http\Requests\{ChargeAdd,ServiceChangeRequest};
|
||||
use App\Mail\{CancelRequest,ChangeRequest};
|
||||
use App\Models\{Charge,Invoice,Product,Service};
|
||||
|
||||
@@ -265,6 +266,49 @@ class ServiceController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a charge to a service/account
|
||||
*
|
||||
* @param ChargeAdd $request
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function charge_addedit(ChargeAdd $request): RedirectResponse
|
||||
{
|
||||
$o = Charge::findOrNew(Arr::get($request->validated(),'id'));
|
||||
|
||||
// Dont update processed charges
|
||||
if ($o->processed)
|
||||
abort(403);
|
||||
|
||||
$o->forceFill(array_merge(Arr::except($request->validated(),['id']),['active'=>TRUE]));
|
||||
$o->save();
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success',sprintf('Charge %s #%d',$o->wasRecentlyCreated ? 'Created' : 'Updated',$o->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a charge to a service/account
|
||||
*
|
||||
* @param Request $request
|
||||
* @return View
|
||||
*/
|
||||
public function charge_edit(Request $request): View
|
||||
{
|
||||
$o = Charge::where('processed',FALSE)
|
||||
->where('id',$request->id)
|
||||
->firstOrFail();
|
||||
|
||||
if (Gate::allows('update',$o)) {
|
||||
return view('theme.backend.adminlte.charge.widget.addedit')
|
||||
->with('o',$o)
|
||||
->with('so',$o->service);
|
||||
}
|
||||
|
||||
abort(403);
|
||||
}
|
||||
|
||||
/**
|
||||
* List all the domains managed by the user
|
||||
*
|
||||
|
46
app/Http/Requests/ChargeAdd.php
Normal file
46
app/Http/Requests/ChargeAdd.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
use App\Models\{Charge,InvoiceItem};
|
||||
|
||||
class ChargeAdd extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Auth::user()
|
||||
->accounts_all
|
||||
->contains(request()->post('account_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
Session::put('charge_add',true);
|
||||
|
||||
return [
|
||||
'id' => 'sometimes|exists:charges,id',
|
||||
'account_id' => 'required|exists:accounts,id',
|
||||
'charge_at' => 'required|date',
|
||||
'service_id' => 'required|exists:services,id',
|
||||
'site_id' => 'required|exists:sites,id',
|
||||
'quantity' => 'required|numeric|not_in:0',
|
||||
'amount' => 'required|numeric|min:0.01',
|
||||
'sweep_type' => 'required|numeric|in:'.implode(',',array_keys(Charge::sweep)),
|
||||
'type' => 'required|numeric|in:'.implode(',',array_keys(InvoiceItem::type)),
|
||||
'taxable' => 'nullable|boolean',
|
||||
'description' => 'nullable|string|min:5|max:128',
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user