buildIsinModifyFromFunds function

List<String> buildIsinModifyFromFunds(
  1. List<FundDetail> funds
)

Format helpers for edit-loan-amount API

Implementation

List<String> buildIsinModifyFromFunds(List<FundDetail> funds) {
  // server expects "<fund_code>:<folioNo>:<updatedFundAmount>"
  return funds
      .where((f) {
        // keep only those with required values present and a non-null updated amount
        return (f.fundCode.isNotEmpty &&
            f.folioNo.isNotEmpty &&
            f.updatedFundAmount != null);
      })
      .map((f) {
        // If API expects integer units, use toStringAsFixed(0). If decimals allowed, use toString()
        final amt = f.updatedFundAmount!;
        final amtStr = amt == amt.roundToDouble()
            ? amt.toStringAsFixed(0)
            : amt.toString();
        return '${f.fundCode}:${f.folioNo}:$amtStr';
      })
      .toList();
}