migrate to gtea from bistbucket

This commit is contained in:
2026-03-15 17:08:23 +07:00
commit 129ca2260c
3716 changed files with 566316 additions and 0 deletions

25
app/Models/Banner.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Banner extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'imageUrl',
'status',
];
protected $casts = [
'status' => 'integer',
];
}

34
app/Models/Blog.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Blog extends Model
{
use HasFactory;
protected $fillable = ['user_id', 'title', 'slug', 'image', 'status', 'descriptions', 'tags', 'meta'];
protected $casts = [
'user_id' => 'integer',
'tags' => 'json',
'meta' => 'json',
'status' => 'integer'
];
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
protected static function boot()
{
parent::boot();
static::creating(function ($blog) {
$blog->slug = Str::slug($blog->title);
});
}
}

71
app/Models/Branch.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Modules\HrmAddon\App\Models\Employee;
class Branch extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'business_id',
'name',
'phone',
'email',
'is_main',
'address',
'description',
'status',
'branchOpeningBalance',
'branchRemainingBalance',
];
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->business_id = auth()->user()->business_id;
});
}
public function users(): HasMany
{
return $this->hasMany(User::class, 'branch_id');
}
public function employees(): ?HasMany
{
return moduleCheck('MultiBranchAddon')
? $this->hasMany(Employee::class, 'branch_id')
: null;
}
public function expiredStocks(): HasMany
{
return $this->hasMany(Stock::class, 'branch_id')->whereDate('expire_date', '<', today())->where('productStock', '>', 0);
}
public function sales(): HasMany
{
return $this->hasMany(Sale::class, 'branch_id');
}
public function purchases(): HasMany
{
return $this->hasMany(Purchase::class, 'branch_id');
}
protected $casts = [
'business_id' => 'integer',
'is_main' => 'integer',
'status' => 'integer',
'branchOpeningBalance' => 'double',
'branchRemainingBalance' => 'double',
];
}

29
app/Models/Brand.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Brand extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'brandName',
'description',
'business_id',
'icon',
'status',
];
protected $casts = [
'business_id' => 'integer',
'status' => 'integer'
];
}

71
app/Models/Business.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Modules\AffiliateAddon\App\Models\Affiliate;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Business extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'plan_subscribe_id',
'business_category_id',
'companyName',
'address',
'phoneNumber',
'pictureUrl',
'will_expire',
'subscriptionDate',
'remainingShopBalance',
'shopOpeningBalance',
'vat_name',
'vat_no',
'affiliator_id',
'email',
'status',
'meta'
];
public function enrolled_plan()
{
return $this->belongsTo(PlanSubscribe::class, 'plan_subscribe_id');
}
public function category()
{
return $this->belongsTo(BusinessCategory::class, 'business_category_id');
}
public function user()
{
return $this->hasMany(User::class);
}
public function affiliator(): BelongsTo
{
return $this->belongsTo(Affiliate::class, 'affiliator_id');
}
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'plan_subscribe_id' => 'integer',
'business_category_id' => 'integer',
'remainingShopBalance' => 'double',
'shopOpeningBalance' => 'double',
'status' => 'integer',
'meta' => 'json',
];
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class BusinessCategory extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'status',
'description',
];
protected $casts = [
'status' => 'integer'
];
}

43
app/Models/Category.php Normal file
View File

@@ -0,0 +1,43 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'categoryName',
'business_id',
'variationCapacity',
'variationColor',
'variationSize',
'variationType',
'variationWeight',
'icon',
'status',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'business_id' => 'integer',
'variationSize' => 'boolean',
'variationColor' => 'boolean',
'variationCapacity' => 'boolean',
'variationType' => 'boolean',
'variationWeight' => 'boolean',
'status' => 'integer',
];
}

View File

