+ itemsWithEmptyAmount.add(item);
+
+ if (!acc_name.isEmpty()) {
+ itemsWithAccountAndEmptyAmount.add(item);
+ }
+ }
+ }
+
+ // 1) has at least two account names
+ if (accounts < 2) {
+ Logger.debug("submittable",
+ String.format("Transaction not submittable: only %d account names",
+ accounts));
+ submittable = false;
+ }
+
+ // 3) amount must balance to 0, or
+ // 3a) there must be exactly one empty amount (with account)
+ if (Misc.isZero(balance)) {
+ for (Item item : items) {
+ item.setAmountHint(null);
+ }
+ }
+ else {
+ int balanceReceiversCount = itemsWithAccountAndEmptyAmount.size();
+ if (balanceReceiversCount != 1) {
+ Logger.debug("submittable", (balanceReceiversCount == 0) ?
+ "Transaction not submittable: non-zero balance " +
+ "with no empty amounts with accounts" :
+ "Transaction not submittable: non-zero balance " +
+ "with multiple empty amounts with accounts");
+ submittable = false;
+ }
+
+ // suggest off-balance amount to a row and remove hints on other rows
+ Item receiver = null;
+ if (!itemsWithAccountAndEmptyAmount.isEmpty())
+ receiver = itemsWithAccountAndEmptyAmount.get(0);
+ else if (!itemsWithEmptyAmount.isEmpty())
+ receiver = itemsWithEmptyAmount.get(0);
+
+ for (Item item : items) {
+ if (item.equals(receiver)) {
+ Logger.debug("submittable",
+ String.format("Setting amount hint to %1.2f", -balance));
+ item.setAmountHint(String.format("%1.2f", -balance));
+ }
+ else
+ item.setAmountHint(null);