trip report

This commit is contained in:
Pringgosutono
2025-09-02 09:17:56 +07:00
parent 64d7ce4f65
commit cf6594a5da
4 changed files with 825 additions and 389 deletions

View File

@ -11,10 +11,12 @@ use Validator;
use Auth;
use App\Responses;
use App\Helper;
use App\Models\Vehicles;
use App\Models\Devices;
use App\Models\VehiclesDetail;
use App\Models\Users;
use Maatwebsite\Excel\Facades\Excel;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class ReportsController extends Controller
{
@ -30,5 +32,150 @@ class ReportsController extends Controller
return view('menu_v1.reports.vehicle_trips', $data);
}
public function api_report_vehicle_trips_list(Request $req)
{
// Validate input
// date in unix datetime format
// dd($req->type);
$rules = [
// 'from_date' => 'required|date',
// 'to_date' => 'required|date|after_or_equal:from_date',
'type' => 'nullable|in:report,list', // enum "report", "list". nullable default "list"
];
$isValidInput = Validator::make($req->all(), $rules);
if (!$isValidInput->passes()) {
$apiResp = Responses::bad_input($isValidInput->messages()->first());
return new Response($apiResp, $apiResp["meta"]["code"]);
}
$from_date = $req->input('from_date');
$to_date = $req->input('to_date');
// $from_date = 1756054800;
// $to_date = 1756745940;
try {
$q = "
WITH trips AS (
SELECT
t.*,
-- mark the start of a trip when ignition=4 and previous ignition <> 4
CASE
WHEN ignition = 4
AND LAG(ignition, 1, 0) OVER (PARTITION BY vhc_id ORDER BY crt_d) <> 4
THEN 1 ELSE 0
END AS trip_start
FROM t_gps_tracks t
WHERE
t.latitude IS NOT NULL
AND t.longitude IS NOT NULL
AND t.action = 'location'
AND t.crt_d BETWEEN ? AND ?
)
, numbered AS (
SELECT
*,
-- assign a trip_id by cumulative sum of trip_start
SUM(trip_start) OVER (PARTITION BY vhc_id ORDER BY crt_d) AS trip_id
FROM trips
)
SELECT
v.id,
coalesce(max(a.trip_id), 0) numOfTrip,
SUM(pre_milleage) AS total_milleage,
v.name, v.nopol1
FROM
t_vehicles v
left join numbered a on a.vhc_id = v.id
WHERE v.dlt is null
GROUP BY v.id
ORDER BY v.id;
";
$d = [$from_date, $to_date];
$list = DB::select($q, $d);
// RETURN 1 - LIST
if($req->type != 'report'){
$apiResp = Responses::success("success list vehicles report");
$apiResp["data"] = $list;
return new Response($apiResp, $apiResp["meta"]["code"]);
}
// RETURN 2 - REPORT
if($req->type == 'report'){
$headings = ['Name', 'License Plate', 'Number of Trip', 'Total Mileage'];
$export = new class($list, $headings) implements FromArray, WithHeadings {
private $list;
private $headings;
public function __construct($list, $headings)
{
$this->list = $list;
$this->headings = $headings;
}
public function array(): array
{
return array_map(function ($item) {
return [
$item->name,
$item->nopol1,
$item->numOfTrip,
$item->total_milleage,
];
}, $this->list);
}
public function headings(): array
{
return $this->headings;
}
// Start table from A3
public function startCell(): string
{
return 'A3';
}
// Add title & border styling
public function styles(Worksheet $sheet)
{
$tgl0 = date('d-m-Y', $GLOBALS['from_date']);
$tgl1 = date('d-m-Y', $GLOBALS['to_date']);
// Title in A1
$sheet->setCellValue('A1', 'Vehicle Trip Report $tgl0 until $tgl1');
$sheet->mergeCells('A1:D1'); // Merge across 4 columns
$sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
$sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
// Get last row
$lastRow = $this->list->count() + 3; // 3 = heading row
$range = "A3:D{$lastRow}";
// Add borders
$sheet->getStyle($range)->getBorders()->getAllBorders()
->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN);
// Bold headings
$sheet->getStyle('A3:D3')->getFont()->setBold(true);
return [];
}
};
return Excel::download($export, 'trip_report.xlsx');
}
} catch (\Exception $e) {
$apiResp = Responses::error($e->getMessage());
return new Response($apiResp, $apiResp["meta"]["code"]);
// return Responses::json(Responses::SERVER_ERROR, 'An error occurred while generating the report.', (object)[]);
}
}
}

