feat: initial commit
This commit is contained in:
20
app/Commands/Branches/CreateBranchCommand.php
Normal file
20
app/Commands/Branches/CreateBranchCommand.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands\Branches;
|
||||
|
||||
use App\Commands\Command;
|
||||
use App\Models\Branch;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateBranchCommand implements Command
|
||||
{
|
||||
public function execute(array $data): \Illuminate\Database\Eloquent\Model
|
||||
{
|
||||
return DB::transaction(
|
||||
callback: fn() => Branch::query()->updateOrCreate(['id' => $data['id'] ?? null], Arr::except($data, ['series'])),
|
||||
attempts: 2
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
11
app/Commands/Command.php
Normal file
11
app/Commands/Command.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
interface Command
|
||||
{
|
||||
public function execute(array $data) : mixed;
|
||||
}
|
||||
21
app/Commands/Series/CreateSeriesCommand.php
Normal file
21
app/Commands/Series/CreateSeriesCommand.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands\Series;
|
||||
|
||||
use App\Actions\BaseAction;
|
||||
use App\Commands\Command;
|
||||
use App\Models\Series;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateSeriesCommand implements Command
|
||||
{
|
||||
public function execute($data) : Model
|
||||
{
|
||||
return DB::transaction(
|
||||
callback: fn () => Series::query()->create($data),
|
||||
attempts: 2
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
23
app/Commands/Transmittal/GenerateTransmittalSeries.php
Normal file
23
app/Commands/Transmittal/GenerateTransmittalSeries.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands\Transmittal;
|
||||
|
||||
use App\Commands\Command;
|
||||
use App\Models\Transmittal;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class GenerateTransmittalSeries implements Command
|
||||
{
|
||||
|
||||
public function execute(array $data): string
|
||||
{
|
||||
$lastSeries = Transmittal::query()->orderBy('id', 'desc')->first();
|
||||
|
||||
if ($lastSeries) {
|
||||
$series = explode('-', $lastSeries->series)[1];
|
||||
return 'TR-'.str_pad((int)$series + 1, 10, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
return $series = 'TR-'.str_pad(1, 10, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
19
app/Commands/Transmittal/StoreCommentCommand.php
Normal file
19
app/Commands/Transmittal/StoreCommentCommand.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands\Transmittal;
|
||||
|
||||
use App\Commands\Command;
|
||||
use App\Models\Comment;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StoreCommentCommand implements Command
|
||||
{
|
||||
|
||||
public function execute(array $data): mixed
|
||||
{
|
||||
return DB::transaction(
|
||||
callback: fn () => Comment::query()->create($data),
|
||||
attempts: 2
|
||||
);
|
||||
}
|
||||
}
|
||||
20
app/Commands/Transmittal/StoreFileCommand.php
Normal file
20
app/Commands/Transmittal/StoreFileCommand.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands\Transmittal;
|
||||
|
||||
use App\Commands\Command;
|
||||
use App\Models\File;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use function PHPUnit\Framework\callback;
|
||||
|
||||
class StoreFileCommand implements Command
|
||||
{
|
||||
|
||||
public function execute(array $data): mixed
|
||||
{
|
||||
return DB::transaction(
|
||||
callback: fn () => File::query()->create($data),
|
||||
attempts: 2
|
||||
);
|
||||
}
|
||||
}
|
||||
19
app/Commands/Transmittal/StoreRemarkCommand.php
Normal file
19
app/Commands/Transmittal/StoreRemarkCommand.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands\Transmittal;
|
||||
|
||||
use App\Commands\Command;
|
||||
use App\Models\Remark;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StoreRemarkCommand implements Command
|
||||
{
|
||||
|
||||
public function execute(array $data): mixed
|
||||
{
|
||||
return DB::transaction(
|
||||
callback: fn () => Remark::query()->create($data),
|
||||
attempts: 2
|
||||
);
|
||||
}
|
||||
}
|
||||
20
app/Commands/Transmittal/StoreTransmittalCommand.php
Normal file
20
app/Commands/Transmittal/StoreTransmittalCommand.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands\Transmittal;
|
||||
|
||||
use App\Commands\Command;
|
||||
use App\Models\Transmittal;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StoreTransmittalCommand implements Command
|
||||
{
|
||||
|
||||
public function execute(array $data): Model
|
||||
{
|
||||
return DB::transaction(
|
||||
callback: fn () => Transmittal::query()->updateOrCreate(['id' => $data['id'] ?? null], $data),
|
||||
attempts: 2
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user