- LedgerTransactionAccount acc = item.getAccount();
- String acc_name = acc.getAccountName()
- .trim();
- if (!acc_name.isEmpty()) {
- accounts++;
-
- if (acc.isAmountSet()) {
- accounts_with_values++;
- }
- }
- else empty_rows++;
-
- if (!acc.isAmountSet()) {
- if (empty_amount == null) {
- empty_amount = item;
- single_empty_amount = true;
- single_empty_amount_has_account = !acc_name.isEmpty();
- }
- else if (!acc_name.isEmpty()) single_empty_amount = false;
- }
- else {
- amounts++;
- if (!acc_name.isEmpty()) amounts_with_accounts++;
- running_total += acc.getAmount();
- }
- }
-
- if ((empty_rows == 0) &&
- ((this.items.size() == accounts) || (this.items.size() == amounts)))
- {
- adapter.addRow();
- }
-
- if (single_empty_amount) {
- empty_amount.setAmountHint(String.format(Locale.US, "%1.2f",
- Misc.isZero(running_total) ? 0f : -running_total));
- }
-
- debug("submittable", String.format(Locale.US,
- "%s, accounts=%d, accounts_with_values=%s, " +
- "amounts_with_accounts=%d, amounts=%d, running_total=%1.2f, " +
- "single_empty_with_acc=%s", have_description ? "description" : "NO description",
- accounts, accounts_with_values, amounts_with_accounts, amounts, running_total,
- (single_empty_amount && single_empty_amount_has_account) ? "true" : "false"));
-
- if (have_description && (accounts >= 2) && (accounts_with_values >= (accounts - 1)) &&
- (amounts_with_accounts == amounts) &&
- (single_empty_amount && single_empty_amount_has_account || isZero(running_total)))
- {
- debug("submittable", "YES");
- isSubmittable.setValue(true);
- }
- else {
- debug("submittable", "NO");
- isSubmittable.setValue(false);
- }
-
- }
- catch (NumberFormatException e) {
- debug("submittable", "NO (because of NumberFormatException)");
- isSubmittable.setValue(false);
- }
- catch (Exception e) {
- e.printStackTrace();
- debug("submittable", "NO (because of an Exception)");
- isSubmittable.setValue(false);