UNPKG

@inbridge/oif-ts

Version:

TypeScript integration for the Open Invoice Format (OIF) schema. Easily create OIF-compliant PDFs and parse/validate JSON.

2 lines (1 loc) 1.85 kB
var O=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var p=(s,t,r,R)=>{for(var E=R>1?void 0:R?S(t,r):t,A=s.length-1,T;A>=0;A--)(T=s[A])&&(E=(R?T(t,r,E):T(E))||E);return R&&E&&O(t,r,E),E};import{plainToInstance as D,Transform as f,Type as N}from"class-transformer";var m=class{constructor(t,r,R,E){this.id="";this.description="";this.quantity=1;this.unit="piece";this.currency="EUR";this.taxRate=0;this.id=t,this.price=r,this.description=E||"",this.unit=R||"piece"}get netPrice(){return this.price*this.quantity}get tax(){return this.netPrice*(this.taxRate/100)}get grossPrice(){return this.netPrice+this.tax}addDiscount(t,r){Object.assign(this,{discount:t,discountType:r}),Object.setPrototypeOf(this,i.prototype)}};var i=class extends m{constructor(){super(...arguments);this.discount=0;this.discountType="fixed";this.discountReason=""}get discountAmount(){return this.discountType==="percentage"?this.price*this.quantity*(this.discount/100):this.discount}get netPrice(){return this.price*this.quantity-this.discountAmount}};import"reflect-metadata";var o=class{constructor(){this.paymentType="sepa"}};var e={sepa_mandate:o,sepa:o,swift:o,credit_card:o,cash:o};function P(s){return e[s]}var a=class{constructor(t,r){this.createdAt=new Date;this.items=[];this.id=t,this.servicePeriod=r}get netPriceSum(){return this.items.reduce((t,r)=>t+r.netPrice,0)}get taxSum(){return this.items.reduce((t,r)=>t+r.tax,0)}get grossPriceSum(){return this.items.reduce((t,r)=>t+r.grossPrice,0)}};p([N(()=>Date)],a.prototype,"createdAt",2),p([N(()=>Date)],a.prototype,"servicePeriod",2),p([f(({value:t})=>D(P(t.paymentType),t))],a.prototype,"paymentInformation",2),p([f(({value:t})=>t.map(r=>"discount"in r?D(i,r):D(m,r)))],a.prototype,"items",2);var d=class extends a{constructor(){super(...arguments);this.type="invoice"}};export{d as DefaultInvoice};