sistemati ticket
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/features/customers/models/customer_model.dart';
|
||||
import 'package:flux/features/operations/data/operations_repository.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
@@ -90,7 +91,7 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
||||
storeDisplayName: current.storeDisplayName,
|
||||
batchUuid: current.batchUuid, // MANTIENE IL COLLEGAMENTO
|
||||
customerId: current.customerId, // MANTIENE IL CLIENTE
|
||||
customerDisplayName: current.customerDisplayName,
|
||||
customer: current.customer,
|
||||
status: OperationStatus.draft,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
@@ -178,8 +179,7 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
||||
// --- GESTIONE DEI CAMPI IN TEMPO REALE ---
|
||||
|
||||
void updateFields({
|
||||
String? customerId,
|
||||
String? customerDisplayName,
|
||||
CustomerModel? customer,
|
||||
String? reference,
|
||||
String? note,
|
||||
String? type,
|
||||
@@ -211,10 +211,8 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
||||
if (quantity != null && quantity > 0) newQuantity = quantity;
|
||||
|
||||
final updated = current.copyWith(
|
||||
customerId:
|
||||
customerId ??
|
||||
current.customerId, // Se non passo customerId, tengo il vecchio
|
||||
customerDisplayName: customerDisplayName ?? current.customerDisplayName,
|
||||
customer: customer ?? current.customer,
|
||||
customerId: customer?.id ?? current.customerId,
|
||||
reference: reference ?? current.reference,
|
||||
note: note ?? current.note,
|
||||
providerId: clearProvider ? null : (providerId ?? current.providerId),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/core/utils/extensions.dart';
|
||||
import 'package:flux/features/attachments/models/attachment_model.dart';
|
||||
import 'package:flux/features/customers/models/customer_model.dart';
|
||||
|
||||
enum OperationStatus {
|
||||
success('success', 'OK'),
|
||||
@@ -45,7 +46,7 @@ class OperationModel extends Equatable {
|
||||
final String? lastCampaignId;
|
||||
final OperationStatus status;
|
||||
final String? customerId;
|
||||
final String? customerDisplayName;
|
||||
final CustomerModel? customer;
|
||||
final String reference;
|
||||
|
||||
// ALLEGATI (Aggiunto)
|
||||
@@ -74,7 +75,7 @@ class OperationModel extends Equatable {
|
||||
this.lastCampaignId,
|
||||
this.status = OperationStatus.draft,
|
||||
this.customerId,
|
||||
this.customerDisplayName,
|
||||
this.customer,
|
||||
this.reference = '',
|
||||
this.attachments = const [],
|
||||
});
|
||||
@@ -102,7 +103,7 @@ class OperationModel extends Equatable {
|
||||
String? lastCampaignId,
|
||||
OperationStatus? status,
|
||||
String? customerId,
|
||||
String? customerDisplayName,
|
||||
CustomerModel? customer,
|
||||
String? reference,
|
||||
List<AttachmentModel>? attachments,
|
||||
}) => OperationModel(
|
||||
@@ -128,7 +129,7 @@ class OperationModel extends Equatable {
|
||||
lastCampaignId: lastCampaignId ?? this.lastCampaignId,
|
||||
status: status ?? this.status,
|
||||
customerId: customerId ?? this.customerId,
|
||||
customerDisplayName: customerDisplayName ?? this.customerDisplayName,
|
||||
customer: customer ?? this.customer,
|
||||
reference: reference ?? this.reference,
|
||||
attachments: attachments ?? this.attachments,
|
||||
);
|
||||
@@ -157,7 +158,7 @@ class OperationModel extends Equatable {
|
||||
lastCampaignId,
|
||||
status,
|
||||
customerId,
|
||||
customerDisplayName,
|
||||
customer,
|
||||
reference,
|
||||
attachments,
|
||||
];
|
||||
@@ -207,9 +208,11 @@ class OperationModel extends Equatable {
|
||||
|
||||
lastCampaignId: map['last_campaign_id'] as String?,
|
||||
status: OperationStatus.fromString(map['status'] ?? 'draft'),
|
||||
|
||||
customerId: map['customer_id'] as String?,
|
||||
customerDisplayName: (map['customer']?['name'] as String?)?.myFormat(),
|
||||
|
||||
customer: map['customer'] != null
|
||||
? CustomerModel.fromMap(map['customer'] as Map<String, dynamic>)
|
||||
: null,
|
||||
|
||||
attachments:
|
||||
(map['attachment'] as List?)
|
||||
|
||||
@@ -265,23 +265,6 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: OutlinedButton(
|
||||
onPressed: state.status == OperationFormStatus.saving
|
||||
? null
|
||||
: () => _saveOperation(
|
||||
keepAdding: true,
|
||||
targetStatus:
|
||||
displayStatus, // <-- Usiamo lo stato selezionato nel form!
|
||||
),
|
||||
child: const Text(
|
||||
'Salva e Aggiungi Altro',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: ElevatedButton(
|
||||
@@ -317,6 +300,24 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
: const Text('Salva ed Esci'),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: OutlinedButton(
|
||||
onPressed: state.status == OperationFormStatus.saving
|
||||
? null
|
||||
: () => _saveOperation(
|
||||
keepAdding: true,
|
||||
targetStatus:
|
||||
displayStatus, // <-- Usiamo lo stato selezionato nel form!
|
||||
),
|
||||
child: const Text(
|
||||
'Salva e Aggiungi Altro',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -466,13 +467,9 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
|
||||
Widget _buildCustomerSection(OperationFormState state) {
|
||||
return SharedCustomerSection(
|
||||
customerId: state.operation.customerId,
|
||||
customerName: state.operation.customerDisplayName,
|
||||
customer: state.operation.customer,
|
||||
onCustomerSelected: (customer) {
|
||||
context.read<OperationFormCubit>().updateFields(
|
||||
customerId: customer.id,
|
||||
customerDisplayName: customer.name,
|
||||
);
|
||||
context.read<OperationFormCubit>().updateFields(customer: customer);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -559,7 +556,7 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
return SharedAttachmentsSection(
|
||||
parentType: AttachmentParentType.operation,
|
||||
parentId: state.operation.id,
|
||||
titleForUpload: state.operation.customerDisplayName ?? 'Nuova pratica',
|
||||
titleForUpload: state.operation.customer?.name ?? 'Nuova pratica',
|
||||
onGenerateIdForQr: _generateIdForQr,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ class _OperationListScreenState extends State<OperationListScreen> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
operation.customerDisplayName ?? "Cliente sconosciuto",
|
||||
operation.customer?.name ?? "Cliente sconosciuto",
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
|
||||
Reference in New Issue
Block a user