Initial support for importing supplier costs
This commit is contained in:
40
app/Models/Cost.php
Normal file
40
app/Models/Cost.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Models\Cost\{Broadband,Generic,Phone};
|
||||
|
||||
class Cost extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $dates = [
|
||||
'billed_at',
|
||||
];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function broadbands()
|
||||
{
|
||||
return $this->hasMany(Broadband::class)
|
||||
->where('active',TRUE);
|
||||
}
|
||||
|
||||
public function generics()
|
||||
{
|
||||
return $this->hasMany(Generic::class)
|
||||
->where('active',TRUE);
|
||||
}
|
||||
|
||||
public function phones()
|
||||
{
|
||||
return $this->hasMany(Phone::class)
|
||||
->where('active',TRUE);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
}
|
18
app/Models/Cost/Broadband.php
Normal file
18
app/Models/Cost/Broadband.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cost;
|
||||
|
||||
use App\Models\Service;
|
||||
use App\Models\Service\Broadband as BroadbandService;
|
||||
|
||||
class Broadband extends Type
|
||||
{
|
||||
protected $table = 'cost_broadband';
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function service()
|
||||
{
|
||||
return $this->hasOneThrough(Service::class,BroadbandService::class,'id','id','service_broadband_id','service_id');
|
||||
}
|
||||
}
|
18
app/Models/Cost/Generic.php
Normal file
18
app/Models/Cost/Generic.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cost;
|
||||
|
||||
use App\Models\Service;
|
||||
use App\Models\Service\Generic as GenericService;
|
||||
|
||||
class Generic extends Type
|
||||
{
|
||||
protected $table = 'cost_generic';
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function service()
|
||||
{
|
||||
return $this->hasOneThrough(Service::class,GenericService::class,'id','id','service_generic_id','service_id');
|
||||
}
|
||||
}
|
18
app/Models/Cost/Phone.php
Normal file
18
app/Models/Cost/Phone.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cost;
|
||||
|
||||
use App\Models\Service;
|
||||
use App\Models\Service\Phone as PhoneService;
|
||||
|
||||
class Phone extends Type
|
||||
{
|
||||
protected $table = 'cost_phone';
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function service()
|
||||
{
|
||||
return $this->hasOneThrough(Service::class,PhoneService::class,'id','id','service_phone_id','service_id');
|
||||
}
|
||||
}
|
26
app/Models/Cost/Type.php
Normal file
26
app/Models/Cost/Type.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cost;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
abstract class Type extends Model
|
||||
{
|
||||
public $timestamps = FALSE;
|
||||
|
||||
protected $dates = [
|
||||
'start_at',
|
||||
'end_at',
|
||||
];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
abstract public function service();
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getCostAttribute(): float
|
||||
{
|
||||
return $this->base+$this->excess;
|
||||
}
|
||||
}
|
17
app/Models/Policies/CostPolicy.php
Normal file
17
app/Models/Policies/CostPolicy.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
use App\Models\{Cost,User};
|
||||
|
||||
class CostPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function view(User $uo,Cost $co): bool
|
||||
{
|
||||
return $uo->isWholesaler();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user