From 42da98a132bb9e5c8f1804ecb6447586d36e1193 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 8 Jul 2024 11:25:28 +1000 Subject: [PATCH 1/3] E Invoice Validation --- .../Requests/Company/UpdateCompanyRequest.php | 6 +- ...ValidScheme.php => ValidCompanyScheme.php} | 7 +- .../Validation/Peppol/CompanyLevel.php | 303 ++++++++++++++++++ 3 files changed, 309 insertions(+), 7 deletions(-) rename app/Http/ValidationRules/EInvoice/{ValidScheme.php => ValidCompanyScheme.php} (83%) create mode 100644 app/Services/EDocument/Standards/Validation/Peppol/CompanyLevel.php diff --git a/app/Http/Requests/Company/UpdateCompanyRequest.php b/app/Http/Requests/Company/UpdateCompanyRequest.php index d69ac24a9c85..c48ee397ee0e 100644 --- a/app/Http/Requests/Company/UpdateCompanyRequest.php +++ b/app/Http/Requests/Company/UpdateCompanyRequest.php @@ -15,10 +15,8 @@ use App\Utils\Ninja; use App\Http\Requests\Request; 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\EInvoice\ValidCompanyScheme; use App\Http\ValidationRules\Company\ValidSubdomain; class UpdateCompanyRequest extends Request @@ -67,7 +65,7 @@ class UpdateCompanyRequest extends Request $rules['smtp_local_domain'] = 'sometimes|string|nullable'; // $rules['smtp_verify_peer'] = 'sometimes|string'; - // $rules['e_invoice'] = ['sometimes','nullable', new ValidScheme()]; + $rules['e_invoice'] = ['sometimes','nullable', new ValidCompanyScheme()]; if (isset($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) { $rules['portal_domain'] = 'bail|nullable|sometimes|url'; diff --git a/app/Http/ValidationRules/EInvoice/ValidScheme.php b/app/Http/ValidationRules/EInvoice/ValidCompanyScheme.php similarity index 83% rename from app/Http/ValidationRules/EInvoice/ValidScheme.php rename to app/Http/ValidationRules/EInvoice/ValidCompanyScheme.php index bdd7a450df57..bd5777bf30ea 100644 --- a/app/Http/ValidationRules/EInvoice/ValidScheme.php +++ b/app/Http/ValidationRules/EInvoice/ValidCompanyScheme.php @@ -11,6 +11,7 @@ namespace App\Http\ValidationRules\EInvoice; +use App\Services\EDocument\Standards\Validation\Peppol\CompanyLevel; use Closure; use InvoiceNinja\EInvoice\EInvoice; use Illuminate\Validation\Validator; @@ -19,9 +20,9 @@ use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Contracts\Validation\ValidatorAwareRule; /** - * Class BlackListRule. + * Class ValidScheme. */ -class ValidScheme implements ValidationRule, ValidatorAwareRule +class ValidCompanyScheme implements ValidationRule, ValidatorAwareRule { /** @@ -35,7 +36,7 @@ class ValidScheme implements ValidationRule, ValidatorAwareRule { $r = new EInvoice(); - $errors = $r->validateRequest($value['Invoice'], Invoice::class); + $errors = $r->validateRequest($value['Invoice'], CompanyLevel::class); foreach ($errors as $key => $msg) { diff --git a/app/Services/EDocument/Standards/Validation/Peppol/CompanyLevel.php b/app/Services/EDocument/Standards/Validation/Peppol/CompanyLevel.php new file mode 100644 index 000000000000..9de7f548e714 --- /dev/null +++ b/app/Services/EDocument/Standards/Validation/Peppol/CompanyLevel.php @@ -0,0 +1,303 @@ + 'Y-m-d'])] + // #[SerializedName('cbc:IssueDate')] + // public ?DateTime $IssueDate; + + // /** @var ?\DateTime */ + // #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d\TH:i:s.uP'])] + // #[SerializedName('cbc:IssueTime')] + // public ?DateTime $IssueTime; + + // /** @var ?\DateTime */ + // #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])] + // #[SerializedName('cbc:DueDate')] + // public ?DateTime $DueDate; + + /** @var InvoiceTypeCode */ + #[SerializedName('cbc:InvoiceTypeCode')] + public $InvoiceTypeCode; + + /** @var string */ + #[SerializedName('cbc:Note')] + public string $Note; + + /** @var ?\DateTime */ + #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])] + #[SerializedName('cbc:TaxPointDate')] + public ?DateTime $TaxPointDate; + + /** @var DocumentCurrencyCode */ + #[SerializedName('cbc:DocumentCurrencyCode')] + public $DocumentCurrencyCode; + + /** @var TaxCurrencyCode */ + #[SerializedName('cbc:TaxCurrencyCode')] + public $TaxCurrencyCode; + + /** @var PricingCurrencyCode */ + #[SerializedName('cbc:PricingCurrencyCode')] + public $PricingCurrencyCode; + + /** @var PaymentCurrencyCode */ + #[SerializedName('cbc:PaymentCurrencyCode')] + public $PaymentCurrencyCode; + + /** @var PaymentAlternativeCurrencyCode */ + #[SerializedName('cbc:PaymentAlternativeCurrencyCode')] + public $PaymentAlternativeCurrencyCode; + + // /** @var AccountingCostCode */ + // #[SerializedName('cbc:AccountingCostCode')] + // public $AccountingCostCode; + + // /** @var string */ + // #[SerializedName('cbc:AccountingCost')] + // public string $AccountingCost; + + // /** @var LineCountNumeric */ + // #[SerializedName('cbc:LineCountNumeric')] + // public $LineCountNumeric; + + // /** @var string */ + // #[SerializedName('cbc:BuyerReference')] + // public string $BuyerReference; + + // /** @var InvoicePeriod[] */ + // #[SerializedName('cac:InvoicePeriod')] + // public array $InvoicePeriod; + + // /** @var OrderReference */ + // #[SerializedName('cac:OrderReference')] + // public $OrderReference; + + // /** @var BillingReference[] */ + // #[SerializedName('cac:BillingReference')] + // public array $BillingReference; + + /** @var DespatchDocumentReference[] */ + #[SerializedName('cac:DespatchDocumentReference')] + public array $DespatchDocumentReference; + + /** @var ReceiptDocumentReference[] */ + #[SerializedName('cac:ReceiptDocumentReference')] + public array $ReceiptDocumentReference; + + /** @var StatementDocumentReference[] */ + #[SerializedName('cac:StatementDocumentReference')] + public array $StatementDocumentReference; + + /** @var OriginatorDocumentReference[] */ + #[SerializedName('cac:OriginatorDocumentReference')] + public array $OriginatorDocumentReference; + + /** @var ContractDocumentReference[] */ + #[SerializedName('cac:ContractDocumentReference')] + public array $ContractDocumentReference; + + /** @var AdditionalDocumentReference[] */ + #[SerializedName('cac:AdditionalDocumentReference')] + public array $AdditionalDocumentReference; + + /** @var ProjectReference[] */ + #[SerializedName('cac:ProjectReference')] + public array $ProjectReference; + + // /** @var Signature[] */ + // #[SerializedName('cac:Signature')] + // public array $Signature; + + // /** @var AccountingSupplierParty */ + // #[NotNull] + // #[NotBlank] + // #[Valid] + // #[SerializedName('cac:AccountingSupplierParty')] + // public $AccountingSupplierParty; + + // /** @var AccountingCustomerParty */ + // #[NotNull] + // #[NotBlank] + // #[Valid] + // #[SerializedName('cac:AccountingCustomerParty')] + // public $AccountingCustomerParty; + + /** @var PayeeParty */ + #[SerializedName('cac:PayeeParty')] + public $PayeeParty; + + // /** @var BuyerCustomerParty */ + // #[SerializedName('cac:BuyerCustomerParty')] + // public $BuyerCustomerParty; + + // /** @var SellerSupplierParty */ + // #[SerializedName('cac:SellerSupplierParty')] + // public $SellerSupplierParty; + + /** @var TaxRepresentativeParty */ + #[SerializedName('cac:TaxRepresentativeParty')] + public $TaxRepresentativeParty; + + /** @var Delivery[] */ + #[SerializedName('cac:Delivery')] + public array $Delivery; + + /** @var DeliveryTerms */ + #[SerializedName('cac:DeliveryTerms')] + public $DeliveryTerms; + + /** @var PaymentMeans[] */ + #[SerializedName('cac:PaymentMeans')] + public array $PaymentMeans; + + /** @var PaymentTerms[] */ + #[SerializedName('cac:PaymentTerms')] + public array $PaymentTerms; + + // /** @var PrepaidPayment[] */ + // #[SerializedName('cac:PrepaidPayment')] + // public array $PrepaidPayment; + + // /** @var AllowanceCharge[] */ + // #[SerializedName('cac:AllowanceCharge')] + // public array $AllowanceCharge; + + // /** @var TaxExchangeRate */ + // #[SerializedName('cac:TaxExchangeRate')] + // public $TaxExchangeRate; + + // /** @var PricingExchangeRate */ + // #[SerializedName('cac:PricingExchangeRate')] + // public $PricingExchangeRate; + + // /** @var PaymentExchangeRate */ + // #[SerializedName('cac:PaymentExchangeRate')] + // public $PaymentExchangeRate; + + // /** @var PaymentAlternativeExchangeRate */ + // #[SerializedName('cac:PaymentAlternativeExchangeRate')] + // public $PaymentAlternativeExchangeRate; + + // /** @var TaxTotal[] */ + // #[SerializedName('cac:TaxTotal')] + // public array $TaxTotal; + + // /** @var WithholdingTaxTotal[] */ + // #[SerializedName('cac:WithholdingTaxTotal')] + // public array $WithholdingTaxTotal; + + // /** @var LegalMonetaryTotal */ + // #[NotNull] + // #[NotBlank] + // #[Valid] + // #[SerializedName('cac:LegalMonetaryTotal')] + // public $LegalMonetaryTotal; + + // /** @var InvoiceLine[] */ + // #[NotNull] + // #[NotBlank] + // #[Valid] + // #[SerializedName('cac:InvoiceLine')] + // public array $InvoiceLine; +} From 045dbac6ff8011c065ce9617924ef0dfeefc1c57 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 9 Jul 2024 07:32:13 +1000 Subject: [PATCH 2/3] Updates for check_version --- app/Http/Controllers/SelfUpdateController.php | 3 ++ app/Repositories/VendorRepository.php | 8 +--- app/Services/Client/ClientService.php | 2 +- app/Services/Vendor/VendorService.php | 45 +++++++++++++++++++ 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/SelfUpdateController.php b/app/Http/Controllers/SelfUpdateController.php index d25b056a0e1a..3c7caf650ed9 100644 --- a/app/Http/Controllers/SelfUpdateController.php +++ b/app/Http/Controllers/SelfUpdateController.php @@ -181,6 +181,9 @@ class SelfUpdateController extends BaseController public function checkVersion() { + if(Ninja::isHosted()) + return '5.10.SaaS'; + return trim(file_get_contents(config('ninja.version_url'))); } diff --git a/app/Repositories/VendorRepository.php b/app/Repositories/VendorRepository.php index a957c92a9074..de1b998b188f 100644 --- a/app/Repositories/VendorRepository.php +++ b/app/Repositories/VendorRepository.php @@ -53,12 +53,8 @@ class VendorRepository extends BaseRepository $vendor->saveQuietly(); - if ($vendor->number == '' || ! $vendor->number) { - $vendor->number = $this->getNextVendorNumber($vendor); - } - - $vendor->saveQuietly(); - + $vendor->service()->applyNumber(); + if (isset($data['contacts']) || $vendor->contacts()->count() == 0) { $this->contact_repo->save($data, $vendor); } diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index b792d44bf35f..e2a4eddfa44a 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -169,7 +169,7 @@ class ClientService } catch (QueryException $e) { $x++; - if ($x > 10) { + if ($x > 50) { $this->completed = false; } } diff --git a/app/Services/Vendor/VendorService.php b/app/Services/Vendor/VendorService.php index 4d319430ecac..5d4bb5bd6dee 100644 --- a/app/Services/Vendor/VendorService.php +++ b/app/Services/Vendor/VendorService.php @@ -12,10 +12,55 @@ namespace App\Services\Vendor; use App\Models\Vendor; +use App\Utils\Traits\GeneratesCounter; +use Illuminate\Database\QueryException; class VendorService { + + use GeneratesCounter; + + private bool $completed = true; + public function __construct(public Vendor $vendor) { } + + public function applyNumber(): self + { + $x = 1; + + if(isset($this->vendor->number)) { + return $this; + } + + do { + try { + $this->vendor->number = $this->getNextVendorNumber($this->vendor); + $this->vendor->saveQuietly(); + + $this->completed = false; + } catch (QueryException $e) { + $x++; + + if ($x > 50) { + $this->completed = false; + } + } + } while ($this->completed); + + return $this; + } + + /** + * Saves the vendor instance + * + * @return Vendor The Vendor Model + */ + public function save(): Vendor + { + $this->vendor->saveQuietly(); + + return $this->vendor->fresh(); + } } From a9759edcca926320db4de5b11af8d3d575f2dac1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 9 Jul 2024 08:04:39 +1000 Subject: [PATCH 3/3] Fixes for react build --- .github/workflows/react_release.yml | 1 + VERSION.txt | 2 +- config/ninja.php | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/react_release.yml b/.github/workflows/react_release.yml index bce78bb249c3..c4d6f63994aa 100644 --- a/.github/workflows/react_release.yml +++ b/.github/workflows/react_release.yml @@ -44,6 +44,7 @@ jobs: git clone https://${{secrets.commit_secret}}@github.com/invoiceninja/ui.git cd ui git checkout develop + cp .env.example .env cp ../vite.config.ts.react ./vite.config.js npm i npm run build diff --git a/VERSION.txt b/VERSION.txt index a16dcb354a2b..d591e33ef383 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.10.5 \ No newline at end of file +5.10.6 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index e77809a3f432..889fffe9fcbc 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -17,8 +17,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => env('APP_VERSION', '5.10.5'), - 'app_tag' => env('APP_TAG', '5.10.5'), + 'app_version' => env('APP_VERSION', '5.10.6'), + 'app_tag' => env('APP_TAG', '5.10.6'), 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false),