View File

@ -17,6 +17,7 @@
"laravel/framework": "^9.0.0",
"laravel/tinker": "^2.5",
"laravel/ui": "^4.0",
"maatwebsite/excel": "^3.1",
"spatie/laravel-permission": "^6.20",
"yajra/laravel-datatables": "^9.0"
},

591
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "1d471cd31c444b2d18a5d42b8df9a0ca",
"content-hash": "01c0c9e02caa82e92dd9b4d028602130",
"packages": [
{
"name": "asm89/stack-cors",
@ -262,6 +262,162 @@
],
"time": "2024-02-09T16:56:22+00:00"
},
{
"name": "composer/pcre",
"version": "3.3.2",
"source": {
"type": "git",
"url": "https://github.com/composer/pcre.git",
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0"
},
"conflict": {
"phpstan/phpstan": "<1.11.10"
},
"require-dev": {
"phpstan/phpstan": "^1.12 || ^2",
"phpstan/phpstan-strict-rules": "^1 || ^2",
"phpunit/phpunit": "^8 || ^9"
},
"type": "library",
"extra": {
"phpstan": {
"includes": [
"extension.neon"
]
},
"branch-alias": {
"dev-main": "3.x-dev"
}
},
"autoload": {
"psr-4": {
"Composer\\Pcre\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
}
],
"description": "PCRE wrapping library that offers type-safe preg_* replacements.",
"keywords": [
"PCRE",
"preg",
"regex",
"regular expression"
],
"support": {
"issues": "https://github.com/composer/pcre/issues",
"source": "https://github.com/composer/pcre/tree/3.3.2"
},
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://github.com/composer",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
"type": "tidelift"
}
],
"time": "2024-11-12T16:29:46+00:00"
},
{
"name": "composer/semver",
"version": "3.4.4",
"source": {
"type": "git",
"url": "https://github.com/composer/semver.git",
"reference": "198166618906cb2de69b95d7d47e5fa8aa1b2b95"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/semver/zipball/198166618906cb2de69b95d7d47e5fa8aa1b2b95",
"reference": "198166618906cb2de69b95d7d47e5fa8aa1b2b95",
"shasum": ""
},
"require": {
"php": "^5.3.2 || ^7.0 || ^8.0"
},
"require-dev": {
"phpstan/phpstan": "^1.11",
"symfony/phpunit-bridge": "^3 || ^7"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.x-dev"
}
},
"autoload": {
"psr-4": {
"Composer\\Semver\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nils Adermann",
"email": "naderman@naderman.de",
"homepage": "http://www.naderman.de"
},
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
},
{
"name": "Rob Bast",
"email": "rob.bast@gmail.com",
"homepage": "http://robbast.nl"
}
],
"description": "Semver library that offers utilities, version constraint parsing and validation.",
"keywords": [
"semantic",
"semver",
"validation",
"versioning"
],
"support": {
"irc": "ircs://irc.libera.chat:6697/composer",
"issues": "https://github.com/composer/semver/issues",
"source": "https://github.com/composer/semver/tree/3.4.4"
},
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://github.com/composer",
"type": "github"
}
],
"time": "2025-08-20T19:15:30+00:00"
},
{
"name": "dflydev/dot-access-data",
"version": "v3.0.3",
@ -706,6 +862,67 @@
],
"time": "2025-03-06T22:45:56+00:00"
},
{
"name": "ezyang/htmlpurifier",
"version": "v4.18.0",
"source": {
"type": "git",
"url": "https://github.com/ezyang/htmlpurifier.git",
"reference": "cb56001e54359df7ae76dc522d08845dc741621b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/cb56001e54359df7ae76dc522d08845dc741621b",
"reference": "cb56001e54359df7ae76dc522d08845dc741621b",
"shasum": ""
},
"require": {
"php": "~5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0"
},
"require-dev": {
"cerdic/css-tidy": "^1.7 || ^2.0",
"simpletest/simpletest": "dev-master"
},
"suggest": {
"cerdic/css-tidy": "If you want to use the filter 'Filter.ExtractStyleBlocks'.",
"ext-bcmath": "Used for unit conversion and imagecrash protection",
"ext-iconv": "Converts text to and from non-UTF-8 encodings",
"ext-tidy": "Used for pretty-printing HTML"
},
"type": "library",
"autoload": {
"files": [
"library/HTMLPurifier.composer.php"
],
"psr-0": {
"HTMLPurifier": "library/"
},
"exclude-from-classmap": [
"/library/HTMLPurifier/Language/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1-or-later"
],
"authors": [
{
"name": "Edward Z. Yang",
"email": "admin@htmlpurifier.org",
"homepage": "http://ezyang.com"
}
],
"description": "Standards compliant HTML filter written in PHP",
"homepage": "http://htmlpurifier.org/",
"keywords": [
"html"
],
"support": {
"issues": "https://github.com/ezyang/htmlpurifier/issues",
"source": "https://github.com/ezyang/htmlpurifier/tree/v4.18.0"
},
"time": "2024-11-01T03:51:45+00:00"
},
{
"name": "fruitcake/laravel-cors",
"version": "v2.2.0",
@ -2344,6 +2561,272 @@
],
"time": "2024-09-21T08:32:55+00:00"
},
{
"name": "maatwebsite/excel",
"version": "3.1.67",
"source": {
"type": "git",
"url": "https://github.com/SpartnerNL/Laravel-Excel.git",
"reference": "e508e34a502a3acc3329b464dad257378a7edb4d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/e508e34a502a3acc3329b464dad257378a7edb4d",
"reference": "e508e34a502a3acc3329b464dad257378a7edb4d",
"shasum": ""
},
"require": {
"composer/semver": "^3.3",
"ext-json": "*",
"illuminate/support": "5.8.*||^6.0||^7.0||^8.0||^9.0||^10.0||^11.0||^12.0",
"php": "^7.0||^8.0",
"phpoffice/phpspreadsheet": "^1.30.0",
"psr/simple-cache": "^1.0||^2.0||^3.0"
},
"require-dev": {
"laravel/scout": "^7.0||^8.0||^9.0||^10.0",
"orchestra/testbench": "^6.0||^7.0||^8.0||^9.0||^10.0",
"predis/predis": "^1.1"
},
"type": "library",
"extra": {
"laravel": {
"aliases": {
"Excel": "Maatwebsite\\Excel\\Facades\\Excel"
},
"providers": [
"Maatwebsite\\Excel\\ExcelServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Maatwebsite\\Excel\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Patrick Brouwers",
"email": "patrick@spartner.nl"
}
],
"description": "Supercharged Excel exports and imports in Laravel",
"keywords": [
"PHPExcel",
"batch",
"csv",
"excel",
"export",
"import",
"laravel",
"php",
"phpspreadsheet"
],
"support": {
"issues": "https://github.com/SpartnerNL/Laravel-Excel/issues",
"source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.67"
},
"funding": [
{
"url": "https://laravel-excel.com/commercial-support",
"type": "custom"
},
{
"url": "https://github.com/patrickbrouwers",
"type": "github"
}
],
"time": "2025-08-26T09:13:16+00:00"
},
{
"name": "maennchen/zipstream-php",
"version": "3.1.2",
"source": {
"type": "git",
"url": "https://github.com/maennchen/ZipStream-PHP.git",
"reference": "aeadcf5c412332eb426c0f9b4485f6accba2a99f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/aeadcf5c412332eb426c0f9b4485f6accba2a99f",
"reference": "aeadcf5c412332eb426c0f9b4485f6accba2a99f",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"ext-zlib": "*",
"php-64bit": "^8.2"
},
"require-dev": {
"brianium/paratest": "^7.7",
"ext-zip": "*",
"friendsofphp/php-cs-fixer": "^3.16",
"guzzlehttp/guzzle": "^7.5",
"mikey179/vfsstream": "^1.6",
"php-coveralls/php-coveralls": "^2.5",
"phpunit/phpunit": "^11.0",
"vimeo/psalm": "^6.0"
},
"suggest": {
"guzzlehttp/psr7": "^2.4",
"psr/http-message": "^2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"ZipStream\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paul Duncan",
"email": "pabs@pablotron.org"
},
{
"name": "Jonatan Männchen",
"email": "jonatan@maennchen.ch"
},
{
"name": "Jesse Donat",
"email": "donatj@gmail.com"
},
{
"name": "András Kolesár",
"email": "kolesar@kolesar.hu"
}
],
"description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.",
"keywords": [
"stream",
"zip"
],
"support": {
"issues": "https://github.com/maennchen/ZipStream-PHP/issues",
"source": "https://github.com/maennchen/ZipStream-PHP/tree/3.1.2"
},
"funding": [
{
"url": "https://github.com/maennchen",
"type": "github"
}
],
"time": "2025-01-27T12:07:53+00:00"
},
{
"name": "markbaker/complex",
"version": "3.0.2",
"source": {
"type": "git",
"url": "https://github.com/MarkBaker/PHPComplex.git",
"reference": "95c56caa1cf5c766ad6d65b6344b807c1e8405b9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/95c56caa1cf5c766ad6d65b6344b807c1e8405b9",
"reference": "95c56caa1cf5c766ad6d65b6344b807c1e8405b9",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
"phpcompatibility/php-compatibility": "^9.3",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
"squizlabs/php_codesniffer": "^3.7"
},
"type": "library",
"autoload": {
"psr-4": {
"Complex\\": "classes/src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Baker",
"email": "mark@lange.demon.co.uk"
}
],
"description": "PHP Class for working with complex numbers",
"homepage": "https://github.com/MarkBaker/PHPComplex",
"keywords": [
"complex",
"mathematics"
],
"support": {
"issues": "https://github.com/MarkBaker/PHPComplex/issues",
"source": "https://github.com/MarkBaker/PHPComplex/tree/3.0.2"
},
"time": "2022-12-06T16:21:08+00:00"
},
{
"name": "markbaker/matrix",
"version": "3.0.1",
"source": {
"type": "git",
"url": "https://github.com/MarkBaker/PHPMatrix.git",
"reference": "728434227fe21be27ff6d86621a1b13107a2562c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/728434227fe21be27ff6d86621a1b13107a2562c",
"reference": "728434227fe21be27ff6d86621a1b13107a2562c",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
"phpcompatibility/php-compatibility": "^9.3",
"phpdocumentor/phpdocumentor": "2.*",
"phploc/phploc": "^4.0",
"phpmd/phpmd": "2.*",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
"sebastian/phpcpd": "^4.0",
"squizlabs/php_codesniffer": "^3.7"
},
"type": "library",
"autoload": {
"psr-4": {
"Matrix\\": "classes/src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Baker",
"email": "mark@demon-angel.eu"
}
],
"description": "PHP Class for working with matrices",
"homepage": "https://github.com/MarkBaker/PHPMatrix",
"keywords": [
"mathematics",
"matrix",
"vector"
],
"support": {
"issues": "https://github.com/MarkBaker/PHPMatrix/issues",
"source": "https://github.com/MarkBaker/PHPMatrix/tree/3.0.1"
},
"time": "2022-12-02T22:17:43+00:00"
},
{
"name": "monolog/monolog",
"version": "2.10.0",
@ -2984,6 +3467,112 @@
},
"time": "2022-03-07T12:52:04+00:00"
},
{
"name": "phpoffice/phpspreadsheet",
"version": "1.30.0",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
"reference": "2f39286e0136673778b7a142b3f0d141e43d1714"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/2f39286e0136673778b7a142b3f0d141e43d1714",
"reference": "2f39286e0136673778b7a142b3f0d141e43d1714",
"shasum": ""
},
"require": {
"composer/pcre": "^1||^2||^3",
"ext-ctype": "*",
"ext-dom": "*",
"ext-fileinfo": "*",
"ext-gd": "*",
"ext-iconv": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-simplexml": "*",
"ext-xml": "*",
"ext-xmlreader": "*",
"ext-xmlwriter": "*",
"ext-zip": "*",
"ext-zlib": "*",
"ezyang/htmlpurifier": "^4.15",
"maennchen/zipstream-php": "^2.1 || ^3.0",
"markbaker/complex": "^3.0",
"markbaker/matrix": "^3.0",
"php": "^7.4 || ^8.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "dev-main",
"dompdf/dompdf": "^1.0 || ^2.0 || ^3.0",
"friendsofphp/php-cs-fixer": "^3.2",
"mitoteam/jpgraph": "^10.3",
"mpdf/mpdf": "^8.1.1",
"phpcompatibility/php-compatibility": "^9.3",
"phpstan/phpstan": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^8.5 || ^9.0",
"squizlabs/php_codesniffer": "^3.7",
"tecnickcom/tcpdf": "^6.5"
},
"suggest": {
"dompdf/dompdf": "Option for rendering PDF with PDF Writer",
"ext-intl": "PHP Internationalization Functions",
"mitoteam/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers",
"mpdf/mpdf": "Option for rendering PDF with PDF Writer",
"tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer"
},
"type": "library",
"autoload": {
"psr-4": {
"PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Maarten Balliauw",
"homepage": "https://blog.maartenballiauw.be"
},
{
"name": "Mark Baker",
"homepage": "https://markbakeruk.net"
},
{
"name": "Franck Lefevre",
"homepage": "https://rootslabs.net"
},
{
"name": "Erik Tilt"
},
{
"name": "Adrien Crivelli"
}
],
"description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine",
"homepage": "https://github.com/PHPOffice/PhpSpreadsheet",
"keywords": [
"OpenXML",
"excel",
"gnumeric",
"ods",
"php",
"spreadsheet",
"xls",
"xlsx"
],
"support": {
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.30.0"
},
"time": "2025-08-10T06:28:02+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.9.3",

