save method
Creates or updates the contract. Returns true when the dialog can close.
Implementation
Future<bool> save() async {
// Daily contracts are single-invoice with no deposit; monthly ones keep rent + deposit.
final bool isDaily = type == TagDormBedContract.daily;
final List<int> tags = <int>[type.number, if (isDaily) TagDormBedContract.singleInvoice.number];
if (editing != null) {
return await send(
UServices.hotel.updateDormBedContract(
p: UDormBedContractUpdateParams(id: editing!.id, tags: tags, startDate: contractStart, endDate: contractEnd, deposit: isDaily ? 0 : numOf(depositController), rent: numOf(rentController)),
),
read,
) !=
null;
}
if (formBed == null) {
UToast.error(message: U.s.selectAItem(U.s.bed));
return false;
}
if (formUser == null) {
UToast.error(message: U.s.selectAItem(U.s.user));
return false;
}
return await send(
UServices.hotel.createDormBedContract(
p: UDormBedContractCreateParams(
tags: tags,
startDate: contractStart!,
endDate: contractEnd!,
userId: formUser!.id,
bedId: formBed!.id,
deposit: isDaily ? null : numOf(depositController),
rent: numOf(rentController),
penaltyPrecentEveryDate: isDaily ? null : intOf(penaltyController),
detail1: descriptionController.text.nullIfEmpty(),
),
),
read,
) !=
null;
}