2021-01-12 15:43:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-01-12 15:43:07 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-01-12 15:43:07 +01:00
|
|
|
*/
|
|
|
|
|
2023-12-13 17:52:49 +01:00
|
|
|
namespace App\Livewire;
|
2021-01-12 15:43:07 +01:00
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
use App\Models\Invoice;
|
|
|
|
use Livewire\Component;
|
2021-06-07 03:06:31 +02:00
|
|
|
use App\Libraries\MultiDB;
|
2024-03-11 03:35:16 +01:00
|
|
|
use Illuminate\Support\Str;
|
2021-01-12 16:30:11 +01:00
|
|
|
use App\Models\ClientContact;
|
2022-09-13 01:59:16 +02:00
|
|
|
use App\Models\CompanyGateway;
|
2023-02-02 04:56:05 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2024-03-11 03:35:16 +01:00
|
|
|
use Livewire\Attributes\Computed;
|
2023-02-02 04:56:05 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2021-01-12 15:43:07 +01:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
|
|
class RequiredClientInfo extends Component
|
|
|
|
{
|
2023-02-02 04:56:05 +01:00
|
|
|
use MakesHash;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $show_terms = false;
|
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
public $invoice_terms;
|
2023-02-02 04:56:05 +01:00
|
|
|
|
2023-02-02 08:19:37 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $terms_accepted = true;
|
2023-02-02 04:56:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2021-01-12 15:43:07 +01:00
|
|
|
public $fields = [];
|
|
|
|
|
2021-01-12 16:30:11 +01:00
|
|
|
/**
|
|
|
|
* @var ClientContact
|
|
|
|
*/
|
2024-03-11 03:35:16 +01:00
|
|
|
public $contact_id;
|
2021-01-12 16:23:39 +01:00
|
|
|
|
2023-02-02 04:56:05 +01:00
|
|
|
/**
|
2023-08-07 00:23:13 +02:00
|
|
|
* @var \App\Models\Client
|
2023-02-02 04:56:05 +01:00
|
|
|
*/
|
2024-03-11 03:35:16 +01:00
|
|
|
public $client_id;
|
2022-03-08 13:33:20 +01:00
|
|
|
|
2021-01-19 14:36:07 +01:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $countries;
|
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
|
|
|
|
public $client_name;
|
|
|
|
public $contact_first_name;
|
|
|
|
public $contact_last_name;
|
|
|
|
public $contact_email;
|
|
|
|
public $client_phone;
|
|
|
|
public $client_address_line_1;
|
|
|
|
public $client_city;
|
|
|
|
public $client_state;
|
|
|
|
public $client_country_id;
|
|
|
|
public $client_postal_code;
|
|
|
|
public $client_shipping_address_line_1;
|
|
|
|
public $client_shipping_city;
|
|
|
|
public $client_shipping_state;
|
|
|
|
public $client_shipping_postal_code;
|
|
|
|
public $client_shipping_country_id;
|
|
|
|
public $client_custom_value1;
|
|
|
|
public $client_custom_value2;
|
|
|
|
public $client_custom_value3;
|
|
|
|
public $client_custom_value4;
|
2024-04-25 09:46:11 +02:00
|
|
|
private ?CompanyGateway $company_gateway;
|
|
|
|
private int $unfilled_fields = 0;
|
2024-03-11 03:35:16 +01:00
|
|
|
|
2021-01-12 16:30:11 +01:00
|
|
|
/**
|
|
|
|
* Mappings for updating the database. Left side is mapping from gateway,
|
|
|
|
* right side is column in database.
|
|
|
|
*
|
|
|
|
* @var string[]
|
|
|
|
*/
|
2021-01-12 16:23:39 +01:00
|
|
|
private $mappings = [
|
|
|
|
'client_name' => 'name',
|
2021-01-12 16:30:11 +01:00
|
|
|
'client_website' => 'website',
|
|
|
|
'client_phone' => 'phone',
|
|
|
|
|
|
|
|
'client_address_line_1' => 'address1',
|
|
|
|
'client_address_line_2' => 'address2',
|
|
|
|
'client_city' => 'city',
|
|
|
|
'client_state' => 'state',
|
|
|
|
'client_postal_code' => 'postal_code',
|
|
|
|
'client_country_id' => 'country_id',
|
|
|
|
|
|
|
|
'client_shipping_address_line_1' => 'shipping_address1',
|
|
|
|
'client_shipping_address_line_2' => 'shipping_address2',
|
|
|
|
'client_shipping_city' => 'shipping_city',
|
|
|
|
'client_shipping_state' => 'shipping_state',
|
|
|
|
'client_shipping_postal_code' => 'shipping_postal_code',
|
|
|
|
'client_shipping_country_id' => 'shipping_country_id',
|
|
|
|
|
2023-02-02 08:19:37 +01:00
|
|
|
'client_custom_value1' => 'custom_value1',
|
|
|
|
'client_custom_value2' => 'custom_value2',
|
|
|
|
'client_custom_value3' => 'custom_value3',
|
|
|
|
'client_custom_value4' => 'custom_value4',
|
|
|
|
|
2021-01-12 16:30:11 +01:00
|
|
|
'contact_first_name' => 'first_name',
|
|
|
|
'contact_last_name' => 'last_name',
|
2021-11-28 21:43:54 +01:00
|
|
|
'contact_email' => 'email',
|
2021-11-24 04:31:05 +01:00
|
|
|
// 'contact_phone' => 'phone',
|
2021-01-12 16:23:39 +01:00
|
|
|
];
|
|
|
|
|
2022-03-08 13:09:20 +01:00
|
|
|
public $client_address_array = [
|
2022-03-08 13:33:20 +01:00
|
|
|
'address1',
|
|
|
|
'address2',
|
2022-03-08 13:09:20 +01:00
|
|
|
'city',
|
|
|
|
'state',
|
|
|
|
'postal_code',
|
|
|
|
'country_id',
|
2022-07-14 13:29:17 +02:00
|
|
|
'shipping_address1',
|
|
|
|
'shipping_address2',
|
|
|
|
'shipping_city',
|
|
|
|
'shipping_state',
|
|
|
|
'shipping_postal_code',
|
2022-07-14 02:39:55 +02:00
|
|
|
'shipping_country_id',
|
2022-03-08 13:09:20 +01:00
|
|
|
];
|
|
|
|
|
2022-03-08 13:33:20 +01:00
|
|
|
protected $rules = [
|
2024-03-11 03:35:16 +01:00
|
|
|
// 'client.address1' => '',
|
|
|
|
// 'client.address2' => '',
|
|
|
|
// 'client.city' => '',
|
|
|
|
// 'client.state' => '',
|
|
|
|
// 'client.postal_code' => '',
|
|
|
|
// 'client.country_id' => '',
|
|
|
|
// 'client.shipping_address1' => '',
|
|
|
|
// 'client.shipping_address2' => '',
|
|
|
|
// 'client.shipping_city' => '',
|
|
|
|
// 'client.shipping_state' => '',
|
|
|
|
// 'client.shipping_postal_code' => '',
|
|
|
|
// 'client.shipping_country_id' => '',
|
|
|
|
// 'contact.first_name' => '',
|
|
|
|
// 'contact.last_name' => '',
|
|
|
|
// 'contact.email' => '',
|
|
|
|
// 'client.name' => '',
|
|
|
|
// 'client.website' => '',
|
|
|
|
// 'client.phone' => '',
|
|
|
|
// 'client.custom_value1' => '',
|
|
|
|
// 'client.custom_value2' => '',
|
|
|
|
// 'client.custom_value3' => '',
|
|
|
|
// 'client.custom_value4' => '',
|
|
|
|
'client_name' => '',
|
|
|
|
'client_website' => '',
|
|
|
|
'client_phone' => '',
|
|
|
|
'client_address_line_1' => '',
|
|
|
|
'client_address_line_2' => '',
|
|
|
|
'client_city' => '',
|
|
|
|
'client_state' => '',
|
|
|
|
'client_postal_code' => '',
|
|
|
|
'client_country_id' => '',
|
|
|
|
'client_shipping_address_line_1' => '',
|
|
|
|
'client_shipping_address_line_2' => '',
|
|
|
|
'client_shipping_city' => '',
|
|
|
|
'client_shipping_state' => '',
|
|
|
|
'client_shipping_postal_code' => '',
|
|
|
|
'client_shipping_country_id' => '',
|
|
|
|
'client_custom_value1' => '',
|
|
|
|
'client_custom_value2' => '',
|
|
|
|
'client_custom_value3' => '',
|
|
|
|
'client_custom_value4' => '',
|
|
|
|
'contact_first_name' => '',
|
|
|
|
'contact_last_name' => '',
|
|
|
|
'contact_email' => '',
|
2022-03-08 13:33:20 +01:00
|
|
|
];
|
|
|
|
|
2021-01-19 14:36:07 +01:00
|
|
|
public $show_form = false;
|
2021-01-13 13:31:00 +01:00
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
public $company_id;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-09-13 01:59:16 +02:00
|
|
|
public $company_gateway_id;
|
|
|
|
|
2024-02-22 14:07:34 +01:00
|
|
|
public bool $form_only = false;
|
2024-04-02 13:12:30 +02:00
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
public $db;
|
2024-02-22 14:07:34 +01:00
|
|
|
|
2024-05-09 00:53:45 +02:00
|
|
|
public bool $is_subscription = false;
|
|
|
|
|
2021-06-07 03:06:31 +02:00
|
|
|
public function mount()
|
|
|
|
{
|
2024-06-15 08:51:34 +02:00
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
MultiDB::setDb($this->db);
|
2024-06-15 08:51:34 +02:00
|
|
|
$contact = ClientContact::withTrashed()->with(['client' => function ($query) {
|
|
|
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
|
|
|
}])->find($this->contact_id);
|
|
|
|
|
|
|
|
$this->company_gateway = CompanyGateway::withTrashed()->with('company')->find($this->company_gateway_id);
|
|
|
|
$company = $this->company_gateway->company;
|
2024-03-11 03:35:16 +01:00
|
|
|
|
|
|
|
$this->client_name = $contact->client->name;
|
|
|
|
$this->contact_first_name = $contact->first_name;
|
|
|
|
$this->contact_last_name = $contact->last_name;
|
|
|
|
$this->contact_email = $contact->email;
|
|
|
|
$this->client_phone = $contact->client->phone;
|
|
|
|
$this->client_address_line_1 = $contact->client->address1;
|
|
|
|
$this->client_city = $contact->client->city ;
|
|
|
|
$this->client_state = $contact->client->state;
|
|
|
|
$this->client_country_id = $contact->client->country_id;
|
|
|
|
$this->client_postal_code = $contact->client->postal_code;
|
|
|
|
$this->client_shipping_address_line_1 = $contact->client->shipping_address1;
|
|
|
|
$this->client_shipping_city = $contact->client->shipping_city;
|
|
|
|
$this->client_shipping_state = $contact->client->shipping_state;
|
|
|
|
$this->client_shipping_postal_code = $contact->client->shipping_postal_code;
|
|
|
|
$this->client_shipping_country_id = $contact->client->shipping_country_id;
|
|
|
|
$this->client_custom_value1 = $contact->client->custom_value1;
|
|
|
|
$this->client_custom_value2 = $contact->client->custom_value2;
|
|
|
|
$this->client_custom_value3 = $contact->client->custom_value3;
|
|
|
|
$this->client_custom_value4 = $contact->client->custom_value4;
|
|
|
|
|
|
|
|
if ($company->settings->show_accept_invoice_terms && request()->query('hash')) {
|
2023-02-02 04:56:05 +01:00
|
|
|
$this->show_terms = true;
|
2023-02-02 08:19:37 +01:00
|
|
|
$this->terms_accepted = false;
|
|
|
|
$this->show_form = true;
|
2023-02-02 04:56:05 +01:00
|
|
|
|
|
|
|
$hash = Cache::get(request()->input('hash'));
|
2024-04-02 13:12:30 +02:00
|
|
|
|
2024-03-20 22:01:13 +01:00
|
|
|
/** @var \App\Models\Invoice $invoice */
|
2024-03-14 23:08:44 +01:00
|
|
|
$invoice = Invoice::find($this->decodePrimaryKey($hash['invoice_id']));
|
2023-02-02 04:56:05 +01:00
|
|
|
|
2024-03-14 23:08:44 +01:00
|
|
|
$this->invoice_terms = $invoice->terms;
|
2023-02-02 04:56:05 +01:00
|
|
|
}
|
|
|
|
|
2024-06-14 09:09:44 +02:00
|
|
|
if(!$this->company_gateway->always_show_required_fields || $this->is_subscription) {
|
2024-04-25 09:46:11 +02:00
|
|
|
$this->checkFields();
|
2024-06-14 09:09:44 +02:00
|
|
|
}
|
2024-02-22 14:07:34 +01:00
|
|
|
|
2024-06-14 09:09:44 +02:00
|
|
|
if($this->unfilled_fields > 0 || ($this->company_gateway->always_show_required_fields || $this->is_subscription)) {
|
2024-04-25 09:46:11 +02:00
|
|
|
$this->show_form = true;
|
2024-06-14 09:09:44 +02:00
|
|
|
}
|
2023-02-02 08:19:37 +01:00
|
|
|
}
|
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
#[Computed]
|
|
|
|
public function contact()
|
|
|
|
{
|
|
|
|
|
|
|
|
MultiDB::setDb($this->db);
|
|
|
|
return ClientContact::withTrashed()->find($this->contact_id);
|
2024-04-02 13:12:30 +02:00
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[Computed]
|
|
|
|
public function client()
|
|
|
|
{
|
|
|
|
|
|
|
|
MultiDB::setDb($this->db);
|
|
|
|
return ClientContact::withTrashed()->find($this->contact_id)->client;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-02 08:19:37 +01:00
|
|
|
public function toggleTermsAccepted()
|
|
|
|
{
|
|
|
|
$this->terms_accepted = !$this->terms_accepted;
|
2021-06-07 03:06:31 +02:00
|
|
|
}
|
2021-01-25 10:07:12 +01:00
|
|
|
|
2021-01-12 15:43:07 +01:00
|
|
|
public function handleSubmit(array $data): bool
|
|
|
|
{
|
2024-04-02 13:12:30 +02:00
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
MultiDB::setDb($this->db);
|
2024-06-15 08:51:34 +02:00
|
|
|
|
|
|
|
$contact = ClientContact::withTrashed()->with(['client' => function ($query) {
|
|
|
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
|
|
|
}])->find($this->contact_id);
|
2024-03-11 03:35:16 +01:00
|
|
|
|
2021-01-12 15:43:07 +01:00
|
|
|
$rules = [];
|
|
|
|
|
|
|
|
collect($this->fields)->map(function ($field) use (&$rules) {
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! array_key_exists('filled', $field)) {
|
2021-01-19 14:36:07 +01:00
|
|
|
$rules[$field['name']] = array_key_exists('validation_rules', $field)
|
|
|
|
? $field['validation_rules']
|
|
|
|
: 'required';
|
|
|
|
}
|
2021-01-12 15:43:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$validator = Validator::make($data, $rules);
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
session()->flash('validation_errors', $validator->getMessageBag()->getMessages());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-12 16:23:39 +01:00
|
|
|
if ($this->updateClientDetails($data)) {
|
2023-12-15 02:29:47 +01:00
|
|
|
$this->dispatch(
|
|
|
|
'passed-required-fields-check',
|
2024-03-11 03:35:16 +01:00
|
|
|
client_postal_code: $contact->client->postal_code
|
2023-12-15 02:29:47 +01:00
|
|
|
);
|
2021-01-12 16:23:39 +01:00
|
|
|
|
2022-09-13 01:59:16 +02:00
|
|
|
//if stripe is enabled, we want to update the customer at this point.
|
|
|
|
|
2021-01-12 16:23:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Throw an exception about not being able to update the profile.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function updateClientDetails(array $data): bool
|
|
|
|
{
|
|
|
|
$client = [];
|
|
|
|
$contact = [];
|
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
|
|
|
|
MultiDB::setDb($this->db);
|
2024-06-15 08:51:34 +02:00
|
|
|
// $_contact = ClientContact::withTrashed()->with('client')->find($this->contact_id);
|
|
|
|
|
|
|
|
$_contact = ClientContact::withTrashed()->with(['client' => function ($query) {
|
|
|
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
|
|
|
}])->find($this->contact_id);
|
2024-03-11 03:35:16 +01:00
|
|
|
|
|
|
|
|
2021-01-12 16:23:39 +01:00
|
|
|
foreach ($data as $field => $value) {
|
2021-01-12 16:30:11 +01:00
|
|
|
if (Str::startsWith($field, 'client_')) {
|
2021-01-12 16:23:39 +01:00
|
|
|
$client[$this->mappings[$field]] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Str::startsWith($field, 'contact_')) {
|
|
|
|
$contact[$this->mappings[$field]] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
|
2024-04-25 09:46:11 +02:00
|
|
|
$_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();
|
2024-03-11 03:35:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
$contact_update = $_contact
|
2021-01-12 16:23:39 +01:00
|
|
|
->fill($contact)
|
|
|
|
->push();
|
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
$client_update = $_contact->client
|
2021-01-12 16:23:39 +01:00
|
|
|
->fill($client)
|
|
|
|
->push();
|
|
|
|
|
2024-03-11 03:35:16 +01:00
|
|
|
if ($_contact) {
|
2023-08-07 00:23:13 +02:00
|
|
|
/** @var \App\Models\CompanyGateway $cg */
|
2022-09-13 01:59:16 +02:00
|
|
|
$cg = CompanyGateway::find($this->company_gateway_id);
|
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
if ($cg && $cg->update_details) {
|
2024-03-11 03:35:16 +01:00
|
|
|
$payment_gateway = $cg->driver($_contact->client)->init();
|
2022-09-13 01:59:16 +02:00
|
|
|
|
2023-03-18 08:24:56 +01:00
|
|
|
if (method_exists($payment_gateway, "updateCustomer")) {
|
2023-03-14 07:56:04 +01:00
|
|
|
$payment_gateway->updateCustomer();
|
2023-03-18 08:24:56 +01:00
|
|
|
}
|
2022-09-13 01:59:16 +02:00
|
|
|
}
|
|
|
|
|
2021-01-12 16:23:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
2021-01-12 15:43:07 +01:00
|
|
|
|
2021-01-12 16:23:39 +01:00
|
|
|
return false;
|
2021-01-12 15:43:07 +01:00
|
|
|
}
|
|
|
|
|
2021-01-13 13:31:00 +01:00
|
|
|
public function checkFields()
|
|
|
|
{
|
2024-05-09 00:53:45 +02:00
|
|
|
|
2024-04-25 09:46:11 +02:00
|
|
|
MultiDB::setDb($this->db);
|
|
|
|
$_contact = ClientContact::withTrashed()->find($this->contact_id);
|
|
|
|
|
|
|
|
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})
|
|
|
|
) {
|
|
|
|
// $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->unfilled_fields++;
|
|
|
|
} else {
|
|
|
|
// $this->fields[$index]['filled'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-09 00:53:45 +02:00
|
|
|
if ($this->unfilled_fields === 0 && (!$this->company_gateway->always_show_required_fields || $this->is_subscription)) {
|
2024-04-25 09:46:11 +02:00
|
|
|
$this->dispatch(
|
|
|
|
'passed-required-fields-check',
|
2024-06-06 04:31:24 +02:00
|
|
|
client_postal_code: $_contact->client->postal_code
|
2024-04-25 09:46:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-13 13:31:00 +01:00
|
|
|
}
|
|
|
|
|
2021-08-05 17:36:24 +02:00
|
|
|
public function showCopyBillingCheckbox(): bool
|
|
|
|
{
|
|
|
|
$fields = [];
|
|
|
|
|
|
|
|
collect($this->fields)->map(function ($field) use (&$fields) {
|
|
|
|
if (! array_key_exists('filled', $field)) {
|
|
|
|
$fields[] = $field['name'];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
if (Str::startsWith($field, 'client_shipping')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleCopyBilling(): void
|
|
|
|
{
|
2024-03-11 03:35:16 +01:00
|
|
|
|
|
|
|
MultiDB::setDb($this->db);
|
|
|
|
$_contact = ClientContact::withTrashed()->find($this->contact_id);
|
|
|
|
|
2023-12-15 02:29:47 +01:00
|
|
|
$this->dispatch(
|
|
|
|
'update-shipping-data',
|
2024-03-11 03:35:16 +01:00
|
|
|
client_shipping_address_line_1: $_contact->client->address1,
|
|
|
|
client_shipping_address_line_2: $_contact->client->address2,
|
|
|
|
client_shipping_city: $_contact->client->city,
|
|
|
|
client_shipping_state: $_contact->client->state,
|
|
|
|
client_shipping_postal_code: $_contact->client->postal_code,
|
|
|
|
client_shipping_country_id: $_contact->client->country_id,
|
2023-12-15 02:29:47 +01:00
|
|
|
);
|
2021-08-05 17:36:24 +02:00
|
|
|
}
|
|
|
|
|
2021-01-12 15:43:07 +01:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return render('components.livewire.required-client-info');
|
|
|
|
}
|
|
|
|
}
|