@@ -0,0 +1,54 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class ComboProduct extends Model
{
use HasFactory;
protected $fillable = [
'product_id',
'stock_id',
'branch_id',
'purchase_price',
'quantity',
];
public $timestamps = false;
protected static function booted()
{
static::addGlobalScope(new BranchScope);
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
public function product()
{
return $this->belongsTo(Product::class, 'product_id', 'id');
}
public function stock()
{
return $this->belongsTo(Stock::class);
}
protected $casts = [
'product_id' => 'integer',
'branch_id' => 'integer',
'stock_id' => 'integer',
'quantity' => 'double',
'purchase_price' => 'double',
];
}

35
app/Models/Comment.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Comment extends Model
{
use HasFactory;
protected $fillable = ['name', 'email', 'comment', 'blog_id'];
public function blog(): BelongsTo
{
return $this->belongsTo(Blog::class);
}
public function parentComment(): BelongsTo
{
return $this->belongsTo(Comment::class, 'comment_id');
}
public function replies(): HasMany
{
return $this->hasMany(Comment::class, 'comment_id');
}
protected $casts = [
'blog_id' => 'integer',
'comment_id' => 'integer',
'status' => 'integer'
];
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CreditRange extends Model
{
use HasFactory;
protected $fillable = [
'business_id',
'name',
'range',
'status',
];
protected $casts =[
'business_id' => 'integer',
'range' => 'double',
'status' => 'integer',
];
}

33
app/Models/Currency.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Currency extends Model
{
use HasFactory;
protected $fillable = [
'name',
'country_name',
'code',
'rate',
'symbol',
'position',
'status',
'is_default',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'status' => 'boolean',
'is_default' => 'boolean',
'rate' => 'double',
];
}

115
app/Models/DueCollect.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class DueCollect extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'business_id',
'party_id',
'user_id',
'branch_id',
'sale_id',
'purchase_id',
'invoiceNumber',
'totalDue',
'dueAmountAfterPay',
'payDueAmount',
'paymentType',
'payment_type_id',
'paymentDate',
];
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$id = DueCollect::where('business_id', auth()->user()?->business_id ?? 1)->count() + 1;
$model->invoiceNumber = "D" . str_pad($id, 2, '0', STR_PAD_LEFT);
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function party(): BelongsTo
{
return $this->belongsTo(Party::class);
}
public function sale(): BelongsTo
{
return $this->belongsTo(Sale::class);
}
public function purchase(): BelongsTo
{
return $this->belongsTo(Purchase::class);
}
public function business(): BelongsTo
{
return $this->belongsTo(Business::class);
}
public function payment_type(): BelongsTo
{
return $this->belongsTo(PaymentType::class);
}
public function transactions()
{
return $this->hasMany(Transaction::class, 'reference_id')
->whereIn('platform', ['due_collect', 'due_pay']);
}
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'business_id' => 'integer',
'payment_type_id' => 'integer',
'user_id' => 'integer',
'party_id' => 'integer',
'sale_id' => 'integer',
'purchase_id' => 'integer',
'branch_id' => 'integer',
'payDueAmount' => 'double',
'totalDue' => 'double',
'dueAmountAfterPay' => 'double',
];
}

92
app/Models/Expense.php Normal file
View File

@@ -0,0 +1,92 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Expense extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'expense_category_id',
'business_id',
'branch_id',
'user_id',
'amount',
'expanseFor',
'paymentType',
'payment_type_id',
'referenceNo',
'note',
'expenseDate',
];
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
public function category(): BelongsTo
{
return $this->belongsTo(ExpenseCategory::class, 'expense_category_id');
}
public function payment_type(): BelongsTo
{
return $this->belongsTo(PaymentType::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function transactions()
{
return $this->hasMany(Transaction::class, 'reference_id')
->where('platform', 'expense');
}
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'amount' => 'double',
'user_id' => 'integer',
'business_id' => 'integer',
'payment_type_id' => 'integer',
'expense_category_id' => 'integer',
'branch_id' => 'integer',
];
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class ExpenseCategory extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'categoryName',
'business_id',
'categoryDescription',
'status',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'business_id' => 'integer',
'status' => 'boolean',
];
}

22
app/Models/Feature.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Feature extends Model
{
use HasFactory;
protected $fillable = [
'title',
'bg_color',
'image',
'status',
];
protected $casts = [
'status' => 'integer',
];
}

53
app/Models/Gateway.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Gateway extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'mode',
'data',
'image',
'status',
'charge',
'platform',
'is_manual',
'namespace',
'accept_img',
'manual_data',
'currency_id',
'instructions',
'phone_required',
];
public function currency()
{
return $this->belongsTo(Currency::class, 'currency_id');
}
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'currency_id' => 'integer',
'phone_required' => 'integer',
'data' => 'json',
'manual_data' => 'json',
'charge' => 'integer',
'is_manual' => 'integer',
'accept_img' => 'integer',
];
}

