feat: implement barangay system phases 2-14
Some checks failed
tests / PHP 8.2 (swoole-5.1.6) (push) Has been cancelled
tests / PHP 8.3 (swoole-5.1.6) (push) Has been cancelled
tests / PHP 8.4 (swoole-6.0) (push) Has been cancelled

Complete adaptation from BukidBountyApp to Philippine barangay governance:

- Barangay models: Resident, Household, HouseholdMember, Blotter, BlotterHearing,
  DocumentRequest, RequestPayment, RequestType, BarangayProject, BarangayBudget
- Controllers: ResidentController, HouseholdController, BlotterController,
  BlotterHearingController, DocumentRequestController, RequestTypeController,
  ProjectController, BudgetController, QRPHController, AdminConsoleController,
  UserController, FileController, ChapterController, LoginController
- Vue pages: Home, ManageResidents, ResidentProfile, ManageHouseholds, ManageBlotters,
  BlotterDetail, RequestDocument, ManageDocumentRequests, DocumentRequestDetail,
  ManageRequestTypes, ManageProjects, BudgetLedger, AdminConsole
- Barangay roles: PunongBarangay, Kagawad, Secretary, Treasurer, SK, Tanod, BHW, Staff, Resident
- UserPermissions matrix rewritten with barangay-specific permission mappings
- VueRouteMap replaced with barangay SPA routes
- UserActions enum references corrected across all controllers
- Removed all market/cooperative/POS/subscription code and models
This commit is contained in:
Jonathan Sykes
2026-06-07 03:09:09 +08:00
parent 19fec0933b
commit fbb7e3ff37
234 changed files with 5582 additions and 39457 deletions

View File

