patrimoniumjs
Version:
Patrimonium.js is a JavaScript library providing a set of tools to modelize the real estate operations of an individual and their impact on the financial situation of the same individual.
1 lines • 14.6 kB
JavaScript
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e){var t,n;this.amount=e.amount,this.period=e.period,this.interestRate=e.interestRate,this.insuranceRate=e.insuranceRate,this.bankingFees=null!==(t=e.bankingFees)&&void 0!==t?t:0,this.elapsedMonths=null!==(n=e.elapsedMonths)&&void 0!==n?n:0}return Object.defineProperty(e.prototype,"monthlyPayment",{get:function(){var e,t,n=this.amount,r=(t=((e=this).interestRate+e.insuranceRate)/100,Math.pow(1+t,1/12)-1),o=this.period;return n*r*Math.pow(1+r,o)/(Math.pow(1+r,o)-1)},enumerable:!0,configurable:!0}),e.prototype.getAmountStillToBeRepaid=function(){return this.amount-function(e){for(var t,n=e.period,r=(e.interestRate+e.insuranceRate)/100,o=e.amount,i=0,u=null!==(t=e.elapsedMonths)&&void 0!==t?t:0,s=0;s<u;s++)i+=o*r*Math.pow(1+r/12,s)/(12*(Math.pow(1+r/12,n)-1));return i}(this)},e}();t.Loan=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(11);t.SimpleDate=r.SimpleDate;var o=n(12);t.Person=o.Person;var i=n(0);t.Loan=i.Loan;var u=n(13);t.History=u.History},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3);t.BuyPropertyAction=r.BuyPropertyAction;var o=n(4);t.SignLoanAction=o.SignLoanAction;var i=n(5);t.SellPropertyAction=i.SellPropertyAction;var u=n(6);t.RentPropertyAction=u.RentPropertyAction;var s=n(7);t.LeaveRentalPropertyAction=s.LeaveRentalPropertyAction;var a=n(8);t.MoveInAction=a.MoveInAction;var c=n(9);t.MakePropertyImprovementAction=c.MakePropertyImprovementAction;var p=n(10);t.RentOutPropertyAction=p.RentOutPropertyAction},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){this.date=e,this.purchase=function(e){var t,n,r,o,i,u,s,a,c,p;return{price:null!==(t=null==e?void 0:e.price)&&void 0!==t?t:0,notaryFees:null!==(n=null==e?void 0:e.notaryFees)&&void 0!==n?n:0,recurrentExpenses:{residenceTax:null!==(o=null===(r=null==e?void 0:e.recurrentExpenses)||void 0===r?void 0:r.residenceTax)&&void 0!==o?o:0,propertyTax:null!==(u=null===(i=null==e?void 0:e.recurrentExpenses)||void 0===i?void 0:i.propertyTax)&&void 0!==u?u:0,maintenanceFees:null!==(a=null===(s=null==e?void 0:e.recurrentExpenses)||void 0===s?void 0:s.maintenanceFees)&&void 0!==a?a:0},rent:null!==(c=null==e?void 0:e.rent)&&void 0!==c?c:0,growthRate:null!==(p=null==e?void 0:e.growthRate)&&void 0!==p?p:0}}(t)}return e.prototype.execute=function(e){var t,n,r,o,i,u,s,a,c;e.currentAccount-=this.purchase.price+this.purchase.notaryFees,e.properties.push({purchasePrice:(t=this.purchase).price,currentWorth:t.price,recurrentExpenses:{residenceTax:null!==(r=null===(n=t.recurrentExpenses)||void 0===n?void 0:n.residenceTax)&&void 0!==r?r:0,propertyTax:null!==(i=null===(o=t.recurrentExpenses)||void 0===o?void 0:o.propertyTax)&&void 0!==i?i:0,maintenanceFees:null!==(s=null===(u=t.recurrentExpenses)||void 0===u?void 0:u.maintenanceFees)&&void 0!==s?s:0},rent:null!==(a=t.rent)&&void 0!==a?a:0,state:"empty",growthRate:null!==(c=t.growthRate)&&void 0!==c?c:0})},e}();t.BuyPropertyAction=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),o=function(){function e(e,t){this.date=e,this.options=t,this.date=e}return e.prototype.execute=function(e){var t=new r.Loan(this.options);e.currentAccount+=t.amount-t.bankingFees,e.loans.push(t)},e}();t.SignLoanAction=o},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){void 0===t&&(t=0),this.date=e,this.propertyIdx=t,this.date=e}return e.prototype.execute=function(e){if(e.properties.length<=this.propertyIdx)throw new Error("Property not found with index '"+this.propertyIdx+".'");var t=e.properties[this.propertyIdx].currentWorth;e.currentAccount+=t,e.properties.splice(this.propertyIdx,1)},e}();t.SellPropertyAction=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){this.date=e,this.rental=t,this.date=e}return e.prototype.execute=function(e){var t,n,r;e.rental=(t=this.rental,{price:null!==(n=t.price)&&void 0!==n?n:0,residenceTax:null!==(r=t.residenceTax)&&void 0!==r?r:0})},e}();t.RentPropertyAction=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e){this.date=e,this.date=e}return e.prototype.execute=function(e){e.rental=null},e}();t.LeaveRentalPropertyAction=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){void 0===t&&(t=0),this.date=e,this.propertyIdx=t,this.date=e}return e.prototype.execute=function(e){if(e.properties.length<=this.propertyIdx)throw new Error("Invalid operation: no property with index '"+this.propertyIdx+"'");!function(e){var t=e.properties.findIndex((function(e){return"usedAsPrincipalResidence"===e.state}));t>-1&&(e.properties[t].state="empty")}(e),function(e,t){e.properties[t].state="usedAsPrincipalResidence"}(e,this.propertyIdx)},e}();t.MoveInAction=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t,n,r){void 0===r&&(r=0),this.date=e,this.cost=t,this.addedValue=n,this.propertyIdx=r,this.date=e}return e.prototype.execute=function(e){if(e.properties.length<=this.propertyIdx)throw new Error("Invalid operation: no property with index '"+this.propertyIdx+"'");e.properties[this.propertyIdx].currentWorth+=this.addedValue,e.currentAccount-=this.cost},e}();t.MakePropertyImprovementAction=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){void 0===t&&(t=0),this.date=e,this.propertyIdx=t}return e.prototype.execute=function(e){if(e.properties.length<=this.propertyIdx)throw new Error("Property not found with index '"+this.propertyIdx+".'");if(!e.properties[this.propertyIdx].rent)throw new Error("Unable to rent out property with index '"+this.propertyIdx+"': the rent of the property has not been defined.");e.properties[this.propertyIdx].state="rented"},e}();t.RentOutPropertyAction=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e){var t;this.options={nthMonth:null!==(t=null==e?void 0:e.nthMonth)&&void 0!==t?t:0}}return e.prototype.getMonths=function(){return this.options.nthMonth},e.prototype.addMonths=function(t){var n=new e(this.options);return n.options.nthMonth+=t,n},e.prototype.getDatesFromOrigin=function(){for(var t=[],n=new e({nthMonth:0});n.getMonths()<this.getMonths();)t.push(n),n=n.addMonths(1);return t},e}();t.SimpleDate=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),o=n(1),i=function(){function e(e){this._actions=[],this._initialSituation=s(e)}return e.prototype.getHistory=function(e){var t=[],n=s(this._initialSituation);t.push({balanceSheet:p(n),plStatement:{income:{salaries:[],investementReturn:0,rentalIncome:[]},expenses:{rent:0,tax:0,other:0,loans:[],realEstate:{tax:0,fees:0}},netProfit:0}});var r=0,i=this._actions.slice().sort((function(e,t){return e.date.getMonths()-t.date.getMonths()}));return(e=a(e)).getDatesFromOrigin().forEach((function(e){for(var o={income:{salaries:[],investementReturn:0,rentalIncome:[]},expenses:{rent:0,tax:0,other:0,loans:[],realEstate:{tax:0,fees:0}},netProfit:0};i.length>r&&i[r].date.getMonths()===e.getMonths();)i[r].execute(n,o),r++;!function(e,t,n){(function(e){e.properties=e.properties.map((function(e){var t=u(e.growthRate);return e.currentWorth*=1+t,e}))})(e),function(e,t){if(!e.environment.investmentRateOfReturn)return;var n=u(e.environment.investmentRateOfReturn/100),r=e.currentAccount*n;e.currentAccount+=r,t.income.investementReturn=r}(e,t),function(e,t,n){var r=Math.floor(n.getMonths()/12),o=e.employments.reduce((function(e,t){return e+t.salary(r)}),0),i=e.employments.map((function(e){return{amount:e.salary(r),status:e.status}}));t.income.salaries=e.employments.map((function(e){return e.salary(r)/12}));var u=e.properties.filter((function(e){return"rented"===e.state})),s=12*u.reduce((function(e,t){return e+t.rent}),0);t.income.rentalIncome=u.map((function(e){return e.rent}));var a=o+s,c=e.environment.netIncomeCalculation?e.environment.netIncomeCalculation(i,e.properties):a;t.expenses.tax=(a-c)/12,e.currentAccount+=c/12}(e,t,n),function(e,t){e.properties.forEach((function(n){var r=n.recurrentExpenses.propertyTax/12;e.currentAccount-=r,t.expenses.realEstate.tax+=r}))}(e,t),function(e,t){if(!e.rental)return;e.currentAccount-=e.rental.price,t.expenses.rent=e.rental.price}(e,t),function(e,t){var n,r;if(e.rental){var o=e.rental.residenceTax/12;return e.currentAccount-=o,void(t.expenses.realEstate.tax+=o)}var i=null!==(r=null===(n=e.properties.find((function(e){return"usedAsPrincipalResidence"===e.state})))||void 0===n?void 0:n.recurrentExpenses.residenceTax)&&void 0!==r?r:0;e.currentAccount-=i/12,t.expenses.realEstate.tax+=i/12}(e,t),function(e,t){e.loans=e.loans.filter((function(e){return e.elapsedMonths!==e.period})).map((function(n){return e.currentAccount-=n.monthlyPayment,t.expenses.loans.push(n.monthlyPayment),n.elapsedMonths++,n}))}(e,t),function(e,t){e.properties.forEach((function(n){var r=n.recurrentExpenses.maintenanceFees/12;e.currentAccount-=r,t.expenses.realEstate.fees+=r}))}(e,t),function(e,t,n){var r=e.expenses(a(n));e.currentAccount-=r,t.expenses.other=r}(e,t,n)}(n,o,e),o.netProfit=function(e){var t=e.income.salaries.reduce((function(e,t){return e+t}),0)+e.income.rentalIncome.reduce((function(e,t){return e+t}),0)+e.income.investementReturn,n=e.expenses.tax+e.expenses.rent+e.expenses.other+e.expenses.loans.reduce((function(e,t){return e+t}),0)+e.expenses.realEstate.fees+e.expenses.realEstate.tax;return t-n}(o),t.push({balanceSheet:p(n),plStatement:o})})),new o.History(t)},e.prototype.buyProperty=function(e,t){var n=new r.BuyPropertyAction(a(e),t);this._actions.push(n)},e.prototype.signLoan=function(e,t){var n=new r.SignLoanAction(a(e),t);this._actions.push(n)},e.prototype.sellProperty=function(e,t){var n,o=new r.SellPropertyAction(a(e),null!==(n=null==t?void 0:t.propertyIdx)&&void 0!==n?n:void 0);this._actions.push(o)},e.prototype.rentProperty=function(e,t){var n=new r.RentPropertyAction(a(e),t);this._actions.push(n)},e.prototype.leaveRentalProperty=function(e){var t=new r.LeaveRentalPropertyAction(a(e));this._actions.push(t)},e.prototype.moveIn=function(e,t){var n,o=new r.MoveInAction(a(e),null!==(n=null==t?void 0:t.propertyIdx)&&void 0!==n?n:void 0);this._actions.push(o)},e.prototype.makePropertyImprovement=function(e,t){var n=new r.MakePropertyImprovementAction(a(e),t.cost,t.addedValue,t.propertyIdx);this._actions.push(n)},e.prototype.rentOutProperty=function(e,t){var n,o=new r.RentOutPropertyAction(a(e),null!==(n=null==t?void 0:t.propertyIdx)&&void 0!==n?n:void 0);this._actions.push(o)},e}();function u(e){return Math.pow(1+e,1/12)-1}function s(e){var t,n,r,i,u,s,a,p,l,d,v;return{properties:null!==(n=null===(t=null==e?void 0:e.properties)||void 0===t?void 0:t.map((function(e){return{purchasePrice:(t=e).purchasePrice,currentWorth:t.currentWorth,recurrentExpenses:{propertyTax:t.recurrentExpenses.propertyTax,residenceTax:t.recurrentExpenses.residenceTax,maintenanceFees:t.recurrentExpenses.maintenanceFees},rent:t.rent,state:t.state,growthRate:t.growthRate};var t})))&&void 0!==n?n:[],loans:null!==(i=null===(r=null==e?void 0:e.loans)||void 0===r?void 0:r.slice().map((function(e){return t=e,new o.Loan({amount:t.amount,period:t.period,interestRate:t.interestRate,insuranceRate:t.insuranceRate,bankingFees:t.bankingFees,elapsedMonths:t.elapsedMonths});var t})))&&void 0!==i?i:[],currentAccount:null!==(u=null==e?void 0:e.currentAccount)&&void 0!==u?u:0,environment:{investmentRateOfReturn:null!==(a=null===(s=null==e?void 0:e.environment)||void 0===s?void 0:s.investmentRateOfReturn)&&void 0!==a?a:0,netIncomeCalculation:null===(p=null==e?void 0:e.environment)||void 0===p?void 0:p.netIncomeCalculation},rental:(null==e?void 0:e.rental)?c(e.rental):null,employments:null!==(d=null===(l=null==e?void 0:e.employments)||void 0===l?void 0:l.map((function(e){return function(e){var t;return{salary:null!==(t=e.salary)&&void 0!==t?t:function(e){return 0},status:e.status}}(e)})))&&void 0!==d?d:[],expenses:null!==(v=null==e?void 0:e.expenses)&&void 0!==v?v:function(){return 0}}}function a(e){return new o.SimpleDate({nthMonth:e.getMonths()})}function c(e){var t,n;return{price:null!==(t=e.price)&&void 0!==t?t:0,residenceTax:null!==(n=e.residenceTax)&&void 0!==n?n:0}}function p(e){var t,n,r={assets:{currentAccount:e.currentAccount,properties:null!==(t=e.properties.map((function(e){return e.currentWorth})))&&void 0!==t?t:[]},liabilities:{loan:null!==(n=e.loans.reduce((function(e,t){return e+t.getAmountStillToBeRepaid()}),0))&&void 0!==n?n:0},netWorth:0};return r.netWorth=r.assets.currentAccount+r.assets.properties.reduce((function(e,t){return e+t}),0)-r.liabilities.loan,r}t.Person=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(14);t.History=r.History},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e){this._reporting=e}return e.prototype.getReporting=function(e){return this._reporting[e.getMonths()]},e.prototype.toArray=function(){return this._reporting},e}();t.History=r}])}));