daeng.deni@dharma.or.id
a9556ffdd3
- Add Cetak Label - Add Cetak Odner - Add Generate QRCode - Add Cetak Segel - Add List Document Setiap Cetak Labeld Dus Atau Odner
114 lines
4.2 KiB
PHP
114 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Cetaklabel\Http\Requests\DocumentDetail;
|
|
|
|
use Haruncpi\LaravelIdGenerator\IdGenerator;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Illuminate\Validation\Validator;
|
|
use Modules\Cetaklabel\Entities\Document;
|
|
use Modules\Cetaklabel\Entities\SpecialCode;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
|
class StoreDocumentDetailRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize()
|
|
: bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
|
|
*/
|
|
public function rules()
|
|
: array
|
|
{
|
|
return [
|
|
'document_id' => 'required|integer|exists:documents,id',
|
|
'kode' => 'required|string|unique:document_details,kode',
|
|
'document_type_id' => 'required|string|exists:document_type,document_type_id',
|
|
'special_code_id' => 'required|integer|exists:special_codes,id',
|
|
'nama_nasabah' => 'nullable|string',
|
|
'no_rekening' => 'nullable|string',
|
|
'no_cif' => 'nullable|string',
|
|
'group' => 'nullable|string',
|
|
'tanggal_dokumen' => 'nullable|date',
|
|
'tanggal_upload' => 'nullable|date',
|
|
'nomor_dokumen' => 'nullable|string',
|
|
'perihal' => 'nullable|string',
|
|
'kode_cabang' => 'nullable|string',
|
|
'jumlah_halaman' => 'nullable|integer',
|
|
'custom_field_1' => 'nullable|string',
|
|
'custom_field_2' => 'nullable|string',
|
|
'custom_field_3' => 'nullable|string',
|
|
'custom_field_4' => 'nullable|string',
|
|
'status' => 'nullable|string',
|
|
'file' => 'nullable|string',
|
|
'no_urut' => 'nullable|integer',
|
|
'keterangan' => 'nullable|string',
|
|
'status' => 'nullable|string',
|
|
'kategori' => 'nullable|string',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Configure the validator instance.
|
|
*/
|
|
public function withValidator(Validator $validator)
|
|
: void
|
|
{
|
|
$validator->after(function (Validator $validator) {
|
|
if ($validator->errors()->any()) {
|
|
$error = json_decode($validator->errors()->toJson(), true);
|
|
foreach ($error as $key => $value) {
|
|
flash($value[0]);
|
|
}
|
|
|
|
return redirect()->route('document.index')->with('error', 'Document created failed.');
|
|
}
|
|
});
|
|
}
|
|
|
|
protected function failedValidation(Validator|\Illuminate\Contracts\Validation\Validator $validator)
|
|
: JsonResponse
|
|
{
|
|
$errors = (new ValidationException($validator))->errors();
|
|
|
|
throw new HttpResponseException(response()->json([
|
|
'success' => false,
|
|
'errors' => $errors,
|
|
'messages' => 'Document created failed.'
|
|
], JsonResponse::HTTP_UNPROCESSABLE_ENTITY));
|
|
}
|
|
|
|
protected function prepareForValidation()
|
|
: void
|
|
{
|
|
|
|
$document = Document::find($this->document_id);
|
|
$special_code = SpecialCode::find($this->special_code_id);
|
|
|
|
$prefix = $document->kode;
|
|
$suffix = $special_code->kode;
|
|
|
|
$kode = IdGenerator::generate([
|
|
'table' => 'document_details',
|
|
'field' => 'kode',
|
|
'length' => 13,
|
|
'prefix' => $prefix
|
|
]);
|
|
|
|
$this->merge([
|
|
'kode' => $kode . $suffix,
|
|
'no_urut' => substr($kode, -3, 3)
|
|
]);
|
|
}
|
|
}
|