NUEVO:
- Empezada nueva vista y modelo gastos.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('expenses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('supplier_id')->nullable()->constrained('suppliers')->nullOnDelete();
|
||||
$table->string('description');
|
||||
$table->enum('expense_category', ['Mercadería', 'Servicios', 'Impuestos', 'Logística', 'Otros'])->default('Otros');
|
||||
$table->enum('type', ['Compra', 'Pedido', 'Factura'])->default('Compra');
|
||||
$table->enum('status', ['Pendiente', 'Pagado', 'Cancelado'])->default('Pendiente');
|
||||
$table->decimal('total_amount', 10, 2)->default(0);
|
||||
$table->string('document_number')->nullable();
|
||||
$table->date('expense_date')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('expenses');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Sale;
|
||||
use App\Models\SaleDetail;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Product;
|
||||
use App\Models\Client;
|
||||
use App\Models\Supplier;
|
||||
|
||||
class FakeDataSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Ensure there are some products, clients, and suppliers
|
||||
$client = Client::first() ?? Client::create(['name' => 'Cliente Falso', 'phone' => '123456', 'email' => 'cliente@fake.com']);
|
||||
$product = Product::first() ?? Product::create([
|
||||
'name' => 'Bicicleta de Prueba',
|
||||
'description' => 'Prueba',
|
||||
'sale_price' => 50000,
|
||||
'stock_quantity' => 10,
|
||||
'type' => 'bike'
|
||||
]);
|
||||
$supplier = Supplier::first() ?? Supplier::create(['name' => 'Proveedor Falso', 'phone' => '123456', 'email' => 'prov@fake.com']);
|
||||
|
||||
// 1. Create 10 Sales
|
||||
$paymentMethods = ['Efectivo', 'Tarjeta de Débito', 'Tarjeta de Crédito', 'Transferencia'];
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$sale = Sale::create([
|
||||
'client_id' => $client->id,
|
||||
'total' => 50000,
|
||||
'payment_method' => $paymentMethods[array_rand($paymentMethods)],
|
||||
'created_at' => now()->subDays(rand(1, 30)),
|
||||
]);
|
||||
|
||||
SaleDetail::create([
|
||||
'sale_id' => $sale->id,
|
||||
'product_id' => $product->id,
|
||||
'quantity' => 1,
|
||||
'price' => 50000,
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Create 10 Expenses (Servicios/Impuestos)
|
||||
$expenseCategories = ['Servicios', 'Impuestos', 'Otros'];
|
||||
$services = ['Factura de Luz - Edesur', 'Internet - Fibertel', 'Agua - AySA', 'Gas - Metrogas', 'Alquiler Local', 'Impuesto Municipal', 'Monotributo', 'Papelería', 'Limpieza', 'Café y Mate'];
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
Expense::create([
|
||||
'description' => $services[$i],
|
||||
'expense_category' => $expenseCategories[array_rand($expenseCategories)],
|
||||
'type' => 'Factura',
|
||||
'status' => 'Pagado',
|
||||
'total_amount' => rand(1500, 25000),
|
||||
'expense_date' => now()->subDays(rand(1, 30)),
|
||||
]);
|
||||
}
|
||||
|
||||
// 3. Create 10 Orders (Pedidos a Proveedores)
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
Expense::create([
|
||||
'supplier_id' => $supplier->id,
|
||||
'description' => 'Pedido de repuestos varios #' . $i,
|
||||
'expense_category' => 'Mercadería',
|
||||
'type' => 'Pedido',
|
||||
'status' => 'Pendiente',
|
||||
'total_amount' => 0, // Orders might not have amounts until they arrive
|
||||
'expense_date' => now()->subDays(rand(1, 10)),
|
||||
]);
|
||||
}
|
||||
|
||||
// 4. Create 10 Bills (Facturas de Proveedores)
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
Expense::create([
|
||||
'supplier_id' => $supplier->id,
|
||||
'description' => 'Compra de bicicletas y cascos',
|
||||
'expense_category' => 'Mercadería',
|
||||
'type' => 'Compra',
|
||||
'status' => 'Pagado',
|
||||
'total_amount' => rand(100000, 500000),
|
||||
'document_number' => 'FAC-0001-0000' . rand(1000, 9999),
|
||||
'expense_date' => now()->subDays(rand(1, 30)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user