1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

fix: processReservedKeywords should be aware of recurring invoice date

This commit is contained in:
Gary Turner 2023-01-23 12:45:45 +00:00
parent e2c7d42247
commit fda7004f3a
2 changed files with 37 additions and 1 deletions

View File

@ -15,6 +15,7 @@ use App\Models\Client;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\RecurringInvoice; use App\Models\RecurringInvoice;
use App\Utils\Helpers; use App\Utils\Helpers;
use Carbon\Carbon;
class RecurringInvoiceToInvoiceFactory class RecurringInvoiceToInvoiceFactory
{ {
@ -70,11 +71,16 @@ class RecurringInvoiceToInvoiceFactory
private static function transformItems($recurring_invoice, $client) private static function transformItems($recurring_invoice, $client)
{ {
$currentDateTime = null;
$line_items = $recurring_invoice->line_items; $line_items = $recurring_invoice->line_items;
if (isset($recurring_invoice->next_send_date)) {
$currentDateTime = Carbon::parse($recurring_invoice->next_send_date)->timezone($client->timezone()->name);
}
foreach ($line_items as $key => $item) { foreach ($line_items as $key => $item) {
if (property_exists($line_items[$key], 'notes')) { if (property_exists($line_items[$key], 'notes')) {
$line_items[$key]->notes = Helpers::processReservedKeywords($item->notes, $client); $line_items[$key]->notes = Helpers::processReservedKeywords($item->notes, $client, $currentDateTime);
} }
} }

View File

@ -17,6 +17,7 @@ use App\Factory\RecurringInvoiceToInvoiceFactory;
use App\Models\Client; use App\Models\Client;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\RecurringInvoice; use App\Models\RecurringInvoice;
use App\Utils\Helpers;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -304,6 +305,35 @@ class RecurringInvoiceTest extends TestCase
$this->assertEquals(10, $invoice->subscription_id); $this->assertEquals(10, $invoice->subscription_id);
} }
public function testRecurringDatePassesToInvoice()
{
$noteText = "Hello this is for :MONTH_AFTER";
$recurringDate = \Carbon\Carbon::now()->subDays(10);
$item = InvoiceItemFactory::create();
$item->cost = 10;
$item->notes = $noteText;
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
$recurring_invoice->user_id = $this->user->id;
$recurring_invoice->next_send_date = $recurringDate;
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
$recurring_invoice->remaining_cycles = 2;
$recurring_invoice->next_send_date = $recurringDate;
$recurring_invoice->line_items = [$item];
$recurring_invoice->save();
$recurring_invoice->number = $this->getNextRecurringInvoiceNumber($this->invoice->client, $this->invoice);
$recurring_invoice->subscription_id = 10;
$recurring_invoice->save();
$invoice = RecurringInvoiceToInvoiceFactory::create($recurring_invoice, $this->invoice->client);
$expectedNote = Helpers::processReservedKeywords($noteText, $this->invoice->client, $recurringDate);
$this->assertEquals($expectedNote, $invoice->line_items[0]->notes);
}
public function testSubscriptionIdPassesToInvoiceIfNull() public function testSubscriptionIdPassesToInvoiceIfNull()
{ {
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice); $recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);