diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 1122683a7735..e7d8eb2f6869 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -402,7 +402,7 @@ class InvoiceService $balance = $this->invoice->balance; //return early if type three does not exist. - if (! collect($this->invoice->line_items)->contains('type_id', 3)) { + if (! collect($this->invoice->line_items)->contains('type_id', '3')) { return $this; } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 46f741e7b4c6..f96d37be5df8 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -1042,8 +1042,6 @@ html { $dom = null; - nlog($html); - return $html; } diff --git a/tests/Unit/LateFeeTest.php b/tests/Unit/LateFeeTest.php index 383e9b2424dd..5721f79e0727 100644 --- a/tests/Unit/LateFeeTest.php +++ b/tests/Unit/LateFeeTest.php @@ -22,6 +22,8 @@ use App\Jobs\Util\ReminderJob; use App\DataMapper\InvoiceItem; use App\DataMapper\FeesAndLimits; use App\DataMapper\CompanySettings; +use App\Factory\InvoiceItemFactory; +use App\Factory\ClientGatewayTokenFactory; use Illuminate\Foundation\Testing\DatabaseTransactions; /** @@ -93,6 +95,122 @@ class LateFeeTest extends TestCase return $client; } + public function testLateFeeRemovals() + { + + $data = []; + $data[1]['min_limit'] = -1; + $data[1]['max_limit'] = -1; + $data[1]['fee_amount'] = 0.00; + $data[1]['fee_percent'] = 1; + $data[1]['fee_tax_name1'] = ''; + $data[1]['fee_tax_rate1'] = 0; + $data[1]['fee_tax_name2'] = ''; + $data[1]['fee_tax_rate2'] = 0; + $data[1]['fee_tax_name3'] = ''; + $data[1]['fee_tax_rate3'] = 0; + $data[1]['adjust_fee_percent'] = false; + $data[1]['fee_cap'] = 0; + $data[1]['is_enabled'] = true; + + $cg = new \App\Models\CompanyGateway; + $cg->company_id = $this->company->id; + $cg->user_id = $this->user->id; + $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; + $cg->require_cvv = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; + $cg->update_details = true; + $cg->config = encrypt(config('ninja.testvars.stripe')); + $cg->fees_and_limits = $data; + $cg->save(); + + $cgt = ClientGatewayTokenFactory::create($this->company->id); + $cgt->client_id = $this->client->id; + $cgt->token = ''; + $cgt->gateway_customer_reference = ''; + $cgt->gateway_type_id = 1; + $cgt->company_gateway_id = $cg->id; + $cgt->save(); + + $line_items = []; + + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 10; + $item->type_id = '1'; + + $line_items[] = $item; + + $invoice_item = new InvoiceItem; + $invoice_item->type_id = '5'; + $invoice_item->product_key = trans('texts.fee'); + $invoice_item->quantity = 1; + $invoice_item->cost = 10; + + $line_items[] = $item; + + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 1; + $item->type_id = '3'; + + $line_items[] = $item; + + $this->assertTrue(collect($line_items)->contains('type_id', '3')); + $this->assertTrue(collect($line_items)->contains('type_id', 3)); + + $i = Invoice::factory()->create([ + + 'client_id' => $this->client->id, + 'company_id' => $this->company->id, + 'user_id' => $this->user->id, + 'line_items' => $line_items, + ]); + + $i = $i->calc()->getInvoice(); + + $this->assertEquals(3, count($i->line_items)); + + $invoice_items = (array) $i->line_items; + + $invoice_items = collect($invoice_items)->filter(function ($item) { + return $item->type_id != '3'; + }); + + $i->line_items = $invoice_items; + + $i->line_items = collect($i->line_items) + ->reject(function ($item) { + return $item->type_id == '3'; + })->toArray(); + + $this->assertEquals(2, count($i->line_items)); + + $i->service()->autoBill(); + + $i = $i->fresh(); + + $this->assertCount(2, $i->line_items); + + $line_items = $i->line_items; + + $invoice_item = new InvoiceItem; + $invoice_item->type_id = '5'; + $invoice_item->product_key = trans('texts.fee'); + $invoice_item->quantity = 1; + $invoice_item->cost = 10; + + $line_items[] = $item; + + $i->line_items = $line_items; + + $i = $i->calc()->getInvoice(); + + $this->assertCount(3, $i->line_items); + + } + public function testLateFeeAdded() {