Compare commits
5 Commits
feature/Ad
...
feature/Ma
| Author | SHA1 | Date | |
|---|---|---|---|
| a0ee7cccd3 | |||
| 25e2883e9c | |||
| 23dd62550d | |||
| e3b49ebbb3 | |||
| 7d7507411d |
73
app/Exports/V3/Mission/Report/Machine/machineReport.php
Normal file
73
app/Exports/V3/Mission/Report/Machine/machineReport.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\V3\Mission\Report\Machine;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithDrawings;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Exception;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
|
||||
class machineReport implements FromView, ShouldAutoSize, WithDrawings, WithEvents
|
||||
{
|
||||
public function __construct(private array $data)
|
||||
{
|
||||
}
|
||||
|
||||
public function view(): View
|
||||
{ $exportRows = [];
|
||||
|
||||
foreach ($this->data as $r) {
|
||||
$exportRows[] = [
|
||||
'city_name' => $r->c_name ?? '',
|
||||
'province_name' => $r->p_name ?? '',
|
||||
'missions' => $r->missions ?? 0,
|
||||
'distance' => (int) ($r->distance ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
return view('v3.Reports.Mission.Report.Machine.ActivityReport', [
|
||||
'rows' => $exportRows,
|
||||
]);
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$event->sheet->getDelegate()->setRightToLeft(true);
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function drawings(): array
|
||||
{
|
||||
$drawing = new Drawing();
|
||||
$drawing->setName('Logo');
|
||||
$drawing->setDescription('This is my logo');
|
||||
$drawing->setPath(public_path('/dist/logo.png'));
|
||||
$drawing->setWidth(50);
|
||||
$drawing->setHeight(50);
|
||||
$drawing->setOffsetX(5);
|
||||
$drawing->setOffsetY(5);
|
||||
$drawing->setCoordinates('A1');
|
||||
|
||||
$drawing2 = new Drawing();
|
||||
$drawing2->setName('Logo');
|
||||
$drawing2->setDescription('This is my logo');
|
||||
$drawing2->setPath(public_path('/dist/141icon.png'));
|
||||
$drawing2->setWidth(50);
|
||||
$drawing2->setHeight(50);
|
||||
$drawing2->setOffsetX(5);
|
||||
$drawing2->setOffsetY(5);
|
||||
$drawing2->setCoordinates('D1');
|
||||
|
||||
return [$drawing, $drawing2];
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,9 @@ class CountryReport implements FromView, ShouldAutoSize, WithDrawings, WithEvent
|
||||
$national = [
|
||||
'province_name' => $name,
|
||||
'total' => (int) ($r->total ?? 0),
|
||||
'khareg_mahdode' => (int) ($r->khareg_mahdode ?? 0),
|
||||
'gps' => (int) ($r->gps ?? 0),
|
||||
'durations' => (int) ($r->durations ?? 0),
|
||||
'khareg_mahdode' => (int) ($r->khareg_mahdode ?? 0),
|
||||
'bafarayand_saeti' => (int) ($r->far_h ?? 0),
|
||||
'bafarayand_rozaneh' => (int) ($r->far_d ?? 0),
|
||||
'bedon_bafarayand_saeti' => (int) ($r->un_far_h ?? 0),
|
||||
@@ -50,9 +50,9 @@ class CountryReport implements FromView, ShouldAutoSize, WithDrawings, WithEvent
|
||||
}
|
||||
|
||||
$grid[$pid]['total'] = (int) ($r->total ?? 0);
|
||||
$grid[$pid]['khareg_mahdode'] = ($r->khareg_mahdode ?? 0);
|
||||
$grid[$pid]['gps'] = (int) ($r->gps ?? 0);
|
||||
$grid[$pid]['durations'] = (int) ($r->durations ?? 0);
|
||||
$grid[$pid]['khareg_mahdode'] = ($r->khareg_mahdode ?? 0);
|
||||
$grid[$pid]['bafarayand_saeti'] = (int) ($r->far_h ?? 0);
|
||||
$grid[$pid]['bafarayand_rozaneh'] = (int) ($r->far_d ?? 0);
|
||||
$grid[$pid]['bedon_bafarayand_saeti'] = (int) ($r->un_far_h ?? 0);
|
||||
|
||||
@@ -30,9 +30,9 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithDrawings, WithEven
|
||||
$province = [
|
||||
'city_name' => $name,
|
||||
'total' => (int) ($r->total ?? 0),
|
||||
'khareg_mahdode' => (int) ($r->khareg_mahdode ?? 0),
|
||||
'gps' => (int) ($r->gps ?? 0),
|
||||
'durations' => (int) ($r->durations ?? 0),
|
||||
'khareg_mahdode' => (int) ($r->khareg_mahdode ?? 0),
|
||||
'bafarayand_saeti' => (int) ($r->far_h ?? 0),
|
||||
'bafarayand_rozaneh' => (int) ($r->far_d ?? 0),
|
||||
'bedon_bafarayand_saeti' => (int) ($r->un_far_h ?? 0),
|
||||
@@ -51,9 +51,9 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithDrawings, WithEven
|
||||
}
|
||||
|
||||
$grid[$cid]['total'] = (int) ($r->total ?? 0);
|
||||
$grid[$cid]['khareg_mahdode'] = ($r->khareg_mahdode ?? 0);
|
||||
$grid[$cid]['gps'] = (int) ($r->gps ?? 0);
|
||||
$grid[$cid]['durations'] = (int) ($r->durations ?? 0);
|
||||
$grid[$cid]['khareg_mahdode'] = ($r->khareg_mahdode ?? 0);
|
||||
$grid[$cid]['bafarayand_saeti'] = (int) ($r->far_h ?? 0);
|
||||
$grid[$cid]['bafarayand_rozaneh'] = (int) ($r->far_d ?? 0);
|
||||
$grid[$cid]['bedon_bafarayand_saeti'] = (int) ($r->un_far_h ?? 0);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Mission\Report;
|
||||
|
||||
use App\Exports\V3\Mission\Report\Machine\machineReport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Province;
|
||||
use App\Services\Cartables\Mission\Report\ReportMachineService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use PhpOffice\PhpSpreadsheet\Exception;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class ReportMachineController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function activity(Request $request, ReportMachineService $reportMachineService): JsonResponse
|
||||
{
|
||||
return $this->successResponse([
|
||||
'activities' => $reportMachineService->activity($request),
|
||||
'provinces' => Province::all(['id', 'name_fa']),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
public function excelActivity(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse
|
||||
{
|
||||
$data = $reportMachineService->activity($request);
|
||||
$name = 'گزارش کل تردد یک ماشین '.verta()->now()->format('Y-m-d H-i').'.xlsx';
|
||||
|
||||
return Excel::download(new machineReport($data), $name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Requests\V3\Mission\ControlUnit;
|
||||
use App\Enums\MissionStates;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class FinishRequest extends FormRequest
|
||||
{
|
||||
@@ -28,4 +29,25 @@ class FinishRequest extends FormRequest
|
||||
'end_km' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
public function after(): array
|
||||
{
|
||||
return [
|
||||
function (Validator $validator) {
|
||||
$mission = $this->mission;
|
||||
if (strtotime($this->time) < strtotime($mission->start_time)) {
|
||||
$validator->errors()->add(
|
||||
'time',
|
||||
'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.'
|
||||
);
|
||||
}
|
||||
if ($this->end_km < $mission->km) {
|
||||
$validator->errors()->add(
|
||||
'end_km',
|
||||
'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.'
|
||||
);
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cartables\Mission\Report;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\MissionViolation;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ReportMachineService
|
||||
{
|
||||
public function activity(Request $request): array
|
||||
{
|
||||
$code = $request->machine_code;
|
||||
$from = $request->from_date ?? today()->startOfDay();
|
||||
$to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay();
|
||||
|
||||
$sql = "
|
||||
SELECT*
|
||||
m.city_name AS c.name,
|
||||
m.city_id AS c_id,
|
||||
m.province_name AS p_name,
|
||||
m.province_id AS p_id,
|
||||
COUNT(m.id) As missions,
|
||||
(SUM(m.end_km)-SUM(m.km)) AS distance
|
||||
|
||||
FROM missions m
|
||||
WHERE m.machine_code = :machineCode
|
||||
AND m.created_at >= :from
|
||||
AND m.created_at <= :to;
|
||||
";
|
||||
|
||||
return DB::select($sql, [
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'machineCode' => $code,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>گزارش کل تردد های یک ماشین </title>
|
||||
|
||||
<style>
|
||||
table,
|
||||
th,
|
||||
td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body dir="rtl" style="text-align: center;">
|
||||
@php
|
||||
// show a dot if key missing or value is 0/empty
|
||||
function cell($row, $key) {
|
||||
return array_key_exists($key, $row) ? ($row[$key] ?: '0') : '0';
|
||||
}
|
||||
@endphp
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="4"
|
||||
style="background-color: #DAEEF3;text-align: center;border-right: 1px solid black;font-weight:bolder;">
|
||||
تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="4"
|
||||
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;">
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="4"
|
||||
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;">
|
||||
گزارش ماشین های ماموریت رفته
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th rowspan="1"
|
||||
style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">
|
||||
استان
|
||||
</th>
|
||||
<th rowspan="1"
|
||||
style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">
|
||||
شهر
|
||||
</th>
|
||||
<th rowspan="1"
|
||||
style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">
|
||||
تعداد ماموریت </th>
|
||||
<th rowspan="1"
|
||||
style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">
|
||||
جمع کارکرد
|
||||
</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach ($rows as $item)
|
||||
<tr>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['province_name'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['city_name'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['missions'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['distance'] ?? '-' }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -93,9 +93,9 @@
|
||||
<tr>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['province_name'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['total'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['khareg_mahdode'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['gps'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['durations'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['khareg_mahdode'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['bafarayand_saeti'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['bafarayand_rozaneh'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['bedon_bafarayand_saeti'] ?? '-' }}</td>
|
||||
|
||||
@@ -93,9 +93,9 @@
|
||||
<tr>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['city_name'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['total'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['khareg_mahdode'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['gps'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['durations'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['khareg_mahdode'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['bafarayand_saeti'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['bafarayand_rozaneh'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['bedon_bafarayand_saeti'] ?? '-' }}</td>
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Http\Controllers\V3\Dashboard\Harim\TechnicalDeputyController;
|
||||
use App\Http\Controllers\V3\Dashboard\ItemsManagementController;
|
||||
use App\Http\Controllers\V3\Dashboard\Mission\ControlUnitController;
|
||||
use App\Http\Controllers\V3\Dashboard\Mission\DetailController;
|
||||
use App\Http\Controllers\V3\Dashboard\Mission\Report\ReportMachineController;
|
||||
use App\Http\Controllers\V3\Dashboard\Mission\Report\ReportTradodController;
|
||||
use App\Http\Controllers\V3\Dashboard\Mission\Report\ReportViolationController;
|
||||
use App\Http\Controllers\V3\Dashboard\Mission\RequestPortalController;
|
||||
@@ -556,6 +557,14 @@ Route::prefix('missions')
|
||||
Route::get('/country_excel_activity', 'countryExcelActivity')->name('countryExcelActivity');
|
||||
Route::get('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity');
|
||||
});
|
||||
Route::prefix('report_machine')
|
||||
->name('reportsMachine.')
|
||||
->middleware(['permission:mission-report-province|mission-report-country'])
|
||||
->controller(ReportMachineController::class)
|
||||
->group(function () {
|
||||
Route::get('/activity', 'activity')->name('Activity');
|
||||
Route::get('/excel_activity', 'excelActivity')->name('ProvinceActivity');
|
||||
});
|
||||
});
|
||||
|
||||
Route::prefix('harim')
|
||||
|
||||
Reference in New Issue
Block a user