Files
firefly-iii/public/build/assets/splice-errors-into-transactions-528a3749.js
2024-02-15 01:29:20 +01:00

2 lines
9.9 KiB
JavaScript

import{a as l}from"./format-money-62afb78b.js";import{a as p,G as f}from"./get-5b4283ca.js";import{n as m,i as _}from"./vendor-2609b2c9.js";function x(r,t,a){let n=[];for(let o in r)if(r.hasOwnProperty(o)){const e=r[o];let i=!1,u={};t!==null&&t.hasOwnProperty(o)&&(i=!0,t[o]);let c={};(i&&u.description!==e.description||!i)&&(c.description=e.description),c.source_name=e.source_account.name,c.destination_name=e.destination_account.name,c.amount=e.amount,c.currency_code=e.currency_code,c.date=e.date,c.interest_date=e.interest_date,c.book_date=e.book_date,c.process_date=e.process_date,c.due_date=e.due_date,c.payment_date=e.payment_date,c.invoice_date=e.invoice_date,c.budget_id=e.budget_id,c.category_name=e.category_name,c.piggy_bank_id=e.piggy_bank_id,c.bill_id=e.bill_id,c.tags=e.tags,c.notes=e.notes,c.internal_reference=e.internal_reference,c.external_url=e.external_url,c.store_location=!1,e.hasLocation&&(c.store_location=!0,c.longitude=e.longitude.toString(),c.latitude=e.latitude.toString(),c.zoom_level=e.zoomLevel),typeof e.foreign_currency_code<"u"&&e.foreign_currency_code.toString()!==""&&(c.foreign_currency_code=e.foreign_currency_code,typeof e.foreign_amount<"u"&&e.foreign_amount.toString()!==""&&(c.foreign_amount=e.foreign_amount),(typeof e.foreign_amount>"u"||e.foreign_amount.toString()==="")&&(delete c.foreign_amount,delete c.foreign_currency_code)),typeof e.source_account.id<"u"&&e.source_account.id.toString()!==""&&(c.source_id=e.source_account.id),typeof e.destination_account.id<"u"&&e.destination_account.id.toString()!==""&&(c.destination_id=e.destination_account.id),c.type=a,n.push(c)}return n}let g=class{list(t){return l.get("/api/v2/currencies",{params:t})}};function C(){let r={page:1,limit:1337};return new g().list(r).then(a=>{let n={defaultCurrency:{},nativeCurrencies:[],foreignCurrencies:[],enabledCurrencies:[]};n.foreignCurrencies.push({id:0,name:"(no foreign currency)",code:"",default:!1,symbol:"",decimal_places:2});for(let o in a.data.data)if(a.data.data.hasOwnProperty(o)){let e=a.data.data[o];if(e.attributes.enabled){let i={id:e.id,name:e.attributes.name,code:e.attributes.code,default:e.attributes.default,symbol:e.attributes.symbol,decimal_places:e.attributes.decimal_places};i.default&&(n.defaultCurrency=i),n.enabledCurrencies.push(i),n.nativeCurrencies.push(i),n.foreignCurrencies.push(i)}}return n})}class y{list(t){return l.get("/api/v2/budgets",{params:t})}}function $(){let r={page:1,limit:1337};return new y().list(r).then(a=>{let n=[{id:0,name:"(no budget)"}];for(let o in a.data.data)if(a.data.data.hasOwnProperty(o)){let e=a.data.data[o],i={id:e.id,name:e.attributes.name};n.push(i)}return n})}function O(){let r={page:1,limit:1337};return new p().list(r).then(a=>{let n={0:{id:0,name:"(no group)",order:0,piggyBanks:[{id:0,name:"(no piggy bank)",order:0}]}};for(let o in a.data.data)if(a.data.data.hasOwnProperty(o)){let e=a.data.data[o],i=e.attributes.object_group_id??"0",u=e.attributes.object_group_title??"(no group)",c={id:e.id,name:e.attributes.name,order:e.attributes.order};n.hasOwnProperty(i)||(n[i]={id:i,name:u,order:e.attributes.object_group_order??0,piggyBanks:[]}),n[i].piggyBanks.push(c),n[i].piggyBanks.sort((d,s)=>d.order-s.order)}return Object.keys(n).sort().reduce((o,e)=>(o[e]=n[e],o),{})})}function P(){let r={page:1,limit:1337};return new f().list(r).then(a=>{let n={0:{id:0,name:"(no group)",order:0,subscriptions:[{id:0,name:"(no subscription)",order:0}]}};for(let o in a.data.data)if(a.data.data.hasOwnProperty(o)){let e=a.data.data[o],i=e.attributes.object_group_id??"0",u=e.attributes.object_group_title??"(no group)",c={id:e.id,name:e.attributes.name,order:e.attributes.order};n.hasOwnProperty(i)||(n[i]={id:i,name:u,order:e.attributes.object_group_order??0,subscriptions:[]}),n[i].subscriptions.push(c),n[i].subscriptions.sort((d,s)=>d.order-s.order)}return Object.keys(n).sort().reduce((o,e)=>(o[e]=n[e],o),{})})}function j(){return{description:"/api/v2/autocomplete/transaction-descriptions",account:"/api/v2/autocomplete/accounts",category:"/api/v2/autocomplete/categories",tag:"/api/v2/autocomplete/tags"}}function A(r){const t={server:r.serverUrl,serverParams:{},fetchOptions:{headers:{"X-CSRF-TOKEN":document.head.querySelector('meta[name="csrf-token"]').content}},hiddenInput:!0,highlightTyped:!0,liveServer:!0};typeof r.filters<"u"&&r.filters.length>0&&(t.serverParams.types=r.filters),typeof r.onRenderItem<"u"&&r.onRenderItem!==null&&(t.onRenderItem=r.onRenderItem),r.valueField&&(t.valueField=r.valueField),r.labelField&&(t.labelField=r.labelField),r.onSelectItem&&(t.onSelectItem=r.onSelectItem),r.onChange&&(t.onChange=r.onChange),r.hiddenValue&&(t.hiddenValue=r.hiddenValue),m.init(r.selector,t)}function q(r,t){const a=parseInt(t._searchInput.attributes["data-index"].value);if(typeof r<"u"&&r.name){document.querySelector("#form")._x_dataStack[0].$data.entries[a].category_name=r.name;return}document.querySelector("#form")._x_dataStack[0].$data.entries[a].category_name=t._searchInput.value}function E(r,t){const a=parseInt(t._searchInput.attributes["data-index"].value);if(typeof r<"u"&&r.description){document.querySelector("#form")._x_dataStack[0].$data.entries[a].description=r.description;return}document.querySelector("#form")._x_dataStack[0].$data.entries[a].description=t._searchInput.value}function B(r,t){if(typeof r>"u"){const a=parseInt(t._searchInput.attributes["data-index"].value);if(document.querySelector("#form")._x_dataStack[0].$data.entries[a].destination_account.name===t._searchInput.value){console.warn('Ignore hallucinated destination account name change to "'+t._searchInput.value+'"');return}document.querySelector("#form")._x_dataStack[0].$data.entries[a].destination_account={name:t._searchInput.value,alpine_name:t._searchInput.value},document.querySelector("#form")._x_dataStack[0].changedDestinationAccount()}}function F(r,t){const a=parseInt(t._searchInput.attributes["data-index"].value);document.querySelector("#form")._x_dataStack[0].$data.entries[a].destination_account={id:r.id,name:r.name,alpine_name:r.name,type:r.type,currency_code:r.currency_code},document.querySelector("#form")._x_dataStack[0].changedDestinationAccount()}function G(r,t){if(typeof r>"u"){const a=parseInt(t._searchInput.attributes["data-index"].value);if(document.querySelector("#form")._x_dataStack[0].$data.entries[a].source_account.name===t._searchInput.value)return;document.querySelector("#form")._x_dataStack[0].$data.entries[a].source_account={name:t._searchInput.value,alpine_name:t._searchInput.value},document.querySelector("#form")._x_dataStack[0].changedSourceAccount()}}function R(r,t){const a=parseInt(t._searchInput.attributes["data-index"].value);document.querySelector("#form")._x_dataStack[0].$data.entries[a].source_account={id:r.id,name:r.name,alpine_name:r.name,type:r.type,currency_code:r.currency_code},document.querySelector("#form")._x_dataStack[0].changedSourceAccount()}class h{post(t,a,n){let o="/api/v1/attachments";return l.post(o,{filename:t,attachable_type:a,attachable_id:n})}upload(t,a){let n="./api/v1/attachments/"+t+"/upload";return axios.post(n,a)}}let b=function(r){let t=r.length,a=0,n=!1;for(const o in r)if(r.hasOwnProperty(o)&&/^0$|^[1-9]\d*$/.test(o)&&o<=4294967294&&n===!1){let e=new h;e.post(r[o].name,"TransactionJournal",r[o].journal).then(i=>{let u=parseInt(i.data.data.id);e.upload(u,r[o].content).then(c=>{if(a++,a===t){const d=new CustomEvent("upload-success",{some:"details"});document.dispatchEvent(d)}}).catch(c=>{console.error("Could not upload"),console.error(c),a++;const d=new CustomEvent("upload-failed",{error:c});document.dispatchEvent(d),n=!0})}).catch(i=>{console.error("Could not create upload."),console.error(i),a++;const u=new CustomEvent("upload-failed",{error:i});document.dispatchEvent(u),n=!0})}};function T(r,t){t=t.reverse();let a=[],n=0,o=[],e=document.querySelectorAll('input[name="attachments[]"]');for(const i in e)if(e.hasOwnProperty(i)&&/^0$|^[1-9]\d*$/.test(i)&&i<=4294967294)for(const u in e[i].files)e[i].files.hasOwnProperty(u)&&/^0$|^[1-9]\d*$/.test(u)&&u<=4294967294&&(a.push({journal:t[i].transaction_journal_id,file:e[i].files[u]}),n++);for(const i in a)a.hasOwnProperty(i)&&/^0$|^[1-9]\d*$/.test(i)&&i<=4294967294&&function(u,c){let d=new FileReader;d.onloadend=function(s){s.target.readyState===FileReader.DONE&&(o.push({name:a[c].file.name,journal:a[c].journal,content:new Blob([s.target.result])}),o.length===n&&b(o))},d.readAsArrayBuffer(u.file)}(a[i],i);return n}function v(r,t,a){let n=[];for(let o in a)a.hasOwnProperty(o)&&n.push(a[o].replace(r,t));return n}function D(r,t){let a,n,o;for(const e in r)if(r.hasOwnProperty(e)){if(e==="group_title"){console.error("Cannot handle error in group title.");continue}if(a=parseInt(e.split(".")[1]),n=e.split(".")[2],o=v(e,n,r[e]),!t.hasOwnProperty(a)){console.error("Cannot handle errors in index #"+a);continue}switch(n){case"currency_code":case"foreign_currency_code":case"category_name":case"piggy_bank_id":case"notes":case"internal_reference":case"external_url":case"latitude":case"longitude":case"zoom_level":case"interest_date":case"book_date":case"process_date":case"due_date":case"payment_date":case"invoice_date":case"amount":case"date":case"budget_id":case"bill_id":case"description":case"tags":t[a].errors[n]=o;break;case"source_name":case"source_id":t[a].errors.source_account=t[a].errors.source_account.concat(o);break;case"type":t[a].errors.source_account=t[a].errors.source_account.concat([_.t("validation.bad_type_source")]),t[a].errors.destination_account=t[a].errors.destination_account.concat([_.t("validation.bad_type_destination")]);break;case"destination_name":case"destination_id":t[a].errors.destination_account=t[a].errors.destination_account.concat(o);break;case"foreign_amount":case"foreign_currency_id":t[a].errors.foreign_amount=t[a].errors.foreign_amount.concat(o);break}typeof t[a]<"u"&&(t[a].errors.source_account=Array.from(new Set(t[a].errors.source_account)),t[a].errors.destination_account=Array.from(new Set(t[a].errors.destination_account)))}return console.log(t[0].errors),t}export{$ as a,O as b,P as c,T as d,A as e,G as f,R as g,B as h,F as i,j,q as k,C as l,E as m,x as p,D as s};