@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.77 kB
JavaScript
var S=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var T=(E,t,s,R)=>{for(var r=R>1?void 0:R?N(t,s):t,A=E.length-1,i;A>=0;A--)(i=E[A])&&(r=(R?i(t,s,r):i(r))||r);return R&&r&&S(t,s,r),r};import{plainToInstance as D,Transform as f,Type as d}from"class-transformer";var a=class{constructor(t,s,R,r){this.id="";this.description="";this.quantity=1;this.unit="piece";this.currency="EUR";this.taxRate=0;this.id=t,this.price=s,this.description=r||"",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,s){Object.assign(this,{discount:t,discountType:s}),Object.setPrototypeOf(this,m.prototype)}};var m=class extends a{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 O={sepa_mandate:o,sepa:o,swift:o,credit_card:o,cash:o};function P(E){return O[E]}var p=class{constructor(t,s){this.createdAt=new Date;this.items=[];this.id=t,this.servicePeriod=s}get netPriceSum(){return this.items.reduce((t,s)=>t+s.netPrice,0)}get taxSum(){return this.items.reduce((t,s)=>t+s.tax,0)}get grossPriceSum(){return this.items.reduce((t,s)=>t+s.grossPrice,0)}};T([d(()=>Date)],p.prototype,"createdAt",2),T([d(()=>Date)],p.prototype,"servicePeriod",2),T([f(({value:t})=>D(P(t.paymentType),t))],p.prototype,"paymentInformation",2),T([f(({value:t})=>t.map(s=>"discount"in s?D(m,s):D(a,s)))],p.prototype,"items",2);export{p as BaseInvoice};