82
app/Models/Income.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Income extends Model
{
use HasFactory;
protected $fillable = [
'income_category_id',
'business_id',
'branch_id',
'user_id',
'amount',
'incomeFor',
'paymentType',
'payment_type_id',
'referenceNo',
'note',
'incomeDate',
];
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
public function category(): BelongsTo
{
return $this->belongsTo(IncomeCategory::class, 'income_category_id');
}
public function payment_type(): BelongsTo
{
return $this->belongsTo(PaymentType::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function transactions()
{
return $this->hasMany(Transaction::class, 'reference_id')
->where('platform', 'income');
}
protected $casts = [
'amount' => 'double',
'income_category_id' => 'integer',
'user_id' => 'integer',
'business_id' => 'integer',
'payment_type_id' => 'integer',
'branch_id' => 'integer',
];
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class IncomeCategory extends Model
{
use HasFactory;
protected $fillable = [
'categoryName',
'business_id',
'categoryDescription',
'status',
];
protected $casts = [
'business_id' =>'integer',
'status' => 'boolean'
];
}

20
app/Models/Language.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Language extends Model
{
use HasFactory;
protected $fillable = [
'name',
'icon',
'status',
];
protected $casts = [
'status' => 'integer',
];
}

12
app/Models/Message.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Message extends Model
{
use HasFactory;
protected $fillable = ['name', 'phone', 'email', 'company_name', 'message'];
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Notification extends Model
{
use HasFactory, SoftDeletes;
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'notifications';
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'data' => 'json',
];
}

18
app/Models/Option.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Option extends Model
{
use HasFactory;
protected $fillable = ['key','value','status'];
protected $casts = [
'value' => 'json',
'status' => 'integer'
];
}

104
app/Models/Party.php Normal file
View File

@@ -0,0 +1,104 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Party extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'type',
'name',
'email',
'phone',
'due',
'image',
'status',
'address',
'branch_id',
'business_id',
'credit_limit',
'loyalty_points',
'wallet',
'opening_balance',
'opening_balance_type',
'billing_address',
'shipping_address',
'meta',
];
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
public function sales()
{
return $this->hasMany(Sale::class);
}
public function purchases()
{
return $this->hasMany(Purchase::class);
}
public function canBeDeleted(): bool
{
// Party cannot be deleted if it has sales or purchases
if ($this->sales()->exists() || $this->purchases()->exists()) {
return false;
}
// Party cannot be deleted if due != opening_balance or wallet != 0
if ($this->due != $this->opening_balance || $this->wallet != 0) {
return false;
}
return true;
}
public function sales_dues() : HasMany
{
return $this->hasMany(Sale::class)->where('dueAmount', '>', 0);
}
public function purchases_dues() : HasMany
{
return $this->hasMany(Purchase::class)->where('dueAmount', '>', 0);
}
public function dueCollect()
{
return $this->hasOne(DueCollect::class);
}
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'due' => 'double',
'wallet' => 'double',
'business_id' => 'integer',
'status' => 'integer',
'meta' => 'json',
'credit_limit' => 'double',
'loyalty_points' => 'double',
'opening_balance' => 'double',
'billing_address' => 'json',
'shipping_address' => 'json',
];
}

View File

