Merge pull request #3248 from CihanSenturk/fix-document-global-discount-issue
Global discount calculate method changed
This commit is contained in:
commit
21e99867c6
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Listeners\Update\V31;
|
||||
|
||||
use App\Abstracts\Listeners\Update as Listener;
|
||||
use App\Events\Install\UpdateFinished as Event;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Version3115 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '3.1.15';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
if ($this->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.');
|
||||
}
|
||||
}
|
||||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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') {
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('documents', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -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({
|
|||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
<td class="border-t-0 py-0"></td>
|
||||
|
||||
<td class="ltr:text-right rtl:text-left border-t-0 border-r-0 border-b-0 align-middle py-0 pr-0">
|
||||
<div v-if="show_discount_text" v-if="!totals.discount_text" @click="onAddDiscount()">
|
||||
<div v-if="show_discount_text" @click="onAddDiscount()">
|
||||
<x-button.hover color="to-purple">
|
||||
{{ trans('invoices.add_discount') }}
|
||||
</x-button.hover>
|
||||
|
|
@ -125,7 +125,8 @@
|
|||
/>
|
||||
</div>
|
||||
|
||||
<x-form.input.hidden name="discount" v-model="form.discount" />
|
||||
<x-form.input.hidden name="discount_type" value="{{ $document->discount_type ?? 'percentage' }}" v-model="form.discount_type" />
|
||||
<x-form.input.hidden name="discount" value="{{ $document->discount_rate ?? 0 }}" v-model="form.discount" />
|
||||
|
||||
<span v-if="delete_discount" @click="onRemoveDiscountArea()" class="material-icons-outlined absolute w-6 h-7 flex justify-center ltr:-right-10 rtl:-left-10 top-2 text-lg text-gray-300 rounded-lg cursor-pointer hover:bg-gray-100 hover:text-gray-500">delete</span>
|
||||
</td>
|
||||
|
|
|
|||
Loading…
Reference in New Issue