Moved to _dev

This commit is contained in:
2025-09-20 16:11:47 +02:00
parent fb1a8753b7
commit b2ba11fcd3
1670 changed files with 224899 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace Crater\Http\Requests;
use Crater\Rules\Base64Mime;
use Illuminate\Foundation\Http\FormRequest;
class AvatarRequest 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 [
'admin_avatar' => [
'nullable',
'file',
'mimes:gif,jpg,png',
'max:20000'
],
'avatar' => [
'nullable',
new Base64Mime(['gif', 'jpg', 'png'])
]
];
}
}

View 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'
]
];
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
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,
'slug' => Str::slug($this->name)
])
->toArray();
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Crater\Http\Requests;
use Crater\Rules\Base64Mime;
use Illuminate\Foundation\Http\FormRequest;
class CompanyLogoRequest 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 [
'company_logo' => [
'nullable',
new Base64Mime(['gif', 'jpg', 'png'])
]
];
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class CompanyRequest 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')->ignore($this->header('company'), 'id'),
],
'slug' => [
'nullable'
],
'address.country_id' => [
'required',
],
];
}
public function getCompanyPayload()
{
return collect($this->validated())
->only([
'name',
'slug'
])
->toArray();
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CompanySettingRequest 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 [
'currency' => [
'required',
],
'time_zone' => [
'required',
],
'language' => [
'required',
],
'fiscal_year' => [
'required',
],
'moment_date_format' => [
'required',
],
'carbon_date_format' => [
'required',
],
];
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CustomFieldRequest 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',
'label' => 'required',
'model_type' => 'required',
'order' => 'required',
'type' => 'required',
'is_required' => 'required|boolean',
'options' => 'array',
'placeholder' => 'string|nullable',
];
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Crater\Http\Requests\Customer;
use Illuminate\Foundation\Http\FormRequest;
class CustomerLoginRequest 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 [
'email' => [
'required',
'string'
],
'password' => [
'required',
'string'
]
];
}
}

View File

@@ -0,0 +1,122 @@
<?php
namespace Crater\Http\Requests\Customer;
use Crater\Models\Address;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
class CustomerProfileRequest 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' => [
'nullable',
],
'password' => [
'nullable',
'min:8',
],
'email' => [
'nullable',
'email',
Rule::unique('customers')->where('company_id', $this->header('company'))->ignore(Auth::id(), 'id'),
],
'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',
],
'customer_avatar' => [
'nullable',
'file',
'mimes:gif,jpg,png',
'max:20000'
]
];
}
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();
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CustomerEstimateStatusRequest 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 [
'status' => [
'required',
'in:ACCEPTED,REJECTED',
]
];
}
}

View File

@@ -0,0 +1,181 @@
<?php
namespace Crater\Http\Requests;
use Crater\Models\Address;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Arr;
use Illuminate\Validation\Rule;
class CustomerRequest 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',
],
'email' => [
'email',
'nullable',
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' => [
'boolean'
],
'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('customers')->where('company_id', $this->header('company'))->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;
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class DatabaseEnvironmentRequest 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()
{
switch ($this->get('database_connection')) {
case 'sqlite':
return [
'app_url' => [
'required',
'url',
],
'database_connection' => [
'required',
'string',
],
'database_name' => [
'required',
'string',
],
];
break;
default:
return [
'app_url' => [
'required',
'url',
],
'database_connection' => [
'required',
'string',
],
'database_hostname' => [
'required',
'string',
],
'database_port' => [
'required',
'numeric',
],
'database_name' => [
'required',
'string',
],
'database_username' => [
'required',
'string',
],
];
break;
}
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class DeleteCustomersRequest 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 [
'ids' => [
'required',
],
'ids.*' => [
'required',
Rule::exists('customers', 'id'),
],
];
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class DeleteEstimatesRequest 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 [
'ids' => [
'required',
],
'ids.*' => [
'required',
Rule::exists('estimates', 'id'),
],
];
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class DeleteExpensesRequest 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 [
'ids' => [
'required',
],
'ids.*' => [
'required',
Rule::exists('expenses', 'id'),
],
];
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Crater\Http\Requests;
use Crater\Models\Invoice;
use Crater\Rules\RelationNotExist;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class DeleteInvoiceRequest 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 [
'ids' => [
'required',
],
'ids.*' => [
'required',
Rule::exists('invoices', 'id'),
new RelationNotExist(Invoice::class, 'payments'),
],
];
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Crater\Http\Requests;
use Crater\Models\Item;
use Crater\Rules\RelationNotExist;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class DeleteItemsRequest 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 [
'ids' => [
'required',
],
'ids.*' => [
'required',
Rule::exists('items', 'id'),
new RelationNotExist(Item::class, 'invoiceItems'),
new RelationNotExist(Item::class, 'estimateItems'),
new RelationNotExist(Item::class, 'taxes'),
],
];
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class DeletePaymentsRequest 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 [
'ids' => [
'required',
],
'ids.*' => [
'required',
Rule::exists('payments', 'id'),
],
];
}
}