View File

@ -18,7 +18,7 @@
<div class="card-header">
<div class="row d-flex align-items-center">
<div class="col-3">
<p class="card-title text-bold mb-0">Vehicle Trips Report</p>
<p class="card-title text-bold mb-0">Vehicle Trip Report</p>
</div>
@if ($user_role == \App\Models\Users::ROLE_VENDOR || $user_role == \App\Models\Users::ROLE_ADMIN)
@can('vehicle.create')
@ -42,23 +42,22 @@
<div class="col-2">
<div class="form-group">
<label class="text-muted">From</label>
<input type="date" class="form-control"id="tgl0" value="2025-08-01">
<!-- default today -->
<input type="date" class="form-control" id="tgl0" value="{{ date('Y-m-d') }}">
</div>
</div>
<div class="col-2">
<div class="form-group">
<label class="text-muted">To</label>
<input type="date" class="form-control" id="tgl1" value="2025-08-28">
<input type="date" class="form-control" id="tgl1" value="{{ date('Y-m-d') }}">
</div>
</div>
<div class="col-2 d-flex align-items-end">
<!-- <button class="btn btn-sm btn-danger">Filter</button> -->
<button class="btn btn-sm btn-danger">Download</button>
<div class="col-8 d-flex align-items-end">
<button class="btn btn-sm btn-danger ms-auto" id="btnDownloadReport">Download Report</button>
</div>
</div>
</div>
<div class="table-responsive p-2">
<div class="table-responsive p-3">
<table id="tVehicleTrips" class="table table-hover dataTable ">
<thead>
<tr class="">
@ -66,11 +65,11 @@
<!-- <th class="text-center">Action</th> -->
<th class="">Vehicle Name</th>
<th class="">License Plate Number</th>
<th class="">Number of Trips</th>
<th class="">Number of Trip</th>
<th class="">Total Milage (km)</th>
</tr>
</thead>
<tbody>
<!-- <tbody>
<tr>
<td>24-679</td>
<td>24-679</td>
@ -137,7 +136,7 @@
<td>26</td>
<td>508.2</td>
</tr>
</tbody>
</tbody> -->
</table>
</div>
</div>
@ -150,7 +149,11 @@
@section('customjs')
<script src="{{ asset('assets/js/load-image.all.min.js') }}"></script>
<script>
<!-- DataTables Buttons + JSZip (for Excel export) -->
<script src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js"></script>
<script>
'use strict';
const State = {
file_jimp_worker: "{{ asset('assets/js/worker/jimp.js') }}",
@ -165,387 +168,83 @@
activate: function() {
Wrapper.event();
DTable.activate();
},
event: function() {
$('#add-device_id').select2({
dropdownParent: $('#mdlNewVhc'),
});
$('#add-brand').select2({
dropdownParent: $('#mdlNewVhc'),
});
$('#add-type').select2({
dropdownParent: $('#mdlNewVhc'),
});
$('#add-model').select2({
dropdownParent: $('#mdlNewVhc'),
});
$('#add-dcurrent').select2({
dropdownParent: $('#mdlNewVhc'),
});
$('#add-dassign').select2({
dropdownParent: $('#mdlNewVhc'),
});
$('#add-vendor_id').select2({
dropdownParent: $('#mdlNewVhc'),
});
$('#edt-device_id').select2({
dropdownParent: $('#mdlEdtVhc'),
});
$('#edt-brand').select2({
dropdownParent: $('#mdlEdtVhc'),
});
$('#edt-type').select2({
dropdownParent: $('#mdlEdtVhc'),
});
$('#edt-model').select2({
dropdownParent: $('#mdlEdtVhc'),
});
$('#edt-dcurrent').select2({
dropdownParent: $('#mdlEdtVhc'),
});
$('#edt-dassign').select2({
dropdownParent: $('#mdlEdtVhc'),
});
$('#edt-vendor_id').select2({
dropdownParent: $('#mdlEdtVhc'),
});
},
event: function() {
$('#tgl0, #tgl1').on('change', function() {
DTable.reload();
});
// Trigger export on external button click
$('#btnDownloadReport').on('click', function() {
DTable.table.button('.buttons-excel').trigger();
});
},
};
const DTable = {
table: null,
activate: function() {
DTable.reload();
},
reload: function() {
$('#tVehicleTrips').DataTable();
// if (Driver.Table.firstInitDataTable == 1) { loadTableSkeletonLoading() } else { Driver.Table.firstInitDataTable = 1; }
// $('#tVehicles').DataTable({
// processing: true,
// serverSide: false,
// bLengthChange: true,
// deferRender: true,
// destroy: true,
// ajax: {
// url: "{{ route('api_report_vehicle_trips_list') }}?cptid=" + AppState.current_company,
// type: 'GET',
// complete: function() {
// // removeTableSkeletonLoading()
// },
// },
// deferRender: true,
// columns: [{
// data: 'DT_RowIndex',
// className: 'text-end',
// visible: true,
// orderable: true,
// searchable: true,
// },
// {
// data: 'action',
// className: 'text-center',
// visible: true,
// orderable: true,
// searchable: true,
// render: function(data, type, row, meta) {
// let action = `
// <a href="#" class="text-decoration-none me-1 btnEdtVhc">
// <span class="icon ion-eye fz-16"></span>
// </a>
// `;
// // <a href="#" class="text-decoration-none text-danger btnDelVhc">
// // <span class="icon ion-trash-b fz-16"></span>
// // </a>
// return action;
// }
// },
// {
// data: 'name',
// className: 'text-start text-nowrap',
// visible: true,
// orderable: true,
// searchable: true,
// render: function(data, type, row, meta) {
// return `
// <img src="${State.storage_lara}${row.fvhc_img}" class="img-fluid thumb-img-table" /><br>
// ${row.nopol1} ${row.nopol2} ${row.nopol3}
// `;
// },
// createdCell: function(td, cellData, rowData, row, col) {
// $(td).attr('data-vid', rowData.vid);
// $(td).attr('data-name', rowData.name);
// $(td).attr('data-nopol1', rowData.nopol1);
// $(td).attr('data-nopol2', rowData.nopol2);
// $(td).attr('data-nopol3', rowData.nopol3);
// },
// },
// // {
// // data: 'stnk_img',
// // className: 'text-start text-nowrap',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // // exp: ${row.stnk_exp?.split('-').reverse().join('-') || ''}
// // return `
// // <img src="${State.storage_lara}${data}" class="img-fluid thumb-img-table" /><br>
// // ${row.nopol1} ${row.nopol2} ${row.nopol3}<br>
// // exp: ${moment(row.stnk_exp).format('DD MMM YYYY') || '-'}
// // `;
// // },
// // },
// {
// data: 'tax_exp',
// className: 'text-end text-nowrap',
// visible: true,
// orderable: true,
// searchable: true,
// render: function(data, type, row, meta) {
// // return (`${data?.split('-').reverse().join('-') || '-'}`);
// return (`${moment(data).format('DD MMM YYYY') || '-'}`);
// },
// },
// // {
// // data: 'kir_exp',
// // className: 'text-end text-nowrap',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return (`${moment(data).format('DD MMM YYYY') || '-'}`);
// // },
// // },
// {
// data: 'crt',
// className: 'text-end text-nowrap',
// visible: true,
// orderable: true,
// searchable: true,
// render: function(data, type, row, meta) {
// return moment.unix(data).format('DD MMM YYYY');
// },
// },
// @if ($user_role != \App\Models\Users::ROLE_VENDOR)
// {
// data: 'device_id',
// className: 'text-end text-nowrap',
// visible: true,
// orderable: true,
// searchable: true,
// render: function(data, type, row, meta) {
// return `<span class="d-none">${data}</span>` + Helper.splitEvery4Char(`${data}`);
// },
// },
// @endif
// // {
// // data: 'dc_fullname',
// // className: 'text-start text-nowrap',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return (
// // `${data}<br>` +
// // `<a href="tel:0${row.dc_phone}">${Helper.splitEvery4Char('0'+row.dc_phone)}</a>` +
// // ` || ` +
// // `<a href="https://api.whatsapp.com/send/?phone=62${row.dc_phone}&text=Halo&app_absent=0" class="bg-light" target="_blank"><i class="text-success ion-social-whatsapp"></i></a>`
// // );
// // },
// // },
// // {
// // data: 'da_fullname',
// // className: 'text-start text-nowrap',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return (
// // `${data}<br>` +
// // `<a href="tel:0${row.da_phone}">${Helper.splitEvery4Char('0'+row.da_phone)}</a>` +
// // ` || ` +
// // `<a href="https://api.whatsapp.com/send/?phone=62${row.da_phone}&text=Halo&app_absent=0" class="bg-light" target="_blank"><i class="text-success ion-social-whatsapp"></i></a>`
// // );
// // },
// // },
// {
// data: 'type_name',
// className: 'text-start text-nowrap',
// visible: true,
// orderable: true,
// searchable: true,
// render: function(data, type, row, meta) {
// // return (`${row.brand_name}<br>-<br>${data}`);
// return data;
// },
// },
// {
// data: 'vyear',
// className: 'text-end',
// visible: true,
// orderable: true,
// searchable: true,
// render: function(data, type, row, meta) {
// return (`${(data || '-')}`);
// },
// },
// // {
// // data: 'cc',
// // className: 'text-start',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return (`${(data || '0')} CC`);
// // },
// // },
// // {
// // data: 'vin',
// // className: 'text-start text-nowrap',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return (`${Helper.splitEvery4Char(data || '-')}`);
// // },
// // },
// // {
// // data: 'en',
// // className: 'text-start text-nowrap',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return (`${Helper.splitEvery4Char(data || '-')}`);
// // },
// // },
// // {
// // data: 'vcolor',
// // className: 'text-start',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return (`${(data || '-')}`);
// // },
// // },
// // {
// // data: 'fuel_type',
// // className: 'text-start',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return (`${(data || '-')}`);
// // },
// // },
// // {
// // data: 'tnkb_color',
// // className: 'text-start text-nowrap',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return (`${(data || '-')}`);
// // },
// // },
// // {
// // data: 'regis_year',
// // className: 'text-end',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return (`${(data || '-')}`);
// // },
// // },
// // {
// // data: 'speed_limit',
// // className: 'text-end',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // },
// // {
// // data: 'fuel_capacity',
// // className: 'text-end',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // },
// // {
// // data: 'fuel_drop_treshold',
// // className: 'text-end',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // },
// // {
// // data: 'max_pressure',
// // className: 'text-end',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // },
// // {
// // data: 'alert_zones',
// // className: 'text-start',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // },
// // {
// // data: 'is_track_holiday_text',
// // className: 'text-start',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // },
// // {
// // data: 'track_schedule',
// // className: 'text-end',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // },
// {
// data: 'sum_milleage',
// className: 'text-end',
// visible: true,
// orderable: true,
// searchable: true,
// render: function(data, type, row, meta) {
// return Number(data).toFixed(2);
// }
// },
// // {
// // data: 'cameras',
// // className: 'text-start',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // },
// {
// data: 'company_name',
// className: 'text-start text-nowrap',
// visible: true,
// orderable: true,
// searchable: true,
// render: function(data, type, row, meta) {
// return data || '-';
// }
// },
// // {
// // data: 'group_name',
// // className: 'text-start text-nowrap',
// // visible: true,
// // orderable: true,
// // searchable: true,
// // render: function(data, type, row, meta) {
// // return data || 'All Group';
// // }
// // },
// ],
// });
DTable.table = $('#tVehicleTrips').DataTable({
processing: true,
serverSide: false,
bLengthChange: true,
deferRender: true,
destroy: true,
ajax: {
url: `{{ route('api_report_vehicle_trips_list') }}?
cptid=${AppState.current_company}
&from_date=${moment(safeVal('#tgl0')).startOf('day').unix()}
&to_date=${moment(safeVal('#tgl1')).endOf('day').unix()}`,
type: 'GET',
complete: function() {
// removeTableSkeletonLoading()
},
},
deferRender: true,
columns: [
{
data: 'name',
className: 'text-start text-nowrap',
visible: true,
orderable: true,
searchable: true,
},
{
data: 'nopol1',
className: 'text-start',
visible: true,
orderable: true,
searchable: true,
},
{
data: 'numOfTrip',
className: 'text-end',
visible: true,
orderable: true,
searchable: true,
},
{
data: 'total_milleage',
className: 'text-end',
visible: true,
orderable: true,
searchable: false,
render: function(data, type, row, meta) {
return (data === null) ? '0' : parseFloat(data).toFixed(2);
}
},
],
buttons: [
{
extend: 'excelHtml5',
title: 'Trip Report',
className: 'd-none' // hide default button
}
]
});
},
};