update code

This commit is contained in:
manhlab
2021-04-07 06:32:42 -04:00
parent 7fb98911a6
commit a4753625f6
779 changed files with 335717 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithPreCalculateFormulas;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\BeforeWriting;
use Maatwebsite\Excel\Events\BeforeSheet;
use Maatwebsite\Excel\Events\AfterSheet;
abstract class BaseDocumentsExport
implements
FromCollection,
WithHeadings,
WithMapping,
ShouldAutoSize,
WithTitle,
WithCustomStartCell,
WithColumnFormatting,
WithPreCalculateFormulas,
WithEvents
{
protected $documents;
protected $title;
protected $from;
protected $to;
public function __construct($documents, string $title, $from = null, $to = null){
$this->documents = $documents;
$this->title = $title;
$this->from = $from;
$this->to = $to;
}
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return $this->documents;
}
abstract public function headings(): array;
abstract public function map($document): array;
public function title(): string
{
return $this->title;
}
public function startCell(): string
{
return 'A1';
}
public function columnFormats(): array
{
return [
'A' => NumberFormat::FORMAT_DATE_DDMMYYYY,
];
}
public function registerEvents(): array
{
return [
AfterSheet::class => [self::class, 'afterSheet'],
];
}
public static function afterSheet(AfterSheet $event)
{
// $event->getSheet()->getDelegate()->setCellValue('A10', 'xxx');
// $style = new Color(Color::COLOR_RED);!
// $event->getSheet()->getDelegate()->setConditionalStyles('A10', $style);!
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use App\Entities\Book;
use App\Exports\{
ComeInDocumentsExport,
ComeOutDocumentsExport,
PrivateDocumentsExport,
};
class BooksExport implements WithMultipleSheets
{
protected $books;
protected $from;
protected $to;
public function __construct($books, $from = null, $to = null){
$this->books = $books;
$this->from = $from;
$this->to = $to;
}
public function sheets(): array
{
$sheets = [];
foreach ($this->books as $book) {
$sheets[] = $this->getSheet($book);
}
return $sheets;
}
protected function getSheet(Book $book)
{
if($book->isComeIn()){
return new ComeInDocumentsExport($book->documents, $book->name, $this->from, $this->to);
}
if($book->isComeOut()){
return new ComeOutDocumentsExport($book->documents, $book->name, $this->from, $this->to);
}
if($book->isPrivate()){
return new PrivateDocumentsExport($book->documents, $book->name, $this->from, $this->to);
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Exports;
use PhpOffice\PhpSpreadsheet\Shared\Date;
class ComeInDocumentsExport extends BaseDocumentsExport
{
public function headings(): array
{
return [
'Ngày nhận',
'Nơi ban hành',
'Ký hiệu',
'Loại',
'Trích yếu',
'Người nhận',
];
}
public function map($document): array
{
return [
Date::dateTimeToExcel($document->effective_at),
$document->publisher->name,
$document->symbol,
$document->type->name,
$document->abstract,
implode(', ', ($document->receivers->map(function($receiver){
return $receiver->name;
}))->toArray()),
];
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Exports;
use PhpOffice\PhpSpreadsheet\Shared\Date;
class ComeOutDocumentsExport extends BaseDocumentsExport
{
public function headings(): array
{
return [
'Ngày ban hành',
'Ký hiệu',
'Loại',
'Trích yếu',
'Nơi nhận',
];
}
/**
* @param mixed $document
*
* @return array
*/
public function map($document): array
{
return [
Date::dateTimeToExcel($document->effective_at),
$document->symbol,
$document->type->name,
$document->abstract,
implode(', ', ($document->organizes->map(function($organize){
return $organize->name;
}))->toArray()),
];
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Exports;
use PhpOffice\PhpSpreadsheet\Shared\Date;
class PrivateDocumentsExport extends BaseDocumentsExport
{
public function headings(): array
{
return [
'Ngày ban hành',
'Ký hiệu',
'Loại',
'Trích yếu',
'Người nhận',
];
}
/**
* @param mixed $document
*
* @return array
*/
public function map($document): array
{
return [
Date::dateTimeToExcel($document->effective_at),
$document->symbol,
$document->type->name,
$document->abstract,
implode(', ', ($document->organizes->map(function($organize){
return $organize->name;
}))->toArray()),
];
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithPreCalculateFormulas;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\BeforeWriting;
use Maatwebsite\Excel\Events\BeforeSheet;
use Maatwebsite\Excel\Events\AfterSheet;
class UsersExport
implements
FromCollection,
WithHeadings,
WithMapping,
ShouldAutoSize,
WithTitle,
WithCustomStartCell
{
protected $users;
public function __construct($users){
$this->users = $users;
}
public function collection()
{
return $this->users;
}
public function headings(): array
{
return [
'Mã',
'Tên',
'Email',
'Số điện thoại',
'Ngày sinh',
'Chức danh',
'Phòng ban',
'Kích hoạt',
];
}
public function map($user): array
{
return [
$user->id,
$user->name,
$user->email,
$user->tel,
explode(' ', $user->birthday)[0],
$user->title_id,
$user->department_id,
$user->active,
];
}
public function title(): string
{
return 'Danh sách người dùng';
}
public function startCell(): string
{
return 'A1';
}
}