View 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'),
],
];
}
}

View File

@@ -0,0 +1,122 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class DiskEnvironmentRequest 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 = [];
switch ($this->get('driver')) {
case 's3':
$rules = [
'credentials.key' => [
'required',
'string',
],
'credentials.secret' => [
'required',
'string',
],
'credentials.region' => [
'required',
'string',
],
'credentials.bucket' => [
'required',
'string',
],
'credentials.root' => [
'required',
'string',
],
];
break;
case 'doSpaces':
$rules = [
'credentials.key' => [
'required',
'string',
],
'credentials.secret' => [
'required',
'string',
],
'credentials.region' => [
'required',
'string',
],
'credentials.bucket' => [
'required',
'string',
],
'credentials.endpoint' => [
'required',
'string',
],
'credentials.root' => [
'required',
'string',
],
];
break;
case 'dropbox':
$rules = [
'credentials.token' => [
'required',
'string',
],
'credentials.key' => [
'required',
'string',
],
'credentials.secret' => [
'required',
'string',
],
'credentials.app' => [
'required',
'string',
],
'credentials.root' => [
'required',
'string',
],
];
break;
}
$defaultRules = [
'name' => [
'required',
],
'driver' => [
'required',
],
];
return array_merge($rules, $defaultRules);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class DomainEnvironmentRequest 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 [
'app_domain' => [
'required',
],
];
}
}

View File

@@ -0,0 +1,134 @@
<?php
namespace Crater\Http\Requests;
use Crater\Models\CompanySetting;
use Crater\Models\Customer;
use Crater\Models\Estimate;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class EstimatesRequest 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 = [
'estimate_date' => [
'required',
],
'expiry_date' => [
'nullable',
],
'customer_id' => [
'required',
],
'estimate_number' => [
'required',
Rule::unique('estimates')->where('company_id', $this->header('company'))
],
'exchange_rate' => [
'nullable'
],
'discount' => [
'required',
],
'discount_val' => [
'required',
],
'sub_total' => [
'required',
],
'total' => [
'required',
],
'tax' => [
'required',
],
'template_name' => [
'required'
],
'items' => [
'required',
'array',
],
'items.*.description' => [
'nullable',
],
'items.*' => [
'required',
'max:255',
],
'items.*.name' => [
'required',
],
'items.*.quantity' => [
'required',
],
'items.*.price' => [
'required',
],
];
$companyCurrency = CompanySetting::getSetting('currency', $this->header('company'));
$customer = Customer::find($this->customer_id);
if ($companyCurrency && $customer) {
if ((string)$customer->currency_id !== $companyCurrency) {
$rules['exchange_rate'] = [
'required',
];
};
}
if ($this->isMethod('PUT')) {
$rules['estimate_number'] = [
'required',
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 ?? null,
'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();
}
}

View 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();
}
}
}

View 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();
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ExpenseCategoryRequest 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',
],
'description' => [
'nullable',
],
];
}
public function getExpenseCategoryPayload()
{
return collect($this->validated())
->merge([
'company_id' => $this->header('company')
])
->toArray();
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace Crater\Http\Requests;
use Crater\Models\CompanySetting;
use Illuminate\Foundation\Http\FormRequest;
class ExpenseRequest 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 = [
'expense_date' => [
'required',
],
'expense_category_id' => [
'required',
],
'exchange_rate' => [
'nullable'
],
'payment_method_id' => [
'nullable',
],
'amount' => [
'required',
],
'customer_id' => [
'nullable',
],
'notes' => [
'nullable',
],
'currency_id' => [
'required'
],
'attachment_receipt' => [
'nullable',
'file',
'mimes:jpg,png,pdf,doc,docx,xls,xlsx,ppt,pptx',
'max:20000'
]
];
if ($companyCurrency && $this->currency_id) {
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();
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class GetSettingRequest 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 [
'key' => [
'required',
'string'
]
];
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class GetSettingsRequest 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 [
'settings' => [
'required',
],
'settings.*' => [
'required',
'string',
],
];
}
}

