theduke

0.2.1 • Public • Published

Template

Naming convention

_duke/

  • Data and templates live here

MYC123 ABC-RAQ13232 My Job

  • MYC123 job.num (prefixed by client.code)
  • ABC super.client.code (optional)
  • RAQ1323 super.job.num (optional)
  • My Job Job name

inv-1.xls

  • inv is the template to use
  • 1 is the part (1,2,3 etc)

Entities

config

tax: gst: 0.1 (tax rate as percentage, required)

global

global

  • today

job

job num (pulled from job folder, 3 letter int prefixed by client.code, eg. MFC001) name: My Job (pulled from job dir) total: ex (subtotal ex GST) gst (GST component) inc (total inc GST)

super.job

Client's client's job

super.job num: (Can be any coding convention)

*inv

Invoice specific content

inv num: MYC001-1 part: 1 time_based: true / false auto_summary (Will attempt to summarise the job) data: (internal info about invoice data excel doc) total (optional) min ex (in cents, int) gst (in cents, int) inc (in cents, int) sections: (required array) section (Each invoice consists of one or more sections) title (optional) desc (optional) ex (in cents, int) gst (in cents, int) inc (in cents, int) subs (optional array) sub desc hrs (optional) cost (optional) ex (in cents, int) gst (in cents, int) inc (in cents, int)

client code: mfc (set by filename) company: fullname: My Full Company Name (optional) nickname: Company (optional) abn: 1234567890 (optional) contact: fullname: Barry White (one or the other required) nickname: Bazza (one or the other required) phone: 0412 123 123 (optional) address: line_1: 21 Jump Street line_2: Toowong, QLD 4000 terms: (optional, will override me.terms.rate) rate: 10 (hourly rate ex GST, optional, will override me.terms.rate)

super.client

Same as client, though indicates client's client,

super.client fullname: My Full Company Name (optional) nickname: Company (optional)

me

As client above though with additional fields

bank: name: My Bank Name account: My Bank Account Name bsb: 123-456 account_number: 12-123-123 terms: rate: 10 (hourly rate ex GST, required)

Logic

Optionals

If prop exists will return value, otherwise will return an empty string. %client.contact.nickname?

Optional chains

If first choice is set, will attempt 2nd, 3rd etc. Separated by ??. %client.contact.nickname??client.contact.fullname%

Logic props

%!inv.timebased% Bool only supported for now.

Ternary conditions

Eg. %inv.time_based?inv.total.mins(minsToHrs):inv.total.ex(currency)%

The conditional subject can be an expression, supporting option chains and filters.

Conditional blocks

%if inv.time_based%
Hrs: %inv.total.mins(minsToHrs)%
%else%
Cost: %inv.total.ex(currency)%
%/if%

Conditional optionals

If last char is ? then the result is a bool of whether expression is defined or undefined

%if nosuchprop?%
Prop doesn't exist
%else%
Prop exists
%/if%

Loops

%each inv.arrays as item%

Arry item value is %item%

%/each%
%each inv.arrays as index,item%

Item[%index%] = %item%

%/each%
%each inv.obj as propValue%

- %propValue%

%/each%
%each inv.obj as propName,propValue%

Obj.%propName% is %propValue%

%/each%

Literals

  • Strings, eg 'foo', NOTE: Double quotes not supported.
  • Numbers and numeric expressions, eg -1232132, 123213.2323, 100, 123/4*3` (Brackets not supported);
  • Bools, eg true, false

Eg. %inv.time_based?'YAY':'NAY'%

Relational operators

Supported operators ==,!=,>,>=,<``<=

Filters

Appear as brackets after template entity. Note: camel case

Eg %me.contact.fullname(slugify,nbsp)??global.today(display)%

str

slugify

  • Lowercase, replace spacing with hyphens.

hyphenate

  • Replace spaces with hyphens, leave case as is.

nbsp

  • Replace spaces with &nbsp; HTML

phoneAuHref

  • Eg. 0412 123 123 to +6412123123

int

currency

  • Covert cents to dollars (x100), round to 2 decimal places, add thousand commas. Note: no dollar sign will be added

$currency

  • Same as currency though will add a dollar sign

minsToHrs

  • For display, convert mins int to hours float with 2 decimal places, including hrs suffix.

date

display

  • Eg. 01.12.2017

filename

  • Eg. 2017-12-01

HTML tips

Use below to control page breaks:

page-break-inside: avoid !important;

Add a new section with the title (col #1) as simply --- to insert a linebreak.

Version History

  • 0.2.1 Add PO column above summary for it to be added to invoice header
  • 0.2.0 Will reject jobs with placeholder number 999
  • 0.1.8 Updated page break (---) to ignore line breaks.
  • 0.1.7 Page break code added (---), line break code added (\n)
  • 0.1.5 Direct PDF publishing
  • 0.1.4 Fixed hrs filter, excel doc defines template, multi-line description support added
  • 0.1.3 Added node env
  • 0.1.2 Added README

Readme

Keywords

none

Package Sidebar

Install

npm i theduke

Weekly Downloads

12

Version

0.2.1

License

MIT

Unpacked Size

30.9 MB

Total Files

48

Last publish

Collaborators

  • loksland