save method

Future<bool> save()

Creates or updates the invoice. Returns true when the dialog can close.

Implementation

Future<bool> save() async {
  if (editing != null) {
    return await send(
          UServices.hotel.updateDormBedInvoice(
            p: UDormBedInvoiceUpdateParams(
              id: editing!.id,
              tags: <int>[type.number],
              debtAmount: numOf(debtController),
              creditorAmount: numOf(creditorController),
              paidAmount: numOf(paidController),
              penaltyAmount: numOf(penaltyController),
              dueDate: dueDate,
              detail1: descriptionController.text.nullIfEmpty(),
            ),
          ),
          read,
        ) !=
        null;
  }
  if (formContract == null) {
    UToast.error(message: U.s.selectAItem(U.s.contract));
    return false;
  }
  return await send(
        UServices.hotel.createDormBedInvoice(
          p: UDormBedInvoiceCreateParams(
            tags: <int>[TagDormBedInvoice.notPaid.number, type.number],
            debtAmount: numOf(debtController) ?? 0,
            creditorAmount: numOf(creditorController) ?? 0,
            paidAmount: numOf(paidController) ?? 0,
            penaltyAmount: numOf(penaltyController) ?? 0,
            contractId: formContract!.id,
            dueDate: dueDate!,
            detail1: descriptionController.text.trim(),
          ),
        ),
        read,
      ) !=
      null;
}