View File

@@ -0,0 +1,137 @@
<?php
namespace Crater\Http\Requests;
use Crater\Models\CompanySetting;
use Crater\Models\Customer;
use Crater\Models\Invoice;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class InvoicesRequest 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.s
*
* @return array
*/
public function rules()
{
$rules = [
'invoice_date' => [
'required',
],
'due_date' => [
'nullable',
],
'customer_id' => [
'required',
],
'invoice_number' => [
'required',
Rule::unique('invoices')->where('company_id', $this->header('company'))
],
'exchange_rate' => [
'nullable'
],
'discount' => [
'required',
],
'discount_val' => [
'required',
],
'sub_total' => [
'required',
],
'total' => [
'required',
],
'tax' => [
'required',
],
'template_name' => [
'required'
],
'items' => [
'required',
'array',
],
'items.*' => [
'required',
'max:255',
],
'items.*.description' => [
'nullable',
],
'items.*.name' => [
'required',
],
'items.*.quantity' => [
'required',
],
'items.*.price' => [
'required',
],
];
$companyCurrency = CompanySetting::getSetting('currency', $this->header('company'));
$customer = Customer::find($this->customer_id);
if ($customer && $companyCurrency) {
if ((string)$customer->currency_id !== $companyCurrency) {
$rules['exchange_rate'] = [
'required',
];
};
}
if ($this->isMethod('PUT')) {
$rules['invoice_number'] = [
'required',
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 ?? null,
'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();
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ItemsRequest 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',
],
'price' => [
'required',
],
'unit_id' => [
'nullable',
],
'description' => [
'nullable',
],
];
}
}

View 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'
],
];
}
}

View File

