-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,576 additions
and
0 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
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
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
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,47 @@ | ||
<?php | ||
|
||
namespace Instrument\Actions; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Facades\Validator; | ||
use Instrument\Report; | ||
use Instrument\Contracts\CreatesReports; | ||
use Instrument\Events\ReportCreated; | ||
use Instrument\Events\CreatingReport; | ||
use Instrument\Instrument; | ||
|
||
class CreateReport implements CreatesReports | ||
{ | ||
/** | ||
* Create a new report. | ||
*/ | ||
public function __invoke(Model $user, array $data, $teamId = null): Report | ||
{ | ||
event(new CreatingReport(user: $user, data: $data)); | ||
|
||
Validator::make($data, [ | ||
'type' => 'required|string|max:255|in:'.implode(',', collect(config('instrument.report_types'))->keys()->toArray()), | ||
'name' => 'required|string|max:255', | ||
'description' => 'required|string|max:255', | ||
'settings' => 'nullable|array', | ||
'settings.group' => 'nullable|string|max:255|in:'.implode(',', config('instrument.report_groups')), | ||
'settings.period' => 'nullable|string|max:255|in:'.implode(',', config('instrument.report_periods')), | ||
'settings.basis' => 'nullable|string|max:255|in:'.implode(',', config('instrument.report_accounting_basis')), | ||
])->validateWithBag('createReport'); | ||
|
||
$fields = collect($data)->only([ | ||
'type', | ||
'name', | ||
'description', | ||
'settings', | ||
])->toArray(); | ||
|
||
$report = Instrument::$supportsTeams ? | ||
Instrument::findTeamByIdOrFail($teamId)->reports()->create($fields) : | ||
Instrument::newReportModel()->create($fields); | ||
|
||
event(new ReportCreated(user: $user, report: $report, data: $data)); | ||
|
||
return $report; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace Instrument\Actions; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Instrument\Report; | ||
use Instrument\Contracts\DeletesReports; | ||
use Instrument\Events\ReportDeleted; | ||
use Instrument\Events\DeletingReport; | ||
|
||
class DeleteReport implements DeletesReports | ||
{ | ||
/** | ||
* Delete a report. | ||
*/ | ||
public function __invoke(Model $user, Report $report): void | ||
{ | ||
event(new DeletingReport($user, report: $report)); | ||
|
||
$report->delete(); | ||
|
||
event(new ReportDeleted(user: $user, report: $report)); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace Instrument\Actions; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Facades\Validator; | ||
use Instrument\Report; | ||
use Instrument\Contracts\UpdatesReports; | ||
use Instrument\Events\ReportUpdated; | ||
use Instrument\Events\UpdatingReport; | ||
|
||
class UpdateReport implements UpdatesReports | ||
{ | ||
/** | ||
* Update an existing report. | ||
*/ | ||
public function __invoke(Model $user, Report $report, array $data): Report | ||
{ | ||
event(new UpdatingReport(user: $user, report: $report, data: $data)); | ||
|
||
Validator::make($data, [ | ||
'name' => 'required|string|max:255', | ||
'description' => 'required|string|max:255', | ||
'settings' => 'nullable|array', | ||
'settings.group' => 'nullable|string|max:255|in:'.implode(',', config('instrument.report_groups')), | ||
'settings.period' => 'nullable|string|max:255|in:'.implode(',', config('instrument.report_periods')), | ||
'settings.basis' => 'nullable|string|max:255|in:'.implode(',', config('instrument.report_accounting_basis')), | ||
])->validateWithBag('updateReport'); | ||
|
||
$report->update(collect($data)->only([ | ||
'name', | ||
'description', | ||
'settings', | ||
])->toArray()); | ||
|
||
event(new ReportUpdated(user: $user, report: $report, data: $data)); | ||
|
||
return $report->refresh(); | ||
} | ||
} |
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
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,14 @@ | ||
<?php | ||
|
||
namespace Instrument\Contracts; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Instrument\Report; | ||
|
||
interface CreatesReports | ||
{ | ||
/** | ||
* Create a new report. | ||
*/ | ||
public function __invoke(Model $user, array $data, $teamId = null): Report; | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace Instrument\Contracts; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Instrument\Report; | ||
|
||
interface DeletesReports | ||
{ | ||
/** | ||
* Delete an existing report. | ||
*/ | ||
public function __invoke(Model $user, Report $report): void; | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace Instrument\Contracts; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Instrument\Report; | ||
|
||
interface UpdatesReports | ||
{ | ||
/** | ||
* Update an existing report. | ||
*/ | ||
public function __invoke(Model $user, Report $report, array $data): Report; | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Instrument\Events; | ||
|
||
class CreatingReport extends ReportEvent | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Instrument\Events; | ||
|
||
class DeletingReport extends ReportEvent | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Instrument\Events; | ||
|
||
class ReportCreated extends ReportEvent | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Instrument\Events; | ||
|
||
class ReportDeleted extends ReportEvent | ||
{ | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace Instrument\Events; | ||
|
||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
abstract class ReportEvent | ||
{ | ||
use Dispatchable; | ||
use InteractsWithSockets; | ||
use SerializesModels; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param mixed $user | ||
* @param mixed $report | ||
* @param array $data | ||
* @return void | ||
*/ | ||
public function __construct( | ||
public $user = null, | ||
public $report = null, | ||
public $data = [] | ||
) { | ||
} | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Instrument\Events; | ||
|
||
class ReportUpdated extends ReportEvent | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Instrument\Events; | ||
|
||
class UpdatingReport extends ReportEvent | ||
{ | ||
} |
Oops, something went wrong.