mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-27 22:00:47 +00:00
2 lines
16 KiB
JavaScript
2 lines
16 KiB
JavaScript
|
|
import{a as v,d as P,f as _,g as E,l as S}from"./get-c53daca3.js";import{l as T,a as L,b as k,c as A,d as x,e as D,f as h,g as O,s as B,h as F,i as I,j as U,k as y,m as w}from"./autocomplete-functions-31caaca5.js";import{k as g,I as z,l as M}from"./vendor-4332182f.js";function R(e,t){let o=[];for(let r in e)if(e.hasOwnProperty(r)){const n=e[r];let i={};i.description=n.description,i.source_name=n.source_account.name,i.destination_name=n.destination_account.name,i.amount=n.amount,i.currency_code=n.currency_code,i.date=n.date,i.interest_date=n.interest_date,i.book_date=n.book_date,i.process_date=n.process_date,i.due_date=n.due_date,i.payment_date=n.payment_date,i.invoice_date=n.invoice_date,i.budget_id=n.budget_id,i.category_name=n.category_name,i.piggy_bank_id=n.piggy_bank_id,i.bill_id=n.bill_id,i.tags=n.tags,i.notes=n.notes,i.internal_reference=n.internal_reference,i.external_url=n.external_url,i.store_location=!1,n.hasLocation&&(i.store_location=!0,i.longitude=n.longitude.toString(),i.latitude=n.latitude.toString(),i.zoom_level=n.zoomLevel),typeof n.foreign_currency_code<"u"&&n.foreign_currency_code.toString()!==""&&(i.foreign_currency_code=n.foreign_currency_code,typeof n.foreign_amount<"u"&&n.foreign_amount.toString()!==""&&(i.foreign_amount=n.foreign_amount),(typeof n.foreign_amount>"u"||n.foreign_amount.toString()==="")&&(delete i.foreign_amount,delete i.foreign_currency_code)),typeof n.source_account.id<"u"&&n.source_account.id.toString()!==""&&(i.source_id=n.source_account.id),typeof n.destination_account.id<"u"&&n.destination_account.id.toString()!==""&&(i.destination_id=n.destination_account.id),i.type=t,o.push(i)}return o}let N=class{post(t){let o="/api/v2/transactions";return v.post(o,t)}};class ${post(t,o,r){let n="/api/v1/attachments";return v.post(n,{filename:t,attachable_type:o,attachable_id:r})}upload(t,o){let r="./api/v1/attachments/"+t+"/upload";return axios.post(r,o)}}let j=function(e){let t=e.length,o=0,r=!1;for(const n in e)if(e.hasOwnProperty(n)&&/^0$|^[1-9]\d*$/.test(n)&&n<=4294967294&&r===!1){let i=new $;i.post(e[n].name,"TransactionJournal",e[n].journal).then(s=>{let a=parseInt(s.data.data.id);i.upload(a,e[n].content).then(l=>{if(o++,o===t){const d=new CustomEvent("upload-success",{some:"details"});document.dispatchEvent(d)}}).catch(l=>{console.error("Could not upload"),console.error(l),o++;const d=new CustomEvent("upload-failed",{error:l});document.dispatchEvent(d),r=!0})}).catch(s=>{console.error("Could not create upload."),console.error(s),o++;const a=new CustomEvent("upload-failed",{error:s});document.dispatchEvent(a),r=!0})}};function q(e,t){t=t.reverse();let o=[],r=0,n=[],i=document.querySelectorAll('input[name="attachments[]"]');for(const s in i)if(i.hasOwnProperty(s)&&/^0$|^[1-9]\d*$/.test(s)&&s<=4294967294)for(const a in i[s].files)i[s].files.hasOwnProperty(a)&&/^0$|^[1-9]\d*$/.test(a)&&a<=4294967294&&(o.push({journal:t[s].transaction_journal_id,file:i[s].files[a]}),r++);for(const s in o)o.hasOwnProperty(s)&&/^0$|^[1-9]\d*$/.test(s)&&s<=4294967294&&function(a,l){let d=new FileReader;d.onloadend=function(m){m.target.readyState===FileReader.DONE&&(n.push({name:o[l].file.name,journal:o[l].journal,content:new Blob([m.target.result])}),n.length===r&&j(n))},d.readAsArrayBuffer(a.file)}(o[s],s);return r}function Z(e,t,o){let r=[];for(let n in o)o.hasOwnProperty(n)&&r.push(o[n].replace(e,t));return r}function V(e,t,o){let r,n,i;for(const s in t)if(t.hasOwnProperty(s)){if(s==="group_title"){console.error("Cannot handle error in group title.");continue}if(r=parseInt(s.split(".")[1]),n=s.split(".")[2],i=Z(s,n,t[s]),!o.hasOwnProperty(r)){console.error("Cannot handle errors in index #"+r);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":o[r].errors[n]=i;
|