v2 first commit
This commit is contained in:
@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Requests\Expense;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use Date;
|
||||
|
||||
class Bill extends Request
|
||||
class Bill extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -26,11 +26,17 @@ class Bill extends Request
|
||||
{
|
||||
// Check if store or update
|
||||
if ($this->getMethod() == 'PATCH') {
|
||||
$id = $this->bill->getAttribute('id');
|
||||
$id = is_numeric($this->bill) ? $this->bill : $this->bill->getAttribute('id');
|
||||
} else {
|
||||
$id = null;
|
||||
}
|
||||
|
||||
$attachment = 'nullable';
|
||||
|
||||
if ($this->request->get('attachment', null)) {
|
||||
$attachment = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
|
||||
}
|
||||
|
||||
// Get company id
|
||||
$company_id = $this->request->get('company_id');
|
||||
|
||||
@ -40,16 +46,16 @@ class Bill extends Request
|
||||
'billed_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'due_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'amount' => 'required',
|
||||
'item.*.name' => 'required|string',
|
||||
'item.*.quantity' => 'required',
|
||||
'item.*.price' => 'required|amount',
|
||||
'item.*.currency' => 'required|string|currency',
|
||||
'items.*.name' => 'required|string',
|
||||
'items.*.quantity' => 'required',
|
||||
'items.*.price' => 'required|amount',
|
||||
'items.*.currency' => 'required|string|currency',
|
||||
'currency_code' => 'required|string|currency',
|
||||
'currency_rate' => 'required',
|
||||
'vendor_id' => 'required|integer',
|
||||
'vendor_name' => 'required|string',
|
||||
'contact_id' => 'required|integer',
|
||||
'contact_name' => 'required|string',
|
||||
'category_id' => 'required|integer',
|
||||
'attachment' => 'mimes:' . setting('general.file_types') . '|between:0,' . setting('general.file_size') * 1024,
|
||||
'attachment' => $attachment,
|
||||
];
|
||||
}
|
||||
|
||||
@ -68,11 +74,11 @@ class Bill extends Request
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'item.*.name.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('general.name'))]),
|
||||
'item.*.quantity.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('bills.quantity'))]),
|
||||
'item.*.price.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('bills.price'))]),
|
||||
'item.*.currency.required' => trans('validation.custom.invalid_currency'),
|
||||
'item.*.currency.string' => trans('validation.custom.invalid_currency'),
|
||||
'items.*.name.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('general.name'))]),
|
||||
'items.*.quantity.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('bills.quantity'))]),
|
||||
'items.*.price.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('bills.price'))]),
|
||||
'items.*.currency.required' => trans('validation.custom.invalid_currency'),
|
||||
'items.*.currency.string' => trans('validation.custom.invalid_currency'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Http\Requests\Expense;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class BillAddItem extends Request
|
||||
class BillAddItem extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Http\Requests\Expense;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class BillHistory extends Request
|
||||
class BillHistory extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Http\Requests\Expense;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class BillItem extends Request
|
||||
class BillItem extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Expense;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use Date;
|
||||
|
||||
class BillPayment extends Request
|
||||
{
|
||||
/**
|
||||
* 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 [
|
||||
'account_id' => 'required|integer',
|
||||
'paid_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'amount' => 'required|amount',
|
||||
'currency_code' => 'required|string|currency',
|
||||
'payment_method' => 'required|string',
|
||||
'attachment' => 'mimes:' . setting('general.file_types', 'pdf,jpeg,jpg,png'),
|
||||
];
|
||||
}
|
||||
|
||||
public function withValidator($validator)
|
||||
{
|
||||
if ($validator->errors()->count()) {
|
||||
$paid_at = Date::parse($this->request->get('paid_at'))->format('Y-m-d');
|
||||
|
||||
$this->request->set('paid_at', $paid_at);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Http\Requests\Expense;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class BillTotal extends Request
|
||||
class BillTotal extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Expense;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use Date;
|
||||
|
||||
class Payment extends Request
|
||||
{
|
||||
/**
|
||||
* 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 [
|
||||
'account_id' => 'required|integer',
|
||||
'paid_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'amount' => 'required|amount',
|
||||
'currency_code' => 'required|string|currency',
|
||||
'currency_rate' => 'required',
|
||||
'vendor_id' => 'nullable|integer',
|
||||
'category_id' => 'required|integer',
|
||||
'payment_method' => 'required|string',
|
||||
'attachment' => 'mimes:' . setting('general.file_types') . '|between:0,' . setting('general.file_size') * 1024,
|
||||
];
|
||||
}
|
||||
|
||||
public function withValidator($validator)
|
||||
{
|
||||
if ($validator->errors()->count()) {
|
||||
$paid_at = Date::parse($this->request->get('paid_at'))->format('Y-m-d');
|
||||
|
||||
$this->request->set('paid_at', $paid_at);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Expense;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class Vendor extends Request
|
||||
{
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$email = '';
|
||||
|
||||
// Get company id
|
||||
$company_id = $this->request->get('company_id');
|
||||
|
||||
// Check if store or update
|
||||
if ($this->getMethod() == 'PATCH') {
|
||||
$id = $this->vendor->getAttribute('id');
|
||||
} else {
|
||||
$id = null;
|
||||
}
|
||||
|
||||
if (!empty($this->request->get('email'))) {
|
||||
$email = 'email|unique:vendors,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL';
|
||||
}
|
||||
|
||||
return [
|
||||
'user_id' => 'nullable|integer',
|
||||
'name' => 'required|string',
|
||||
'email' => $email,
|
||||
'currency_code' => 'required|string|currency',
|
||||
'enabled' => 'integer|boolean',
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user