|
|
@@ -8,6 +8,7 @@ use App\DischargeTask;
|
|
|
use App\Filters\DischargeTaskFilters;
|
|
|
use App\Services\common\ExportService;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
class FacilitatorController extends Controller
|
|
|
{
|
|
|
@@ -16,7 +17,9 @@ class FacilitatorController extends Controller
|
|
|
// 服务商基础设置
|
|
|
public function index(Request $request)
|
|
|
{
|
|
|
- // 权限 ***
|
|
|
+ if (!Gate::allows('服务商-查询')) {
|
|
|
+ return redirect(url('/'));
|
|
|
+ }
|
|
|
$facilitators = Facilitator::query()->select(['id', 'name', 'created_at'])->orderByDesc('id')->paginate($request['paginate'] ?? 50);
|
|
|
return view('maintenance.facilitator.index', compact('facilitators'));
|
|
|
}
|
|
|
@@ -24,9 +27,12 @@ class FacilitatorController extends Controller
|
|
|
// 服务商对账单
|
|
|
public function statementIndex(Request $request, DischargeTaskFilters $filters)
|
|
|
{
|
|
|
- // 权限 ***
|
|
|
- $facilitatorStatements = DischargeTask::query()->with('facilitator')
|
|
|
- ->select(['id', 'discharge_provider_id', 'expenditure_amount', 'expenditure_unit', 'expenditure_unit_price', 'expenditure_total_cost', 'expenditure_remark', 'created_at'])
|
|
|
+ if (!Gate::allows('服务商-对账单-查询')) {
|
|
|
+ return redirect(url('/'));
|
|
|
+ }
|
|
|
+ $facilitatorStatements = DischargeTask::query()->with('facilitator')
|
|
|
+ ->whereNotNull('facilitator_id')
|
|
|
+ ->select(['id', 'facilitator_id', 'expenditure_amount', 'expenditure_unit', 'expenditure_unit_price', 'expenditure_total_cost', 'expenditure_remark', 'created_at'])
|
|
|
->filter($filters)->orderByDesc('id')->paginate($request['paginate'] ?? 50);
|
|
|
$facilitators = Facilitator::query()->get();
|
|
|
return view('transport.discharge.facilitator.index', compact('facilitatorStatements', 'facilitators'));
|
|
|
@@ -44,7 +50,7 @@ class FacilitatorController extends Controller
|
|
|
|
|
|
public function storeApi(Request $request)
|
|
|
{
|
|
|
- // 权限 ***
|
|
|
+ $this->gate('服务商-创建');
|
|
|
$facilitator = Facilitator::query()->create($request->all());
|
|
|
$this->success($facilitator);
|
|
|
}
|
|
|
@@ -66,7 +72,7 @@ class FacilitatorController extends Controller
|
|
|
|
|
|
public function updateApi(Request $request)
|
|
|
{
|
|
|
- // 权限 ***
|
|
|
+ $this->gate('服务商-编辑');
|
|
|
$facilitator = Facilitator::query()->where('id', $request['id'])->update($request->only(['name']));
|
|
|
if ($facilitator) $this->success(Facilitator::query()->find($request['id']));
|
|
|
$this->error('更新失败');
|
|
|
@@ -80,6 +86,7 @@ class FacilitatorController extends Controller
|
|
|
|
|
|
public function destroyApi(Request $request)
|
|
|
{
|
|
|
+ $this->gate('服务商-删除');
|
|
|
$count = Facilitator::query()->where('id', $request['id'])->delete();
|
|
|
if ($count > 0) $this->success('删除成功');
|
|
|
$this->error('删除失败');
|
|
|
@@ -89,12 +96,14 @@ class FacilitatorController extends Controller
|
|
|
public function exportStatement(Request $request, DischargeTaskFilters $filters)
|
|
|
{
|
|
|
// 权限 ***
|
|
|
+ $this->gate('服务商-对账单-查询');
|
|
|
$dischargeTasks = DischargeTask::query()->with('facilitator')
|
|
|
- ->select(['id', 'discharge_provider_id', 'expenditure_amount', 'expenditure_unit', 'expenditure_unit_price', 'expenditure_total_cost', 'expenditure_remark', 'created_at'])
|
|
|
+ ->whereNotNull('facilitator_id')
|
|
|
+ ->select(['id', 'facilitator_id', 'expenditure_amount', 'expenditure_unit', 'expenditure_unit_price', 'expenditure_total_cost', 'expenditure_remark', 'created_at'])
|
|
|
->filter($filters)->orderByDesc('id')->get();
|
|
|
$row = ['日期', '服务商', '数量', '单位', '单价', '总金额合计'];
|
|
|
$json = app('DischargeTaskService')->getStatementsJson($dischargeTasks);
|
|
|
- return app(ExportService::class)->json($row, $json, "卸货结算报表");
|
|
|
+ return app(ExportService::class)->json($row, $json, "服务商对账单报表");
|
|
|
}
|
|
|
|
|
|
}
|