Skip to content

Commit

Permalink
Fixes #1600: Fix invoice type formatting and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kyungmin committed Dec 26, 2014
1 parent f6c675d commit 6fc3720
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 0 deletions.
47 changes: 47 additions & 0 deletions app/templates/results/invoice-table.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<thead>
<tr>
<th class="col-md-2"><span>Type</span></th>
<th class="col-md-1 num"><span>Quantity</span></th>
<th class="col-md-2 num"><span>Txn amount</span></th>
<th class="col-md-3"><span>Fee</span></th>
<th class="col-md-2 num total"><span>Amount</span></th>
</tr>
</thead>
<tbody>
{{#each fee in view.fees}}
<tr class="dispute-details-row">
{{#if fee.primary}}
<td class="two-lines">
<a href="#">
<span>
<span class="primary">{{fee.primary}}</span>
<span class="secondary">{{fee.secondary}}</span>
</span>
</a>
</td>
{{else}}
<td>
<span>{{fee.type}}</span>
</td>
{{/if}}
<td class="num">
<span>{{fee.quantity}}</span>
</td>
<td class="num">
<span>{{fee.txnAmount}}</span>
</td>
<td class="sl-none">
<span>{{fee.fee}}</span>
</td>
<td class="num total">
<span>{{fee.totalFee}}</span>
</td>
</tr>
{{/each}}
</tbody>
<tfoot>
<tr class="subtotal-row">
<td class="sl-sb" colspan="4"><span>Total fees</span></td>
<td class="num total sl-sb"><span>{{format-currency subtotal}}</span></td>
</tr>
</tfoot>
25 changes: 25 additions & 0 deletions app/templates/settlement.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{view "page-navigations/page-navigation" pageType=model.type_name title=model.amountInDollars}}

{{#view "detail-views/body-panel"}}
{{#view "detail-views/api-model-panel" model=model}}
{{view detail-views/summary-sections/settlement-summary-section model=model}}
{{view detail-views/description-lists/transaction-titled-key-values-section model=model}}
{{view "meta-list" type=model}}
{{/view}}

{{#view "detail-views/main-panel"}}
<h3>Related activity</h3>
<div class="results">
{{view "results/embedded-transactions-table" loader=creditsResultsLoader}}
</div>
<h3>Logs</h3>
<div class="results">
{{view "resource-logs" content=model}}
</div>

<h3>Events</h3>
<div class="results">
{{view "resource-events" content=model}}
</div>
{{/view}}
{{/view}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SummarySectionView from "./summary-section";
import Utils from "balanced-dashboard/lib/utils";

var SettlementSummarySectionView = SummarySectionView.extend({
linkedResources: function() {
return this.resourceLinks("model.description", "model.source", "model.destination", "model.customer");
}.property('model.description', 'model.source', 'model.destination', 'model.customer'),
});

export default SettlementSummarySectionView;
67 changes: 67 additions & 0 deletions app/views/results/grouped-settlement-row.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import Ember from "ember";
import Computed from "balanced-dashboard/utils/computed";
import LinkedTwoLinesCellView from "../tables/cells/linked-two-lines-cell";
import Utils from "balanced-dashboard/lib/utils";

var GroupedTransactionRowView = LinkedTwoLinesCellView.extend({
tagName: 'tr',
templateName: 'results/grouped-transaction-row',
routeName: Ember.computed.oneWay("item.route_name"),
spanClassNames: Ember.computed.oneWay("item.status"),

title: function() {
var description = this.get("item.description");

if (description) {
return description;
}
if (_.contains(this.get("classNames"), "current")) {
return 'You are currently viewing this transaction.';
}
return '(Created at %@)'.fmt(this.get("secondaryLabelText"));
}.property("item.description", "primaryLabelText", "secondaryLabelText"),

primaryLabelText: function() {
if (_.contains(this.get("classNames"), "current")) {
return '%@ (currently viewing)'.fmt(this.get('item.type_name'));
}
var transactionText;
var description = this.get('item.description');
var status = Utils.capitalize(this.get('item.status'));

if (status) {
status = status.toLowerCase();
}

if (description) {
transactionText = '%@ (%@) %@'.fmt(this.get('item.type_name'), description, status);
} else {
transactionText = '%@ %@'.fmt(this.get('item.type_name'), status);
}

if (this.get('item.type_name') === 'Dispute') {
transactionText = '%@ %@'.fmt(this.get('item.type_name'), status);
}

return Utils.safeFormat(transactionText).htmlSafe();
}.property('classNames', 'item.type_name', 'item.status', 'item.description'),

secondaryLabelText: function () {
return Utils.humanReadableDateTime(this.get('item.created_at'));
}.property('item.created_at'),

paymentMethodText: function() {
var label = '<span class="primary">%@</span><span class="secondary">%@</span>';
var secondaryLabel = this.get('paymentMethodSecondaryLabelText') || '';
return Utils.safeFormat(label, this.get('paymentMethodPrimaryLabelText'), secondaryLabel).htmlSafe();
}.property('paymentMethodPrimaryLabelText', 'paymentMethodSecondaryLabelText'),

paymentMethodPrimaryLabelText: Computed.fmt('item.last_four', 'item.brand', '%@ %@'),
paymentMethodSecondaryLabelText: Ember.computed.reads('item.funding_instrument_type'),

amountText: function() {
return Utils.formatCurrency(this.get("item.amount"));
}.property("item.amount")
});

export default GroupedTransactionRowView;
93 changes: 93 additions & 0 deletions app/views/results/invoice-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import ResultsTableView from "././results-table";
import Utils from "balanced-dashboard/lib/utils";

var InvoiceTableView = ResultsTableView.extend({
classNames: ['invoice', 'non-interactive'],
templateName: 'results/invoice-table',

getValue: function(field) {
var model = this.get("model");

if (model) {
return model.get(field);
}
return null;
},

fees: function() {
var feesByType = this.get("feesByType");
var self = this;
return feesByType.map(function(fee) {
var rowObject = Ember.Object.create({
type: fee.type,
quantity: Utils.formatNumber(self.getValue(fee.quantity)),
txnAmount: Utils.formatCurrency(self.getValue(fee.txnAmount)),
fee: Utils.safeFormat(fee.fee).htmlSafe(),
totalFee: Utils.formatCurrency(self.getValue(fee.totalFee))
});

if (fee.primary) {
rowObject.set("primary", fee.primary);
rowObject.set("secondary", fee.secondary);
}

return rowObject;
});
}.property(),

feesByType: function() {
if (this.get("model.isDispute")) {
return [{
type: "Dispute",
quantity: "disputes_count",
txnAmount: "disputes_total_amount",
fee: "%@ per dispute".fmt(Utils.formatCurrency(this.get("model.dispute_fixed_fee"))),
totalFee: "disputes_total_fee"
}];
}

return [{
type: "Hold",
quantity: "holds_count",
txnAmount: "holds_total_amount",
fee: "%@ per hold".fmt(Utils.formatCurrency(this.get("model.hold_fee"))),
totalFee: "holds_total_fee"
}, {
primary: "Debit",
secondary: "Cards",
quantity: "card_debits_count",
txnAmount: "card_debits_total_amount",
fee: "%@% of txn + %@".fmt(this.get("model.variable_fee_percentage"), Utils.formatCurrency(this.get("model.card_debit_fixed_fee"))),
totalFee: "card_debits_total_fee"
}, {
primary: "Debit",
secondary: "Bank accounts",
quantity: "bank_account_debits_count",
txnAmount: "bank_account_debits_total_amount",
fee: "%@% of txn + $0.30 (%@ cap)".fmt(this.get("model.bank_account_debit_variable_fee_percentage"), Utils.formatCurrency(this.get("model.bank_account_debit_variable_fee_cap"))),
totalFee: "bank_account_debits_total_fee"
}, {
primary: "Credit",
secondary: "Succeeded",
quantity: "bank_account_credits_total_amount",
txnAmount: "disputes_total_amount",
fee: "%@ per credit".fmt(Utils.formatCurrency(this.get("model.bank_account_credit_fee"))),
totalFee: "bank_account_credits_total_fee"
}, {
primary: "Credit",
secondary: "Push to card",
quantity: "card_credits_count",
txnAmount: "card_credits_total_amount",
fee: "%@ per credit".fmt(Utils.formatCurrency(this.get("model.card_credit_fixed_fee"))),
totalFee: "card_credits_total_fee"
}, {
type: "Refund",
quantity: "refunds_count",
txnAmount: "refunds_total_amount",
fee: "%@% of txn amount returned".fmt(this.get("model.variable_fee_percentage")),
totalFee: "refunds_total_fee"
}];
}.property("model.isDispute")
});

export default InvoiceTableView;

0 comments on commit 6fc3720

Please sign in to comment.