Skip to content

Commit

Permalink
Add maximum credit amount validation and clean up form section labels
Browse files Browse the repository at this point in the history
  • Loading branch information
kyungmin committed Jan 29, 2015
1 parent 3f27552 commit 1de34bf
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 52 deletions.
2 changes: 2 additions & 0 deletions app/models/account.coffee
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
4 changes: 3 additions & 1 deletion app/models/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions app/templates/modals/bank-account-credit-create-modal.hbs
Original file line number Diff line number Diff line change
@@ -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='<img src="images/bank-account-instructions.png" alt="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='<img src="images/bank-account-instructions.png" alt="Bank Account Instructions"/>'}}
Expand All @@ -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"}}
<div class="form-group">
<p>Funds will appear in the bank account by the next business day. First time credits to new accounts may take 3-5 business days.</p>
</div>
{{/view}}
2 changes: 1 addition & 1 deletion app/templates/modals/capture-hold-modal.hbs
Original file line number Diff line number Diff line change
@@ -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"}}

Expand Down
4 changes: 2 additions & 2 deletions app/templates/modals/card-debit-create-modal.hbs
Original file line number Diff line number Diff line change
@@ -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"}}
Expand All @@ -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}}
21 changes: 5 additions & 16 deletions app/templates/modals/credit-customer-modal.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}
Expand All @@ -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"}}
Expand Down
14 changes: 1 addition & 13 deletions app/templates/modals/credit-funding-instrument.hbs
Original file line number Diff line number Diff line change
@@ -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}}
<div class="form-group">
<p>This credit is expected to appear on {{human-readable-date view.model.destination.expected_credit_date}}.</p>
</div>
{{/view}}
8 changes: 5 additions & 3 deletions app/templates/modals/credit-order-modal.hbs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,16 +17,18 @@
name="destination"
field="destination"
explanationText=view.parentView.nameOnAccount
prompt="Select one"
}}
{{else}}
<div class="form-group">
<p>This customer doesn't have any payment method to credit.</p>
</div>
{{/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}}
6 changes: 3 additions & 3 deletions app/templates/modals/debit-customer-modal.hbs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}}
2 changes: 1 addition & 1 deletion app/templates/modals/debit-funding-instrument.hbs
Original file line number Diff line number Diff line change
@@ -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"}}

Expand Down
2 changes: 1 addition & 1 deletion app/templates/modals/debit-order-modal.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
2 changes: 1 addition & 1 deletion app/templates/modals/hold-card-modal.hbs
Original file line number Diff line number Diff line change
@@ -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"}}

Expand Down
2 changes: 1 addition & 1 deletion app/templates/modals/refund-debit-modal.hbs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/templates/modals/reverse-credit-modal.hbs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions app/views/modals/credit-customer-modal.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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");
Expand Down
6 changes: 6 additions & 0 deletions app/views/modals/credit-funding-instrument-modal.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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);
Expand Down

0 comments on commit 1de34bf

Please sign in to comment.