e_invoice column for recurring
This commit is contained in:
parent
d91c0c096e
commit
2622976730
|
|
@ -66,10 +66,72 @@ class RecurringInvoiceToInvoiceFactory
|
||||||
$invoice->auto_bill_enabled = $recurring_invoice->auto_bill_enabled;
|
$invoice->auto_bill_enabled = $recurring_invoice->auto_bill_enabled;
|
||||||
$invoice->paid_to_date = 0;
|
$invoice->paid_to_date = 0;
|
||||||
$invoice->design_id = $recurring_invoice->design_id;
|
$invoice->design_id = $recurring_invoice->design_id;
|
||||||
|
$invoice->e_invoice = self::transformEInvoice($recurring_invoice);
|
||||||
|
|
||||||
return $invoice;
|
return $invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function transformEInvoice($recurring_invoice)
|
||||||
|
{
|
||||||
|
if(!$recurring_invoice->e_invoice)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if(isset($recurring_invoice->e_invoice->Invoice)) {
|
||||||
|
|
||||||
|
if(isset($recurring_invoice->e_invoice->Invoice->InvoicePeriod) && is_array($recurring_invoice->e_invoice->Invoice->InvoicePeriod)) {
|
||||||
|
$period = $recurring_invoice->e_invoice->Invoice->InvoicePeriod[0];
|
||||||
|
|
||||||
|
if($description = $period->Description)
|
||||||
|
{
|
||||||
|
$parts = explode('|', $description);
|
||||||
|
|
||||||
|
if(count($parts) == 2)
|
||||||
|
{
|
||||||
|
$start_template = explode(',', $parts[0]);
|
||||||
|
$end_template = explode(',', $parts[1]);
|
||||||
|
|
||||||
|
$start_date = date_create('now', new \DateTimeZone($client->timezone()->name));
|
||||||
|
|
||||||
|
foreach($start_template as $template)
|
||||||
|
{
|
||||||
|
$start_date->modify($template);
|
||||||
|
}
|
||||||
|
|
||||||
|
$start_date = $start_date->format('Y-m-d');
|
||||||
|
|
||||||
|
$end_date = date_create('now', new \DateTimeZone($client->timezone()->name));
|
||||||
|
|
||||||
|
foreach($end_template as $template)
|
||||||
|
{
|
||||||
|
$end_date->modify($template);
|
||||||
|
}
|
||||||
|
|
||||||
|
$end_date = $end_date->format('Y-m-d');
|
||||||
|
|
||||||
|
$einvoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice();
|
||||||
|
|
||||||
|
$ip = new InvoiceNinja\EInvoice\Models\Peppol\PeriodType\InvoicePeriod();
|
||||||
|
$ip->StartDate = new \DateTime($start_date);
|
||||||
|
$ip->EndDate = new \DateTime($end_date);
|
||||||
|
$einvoice->InvoicePeriod = [$ip];
|
||||||
|
|
||||||
|
|
||||||
|
$stub = new \stdClass();
|
||||||
|
$stub->Invoice = $einvoice;
|
||||||
|
|
||||||
|
return $stub;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static function transformItems($recurring_invoice, $client)
|
private static function transformItems($recurring_invoice, $client)
|
||||||
{
|
{
|
||||||
$currentDateTime = null;
|
$currentDateTime = null;
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,7 @@ class RecurringInvoice extends BaseModel
|
||||||
'vendor_id',
|
'vendor_id',
|
||||||
'next_send_date_client',
|
'next_send_date_client',
|
||||||
'uses_inclusive_taxes',
|
'uses_inclusive_taxes',
|
||||||
|
'e_invoice',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
|
@ -235,6 +236,7 @@ class RecurringInvoice extends BaseModel
|
||||||
'updated_at' => 'timestamp',
|
'updated_at' => 'timestamp',
|
||||||
'created_at' => 'timestamp',
|
'created_at' => 'timestamp',
|
||||||
'deleted_at' => 'timestamp',
|
'deleted_at' => 'timestamp',
|
||||||
|
'e_invoice' => 'object',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $appends = [
|
protected $appends = [
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,7 @@ class RecurringInvoiceTransformer extends EntityTransformer
|
||||||
'due_date_days' => (string) $invoice->due_date_days ?: '',
|
'due_date_days' => (string) $invoice->due_date_days ?: '',
|
||||||
'paid_to_date' => (float) $invoice->paid_to_date,
|
'paid_to_date' => (float) $invoice->paid_to_date,
|
||||||
'subscription_id' => (string) $this->encodePrimaryKey($invoice->subscription_id),
|
'subscription_id' => (string) $this->encodePrimaryKey($invoice->subscription_id),
|
||||||
|
'e_invoice' => $invoice->e_invoice ?: new \stdClass(),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (request()->has('show_dates') && request()->query('show_dates') == 'true') {
|
if (request()->has('show_dates') && request()->query('show_dates') == 'true') {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
Schema::table('recurring_invoices', function (Blueprint $table) {
|
||||||
|
$table->mediumText('e_invoice')->nullable();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -26,6 +26,46 @@ class InvoicePeriodTest extends TestCase
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testERecurringInvoicePeriodValidationPasses()
|
||||||
|
{
|
||||||
|
|
||||||
|
$r = \App\Models\RecurringInvoice::factory()->create(
|
||||||
|
[
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'client_id' => $this->client->id,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$data = $r->toArray();
|
||||||
|
|
||||||
|
$data['client_id'] = $this->client->hashed_id;
|
||||||
|
|
||||||
|
$data['e_invoice'] = [
|
||||||
|
'Invoice' => [
|
||||||
|
'InvoicePeriod' => [
|
||||||
|
[
|
||||||
|
'StartDate' => '2025-01-01',
|
||||||
|
'EndDate' => '2025-01-01',
|
||||||
|
'Description' => 'first day of the month|last day of the month'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->putJson('/api/v1/recurring_invoices/'.$r->hashed_id, $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals($arr['data']['e_invoice']['Invoice']['InvoicePeriod'][0]['Description'], 'first day of the month|last day of the month');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testEInvoicePeriodValidationPasses()
|
public function testEInvoicePeriodValidationPasses()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue