mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
v5.0.0 update
This commit is contained in:
39
app/Http/Requests/BulkExchangeRateRequest.php
Normal file
39
app/Http/Requests/BulkExchangeRateRequest.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class BulkExchangeRateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'currencies' => [
|
||||
'required'
|
||||
],
|
||||
'currencies.*.id' => [
|
||||
'required',
|
||||
'numeric'
|
||||
],
|
||||
'currencies.*.exchange_rate' => [
|
||||
'required'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
77
app/Http/Requests/CompaniesRequest.php
Normal file
77
app/Http/Requests/CompaniesRequest.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CompaniesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => [
|
||||
'required',
|
||||
Rule::unique('companies'),
|
||||
'string'
|
||||
],
|
||||
'currency' => [
|
||||
'required'
|
||||
],
|
||||
'address.name' => [
|
||||
'nullable',
|
||||
],
|
||||
'address.address_street_1' => [
|
||||
'nullable',
|
||||
],
|
||||
'address.address_street_2' => [
|
||||
'nullable',
|
||||
],
|
||||
'address.city' => [
|
||||
'nullable',
|
||||
],
|
||||
'address.state' => [
|
||||
'nullable',
|
||||
],
|
||||
'address.country_id' => [
|
||||
'required',
|
||||
],
|
||||
'address.zip' => [
|
||||
'nullable',
|
||||
],
|
||||
'address.phone' => [
|
||||
'nullable',
|
||||
],
|
||||
'address.fax' => [
|
||||
'nullable',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getCompanyPayload()
|
||||
{
|
||||
return collect($this->validated())
|
||||
->only([
|
||||
'name'
|
||||
])
|
||||
->merge([
|
||||
'owner_id' => $this->user()->id
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CompanyRequest extends FormRequest
|
||||
{
|
||||
@ -26,8 +27,9 @@ class CompanyRequest extends FormRequest
|
||||
return [
|
||||
'name' => [
|
||||
'required',
|
||||
Rule::unique('companies')->ignore($this->header('company'), 'id'),
|
||||
],
|
||||
'country_id' => [
|
||||
'address.country_id' => [
|
||||
'required',
|
||||
],
|
||||
];
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ class DatabaseEnvironmentRequest extends FormRequest
|
||||
{
|
||||
switch ($this->get('database_connection')) {
|
||||
case 'sqlite':
|
||||
return [
|
||||
return [
|
||||
'app_url' => [
|
||||
'required',
|
||||
'url',
|
||||
@ -42,7 +42,7 @@ class DatabaseEnvironmentRequest extends FormRequest
|
||||
|
||||
break;
|
||||
default:
|
||||
return [
|
||||
return [
|
||||
'app_url' => [
|
||||
'required',
|
||||
'url',
|
||||
|
||||
@ -30,7 +30,7 @@ class DeleteCustomersRequest extends FormRequest
|
||||
],
|
||||
'ids.*' => [
|
||||
'required',
|
||||
Rule::exists('users', 'id'),
|
||||
Rule::exists('customers', 'id'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
37
app/Http/Requests/DeleteUserRequest.php
Normal file
37
app/Http/Requests/DeleteUserRequest.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class DeleteUserRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'users' => [
|
||||
'required',
|
||||
],
|
||||
'users.*' => [
|
||||
'required',
|
||||
Rule::exists('users', 'id'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -2,9 +2,11 @@
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Rules\UniqueNumber;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class EstimatesRequest extends FormRequest
|
||||
{
|
||||
@ -30,14 +32,17 @@ class EstimatesRequest extends FormRequest
|
||||
'required',
|
||||
],
|
||||
'expiry_date' => [
|
||||
'required',
|
||||
'nullable',
|
||||
],
|
||||
'user_id' => [
|
||||
'customer_id' => [
|
||||
'required',
|
||||
],
|
||||
'estimate_number' => [
|
||||
'required',
|
||||
new UniqueNumber(Estimate::class),
|
||||
Rule::unique('estimates')->where('company_id', $this->header('company'))
|
||||
],
|
||||
'exchange_rate' => [
|
||||
'nullable'
|
||||
],
|
||||
'discount' => [
|
||||
'required',
|
||||
@ -62,7 +67,7 @@ class EstimatesRequest extends FormRequest
|
||||
'array',
|
||||
],
|
||||
'items.*.description' => [
|
||||
'max:255',
|
||||
'nullable',
|
||||
],
|
||||
'items.*' => [
|
||||
'required',
|
||||
@ -79,13 +84,49 @@ class EstimatesRequest extends FormRequest
|
||||
],
|
||||
];
|
||||
|
||||
$companyCurrency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
|
||||
$customerCurrency = Customer::find($this->customer_id)->currency_id;
|
||||
|
||||
if ((string)$customerCurrency !== $companyCurrency) {
|
||||
$rules['exchange_rate'] = [
|
||||
'required',
|
||||
];
|
||||
};
|
||||
|
||||
if ($this->isMethod('PUT')) {
|
||||
$rules['estimate_number'] = [
|
||||
'required',
|
||||
new UniqueNumber(Estimate::class, $this->route('estimate')->id),
|
||||
Rule::unique('estimates')
|
||||
->ignore($this->route('estimate')->id)
|
||||
->where('company_id', $this->header('company')),
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getEstimatePayload()
|
||||
{
|
||||
$company_currency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
$current_currency = $this->currency_id;
|
||||
$exchange_rate = $company_currency != $current_currency ? $this->exchange_rate : 1;
|
||||
$currency = Customer::find($this->customer_id)->currency_id;
|
||||
|
||||
return collect($this->except('items', 'taxes'))
|
||||
->merge([
|
||||
'creator_id' => $this->user()->id,
|
||||
'status' => $this->has('estimateSend') ? Estimate::STATUS_SENT : Estimate::STATUS_DRAFT,
|
||||
'company_id' => $this->header('company'),
|
||||
'tax_per_item' => CompanySetting::getSetting('tax_per_item', $this->header('company')) ?? 'NO ',
|
||||
'discount_per_item' => CompanySetting::getSetting('discount_per_item', $this->header('company')) ?? 'NO',
|
||||
'exchange_rate' => $exchange_rate,
|
||||
'base_discount_val' => $this->discount_val * $exchange_rate,
|
||||
'base_sub_total' => $this->sub_total * $exchange_rate,
|
||||
'base_total' => $this->total * $exchange_rate,
|
||||
'base_tax' => $this->tax * $exchange_rate,
|
||||
'currency_id' => $currency,
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
53
app/Http/Requests/ExchangeRateLogRequest.php
Normal file
53
app/Http/Requests/ExchangeRateLogRequest.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ExchangeRateLogRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'exchange_rate' => [
|
||||
'required',
|
||||
],
|
||||
'currency_id' => [
|
||||
'required'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getExchangeRateLogPayload()
|
||||
{
|
||||
$companyCurrency = CompanySetting::getSetting(
|
||||
'currency',
|
||||
$this->header('company')
|
||||
);
|
||||
|
||||
if ($this->currency_id !== $companyCurrency) {
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'company_id' => $this->header('company'),
|
||||
'base_currency_id' => $companyCurrency,
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
59
app/Http/Requests/ExchangeRateProviderRequest.php
Normal file
59
app/Http/Requests/ExchangeRateProviderRequest.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ExchangeRateProviderRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'driver' => [
|
||||
'required'
|
||||
],
|
||||
'key' => [
|
||||
'required',
|
||||
],
|
||||
'currencies' => [
|
||||
'nullable',
|
||||
],
|
||||
'currencies.*' => [
|
||||
'nullable',
|
||||
],
|
||||
'driver_config' => [
|
||||
'nullable'
|
||||
],
|
||||
'active' => [
|
||||
'nullable',
|
||||
'boolean'
|
||||
],
|
||||
];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getExchangeRateProviderPayload()
|
||||
{
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'company_id' => $this->header('company')
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@ -32,4 +32,13 @@ class ExpenseCategoryRequest extends FormRequest
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getExpenseCategoryPayload()
|
||||
{
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'company_id' => $this->header('company')
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ExpenseRequest extends FormRequest
|
||||
@ -23,22 +24,58 @@ class ExpenseRequest extends FormRequest
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
$companyCurrency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
|
||||
$rules = [
|
||||
'expense_date' => [
|
||||
'required',
|
||||
],
|
||||
'expense_category_id' => [
|
||||
'required',
|
||||
],
|
||||
'exchange_rate' => [
|
||||
'nullable'
|
||||
],
|
||||
'payment_method_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'amount' => [
|
||||
'required',
|
||||
],
|
||||
'user_id' => [
|
||||
'customer_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'notes' => [
|
||||
'nullable',
|
||||
],
|
||||
'currency_id' => [
|
||||
'required'
|
||||
],
|
||||
];
|
||||
|
||||
if ($companyCurrency !== $this->currency_id) {
|
||||
$rules['exchange_rate'] = [
|
||||
'required',
|
||||
];
|
||||
};
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getExpensePayload()
|
||||
{
|
||||
$company_currency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
$current_currency = $this->currency_id;
|
||||
$exchange_rate = $company_currency != $current_currency ? $this->exchange_rate : 1;
|
||||
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'creator_id' => $this->user()->id,
|
||||
'company_id' => $this->header('company'),
|
||||
'exchange_rate' => $exchange_rate,
|
||||
'base_amount' => $this->amount * $exchange_rate,
|
||||
'currency_id' => $current_currency
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,9 +2,11 @@
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Rules\UniqueNumber;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class InvoicesRequest extends FormRequest
|
||||
{
|
||||
@ -30,14 +32,17 @@ class InvoicesRequest extends FormRequest
|
||||
'required',
|
||||
],
|
||||
'due_date' => [
|
||||
'required',
|
||||
'nullable',
|
||||
],
|
||||
'user_id' => [
|
||||
'customer_id' => [
|
||||
'required',
|
||||
],
|
||||
'invoice_number' => [
|
||||
'required',
|
||||
new UniqueNumber(Invoice::class),
|
||||
Rule::unique('invoices')->where('company_id', $this->header('company'))
|
||||
],
|
||||
'exchange_rate' => [
|
||||
'nullable'
|
||||
],
|
||||
'discount' => [
|
||||
'required',
|
||||
@ -66,7 +71,7 @@ class InvoicesRequest extends FormRequest
|
||||
'max:255',
|
||||
],
|
||||
'items.*.description' => [
|
||||
'max:255',
|
||||
'nullable',
|
||||
],
|
||||
'items.*.name' => [
|
||||
'required',
|
||||
@ -79,13 +84,52 @@ class InvoicesRequest extends FormRequest
|
||||
],
|
||||
];
|
||||
|
||||
$companyCurrency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
|
||||
$customerCurrency = Customer::find($this->customer_id)->currency_id;
|
||||
|
||||
if ((string)$customerCurrency !== $companyCurrency) {
|
||||
$rules['exchange_rate'] = [
|
||||
'required',
|
||||
];
|
||||
};
|
||||
|
||||
if ($this->isMethod('PUT')) {
|
||||
$rules['invoice_number'] = [
|
||||
'required',
|
||||
new UniqueNumber(Invoice::class, $this->route('invoice')->id),
|
||||
Rule::unique('invoices')
|
||||
->ignore($this->route('invoice')->id)
|
||||
->where('company_id', $this->header('company')),
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getInvoicePayload()
|
||||
{
|
||||
$company_currency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
$current_currency = $this->currency_id;
|
||||
$exchange_rate = $company_currency != $current_currency ? $this->exchange_rate : 1;
|
||||
$currency = Customer::find($this->customer_id)->currency_id;
|
||||
|
||||
return collect($this->except('items', 'taxes'))
|
||||
->merge([
|
||||
'creator_id' => $this->user()->id,
|
||||
'status' => $this->has('invoiceSend') ? Invoice::STATUS_SENT : Invoice::STATUS_DRAFT,
|
||||
'paid_status' => Invoice::STATUS_UNPAID,
|
||||
'company_id' => $this->header('company'),
|
||||
'tax_per_item' => CompanySetting::getSetting('tax_per_item', $this->header('company')) ?? 'NO ',
|
||||
'discount_per_item' => CompanySetting::getSetting('discount_per_item', $this->header('company')) ?? 'NO',
|
||||
'due_amount' => $this->total,
|
||||
'exchange_rate' => $exchange_rate,
|
||||
'base_total' => $this->total * $exchange_rate,
|
||||
'base_discount_val' => $this->discount_val * $exchange_rate,
|
||||
'base_sub_total' => $this->sub_total * $exchange_rate,
|
||||
'base_tax' => $this->tax * $exchange_rate,
|
||||
'base_due_amount' => $this->total * $exchange_rate,
|
||||
'currency_id' => $currency,
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
38
app/Http/Requests/LoginRequest.php
Normal file
38
app/Http/Requests/LoginRequest.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'username' => [
|
||||
'required',
|
||||
],
|
||||
'password' => [
|
||||
'required',
|
||||
],
|
||||
'device_name' => [
|
||||
'required'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -105,7 +105,7 @@ class MailEnvironmentRequest extends FormRequest
|
||||
'string',
|
||||
],
|
||||
'mail_encryption' => [
|
||||
'required',
|
||||
'nullable',
|
||||
'string',
|
||||
],
|
||||
'from_name' => [
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class NotesRequest extends FormRequest
|
||||
{
|
||||
@ -23,10 +24,40 @@ class NotesRequest extends FormRequest
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'type' => ['required'],
|
||||
'name' => ['required'],
|
||||
'notes' => ['required'],
|
||||
$rules = [
|
||||
'type' => [
|
||||
'required'
|
||||
],
|
||||
'name' => [
|
||||
'required',
|
||||
Rule::unique('notes')
|
||||
->where('company_id', $this->header('company'))
|
||||
->where('type', $this->type)
|
||||
],
|
||||
'notes' => [
|
||||
'required'
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->isMethod('PUT')) {
|
||||
$rules['name'] = [
|
||||
'required',
|
||||
Rule::unique('notes')
|
||||
->ignore($this->route('note')->id)
|
||||
->where('type', $this->type)
|
||||
->where('company_id', $this->header('company'))
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getNotesPayload()
|
||||
{
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'company_id' => $this->header('company')
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,14 +27,17 @@ class PaymentMethodRequest extends FormRequest
|
||||
$data = [
|
||||
'name' => [
|
||||
'required',
|
||||
'unique:payment_methods,name',
|
||||
Rule::unique('payment_methods')
|
||||
->where('company_id', $this->header('company')),
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->getMethod() == 'PUT') {
|
||||
$data['name'] = [
|
||||
'required',
|
||||
Rule::unique('payment_methods')->ignore($this->route('payment_method'), 'id'),
|
||||
Rule::unique('payment_methods')
|
||||
->ignore($this->route('payment_method'), 'id')
|
||||
->where('company_id', $this->header('company')),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -2,9 +2,10 @@
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Crater\Models\Payment;
|
||||
use Crater\Rules\UniqueNumber;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Customer;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class PaymentRequest extends FormRequest
|
||||
{
|
||||
@ -29,15 +30,18 @@ class PaymentRequest extends FormRequest
|
||||
'payment_date' => [
|
||||
'required',
|
||||
],
|
||||
'user_id' => [
|
||||
'customer_id' => [
|
||||
'required',
|
||||
],
|
||||
'exchange_rate' => [
|
||||
'nullable'
|
||||
],
|
||||
'amount' => [
|
||||
'required',
|
||||
],
|
||||
'payment_number' => [
|
||||
'required',
|
||||
new UniqueNumber(Payment::class),
|
||||
Rule::unique('payments')->where('company_id', $this->header('company'))
|
||||
],
|
||||
'invoice_id' => [
|
||||
'nullable',
|
||||
@ -53,10 +57,40 @@ class PaymentRequest extends FormRequest
|
||||
if ($this->isMethod('PUT')) {
|
||||
$rules['payment_number'] = [
|
||||
'required',
|
||||
new UniqueNumber(Payment::class, $this->route('payment')->id),
|
||||
Rule::unique('payments')
|
||||
->ignore($this->route('payment')->id)
|
||||
->where('company_id', $this->header('company')),
|
||||
];
|
||||
}
|
||||
|
||||
$companyCurrency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
|
||||
$customerCurrency = Customer::find($this->customer_id)->currency_id;
|
||||
|
||||
if ((string)$customerCurrency !== $companyCurrency) {
|
||||
$rules['exchange_rate'] = [
|
||||
'required',
|
||||
];
|
||||
};
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getPaymentPayload()
|
||||
{
|
||||
$company_currency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
$current_currency = $this->currency_id;
|
||||
$exchange_rate = $company_currency != $current_currency ? $this->exchange_rate : 1;
|
||||
$currency = Customer::find($this->customer_id)->currency_id;
|
||||
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'creator_id' => $this->user()->id,
|
||||
'company_id' => $this->header('company'),
|
||||
'exchange_rate' => $exchange_rate,
|
||||
'base_amount' => $this->amount * $exchange_rate,
|
||||
'currency_id' => $currency
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
119
app/Http/Requests/RecurringInvoiceRequest.php
Normal file
119
app/Http/Requests/RecurringInvoiceRequest.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\RecurringInvoice;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RecurringInvoiceRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$companyCurrency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
|
||||
$rules = [
|
||||
'starts_at' => [
|
||||
'required'
|
||||
],
|
||||
'send_automatically' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'customer_id' => [
|
||||
'required'
|
||||
],
|
||||
'exchange_rate' => [
|
||||
'nullable'
|
||||
],
|
||||
'discount' => [
|
||||
'required',
|
||||
],
|
||||
'discount_val' => [
|
||||
'required',
|
||||
],
|
||||
'sub_total' => [
|
||||
'required',
|
||||
],
|
||||
'total' => [
|
||||
'required',
|
||||
],
|
||||
'tax' => [
|
||||
'required',
|
||||
],
|
||||
'status' => [
|
||||
'required'
|
||||
],
|
||||
'exchange_rate' => [
|
||||
'nullable'
|
||||
],
|
||||
'frequency' => [
|
||||
'required'
|
||||
],
|
||||
'limit_by' => [
|
||||
'required'
|
||||
],
|
||||
'limit_count' => [
|
||||
'required_if:limit_by,COUNT',
|
||||
],
|
||||
'limit_date' => [
|
||||
'required_if:limit_by,DATE',
|
||||
],
|
||||
'items' => [
|
||||
'required'
|
||||
],
|
||||
'items.*' => [
|
||||
'required'
|
||||
]
|
||||
];
|
||||
|
||||
$customerCurrency = Customer::find($this->customer_id)->currency_id;
|
||||
|
||||
if ((string)$customerCurrency !== $companyCurrency) {
|
||||
$rules['exchange_rate'] = [
|
||||
'required',
|
||||
];
|
||||
};
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getRecurringInvoicePayload()
|
||||
{
|
||||
$company_currency = CompanySetting::getSetting('currency', $this->header('company'));
|
||||
$current_currency = $this->currency_id;
|
||||
$exchange_rate = $company_currency != $current_currency ? $this->exchange_rate : 1;
|
||||
$currency = Customer::find($this->customer_id)->currency_id;
|
||||
|
||||
$nextInvoiceAt = RecurringInvoice::getNextInvoiceDate($this->frequency, $this->starts_at);
|
||||
|
||||
return collect($this->except('items', 'taxes'))
|
||||
->merge([
|
||||
'creator_id' => $this->user()->id,
|
||||
'company_id' => $this->header('company'),
|
||||
'next_invoice_at' => $nextInvoiceAt,
|
||||
'tax_per_item' => CompanySetting::getSetting('tax_per_item', $this->header('company')) ?? 'NO ',
|
||||
'discount_per_item' => CompanySetting::getSetting('discount_per_item', $this->header('company')) ?? 'NO',
|
||||
'due_amount' => $this->total,
|
||||
'exchange_rate' => $exchange_rate,
|
||||
'currency_id' => $currency
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
62
app/Http/Requests/RoleRequest.php
Normal file
62
app/Http/Requests/RoleRequest.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class RoleRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'name' => [
|
||||
'required',
|
||||
'string',
|
||||
Rule::unique('roles')->where('scope', $this->header('company'))
|
||||
],
|
||||
'abilities' => [
|
||||
'required'
|
||||
],
|
||||
'abilities.*' => [
|
||||
'required'
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->getMethod() == 'PUT') {
|
||||
$rules['name'] = [
|
||||
'required',
|
||||
'string',
|
||||
Rule::unique('roles')
|
||||
->ignore($this->route('role')->id, 'id')
|
||||
->where('scope', $this->header('company'))
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getRolePayload()
|
||||
{
|
||||
return collect($this->except('abilities'))
|
||||
->merge([
|
||||
'scope' => $this->header('company'),
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class TaxTypeRequest extends FormRequest
|
||||
{
|
||||
@ -23,9 +24,11 @@ class TaxTypeRequest extends FormRequest
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
$rules = [
|
||||
'name' => [
|
||||
'required',
|
||||
Rule::unique('tax_types')
|
||||
->where('company_id', $this->header('company'))
|
||||
],
|
||||
'percent' => [
|
||||
'required',
|
||||
@ -40,5 +43,25 @@ class TaxTypeRequest extends FormRequest
|
||||
'nullable',
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->isMethod('PUT')) {
|
||||
$rules['name'] = [
|
||||
'required',
|
||||
Rule::unique('tax_types')
|
||||
->ignore($this->route('tax_type')->id)
|
||||
->where('company_id', $this->header('company'))
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getTaxTypePayload()
|
||||
{
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'company_id' => $this->header('company')
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,17 +27,29 @@ class UnitRequest extends FormRequest
|
||||
$data = [
|
||||
'name' => [
|
||||
'required',
|
||||
'unique:units,name',
|
||||
Rule::unique('units')
|
||||
->where('company_id', $this->header('company')),
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->getMethod() == 'PUT') {
|
||||
$data['name'] = [
|
||||
'required',
|
||||
Rule::unique('units')->ignore($this->route('unit'), 'id'),
|
||||
Rule::unique('units')
|
||||
->ignore($this->route('unit'), 'id')
|
||||
->where('company_id', $this->header('company')),
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getUnitPayload()
|
||||
{
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'company_id' => $this->header('company')
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,9 +27,6 @@ class UpdateSettingsRequest extends FormRequest
|
||||
'settings' => [
|
||||
'required',
|
||||
],
|
||||
'settings.*' => [
|
||||
'required',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,15 @@ class UserRequest extends FormRequest
|
||||
'required',
|
||||
'min:8',
|
||||
],
|
||||
'companies' => [
|
||||
'required',
|
||||
],
|
||||
'companies.*.id' => [
|
||||
'required',
|
||||
],
|
||||
'companies.*.role' => [
|
||||
'required',
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->getMethod() == 'PUT') {
|
||||
@ -56,4 +65,13 @@ class UserRequest extends FormRequest
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getUserPayload()
|
||||
{
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'creator_id' => $this->user()->id,
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user