@@ -0,0 +1,90 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
class PaymentType extends Model
{
use HasFactory, softDeletes;
protected $fillable = [
'business_id',
'branch_id',
'name',
'balance',
'status',
'opening_balance',
'opening_date',
'show_in_invoice',
'meta',
];
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
// uncomment fromTransactions, toTransactions, paymentTransactions if needed otherwise remove.
// public function fromTransactions()
// {
// return $this->hasMany(Transaction::class, 'from_bank')->withTrashed();
// }
//
// public function toTransactions()
// {
// return $this->hasMany(Transaction::class, 'to_bank')->withTrashed();
// }
//
// public function paymentTransactions()
// {
// return $this->hasMany(Transaction::class, 'payment_type_id')->withTrashed();
// }
public function transactions()
{
return Transaction::where('payment_type_id', $this->id)
->orWhere('from_bank', $this->id)
->orWhere('to_bank', $this->id)
->withTrashed();
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
static::addGlobalScope('excludeCashCheque', function ($builder) {
$builder->whereNotIn(DB::raw('LOWER(name)'), ['cash', 'cheque']);
});
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
protected $casts = [
'business_id' => 'integer',
'branch_id' => 'integer',
'status' => 'integer',
'show_in_invoice' => 'integer',
'balance' => 'double',
'opening_balance' => 'double',
'meta' => 'json',
];
}

53
app/Models/Plan.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Plan extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'status',
'duration',
'offerPrice',
'subscriptionName',
'subscriptionPrice',
'visibility',
'features',
'affiliate_commission',
'allow_multibranch',
'addon_domain_limit',
'subdomain_limit',
];
public function planSubscribes()
{
return $this->hasMany(PlanSubscribe::class, 'plan_id');
}
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'features' => 'json',
'duration' => 'integer',
'offerPrice' => 'double',
'status' => 'integer',
'visibility' => 'json',
'subscriptionPrice' => 'double',
'allow_multibranch' => 'integer',
'addon_domain_limit' => 'integer',
'subdomain_limit' => 'integer',
];
}

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PlanSubscribe extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'price',
'notes',
'plan_id',
'duration',
'gateway_id',
'business_id',
'payment_status',
'allow_multibranch',
'addon_domain_limit',
'subdomain_limit',
];
protected $casts = [
'notes' => 'json',
'duration' => 'integer',
'price' => 'double',
'plan_id' => 'integer',
'business_id' => 'integer',
'gateway_id' => 'integer',
'allow_multibranch' => 'integer',
'addon_domain_limit' => 'integer',
'subdomain_limit' => 'integer',
];
public function plan(): BelongsTo
{
return $this->belongsTo(Plan::class);
}
public function business(): BelongsTo
{
return $this->belongsTo(Business::class);
}
public function gateway(): BelongsTo
{
return $this->belongsTo(Gateway::class);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PosAppInterface extends Model
{
use HasFactory;
protected $fillable = [
'image',
'status'
];
protected $casts = [
'status' => 'integer',
];
}

153
app/Models/Product.php Normal file
View File

@@ -0,0 +1,153 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Product extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'type',
'productName',
'business_id',
'unit_id',
'brand_id',
'vat_id',
'vat_type',
'vat_amount',
'profit_percent',
'category_id',
'productCode',
'productPicture',
'productDealerPrice',
'productPurchasePrice',
'productSalePrice',
'productWholeSalePrice',
'productStock',
'alert_qty',
'expire_date',
'size',
'meta',
'color',
'weight',
'capacity',
'productManufacturer',
'model_id',
'warehouse_id',
'product_type',
'rack_id',
'shelf_id',
'variation_ids',
'has_serial',
'warranty_guarantee_info',
'is_displayed_in_pos',
];
public function saleDetails()
{
return $this->hasMany(SaleDetails::class, 'product_id', 'id');
}
public function purchaseDetails()
{
return $this->hasMany(PurchaseDetails::class, 'product_id', 'id');
}
public function business()
{
return $this->belongsTo(Business::class);
}
public function unit(): BelongsTo
{
return $this->belongsTo(Unit::class);
}
public function brand(): BelongsTo
{
return $this->belongsTo(Brand::class);
}
public function category(): BelongsTo
{
return $this->belongsTo(Category::class);
}
public function warehouse(): BelongsTo
{
return $this->belongsTo(Warehouse::class);
}
public function rack(): BelongsTo
{
return $this->belongsTo(Rack::class);
}
public function shelf(): BelongsTo
{
return $this->belongsTo(Shelf::class);
}
public function stocks()
{
return $this->hasMany(Stock::class);
}
public function combo_products()
{
return $this->hasMany(ComboProduct::class, 'product_id', 'id')->with('stock');
}
public function product_model()
{
return $this->belongsTo(ProductModel::class, 'model_id', 'id');
}
public function vat()
{
return $this->belongsTo(Vat::class);
}
public function batch()
{
return $this->hasOne(Stock::class)
->where('productStock', '>', 0)
->latestOfMany();
}
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'model_id' => 'integer',
'warehouse_id' => 'integer',
'business_id' => 'integer',
'unit_id' => 'integer',
'brand_id' => 'integer',
'vat_id' => 'integer',
'category_id' => 'integer',
'productDealerPrice' => 'double',
'productPurchasePrice' => 'double',
'productSalePrice' => 'double',
'productWholeSalePrice' => 'double',
'productStock' => 'double',
'vat_amount' => 'double',
'profit_percent' => 'double',
'alert_qty' => 'double',
'stocks_sum_product_stock' => 'double',
'meta' => 'json',
'variation_ids' => 'json',
'warranty_guarantee_info' => 'json',
];
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ProductModel extends Model
{
use HasFactory;
protected $fillable = [
'name',
'business_id',
'status'
];
protected $casts = [
'business_id' => 'integer',
'status' => 'integer',
];
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ProductSetting extends Model
{
use HasFactory;
protected $fillable = [
'business_id',
'modules'
];
protected $casts = [
'modules' => 'json',
'business_id' => 'integer',
'branch_id' => 'integer'
];
}

133
app/Models/Purchase.php Normal file
View File

@@ -0,0 +1,133 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Purchase extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'party_id',
'business_id',
'branch_id',
'discountAmount',
'discount_percent',
'discount_type',
'shipping_charge',
'dueAmount',
'paidAmount',
'totalAmount',
'invoiceNumber',
'vat_id',
'vat_amount',
'vat_percent',
'isPaid',
'paymentType',
'payment_type_id',
'purchaseDate',
'change_amount',
];
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
public function business(): BelongsTo
{
return $this->belongsTo(Business::class);
}
public function vat(): BelongsTo
{
return $this->belongsTo(Vat::class);
}
public function details()
{
return $this->hasMany(PurchaseDetails::class);
}
public function party(): BelongsTo
{
return $this->belongsTo(Party::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function purchaseReturns()
{
return $this->hasMany(PurchaseReturn::class, 'purchase_id');
}
public function payment_type(): BelongsTo
{
return $this->belongsTo(PaymentType::class);
}
public function transactions()
{
return $this->hasMany(Transaction::class, 'reference_id')
->where('platform', 'purchase');
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$id = Purchase::where('business_id', auth()->user()?->business_id ?? 1)->count() + 1;
$model->invoiceNumber = "P" . str_pad($id, 2, '0', STR_PAD_LEFT);
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'party_id' => 'integer',
'payment_type_id' => 'integer',
'business_id' => 'integer',
'user_id' => 'integer',
'branch_id' => 'integer',
'vat_id' => 'integer',
'isPaid' => 'boolean',
'discountAmount' => 'double',
'dueAmount' => 'double',
'paidAmount' => 'double',
'change_amount' => 'double',
'totalAmount' => 'double',
'vat_amount' => 'double',
'vat_percent' => 'double',
'discount_percent' => 'double',
'shipping_charge' => 'double',
];
}

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PurchaseDetails extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'purchase_id',
'product_id',
'productDealerPrice',
'productPurchasePrice',
'profit_percent',
'productSalePrice',
'productWholeSalePrice',
'quantities',
'stock_id',
'mfg_date',
'expire_date',
];
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
public function purchase(): BelongsTo
{
return $this->belongsTo(Purchase::class, 'purchase_id');
}
public function product(): BelongsTo
{
return $this->belongsTo(Product::class, 'product_id');
}
public function stock(): BelongsTo
{
return $this->belongsTo(Stock::class);
}
protected $casts = [
'stock_id' => 'integer',
'purchase_id' => 'integer',
'product_id' => 'integer',
'productDealerPrice' => 'double',
'productPurchasePrice' => 'double',
'productSalePrice' => 'double',
'productWholeSalePrice' => 'double',
'quantities' => 'double',
'profit_percent' => 'double',
];
}

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class PurchaseReturn extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'business_id',
'branch_id',
'purchase_id',
'invoice_no',
'return_date',
];
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$id = PurchaseReturn::where('business_id', auth()->user()?->business_id ?? 1)->count() + 1;
$model->invoice_no = "PR" . str_pad($id, 2, '0', STR_PAD_LEFT);
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
public function purchase()
{
return $this->belongsTo(Purchase::class);
}
public function details()
{
return $this->hasMany(PurchaseReturnDetail::class);
}
public function transactions()
{
return $this->hasMany(Transaction::class, 'reference_id')
->where('platform', 'purchase_return');
}
protected $casts = [
'business_id' => 'integer',
'purchase_id' => 'integer',
'branch_id' => 'integer',
];
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PurchaseReturnDetail extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'business_id',
'purchase_return_id',
'purchase_detail_id',
'return_amount',
'return_qty',
];
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
public function purchaseReturn()
{
return $this->belongsTo(PurchaseReturn::class, 'purchase_return_id');
}
public function purchaseDetail()
{
return $this->belongsTo(PurchaseDetails::class, 'purchase_detail_id');
}
protected $casts = [
'business_id' => 'integer',
'purchase_return_id' => 'integer',
'purchase_detail_id' => 'integer',
'return_amount' => 'double',
'return_qty' => 'double',
];
}

