-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #178 - Equipment management * Exporting equipment to excel file * Added equipment tests * #178 - change text in is mobile column to icons * #178 - linter fix * CR fixes * Linter fixes * #178 - fix * #178 - fix * CR fixes * CR fix * CR fix * #178 - fix * #178 - fix --------- Co-authored-by: EwelinaSkrzypacz <[email protected]>
- Loading branch information
1 parent
8024176
commit 4cc2f52
Showing
33 changed files
with
2,494 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Domain; | ||
|
||
use Generator; | ||
use Illuminate\Support\Collection; | ||
use Maatwebsite\Excel\Concerns\FromGenerator; | ||
use Maatwebsite\Excel\Concerns\RegistersEventListeners; | ||
use Maatwebsite\Excel\Concerns\ShouldAutoSize; | ||
use Maatwebsite\Excel\Concerns\WithColumnFormatting; | ||
use Maatwebsite\Excel\Concerns\WithEvents; | ||
use Maatwebsite\Excel\Concerns\WithHeadings; | ||
use Maatwebsite\Excel\Concerns\WithStrictNullComparison; | ||
use Maatwebsite\Excel\Concerns\WithStyles; | ||
use PhpOffice\PhpSpreadsheet\Cell\DataType; | ||
use PhpOffice\PhpSpreadsheet\Shared\Date; | ||
use PhpOffice\PhpSpreadsheet\Style\Alignment; | ||
use PhpOffice\PhpSpreadsheet\Style\Border; | ||
use PhpOffice\PhpSpreadsheet\Style\Fill; | ||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; | ||
|
||
class EquipmentExport implements WithHeadings, WithStyles, WithEvents, WithStrictNullComparison, WithColumnFormatting, ShouldAutoSize, FromGenerator | ||
{ | ||
use RegistersEventListeners; | ||
|
||
public function __construct( | ||
protected Collection $equipmentItems, | ||
) {} | ||
|
||
public function generator(): Generator | ||
{ | ||
foreach ($this->equipmentItems as $equipmentItem) { | ||
$row = [ | ||
$equipmentItem->id_number, | ||
$equipmentItem->name, | ||
$equipmentItem->labels?->implode(", "), | ||
$equipmentItem->is_mobile, | ||
$equipmentItem->assignee->profile->full_name ?? "", | ||
$equipmentItem->assigned_at ? Date::dateTimeToExcel($equipmentItem->assigned_at) : "", | ||
]; | ||
|
||
yield $row; | ||
} | ||
} | ||
|
||
public function headings(): array | ||
{ | ||
return [ | ||
__("ID"), | ||
__("Name"), | ||
__("Labels"), | ||
__("Is mobile"), | ||
__("Assignee"), | ||
__("Assigned at"), | ||
]; | ||
} | ||
|
||
public function columnFormats(): array | ||
{ | ||
return [ | ||
"A" => NumberFormat::FORMAT_TEXT, | ||
"B" => NumberFormat::FORMAT_TEXT, | ||
"C" => NumberFormat::FORMAT_TEXT, | ||
"D" => DataType::TYPE_BOOL, | ||
"E" => NumberFormat::FORMAT_TEXT, | ||
"F" => NumberFormat::FORMAT_DATE_DDMMYYYY, | ||
]; | ||
} | ||
|
||
public function styles(Worksheet $sheet): void | ||
{ | ||
$lastRow = $sheet->getHighestRow(); | ||
$lastColumn = $sheet->getHighestColumn(); | ||
|
||
$sheet->getStyle("A1:{$lastColumn}1") | ||
->getFont() | ||
->setBold(true); | ||
|
||
$sheet->getStyle("A1:{$lastColumn}1") | ||
->getAlignment() | ||
->setVertical(Alignment::VERTICAL_CENTER); | ||
|
||
$sheet->getStyle("A1:{$lastColumn}1") | ||
->getFill() | ||
->setFillType(Fill::FILL_SOLID) | ||
->getStartColor() | ||
->setRGB("D9D9D9"); | ||
|
||
$sheet->getStyle("A2:A{$lastRow}") | ||
->getFont() | ||
->setBold(true); | ||
|
||
$sheet->getStyle("A1:{$lastColumn}{$lastRow}") | ||
->getBorders() | ||
->getAllBorders() | ||
->setBorderStyle(Border::BORDER_THIN) | ||
->getColor() | ||
->setRGB("B7B7B7"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Eloquent\Models; | ||
|
||
use Carbon\Carbon; | ||
use Database\Factories\EquipmentItemFactory; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Casts\AsCollection; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
/** | ||
* @property int $id | ||
* @property string $id_number | ||
* @property string $name | ||
* @property bool $is_mobile | ||
* @property ?int $assignee_id | ||
* @property ?User $assignee | ||
* @property Carbon $assigned_at | ||
* @property Collection $labels | ||
*/ | ||
class EquipmentItem extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $casts = [ | ||
"assigned_at" => "date", | ||
"labels" => AsCollection::class, | ||
]; | ||
protected $fillable = [ | ||
"id_number", | ||
"name", | ||
"is_mobile", | ||
"labels", | ||
"assignee_id", | ||
"assigned_at", | ||
]; | ||
|
||
public function scopeSearch(Builder $query, ?string $text): Builder | ||
{ | ||
if ($text === null) { | ||
return $query; | ||
} | ||
|
||
return $query | ||
->where("id_number", "ILIKE", "%{$text}%") | ||
->orWhere("name", "ILIKE", "%{$text}%") | ||
->orWhere("labels", "ILIKE", "%{$text}%") | ||
->orWhereRelation( | ||
"assignee", | ||
fn(Builder $query): Builder => $query | ||
->where("email", "ILIKE", "%{$text}%") | ||
->orWhereRelation( | ||
"profile", | ||
fn(Builder $query): Builder => $query | ||
->where("first_name", "ILIKE", "%{$text}%") | ||
->orWhere("last_name", "ILIKE", "%{$text}%") | ||
->orWhere(DB::raw("CONCAT(first_name, ' ', last_name)"), "ILIKE", "%{$text}%"), | ||
), | ||
); | ||
} | ||
|
||
public function scopeLabels(Builder $query, ?array $labels): Builder | ||
{ | ||
if ($labels === null) { | ||
return $query; | ||
} | ||
|
||
$query->where(function (Builder $query) use ($labels): Builder { | ||
foreach ($labels as $label) { | ||
$query->orWhereJsonContains("labels", $label); | ||
} | ||
|
||
return $query; | ||
}); | ||
|
||
return $query; | ||
} | ||
|
||
public function assignee(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class, "assignee_id"); | ||
} | ||
|
||
protected static function newFactory(): EquipmentItemFactory | ||
{ | ||
return EquipmentItemFactory::new(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Eloquent\Models; | ||
|
||
use Database\Factories\EquipmentLabelFactory; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsToMany; | ||
use Illuminate\Support\Collection; | ||
|
||
/** | ||
* @property int $id | ||
* @property string $name | ||
* @property Collection $items | ||
*/ | ||
class EquipmentLabel extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
"name", | ||
]; | ||
|
||
public function items(): BelongsToMany | ||
{ | ||
return $this->belongsToMany(EquipmentItem::class, "equipment_items_labels"); | ||
} | ||
|
||
protected static function newFactory(): EquipmentLabelFactory | ||
{ | ||
return EquipmentLabelFactory::new(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.