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.86 kB
var d=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var p=(o,t,r,m)=>{for(var s=m>1?void 0:m?O(t,r):t,A=o.length-1,T;A>=0;A--)(T=o[A])&&(s=(m?T(t,r,s):T(s))||s);return m&&s&&d(t,r,s),s};import{plainToInstance as D,Transform as f,Type as N}from"class-transformer";var R=class{constructor(t,r,m,s){this.id="";this.description="";this.quantity=1;this.unit="piece";this.currency="EUR";this.taxRate=0;this.id=t,this.price=r,this.description=s||"",this.unit=m||"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 R{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 E=class{constructor(){this.paymentType="sepa"}};var S={sepa_mandate:E,sepa:E,swift:E,credit_card:E,cash:E};function P(o){return S[o]}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(R,r)))],a.prototype,"items",2);var e=class extends a{constructor(){super(...arguments);this.type="recurring_invoice"}};export{e as RecurringInvoice};