Skip to content

Commit

Permalink
Order PDF Formatting updates
Browse files Browse the repository at this point in the history
Issues #307
  • Loading branch information
aaronjudd committed Feb 2, 2015
1 parent 088d2ee commit c2d34ae
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 23 deletions.
17 changes: 7 additions & 10 deletions packages/reaction-core/client/helpers/helpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,15 @@ currentProduct = @currentProduct
# save an order as PDF
###
@saveOrderAsPDF = (order) ->
Blaze.saveAsPDF Template.completedOrderDetails,
Blaze.saveAsPDF Template.completedPDFLayout,
data: order
filename: "order-" + order._id + ".pdf" #TODO should be configurable by admin
orientation: "portrait" #TODO should be configurable by admin
format: "letter" #TODO should be configurable by admin
unit: "cm"
# NOTE specifying margins seem to make formatting wonky, likely jsPDF issue
#margins:
# left: 2.5
# right: 2.5
# top: 1
# bottom: 1
margins:
top: 80,
bottom: 60,
left: 40,
width: 522

return

###
Expand Down
2 changes: 1 addition & 1 deletion packages/reaction-core/client/helpers/i18n/i18n.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Template.registerHelper "formatPrice", (price) ->
price = price.replace(originalPrice, formattedPrice)
catch
if ReactionCore.Locale?.currency?.exchangeRate then price = price * ReactionCore.Locale?.currency?.exchangeRate.Rate
price = accounting.formatMoney price, ReactionCore.Locale?.currency
price = accounting?.formatMoney price, ReactionCore.Locale?.currency

return price

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ <h1>
<span data-i18n="cartCompleted.thankYou">Thank you.</span>
<small><span data-i18n="cartCompleted.yourOrderHasBeen">Your order has been</span> {{orderStatus}}.</small>
</h1>
{{> completedOrderDetails}}
{{> completedOrderLayout}}
</template>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template name="completedOrderDetails">
<template name="completedOrderLayout">
<div class="row">
<div class="col-md-4">
<div class="panel panel-default">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
###
# Template for orders pdf layout, uses jsPDF with
# very limited html support.
# jsPDF docs state: "HTML Element, or anything supported by html2canvas"
# see: http://mrrio.github.io/jsPDF/examples/basic.html
###

Template.completedPDFLayout.inheritsHelpersFrom "completedOrderLayout"
Template.completedPDFLayout.inheritsEventsFrom "completedOrderLayout"
Template.completedPDFLayout.helpers
invoice: () ->
return @.payment.invoices[0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template name="completedPDFLayout">
<header>
<div style="font-family:monospace; font-size: 1.5em">{{> headerBrand}}</div>
<div style="font-family:monospace; margin-top: 1em">ORDER: {{_id}}</div>
<div style="margin-left: 10em; font-family:monospace; text-align: right;">
DATE: {{dateFormat createdAt format="MM/D/YY"}}
</div>
</header>
<h2 style='margin-top:2em'>SHIP VIA {{shipping.shipmentMethod.method.label}} TO</h2>
{{#with shipping.address}}
<div style='margin-left:10em'>{{fullName}}</div>
<div style='margin-left:10em'>{{address1}}</div>
<div style='margin-left:10em'>{{#if address2}}{{address2}},{{/if}}</div>
<div style='margin-left:10em'>{{city}}, {{region}} {{postal}} {{country}}</div>
<div style='margin-left:10em'>{{phone}}</div>
{{/with}}


<h2 style='margin-top:2em'>BILL TO</h2>
{{#with payment.address}}
<div style='margin-left:10em'>{{fullName}}</div>
<div style='margin-left:10em'>{{address1}}</div>
<div style='margin-left:10em'>{{#if address2}}{{address2}},{{/if}}</div>
<div style='margin-left:10em'>{{city}}, {{region}} {{postal}} {{country}}</div>
<div style='margin-left:10em'>{{phone}}</div>
<div></div>
{{/with}}
{{#each payment.paymentMethod}}
<div style='margin-left:10em; margin-top:1em'>{{storedCard}}</div>
<div style='margin-left:10em'>Ref: {{transactionId}}</div>
{{/each}}

<h2 style='margin-top:2em'>ORDER ITEMS</h2>
<ul>
{{#each items}}
<li><h3>{{quantity}} {{variants.title}} {{variants.price}}</h3></li>
{{/each}}
</ul>


<h2 style='margin-top:2em'>ORDER SUMMARY</h2>
{{#with invoice}}
<div style='margin-left:10em' data-i18n='cartSubTotals.subtotal'>Sub total <span style='margin-left:10em'> {{subtotal}}</span></div>
<div style='margin-left:10em' data-i18n='cartSubTotals.shipping'>Shipping <span style='margin-left:10em'> {{shipping}}</span></div>
<div style='margin-left:10em' data-i18n='cartSubTotals.tax'>Tax <span>{{taxes}}</span></div>
<div style='margin-left:10em' data-i18n='cartSubTotals.discount'>Discount <span>{{discounts}}</span></div>
<div style='margin-left:10em' data-i18n='cartSubTotals.total'>Total <span style="margin-left:5em">{{total}}</span></div>
{{/with}}


<div style='margin-top: 2em' data-i18n="cartCompleted.summaryMessage">Thank you for your order.</div>

</template>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
{{#each documents}}
<a href="{{url}}" target="_blank" class="btn btn-success">Download</a>
{{/each}}
<button type="button" class="btn btn-success save-order-pdf">Download As PDF</button>
<button type="button" class="btn btn-success save-order-pdf" data-i18n="app.download">Download PDF</button>
</span>
</template>
18 changes: 9 additions & 9 deletions packages/reaction-core/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ Package.onUse(function (api) {
"lib/jquery-serialize/jquery.serialize-hash.coffee",
"lib/jquery-cookie/jquery.cookie.js",

"lib/openexchangerates/money.js",
"lib/openexchangerates/accounting.js",

"client/subscriptions.coffee",
"client/app.coffee",

Expand Down Expand Up @@ -260,14 +257,17 @@ Package.onUse(function (api) {
"client/templates/cart/checkout/completed/completed.html",
"client/templates/cart/checkout/completed/completed.coffee",

"client/templates/cart/checkout/completed/orderDetails/orderDetails.html",
"client/templates/cart/checkout/completed/orderDetails/orderDetails.coffee",
"client/templates/cart/checkout/completed/orderLayout/orderLayout.html",
"client/templates/cart/checkout/completed/orderLayout/orderLayout.coffee",

"client/templates/cart/checkout/completed/orderLayout/orderItems/orderItems.html",
"client/templates/cart/checkout/completed/orderLayout/orderItems/orderItems.coffee",

"client/templates/cart/checkout/completed/orderItems/orderItems.html",
"client/templates/cart/checkout/completed/orderItems/orderItems.coffee",
"client/templates/cart/checkout/completed/orderLayout/orderSummary/orderSummary.html",
"client/templates/cart/checkout/completed/orderLayout/orderSummary/orderSummary.coffee",

"client/templates/cart/checkout/completed/orderSummary/orderSummary.html",
"client/templates/cart/checkout/completed/orderSummary/orderSummary.coffee",
"client/templates/cart/checkout/completed/pdfLayout/pdfLayout.html",
"client/templates/cart/checkout/completed/pdfLayout/pdfLayout.coffee",

"client/templates/cart/checkout/shipping/shipping.html",
"client/templates/cart/checkout/shipping/shipping.coffee",
Expand Down

0 comments on commit c2d34ae

Please sign in to comment.