From bbb2f0b02b7acffe55fb29f7c8478dc6f782a04b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 24 Apr 2024 16:39:54 +1000 Subject: [PATCH 01/29] Fixes for validation on store payment prop --- .../Requests/Payment/StorePaymentRequest.php | 8 +++--- tests/Feature/PaymentTest.php | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index 8e40f0b3478f..152a8aecff43 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -45,12 +45,12 @@ class StorePaymentRequest extends Request $rules = [ 'client_id' => ['bail','required',Rule::exists('clients','id')->where('company_id',$user->company()->id)->where('is_deleted', 0)], - 'amount' => ['bail', 'numeric', new PaymentAmountsBalanceRule()], + 'invoices' => ['bail','sometimes', 'nullable', 'array', new ValidPayableInvoicesRule()], 'invoices.*.amount' => ['bail','required'], 'invoices.*.invoice_id' => ['bail','required','distinct', new ValidInvoicesRules($this->all()),Rule::exists('invoices','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)], 'credits.*.credit_id' => ['bail','required','distinct', new ValidCreditsRules($this->all()),Rule::exists('credits','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)], 'credits.*.amount' => ['bail','required', new CreditsSumRule($this->all())], - 'invoices' => ['bail','sometimes', 'nullable', 'array', new ValidPayableInvoicesRule()], + 'amount' => ['bail', 'numeric', new PaymentAmountsBalanceRule()], 'number' => ['bail', 'nullable', Rule::unique('payments')->where('company_id', $user->company()->id)], 'idempotency_key' => ['nullable', 'bail', 'string','max:64', Rule::unique('payments')->where('company_id', $user->company()->id)], ]; @@ -94,7 +94,7 @@ class StorePaymentRequest extends Request if (isset($input['invoices']) && is_array($input['invoices']) !== false) { foreach ($input['invoices'] as $key => $value) { - if (is_string($value['invoice_id'])) { + if (isset($value['invoice_id']) && is_string($value['invoice_id'])) { $input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($value['invoice_id']); } @@ -110,7 +110,7 @@ class StorePaymentRequest extends Request if (isset($input['credits']) && is_array($input['credits']) !== false) { foreach ($input['credits'] as $key => $value) { - if (array_key_exists('credit_id', $input['credits'][$key])) { + if (isset($value['credit_id']) && is_string($value['credit_id'])) { $input['credits'][$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']); $credits_total += $value['amount']; } diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 3dd9813def58..cf5816191f4d 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -62,6 +62,31 @@ class PaymentTest extends TestCase ); } + public function testInvoicesValidationProp() + { + + $data = [ + 'amount' => 5, + 'client_id' => $this->client->hashed_id, + 'invoices' => [ + [ + 'invoice_id:' => $this->invoice->hashed_id, + 'amount' => 5, + ], + ], + 'date' => '2020/12/11', + 'idempotency_key' => \Illuminate\Support\Str::uuid()->toString() + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/payments/', $data); + + $response->assertStatus(422); + + } + public function testClientIdValidation() { $p = Payment::factory()->create([ From b43a4ec866a54a18f743234716837c8bbbf65872 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 24 Apr 2024 16:51:03 +1000 Subject: [PATCH 02/29] Add new prop for company gateways table --- app/Factory/CompanyGatewayFactory.php | 3 +- app/Models/CompanyGateway.php | 3 ++ .../CompanyGatewayTransformer.php | 1 + ...splay_required_fields_payment_gateways.php | 28 +++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2024_04_24_064301_optional_display_required_fields_payment_gateways.php diff --git a/app/Factory/CompanyGatewayFactory.php b/app/Factory/CompanyGatewayFactory.php index c131d534b06c..ecb7b3934005 100644 --- a/app/Factory/CompanyGatewayFactory.php +++ b/app/Factory/CompanyGatewayFactory.php @@ -23,7 +23,8 @@ class CompanyGatewayFactory $company_gateway->require_billing_address = false; $company_gateway->require_shipping_address = false; $company_gateway->config = encrypt(json_encode(new \stdClass())); - + $company_gateway->always_show_required_fields = true; + return $company_gateway; } } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 5a3fd2ebaad1..530c0bb46196 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -47,6 +47,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property bool $require_custom_value2 * @property bool $require_custom_value3 * @property bool $require_custom_value4 + * @property bool $always_show_required_fields * @property-read int|null $client_gateway_tokens_count * @property-read \App\Models\Company $company * @property-read \App\Models\Gateway $gateway @@ -77,6 +78,7 @@ class CompanyGateway extends BaseModel 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', + 'always_show_required_fields' => 'bool', ]; protected $with = [ @@ -107,6 +109,7 @@ class CompanyGateway extends BaseModel 'custom_value4', 'token_billing', 'label', + 'always_show_required_fields', ]; public static $credit_cards = [ diff --git a/app/Transformers/CompanyGatewayTransformer.php b/app/Transformers/CompanyGatewayTransformer.php index aad31e10d3e4..d4143faf5818 100644 --- a/app/Transformers/CompanyGatewayTransformer.php +++ b/app/Transformers/CompanyGatewayTransformer.php @@ -80,6 +80,7 @@ class CompanyGatewayTransformer extends EntityTransformer 'label' => (string) $company_gateway->label ?: '', 'token_billing' => (string) $company_gateway->token_billing, 'test_mode' => (bool) $company_gateway->isTestMode(), + 'always_show_required_fields' => (bool) $company_gateway->always_show_required_fields, ]; } diff --git a/database/migrations/2024_04_24_064301_optional_display_required_fields_payment_gateways.php b/database/migrations/2024_04_24_064301_optional_display_required_fields_payment_gateways.php new file mode 100644 index 000000000000..3a16f3b79c9a --- /dev/null +++ b/database/migrations/2024_04_24_064301_optional_display_required_fields_payment_gateways.php @@ -0,0 +1,28 @@ +boolean('always_show_required_fields')->default(true); + }); + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; From 4dedfd616b63cefe1e64cf9159f10cfbc578a956 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 25 Apr 2024 06:50:55 +1000 Subject: [PATCH 03/29] filter for recurring invoice filters --- app/Filters/RecurringInvoiceFilters.php | 4 ++++ app/Http/Controllers/ClientController.php | 10 ++++++++++ app/Http/Requests/Client/BulkClientRequest.php | 17 +++++++++++++++-- app/Repositories/BaseRepository.php | 5 +++++ lang/bg/texts.php | 2 ++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/Filters/RecurringInvoiceFilters.php b/app/Filters/RecurringInvoiceFilters.php index 4917a12a1f10..b9124c9168cb 100644 --- a/app/Filters/RecurringInvoiceFilters.php +++ b/app/Filters/RecurringInvoiceFilters.php @@ -133,6 +133,10 @@ class RecurringInvoiceFilters extends QueryFilters return $this->builder->orderByRaw("REGEXP_REPLACE(number,'[^0-9]+','')+0 " . $dir); } + if($sort_col[0] == 'next_send_datetime'){ + $sort_col[0] = 'next_send_date'; + } + return $this->builder->orderBy($sort_col[0], $dir); } diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index e9e733191d5e..b8ba7573ad79 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -258,6 +258,16 @@ class ClientController extends BaseController } + if($action == 'bulk_update' && $user->can('edit', $clients->first())){ + + $clients = Client::withTrashed() + ->company() + ->whereIn('id', $request->ids); + + $this->client_repo->bulkUpdate($clients, $request->column, $request->new_value); + + } + $clients->each(function ($client) use ($action, $user) { if ($user->can('edit', $client)) { $this->client_repo->{$action}($client); diff --git a/app/Http/Requests/Client/BulkClientRequest.php b/app/Http/Requests/Client/BulkClientRequest.php index 1d61c0ddc7ae..b16fec93abb4 100644 --- a/app/Http/Requests/Client/BulkClientRequest.php +++ b/app/Http/Requests/Client/BulkClientRequest.php @@ -19,6 +19,17 @@ class BulkClientRequest extends Request { use MakesHash; + private array $bulk_update_columns = [ + 'public_notes', + 'industry_id', + 'size_id', + 'country_id', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + ]; + /** * Determine if the user is authorized to make this request. * @@ -35,12 +46,14 @@ class BulkClientRequest extends Request $user = auth()->user(); return [ - 'action' => 'required|string|in:archive,restore,delete,template,assign_group', + 'action' => 'required|string|in:archive,restore,delete,template,assign_group,bulk_update', 'ids' => ['required','bail','array',Rule::exists('clients', 'id')->where('company_id', $user->company()->id)], 'template' => 'sometimes|string', 'template_id' => 'sometimes|string', 'group_settings_id' => ['required_if:action,assign_group',Rule::exists('group_settings', 'id')->where('company_id', $user->company()->id)], - 'send_email' => 'sometimes|bool' + 'send_email' => 'sometimes|bool', + 'column' => ['required_if:action,bulk_update','string', Rule::in($this->client_bulk_update_columns)], + 'new_value' => ['required_id:action,bulk_update|string'], ]; } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index be0bfbf31b2a..ff2c6e1f8816 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -379,4 +379,9 @@ class BaseRepository return $model->fresh(); } + + public function bulkUpdate(\Illuminate\Database\Eloquent\Builder $model, string $column, mixed $new_value) :void + { + $model->update([$column => $new_value]); + } } diff --git a/lang/bg/texts.php b/lang/bg/texts.php index 602ace3c55e0..af87cbbca4f4 100644 --- a/lang/bg/texts.php +++ b/lang/bg/texts.php @@ -5296,6 +5296,8 @@ $lang = array( 'flutter_web_warning' => 'We recommend using the new web app or the desktop app for the best performance', 'rappen_rounding' => 'Rappen Rounding', 'rappen_rounding_help' => 'Round amount to 5 cents', + 'always_show_required_fields' => 'Always display required fields', + 'always_show_required_fields_help' => 'Will show the form regards if the fields are filled or not' ); return $lang; From 108ca2633db660270019d72c8657168402efe302 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 25 Apr 2024 16:31:15 +1000 Subject: [PATCH 04/29] Bulk updates --- app/Http/Controllers/ClientController.php | 2 ++ .../Requests/Client/BulkClientRequest.php | 15 ++--------- app/Models/Client.php | 15 +++++++---- .../EDocument/Standards/ZugferdEDokument.php | 7 ++++- app/Utils/Statics.php | 4 +++ tests/Feature/ClientApiTest.php | 27 +++++++++++++++++++ 6 files changed, 51 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index b8ba7573ad79..ffe011a6e3fc 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -266,6 +266,8 @@ class ClientController extends BaseController $this->client_repo->bulkUpdate($clients, $request->column, $request->new_value); + return $this->listResponse(Client::query()->withTrashed()->company()->whereIn('id', $request->ids)); + } $clients->each(function ($client) use ($action, $user) { diff --git a/app/Http/Requests/Client/BulkClientRequest.php b/app/Http/Requests/Client/BulkClientRequest.php index b16fec93abb4..31870f0e2752 100644 --- a/app/Http/Requests/Client/BulkClientRequest.php +++ b/app/Http/Requests/Client/BulkClientRequest.php @@ -18,17 +18,6 @@ use Illuminate\Validation\Rule; class BulkClientRequest extends Request { use MakesHash; - - private array $bulk_update_columns = [ - 'public_notes', - 'industry_id', - 'size_id', - 'country_id', - 'custom_value1', - 'custom_value2', - 'custom_value3', - 'custom_value4', - ]; /** * Determine if the user is authorized to make this request. @@ -52,8 +41,8 @@ class BulkClientRequest extends Request 'template_id' => 'sometimes|string', 'group_settings_id' => ['required_if:action,assign_group',Rule::exists('group_settings', 'id')->where('company_id', $user->company()->id)], 'send_email' => 'sometimes|bool', - 'column' => ['required_if:action,bulk_update','string', Rule::in($this->client_bulk_update_columns)], - 'new_value' => ['required_id:action,bulk_update|string'], + 'column' => ['required_if:action,bulk_update', 'string', Rule::in(\App\Models\Client::$bulk_update_columns)], + 'new_value' => ['required_if:action,bulk_update|string'], ]; } diff --git a/app/Models/Client.php b/app/Models/Client.php index 826b86ef1948..c34c16bf67ea 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -220,12 +220,17 @@ class Client extends BaseModel implements HasLocalePreference 'routing_id', ]; - // public function scopeExclude($query) - // { - // $query->makeHidden(['balance','paid_to_date']); + public static array $bulk_update_columns = [ + 'public_notes', + 'industry_id', + 'size_id', + 'country_id', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + ]; - // return $query; - // } public function getEntityType() { diff --git a/app/Services/EDocument/Standards/ZugferdEDokument.php b/app/Services/EDocument/Standards/ZugferdEDokument.php index ddb362bbee18..412825109496 100644 --- a/app/Services/EDocument/Standards/ZugferdEDokument.php +++ b/app/Services/EDocument/Standards/ZugferdEDokument.php @@ -102,7 +102,12 @@ class ZugferdEDokument extends AbstractService $this->xdocument->setDocumentShipToAddress($client->shipping_address1, $client->shipping_address2, "", $client->shipping_postal_code, $client->shipping_city, $client->shipping_country->iso_3166_2, $client->shipping_state); } - $this->xdocument->addDocumentPaymentMean(68, ctrans("texts.xinvoice_online_payment")); + //Payment Means - Switcher + if($company->settings->custom_value1 == '42'){ + $this->xdocument->addDocumentPaymentMean(typecode: 42, payeeIban: $company->settings->custom_value2, payeeAccountName: $company->settings->custom_value4, payeeBic: $company->settings->custom_value3); + } + else + $this->xdocument->addDocumentPaymentMean(68, ctrans("texts.xinvoice_online_payment")); if (str_contains($company->getSetting('vat_number'), "/")) { $this->xdocument->addDocumentSellerTaxRegistration("FC", $company->getSetting('vat_number')); diff --git a/app/Utils/Statics.php b/app/Utils/Statics.php index 54a32dd6d249..ee36bbd80b2b 100644 --- a/app/Utils/Statics.php +++ b/app/Utils/Statics.php @@ -127,6 +127,10 @@ class Statics $data['templates'] = Cache::get('templates'); } + $data['bulk_updates'] = [ + 'client' => \App\Models\Client::$bulk_update_columns, + ]; + return $data; } } diff --git a/tests/Feature/ClientApiTest.php b/tests/Feature/ClientApiTest.php index 6bbbfb2dcc52..eb3c18ad9d4d 100644 --- a/tests/Feature/ClientApiTest.php +++ b/tests/Feature/ClientApiTest.php @@ -59,6 +59,33 @@ class ClientApiTest extends TestCase Model::reguard(); } + public function testBulkUpdates() + { + Client::factory()->count(3)->create([ + "company_id" => $this->company->id, + "user_id" => $this->user->id, + ]); + + $client_count = Client::query()->where('company_id', $this->company->id)->count(); + + $data = [ + "column" => "public_notes", + "new_value" => "THISISABULKUPDATE", + "action" => "bulk_update", + "ids" => Client::where('company_id', $this->company->id)->get()->pluck("hashed_id") + ]; + + $response = $this->withHeaders([ + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/clients/bulk", $data); + + + $response->assertStatus(200); + + $this->assertEquals($client_count, Client::query()->where('public_notes', "THISISABULKUPDATE")->where('company_id', $this->company->id)->count()); + + } + public function testCountryCodeValidation() { From 50e211104d40bb5c66af6811eb52515b9dcfbb33 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 25 Apr 2024 17:46:11 +1000 Subject: [PATCH 05/29] Improvements for showing required fields --- app/Jobs/Mail/NinjaMailerJob.php | 3 +- app/Livewire/RequiredClientInfo.php | 121 ++++++++---------- .../livewire/required-client-info.blade.php | 2 +- 3 files changed, 58 insertions(+), 68 deletions(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index c02a751f6169..3f33759a0b17 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -77,6 +77,8 @@ class NinjaMailerJob implements ShouldQueue /*Set the correct database*/ MultiDB::setDb($this->nmo->company->db); +nlog("nn"); + /* Serializing models from other jobs wipes the primary key */ $this->company = Company::query()->where('company_key', $this->nmo->company->company_key)->first(); @@ -87,7 +89,6 @@ class NinjaMailerJob implements ShouldQueue if (!$this->company || $this->preFlightChecksFail()) { return; } - /* Run time we set Reply To Email*/ if (strlen($this->nmo->settings->reply_to_email) > 1) { if (property_exists($this->nmo->settings, 'reply_to_name')) { diff --git a/app/Livewire/RequiredClientInfo.php b/app/Livewire/RequiredClientInfo.php index 909c3462d318..a4327f95faa4 100644 --- a/app/Livewire/RequiredClientInfo.php +++ b/app/Livewire/RequiredClientInfo.php @@ -79,7 +79,8 @@ class RequiredClientInfo extends Component public $client_custom_value2; public $client_custom_value3; public $client_custom_value4; - + private ?CompanyGateway $company_gateway; + private int $unfilled_fields = 0; /** * Mappings for updating the database. Left side is mapping from gateway, @@ -194,6 +195,7 @@ class RequiredClientInfo extends Component MultiDB::setDb($this->db); $contact = ClientContact::withTrashed()->find($this->contact_id); $company = $contact->company; + $this->company_gateway = CompanyGateway::withTrashed()->find($this->company_gateway_id); $this->client_name = $contact->client->name; $this->contact_first_name = $contact->first_name; @@ -215,8 +217,6 @@ class RequiredClientInfo extends Component $this->client_custom_value3 = $contact->client->custom_value3; $this->client_custom_value4 = $contact->client->custom_value4; - // $this->client = $this->contact->client; - if ($company->settings->show_accept_invoice_terms && request()->query('hash')) { $this->show_terms = true; $this->terms_accepted = false; @@ -230,18 +230,12 @@ class RequiredClientInfo extends Component $this->invoice_terms = $invoice->terms; } - count($this->fields) > 0 || $this->show_terms - ? $this->checkFields() - : $this->show_form = false; + if(!$this->company_gateway->always_show_required_fields) + $this->checkFields(); - if (request()->query('source') === 'subscriptions') { - $this->show_form = false; + if($this->unfilled_fields > 0 || $this->company_gateway->always_show_required_fields) + $this->show_form = true; - $this->dispatch( - 'passed-required-fields-check', - client_postal_code: $this->contact->client->postal_code - ); - } } #[Computed] @@ -327,26 +321,26 @@ class RequiredClientInfo extends Component } -$_contact->first_name = $this->contact_first_name; -$_contact->last_name = $this->contact_last_name; -$_contact->client->name = $this->client_name; -$_contact->email = $this->contact_email; -$_contact->client->phone = $this->client_phone; -$_contact->client->address1 = $this->client_address_line_1; -$_contact->client->city = $this->client_city; -$_contact->client->state = $this->client_state; -$_contact->client->country_id = $this->client_country_id; -$_contact->client->postal_code = $this->client_postal_code; -$_contact->client->shipping_address1 = $this->client_shipping_address_line_1; -$_contact->client->shipping_city = $this->client_shipping_city; -$_contact->client->shipping_state = $this->client_shipping_state; -$_contact->client->shipping_postal_code = $this->client_shipping_postal_code; -$_contact->client->shipping_country_id = $this->client_shipping_country_id; -$_contact->client->custom_value1 = $this->client_custom_value1; -$_contact->client->custom_value2 = $this->client_custom_value2; -$_contact->client->custom_value3 = $this->client_custom_value3; -$_contact->client->custom_value4 = $this->client_custom_value4; -$_contact->push(); + $_contact->first_name = $this->contact_first_name; + $_contact->last_name = $this->contact_last_name; + $_contact->client->name = $this->client_name; + $_contact->email = $this->contact_email; + $_contact->client->phone = $this->client_phone; + $_contact->client->address1 = $this->client_address_line_1; + $_contact->client->city = $this->client_city; + $_contact->client->state = $this->client_state; + $_contact->client->country_id = $this->client_country_id; + $_contact->client->postal_code = $this->client_postal_code; + $_contact->client->shipping_address1 = $this->client_shipping_address_line_1; + $_contact->client->shipping_city = $this->client_shipping_city; + $_contact->client->shipping_state = $this->client_shipping_state; + $_contact->client->shipping_postal_code = $this->client_shipping_postal_code; + $_contact->client->shipping_country_id = $this->client_shipping_country_id; + $_contact->client->custom_value1 = $this->client_custom_value1; + $_contact->client->custom_value2 = $this->client_custom_value2; + $_contact->client->custom_value3 = $this->client_custom_value3; + $_contact->client->custom_value4 = $this->client_custom_value4; + $_contact->push(); $contact_update = $_contact @@ -378,44 +372,39 @@ $_contact->push(); public function checkFields() { - $this->show_form = true; -//@todo - need to make this optional - // MultiDB::setDb($this->db); - // $_contact = ClientContact::withTrashed()->find($this->contact_id); + MultiDB::setDb($this->db); + $_contact = ClientContact::withTrashed()->find($this->contact_id); - // foreach ($this->fields as $index => $field) { - // $_field = $this->mappings[$field['name']]; + foreach ($this->fields as $index => $field) { + $_field = $this->mappings[$field['name']]; - // if (Str::startsWith($field['name'], 'client_')) { - // if (empty($_contact->client->{$_field}) - // || is_null($_contact->client->{$_field}) - // // || in_array($_field, $this->client_address_array) - // ) { - // $this->show_form = true; - // } else { - // $this->fields[$index]['filled'] = true; - // } - // } + if (Str::startsWith($field['name'], 'client_')) { + if (empty($_contact->client->{$_field}) + || is_null($_contact->client->{$_field}) + ) { + // $this->show_form = true; + $this->unfilled_fields++; + } else { + // $this->fields[$index]['filled'] = true; + } + } - // if (Str::startsWith($field['name'], 'contact_')) { - // if (empty($_contact->{$_field}) || is_null($_contact->{$_field}) || str_contains($_contact->{$_field}, '@example.com')) { - // $this->show_form = true; - // } else { - // $this->fields[$index]['filled'] = true; - // } - // } - // } + if (Str::startsWith($field['name'], 'contact_')) { + if (empty($_contact->{$_field}) || is_null($_contact->{$_field}) || str_contains($_contact->{$_field}, '@example.com')) { + $this->unfilled_fields++; + } else { + // $this->fields[$index]['filled'] = true; + } + } + } - // $left = collect($this->fields) - // ->filter(fn ($field) => !array_key_exists('filled', $field)) - // ->count(); + if ($this->unfilled_fields === 0 && !$this->company_gateway->always_show_required_fields) { + $this->dispatch( + 'passed-required-fields-check', + client_postal_code: $this->contact->client->postal_code + ); + } - // if ($left === 0) { - // $this->dispatch( - // 'passed-required-fields-check', - // client_postal_code: $this->contact->client->postal_code - // ); - // } } public function showCopyBillingCheckbox(): bool diff --git a/resources/views/portal/ninja2020/components/livewire/required-client-info.blade.php b/resources/views/portal/ninja2020/components/livewire/required-client-info.blade.php index fd5b6b8bbf25..39aa9e1d4f72 100644 --- a/resources/views/portal/ninja2020/components/livewire/required-client-info.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/required-client-info.blade.php @@ -125,7 +125,7 @@ @if(!$show_form)