Fixes for tests

This commit is contained in:
David Bomba 2024-11-07 16:35:27 +11:00
parent ce6eb9d975
commit 55188c9820
2 changed files with 390 additions and 329 deletions

View File

@ -64,6 +64,9 @@ use InvoiceNinja\EInvoice\Models\Peppol\SupplierPartyType\AccountingSupplierPart
use InvoiceNinja\EInvoice\Models\Peppol\PartyIdentificationType\PartyIdentification;
use InvoiceNinja\EInvoice\Models\Peppol\TaxCategoryType\TaxCategory;
/**
*
*/
class Fact1Test extends TestCase
{
use MockAccountData;
@ -78,371 +81,371 @@ class Fact1Test extends TestCase
$this->makeTestData();
}
// public function testRoBuild()
// {
// $settings = $this->company->settings;
// $settings->currency_id = '42';
// $this->company->saveSettings($settings, $this->company);
// $this->company->save();
// $settings = ClientSettings::defaults();
// $settings->currency_id = '42';
// //VAT
// //19%
// $client = Client::factory()
// ->create([
// 'user_id' => $this->user->id,
// 'company_id' => $this->company->id,
// 'id_number' => '646546549',
// 'address1' => '40D, Șoseaua București-Ploiești',
// 'city' => 'SECTOR3',
// 'state' => 'RO-B',
// 'country_id' => 642,
// 'vat_number' => 646546549,
// 'name' => 'Client Company Name',
// 'settings' => $settings,
// ]);
// ClientContact::factory()->create([
// 'user_id' => $this->user->id,
// 'company_id' => $this->company->id,
// 'client_id' => $client->id,
// 'first_name' => 'Bob',
// 'last_name' => 'Jane',
// 'email' => 'bob@gmail.com',
// ]);
// $items = [];
// $item = new InvoiceItem();
// $item->cost = 10;
// $item->quantity = 10;
// $item->tax_name1 = 'VAT';
// $item->tax_rate1 = '19';
// $item->product_key = "Product Name";
// $item->notes = "A great product description";
// $_invoice = Invoice::factory()->create([
// 'user_id' => $this->user->id,
// 'company_id' => $this->company->id,
// 'client_id' => $client->id,
// 'number' => 'INV-'.rand(1000, 1000000),
// 'line_items' => [$item],
// 'due_date' => now()->addDays(20)->format('Y-m-d'),
// 'status_id' => 1,
// 'discount' => 0,
// ]);
// $_invoice->service()->markSent()->save();
// $calc = $_invoice->calc();
// $invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice();
// $invoice->UBLVersionID = '2.1';
// $invoice->CustomizationID = 'urn:cen.eu:en16931:2017#compliant#urn:efactura.mfinante.ro:CIUS-RO:1.0.1';
// $invoice->ID = $_invoice->number;
// $invoice->InvoiceTypeCode = 380;
// $invoice->IssueDate = new DateTime($_invoice->date);
// $invoice->DueDate = new DateTime($_invoice->due_date);
// $invoice->DocumentCurrencyCode = 'RON';
// $invoice->TaxCurrencyCode = 'RON';
// $asp = new AccountingSupplierParty();
// $party = new Party();
// $party_identification = new PartyIdentification();
// $party_identification->ID = 'company_id_number';
// $party->PartyIdentification[] = $party_identification;
// $sp_address = new PostalAddress();
// $sp_address->StreetName = $this->company->settings->address1;
// $sp_address->CityName = 'SECTOR2';
// $sp_address->CountrySubentity = 'RO-B';
// $country = new Country();
// $country->IdentificationCode = 'RO';
// $sp_address->Country = $country;
// $party->PostalAddress = $sp_address;
// $pts = new PartyTaxScheme();
// $tax_scheme = new TaxScheme();
// $tax_scheme->ID = 'VAT';
// $pts->CompanyID = 'RO234234234';
// $pts->TaxScheme = $tax_scheme;
// $party->PartyTaxScheme[] = $pts;
// $ple = new PartyLegalEntity();
// $ple->RegistrationName = $this->company->settings->name;
// $ple->CompanyID = 'J40/2222/2009';
// $party->PartyLegalEntity[] = $ple;
public function testRoBuild()
{
$settings = $this->company->settings;
$settings->currency_id = '42';
$this->company->saveSettings($settings, $this->company);
$this->company->save();
$settings = ClientSettings::defaults();
$settings->currency_id = '42';
//VAT
//19%
$client = Client::factory()
->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'id_number' => '646546549',
'address1' => '40D, Șoseaua București-Ploiești',
'city' => 'SECTOR3',
'state' => 'RO-B',
'country_id' => 642,
'vat_number' => 646546549,
'name' => 'Client Company Name',
'settings' => $settings,
]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'client_id' => $client->id,
'first_name' => 'Bob',
'last_name' => 'Jane',
'email' => 'bob@gmail.com',
]);
$items = [];
$item = new InvoiceItem();
$item->cost = 10;
$item->quantity = 10;
$item->tax_name1 = 'VAT';
$item->tax_rate1 = '19';
$item->product_key = "Product Name";
$item->notes = "A great product description";
$_invoice = Invoice::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'client_id' => $client->id,
'number' => 'INV-'.rand(1000, 1000000),
'line_items' => [$item],
'due_date' => now()->addDays(20)->format('Y-m-d'),
'status_id' => 1,
'discount' => 0,
]);
$_invoice->service()->markSent()->save();
$calc = $_invoice->calc();
$invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice();
$invoice->UBLVersionID = '2.1';
$invoice->CustomizationID = 'urn:cen.eu:en16931:2017#compliant#urn:efactura.mfinante.ro:CIUS-RO:1.0.1';
$invoice->ID = $_invoice->number;
$invoice->InvoiceTypeCode = 380;
$invoice->IssueDate = new DateTime($_invoice->date);
$invoice->DueDate = new DateTime($_invoice->due_date);
$invoice->DocumentCurrencyCode = 'RON';
$invoice->TaxCurrencyCode = 'RON';
$asp = new AccountingSupplierParty();
$party = new Party();
$party_identification = new PartyIdentification();
$party_identification->ID = 'company_id_number';
$party->PartyIdentification[] = $party_identification;
$sp_address = new PostalAddress();
$sp_address->StreetName = $this->company->settings->address1;
$sp_address->CityName = 'SECTOR2';
$sp_address->CountrySubentity = 'RO-B';
$country = new Country();
$country->IdentificationCode = 'RO';
$sp_address->Country = $country;
$party->PostalAddress = $sp_address;
$pts = new PartyTaxScheme();
$tax_scheme = new TaxScheme();
$tax_scheme->ID = 'VAT';
$pts->CompanyID = 'RO234234234';
$pts->TaxScheme = $tax_scheme;
$party->PartyTaxScheme[] = $pts;
$ple = new PartyLegalEntity();
$ple->RegistrationName = $this->company->settings->name;
$ple->CompanyID = 'J40/2222/2009';
$party->PartyLegalEntity[] = $ple;
// $p_contact = new Contact();
// $p_contact->Name = $this->company->owner()->present()->name();
// $p_contact->Telephone = $this->company->settings->phone;
// $p_contact->ElectronicMail = $this->company->owner()->email;
// $party->Contact = $p_contact;
// $asp->Party = $party;
$p_contact = new Contact();
$p_contact->Name = $this->company->owner()->present()->name();
$p_contact->Telephone = $this->company->settings->phone;
$p_contact->ElectronicMail = $this->company->owner()->email;
$party->Contact = $p_contact;
$asp->Party = $party;
// $invoice->AccountingSupplierParty = $asp;
$invoice->AccountingSupplierParty = $asp;
// $acp = new AccountingCustomerParty();
$acp = new AccountingCustomerParty();
// $party = new Party();
$party = new Party();
// $party_identification = new PartyIdentification();
// $party_identification->ID = 'client_id_number';
// $party->PartyIdentification[] = $party_identification;
$party_identification = new PartyIdentification();
$party_identification->ID = 'client_id_number';
$party->PartyIdentification[] = $party_identification;
// $sp_address = new PostalAddress();
// $sp_address->StreetName = $client->address1;
// $sp_address->CityName = 'SECTOR2';
// $sp_address->CountrySubentity = 'RO-B';
$sp_address = new PostalAddress();
$sp_address->StreetName = $client->address1;
$sp_address->CityName = 'SECTOR2';
$sp_address->CountrySubentity = 'RO-B';
// $country = new Country();
// $country->IdentificationCode = 'RO';
// $sp_address->Country = $country;
$country = new Country();
$country->IdentificationCode = 'RO';
$sp_address->Country = $country;
// $party->PostalAddress = $sp_address;
$party->PostalAddress = $sp_address;
// $ple = new PartyLegalEntity();
// $ple->RegistrationName = $client->name;
// $ple->CompanyID = '646546549';
$ple = new PartyLegalEntity();
$ple->RegistrationName = $client->name;
$ple->CompanyID = '646546549';
// $party->PartyLegalEntity[] = $ple;
$party->PartyLegalEntity[] = $ple;
// $p_contact = new Contact();
// $p_contact->Name = $client->contacts->first()->present()->name();
// $p_contact->Telephone = $client->contacts->first()->present()->phone();
// $p_contact->ElectronicMail = $client->contacts->first()->present()->email();
$p_contact = new Contact();
$p_contact->Name = $client->contacts->first()->present()->name();
$p_contact->Telephone = $client->contacts->first()->present()->phone();
$p_contact->ElectronicMail = $client->contacts->first()->present()->email();
// $party->Contact = $p_contact;
$party->Contact = $p_contact;
// $acp->Party = $party;
// $invoice->AccountingCustomerParty = $acp;
$acp->Party = $party;
$invoice->AccountingCustomerParty = $acp;
// $taxtotal = new TaxTotal();
// $tax_amount = new TaxAmount();
$taxtotal = new TaxTotal();
$tax_amount = new TaxAmount();
// $tax_amount->amount = $calc->getItemTotalTaxes();
// $tax_amount->currencyID = $_invoice->client->currency()->code;
$tax_amount->amount = $calc->getItemTotalTaxes();
$tax_amount->currencyID = $_invoice->client->currency()->code;
// $tc = new TaxCategory();
// $tc->ID = "S";
$tc = new TaxCategory();
$tc->ID = "S";
// $taxable = $this->getTaxable($_invoice);
$taxable = $this->getTaxable($_invoice);
// $taxable_amount = new TaxableAmount();
// $taxable_amount->amount = $taxable;
// $taxable_amount->currencyID = $_invoice->client->currency()->code;
$taxable_amount = new TaxableAmount();
$taxable_amount->amount = $taxable;
$taxable_amount->currencyID = $_invoice->client->currency()->code;
// $tax_sub_total = new TaxSubtotal();
// $tax_sub_total->TaxAmount = $tax_amount;
// $tax_sub_total->TaxCategory = $tc;
// $tax_sub_total->TaxableAmount = $taxable_amount;
// $taxtotal->TaxSubtotal[] = $tax_sub_total;
$tax_sub_total = new TaxSubtotal();
$tax_sub_total->TaxAmount = $tax_amount;
$tax_sub_total->TaxCategory = $tc;
$tax_sub_total->TaxableAmount = $taxable_amount;
$taxtotal->TaxSubtotal[] = $tax_sub_total;
// $invoice->TaxTotal[] = $taxtotal;
$invoice->TaxTotal[] = $taxtotal;
// $lmt = new LegalMonetaryTotal();
$lmt = new LegalMonetaryTotal();
// $lea = new LineExtensionAmount();
// $lea->amount = $taxable;
// $lea->currencyID = $_invoice->client->currency()->code;
$lea = new LineExtensionAmount();
$lea->amount = $taxable;
$lea->currencyID = $_invoice->client->currency()->code;
// $lmt->LineExtensionAmount = $lea;
$lmt->LineExtensionAmount = $lea;
// $tea = new TaxExclusiveAmount();
// $tea->amount = $taxable;
// $tea->currencyID = $_invoice->client->currency()->code;
$tea = new TaxExclusiveAmount();
$tea->amount = $taxable;
$tea->currencyID = $_invoice->client->currency()->code;
// $lmt->TaxExclusiveAmount = $tea;
$lmt->TaxExclusiveAmount = $tea;
// $tia = new TaxInclusiveAmount();
// $tia->amount = $_invoice->amount;
// $tia->currencyID = $_invoice->client->currency()->code;
$tia = new TaxInclusiveAmount();
$tia->amount = $_invoice->amount;
$tia->currencyID = $_invoice->client->currency()->code;
// $lmt->TaxInclusiveAmount = $tia;
$lmt->TaxInclusiveAmount = $tia;
// $pa = new PayableAmount();
// $pa->amount = $_invoice->amount;
// $pa->currencyID = $_invoice->client->currency()->code;
$pa = new PayableAmount();
$pa->amount = $_invoice->amount;
$pa->currencyID = $_invoice->client->currency()->code;
// $lmt->PayableAmount = $pa;
// $invoice->LegalMonetaryTotal = $lmt;
$lmt->PayableAmount = $pa;
$invoice->LegalMonetaryTotal = $lmt;
// foreach($_invoice->line_items as $key => $item) {
foreach($_invoice->line_items as $key => $item) {
// $invoice_line = new InvoiceLine();
// $invoice_line->ID = $key++;
$invoice_line = new InvoiceLine();
$invoice_line->ID = $key++;
// $iq = new InvoicedQuantity();
// $iq->amount = $item->cost;
// $iq->unitCode = 'H87';
$iq = new InvoicedQuantity();
$iq->amount = $item->cost;
$iq->unitCode = 'H87';
// $invoice_line->InvoicedQuantity = $iq;
$invoice_line->InvoicedQuantity = $iq;
// $invoice_line->Note = substr($item->notes, 0, 200);
$invoice_line->Note = substr($item->notes, 0, 200);
// $ctc = new ClassifiedTaxCategory();
// $ctc->ID = 'S';
$ctc = new ClassifiedTaxCategory();
$ctc->ID = 'S';
// $i = new Item();
// $i->Description = $item->notes;
// $i->Name = $item->product_key;
$i = new Item();
$i->Description = $item->notes;
$i->Name = $item->product_key;
// $tax_scheme = new PeppolTaxScheme();
// $tax_scheme->ID = $item->tax_name1;
// $tax_scheme->Name = $item->tax_rate1;
$tax_scheme = new PeppolTaxScheme();
$tax_scheme->ID = $item->tax_name1;
$tax_scheme->Name = $item->tax_rate1;
// $ctc = new ClassifiedTaxCategory();
// $ctc->TaxScheme = $tax_scheme;
// $ctc->ID = 'S';
$ctc = new ClassifiedTaxCategory();
$ctc->TaxScheme = $tax_scheme;
$ctc->ID = 'S';
// $i->ClassifiedTaxCategory[] = $ctc;
$i->ClassifiedTaxCategory[] = $ctc;
// $invoice_line->Item = $i;
$invoice_line->Item = $i;
// $lea = new LineExtensionAmount();
// $lea->amount = $item->line_total;
// $lea->currencyID = $_invoice->client->currency()->code;
$lea = new LineExtensionAmount();
$lea->amount = $item->line_total;
$lea->currencyID = $_invoice->client->currency()->code;
// $invoice_line->LineExtensionAmount = $lea;
$invoice_line->LineExtensionAmount = $lea;
// $price = new Price();
// $pa = new PriceAmount();
// $pa->amount = $item->line_total;
// $pa->currencyID = $_invoice->client->currency()->code;
$price = new Price();
$pa = new PriceAmount();
$pa->amount = $item->line_total;
$pa->currencyID = $_invoice->client->currency()->code;
// $price->PriceAmount = $pa;
$price->PriceAmount = $pa;
// $lea = new LineExtensionAmount();
// $lea->amount = $item->line_total;
// $lea->currencyID = $_invoice->client->currency()->code;
$lea = new LineExtensionAmount();
$lea->amount = $item->line_total;
$lea->currencyID = $_invoice->client->currency()->code;
// $invoice_line->LineExtensionAmount = $lea;
$invoice_line->LineExtensionAmount = $lea;
// $invoice->InvoiceLine[] = $invoice_line;
// }
$invoice->InvoiceLine[] = $invoice_line;
}
// $validator = Validation::createValidatorBuilder()
// ->enableAttributeMapping()
// ->getValidator();
$validator = Validation::createValidatorBuilder()
->enableAttributeMapping()
->getValidator();
// $errors = $validator->validate($invoice);
$errors = $validator->validate($invoice);
// foreach($errors as $error) {
// // echo $error->getPropertyPath() . ': ' . $error->getMessage() . "\n";
// }
foreach($errors as $error) {
// echo $error->getPropertyPath() . ': ' . $error->getMessage() . "\n";
}
// $this->assertCount(0, $errors);
$this->assertCount(0, $errors);
// $phpDocExtractor = new PhpDocExtractor();
// $reflectionExtractor = new ReflectionExtractor();
// // list of PropertyListExtractorInterface (any iterable)
// $listExtractors = [$reflectionExtractor];
// // list of PropertyTypeExtractorInterface (any iterable)
// $typeExtractors = [$reflectionExtractor,$phpDocExtractor];
// // list of PropertyDescriptionExtractorInterface (any iterable)
// $descriptionExtractors = [$phpDocExtractor];
// // list of PropertyAccessExtractorInterface (any iterable)
// $accessExtractors = [$reflectionExtractor];
// // list of PropertyInitializableExtractorInterface (any iterable)
// $propertyInitializableExtractors = [$reflectionExtractor];
// $propertyInfo = new PropertyInfoExtractor(
// // $listExtractors,
// $propertyInitializableExtractors,
// $descriptionExtractors,
// $typeExtractors,
// // $accessExtractors,
// );
// $context = [
// 'xml_format_output' => true,
// 'remove_empty_tags' => true,
// ];
$phpDocExtractor = new PhpDocExtractor();
$reflectionExtractor = new ReflectionExtractor();
// list of PropertyListExtractorInterface (any iterable)
$listExtractors = [$reflectionExtractor];
// list of PropertyTypeExtractorInterface (any iterable)
$typeExtractors = [$reflectionExtractor,$phpDocExtractor];
// list of PropertyDescriptionExtractorInterface (any iterable)
$descriptionExtractors = [$phpDocExtractor];
// list of PropertyAccessExtractorInterface (any iterable)
$accessExtractors = [$reflectionExtractor];
// list of PropertyInitializableExtractorInterface (any iterable)
$propertyInitializableExtractors = [$reflectionExtractor];
$propertyInfo = new PropertyInfoExtractor(
// $listExtractors,
$propertyInitializableExtractors,
$descriptionExtractors,
$typeExtractors,
// $accessExtractors,
);
$context = [
'xml_format_output' => true,
'remove_empty_tags' => true,
];
// $encoder = new XmlEncoder($context);
// $classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
// $metadataAwareNameConverter = new MetadataAwareNameConverter($classMetadataFactory);
// $discriminator = new ClassDiscriminatorFromClassMetadata($classMetadataFactory);
$encoder = new XmlEncoder($context);
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
$metadataAwareNameConverter = new MetadataAwareNameConverter($classMetadataFactory);
$discriminator = new ClassDiscriminatorFromClassMetadata($classMetadataFactory);
// $normalizer = new ObjectNormalizer($classMetadataFactory, $metadataAwareNameConverter, null, $propertyInfo);
$normalizer = new ObjectNormalizer($classMetadataFactory, $metadataAwareNameConverter, null, $propertyInfo);
// $normalizers = [ new DateTimeNormalizer(), $normalizer, new ArrayDenormalizer() , ];
// $encoders = [$encoder, new JsonEncoder()];
// $serializer = new Serializer($normalizers, $encoders);
$normalizers = [ new DateTimeNormalizer(), $normalizer, new ArrayDenormalizer() , ];
$encoders = [$encoder, new JsonEncoder()];
$serializer = new Serializer($normalizers, $encoders);
// $n_context = [
// AbstractObjectNormalizer::SKIP_NULL_VALUES => true,
// // AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true,
// ];
$n_context = [
AbstractObjectNormalizer::SKIP_NULL_VALUES => true,
// AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true,
];
// // $invoice = $normalizer->normalize($invoice, 'json', $n_context);
// // echo print_r($invoice);
// // $invoice = $serializer->serialize($invoice, 'xml', $n_context);
// $dataxml = $serializer->encode($invoice, 'xml', $context);
// $invoice = $normalizer->normalize($invoice, 'json', $n_context);
// echo print_r($invoice);
// $invoice = $serializer->serialize($invoice, 'xml', $n_context);
$dataxml = $serializer->encode($invoice, 'xml', $context);
// // echo $dataxml;
// echo $dataxml;
// //set default standard props
// }
//set default standard props
}
// /**
// * @return float|int|mixed
// */
// private function getTaxable(Invoice $invoice): float
// {
// $total = 0;
/**
* @return float|int|mixed
*/
private function getTaxable(Invoice $invoice): float
{
$total = 0;
// foreach ($invoice->line_items as $item) {
// $line_total = $item->quantity * $item->cost;
foreach ($invoice->line_items as $item) {
$line_total = $item->quantity * $item->cost;
// if ($item->discount != 0) {
// if ($invoice->is_amount_discount) {
// $line_total -= $item->discount;
// } else {
// $line_total -= $line_total * $item->discount / 100;
// }
// }
// $total += $line_total;
// }
// if ($invoice->discount > 0) {
// if ($invoice->is_amount_discount) {
// $total -= $invoice->discount;
// } else {
// $total *= (100 - $invoice->discount) / 100;
// $total = round($total, 2);
// }
// }
// if ($invoice->custom_surcharge1 && $invoice->custom_surcharge_tax1) {
// $total += $invoice->custom_surcharge1;
// }
// if ($invoice->custom_surcharge2 && $invoice->custom_surcharge_tax2) {
// $total += $invoice->custom_surcharge2;
// }
// if ($invoice->custom_surcharge3 && $invoice->custom_surcharge_tax3) {
// $total += $invoice->custom_surcharge3;
// }
// if ($invoice->custom_surcharge4 && $invoice->custom_surcharge_tax4) {
// $total += $invoice->custom_surcharge4;
// }
// return $total;
// }
if ($item->discount != 0) {
if ($invoice->is_amount_discount) {
$line_total -= $item->discount;
} else {
$line_total -= $line_total * $item->discount / 100;
}
}
$total += $line_total;
}
if ($invoice->discount > 0) {
if ($invoice->is_amount_discount) {
$total -= $invoice->discount;
} else {
$total *= (100 - $invoice->discount) / 100;
$total = round($total, 2);
}
}
if ($invoice->custom_surcharge1 && $invoice->custom_surcharge_tax1) {
$total += $invoice->custom_surcharge1;
}
if ($invoice->custom_surcharge2 && $invoice->custom_surcharge_tax2) {
$total += $invoice->custom_surcharge2;
}
if ($invoice->custom_surcharge3 && $invoice->custom_surcharge_tax3) {
$total += $invoice->custom_surcharge3;
}
if ($invoice->custom_surcharge4 && $invoice->custom_surcharge_tax4) {
$total += $invoice->custom_surcharge4;
}
return $total;
}
}

