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 e=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var p=(s,t,r,a)=>{for(var o=a>1?void 0:a?O(t,r):t,A=s.length-1,T;A>=0;A--)(T=s[A])&&(o=(a?T(t,r,o):T(o))||o);return a&&o&&e(t,r,o),o};import{plainToInstance as D,Transform as f,Type as N}from"class-transformer";var i=class{constructor(t,r,a,o){this.id="";this.description="";this.quantity=1;this.unit="piece";this.currency="EUR";this.taxRate=0;this.id=t,this.price=r,this.description=o||"",this.unit=a||"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,m.prototype)}};var m=class extends i{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(s){return S[s]}var R=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)],R.prototype,"createdAt",2),p([N(()=>Date)],R.prototype,"servicePeriod",2),p([f(({value:t})=>D(P(t.paymentType),t))],R.prototype,"paymentInformation",2),p([f(({value:t})=>t.map(r=>"discount"in r?D(m,r):D(i,r)))],R.prototype,"items",2);var d=class extends R{constructor(){super(...arguments);this.type="partial_invoice"}};export{d as PartialInvoice};