diff --git a/app/BulkActions/Purchases/Bills.php b/app/BulkActions/Purchases/Bills.php index 18fc2c396..8d65a3277 100644 --- a/app/BulkActions/Purchases/Bills.php +++ b/app/BulkActions/Purchases/Bills.php @@ -31,7 +31,7 @@ class Bills extends BulkAction ], 'cancelled' => [ 'icon' => 'cancel', - 'name' => 'general.cancel', + 'name' => 'documents.actions.cancel', 'message' => 'bulk_actions.message.cancelled', 'permission' => 'update-purchases-bills', ], diff --git a/app/BulkActions/Sales/Invoices.php b/app/BulkActions/Sales/Invoices.php index 7f202dfdb..07e78051b 100644 --- a/app/BulkActions/Sales/Invoices.php +++ b/app/BulkActions/Sales/Invoices.php @@ -31,7 +31,7 @@ class Invoices extends BulkAction ], 'cancelled' => [ 'icon' => 'cancel', - 'name' => 'general.cancel', + 'name' => 'documents.actions.cancel', 'message' => 'bulk_actions.message.cancelled', 'permission' => 'update-sales-invoices', ], diff --git a/app/Events/Document/DocumentSending.php b/app/Events/Document/DocumentSending.php new file mode 100644 index 000000000..97db6503e --- /dev/null +++ b/app/Events/Document/DocumentSending.php @@ -0,0 +1,20 @@ +document = $document; + } +} diff --git a/app/Http/Controllers/Sales/Invoices.php b/app/Http/Controllers/Sales/Invoices.php index be3f68250..04502c8ea 100644 --- a/app/Http/Controllers/Sales/Invoices.php +++ b/app/Http/Controllers/Sales/Invoices.php @@ -10,6 +10,7 @@ use App\Imports\Sales\Invoices as Import; use App\Jobs\Document\CreateDocument; use App\Jobs\Document\DeleteDocument; use App\Jobs\Document\DuplicateDocument; +use App\Jobs\Document\SendDocument; use App\Jobs\Document\UpdateDocument; use App\Models\Document\Document; use App\Notifications\Sale\Invoice as Notification; @@ -260,12 +261,17 @@ class Invoices extends Controller return redirect()->back(); } - // Notify the customer - $invoice->contact->notify(new Notification($invoice, 'invoice_new_customer', true)); + $response = $this->ajaxDispatch(new SendDocument($invoice)); - event(new \App\Events\Document\DocumentSent($invoice)); + if ($response['success']) { + $message = trans('documents.messages.email_sent', ['type' => trans_choice('general.invoices', 1)]); - flash(trans('documents.messages.email_sent', ['type' => trans_choice('general.invoices', 1)]))->success(); + flash($message)->success(); + } else { + $message = $response['message']; + + flash($message)->error()->important(); + } return redirect()->back(); } diff --git a/app/Jobs/Document/SendDocument.php b/app/Jobs/Document/SendDocument.php new file mode 100644 index 000000000..62e271a68 --- /dev/null +++ b/app/Jobs/Document/SendDocument.php @@ -0,0 +1,26 @@ +document = $document; + } + + public function handle(): void + { + event(new DocumentSending($document)); + + // Notify the customer + $invoice->contact->notify(new Notification($invoice, 'invoice_new_customer', true)); + + event(new DocumentSent($document)); + } +} diff --git a/app/Jobs/Document/SendDocumentAsCustomMail.php b/app/Jobs/Document/SendDocumentAsCustomMail.php index cbc44d313..db8540437 100644 --- a/app/Jobs/Document/SendDocumentAsCustomMail.php +++ b/app/Jobs/Document/SendDocumentAsCustomMail.php @@ -3,6 +3,7 @@ namespace App\Jobs\Document; use App\Abstracts\Job; +use App\Events\Document\DocumentSending; use App\Events\Document\DocumentSent; use App\Models\Document\Document; @@ -18,6 +19,8 @@ class SendDocumentAsCustomMail extends Job { $document = Document::find($this->request->get('document_id')); + event(new DocumentSending($document)); + $custom_mail = $this->request->only(['to', 'subject', 'body']); if ($this->request->get('user_email', false)) { diff --git a/app/Listeners/Update/V30/Version3013.php b/app/Listeners/Update/V30/Version3013.php new file mode 100644 index 000000000..4bda06ab4 --- /dev/null +++ b/app/Listeners/Update/V30/Version3013.php @@ -0,0 +1,71 @@ +skipThisUpdate($event)) { + return; + } + + Log::channel('stdout')->info('Updating to 3.0.13 version...'); + + DB::transaction(function () { + $types = $this->getTypesByAllowedTranslations(); + + foreach ($types as $type => $translations) { + DB::table('categories')->whereIn('type', $translations)->update(['type' => $type]); + } + }); + + Log::channel('stdout')->info('Done!'); + } + + protected function getTypesByAllowedTranslations(): array + { + $types = $this->getCategoryTypes(false); + $lang_codes = array_keys(language()->allowed()); + + foreach ($types as $type => $trans_name) { + $translations_for_type = []; + + foreach ($lang_codes as $lang_code) { + $translation = trans_choice($trans_name, 1, locale: $lang_code); + + if ($translation === $trans_name) { + continue; + } + + $translations_for_type[] = $translation; + } + + $types[$type] = $translations_for_type; + } + + /** + * Example: en-GB es-ES + * 'income' => ['Income', 'Ingresos'] + */ + return $types; + } +} diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index 68b0e2ec1..4a0694ac8 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -614,7 +614,7 @@ class Document extends Model if (! in_array($this->status, ['cancelled', 'draft'])) { try { $actions[] = [ - 'title' => trans('general.cancel'), + 'title' => trans('documents.actions.cancel'), 'icon' => 'cancel', 'url' => route($prefix . '.cancelled', $this->id), 'permission' => 'update-' . $group . '-' . $permission_prefix, diff --git a/app/Providers/Event.php b/app/Providers/Event.php index 498fe7a85..9593392f5 100644 --- a/app/Providers/Event.php +++ b/app/Providers/Event.php @@ -21,6 +21,7 @@ class Event extends Provider 'App\Listeners\Update\V30\Version305', 'App\Listeners\Update\V30\Version307', 'App\Listeners\Update\V30\Version309', + 'App\Listeners\Update\V30\Version3013', ], 'Illuminate\Auth\Events\Login' => [ 'App\Listeners\Auth\Login', diff --git a/app/Traits/Categories.php b/app/Traits/Categories.php index 14789fdd8..c2ee8f5fb 100644 --- a/app/Traits/Categories.php +++ b/app/Traits/Categories.php @@ -7,7 +7,7 @@ use Illuminate\Support\Str; trait Categories { - public function getCategoryTypes(): array + public function getCategoryTypes(bool $translate = true): array { $types = []; $configs = config('type.category'); @@ -21,7 +21,7 @@ trait Categories $name = $attr['alias'] . '::' . $name; } - $types[$type] = trans_choice($name, 1); + $types[$type] = $translate ? trans_choice($name, 1) : $name; } return $types; diff --git a/config/api.php b/config/api.php index d374a644c..bbff4122c 100644 --- a/config/api.php +++ b/config/api.php @@ -156,20 +156,4 @@ return [ */ 'middleware' => explode(',', env('API_MIDDLEWARE', 'api')), - - /* - |-------------------------------------------------------------------------- - | Rate Limit (Throttle) - |-------------------------------------------------------------------------- - | - | Consumers of your API can be limited to the amount of requests they can - | make. You can create your own throttles or simply change the default - | throttles. - | - */ - - 'rate_limit' => [ - Limit::perMinute(env('API_RATE_LIMIT', 60)), - ], - ]; diff --git a/resources/lang/en-GB/documents.php b/resources/lang/en-GB/documents.php index bb4170856..aa68c1644 100644 --- a/resources/lang/en-GB/documents.php +++ b/resources/lang/en-GB/documents.php @@ -10,6 +10,10 @@ return [ 'billing' => 'Billing', 'advanced' => 'Advanced', + 'actions' => [ + 'cancel' => 'Cancel', + ], + 'invoice_detail' => [ 'marked' => 'You marked this invoice as', 'services' => 'Services', diff --git a/resources/views/components/documents/show/get-paid.blade.php b/resources/views/components/documents/show/get-paid.blade.php index 5f7d1f2f4..d08cd1254 100644 --- a/resources/views/components/documents/show/get-paid.blade.php +++ b/resources/views/components/documents/show/get-paid.blade.php @@ -61,54 +61,56 @@
- @if (! empty($transaction->contact) && $transaction->contact->email) - - - {{ trans('general.title.send', ['type' => trans_choice('general.receipts', 1)]) }} - - - @else - - +
+ @if (! empty($transaction->contact) && $transaction->contact->email) + {{ trans('general.title.send', ['type' => trans_choice('general.receipts', 1)]) }} - - @endif + @else + + + + {{ trans('general.title.send', ['type' => trans_choice('general.receipts', 1)]) }} + + + + @endif - - + - - - - {{ trans('general.title.edit', ['type' => trans_choice('general.payments', 1)]) }} - - + + + {{ trans('general.title.edit', ['type' => trans_choice('general.payments', 1)]) }} + + - - + - - @php - $message = trans('general.delete_confirm', [ - 'name' => '' . Date::parse($transaction->paid_at)->format(company_date_format()) . ' - ' . money($transaction->amount, $transaction->currency_code, true) . ' - ' . $transaction->account->name . '', - 'type' => strtolower(trans_choice('general.transactions', 1)) - ]); - @endphp + @php + $message = trans('general.delete_confirm', [ + 'name' => '' . Date::parse($transaction->paid_at)->format(company_date_format()) . ' - ' . money($transaction->amount, $transaction->currency_code, true) . ' - ' . $transaction->account->name . '', + 'type' => strtolower(trans_choice('general.transactions', 1)) + ]); + @endphp - + +
@endforeach @else diff --git a/resources/views/components/documents/show/make-payment.blade.php b/resources/views/components/documents/show/make-payment.blade.php index ed7a37304..c382bae9a 100644 --- a/resources/views/components/documents/show/make-payment.blade.php +++ b/resources/views/components/documents/show/make-payment.blade.php @@ -44,54 +44,56 @@
- @if (! empty($transaction->contact) && $transaction->contact->email) - - - {{ trans('general.title.send', ['type' => trans_choice('general.receipts', 1)]) }} - - - @else - - +
+ @if (! empty($transaction->contact) && $transaction->contact->email) + {{ trans('general.title.send', ['type' => trans_choice('general.receipts', 1)]) }} - - @endif + @else + + + + {{ trans('general.title.send', ['type' => trans_choice('general.receipts', 1)]) }} + + + + @endif - - + - - - - {{ trans('general.title.edit', ['type' => trans_choice('general.payments', 1)]) }} - - + + + {{ trans('general.title.edit', ['type' => trans_choice('general.payments', 1)]) }} + + - - + - - @php - $message = trans('general.delete_confirm', [ - 'name' => '' . Date::parse($transaction->paid_at)->format(company_date_format()) . ' - ' . money($transaction->amount, $transaction->currency_code, true) . ' - ' . $transaction->account->name . '', - 'type' => strtolower(trans_choice('general.transactions', 1)) - ]); - @endphp + @php + $message = trans('general.delete_confirm', [ + 'name' => '' . Date::parse($transaction->paid_at)->format(company_date_format()) . ' - ' . money($transaction->amount, $transaction->currency_code, true) . ' - ' . $transaction->account->name . '', + 'type' => strtolower(trans_choice('general.transactions', 1)) + ]); + @endphp - + +
@endforeach @else diff --git a/resources/views/components/documents/show/more-buttons.blade.php b/resources/views/components/documents/show/more-buttons.blade.php index d0cb0bcb5..3f6421010 100644 --- a/resources/views/components/documents/show/more-buttons.blade.php +++ b/resources/views/components/documents/show/more-buttons.blade.php @@ -113,7 +113,7 @@ - {{ trans('general.cancel') }} + {{ trans('documents.actions.cancel') }} @endcan @endif diff --git a/resources/views/modals/transactions/share.blade.php b/resources/views/modals/transactions/share.blade.php index 43195086a..29a818866 100644 --- a/resources/views/modals/transactions/share.blade.php +++ b/resources/views/modals/transactions/share.blade.php @@ -10,7 +10,7 @@ value="{{ $signedUrl }}" ref="clone" @click="onCopyLink()" - style="appearance: none; background-color: whitesmoke; border: none; font-size: 16px;" + style="appearance: none; background-color: whitesmoke; cursor:pointer; border: none; font-size: 16px;" />