add datatable export

This commit is contained in:
daengdeni 2024-05-19 18:23:34 +07:00
parent 841837f541
commit bb59625753
5 changed files with 220 additions and 0 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ yarn-error.log
/.idea
/.vscode
composer.lock
*.lock

View File

@ -0,0 +1,129 @@
<?php
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
return [
/*
|--------------------------------------------------------------------------
| Method
|--------------------------------------------------------------------------
|
| Method to use to iterate with the query results.
| Options: lazy, cursor
|
| @link https://laravel.com/docs/eloquent#cursors
| @link https://laravel.com/docs/eloquent#chunking-using-lazy-collections
|
*/
'method' => 'lazy',
/*
|--------------------------------------------------------------------------
| Chunk Size
|--------------------------------------------------------------------------
|
| Chunk size to be used when using lazy method.
|
*/
'chunk' => 1000,
/*
|--------------------------------------------------------------------------
| Export filesystem disk
|--------------------------------------------------------------------------
|
| Export filesystem disk where generated files will be stored.
|
*/
'disk' => 'local',
/*
|--------------------------------------------------------------------------
| Use S3 for final file destination
|--------------------------------------------------------------------------
|
| After generating the file locally, it can be uploaded to s3.
|
*/
's3_disk' => '',
/*
|--------------------------------------------------------------------------
| Mail from address
|--------------------------------------------------------------------------
|
| Will be used to email report from this address.
|
*/
'mail_from' => env('MAIL_FROM_ADDRESS', ''),
/*
|--------------------------------------------------------------------------
| Default Date Format
|--------------------------------------------------------------------------
|
| Default export format for date.
|
*/
'default_date_format' => 'yyyy-mm-dd',
/*
|--------------------------------------------------------------------------
| Valid Date Formats
|--------------------------------------------------------------------------
|
| List of valid date formats to be used for auto-detection.
|
*/
'date_formats' => [
'mm/dd/yyyy',
NumberFormat::FORMAT_DATE_DATETIME,
NumberFormat::FORMAT_DATE_YYYYMMDD,
NumberFormat::FORMAT_DATE_XLSX22,
NumberFormat::FORMAT_DATE_DDMMYYYY,
NumberFormat::FORMAT_DATE_DMMINUS,
NumberFormat::FORMAT_DATE_DMYMINUS,
NumberFormat::FORMAT_DATE_DMYSLASH,
NumberFormat::FORMAT_DATE_MYMINUS,
NumberFormat::FORMAT_DATE_TIME1,
NumberFormat::FORMAT_DATE_TIME2,
NumberFormat::FORMAT_DATE_TIME3,
NumberFormat::FORMAT_DATE_TIME4,
NumberFormat::FORMAT_DATE_TIME5,
NumberFormat::FORMAT_DATE_TIME6,
NumberFormat::FORMAT_DATE_TIME7,
NumberFormat::FORMAT_DATE_XLSX14,
NumberFormat::FORMAT_DATE_XLSX15,
NumberFormat::FORMAT_DATE_XLSX16,
NumberFormat::FORMAT_DATE_XLSX17,
NumberFormat::FORMAT_DATE_YYYYMMDD2,
NumberFormat::FORMAT_DATE_YYYYMMDDSLASH,
],
/*
|--------------------------------------------------------------------------
| Valid Text Formats
|--------------------------------------------------------------------------
|
| List of valid text formats to be used.
|
*/
'text_formats' => [
'@',
NumberFormat::FORMAT_GENERAL,
NumberFormat::FORMAT_TEXT,
],
/*
|--------------------------------------------------------------------------
| Purge Options
|--------------------------------------------------------------------------
|
| Purge all exported by purge.days old files.
|
*/
'purge' => [
'days' => 1,
],
];

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('job_batches');
}
};

View File

@ -0,0 +1,54 @@
<div class="d-flex align-items-center" x-data>
<form class="mr-2"
x-on:submit.prevent="
$refs.exportBtn.disabled = true;
var oTable = LaravelDataTables['{{ $tableId }}'];
var baseUrl = oTable.ajax.url() === '' ? window.location.toString() : oTable.ajax.url();
var params = new URLSearchParams({
action: 'exportQueue',
exportType: '{{$fileType}}',
sheetName: '{{$sheetName}}',
emailTo: '{{urlencode($emailTo)}}',
});
toastr.success('Exporting data, please wait.');
$.get(baseUrl + '?' + params.toString() + '&' + $.param(oTable.ajax.params())).then(function(exportId) {
$wire.export(exportId);
toastr.success('Done. File has been downloaded.');
})
.catch(function(error) {
$wire.exportFinished = true;
$wire.exporting = false;
$wire.exportFailed = true;
toastr.error('Export failed, please try again later.');
});
"
>
<button type="submit" class="btn btn-light-primary"
x-ref="exportBtn"
:disabled="$wire.exporting"
><i class="ki-duotone ki-exit-down fs-2"><span class="path1"></span><span class="path2"></span></i> Export
</button>
</form>
@if($exporting && $emailTo)
<div class="d-inline" style="display: none">Export will be emailed to {{ $emailTo }}.</div>
@endif
@if($exporting && !$exportFinished)
<div class="d-inline" style="display: none" wire:poll="updateExportProgress">&nbsp;</div>
@endif
@if($exportFinished && !$exportFailed && !$autoDownload)
<span style="display: none">Done. Download file <a href="#" class="text-primary" wire:click.prevent="downloadExport">here</a></span>
@endif
@if($exportFinished && !$exportFailed && $autoDownload && $downloaded)
<span style="display: none">Done. File has been downloaded.</span>
@endif
@if($exportFailed)
<span style="display: none">Export failed, please try again later.</span>
@endif
</div>

View File

@ -0,0 +1 @@
Attached you will find requested report.