- Mejorados los graficos en la parte de reportes.
- Agregados 3 nuevos charts para mayor utilidad de la pagina.
This commit is contained in:
Bryam105
2026-06-05 08:44:32 -03:00
parent bc9e327913
commit 2b3b87b0ba
3 changed files with 236 additions and 1 deletions
+104
View File
@@ -0,0 +1,104 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\Client;
use App\Models\Product;
use App\Models\Sale;
use App\Models\SaleDetail;
class ReportTestSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$faker = \Faker\Factory::create('es_AR');
// 1. Create 10 Fictional Clients
$clients = [];
for ($i = 0; $i < 10; $i++) {
$clients[] = Client::create([
'name' => $faker->name,
'phone' => $faker->phoneNumber,
'email' => $faker->unique()->safeEmail,
'address' => $faker->address,
]);
}
// 2. Ensure we have some products and spare parts
$supplier = \App\Models\Supplier::first() ?? \App\Models\Supplier::create(['name' => 'Test Supplier', 'phone' => '123']);
$products = [];
// Create 3 Spares
for ($i = 1; $i <= 3; $i++) {
$products[] = Product::create([
'name' => 'Repuesto Test ' . $i,
'type' => 'spare',
'cost' => rand(500, 2000),
'price' => rand(3000, 8000),
'stock_quantity' => 100,
'suppliers_id' => $supplier->id,
]);
}
// Create 3 Accessories
for ($i = 1; $i <= 3; $i++) {
$products[] = Product::create([
'name' => 'Accesorio Test ' . $i,
'type' => 'accessory',
'cost' => rand(1000, 4000),
'price' => rand(5000, 15000),
'stock_quantity' => 50,
'suppliers_id' => $supplier->id,
]);
}
$allProducts = Product::all();
$paymentMethods = ['Efectivo', 'Tarjeta de Débito', 'Tarjeta de Crédito', 'Transferencia'];
// 3. Create 20 Sales
for ($i = 1; $i <= 20; $i++) {
// Pick a random client (some clients will buy more often, making them Top Spenders)
// Weight the randomness a bit by picking from array_rand with duplicates
$weightedClients = array_merge($clients, array_slice($clients, 0, 3));
$client = $weightedClients[array_rand($weightedClients)];
// Random date in the last 4 months
$date = now()->subDays(rand(1, 120));
$sale = Sale::create([
'client_id' => $client->id,
'total' => 0, // We'll calculate this
'payment_method' => $paymentMethods[array_rand($paymentMethods)],
'created_at' => $date,
'updated_at' => $date,
]);
// Add 1 to 3 random products to this sale
$numProducts = rand(1, 3);
$totalSale = 0;
$shuffledProducts = $allProducts->shuffle();
for ($j = 0; $j < $numProducts; $j++) {
$product = $shuffledProducts[$j];
$quantity = rand(1, 5);
$price = $product->price ?? 5000;
SaleDetail::create([
'sale_id' => $sale->id,
'product_id' => $product->id,
'quantity' => $quantity,
'price' => $price,
'created_at' => $date,
'updated_at' => $date,
]);
$totalSale += ($quantity * $price);
}
// Update total
$sale->update(['total' => $totalSale]);
}
}
}