diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 42cc3f86ee05d..469f98a4a87e5 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -415,8 +415,8 @@ class CheckData extends Command $invitation->company_id = $invoice->company_id; $invitation->user_id = $invoice->user_id; $invitation->invoice_id = $invoice->id; - $invitation->contact_id = ClientContact::whereClientId($invoice->client_id)->first()->id; - $invitation->invitation_key = Str::random(config('ninja.key_length')); + $invitation->client_contact_id = ClientContact::whereClientId($invoice->client_id)->first()->id; + $invitation->key = Str::random(config('ninja.key_length')); $invitation->save(); } } @@ -447,7 +447,7 @@ class CheckData extends Command $contact_id = 'client_contact_id'; $contact_class = ClientContact::class; - $entity_key = \Illuminate\Support\Str::of(class_basename($entity))->snake()->append('_id')->value; + $entity_key = \Illuminate\Support\Str::of(class_basename($entity))->snake()->append('_id')->toString(); $entity_obj = get_class($entity).'Invitation'; if ($entity instanceof PurchaseOrder) { diff --git a/app/Console/Commands/CreateAccount.php b/app/Console/Commands/CreateAccount.php index e4e5b31e3dca3..4bfa4c7a13267 100644 --- a/app/Console/Commands/CreateAccount.php +++ b/app/Console/Commands/CreateAccount.php @@ -42,11 +42,6 @@ class CreateAccount extends Command */ protected $signature = 'ninja:create-account {--email=} {--password=}'; - /** - * Create a new command instance. - * - * @param InvoiceRepository $invoice_repo - */ public function __construct() { parent::__construct(); diff --git a/app/Console/Commands/DesignUpdate.php b/app/Console/Commands/DesignUpdate.php index c924ea268dfc0..4ff2f685678c0 100644 --- a/app/Console/Commands/DesignUpdate.php +++ b/app/Console/Commands/DesignUpdate.php @@ -60,7 +60,7 @@ class DesignUpdate extends Command foreach (MultiDB::$dbs as $db) { MultiDB::setDB($db); - $this->handleOnDb($db); + $this->handleOnDb(); } MultiDB::setDB($current_db); diff --git a/app/Console/Commands/HostedMigrations.php b/app/Console/Commands/HostedMigrations.php index d2a3b4bcc1b89..7bcb5c8aba0b8 100644 --- a/app/Console/Commands/HostedMigrations.php +++ b/app/Console/Commands/HostedMigrations.php @@ -105,7 +105,7 @@ class HostedMigrations extends Command Import::dispatch($import_file, $user->companies()->first(), $user); } catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) { - \Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); + \Mail::to($user)->send(new MigrationFailed($e, $company)); if (app()->environment() !== 'production') { info($e->getMessage()); diff --git a/app/Console/Commands/HostedUsers.php b/app/Console/Commands/HostedUsers.php index 133198b3e4cd5..74341544ec5e1 100644 --- a/app/Console/Commands/HostedUsers.php +++ b/app/Console/Commands/HostedUsers.php @@ -44,7 +44,6 @@ class HostedUsers extends Command /** * Execute the console command. * - * @return int */ public function handle() { diff --git a/app/Console/Commands/ImportMigrations.php b/app/Console/Commands/ImportMigrations.php index 2d04838616185..7e741c4bea549 100644 --- a/app/Console/Commands/ImportMigrations.php +++ b/app/Console/Commands/ImportMigrations.php @@ -107,7 +107,7 @@ class ImportMigrations extends Command Import::dispatch($import_file, $this->getUser()->companies()->first(), $this->getUser()); // StartMigration::dispatch($file->getRealPath(), $this->getUser(), $this->getUser()->companies()->first()); } catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) { - \Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); + \Mail::to($user)->send(new MigrationFailed($e, $company)); if (app()->environment() !== 'production') { info($e->getMessage()); diff --git a/app/Console/Commands/OpenApiYaml.php b/app/Console/Commands/OpenApiYaml.php index 204f06b9abad3..530e0da1b7e06 100644 --- a/app/Console/Commands/OpenApiYaml.php +++ b/app/Console/Commands/OpenApiYaml.php @@ -12,7 +12,6 @@ namespace App\Console\Commands; use DirectoryIterator; -use Faker\Factory; use Illuminate\Console\Command; use Illuminate\Support\Facades\Storage; @@ -44,8 +43,6 @@ class OpenApiYaml extends Command */ public function __construct() { - $this->faker = Factory::create(); - parent::__construct(); } diff --git a/app/Console/Commands/S3Cleanup.php b/app/Console/Commands/S3Cleanup.php index f5beffe529776..0397040120de9 100644 --- a/app/Console/Commands/S3Cleanup.php +++ b/app/Console/Commands/S3Cleanup.php @@ -47,7 +47,6 @@ class S3Cleanup extends Command /** * Execute the console command. * - * @return int */ public function handle() { diff --git a/app/Console/Commands/SendRemindersCron.php b/app/Console/Commands/SendRemindersCron.php index 7921633c8d9da..b7f44231fa753 100644 --- a/app/Console/Commands/SendRemindersCron.php +++ b/app/Console/Commands/SendRemindersCron.php @@ -57,7 +57,6 @@ class SendRemindersCron extends Command /** * Execute the console command. * - * @return int */ public function handle() { diff --git a/app/DataMapper/Analytics/AccountCreated.php b/app/DataMapper/Analytics/AccountCreated.php index 3400cd856406f..9f3b5c5d6e82c 100644 --- a/app/DataMapper/Analytics/AccountCreated.php +++ b/app/DataMapper/Analytics/AccountCreated.php @@ -37,7 +37,7 @@ class AccountCreated extends GenericCounter * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/AccountDeleted.php b/app/DataMapper/Analytics/AccountDeleted.php index 40973c93e905f..fba503ed543bd 100644 --- a/app/DataMapper/Analytics/AccountDeleted.php +++ b/app/DataMapper/Analytics/AccountDeleted.php @@ -37,7 +37,7 @@ class AccountDeleted extends GenericCounter * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/AccountPlatform.php b/app/DataMapper/Analytics/AccountPlatform.php index a1c3027f7fe89..db3e785767d35 100644 --- a/app/DataMapper/Analytics/AccountPlatform.php +++ b/app/DataMapper/Analytics/AccountPlatform.php @@ -37,7 +37,7 @@ class AccountPlatform extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/AccountSignup.php b/app/DataMapper/Analytics/AccountSignup.php index ee8548468f166..49baf78a9bca3 100644 --- a/app/DataMapper/Analytics/AccountSignup.php +++ b/app/DataMapper/Analytics/AccountSignup.php @@ -37,7 +37,7 @@ class AccountSignup extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/BankAccountsCreated.php b/app/DataMapper/Analytics/BankAccountsCreated.php index 494a5e40d0be5..18d05e3a145ea 100644 --- a/app/DataMapper/Analytics/BankAccountsCreated.php +++ b/app/DataMapper/Analytics/BankAccountsCreated.php @@ -37,7 +37,7 @@ class BankAccountsCreated extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/DbQuery.php b/app/DataMapper/Analytics/DbQuery.php index f0e4c779f1aeb..6e9ac09f88d5d 100644 --- a/app/DataMapper/Analytics/DbQuery.php +++ b/app/DataMapper/Analytics/DbQuery.php @@ -37,7 +37,7 @@ class DbQuery extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/EmailCount.php b/app/DataMapper/Analytics/EmailCount.php index d8e50c4ad15e9..ec41dbb4d5bae 100644 --- a/app/DataMapper/Analytics/EmailCount.php +++ b/app/DataMapper/Analytics/EmailCount.php @@ -37,7 +37,7 @@ class EmailCount extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/EmailFailure.php b/app/DataMapper/Analytics/EmailFailure.php index 65fb590f823ff..bd31ac13e43aa 100644 --- a/app/DataMapper/Analytics/EmailFailure.php +++ b/app/DataMapper/Analytics/EmailFailure.php @@ -37,7 +37,7 @@ class EmailFailure extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/EmailInvoiceFailure.php b/app/DataMapper/Analytics/EmailInvoiceFailure.php index a1ef868a654f2..058f8c7cfea50 100644 --- a/app/DataMapper/Analytics/EmailInvoiceFailure.php +++ b/app/DataMapper/Analytics/EmailInvoiceFailure.php @@ -37,7 +37,7 @@ class EmailInvoiceFailure extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/EmailSuccess.php b/app/DataMapper/Analytics/EmailSuccess.php index ec1ccc35da06b..94ddf34ecdb45 100644 --- a/app/DataMapper/Analytics/EmailSuccess.php +++ b/app/DataMapper/Analytics/EmailSuccess.php @@ -37,7 +37,7 @@ class EmailSuccess extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/LivePreview.php b/app/DataMapper/Analytics/LivePreview.php index c2abf7470020e..7cf062b75c718 100644 --- a/app/DataMapper/Analytics/LivePreview.php +++ b/app/DataMapper/Analytics/LivePreview.php @@ -37,7 +37,7 @@ class LivePreview extends GenericCounter * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/LoginFailure.php b/app/DataMapper/Analytics/LoginFailure.php index 474989fe91c10..954c1edb1fec0 100644 --- a/app/DataMapper/Analytics/LoginFailure.php +++ b/app/DataMapper/Analytics/LoginFailure.php @@ -37,7 +37,7 @@ class LoginFailure extends GenericCounter * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/LoginSuccess.php b/app/DataMapper/Analytics/LoginSuccess.php index e24ea25b90481..00099a1b458f2 100644 --- a/app/DataMapper/Analytics/LoginSuccess.php +++ b/app/DataMapper/Analytics/LoginSuccess.php @@ -37,7 +37,7 @@ class LoginSuccess extends GenericCounter * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/Mail/EmailBounce.php b/app/DataMapper/Analytics/Mail/EmailBounce.php index f7a0d098e2c17..7605447d346ac 100644 --- a/app/DataMapper/Analytics/Mail/EmailBounce.php +++ b/app/DataMapper/Analytics/Mail/EmailBounce.php @@ -37,7 +37,7 @@ class EmailBounce extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/Mail/EmailSpam.php b/app/DataMapper/Analytics/Mail/EmailSpam.php index 78289e7968fab..d5a4bd14553f8 100644 --- a/app/DataMapper/Analytics/Mail/EmailSpam.php +++ b/app/DataMapper/Analytics/Mail/EmailSpam.php @@ -37,7 +37,7 @@ class EmailSpam extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/MigrationFailure.php b/app/DataMapper/Analytics/MigrationFailure.php index 30f5fafe7bbe5..42e9fcb7af7a3 100644 --- a/app/DataMapper/Analytics/MigrationFailure.php +++ b/app/DataMapper/Analytics/MigrationFailure.php @@ -37,7 +37,7 @@ class MigrationFailure extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/QueueSize.php b/app/DataMapper/Analytics/QueueSize.php index 98816e06226bc..b489d3f0f10d6 100644 --- a/app/DataMapper/Analytics/QueueSize.php +++ b/app/DataMapper/Analytics/QueueSize.php @@ -37,7 +37,7 @@ class QueueSize extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/SendRecurringFailure.php b/app/DataMapper/Analytics/SendRecurringFailure.php index 1d35e6da74101..1ddf02cbeb3f3 100644 --- a/app/DataMapper/Analytics/SendRecurringFailure.php +++ b/app/DataMapper/Analytics/SendRecurringFailure.php @@ -37,7 +37,7 @@ class SendRecurringFailure extends GenericMixedMetric * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/TrialFinished.php b/app/DataMapper/Analytics/TrialFinished.php index 4ca9dd8b1ee4c..69f1c5db69cc1 100644 --- a/app/DataMapper/Analytics/TrialFinished.php +++ b/app/DataMapper/Analytics/TrialFinished.php @@ -37,7 +37,7 @@ class TrialFinished extends GenericCounter * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/DataMapper/Analytics/TrialStarted.php b/app/DataMapper/Analytics/TrialStarted.php index 0b6a1d9c7ba5d..15bba1be6782b 100644 --- a/app/DataMapper/Analytics/TrialStarted.php +++ b/app/DataMapper/Analytics/TrialStarted.php @@ -37,7 +37,7 @@ class TrialStarted extends GenericCounter * * date("Y-m-d H:i:s") * - * @var DateTime + * @var \DateTime */ public $datetime; diff --git a/app/Events/Account/AccountCreated.php b/app/Events/Account/AccountCreated.php index fc4f7e3f098c9..f2149b2a82d2e 100644 --- a/app/Events/Account/AccountCreated.php +++ b/app/Events/Account/AccountCreated.php @@ -47,13 +47,14 @@ class AccountCreated $this->event_vars = $event_vars; } - /** - * Get the channels the event should broadcast on. - * - * @return Channel|array - */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + // /** + // * Get the channels the event should broadcast on. + // * + // * @return Channel|array + // */ + public function broadcastOn() + { + return []; + // return new PrivateChannel('channel-name'); + } } diff --git a/app/Events/Client/ClientWasArchived.php b/app/Events/Client/ClientWasArchived.php index 709d9c7b11ac4..aca000b8e594e 100644 --- a/app/Events/Client/ClientWasArchived.php +++ b/app/Events/Client/ClientWasArchived.php @@ -49,13 +49,13 @@ class ClientWasArchived $this->event_vars = $event_vars; } - /** - * Get the channels the event should broadcast on. - * - * @return Channel|array - */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + // /** + // * Get the channels the event should broadcast on. + // * + // * @return Channel|array + // */ + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/Company/CompanyDocumentsDeleted.php b/app/Events/Company/CompanyDocumentsDeleted.php index 181ed024ea5f6..2c8f11c4f27f8 100644 --- a/app/Events/Company/CompanyDocumentsDeleted.php +++ b/app/Events/Company/CompanyDocumentsDeleted.php @@ -42,8 +42,8 @@ class CompanyDocumentsDeleted * * @return Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { +return []; + } } diff --git a/app/Events/Contact/ContactLoggedIn.php b/app/Events/Contact/ContactLoggedIn.php index ac19467f9b09e..577ebed0cde3f 100644 --- a/app/Events/Contact/ContactLoggedIn.php +++ b/app/Events/Contact/ContactLoggedIn.php @@ -53,8 +53,8 @@ class ContactLoggedIn * * @return Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/Design/DesignWasArchived.php b/app/Events/Design/DesignWasArchived.php index 898bc0b9031f8..1dd9105c7c638 100644 --- a/app/Events/Design/DesignWasArchived.php +++ b/app/Events/Design/DesignWasArchived.php @@ -26,29 +26,8 @@ class DesignWasArchived { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var Design - */ - public $design; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Design $design - * @param Company $company - * @param array $event_vars - */ - public function __construct(Design $design, Company $company, array $event_vars) + public function __construct(public Design $design, public Company $company, public array $event_vars) { - $this->design = $design; - - $this->company = $company; - - $this->event_vars = $event_vars; } /** @@ -56,8 +35,8 @@ class DesignWasArchived * * @return Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/Design/DesignWasCreated.php b/app/Events/Design/DesignWasCreated.php index 6f005f1b86d7d..c919768ac511e 100644 --- a/app/Events/Design/DesignWasCreated.php +++ b/app/Events/Design/DesignWasCreated.php @@ -11,9 +11,10 @@ namespace App\Events\Design; -use App\Models\Company; use App\Models\Design; +use App\Models\Company; use Illuminate\Queue\SerializesModels; +use Illuminate\Broadcasting\PrivateChannel; /** * Class DesignWasCreated. @@ -22,29 +23,8 @@ class DesignWasCreated { use SerializesModels; - /** - * @var Design - */ - public $design; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Design $design - * @param Company $company - * @param array $event_vars - */ - public function __construct(Design $design, Company $company, array $event_vars) + public function __construct(public Design $design, public Company $company, public array $event_vars) { - $this->design = $design; - - $this->company = $company; - - $this->event_vars = $event_vars; } /** @@ -52,8 +32,8 @@ class DesignWasCreated * * @return PrivateChannel */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/Design/DesignWasDeleted.php b/app/Events/Design/DesignWasDeleted.php index b0f1479613924..f2339cd59d1f2 100644 --- a/app/Events/Design/DesignWasDeleted.php +++ b/app/Events/Design/DesignWasDeleted.php @@ -11,9 +11,10 @@ namespace App\Events\Design; -use App\Models\Company; use App\Models\Design; +use App\Models\Company; use Illuminate\Queue\SerializesModels; +use Illuminate\Broadcasting\PrivateChannel; /** * Class DesignWasDeleted. @@ -22,38 +23,17 @@ class DesignWasDeleted { use SerializesModels; - /** - * @var Design - */ - public $design; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Design $design - * @param Company $company - * @param array $event_vars - */ - public function __construct(Design $design, Company $company, array $event_vars) + public function __construct(public Design $design, public Company $company, public array $event_vars) { - $this->design = $design; - - $this->company = $company; - - $this->event_vars = $event_vars; } /** * Get the channels the event should broadcast on. * * @return PrivateChannel - */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + */ + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/Design/DesignWasRestored.php b/app/Events/Design/DesignWasRestored.php index e1a52463af940..789ff15a684b1 100644 --- a/app/Events/Design/DesignWasRestored.php +++ b/app/Events/Design/DesignWasRestored.php @@ -11,9 +11,10 @@ namespace App\Events\Design; -use App\Models\Company; use App\Models\Design; +use App\Models\Company; use Illuminate\Queue\SerializesModels; +use Illuminate\Broadcasting\PrivateChannel; /** * Class DesignWasRestored. @@ -22,33 +23,8 @@ class DesignWasRestored { use SerializesModels; - /** - * @var Design - */ - public $design; - - public $company; - - public $event_vars; - - public $fromDeleted; - - /** - * Create a new event instance. - * - * @param Design $design - * @param Company $company - * @param array $event_vars - */ - public function __construct(Design $design, $fromDeleted, Company $company, array $event_vars) + public function __construct(public Design $design, public bool $fromDeleted, public Company $company, public array $event_vars) { - $this->design = $design; - - $this->fromDeleted = $fromDeleted; - - $this->company = $company; - - $this->event_vars = $event_vars; } /** @@ -56,8 +32,8 @@ class DesignWasRestored * * @return PrivateChannel */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/Design/DesignWasUpdated.php b/app/Events/Design/DesignWasUpdated.php index 18ec8c634d14b..30d49a85c4fb3 100644 --- a/app/Events/Design/DesignWasUpdated.php +++ b/app/Events/Design/DesignWasUpdated.php @@ -11,9 +11,10 @@ namespace App\Events\Design; -use App\Models\Company; use App\Models\Design; +use App\Models\Company; use Illuminate\Queue\SerializesModels; +use Illuminate\Broadcasting\PrivateChannel; /** * Class DesignWasUpdated. @@ -22,29 +23,8 @@ class DesignWasUpdated { use SerializesModels; - /** - * @var Design - */ - public $design; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Design $design - * @param Company $company - * @param array $event_vars - */ - public function __construct(Design $design, Company $company, array $event_vars) + public function __construct(public Design $design, public Company $company, public array $event_vars) { - $this->design = $design; - - $this->company = $company; - - $this->event_vars = $event_vars; } /** @@ -52,8 +32,8 @@ class DesignWasUpdated * * @return PrivateChannel */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/Document/DocumentWasArchived.php b/app/Events/Document/DocumentWasArchived.php index d504e94f63784..229e7d6c16735 100644 --- a/app/Events/Document/DocumentWasArchived.php +++ b/app/Events/Document/DocumentWasArchived.php @@ -56,6 +56,6 @@ class DocumentWasArchived */ public function broadcastOn() { - return new PrivateChannel('channel-name'); + return []; } } diff --git a/app/Events/Invoice/InvoiceReminderWasEmailed.php b/app/Events/Invoice/InvoiceReminderWasEmailed.php index 855aded2e6043..4eec242ee0a6b 100644 --- a/app/Events/Invoice/InvoiceReminderWasEmailed.php +++ b/app/Events/Invoice/InvoiceReminderWasEmailed.php @@ -22,29 +22,7 @@ class InvoiceReminderWasEmailed { use SerializesModels; - /** - * @var Invoice - */ - public $invitation; - - public $reminder; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param InvoiceInvitation $invitation - * @param Company $company - * @param array $event_vars - */ - public function __construct(InvoiceInvitation $invitation, Company $company, array $event_vars, string $reminder) + public function __construct(public InvoiceInvitation $invitation, public Company $company, public array $event_vars, public int $reminder) { - $this->invitation = $invitation; - $this->company = $company; - $this->event_vars = $event_vars; - $this->reminder = $reminder; } } diff --git a/app/Events/Invoice/InvoiceWasCreated.php b/app/Events/Invoice/InvoiceWasCreated.php index 741b40b639308..cf1da1c425213 100644 --- a/app/Events/Invoice/InvoiceWasCreated.php +++ b/app/Events/Invoice/InvoiceWasCreated.php @@ -56,17 +56,17 @@ class InvoiceWasCreated implements ShouldBroadcast */ public function broadcastOn() { - return ['simple-channel']; + return []; } - /** - * Get the data to broadcast. - * - * @return array - */ - public function broadcastWith(): array - { - return ['id' => 'value']; - } + // /** + // * Get the data to broadcast. + // * + // * @return array + // */ + // public function broadcastWith(): array + // { + // return ['id' => 'value']; + // } } diff --git a/app/Events/Invoice/InvoiceWasEmailedAndFailed.php b/app/Events/Invoice/InvoiceWasEmailedAndFailed.php index eb72a09b9be60..b3d13d28f46af 100644 --- a/app/Events/Invoice/InvoiceWasEmailedAndFailed.php +++ b/app/Events/Invoice/InvoiceWasEmailedAndFailed.php @@ -21,34 +21,7 @@ class InvoiceWasEmailedAndFailed { use SerializesModels; - public $invitation; - - public $message; - - public $company; - - public $event_vars; - - public $template; - - /** - * Create a new event instance. - * - * @param $invitation - * @param Company $company - * @param string $errors - * @param array $event_vars - */ - public function __construct($invitation, Company $company, string $message, string $template, array $event_vars) + public function __construct(public mixed $invitation, public Company $company, public string $message, public string $template, public array $event_vars) { - $this->invitation = $invitation; - - $this->company = $company; - - $this->message = $message; - - $this->event_vars = $event_vars; - - $this->template = $template; } } diff --git a/app/Events/Invoice/InvoiceWasViewed.php b/app/Events/Invoice/InvoiceWasViewed.php index cd3ba6a6f3858..81a64574a4ea8 100644 --- a/app/Events/Invoice/InvoiceWasViewed.php +++ b/app/Events/Invoice/InvoiceWasViewed.php @@ -22,14 +22,6 @@ class InvoiceWasViewed { use SerializesModels; - /** - * @var Invoice - */ - public $invitation; - - public $company; - - public $event_vars; /** * Create a new event instance. @@ -38,10 +30,7 @@ class InvoiceWasViewed * @param Company $company * @param array $event_vars */ - public function __construct(InvoiceInvitation $invitation, Company $company, array $event_vars) + public function __construct(public InvoiceInvitation $invitation, Company $company, array $event_vars) { - $this->invitation = $invitation; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/Methods/MethodDeleted.php b/app/Events/Payment/Methods/MethodDeleted.php index d93fd4108c4b1..4b1d3d7103978 100644 --- a/app/Events/Payment/Methods/MethodDeleted.php +++ b/app/Events/Payment/Methods/MethodDeleted.php @@ -51,8 +51,8 @@ class MethodDeleted * * @return Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/Product/ProductWasArchived.php b/app/Events/Product/ProductWasArchived.php index dec5209c9afa1..bbea05f967dba 100644 --- a/app/Events/Product/ProductWasArchived.php +++ b/app/Events/Product/ProductWasArchived.php @@ -19,26 +19,7 @@ class ProductWasArchived { use SerializesModels; - /** - * @var Product - */ - public $product; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Product $product - * @param Company $company - * @param array $event_vars - */ - public function __construct(Product $product, Company $company, array $event_vars) + public function __construct(public Product $product, public Company $company, public array $event_vars) { - $this->product = $product; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/Product/ProductWasCreated.php b/app/Events/Product/ProductWasCreated.php index acd2978d31041..a4c5aac30e97f 100644 --- a/app/Events/Product/ProductWasCreated.php +++ b/app/Events/Product/ProductWasCreated.php @@ -19,30 +19,7 @@ class ProductWasCreated { use SerializesModels; - /** - * @var Product - */ - public $product; - - public $input; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Product $product - * @param $input - * @param Company $company - * @param array $event_vars - */ - public function __construct(Product $product, $input, Company $company, array $event_vars) + public function __construct(public Product $product, public mixed $input, public Company $company, public array $event_vars) { - $this->product = $product; - $this->input = $input; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/Product/ProductWasDeleted.php b/app/Events/Product/ProductWasDeleted.php index 9ebea4acd5c59..b1fee5066cab1 100644 --- a/app/Events/Product/ProductWasDeleted.php +++ b/app/Events/Product/ProductWasDeleted.php @@ -19,26 +19,7 @@ class ProductWasDeleted { use SerializesModels; - /** - * @var Product - */ - public $product; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Product $product - * @param Company $company - * @param array $event_vars - */ - public function __construct(Product $product, Company $company, array $event_vars) + public function __construct(public Product $product, public Company $company, public array $event_vars) { - $this->product = $product; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/Product/ProductWasRestored.php b/app/Events/Product/ProductWasRestored.php index 88353d47da58d..b19ad5eef8c47 100644 --- a/app/Events/Product/ProductWasRestored.php +++ b/app/Events/Product/ProductWasRestored.php @@ -22,29 +22,7 @@ class ProductWasRestored { use SerializesModels; - /** - * @var Product - */ - public $invoice; - - public $company; - - public $event_vars; - - public $fromDeleted; - - /** - * Create a new event instance. - * - * @param Product $invoice - * @param Company $company - * @param array $event_vars - */ - public function __construct(Product $product, $fromDeleted, Company $company, array $event_vars) + public function __construct(public Product $product, public bool $fromDeleted, public Company $company, public array $event_vars) { - $this->product = $product; - $this->fromDeleted = $fromDeleted; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/Product/ProductWasUpdated.php b/app/Events/Product/ProductWasUpdated.php index de8850458efa1..e84604d876134 100644 --- a/app/Events/Product/ProductWasUpdated.php +++ b/app/Events/Product/ProductWasUpdated.php @@ -11,6 +11,7 @@ namespace App\Events\Product; +use App\Models\Company; use App\Models\Product; use Illuminate\Queue\SerializesModels; @@ -18,26 +19,7 @@ class ProductWasUpdated { use SerializesModels; - /** - * @var Product - */ - public $product; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Product $product - * @param Company $company - * @param array $event_vars - */ - public function __construct(Product $product, Company $company, array $event_vars) + public function __construct(public Product $product, public Company $company, public array $event_vars) { - $this->product = $product; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/PurchaseOrder/PurchaseOrderWasEmailed.php b/app/Events/PurchaseOrder/PurchaseOrderWasEmailed.php index e2e391cf3c22c..d1040a75fe93a 100644 --- a/app/Events/PurchaseOrder/PurchaseOrderWasEmailed.php +++ b/app/Events/PurchaseOrder/PurchaseOrderWasEmailed.php @@ -12,7 +12,6 @@ namespace App\Events\PurchaseOrder; use App\Models\Company; -use App\Models\PurchaseOrder; use App\Models\PurchaseOrderInvitation; use Illuminate\Queue\SerializesModels; @@ -23,26 +22,7 @@ class PurchaseOrderWasEmailed { use SerializesModels; - /** - * @var PurchaseOrder - */ - public $invitation; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param PurchaseOrder $purchase_order - * @param Company $company - * @param array $event_vars - */ - public function __construct(PurchaseOrderInvitation $invitation, Company $company, array $event_vars) + public function __construct(public PurchaseOrderInvitation $invitation, public Company $company, public array $event_vars) { - $this->invitation = $invitation; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/PurchaseOrder/PurchaseOrderWasRestored.php b/app/Events/PurchaseOrder/PurchaseOrderWasRestored.php index 0d551f3974ba1..b9866b1f56432 100644 --- a/app/Events/PurchaseOrder/PurchaseOrderWasRestored.php +++ b/app/Events/PurchaseOrder/PurchaseOrderWasRestored.php @@ -22,29 +22,7 @@ class PurchaseOrderWasRestored { use SerializesModels; - /** - * @var PurchaseOrder - */ - public $purchase_order; - - public $company; - - public $event_vars; - - public $fromDeleted; - - /** - * Create a new event instance. - * - * @param PurchaseOrder $purchase_order - * @param Company $company - * @param array $event_vars - */ - public function __construct(PurchaseOrder $purchase_order, $fromDeleted, Company $company, array $event_vars) + public function __construct(public PurchaseOrder $purchase_order, public bool $fromDeleted, public Company $company, public array $event_vars) { - $this->purchase_order = $purchase_order; - $this->fromDeleted = $fromDeleted; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/PurchaseOrder/PurchaseOrderWasUpdated.php b/app/Events/PurchaseOrder/PurchaseOrderWasUpdated.php index 91b77473b9962..2abaeaf6db9d1 100644 --- a/app/Events/PurchaseOrder/PurchaseOrderWasUpdated.php +++ b/app/Events/PurchaseOrder/PurchaseOrderWasUpdated.php @@ -22,26 +22,7 @@ class PurchaseOrderWasUpdated { use SerializesModels; - /** - * @var PurchaseOrder - */ - public $purchase_order; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param PurchaseOrder $purchase_order - * @param Company $company - * @param array $event_vars - */ - public function __construct(PurchaseOrder $purchase_order, Company $company, array $event_vars) + public function __construct(public PurchaseOrder $purchase_order, public Company $company, public array $event_vars) { - $this->purchase_order = $purchase_order; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/PurchaseOrder/PurchaseOrderWasViewed.php b/app/Events/PurchaseOrder/PurchaseOrderWasViewed.php index 9caa4131aef69..a144639a68720 100644 --- a/app/Events/PurchaseOrder/PurchaseOrderWasViewed.php +++ b/app/Events/PurchaseOrder/PurchaseOrderWasViewed.php @@ -23,26 +23,7 @@ class PurchaseOrderWasViewed { use SerializesModels; - /** - * @var PurchaseOrder - */ - public $invitation; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param PurchaseOrder $purchase_order - * @param Company $company - * @param array $event_vars - */ - public function __construct(PurchaseOrderInvitation $invitation, Company $company, array $event_vars) + public function __construct(public PurchaseOrderInvitation $invitation, public Company $company, public array $event_vars) { - $this->invitation = $invitation; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasEmailed.php b/app/Events/Quote/QuoteWasEmailed.php index 3f317a6fb818a..5792167c42d99 100644 --- a/app/Events/Quote/QuoteWasEmailed.php +++ b/app/Events/Quote/QuoteWasEmailed.php @@ -23,27 +23,7 @@ class QuoteWasEmailed { use SerializesModels; - public $invitation; - - public $company; - - public $event_vars; - - public $template; - - /** - * Create a new event instance. - * - * @param Quote $quote - * @param string $notes - * @param Company $company - * @param array $event_vars - */ - public function __construct(QuoteInvitation $invitation, Company $company, array $event_vars, string $template) + public function __construct(public QuoteInvitation $invitation, public Company $company, public array $event_vars, public string $template) { - $this->invitation = $invitation; - $this->company = $company; - $this->event_vars = $event_vars; - $this->template = $template; } } diff --git a/app/Events/RecurringInvoice/RecurringInvoiceWasArchived.php b/app/Events/RecurringInvoice/RecurringInvoiceWasArchived.php index 41d40332c97c5..33f9029cceda8 100644 --- a/app/Events/RecurringInvoice/RecurringInvoiceWasArchived.php +++ b/app/Events/RecurringInvoice/RecurringInvoiceWasArchived.php @@ -22,26 +22,7 @@ class RecurringInvoiceWasArchived { use SerializesModels; - /** - * @var Invoice - */ - public $recurring_invoice; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Invoice $recurring_invoice - * @param Company $company - * @param array $event_vars - */ - public function __construct(RecurringInvoice $recurring_invoice, Company $company, array $event_vars) + public function __construct(public RecurringInvoice $recurring_invoice, public Company $company, public array $event_vars) { - $this->recurring_invoice = $recurring_invoice; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/RecurringInvoice/RecurringInvoiceWasDeleted.php b/app/Events/RecurringInvoice/RecurringInvoiceWasDeleted.php index b652206b05124..2ee4d85686c83 100644 --- a/app/Events/RecurringInvoice/RecurringInvoiceWasDeleted.php +++ b/app/Events/RecurringInvoice/RecurringInvoiceWasDeleted.php @@ -21,27 +21,8 @@ use Illuminate\Queue\SerializesModels; class RecurringInvoiceWasDeleted { use SerializesModels; - - /** - * @var RecurringInvoice - */ - public $recurring_invoice; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Invoice $invoice - * @param Company $company - * @param array $event_vars - */ - public function __construct(RecurringInvoice $recurring_invoice, Company $company, array $event_vars) + + public function __construct(public RecurringInvoice $recurring_invoice, public Company $company, public array $event_vars) { - $this->recurring_invoice = $recurring_invoice; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/RecurringInvoice/RecurringInvoiceWasRestored.php b/app/Events/RecurringInvoice/RecurringInvoiceWasRestored.php index 017fbdc153925..e203ab6c46089 100644 --- a/app/Events/RecurringInvoice/RecurringInvoiceWasRestored.php +++ b/app/Events/RecurringInvoice/RecurringInvoiceWasRestored.php @@ -22,30 +22,7 @@ class RecurringInvoiceWasRestored { use SerializesModels; - /** - * @var RecurringInvoice - */ - public $recurring_invoice; - - public $fromDeleted; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Invoice $invoice - * @param $fromDeleted - * @param Company $company - * @param array $event_vars - */ - public function __construct(RecurringInvoice $recurring_invoice, $fromDeleted, Company $company, array $event_vars) + public function __construct(public RecurringInvoice $recurring_invoice, public bool $fromDeleted, public Company $company, public array $event_vars) { - $this->recurring_invoice = $recurring_invoice; - $this->fromDeleted = $fromDeleted; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/RecurringInvoice/RecurringInvoiceWasUpdated.php b/app/Events/RecurringInvoice/RecurringInvoiceWasUpdated.php index 6cccfcf3e2226..8298f32d3f45a 100644 --- a/app/Events/RecurringInvoice/RecurringInvoiceWasUpdated.php +++ b/app/Events/RecurringInvoice/RecurringInvoiceWasUpdated.php @@ -24,26 +24,7 @@ class RecurringInvoiceWasUpdated { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var Invoice - */ - public $recurring_invoice; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param RecurringInvoice $recurring_invoice - * @param Company $company - * @param array $event_vars - */ - public function __construct(RecurringInvoice $recurring_invoice, Company $company, array $event_vars) + public function __construct(public RecurringInvoice $recurring_invoice, public Company $company, public array $event_vars) { - $this->recurring_invoice = $recurring_invoice; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/RecurringQuote/RecurringQuoteWasDeleted.php b/app/Events/RecurringQuote/RecurringQuoteWasDeleted.php index 2e2fbb6379a3c..2c856d4c3311c 100644 --- a/app/Events/RecurringQuote/RecurringQuoteWasDeleted.php +++ b/app/Events/RecurringQuote/RecurringQuoteWasDeleted.php @@ -22,26 +22,7 @@ class RecurringQuoteWasDeleted { use SerializesModels; - /** - * @var RecurringQuote - */ - public $recurring_quote; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Invoice $invoice - * @param Company $company - * @param array $event_vars - */ - public function __construct(RecurringQuote $recurring_quote, Company $company, array $event_vars) + public function __construct(public RecurringQuote $recurring_quote, public Company $company, public array $event_vars) { - $this->recurring_quote = $recurring_quote; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/RecurringQuote/RecurringQuoteWasRestored.php b/app/Events/RecurringQuote/RecurringQuoteWasRestored.php index d0add0f36c7a2..831f21720438d 100644 --- a/app/Events/RecurringQuote/RecurringQuoteWasRestored.php +++ b/app/Events/RecurringQuote/RecurringQuoteWasRestored.php @@ -22,30 +22,7 @@ class RecurringQuoteWasRestored { use SerializesModels; - /** - * @var RecurringQuote - */ - public $recurring_quote; - - public $fromDeleted; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param Invoice $invoice - * @param $fromDeleted - * @param Company $company - * @param array $event_vars - */ - public function __construct(RecurringQuote $recurring_quote, $fromDeleted, Company $company, array $event_vars) + public function __construct(public RecurringQuote $recurring_quote, public bool $fromDeleted, public Company $company, public array $event_vars) { - $this->recurring_quote = $recurring_quote; - $this->fromDeleted = $fromDeleted; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/RecurringQuote/RecurringQuoteWasUpdated.php b/app/Events/RecurringQuote/RecurringQuoteWasUpdated.php index 7c2ce1767efd1..5d3a9da30ca91 100644 --- a/app/Events/RecurringQuote/RecurringQuoteWasUpdated.php +++ b/app/Events/RecurringQuote/RecurringQuoteWasUpdated.php @@ -24,26 +24,8 @@ class RecurringQuoteWasUpdated { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var Invoice - */ - public $recurring_quote; - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param RecurringQuote $recurring_quote - * @param Company $company - * @param array $event_vars - */ - public function __construct(RecurringQuote $recurring_quote, Company $company, array $event_vars) + public function __construct(public RecurringQuote $recurring_quote, public Company $company, public array $event_vars) { - $this->recurring_quote = $recurring_quote; - $this->company = $company; - $this->event_vars = $event_vars; } } diff --git a/app/Events/Subscription/SubscriptionWasCreated.php b/app/Events/Subscription/SubscriptionWasCreated.php index 1aef2036b4ed6..9d1616defb281 100644 --- a/app/Events/Subscription/SubscriptionWasCreated.php +++ b/app/Events/Subscription/SubscriptionWasCreated.php @@ -45,8 +45,8 @@ class SubscriptionWasCreated * * @return \Illuminate\Broadcasting\Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/User/UserLoggedIn.php b/app/Events/User/UserLoggedIn.php index 8760679242d39..f3b55c2a1c71a 100644 --- a/app/Events/User/UserLoggedIn.php +++ b/app/Events/User/UserLoggedIn.php @@ -26,27 +26,8 @@ class UserLoggedIn { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var - */ - public $user; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param User $user - * @param Company $company - * @param array $event_vars - */ - public function __construct(User $user, Company $company, array $event_vars) + public function __construct(public User $user, public Company $company, public array $event_vars) { - $this->user = $user; - $this->company = $company; - $this->event_vars = $event_vars; } /** @@ -54,8 +35,8 @@ class UserLoggedIn * * @return Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/User/UserWasArchived.php b/app/Events/User/UserWasArchived.php index 4c78d3e0c8d49..51657baffbfc3 100644 --- a/app/Events/User/UserWasArchived.php +++ b/app/Events/User/UserWasArchived.php @@ -26,30 +26,8 @@ class UserWasArchived { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var - */ - public $user; - - public $creating_user; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param User $user - * @param Company $company - * @param array $event_vars - */ - public function __construct(User $user, User $creating_user, Company $company, array $event_vars) + public function __construct(public User $user, public User $creating_user, public Company $company, public array $event_vars) { - $this->user = $user; - $this->creating_user = $creating_user; - $this->company = $company; - $this->event_vars = $event_vars; } /** @@ -57,8 +35,8 @@ class UserWasArchived * * @return Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/User/UserWasCreated.php b/app/Events/User/UserWasCreated.php index 72fec733a95f6..36268aa5d157c 100644 --- a/app/Events/User/UserWasCreated.php +++ b/app/Events/User/UserWasCreated.php @@ -26,30 +26,8 @@ class UserWasCreated { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var - */ - public $user; - - public $creating_user; - - public $company; - - public $event_vars; - - /** - * Create a new event instance. - * - * @param User $user - * @param Company $company - * @param array $event_vars - */ - public function __construct(User $user, User $creating_user, Company $company, array $event_vars) + public function __construct(public User $user, public User $creating_user, public Company $company, public array $event_vars) { - $this->user = $user; - $this->creating_user = $creating_user; - $this->company = $company; - $this->event_vars = $event_vars; } /** @@ -57,8 +35,8 @@ class UserWasCreated * * @return Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/User/UserWasDeleted.php b/app/Events/User/UserWasDeleted.php index a4e596e90f70e..04e6e68a26512 100644 --- a/app/Events/User/UserWasDeleted.php +++ b/app/Events/User/UserWasDeleted.php @@ -57,8 +57,8 @@ class UserWasDeleted * * @return Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/User/UserWasRestored.php b/app/Events/User/UserWasRestored.php index eeefc0da49247..10870b0b09edf 100644 --- a/app/Events/User/UserWasRestored.php +++ b/app/Events/User/UserWasRestored.php @@ -57,8 +57,8 @@ class UserWasRestored * * @return Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Events/User/UserWasUpdated.php b/app/Events/User/UserWasUpdated.php index ac5b5145cd68b..79bf871eaa563 100644 --- a/app/Events/User/UserWasUpdated.php +++ b/app/Events/User/UserWasUpdated.php @@ -57,8 +57,8 @@ class UserWasUpdated * * @return Channel|array */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } + public function broadcastOn() + { + return []; + } } diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index f3a086967f7c3..2b6b02ff938a1 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -11,28 +11,30 @@ namespace App\Exceptions; +use Throwable; +use PDOException; use App\Utils\Ninja; -use Illuminate\Auth\Access\AuthorizationException; -use Illuminate\Auth\AuthenticationException; -use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException; -use Illuminate\Database\Eloquent\RelationNotFoundException; -use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; -use Illuminate\Http\Exceptions\ThrottleRequestsException; +use Sentry\State\Scope; +use Illuminate\Support\Arr; use Illuminate\Http\Request; use Illuminate\Http\Response; -use Illuminate\Queue\MaxAttemptsExceededException; -use Illuminate\Session\TokenMismatchException; -use Illuminate\Support\Arr; -use Illuminate\Support\Facades\Schema; -use Illuminate\Validation\ValidationException; -use League\Flysystem\UnableToCreateDirectory; -use PDOException; use Sentry\Laravel\Integration; -use Sentry\State\Scope; +use Illuminate\Support\Facades\Schema; +use GuzzleHttp\Exception\ConnectException; +use Illuminate\Auth\AuthenticationException; +use League\Flysystem\UnableToCreateDirectory; +use Illuminate\Session\TokenMismatchException; +use Illuminate\Validation\ValidationException; +use Illuminate\Auth\Access\AuthorizationException; +use Illuminate\Queue\MaxAttemptsExceededException; +use Illuminate\Http\Exceptions\ThrottleRequestsException; +use Symfony\Component\Process\Exception\RuntimeException; +use Illuminate\Database\Eloquent\RelationNotFoundException; +use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Symfony\Component\Console\Exception\CommandNotFoundException; -use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Throwable; +use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; +use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException; class Handler extends ExceptionHandler { @@ -59,10 +61,9 @@ class Handler extends ExceptionHandler ModelNotFoundException::class, NotFoundHttpException::class, UnableToCreateDirectory::class, - GuzzleHttp\Exception\ConnectException::class, - Symfony\Component\Process\Exception\RuntimeException::class, - InvalidArgumentException::class, + ConnectException::class, RuntimeException::class, + InvalidArgumentException::class, Aws\Exception\CredentialsException::class, ]; diff --git a/app/Export/CSV/ProductExport.php b/app/Export/CSV/ProductExport.php index 2b1a6d698f3d8..de1b41e031fc1 100644 --- a/app/Export/CSV/ProductExport.php +++ b/app/Export/CSV/ProductExport.php @@ -120,9 +120,9 @@ class ProductExport extends BaseExport $entity['vendor'] = $product->vendor()->exists() ? $product->vendor->name : ''; } - if (array_key_exists('project_id', $this->input['report_keys'])) { - $entity['project'] = $product->project()->exists() ? $product->project->name : ''; - } + // if (array_key_exists('project_id', $this->input['report_keys'])) { + // $entity['project'] = $product->project()->exists() ? $product->project->name : ''; + // } return $entity; } diff --git a/app/Export/CSV/ProductSalesExport.php b/app/Export/CSV/ProductSalesExport.php index e933f06d38dae..a3228dfcdb2f5 100644 --- a/app/Export/CSV/ProductSalesExport.php +++ b/app/Export/CSV/ProductSalesExport.php @@ -229,7 +229,7 @@ class ProductSalesExport extends BaseExport /** * calculateTax * - * @param mixed $invoice + * @param Invoice $invoice * @param float $amount * @param float $tax_rate * @return float @@ -250,7 +250,7 @@ class ProductSalesExport extends BaseExport /** * calculateDiscount * - * @param mixed $invoice + * @param Invoice $invoice * @param mixed $entity * @return float */ diff --git a/app/Factory/RecurringInvoiceFactory.php b/app/Factory/RecurringInvoiceFactory.php index 54fbbc354272f..fa2b4ee886e06 100644 --- a/app/Factory/RecurringInvoiceFactory.php +++ b/app/Factory/RecurringInvoiceFactory.php @@ -57,5 +57,6 @@ class RecurringInvoiceFactory $invoice->auto_bill = 'off'; return $invoice; + } } diff --git a/app/Filters/BankIntegrationFilters.php b/app/Filters/BankIntegrationFilters.php index c1340b6f2651c..f0a6aa117ce4d 100644 --- a/app/Filters/BankIntegrationFilters.php +++ b/app/Filters/BankIntegrationFilters.php @@ -36,7 +36,7 @@ class BankIntegrationFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter + * @param string $filter * @return Builder * @deprecated */ @@ -55,7 +55,7 @@ class BankIntegrationFilters extends QueryFilters * Filters the list based on the status * archived, active, deleted. * - * @param string filter + * @param string $filter * @return Builder */ public function status(string $filter = ''): Builder diff --git a/app/Filters/ClientFilters.php b/app/Filters/ClientFilters.php index c2b23f0ad28ff..5fae1e910955e 100644 --- a/app/Filters/ClientFilters.php +++ b/app/Filters/ClientFilters.php @@ -53,7 +53,7 @@ class ClientFilters extends QueryFilters /** * Filter between balances. * - * @param string balance + * @param string $balance * @return Builder */ public function between_balance(string $balance = ''): Builder @@ -108,7 +108,7 @@ class ClientFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter + * @param string $filter * @return Builder * @deprecated */ @@ -136,7 +136,7 @@ class ClientFilters extends QueryFilters /** * Sorts the list based on $sort. * - * @param string sort formatted as column|asc + * @param string $sort formatted as column|asc * @return Builder */ public function sort(string $sort = ''): Builder @@ -157,9 +157,9 @@ class ClientFilters extends QueryFilters /** * Filters the query by the users company ID. * - * @return Illuminate\Database\Query\Builder + * @return Builder */ - public function entityFilter() + public function entityFilter(): Builder { return $this->builder->company(); } diff --git a/app/Filters/CompanyGatewayFilters.php b/app/Filters/CompanyGatewayFilters.php index d7c07b5c92f1b..e41d61fac4ff1 100644 --- a/app/Filters/CompanyGatewayFilters.php +++ b/app/Filters/CompanyGatewayFilters.php @@ -21,7 +21,7 @@ class CompanyGatewayFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter + * @param string $filter * @return Builder * @deprecated */ @@ -39,7 +39,7 @@ class CompanyGatewayFilters extends QueryFilters /** * Sorts the list based on $sort. * - * @param string sort formatted as column|asc + * @param string $sort formatted as column|asc * @return Builder */ public function sort(string $sort = ''): Builder @@ -56,9 +56,9 @@ class CompanyGatewayFilters extends QueryFilters /** * Filters the query by the users company ID. * - * @return Illuminate\Database\Query\Builder + * @return Builder */ - public function entityFilter() + public function entityFilter(): Builder { return $this->builder->company(); } diff --git a/app/Filters/CreditFilters.php b/app/Filters/CreditFilters.php index ffbbba3fdb900..0370aa005d2fb 100644 --- a/app/Filters/CreditFilters.php +++ b/app/Filters/CreditFilters.php @@ -27,7 +27,7 @@ class CreditFilters extends QueryFilters * - overdue * - reversed * - * @param string credit_status The credit status as seen by the client + * @param string $value The credit status as seen by the client * @return Builder */ public function credit_status(string $value = ''): Builder @@ -66,7 +66,7 @@ class CreditFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter + * @param string $filter * @return Builder * @deprecated */ @@ -104,7 +104,7 @@ class CreditFilters extends QueryFilters /** * Sorts the list based on $sort. * - * @param string sort formatted as column|asc + * @param string $sort formatted as column|asc * @return Builder */ public function sort(string $sort = ''): Builder @@ -124,7 +124,7 @@ class CreditFilters extends QueryFilters * We need to ensure we are using the correct company ID * as we could be hitting this from either the client or company auth guard * - * @return Illuminate\Database\Query\Builder + * @return Builder */ public function entityFilter() { diff --git a/app/Filters/DocumentFilters.php b/app/Filters/DocumentFilters.php index 1b312161ab84f..73f9b4a0b2d13 100644 --- a/app/Filters/DocumentFilters.php +++ b/app/Filters/DocumentFilters.php @@ -22,7 +22,7 @@ class DocumentFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter + * @param string $filter * @return Builder * @deprecated */ @@ -52,7 +52,7 @@ class DocumentFilters extends QueryFilters /** * Sorts the list based on $sort. * - * @param string sort formatted as column|asc + * @param string $sort formatted as column|asc * @return Builder */ public function sort(string $sort = ''): Builder @@ -79,9 +79,9 @@ class DocumentFilters extends QueryFilters /** * Filters the query by the users company ID. * - * @return Illuminate\Database\Query\Builder + * @return Builder */ - public function entityFilter() + public function entityFilter(): Builder { return $this->builder->company(); } diff --git a/app/Filters/ExpenseCategoryFilters.php b/app/Filters/ExpenseCategoryFilters.php index b25ad4d282e9a..6e8edaa0c3a50 100644 --- a/app/Filters/ExpenseCategoryFilters.php +++ b/app/Filters/ExpenseCategoryFilters.php @@ -21,7 +21,7 @@ class ExpenseCategoryFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter + * @param string $filter * @return Builder * @deprecated */ @@ -37,7 +37,7 @@ class ExpenseCategoryFilters extends QueryFilters /** * Sorts the list based on $sort. * - * @param string sort formatted as column|asc + * @param string $sort formatted as column|asc * @return Builder */ public function sort(string $sort = ''): Builder @@ -59,9 +59,9 @@ class ExpenseCategoryFilters extends QueryFilters /** * Filters the query by the users company ID. * - * @return Illuminate\Database\Query\Builder + * @return Builder */ - public function entityFilter() + public function entityFilter(): Builder { return $this->builder->company(); } diff --git a/app/Filters/ExpenseFilters.php b/app/Filters/ExpenseFilters.php index 0ff6e69035a81..d589362a63b7a 100644 --- a/app/Filters/ExpenseFilters.php +++ b/app/Filters/ExpenseFilters.php @@ -21,7 +21,7 @@ class ExpenseFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter + * @param string $filter * @return Builder * @deprecated */ @@ -130,7 +130,7 @@ class ExpenseFilters extends QueryFilters /** * Sorts the list based on $sort. * - * @param string sort formatted as column|asc + * @param string $sort formatted as column|asc * @return Builder */ public function sort(string $sort = ''): Builder @@ -151,9 +151,9 @@ class ExpenseFilters extends QueryFilters /** * Filters the query by the users company ID. * - * @return Illuminate\Database\Query\Builder + * @return Builder */ - public function entityFilter() + public function entityFilter(): Builder { return $this->builder->company(); } diff --git a/app/Filters/PaymentFilters.php b/app/Filters/PaymentFilters.php index 550af5850e84a..58ab78f23687e 100644 --- a/app/Filters/PaymentFilters.php +++ b/app/Filters/PaymentFilters.php @@ -156,7 +156,7 @@ class PaymentFilters extends QueryFilters /** * Filters the query by the users company ID. * - * @return Illuminate\Database\Eloquent\Builder + * @return Builder */ public function entityFilter(): Builder { diff --git a/app/Filters/ProjectFilters.php b/app/Filters/ProjectFilters.php index bcb6d1f0a2604..d5abf0a7b86ec 100644 --- a/app/Filters/ProjectFilters.php +++ b/app/Filters/ProjectFilters.php @@ -21,8 +21,8 @@ class ProjectFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter - * @return Illuminate\Eloquent\Query\Builder + * @param string $filter + * @return Builder * @deprecated */ public function filter(string $filter = ''): Builder @@ -50,8 +50,8 @@ class ProjectFilters extends QueryFilters /** * Sorts the list based on $sort. * - * @param string sort formatted as column|asc - * @return Illuminate\Eloquent\Query\Builder + * @param string $sort formatted as column|asc + * @return Builder */ public function sort(string $sort = ''): Builder { @@ -69,7 +69,7 @@ class ProjectFilters extends QueryFilters /** * Filters the query by the users company ID. * - * @return Illuminate\Eloquent\Query\Builder + * @return Builder */ public function entityFilter(): Builder { diff --git a/app/Filters/PurchaseOrderFilters.php b/app/Filters/PurchaseOrderFilters.php index ea3035db32eee..4b86b618ac092 100644 --- a/app/Filters/PurchaseOrderFilters.php +++ b/app/Filters/PurchaseOrderFilters.php @@ -74,7 +74,7 @@ class PurchaseOrderFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter + * @param string $filter * @return Builder * @deprecated */ @@ -112,7 +112,7 @@ class PurchaseOrderFilters extends QueryFilters /** * Sorts the list based on $sort. * - * @param string sort formatted as column|asc + * @param string $sort formatted as column|asc * @return Builder */ public function sort(string $sort = ''): Builder diff --git a/app/Filters/RecurringInvoiceFilters.php b/app/Filters/RecurringInvoiceFilters.php index 2a38a3a04deba..40326ca944a64 100644 --- a/app/Filters/RecurringInvoiceFilters.php +++ b/app/Filters/RecurringInvoiceFilters.php @@ -151,7 +151,7 @@ class RecurringInvoiceFilters extends QueryFilters /** * next send date between. * - * @param string range + * @param string $range * @return Builder */ public function next_send_between(string $range = ''): Builder @@ -187,7 +187,7 @@ class RecurringInvoiceFilters extends QueryFilters /** * Filter by frequency id. * - * @param integer frequency_id + * @param string $value * @return Builder */ public function frequency_id(string $value = ''): Builder diff --git a/app/Filters/RecurringQuoteFilters.php b/app/Filters/RecurringQuoteFilters.php index eb9d593aa221a..2ac2a170d2e1f 100644 --- a/app/Filters/RecurringQuoteFilters.php +++ b/app/Filters/RecurringQuoteFilters.php @@ -21,8 +21,8 @@ class RecurringQuoteFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter - * @return Illuminate\Database\Eloquent\Builder + * @param string $filter + * @return Builder * @deprecated */ public function filter(string $filter = ''): Builder @@ -51,8 +51,8 @@ class RecurringQuoteFilters extends QueryFilters /** * Sorts the list based on $sort. * - * @param string sort formatted as column|asc - * @return Illuminate\Database\Eloquent\Builder + * @param string $sort formatted as column|asc + * @return Builder */ public function sort(string $sort = ''): Builder { @@ -68,7 +68,7 @@ class RecurringQuoteFilters extends QueryFilters /** * Filters the query by the users company ID. * - * @return Illuminate\Database\Eloquent\Builder + * @return Builder */ public function entityFilter(): Builder { diff --git a/app/Filters/SchedulerFilters.php b/app/Filters/SchedulerFilters.php index 5721c1502035d..8368b34be09f4 100644 --- a/app/Filters/SchedulerFilters.php +++ b/app/Filters/SchedulerFilters.php @@ -21,7 +21,7 @@ class SchedulerFilters extends QueryFilters /** * Filter based on search text. * - * @param string query filter + * @param string $filter * @return Builder * @deprecated */ @@ -39,7 +39,7 @@ class SchedulerFilters extends QueryFilters /** * Sorts the list based on $sort. * - * @param string sort formatted as column|asc + * @param string $sort formatted as column|asc * @return Builder */ public function sort(string $sort = ''): Builder diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index 6c6846470378a..0ed53d0472464 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -11,13 +11,17 @@ namespace App\Helpers\Invoice; +use App\Models\Quote; use App\Models\Client; +use App\Models\Credit; use App\Models\Invoice; +use App\Models\PurchaseOrder; +use App\Models\RecurringQuote; use App\DataMapper\InvoiceItem; use App\DataMapper\BaseSettings; +use App\Models\RecurringInvoice; use App\DataMapper\Tax\RuleInterface; use App\Utils\Traits\NumberFormatter; -use App\DataMapper\Tax\ZipTax\Response; class InvoiceItemSum { @@ -59,7 +63,7 @@ class InvoiceItemSum 'AU', // Australia ]; - protected $invoice; + protected RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; private $items; @@ -91,7 +95,7 @@ class InvoiceItemSum private RuleInterface $rule; - public function __construct($invoice) + public function __construct( RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice) { $this->tax_collection = collect([]); @@ -108,9 +112,9 @@ class InvoiceItemSum $this->line_items = []; } - public function process() + public function process(): self { - if (! $this->invoice->line_items || ! isset($this->invoice->line_items) || ! is_array($this->invoice->line_items) || count($this->invoice->line_items) == 0) { + if (!$this->invoice->line_items || !is_array($this->invoice->line_items)) { $this->items = []; return $this; @@ -121,7 +125,7 @@ class InvoiceItemSum return $this; } - private function calcLineItems() + private function calcLineItems(): self { foreach ($this->invoice->line_items as $this->item) { $this->cleanLineItem() @@ -136,7 +140,7 @@ class InvoiceItemSum private function shouldCalculateTax(): self { - if (!$this->invoice->company?->calculate_taxes) { + if (!$this->invoice->company->calculate_taxes) { $this->calc_tax = false; return $this; } @@ -159,7 +163,7 @@ class InvoiceItemSum return $this; } - private function push() + private function push(): self { $this->sub_total += $this->getLineTotal(); diff --git a/app/Helpers/Invoice/InvoiceItemSumInclusive.php b/app/Helpers/Invoice/InvoiceItemSumInclusive.php index 21f12bc5e55c4..7f8d33b2dd021 100644 --- a/app/Helpers/Invoice/InvoiceItemSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceItemSumInclusive.php @@ -11,7 +11,12 @@ namespace App\Helpers\Invoice; +use App\Models\Quote; +use App\Models\Credit; use App\Models\Invoice; +use App\Models\PurchaseOrder; +use App\Models\RecurringQuote; +use App\Models\RecurringInvoice; use App\Utils\Traits\NumberFormatter; class InvoiceItemSumInclusive @@ -20,11 +25,7 @@ class InvoiceItemSumInclusive use Discounter; use Taxer; - protected $invoice; - - private $items; - - private $line_total; + protected RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; private $currency; @@ -36,13 +37,9 @@ class InvoiceItemSumInclusive private $sub_total; - private $total_discount; - private $tax_collection; - private $tax_amount; - - public function __construct($invoice) + public function __construct(RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice) { $this->tax_collection = collect([]); @@ -60,7 +57,6 @@ class InvoiceItemSumInclusive public function process() { if (! $this->invoice->line_items || ! is_array($this->invoice->line_items) || count($this->invoice->line_items) == 0) { - $this->items = []; return $this; } diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index 09d181fe198a9..a56e52478f313 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -11,9 +11,15 @@ namespace App\Helpers\Invoice; +use App\Models\Quote; +use App\Utils\Number; +use App\Models\Credit; use App\Models\Invoice; -use App\Utils\Traits\NumberFormatter; +use App\Models\PurchaseOrder; +use App\Models\RecurringQuote; +use App\Models\RecurringInvoice; use Illuminate\Support\Collection; +use App\Utils\Traits\NumberFormatter; class InvoiceSum { @@ -22,7 +28,7 @@ class InvoiceSum use Discounter; use NumberFormatter; - protected $invoice; + protected RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; public $tax_map; @@ -49,7 +55,7 @@ class InvoiceSum /** * Constructs the object with Invoice and Settings object. * - * @param \App\Models\RecurringInvoice|\App\Models\Quote|\App\Models\Credit|\App\Models\PurchaseOrder|\App\Models\Invoice $invoice The entity + * @param RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; */ public function __construct($invoice) { @@ -78,7 +84,7 @@ class InvoiceSum return $this; } - private function calculateLineItems() + private function calculateLineItems(): self { $this->invoice_items = new InvoiceItemSum($this->invoice); $this->invoice_items->process(); @@ -90,7 +96,7 @@ class InvoiceSum return $this; } - private function calculateDiscount() + private function calculateDiscount(): self { $this->total_discount = $this->discount($this->invoice_items->getSubTotal()); @@ -99,7 +105,7 @@ class InvoiceSum return $this; } - private function calculateCustomValues() + private function calculateCustomValues(): self { $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1); @@ -114,7 +120,7 @@ class InvoiceSum return $this; } - private function calculateInvoiceTaxes() + private function calculateInvoiceTaxes(): self { if (is_string($this->invoice->tax_name1) && strlen($this->invoice->tax_name1) > 1) { $tax = $this->taxer($this->total, $this->invoice->tax_rate1); @@ -148,23 +154,24 @@ class InvoiceSum * * @return self The balance. */ - private function calculateBalance() + private function calculateBalance(): self { $this->setCalculatedAttributes(); return $this; } - private function calculatePartial() + private function calculatePartial(): self { if (! isset($this->invoice->id) && isset($this->invoice->partial)) { - $this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance)); + $this->invoice->partial = max(0, min(Number::roundValue($this->invoice->partial, 2), $this->invoice->balance)); +// $this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance)); } return $this; } - private function calculateTotals() + private function calculateTotals(): self { $this->total += $this->total_taxes; @@ -230,7 +237,7 @@ class InvoiceSum * Build $this->invoice variables after * calculations have been performed. */ - private function setCalculatedAttributes() + private function setCalculatedAttributes(): self { /* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */ @@ -238,9 +245,9 @@ class InvoiceSum if ($this->invoice->amount != $this->invoice->balance) { $paid_to_date = $this->invoice->amount - $this->invoice->balance; - $this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision) - $paid_to_date; + $this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision) - $paid_to_date; } else { - $this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision); + $this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision); } } /* Set new calculated total */ @@ -268,7 +275,7 @@ class InvoiceSum return $this->gross_sub_total; } - public function setGrossSubTotal($value) + public function setGrossSubTotal($value): self { $this->gross_sub_total = $value; @@ -300,7 +307,7 @@ class InvoiceSum return $this->total_custom_values; } - public function setTaxMap() + public function setTaxMap(): self { if ($this->invoice->is_amount_discount == true) { $this->invoice_items->calcTaxesWithAmountDiscount(); @@ -369,18 +376,18 @@ class InvoiceSum return $this->getTotalTaxes(); } - public function purgeTaxes() + public function purgeTaxes(): self { - $this->tax_rate1 = 0; - $this->tax_name1 = ''; + // $this->tax_rate1 = 0; + // $this->tax_name1 = ''; - $this->tax_rate2 = 0; - $this->tax_name2 = ''; + // $this->tax_rate2 = 0; + // $this->tax_name2 = ''; - $this->tax_rate3 = 0; - $this->tax_name3 = ''; + // $this->tax_rate3 = 0; + // $this->tax_name3 = ''; - $this->discount = 0; + // $this->discount = 0; $line_items = collect($this->invoice->line_items); diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index d0d9c1e9c6e37..e57237bf3d05b 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -11,9 +11,15 @@ namespace App\Helpers\Invoice; +use App\Models\Quote; +use App\Models\Credit; use App\Models\Invoice; -use App\Utils\Traits\NumberFormatter; +use App\Models\PurchaseOrder; +use App\Models\RecurringQuote; +use App\Models\RecurringInvoice; use Illuminate\Support\Collection; +use App\Utils\Traits\NumberFormatter; +use App\Helpers\Invoice\InvoiceItemSumInclusive; class InvoiceSumInclusive { @@ -22,7 +28,7 @@ class InvoiceSumInclusive use Discounter; use NumberFormatter; - protected $invoice; + protected RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; public $tax_map; @@ -42,10 +48,11 @@ class InvoiceSumInclusive private $precision; + public InvoiceItemSumInclusive $invoice_items; /** * Constructs the object with Invoice and Settings object. * - * @param \App\Models\RecurringInvoice|\App\Models\Quote|\App\Models\Credit|\App\Models\PurchaseOrder|\App\Models\Invoice $invoice The entity + * @param RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; */ public function __construct($invoice) { @@ -196,6 +203,9 @@ class InvoiceSumInclusive return $this->invoice; } + /** + * @return Invoice | RecurringInvoice | Quote | Credit | PurchaseOrder + */ public function getInvoice() { //Build invoice values here and return Invoice @@ -205,6 +215,9 @@ class InvoiceSumInclusive return $this->invoice; } + /** + * @return Invoice | RecurringInvoice | Quote | Credit | PurchaseOrder + */ public function getQuote() { //Build invoice values here and return Invoice @@ -214,6 +227,9 @@ class InvoiceSumInclusive return $this->invoice; } + /** + * @return Invoice | RecurringInvoice | Quote | Credit | PurchaseOrder + */ public function getCredit() { //Build invoice values here and return Invoice @@ -223,6 +239,9 @@ class InvoiceSumInclusive return $this->invoice; } + /** + * @return Invoice | RecurringInvoice | Quote | Credit | PurchaseOrder + */ public function getPurchaseOrder() { //Build invoice values here and return Invoice diff --git a/app/Helpers/TranslationHelper.php b/app/Helpers/TranslationHelper.php index 86bb64d011568..6ed961d849cb2 100644 --- a/app/Helpers/TranslationHelper.php +++ b/app/Helpers/TranslationHelper.php @@ -15,7 +15,7 @@ * * //Cache::forever($custom_company_translated_string, 'mogly'); * - * @param string translation string key + * @param string $string * @param array $replace * @param null $locale * @return string diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index e44feb595b2dc..b3fc93c0938d3 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -11,39 +11,40 @@ namespace App\Http\Controllers; -use App\Models\User; -use App\Utils\Ninja; -use App\Models\Client; -use App\Models\Design; -use App\Utils\Statics; use App\Models\Account; -use App\Models\TaxRate; -use App\Models\Webhook; -use App\Models\Scheduler; -use App\Models\TaskStatus; -use App\Models\PaymentTerm; -use Illuminate\Support\Str; -use League\Fractal\Manager; -use App\Models\GroupSetting; -use Illuminate\Http\Response; -use App\Models\CompanyGateway; -use App\Utils\Traits\AppSetup; use App\Models\BankIntegration; use App\Models\BankTransaction; -use App\Models\ExpenseCategory; -use League\Fractal\Resource\Item; use App\Models\BankTransactionRule; -use Illuminate\Support\Facades\Auth; +use App\Models\Client; +use App\Models\CompanyGateway; +use App\Models\Design; +use App\Models\ExpenseCategory; +use App\Models\GroupSetting; +use App\Models\PaymentTerm; +use App\Models\Scheduler; +use App\Models\TaskStatus; +use App\Models\TaxRate; +use App\Models\User; +use App\Models\Webhook; use App\Transformers\ArraySerializer; use App\Transformers\EntityTransformer; -use League\Fractal\Resource\Collection; -use Illuminate\Database\Eloquent\Builder; -use League\Fractal\Serializer\JsonApiSerializer; -use League\Fractal\Pagination\IlluminatePaginatorAdapter; +use App\Utils\Ninja; +use App\Utils\Statics; +use App\Utils\Traits\AppSetup; use Illuminate\Contracts\Container\BindingResolutionException; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Http\Response; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Str; +use League\Fractal\Manager; +use League\Fractal\Pagination\IlluminatePaginatorAdapter; +use League\Fractal\Resource\Collection; +use League\Fractal\Resource\Item; +use League\Fractal\Serializer\JsonApiSerializer; /** * Class BaseController. + * @method static Illuminate\Database\Eloquent\Builder exclude($columns) */ class BaseController extends Controller { @@ -236,26 +237,26 @@ class BaseController extends Controller * @param string $includes The includes for the object * @return string The filtered array of includes */ - private function filterIncludes(string $includes): string - { - $permissions_array = [ - 'payments' => 'view_payment', - 'client' => 'view_client', - 'clients' => 'view_client', - 'vendor' => 'view_vendor', - 'vendors' => 'view_vendors', - 'expense' => 'view_expense', - 'expenses' => 'view_expense', - ]; + // private function filterIncludes(string $includes): string + // { + // $permissions_array = [ + // 'payments' => 'view_payment', + // 'client' => 'view_client', + // 'clients' => 'view_client', + // 'vendor' => 'view_vendor', + // 'vendors' => 'view_vendors', + // 'expense' => 'view_expense', + // 'expenses' => 'view_expense', + // ]; - $collection = collect(explode(",", $includes)); + // $collection = collect(explode(",", $includes)); - $filtered_includes = $collection->filter(function ($include) use ($permissions_array) { - return auth()->user()->hasPermission($permissions_array[$include]); - }); + // $filtered_includes = $collection->filter(function ($include) use ($permissions_array) { + // return auth()->user()->hasPermission($permissions_array[$include]); + // }); - return $filtered_includes->implode(","); - } + // return $filtered_includes->implode(","); + // } /** * 404 for the client portal. @@ -294,10 +295,11 @@ class BaseController extends Controller * Refresh API response with latest cahnges * * @param Builder $query - * @return Builder + * @return Response */ protected function refreshResponse($query) { + /** @var \App\Models\User $user */ $user = auth()->user(); $this->manager->parseIncludes($this->first_load); @@ -536,14 +538,18 @@ class BaseController extends Controller $paginator = $query->paginate($limit); - $query = $paginator->getCollection(); + /** @phpstan-ignore-next-line */ + $query = $paginator->getCollection(); /** @phpstan-ignore-line */ + $resource = new Collection($query, $transformer, $this->entity_type); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); - } else { - $resource = new Collection($query, $transformer, $this->entity_type); } + + // else { + // $resource = new Collection($query, $transformer, $this->entity_type); + // } return $this->response($this->manager->createData($resource)->toArray()); } @@ -565,11 +571,12 @@ class BaseController extends Controller /** * Mini Load Query * - * @param Builder $query - * @return void + * @param Builder $query + * */ protected function miniLoadResponse($query) { + /** @var \App\Models\User $user */ $user = auth()->user(); $this->serializer = request()->input('serializer') ?: EntityTransformer::API_SERIALIZER_ARRAY; @@ -636,12 +643,15 @@ class BaseController extends Controller $limit = $this->resolveQueryLimit(); $paginator = $query->paginate($limit); + + /** @phpstan-ignore-next-line */ $query = $paginator->getCollection(); $resource = new Collection($query, $transformer, $this->entity_type); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); - } else { - $resource = new Collection($query, $transformer, $this->entity_type); } + // else { + // $resource = new Collection($query, $transformer, $this->entity_type); + // } return $this->response($this->manager->createData($resource)->toArray()); } @@ -654,24 +664,25 @@ class BaseController extends Controller * @deprecated * @return bool */ - private function complexPermissionsUser(): bool - { - //if the user is attached to more than one company AND they are not an admin across all companies - if (auth()->user()->company_users()->count() > 1 && (auth()->user()->company_users()->where('is_admin', 1)->count() != auth()->user()->company_users()->count())) { - return true; - } + // private function complexPermissionsUser(): bool + // { + // //if the user is attached to more than one company AND they are not an admin across all companies + // if (auth()->user()->company_users()->count() > 1 && (auth()->user()->company_users()->where('is_admin', 1)->count() != auth()->user()->company_users()->count())) { + // return true; + // } - return false; - } + // return false; + // } /** * Passes back the miniloaded data response * * @param Builder $query - * + * */ protected function timeConstrainedResponse($query) { + /** @var \App\Models\User $user */ $user = auth()->user(); if ($user->getCompany()->is_large) { @@ -899,22 +910,27 @@ class BaseController extends Controller $limit = $this->resolveQueryLimit(); $paginator = $query->paginate($limit); + + /** @phpstan-ignore-next-line */ $query = $paginator->getCollection(); + $resource = new Collection($query, $transformer, $this->entity_type); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); - } else { - $resource = new Collection($query, $transformer, $this->entity_type); - } + } + + // else { + // $resource = new Collection($query, $transformer, $this->entity_type); + // } return $this->response($this->manager->createData($resource)->toArray()); } /** * List response - * - * @param Builder $query + * + * @param Builder $query */ - protected function listResponse($query) + protected function listResponse(Builder $query) { $this->buildManager(); @@ -963,9 +979,10 @@ class BaseController extends Controller $query = $paginator->getCollection(); $resource = new Collection($query, $transformer, $this->entity_type); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); - } else { - $resource = new Collection($query, $transformer, $this->entity_type); } + // else { + // $resource = new Collection($query, $transformer, $this->entity_type); + // } return $this->response($this->manager->createData($resource)->toArray()); } @@ -974,7 +991,7 @@ class BaseController extends Controller * Sorts the response by keys * * @param mixed $response - * @return void + * @return Response */ protected function response($response) { @@ -994,7 +1011,11 @@ class BaseController extends Controller } if (request()->include_static) { - $response['static'] = Statics::company(auth()->user()->getCompany()->getLocale()); + + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $response['static'] = Statics::company($user->getCompany()->getLocale()); } } @@ -1011,6 +1032,7 @@ class BaseController extends Controller * Item Response * * @param mixed $item + * @return Response */ protected function itemResponse($item) { @@ -1024,8 +1046,11 @@ class BaseController extends Controller $resource = new Item($item, $transformer, $this->entity_type); - if (auth()->user() && request()->include_static) { - $data['static'] = Statics::company(auth()->user()->getCompany()->getLocale()); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + if ($user && request()->include_static) { + $data['static'] = Statics::company($user->getCompany()->getLocale()); } return $this->response($this->manager->createData($resource)->toArray()); @@ -1057,7 +1082,11 @@ class BaseController extends Controller * Thresholds for displaying large account on first load */ if (request()->has('first_load') && request()->input('first_load') == 'true') { - if (auth()->user()->getCompany()->is_large && request()->missing('updated_at')) { + + /** @var \App\Models\User $user */ + $user = auth()->user(); + + if ($user->getCompany()->is_large && request()->missing('updated_at')) { $data = $this->mini_load; } else { $data = $this->first_load; @@ -1085,7 +1114,11 @@ class BaseController extends Controller */ public function flutterRoute() { + if ((bool) $this->checkAppSetup() !== false && $account = Account::first()) { + + /** @var \App\Models\Account $account */ + //always redirect invoicing.co to invoicing.co if (Ninja::isHosted() && !in_array(request()->getSchemeAndHttpHost(), ['https://staging.invoicing.co', 'https://invoicing.co', 'https://demo.invoicing.co', 'https://invoiceninja.net'])) { return redirect()->secure('https://invoicing.co'); @@ -1151,9 +1184,9 @@ class BaseController extends Controller /** * Sets the Flutter build to serve * - * @return void + * @return string */ - private function setBuild() + private function setBuild(): string { $build = ''; diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 830a8fc3156ff..00567fcec83f7 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -62,35 +62,9 @@ class PreviewController extends BaseController /** * Returns a template filled with entity variables. * - * @return \Illuminate\Http\Response - * - * @OA\Post( - * path="/api/v1/preview", - * operationId="getPreview", - * tags={"preview"}, - * summary="Returns a pdf preview", - * description="Returns a pdf preview.", - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Response( - * response=200, - * description="The pdf response", - * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), - * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), - * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), - * ), - * @OA\Response( - * response=422, - * description="Validation error", - * @OA\JsonContent(ref="#/components/schemas/ValidationError"), - - * ), - * @OA\Response( - * response="default", - * description="Unexpected Error", - * @OA\JsonContent(ref="#/components/schemas/Error"), - * ), - * ) + * @return mixed */ + public function show() { if (request()->has('entity') && @@ -154,10 +128,17 @@ class PreviewController extends BaseController return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true)); } + + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $company = $user->company(); + if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') { + $pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true)); - $numbered_pdf = $this->pageNumbering($pdf, auth()->user()->company()); + $numbered_pdf = $this->pageNumbering($pdf, $company); if ($numbered_pdf) { $pdf = $numbered_pdf; @@ -166,9 +147,8 @@ class PreviewController extends BaseController return $pdf; } - //else + $file_path = (new PreviewPdf($maker->getCompiledHTML(true), $company))->handle(); - $file_path = (new PreviewPdf($maker->getCompiledHTML(true), auth()->user()->company()))->handle(); return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); } @@ -177,8 +157,13 @@ class PreviewController extends BaseController public function design(DesignPreviewRequest $request) { - - $pdf = (new PdfMock($request->all(), auth()->user()->company()))->build()->getPdf(); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + /** @var \App\Models\Company $company */ + $company = $user->company(); + + $pdf = (new PdfMock($request->all(), $company))->build()->getPdf(); $response = Response::make($pdf, 200); $response->header('Content-Type', 'application/pdf'); @@ -192,7 +177,10 @@ class PreviewController extends BaseController return response()->json(['message' => 'This server cannot handle this request.'], 400); } - $company = auth()->user()->company(); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $company = $user->company(); MultiDB::setDb($company->db); @@ -218,6 +206,8 @@ class PreviewController extends BaseController DB::connection(config('database.default'))->beginTransaction(); if ($request->has('entity_id')) { + + /** @var \App\Models\BaseModel $class */ $entity_obj = $class::on(config('database.default')) ->with('client.company') ->where('id', $this->decodePrimaryKey($request->input('entity_id'))) @@ -304,13 +294,16 @@ class PreviewController extends BaseController return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true)); } + /** @var \App\Models\User $user */ + $user = auth()->user(); + + /** @var \App\Models\Company $company */ + $company = $user->company(); + if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') { $pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true)); - $numbered_pdf = $this->pageNumbering($pdf, auth()->user()->company()); - - - $numbered_pdf = $this->pageNumbering($pdf, auth()->user()->company()); + $numbered_pdf = $this->pageNumbering($pdf, $company); if ($numbered_pdf) { $pdf = $numbered_pdf; @@ -335,11 +328,18 @@ class PreviewController extends BaseController private function blankEntity() { + + /** @var \App\Models\User $user */ + $user = auth()->user(); + + /** @var \App\Models\Company $company */ + $company = $user->company(); + App::forgetInstance('translator'); $t = app('translator'); - $t->replace(Ninja::transformTranslations(auth()->user()->company()->settings)); + $t->replace(Ninja::transformTranslations($company->settings)); - $invitation = InvoiceInvitation::where('company_id', auth()->user()->company()->id)->orderBy('id', 'desc')->first(); + $invitation = InvoiceInvitation::where('company_id', $company->id)->orderBy('id', 'desc')->first(); /* If we don't have a valid invitation in the system - create a mock using transactions */ if (! $invitation) { @@ -381,10 +381,16 @@ class PreviewController extends BaseController return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true)); } + /** @var \App\Models\User $user */ + $user = auth()->user(); + + /** @var \App\Models\Company $company */ + $company = $user->company(); + if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') { $pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true)); - $numbered_pdf = $this->pageNumbering($pdf, auth()->user()->company()); + $numbered_pdf = $this->pageNumbering($pdf, $company); if ($numbered_pdf) { $pdf = $numbered_pdf; @@ -393,7 +399,7 @@ class PreviewController extends BaseController return $pdf; } - $file_path = (new PreviewPdf($maker->getCompiledHTML(true), auth()->user()->company()))->handle(); + $file_path = (new PreviewPdf($maker->getCompiledHTML(true), $company))->handle(); $response = Response::make($file_path, 200); $response->header('Content-Type', 'application/pdf'); @@ -403,40 +409,51 @@ class PreviewController extends BaseController private function mockEntity() { - DB::connection(auth()->user()->company()->db)->beginTransaction(); + /** @var \App\Models\User $user */ + $user = auth()->user(); + /** @var \App\Models\Company $company */ + $company = $user->company(); + + + DB::connection($company->db)->beginTransaction(); + + /** @var \App\Models\Client $client */ $client = Client::factory()->create([ 'user_id' => auth()->user()->id, - 'company_id' => auth()->user()->company()->id, + 'company_id' => $company->id, ]); + /** @var \App\Models\ClientContact $contact */ $contact = ClientContact::factory()->create([ 'user_id' => auth()->user()->id, - 'company_id' => auth()->user()->company()->id, + 'company_id' => $company->id, 'client_id' => $client->id, 'is_primary' => 1, 'send_email' => true, ]); + /** @var \App\Models\Invoice $invoice */ + $invoice = Invoice::factory()->create([ 'user_id' => auth()->user()->id, - 'company_id' => auth()->user()->company()->id, + 'company_id' => $company->id, 'client_id' => $client->id, - 'terms' => auth()->user()->company()->settings->invoice_terms, - 'footer' => auth()->user()->company()->settings->invoice_footer, + 'terms' => $company->settings->invoice_terms, + 'footer' => $company->settings->invoice_footer, 'public_notes' => 'Sample Public Notes', ]); $invitation = InvoiceInvitation::factory()->create([ 'user_id' => auth()->user()->id, - 'company_id' => auth()->user()->company()->id, + 'company_id' => $company->id, 'invoice_id' => $invoice->id, 'client_contact_id' => $contact->id, ]); $invoice->setRelation('invitations', $invitation); $invoice->setRelation('client', $client); - $invoice->setRelation('company', auth()->user()->company()); + $invoice->setRelation('company', $company); $invoice->load('client.company'); $design_object = json_decode(json_encode(request()->input('design'))); @@ -466,7 +483,7 @@ class PreviewController extends BaseController ->design($design) ->build(); - DB::connection(auth()->user()->company()->db)->rollBack(); + DB::connection($company->db)->rollBack(); if (request()->query('html') == 'true') { return $maker->getCompiledHTML(); @@ -479,7 +496,7 @@ class PreviewController extends BaseController if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') { $pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true)); - $numbered_pdf = $this->pageNumbering($pdf, auth()->user()->company()); + $numbered_pdf = $this->pageNumbering($pdf, $company); if ($numbered_pdf) { $pdf = $numbered_pdf; @@ -488,8 +505,7 @@ class PreviewController extends BaseController return $pdf; } - - $file_path = (new PreviewPdf($maker->getCompiledHTML(true), auth()->user()->company()))->handle(); + $file_path = (new PreviewPdf($maker->getCompiledHTML(true), $company))->handle(); $response = Response::make($file_path, 200); $response->header('Content-Type', 'application/pdf'); diff --git a/app/Http/Controllers/SelfUpdateController.php b/app/Http/Controllers/SelfUpdateController.php index c7cdb99881e2f..fcd642c284ae9 100644 --- a/app/Http/Controllers/SelfUpdateController.php +++ b/app/Http/Controllers/SelfUpdateController.php @@ -99,9 +99,6 @@ class SelfUpdateController extends BaseController nlog('Extracting zip'); - //clean up old snappdf installations - //$this->cleanOldSnapChromeBinaries(); - $zipFile = new \PhpZip\ZipFile(); $zipFile->openFile($file); @@ -144,29 +141,6 @@ class SelfUpdateController extends BaseController return response()->json(['message' => 'Update completed'], 200); } - private function cleanOldSnapChromeBinaries() - { - $current_revision = base_path('vendor/beganovich/snappdf/versions/revision.txt'); - $current_revision_text = file_get_contents($current_revision); - - $iterator = new \DirectoryIterator(base_path('vendor/beganovich/snappdf/versions')); - - foreach ($iterator as $file) { - if ($file->isDir() && ! $file->isDot() && ($current_revision_text != $file->getFileName())) { - $directoryIterator = new \RecursiveDirectoryIterator(base_path('vendor/beganovich/snappdf/versions/'.$file->getFileName()), \RecursiveDirectoryIterator::SKIP_DOTS); - - foreach (new \RecursiveIteratorIterator($directoryIterator) as $filex) { - unlink($filex->getPathName()); - } - - $this->deleteDirectory(base_path('vendor/beganovich/snappdf/versions/'.$file->getFileName())); - } - } - - $iterator = null; - - } - private function deleteDirectory($dir) { if (! file_exists($dir)) { diff --git a/app/Http/ValidationRules/Invoice/LockedInvoiceRule.php b/app/Http/ValidationRules/Invoice/LockedInvoiceRule.php index c8bd816aa3e29..9d06a835d05fa 100644 --- a/app/Http/ValidationRules/Invoice/LockedInvoiceRule.php +++ b/app/Http/ValidationRules/Invoice/LockedInvoiceRule.php @@ -54,7 +54,6 @@ class LockedInvoiceRule implements Rule switch ($lock_invoices) { case 'off': return true; - break; case 'when_sent': if ($this->invoice->status_id == Invoice::STATUS_SENT) { return false; @@ -62,17 +61,14 @@ class LockedInvoiceRule implements Rule return true; - break; case 'when_paid': if ($this->invoice->status_id == Invoice::STATUS_PAID) { return false; } return true; - break; default: return true; - break; } } } diff --git a/app/Jobs/Cron/AutoBill.php b/app/Jobs/Cron/AutoBill.php index 8fde5b16374c3..824f9463f29ae 100644 --- a/app/Jobs/Cron/AutoBill.php +++ b/app/Jobs/Cron/AutoBill.php @@ -48,16 +48,19 @@ class AutoBill implements ShouldQueue MultiDB::setDb($this->db); } + $invoice = false; + try { nlog("autobill {$this->invoice_id}"); $invoice = Invoice::withTrashed()->find($this->invoice_id); $invoice->service()->autoBill(); + } catch (\Exception $e) { nlog("Failed to capture payment for {$this->invoice_id} ->".$e->getMessage()); - if($this->send_email_on_failure) + if($this->send_email_on_failure && $invoice) { $invoice->invitations->each(function ($invitation) use ($invoice) { diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index 561cb0ed83b6f..82cbef1929374 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -61,7 +61,7 @@ class EmailEntity implements ShouldQueue * EmailEntity constructor. * * - * @param Invitation $invitation + * @param mixed $invitation * @param Company $company * @param ?string $reminder_template * @param array $template_data @@ -146,21 +146,26 @@ class EmailEntity implements ShouldQueue } elseif ($this->invitation instanceof RecurringInvoiceInvitation) { return 'recurring_invoice'; } + + return ''; } - /* Switch statement to handle failure notifications */ - private function entityEmailFailed($message) - { - switch ($this->entity_string) { - case 'invoice': - event(new InvoiceWasEmailedAndFailed($this->invitation, $this->company, $message, $this->reminder_template, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - break; + /** + * @deprecated + * @unused + */ + // private function entityEmailFailed($message) + // { + // switch ($this->entity_string) { + // case 'invoice': + // event(new InvoiceWasEmailedAndFailed($this->invitation, $this->company, $message, $this->reminder_template, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + // break; - default: - // code... - break; - } - } + // default: + // // code... + // break; + // } + // } /* Builds the email builder object */ private function resolveEmailBuilder() diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index eaab72bf42888..45a6b4a857675 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -52,7 +52,7 @@ class NinjaMailerJob implements ShouldQueue public $override; /* @var Company $company*/ - public $company; + public ?Company $company; private $mailer; @@ -580,10 +580,10 @@ class NinjaMailerJob implements ShouldQueue /** * Attempts to refresh the Microsoft refreshToken * - * @param App\Models\User - * @return string | boool + * @param \App\Models\User $user + * @return mixed */ - private function refreshOfficeToken($user) + private function refreshOfficeToken(User $user) { $expiry = $user->oauth_user_token_expiry ?: now()->subDay(); diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index df52f0084b158..08053467d8e7e 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -12,6 +12,7 @@ namespace App\Jobs\Util; use App\DataMapper\InvoiceItem; +use App\Factory\InvoiceFactory; use App\Jobs\Entity\EmailEntity; use App\Jobs\Ninja\TransactionLog; use App\Libraries\MultiDB; @@ -109,8 +110,13 @@ class ReminderJob implements ShouldQueue } } - private function sendReminderForInvoice($invoice) + private function sendReminderForInvoice(Invoice $invoice) { + App::forgetInstance('translator'); + $t = app('translator'); + $t->replace(Ninja::transformTranslations($invoice->client->getMergedSettings())); + App::setLocale($invoice->client->locale()); + if ($invoice->isPayable()) { //Attempts to prevent duplicates from sending if ($invoice->reminder_last_sent && Carbon::parse($invoice->reminder_last_sent)->startOfDay()->eq(now()->startOfDay())) { @@ -121,7 +127,14 @@ class ReminderJob implements ShouldQueue $reminder_template = $invoice->calculateTemplate('invoice'); nlog("reminder template = {$reminder_template}"); $invoice->service()->touchReminder($reminder_template)->save(); - $invoice = $this->calcLateFee($invoice, $reminder_template); + $fees = $this->calcLateFee($invoice, $reminder_template); + + if(in_array($invoice->client->getSetting('lock_invoices'), ['when_sent','when_paid'])) { + return $this->addFeeToNewInvoice($invoice, $reminder_template, $fees); + } + else + $invoice = $this->setLateFee($invoice, $fees[0], $fees[1]); + //20-04-2022 fixes for endless reminders - generic template naming was wrong $enabled_reminder = 'enable_'.$reminder_template; @@ -148,14 +161,84 @@ class ReminderJob implements ShouldQueue } } + private function addFeeToNewInvoice(Invoice $over_due_invoice, string $reminder_template, array $fees): void + { + + $amount = $fees[0]; + $percent = $fees[1]; + + $temp_invoice_balance = $over_due_invoice->balance; + + if ($amount <= 0 && $percent <= 0) { + return; + } + + $fee = $amount; + + if ($over_due_invoice->partial > 0) { + $fee += round($over_due_invoice->partial * $percent / 100, 2); + } else { + $fee += round($over_due_invoice->balance * $percent / 100, 2); + } + + /** @var \App\Models\Invoice $invoice */ + $invoice = InvoiceFactory::create($over_due_invoice->company_id, $over_due_invoice->user_id); + $invoice->client_id = $over_due_invoice->client_id; + $invoice->date = now()->format('Y-m-d'); + $invoice->due_date = now()->format('Y-m-d'); + + $invoice_item = new InvoiceItem(); + $invoice_item->type_id = '5'; + $invoice_item->product_key = trans('texts.fee'); + $invoice_item->notes = ctrans('texts.late_fee_added_locked_invoice', ['invoice' => $over_due_invoice->number, 'date' => $this->translateDate(now()->startOfDay(), $over_due_invoice->client->date_format(), $over_due_invoice->client->locale())]); + $invoice_item->quantity = 1; + $invoice_item->cost = $fee; + + $invoice_items = []; + $invoice_items[] = $invoice_item; + + $invoice->line_items = $invoice_items; + + /**Refresh Invoice values*/ + $invoice = $invoice->calc()->getInvoice(); + $invoice->service() + ->createInvitations() + ->applyNumber() + ->markSent() + ->save(); + + $invoice->service()->touchPdf(true); + + $enabled_reminder = 'enable_'.$reminder_template; + if ($reminder_template == 'endless_reminder') { + $enabled_reminder = 'enable_reminder_endless'; + } + + if (in_array($reminder_template, ['reminder1', 'reminder2', 'reminder3', 'reminder_endless', 'endless_reminder']) && + $invoice->client->getSetting($enabled_reminder) && + $invoice->client->getSetting('send_reminders') && + (Ninja::isSelfHost() || $invoice->company->account->isPaidHostedClient())) { + $invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) { + if ($invitation->contact && !$invitation->contact->trashed() && $invitation->contact->email) { + EmailEntity::dispatch($invitation, $invitation->company, $reminder_template); + nlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}"); + $invoice->entityEmailEvent($invitation, $reminder_template); + } + }); + } + + $invoice->service()->setReminder()->save(); + + } + /** * Calculates the late if - if any - and rebuilds the invoice * * @param Invoice $invoice * @param string $template - * @return Invoice + * @return array */ - private function calcLateFee($invoice, $template): Invoice + private function calcLateFee($invoice, $template): array { $late_fee_amount = 0; $late_fee_percent = 0; @@ -183,7 +266,8 @@ class ReminderJob implements ShouldQueue break; } - return $this->setLateFee($invoice, $late_fee_amount, $late_fee_percent); + return [$late_fee_amount, $late_fee_percent]; + // return $this->setLateFee($invoice, $late_fee_amount, $late_fee_percent); } /** @@ -197,10 +281,6 @@ class ReminderJob implements ShouldQueue */ private function setLateFee($invoice, $amount, $percent): Invoice { - App::forgetInstance('translator'); - $t = app('translator'); - $t->replace(Ninja::transformTranslations($invoice->client->getMergedSettings())); - App::setLocale($invoice->client->locale()); $temp_invoice_balance = $invoice->balance; @@ -236,16 +316,6 @@ class ReminderJob implements ShouldQueue $invoice->client->service()->updateBalance($invoice->balance - $temp_invoice_balance); $invoice->ledger()->updateInvoiceBalance($invoice->balance - $temp_invoice_balance, "Late Fee Adjustment for invoice {$invoice->number}"); - // $transaction = [ - // 'invoice' => $invoice->transaction_event(), - // 'payment' => [], - // 'client' => $invoice->client->transaction_event(), - // 'credit' => [], - // 'metadata' => ['setLateFee'], - // ]; - - // TransactionLog::dispatch(TransactionEvent::CLIENT_STATUS, $transaction, $invoice->company->db); - $invoice->service()->touchPdf(true); return $invoice; diff --git a/app/Listeners/Invoice/InvoiceEmailedNotification.php b/app/Listeners/Invoice/InvoiceEmailedNotification.php index f2b4c77fc80a0..4eb588879f4e0 100644 --- a/app/Listeners/Invoice/InvoiceEmailedNotification.php +++ b/app/Listeners/Invoice/InvoiceEmailedNotification.php @@ -16,7 +16,6 @@ use App\Jobs\Mail\NinjaMailerJob; use App\Jobs\Mail\NinjaMailerObject; use App\Libraries\MultiDB; use App\Mail\Admin\EntitySentObject; -use App\Notifications\Admin\EntitySentNotification; use App\Utils\Traits\Notifications\UserNotifies; use Illuminate\Contracts\Queue\ShouldQueue; diff --git a/app/Models/Account.php b/app/Models/Account.php index d6ce88c69d684..97d9941e2d94b 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -130,50 +130,12 @@ use Laracasts\Presenter\PresentableTrait; * @method static \Illuminate\Database\Eloquent\Builder|Account whereUtmMedium($value) * @method static \Illuminate\Database\Eloquent\Builder|Account whereUtmSource($value) * @method static \Illuminate\Database\Eloquent\Builder|Account whereUtmTerm($value) + * @method static \Illuminate\Database\Eloquent\Builder|Account first() * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations * @property-read \Illuminate\Database\Eloquent\Collection $companies * @property-read \Illuminate\Database\Eloquent\Collection $company_users * @property-read \Illuminate\Database\Eloquent\Collection $users - * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $users - * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $users - * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $users - * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $users - * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $users - * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $users - * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $users - * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $users - * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $users - * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $users + * @mixin \Eloquent */ class Account extends BaseModel @@ -184,14 +146,12 @@ class Account extends BaseModel private $free_plan_email_quota = 20; private $paid_plan_email_quota = 500; + /** * @var string */ protected $presenter = AccountPresenter::class; - /** - * @var array - */ protected $fillable = [ 'plan', 'plan_term', @@ -450,6 +410,8 @@ class Account extends BaseModel } $trial_active = false; + $trial_expires = false; + $trial_started = false; //14 day trial $duration = 60*60*24*14; @@ -464,10 +426,11 @@ class Account extends BaseModel } $plan_active = false; + $plan_expires = false; + if ($plan) { if ($this->plan_expires == null) { $plan_active = true; - $plan_expires = false; } else { $plan_expires = Carbon::parse($this->plan_expires); if ($plan_expires->greaterThan(now())) { @@ -480,7 +443,6 @@ class Account extends BaseModel return null; } - // Should we show plan details or trial details? if (($plan && ! $trial_plan) || ! $include_trial) { $use_plan = true; @@ -662,11 +624,11 @@ class Account extends BaseModel $plan_expires = Carbon::parse($this->plan_expires); - if (!$this->payment_id && $plan_expires->gt(now())) { + if ($plan_expires->gt(now())) { $diff = $plan_expires->diffInDays(); - if ($diff > 14); - return 0; + if ($diff > 14) + return 0; return $diff; } diff --git a/app/Models/BankAccount.php b/app/Models/BankAccount.php index 9550b136d51a6..5b4abddc9a963 100644 --- a/app/Models/BankAccount.php +++ b/app/Models/BankAccount.php @@ -43,6 +43,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property-read \Illuminate\Database\Eloquent\Collection $bank_subaccounts * @property-read \Illuminate\Database\Eloquent\Collection $bank_subaccounts * @property-read \Illuminate\Database\Eloquent\Collection $bank_subaccounts + * @property-read \Illuminate\Database\Eloquent\Collection $bank_subaccounts * @mixin \Eloquent */ class BankAccount extends BaseModel diff --git a/app/Models/BankIntegration.php b/app/Models/BankIntegration.php index ca61f7951c231..5205e2467eb22 100644 --- a/app/Models/BankIntegration.php +++ b/app/Models/BankIntegration.php @@ -86,6 +86,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property-read \Illuminate\Database\Eloquent\Collection $transactions * @property-read \Illuminate\Database\Eloquent\Collection $transactions * @property-read \Illuminate\Database\Eloquent\Collection $transactions + * @property-read \Illuminate\Database\Eloquent\Collection $transactions * @mixin \Eloquent */ class BankIntegration extends BaseModel diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 4f618cfb431ff..52901ea8a2154 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -11,7 +11,6 @@ namespace App\Models; -use App\DataMapper\ClientSettings; use App\Jobs\Util\WebhookHandler; use App\Models\Traits\Excludable; use App\Utils\Traits\MakesHash; @@ -28,12 +27,24 @@ use Illuminate\Support\Str; * @method scope() static * @package App\Models * @property-read mixed $hashed_id - * @method static \Illuminate\Database\Eloquent\Builder|BaseModel company() + * @property string $number + * @property int $company_id + * @property \App\Models\Company $company + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|Illuminate\Database\Eloquent\Relations\BelongsTo|\Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo|\App\Models\Company company() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel newQuery() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel query() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude(array $excludeable) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel withTrashed() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel scopeExclude() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel find() + * @method \App\Models\Company company() + * @method int companyId() + * @method Builder|static exclude($columns) + * @method static \Illuminate\Database\Eloquent\Builder exclude(array $columns) * @mixin \Eloquent + * @mixin \Illuminate\Database\Eloquent\Builder */ class BaseModel extends Model { @@ -90,7 +101,10 @@ class BaseModel extends Model */ public function scopeCompany($query) { - $query->where('company_id', auth()->user()->companyId()); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $query->where('company_id', $user->companyId()); return $query; } @@ -100,7 +114,10 @@ class BaseModel extends Model */ public function scopeScope($query) { - $query->where($this->getTable().'.company_id', '=', auth()->user()->company()->id); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $query->where($this->getTable().'.company_id', '=', $user->company()->id); return $query; } @@ -132,39 +149,39 @@ class BaseModel extends Model // } // } - public function setSettingsByEntity($entity, $settings) - { - switch ($entity) { - case Client::class: + // public function setSettingsByEntity($entity, $settings) + // { + // switch ($entity) { + // case Client::class: - $this->settings = $settings; - $this->save(); - $this->fresh(); - break; - case Company::class: + // $this->settings = $settings; + // $this->save(); + // $this->fresh(); + // break; + // case Company::class: - $this->company->settings = $settings; - $this->company->save(); - break; - //todo check that saving any other entity (Invoice:: RecurringInvoice::) settings is valid using the default: - default: - $this->client->settings = $settings; - $this->client->save(); - break; - } - } + // $this->company->settings = $settings; + // $this->company->save(); + // break; + // //todo check that saving any other entity (Invoice:: RecurringInvoice::) settings is valid using the default: + // default: + // $this->client->settings = $settings; + // $this->client->save(); + // break; + // } + // } /** * Gets the settings. * * Generic getter for client settings * - * @return ClientSettings The settings. + * @return ClientSettings. */ - public function getSettings() - { - return new ClientSettings($this->settings); - } + // public function getSettings() + // { + // return new ClientSettings($this->settings); + // } /** * Retrieve the model for a bound value. @@ -181,7 +198,6 @@ class BaseModel extends Model return $this ->withTrashed() - // ->company() ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); } diff --git a/app/Models/Client.php b/app/Models/Client.php index fb130dbf88258..37b5c76c2aa4f 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -41,7 +41,7 @@ use Laracasts\Presenter\PresentableTrait; * @property string|null $client_hash * @property string|null $logo * @property string|null $phone - * @property string|null routing_id + * @property string|null $routing_id * @property string $balance * @property string $paid_to_date * @property string $credit_balance @@ -365,6 +365,23 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $system_logs * @property-read \Illuminate\Database\Eloquent\Collection $tasks * @method static \Illuminate\Database\Eloquent\Builder|Client whereRoutingId($value) + * @property-read \Illuminate\Database\Eloquent\Collection $activities + * @property-read \Illuminate\Database\Eloquent\Collection $company_ledger + * @property-read \Illuminate\Database\Eloquent\Collection $contacts + * @property-read \Illuminate\Database\Eloquent\Collection $credits + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $expenses + * @property-read \Illuminate\Database\Eloquent\Collection $gateway_tokens + * @property-read \Illuminate\Database\Eloquent\Collection $invoices + * @property-read \Illuminate\Database\Eloquent\Collection $ledger + * @property-read \Illuminate\Database\Eloquent\Collection $payments + * @property-read \Illuminate\Database\Eloquent\Collection $primary_contact + * @property-read \Illuminate\Database\Eloquent\Collection $projects + * @property-read \Illuminate\Database\Eloquent\Collection $quotes + * @property-read \Illuminate\Database\Eloquent\Collection $recurring_expenses + * @property-read \Illuminate\Database\Eloquent\Collection $recurring_invoices + * @property-read \Illuminate\Database\Eloquent\Collection $system_logs + * @property-read \Illuminate\Database\Eloquent\Collection $tasks * @mixin \Eloquent */ class Client extends BaseModel implements HasLocalePreference @@ -626,6 +643,11 @@ class Client extends BaseModel implements HasLocalePreference })->first(); } + public function industry() + { + return $this->belongsTo(Industry::class); + } + public function locale() { if (! $this->language()) { @@ -774,7 +796,7 @@ class Client extends BaseModel implements HasLocalePreference if ($pm['gateway_type_id'] == GatewayType::CREDIT_CARD) { $cg = CompanyGateway::find($pm['company_gateway_id']); - if ($cg && ! property_exists($cg->fees_and_limits, GatewayType::CREDIT_CARD)) { + if ($cg && ! property_exists($cg->fees_and_limits, strval(GatewayType::CREDIT_CARD))) { $fees_and_limits = $cg->fees_and_limits; $fees_and_limits->{GatewayType::CREDIT_CARD} = new FeesAndLimits; $cg->fees_and_limits = $fees_and_limits; diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 3eb998b68176c..5f3254d14cf59 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -178,6 +178,11 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications * @property-read \Illuminate\Database\Eloquent\Collection $quote_invitations * @property-read \Illuminate\Database\Eloquent\Collection $recurring_invoice_invitations + * @property-read \Illuminate\Database\Eloquent\Collection $credit_invitations + * @property-read \Illuminate\Database\Eloquent\Collection $invoice_invitations + * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications + * @property-read \Illuminate\Database\Eloquent\Collection $quote_invitations + * @property-read \Illuminate\Database\Eloquent\Collection $recurring_invoice_invitations * @mixin \Eloquent */ class ClientContact extends Authenticatable implements HasLocalePreference diff --git a/app/Models/Company.php b/app/Models/Company.php index e4bcfca7aa7b7..e01bb4dfc9777 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -62,7 +62,7 @@ use Laracasts\Presenter\PresentableTrait; * @property int|null $created_at * @property int|null $updated_at * @property int $enabled_item_tax_rates - * @property int $is_large + * @property bool $is_large * @property int $enable_shop_api * @property string $default_auto_bill * @property int $mark_expenses_invoiceable @@ -777,6 +777,51 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $vendors * @property-read \Illuminate\Database\Eloquent\Collection $webhooks * @method static \Illuminate\Database\Eloquent\Builder|Company whereEnableEInvoice($value) + * @property-read \Illuminate\Database\Eloquent\Collection $activities + * @property-read \Illuminate\Database\Eloquent\Collection $all_activities + * @property-read \Illuminate\Database\Eloquent\Collection $all_documents + * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations + * @property-read \Illuminate\Database\Eloquent\Collection $bank_transaction_rules + * @property-read \Illuminate\Database\Eloquent\Collection $bank_transactions + * @property-read \Illuminate\Database\Eloquent\Collection $client_contacts + * @property-read \Illuminate\Database\Eloquent\Collection $client_gateway_tokens + * @property-read \Illuminate\Database\Eloquent\Collection $clients + * @property-read \Illuminate\Database\Eloquent\Collection $company_gateways + * @property-read \Illuminate\Database\Eloquent\Collection $company_users + * @property-read \Illuminate\Database\Eloquent\Collection $contacts + * @property-read \Illuminate\Database\Eloquent\Collection $credits + * @property-read \Illuminate\Database\Eloquent\Collection $designs + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $expense_categories + * @property-read \Illuminate\Database\Eloquent\Collection $expenses + * @property-read \Illuminate\Database\Eloquent\Collection $group_settings + * @property-read \Illuminate\Database\Eloquent\Collection $groups + * @property-read \Illuminate\Database\Eloquent\Collection $invoices + * @property-read \Illuminate\Database\Eloquent\Collection $ledger + * @property-read \Illuminate\Database\Eloquent\Collection $payment_terms + * @property-read \Illuminate\Database\Eloquent\Collection $payments + * @property-read \Illuminate\Database\Eloquent\Collection $products + * @property-read \Illuminate\Database\Eloquent\Collection $projects + * @property-read \Illuminate\Database\Eloquent\Collection $purchase_orders + * @property-read \Illuminate\Database\Eloquent\Collection $quotes + * @property-read \Illuminate\Database\Eloquent\Collection $recurring_expenses + * @property-read \Illuminate\Database\Eloquent\Collection $recurring_invoices + * @property-read \Illuminate\Database\Eloquent\Collection $schedulers + * @property-read \Illuminate\Database\Eloquent\Collection $subscriptions + * @property-read \Illuminate\Database\Eloquent\Collection $system_log_relation + * @property-read \Illuminate\Database\Eloquent\Collection $system_logs + * @property-read \Illuminate\Database\Eloquent\Collection $task_schedulers + * @property-read \Illuminate\Database\Eloquent\Collection $task_statuses + * @property-read \Illuminate\Database\Eloquent\Collection $tasks + * @property-read \Illuminate\Database\Eloquent\Collection $tax_rates + * @property-read \Illuminate\Database\Eloquent\Collection $tokens + * @property-read \Illuminate\Database\Eloquent\Collection $tokens_hashed + * @property-read \Illuminate\Database\Eloquent\Collection $user_designs + * @property-read \Illuminate\Database\Eloquent\Collection $user_payment_terms + * @property-read \Illuminate\Database\Eloquent\Collection $users + * @property-read \Illuminate\Database\Eloquent\Collection $vendors + * @property-read \Illuminate\Database\Eloquent\Collection $webhooks + * @method \App\Models\User|null owner() * @mixin \Eloquent */ class Company extends BaseModel @@ -1348,7 +1393,10 @@ class Company extends BaseModel return $this->hasMany(CompanyUser::class)->withTrashed(); } - public function owner() + /** + * @return \App\Models\User|null + */ + public function owner(): ?User { return $this->company_users()->withTrashed()->where('is_owner', true)->first()?->user; } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 059ad639a3817..b104cbccdada0 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -92,6 +92,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Eloquent\Builder|CompanyGateway whereUserId($value) * @method static \Illuminate\Database\Eloquent\Builder|CompanyGateway withTrashed() * @method static \Illuminate\Database\Eloquent\Builder|CompanyGateway withoutTrashed() + * @method static \Illuminate\Database\Eloquent\Builder|CompanyGateway find() + * @property-read \Illuminate\Database\Eloquent\Collection $client_gateway_tokens * @property-read \Illuminate\Database\Eloquent\Collection $client_gateway_tokens * @property-read \Illuminate\Database\Eloquent\Collection $client_gateway_tokens * @property-read \Illuminate\Database\Eloquent\Collection $client_gateway_tokens diff --git a/app/Models/CompanyToken.php b/app/Models/CompanyToken.php index 545758f058a7d..b3564f1e7b3b7 100644 --- a/app/Models/CompanyToken.php +++ b/app/Models/CompanyToken.php @@ -25,15 +25,14 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property int|null $created_at * @property int|null $updated_at * @property int|null $deleted_at - * @property int $is_deleted - * @property int $is_system + * @property bool $is_deleted + * @property bool $is_system * @property-read \App\Models\Account $account * @property-read \App\Models\Company $company * @property-read \App\Models\CompanyUser|null $company_user * @property-read \App\Models\CompanyUser|null $cu * @property-read mixed $hashed_id * @property-read \App\Models\User $user - * @method static \Illuminate\Database\Eloquent\Builder|BaseModel company() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns) * @method static \Illuminate\Database\Eloquent\Builder|CompanyToken filter(\App\Filters\QueryFilters $filters) * @method static \Illuminate\Database\Eloquent\Builder|CompanyToken newModelQuery() @@ -54,6 +53,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Eloquent\Builder|CompanyToken whereUserId($value) * @method static \Illuminate\Database\Eloquent\Builder|CompanyToken withTrashed() * @method static \Illuminate\Database\Eloquent\Builder|CompanyToken withoutTrashed() + * @method static \Illuminate\Database\Eloquent\Builder|CompanyToken with() * @mixin \Eloquent */ class CompanyToken extends BaseModel @@ -100,6 +100,9 @@ class CompanyToken extends BaseModel ->where('user_id', $this->user_id); } + /** + * @return \Awobaz\Compoships\Database\Eloquent\Relations\HasOne + */ public function cu() { return $this->hasOne(CompanyUser::class, 'user_id', 'user_id') diff --git a/app/Models/CompanyUser.php b/app/Models/CompanyUser.php index afab046e15ce7..eef53d332f316 100644 --- a/app/Models/CompanyUser.php +++ b/app/Models/CompanyUser.php @@ -11,8 +11,10 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Eloquent\Relations\Pivot; +use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * App\Models\CompanyUser @@ -25,9 +27,9 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property object|null $notifications * @property object|null $settings * @property string $slack_webhook_url - * @property int $is_owner - * @property int $is_admin - * @property int $is_locked + * @property bool $is_owner + * @property bool $is_admin + * @property bool $is_locked * @property int|null $deleted_at * @property int|null $created_at * @property int|null $updated_at @@ -36,6 +38,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property string|null $react_settings * @property-read \App\Models\Account $account * @property-read \App\Models\Company $company + * @property-read \App\Models\CompanyUser $cu * @property-read \Illuminate\Database\Eloquent\Collection $token * @property-read int|null $token_count * @property-read \Illuminate\Database\Eloquent\Collection $tokens @@ -73,6 +76,10 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property-read \Illuminate\Database\Eloquent\Collection $token * @property-read \Illuminate\Database\Eloquent\Collection $tokens * @property-read \Illuminate\Database\Eloquent\Collection $users + * @property-read \Illuminate\Database\Eloquent\Collection $cu + * @property-read \Illuminate\Database\Eloquent\Collection $token + * @property-read \Illuminate\Database\Eloquent\Collection $tokens + * @property-read \Illuminate\Database\Eloquent\Collection $users * @property-read \Illuminate\Database\Eloquent\Collection $token * @property-read \Illuminate\Database\Eloquent\Collection $tokens * @property-read \Illuminate\Database\Eloquent\Collection $users @@ -107,14 +114,11 @@ class CompanyUser extends Pivot use SoftDeletes; use \Awobaz\Compoships\Compoships; - // protected $guarded = ['id']; - protected $dateFormat = 'Y-m-d H:i:s.u'; /** * The attributes that should be cast to native types. * - * @var array */ protected $casts = [ 'permissions_updated_at' => 'timestamp', @@ -148,11 +152,6 @@ class CompanyUser extends Pivot return self::class; } - // public function tax_rates() - // { - // return $this->hasMany(TaxRate::class, 'company_id', 'company_id'); - // } - public function account() { return $this->belongsTo(Account::class); @@ -168,7 +167,7 @@ class CompanyUser extends Pivot return $this->hasOne(Company::class)->withPivot('permissions', 'settings', 'react_settings', 'is_admin', 'is_owner', 'is_locked', 'slack_webhook_url', 'migrating'); } - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class)->withTrashed(); } diff --git a/app/Models/Credit.php b/app/Models/Credit.php index cf6b322b97509..e4dfe6e5f79bc 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -49,7 +49,7 @@ use Laracasts\Presenter\PresentableTrait; * @property string|null $last_sent_date * @property string|null $due_date * @property int $is_deleted - * @property object|null $line_items + * @property array|null $line_items * @property object|null $backup * @property string|null $footer * @property string|null $public_notes @@ -76,10 +76,10 @@ use Laracasts\Presenter\PresentableTrait; * @property int $custom_surcharge_tax2 * @property int $custom_surcharge_tax3 * @property int $custom_surcharge_tax4 - * @property string $exchange_rate - * @property string $amount - * @property string $balance - * @property string|null $partial + * @property float $exchange_rate + * @property float $amount + * @property float $balance + * @property float|null $partial * @property string|null $partial_due_date * @property string|null $last_viewed * @property int|null $created_at @@ -262,6 +262,13 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @property-read \Illuminate\Database\Eloquent\Collection $invoices * @property-read \Illuminate\Database\Eloquent\Collection $payments + * @property-read \Illuminate\Database\Eloquent\Collection $activities + * @property-read \Illuminate\Database\Eloquent\Collection $company_ledger + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $history + * @property-read \Illuminate\Database\Eloquent\Collection $invitations + * @property-read \Illuminate\Database\Eloquent\Collection $invoices + * @property-read \Illuminate\Database\Eloquent\Collection $payments * @mixin \Eloquent */ class Credit extends BaseModel @@ -443,9 +450,9 @@ class Credit extends BaseModel /** * Access the invoice calculator object. * - * @return stdClass The invoice calculator object getters + * @return InvoiceSumInclusive | InvoiceSum The invoice calculator object getters */ - public function calc() + public function calc(): InvoiceSumInclusive | InvoiceSum { $credit_calc = null; @@ -517,6 +524,8 @@ class Credit extends BaseModel return Storage::disk(config('filesystems.default'))->{$type}($file_path); } + $file_exists = false; + try { $file_exists = Storage::disk(config('filesystems.default'))->exists($file_path); } catch (\Exception $e) { @@ -569,19 +578,14 @@ class Credit extends BaseModel switch ($status) { case self::STATUS_DRAFT: return ctrans('texts.draft'); - break; case self::STATUS_SENT: return ctrans('texts.sent'); - break; case self::STATUS_PARTIAL: return ctrans('texts.partial'); - break; case self::STATUS_APPLIED: return ctrans('texts.applied'); - break; default: - return ''; - break; + return ctrans('texts.sent'); } } } diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 3f3b32f6f0d4a..648e1d5635e9a 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -142,6 +142,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property-read \App\Models\BankTransaction|null $transaction * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $documents * @mixin \Eloquent */ class Expense extends BaseModel diff --git a/app/Models/GatewayType.php b/app/Models/GatewayType.php index 41c42f9c97d06..2ca4159cd3e12 100644 --- a/app/Models/GatewayType.php +++ b/app/Models/GatewayType.php @@ -39,6 +39,7 @@ namespace App\Models; * @property-read \Illuminate\Database\Eloquent\Collection $payment_methods * @property-read \Illuminate\Database\Eloquent\Collection $payment_methods * @property-read \Illuminate\Database\Eloquent\Collection $payment_methods + * @property-read \Illuminate\Database\Eloquent\Collection $payment_methods * @mixin \Eloquent */ class GatewayType extends StaticModel diff --git a/app/Models/GroupSetting.php b/app/Models/GroupSetting.php index f3a1799d40d94..8e2c99d6f27b2 100644 --- a/app/Models/GroupSetting.php +++ b/app/Models/GroupSetting.php @@ -76,6 +76,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $clients * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $clients + * @property-read \Illuminate\Database\Eloquent\Collection $documents * @mixin \Eloquent */ class GroupSetting extends StaticModel diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 7ba08d7e7be51..d0dc1024f58e2 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -51,20 +51,20 @@ use Laracasts\Presenter\PresentableTrait; * @property string|null $last_sent_date * @property string|null $due_date * @property bool $is_deleted - * @property object|null $line_items + * @property object|array $line_items * @property object|null $backup * @property string|null $footer * @property string|null $public_notes * @property string|null $private_notes * @property string|null $terms * @property string|null $tax_name1 - * @property string $tax_rate1 + * @property float $tax_rate1 * @property string|null $tax_name2 - * @property string $tax_rate2 + * @property float $tax_rate2 * @property string|null $tax_name3 - * @property string $tax_rate3 - * @property string $total_taxes - * @property int $uses_inclusive_taxes + * @property float $tax_rate3 + * @property float $total_taxes + * @property bool $uses_inclusive_taxes * @property string|null $custom_value1 * @property string|null $custom_value2 * @property string|null $custom_value3 @@ -74,14 +74,14 @@ use Laracasts\Presenter\PresentableTrait; * @property string|null $custom_surcharge2 * @property string|null $custom_surcharge3 * @property string|null $custom_surcharge4 - * @property int $custom_surcharge_tax1 - * @property int $custom_surcharge_tax2 - * @property int $custom_surcharge_tax3 - * @property int $custom_surcharge_tax4 - * @property string $exchange_rate - * @property string $amount - * @property string $balance - * @property string|null $partial + * @property bool $custom_surcharge_tax1 + * @property bool $custom_surcharge_tax2 + * @property bool $custom_surcharge_tax3 + * @property bool $custom_surcharge_tax4 + * @property float $exchange_rate + * @property float $amount + * @property float $balance + * @property float|null $partial * @property string|null $partial_due_date * @property string|null $last_viewed * @property int|null $created_at @@ -91,11 +91,11 @@ use Laracasts\Presenter\PresentableTrait; * @property string|null $reminder2_sent * @property string|null $reminder3_sent * @property string|null $reminder_last_sent - * @property int $auto_bill_enabled - * @property string $paid_to_date + * @property bool $auto_bill_enabled + * @property float $paid_to_date * @property int|null $subscription_id * @property int $auto_bill_tries - * @property int $is_proforma + * @property bool $is_proforma * @property-read \Illuminate\Database\Eloquent\Collection $activities * @property-read int|null $activities_count * @property-read \App\Models\User|null $assigned_user @@ -304,6 +304,15 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @property-read \Illuminate\Database\Eloquent\Collection $payments * @property-read \Illuminate\Database\Eloquent\Collection $tasks + * @property-read \Illuminate\Database\Eloquent\Collection $activities + * @property-read \Illuminate\Database\Eloquent\Collection $company_ledger + * @property-read \Illuminate\Database\Eloquent\Collection $credits + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $expenses + * @property-read \Illuminate\Database\Eloquent\Collection $history + * @property-read \Illuminate\Database\Eloquent\Collection $invitations + * @property-read \Illuminate\Database\Eloquent\Collection $payments + * @property-read \Illuminate\Database\Eloquent\Collection $tasks * @mixin \Eloquent */ class Invoice extends BaseModel @@ -603,78 +612,61 @@ class Invoice extends BaseModel return ($this->partial && $this->partial > 0) === true; } - public static function badgeForStatus(int $status) + public static function badgeForStatus(int $status): string { switch ($status) { case self::STATUS_DRAFT: return '
'.ctrans('texts.draft').'
'; - break; case self::STATUS_SENT: return '
'.ctrans('texts.sent').'
'; - break; case self::STATUS_PARTIAL: return '
'.ctrans('texts.partial').'
'; - break; case self::STATUS_PAID: return '
'.ctrans('texts.paid').'
'; - break; case self::STATUS_CANCELLED: return '
'.ctrans('texts.cancelled').'
'; - break; case self::STATUS_OVERDUE: return '
'.ctrans('texts.overdue').'
'; - break; case self::STATUS_UNPAID: return '
'.ctrans('texts.unpaid').'
'; - break; case self::STATUS_REVERSED: return '
'.ctrans('texts.reversed').'
'; - break; default: - // code... - break; + return '
'.ctrans('texts.sent').'
'; + } } - public static function stringStatus(int $status) + public static function stringStatus(int $status): string { switch ($status) { case self::STATUS_DRAFT: return ctrans('texts.draft'); - break; case self::STATUS_SENT: return ctrans('texts.sent'); - break; case self::STATUS_PARTIAL: return ctrans('texts.partial'); - break; case self::STATUS_PAID: return ctrans('texts.paid'); - break; case self::STATUS_CANCELLED: return ctrans('texts.cancelled'); - break; case self::STATUS_OVERDUE: return ctrans('texts.overdue'); - break; case self::STATUS_UNPAID: return ctrans('texts.unpaid'); - break; case self::STATUS_REVERSED: return ctrans('texts.reversed'); - break; default: - // code... - break; + return ctrans('texts.sent'); } } /** * Access the invoice calculator object. * - * @return \stdClass The invoice calculator object getters + * @return InvoiceSumInclusive | InvoiceSum The invoice calculator object getters */ - public function calc() + public function calc(): InvoiceSumInclusive | InvoiceSum { $invoice_calc = null; @@ -771,16 +763,12 @@ class Invoice extends BaseModel switch ($locked_status) { case 'off': return false; - break; case 'when_sent': return $this->status_id == self::STATUS_SENT; - break; case 'when_paid': return $this->status_id == self::STATUS_PAID || $this->status_id == self::STATUS_PARTIAL; - break; default: return false; - break; } } @@ -804,7 +792,7 @@ class Invoice extends BaseModel return $this->balance; } - if ($this->status_id = 1) { + if ($this->status_id == 1) { return $this->amount; } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index adab70d5006a5..27cd529483acf 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -39,9 +39,9 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property int|null $gateway_type_id * @property int|null $type_id * @property int $status_id - * @property string $amount - * @property string $refunded - * @property string $applied + * @property float $amount + * @property float $refunded + * @property float $applied * @property string|null $date * @property string|null $transaction_reference * @property string|null $payer_id @@ -51,7 +51,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property int|null $updated_at * @property int|null $deleted_at * @property bool $is_deleted - * @property int $is_manual + * @property bool $is_manual * @property float $exchange_rate * @property int $currency_id * @property int|null $exchange_currency_id @@ -187,6 +187,11 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $invoices * @property-read \Illuminate\Database\Eloquent\Collection $paymentables + * @property-read \Illuminate\Database\Eloquent\Collection $company_ledger + * @property-read \Illuminate\Database\Eloquent\Collection $credits + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $invoices + * @property-read \Illuminate\Database\Eloquent\Collection $paymentables * @mixin \Eloquent */ class Payment extends BaseModel @@ -394,66 +399,52 @@ class Payment extends BaseModel return $this->createClientDate($this->date, $this->client->timezone()->name)->format($date_format->format); } - public static function badgeForStatus(int $status) + public static function badgeForStatus(int $status): string { switch ($status) { case self::STATUS_PENDING: return '
'.ctrans('texts.payment_status_1').'
'; - break; case self::STATUS_CANCELLED: return '
'.ctrans('texts.payment_status_2').'
'; - break; case self::STATUS_FAILED: return '
'.ctrans('texts.payment_status_3').'
'; - break; case self::STATUS_COMPLETED: return '
'.ctrans('texts.payment_status_4').'
'; - break; case self::STATUS_PARTIALLY_REFUNDED: return '
'.ctrans('texts.payment_status_5').'
'; - break; case self::STATUS_REFUNDED: return '
'.ctrans('texts.payment_status_6').'
'; - break; default: - // code... - break; + return ''; } } - public static function stringStatus(int $status) + public static function stringStatus(int $status): string { switch ($status) { case self::STATUS_PENDING: return ctrans('texts.payment_status_1'); - break; case self::STATUS_CANCELLED: return ctrans('texts.payment_status_2'); - break; case self::STATUS_FAILED: return ctrans('texts.payment_status_3'); - break; case self::STATUS_COMPLETED: return ctrans('texts.payment_status_4'); - break; case self::STATUS_PARTIALLY_REFUNDED: return ctrans('texts.payment_status_5'); - break; case self::STATUS_REFUNDED: return ctrans('texts.payment_status_6'); - break; default: return ''; - break; } } - public function ledger() + public function ledger(): LedgerService { return new LedgerService($this); } - public function service() + public function service(): PaymentService { return new PaymentService($this); } @@ -464,7 +455,7 @@ class Payment extends BaseModel } /** - * @return mixed + * @return float */ public function getCompletedAmount() :float { @@ -558,7 +549,7 @@ class Payment extends BaseModel 'payment_refunded' => $payment->refunded ?: 0, 'payment_status' => $payment->status_id ?: 1, 'paymentables' => $payment->paymentables->toArray(), - 'payment_request' => request() ? request()->all() : [], + 'payment_request' => [], ]; } diff --git a/app/Models/Paymentable.php b/app/Models/Paymentable.php index 81aaf23fb413b..c8112f826c0b8 100644 --- a/app/Models/Paymentable.php +++ b/app/Models/Paymentable.php @@ -20,8 +20,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property int $id * @property int $payment_id * @property int $paymentable_id - * @property string $amount - * @property string $refunded + * @property float $amount + * @property float $refunded * @property string $paymentable_type * @property int|null $created_at * @property int|null $updated_at @@ -51,13 +51,6 @@ class Paymentable extends Pivot protected $table = 'paymentables'; - //protected $dateFormat = 'Y-m-d H:i:s.u'; - - /** - * The attributes that should be cast to native types. - * - * @var array - */ protected $casts = [ 'updated_at' => 'timestamp', 'created_at' => 'timestamp', diff --git a/app/Models/Product.php b/app/Models/Product.php index 86f4aa57e0d33..98c7af855c306 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -109,6 +109,7 @@ use League\CommonMark\CommonMarkConverter; * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $documents * @mixin \Eloquent */ class Product extends BaseModel diff --git a/app/Models/Project.php b/app/Models/Project.php index 40c2012df9ea0..7e88c884072ed 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -96,6 +96,8 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $tasks * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $tasks + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $tasks * @mixin \Eloquent */ class Project extends BaseModel diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index 169a6f999cf42..30e0a23c0c075 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.php @@ -39,6 +39,7 @@ use App\Utils\Traits\MakesHash; * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $documents * @mixin \Eloquent */ class Proposal extends BaseModel diff --git a/app/Models/PurchaseOrder.php b/app/Models/PurchaseOrder.php index 4c132337e1293..01ad73b4c3b7a 100644 --- a/app/Models/PurchaseOrder.php +++ b/app/Models/PurchaseOrder.php @@ -76,7 +76,7 @@ use Illuminate\Support\Facades\Storage; * @property int $custom_surcharge_tax4 * @property string $exchange_rate * @property string $balance - * @property string|null $partial + * @property float|null $partial * @property string $amount * @property string $paid_to_date * @property string|null $partial_due_date @@ -246,6 +246,12 @@ use Illuminate\Support\Facades\Storage; * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @property-read \Illuminate\Database\Eloquent\Collection $invoices * @property-read \Illuminate\Database\Eloquent\Collection $payments + * @property-read \Illuminate\Database\Eloquent\Collection $activities + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $history + * @property-read \Illuminate\Database\Eloquent\Collection $invitations + * @property-read \Illuminate\Database\Eloquent\Collection $invoices + * @property-read \Illuminate\Database\Eloquent\Collection $payments * @mixin \Eloquent */ class PurchaseOrder extends BaseModel @@ -329,18 +335,15 @@ class PurchaseOrder extends BaseModel switch ($status) { case self::STATUS_DRAFT: return ctrans('texts.draft'); - break; case self::STATUS_SENT: return ctrans('texts.sent'); - break; case self::STATUS_ACCEPTED: return ctrans('texts.accepted'); - break; case self::STATUS_CANCELLED: return ctrans('texts.cancelled'); - break; - // code... - break; + default: + return ctrans('texts.sent'); + } } @@ -350,19 +353,14 @@ class PurchaseOrder extends BaseModel switch ($status) { case self::STATUS_DRAFT: return '
'.ctrans('texts.draft').'
'; - break; case self::STATUS_SENT: return '
'.ctrans('texts.sent').'
'; - break; case self::STATUS_ACCEPTED: return '
'.ctrans('texts.accepted').'
'; - break; case self::STATUS_CANCELLED: return '
'.ctrans('texts.cancelled').'
'; - break; default: - // code... - break; + return '
'.ctrans('texts.sent').'
'; } } @@ -488,7 +486,12 @@ class PurchaseOrder extends BaseModel return $this->morphMany(Document::class, 'documentable'); } - public function calc() + /** + * Access the invoice calculator object. + * + * @return InvoiceSumInclusive | InvoiceSum The invoice calculator object getters + */ + public function calc(): InvoiceSumInclusive | InvoiceSum { $purchase_order_calc = null; diff --git a/app/Models/Quote.php b/app/Models/Quote.php index b7b6055969c5e..89e4462de56cc 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -75,10 +75,10 @@ use Laracasts\Presenter\PresentableTrait; * @property int $custom_surcharge_tax2 * @property int $custom_surcharge_tax3 * @property int $custom_surcharge_tax4 - * @property string $exchange_rate - * @property string $amount - * @property string $balance - * @property string|null $partial + * @property float $exchange_rate + * @property float $amount + * @property float $balance + * @property float|null $partial * @property string|null $partial_due_date * @property string|null $last_viewed * @property int|null $created_at @@ -225,6 +225,10 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $history * @property-read \Illuminate\Database\Eloquent\Collection $invitations + * @property-read \Illuminate\Database\Eloquent\Collection $activities + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $history + * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @mixin \Eloquent */ class Quote extends BaseModel @@ -389,9 +393,9 @@ class Quote extends BaseModel /** * Access the quote calculator object. * - * @return stdClass The quote calculator object getters + * @return InvoiceSumInclusive | InvoiceSum The quote calculator object getters */ - public function calc() + public function calc(): InvoiceSumInclusive | InvoiceSum { $quote_calc = null; @@ -446,6 +450,8 @@ class Quote extends BaseModel return Storage::disk(config('filesystems.default'))->{$type}($file_path); } + $file_exists = false; + try { $file_exists = Storage::disk(config('filesystems.default'))->exists($file_path); } catch (\Exception $e) { @@ -469,51 +475,40 @@ class Quote extends BaseModel * @param int $status * @return string */ - public static function badgeForStatus(int $status) + public static function badgeForStatus(int $status): string { switch ($status) { case self::STATUS_DRAFT: return '
'.ctrans('texts.draft').'
'; - break; case self::STATUS_SENT: return '
'.ctrans('texts.pending').'
'; - break; case self::STATUS_APPROVED: return '
'.ctrans('texts.approved').'
'; - break; case self::STATUS_EXPIRED: return '
'.ctrans('texts.expired').'
'; - break; case self::STATUS_CONVERTED: return '
'.ctrans('texts.converted').'
'; - break; default: - // code... - break; + return '
'.ctrans('texts.draft').'
'; } } - public static function stringStatus(int $status) + public static function stringStatus(int $status): string { switch ($status) { case self::STATUS_DRAFT: return ctrans('texts.draft'); - break; case self::STATUS_SENT: return ctrans('texts.pending'); - break; case self::STATUS_APPROVED: return ctrans('texts.approved'); - break; case self::STATUS_EXPIRED: return ctrans('texts.expired'); - break; case self::STATUS_CONVERTED: return ctrans('texts.converted'); - break; default: - // code... - break; + return ctrans('texts.draft'); + } } diff --git a/app/Models/RecurringExpense.php b/app/Models/RecurringExpense.php index bce2f6a60414c..642aa099858a0 100644 --- a/app/Models/RecurringExpense.php +++ b/app/Models/RecurringExpense.php @@ -150,6 +150,7 @@ use Illuminate\Support\Carbon; * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $documents * @mixin \Eloquent */ class RecurringExpense extends BaseModel diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index 9eb4e272a6d2f..eab645792ac86 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -35,31 +35,31 @@ use Laracasts\Presenter\PresentableTrait; * @property int $status_id * @property string|null $number * @property float $discount - * @property int $is_amount_discount + * @property bool $is_amount_discount * @property string|null $po_number * @property string|null $date * @property string|null $due_date - * @property int $is_deleted - * @property object|null $line_items + * @property bool $is_deleted + * @property mixed $line_items * @property object|null $backup * @property string|null $footer * @property string|null $public_notes * @property string|null $private_notes * @property string|null $terms * @property string|null $tax_name1 - * @property string $tax_rate1 + * @property float $tax_rate1 * @property string|null $tax_name2 - * @property string $tax_rate2 + * @property float $tax_rate2 * @property string|null $tax_name3 - * @property string $tax_rate3 - * @property string $total_taxes + * @property float $tax_rate3 + * @property float $total_taxes * @property string|null $custom_value1 * @property string|null $custom_value2 * @property string|null $custom_value3 * @property string|null $custom_value4 - * @property string $amount - * @property string $balance - * @property string|null $partial + * @property float $amount + * @property float $balance + * @property float|null $partial * @property string|null $last_viewed * @property int $frequency_id * @property string|null $last_sent_date @@ -69,21 +69,21 @@ use Laracasts\Presenter\PresentableTrait; * @property int|null $updated_at * @property int|null $deleted_at * @property string $auto_bill - * @property int $auto_bill_enabled + * @property bool $auto_bill_enabled * @property int|null $design_id - * @property int $uses_inclusive_taxes + * @property bool $uses_inclusive_taxes * @property string|null $custom_surcharge1 * @property string|null $custom_surcharge2 * @property string|null $custom_surcharge3 * @property string|null $custom_surcharge4 - * @property int $custom_surcharge_tax1 - * @property int $custom_surcharge_tax2 - * @property int $custom_surcharge_tax3 - * @property int $custom_surcharge_tax4 + * @property bool $custom_surcharge_tax1 + * @property bool $custom_surcharge_tax2 + * @property bool $custom_surcharge_tax3 + * @property bool $custom_surcharge_tax4 * @property string|null $due_date_days * @property string|null $partial_due_date * @property string $exchange_rate - * @property string $paid_to_date + * @property float $paid_to_date * @property int|null $subscription_id * @property string|null $next_send_date_client * @property-read \Illuminate\Database\Eloquent\Collection $activities @@ -182,7 +182,7 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $history * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @property-read \Illuminate\Database\Eloquent\Collection $invoices - * @property int $is_proforma + * @property bool $is_proforma * @property-read \Illuminate\Database\Eloquent\Collection $activities * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $history @@ -234,6 +234,11 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $history * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @property-read \Illuminate\Database\Eloquent\Collection $invoices + * @property-read \Illuminate\Database\Eloquent\Collection $activities + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $history + * @property-read \Illuminate\Database\Eloquent\Collection $invitations + * @property-read \Illuminate\Database\Eloquent\Collection $invoices * @mixin \Eloquent */ class RecurringInvoice extends BaseModel @@ -604,22 +609,17 @@ class RecurringInvoice extends BaseModel switch ($status) { case self::STATUS_DRAFT: return '

'.ctrans('texts.draft').'

'; - break; case self::STATUS_PENDING: return '

'.ctrans('texts.pending').'

'; - break; case self::STATUS_ACTIVE: return '

'.ctrans('texts.active').'

'; - break; case self::STATUS_COMPLETED: return '

'.ctrans('texts.status_completed').'

'; - break; case self::STATUS_PAUSED: return '

'.ctrans('texts.paused').'

'; - break; default: - // code... - break; + return '

'.ctrans('texts.pending').'

'; + } } @@ -628,22 +628,17 @@ class RecurringInvoice extends BaseModel switch ($status) { case self::STATUS_DRAFT: return ctrans('texts.draft'); - break; case self::STATUS_PENDING: return ctrans('texts.pending'); - break; case self::STATUS_ACTIVE: return ctrans('texts.active'); - break; case self::STATUS_COMPLETED: return ctrans('texts.status_completed'); - break; case self::STATUS_PAUSED: return ctrans('texts.paused'); - break; default: - // code... - break; + return ctrans('texts.pending'); + } } @@ -652,47 +647,39 @@ class RecurringInvoice extends BaseModel switch ($frequency_id) { case self::FREQUENCY_DAILY: return ctrans('texts.freq_daily'); - break; case self::FREQUENCY_WEEKLY: return ctrans('texts.freq_weekly'); - break; case self::FREQUENCY_TWO_WEEKS: return ctrans('texts.freq_two_weeks'); - break; case self::FREQUENCY_FOUR_WEEKS: return ctrans('texts.freq_four_weeks'); - break; case self::FREQUENCY_MONTHLY: return ctrans('texts.freq_monthly'); - break; case self::FREQUENCY_TWO_MONTHS: return ctrans('texts.freq_two_months'); - break; case self::FREQUENCY_THREE_MONTHS: return ctrans('texts.freq_three_months'); - break; case self::FREQUENCY_FOUR_MONTHS: return ctrans('texts.freq_four_months'); - break; case self::FREQUENCY_SIX_MONTHS: return ctrans('texts.freq_six_months'); - break; case self::FREQUENCY_ANNUALLY: return ctrans('texts.freq_annually'); - break; case self::FREQUENCY_TWO_YEARS: return ctrans('texts.freq_two_years'); - break; case self::FREQUENCY_THREE_YEARS: return ctrans('texts.freq_three_years'); - break; default: return ''; - break; } } - public function calc() + /** + * Access the invoice calculator object. + * + * @return InvoiceSumInclusive | InvoiceSum The invoice calculator object getters + */ + public function calc(): InvoiceSumInclusive | InvoiceSum { $invoice_calc = null; @@ -764,15 +751,12 @@ class RecurringInvoice extends BaseModel case '': case '0': return $this->calculateDateFromTerms($date); - break; case 'on_receipt': return Carbon::parse($date)->copy(); - break; default: return $this->setDayOfMonth($date, $this->due_date_days); - break; } } diff --git a/app/Models/RecurringQuote.php b/app/Models/RecurringQuote.php index fb54c34457a3b..76d90a1da7789 100644 --- a/app/Models/RecurringQuote.php +++ b/app/Models/RecurringQuote.php @@ -80,7 +80,7 @@ use Laracasts\Presenter\PresentableTrait; * @property int $custom_surcharge_tax4 * @property string|null $due_date_days * @property string $exchange_rate - * @property string|null $partial + * @property float|null $partial * @property string|null $partial_due_date * @property int|null $subscription_id * @property int $uses_inclusive_taxes @@ -226,6 +226,11 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $history * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @property-read \Illuminate\Database\Eloquent\Collection $quotes + * @property-read \Illuminate\Database\Eloquent\Collection $activities + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $history + * @property-read \Illuminate\Database\Eloquent\Collection $invitations + * @property-read \Illuminate\Database\Eloquent\Collection $quotes * @mixin \Eloquent */ class RecurringQuote extends BaseModel @@ -538,22 +543,16 @@ class RecurringQuote extends BaseModel switch ($status) { case self::STATUS_DRAFT: return '

'.ctrans('texts.draft').'

'; - break; case self::STATUS_PENDING: return '

'.ctrans('texts.pending').'

'; - break; case self::STATUS_ACTIVE: return '

'.ctrans('texts.active').'

'; - break; case self::STATUS_COMPLETED: return '

'.ctrans('texts.status_completed').'

'; - break; case self::STATUS_PAUSED: return '

'.ctrans('texts.paused').'

'; - break; default: - // code... - break; + return '

'.ctrans('texts.pending').'

'; } } @@ -562,50 +561,43 @@ class RecurringQuote extends BaseModel switch ($frequency_id) { case self::FREQUENCY_DAILY: return ctrans('texts.freq_daily'); - break; case self::FREQUENCY_WEEKLY: return ctrans('texts.freq_weekly'); - break; case self::FREQUENCY_TWO_WEEKS: return ctrans('texts.freq_two_weeks'); - break; case self::FREQUENCY_FOUR_WEEKS: return ctrans('texts.freq_four_weeks'); - break; case self::FREQUENCY_MONTHLY: return ctrans('texts.freq_monthly'); - break; case self::FREQUENCY_TWO_MONTHS: return ctrans('texts.freq_two_months'); - break; case self::FREQUENCY_THREE_MONTHS: return ctrans('texts.freq_three_months'); - break; case self::FREQUENCY_FOUR_MONTHS: return ctrans('texts.freq_four_months'); - break; case self::FREQUENCY_SIX_MONTHS: return ctrans('texts.freq_six_months'); - break; case self::FREQUENCY_ANNUALLY: return ctrans('texts.freq_annually'); - break; case self::FREQUENCY_TWO_YEARS: return ctrans('texts.freq_two_years'); - break; default: - // code... - break; + return ctrans('texts.freq_weekly'); + } } - public function calc() + /** + * Access the invoice calculator object. + * @return InvoiceSumInclusive | InvoiceSum The invoice calculator object getters + */ + public function calc(): InvoiceSumInclusive | InvoiceSum { $invoice_calc = null; - if ($this->uses_inclusive_taxes) { + if ($this->uses_inclusive_taxes) { $invoice_calc = new InvoiceSumInclusive($this); - } else { + } else { $invoice_calc = new InvoiceSum($this); } @@ -669,10 +661,8 @@ class RecurringQuote extends BaseModel switch ($this->due_date_days) { case 'terms': return $this->calculateDateFromTerms($date); - break; default: return $this->setDayOfMonth($date, $this->due_date_days); - break; } } @@ -697,6 +687,7 @@ class RecurringQuote extends BaseModel /** * Service entry points. + * @return RecurringService */ public function service() :RecurringService { diff --git a/app/Models/Task.php b/app/Models/Task.php index c6500ec00d5d3..d27221ebd68b7 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -46,7 +46,7 @@ use Illuminate\Support\Carbon; * @property int|null $status_order * @property-read \App\Models\User|null $assigned_user * @property-read \App\Models\Client|null $client - * @property-read \App\Models\Company $company + * @property-read \App\Models\Company|null $company * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read int|null $documents_count * @property-read mixed $hashed_id @@ -54,7 +54,6 @@ use Illuminate\Support\Carbon; * @property-read \App\Models\Project|null $project * @property-read \App\Models\TaskStatus|null $status * @property-read \App\Models\User $user - * @method static \Illuminate\Database\Eloquent\Builder|BaseModel company() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns) * @method static \Database\Factories\TaskFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|Task filter(\App\Filters\QueryFilters $filters) @@ -92,16 +91,6 @@ use Illuminate\Support\Carbon; * @method static \Illuminate\Database\Eloquent\Builder|Task withTrashed() * @method static \Illuminate\Database\Eloquent\Builder|Task withoutTrashed() * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $documents * @mixin \Eloquent */ class Task extends BaseModel @@ -138,7 +127,12 @@ class Task extends BaseModel return self::class; } - public function company() + /** + * Get all of the users that belong to the team. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Company::class); } diff --git a/app/Models/Timezone.php b/app/Models/Timezone.php index daf773deb09b1..3bc9c16a62c99 100644 --- a/app/Models/Timezone.php +++ b/app/Models/Timezone.php @@ -27,6 +27,7 @@ namespace App\Models; * @method static \Illuminate\Database\Eloquent\Builder|Timezone whereLocation($value) * @method static \Illuminate\Database\Eloquent\Builder|Timezone whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|Timezone whereUtcOffset($value) + * @method static \Illuminate\Database\Eloquent\Builder|Timezone find() * @mixin \Eloquent */ class Timezone extends StaticModel diff --git a/app/Models/Traits/Excludable.php b/app/Models/Traits/Excludable.php index ba8f87431da23..55249c56dedea 100644 --- a/app/Models/Traits/Excludable.php +++ b/app/Models/Traits/Excludable.php @@ -11,6 +11,13 @@ namespace App\Models\Traits; +use Illuminate\Support\Facades\Schema; + +/** + * @template TModelClass of \Illuminate\Database\Eloquent\Model + * @extends \Illuminate\Database\Eloquent\Builder + * @mixin \Illuminate\Database\Eloquent\Builder + */ trait Excludable { /** @@ -20,18 +27,20 @@ trait Excludable */ private function getTableColumns() { + /** @var Schema|\App\Models\BaseModel $this */ return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable()); } /** * Exclude an array of elements from the result. - * @param $query - * @param $columns + * @param Builder $query + * @param array $columns * - * @return mixed + * @return Builder */ - public function scopeExclude($query, $columns) + public function scopeExclude($query, $columns): \Illuminate\Database\Eloquent\Builder { + /** @var \Illuminate\Database\Eloquent\Builder|static $query */ return $query->select(array_diff($this->getTableColumns(), (array) $columns)); } } diff --git a/app/Models/User.php b/app/Models/User.php index 2b4d6ffe212b2..62bc06e240c45 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -11,26 +11,25 @@ namespace App\Models; +use App\Models\Company; +use App\Utils\TruthSource; use App\Jobs\Mail\NinjaMailer; +use Illuminate\Support\Carbon; +use App\Utils\Traits\MakesHash; use App\Jobs\Mail\NinjaMailerJob; +use App\Services\User\UserService; +use App\Utils\Traits\UserSettings; use App\Jobs\Mail\NinjaMailerObject; use App\Mail\Admin\ResetPasswordObject; +use Illuminate\Database\Eloquent\Model; use App\Models\Presenters\UserPresenter; -use App\Notifications\ResetPasswordNotification; -use App\Services\User\UserService; -use App\Utils\Traits\MakesHash; +use Illuminate\Notifications\Notifiable; +use Laracasts\Presenter\PresentableTrait; use App\Utils\Traits\UserSessionAttributes; -use App\Utils\Traits\UserSettings; -use App\Utils\TruthSource; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; -use Illuminate\Notifications\Notifiable; -use Illuminate\Support\Carbon; -use Illuminate\Support\Facades\Auth; -use Laracasts\Presenter\PresentableTrait; /** * App\Models\User @@ -76,6 +75,7 @@ use Laracasts\Presenter\PresentableTrait; * @property string|null $sms_verification_code * @property int $verified_phone_number * @property-read \App\Models\Account $account + * @property-read \App\Models\Company $company * @property-read \Illuminate\Database\Eloquent\Collection $clients * @property-read int|null $clients_count * @property-read \Illuminate\Database\Eloquent\Collection $companies @@ -146,76 +146,15 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications * @property-read \Illuminate\Database\Eloquent\Collection $tokens - * @property-read \Illuminate\Database\Eloquent\Collection $clients - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $contacts - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications - * @property-read \Illuminate\Database\Eloquent\Collection $tokens - * @property-read \Illuminate\Database\Eloquent\Collection $clients - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $contacts - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications - * @property-read \Illuminate\Database\Eloquent\Collection $tokens - * @property-read \Illuminate\Database\Eloquent\Collection $clients - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $contacts - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications - * @property-read \Illuminate\Database\Eloquent\Collection $tokens - * @property-read \Illuminate\Database\Eloquent\Collection $clients - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $contacts - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications - * @property-read \Illuminate\Database\Eloquent\Collection $tokens - * @property-read \Illuminate\Database\Eloquent\Collection $clients - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $contacts - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications - * @property-read \Illuminate\Database\Eloquent\Collection $tokens - * @property-read \Illuminate\Database\Eloquent\Collection $clients - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $contacts - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications - * @property-read \Illuminate\Database\Eloquent\Collection $tokens - * @property-read \Illuminate\Database\Eloquent\Collection $clients - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $contacts - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications - * @property-read \Illuminate\Database\Eloquent\Collection $tokens - * @property-read \Illuminate\Database\Eloquent\Collection $clients - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $contacts - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications - * @property-read \Illuminate\Database\Eloquent\Collection $tokens - * @property-read \Illuminate\Database\Eloquent\Collection $clients - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $contacts - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications - * @property-read \Illuminate\Database\Eloquent\Collection $tokens - * @property-read \Illuminate\Database\Eloquent\Collection $clients - * @property-read \Illuminate\Database\Eloquent\Collection $companies - * @property-read \Illuminate\Database\Eloquent\Collection $company_users - * @property-read \Illuminate\Database\Eloquent\Collection $contacts - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications - * @property-read \Illuminate\Database\Eloquent\Collection $tokens + * @method bool hasPermissionTo(string $permission) + * @method \App\Models\Company getCompany() + * @method \App\Models\Company company() + * @method bool hasExcludedPermissions(array $matched_permission, array $excluded_permissions) + * @method bool isAdmin() + * @method bool isSuperUser() + * @method bool hasIntersectPermissions(array $permissions) + * @method int companyId() + * @method bool isOwner() * @mixin \Eloquent */ class User extends Authenticatable implements MustVerifyEmail @@ -238,7 +177,7 @@ class User extends Authenticatable implements MustVerifyEmail protected $dateFormat = 'Y-m-d H:i:s.u'; - public $company; + public Company $company; protected $appends = [ 'hashed_id', @@ -247,7 +186,6 @@ class User extends Authenticatable implements MustVerifyEmail /** * The attributes that are mass assignable. * - * @var array */ protected $fillable = [ 'first_name', @@ -271,7 +209,6 @@ class User extends Authenticatable implements MustVerifyEmail /** * The attributes that should be hidden for arrays. * - * @var array */ protected $hidden = [ 'remember_token', @@ -366,7 +303,7 @@ class User extends Authenticatable implements MustVerifyEmail /** * Returns the currently set Company. */ - public function getCompany() + public function getCompany(): ?Company { $truth = app()->make(TruthSource::class); @@ -375,38 +312,34 @@ class User extends Authenticatable implements MustVerifyEmail } elseif ($truth->getCompany()) { return $truth->getCompany(); } elseif (request()->header('X-API-TOKEN')) { - $company_token = CompanyToken::with(['company'])->where('token', request()->header('X-API-TOKEN'))->first(); + $company_token = CompanyToken::with('company')->where('token', request()->header('X-API-TOKEN'))->first(); return $company_token->company; } throw new \Exception('No Company Found'); } - public function companyIsSet() + public function companyIsSet(): bool { - if ($this->company) { - return true; - } - - return false; + return isset($this->company); } /** * Returns the current company. * - * @return App\Models\Company $company + * @return \App\Models\Company $company */ - public function company() + public function company(): Company { return $this->getCompany(); } - private function setCompanyByGuard() - { - if (Auth::guard('contact')->check()) { - $this->setCompany(auth()->user()->client->company); - } - } + // private function setCompanyByGuard() + // { + // if (Auth::guard('contact')->check()) { + // $this->setCompany(auth()->user()->client->company); + // } + // } public function company_users() { @@ -460,19 +393,18 @@ class User extends Authenticatable implements MustVerifyEmail /** * Returns a comma separated list of user permissions. * - * @return comma separated list + * @return string $permissions */ public function permissions() { return $this->token()->cu->permissions; - // return $this->company_user->permissions; } /** * Returns a object of User Settings. * - * @return stdClass + * @return \stdClass */ public function settings() { @@ -523,7 +455,7 @@ class User extends Authenticatable implements MustVerifyEmail /** * Returns a boolean value if the user owns the current Entity. * - * @param string Entity + * @param mixed $entity * @return bool */ public function owns($entity) : bool @@ -534,7 +466,7 @@ class User extends Authenticatable implements MustVerifyEmail /** * Returns a boolean value if the user is assigned to the current Entity. * - * @param string Entity + * @param mixed $entity * @return bool */ public function assigned($entity) : bool @@ -545,7 +477,7 @@ class User extends Authenticatable implements MustVerifyEmail /** * Returns true if permissions exist in the map. * - * @param string permission + * @param string $permission * @return bool */ public function hasPermission($permission) : bool diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index eb0ff47125c7c..e7eeae12c41a2 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -148,6 +148,10 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $contacts * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $primary_contact + * @property-read \Illuminate\Database\Eloquent\Collection $activities + * @property-read \Illuminate\Database\Eloquent\Collection $contacts + * @property-read \Illuminate\Database\Eloquent\Collection $documents + * @property-read \Illuminate\Database\Eloquent\Collection $primary_contact * @mixin \Eloquent */ class Vendor extends BaseModel diff --git a/app/Models/VendorContact.php b/app/Models/VendorContact.php index 3e68710494bce..e78715903a71c 100644 --- a/app/Models/VendorContact.php +++ b/app/Models/VendorContact.php @@ -132,6 +132,8 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $purchase_order_invitations * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications * @property-read \Illuminate\Database\Eloquent\Collection $purchase_order_invitations + * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications + * @property-read \Illuminate\Database\Eloquent\Collection $purchase_order_invitations * @mixin \Eloquent */ class VendorContact extends Authenticatable implements HasLocalePreference diff --git a/app/Models/Webhook.php b/app/Models/Webhook.php index 8b419a6bd7392..05eab5acd514e 100644 --- a/app/Models/Webhook.php +++ b/app/Models/Webhook.php @@ -53,6 +53,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Eloquent\Builder|Webhook whereUserId($value) * @method static \Illuminate\Database\Eloquent\Builder|Webhook withTrashed() * @method static \Illuminate\Database\Eloquent\Builder|Webhook withoutTrashed() + * @method static \Illuminate\Database\Eloquent\Builder|Webhook where() * @mixin \Eloquent */ class Webhook extends BaseModel diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 1028a0c943cc0..5e8f8d60876c7 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -11,266 +11,270 @@ namespace App\Providers; -use App\Events\Account\AccountCreated; -use App\Events\Client\ClientWasArchived; -use App\Events\Client\ClientWasCreated; -use App\Events\Client\ClientWasDeleted; -use App\Events\Client\ClientWasRestored; -use App\Events\Client\ClientWasUpdated; -use App\Events\Client\DesignWasDeleted; -use App\Events\Client\DesignWasRestored; -use App\Events\Client\DesignWasUpdated; -use App\Events\Company\CompanyDocumentsDeleted; -use App\Events\Contact\ContactLoggedIn; -use App\Events\Credit\CreditWasArchived; -use App\Events\Credit\CreditWasCreated; -use App\Events\Credit\CreditWasDeleted; -use App\Events\Credit\CreditWasEmailed; -use App\Events\Credit\CreditWasEmailedAndFailed; -use App\Events\Credit\CreditWasMarkedSent; -use App\Events\Credit\CreditWasRestored; -use App\Events\Credit\CreditWasUpdated; -use App\Events\Credit\CreditWasViewed; -use App\Events\Design\DesignWasArchived; -use App\Events\Expense\ExpenseWasArchived; -use App\Events\Expense\ExpenseWasCreated; -use App\Events\Expense\ExpenseWasDeleted; -use App\Events\Expense\ExpenseWasRestored; -use App\Events\Expense\ExpenseWasUpdated; -use App\Events\Invoice\InvoiceReminderWasEmailed; -use App\Events\Invoice\InvoiceWasArchived; -use App\Events\Invoice\InvoiceWasCancelled; -use App\Events\Invoice\InvoiceWasCreated; -use App\Events\Invoice\InvoiceWasDeleted; -use App\Events\Invoice\InvoiceWasEmailed; -use App\Events\Invoice\InvoiceWasEmailedAndFailed; -use App\Events\Invoice\InvoiceWasMarkedSent; -use App\Events\Invoice\InvoiceWasPaid; -use App\Events\Invoice\InvoiceWasRestored; -use App\Events\Invoice\InvoiceWasReversed; -use App\Events\Invoice\InvoiceWasUpdated; -use App\Events\Invoice\InvoiceWasViewed; -use App\Events\Misc\InvitationWasViewed; -use App\Events\Payment\PaymentWasArchived; -use App\Events\Payment\PaymentWasCreated; -use App\Events\Payment\PaymentWasDeleted; -use App\Events\Payment\PaymentWasEmailed; -use App\Events\Payment\PaymentWasEmailedAndFailed; -use App\Events\Payment\PaymentWasRefunded; -use App\Events\Payment\PaymentWasRestored; -use App\Events\Payment\PaymentWasUpdated; -use App\Events\Payment\PaymentWasVoided; -use App\Events\PurchaseOrder\PurchaseOrderWasAccepted; -use App\Events\PurchaseOrder\PurchaseOrderWasArchived; -use App\Events\PurchaseOrder\PurchaseOrderWasCreated; -use App\Events\PurchaseOrder\PurchaseOrderWasDeleted; -use App\Events\PurchaseOrder\PurchaseOrderWasEmailed; -use App\Events\PurchaseOrder\PurchaseOrderWasRestored; -use App\Events\PurchaseOrder\PurchaseOrderWasUpdated; -use App\Events\PurchaseOrder\PurchaseOrderWasViewed; -use App\Events\Quote\QuoteWasApproved; -use App\Events\Quote\QuoteWasArchived; -use App\Events\Quote\QuoteWasCreated; -use App\Events\Quote\QuoteWasDeleted; -use App\Events\Quote\QuoteWasEmailed; -use App\Events\Quote\QuoteWasRestored; -use App\Events\Quote\QuoteWasUpdated; -use App\Events\Quote\QuoteWasViewed; -use App\Events\RecurringExpense\RecurringExpenseWasArchived; -use App\Events\RecurringExpense\RecurringExpenseWasCreated; -use App\Events\RecurringExpense\RecurringExpenseWasDeleted; -use App\Events\RecurringExpense\RecurringExpenseWasRestored; -use App\Events\RecurringExpense\RecurringExpenseWasUpdated; -use App\Events\RecurringInvoice\RecurringInvoiceWasArchived; -use App\Events\RecurringInvoice\RecurringInvoiceWasCreated; -use App\Events\RecurringInvoice\RecurringInvoiceWasDeleted; -use App\Events\RecurringInvoice\RecurringInvoiceWasRestored; -use App\Events\RecurringInvoice\RecurringInvoiceWasUpdated; -use App\Events\RecurringQuote\RecurringQuoteWasArchived; -use App\Events\RecurringQuote\RecurringQuoteWasCreated; -use App\Events\RecurringQuote\RecurringQuoteWasDeleted; -use App\Events\RecurringQuote\RecurringQuoteWasRestored; -use App\Events\RecurringQuote\RecurringQuoteWasUpdated; -use App\Events\Subscription\SubscriptionWasArchived; -use App\Events\Subscription\SubscriptionWasCreated; -use App\Events\Subscription\SubscriptionWasDeleted; -use App\Events\Subscription\SubscriptionWasRestored; -use App\Events\Subscription\SubscriptionWasUpdated; -use App\Events\Task\TaskWasArchived; -use App\Events\Task\TaskWasCreated; -use App\Events\Task\TaskWasDeleted; -use App\Events\Task\TaskWasRestored; -use App\Events\Task\TaskWasUpdated; -use App\Events\User\UserLoggedIn; -use App\Events\User\UserWasArchived; -use App\Events\User\UserWasCreated; -use App\Events\User\UserWasDeleted; -use App\Events\User\UserWasRestored; -use App\Events\User\UserWasUpdated; -use App\Events\Vendor\VendorWasArchived; -use App\Events\Vendor\VendorWasCreated; -use App\Events\Vendor\VendorWasDeleted; -use App\Events\Vendor\VendorWasRestored; -use App\Events\Vendor\VendorWasUpdated; -use App\Listeners\Activity\ArchivedClientActivity; -use App\Listeners\Activity\ClientUpdatedActivity; -use App\Listeners\Activity\CreatedClientActivity; -use App\Listeners\Activity\CreatedCreditActivity; -use App\Listeners\Activity\CreatedExpenseActivity; -use App\Listeners\Activity\CreatedQuoteActivity; -use App\Listeners\Activity\CreatedSubscriptionActivity; -use App\Listeners\Activity\CreatedTaskActivity; -use App\Listeners\Activity\CreatedVendorActivity; -use App\Listeners\Activity\CreditArchivedActivity; -use App\Listeners\Activity\DeleteClientActivity; -use App\Listeners\Activity\DeleteCreditActivity; -use App\Listeners\Activity\ExpenseArchivedActivity; -use App\Listeners\Activity\ExpenseDeletedActivity; -use App\Listeners\Activity\ExpenseRestoredActivity; -use App\Listeners\Activity\ExpenseUpdatedActivity; -use App\Listeners\Activity\PaymentArchivedActivity; -use App\Listeners\Activity\PaymentCreatedActivity; -use App\Listeners\Activity\PaymentDeletedActivity; -use App\Listeners\Activity\PaymentRefundedActivity; -use App\Listeners\Activity\PaymentUpdatedActivity; -use App\Listeners\Activity\PaymentVoidedActivity; -use App\Listeners\Activity\QuoteUpdatedActivity; -use App\Listeners\Activity\RestoreClientActivity; -use App\Listeners\Activity\SubscriptionArchivedActivity; -use App\Listeners\Activity\SubscriptionDeletedActivity; -use App\Listeners\Activity\SubscriptionRestoredActivity; -use App\Listeners\Activity\SubscriptionUpdatedActivity; -use App\Listeners\Activity\TaskArchivedActivity; -use App\Listeners\Activity\TaskDeletedActivity; -use App\Listeners\Activity\TaskRestoredActivity; -use App\Listeners\Activity\TaskUpdatedActivity; -use App\Listeners\Activity\UpdatedCreditActivity; -use App\Listeners\Activity\VendorArchivedActivity; -use App\Listeners\Activity\VendorDeletedActivity; -use App\Listeners\Activity\VendorRestoredActivity; -use App\Listeners\Activity\VendorUpdatedActivity; -use App\Listeners\Contact\UpdateContactLastLogin; -use App\Listeners\Credit\CreditCreatedNotification; -use App\Listeners\Credit\CreditEmailedNotification; -use App\Listeners\Credit\CreditRestoredActivity; -use App\Listeners\Credit\CreditViewedActivity; -use App\Listeners\Document\DeleteCompanyDocuments; -use App\Listeners\Invoice\CreateInvoiceActivity; -use App\Listeners\Invoice\CreateInvoicePdf; -use App\Listeners\Invoice\InvoiceArchivedActivity; -use App\Listeners\Invoice\InvoiceCancelledActivity; -use App\Listeners\Invoice\InvoiceCreatedNotification; -use App\Listeners\Invoice\InvoiceDeletedActivity; -use App\Listeners\Invoice\InvoiceEmailActivity; -use App\Listeners\Invoice\InvoiceEmailedNotification; -use App\Listeners\Invoice\InvoiceEmailFailedActivity; -use App\Listeners\Invoice\InvoiceFailedEmailNotification; -use App\Listeners\Invoice\InvoicePaidActivity; -use App\Listeners\Invoice\InvoiceReminderEmailActivity; -use App\Listeners\Invoice\InvoiceRestoredActivity; -use App\Listeners\Invoice\InvoiceReversedActivity; -use App\Listeners\Invoice\InvoiceViewedActivity; -use App\Listeners\Invoice\UpdateInvoiceActivity; -use App\Listeners\Mail\MailSentListener; -use App\Listeners\Misc\InvitationViewedListener; -use App\Listeners\Payment\PaymentBalanceActivity; -use App\Listeners\Payment\PaymentEmailedActivity; -use App\Listeners\Payment\PaymentNotification; -use App\Listeners\Payment\PaymentRestoredActivity; -use App\Listeners\PurchaseOrder\CreatePurchaseOrderActivity; -use App\Listeners\PurchaseOrder\PurchaseOrderAcceptedActivity; -use App\Listeners\PurchaseOrder\PurchaseOrderAcceptedListener; -use App\Listeners\PurchaseOrder\PurchaseOrderArchivedActivity; -use App\Listeners\PurchaseOrder\PurchaseOrderCreatedListener; -use App\Listeners\PurchaseOrder\PurchaseOrderDeletedActivity; -use App\Listeners\PurchaseOrder\PurchaseOrderEmailActivity; -use App\Listeners\PurchaseOrder\PurchaseOrderEmailedNotification; -use App\Listeners\PurchaseOrder\PurchaseOrderRestoredActivity; -use App\Listeners\PurchaseOrder\PurchaseOrderViewedActivity; -use App\Listeners\PurchaseOrder\UpdatePurchaseOrderActivity; -use App\Listeners\Quote\QuoteApprovedActivity; -use App\Listeners\Quote\QuoteApprovedNotification; -use App\Listeners\Quote\QuoteApprovedWebhook; -use App\Listeners\Quote\QuoteArchivedActivity; -use App\Listeners\Quote\QuoteCreatedNotification; -use App\Listeners\Quote\QuoteDeletedActivity; -use App\Listeners\Quote\QuoteEmailActivity; -use App\Listeners\Quote\QuoteEmailedNotification; -use App\Listeners\Quote\QuoteRestoredActivity; -use App\Listeners\Quote\QuoteViewedActivity; -use App\Listeners\Quote\ReachWorkflowSettings; -use App\Listeners\RecurringExpense\CreatedRecurringExpenseActivity; -use App\Listeners\RecurringExpense\RecurringExpenseArchivedActivity; -use App\Listeners\RecurringExpense\RecurringExpenseDeletedActivity; -use App\Listeners\RecurringExpense\RecurringExpenseRestoredActivity; -use App\Listeners\RecurringExpense\RecurringExpenseUpdatedActivity; -use App\Listeners\RecurringInvoice\CreateRecurringInvoiceActivity; -use App\Listeners\RecurringInvoice\RecurringInvoiceArchivedActivity; -use App\Listeners\RecurringInvoice\RecurringInvoiceDeletedActivity; -use App\Listeners\RecurringInvoice\RecurringInvoiceRestoredActivity; -use App\Listeners\RecurringInvoice\UpdateRecurringInvoiceActivity; -use App\Listeners\RecurringQuote\CreateRecurringQuoteActivity; -use App\Listeners\RecurringQuote\RecurringQuoteArchivedActivity; -use App\Listeners\RecurringQuote\RecurringQuoteDeletedActivity; -use App\Listeners\RecurringQuote\RecurringQuoteRestoredActivity; -use App\Listeners\RecurringQuote\UpdateRecurringQuoteActivity; -use App\Listeners\SendVerificationNotification; -use App\Listeners\User\ArchivedUserActivity; -use App\Listeners\User\CreatedUserActivity; -use App\Listeners\User\DeletedUserActivity; -use App\Listeners\User\RestoredUserActivity; -use App\Listeners\User\UpdatedUserActivity; -use App\Listeners\User\UpdateUserLastLogin; -use App\Models\Account; +use App\Models\Task; +use App\Models\User; +use App\Models\Quote; use App\Models\Client; -use App\Models\ClientContact; -use App\Models\Company; -use App\Models\CompanyGateway; -use App\Models\CompanyToken; use App\Models\Credit; +use App\Models\Vendor; +use App\Models\Account; +use App\Models\Company; use App\Models\Expense; use App\Models\Invoice; use App\Models\Payment; use App\Models\Product; use App\Models\Project; use App\Models\Proposal; -use App\Models\PurchaseOrder; -use App\Models\Quote; +use App\Models\CompanyToken; use App\Models\Subscription; -use App\Models\Task; -use App\Models\User; -use App\Models\Vendor; +use App\Models\ClientContact; +use App\Models\PurchaseOrder; use App\Models\VendorContact; -use App\Observers\AccountObserver; -use App\Observers\ClientContactObserver; +use App\Models\CompanyGateway; +use App\Observers\TaskObserver; +use App\Observers\UserObserver; +use App\Observers\QuoteObserver; +use App\Events\User\UserLoggedIn; use App\Observers\ClientObserver; -use App\Observers\CompanyGatewayObserver; -use App\Observers\CompanyObserver; -use App\Observers\CompanyTokenObserver; use App\Observers\CreditObserver; +use App\Observers\VendorObserver; +use App\Observers\AccountObserver; +use App\Observers\CompanyObserver; use App\Observers\ExpenseObserver; use App\Observers\InvoiceObserver; use App\Observers\PaymentObserver; use App\Observers\ProductObserver; use App\Observers\ProjectObserver; +use App\Events\Task\TaskWasCreated; +use App\Events\Task\TaskWasDeleted; +use App\Events\Task\TaskWasUpdated; +use App\Events\User\UserWasCreated; +use App\Events\User\UserWasDeleted; +use App\Events\User\UserWasUpdated; use App\Observers\ProposalObserver; -use App\Observers\PurchaseOrderObserver; -use App\Observers\QuoteObserver; +use App\Events\Quote\QuoteWasViewed; +use App\Events\Task\TaskWasArchived; +use App\Events\Task\TaskWasRestored; +use App\Events\User\UserWasArchived; +use App\Events\User\UserWasRestored; +use App\Events\Quote\QuoteWasCreated; +use App\Events\Quote\QuoteWasDeleted; +use App\Events\Quote\QuoteWasEmailed; +use App\Events\Quote\QuoteWasUpdated; +use App\Events\Account\AccountCreated; +use App\Events\Credit\CreditWasViewed; +use App\Events\Invoice\InvoiceWasPaid; +use App\Events\Quote\QuoteWasApproved; +use App\Events\Quote\QuoteWasArchived; +use App\Events\Quote\QuoteWasRestored; +use App\Events\Client\ClientWasCreated; +use App\Events\Client\ClientWasDeleted; +use App\Events\Client\ClientWasUpdated; +use App\Events\Design\DesignWasDeleted; +use App\Events\Design\DesignWasUpdated; +use App\Events\Contact\ContactLoggedIn; +use App\Events\Credit\CreditWasCreated; +use App\Events\Credit\CreditWasDeleted; +use App\Events\Credit\CreditWasEmailed; +use App\Events\Credit\CreditWasUpdated; +use App\Events\Vendor\VendorWasCreated; +use App\Events\Vendor\VendorWasDeleted; +use App\Events\Vendor\VendorWasUpdated; +use App\Observers\CompanyTokenObserver; use App\Observers\SubscriptionObserver; -use App\Observers\TaskObserver; -use App\Observers\UserObserver; -use App\Observers\VendorContactObserver; -use App\Observers\VendorObserver; -use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -use Illuminate\Mail\Events\MessageSending; use Illuminate\Mail\Events\MessageSent; +use App\Events\Client\ClientWasArchived; +use App\Events\Client\ClientWasRestored; +use App\Events\Design\DesignWasRestored; +use App\Events\Credit\CreditWasArchived; +use App\Events\Credit\CreditWasRestored; +use App\Events\Design\DesignWasArchived; +use App\Events\Invoice\InvoiceWasViewed; +use App\Events\Misc\InvitationWasViewed; +use App\Events\Payment\PaymentWasVoided; +use App\Events\Vendor\VendorWasArchived; +use App\Events\Vendor\VendorWasRestored; +use App\Listeners\Mail\MailSentListener; +use App\Observers\ClientContactObserver; +use App\Observers\PurchaseOrderObserver; +use App\Observers\VendorContactObserver; +use App\Events\Expense\ExpenseWasCreated; +use App\Events\Expense\ExpenseWasDeleted; +use App\Events\Expense\ExpenseWasUpdated; +use App\Events\Invoice\InvoiceWasCreated; +use App\Events\Invoice\InvoiceWasDeleted; +use App\Events\Invoice\InvoiceWasEmailed; +use App\Events\Invoice\InvoiceWasUpdated; +use App\Events\Payment\PaymentWasCreated; +use App\Events\Payment\PaymentWasDeleted; +use App\Events\Payment\PaymentWasEmailed; +use App\Events\Payment\PaymentWasUpdated; +use App\Observers\CompanyGatewayObserver; +use App\Events\Credit\CreditWasMarkedSent; +use App\Events\Expense\ExpenseWasArchived; +use App\Events\Expense\ExpenseWasRestored; +use App\Events\Invoice\InvoiceWasArchived; +use App\Events\Invoice\InvoiceWasRestored; +use App\Events\Invoice\InvoiceWasReversed; +use App\Events\Payment\PaymentWasArchived; +use App\Events\Payment\PaymentWasRefunded; +use App\Events\Payment\PaymentWasRestored; +use Illuminate\Mail\Events\MessageSending; +use App\Events\Document\DocumentWasCreated; +use App\Events\Document\DocumentWasDeleted; +use App\Events\Document\DocumentWasUpdated; +use App\Events\Invoice\InvoiceWasCancelled; +use App\Listeners\Invoice\CreateInvoicePdf; +use App\Listeners\Quote\QuoteEmailActivity; +use App\Listeners\User\CreatedUserActivity; +use App\Listeners\User\DeletedUserActivity; +use App\Listeners\User\UpdatedUserActivity; +use App\Listeners\User\UpdateUserLastLogin; +use App\Events\Document\DocumentWasArchived; +use App\Events\Document\DocumentWasRestored; +use App\Events\Invoice\InvoiceWasMarkedSent; +use App\Listeners\Quote\QuoteViewedActivity; +use App\Listeners\User\ArchivedUserActivity; +use App\Listeners\User\RestoredUserActivity; +use App\Listeners\Quote\QuoteApprovedWebhook; +use App\Listeners\Quote\QuoteDeletedActivity; +use App\Listeners\Credit\CreditViewedActivity; +use App\Listeners\Invoice\InvoicePaidActivity; +use App\Listeners\Payment\PaymentNotification; +use App\Listeners\Quote\QuoteApprovedActivity; +use App\Listeners\Quote\QuoteArchivedActivity; +use App\Listeners\Quote\QuoteRestoredActivity; +use App\Listeners\Quote\ReachWorkflowSettings; +use App\Events\Company\CompanyDocumentsDeleted; +use App\Listeners\Activity\CreatedTaskActivity; +use App\Listeners\Activity\TaskDeletedActivity; +use App\Listeners\Activity\TaskUpdatedActivity; +use App\Listeners\Invoice\InvoiceEmailActivity; +use App\Listeners\SendVerificationNotification; +use App\Events\Credit\CreditWasEmailedAndFailed; +use App\Listeners\Activity\CreatedQuoteActivity; +use App\Listeners\Activity\DeleteClientActivity; +use App\Listeners\Activity\DeleteCreditActivity; +use App\Listeners\Activity\QuoteUpdatedActivity; +use App\Listeners\Activity\TaskArchivedActivity; +use App\Listeners\Activity\TaskRestoredActivity; +use App\Listeners\Credit\CreditRestoredActivity; +use App\Listeners\Invoice\CreateInvoiceActivity; +use App\Listeners\Invoice\InvoiceViewedActivity; +use App\Listeners\Invoice\UpdateInvoiceActivity; +use App\Listeners\Misc\InvitationViewedListener; +use App\Events\Invoice\InvoiceReminderWasEmailed; +use App\Listeners\Activity\ClientUpdatedActivity; +use App\Listeners\Activity\CreatedClientActivity; +use App\Listeners\Activity\CreatedCreditActivity; +use App\Listeners\Activity\CreatedVendorActivity; +use App\Listeners\Activity\PaymentVoidedActivity; +use App\Listeners\Activity\RestoreClientActivity; +use App\Listeners\Activity\UpdatedCreditActivity; +use App\Listeners\Activity\VendorDeletedActivity; +use App\Listeners\Activity\VendorUpdatedActivity; +use App\Listeners\Contact\UpdateContactLastLogin; +use App\Listeners\Invoice\InvoiceDeletedActivity; +use App\Listeners\Payment\PaymentBalanceActivity; +use App\Listeners\Payment\PaymentEmailedActivity; +use App\Listeners\Quote\QuoteCreatedNotification; +use App\Listeners\Quote\QuoteEmailedNotification; +use App\Events\Invoice\InvoiceWasEmailedAndFailed; +use App\Events\Payment\PaymentWasEmailedAndFailed; +use App\Listeners\Activity\ArchivedClientActivity; +use App\Listeners\Activity\CreatedExpenseActivity; +use App\Listeners\Activity\CreditArchivedActivity; +use App\Listeners\Activity\ExpenseDeletedActivity; +use App\Listeners\Activity\ExpenseUpdatedActivity; +use App\Listeners\Activity\PaymentCreatedActivity; +use App\Listeners\Activity\PaymentDeletedActivity; +use App\Listeners\Activity\PaymentUpdatedActivity; +use App\Listeners\Activity\VendorArchivedActivity; +use App\Listeners\Activity\VendorRestoredActivity; +use App\Listeners\Document\DeleteCompanyDocuments; +use App\Listeners\Invoice\InvoiceArchivedActivity; +use App\Listeners\Invoice\InvoiceRestoredActivity; +use App\Listeners\Invoice\InvoiceReversedActivity; +use App\Listeners\Payment\PaymentRestoredActivity; +use App\Listeners\Quote\QuoteApprovedNotification; +use App\Events\Subscription\SubscriptionWasCreated; +use App\Events\Subscription\SubscriptionWasDeleted; +use App\Events\Subscription\SubscriptionWasUpdated; +use App\Listeners\Activity\ExpenseArchivedActivity; +use App\Listeners\Activity\ExpenseRestoredActivity; +use App\Listeners\Activity\PaymentArchivedActivity; +use App\Listeners\Activity\PaymentRefundedActivity; +use App\Listeners\Credit\CreditCreatedNotification; +use App\Listeners\Credit\CreditEmailedNotification; +use App\Listeners\Invoice\InvoiceCancelledActivity; +use App\Events\PurchaseOrder\PurchaseOrderWasViewed; +use App\Events\Subscription\SubscriptionWasArchived; +use App\Events\Subscription\SubscriptionWasRestored; +use App\Events\PurchaseOrder\PurchaseOrderWasCreated; +use App\Events\PurchaseOrder\PurchaseOrderWasDeleted; +use App\Events\PurchaseOrder\PurchaseOrderWasEmailed; +use App\Events\PurchaseOrder\PurchaseOrderWasUpdated; +use App\Listeners\Invoice\InvoiceCreatedNotification; +use App\Listeners\Invoice\InvoiceEmailedNotification; +use App\Listeners\Invoice\InvoiceEmailFailedActivity; +use App\Events\PurchaseOrder\PurchaseOrderWasAccepted; +use App\Events\PurchaseOrder\PurchaseOrderWasArchived; +use App\Events\PurchaseOrder\PurchaseOrderWasRestored; +use App\Events\RecurringQuote\RecurringQuoteWasCreated; +use App\Events\RecurringQuote\RecurringQuoteWasDeleted; +use App\Events\RecurringQuote\RecurringQuoteWasUpdated; +use App\Listeners\Activity\CreatedSubscriptionActivity; +use App\Listeners\Activity\SubscriptionDeletedActivity; +use App\Listeners\Activity\SubscriptionUpdatedActivity; +use App\Listeners\Invoice\InvoiceReminderEmailActivity; +use App\Events\RecurringQuote\RecurringQuoteWasArchived; +use App\Events\RecurringQuote\RecurringQuoteWasRestored; +use App\Listeners\Activity\SubscriptionArchivedActivity; +use App\Listeners\Activity\SubscriptionRestoredActivity; +use App\Listeners\Invoice\InvoiceFailedEmailNotification; +use App\Events\RecurringExpense\RecurringExpenseWasCreated; +use App\Events\RecurringExpense\RecurringExpenseWasDeleted; +use App\Events\RecurringExpense\RecurringExpenseWasUpdated; +use App\Events\RecurringInvoice\RecurringInvoiceWasCreated; +use App\Events\RecurringInvoice\RecurringInvoiceWasDeleted; +use App\Events\RecurringInvoice\RecurringInvoiceWasUpdated; +use App\Listeners\PurchaseOrder\PurchaseOrderEmailActivity; +use App\Events\RecurringExpense\RecurringExpenseWasArchived; +use App\Events\RecurringExpense\RecurringExpenseWasRestored; +use App\Events\RecurringInvoice\RecurringInvoiceWasArchived; +use App\Events\RecurringInvoice\RecurringInvoiceWasRestored; +use App\Listeners\PurchaseOrder\CreatePurchaseOrderActivity; +use App\Listeners\PurchaseOrder\PurchaseOrderViewedActivity; +use App\Listeners\PurchaseOrder\UpdatePurchaseOrderActivity; +use App\Listeners\PurchaseOrder\PurchaseOrderCreatedListener; +use App\Listeners\PurchaseOrder\PurchaseOrderDeletedActivity; +use App\Listeners\PurchaseOrder\PurchaseOrderAcceptedActivity; +use App\Listeners\PurchaseOrder\PurchaseOrderAcceptedListener; +use App\Listeners\PurchaseOrder\PurchaseOrderArchivedActivity; +use App\Listeners\PurchaseOrder\PurchaseOrderRestoredActivity; +use App\Listeners\RecurringQuote\CreateRecurringQuoteActivity; +use App\Listeners\RecurringQuote\UpdateRecurringQuoteActivity; +use App\Listeners\RecurringQuote\RecurringQuoteDeletedActivity; +use App\Listeners\RecurringQuote\RecurringQuoteArchivedActivity; +use App\Listeners\RecurringQuote\RecurringQuoteRestoredActivity; +use App\Listeners\PurchaseOrder\PurchaseOrderEmailedNotification; +use App\Listeners\RecurringInvoice\CreateRecurringInvoiceActivity; +use App\Listeners\RecurringInvoice\UpdateRecurringInvoiceActivity; +use App\Listeners\RecurringExpense\CreatedRecurringExpenseActivity; +use App\Listeners\RecurringExpense\RecurringExpenseDeletedActivity; +use App\Listeners\RecurringExpense\RecurringExpenseUpdatedActivity; +use App\Listeners\RecurringInvoice\RecurringInvoiceDeletedActivity; +use App\Listeners\RecurringExpense\RecurringExpenseArchivedActivity; +use App\Listeners\RecurringExpense\RecurringExpenseRestoredActivity; +use App\Listeners\RecurringInvoice\RecurringInvoiceArchivedActivity; +use App\Listeners\RecurringInvoice\RecurringInvoiceRestoredActivity; +use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider { /** * The event listener mappings for the application. * - * @var array */ protected $listen = [ AccountCreated::class => [ @@ -434,6 +438,7 @@ class EventServiceProvider extends ServiceProvider ], InvoiceReminderWasEmailed::class => [ InvoiceReminderEmailActivity::class, + InvoiceEmailedNotification::class, ], InvoiceWasDeleted::class => [ InvoiceDeletedActivity::class, diff --git a/app/Services/Invoice/AddGatewayFee.php b/app/Services/Invoice/AddGatewayFee.php index 341da87894443..fc75d40bf7bbd 100644 --- a/app/Services/Invoice/AddGatewayFee.php +++ b/app/Services/Invoice/AddGatewayFee.php @@ -20,23 +20,9 @@ use Illuminate\Support\Facades\App; class AddGatewayFee extends AbstractService { - private $company_gateway; - - public $invoice; - - private $amount; - - private $gateway_type_id; - - public function __construct(CompanyGateway $company_gateway, int $gateway_type_id, Invoice $invoice, float $amount) + + public function __construct(private CompanyGateway $company_gateway, private int $gateway_type_id, public Invoice $invoice, private float $amount) { - $this->company_gateway = $company_gateway; - - $this->invoice = $invoice; - - $this->amount = $amount; - - $this->gateway_type_id = $gateway_type_id; } public function run() diff --git a/app/Services/Invoice/ApplyRecurringNumber.php b/app/Services/Invoice/ApplyRecurringNumber.php index dbb96d7df97ea..f7b908e7d07f1 100644 --- a/app/Services/Invoice/ApplyRecurringNumber.php +++ b/app/Services/Invoice/ApplyRecurringNumber.php @@ -21,17 +21,10 @@ class ApplyRecurringNumber extends AbstractService { use GeneratesCounter; - private $client; - - private $invoice; - private bool $completed = true; - public function __construct(Client $client, Invoice $invoice) + public function __construct(private Client $client, private Invoice $invoice) { - $this->client = $client; - - $this->invoice = $invoice; } public function run() diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 4e54c27ee3f95..de76290a75e07 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -11,45 +11,41 @@ namespace App\Services\Invoice; -use App\DataMapper\InvoiceItem; -use App\Events\Invoice\InvoiceWasPaid; -use App\Events\Payment\PaymentWasCreated; -use App\Factory\PaymentFactory; -use App\Libraries\MultiDB; +use App\Utils\Ninja; +use App\Models\Client; use App\Models\Credit; use App\Models\Invoice; use App\Models\Payment; +use App\Libraries\MultiDB; use App\Models\PaymentHash; use App\Models\PaymentType; -use App\Services\AbstractService; -use App\Utils\Ninja; use Illuminate\Support\Str; +use App\DataMapper\InvoiceItem; +use App\Factory\PaymentFactory; +use App\Services\AbstractService; +use App\Models\ClientGatewayToken; +use App\Events\Invoice\InvoiceWasPaid; +use App\Events\Payment\PaymentWasCreated; class AutoBillInvoice extends AbstractService { - private $invoice; - private $client; + private Client $client; - private $used_credit = []; - - protected $db; + private array $used_credit = []; /*Specific variable for partial payments */ private bool $is_partial_amount = false; - public function __construct(Invoice $invoice, $db) + public function __construct(private Invoice $invoice, protected string $db) { - $this->invoice = $invoice; - - $this->db = $db; } public function run() { MultiDB::setDb($this->db); - /* Harvest Client*/ + /* @var \App\Modesl\Client $client */ $this->client = $this->invoice->client; $is_partial = false; @@ -78,6 +74,7 @@ class AutoBillInvoice extends AbstractService } $amount = 0; + $invoice_total = 0; /* Determine $amount */ if ($this->invoice->partial > 0) { @@ -93,13 +90,15 @@ class AutoBillInvoice extends AbstractService info("Auto Bill - balance remains to be paid!! - {$amount}"); /* Retrieve the Client Gateway Token */ + /** @var \App\Models\ClientGatewayToken $gateway_token */ $gateway_token = $this->getGateway($amount); /* Bail out if no payment methods available */ if (! $gateway_token || ! $gateway_token->gateway || ! $gateway_token->gateway->driver($this->client)->token_billing) { nlog('Bailing out - no suitable gateway token found.'); - return $this->invoice; + throw new \Exception(ctrans('texts.no_payment_method_specified')); + // return $this->invoice; } nlog('Gateway present - adding gateway fee'); @@ -191,6 +190,8 @@ class AutoBillInvoice extends AbstractService ->service() ->setCalculatedStatus() ->save(); + + $current_credit = false; foreach ($this->used_credit as $credit) { $current_credit = Credit::find($credit['credit_id']); @@ -219,8 +220,10 @@ class AutoBillInvoice extends AbstractService ->adjustCreditBalance($amount * -1) ->save(); + $credit_reference = $current_credit ? $current_credit->number : 'unknown'; + $this->invoice->ledger() //09-03-2022 - ->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}") + ->updateCreditBalance($amount * -1, "Credit {$credit_reference} used to pay down Invoice {$this->invoice->number}") ->save(); event('eloquent.created: App\Models\Payment', $payment); @@ -245,7 +248,7 @@ class AutoBillInvoice extends AbstractService * * @return $this */ - private function applyCreditPayment() + private function applyCreditPayment(): self { $available_credits = Credit::where('client_id', $this->client->id) ->where('is_deleted', false) @@ -258,7 +261,7 @@ class AutoBillInvoice extends AbstractService info("available credit balance = {$available_credit_balance}"); if ((int) $available_credit_balance == 0) { - return; + return $this; } if ($this->invoice->partial > 0) { @@ -307,32 +310,32 @@ class AutoBillInvoice extends AbstractService return $this; } - private function applyPaymentToCredit($credit, $amount) :Credit - { - $credit_item = new InvoiceItem; - $credit_item->type_id = '1'; - $credit_item->product_key = ctrans('texts.credit'); - $credit_item->notes = ctrans('texts.credit_payment', ['invoice_number' => $this->invoice->number]); - $credit_item->quantity = 1; - $credit_item->cost = $amount * -1; + // private function applyPaymentToCredit($credit, $amount) :Credit + // { + // $credit_item = new InvoiceItem; + // $credit_item->type_id = '1'; + // $credit_item->product_key = ctrans('texts.credit'); + // $credit_item->notes = ctrans('texts.credit_payment', ['invoice_number' => $this->invoice->number]); + // $credit_item->quantity = 1; + // $credit_item->cost = $amount * -1; - $credit_items = $credit->line_items; - $credit_items[] = $credit_item; + // $credit_items = $credit->line_items; + // $credit_items[] = $credit_item; - $credit->line_items = $credit_items; + // $credit->line_items = $credit_items; - $credit = $credit->calc()->getCredit(); - $credit->save(); + // $credit = $credit->calc()->getCredit(); + // $credit->save(); - return $credit; - } + // return $credit; + // } /** * Harvests a client gateway token which passes the * necessary filters for an $amount. * * @param float $amount The amount to charge - * @return ClientGatewayToken The client gateway token + * @return ClientGatewayToken | bool The client gateway token */ public function getGateway($amount) { @@ -373,31 +376,32 @@ class AutoBillInvoice extends AbstractService * * @param float $fee The fee amount. * @return AutoBillInvoice + * @deprecated / unused */ - private function addFeeToInvoice(float $fee) - { - //todo if we increase the invoice balance here, we will also need to adjust UP the client balance and ledger? - $starting_amount = $this->invoice->amount; + // private function addFeeToInvoice(float $fee) + // { + // //todo if we increase the invoice balance here, we will also need to adjust UP the client balance and ledger? + // $starting_amount = $this->invoice->amount; - $item = new InvoiceItem; - $item->quantity = 1; - $item->cost = $fee; - $item->notes = ctrans('texts.online_payment_surcharge'); - $item->type_id = 3; + // $item = new InvoiceItem; + // $item->quantity = 1; + // $item->cost = $fee; + // $item->notes = ctrans('texts.online_payment_surcharge'); + // $item->type_id = 3; - $items = (array) $this->invoice->line_items; - $items[] = $item; + // $items = (array) $this->invoice->line_items; + // $items[] = $item; - $this->invoice->line_items = $items; - $this->invoice->saveQuietly(); + // $this->invoice->line_items = $items; + // $this->invoice->saveQuietly(); - $this->invoice = $this->invoice->calc()->getInvoice()->saveQuietly(); + // $this->invoice = $this->invoice->calc()->getInvoice()->saveQuietly(); - if ($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT) { - $this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save(); - $this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, "Invoice {$this->invoice->number} balance updated after stale gateway fee removed")->save(); - } + // if ($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT) { + // $this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save(); + // $this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, "Invoice {$this->invoice->number} balance updated after stale gateway fee removed")->save(); + // } - return $this; - } + // return $this; + // } } diff --git a/app/Services/Invoice/EInvoice/FacturaEInvoice.php b/app/Services/Invoice/EInvoice/FacturaEInvoice.php index 7505956c74abd..b2255bc9959da 100644 --- a/app/Services/Invoice/EInvoice/FacturaEInvoice.php +++ b/app/Services/Invoice/EInvoice/FacturaEInvoice.php @@ -146,7 +146,7 @@ class FacturaEInvoice extends AbstractService private function setPoNumber(): self { - if(strlen($this->invoice->po_number > 1)) { + if(strlen($this->invoice->po_number) > 1) { $this->fac->setReferences($this->invoice->po_number); } diff --git a/app/Services/Invoice/HandleReversal.php b/app/Services/Invoice/HandleReversal.php index 8000ecf4caeec..008fd44534af7 100644 --- a/app/Services/Invoice/HandleReversal.php +++ b/app/Services/Invoice/HandleReversal.php @@ -12,16 +12,9 @@ namespace App\Services\Invoice; use App\Events\Invoice\InvoiceWasReversed; -use App\Factory\CreditFactory; -use App\Factory\InvoiceItemFactory; -use App\Helpers\Invoice\InvoiceSum; -use App\Jobs\Ninja\TransactionLog; -use App\Models\Client; -use App\Models\Credit; use App\Models\Invoice; use App\Models\Payment; use App\Models\Paymentable; -use App\Models\TransactionEvent; use App\Services\AbstractService; use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; @@ -74,48 +67,6 @@ class HandleReversal extends AbstractService /* Generate a credit for the $total_paid amount */ $notes = 'Credit for reversal of '.$this->invoice->number; - $credit = false; - - // if ($total_paid > 0) { - - // $credit = CreditFactory::create($this->invoice->company_id, $this->invoice->user_id); - // $credit->client_id = $this->invoice->client_id; - // $credit->invoice_id = $this->invoice->id; - // $credit->date = now(); - - // $item = InvoiceItemFactory::create(); - // $item->quantity = 1; - // $item->cost = (float) $total_paid; - // $item->notes = $notes; - - // $line_items[] = $item; - // $credit->line_items = $line_items; - // $credit->save(); - - // $credit_calc = new InvoiceSum($credit); - // $credit_calc->build(); - - // $credit = $credit_calc->purgeTaxes()->getCredit(); - // $credit->service()->markSent()->save(); - // } - - /*If there is a payment linked, then the credit needs to be linked back to that payment in case of refund*/ - if ($paymentables->count() > 0 && $credit) { - // $payment = $paymentables->first()->payment; - // $payment->credits()->save($credit); - - // $paymentable_credit = $payment->credits() - // ->wherePaymentableType(Credit::class) - // ->wherePaymentableId($credit->id) - // ->first(); - - // //harvest the credit record and add in the amount for the credit. - // $paymentable_credit->pivot->amount = $total_paid; - // $paymentable_credit->pivot->save(); - - // $paymentable_credit->paid_to_date += $total_paid; - // $paymentable_credit->save(); - } /* Set invoice balance to 0 */ if ($this->invoice->balance != 0) { @@ -133,22 +84,11 @@ class HandleReversal extends AbstractService $this->invoice->client->service() ->updateBalance($balance_remaining * -1) - // ->updatePaidToDate($total_paid * -1) ->save(); event(new InvoiceWasReversed($this->invoice, $this->invoice->company, Ninja::eventVars())); - $transaction = [ - 'invoice' => $this->invoice->transaction_event(), - 'payment' => [], - 'client' => $this->invoice->client->transaction_event(), - 'credit' => [], - 'metadata' => [], - ]; - - // TransactionLog::dispatch(TransactionEvent::INVOICE_REVERSED, $transaction, $this->invoice->company->db); - return $this->invoice; - //create a ledger row for this with the resulting Credit ( also include an explanation in the notes section ) + } } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 7b750f46cdabf..2ea0f677f79f7 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -396,7 +396,7 @@ class InvoiceService })->toArray(); $this->invoice = $this->invoice->calc()->getInvoice(); - $this->invoice->service()->touchPdf(); + $this->touchPdf(); /* 24-03-2022 */ $new_balance = $this->invoice->balance; @@ -541,7 +541,7 @@ class InvoiceService $settings = $this->invoice->client->getMergedSettings(); if (! $this->invoice->design_id) { - $this->invoice->design_id = $this->decodePrimaryKey($settings->invoice_design_id); + $this->invoice->design_id = intval($this->decodePrimaryKey($settings->invoice_design_id)); } if (! isset($this->invoice->footer) || empty($this->invoice->footer)) { diff --git a/app/Services/Invoice/UpdateBalance.php b/app/Services/Invoice/UpdateBalance.php index 9b9faef66efe3..a998dc955fd36 100644 --- a/app/Services/Invoice/UpdateBalance.php +++ b/app/Services/Invoice/UpdateBalance.php @@ -16,17 +16,9 @@ use App\Services\AbstractService; class UpdateBalance extends AbstractService { - public $invoice; - public $balance_adjustment; - - private $is_draft; - - public function __construct($invoice, $balance_adjustment, bool $is_draft) + public function __construct(public Invoice $invoice, public float $balance_adjustment, public bool $is_draft) { - $this->invoice = $invoice; - $this->balance_adjustment = $balance_adjustment; - $this->is_draft = $is_draft; } public function run() @@ -35,20 +27,12 @@ class UpdateBalance extends AbstractService return $this->invoice; } - nlog("invoice id = {$this->invoice->id}"); - nlog("invoice balance = {$this->invoice->balance}"); - nlog("invoice adjustment = {$this->balance_adjustment}"); - - // $this->invoice->balance += floatval($this->balance_adjustment); - $this->invoice->increment('balance', floatval($this->balance_adjustment)); if ($this->invoice->balance == 0 && ! $this->is_draft) { $this->invoice->status_id = Invoice::STATUS_PAID; } - nlog("final balance = {$this->invoice->balance}"); - return $this->invoice; } } diff --git a/app/Services/Invoice/UpdateReminder.php b/app/Services/Invoice/UpdateReminder.php index 6109eb54c400a..cba87bacdf841 100644 --- a/app/Services/Invoice/UpdateReminder.php +++ b/app/Services/Invoice/UpdateReminder.php @@ -160,19 +160,6 @@ class UpdateReminder extends AbstractService return $this->invoice; } - private function testReminderValid($reminder_number, $reminder_schedule) :bool - { - $reminder_sent = "reminder{$reminder_number}_sent"; - $schedule_reminder = "schedule_reminder{$reminder_number}"; - $enable_reminder = "enable_reminder{$reminder_number}"; - $late_fee_amount = "late_fee_amount{$reminder_number}"; - $late_fee_percent = "late_fee_percent{$reminder_number}"; - - return is_null($this->invoice->{$reminder_sent}) && - $this->settings->{$schedule_reminder} == $reminder_schedule && - ($this->settings->{$enable_reminder} || $late_fee_percent > 0 || $late_fee_amount > 0); - } - private function addTimeInterval($date, $endless_reminder_frequency_id) :?Carbon { if (! $date) { diff --git a/app/Services/Pdf/PdfMock.php b/app/Services/Pdf/PdfMock.php index 6e5ba641c12d3..24c687be1e678 100644 --- a/app/Services/Pdf/PdfMock.php +++ b/app/Services/Pdf/PdfMock.php @@ -383,7 +383,7 @@ class PdfMock '$product.tax' => '', '$valid_until' => '', '$your_entity' => '', - '$shipping' => '', + '$shipping' => ctrans('texts.shipping_address'), '$balance_due' => '$0.00', '$outstanding' => '$0.00', '$partial_due' => '$0.00', @@ -739,7 +739,7 @@ class PdfMock '$font_name_label' => '', '$auto_bill_label' => ctrans('texts.auto_bill'), '$payments_label' => ctrans('texts.payments'), - '$shipping_label' => '', + '$shipping_label' => ctrans('texts.shipping_address'), '$task.tax_label' => ctrans('texts.tax'), '$viewLink_label' => ctrans('texts.link'), '$company1_label' => ctrans('texts.company1'), diff --git a/app/Services/Recurring/RecurringService.php b/app/Services/Recurring/RecurringService.php index e9c81b870dc15..c962b5f45f45c 100644 --- a/app/Services/Recurring/RecurringService.php +++ b/app/Services/Recurring/RecurringService.php @@ -11,15 +11,16 @@ namespace App\Services\Recurring; -use App\Jobs\RecurringInvoice\SendRecurring; use App\Jobs\Util\UnlinkFile; +use App\Models\RecurringQuote; +use Illuminate\Support\Carbon; use App\Models\RecurringExpense; use App\Models\RecurringInvoice; -use Illuminate\Support\Carbon; +use App\Jobs\RecurringInvoice\SendRecurring; class RecurringService { - public function __construct(public RecurringInvoice | RecurringExpense $recurring_entity) + public function __construct(public RecurringInvoice | RecurringExpense | RecurringQuote $recurring_entity) { } diff --git a/app/Utils/Number.php b/app/Utils/Number.php index d53e335f98abc..2c6fdf0e7ea71 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -129,7 +129,7 @@ class Number /** * Formats a given value based on the clients currency AND country. * - * @param floatval $value The number to be formatted + * @param $value The number to be formatted * @param $entity * @return string The formatted value */ diff --git a/lang/ar/texts.php b/lang/ar/texts.php index 4645b679d78cf..09b6943947d05 100644 --- a/lang/ar/texts.php +++ b/lang/ar/texts.php @@ -5010,11 +5010,6 @@ $LANG = array( 'notification_payment_emailed' => 'الدفع: تم إرسال الدفع بالبريد الإلكتروني إلى: العميل', 'notification_payment_emailed_subject' => 'الدفع: الدفع بالبريد الإلكتروني', 'record_not_found' => 'لم يتم العثور على السجل', - 'product_tax_exempt' => 'معفى من ضريبة المنتج', - 'product_type_physical' => 'البضائع المادية', - 'product_type_digital' => 'السلع الرقمية', - 'product_type_service' => 'خدمات', - 'product_type_freight' => 'شحن', 'minimum_payment_amount' => 'الحد الأدنى لمبلغ السداد', 'client_initiated_payments' => 'مدفوعات يبدأها العميل', 'client_initiated_payments_help' => 'دعم إجراء الدفع في بوابة العميل بدون فاتورة', @@ -5083,6 +5078,14 @@ $LANG = array( 'here' => 'هنا', 'industry_Restaurant & Catering' => 'Restaurant & Catering', 'show_credits_table' => 'Show Credits Table', + 'manual_payment' => 'Payment Manual', + 'tax_summary_report' => 'Tax Summary Report', + 'tax_category' => 'Tax Category', + 'physical_goods' => 'Physical Goods', + 'digital_products' => 'Digital Products', + 'services' => 'Services', + 'shipping' => 'Shipping', + 'tax_exempt' => 'Tax Exempt', ); diff --git a/lang/de/texts.php b/lang/de/texts.php index f5f126c0d0e0a..8c236504dea38 100644 --- a/lang/de/texts.php +++ b/lang/de/texts.php @@ -4991,11 +4991,6 @@ https://invoiceninja.github.io/docs/migration/#troubleshooting', 'notification_payment_emailed' => 'Zahlung :payment wurde per E-Mail an den Kunden gesendet', 'notification_payment_emailed_subject' => 'Zahlung :payment wurde per E-Mail gesendet', 'record_not_found' => 'Aufnahme nicht gefunden', - 'product_tax_exempt' => 'Produktsteuerbefreit', - 'product_type_physical' => 'Physische Güter', - 'product_type_digital' => 'Digitale Güter', - 'product_type_service' => 'Dienstleistungen', - 'product_type_freight' => 'Versand', 'minimum_payment_amount' => 'Mindestzahlungsbetrag', 'client_initiated_payments' => 'Vom Kunden initiierte Zahlungen', 'client_initiated_payments_help' => 'Unterstützung bei der Durchführung einer Zahlung im Kundenportal ohne Rechnung', @@ -5064,6 +5059,14 @@ https://invoiceninja.github.io/docs/migration/#troubleshooting', 'here' => 'Hier', 'industry_Restaurant & Catering' => 'Restaurant & Catering', 'show_credits_table' => 'Show Credits Table', + 'manual_payment' => 'Payment Manual', + 'tax_summary_report' => 'Tax Summary Report', + 'tax_category' => 'Tax Category', + 'physical_goods' => 'Physical Goods', + 'digital_products' => 'Digital Products', + 'services' => 'Services', + 'shipping' => 'Shipping', + 'tax_exempt' => 'Tax Exempt', ); diff --git a/lang/en/texts.php b/lang/en/texts.php index 3180ee628cb3b..2589724e3a11f 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -4981,7 +4981,7 @@ $LANG = array( 'payment_type_Interac E Transfer' => 'Interac E Transfer', 'xinvoice_payable' => 'Payable within :payeddue days net until :paydate', 'xinvoice_no_buyers_reference' => "No buyer's reference given", - 'xinvoice_online_payment' => 'The invoice needs to be payed online via the provided link', + 'xinvoice_online_payment' => 'The invoice needs to be paid online via the provided link', 'pre_payment' => 'Pre Payment', 'number_of_payments' => 'Number of payments', 'number_of_payments_helper' => 'The number of times this payment will be made', @@ -5065,6 +5065,8 @@ $LANG = array( 'services' => 'Services', 'shipping' => 'Shipping', 'tax_exempt' => 'Tax Exempt', + 'late_fee_added_locked_invoice' => 'Late fee for invoice :invoice added on :date', + ); diff --git a/lang/es/texts.php b/lang/es/texts.php index 23cac13ee3cea..e4b63f7541a8d 100644 --- a/lang/es/texts.php +++ b/lang/es/texts.php @@ -4987,11 +4987,6 @@ $LANG = array( 'notification_payment_emailed' => 'El pago :payment se envió por correo electrónico a :client', 'notification_payment_emailed_subject' => 'El pago :payment fue enviado por correo electrónico', 'record_not_found' => 'Registro no encontrado', - 'product_tax_exempt' => 'Producto exento de impuestos', - 'product_type_physical' => 'Bienes físicos', - 'product_type_digital' => 'Bienes digitales', - 'product_type_service' => 'Servicios', - 'product_type_freight' => 'Envío', 'minimum_payment_amount' => 'Monto mínimo de pago', 'client_initiated_payments' => 'Pagos iniciados por el cliente', 'client_initiated_payments_help' => 'Soporte para realizar un pago en el portal del cliente sin factura', @@ -5060,6 +5055,14 @@ $LANG = array( 'here' => 'aquí', 'industry_Restaurant & Catering' => 'Restaurant & Catering', 'show_credits_table' => 'Show Credits Table', + 'manual_payment' => 'Payment Manual', + 'tax_summary_report' => 'Tax Summary Report', + 'tax_category' => 'Tax Category', + 'physical_goods' => 'Physical Goods', + 'digital_products' => 'Digital Products', + 'services' => 'Services', + 'shipping' => 'Shipping', + 'tax_exempt' => 'Tax Exempt', ); diff --git a/lang/es_ES/texts.php b/lang/es_ES/texts.php index 973161bd50f9d..5aa49b092e8c6 100644 --- a/lang/es_ES/texts.php +++ b/lang/es_ES/texts.php @@ -4979,11 +4979,6 @@ Una vez que tenga los montos, vuelva a esta página de métodos de pago y haga c 'notification_payment_emailed' => 'El pago :payment se envió por correo electrónico a :client', 'notification_payment_emailed_subject' => 'El pago :payment fue enviado por correo electrónico', 'record_not_found' => 'Registro no encontrado', - 'product_tax_exempt' => 'Producto exento de impuestos', - 'product_type_physical' => 'Bienes físicos', - 'product_type_digital' => 'Bienes digitales', - 'product_type_service' => 'Servicios', - 'product_type_freight' => 'Envío', 'minimum_payment_amount' => 'Importe mínimo de pago', 'client_initiated_payments' => 'Pagos iniciados por el cliente', 'client_initiated_payments_help' => 'Soporte para realizar un pago en el portal del cliente sin factura', diff --git a/lang/fr/texts.php b/lang/fr/texts.php index 90fd9149bcd33..bf190afc422c9 100644 --- a/lang/fr/texts.php +++ b/lang/fr/texts.php @@ -4983,11 +4983,6 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette 'notification_payment_emailed' => 'Paiement :payment a été envoyé par e-mail à :client', 'notification_payment_emailed_subject' => 'Paiement :payment a été envoyé par e-mail', 'record_not_found' => 'Enregistrement non trouvé', - 'product_tax_exempt' => 'Exemption de taxe sur les produits', - 'product_type_physical' => 'Biens physiques', - 'product_type_digital' => 'Biens numériques', - 'product_type_service' => 'Prestations de service', - 'product_type_freight' => 'Expédition', 'minimum_payment_amount' => 'Montant du paiement minimal', 'client_initiated_payments' => 'Paiements initiés par le client', 'client_initiated_payments_help' => 'Assistance pour effectuer un paiement dans le portail client sans facture', @@ -5056,6 +5051,14 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette 'here' => 'ici', 'industry_Restaurant & Catering' => 'Restaurant & Catering', 'show_credits_table' => 'Show Credits Table', + 'manual_payment' => 'Payment Manual', + 'tax_summary_report' => 'Tax Summary Report', + 'tax_category' => 'Tax Category', + 'physical_goods' => 'Physical Goods', + 'digital_products' => 'Digital Products', + 'services' => 'Services', + 'shipping' => 'Shipping', + 'tax_exempt' => 'Tax Exempt', ); diff --git a/lang/fr_CA/texts.php b/lang/fr_CA/texts.php index 63b0b416e4653..1478f597cc62f 100644 --- a/lang/fr_CA/texts.php +++ b/lang/fr_CA/texts.php @@ -4981,11 +4981,6 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette 'notification_payment_emailed' => 'Le paiement :payment a été envoyé par courriel à :client', 'notification_payment_emailed_subject' => 'Le paiement :payment a été envoyé par courriel', 'record_not_found' => 'Enregistrement introuvable', - 'product_tax_exempt' => 'Produit exempt de taxes', - 'product_type_physical' => 'Produits physiques', - 'product_type_digital' => 'Produits virtuels', - 'product_type_service' => 'Services', - 'product_type_freight' => 'Livraison', 'minimum_payment_amount' => 'Montant minimal de paiement', 'client_initiated_payments' => 'Paiements initiés par le client', 'client_initiated_payments_help' => 'Autorise le paiement sans facture dans le portail client', diff --git a/lang/fr_CH/texts.php b/lang/fr_CH/texts.php index a737c9520238d..3fbf2e6460058 100644 --- a/lang/fr_CH/texts.php +++ b/lang/fr_CH/texts.php @@ -4981,11 +4981,6 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette 'notification_payment_emailed' => 'Le paiement :payment à été envoyé à :client', 'notification_payment_emailed_subject' => 'Le paiement :payment a été envoyé', 'record_not_found' => 'Record not found', - 'product_tax_exempt' => 'Product Tax Exempt', - 'product_type_physical' => 'Physical Goods', - 'product_type_digital' => 'Digital Goods', - 'product_type_service' => 'Services', - 'product_type_freight' => 'Shipping', 'minimum_payment_amount' => 'Montant minimum de paiement', 'client_initiated_payments' => 'Paiements initiés par le client', 'client_initiated_payments_help' => 'Assistance pour effectuer un paiement dans le portail client sans facture', @@ -5054,6 +5049,14 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette 'here' => 'here', 'industry_Restaurant & Catering' => 'Restaurant & Catering', 'show_credits_table' => 'Show Credits Table', + 'manual_payment' => 'Payment Manual', + 'tax_summary_report' => 'Tax Summary Report', + 'tax_category' => 'Tax Category', + 'physical_goods' => 'Physical Goods', + 'digital_products' => 'Digital Products', + 'services' => 'Services', + 'shipping' => 'Shipping', + 'tax_exempt' => 'Tax Exempt', ); diff --git a/lang/it/texts.php b/lang/it/texts.php index 422d63c4f961b..de7d597d70368 100644 --- a/lang/it/texts.php +++ b/lang/it/texts.php @@ -4974,11 +4974,6 @@ $LANG = array( 'notification_payment_emailed' => 'Il pagamento :payment è stato inviato via email a :client', 'notification_payment_emailed_subject' => 'Il pagamento :payment è stato inviato via email', 'record_not_found' => 'Inserimento non trovato', - 'product_tax_exempt' => 'Prodotto esentasse', - 'product_type_physical' => 'Beni fisici', - 'product_type_digital' => 'Beni digitali', - 'product_type_service' => 'Servizi', - 'product_type_freight' => 'Spedizione', 'minimum_payment_amount' => 'Importo minimo di pagamento', 'client_initiated_payments' => 'Pagamenti avviati dal cliente', 'client_initiated_payments_help' => 'Supporto per effettuare un pagamento nel portale clienti senza fattura', @@ -5047,6 +5042,14 @@ $LANG = array( 'here' => 'Qui', 'industry_Restaurant & Catering' => 'Ristorante e ristorazione', 'show_credits_table' => 'Mostra la tabella dei crediti', + 'manual_payment' => 'Payment Manual', + 'tax_summary_report' => 'Tax Summary Report', + 'tax_category' => 'Tax Category', + 'physical_goods' => 'Physical Goods', + 'digital_products' => 'Digital Products', + 'services' => 'Services', + 'shipping' => 'Shipping', + 'tax_exempt' => 'Tax Exempt', ); diff --git a/lang/lt/texts.php b/lang/lt/texts.php index aa59ec79c9925..126f9b229a096 100644 --- a/lang/lt/texts.php +++ b/lang/lt/texts.php @@ -4389,7 +4389,7 @@ $LANG = array( 'imported_customers' => 'Successfully started importing customers', 'login_success' => 'Successful Login', 'login_failure' => 'Failed Login', - 'exported_data' => 'Once the file is ready you"ll receive an email with a download link', + 'exported_data' => 'Once the file is ready you\'ll receive an email with a download link', 'include_deleted_clients' => 'Include Deleted Clients', 'include_deleted_clients_help' => 'Load records belonging to deleted clients', 'step_1_sign_in' => 'Step 1: Sign In', @@ -4478,7 +4478,7 @@ $LANG = array( 'activity_123' => ':user deleted recurring expense :recurring_expense', 'activity_124' => ':user restored recurring expense :recurring_expense', 'fpx' => "FPX", - 'to_view_entity_set_password' => 'To view the :entity you need to set password.', + 'to_view_entity_set_password' => 'To view the :entity you need to set a password.', 'unsubscribe' => 'Unsubscribe', 'unsubscribed' => 'Unsubscribed', 'unsubscribed_text' => 'You have been removed from notifications for this document', @@ -4576,7 +4576,7 @@ $LANG = array( 'purchase_order_number' => 'Purchase Order Number', 'purchase_order_number_short' => 'Purchase Order #', 'inventory_notification_subject' => 'Inventory threshold notification for product: :product', - 'inventory_notification_body' => 'Threshold of :amount has been reach for product: :product', + 'inventory_notification_body' => 'Threshold of :amount has been reached for product: :product', 'activity_130' => ':user created purchase order :purchase_order', 'activity_131' => ':user updated purchase order :purchase_order', 'activity_132' => ':user archived purchase order :purchase_order', @@ -4608,7 +4608,7 @@ $LANG = array( 'vendor_document_upload' => 'Vendor Document Upload', 'vendor_document_upload_help' => 'Enable vendors to upload documents', 'are_you_enjoying_the_app' => 'Are you enjoying the app?', - 'yes_its_great' => 'Yes, it"s great!', + 'yes_its_great' => 'Yes, it\'s great!', 'not_so_much' => 'Not so much', 'would_you_rate_it' => 'Great to hear! Would you like to rate it?', 'would_you_tell_us_more' => 'Sorry to hear it! Would you like to tell us more?', @@ -4989,11 +4989,6 @@ $LANG = array( 'notification_payment_emailed' => 'Mokėjimas :payment buvo išsiųstas el. paštu klientui :client', 'notification_payment_emailed_subject' => 'Mokėjimas :payment buvo išsiųstas el. paštu', 'record_not_found' => 'Įrašas nerastas', - 'product_tax_exempt' => 'Product Tax Exempt', - 'product_type_physical' => 'Fizinės prekės', - 'product_type_digital' => 'Skaitmeninės prekės', - 'product_type_service' => 'Paslaugos', - 'product_type_freight' => 'Shipping', 'minimum_payment_amount' => 'Minimali mokėjimo suma', 'client_initiated_payments' => 'Client Initiated Payments', 'client_initiated_payments_help' => 'Support making a payment in the client portal without an invoice', @@ -5046,6 +5041,30 @@ $LANG = array( 'oauth_mail' => 'OAuth / Mail', 'preferences' => 'Preferences', 'analytics' => 'Analytics', + 'reduced_rate' => 'Reduced Rate', + 'tax_all' => 'Tax All', + 'tax_selected' => 'Tax Selected', + 'version' => 'version', + 'seller_subregion' => 'Seller Subregion', + 'calculate_taxes' => 'Calculate Taxes', + 'calculate_taxes_help' => 'Automatically calculate taxes when saving invoices', + 'link_expenses' => 'Link Expenses', + 'converted_client_balance' => 'Converted Client Balance', + 'converted_payment_balance' => 'Converted Payment Balance', + 'total_hours' => 'Total Hours', + 'date_picker_hint' => 'Use +days to set the date in the future', + 'app_help_link' => 'More information ', + 'here' => 'here', + 'industry_Restaurant & Catering' => 'Restaurant & Catering', + 'show_credits_table' => 'Show Credits Table', + 'manual_payment' => 'Payment Manual', + 'tax_summary_report' => 'Tax Summary Report', + 'tax_category' => 'Tax Category', + 'physical_goods' => 'Physical Goods', + 'digital_products' => 'Digital Products', + 'services' => 'Services', + 'shipping' => 'Shipping', + 'tax_exempt' => 'Tax Exempt', ); diff --git a/lang/nl/texts.php b/lang/nl/texts.php index 15ff8a8197138..afadc1e677dc1 100644 --- a/lang/nl/texts.php +++ b/lang/nl/texts.php @@ -4383,7 +4383,7 @@ Email: :email
', 'imported_customers' => 'Succesvol begonnen met het importeren van klanten', 'login_success' => 'Login succesvol', 'login_failure' => 'Inloggen mislukt', - 'exported_data' => 'Once the file is ready you\'ll receive an email with a download link', + 'exported_data' => 'Zodra het bestand klaar is, ontvang je een e-mail met een downloadlink', 'include_deleted_clients' => 'Inclusief verwijderde klanten', 'include_deleted_clients_help' => 'Laad records van verwijderde clients', 'step_1_sign_in' => 'Stap 1: Inloggen', @@ -4472,7 +4472,7 @@ Email: :email
', 'activity_123' => ':user heeft terugkerende uitgave :recurring_expense verwijderd', 'activity_124' => ':user heeft terugkerende uitgave :recurring_expense teruggezet', 'fpx' => "FPX", - 'to_view_entity_set_password' => 'To view the :entity you need to set a password.', + 'to_view_entity_set_password' => 'Om de :entity te bekijken, moet u een wachtwoord instellen.', 'unsubscribe' => 'Afmelden', 'unsubscribed' => 'Afgemeld', 'unsubscribed_text' => 'Je bent verwijderd uit meldingen voor dit document', @@ -4570,7 +4570,7 @@ Email: :email
', 'purchase_order_number' => 'Aankoop ordernummer', 'purchase_order_number_short' => 'Aankoop order #', 'inventory_notification_subject' => 'Melding van voorraaddrempel voor product: :product', - 'inventory_notification_body' => 'Threshold of :amount has been reached for product: :product', + 'inventory_notification_body' => 'Drempel van :amount is bereikt voor product: :product', 'activity_130' => ':user heeft aankooporder :purchase_order aangemaakt', 'activity_131' => ':user heeft aankooporder :purchase_order aangepast', 'activity_132' => ':user heeft aankooporder :purchase_order gearchiveerd', @@ -4602,7 +4602,7 @@ Email: :email
', 'vendor_document_upload' => 'Uploaden verkoperdocument', 'vendor_document_upload_help' => 'Leveranciers in staat stellen documenten te uploaden', 'are_you_enjoying_the_app' => 'Geniet je van de app?', - 'yes_its_great' => 'Yes, it\'s great!', + 'yes_its_great' => 'Ja, het is geweldig!', 'not_so_much' => 'Niet zo veel', 'would_you_rate_it' => 'Goed om te horen! Zou je het willen beoordelen?', 'would_you_tell_us_more' => 'Dat is jammer om te horen! Wil je ons meer vertellen?', @@ -4983,11 +4983,6 @@ Email: :email
', 'notification_payment_emailed' => 'Betaling :payment is gemaild naar :client', 'notification_payment_emailed_subject' => 'Betaling :payment is per e-mail verzonden', 'record_not_found' => 'document niet gevonden', - 'product_tax_exempt' => 'Vrijgesteld van productbelasting', - 'product_type_physical' => 'Fysieke goederen', - 'product_type_digital' => 'Digitale Goederen', - 'product_type_service' => 'Diensten', - 'product_type_freight' => 'Verzenden', 'minimum_payment_amount' => 'Minimum betalingsbedrag', 'client_initiated_payments' => 'Door de klant geïnitieerde betalingen', 'client_initiated_payments_help' => 'Ondersteuning bij het uitvoeren van een betaling in het klantenportaal zonder factuur', @@ -5054,8 +5049,16 @@ Email: :email
', 'date_picker_hint' => 'Gebruik +days om de datum in de toekomst te zetten', 'app_help_link' => 'Meer informatie', 'here' => 'hier', - 'industry_Restaurant & Catering' => 'Restaurant & Catering', - 'show_credits_table' => 'Show Credits Table', + 'industry_Restaurant & Catering' => 'Restaurant & Horeca', + 'show_credits_table' => 'Credittabel tonen', + 'manual_payment' => 'Betalingshandleiding', + 'tax_summary_report' => 'Fiscaal overzichtsrapport', + 'tax_category' => 'Belastingcategorie', + 'physical_goods' => 'Fysieke goederen', + 'digital_products' => 'Digitale producten', + 'services' => 'Diensten', + 'shipping' => 'Verzenden', + 'tax_exempt' => 'Vrijgesteld van belasting', ); diff --git a/lang/pl/texts.php b/lang/pl/texts.php index 179936a946f7d..b51337694d5d8 100644 --- a/lang/pl/texts.php +++ b/lang/pl/texts.php @@ -4986,11 +4986,6 @@ Gdy przelewy zostaną zaksięgowane na Twoim koncie, wróć do tej strony i klik 'notification_payment_emailed' => 'Płatność :payment została wysłana e-mailem do :client', 'notification_payment_emailed_subject' => 'Płatność :payment została wysłana e-mailem', 'record_not_found' => 'Rekord nie znaleziony', - 'product_tax_exempt' => 'Produkt zwolniony z podatku', - 'product_type_physical' => 'Towary materialne', - 'product_type_digital' => 'Towary cyfrowe', - 'product_type_service' => 'Usługi', - 'product_type_freight' => 'Shipping', 'minimum_payment_amount' => 'Minimalna kwota płatności', 'client_initiated_payments' => 'Płatności zainicjowane przez Klienta', 'client_initiated_payments_help' => 'Support making a payment in the client portal without an invoice', @@ -5059,6 +5054,14 @@ Gdy przelewy zostaną zaksięgowane na Twoim koncie, wróć do tej strony i klik 'here' => 'here', 'industry_Restaurant & Catering' => 'Restaurant & Catering', 'show_credits_table' => 'Show Credits Table', + 'manual_payment' => 'Payment Manual', + 'tax_summary_report' => 'Tax Summary Report', + 'tax_category' => 'Tax Category', + 'physical_goods' => 'Physical Goods', + 'digital_products' => 'Digital Products', + 'services' => 'Services', + 'shipping' => 'Shipping', + 'tax_exempt' => 'Tax Exempt', ); diff --git a/lang/pt_PT/texts.php b/lang/pt_PT/texts.php index 5e2ea451fa070..2a15011d2f2d4 100644 --- a/lang/pt_PT/texts.php +++ b/lang/pt_PT/texts.php @@ -4986,11 +4986,6 @@ O envio de E-mails foi suspenso. Será retomado às 23:00 UTC.', 'notification_payment_emailed' => 'O pagamento :payment foi enviado por e-mail para :client', 'notification_payment_emailed_subject' => 'O pagamento :payment foi enviado por e-mail', 'record_not_found' => 'Registro não encontrado', - 'product_tax_exempt' => 'Produto isento de impostos', - 'product_type_physical' => 'Bens físicos', - 'product_type_digital' => 'Bens digitais', - 'product_type_service' => 'Serviços', - 'product_type_freight' => 'Envio', 'minimum_payment_amount' => 'Valor Mínimo de Pagamento', 'client_initiated_payments' => 'Pagamentos iniciados pelo cliente', 'client_initiated_payments_help' => 'Suporte para efetuar um pagamento no portal do cliente sem fatura', @@ -5059,6 +5054,14 @@ O envio de E-mails foi suspenso. Será retomado às 23:00 UTC.', 'here' => 'aqui', 'industry_Restaurant & Catering' => 'Restaurante e Catering', 'show_credits_table' => 'Mostrar tabela de créditos', + 'manual_payment' => 'Payment Manual', + 'tax_summary_report' => 'Tax Summary Report', + 'tax_category' => 'Tax Category', + 'physical_goods' => 'Physical Goods', + 'digital_products' => 'Digital Products', + 'services' => 'Services', + 'shipping' => 'Shipping', + 'tax_exempt' => 'Tax Exempt', ); diff --git a/lang/sk/texts.php b/lang/sk/texts.php index 11ddd1283f455..fcc7ec8a22b78 100644 --- a/lang/sk/texts.php +++ b/lang/sk/texts.php @@ -4972,11 +4972,6 @@ Nemôžete nájsť faktúru? Potrebujete poradiť? Radi Vám pomôžeme 'notification_payment_emailed' => 'Platba :payment bola odoslaná e-mailom na adresu :client', 'notification_payment_emailed_subject' => 'Platba :payment bola odoslaná e-mailom', 'record_not_found' => 'Záznam sa nenašiel', - 'product_tax_exempt' => 'Oslobodenie od dane z produktov', - 'product_type_physical' => 'Fyzický tovar', - 'product_type_digital' => 'Digitálny tovar', - 'product_type_service' => 'Služby', - 'product_type_freight' => 'Doprava', 'minimum_payment_amount' => 'Minimálna výška platby', 'client_initiated_payments' => 'Platby iniciované klientom', 'client_initiated_payments_help' => 'Podpora uskutočňovania platby na klientskom portáli bez faktúry', @@ -5045,6 +5040,14 @@ Nemôžete nájsť faktúru? Potrebujete poradiť? Radi Vám pomôžeme 'here' => 'tu', 'industry_Restaurant & Catering' => 'Reštaurácia & Catering', 'show_credits_table' => 'Zobraziť tabuľku kreditov', + 'manual_payment' => 'Payment Manual', + 'tax_summary_report' => 'Tax Summary Report', + 'tax_category' => 'Tax Category', + 'physical_goods' => 'Physical Goods', + 'digital_products' => 'Digital Products', + 'services' => 'Services', + 'shipping' => 'Shipping', + 'tax_exempt' => 'Tax Exempt', ); diff --git a/phpstan.neon b/phpstan.neon index 5a42eb355d68f..c6be40ce7139d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,6 +4,7 @@ includes: parameters: ignoreErrors: - '#Call to an undefined method .*badMethod\(\)#' + - 'Call to an undefined method Illuminate\Database\Eloquent\Builder::exclude(). level: 2 paths: - app diff --git a/tests/Feature/DesignApiTest.php b/tests/Feature/DesignApiTest.php index dec0cc00bed7a..1fa8bb9c2c1e3 100644 --- a/tests/Feature/DesignApiTest.php +++ b/tests/Feature/DesignApiTest.php @@ -11,13 +11,18 @@ namespace Tests\Feature; -use App\Models\Design; -use App\Utils\Traits\MakesHash; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Support\Facades\Session; -use Tests\MockAccountData; use Tests\TestCase; +use App\Models\Design; +use Tests\MockAccountData; +use App\Utils\Traits\MakesHash; +use App\Events\Design\DesignWasCreated; +use App\Events\Design\DesignWasDeleted; +use App\Events\Design\DesignWasUpdated; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Session; +use App\Events\Design\DesignWasArchived; +use App\Events\Design\DesignWasRestored; +use Illuminate\Foundation\Testing\DatabaseTransactions; /** * @test @@ -46,6 +51,7 @@ class DesignApiTest extends TestCase public function testDesignPost() { + $design = [ 'body' => 'body', 'includes' => 'includes', @@ -127,6 +133,7 @@ class DesignApiTest extends TestCase public function testDesignArchive() { + $design = [ 'body' => 'body', 'includes' => 'includes', diff --git a/tests/Feature/RecurringQuoteTest.php b/tests/Feature/RecurringQuoteTest.php index d795b5cf035a8..eabcd39741ba6 100644 --- a/tests/Feature/RecurringQuoteTest.php +++ b/tests/Feature/RecurringQuoteTest.php @@ -30,6 +30,8 @@ class RecurringQuoteTest extends TestCase use DatabaseTransactions; use MockAccountData; + public $faker; + protected function setUp() :void { parent::setUp(); diff --git a/tests/Unit/LateFeeTest.php b/tests/Unit/LateFeeTest.php index 66acfdbe742ad..b99bfac503985 100644 --- a/tests/Unit/LateFeeTest.php +++ b/tests/Unit/LateFeeTest.php @@ -11,11 +11,18 @@ namespace Tests\Unit; -use App\DataMapper\InvoiceItem; -use App\Models\Invoice; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Tests\MockAccountData; use Tests\TestCase; +use App\Models\User; +use App\Models\Client; +use App\Models\Account; +use App\Models\Company; +use App\Models\Invoice; +use Tests\MockAccountData; +use App\Jobs\Util\ReminderJob; +use App\DataMapper\InvoiceItem; +use App\DataMapper\FeesAndLimits; +use App\DataMapper\CompanySettings; +use Illuminate\Foundation\Testing\DatabaseTransactions; /** * @test @@ -25,13 +32,175 @@ class LateFeeTest extends TestCase use DatabaseTransactions; use MockAccountData; + public $faker; + + public $account; + + public $company; + + public $client; + protected function setUp() :void { parent::setUp(); + $this->faker = \Faker\Factory::create(); + + $this->withoutMiddleware( + ThrottleRequests::class + ); + $this->makeTestData(); + + $this->withoutExceptionHandling(); + } + private function buildData($settings) + { + $this->account = Account::factory()->create([ + 'hosted_client_count' => 1000, + 'hosted_company_count' => 1000, + ]); + + $this->account->num_users = 3; + $this->account->save(); + + $this->user = User::factory()->create([ + 'account_id' => $this->account->id, + 'confirmation_code' => 'xyz123', + 'email' => $this->faker->unique()->safeEmail(), + ]); + + $this->company = Company::factory()->create([ + 'account_id' => $this->account->id, + 'settings' => $settings, + ]); + + $this->company->settings = $settings; + $this->company->save(); + + $settings = new \stdClass; + $settings->currency_id = '1'; + + $client = Client::factory()->create([ + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'is_deleted' => 0, + 'settings' => $settings, + ]); + + return $client; + } + + public function testLateFeeAdded() + { + + $settings = CompanySettings::defaults(); + $settings->client_online_payment_notification = false; + $settings->client_manual_payment_notification = false; + $settings->late_fee_amount1 = 10; + $settings->late_fee_percent1 = 0; + $settings->lock_invoices = 'off'; + $settings->enable_reminder1 = true; + $settings->num_days_reminder1 = 10; + $settings->schedule_reminder1 = 'after_due_date'; + + $client = $this->buildData($settings); + + $i = Invoice::factory()->create([ + 'client_id' => $client->id, + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'amount' => 0, + 'balance' => 0, + 'status_id' => 2, + 'total_taxes' => 1, + 'date' => now()->format('Y-m-d'), + 'due_date' => now()->subDays(10)->format('Y-m-d'), + 'terms' => 'nada', + 'discount' => 0, + 'tax_rate1' => 0, + 'tax_rate2' => 0, + 'tax_rate3' => 0, + 'tax_name1' => '', + 'tax_name2' => '', + 'tax_name3' => '', + 'uses_inclusive_taxes' => false, + 'line_items' => $this->buildLineItems(), + ]); + + $i = $i->calc()->getInvoice(); + $i->service()->applyNumber()->createInvitations()->save(); + + $this->assertEquals(10, $i->amount); + $this->assertEquals(10, $i->balance); + + $reflectionMethod = new \ReflectionMethod(ReminderJob::class, 'sendReminderForInvoice'); + $reflectionMethod->setAccessible(true); + $reflectionMethod->invokeArgs(new ReminderJob(), [$i]); + + $i->fresh(); + + $this->assertEquals(20, $i->balance); + + } + + public function testLateFeeAddedToNewInvoiceWithLockedInvoiceConfig() + { + + $settings = CompanySettings::defaults(); + $settings->client_online_payment_notification = false; + $settings->client_manual_payment_notification = false; + $settings->late_fee_amount1 = 10; + $settings->late_fee_percent1 = 0; + $settings->lock_invoices = 'when_sent'; + $settings->enable_reminder1 = true; + $settings->num_days_reminder1 = 10; + $settings->schedule_reminder1 = 'after_due_date'; + + $client = $this->buildData($settings); + + $i = Invoice::factory()->create([ + 'client_id' => $client->id, + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'amount' => 0, + 'balance' => 0, + 'status_id' => Invoice::STATUS_DRAFT, + 'total_taxes' => 1, + 'date' => now()->format('Y-m-d'), + 'due_date' => now()->subDays(10)->format('Y-m-d'), + 'terms' => 'nada', + 'discount' => 0, + 'tax_rate1' => 0, + 'tax_rate2' => 0, + 'tax_rate3' => 0, + 'tax_name1' => '', + 'tax_name2' => '', + 'tax_name3' => '', + 'uses_inclusive_taxes' => false, + 'line_items' => $this->buildLineItems(), + ]); + + $i = $i->calc()->getInvoice(); + $i->service()->applyNumber()->createInvitations()->markSent()->save(); + + $this->assertEquals(10, $i->amount); + $this->assertEquals(10, $i->balance); + $this->assertEquals(10, $client->fresh()->balance); + + $reflectionMethod = new \ReflectionMethod(ReminderJob::class, 'sendReminderForInvoice'); + $reflectionMethod->setAccessible(true); + $reflectionMethod->invokeArgs(new ReminderJob(), [$i]); + + $i->fresh(); + + $this->assertEquals(10, $i->balance); + $this->assertEquals(20, $client->fresh()->balance); + } + + public function testLateFeeBalances() { $this->assertEquals(10, $this->client->balance);