22
app/Models/Rack.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Rack extends Model
{
use HasFactory;
protected $fillable = [
'business_id',
'name',
'status',
];
public function shelves()
{
return $this->belongsToMany(Shelf::class, 'rack_shelf');
}
}

148
app/Models/Sale.php Normal file
View File

@@ -0,0 +1,148 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Sale extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'business_id',
'party_id',
'branch_id',
'user_id',
'discountAmount',
'discount_percent',
'discount_type',
'shipping_charge',
'dueAmount',
'isPaid',
'vat_amount',
'vat_percent',
'vat_id',
'paidAmount',
'lossProfit',
'totalAmount',
'paymentType',
'payment_type_id',
'invoiceNumber',
'saleDate',
'image',
'meta',
'rounding_option',
'rounding_amount',
'actual_total_amount',
'change_amount',
'type',
];
public function business(): BelongsTo
{
return $this->belongsTo(Business::class);
}
public function details()
{
return $this->hasMany(SaleDetails::class);
}
public function party(): BelongsTo
{
return $this->belongsTo(Party::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function saleReturns()
{
return $this->hasMany(SaleReturn::class, 'sale_id');
}
public function vat(): BelongsTo
{
return $this->belongsTo(Vat::class);
}
public function payment_type(): BelongsTo
{
return $this->belongsTo(PaymentType::class);
}
public function dueCollect()
{
return $this->hasOne(DueCollect::class);
}
public function transactions()
{
return $this->hasMany(Transaction::class, 'reference_id')
->where('platform', 'sale');
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$id = Sale::where('business_id', auth()->user()?->business_id ?? 1)->count() + 1;
$model->invoiceNumber = "S" . str_pad($id, 2, '0', STR_PAD_LEFT);
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'business_id' => 'integer',
'payment_type_id' => 'integer',
'party_id' => 'integer',
'branch_id' => 'integer',
'user_id' => 'integer',
'vat_id' => 'integer',
'discountAmount' => 'double',
'dueAmount' => 'double',
'isPaid' => 'boolean',
'vat_amount' => 'double',
'vat_percent' => 'double',
'paidAmount' => 'double',
'change_amount' => 'double',
'totalAmount' => 'double',
'lossProfit' => 'double',
'shipping_charge' => 'double',
'rounding_amount' => 'double',
'actual_total_amount' => 'double',
'discount_percent' => 'double',
'meta' => 'json',
];
}

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class SaleDetails extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'sale_id',
'product_id',
'price',
'discount',
'lossProfit',
'quantities',
'stock_id',
'expire_date',
'mfg_date',
'productPurchasePrice',
'warranty_guarantee_info',
];
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
public function product(): BelongsTo
{
return $this->belongsTo(Product::class, 'product_id');
}
public function stock()
{
return $this->belongsTo(Stock::class);
}
public function sale(): BelongsTo
{
return $this->belongsTo(Sale::class, 'sale_id');
}
protected $casts = [
'sale_id' => 'integer',
'stock_id' => 'integer',
'product_id' => 'integer',
'price' => 'double',
'discount' => 'double',
'lossProfit' => 'double',
'quantities' => 'double',
'productPurchasePrice' => 'double',
'warranty_guarantee_info' => 'json',
];
}

