first commit
This commit is contained in:
31
app/Models/Customer.php
Normal file
31
app/Models/Customer.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Customer extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'address',
|
||||
'owner_name',
|
||||
'phone',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'city',
|
||||
'pic_sales_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the sales user associated with the customer.
|
||||
*/
|
||||
public function sales(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'pic_sales_id');
|
||||
}
|
||||
}
|
||||
42
app/Models/PlanTarget.php
Normal file
42
app/Models/PlanTarget.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PlanTarget extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'sales_plan_id',
|
||||
'order',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'name',
|
||||
'address',
|
||||
'phone',
|
||||
'notes',
|
||||
'estimated_duration_minutes',
|
||||
'is_completed',
|
||||
'completed_at',
|
||||
'source', // 'admin', 'mobile_manual', etc.
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'latitude' => 'decimal:8',
|
||||
'longitude' => 'decimal:8',
|
||||
'is_completed' => 'boolean',
|
||||
'completed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sales plan that owns the target.
|
||||
*/
|
||||
public function salesPlan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SalesPlan::class);
|
||||
}
|
||||
}
|
||||
55
app/Models/SalesPlan.php
Normal file
55
app/Models/SalesPlan.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class SalesPlan extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'date',
|
||||
'status',
|
||||
'total_distance_km',
|
||||
'optimized_at',
|
||||
'optimized_route',
|
||||
'notes',
|
||||
'created_by',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'date' => 'date',
|
||||
'total_distance_km' => 'decimal:2',
|
||||
'optimized_at' => 'datetime',
|
||||
'optimized_route' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that owns the plan.
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that created the plan.
|
||||
*/
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the targets for the plan.
|
||||
*/
|
||||
public function targets(): HasMany
|
||||
{
|
||||
return $this->hasMany(PlanTarget::class, 'sales_plan_id')->orderBy('order');
|
||||
}
|
||||
}
|
||||
47
app/Models/SalesRoute.php
Normal file
47
app/Models/SalesRoute.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class SalesRoute extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'date',
|
||||
'status',
|
||||
'total_distance_km',
|
||||
'total_duration_minutes',
|
||||
'total_visits',
|
||||
'started_at',
|
||||
'ended_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'date' => 'date',
|
||||
'total_distance_km' => 'decimal:2',
|
||||
'started_at' => 'datetime',
|
||||
'ended_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that owns the route.
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the waypoints for the route.
|
||||
*/
|
||||
public function waypoints(): HasMany
|
||||
{
|
||||
return $this->hasMany(Waypoint::class)->orderBy('recorded_at');
|
||||
}
|
||||
}
|
||||
40
app/Models/SalesRouteSummary.php
Normal file
40
app/Models/SalesRouteSummary.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SalesRouteSummary extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'sales_route_id',
|
||||
'date',
|
||||
'total_distance_km',
|
||||
'total_duration_minutes',
|
||||
'total_visits',
|
||||
'started_at',
|
||||
'ended_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'date' => 'date',
|
||||
'total_distance_km' => 'decimal:2',
|
||||
'started_at' => 'datetime',
|
||||
'ended_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function route(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SalesRoute::class, 'sales_route_id');
|
||||
}
|
||||
}
|
||||
63
app/Models/User.php
Normal file
63
app/Models/User.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use MongoDB\Laravel\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'employee_id',
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'phone',
|
||||
'color',
|
||||
'role',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sales routes for the user.
|
||||
*/
|
||||
public function salesRoutes(): HasMany
|
||||
{
|
||||
return $this->hasMany(SalesRoute::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sales plans for the user.
|
||||
*/
|
||||
public function salesPlans(): HasMany
|
||||
{
|
||||
return $this->hasMany(SalesPlan::class);
|
||||
}
|
||||
}
|
||||
38
app/Models/Waypoint.php
Normal file
38
app/Models/Waypoint.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Waypoint extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'sales_route_id',
|
||||
'type',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'recorded_at',
|
||||
'location_name',
|
||||
'address',
|
||||
'notes',
|
||||
'photo_url',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'latitude' => 'decimal:8',
|
||||
'longitude' => 'decimal:8',
|
||||
'recorded_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sales route that owns the waypoint.
|
||||
*/
|
||||
public function salesRoute(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SalesRoute::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user