@@ -0,0 +1,152 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class MailEnvironmentRequest 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()
{
switch ($this->get('mail_driver')) {
case 'smtp':
return [
'mail_driver' => [
'required',
'string',
],
'mail_host' => [
'required',
'string',
],
'mail_port' => [
'required',
],
'mail_encryption' => [
'required',
'string',
],
'from_name' => [
'required',
'string',
],
'from_mail' => [
'required',
'string',
],
];
break;
case 'mailgun':
return [
'mail_driver' => [
'required',
'string',
],
'mail_mailgun_domain' => [
'required',
'string',
],
'mail_mailgun_secret' => [
'required',
'string',
],
'mail_mailgun_endpoint' => [
'required',
'string',
],
'from_name' => [
'required',
'string',
],
'from_mail' => [
'required',
'string',
],
];
break;
case 'ses':
return [
'mail_driver' => [
'required',
'string',
],
'mail_host' => [
'required',
'string',
],
'mail_port' => [
'required',
],
'mail_ses_key' => [
'required',
'string',
],
'mail_ses_secret' => [
'required',
'string',
],
'mail_encryption' => [
'nullable',
'string',
],
'from_name' => [
'required',
'string',
],
'from_mail' => [
'required',
'string',
],
];
break;
case 'mail':
return [
'from_name' => [
'required',
'string',
],
'from_mail' => [
'required',
'string',
],
];
break;
case 'sendmail':
return [
'from_name' => [
'required',
'string',
],
'from_mail' => [
'required',
'string',
],
];
break;
}
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class NotesRequest 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 = [
'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();
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace Crater\Http\Requests;
use Crater\Models\PaymentMethod;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class PaymentMethodRequest 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()
{
$data = [
'name' => [
'required',
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')
->where('company_id', $this->header('company')),
];
}
return $data;
}
public function getPaymentMethodPayload()
{
return collect($this->validated())
->merge([
'company_id' => $this->header('company'),
'type' => PaymentMethod::TYPE_GENERAL,
])
->toArray();
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace Crater\Http\Requests;
use Crater\Models\CompanySetting;
use Crater\Models\Customer;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class PaymentRequest 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 = [
'payment_date' => [
'required',
],
'customer_id' => [
'required',
],
'exchange_rate' => [
'nullable'
],
'amount' => [
'required',
],
'payment_number' => [
'required',
Rule::unique('payments')->where('company_id', $this->header('company'))
],
'invoice_id' => [
'nullable',
],
'payment_method_id' => [
'nullable',
],
'notes' => [
'nullable',
],
];
if ($this->isMethod('PUT')) {
$rules['payment_number'] = [
'required',
Rule::unique('payments')
->ignore($this->route('payment')->id)
->where('company_id', $this->header('company')),
];
}
$companyCurrency = CompanySetting::getSetting('currency', $this->header('company'));
$customer = Customer::find($this->customer_id);
if ($customer && $companyCurrency) {
if ((string)$customer->currency_id !== $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();
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
class ProfileRequest 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',
],
'password' => [
'nullable',
'min:8',
],
'email' => [
'required',
'email',
Rule::unique('users')->ignore(Auth::id(), 'id'),
],
];
}
}

View File

@@ -0,0 +1,121 @@
<?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'
]
];
$customer = Customer::find($this->customer_id);
if ($customer && $companyCurrency) {
if ((string)$customer->currency_id !== $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();
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
abstract class Request extends FormRequest
{
//
}

View 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();
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SendEstimatesRequest 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 [
'subject' => [
'required',
],
'body' => [
'required',
],
'from' => [
'required',
],
'to' => [
'required',
],
];
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SendInvoiceRequest 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 [
'body' => [
'required',
],
'subject' => [
'required',
],
'from' => [
'required',
],
'to' => [
'required',
],
];
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SendPaymentRequest 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 [
'subject' => [
'required',
],
'body' => [
'required',
],
'from' => [
'required',
],
'to' => [
'required',
],
];
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SettingKeyRequest 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 [
'key' => [
'required',
],
];
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SettingRequest 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 [
'settings' => [
'required',
],
];
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Crater\Http\Requests;
use Crater\Models\TaxType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class TaxTypeRequest 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',
Rule::unique('tax_types')
->where('type', TaxType::TYPE_GENERAL)
->where('company_id', $this->header('company'))
],
'percent' => [
'required',
],
'description' => [
'nullable',
],
'compound_tax' => [
'nullable',
],
'collective_tax' => [
'nullable',
],
];
if ($this->isMethod('PUT')) {
$rules['name'] = [
'required',
Rule::unique('tax_types')
->ignore($this->route('tax_type')->id)
->where('type', TaxType::TYPE_GENERAL)
->where('company_id', $this->header('company'))
];
}
return $rules;
}
public function getTaxTypePayload()
{
return collect($this->validated())
->merge([
'company_id' => $this->header('company'),
'type' => TaxType::TYPE_GENERAL
])
->toArray();
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UnitRequest 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()
{
$data = [
'name' => [
'required',
Rule::unique('units')
->where('company_id', $this->header('company')),
],
];
if ($this->getMethod() == 'PUT') {
$data['name'] = [
'required',
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();
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UnzipUpdateRequest 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 [
'path' => [
'required',
'regex:/^[\.\/\w\-]+$/'
],
'module' => [
'required',
'string'
]
];
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateSettingsRequest 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 [
'settings' => [
'required',
],
];
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Crater\Http\Requests;
use Crater\Rules\Base64Mime;
use Illuminate\Foundation\Http\FormRequest;
class UploadExpenseReceiptRequest 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 [
'attachment_receipt' => [
'nullable',
new Base64Mime(['gif', 'jpg', 'png'])
]
];
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UploadModuleRequest 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 [
'avatar' => [
'required',
'file',
'mimes:zip',
'max:20000'
],
'module' => [
'required',
'string',
'max:100'
]
];
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace Crater\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UserRequest 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',
],
'email' => [
'required',
'email',
Rule::unique('users'),
],
'phone' => [
'nullable',
],
'password' => [
'required',
'min:8',
],
'companies' => [
'required',
],
'companies.*.id' => [
'required',
],
'companies.*.role' => [
'required',
],
];
if ($this->getMethod() == 'PUT') {
$rules['email'] = [
'required',
'email',
Rule::unique('users')->ignore($this->user),
];
$rules['password'] = [
'nullable',
'min:8',
];
}
return $rules;
}
public function getUserPayload()
{
return collect($this->validated())
->merge([
'creator_id' => $this->user()->id,
])
->toArray();
}
}