75
app/Models/SaleReturn.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class SaleReturn extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'sale_id',
'branch_id',
'invoice_no',
'business_id',
'return_date',
];
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$id = SaleReturn::where('business_id', auth()->user()?->business_id ?? 1)->count() + 1;
$model->invoice_no = "SR" . str_pad($id, 2, '0', STR_PAD_LEFT);
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
public function sale()
{
return $this->belongsTo(Sale::class);
}
public function details()
{
return $this->hasMany(SaleReturnDetails::class);
}
public function transactions()
{
return $this->hasMany(Transaction::class, 'reference_id')
->where('platform', 'sale_return');
}
protected $casts = [
'business_id' => 'integer',
'sale_id' => 'integer',
'branch_id' => 'integer',
];
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SaleReturnDetails extends Model
{
use HasFactory;
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'business_id',
'sale_return_id',
'sale_detail_id',
'return_amount',
'return_qty',
];
public function saleReturn()
{
return $this->belongsTo(SaleReturn::class, 'sale_return_id');
}
public function saleDetail()
{
return $this->belongsTo(SaleDetails::class, 'sale_detail_id');
}
protected $casts = [
'business_id' => 'integer',
'sale_return_id' => 'integer',
'sale_detail_id' => 'integer',
'return_amount' => 'double',
'return_qty' => 'double',
];
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Models\Scopes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
class BranchScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*/
public function apply(Builder $builder, Model $model)
{
// If addon not enabled, skip
if (!moduleCheck('MultiBranchAddon')) return;
$user = auth()->user();
if (!$user) return;
// Skip global scope for shop-owner when not inside a branch
if ($user->role === 'shop-owner' && !$user->active_branch_id) {
return;
}
if ($user->active_branch_id) {
$builder->where($model->getTable() . '.branch_id', $user->active_branch_id);
return;
}
// Otherwise fall back to user's fixed branch (for staff)
if (!is_null($user->branch_id)) {
$builder->where($model->getTable() . '.branch_id', $user->branch_id);
}
}
}

