feat: Implement price list management and import functionality
- Added ListinoRelationManager for managing price lists associated with models. - Introduced ImportaListiniAction for importing price lists from Excel files. - Created ListinoPrezzo model to represent price entries in the database. - Developed ListinoExcelParser for parsing Excel files containing price lists. - Implemented ListinoImporter to handle the import logic and associations. - Added migration for creating listino_prezzi table and converting measures to mm. - Updated frontend logic to handle new price list features and validations. - Enhanced tests for price list import and conversion functionalities.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Modello;
|
||||
use App\Models\Preventivo;
|
||||
use App\Support\ConfigurazioneFormatter;
|
||||
use Database\Seeders\CatalogoSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ConversioneMisureMmTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const MIGRAZIONE = 'database/migrations/2026_10_19_150000_converti_misure_in_mm.php';
|
||||
|
||||
public function test_la_migrazione_porta_listini_e_preventivi_esistenti_in_mm(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
$this->seed(CatalogoSeeder::class);
|
||||
|
||||
// Riporta lo schema e i dati allo stato precedente (in cm).
|
||||
Artisan::call('migrate:rollback', ['--path' => self::MIGRAZIONE]);
|
||||
|
||||
$modello = Modello::where('codice', 'finestra_1_anta')->firstOrFail();
|
||||
DB::table('listino_prezzi')->insert(['modello_id' => $modello->id, 'larghezza' => 145, 'altezza' => 40, 'prezzo' => 367.2]);
|
||||
$preventivo = Preventivo::create(['token' => Str::random(40), 'stato' => 'bozza']);
|
||||
$item = $preventivo->items()->create([
|
||||
'nome_modello' => 'Finestra 1 anta',
|
||||
'larghezza' => 80,
|
||||
'altezza' => 120,
|
||||
'payload' => ['width' => '80.00', 'height' => '120.5', 'maniglia' => 'Bianca'],
|
||||
]);
|
||||
|
||||
Artisan::call('migrate', ['--path' => self::MIGRAZIONE]);
|
||||
|
||||
$this->assertSame([1450, 400], [(int) $modello->listino()->value('larghezza'), (int) $modello->listino()->value('altezza')]);
|
||||
|
||||
$item->refresh();
|
||||
$this->assertSame([800, 1200], [$item->larghezza, $item->altezza]);
|
||||
$this->assertSame(['width' => '800', 'height' => '1205', 'maniglia' => 'Bianca'], $item->payload);
|
||||
|
||||
$righe = collect(ConfigurazioneFormatter::toRows($item->payload))->pluck('value', 'label');
|
||||
$this->assertSame('800', $righe['Larghezza (mm)']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user