From 1de34bf4be6f848d6d534092752ebd73f40b86ab Mon Sep 17 00:00:00 2001 From: Kyungmin Kim Date: Thu, 29 Jan 2015 15:45:11 -0800 Subject: [PATCH] Add maximum credit amount validation and clean up form section labels --- app/models/account.coffee | 2 + app/models/customer.js | 4 +- ...-funding-instrument-transaction-factory.js | 37 ++++++++++++++++++- .../bank-account-credit-create-modal.hbs | 8 +--- app/templates/modals/capture-hold-modal.hbs | 2 +- .../modals/card-debit-create-modal.hbs | 4 +- .../modals/credit-customer-modal.hbs | 21 +++-------- .../modals/credit-funding-instrument.hbs | 14 +------ app/templates/modals/credit-order-modal.hbs | 8 ++-- app/templates/modals/debit-customer-modal.hbs | 6 +-- .../modals/debit-funding-instrument.hbs | 2 +- app/templates/modals/debit-order-modal.hbs | 2 +- app/templates/modals/hold-card-modal.hbs | 2 +- app/templates/modals/refund-debit-modal.hbs | 2 +- app/templates/modals/reverse-credit-modal.hbs | 2 +- app/views/modals/credit-customer-modal.js | 13 +++++++ .../modals/credit-funding-instrument-modal.js | 6 +++ 17 files changed, 83 insertions(+), 52 deletions(-) diff --git a/app/models/account.coffee b/app/models/account.coffee index 527edbd13..1ad979004 100644 --- a/app/models/account.coffee +++ b/app/models/account.coffee @@ -1,11 +1,13 @@ `import Ember from "ember";` `import Model from "./core/model";` `import Computed from "balanced-dashboard/utils/computed";` +`import Constants from "balanced-dashboard/utils/constants";` Account = Model.extend( routeName: "account" route_name: "account" isPayableAccount: Ember.computed.equal("type", "payable") + appears_on_statement_max_length: Constants.MAXLENGTH.APPEARS_ON_STATEMENT_BANK_ACCOUNT, type_name: Ember.computed "type", -> type = @get("type") diff --git a/app/models/customer.js b/app/models/customer.js index ae7ed29d6..70d658ef3 100644 --- a/app/models/customer.js +++ b/app/models/customer.js @@ -62,7 +62,9 @@ var Customer = Model.extend({ return DisputesResultsLoader.create(attributes); }, - hasCreditableOrders: Ember.computed.gt("creditableOrders.length", 0), + hasCreditableOrders: function() { + return (this.get("creditableOrders.isLoaded") && this.get("creditableOrders.length") > 0); + }.property("creditableOrders.isLoaded", "creditableOrders.length"), creditableOrders: function () { return this.getOrdersLoader().get("results"); diff --git a/app/models/factories/credit-existing-funding-instrument-transaction-factory.js b/app/models/factories/credit-existing-funding-instrument-transaction-factory.js index f0f9c987a..f57996b74 100644 --- a/app/models/factories/credit-existing-funding-instrument-transaction-factory.js +++ b/app/models/factories/credit-existing-funding-instrument-transaction-factory.js @@ -1,5 +1,6 @@ import Ember from "ember"; import ValidationHelpers from "balanced-dashboard/utils/validation-helpers"; +import Utils from "balanced-dashboard/lib/utils"; import CreditOrderFactory from "./credit-order-factory"; var CreditExistingFundingInstrumentTransactionFactory = CreditOrderFactory.extend({ @@ -9,8 +10,42 @@ var CreditExistingFundingInstrumentTransactionFactory = CreditOrderFactory.exten return Ember.RSVP.resolve(this.get("destination")); }, + isAmountOverMaximum: function() { + if (this.get("order")) { + return this.get("amount") > this.get("order.amount_escrowed"); + } + return false; + }, + validations: { - dollar_amount: ValidationHelpers.positiveDollarAmount, + dollar_amount: { + format: { + validator: function(object, attribute, value) { + var message = function(message) { + object.get("validationErrors").add(attribute, "format", null, message); + }; + + value = (value || "").toString().trim(); + if (Ember.isBlank(value)) { + message("is required"); + } else if (object.isAmountOverMaximum()) { + var maxAmount = object.get("order.amount_escrowed"); + message("cannot be more than %@".fmt(Utils.formatCurrency(maxAmount))); + } else if (!object.isAmountPositive()) { + message("must be a positive number"); + } else { + try { + var v = Utils.dollarsToCents(value); + if (isNaN(v) || v <= 0) { + message("must be a positive number"); + } + } catch (e) { + message(e.message.replace("Error: ", "")); + } + } + } + } + }, appears_on_statement_as: ValidationHelpers.bankTransactionAppearsOnStatementAs, destination: { presence: true diff --git a/app/templates/modals/bank-account-credit-create-modal.hbs b/app/templates/modals/bank-account-credit-create-modal.hbs index 93862ba37..3d540d7dd 100644 --- a/app/templates/modals/bank-account-credit-create-modal.hbs +++ b/app/templates/modals/bank-account-credit-create-modal.hbs @@ -1,4 +1,4 @@ -{{#view "form-fields/form-section" appearsOnStatementAsLabelText=view.appearsOnStatementAsLabelText bankAccountTypes=view.bankAccountTypes model=view.model sectionTitle="Payment information"}} +{{#view "form-fields/form-section" appearsOnStatementAsLabelText=view.appearsOnStatementAsLabelText bankAccountTypes=view.bankAccountTypes model=view.model sectionTitle="Credit information" sectionDescription="Funds will appear in the bank account by the next business day. First time credits to new accounts may take 3-5 business days."}} {{view "form-fields/text-form-field" model=view.model field="name" labelText="Name on account" inputClassNames="full"}} {{view "form-fields/text-form-field" model=view.model field="routing_number" labelText="Routing number" inputClassNames="full" tooltipTitle="Where is the routing number?" tooltipContent='Bank Account Instructions'}} {{view "form-fields/text-form-field" model=view.model field="account_number" labelText="Account number" inputClassNames="full" tooltipTitle="Where is the account number?" tooltipContent='Bank Account Instructions'}} @@ -20,9 +20,3 @@ {{view "form-fields/text-form-field" model=view.model field="description" labelText="Internal description" inputClassNames="full"}} {{/view}} - -{{#view "form-fields/form-section" sectionTitle="Note"}} -
-

Funds will appear in the bank account by the next business day. First time credits to new accounts may take 3-5 business days.

-
-{{/view}} diff --git a/app/templates/modals/capture-hold-modal.hbs b/app/templates/modals/capture-hold-modal.hbs index a83077b13..4220831ad 100644 --- a/app/templates/modals/capture-hold-modal.hbs +++ b/app/templates/modals/capture-hold-modal.hbs @@ -1,4 +1,4 @@ -{{#view "form-fields/form-section" appearsOnStatementAsLabelText=view.appearsOnStatementAsLabelText model=view.model sectionTitle="Payment information"}} +{{#view "form-fields/form-section" appearsOnStatementAsLabelText=view.appearsOnStatementAsLabelText model=view.model sectionTitle="Hold information"}} {{view "form-fields/static-text-form-field" value=view.model.hold.source.customer.display_me labelText="Customer" inputClassNames="full"}} diff --git a/app/templates/modals/card-debit-create-modal.hbs b/app/templates/modals/card-debit-create-modal.hbs index bab17c3aa..c4a0b7845 100644 --- a/app/templates/modals/card-debit-create-modal.hbs +++ b/app/templates/modals/card-debit-create-modal.hbs @@ -1,5 +1,5 @@ {{#view "form-fields/form-section" sectionTitle="Order information" appearsOnStatementAsLabelText=view.appearsOnStatementAsLabelText appearsOnStatementAsMaxLength=view.appearsOnStatementAsMaxLength model=view.model}} - {{view "form-fields/text-form-field" model=view.model field="order_description" labelText="Order description" inputClassNames="full"}} + {{view "form-fields/text-form-field" model=view.model field="order_description" labelText="Internal description" inputClassNames="full"}} {{view "form-fields/text-form-field" model=view.model field="seller_name" labelText="Merchant's name" inputClassNames="full"}} {{view "form-fields/email-form-field" model=view.model field="seller_email_address" labelText="Merchant's email address" inputClassNames="full"}} @@ -25,5 +25,5 @@ {{view "form-fields/text-form-field" model=view.model field="appears_on_statement_as" labelText=view.appearsOnStatementAsLabelText maxlength=view.appearsOnStatementAsMaxLength inputClassNames="full"}} - {{view "form-fields/text-form-field" model=view.model field="debit_description" labelText="Debit description" inputClassNames="full"}} + {{view "form-fields/text-form-field" model=view.model field="debit_description" labelText="Internal description" inputClassNames="full"}} {{/view}} diff --git a/app/templates/modals/credit-customer-modal.hbs b/app/templates/modals/credit-customer-modal.hbs index 4c8741b68..d6bd0fb86 100644 --- a/app/templates/modals/credit-customer-modal.hbs +++ b/app/templates/modals/credit-customer-modal.hbs @@ -12,30 +12,19 @@ }} {{/view}} -{{#view "form-fields/form-section" fundingInstruments=view.fundingInstruments model=view.model sectionTitle="Payment information"}} - - {{view "form-fields/static-text-form-field" labelText="Customer" value=view.customer.display_me_with_email}} +{{#view "form-fields/form-section" fundingInstruments=view.fundingInstruments model=view.model sectionTitle="Payment method"}} {{#if view.parentView.isDisplayExistingFundingInstruments}} {{view "form-fields/select-form-field" model=view.model content=view.fundingInstruments value=view.model.destination - labelText="Payment method" + labelText="Select one" optionValuePath="content" optionLabelPath="content.description_with_type" name="destination" field="destination" - }} - - {{view "form-fields/static-text-form-field" - labelText="Name on account" - value=view.model.destination.name - }} - - {{view "form-fields/static-text-form-field" - labelText="Bank" - value=view.model.destination.formatted_bank_name + explanationText=view.parentView.nameOnAccountText }} {{else}} {{view "form-fields/text-form-field" model=view.model field="name" labelText="Card holder's name" inputClassNames="full"}} @@ -52,11 +41,11 @@ {{/view}} {{#view "form-fields/form-section" appearsOnStatementAsMaxLength=view.appearsOnStatementAsMaxLength appearsOnStatementAsLabelText=view.appearsOnStatementAsLabelText model=view.model sectionTitle="Credit information"}} - {{view "form-fields/amount-form-field" model=view.model field="dollar_amount" labelText="Amount" explanationText=view.parentView.source.escrow_balance}} + {{view "form-fields/amount-form-field" model=view.model field="dollar_amount" labelText="Amount" explanationText=view.parentView.orderBalanceText}} {{view "form-fields/text-form-field" model=view.model field="appears_on_statement_as" labelText=view.appearsOnStatementAsLabelText maxLength=view.appearsOnStatementAsMaxLength inputClassNames="full" maxlength=view.appearsOnStatementAsMaxLength}} - {{view "form-fields/text-form-field" model=view.model field="credit_description" labelText="Credit description" maxlength=Constants.MAXLENGTH.DESCRIPTION inputClassNames="full"}} + {{view "form-fields/text-form-field" model=view.model field="credit_description" labelText="Internal description" maxlength=Constants.MAXLENGTH.DESCRIPTION inputClassNames="full"}} {{/view}} {{#view "form-fields/form-section" sectionTitle="Note"}} diff --git a/app/templates/modals/credit-funding-instrument.hbs b/app/templates/modals/credit-funding-instrument.hbs index fa44c9058..3b3320252 100644 --- a/app/templates/modals/credit-funding-instrument.hbs +++ b/app/templates/modals/credit-funding-instrument.hbs @@ -1,19 +1,7 @@ -{{#view "form-fields/form-section" appearsOnStatementAsLabelText=view.appearsOnStatementAsLabelText model=view.model sectionTitle="Payment information"}} - {{view "form-fields/static-text-form-field" value=view.model.destination.title_description field="name" labelText=view.model.destination.type_name inputClassNames="full"}} - - {{view "form-fields/static-text-form-field" value=view.model.destination.name labelText="Name on account" inputClassNames="full"}} - - {{view "form-fields/static-text-form-field" value=view.model.destination.formatted_bank_name emptyText="unknown" labelText="Bank" inputClassNames="full"}} - +{{#view "form-fields/form-section" appearsOnStatementAsLabelText=view.appearsOnStatementAsLabelText model=view.model sectionTitle="Credit information" sectionDescription=view.expectedDateText}} {{view "form-fields/amount-form-field" model=view.model field="dollar_amount" labelText="Amount"}} {{view "form-fields/text-form-field" model=view.model field="appears_on_statement_as" labelText=view.appearsOnStatementAsLabelText maxlength=view.model.destination.appears_on_statement_max_length inputClassNames="full"}} {{view "form-fields/text-form-field" model=view.model field="description" labelText="Internal description" inputClassNames="full" maxlength=Constants.MAXLENGTH.DESCRIPTION}} {{/view}} - -{{#view "form-fields/form-section" sectionTitle="Note" model=view.model}} -
-

This credit is expected to appear on {{human-readable-date view.model.destination.expected_credit_date}}.

-
-{{/view}} diff --git a/app/templates/modals/credit-order-modal.hbs b/app/templates/modals/credit-order-modal.hbs index ffa810f26..05f3ddded 100644 --- a/app/templates/modals/credit-order-modal.hbs +++ b/app/templates/modals/credit-order-modal.hbs @@ -1,4 +1,4 @@ -{{#view "form-fields/form-section" appearsOnStatementAsMaxLength=view.appearsOnStatementAsMaxLength appearsOnStatementAsLabelText=view.appearsOnStatementAsLabelText fundingInstruments=view.fundingInstruments model=view.model sectionTitle="Payment information" sectionDescription="Funds will appear in the bank account by the next business day. First time credits to new accounts may take 3-5 business days."}} +{{#view "form-fields/form-section" fundingInstruments=view.fundingInstruments model=view.model sectionTitle="Payment method"}} {{view "form-fields/static-text-form-field" labelText="From" value=view.parentView.fromText @@ -17,16 +17,18 @@ name="destination" field="destination" explanationText=view.parentView.nameOnAccount + prompt="Select one" }} {{else}}

This customer doesn't have any payment method to credit.

{{/if}} - +{{/view}} +{{#view "form-fields/form-section" model=view.model sectionTitle="Credit information" sectionDescription="Funds will appear in the bank account by the next business day. First time credits to new accounts may take 3-5 business days."}} {{view "form-fields/amount-form-field" model=view.model field="dollar_amount" labelText="Amount"}} - {{view "form-fields/text-form-field" model=view.model field="appears_on_statement_as" labelText=view.appearsOnStatementAsLabelText maxLength=view.appearsOnStatementAsMaxLength inputClassNames="full" maxlength=view.appearsOnStatementAsMaxLength}} + {{view "form-fields/text-form-field" model=view.model field="appears_on_statement_as" labelText=view.parentView.appearsOnStatementAsLabelText maxLength=view.parentView.appearsOnStatementAsMaxLength inputClassNames="full" maxlength=view.appearsOnStatementAsMaxLength}} {{view "form-fields/text-form-field" model=view.model field="description" labelText="Internal description" maxlength=Constants.MAXLENGTH.DESCRIPTION inputClassNames="full"}} {{/view}} diff --git a/app/templates/modals/debit-customer-modal.hbs b/app/templates/modals/debit-customer-modal.hbs index c24e21531..ca6a1494c 100644 --- a/app/templates/modals/debit-customer-modal.hbs +++ b/app/templates/modals/debit-customer-modal.hbs @@ -1,12 +1,12 @@ {{#view "form-fields/form-section" sectionTitle="Order information" model=view.model}} - {{view "form-fields/text-form-field" model=view.model field="order_description" labelText="Order description" inputClassNames="full"}} + {{view "form-fields/text-form-field" model=view.model field="order_description" labelText="Internal description" inputClassNames="full"}} {{view "form-fields/text-form-field" model=view.model field="seller_name" labelText="Merchant's name" inputClassNames="full"}} {{view "form-fields/email-form-field" model=view.model field="seller_email_address" labelText="Merchant's email address" inputClassNames="full"}} {{/view}} -{{#view "form-fields/form-section" fundingInstruments=view.fundingInstruments model=view.model sectionTitle="Payment information"}} +{{#view "form-fields/form-section" fundingInstruments=view.fundingInstruments model=view.model sectionTitle="Payment method"}} {{#if view.parentView.isDisplayExistingFundingInstruments}} {{view "form-fields/select-form-field" model=view.model @@ -45,5 +45,5 @@ {{view "form-fields/text-form-field" model=view.model field="appears_on_statement_as" labelText=view.appearsOnStatementAsLabelText maxlength=view.appearsOnStatementAsMaxLength inputClassNames="full"}} - {{view "form-fields/text-form-field" model=view.model field="debit_description" labelText="Debit description" inputClassNames="full" maxlength=Constants.MAXLENGTH.DESCRIPTION}} + {{view "form-fields/text-form-field" model=view.model field="debit_description" labelText="Internal description" inputClassNames="full" maxlength=Constants.MAXLENGTH.DESCRIPTION}} {{/view}} diff --git a/app/templates/modals/debit-funding-instrument.hbs b/app/templates/modals/debit-funding-instrument.hbs index e86849216..dd45447e2 100644 --- a/app/templates/modals/debit-funding-instrument.hbs +++ b/app/templates/modals/debit-funding-instrument.hbs @@ -1,5 +1,5 @@ {{#view "form-fields/form-section" sectionTitle="Order information" model=view.model}} - {{view "form-fields/text-form-field" model=view.model field="order_description" labelText="Order description" inputClassNames="full"}} + {{view "form-fields/text-form-field" model=view.model field="order_description" labelText="Internal description" inputClassNames="full"}} {{view "form-fields/text-form-field" model=view.model field="seller_name" labelText="Merchant's name" inputClassNames="full"}} diff --git a/app/templates/modals/debit-order-modal.hbs b/app/templates/modals/debit-order-modal.hbs index c51e92cc9..b6e8632a3 100644 --- a/app/templates/modals/debit-order-modal.hbs +++ b/app/templates/modals/debit-order-modal.hbs @@ -18,5 +18,5 @@ {{view "form-fields/text-form-field" model=view.model field="appears_on_statement_as" labelText=view.appearsOnStatementAsLabelText maxlength=view.appearsOnStatementAsMaxLength inputClassNames="full"}} - {{view "form-fields/text-form-field" model=view.model field="debit_description" labelText="Debit description" inputClassNames="full"}} + {{view "form-fields/text-form-field" model=view.model field="debit_description" labelText="Internal description" inputClassNames="full"}} {{/view}} diff --git a/app/templates/modals/hold-card-modal.hbs b/app/templates/modals/hold-card-modal.hbs index d7468ecfc..75ac3264e 100644 --- a/app/templates/modals/hold-card-modal.hbs +++ b/app/templates/modals/hold-card-modal.hbs @@ -1,5 +1,5 @@ {{#view "form-fields/form-section" sectionTitle="Order information" model=view.model}} - {{view "form-fields/text-form-field" model=view.model field="order_description" labelText="Order description" inputClassNames="full"}} + {{view "form-fields/text-form-field" model=view.model field="order_description" labelText="Internal description" inputClassNames="full"}} {{view "form-fields/text-form-field" model=view.model field="seller_name" labelText="Merchant's name" inputClassNames="full"}} diff --git a/app/templates/modals/refund-debit-modal.hbs b/app/templates/modals/refund-debit-modal.hbs index 43227fc2c..01051363f 100644 --- a/app/templates/modals/refund-debit-modal.hbs +++ b/app/templates/modals/refund-debit-modal.hbs @@ -1,4 +1,4 @@ -{{#view "form-fields/form-section" recipientLabel=view.recipientLabel recipientDisplay=view.recipientDisplay model=view.model sectionTitle="Payment information"}} +{{#view "form-fields/form-section" recipientLabel=view.recipientLabel recipientDisplay=view.recipientDisplay model=view.model sectionTitle="Refund information"}} {{view "form-fields/static-text-form-field" labelText=view.recipientLabel value=view.recipientDisplay diff --git a/app/templates/modals/reverse-credit-modal.hbs b/app/templates/modals/reverse-credit-modal.hbs index e52129125..6ae5b8e32 100644 --- a/app/templates/modals/reverse-credit-modal.hbs +++ b/app/templates/modals/reverse-credit-modal.hbs @@ -1,4 +1,4 @@ -{{#view "form-fields/form-section" model=view.model sectionTitle="Payment information"}} +{{#view "form-fields/form-section" model=view.model sectionTitle="Reversal information"}} {{view "form-fields/static-text-form-field" labelText="Customer" value=view.parentView.customerDisplay diff --git a/app/views/modals/credit-customer-modal.js b/app/views/modals/credit-customer-modal.js index c677f548f..439c9d3a3 100644 --- a/app/views/modals/credit-customer-modal.js +++ b/app/views/modals/credit-customer-modal.js @@ -1,4 +1,5 @@ import Ember from "ember"; +import Utils from "balanced-dashboard/lib/utils"; import CreditExistingFundingInstrumentTransactionFactory from "balanced-dashboard/models/factories/credit-existing-funding-instrument-transaction-factory"; import ModalBaseView from "./modal-base"; import Form from "balanced-dashboard/views/modals/mixins/form-modal-mixin"; @@ -18,6 +19,18 @@ var CreditCustomerModalView = ModalBaseView.extend(Full, Form, Save, { }); }.property("customer"), + nameOnAccountText: function() { + if (this.get("model.destination.name")) { + return "Name on account: %@".fmt(this.get("model.destination.name")); + } + }.property("model.destination.name"), + + orderBalanceText: function() { + if (this.get("model.order")) { + return "Order balance: %@".fmt(Utils.formatCurrency(this.get("model.order.amount_escrowed"))); + } + }.property("model.order.amount_escrowed"), + appearsOnStatementAsMaxLength: Ember.computed.oneWay("model.appears_on_statement_max_length"), appearsOnStatementAsLabelText: function() { var length = this.get("appearsOnStatementAsMaxLength"); diff --git a/app/views/modals/credit-funding-instrument-modal.js b/app/views/modals/credit-funding-instrument-modal.js index d23e2e61e..65f2775d8 100644 --- a/app/views/modals/credit-funding-instrument-modal.js +++ b/app/views/modals/credit-funding-instrument-modal.js @@ -1,4 +1,5 @@ import BaseFundingInstrumentModalView from "./base-funding-instrument-modal"; +import Utils from "balanced-dashboard/lib/utils"; import CreditExistingFundingInstrumentTransactionFactory from "balanced-dashboard/models/factories/credit-existing-funding-instrument-transaction-factory"; var CreditFundingInstrumentModalView = BaseFundingInstrumentModalView.extend({ @@ -10,6 +11,11 @@ var CreditFundingInstrumentModalView = BaseFundingInstrumentModalView.extend({ cancelButtonText: "Cancel", submitButtonText: "Credit", + expectedDateText: function() { + var creditDate = this.get("model.destination.expected_credit_date"); + return "This credit is expected to appear on %@.".fmt(Utils.humanReadableDate(creditDate)); + }.property("model.destination.expected_credit_date"), + appearsOnStatementAsLabelText: function() { var length = this.get("model.destination.appears_on_statement_max_length"); return "Appears on statement as (%@ characters max)".fmt(length);