114 lines
4.4 KiB
PHP
114 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\BusinessSetting;
|
|
use App\Models\ProductSheet;
|
|
use App\Models\ProductSheetItem;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class BusinessSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$user = User::first();
|
|
|
|
if (!$user) {
|
|
$this->command->error('No user found!');
|
|
return;
|
|
}
|
|
|
|
// Criar configuração de markup
|
|
$setting = BusinessSetting::create([
|
|
'user_id' => $user->id,
|
|
'name' => 'Loja Principal',
|
|
'currency' => 'EUR',
|
|
'monthly_revenue' => 50000,
|
|
'fixed_expenses' => 6000,
|
|
'tax_rate' => 10,
|
|
'sales_commission' => 5,
|
|
'card_fee' => 3,
|
|
'other_variable_costs' => 2,
|
|
'investment_rate' => 5,
|
|
'profit_margin' => 15,
|
|
'is_active' => true,
|
|
]);
|
|
$setting->recalculateMarkup();
|
|
|
|
$this->command->info("Setting criado: {$setting->name} - Markup: {$setting->markup_factor}");
|
|
|
|
// Criar produtos de exemplo com fichas técnicas
|
|
$products = [
|
|
['name' => 'Camiseta Básica', 'sku' => 'CAM-001', 'cmv' => 12.50, 'category' => 'Vestuário'],
|
|
['name' => 'Calça Jeans', 'sku' => 'CAL-001', 'cmv' => 35.00, 'category' => 'Vestuário'],
|
|
['name' => 'Tênis Esportivo', 'sku' => 'TEN-001', 'cmv' => 65.00, 'category' => 'Calçados'],
|
|
['name' => 'Mochila Escolar', 'sku' => 'MOC-001', 'cmv' => 28.00, 'category' => 'Acessórios'],
|
|
['name' => 'Boné Trucker', 'sku' => 'BON-001', 'cmv' => 8.50, 'category' => 'Acessórios'],
|
|
['name' => 'Relógio Digital', 'sku' => 'REL-001', 'cmv' => 45.00, 'category' => 'Acessórios'],
|
|
['name' => 'Óculos de Sol', 'sku' => 'OCU-001', 'cmv' => 22.00, 'category' => 'Acessórios'],
|
|
['name' => 'Jaqueta Corta-Vento', 'sku' => 'JAQ-001', 'cmv' => 55.00, 'category' => 'Vestuário'],
|
|
['name' => 'Shorts Fitness', 'sku' => 'SHO-001', 'cmv' => 18.00, 'category' => 'Vestuário'],
|
|
['name' => 'Meias Pack 3', 'sku' => 'MEI-001', 'cmv' => 6.00, 'category' => 'Vestuário'],
|
|
];
|
|
|
|
foreach ($products as $productData) {
|
|
// Criar a ficha técnica
|
|
$sheet = ProductSheet::create([
|
|
'user_id' => $user->id,
|
|
'business_setting_id' => $setting->id,
|
|
'name' => $productData['name'],
|
|
'sku' => $productData['sku'],
|
|
'description' => 'Produto de exemplo',
|
|
'category' => $productData['category'],
|
|
'currency' => 'EUR',
|
|
'cmv_total' => $productData['cmv'],
|
|
'is_active' => true,
|
|
]);
|
|
|
|
// Criar item de custo principal
|
|
ProductSheetItem::create([
|
|
'product_sheet_id' => $sheet->id,
|
|
'name' => 'Custo de Aquisição',
|
|
'type' => ProductSheetItem::TYPE_PRODUCT_COST,
|
|
'amount' => $productData['cmv'] * 0.8,
|
|
'quantity' => 1,
|
|
'unit' => 'un',
|
|
'unit_cost' => $productData['cmv'] * 0.8,
|
|
'sort_order' => 1,
|
|
]);
|
|
|
|
// Criar item de embalagem
|
|
ProductSheetItem::create([
|
|
'product_sheet_id' => $sheet->id,
|
|
'name' => 'Embalagem',
|
|
'type' => ProductSheetItem::TYPE_PACKAGING,
|
|
'amount' => $productData['cmv'] * 0.15,
|
|
'quantity' => 1,
|
|
'unit' => 'un',
|
|
'unit_cost' => $productData['cmv'] * 0.15,
|
|
'sort_order' => 2,
|
|
]);
|
|
|
|
// Criar item de etiqueta
|
|
ProductSheetItem::create([
|
|
'product_sheet_id' => $sheet->id,
|
|
'name' => 'Etiqueta',
|
|
'type' => ProductSheetItem::TYPE_LABEL,
|
|
'amount' => $productData['cmv'] * 0.05,
|
|
'quantity' => 1,
|
|
'unit' => 'un',
|
|
'unit_cost' => $productData['cmv'] * 0.05,
|
|
'sort_order' => 3,
|
|
]);
|
|
|
|
// Calcular preço de venda
|
|
$sheet->calculateSalePrice($setting);
|
|
|
|
$this->command->info("Produto: {$sheet->name} - CMV: EUR {$sheet->cmv_total} - Venda: EUR {$sheet->sale_price}");
|
|
}
|
|
|
|
$this->command->info('Business seeder concluído!');
|
|
}
|
|
}
|