22
app/Models/Shelf.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Shelf extends Model
{
use HasFactory;
protected $fillable = [
'business_id',
'name',
'status',
];
public function racks()
{
return $this->belongsToMany(Rack::class, 'rack_shelf');
}
}

79
app/Models/Stock.php Normal file
View File

@@ -0,0 +1,79 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Stock extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'business_id',
'branch_id',
'warehouse_id',
'product_id',
'batch_no',
'productStock',
'productPurchasePrice',
'profit_percent',
'productSalePrice',
'productWholeSalePrice',
'productDealerPrice',
'mfg_date',
'expire_date',
'variant_name',
'variation_data',
'serial_numbers'
];
public function product()
{
return $this->belongsTo(Product::class);
}
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
public function warehouse()
{
return $this->belongsTo(Warehouse::class);
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'business_id' => 'integer',
'branch_id' => 'integer',
'warehouse_id' => 'integer',
'product_id' => 'integer',
'productStock' => 'double',
'productPurchasePrice' => 'double',
'profit_percent' => 'double',
'productSalePrice' => 'double',
'productWholeSalePrice' => 'double',
'productDealerPrice' => 'double',
'variation_data' => 'json',
'serial_numbers' => 'json'
];
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Testimonial extends Model
{
use HasFactory;
protected $fillable = [
'text',
'star',
'client_name',
'client_image',
'work_at'
];
protected $casts = [
'star' => 'integer',
];
}

122
app/Models/Transaction.php Normal file
View File

@@ -0,0 +1,122 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Transaction extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'platform',
'transaction_type',
'type',
'amount',
'date',
'business_id',
'branch_id',
'payment_type_id',
'user_id',
'from_bank',
'to_bank',
'reference_id',
'invoice_no',
'image',
'note',
'meta',
];
public function business()
{
return $this->belongsTo(Business::class);
}
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
public function user()
{
return $this->belongsTo(User::class);
}
public function paymentType()
{
return $this->belongsTo(PaymentType::class)->withTrashed();
}
public function fromBank()
{
return $this->belongsTo(PaymentType::class, 'from_bank')->withTrashed();
}
public function toBank()
{
return $this->belongsTo(PaymentType::class, 'to_bank')->withTrashed();
}
public function sale()
{
return $this->belongsTo(Sale::class, 'reference_id');
}
public function saleReturn()
{
return $this->belongsTo(SaleReturn::class, 'reference_id');
}
public function purchase()
{
return $this->belongsTo(Purchase::class, 'reference_id');
}
public function purchaseReturn()
{
return $this->belongsTo(PurchaseReturn::class, 'reference_id');
}
public function dueCollect()
{
return $this->belongsTo(DueCollect::class, 'reference_id');
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$id = Transaction::where('business_id', auth()->user()?->business_id ?? 1)->count() + 1;
$model->invoice_no = "T" . str_pad($id, 2, '0', STR_PAD_LEFT);
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
protected $casts = [
'business_id' => 'integer',
'branch_id' => 'integer',
'payment_type_id' => 'integer',
'user_id' => 'integer',
'from_bank' => 'integer',
'to_bank' => 'integer',
'reference_id' => 'integer',
'amount' => 'double',
'meta' => 'json',
];
}

67
app/Models/Transfer.php Normal file
View File

