fix macos pdf
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/features/settings/document_sequence/data/document_sequence_repository.dart';
|
||||
import 'package:flux/features/settings/document_sequence/models/document_sequence_model.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class TicketRepository {
|
||||
final SupabaseClient _supabase = GetIt.I.get<SupabaseClient>();
|
||||
final DocumentSequenceRepository _documentSequenceRepository = GetIt.I
|
||||
.get<DocumentSequenceRepository>();
|
||||
|
||||
TicketRepository();
|
||||
|
||||
@@ -192,29 +196,29 @@ class TicketRepository {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> generateTicketReference(String companyId) async {
|
||||
final response = await Supabase.instance.client.rpc(
|
||||
'get_next_document_number',
|
||||
params: {'p_company_id': companyId, 'p_doc_type': 'ticket'},
|
||||
);
|
||||
// Future<String> generateTicketReference(String companyId) async {
|
||||
// final response = await Supabase.instance.client.rpc(
|
||||
// 'get_next_document_number',
|
||||
// params: {'p_company_id': companyId, 'p_doc_type': 'ticket'},
|
||||
// );
|
||||
|
||||
// Estraiamo i dati dal JSON
|
||||
final int nextValue = response['next_value'];
|
||||
final String prefix = response['prefix'] ?? '';
|
||||
// // Estraiamo i dati dal JSON
|
||||
// final int nextValue = response['next_value'];
|
||||
// final String prefix = response['prefix'] ?? '';
|
||||
|
||||
final year = DateTime.now().year; // 2026
|
||||
// final year = DateTime.now().year; // 2026
|
||||
|
||||
// Formattazione con zeri iniziali (es. 000125)
|
||||
final paddedNumber = nextValue.toString().padLeft(6, '0');
|
||||
// // Formattazione con zeri iniziali (es. 000125)
|
||||
// final paddedNumber = nextValue.toString().padLeft(6, '0');
|
||||
|
||||
// Costruiamo la stringa. Se c'è un prefisso mette "TCK-2026-000125",
|
||||
// altrimenti solo "2026-000125"
|
||||
if (prefix.isNotEmpty) {
|
||||
return '$prefix-$year-$paddedNumber';
|
||||
} else {
|
||||
return '$year-$paddedNumber';
|
||||
}
|
||||
}
|
||||
// // Costruiamo la stringa. Se c'è un prefisso mette "TCK-2026-000125",
|
||||
// // altrimenti solo "2026-000125"
|
||||
// if (prefix.isNotEmpty) {
|
||||
// return '$prefix-$year-$paddedNumber';
|
||||
// } else {
|
||||
// return '$year-$paddedNumber';
|
||||
// }
|
||||
// }
|
||||
|
||||
/// Salva il ticket
|
||||
Future<TicketModel> insertTicket(TicketModel ticket) async {
|
||||
@@ -223,7 +227,9 @@ class TicketRepository {
|
||||
}
|
||||
try {
|
||||
final ticketToSave = ticket.copyWith(
|
||||
referenceId: await generateTicketReference(ticket.companyId),
|
||||
referenceId: await _documentSequenceRepository.getNextDocumentNumber(
|
||||
DocumentType.ticket.name,
|
||||
),
|
||||
);
|
||||
final response = await _supabase
|
||||
.from(_tableName)
|
||||
|
||||
50
lib/features/tickets/data/tickets_shipment_repository.dart
Normal file
50
lib/features/tickets/data/tickets_shipment_repository.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
import 'package:flux/features/tickets/models/shipment_document_model.dart';
|
||||
import 'package:flux/features/master_data/providers/models/provider_model.dart';
|
||||
import 'package:flux/features/master_data/providers/models/provider_role.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class TicketsShipmentRepository {
|
||||
final _supabase = GetIt.I.get<SupabaseClient>();
|
||||
|
||||
Future<List<ProviderModel>> fetchRepairCenters() async {
|
||||
try {
|
||||
final response = await _supabase
|
||||
.from('provider')
|
||||
.select('*, provider_locations (*)')
|
||||
.eq('is_active', true)
|
||||
.order('name');
|
||||
|
||||
final allProviders = (response as List)
|
||||
.map((row) => ProviderModel.fromMap(row as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
// Filtriamo lato client per prendere SOLO i repairCenter
|
||||
return allProviders
|
||||
.where((p) => p.roles.contains(ProviderRole.repairCenter))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
throw ('Errore caricamento laboratori: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// NUOVO METODO: Salva il DDT e aggiorna i Ticket
|
||||
Future<void> createShipmentDocument({
|
||||
required ShipmentDocumentModel document,
|
||||
required TicketStatus newTicketStatus, // es: 'shipped' o 'inExternalLab'
|
||||
}) async {
|
||||
try {
|
||||
// 1. Inseriamo il singolo Documento di Trasporto
|
||||
await _supabase.from('shipment_documents').insert(document.toMap());
|
||||
|
||||
// 2. Aggiorniamo lo stato di TUTTI i ticket inclusi nel DDT
|
||||
await _supabase
|
||||
.from('ticket')
|
||||
.update({'ticket_status': newTicketStatus.value})
|
||||
.inFilter('id', document.ticketIds);
|
||||
} catch (e) {
|
||||
throw ('Errore durante la creazione della spedizione: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user