Merge Invoice and Bill into Document
This commit is contained in:
90
app/Http/Requests/Document/Document.php
Normal file
90
app/Http/Requests/Document/Document.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use App\Models\Document\Document as Model;
|
||||
use App\Utilities\Date;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Document 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()
|
||||
{
|
||||
$type = $this->request->get('type', Model::INVOICE_TYPE);
|
||||
|
||||
$type = Str::replaceFirst('-', '_', $type);
|
||||
|
||||
// Check if store or update
|
||||
if ($this->getMethod() == 'PATCH') {
|
||||
$id = is_numeric($this->$type) ? $this->$type : $this->{$type}->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');
|
||||
|
||||
return [
|
||||
'type' => 'required|string',
|
||||
'document_number' => 'required|string|unique:documents,NULL,' . $id . ',id,type,' . $type . ',company_id,' . $company_id . ',deleted_at,NULL',
|
||||
'status' => 'required|string',
|
||||
'issued_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'due_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'amount' => 'required',
|
||||
'items.*.name' => 'required|string',
|
||||
'items.*.quantity' => 'required',
|
||||
'items.*.price' => 'required|amount',
|
||||
'currency_code' => 'required|string|currency',
|
||||
'currency_rate' => 'required',
|
||||
'contact_id' => 'required|integer',
|
||||
'contact_name' => 'required|string',
|
||||
'category_id' => 'required|integer',
|
||||
'attachment' => $attachment,
|
||||
];
|
||||
}
|
||||
|
||||
public function withValidator($validator)
|
||||
{
|
||||
if ($validator->errors()->count()) {
|
||||
// Set date
|
||||
$issued_at = Date::parse($this->request->get('issued_at'))->format('Y-m-d');
|
||||
$due_at = Date::parse($this->request->get('due_at'))->format('Y-m-d');
|
||||
|
||||
$this->request->set('issued_at', $issued_at);
|
||||
$this->request->set('due_at', $due_at);
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'items.*.name.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('general.name'))]),
|
||||
'items.*.quantity.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('invoices.quantity'))]),
|
||||
'items.*.price.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('invoices.price'))]),
|
||||
'items.*.currency.required' => trans('validation.custom.invalid_currency'),
|
||||
'items.*.currency.string' => trans('validation.custom.invalid_currency'),
|
||||
];
|
||||
}
|
||||
}
|
31
app/Http/Requests/Document/DocumentAddItem.php
Normal file
31
app/Http/Requests/Document/DocumentAddItem.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class DocumentAddItem 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 [
|
||||
'item_row' => 'required|integer',
|
||||
'currency_code' => 'required|string|currency',
|
||||
];
|
||||
}
|
||||
}
|
33
app/Http/Requests/Document/DocumentHistory.php
Normal file
33
app/Http/Requests/Document/DocumentHistory.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class DocumentHistory 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 [
|
||||
'type' => 'required|string',
|
||||
'document_id' => 'required|integer',
|
||||
'status' => 'required|string',
|
||||
'notify' => 'required|integer',
|
||||
];
|
||||
}
|
||||
}
|
37
app/Http/Requests/Document/DocumentItem.php
Normal file
37
app/Http/Requests/Document/DocumentItem.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class DocumentItem 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 [
|
||||
'type' => 'required|string',
|
||||
'document_id' => 'required|integer',
|
||||
'name' => 'required|string',
|
||||
'quantity' => 'required|integer',
|
||||
'price' => 'required',
|
||||
'total' => 'required',
|
||||
'tax' => 'required',
|
||||
'tax_id' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
35
app/Http/Requests/Document/DocumentItemTax.php
Normal file
35
app/Http/Requests/Document/DocumentItemTax.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class DocumentItemTax 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 [
|
||||
'type' => 'required|string',
|
||||
'document_id' => 'required|integer',
|
||||
'document_item_id' => 'required|integer',
|
||||
'tax_id' => 'required|integer',
|
||||
'name' => 'required|string',
|
||||
'amount' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
34
app/Http/Requests/Document/DocumentTotal.php
Normal file
34
app/Http/Requests/Document/DocumentTotal.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class DocumentTotal 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 [
|
||||
'type' => 'required|string',
|
||||
'document_id' => 'required|integer',
|
||||
'name' => 'required|string',
|
||||
'amount' => 'required|amount',
|
||||
'sort_order' => 'required|integer',
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user