|
|
@@ -4,9 +4,11 @@ namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Owner;
|
|
|
use App\OwnerLogisticFeeReport;
|
|
|
+use App\Services\common\ExportService;
|
|
|
use App\Services\OwnerLogisticFeeReportService;
|
|
|
use App\Services\UserService;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Oursdreams\Export\Export;
|
|
|
|
|
|
class OwnerLogisticFeeReportController extends Controller
|
|
|
{
|
|
|
@@ -15,95 +17,72 @@ class OwnerLogisticFeeReportController extends Controller
|
|
|
/* @var UserService $userService */
|
|
|
private $userService;
|
|
|
|
|
|
+ /**
|
|
|
+ * OwnerLogisticFeeReportController constructor.
|
|
|
+ */
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->middleware('auth');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* Display a listing of the resource.
|
|
|
*/
|
|
|
public function index(Request $request)
|
|
|
{
|
|
|
$paginateParams = $request->input();
|
|
|
- $this->service = app('OwnerLogisticFeeReportService');
|
|
|
- $this->userService = app('UserService');
|
|
|
- $permittingOwnerIds = $this->userService->getPermittingOwnerIds(auth()->user());
|
|
|
- if (is_null($request->year) || is_null($request->month)) {
|
|
|
- $date = now()->subMonth()->startOfMonth()->toDateString();
|
|
|
- } else {
|
|
|
- $date = $request->year . '-' . $request->month . '-' . '01';
|
|
|
- }
|
|
|
- if (is_null($request->owner_id)) {
|
|
|
- $owner_id = $permittingOwnerIds[0];
|
|
|
- }else{
|
|
|
- $owner_id = $request->owner_id;
|
|
|
- }
|
|
|
+ list($permittingOwnerIds, $date, $owner_id) = $this->getRequestParams($request);
|
|
|
$reports = $this->service->getRecordPagination($owner_id, $date, $paginateParams);
|
|
|
$recordTotal = $this->service->getRecordTotal($owner_id, $date);
|
|
|
$owner = Owner::query()->selectRaw("name")->find($owner_id);
|
|
|
$owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
|
|
|
- return view('finance.settlementBills.logisticFee.report.index', compact('reports', 'recordTotal', 'paginateParams', 'owners','owner'));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Show the form for creating a new resource.
|
|
|
- *
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
- */
|
|
|
- public function create()
|
|
|
- {
|
|
|
- //
|
|
|
+ return view('finance.settlementBills.logisticFee.report.index', compact('reports', 'recordTotal', 'paginateParams', 'owners', 'owner'));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Store a newly created resource in storage.
|
|
|
- *
|
|
|
- * @param \Illuminate\Http\Request $request
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
- */
|
|
|
- public function store(Request $request)
|
|
|
+ public function export(Request $request)
|
|
|
{
|
|
|
- //
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Display the specified resource.
|
|
|
- *
|
|
|
- * @param \App\OwnerLogisticFeeReport $ownerLogisticFeeReport
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
- */
|
|
|
- public function show(OwnerLogisticFeeReport $ownerLogisticFeeReport)
|
|
|
- {
|
|
|
- //
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Show the form for editing the specified resource.
|
|
|
- *
|
|
|
- * @param \App\OwnerLogisticFeeReport $ownerLogisticFeeReport
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
- */
|
|
|
- public function edit(OwnerLogisticFeeReport $ownerLogisticFeeReport)
|
|
|
- {
|
|
|
- //
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Update the specified resource in storage.
|
|
|
- *
|
|
|
- * @param \Illuminate\Http\Request $request
|
|
|
- * @param \App\OwnerLogisticFeeReport $ownerLogisticFeeReport
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
- */
|
|
|
- public function update(Request $request, OwnerLogisticFeeReport $ownerLogisticFeeReport)
|
|
|
- {
|
|
|
- //
|
|
|
+ list($permittingOwnerIds, $date, $owner_id) = $this->getRequestParams($request);
|
|
|
+ $query = $this->service->getSql($owner_id, $date);
|
|
|
+ if (!$request->exists('checkAllSign')) {
|
|
|
+ $query->whereIn('id', explode(',', $request['data']));
|
|
|
+ }
|
|
|
+ $reports = $query->get();
|
|
|
+ $json = [];
|
|
|
+ foreach ($reports as $report) {
|
|
|
+ $json[] = [
|
|
|
+ $report->logistic->name ?? '',
|
|
|
+ $report->province,
|
|
|
+ $report->initial_weight,
|
|
|
+ $report->initial_amount,
|
|
|
+ $report->additional_weight,
|
|
|
+ $report->additional_amount,
|
|
|
+ $report->fee,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $row = ['快递公司', '地区', '首重', '订单数', '续重', '续重合计', '(省份)合计'];
|
|
|
+ return Export::make($row, $json, "快递费用合计");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Remove the specified resource from storage.
|
|
|
- *
|
|
|
- * @param \App\OwnerLogisticFeeReport $ownerLogisticFeeReport
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
+ * @param Request $request
|
|
|
+ * @return array
|
|
|
*/
|
|
|
- public function destroy(OwnerLogisticFeeReport $ownerLogisticFeeReport)
|
|
|
+ private function getRequestParams(Request $request): array
|
|
|
{
|
|
|
- //
|
|
|
+ $this->service = app('OwnerLogisticFeeReportService');
|
|
|
+ $this->userService = app('UserService');
|
|
|
+ $permittingOwnerIds = $this->userService->getPermittingOwnerIds(auth()->user());
|
|
|
+ if (is_null($request->year) || is_null($request->month)) {
|
|
|
+ $date = now()->subMonth()->startOfMonth()->toDateString();
|
|
|
+ } else {
|
|
|
+ $date = $request->year . '-' . $request->month . '-' . '01';
|
|
|
+ }
|
|
|
+ if (is_null($request->owner_id)) {
|
|
|
+ $owner_id = $permittingOwnerIds[0];
|
|
|
+ } else {
|
|
|
+ $owner_id = $request->owner_id;
|
|
|
+ }
|
|
|
+ return array($permittingOwnerIds, $date, $owner_id);
|
|
|
}
|
|
|
}
|