df
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
@@ -8,6 +10,7 @@ import 'package:flux/features/master_data/providers/models/provider_model.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:flux/features/tickets/utils/ticket_shipping_pdf_service.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
part 'ticket_shipping_state.dart';
|
||||
@@ -17,18 +20,19 @@ class TicketShippingCubit extends Cubit<TicketShippingState> {
|
||||
GetIt.I<TicketsShipmentRepository>();
|
||||
final DocumentSequenceRepository _sequenceRepository =
|
||||
GetIt.I<DocumentSequenceRepository>();
|
||||
TicketShippingCubit({required List<String> ticketIds})
|
||||
TicketShippingCubit({required List<TicketModel> tickets})
|
||||
: super(
|
||||
TicketShippingState(
|
||||
// Inizializziamo il modello direttamente nello stato!
|
||||
document: ShipmentDocumentModel(
|
||||
companyId: GetIt.I.get<SessionCubit>().state.company!.id!,
|
||||
ticketIds: ticketIds,
|
||||
ticketIds: tickets.map((t) => t.id!).toList(),
|
||||
providerId: '', // Sarà riempito alla selezione
|
||||
destinationLocationId: '', // Sarà riempito alla selezione
|
||||
docNumber: '',
|
||||
docDate: DateTime.now(),
|
||||
),
|
||||
tickets: tickets,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -140,25 +144,35 @@ class TicketShippingCubit extends Cubit<TicketShippingState> {
|
||||
DocumentType.shipment.name,
|
||||
);
|
||||
updateDocument(docNumber: nextNumber);
|
||||
// 3. GENERIAMO I BYTES DEL PDF
|
||||
final provider = state.availableProviders.firstWhere(
|
||||
(p) => p.id == state.document.providerId,
|
||||
);
|
||||
final location = state.availableLocations.firstWhere(
|
||||
(l) => l.id == state.document.destinationLocationId,
|
||||
);
|
||||
final pdfBytes = await TicketShippingPdfService.generateDdt(
|
||||
company: GetIt.I.get<SessionCubit>().state.company!,
|
||||
provider: provider,
|
||||
location: location,
|
||||
document: state.document,
|
||||
tickets: state.tickets,
|
||||
);
|
||||
await _repository.createShipmentWithPdf(
|
||||
document: state.document,
|
||||
pdfBytes: pdfBytes,
|
||||
newTicketStatus: newTicketStatus.value,
|
||||
);
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: TicketShippingStatus.success,
|
||||
pdfBytes: pdfBytes,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
emit(state.copyWith(isAutoNumber: false, errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await _repository.createShipmentDocument(
|
||||
document: state.document,
|
||||
newTicketStatus: newTicketStatus,
|
||||
);
|
||||
emit(state.copyWith(status: TicketShippingStatus.success));
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: TicketShippingStatus.failure,
|
||||
errorMessage: e.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user