Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ardean committed Feb 24, 2016
0 parents commit 85fd981
Show file tree
Hide file tree
Showing 10 changed files with 634 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
Thumbs.db
node_modules
npm-debug.log
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Orbin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# pdf-reminder-simple
A simple pdf reminder template

Example:

```javascript
import simpleReminder from "pdf-reminder-simple";

simpleReminder(invoice, reminder, profile).open();
```
30 changes: 30 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>

<head>
<title>Simple reminder pdf</title>
<meta charset="utf-8" />
<style>
html,
body,
iframe {
height: 100%;
width: 100%;
overflow: hidden;
}

body {
margin: 0;
}

iframe {
border: 0;
}
</style>
</head>

<body>
<iframe></iframe>
</body>

</html>
55 changes: 55 additions & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import $ from "jquery";
import moment from "moment";
import simpleReminder from "../src";

const invoice = {
contactName: "Mein Kontakt",
number: 12,
date: moment(),
dueDate: moment(),
billingAddress: {
street: "Strasse 2",
postCode: "78556",
city: "Andere Stadt"
},
itemDetails: [{
name: "Item Name",
quantity: 2,
rate: 200,
total: 400
}],
subTotal: 400,
taxGroups: [{
name: "Mehrwertsteuer",
amount: 10
}],
adjustment: 20,
total: 430,
currencyId: "EUR"
};

const reminder = {
typeName: "1. Mahnung",
note: "Sie haben die Rechnung nicht bezahlt!",
feeAmount: 10,
creationDate: moment()
};

const profile = {
organizationSettings: {
name: "Orbin",
address: {
street: "Strasse 333",
postCode: "3474",
city: "Stadt"
}
},
invoiceSettings: {
note: "Meine Notiz"
}
};

const pdf = simpleReminder(invoice, reminder, profile);
pdf.getBase64((data) => {
$("iframe").attr("src", `data:application/pdf;base64,${data}`);
});
240 changes: 240 additions & 0 deletions dist/pdf-reminder-simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("roboto-base64"), require("pdfmake/build/pdfmake"));
else if(typeof define === 'function' && define.amd)
define(["roboto-base64", "pdfmake/build/pdfmake"], factory);
else {
var a = typeof exports === 'object' ? factory(require("roboto-base64"), require("pdfmake/build/pdfmake")) : factory(root["roboto-base64"], root["pdfmake/build/pdfmake"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _robotoBase = __webpack_require__(1);

var _robotoBase2 = _interopRequireDefault(_robotoBase);

var _pdfmake = __webpack_require__(2);

var _pdfmake2 = _interopRequireDefault(_pdfmake);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

window.pdfMake = {
vfs: _robotoBase2.default
};

var defaultStyle = {
fontSize: 10
};

var tableLayout = {
hLineWidth: function hLineWidth(i) {
return i === 1 ? 1 : 0;
},
vLineWidth: function vLineWidth() {
return 0;
},
paddingLeft: function paddingLeft() {
return 0;
},
paddingRight: function paddingRight() {
return 0;
},
paddingTop: function paddingTop(i) {
return i === 1 ? 15 : 5;
},
paddingBottom: function paddingBottom() {
return 5;
}
};

var footerLayout = {
hLineWidth: function hLineWidth(i, node) {
return i === 0 || i === node.table.body.length || i === node.table.body.length - 1 ? 1 : 0;
},
vLineWidth: function vLineWidth() {
return 0;
},
paddingLeft: function paddingLeft() {
return 0;
},
paddingRight: function paddingRight() {
return 0;
},
paddingTop: function paddingTop(i, node) {
return i === 0 || i === node.table.body.length - 1 ? 10 : 5;
},
paddingBottom: function paddingBottom(i, node) {
return i === node.table.body.length - 1 || i === node.table.body.length - 2 ? 10 : 5;
}
};

exports.default = function (invoice, reminder, profile) {
return _pdfmake2.default.createPdf(getDoc(invoice, reminder, profile));
};

function getDoc(invoice, reminder, profile) {
var organizationSettings = profile.organizationSettings;
var address = organizationSettings.address;
var billingAddress = invoice.billingAddress;
var totalAmount = invoice.total + reminder.feeAmount;

var doc = {
defaultStyle: defaultStyle,
content: [{
text: returnAddressText({
name: organizationSettings.name,
street: address.street,
postCode: address.postCode,
city: address.city
}),
margin: [0, 120, 0, 0],
fontSize: 8,
color: "gray"
}, {
margin: [0, 10, 0, 0],
layout: "noBorders",
table: {
widths: ["auto", "*", "auto", "auto"],
body: [[invoice.contactName || "", "", "Datum:", {
text: reminder.creationDate.format("DD.MM.YYYY"),
alignment: "right"
}], [billingAddress.street || "", "", "", ""], [(billingAddress.postCode || "") + " " + (billingAddress.city || ""), "", "", ""]]
}
}, {
fontSize: 18,
text: reminder.typeName,
margin: [0, 50, 0, 0]
}, {
margin: [0, 25, 0, 0],
text: reminder.note || ""
}, {
margin: [0, 25, 0, 0],
layout: tableLayout,
table: {
headerRows: 1,
widths: ["*", "auto"],
body: [["Beschreibung", {
text: "Betrag",
alignment: "right"
}]]
}
}]
};

doc.content[4].table.body.push([{
stack: ["Rechnung", {
margin: [0, 2, 0, 0],
text: invoice.date.format("DD.MM.YYYY"),
color: "gray"
}]
}, {
text: invoice.total.toFixed(2),
alignment: "right"
}]);

if (reminder.feeAmount) {
doc.content[4].table.body.push(["Gebühr", {
text: reminder.feeAmount.toFixed(2),
alignment: "right"
}]);
}

doc.content.push({
margin: [0, 25, 0, 0],
layout: footerLayout,
table: {
headerRows: 1,
widths: ["*", "auto"],
body: [["Gesamtsumme " + (invoice.currencyId || "CHF"), {
text: totalAmount.toFixed(2),
alignment: "right"
}]]
}
});

doc.content.push({
text: profile.invoiceSettings.note || "",
margin: [0, 20, 0, 0],
color: "gray",
fontSize: 8
});

return doc;
}

function returnAddressText(address) {
var location = [address.postCode, address.city].join(" ").trim();

return [address.name, address.street, location].filter(function (value) {
return value;
}).join(", ");
}

/***/ },
/* 1 */
/***/ function(module, exports) {

module.exports = __WEBPACK_EXTERNAL_MODULE_1__;

/***/ },
/* 2 */
/***/ function(module, exports) {

module.exports = __WEBPACK_EXTERNAL_MODULE_2__;

/***/ }
/******/ ])
});
;
Loading

0 comments on commit 85fd981

Please sign in to comment.