@@ -1,57 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Accounting;
use App\Models\Model;
use App\Models\User;
class Account extends Model
{
protected ?string $table = 'accounts';
protected array $fillable = [
'hashkey',
'parent_id',
'store_id',
'type',
'default_flow',
'name',
'description',
'theme_key',
'theme_account_code',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'is_active' => 'boolean',
];
public function parent()
{
return $this->belongsTo(self::class, 'parent_id');
}
public function children()
{
return $this->hasMany(self::class, 'parent_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
public function transactions()
{
return $this->hasMany(AccountTransaction::class, 'account_id');
}
}

View File

@@ -1,49 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Accounting;
use App\Models\Model;
use App\Models\User;
class AccountTransaction extends Model
{
protected ?string $table = 'account_transactions';
protected array $fillable = [
'hashkey',
'account_id',
'item',
'target_id',
'amount',
'flow',
'notes',
'transaction_date',
'reference',
'additional_details',
'created_by',
'updated_by',
];
protected array $casts = [
'additional_details' => 'json',
'amount' => 'decimal:2',
'transaction_date' => 'datetime',
];
public function account()
{
return $this->belongsTo(Account::class, 'account_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,55 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Accounting;
use App\Models\Model;
use App\Models\User;
use App\Models\Market\Organization;
class MemberLedger extends Model
{
protected ?string $table = 'member_ledgers';
protected array $fillable = [
'hashkey',
'user_id',
'organization_id',
'amount',
'transaction_type',
'flow',
'balance_after',
'description',
'reference_id',
'created_by',
'updated_by',
'is_active',
];
protected array $casts = [
'amount' => 'decimal:2',
'balance_after' => 'decimal:2',
'is_active' => 'boolean',
];
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function organization()
{
return $this->belongsTo(Organization::class, 'organization_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace App\Models\Barangay;
use App\Models\Model;
class BarangayBudget extends Model
{
protected ?string $table = 'barangay_budget';
protected array $fillable = [
'hashkey', 'fiscal_year', 'category', 'source',
'amount', 'description', 'date', 'reference', 'encoded_by',
];
protected array $casts = [
'amount' => 'decimal:2',
'date' => 'date',
];
public function encodedBy()
{
return $this->belongsTo(\App\Models\User::class, 'encoded_by');
}
public function scopeIncome($query)
{
return $query->where('category', 'INCOME');
}
public function scopeExpense($query)
{
return $query->where('category', 'EXPENSE');
}
public function scopeByYear($query, int $year)
{
return $query->where('fiscal_year', $year);
}
}

View File

@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace App\Models\Barangay;
use App\Models\Model;
use Hypervel\Database\Eloquent\SoftDeletes;
class BarangayProject extends Model
{
use SoftDeletes;
protected ?string $table = 'barangay_projects';
protected array $fillable = [
'hashkey', 'project_name', 'description', 'type', 'budget',
'fund_source', 'start_date', 'end_date', 'status',
'implementing_office', 'contractor', 'location',
'beneficiaries_count', 'created_by', 'updated_by',
];
protected array $casts = [
'budget' => 'decimal:2',
'start_date' => 'date',
'end_date' => 'date',
'beneficiaries_count' => 'integer',
];
public function createdBy()
{
return $this->belongsTo(\App\Models\User::class, 'created_by');
}
public function scopeActive($query)
{
return $query->whereNotIn('status', ['CANCELLED', 'COMPLETED']);
}
public function scopeByType($query, string $type)
{
return $query->where('type', $type);
}
}

View File

@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace App\Models\Barangay;
use App\Models\Model;
use App\Enums\Barangay\BlotterStatus;
use Hypervel\Database\Eloquent\SoftDeletes;
class Blotter extends Model
{
use SoftDeletes;
protected ?string $table = 'barangay_blotters';
protected array $fillable = [
'hashkey', 'blotter_no',
'complainant_user_id', 'complainant_name', 'complainant_contact', 'complainant_address',
'respondent_user_id', 'respondent_name', 'respondent_contact', 'respondent_address',
'incident_type', 'incident_date', 'incident_location', 'narrative',
'status', 'complaint_date', 'filed_by', 'assigned_officer_id',
'resolution', 'settlement_type', 'endorsed_to', 'is_active',
'created_by', 'updated_by',
];
protected array $casts = [
'incident_date' => 'date',
'complaint_date' => 'date',
'is_active' => 'boolean',
'status' => BlotterStatus::class,
];
public function complainant()
{
return $this->belongsTo(\App\Models\User::class, 'complainant_user_id');
}
public function respondent()
{
return $this->belongsTo(\App\Models\User::class, 'respondent_user_id');
}
public function assignedOfficer()
{
return $this->belongsTo(\App\Models\User::class, 'assigned_officer_id');
}
public function hearings()
{
return $this->hasMany(BlotterHearing::class, 'blotter_id');
}
public function nextHearing()
{
return $this->hearings()->where('status', 'SCHEDULED')->orderBy('hearing_date')->first();
}
public function scopeActive($query)
{
return $query->where('is_active', true);
}
public static function generateBlotterNo(): string
{
$year = date('Y');
$count = static::whereYear('created_at', $year)->count() + 1;
return sprintf('BLT-%s-%04d', $year, $count);
}
}

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace App\Models\Barangay;
use App\Models\Model;
class BlotterHearing extends Model
{
protected ?string $table = 'barangay_blotter_hearings';
protected array $fillable = [
'blotter_id', 'hearing_date', 'status', 'officer_id',
'notes', 'resolution', 'next_hearing_date',
];
protected array $casts = [
'hearing_date' => 'datetime',
'next_hearing_date' => 'datetime',
];
public function blotter()
{
return $this->belongsTo(Blotter::class, 'blotter_id');
}
public function officer()
{
return $this->belongsTo(\App\Models\User::class, 'officer_id');
}
}

View File

@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
namespace App\Models\Barangay;
use App\Models\Model;
use App\Enums\Barangay\DocumentStatus;
use App\Enums\Barangay\PaymentStatus;
use Hypervel\Database\Eloquent\SoftDeletes;
class DocumentRequest extends Model
{
use SoftDeletes;
protected ?string $table = 'barangay_document_requests';
protected array $fillable = [
'hashkey', 'request_no', 'resident_user_id', 'request_type_id',
'purpose', 'fee_amount', 'payment_status', 'payment_method',
'payment_ref', 'qrph_code', 'status',
'requested_by', 'processed_by', 'claimed_at', 'notes',
];
protected array $casts = [
'fee_amount' => 'decimal:2',
'status' => DocumentStatus::class,
'payment_status' => PaymentStatus::class,
'claimed_at' => 'datetime',
];
public function requestType()
{
return $this->belongsTo(RequestType::class, 'request_type_id');
}
public function resident()
{
return $this->belongsTo(\App\Models\User::class, 'resident_user_id');
}
public function processedBy()
{
return $this->belongsTo(\App\Models\User::class, 'processed_by');
}
public function requestedBy()
{
return $this->belongsTo(\App\Models\User::class, 'requested_by');
}
public function payments()
{
return $this->hasMany(RequestPayment::class, 'request_id');
}
public function latestPayment()
{
return $this->payments()->latest()->first();
}
public static function generateRequestNo(): string
{
$year = date('Y');
$count = static::whereYear('created_at', $year)->count() + 1;
return sprintf('REQ-%s-%05d', $year, $count);
}
public function scopePending($query)
{
return $query->whereIn('status', [DocumentStatus::DRAFT, DocumentStatus::PENDING_PAYMENT]);
}
public function scopeForProcessing($query)
{
return $query->where('status', DocumentStatus::PAID);
}
}

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace App\Models\Barangay;
use App\Models\Model;
use Hypervel\Database\Eloquent\SoftDeletes;
class Household extends Model
{
use SoftDeletes;
protected ?string $table = 'barangay_households';
protected array $fillable = [
'hashkey', 'household_no', 'head_resident_id',
'address', 'purok', 'barangay', 'city', 'province',
'member_count', 'ownership_type', 'monthly_rental',
'has_electricity', 'has_water', 'housing_material',
'is_active', 'created_by', 'updated_by',
];
protected array $casts = [
'monthly_rental' => 'decimal:2',
'has_electricity' => 'boolean',
'has_water' => 'boolean',
'is_active' => 'boolean',
'member_count' => 'integer',
];
public function head()
{
return $this->belongsTo(Resident::class, 'head_resident_id');
}
public function members()
{
return $this->hasMany(HouseholdMember::class, 'household_id');
}
public function activeMembers()
{
return $this->members()->where('is_active', true);
}
public function scopeActive($query)
{
return $query->where('is_active', true);
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace App\Models\Barangay;
use App\Models\Model;
class HouseholdMember extends Model
{
protected ?string $table = 'barangay_household_members';
protected array $fillable = [
'household_id', 'resident_id', 'relationship_to_head', 'is_active',
];
protected array $casts = [
'is_active' => 'boolean',
];
public function household()
{
return $this->belongsTo(Household::class, 'household_id');
}
public function resident()
{
return $this->belongsTo(Resident::class, 'resident_id');
}
}

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace App\Models\Barangay;
use App\Models\Model;
class RequestPayment extends Model
{
protected ?string $table = 'barangay_request_payments';
protected array $fillable = [
'request_id', 'amount', 'method', 'reference',
'qrph_raw', 'paid_at', 'verified_by',
];
protected array $casts = [
'amount' => 'decimal:2',
'paid_at' => 'datetime',
];
public function documentRequest()
{
return $this->belongsTo(DocumentRequest::class, 'request_id');
}
public function verifiedBy()
{
return $this->belongsTo(\App\Models\User::class, 'verified_by');
}
}

View File

@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Models\Barangay;
use App\Models\Model;
class RequestType extends Model
{
protected ?string $table = 'barangay_request_types';
protected array $fillable = [
'name', 'code', 'description', 'base_fee',
'processing_days', 'is_active', 'requires_clearance',
];
protected array $casts = [
'base_fee' => 'decimal:2',
'processing_days' => 'integer',
'is_active' => 'boolean',
'requires_clearance' => 'boolean',
];
public function documentRequests()
{
return $this->hasMany(DocumentRequest::class, 'request_type_id');
}
public function scopeActive($query)
{
return $query->where('is_active', true);
}
}

View File

@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace App\Models\Barangay;
use App\Models\Model;
use Hypervel\Database\Eloquent\SoftDeletes;
class Resident extends Model
{
use SoftDeletes;
protected ?string $table = 'barangay_residents';
protected array $fillable = [
'hashkey', 'user_id', 'firstname', 'middlename', 'lastname', 'suffix',
'dob', 'birthplace', 'gender', 'civil_status', 'citizenship', 'religion',
'occupation', 'monthly_income', 'blood_type',
'voter_status', 'registered_voter_id', 'voter_precinct', 'head_of_household',
'purok', 'street', 'barangay', 'city', 'province', 'region',
'philhealth_id', 'sss_id', 'gsis_id', 'tin',
'emergency_contact_name', 'emergency_contact_phone', 'emergency_contact_address',
'is_active', 'created_by', 'updated_by',
];
protected array $casts = [
'dob' => 'date',
'monthly_income' => 'decimal:2',
'voter_status' => 'boolean',
'head_of_household' => 'boolean',
'is_active' => 'boolean',
];
public function user()
{
return $this->belongsTo(\App\Models\User::class, 'user_id');
}
public function household()
{
return $this->hasOne(Household::class, 'head_resident_id');
}
public function householdMemberships()
{
return $this->hasMany(HouseholdMember::class, 'resident_id');
}
public function documentRequests()
{
return $this->hasMany(DocumentRequest::class, 'resident_user_id', 'user_id');
}
public function scopeActive($query)
{
return $query->where('is_active', true);
}
public function getFullnameAttribute(): string
{
$parts = array_filter([$this->firstname, $this->middlename, $this->lastname]);
$name = implode(' ', $parts);
if ($this->suffix) $name .= ', ' . $this->suffix;
return $name;
}
}

View File

@@ -4,14 +4,12 @@ declare(strict_types=1);
namespace App\Models;
use App\Models\Market\UserInfo;
class Chapter extends Model
{
protected ?string $table = 'chapters';
protected array $fillable = [
'hashkey', 'name', 'cooperative_id', 'level', 'parent_id', 'location_key',
'hashkey', 'name', 'level', 'parent_id', 'location_key',
'lat', 'lng', 'is_active', 'created_by', 'updated_by',
];
@@ -26,11 +24,6 @@ class Chapter extends Model
return $this->belongsTo(Chapter::class, 'parent_id');
}
public function cooperative()
{
return $this->belongsTo(\App\Models\Market\Organization::class, 'cooperative_id');
}
public function children()
{
return $this->hasMany(Chapter::class, 'parent_id');
@@ -51,61 +44,19 @@ class Chapter extends Model
return $this->activeMembers()->whereNotNull('position');
}
/**
* Find or create a chapter by level + location_key (normalized address field).
*/
public static function findOrCreateByLocation(string $level, string $locationKey, ?int $parentId = null): self
{
$key = strtolower(trim($locationKey));
return static::firstOrCreate(
['level' => $level, 'location_key' => $key],
[
'hashkey' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
'name' => ucwords(strtolower($locationKey)),
'level' => $level,
'location_key'=> $key,
'parent_id' => $parentId,
'is_active' => true,
'hashkey' => hash('sha256', uniqid((string) now(), true)),
'name' => ucwords(strtolower($locationKey)),
'level' => $level,
'location_key' => $key,
'parent_id' => $parentId,
'is_active' => true,
]
);
}
/**
* Auto-assign a user to the appropriate chapters based on their UserInfo address.
* Creates chapter records on the fly if they don't exist.
*/
public static function autoAssignUser(int $userId): void
{
$info = UserInfo::where('user_id', $userId)->first();
if (!$info) {
return;
}
$national = static::firstOrCreate(
['level' => 'national', 'location_key' => 'philippines'],
['hashkey' => \Ramsey\Uuid\Uuid::uuid4()->toString(), 'name' => 'Philippines', 'level' => 'national', 'location_key' => 'philippines', 'is_active' => true]
);
ChapterMember::syncAutoAssignment($userId, $national->id);
if ($info->region) {
$region = static::findOrCreateByLocation('region', $info->region, $national->id);
ChapterMember::syncAutoAssignment($userId, $region->id);
if ($info->province) {
$province = static::findOrCreateByLocation('province', $info->province, $region->id);
ChapterMember::syncAutoAssignment($userId, $province->id);
if ($info->city) {
$city = static::findOrCreateByLocation('city', $info->city, $province->id);
ChapterMember::syncAutoAssignment($userId, $city->id);
if ($info->barangay) {
$barangay = static::findOrCreateByLocation('barangay', $info->barangay, $city->id);
ChapterMember::syncAutoAssignment($userId, $barangay->id);
}
}
}
}
}
}

View File

@@ -1,47 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Generic;
use App\Models\Model;
use App\Models\User;
class TableLog extends Model
{
protected ?string $table = 'table_logs';
protected array $casts = [
'original_data' => 'array',
'new_data' => 'array',
];
protected array $fillable = [
'hashkey',
'table_name',
'target_id',
'original_data',
'new_data',
'created_by',
'updated_by',
];
// Auto-merge accessor
public function get_full_new_row(): array
{
return array_merge($this->original_data ?? [], $this->new_data ?? []);
}
public function data(){
return $this->get_full_new_row();
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,72 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models;
use App\Models\Model;
use App\Models\User;
use App\Models\Market\Product;
use App\Models\Market\Store;
use App\Enums\Market\ProductTransactionType;
use App\Enums\Market\TransactionFlow;
class GlobalTransaction extends Model
{
protected ?string $table = 'global_transactions';
protected string $primaryKey = 'id';
public bool $incrementing = true;
protected string $keyType = 'int';
protected array $fillable = [
'hashkey',
'user_id',
'amount',
'type',
'status',
'description',
'product_id',
'store_id',
'flow',
'created_by',
'updated_by',
];
protected array $casts = [
'amount' => 'decimal:2',
'type' => ProductTransactionType::class,
'user_id' => 'integer',
'product_id' => 'integer',
'store_id' => 'integer',
'flow' => TransactionFlow::class,
'created_by' => 'integer',
'updated_by' => 'integer',
];
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
public function store()
{
return $this->belongsTo(Store::class, 'store_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,35 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class Cart extends Model
{
protected ?string $table = 'carts';
protected array $fillable = [
'hashkey',
'user_id',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'is_active' => 'boolean',
];
public function items()
{
return $this->hasMany(CartItem::class, 'cart_id');
}
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
}

View File

@@ -1,39 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
class CartItem extends Model
{
protected ?string $table = 'cart_items';
protected array $fillable = [
'hashkey',
'cart_id',
'product_id',
'quantity',
'price',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'is_active' => 'boolean',
'quantity' => 'integer',
'price' => 'float',
];
public function cart()
{
return $this->belongsTo(Cart::class, 'cart_id');
}
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
}

View File

@@ -1,41 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\User;
use Hypervel\Database\Eloquent\Model;
class CooperativeDocument extends Model
{
protected ?string $table = 'cooperative_documents';
protected array $fillable = [
'hashkey',
'parent_hashkey',
'version_number',
'organization_id',
'file_hashkey',
'document_type',
'revision_note',
'created_by',
'updated_by',
'is_active',
];
public function organization()
{
return $this->belongsTo(Organization::class, 'organization_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,63 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class CooperativeMember extends Model
{
protected ?string $table = 'cooperative_members';
protected array $fillable = [
'hashkey', 'organization_id', 'user_id', 'role',
'membership_type', 'membership_level',
'officer_position', 'officer_level',
'concurrent_position', 'concurrent_level',
'cooperative_name_alt', 'cooperative_position', 'year_beginning',
// Classification
'priority_sector', 'common_bond', 'vulnerability_classifications',
// Government IDs
'philsys_id', 'sss_number', 'pagibig_number',
// SLP
'slp_track', 'slp_association_name', 'listahanan_id', 'fourtps_household_id',
// TUPAD
'tupad_category', 'tupad_insurance_beneficiary_name', 'tupad_insurance_beneficiary_relation',
// OSEC/NSRP
'preferred_occupation', 'nsrp_skills', 'employment_status',
// Programs
'program_participation',
'joined_at', 'is_active', 'created_by', 'updated_by',
];
protected array $casts = [
'joined_at' => 'datetime',
'is_active' => 'boolean',
'priority_sector' => 'array',
'vulnerability_classifications' => 'array',
'nsrp_skills' => 'array',
'program_participation' => 'array',
];
public function organization()
{
return $this->belongsTo(Organization::class, 'organization_id');
}
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,51 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class CooperativeResolution extends Model
{
protected ?string $table = 'cooperative_resolutions';
protected array $fillable = [
'hashkey',
'organization_id',
'title',
'description',
'date_approved',
'document_url',
'status',
'created_by',
'updated_by',
'is_active',
];
protected array $casts = [
'date_approved' => 'date',
'is_active' => 'boolean',
];
public function organization()
{
return $this->belongsTo(Organization::class, 'organization_id');
}
public function votes()
{
return $this->hasMany(CooperativeVote::class, 'resolution_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,47 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class CooperativeVote extends Model
{
protected ?string $table = 'cooperative_votes';
protected array $fillable = [
'hashkey',
'resolution_id',
'user_id',
'vote_cast',
'created_by',
'updated_by',
'is_active',
];
protected array $casts = [
'is_active' => 'boolean',
];
public function resolution()
{
return $this->belongsTo(CooperativeResolution::class, 'resolution_id');
}
public function voter()
{
return $this->belongsTo(User::class, 'user_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,42 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class Courier extends Model
{
protected ?string $table = 'couriers';
protected array $fillable = [
'hashkey',
'name',
'contact_number',
'type',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'is_active' => 'boolean',
];
public function shipments()
{
return $this->hasMany(Shipment::class, 'courier_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,52 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class Customer extends Model
{
protected ?string $table = 'cst';
protected array $fillable = [
'hashkey',
'name',
'phone',
'email',
'store_id',
'user_id',
'created_by',
'updated_by',
'is_active',
];
protected array $casts = [
'is_active' => 'boolean',
];
/**
* Relationships
*/
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function store()
{
return $this->belongsTo(Store::class, 'store_id');
}
}

View File

@@ -1,53 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class FarmerProfile extends Model
{
protected ?string $table = 'farmer_profiles';
protected array $fillable = [
'hashkey',
'user_id',
'organization_id',
'farm_name',
'farm_location',
'main_crops',
'verification_status',
'certification_details',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'main_crops' => 'array',
'certification_details' => 'array',
'is_active' => 'boolean',
];
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function organization()
{
return $this->belongsTo(Organization::class, 'organization_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,44 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class MainOrganization extends Model
{
protected ?string $table = 'main_organizations';
protected array $fillable = [
'organization_id',
'role',
'priority',
'is_active',
'metadata',
'created_by',
'updated_by',
];
protected array $casts = [
'is_active' => 'boolean',
'priority' => 'integer',
'metadata' => 'array',
];
public function organization()
{
return $this->belongsTo(Organization::class, 'organization_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,78 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class Organization extends Model
{
protected ?string $table = 'organizations';
protected array $fillable = [
'hashkey',
'name',
'type',
'address',
'registration_number',
'cin',
'tin',
'cooperative_type',
'cooperative_category',
'registration_date',
'contact_person',
'contact_number',
'contact_email',
'compliance_status',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'is_active' => 'boolean',
'registration_date' => 'date',
];
public function members()
{
return $this->hasMany(CooperativeMember::class, 'organization_id');
}
public function farmerProfiles()
{
return $this->hasMany(FarmerProfile::class, 'organization_id');
}
public function stores()
{
return $this->belongsToMany(Store::class, 'org_str', 'organization_id', 'store_id')
->withTimestamps();
}
public function mainAssignments()
{
return $this->hasMany(MainOrganization::class, 'organization_id');
}
public function isMain(?string $role = null): bool
{
$query = $this->mainAssignments()->where('is_active', true);
if ($role !== null) {
$query->where('role', $role);
}
return $query->exists();
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,89 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
/**
* @property int $id
* @property string $hashkey
* @property string $access_key
* @property int $store_id
* @property string $name
* @property string $status
* @property string $last_used_at
* @property int $created_by
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
*/
class PosAccessKey extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'pos_access_keys';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [
'hashkey',
'access_key',
'store_id',
'name',
'status',
'is_active',
'expires_at',
'last_used_at',
'created_by',
'updated_by',
];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = [
'id' => 'integer',
'store_id' => 'integer',
'created_by' => 'integer',
'updated_by' => 'integer',
'is_active' => 'boolean',
'expires_at' => 'datetime',
];
/**
* Check if this access key is expired.
*/
public function isExpired(): bool
{
return $this->expires_at !== null && $this->expires_at->isPast();
}
/**
* Auto-expire: set all expired active keys to inactive.
* Call this before listing or validating keys.
*/
public static function autoExpire(): void
{
self::where('status', 'active')
->whereNotNull('expires_at')
->where('expires_at', '<', now())
->update(['status' => 'inactive']);
}
/**
* Relationships
*/
public function store()
{
return $this->belongsTo(Store::class, 'store_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
}

View File

@@ -1,70 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class PosSession extends Model
{
protected ?string $table = 'pos_sessions';
protected array $fillable = [
'hashkey',
'access_key',
'store_id',
'created_by',
'updated_by',
'customer_name',
'total_amount',
'received_amount',
'change_amount',
'payment_method',
'payment_details',
'status',
'is_void',
'notes',
'additionaldata',
];
protected array $casts = [
'is_void' => 'boolean',
'payment_details' => 'array',
'additionaldata' => 'array',
'total_amount' => 'integer',
'received_amount' => 'integer',
'change_amount' => 'integer',
'created_by' => 'integer',
'updated_by' => 'integer',
];
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
/**
* Relationships
*/
public function transactions()
{
return $this->hasMany(PosTransaction::class, 'pos_session_id');
}
public function archives()
{
return $this->hasMany(PosSessionArchive::class, 'pos_session_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function store()
{
return $this->belongsTo(Store::class, 'store_id');
}
}

View File

@@ -1,49 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class PosSessionArchive extends Model
{
protected ?string $table = 'pos_sessions_archive';
protected array $fillable = [
'pos_session_id',
'hashkey',
'session_snapshot',
'transactions_snapshot',
'created_by',
'updated_by',
'remarks',
];
protected array $casts = [
'session_snapshot' => 'array',
'transactions_snapshot' => 'array',
'created_by' => 'integer',
'updated_by' => 'integer',
'pos_session_id' => 'integer',
];
/**
* Relationships
*/
public function session()
{
return $this->belongsTo(PosSession::class, 'pos_session_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,49 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
class PosTransaction extends Model
{
protected ?string $table = 'pos_transactions';
protected array $fillable = [
'pos_session_id',
'product_id',
'quantity',
'price_at_sale',
'discount',
'total_price',
'is_void',
'remarks',
'hashkey',
'created_by',
'updated_by',
];
protected array $casts = [
'is_void' => 'boolean',
'quantity' => 'integer',
'price_at_sale' => 'integer',
'discount' => 'integer',
'total_price' => 'integer',
'created_by' => 'integer',
'updated_by' => 'integer',
];
/**
* Relationships
*/
public function session()
{
return $this->belongsTo(PosSession::class, 'pos_session_id');
}
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
}

View File

@@ -1,91 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class Product extends Model
{
protected ?string $table = 'prd_items';
protected string $primaryKey = 'id';
public bool $incrementing = true;
protected string $keyType = 'int';
protected array $fillable = [
'hashkey',
'created_by',
'updated_by',
'created_for',
'category',
'subcategory',
'logs',
'specs',
'photourl',
'available',
'sold',
'price',
// 'store_id',
'owner_id',
'views',
'name',
'description',
'reviews',
'barcode',
'status',
'remarks',
'unitname',
'rating',
'sku',
'qrcode',
'shortcode',
'shortname',
'is_active',
'product_type'
];
protected array $casts = [
'available' => 'integer',
'sold' => 'integer',
'price' => 'integer',
'views' => 'integer',
'rating' => 'integer',
'is_active' => 'boolean',
'photourl' => 'array',
'reviews' => 'array',
'specs' => 'array',
];
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
public function stores()
{
return $this->belongsToMany(Store::class, 'prd_str')
->withPivot(['available', 'price', 'is_active'])
->withTimestamps();
}
public function owner()
{
return $this->belongsTo(User::class, 'owner_id');
}
public function createdFor()
{
return $this->belongsTo(User::class, 'created_for');
}
}

View File

@@ -1,102 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class ProductTransaction extends Model
{
protected ?string $table = 'prd_trx';
/**
* The primary key for the model.
*/
protected string $primaryKey = 'id';
/**
* Indicates if the IDs are auto-incrementing.
*/
public bool $incrementing = true;
/**
* The "type" of the primary key.
*/
protected string $keyType = 'int';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [
'hashkey',
'created_by',
'updated_by',
'created_for',
'store_id',
'transactiontype',
'product_id',
'transactiondata',
'description',
'subtype',
'name',
'owner_id',
'transactionsessionhash',
'quantity',
'logs',
'remarks',
'price',
'is_void',
'last_total_price',
'last_total_discount',
'notes'
];
/**
* The attributes that should be cast.
*/
protected array $casts = [
'quantity' => 'integer',
'price' => 'integer',
'is_void' => 'boolean',
];
/**
* Relationships.
*/
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
public function store()
{
return $this->belongsTo(Store::class, 'store_id');
}
public function owner()
{
return $this->belongsTo(User::class, 'owner_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
public function createdFor()
{
return $this->belongsTo(User::class, 'created_for');
}
public function session()
{
return $this->belongsTo(ProductTransactionSession::class, 'transactionsessionhash', 'hashkey');
}
}

View File

@@ -1,84 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class ProductTransactionSession extends Model
{
protected ?string $table = 'prd_trx_ses';
/**
* The primary key for the model.
*/
protected $primaryKey = 'id';
/**
* Indicates if the IDs are auto-incrementing.
*/
public $incrementing = true;
/**
* The "type" of the primary key.
*/
protected $keyType = 'int';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [
'hashkey',
'name',
'description',
'logs',
'remarks',
'created_by',
'updated_by',
'created_for',
'subtype',
'additionaldata',
'category',
'store_id',
'status',
'is_void',
'last_total_price',
'last_total_discount',
'notes',
];
protected array $casts = [
'is_void' => 'boolean',
];
/**
* Relationships.
*/
public function transactions()
{
return $this->hasMany(ProductTransaction::class, 'transactionsessionhash', 'hashkey');
}
public function store()
{
return $this->belongsTo(Store::class, 'store_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
public function createdFor()
{
return $this->belongsTo(User::class, 'created_for');
}
}

View File

@@ -1,72 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class ProductTransactionSessionArchive extends Model
{
protected ?string $table = 'prd_trx_ses_arc';
/**
* The primary key for the model.
*/
protected $primaryKey = 'id';
/**
* Indicates if the IDs are auto-incrementing.
*/
public $incrementing = true;
/**
* The "type" of the primary key.
*/
protected $keyType = 'int';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [
'name',
'description',
'details',
'hashkey',
'transactions_sessions_id',
'created_by',
'updated_by',
'created_for',
'transactions_snapshot'
];
protected array $casts = [
'details' => 'array',
'transactions_snapshot' => 'array',
];
/**
* Relationships.
*/
public function transactionSession()
{
return $this->belongsTo(ProductTransactionSession::class, 'transactions_sessions_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
public function createdFor()
{
return $this->belongsTo(User::class, 'created_for');
}
}

View File

@@ -1,69 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
use App\Models\GlobalTransaction;
class Shipment extends Model
{
protected ?string $table = 'shipments';
protected array $fillable = [
'hashkey',
'transaction_id',
'store_id',
'customer_id',
'courier_id',
'tracking_number',
'status',
'origin_address',
'destination_address',
'estimated_delivery_date',
'actual_delivery_date',
'shipping_fee',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'estimated_delivery_date' => 'datetime',
'actual_delivery_date' => 'datetime',
'shipping_fee' => 'decimal:2',
'is_active' => 'boolean',
];
public function transaction()
{
return $this->belongsTo(GlobalTransaction::class, 'transaction_id');
}
public function store()
{
return $this->belongsTo(Store::class, 'store_id');
}
public function customer()
{
return $this->belongsTo(Customer::class, 'customer_id');
}
public function courier()
{
return $this->belongsTo(Courier::class, 'courier_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,117 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class Store extends Model
{
protected ?string $table = 'str';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [
'hashkey',
'storecode',
'name',
'description',
'status',
'created_by',
'updated_by',
'created_for',
'remarks',
'logs',
'specs',
'additionaldata',
'owner_id',
'manager_id',
'category',
'subcategory',
'photourl',
'address',
'is_active',
'store_type',
];
protected array $casts = [
'photourl' => 'array',
'is_active' => 'boolean',
'store_type'=> 'array',
'specs' => 'array',
];
/**
* Relationships
*/
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
public function createdFor()
{
return $this->belongsTo(User::class, 'created_for');
}
public function owner()
{
return $this->belongsTo(User::class, 'owner_id');
}
public function manager()
{
return $this->belongsTo(User::class, 'manager_id');
}
public function managers()
{
return $this->hasMany(StoreManager::class, 'store_id');
}
public function managerUsers()
{
return $this->belongsToMany(User::class, 'store_managers', 'store_id', 'user_id')
->withPivot(['hashkey', 'created_by', 'updated_by', 'is_active'])
->withTimestamps();
}
// public function products()
// {
// return $this->hasMany(Product::class, 'store_id');
// }
public function products()
{
return $this->belongsToMany(Product::class, 'prd_str')
->withPivot(['available', 'price', 'is_active','sold','logs','reviews','status','remarks','description'])
->withTimestamps();
}
public function cooperatives()
{
return $this->belongsToMany(Organization::class, 'org_str', 'store_id', 'organization_id')
->where('organizations.type', 'COOPERATIVE')
->withTimestamps();
}
public function transactions()
{
return $this->hasMany(ProductTransaction::class, 'store_id');
}
public function transactionSessions()
{
return $this->hasMany(ProductTransactionSession::class, 'store_id');
}
}

View File

@@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class StoreManager extends Model
{
protected ?string $table = 'store_managers';
protected array $fillable = [
'hashkey',
'store_id',
'user_id',
'created_by',
'updated_by',
'is_active',
];
protected array $casts = [
'is_active' => 'boolean',
];
public function store()
{
return $this->belongsTo(Store::class, 'store_id');
}
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,114 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Market;
use App\Models\Model;
use App\Models\User;
class UserInfo extends Model
{
protected ?string $table = 'user_infos';
protected array $fillable = [
'hashkey',
'user_id',
'firstname',
'middlename',
'lastname',
'suffix',
'gender',
'dob',
'priority_sector',
'messenger_id',
'viber_number',
'tiktok_username',
'region',
'province',
'city',
'barangay',
'civil_status',
'children_count',
'dependent_count',
'education_level',
'course',
'school',
'year_last_attended',
'livelihood_source',
'last_company',
'employer_name',
'last_position',
'occupation',
'last_employment_year',
'monthly_income',
'tin',
'philhealth_id',
'gov_id',
'id_type',
'id_number',
'beneficiary_type',
'emergency_contact_name',
'emergency_contact_address',
'emergency_contact_phone',
'emergency_contact_relation',
'emergency_contact_user_id',
'fullname',
'landline',
'mobile',
'email',
'alt_email',
'alt_landline',
'alt_mobile',
'facebook_url',
'bank_details',
'bank_account_no',
'addresses',
'other_details',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'bank_details' => 'json',
'addresses' => 'json',
'other_details' => 'json',
'is_active' => 'boolean',
'dob' => 'date',
'monthly_income' => 'float',
'children_count' => 'integer',
'dependent_count' => 'integer',
];
/**
* Get the virtual age attribute.
*/
public function getAgeAttribute(): ?int
{
if (!$this->dob) {
return null;
}
return $this->dob->diffInYears(now());
}
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function emergencyContactUser()
{
return $this->belongsTo(User::class, 'emergency_contact_user_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Property;
use App\Models\Model;
use App\Models\User;
class Property extends Model
{
protected ?string $table = 'properties';
protected array $fillable = [
'hashkey',
'name',
'location',
'price',
'status',
'details',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'details' => 'json',
'price' => 'decimal:2',
'is_active' => 'boolean',
];
public function referrals()
{
return $this->hasMany(Referral::class, 'property_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,57 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Property;
use App\Models\Model;
use App\Models\User;
class Referral extends Model
{
protected ?string $table = 'referrals';
protected array $fillable = [
'hashkey',
'property_id',
'referrer_id',
'referred_id',
'referred_name',
'referred_contact',
'status',
'details',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'details' => 'json',
'is_active' => 'boolean',
];
public function property()
{
return $this->belongsTo(Property::class, 'property_id');
}
public function referrer()
{
return $this->belongsTo(User::class, 'referrer_id');
}
public function referred()
{
return $this->belongsTo(User::class, 'referred_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,41 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Property;
use App\Models\Model;
use App\Models\User;
class ReferralKey extends Model
{
protected ?string $table = 'referral_keys';
protected array $fillable = [
'hashkey',
'user_id',
'key',
'is_active',
'created_by',
'updated_by',
];
protected array $casts = [
'is_active' => 'boolean',
];
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater()
{
return $this->belongsTo(User::class, 'updated_by');
}
}

View File

@@ -1,54 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Subscription;
use Hyperf\DbConnection\Model\Model;
use App\Models\User;
class Subscription extends Model
{
protected ?string $table = 'subscriptions';
public bool $incrementing = true;
protected array $fillable = [
'hashkey',
'user_id',
'plan_id',
'status',
'starts_at',
'expires_at',
'payment_method',
'additional_details',
'created_by',
'updated_by',
];
protected array $casts = [
'starts_at' => 'datetime',
'expires_at' => 'datetime',
'additional_details' => 'array',
];
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function plan()
{
return $this->belongsTo(SubscriptionPlan::class, 'plan_id');
}
public function invoices()
{
return $this->hasMany(SubscriptionInvoice::class, 'subscription_id');
}
public function isActive(): bool
{
return $this->status === 'active' && $this->expires_at && $this->expires_at->isFuture();
}
}

View File

@@ -1,45 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Subscription;
use Hyperf\DbConnection\Model\Model;
use App\Models\User;
class SubscriptionInvoice extends Model
{
protected ?string $table = 'subscription_invoices';
public bool $incrementing = true;
protected array $fillable = [
'hashkey',
'subscription_id',
'user_id',
'amount',
'status',
'paid_at',
'payment_method',
'payment_reference',
'additional_details',
'created_by',
'updated_by',
];
protected array $casts = [
'amount' => 'float',
'paid_at' => 'datetime',
'additional_details' => 'array',
];
public function subscription()
{
return $this->belongsTo(Subscription::class, 'subscription_id');
}
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
}

View File

@@ -1,45 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models\Subscription;
use Hyperf\DbConnection\Model\Model;
use App\Models\User;
class SubscriptionPlan extends Model
{
protected ?string $table = 'subscription_plans';
public bool $incrementing = true;
protected array $fillable = [
'hashkey',
'name',
'description',
'price',
'duration_days',
'expiry_action',
'active',
'additional_details',
'created_by',
'updated_by',
];
protected array $casts = [
'active' => 'boolean',
'price' => 'float',
'duration_days' => 'integer',
'additional_details' => 'array',
];
public function subscriptions()
{
return $this->hasMany(Subscription::class, 'plan_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
}

View File

@@ -84,14 +84,9 @@ class User extends Authenticatable
'denied_roles' => \App\Casts\UserActionsArrayCast::class ,
];
public function userInfo()
public function resident()
{
return $this->hasOne(\App\Models\Market\UserInfo::class, 'user_id');
}
public function cooperativeMemberships()
{
return $this->hasMany(\App\Models\Market\CooperativeMember::class, 'user_id');
return $this->hasOne(\App\Models\Barangay\Resident::class, 'user_id');
}
public function creator()
@@ -153,17 +148,21 @@ class User extends Authenticatable
*/
public function isUltimate(): bool
{
return $this->acct_type === UserTypes::ULTIMATE;
return $this->acct_type === UserTypes::SUPER_ADMIN;
}
public function isSuperOperator(): bool
public function isPunongBarangay(): bool
{
return $this->acct_type === UserTypes::SUPER_OPERATOR;
return $this->acct_type === UserTypes::PUNONG_BARANGAY;
}
public function isOperator(): bool
public function isBarangayStaff(): bool
{
return $this->acct_type === UserTypes::OPERATOR;
return in_array($this->acct_type, [
UserTypes::PUNONG_BARANGAY, UserTypes::KAGAWAD, UserTypes::SECRETARY,
UserTypes::TREASURER, UserTypes::SK_CHAIRPERSON, UserTypes::SK_COUNCILOR,
UserTypes::TANOD, UserTypes::BHW, UserTypes::DAYCARE_WORKER, UserTypes::STAFF,
]);
}
/**