Initial commit: Sistema de comisiones y gastos personales
This commit is contained in:
67
app/Models/DailySale.php
Executable file
67
app/Models/DailySale.php
Executable file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['user_id', 'month_id', 'date', 'user_sales', 'system_sales'])]
|
||||
class DailySale extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'daily_sales';
|
||||
|
||||
/**
|
||||
* Los atributos que son asignables en masa.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'month_id',
|
||||
'date',
|
||||
'user_sales',
|
||||
'system_sales',
|
||||
];
|
||||
|
||||
/**
|
||||
* Los atributos que deben ser convertidos.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'date' => 'date',
|
||||
'user_sales' => 'decimal:2',
|
||||
'system_sales' => 'decimal:2',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con usuario
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con mes
|
||||
*/
|
||||
public function month(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Month::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtener la diferencia entre ventas usuario y sistema
|
||||
*/
|
||||
public function getDifferenceAttribute(): float
|
||||
{
|
||||
return $this->user_sales - $this->system_sales;
|
||||
}
|
||||
}
|
||||
59
app/Models/Expense.php
Executable file
59
app/Models/Expense.php
Executable file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['user_id', 'month_id', 'description', 'amount', 'date', 'expense_type'])]
|
||||
class Expense extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'expenses';
|
||||
|
||||
/**
|
||||
* Los atributos que son asignables en masa.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'month_id',
|
||||
'description',
|
||||
'amount',
|
||||
'date',
|
||||
'expense_type',
|
||||
];
|
||||
|
||||
/**
|
||||
* Los atributos que deben ser convertidos.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'date' => 'date',
|
||||
'amount' => 'decimal:2',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con usuario
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con mes
|
||||
*/
|
||||
public function month(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Month::class);
|
||||
}
|
||||
}
|
||||
97
app/Models/Month.php
Executable file
97
app/Models/Month.php
Executable file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable(['user_id', 'name', 'year', 'status'])]
|
||||
class Month extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'months';
|
||||
|
||||
/**
|
||||
* Los atributos que son asignables en masa.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'name',
|
||||
'year',
|
||||
'status',
|
||||
];
|
||||
|
||||
/**
|
||||
* Los atributos que deben ser convertidos.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'year' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con usuario
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con ventas diarias
|
||||
*/
|
||||
public function dailySales(): HasMany
|
||||
{
|
||||
return $this->hasMany(DailySale::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con gastos
|
||||
*/
|
||||
public function expenses(): HasMany
|
||||
{
|
||||
return $this->hasMany(Expense::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtener el nombre del mes con formato
|
||||
*/
|
||||
public function getDisplayNameAttribute(): string
|
||||
{
|
||||
return $this->name . ' ' . $this->year;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcular ventas totales del mes
|
||||
*/
|
||||
public function getTotalUserSalesAttribute(): float
|
||||
{
|
||||
return $this->dailySales()->sum('user_sales');
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcular ventas del sistema
|
||||
*/
|
||||
public function getTotalSystemSalesAttribute(): float
|
||||
{
|
||||
return $this->dailySales()->sum('system_sales');
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcular gastos totales del mes
|
||||
*/
|
||||
public function getTotalExpensesAttribute(): float
|
||||
{
|
||||
return $this->expenses()->sum('amount');
|
||||
}
|
||||
}
|
||||
48
app/Models/TelegramAccount.php
Executable file
48
app/Models/TelegramAccount.php
Executable file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['user_id', 'chat_id', 'verification_code', 'is_verified'])]
|
||||
class TelegramAccount extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'telegram_accounts';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'chat_id',
|
||||
'verification_code',
|
||||
'is_verified',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_verified' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con usuario
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
84
app/Models/User.php
Executable file
84
app/Models/User.php
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['username', 'name', 'email', 'password', 'commission_percentage', 'monthly_salary', 'is_active', 'fecha_ingreso', 'razon_social', 'sueldo_integro_diario'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'commission_percentage' => 'decimal:2',
|
||||
'monthly_salary' => 'decimal:2',
|
||||
'sueldo_integro_diario' => 'decimal:2',
|
||||
'fecha_ingreso' => 'date',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con cuenta de Telegram
|
||||
*/
|
||||
public function telegramAccount(): HasOne
|
||||
{
|
||||
return $this->hasOne(TelegramAccount::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con meses de trabajo
|
||||
*/
|
||||
public function months(): HasMany
|
||||
{
|
||||
return $this->hasMany(Month::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con ventas diarias
|
||||
*/
|
||||
public function dailySales(): HasMany
|
||||
{
|
||||
return $this->hasMany(DailySale::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relación con gastos
|
||||
*/
|
||||
public function expenses(): HasMany
|
||||
{
|
||||
return $this->hasMany(Expense::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtener el mes activo (si existe)
|
||||
*/
|
||||
public function getCurrentMonth(): ?Month
|
||||
{
|
||||
return $this->months()
|
||||
->where('status', 'open')
|
||||
->orderBy('year', 'desc')
|
||||
->orderByRaw("FIELD(name, 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre')")
|
||||
->first();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user