Skip to content

Commit

Permalink
Merge pull request #27 from insane-code/fix/loger-changes
Browse files Browse the repository at this point in the history
fix: delete invoice taxes on delete
  • Loading branch information
jesusantguerrero authored Mar 30, 2023
2 parents c9fcb4e + 78d4715 commit 3eff09f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Jobs/Invoice/CreateInvoiceLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private function createItemTaxes($taxes, $line) {
"invoice_line_id" => $line->id,
"tax_id" => $tax['id'],
"name" => $tax['name'],
"is_fixed" => $tax['is_fixed'],
"label" => $tax['label'],
"concept" => $tax['description'] ?? $tax['concept'],
"rate" => $taxRate,
Expand Down
8 changes: 4 additions & 4 deletions src/Models/Invoice/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ protected static function booted()

$invoice->payments()->delete();
$invoice->transaction()->delete();
InvoiceLine::where('invoice_id', $invoice->id)->delete();
$invoice->lines()->delete();
$invoice->taxesLines()->delete();
DB::table('invoice_relations')->where('invoice_id', $invoice->id)->delete();
});
}

Expand Down Expand Up @@ -250,9 +252,7 @@ public static function setNumber($invoice)
public static function calculateTotal($invoice)
{
$total = InvoiceLine::where(["invoice_id" => $invoice->id])->selectRaw('sum(price) as price, sum(discount) as discount, sum(amount) as amount')->get();
$totalTax = InvoiceLineTax::where(["invoice_id" => $invoice->id])
->selectRaw('sum(amount * type) as amount')
->get();
$totalTax = InvoiceLineTax::where(["invoice_id" => $invoice->id])->selectRaw('sum(amount * type) as amount')->get();

$discount = $total[0]['discount'] ?? 0;
$taxTotal = $totalTax[0]['amount'] ?? 0;
Expand Down
1 change: 1 addition & 0 deletions src/Models/Invoice/InvoiceLineTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class InvoiceLineTax extends Model
'user_id',
'invoice_id',
'tax_id',
'is_fixed',
'amount',
'amount_base',
'rate',
Expand Down
30 changes: 30 additions & 0 deletions src/database/migrations/2023_03_30_100000_add_is_fixed_taxes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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('invoice_line_taxes', function (Blueprint $table) {
$table->boolean('is_fixed')->default(false);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('invoice_line_taxes');
}
};

0 comments on commit 3eff09f

Please sign in to comment.