inital commit
This commit is contained in:
332
app/Exports/RoadUpgrade/summaryAccidentPerformanceProject.php
Normal file
332
app/Exports/RoadUpgrade/summaryAccidentPerformanceProject.php
Normal file
@@ -0,0 +1,332 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\RoadUpgrade;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use App\Models\ContractSubItems;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Concerns\WithDrawings;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class summaryAccidentPerformanceProject implements FromView, ShouldAutoSize, WithEvents, WithDrawings, WithStyles
|
||||
{
|
||||
public function __construct($fromDate = null, $toDate = null, $province = null, $last_status_id = null)
|
||||
{
|
||||
$this->fromDate = $fromDate ?? null;
|
||||
$this->toDate = $toDate ?? null;
|
||||
$this->province = $province ?? null;
|
||||
$this->last_status_id = $last_status_id ?? null;
|
||||
}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
$query = "SELECT
|
||||
project_title,
|
||||
axis_type_fa,
|
||||
axis_name_fa,
|
||||
unique_code,
|
||||
city_id,
|
||||
city_fa,
|
||||
province_id,
|
||||
province_fa,
|
||||
date_,
|
||||
ROUND(SUM(
|
||||
CASE
|
||||
WHEN operation_type_id1 = 301 THEN (
|
||||
operation_type_amount1 * operation_type_progress1
|
||||
) / 100
|
||||
WHEN operation_type_id2 = 301 THEN (
|
||||
operation_type_amount2 * operation_type_progress2
|
||||
) / 100
|
||||
WHEN operation_type_id3 = 301 THEN (
|
||||
operation_type_amount3 * operation_type_progress3
|
||||
) / 100
|
||||
WHEN operation_type_id4 = 301 THEN (
|
||||
operation_type_amount4 * operation_type_progress4
|
||||
) / 100
|
||||
END
|
||||
),2) AS BotoniDone,
|
||||
ROUND(SUM(
|
||||
CASE
|
||||
WHEN operation_type_id1 = 302 THEN (
|
||||
operation_type_amount1 * operation_type_progress1
|
||||
) / 100
|
||||
WHEN operation_type_id2 = 302 THEN (
|
||||
operation_type_amount2 * operation_type_progress2
|
||||
) / 100
|
||||
WHEN operation_type_id3 = 302 THEN (
|
||||
operation_type_amount3 * operation_type_progress3
|
||||
) / 100
|
||||
WHEN operation_type_id4 = 302 THEN (
|
||||
operation_type_amount4 * operation_type_progress4
|
||||
) / 100
|
||||
END
|
||||
),2) AS FeleziDone,
|
||||
ROUND(SUM(
|
||||
CASE
|
||||
WHEN operation_type_id1 = 303 THEN (
|
||||
operation_type_amount1 * operation_type_progress1
|
||||
) / 100
|
||||
WHEN operation_type_id2 = 303 THEN (
|
||||
operation_type_amount2 * operation_type_progress2
|
||||
) / 100
|
||||
WHEN operation_type_id3 = 303 THEN (
|
||||
operation_type_amount3 * operation_type_progress3
|
||||
) / 100
|
||||
WHEN operation_type_id4 = 303 THEN (
|
||||
operation_type_amount4 * operation_type_progress4
|
||||
) / 100
|
||||
END
|
||||
),2) AS TooliLightingDone,
|
||||
|
||||
ROUND(SUM(
|
||||
CASE
|
||||
WHEN operation_type_id1 = 304 THEN (
|
||||
operation_type_amount1 * operation_type_progress1
|
||||
) / 100
|
||||
WHEN operation_type_id2 = 304 THEN (
|
||||
operation_type_amount2 * operation_type_progress2
|
||||
) / 100
|
||||
WHEN operation_type_id3 = 304 THEN (
|
||||
operation_type_amount3 * operation_type_progress3
|
||||
) / 100
|
||||
WHEN operation_type_id4 = 304 THEN (
|
||||
operation_type_amount4 * operation_type_progress4
|
||||
) / 100
|
||||
END
|
||||
),2) AS NoghteyiLightingDone,
|
||||
ROUND(SUM(
|
||||
CASE
|
||||
WHEN operation_type_id1 = 305 THEN (
|
||||
operation_type_amount1 * operation_type_progress1
|
||||
) / 100
|
||||
WHEN operation_type_id2 = 305 THEN (
|
||||
operation_type_amount2 * operation_type_progress2
|
||||
) / 100
|
||||
WHEN operation_type_id3 = 305 THEN (
|
||||
operation_type_amount3 * operation_type_progress3
|
||||
) / 100
|
||||
WHEN operation_type_id4 = 305 THEN (
|
||||
operation_type_amount4 * operation_type_progress4
|
||||
) / 100
|
||||
END
|
||||
),2) AS AlaemImeniDone,
|
||||
ROUND(SUM(
|
||||
CASE
|
||||
WHEN operation_type_id1 = 306 THEN (
|
||||
operation_type_amount1 * operation_type_progress1
|
||||
) / 100
|
||||
WHEN operation_type_id2 = 306 THEN (
|
||||
operation_type_amount2 * operation_type_progress2
|
||||
) / 100
|
||||
WHEN operation_type_id3 = 306 THEN (
|
||||
operation_type_amount3 * operation_type_progress3
|
||||
) / 100
|
||||
WHEN operation_type_id4 = 306 THEN (
|
||||
operation_type_amount4 * operation_type_progress4
|
||||
) / 100
|
||||
END
|
||||
),2) AS KhatkeshiDone,
|
||||
ROUND(SUM(
|
||||
CASE
|
||||
WHEN operation_type_id1 = 307 THEN (
|
||||
operation_type_amount1 * operation_type_progress1
|
||||
) / 100
|
||||
WHEN operation_type_id2 = 307 THEN (
|
||||
operation_type_amount2 * operation_type_progress2
|
||||
) / 100
|
||||
WHEN operation_type_id3 = 307 THEN (
|
||||
operation_type_amount3 * operation_type_progress3
|
||||
) / 100
|
||||
WHEN operation_type_id4 = 307 THEN (
|
||||
operation_type_amount4 * operation_type_progress4
|
||||
) / 100
|
||||
END
|
||||
),2) AS ShirvaniDone,
|
||||
ROUND(SUM(
|
||||
CASE
|
||||
WHEN operation_type_id1 = 308 THEN (
|
||||
operation_type_amount1 * operation_type_progress1
|
||||
) / 100
|
||||
WHEN operation_type_id2 = 308 THEN (
|
||||
operation_type_amount2 * operation_type_progress2
|
||||
) / 100
|
||||
WHEN operation_type_id3 = 308 THEN (
|
||||
operation_type_amount3 * operation_type_progress3
|
||||
) / 100
|
||||
WHEN operation_type_id4 = 308 THEN (
|
||||
operation_type_amount4 * operation_type_progress4
|
||||
) / 100
|
||||
END
|
||||
),2) AS SayerDone,
|
||||
|
||||
ROUND(AVG(progress_project)) as progress_project
|
||||
FROM(
|
||||
SELECT
|
||||
project_title,
|
||||
axis_type_fa,
|
||||
axis_name_fa,
|
||||
date_,
|
||||
unique_code,
|
||||
city_id,
|
||||
city_fa,
|
||||
province_id,
|
||||
province_fa,
|
||||
operation_type_id1,
|
||||
operation_type_amount1,
|
||||
MAX(operation_type_tonaj1) - MIN(operation_type_tonaj1) AS operation_type_tonaj1,
|
||||
MAX(operation_type_progress1) - MIN(operation_type_progress1) AS operation_type_progress1,
|
||||
operation_type_id2,
|
||||
operation_type_amount2,
|
||||
MAX(operation_type_tonaj2) - MIN(operation_type_tonaj2) AS operation_type_tonaj2,
|
||||
MAX(operation_type_progress2) - MIN(operation_type_progress2) AS operation_type_progress2,
|
||||
operation_type_id3,
|
||||
operation_type_amount3,
|
||||
MAX(operation_type_tonaj3) - MIN(operation_type_tonaj3) AS operation_type_tonaj3,
|
||||
MAX(operation_type_progress3) - MIN(operation_type_progress3) AS operation_type_progress3,
|
||||
operation_type_id4,
|
||||
operation_type_amount4,
|
||||
MAX(operation_type_tonaj4) - MIN(operation_type_tonaj4) AS operation_type_tonaj4,
|
||||
MAX(operation_type_progress4) - MIN(operation_type_progress4) AS operation_type_progress4,
|
||||
MAX(progress_project) - MIN(progress_project) AS progress_project
|
||||
FROM (
|
||||
SELECT project_type_id,
|
||||
unique_code,
|
||||
last_date_update AS date_,
|
||||
city_id,
|
||||
city_fa,
|
||||
province_id,
|
||||
province_fa,
|
||||
project_title,
|
||||
axis_type_fa,
|
||||
axis_name_fa,
|
||||
operation_type_id1,
|
||||
operation_type_amount1,
|
||||
operation_type_progress1,
|
||||
operation_type_tonaj1,
|
||||
operation_type_id2,
|
||||
operation_type_amount2,
|
||||
operation_type_progress2,
|
||||
operation_type_tonaj2,
|
||||
operation_type_id3,
|
||||
operation_type_amount3,
|
||||
operation_type_progress3,
|
||||
operation_type_tonaj3,
|
||||
operation_type_id4,
|
||||
operation_type_amount4,
|
||||
operation_type_progress4,
|
||||
operation_type_tonaj4,
|
||||
progress_project
|
||||
FROM contract_subitems
|
||||
UNION
|
||||
SELECT project_type_id,
|
||||
unique_code,
|
||||
last_date_update AS date_,
|
||||
city_id,
|
||||
city_fa,
|
||||
province_id,
|
||||
province_fa,
|
||||
project_title,
|
||||
axis_type_fa,
|
||||
axis_name_fa,
|
||||
operation_type_id1,
|
||||
operation_type_amount1,
|
||||
operation_type_progress1,
|
||||
operation_type_tonaj1,
|
||||
operation_type_id2,
|
||||
operation_type_amount2,
|
||||
operation_type_progress2,
|
||||
operation_type_tonaj2,
|
||||
operation_type_id3,
|
||||
operation_type_amount3,
|
||||
operation_type_progress3,
|
||||
operation_type_tonaj3,
|
||||
operation_type_id4,
|
||||
operation_type_amount4,
|
||||
operation_type_progress4,
|
||||
operation_type_tonaj4,
|
||||
progress_project
|
||||
FROM contract_sub_items_histories
|
||||
) AS merged_table
|
||||
WHERE project_type_id = 3
|
||||
GROUP BY unique_code
|
||||
) AS mreged_statistics_table WHERE ( progress_project > 0 OR operation_type_progress1 > 0 OR operation_type_progress2 > 0 OR operation_type_progress3 > 0 OR operation_type_progress4 > 0 ) ";
|
||||
|
||||
|
||||
|
||||
if ($this->province) {
|
||||
$query .= " AND province_id = {$this->province}";
|
||||
}
|
||||
|
||||
if ($this->fromDate) {
|
||||
$query .= " AND date_ BETWEEN '{$this->fromDate} 00:00:00' AND '{$this->toDate} 23:59:59'";
|
||||
}
|
||||
|
||||
$query .= " GROUP BY unique_code
|
||||
ORDER BY province_id ASC;";
|
||||
|
||||
$data = DB::select(DB::raw($query));
|
||||
|
||||
return view('excel.Upgrade.summaryAccidentPerformanceProject', [
|
||||
'array' => $data,
|
||||
'fromFa' => $fromDate ?? null,
|
||||
'toFa' => $toDate ?? null
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function(AfterSheet $event) {
|
||||
$event->sheet->getDelegate()->setRightToLeft(true);
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function drawings()
|
||||
{
|
||||
$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('B1');
|
||||
return [$drawing, $drawing2];
|
||||
}
|
||||
|
||||
public function styles(Worksheet $sheet)
|
||||
{
|
||||
|
||||
return [
|
||||
// Style the first row as bold text.
|
||||
'A:BA' => [
|
||||
'font' => [
|
||||
'name' => 'B Nazanin'
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user