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

Validation layer for einvoicing

This commit is contained in:
David Bomba 2024-06-19 11:31:03 +10:00
parent 0c60a11989
commit bc6df79e2b
3 changed files with 102 additions and 41 deletions

View File

@ -11,12 +11,15 @@
namespace App\Http\Requests\Company; namespace App\Http\Requests\Company;
use App\DataMapper\CompanySettings;
use App\Http\Requests\Request;
use App\Http\ValidationRules\Company\ValidSubdomain;
use App\Http\ValidationRules\ValidSettingsRule;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Http\Requests\Request;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\DataMapper\CompanySettings;
use InvoiceNinja\EInvoice\EInvoice;
use App\Http\ValidationRules\ValidSettingsRule;
use InvoiceNinja\EInvoice\Models\Peppol\Invoice;
use App\Http\ValidationRules\EInvoice\ValidScheme;
use App\Http\ValidationRules\Company\ValidSubdomain;
class UpdateCompanyRequest extends Request class UpdateCompanyRequest extends Request
{ {
@ -64,6 +67,7 @@ class UpdateCompanyRequest extends Request
$rules['smtp_local_domain'] = 'sometimes|string|nullable'; $rules['smtp_local_domain'] = 'sometimes|string|nullable';
// $rules['smtp_verify_peer'] = 'sometimes|string'; // $rules['smtp_verify_peer'] = 'sometimes|string';
$rules['e_invoice'] = ['sometimes','nullable', new ValidScheme()];
if (isset($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) { if (isset($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) {
$rules['portal_domain'] = 'bail|nullable|sometimes|url'; $rules['portal_domain'] = 'bail|nullable|sometimes|url';
@ -113,11 +117,6 @@ class UpdateCompanyRequest extends Request
$input['smtp_verify_peer'] == 'true' ? true : false; $input['smtp_verify_peer'] == 'true' ? true : false;
} }
// if(isset($input['e_invoice'])){
// nlog("am i set?");
// $r = FatturaElettronica::validate($input['e_invoice']);
// }
$this->replace($input); $this->replace($input);
} }

View File

@ -0,0 +1,62 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*1`
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\ValidationRules\EInvoice;
use Closure;
use InvoiceNinja\EInvoice\EInvoice;
use Illuminate\Validation\Validator;
use InvoiceNinja\EInvoice\Models\Peppol\Invoice;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Contracts\Validation\ValidatorAwareRule;
/**
* Class BlackListRule.
*/
class ValidScheme implements ValidationRule, ValidatorAwareRule
{
/**
* The validator instance.
*
* @var Validator
*/
protected $validator;
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$r = new EInvoice();
$errors = $r->validateRequest($value['Invoice'], Invoice::class);
foreach ($errors as $key => $msg) {
$this->validator->errors()->add(
"e_invoice.{$key}",
"{$key} - {$msg}"
);
}
}
/**
* Set the current validator.
*/
public function setValidator(Validator $validator): static
{
$this->validator = $validator;
return $this;
}
}

64
composer.lock generated
View File

@ -526,16 +526,16 @@
}, },
{ {
"name": "aws/aws-sdk-php", "name": "aws/aws-sdk-php",
"version": "3.314.3", "version": "3.314.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/aws/aws-sdk-php.git", "url": "https://github.com/aws/aws-sdk-php.git",
"reference": "c9e8a31cfa07f47b7ab9ecc741845a3a9d50fc61" "reference": "fd1261a60495a7aeb2661d8b7eecfd5fc16abd41"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/c9e8a31cfa07f47b7ab9ecc741845a3a9d50fc61", "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/fd1261a60495a7aeb2661d8b7eecfd5fc16abd41",
"reference": "c9e8a31cfa07f47b7ab9ecc741845a3a9d50fc61", "reference": "fd1261a60495a7aeb2661d8b7eecfd5fc16abd41",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -615,9 +615,9 @@
"support": { "support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues", "issues": "https://github.com/aws/aws-sdk-php/issues",
"source": "https://github.com/aws/aws-sdk-php/tree/3.314.3" "source": "https://github.com/aws/aws-sdk-php/tree/3.314.4"
}, },
"time": "2024-06-17T18:13:22+00:00" "time": "2024-06-18T18:13:34+00:00"
}, },
{ {
"name": "bacon/bacon-qr-code", "name": "bacon/bacon-qr-code",
@ -4173,12 +4173,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/invoiceninja/einvoice.git", "url": "https://github.com/invoiceninja/einvoice.git",
"reference": "c26ae46a132b00d9cba5b047218f530ae660ccc7" "reference": "468a2a3696e76b1216a129e79177eb7c16ea9bdb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/invoiceninja/einvoice/zipball/c26ae46a132b00d9cba5b047218f530ae660ccc7", "url": "https://api.github.com/repos/invoiceninja/einvoice/zipball/468a2a3696e76b1216a129e79177eb7c16ea9bdb",
"reference": "c26ae46a132b00d9cba5b047218f530ae660ccc7", "reference": "468a2a3696e76b1216a129e79177eb7c16ea9bdb",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4220,7 +4220,7 @@
"source": "https://github.com/invoiceninja/einvoice/tree/main", "source": "https://github.com/invoiceninja/einvoice/tree/main",
"issues": "https://github.com/invoiceninja/einvoice/issues" "issues": "https://github.com/invoiceninja/einvoice/issues"
}, },
"time": "2024-06-12T06:01:18+00:00" "time": "2024-06-19T00:29:39+00:00"
}, },
{ {
"name": "invoiceninja/inspector", "name": "invoiceninja/inspector",
@ -4725,16 +4725,16 @@
}, },
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v10.48.12", "version": "v10.48.13",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/framework.git", "url": "https://github.com/laravel/framework.git",
"reference": "590afea38e708022662629fbf5184351fa82cf08" "reference": "2c6816d697a4362c09c066118addda251b70b98a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/590afea38e708022662629fbf5184351fa82cf08", "url": "https://api.github.com/repos/laravel/framework/zipball/2c6816d697a4362c09c066118addda251b70b98a",
"reference": "590afea38e708022662629fbf5184351fa82cf08", "reference": "2c6816d697a4362c09c066118addda251b70b98a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4928,20 +4928,20 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-05-28T15:46:19+00:00" "time": "2024-06-18T16:46:35+00:00"
}, },
{ {
"name": "laravel/prompts", "name": "laravel/prompts",
"version": "v0.1.23", "version": "v0.1.24",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/prompts.git", "url": "https://github.com/laravel/prompts.git",
"reference": "9bc4df7c699b0452c6b815e64a2d84b6d7f99400" "reference": "409b0b4305273472f3754826e68f4edbd0150149"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/prompts/zipball/9bc4df7c699b0452c6b815e64a2d84b6d7f99400", "url": "https://api.github.com/repos/laravel/prompts/zipball/409b0b4305273472f3754826e68f4edbd0150149",
"reference": "9bc4df7c699b0452c6b815e64a2d84b6d7f99400", "reference": "409b0b4305273472f3754826e68f4edbd0150149",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4984,9 +4984,9 @@
"description": "Add beautiful and user-friendly forms to your command-line applications.", "description": "Add beautiful and user-friendly forms to your command-line applications.",
"support": { "support": {
"issues": "https://github.com/laravel/prompts/issues", "issues": "https://github.com/laravel/prompts/issues",
"source": "https://github.com/laravel/prompts/tree/v0.1.23" "source": "https://github.com/laravel/prompts/tree/v0.1.24"
}, },
"time": "2024-05-27T13:53:20+00:00" "time": "2024-06-17T13:58:22+00:00"
}, },
{ {
"name": "laravel/serializable-closure", "name": "laravel/serializable-closure",
@ -5111,16 +5111,16 @@
}, },
{ {
"name": "laravel/socialite", "name": "laravel/socialite",
"version": "v5.14.0", "version": "v5.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/socialite.git", "url": "https://github.com/laravel/socialite.git",
"reference": "c7b0193a3753a29aff8ce80aa2f511917e6ed68a" "reference": "c8234bfb286a8210df8d62f94562c71bfda4a446"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/socialite/zipball/c7b0193a3753a29aff8ce80aa2f511917e6ed68a", "url": "https://api.github.com/repos/laravel/socialite/zipball/c8234bfb286a8210df8d62f94562c71bfda4a446",
"reference": "c7b0193a3753a29aff8ce80aa2f511917e6ed68a", "reference": "c8234bfb286a8210df8d62f94562c71bfda4a446",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -5179,7 +5179,7 @@
"issues": "https://github.com/laravel/socialite/issues", "issues": "https://github.com/laravel/socialite/issues",
"source": "https://github.com/laravel/socialite" "source": "https://github.com/laravel/socialite"
}, },
"time": "2024-05-03T20:31:38+00:00" "time": "2024-06-11T13:33:20+00:00"
}, },
{ {
"name": "laravel/tinker", "name": "laravel/tinker",
@ -6178,16 +6178,16 @@
}, },
{ {
"name": "livewire/livewire", "name": "livewire/livewire",
"version": "v3.5.0", "version": "v3.5.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/livewire/livewire.git", "url": "https://github.com/livewire/livewire.git",
"reference": "72e900825c560f0e4e620185b26c5441a8914435" "reference": "da044261bb5c5449397f18fda3409f14acf47c0a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/livewire/livewire/zipball/72e900825c560f0e4e620185b26c5441a8914435", "url": "https://api.github.com/repos/livewire/livewire/zipball/da044261bb5c5449397f18fda3409f14acf47c0a",
"reference": "72e900825c560f0e4e620185b26c5441a8914435", "reference": "da044261bb5c5449397f18fda3409f14acf47c0a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -6242,7 +6242,7 @@
"description": "A front-end framework for Laravel.", "description": "A front-end framework for Laravel.",
"support": { "support": {
"issues": "https://github.com/livewire/livewire/issues", "issues": "https://github.com/livewire/livewire/issues",
"source": "https://github.com/livewire/livewire/tree/v3.5.0" "source": "https://github.com/livewire/livewire/tree/v3.5.1"
}, },
"funding": [ "funding": [
{ {
@ -6250,7 +6250,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-05-21T13:39:04+00:00" "time": "2024-06-18T11:10:42+00:00"
}, },
{ {
"name": "maennchen/zipstream-php", "name": "maennchen/zipstream-php",