Files
firefly-iii/public/build/assets/edit-9f80420b.js
2024-01-06 17:24:54 +01:00

2 lines
6.5 KiB
JavaScript

import{d as h,f as l,g as p,l as m}from"./get-c53daca3.js";import{f,l as _,I as y}from"./vendor-4332182f.js";import{G as b}from"./get-c2292133.js";import{e as w,f as r,g as v,s as A,h as S,i as C,l as P,a as D,b as x,c as L,j as k,k as c,m as u}from"./autocomplete-functions-31caaca5.js";function B(e){let o=[];for(let i in e)if(e.hasOwnProperty(i)){let t=e[i],n=w();n.bill_id=t.bill_id,n.budget_id=t.budget_id,n.category_name=t.category_name,n.piggy_bank_id=t.piggy_bank_id,n.book_date=t.book_date,n.due_date=t.due_date,n.interest_date=t.interest_date,n.invoice_date=t.invoice_date,n.payment_date=t.payment_date,n.process_date=t.process_date,n.external_url=t.external_url,n.internal_reference=t.internal_reference,n.notes=t.notes,n.tags=t.tags,n.amount=parseFloat(t.amount).toFixed(t.currency_decimal_places),n.currency_code=t.currency_code,t.foreign_amount!==null&&(n.forein_currency_code=t.foreign_currency_code,n.foreign_amount=parseFloat(t.foreign_amount).toFixed(t.foreign_currency_decimal_places)),n.date=f(new Date(t.date),"yyyy-MM-dd HH:mm"),n.description=t.description,n.destination_account={id:t.destination_id,name:t.destination_name,type:t.destination_type,alpine_name:t.destination_name},n.source_account={id:t.source_id,name:t.source_name,type:t.source_type,alpine_name:t.source_name},t.latitude!==null&&(n.hasLocation=!0,n.latitude=t.latitude,n.longitude=t.longitude,n.zoomLevel=t.zoom_level),console.log(n.tags),o.push(n)}return o}let s;const a=k();let E=function(){return{entries:[],formStates:{loadingCurrencies:!0,loadingBudgets:!0,loadingPiggyBanks:!0,loadingSubscriptions:!0,isSubmitting:!1,returnHereButton:!1,saveAsNewButton:!1,resetButton:!0,rulesButton:!0,webhooksButton:!0},formBehaviour:{formType:"edit",foreignCurrencyEnabled:!0},formData:{defaultCurrency:null,enabledCurrencies:[],nativeCurrencies:[],foreignCurrencies:[],budgets:[],piggyBanks:[],subscriptions:[]},groupProperties:{transactionType:"unknown",title:null,id:null,totalAmount:0},notifications:{error:{show:!1,text:"",url:""},success:{show:!1,text:"",url:""},wait:{show:!1,text:""}},filters:{source:[],destination:[]},addedSplit(){setTimeout(()=>{const e=function(o,i,t){return o.name_with_balance+'<br><small class="text-muted">'+s.t("firefly.account_type_"+o.type)+"</small>"};r({selector:"input.ac-source",serverUrl:a.account,filters:this.filters.source,onRenderItem:e,onChange:v,onSelectItem:A}),console.log("ok"),console.log(this.entries[0].source_account.alpine_name),r({selector:"input.ac-dest",serverUrl:a.account,filters:this.filters.destination,onRenderItem:e,onChange:S,onSelectItem:C}),r({selector:"input.ac-category",serverUrl:a.category,valueField:"id",labelField:"name",onChange:c,onSelectItem:c}),r({selector:"input.ac-description",serverUrl:a.description,valueField:"id",labelField:"description",onChange:u,onSelectItem:u})},250)},changedDateTime(e){console.warn("changedDateTime, event is not used")},changedDescription(e){console.warn("changedDescription, event is not used")},changedDestinationAccount(e){console.warn("changedDestinationAccount, event is not used")},changedSourceAccount(e){console.warn("changedSourceAccount, event is not used")},formattedTotalAmount(){return this.entries.length===0?l(this.groupProperties.totalAmount,"EUR"):l(this.groupProperties.totalAmount,this.entries[0].currency_code??"EUR")},getTags(e){return console.log("at get tags "+e),console.log(this.entries[e].tags),this.entries[e].tags??[]},getTransactionGroup(){this.entries=[];const e=window.location.href.split("/"),o=parseInt(e[e.length-1]);new b().show(o,{}).then(t=>{const n=t.data.data;this.groupProperties.id=parseInt(n.id),this.groupProperties.transactionType=n.attributes.transactions[0].type,this.groupProperties.title=n.attributes.title??n.attributes.transactions[0].description,this.entries=B(n.attributes.transactions),this.notifications.wait.show=!1}).then(()=>{this.groupProperties.totalAmount=0;for(let t in this.entries)this.entries.hasOwnProperty(t)&&(this.groupProperties.totalAmount=this.groupProperties.totalAmount+parseFloat(this.entries[t].amount),this.filters.source.push(this.entries[t].source_account.type),this.filters.destination.push(this.entries[t].source_account.type));console.log(this.filters),setTimeout(()=>{_.init("select.ac-tags",{allowClear:!0,server:a.tag,liveServer:!0,clearEnd:!0,allowNew:!0,notFoundMessage:s.t("firefly.nothing_found"),noCache:!0,fetchOptions:{headers:{"X-CSRF-TOKEN":document.head.querySelector('meta[name="csrf-token"]').content}}})},150)})},init(){Promise.all([p("language","en_US")]).then(e=>{s=new y;const o=e[0].replace("-","_");s.locale=o,m(s,o).then(()=>{this.notifications.wait.show=!0,this.notifications.wait.text=s.t("firefly.wait_loading_transaction"),this.getTransactionGroup()})}),P().then(e=>{this.formStates.loadingCurrencies=!1,this.formData.defaultCurrency=e.defaultCurrency,this.formData.enabledCurrencies=e.enabledCurrencies,this.formData.nativeCurrencies=e.nativeCurrencies,this.formData.foreignCurrencies=e.foreignCurrencies}),D().then(e=>{this.formData.budgets=e,this.formStates.loadingBudgets=!1}),x().then(e=>{this.formData.piggyBanks=e,this.formStates.loadingPiggyBanks=!1}),L().then(e=>{this.formData.subscriptions=e,this.formStates.loadingSubscriptions=!1}),document.addEventListener("upload-success",e=>{this.processUpload(e),document.querySelectorAll("input[type=file]").value=""}),document.addEventListener("upload-error",e=>{this.processUploadError(e)}),document.addEventListener("location-move",e=>{this.entries[e.detail.index].latitude=e.detail.latitude,this.entries[e.detail.index].longitude=e.detail.longitude}),document.addEventListener("location-set",e=>{this.entries[e.detail.index].hasLocation=!0,this.entries[e.detail.index].latitude=e.detail.latitude,this.entries[e.detail.index].longitude=e.detail.longitude,this.entries[e.detail.index].zoomLevel=e.detail.zoomLevel}),document.addEventListener("location-zoom",e=>{this.entries[e.detail.index].hasLocation=!0,this.entries[e.detail.index].zoomLevel=e.detail.zoomLevel})},changedAmount(e){const o=parseInt(e.target.dataset.index);this.entries[o].amount=parseFloat(e.target.value),this.groupProperties.totalAmount=0;for(let i in this.entries)this.entries.hasOwnProperty(i)&&(this.groupProperties.totalAmount=this.groupProperties.totalAmount+parseFloat(this.entries[i].amount))}}},d={transactions:E,dates:h};function g(){Object.keys(d).forEach(e=>{console.log(`Loading page component "${e}"`);let o=d[e]();Alpine.data(e,()=>o)}),Alpine.start()}document.addEventListener("firefly-iii-bootstrapped",()=>{console.log("Loaded through event listener."),g()});window.bootstrapped&&(console.log("Loaded through window variable."),g());