This commit is contained in:
@@ -21,6 +21,8 @@ class BudgetControl extends Model
|
||||
'transferred_at',
|
||||
'closing_at',
|
||||
'status',
|
||||
'transfer_proof',
|
||||
'transfer_status',
|
||||
];
|
||||
|
||||
public function user()
|
||||
|
||||
@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class FormEntertaimentPresentation extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
use SoftDeletes, \App\Traits\HasAttachments;
|
||||
|
||||
protected $table = 'form_entertainment_presentation';
|
||||
protected $fillable = [
|
||||
@@ -31,17 +31,40 @@ class FormEntertaimentPresentation extends Model
|
||||
'approved2_by',
|
||||
'final_approved_at',
|
||||
'final_approved_by',
|
||||
// Kolom baru
|
||||
'jabatan',
|
||||
'nama_perusahaan',
|
||||
'jenis_usaha',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
'approved_at' => 'datetime',
|
||||
'approved2_at' => 'datetime',
|
||||
'final_approved_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Admin');
|
||||
}
|
||||
|
||||
public function attachments()
|
||||
{
|
||||
return $this->hasMany(\App\Models\AttachmentForm::class, 'form_id')
|
||||
->where('table_name', \App\Enums\AttachmentTableName::FORM_ENTERTAINMENT_PRESENTATION);
|
||||
}
|
||||
// Relasi ke kategori untuk mengambil account_number
|
||||
public function kategori()
|
||||
{
|
||||
return $this->belongsTo(Kategori::class, 'kategori_id');
|
||||
}
|
||||
|
||||
public function rejector() {
|
||||
return $this->belongsTo(User::class, 'rejected_by');
|
||||
}
|
||||
|
||||
// public function attachments()
|
||||
// {
|
||||
// // form_id adalah kolom di tabel attachment_forms
|
||||
// // table_name digunakan jika satu tabel attachment dipakai banyak form
|
||||
// return $this->hasMany(\App\Models\AttachmentForm::class, 'form_id')
|
||||
// ->where('table_name', 'form_entertainment_presentation');
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -4,46 +4,53 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class FormMeetingSeminar extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'form_meeting_seminar';
|
||||
|
||||
protected $fillable = [
|
||||
'expense_number',
|
||||
'user_id',
|
||||
'tanggal',
|
||||
'allowance',
|
||||
'transport_ankot',
|
||||
'hotel',
|
||||
'total',
|
||||
'approved_allowance',
|
||||
'approved_transport_ankot',
|
||||
'approved_hotel',
|
||||
'approved_total',
|
||||
'bukti_allowance',
|
||||
'bukti_transport_ankot',
|
||||
'bukti_hotel',
|
||||
'account_number',
|
||||
'status',
|
||||
'remarks',
|
||||
'approved_at',
|
||||
'approved2_at',
|
||||
'approved_by',
|
||||
'approved2_by',
|
||||
'final_approved_at',
|
||||
'expense_number', 'user_id', 'tanggal', 'allowance', 'transport_ankot',
|
||||
'hotel', 'total', 'approved_allowance', 'approved_transport_ankot',
|
||||
'approved_hotel', 'approved_total', 'bukti_allowance', 'bukti_transport_ankot',
|
||||
'bukti_hotel', 'account_number', 'status', 'remarks', 'approved_at',
|
||||
'approved2_at', 'approved_by', 'approved2_by', 'final_approved_at',
|
||||
'final_approved_by',
|
||||
];
|
||||
|
||||
public function user()
|
||||
/**
|
||||
* Casts untuk otomatisasi format Carbon pada tanggal agar konsisten di Blade.
|
||||
*/
|
||||
protected $casts = [
|
||||
'tanggal' => 'date',
|
||||
'final_approved_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relasi ke Admin (Pengaju).
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Admin::class, 'user_id');
|
||||
}
|
||||
|
||||
public function attachments()
|
||||
/**
|
||||
* Relasi ke Attachments (Dokumen Digital) sesuai pola Entertainment.
|
||||
*/
|
||||
public function attachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\AttachmentForm::class, 'form_id')
|
||||
return $this->hasMany(AttachmentForm::class, 'form_id')
|
||||
->where('table_name', \App\Enums\AttachmentTableName::FORM_MEETING_SEMINAR);
|
||||
}
|
||||
|
||||
public function rejector() {
|
||||
return $this->belongsTo(User::class, 'rejected_by');
|
||||
}
|
||||
|
||||
}
|
||||
+35
-22
@@ -4,6 +4,8 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class FormOthers extends Model
|
||||
{
|
||||
@@ -11,38 +13,49 @@ class FormOthers extends Model
|
||||
|
||||
protected $table = 'form_others';
|
||||
protected $fillable = [
|
||||
'expense_number',
|
||||
'user_id',
|
||||
'kategori_id',
|
||||
'tanggal',
|
||||
'keterangan',
|
||||
'total',
|
||||
'approved_total',
|
||||
'bukti_total',
|
||||
'account_number',
|
||||
'status',
|
||||
'remarks',
|
||||
'approved_at',
|
||||
'approved2_at',
|
||||
'approved_by',
|
||||
'approved2_by',
|
||||
'final_approved_at',
|
||||
'final_approved_by',
|
||||
'expense_number', 'user_id', 'kategori_id', 'tanggal', 'keterangan',
|
||||
'total', 'approved_total', 'bukti_total', 'account_number', 'status',
|
||||
'remarks', 'approved_at', 'approved2_at', 'approved_by', 'approved2_by',
|
||||
'final_approved_at', 'final_approved_by',
|
||||
];
|
||||
|
||||
public function user()
|
||||
/**
|
||||
* Casts untuk otomatisasi format Carbon pada tanggal agar konsisten di Blade.
|
||||
*/
|
||||
protected $casts = [
|
||||
'tanggal' => 'date',
|
||||
'final_approved_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relasi ke Admin (Pengaju).
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Admin::class);
|
||||
return $this->belongsTo(Admin::class, 'user_id');
|
||||
}
|
||||
|
||||
public function kategori()
|
||||
/**
|
||||
* Relasi ke Kategori.
|
||||
*/
|
||||
public function kategori(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Kategori::class);
|
||||
return $this->belongsTo(Kategori::class, 'kategori_id');
|
||||
}
|
||||
|
||||
public function attachments()
|
||||
/**
|
||||
* Relasi ke Attachments (Dokumen Digital) sesuai pola Entertainment.
|
||||
*/
|
||||
public function attachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\AttachmentForm::class, 'form_id')
|
||||
->where('table_name', \App\Enums\AttachmentTableName::FORM_OTHERS);
|
||||
}
|
||||
|
||||
public function rejector() {
|
||||
return $this->belongsTo(User::class, 'rejected_by');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,58 +4,61 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class FormUpCountry extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'form_up_country';
|
||||
|
||||
protected $fillable = [
|
||||
'expense_number',
|
||||
'user_id',
|
||||
'rayon_id',
|
||||
'tanggal',
|
||||
'tujuan',
|
||||
'jarak',
|
||||
'allowance',
|
||||
'transport_dalkot',
|
||||
'transport_ankot',
|
||||
'hotel',
|
||||
'total',
|
||||
'approved_allowance',
|
||||
'approved_transport_dalkot',
|
||||
'approved_transport_ankot',
|
||||
'approved_hotel',
|
||||
'approved_total',
|
||||
'bukti_allowance',
|
||||
'bukti_transport_dalkot',
|
||||
'bukti_transport_ankot',
|
||||
'bukti_hotel',
|
||||
'uc_plan',
|
||||
'account_number',
|
||||
'status',
|
||||
'remarks',
|
||||
'approved_at',
|
||||
'approved2_at',
|
||||
'approved_by',
|
||||
'approved2_by',
|
||||
'final_approved_at',
|
||||
'final_approved_by',
|
||||
'expense_number', 'user_id', 'rayon_id', 'tanggal', 'tujuan', 'jarak',
|
||||
'allowance', 'transport_dalkot', 'transport_ankot', 'hotel', 'total',
|
||||
'approved_allowance', 'approved_transport_dalkot', 'approved_transport_ankot',
|
||||
'approved_hotel', 'approved_total', 'bukti_allowance', 'bukti_transport_dalkot',
|
||||
'bukti_transport_ankot', 'bukti_hotel', 'uc_plan', 'account_number', 'status',
|
||||
'remarks', 'approved_at', 'approved2_at', 'approved_by', 'approved2_by',
|
||||
'final_approved_at', 'final_approved_by','cabang_id','kategori_id',
|
||||
];
|
||||
|
||||
public function user()
|
||||
/**
|
||||
* Casts untuk otomatisasi format Carbon pada tanggal.
|
||||
*/
|
||||
protected $casts = [
|
||||
'tanggal' => 'date',
|
||||
'final_approved_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relasi ke Admin (Pengaju).
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo('App\Models\Admin');
|
||||
return $this->belongsTo(Admin::class, 'user_id');
|
||||
}
|
||||
|
||||
public function rayon()
|
||||
/**
|
||||
* Relasi ke Rayon.
|
||||
*/
|
||||
public function rayon(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo('App\Models\Rayon');
|
||||
return $this->belongsTo(Rayon::class, 'rayon_id');
|
||||
}
|
||||
|
||||
public function attachments()
|
||||
/**
|
||||
* Relasi ke Attachments (Dokumen Digital) sesuai pola Entertainment.
|
||||
*/
|
||||
public function attachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\AttachmentForm::class, 'form_id')
|
||||
return $this->hasMany(AttachmentForm::class, 'form_id')
|
||||
->where('table_name', \App\Enums\AttachmentTableName::FORM_UP_COUNTRY);
|
||||
}
|
||||
|
||||
public function rejector() {
|
||||
return $this->belongsTo(User::class, 'rejected_by');
|
||||
}
|
||||
}
|
||||
@@ -4,44 +4,51 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class FormVehicleRunningCost extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'form_vehicle_running_cost';
|
||||
|
||||
protected $fillable = [
|
||||
'expense_number',
|
||||
'user_id',
|
||||
'tanggal',
|
||||
'liter',
|
||||
'total',
|
||||
'approved_total',
|
||||
'jarak',
|
||||
'tipe_bensin',
|
||||
'nopol',
|
||||
'keterangan',
|
||||
'bukti_total',
|
||||
'account_number',
|
||||
'type',
|
||||
'status',
|
||||
'remarks',
|
||||
'approved_at',
|
||||
'approved2_at',
|
||||
'approved_by',
|
||||
'approved2_by',
|
||||
'final_approved_at',
|
||||
'final_approved_by',
|
||||
'expense_number', 'user_id', 'tanggal', 'liter', 'total', 'approved_total',
|
||||
'jarak', 'tipe_bensin', 'nopol', 'keterangan', 'bukti_total', 'account_number',
|
||||
'type', 'status', 'remarks', 'approved_at', 'approved2_at', 'approved_by',
|
||||
'approved2_by', 'final_approved_at', 'final_approved_by',
|
||||
];
|
||||
|
||||
public function user()
|
||||
/**
|
||||
* Casts untuk otomatisasi format Carbon pada tanggal.
|
||||
*/
|
||||
protected $casts = [
|
||||
'tanggal' => 'date',
|
||||
'final_approved_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relasi ke Admin (Pengaju)
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo('App\Models\Admin', 'user_id');
|
||||
return $this->belongsTo(Admin::class, 'user_id');
|
||||
}
|
||||
|
||||
public function attachments()
|
||||
/**
|
||||
* Relasi ke Attachments (Dokumen Digital)
|
||||
*/
|
||||
public function attachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\AttachmentForm::class, 'form_id')
|
||||
return $this->hasMany(AttachmentForm::class, 'form_id')
|
||||
->where('table_name', \App\Enums\AttachmentTableName::FORM_VEHICLE_RUNNING_COST);
|
||||
}
|
||||
|
||||
public function rejector() {
|
||||
return $this->belongsTo(User::class, 'rejected_by');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Transaction extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'cabang_id', 'budget_control_id', 'transaction_date', 'reference_number',
|
||||
'description', 'amount', 'type', 'category', 'periode_month',
|
||||
'periode_year', 'created_by'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'transaction_date' => 'date',
|
||||
'amount' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function cabang() {
|
||||
return $this->belongsTo(Cabang::class);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,8 @@ class User extends Authenticatable
|
||||
'username',
|
||||
'password',
|
||||
'phone',
|
||||
'region_id',
|
||||
'cabang_id'
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -49,4 +51,42 @@ class User extends Authenticatable
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper untuk mendapatkan ID Cabang & Region milik user
|
||||
*/
|
||||
public function getMyCabangAndRegionId(): array
|
||||
{
|
||||
// Jika User punya cabang_id (Level AM / MR)
|
||||
if ($this->cabang_id) {
|
||||
$cabang = \DB::table('cabang')->where('id', $this->cabang_id)->first();
|
||||
return [
|
||||
'cabang' => (int) $this->cabang_id,
|
||||
'region' => $cabang ? (int) $cabang->region_id : null
|
||||
];
|
||||
}
|
||||
|
||||
// Jika User level Region (Admin Region / MOM Region)
|
||||
// Pastikan kolom 'region_id' ada di tabel users Anda
|
||||
return [
|
||||
'cabang' => null,
|
||||
'region' => $this->region_id ? (int) $this->region_id : null
|
||||
];
|
||||
}
|
||||
|
||||
public function cabangs()
|
||||
{
|
||||
// Relasi Many-to-Many melalui tabel pivot user_has_cabang
|
||||
return $this->belongsToMany(Cabang::class, 'user_has_cabang', 'user_id', 'cabang_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Mendapatkan ID Region berdasarkan penugasan cabang pertama
|
||||
*/
|
||||
public function getAssignedRegionId()
|
||||
{
|
||||
$firstAssignment = $this->cabangs()->first();
|
||||
return $firstAssignment ? $firstAssignment->region_id : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user