@@ -0,0 +1,67 @@
<?php
namespace App\Models;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Transfer extends Model
{
use HasFactory;
protected $fillable = [
'business_id',
'from_warehouse_id',
'to_warehouse_id',
'to_branch_id',
'from_branch_id',
'transfer_date',
'invoice_no',
'note',
'shipping_charge',
'sub_total',
'total_discount',
'total_tax',
'grand_total',
'status',
];
protected static function boot()
{
parent::boot();
static::creating(function ($transfer) {
$lastNumber = (int) self::whereNotNull('invoice_no')
->orderByDesc('id')
->value(DB::raw("CAST(SUBSTRING(invoice_no, 4) AS UNSIGNED)")) ?? 0;
$transfer->invoice_no = str_pad($lastNumber + 1, 5, '0', STR_PAD_LEFT);
});
}
public function fromWarehouse()
{
return $this->belongsTo(Warehouse::class, 'from_warehouse_id');
}
public function toWarehouse()
{
return $this->belongsTo(Warehouse::class, 'to_warehouse_id');
}
public function toBranch()
{
return $this->belongsTo(Branch::class, 'to_branch_id');
}
public function fromBranch()
{
return $this->belongsTo(Branch::class, 'from_branch_id');
}
public function transferProducts()
{
return $this->hasMany(TransferProduct::class);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class TransferProduct extends Model
{
use HasFactory;
protected $fillable = [
'transfer_id',
'product_id',
'stock_id',
'quantity',
'unit_price',
'discount',
'tax',
];
public function transfer()
{
return $this->belongsTo(Transfer::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
public function stock()
{
return $this->belongsTo(Stock::class, 'stock_id');
}
}

27
app/Models/Unit.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Unit extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'status',
'business_id',
'unitName',
];
protected $casts = [
'business_id' => 'integer',
'status' => 'integer',
];
}

115
app/Models/User.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
namespace App\Models;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Notifications\Notifiable;
use Modules\AffiliateAddon\App\Models\Affiliate;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, HasRoles;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'business_id',
'branch_id',
'active_branch_id',
'name',
'role',
'email',
'phone',
'image',
'lang',
'password',
'visibility',
'provider',
'provider_id',
'is_verified',
'remember_token',
'email_verified_at',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'password' => 'hashed',
'visibility' => 'json',
'email_verified_at' => 'datetime',
'business_id' => 'integer',
'is_verified' => 'integer',
'branch_id' => 'integer',
'active_branch_id' => 'integer',
];
public function business(): BelongsTo
{
return $this->belongsTo(Business::class);
}
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
public function active_branch(): BelongsTo
{
return $this->belongsTo(Branch::class, $this->branch_id ? 'branch_id' : 'active_branch_id')->withTrashed();
}
public function affiliate(): HasOne
{
return $this->hasOne(Affiliate::class);
}
public function hasPermission(string $permission): bool
{
if ($this->role === 'shop-owner') return true;
[$module, $action] = explode('.', $permission);
return isset($this->visibility[$module][$action]) && $this->visibility[$module][$action] == "1";
}
public function hasAnyPermission(array $permissions)
{
if ($this->role === 'shop-owner') return true;
$visibility = $this->visibility ?? [];
foreach ($permissions as $permission) {
[$module, $action] = explode('.', $permission);
if (!empty($visibility[$module][$action]) && $visibility[$module][$action] == "1") {
return true;
}
}
return false;
}
public function accessToMultiBranch()
{
return moduleCheck('MultiBranchAddon') && !$this->branch_id && !$this->active_branch_id && multibranch_active() && branch_count();
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserCurrency extends Model
{
use HasFactory;
protected $fillable = ['business_id', 'currency_id', 'name', 'country_name', 'code', 'rate', 'symbol', 'position'];
public function business(){
return $this->belongsTo(Business::class);
}
protected $casts = [
'business_id' => 'integer',
'currency_id' => 'integer',
'rate' => 'double',
];
}

22
app/Models/Variation.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Variation extends Model
{
use HasFactory;
protected $fillable = [
'business_id',
'name',
'status',
'values',
];
protected $casts = [
'values' => 'json',
];
}

31
app/Models/Vat.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Vat extends Model
{
use HasFactory;
protected $fillable = [
'name',
'rate',
'status',
'sub_vat',
'business_id',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'rate' => 'double',
'sub_vat' => 'json',
'status' => 'boolean',
'business_id' => 'integer',
];
}

61
app/Models/Warehouse.php Normal file
View File

@@ -0,0 +1,61 @@
<?php
namespace App\Models;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Warehouse extends Model
{
use HasFactory;
protected $fillable = [
'business_id',
'branch_id',
'name',
'phone',
'email',
'address'
];
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
protected static function booted()
{
if (function_exists('moduleCheck') && moduleCheck('MultiBranchAddon')) {
static::addGlobalScope(new BranchScope);
}
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
public function transferProducts()
{
return $this->hasMany(TransferProduct::class);
}
public function products()
{
return $this->hasMany(Product::class);
}
public function stocks()
{
return $this->hasMany(Stock::class);
}
protected $casts = [
'business_id' => 'integer',
'branch_id' => 'integer',
];
}