View File

@ -12,19 +12,22 @@
namespace Tests\Integration\Einvoice\Storecove;
use Tests\TestCase;
use App\Models\User;
use App\Models\Client;
use App\Models\Account;
use App\Models\Company;
use App\Models\Invoice;
use Tests\MockAccountData;
use App\Models\CompanyToken;
use App\Models\ClientContact;
use App\DataMapper\InvoiceItem;
use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use App\Factory\CompanyUserFactory;
use App\Services\EDocument\Standards\Peppol;
use App\Services\EDocument\Standards\Validation\Peppol\EntityLevel;
use InvoiceNinja\EInvoice\Models\Peppol\PaymentMeans;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Services\EDocument\Standards\Validation\Peppol\EntityLevel;
class EInvoiceValidationTest extends TestCase
{
@ -35,53 +38,107 @@ class EInvoiceValidationTest extends TestCase
{
parent::setUp();
// $this->markTestSkipped('company model issues');
$this->makeTestData();
}
public function testEinvoiceValidationEndpointInvoice()
{
// public function testEinvoiceValidationEndpointInvoice()
// {
$this->company->legal_entity_id = 123432;
$this->company->save();
// $company = Company::factory()->create([
// 'account_id' => $this->account->id,
// 'legal_entity_id' => 123432
// ]);
$data =[
'entity' => 'invoices',
'entity_id' => $this->invoice->hashed_id,
];
// $user = User::factory()->create([
// 'account_id' => $this->account->id,
// 'confirmation_code' => '123',
// 'email' => $this->faker->safeEmail(),
// ]);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/einvoice/validateEntity', $data);
// $cu = CompanyUserFactory::create($user->id, $company->id, $this->account->id);
// $cu->is_owner = true;
// $cu->is_admin = true;
// $cu->is_locked = false;
// $cu->permissions = '["view_client"]';
// $cu->save();
$response->assertStatus(200);
// $different_company_token = \Illuminate\Support\Str::random(64);
$arr = $response->json();
// $company_token = new CompanyToken();
// $company_token->user_id = $user->id;
// $company_token->company_id = $company->id;
// $company_token->account_id = $this->account->id;
// $company_token->name = 'test token';
// $company_token->token = $different_company_token;
// $company_token->is_system = true;
// $company_token->save();
}
// $data = [
// 'action' => 'archive',
// 'ids' => [
// $this->client->id
// ]
// ];
public function testEinvoiceValidationEndpoint()
{
$this->company->legal_entity_id = 123432;
$this->company->save();
// $c = Client::factory()->create([
// 'company_id' => $company->id,
// 'user_id' => $user->id
// ]);
$data =[
'entity' => 'companies',
'entity_id' => $this->company->hashed_id,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/einvoice/validateEntity', $data);
// ClientContact::factory()->create([
// 'user_id' => $user->id,
// 'client_id' => $c->id,
// 'company_id' => $company->id,
// 'is_primary' => 1,
// ]);
$response->assertStatus(200);
$arr = $response->json();
// $i = Invoice::factory()->create([
// 'company_id' => $company->id,
// 'user_id' => $user->id,
// 'client_id' => $c->id
// ]);
}
// $data =[
// 'entity' => 'invoices',
// 'entity_id' => $i->hashed_id,
// ];
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $different_company_token,
// ])->postJson('/api/v1/einvoice/validateEntity', $data);
// $response->assertStatus(200);
// }
// public function testEinvoiceValidationEndpoint()
// {
// $this->company->legal_entity_id = 123432;
// $this->company->save();
// $data =[
// 'entity' => 'companies',
// 'entity_id' => $this->company->hashed_id,
// ];
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->postJson('/api/v1/einvoice/validateEntity', $data);
// $response->assertStatus(200);
// $arr = $response->json();
// }
public function testInvalidCompanySettings()
{
@ -170,6 +227,7 @@ class EInvoiceValidationTest extends TestCase
$settings->postal_code = '2113';
$settings->country_id = '1';
$settings->vat_number = '';
$settings->id_number ='adfadf';
$settings->classification = 'individual';
$account = Account::factory()->create();