create function excel and their dependency for damage
This commit is contained in:
67
app/Exports/V3/Damage/DamageCartableReport.php
Normal file
67
app/Exports/V3/Damage/DamageCartableReport.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\V3\Damage;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
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\Style\Alignment;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||||
|
|
||||||
|
class DamageCartableReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
|
||||||
|
|
||||||
|
{
|
||||||
|
public function __construct(private $data){}
|
||||||
|
|
||||||
|
public function view(): View
|
||||||
|
{
|
||||||
|
return view('v3.Reports.Damage.DamageCartableReport', [
|
||||||
|
'data' => $this->data
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerEvents(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
AfterSheet::class => function (AfterSheet $event) {
|
||||||
|
$event->sheet->getDelegate()->setRightToLeft(true);
|
||||||
|
$event->sheet->getDelegate()->getStyle('A:U')->getFont()->setName('Arial');
|
||||||
|
$event->sheet->getDelegate()->getStyle('A:U')
|
||||||
|
->getAlignment()
|
||||||
|
->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
||||||
|
|
||||||
|
$event->sheet->getDelegate()->getStyle('A:U')
|
||||||
|
->getAlignment()
|
||||||
|
->setVertical(Alignment::VERTICAL_CENTER);
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
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('f1');
|
||||||
|
return [$drawing, $drawing2];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,14 +2,19 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\V3;
|
namespace App\Http\Controllers\V3;
|
||||||
|
|
||||||
|
use App\Exports\V3\Damage\DamageCartableReport;
|
||||||
use App\Facades\DataTable\DataTableFacade;
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\V3\Damage\StoreRequest;
|
use App\Http\Requests\V3\Damage\StoreRequest;
|
||||||
use App\Http\Requests\V3\Damage\UpdateRequest;
|
use App\Http\Requests\V3\Damage\UpdateRequest;
|
||||||
use App\Http\Traits\ApiResponse;
|
use App\Http\Traits\ApiResponse;
|
||||||
use App\Models\Damage;
|
use App\Models\Damage;
|
||||||
|
use App\Services\Cartables\Damage\DamageService;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Maatwebsite\Excel\Excel;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Exception;
|
||||||
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||||
|
|
||||||
class DamageManagementController extends Controller
|
class DamageManagementController extends Controller
|
||||||
{
|
{
|
||||||
@@ -17,20 +22,9 @@ class DamageManagementController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*/
|
*/
|
||||||
public function index(Request $request): JsonResponse
|
public function index(Request $request ,DamageService $damageService): JsonResponse
|
||||||
{
|
{
|
||||||
$allowedFilters = ['*'];
|
$data = $damageService->dataTable($request);
|
||||||
$allowedSortings = ['*'];
|
|
||||||
|
|
||||||
$query = Damage::query();
|
|
||||||
|
|
||||||
$data = DataTableFacade::run(
|
|
||||||
$query,
|
|
||||||
$request,
|
|
||||||
allowedFilters: $allowedFilters,
|
|
||||||
allowedSortings: $allowedSortings);
|
|
||||||
|
|
||||||
|
|
||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +65,6 @@ class DamageManagementController extends Controller
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public function update(UpdateRequest $request, Damage $damage): JsonResponse
|
public function update(UpdateRequest $request, Damage $damage): JsonResponse
|
||||||
|
|
||||||
{
|
{
|
||||||
$damage->update([
|
$damage->update([
|
||||||
'title' => $request->title,
|
'title' => $request->title,
|
||||||
@@ -92,4 +85,15 @@ class DamageManagementController extends Controller
|
|||||||
|
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||||
|
*/
|
||||||
|
public function excel(Request $request, DamageService $damageService): BinaryFileResponse
|
||||||
|
{
|
||||||
|
$name = 'آیتم خسارات وارده بر ابنیه فنی' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||||
|
$data = $damageService->datatable($request);
|
||||||
|
return Excel::download(new DamageCartableReport($data['data']), $name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
app/Services/Cartables/Damage/DamageService.php
Normal file
24
app/Services/Cartables/Damage/DamageService.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Cartables\Damage;
|
||||||
|
|
||||||
|
use App\Exceptions\ProhibitedAction;
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
|
use App\Models\Damage;
|
||||||
|
use App\Models\SafetyAndPrivacy;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class DamageService
|
||||||
|
{
|
||||||
|
public function dataTable(Request $request)
|
||||||
|
{
|
||||||
|
return DataTableFacade::run(
|
||||||
|
Damage::query(),
|
||||||
|
$request,
|
||||||
|
allowedFilters: ['*'],
|
||||||
|
allowedSortings: ['*'],
|
||||||
|
allowedSelects: ['title', 'unit', 'base_price', 'status', 'update_time']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
<!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;">
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th colspan="6"
|
||||||
|
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="6"
|
||||||
|
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;">
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th colspan="6"
|
||||||
|
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>
|
||||||
|
<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 ($data as $item)
|
||||||
|
<tr>
|
||||||
|
<td style="border: 1px solid black;text-align: center;">{{ $item['id'] ?? '-' }}</td>
|
||||||
|
<td style="border: 1px solid black;text-align: center;">{{ $item['title'] ?? '-' }}</td>
|
||||||
|
<td style="border: 1px solid black;text-align: center;">{{ $item['unit'] ?? '-' }}</td>
|
||||||
|
<td style="border: 1px solid black;text-align: center;">{{ $item['base_price'] ?? '-' }}</td>
|
||||||
|
<td style="border: 1px solid black;text-align: center;">{{ $item['status'] ?? '-' }}</td>
|
||||||
|
<td style="border: 1px solid black;text-align: center;">{{ $item['update_time'] ?? '-' }}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
@@ -273,6 +273,7 @@ Route::prefix('damages')
|
|||||||
Route::get('/{damage}', 'show')->name('show');
|
Route::get('/{damage}', 'show')->name('show');
|
||||||
Route::post('/{damage}', 'update')->name('update');
|
Route::post('/{damage}', 'update')->name('update');
|
||||||
Route::post('/activate/{damage}', 'activate')->name('activate');
|
Route::post('/activate/{damage}', 'activate')->name('activate');
|
||||||
|
Route::get('/excel', 'excel')->name('excel');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('receipts')
|
Route::prefix('receipts')
|
||||||
|
|||||||
Reference in New Issue
Block a user