diff --git a/app/Exports/Purchases/Bills/Sheets/Bills.php b/app/Exports/Purchases/Bills/Sheets/Bills.php index b20db5577..c8183db9b 100644 --- a/app/Exports/Purchases/Bills/Sheets/Bills.php +++ b/app/Exports/Purchases/Bills/Sheets/Bills.php @@ -40,6 +40,8 @@ class Bills extends Export implements WithColumnFormatting 'billed_at', 'due_at', 'amount', + 'discount_type', + 'discount_rate', 'currency_code', 'currency_rate', 'category_name', diff --git a/app/Exports/Purchases/RecurringBills/Sheets/RecurringBills.php b/app/Exports/Purchases/RecurringBills/Sheets/RecurringBills.php index fa23ff017..024e3a744 100644 --- a/app/Exports/Purchases/RecurringBills/Sheets/RecurringBills.php +++ b/app/Exports/Purchases/RecurringBills/Sheets/RecurringBills.php @@ -40,6 +40,8 @@ class RecurringBills extends Export implements WithColumnFormatting, WithParentS 'billed_at', 'due_at', 'amount', + 'discount_type', + 'discount_rate', 'currency_code', 'currency_rate', 'category_name', diff --git a/app/Exports/Sales/Invoices/Sheets/Invoices.php b/app/Exports/Sales/Invoices/Sheets/Invoices.php index 1f69dfe53..d82068c93 100644 --- a/app/Exports/Sales/Invoices/Sheets/Invoices.php +++ b/app/Exports/Sales/Invoices/Sheets/Invoices.php @@ -40,6 +40,8 @@ class Invoices extends Export implements WithColumnFormatting 'invoiced_at', 'due_at', 'amount', + 'discount_type', + 'discount_rate', 'currency_code', 'currency_rate', 'category_name', diff --git a/app/Exports/Sales/RecurringInvoices/Sheets/RecurringInvoices.php b/app/Exports/Sales/RecurringInvoices/Sheets/RecurringInvoices.php index 84b6aedc7..aac6fe75f 100644 --- a/app/Exports/Sales/RecurringInvoices/Sheets/RecurringInvoices.php +++ b/app/Exports/Sales/RecurringInvoices/Sheets/RecurringInvoices.php @@ -41,6 +41,8 @@ class RecurringInvoices extends Export implements WithColumnFormatting, WithPare 'invoiced_at', 'due_at', 'amount', + 'discount_type', + 'discount_rate', 'currency_code', 'currency_rate', 'category_name', diff --git a/app/Jobs/Document/CreateDocument.php b/app/Jobs/Document/CreateDocument.php index c6add6eda..1e90560db 100644 --- a/app/Jobs/Document/CreateDocument.php +++ b/app/Jobs/Document/CreateDocument.php @@ -25,6 +25,11 @@ class CreateDocument extends Job implements HasOwner, HasSource, ShouldCreate $this->request['amount'] = 0; } + // Disable this lines for global discount issue fixed ( https://github.com/akaunting/akaunting/issues/2797 ) + if (! empty($this->request['discount'])) { + $this->request['discount_rate'] = $this->request['discount']; + } + event(new DocumentCreating($this->request)); \DB::transaction(function () { diff --git a/app/Jobs/Document/CreateDocumentItemsAndTotals.php b/app/Jobs/Document/CreateDocumentItemsAndTotals.php index eaa6411df..4b5771e9b 100644 --- a/app/Jobs/Document/CreateDocumentItemsAndTotals.php +++ b/app/Jobs/Document/CreateDocumentItemsAndTotals.php @@ -173,6 +173,7 @@ class CreateDocumentItemsAndTotals extends Job implements HasOwner, HasSource, S foreach ((array) $this->request['items'] as $key => $item) { $item['global_discount'] = 0; + /* // Disable this lines for global discount issue fixed ( https://github.com/akaunting/akaunting/issues/2797 ) if (! empty($this->request['discount'])) { if (isset($for_fixed_discount)) { $item['global_discount'] = ($for_fixed_discount[$key] / ($for_fixed_discount['total'] / 100)) * ($this->request['discount'] / 100); @@ -182,6 +183,7 @@ class CreateDocumentItemsAndTotals extends Job implements HasOwner, HasSource, S $item['global_discount_type'] = $this->request['discount_type']; } } + */ $item['created_from'] = $this->request['created_from']; $item['created_by'] = $this->request['created_by']; @@ -244,6 +246,15 @@ class CreateDocumentItemsAndTotals extends Job implements HasOwner, HasSource, S } } + // Disable this lines for global discount issue fixed ( https://github.com/akaunting/akaunting/issues/2797 ) + if (! empty($this->request['discount'])) { + if ($this->request['discount_type'] === 'percentage') { + $actual_total -= ($sub_total * ($this->request['discount'] / 100)); + } else { + $actual_total -= $this->request['discount']; + } + } + return [$sub_total, $actual_total, $discount_amount_total, $taxes]; } diff --git a/app/Jobs/Document/UpdateDocument.php b/app/Jobs/Document/UpdateDocument.php index ba000a3ca..2443d8dbb 100644 --- a/app/Jobs/Document/UpdateDocument.php +++ b/app/Jobs/Document/UpdateDocument.php @@ -22,6 +22,11 @@ class UpdateDocument extends Job implements ShouldUpdate $this->request['amount'] = 0; } + // Disable this lines for global discount issue fixed ( https://github.com/akaunting/akaunting/issues/2797 ) + if (! empty($this->request['discount'])) { + $this->request['discount_rate'] = $this->request['discount']; + } + event(new DocumentUpdating($this->model, $this->request)); \DB::transaction(function () { diff --git a/app/Listeners/Update/V31/Version3115.php b/app/Listeners/Update/V31/Version3115.php new file mode 100644 index 000000000..d06ab5793 --- /dev/null +++ b/app/Listeners/Update/V31/Version3115.php @@ -0,0 +1,43 @@ +skipThisUpdate($event)) { + return; + } + + Log::channel('stdout')->info('Updating to 3.1.15 version...'); + + $this->updateDatabase(); + + Log::channel('stdout')->info('Done!'); + } + + public function updateDatabase(): void + { + Log::channel('stdout')->info('Updating database...'); + + Artisan::call('migrate', ['--force' => true]); + + Log::channel('stdout')->info('Database updated.'); + } +} diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index 264a0cdff..6a786f9ee 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -43,6 +43,8 @@ class Document extends Model 'amount', 'currency_code', 'currency_rate', + 'discount_type', + 'discount_rate', 'category_id', 'contact_id', 'contact_name', @@ -311,6 +313,26 @@ class Document extends Model } } + /** + * Get the discount percentage. + * + * @return string + */ + public function getDiscountRateAttribute($value) + { + return $value ?? 0; + } + + /** + * Get the discount percentage. + * + * @return string + */ + public function getDiscountTypeAttribute($value) + { + return $value ?? 'percentage'; + } + /** * Get the discount percentage. * diff --git a/app/Models/Document/DocumentTotal.php b/app/Models/Document/DocumentTotal.php index ae3a8590b..09592acdb 100644 --- a/app/Models/Document/DocumentTotal.php +++ b/app/Models/Document/DocumentTotal.php @@ -70,20 +70,20 @@ class DocumentTotal extends Model switch ($this->code) { case 'discount': $title = trans($title); - $percent = $this->document->discount; + $percent = ($this->document->discount_rate && $this->document->discount_type == 'percentage') ? $this->document->discount_rate : 0; break; case 'tax': $tax = Tax::where('name', $title)->first(); - if (!empty($tax->rate)) { + if (! empty($tax->rate)) { $percent = $tax->rate; } break; } - if (!empty($percent)) { + if (! empty($percent)) { $title .= ' ('; if (setting('localisation.percent_position', 'after') === 'after') { diff --git a/app/Providers/Event.php b/app/Providers/Event.php index fbb3690be..32e320bdf 100644 --- a/app/Providers/Event.php +++ b/app/Providers/Event.php @@ -31,6 +31,7 @@ class Event extends Provider 'App\Listeners\Update\V31\Version317', 'App\Listeners\Update\V31\Version318', 'App\Listeners\Update\V31\Version3112', + 'App\Listeners\Update\V31\Version3115', ], 'Illuminate\Routing\Events\PreparingResponse' => [ 'App\Listeners\Common\PreparingResponse', diff --git a/database/migrations/2024_12_29_000000_core_v3115.php b/database/migrations/2024_12_29_000000_core_v3115.php new file mode 100644 index 000000000..02ec04d8c --- /dev/null +++ b/database/migrations/2024_12_29_000000_core_v3115.php @@ -0,0 +1,34 @@ +string('discount_type')->nullable()->after('currency_rate'); + $table->double('discount_rate', 15, 4)->nullable()->after('discount_type'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('documents', function (Blueprint $table) { + $table->dropColumn('discount_type'); + $table->dropColumn('discount_rate'); + }); + } +}; diff --git a/public/files/import/bills.xlsx b/public/files/import/bills.xlsx index c773304df..4fb44c9a3 100644 Binary files a/public/files/import/bills.xlsx and b/public/files/import/bills.xlsx differ diff --git a/public/files/import/invoices.xlsx b/public/files/import/invoices.xlsx index 3c4af014c..66fdf1df0 100644 Binary files a/public/files/import/invoices.xlsx and b/public/files/import/invoices.xlsx differ diff --git a/public/files/import/recurring-bills.xlsx b/public/files/import/recurring-bills.xlsx index 9bbc38bc6..c661c0d69 100644 Binary files a/public/files/import/recurring-bills.xlsx and b/public/files/import/recurring-bills.xlsx differ diff --git a/public/files/import/recurring-invoices.xlsx b/public/files/import/recurring-invoices.xlsx index eea3bc376..b6175ed1a 100644 Binary files a/public/files/import/recurring-invoices.xlsx and b/public/files/import/recurring-invoices.xlsx differ diff --git a/resources/assets/js/views/common/documents.js b/resources/assets/js/views/common/documents.js index c9d27d890..ba7911480 100644 --- a/resources/assets/js/views/common/documents.js +++ b/resources/assets/js/views/common/documents.js @@ -87,8 +87,6 @@ const app = new Vue({ }, mounted() { - this.form.discount_type = 'percentage'; - if ((document.getElementById('items') != null) && (document.getElementById('items').rows)) { this.colspan = document.getElementById("items").rows[0].cells.length - 1; } @@ -751,7 +749,7 @@ const app = new Vue({ }, onAddDiscount() { - this.show_discount = !this.show_discount; + this.show_discount = ! this.show_discount; if (this.show_discount) { this.show_discount_text = false; @@ -764,6 +762,10 @@ const app = new Vue({ this.show_discount_text = true; this.discount = false; this.delete_discount = false; + + this.form.discount = 0; + + this.onCalculateTotal(); }, onDeleteTax(item_index, tax_index) { @@ -1017,6 +1019,11 @@ const app = new Vue({ this.onEmailViaTemplate(email_route, email_template); } + // This line added edit document has discount show discount area + if (this.form.discount > 0) { + this.onAddDiscount(); + } + this.page_loaded = true; }, @@ -1054,4 +1061,4 @@ const app = new Vue({ } }, }, -}); +}); \ No newline at end of file diff --git a/resources/views/components/documents/form/totals.blade.php b/resources/views/components/documents/form/totals.blade.php index 529d9eed3..35bb8c5ac 100644 --- a/resources/views/components/documents/form/totals.blade.php +++ b/resources/views/components/documents/form/totals.blade.php @@ -79,7 +79,7 @@ -
+
{{ trans('invoices.add_discount') }} @@ -125,7 +125,8 @@ />
- + + delete