mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 19:51:09 -04:00
v5.0.0 update
This commit is contained in:
@ -2,7 +2,10 @@
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CustomerRequest extends FormRequest
|
||||
@ -28,29 +31,151 @@ class CustomerRequest extends FormRequest
|
||||
'name' => [
|
||||
'required',
|
||||
],
|
||||
'addresses.*.address_street_1' => [
|
||||
'max:255',
|
||||
],
|
||||
'addresses.*.address_street_2' => [
|
||||
'max:255',
|
||||
],
|
||||
'email' => [
|
||||
'email',
|
||||
'nullable',
|
||||
'unique:users,email',
|
||||
Rule::unique('customers')->where('company_id', $this->header('company'))
|
||||
],
|
||||
'password' => [
|
||||
'nullable',
|
||||
],
|
||||
'phone' => [
|
||||
'nullable',
|
||||
],
|
||||
'company_name' => [
|
||||
'nullable',
|
||||
],
|
||||
'contact_name' => [
|
||||
'nullable',
|
||||
],
|
||||
'website' => [
|
||||
'nullable',
|
||||
],
|
||||
'prefix' => [
|
||||
'nullable',
|
||||
],
|
||||
'enable_portal' => [
|
||||
'nullable',
|
||||
],
|
||||
'currency_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.name' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.address_street_1' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.address_street_2' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.city' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.state' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.country_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.zip' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.phone' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.fax' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.name' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.address_street_1' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.address_street_2' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.city' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.state' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.country_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.zip' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.phone' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.fax' => [
|
||||
'nullable',
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->isMethod('PUT') && $this->email != null) {
|
||||
$rules = [
|
||||
'email' => [
|
||||
'email',
|
||||
'nullable',
|
||||
Rule::unique('users')->ignore($this->route('customer')->id),
|
||||
],
|
||||
$rules['email'] = [
|
||||
'email',
|
||||
'nullable',
|
||||
Rule::unique('customers')->ignore($this->route('customer')->id),
|
||||
];
|
||||
};
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getCustomerPayload()
|
||||
{
|
||||
return collect($this->validated())
|
||||
->only([
|
||||
'name',
|
||||
'email',
|
||||
'currency_id',
|
||||
'password',
|
||||
'phone',
|
||||
'prefix',
|
||||
'company_name',
|
||||
'contact_name',
|
||||
'website',
|
||||
'enable_portal',
|
||||
'estimate_prefix',
|
||||
'payment_prefix',
|
||||
'invoice_prefix',
|
||||
])
|
||||
->merge([
|
||||
'creator_id' => $this->user()->id,
|
||||
'company_id' => $this->header('company'),
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getShippingAddress()
|
||||
{
|
||||
return collect($this->shipping)
|
||||
->merge([
|
||||
'type' => Address::SHIPPING_TYPE
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getBillingAddress()
|
||||
{
|
||||
return collect($this->billing)
|
||||
->merge([
|
||||
'type' => Address::BILLING_TYPE
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function hasAddress(array $address)
|
||||
{
|
||||
$data = Arr::where($address, function ($value, $key) {
|
||||
return isset($value);
|
||||
});
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user