upgraded flutter and refactor document sequences
This commit is contained in:
@@ -1,6 +1,22 @@
|
||||
// Se un domani ci saranno nuovi tipi di documento, basterà aggiungerli qui
|
||||
// e alla mappa nella DocumentSequenceSection dei documenti supportati
|
||||
enum DocumentType { ticket, shipment }
|
||||
enum DocumentType {
|
||||
ticket(name: 'ticket', label: 'Ticket', defaultPrefix: 'TCK'),
|
||||
ticketsShipping(
|
||||
name: 'tickets_shipping',
|
||||
label: 'DDT (Documento di Trasporto)',
|
||||
defaultPrefix: 'DDT',
|
||||
);
|
||||
|
||||
final String name;
|
||||
final String label;
|
||||
final String defaultPrefix;
|
||||
const DocumentType({
|
||||
required this.name,
|
||||
required this.label,
|
||||
required this.defaultPrefix,
|
||||
});
|
||||
}
|
||||
|
||||
class DocumentSequence {
|
||||
final String docType;
|
||||
|
||||
@@ -6,22 +6,6 @@ import 'package:flux/features/settings/document_sequence/models/document_sequenc
|
||||
class DocumentSequenceSection extends StatelessWidget {
|
||||
const DocumentSequenceSection({super.key});
|
||||
|
||||
// La nostra lista "Ninja" di tutti i documenti gestiti dall'app
|
||||
// Se domani aggiungo le fatture, basta aggiungere una riga qui!
|
||||
// e all'enum DocumentType nel model
|
||||
static final supportedDocumentTypes = [
|
||||
{
|
||||
'type': DocumentType.ticket.name,
|
||||
'label': 'TICKET',
|
||||
'defaultPrefix': 'TCK',
|
||||
},
|
||||
{
|
||||
'type': DocumentType.shipment.name,
|
||||
'label': 'DDT (Documento di Trasporto)',
|
||||
'defaultPrefix': 'DDT',
|
||||
},
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final year = DateTime.now().year;
|
||||
@@ -46,19 +30,17 @@ class DocumentSequenceSection extends StatelessWidget {
|
||||
),
|
||||
|
||||
// Invece di mappare state.sequences, mappiamo i documenti supportati
|
||||
...supportedDocumentTypes.map((docDef) {
|
||||
final docType = docDef['type']!;
|
||||
|
||||
...DocumentType.values.map((docType) {
|
||||
// Cerchiamo se c'è già una configurazione nello stato per questo documento
|
||||
final existingList = state.sequences
|
||||
.where((s) => s.docType == docType)
|
||||
.where((s) => s.docType == docType.name)
|
||||
.toList();
|
||||
final existingSeq = existingList.isNotEmpty
|
||||
? existingList.first
|
||||
: null;
|
||||
|
||||
// Se esiste usiamo i suoi valori, altrimenti i default
|
||||
final prefix = existingSeq?.prefix ?? docDef['defaultPrefix']!;
|
||||
final prefix = existingSeq?.prefix ?? docType.defaultPrefix;
|
||||
final nextValue = existingSeq?.nextValue ?? 1;
|
||||
|
||||
// Anteprima dinamica (aggiornata a 4 zeri come nel DB!)
|
||||
@@ -73,7 +55,7 @@ class DocumentSequenceSection extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
docDef['label']!,
|
||||
docType.label,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.blue,
|
||||
@@ -92,7 +74,10 @@ class DocumentSequenceSection extends StatelessWidget {
|
||||
),
|
||||
onChanged: (val) => context
|
||||
.read<DocumentSequenceCubit>()
|
||||
.updateLocalSequence(docType, prefix: val),
|
||||
.updateLocalSequence(
|
||||
docType.name,
|
||||
prefix: val,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
@@ -107,7 +92,7 @@ class DocumentSequenceSection extends StatelessWidget {
|
||||
onChanged: (val) => context
|
||||
.read<DocumentSequenceCubit>()
|
||||
.updateLocalSequence(
|
||||
docType,
|
||||
docType.name,
|
||||
nextValue: int.tryParse(val) ?? 1,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -140,7 +140,7 @@ class TicketShippingCubit extends Cubit<TicketShippingState> {
|
||||
if (state.isAutoNumber) {
|
||||
try {
|
||||
final nextNumber = await _sequenceRepository.getNextDocumentNumber(
|
||||
DocumentType.shipment.name,
|
||||
DocumentType.ticketsShipping.name,
|
||||
);
|
||||
updateDocument(docNumber: nextNumber);
|
||||
// 3. GENERIAMO I BYTES DEL PDF
|
||||
|
||||
Reference in New Issue
Block a user