mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2026-03-03 02:57:01 +00:00
Validation for credits
This commit is contained in:
@@ -13,10 +13,11 @@
|
||||
namespace App\Http\Requests\Credit;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Utils\Traits\ChecksEntityStatus;
|
||||
use App\Utils\Traits\CleanLineItems;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Utils\Traits\CleanLineItems;
|
||||
use App\Utils\Traits\ChecksEntityStatus;
|
||||
use App\Http\ValidationRules\EInvoice\ValidCreditScheme;
|
||||
|
||||
class UpdateCreditRequest extends Request
|
||||
{
|
||||
@@ -81,7 +82,7 @@ class UpdateCreditRequest extends Request
|
||||
|
||||
$rules['location_id'] = ['nullable', 'sometimes','bail', Rule::exists('locations', 'id')->where('company_id', $user->company()->id)->where('client_id', $this->credit->client_id)];
|
||||
|
||||
$rules['e_invoice'] = ['sometimes', 'nullable', new ValidInvoiceScheme()];
|
||||
$rules['e_invoice'] = ['sometimes', 'nullable', new ValidCreditScheme()];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
@@ -96,6 +97,7 @@ class UpdateCreditRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
nlog($input);
|
||||
$input = $this->decodePrimaryKeys($input);
|
||||
|
||||
if (isset($input['documents'])) {
|
||||
|
||||
@@ -115,7 +115,6 @@ class UpdateEInvoiceConfiguration extends Request
|
||||
|
||||
return [...$rules, 'nullable'];
|
||||
}),
|
||||
'document_reference' => ['sometimes', 'bail', 'array'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Utils\Traits\CleanLineItems;
|
||||
use App\Utils\Traits\ChecksEntityStatus;
|
||||
use App\Http\ValidationRules\Invoice\LockedInvoiceRule;
|
||||
use App\Http\ValidationRules\EInvoice\ValidInvoiceScheme;
|
||||
use App\Http\ValidationRules\Project\ValidProjectForClient;
|
||||
|
||||
|
||||
@@ -5683,9 +5683,11 @@ Développe automatiquement la section des notes dans le tableau de produits pour
|
||||
'reject_quote_confirmation' => 'Êtes-vous sûr de vouloir rejeter cette soumission ?',
|
||||
'reason' => 'Raison',
|
||||
'enter_reason' => 'Préciser la raison...',
|
||||
'notification_invoice_overdue_summary_subject' => 'Invoice Overdue Summary: :date',
|
||||
'notification_invoice_overdue_summary' => 'The following invoices are overdue:',
|
||||
'purge_user_confirmation' => 'Warning! This action will reassign all entities to the account owner and permanently delete the user across all companies and accounts. Are you sure you want to proceed?',
|
||||
'notification_invoice_overdue_summary_subject' => 'Récapitulatif des factures impayées: :date',
|
||||
'notification_invoice_overdue_summary' => 'Les factures suivantes sont impayées:',
|
||||
'purge_user_confirmation' => 'Attention ! Cette action réattribuera toutes les entités au propriétaire du compte et supprimera définitivement l\'utilisateur de l\'ensemble des entreprises et des comptes. Voulez-vous vraiment continuer ?',
|
||||
'peppol_sending_failed' => 'Problème technique de livraison. Réessai impossible.',
|
||||
'peppol_sending_success' => 'La facture électronique a été envoyée!',
|
||||
);
|
||||
|
||||
return $lang;
|
||||
|
||||
@@ -5684,9 +5684,11 @@ $lang = array(
|
||||
'reject_quote_confirmation' => 'Bạn có chắc chắn muốn đến chối báo giá này không?',
|
||||
'reason' => 'Lý do',
|
||||
'enter_reason' => 'Nhập một lý do...',
|
||||
'notification_invoice_overdue_summary_subject' => 'Invoice Overdue Summary: :date',
|
||||
'notification_invoice_overdue_summary' => 'The following invoices are overdue:',
|
||||
'purge_user_confirmation' => 'Warning! This action will reassign all entities to the account owner and permanently delete the user across all companies and accounts. Are you sure you want to proceed?',
|
||||
'notification_invoice_overdue_summary_subject' => 'Hóa đơn Tóm tắt quá hạn: :date',
|
||||
'notification_invoice_overdue_summary' => 'Các Hóa đơn sau đây đã quá hạn:',
|
||||
'purge_user_confirmation' => 'Cảnh báo! Thao tác này sẽ gán lại tất cả các thực thể đến chủ sở hữu tài khoản và Xóa vĩnh viễn Người dùng trên tất cả các công ty và tài khoản. Bạn có chắc chắn muốn đến tục không?',
|
||||
'peppol_sending_failed' => 'Sự cố giao hàng kỹ thuật. Không thể thử lại',
|
||||
'peppol_sending_success' => 'E- Hóa đơn gửi Thành công !',
|
||||
);
|
||||
|
||||
return $lang;
|
||||
|
||||
@@ -30,6 +30,7 @@ class CreditTest extends TestCase
|
||||
use MakesHash;
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -38,6 +39,128 @@ class CreditTest extends TestCase
|
||||
Model::reguard();
|
||||
|
||||
$this->makeTestData();
|
||||
// $this->withoutExceptionHandling();
|
||||
}
|
||||
|
||||
public function testCreditEInvoiceValidation()
|
||||
{
|
||||
|
||||
$credit_update = [
|
||||
'e_invoice' => [
|
||||
'CreditNote' => [
|
||||
'InvoiceDocumentReference' => [
|
||||
'ID' => '',
|
||||
'IssueDate' => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$data = array_merge($this->credit->toArray(), $credit_update);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->putJson('/api/v1/credits/'.$this->encodePrimaryKey($this->credit->id), $data);
|
||||
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
public function testCreditEInvoiceValidationWithProperNumber()
|
||||
{
|
||||
|
||||
$credit_update = [
|
||||
'e_invoice' => [
|
||||
'CreditNote' => [
|
||||
'InvoiceDocumentReference' => [
|
||||
'ID' => 'INV-123456S',
|
||||
'IssueDate' => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$data = array_merge($this->credit->toArray(), $credit_update);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->putJson('/api/v1/credits/'.$this->encodePrimaryKey($this->credit->id), $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function testCreditEInvoiceValidationWithProperDate()
|
||||
{
|
||||
|
||||
$credit_update = [
|
||||
'e_invoice' => [
|
||||
'CreditNote' => [
|
||||
'InvoiceDocumentReference' => [
|
||||
'ID' => 'INV-123456S',
|
||||
'IssueDate' => '2026-01-18',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$data = array_merge($this->credit->toArray(), $credit_update);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->putJson('/api/v1/credits/'.$this->encodePrimaryKey($this->credit->id), $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
public function testCreditEInvoiceValidationWithIncorrectDate()
|
||||
{
|
||||
|
||||
$credit_update = [
|
||||
'e_invoice' => [
|
||||
'CreditNote' => [
|
||||
'InvoiceDocumentReference' => [
|
||||
'ID' => 'INV-123456S',
|
||||
'IssueDate' => '203326-01-118',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$data = array_merge($this->credit->toArray(), $credit_update);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->putJson('/api/v1/credits/'.$this->encodePrimaryKey($this->credit->id), $data);
|
||||
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
public function testCreditEInvoiceValidationWithIncorrectDateButPassesValidation()
|
||||
{
|
||||
|
||||
$credit_update = [
|
||||
'e_invoice' => [
|
||||
'CreditNote' => [
|
||||
'InvoiceDocumentReference' => [
|
||||
'ID' => 'INV-123456S',
|
||||
'IssueDate' => '3000-01-11',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$data = array_merge($this->credit->toArray(), $credit_update);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->putJson('/api/v1/credits/'.$this->encodePrimaryKey($this->credit->id), $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user