Merge Invoice and Bill into Document
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Sale;
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use Date;
|
||||
use App\Models\Document\Document as Model;
|
||||
use App\Utilities\Date;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Invoice extends FormRequest
|
||||
class Document extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -24,9 +26,13 @@ class Invoice extends FormRequest
|
||||
*/
|
||||
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->invoice) ? $this->invoice : $this->invoice->getAttribute('id');
|
||||
$id = is_numeric($this->$type) ? $this->$type : $this->{$type}->getAttribute('id');
|
||||
} else {
|
||||
$id = null;
|
||||
}
|
||||
@ -41,15 +47,15 @@ class Invoice extends FormRequest
|
||||
$company_id = $this->request->get('company_id');
|
||||
|
||||
return [
|
||||
'invoice_number' => 'required|string|unique:invoices,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL',
|
||||
'type' => 'required|string',
|
||||
'document_number' => 'required|string|unique:documents,NULL,' . $id . ',id,type,' . $type . ',company_id,' . $company_id . ',deleted_at,NULL',
|
||||
'status' => 'required|string',
|
||||
'invoiced_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'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',
|
||||
'items.*.currency' => 'required|string|currency',
|
||||
'currency_code' => 'required|string|currency',
|
||||
'currency_rate' => 'required',
|
||||
'contact_id' => 'required|integer',
|
||||
@ -63,10 +69,10 @@ class Invoice extends FormRequest
|
||||
{
|
||||
if ($validator->errors()->count()) {
|
||||
// Set date
|
||||
$invoiced_at = Date::parse($this->request->get('invoiced_at'))->format('Y-m-d');
|
||||
$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('invoiced_at', $invoiced_at);
|
||||
$this->request->set('issued_at', $issued_at);
|
||||
$this->request->set('due_at', $due_at);
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Sale;
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class InvoiceAddItem extends FormRequest
|
||||
class DocumentAddItem extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Sale;
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class InvoiceHistory extends FormRequest
|
||||
class DocumentHistory extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -24,7 +24,8 @@ class InvoiceHistory extends FormRequest
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'invoice_id' => 'required|integer',
|
||||
'type' => 'required|string',
|
||||
'document_id' => 'required|integer',
|
||||
'status' => 'required|string',
|
||||
'notify' => 'required|integer',
|
||||
];
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Sale;
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class InvoiceItem extends FormRequest
|
||||
class DocumentItem extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -24,7 +24,8 @@ class InvoiceItem extends FormRequest
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'invoice_id' => 'required|integer',
|
||||
'type' => 'required|string',
|
||||
'document_id' => 'required|integer',
|
||||
'name' => 'required|string',
|
||||
'quantity' => 'required|integer',
|
||||
'price' => 'required',
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Purchase;
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class BillItemTax extends FormRequest
|
||||
class DocumentItemTax extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -24,8 +24,9 @@ class BillItemTax extends FormRequest
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'bill_id' => 'required|integer',
|
||||
'bill_item_id' => 'required|integer',
|
||||
'type' => 'required|string',
|
||||
'document_id' => 'required|integer',
|
||||
'document_item_id' => 'required|integer',
|
||||
'tax_id' => 'required|integer',
|
||||
'name' => 'required|string',
|
||||
'amount' => 'required',
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Purchase;
|
||||
namespace App\Http\Requests\Document;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class BillTotal extends FormRequest
|
||||
class DocumentTotal extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -24,7 +24,8 @@ class BillTotal extends FormRequest
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'bill_id' => 'required|integer',
|
||||
'type' => 'required|string',
|
||||
'document_id' => 'required|integer',
|
||||
'name' => 'required|string',
|
||||
'amount' => 'required|amount',
|
||||
'sort_order' => 'required|integer',
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Purchase;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use Date;
|
||||
|
||||
class Bill 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()
|
||||
{
|
||||
// Check if store or update
|
||||
if ($this->getMethod() == 'PATCH') {
|
||||
$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');
|
||||
|
||||
return [
|
||||
'bill_number' => 'required|string|unique:bills,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL',
|
||||
'status' => 'required|string',
|
||||
'billed_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',
|
||||
'items.*.currency' => 'required|string|currency',
|
||||
'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
|
||||
$billed_at = Date::parse($this->request->get('billed_at'))->format('Y-m-d');
|
||||
$due_at = Date::parse($this->request->get('due_at'))->format('Y-m-d');
|
||||
|
||||
$this->request->set('billed_at', $billed_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('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'),
|
||||
];
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Purchase;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class BillAddItem 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',
|
||||
];
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Purchase;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class BillHistory 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 [
|
||||
'bill_id' => 'required|integer',
|
||||
'status' => 'required|string',
|
||||
'notify' => 'required|integer',
|
||||
];
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Purchase;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class BillItem 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 [
|
||||
'bill_id' => 'required|integer',
|
||||
'name' => 'required|string',
|
||||
'quantity' => 'required|integer',
|
||||
'price' => 'required',
|
||||
'total' => 'required',
|
||||
'tax' => 'required',
|
||||
'tax_id' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Sale;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class InvoiceItemTax 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 [
|
||||
'invoice_id' => 'required|integer',
|
||||
'invoice_item_id' => 'required|integer',
|
||||
'tax_id' => 'required|integer',
|
||||
'name' => 'required|string',
|
||||
'amount' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Sale;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class InvoiceTotal 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 [
|
||||
'invoice_id' => 'required|integer',
|
||||
'name' => 'required|string',
|
||||
'amount' => 'required|amount',
|
||||
'sort_order' => 'required|integer',
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user