stampa ddt
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart'; // Per estrarre gli store
|
||||
import '../models/provider_model.dart';
|
||||
@@ -13,7 +14,13 @@ class ProviderFormCubit extends Cubit<ProviderFormState> {
|
||||
final _client = Supabase.instance.client; // Lo usiamo al volo per gli store
|
||||
|
||||
ProviderFormCubit()
|
||||
: super(ProviderFormState(provider: ProviderModel.empty(companyId: '')));
|
||||
: super(
|
||||
ProviderFormState(
|
||||
provider: ProviderModel.empty(
|
||||
companyId: GetIt.I.get<SessionCubit>().state.company!.id!,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// --- INIZIALIZZAZIONE ---
|
||||
Future<void> initForm({
|
||||
@@ -51,7 +58,8 @@ class ProviderFormCubit extends Cubit<ProviderFormState> {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: ProviderFormStatus.initial,
|
||||
provider: existingProvider ?? ProviderModel.empty(companyId: ''),
|
||||
provider:
|
||||
existingProvider ?? ProviderModel.empty(companyId: companyId),
|
||||
availableStores: storesResponse as List<dynamic>,
|
||||
selectedStoreIds: linkedStoreIds,
|
||||
localLocations: existingProvider?.locations ?? [],
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import '../models/provider_model.dart';
|
||||
@@ -5,6 +6,7 @@ import '../models/provider_location_model.dart';
|
||||
|
||||
class ProviderRepository {
|
||||
final _supabase = GetIt.I.get<SupabaseClient>();
|
||||
final _companyId = GetIt.I.get<SessionCubit>().state.company!.id!;
|
||||
|
||||
// 1. Carica i provider abilitati per uno specifico Store
|
||||
Future<List<ProviderModel>> getProvidersByStore(String storeId) async {
|
||||
@@ -44,9 +46,10 @@ class ProviderRepository {
|
||||
List<String> enabledStoreIds,
|
||||
) async {
|
||||
// A. Salva/Aggiorna il Provider principale
|
||||
final providerWithCompany = provider.copyWith(companyId: _companyId);
|
||||
final savedRow = await _supabase
|
||||
.from('provider')
|
||||
.upsert(provider.toMap())
|
||||
.upsert(providerWithCompany.toMap())
|
||||
.select()
|
||||
.single();
|
||||
|
||||
|
||||
@@ -129,8 +129,8 @@ class ProviderModel extends Equatable {
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
if (id != null) 'id': id,
|
||||
Map<String, dynamic> baseMap = {
|
||||
if (id != null && id!.trim().isNotEmpty) 'id': id,
|
||||
'company_id': companyId,
|
||||
'name': name,
|
||||
'is_active': isActive,
|
||||
@@ -146,6 +146,7 @@ class ProviderModel extends Equatable {
|
||||
// Trasformiamo gli Enum di nuovo in stringhe per Supabase
|
||||
'roles': roles.map((e) => e.name).toList(),
|
||||
};
|
||||
return baseMap;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -60,7 +60,13 @@ class _ProviderListScreenState extends State<ProviderListScreen> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Gestione Fornitori')),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => context.pushNamed(Routes.providerForm),
|
||||
onPressed: () async {
|
||||
final providerListCubit = context.read<ProviderListCubit>();
|
||||
final storeId = context.read<SessionCubit>().state.currentStore?.id;
|
||||
await context.pushNamed(Routes.providerForm);
|
||||
if (!mounted || storeId == null) return;
|
||||
providerListCubit.loadProviders(storeId);
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Nuovo Fornitore'),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user