Merge remote-tracking branch 'composer/feature/senior-officer' into staging
This commit is contained in:
@@ -316,3 +316,16 @@
|
||||
return User::find($userId);
|
||||
}
|
||||
|
||||
function generateLpjUniqueCode($randomLength = 6)
|
||||
{
|
||||
|
||||
$year = date('y');
|
||||
$month = str_pad(date('m'), 2, '0', STR_PAD_LEFT);
|
||||
$day = str_pad(date('d'), 2, '0', STR_PAD_LEFT);
|
||||
|
||||
// Generate random numbers
|
||||
$randomNumber = str_pad(mt_rand(0, pow(10, $randomLength) - 1), $randomLength, '0', STR_PAD_LEFT);
|
||||
|
||||
// Concatenate components to create the custom code
|
||||
return $year . $month . $day . $randomNumber;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use Barryvdh\DomPDF\Facade\Pdf; // https://github.com/barryvdh/laravel-dompdf
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Inspeksi;
|
||||
use Modules\Lpj\Models\Penilai;
|
||||
use Modules\Lpj\Models\Laporan;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
@@ -17,6 +18,7 @@ use Modules\Location\Models\City;
|
||||
use Modules\Location\Models\District;
|
||||
use Modules\Location\Models\Village;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Helpers\Lpj;
|
||||
|
||||
class PenilaiController extends Controller
|
||||
{
|
||||
@@ -247,7 +249,7 @@ class PenilaiController extends Controller
|
||||
}
|
||||
|
||||
|
||||
if(!Auth::user()->hasRole('administrator')) {
|
||||
if (!Auth::user()->hasRole('administrator')) {
|
||||
$query->whereHas('penilaian.userPenilai', function ($q) {
|
||||
$q
|
||||
->where('role', 'penilai')
|
||||
@@ -597,6 +599,17 @@ class PenilaiController extends Controller
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
||||
$lpj = Penilai::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
||||
|
||||
$laporan = Laporan::firstOrCreate(
|
||||
[
|
||||
'permohonan_id' => $permohonanId,
|
||||
'dokumen_jaminan_id' => $documentId,
|
||||
],
|
||||
[
|
||||
'nomor_laporan' => generateLpjUniqueCode(6),
|
||||
]
|
||||
);
|
||||
$nomorLaporan = $laporan->nomor_laporan;
|
||||
|
||||
$forminspeksi = null;
|
||||
$lpjData = null;
|
||||
$formFoto = null;
|
||||
@@ -616,20 +629,20 @@ class PenilaiController extends Controller
|
||||
|
||||
$inputAddress = $forminspeksi['asset']['alamat']['sesuai'] ?? $forminspeksi['asset']['alamat']['tidak sesuai'];
|
||||
|
||||
$alamat = [
|
||||
'address' => $inputAddress['address'] ?? null,
|
||||
'village_code' => $this->getWilayahName($inputAddress['village_code'] ?? null, 'village'),
|
||||
'district_code' => $this->getWilayahName($inputAddress['district_code'] ?? null, 'district'),
|
||||
'city_code' => $this->getWilayahName($inputAddress['city_code'] ?? null, 'city'),
|
||||
'province_code' => $this->getWilayahName($inputAddress['province_code'] ?? null, 'province')
|
||||
];
|
||||
|
||||
$alamat = [
|
||||
'address' => $inputAddress['address'] ?? null,
|
||||
'village_code' => $this->getWilayahName($inputAddress['village_code'] ?? null, 'village'),
|
||||
'district_code' => $this->getWilayahName($inputAddress['district_code'] ?? null, 'district'),
|
||||
'city_code' => $this->getWilayahName($inputAddress['city_code'] ?? null, 'city'),
|
||||
'province_code' => $this->getWilayahName($inputAddress['province_code'] ?? null, 'province')
|
||||
];
|
||||
|
||||
$laporan = $lpj->type == 'sederhana' ? true : false;
|
||||
|
||||
$viewLaporan = null;
|
||||
if($laporan){
|
||||
$viewLaporan = 'penilai.components.print-out-sederhana';
|
||||
}else{
|
||||
if ($laporan) {
|
||||
$viewLaporan = 'penilai.components.print-out-sederhana';
|
||||
} else {
|
||||
$viewLaporan = 'penilai.components.print-out-standard';
|
||||
}
|
||||
|
||||
@@ -646,9 +659,10 @@ $alamat = [
|
||||
'lpj',
|
||||
'statusLpj',
|
||||
'alamat',
|
||||
'dataPembanding'
|
||||
'dataPembanding',
|
||||
'nomorLaporan'
|
||||
));
|
||||
}else{
|
||||
} else {
|
||||
$pdf = PDF::loadView('lpj::' . $viewLaporan, compact(
|
||||
'permohonan',
|
||||
'forminspeksi',
|
||||
@@ -659,7 +673,8 @@ $alamat = [
|
||||
'lpj',
|
||||
'statusLpj',
|
||||
'alamat',
|
||||
'dataPembanding'
|
||||
'dataPembanding',
|
||||
'nomorLaporan'
|
||||
));
|
||||
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
@@ -673,31 +688,32 @@ $alamat = [
|
||||
|
||||
}
|
||||
|
||||
function getWilayahName($code, $type) {
|
||||
public function getWilayahName($code, $type)
|
||||
{
|
||||
try {
|
||||
$wilayah = null;
|
||||
|
||||
|
||||
if (!$code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch($type) {
|
||||
|
||||
switch ($type) {
|
||||
case 'province':
|
||||
$wilayah = Province::where('code', $code)->first();
|
||||
return $wilayah ? $wilayah->name : null;
|
||||
|
||||
|
||||
case 'city':
|
||||
$wilayah = City::where('code', $code)->first();
|
||||
return $wilayah ? $wilayah->name : null;
|
||||
|
||||
|
||||
case 'district':
|
||||
$wilayah = District::where('code', $code)->first();
|
||||
return $wilayah ? $wilayah->name : null;
|
||||
|
||||
|
||||
case 'village':
|
||||
$wilayah = Village::where('code', $code)->first();
|
||||
return $wilayah ? $wilayah->name : null;
|
||||
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -705,6 +721,6 @@ $alamat = [
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
36
app/Models/Laporan.php
Normal file
36
app/Models/Laporan.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
// use Modules\Lpj\Database\Factories\LaporanFactory;
|
||||
|
||||
class Laporan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'laporan';
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
|
||||
public function jenisLaporan(){
|
||||
return $this->belongsTo(JenisLaporan::class);
|
||||
}
|
||||
|
||||
public function dokument(){
|
||||
return $this->belongsTo(DokumenJaminan::class);
|
||||
}
|
||||
|
||||
public function permohonan(){
|
||||
return $this->belongsTo(Permohonan::class);
|
||||
}
|
||||
|
||||
// protected static function newFactory(): LaporanFactory
|
||||
// {
|
||||
// // return LaporanFactory::new();
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user