mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 03:53:37 +00:00
2 lines
13 KiB
JavaScript
Executable File
Vendored
2 lines
13 KiB
JavaScript
Executable File
Vendored
(window.webpackJsonp=window.webpackJsonp||[]).push([[9],{422:function(t,e,s){t.exports=s(431)},431:function(t,e,s){"use strict";s.r(e);var i=s(17),a=s(39),n=s(22),r=s(38),o=s(40),c=s(7),d=s(41),l={name:"Edit",created:function(){var t=window.location.pathname.split("/");this.groupId=parseInt(t[t.length-1]),this.getTransactionGroup(),this.getAllowedOpposingTypes(),this.getCustomFields()},data:function(){return{successMessage:"",errorMessage:"",transactions:[],originalTransactions:[],groupTitle:"",originalGroupTitle:"",transactionType:"any",groudId:0,groupTitleErrors:[],customFields:{},returnedGroupId:0,returnedGroupTitle:"",date:new Date,time:new Date,originalDate:new Date,originalTime:new Date,submittedTransaction:!1,submittedLinks:!1,submittedAttachments:!1,allowedOpposingTypes:{},destinationAllowedTypes:[],sourceAllowedTypes:[],enableSubmit:!0,createAnother:!1,resetFormAfter:!1}},components:{Alert:a.a,SplitPills:n.a,SplitForm:r.a,TransactionGroupTitle:o.a},methods:{getTransactionGroup:function(){var t=this;axios.get("./api/v1/transactions/"+this.groupId).then((function(e){t.parseTransactionGroup(e.data)})).catch((function(t){}))},parseTransactionGroup:function(t){var e=t.data.attributes,s=e.transactions.reverse();for(var i in this.groupTitle=e.group_title,this.originalGroupTitle=e.group_title,s)if(s.hasOwnProperty(i)&&/^0$|^[1-9]\d*$/.test(i)&&i<=4294967294){var a=this.parseTransaction(parseInt(i),s[i]);this.transactions.push(a),this.originalTransactions.push(d(a)),this.parseLinks(parseInt(a.transaction_journal_id),parseInt(i))}},parseTransaction:function(t,e){0===t&&(this.transactionType=e.type.charAt(0).toUpperCase()+e.type.slice(1),this.sourceAllowedTypes=[e.source_type],this.destinationAllowedTypes=[e.destination_type],this.date=new Date(e.date),this.time=new Date(e.date),this.originalDate=new Date(e.date),this.originalTime=new Date(e.date));var s=Object(c.b)();return s.description=e.description,s.transaction_journal_id=parseInt(e.transaction_journal_id),s.source_account_id=e.source_id,s.source_account_name=e.source_name,s.source_account_type=e.source_type,s.destination_account_id=e.destination_id,s.destination_account_name=e.destination_name,s.destination_account_type=e.destination_type,s.amount=e.amount,s.currency_id=e.currency_id,s.foreign_amount=e.foreign_amount,s.foreign_currency_id=e.foreign_currency_id,s.category=e.category_name,s.budget_id=e.budget_id,s.bill_id=e.bill_id,s.tags=e.tags,s.interest_date=e.interest_date?e.interest_date.substr(0,10):"",s.book_date=e.book_date?e.book_date.substr(0,10):"",s.process_date=e.process_date?e.process_date.substr(0,10):"",s.due_date=e.due_date?e.due_date.substr(0,10):"",s.payment_date=e.payment_date?e.payment_date.substr(0,10):"",s.invoice_date=e.invoice_date?e.invoice_date.substr(0,10):"",s.internal_reference=e.internal_reference,s.external_url=e.external_uri,s.external_id=e.external_id,s.notes=e.notes,s.location={zoom_level:e.zoom_level,longitude:e.longitude,latitude:e.latitude},s.zoom_level=e.zoom_level,s.longitude=e.longitude,s.latitude=e.latitude,s.errors=Object(c.a)(),s},parseLinks:function(t,e){var s=this;axios.get("./api/v1/transactions/"+t+"/links").then((function(i){var a=i.data.data;for(var n in a)a.hasOwnProperty(n)&&/^0$|^[1-9]\d*$/.test(n)&&n<=4294967294&&s.parseLink(a[n],t,e)}))},parseLink:function(t,e,s){var i=this,a=[],n=parseInt(t.attributes.inward_id),r="inward";n===e&&(n=parseInt(t.attributes.outward_id),r="outward"),a.push(new Promise((function(i){i({link:t,journalId:e,opposingId:n,index:s,direction:r})}))),a.push(axios.get("./api/v1/transaction-journals/"+n)),a.push(axios.get("./api/v1/transaction_links/"+t.attributes.link_type_id)),Promise.all(a).then((function(t){var e=t[1].data.data.attributes.transactions,s=t[0].opposingId,a={};for(var n in e)e.hasOwnProperty(n)&&/^0$|^[1-9]\d*$/.test(n)&&n<=4294967294&&e[n].transaction_journal_id===s&&(a=e[n]);var r=t[0].index,o=t[0].direction,c={link_type_id:t[2].data.data.id+"-"+o,transaction_group_id:t[1].data.data.id,transaction_journal_id:a.transaction_journal_id,description:a.description,type:a.type,currency_code:a.currency_code,amount:a.amount};i.transactions[r].links.push(c),i.originalTransactions[r].links.push(c)}))},getAllowedOpposingTypes:function(){var t=this;axios.get("./api/v1/configuration/static/firefly.allowed_opposing_types").then((function(e){t.allowedOpposingTypes=e.data["firefly.allowed_opposing_types"]}))},getCustomFields:function(){var t=this;axios.get("./api/v1/preferences/transaction_journal_optional_fields").then((function(e){t.customFields=e.data.data.attributes.data}))},uploadedAttachment:function(t){console.log("event: uploadedAttachment"),console.log(t)},storeLocation:function(t){this.transactions[t.index].zoom_level=t.zoomLevel,this.transactions[t.index].longitude=t.lng,this.transactions[t.index].latitude=t.lat},storeAccountValue:function(t){var e=t.direction,s=t.index;this.transactions[s][e+"_account_id"]=t.id,this.transactions[s][e+"_account_type"]=t.type,this.transactions[s][e+"_account_name"]=t.name},storeDate:function(t){this.date=t.date},storeTime:function(t){this.time=t.time},storeField:function(t){var e=t.field;"category"===e&&(e="category_name"),this.transactions[t.index][e]=t.value},removeTransaction:function(t){this.transactions.splice(t.index,1),this.originalTransactions=[]},storeGroupTitle:function(t){this.groupTitle=t},selectedAttachments:function(t){for(var e in this.transactions)this.transactions.hasOwnProperty(e)&&/^0$|^[1-9]\d*$/.test(e)&&e<=4294967294&&parseInt(this.transactions[e].transaction_journal_id)===parseInt(t)&&(this.transactions[e].selectedAttachments=!0)},addTransaction:function(){var t=Object(c.b)();t.errors=Object(c.a)(),this.transactions.push(t)},submitTransaction:function(){var t={transactions:[]},e=!1,s=!1,i=!1;for(var a in this.groupTitle!==this.originalGroupTitle&&(t.group_title=this.groupTitle,e=!0),this.transactions)if(this.transactions.hasOwnProperty(a)&&/^0$|^[1-9]\d*$/.test(a)&&a<=4294967294){var n=this.transactions[a],r=this.originalTransactions.hasOwnProperty(a)?this.originalTransactions[a]:{},o={},d=["description","source_account_id","source_account_name","destination_account_id","destination_account_name","amount","foreign_amount","foreign_currency_id","category_name","budget_id","bill_id","interest_date","book_date","due_date","payment_date","invoice_date","external_url","internal_reference","external_id","notes","zoom_level","longitude","latitude"];for(var l in d)if(d.hasOwnProperty(l)&&/^0$|^[1-9]\d*$/.test(l)&&l<=4294967294){var u=d[l];n[u]!==r[u]&&(o[u]=n[u])}0!==n.piggy_bank_id&&(o.piggy_bank_id=n.piggy_bank_id),JSON.stringify(n.tags)!==JSON.stringify(r.tags)&&(o.tags=n.tags),this.compareLinks(n.links)!==this.compareLinks(r.links)&&(s=!0),void 0!==n.selectedAttachments&&!0===n.selectedAttachments&&(i=!0);var p="invalid";if(this.date.toISOString()!==this.originalDate.toISOString()||this.time.toISOString()!==this.originalTime.toISOString()){e=!0;var _=this.date;_.setHours(this.time.getHours()),_.setMinutes(this.time.getMinutes()),_.setSeconds(this.time.getSeconds()),p=Object(c.c)(_),t.date=p}0!==Object.keys(o).length&&(o.transaction_journal_id=r.transaction_journal_id,t.transactions.push(o),e=!0)}console.log("submitTransaction"),console.log(i),console.log(s),console.log(e),e&&this.submitUpdate(t)},compareLinks:function(t){var e=[];for(var s in t)t.hasOwnProperty(s)&&/^0$|^[1-9]\d*$/.test(s)&&s<=4294967294&&e.push({amount:t[s].amount,currency_code:t[s].currency_code,description:t[s].description,link_type_id:t[s].link_type_id,transaction_group_id:t[s].transaction_group_id,type:t[s].type});return JSON.stringify(e)},submitUpdate:function(t){var e=this;console.log("submitUpdate");var s="./api/v1/transactions/"+this.groupId;axios.put(s,t).then((function(t){e.submittedTransaction=!0})).catch((function(t){console.log("error :("),console.log(t.response.data),e.enableSubmit=!0,e.submittedTransaction=!0,e.submittedAttachments=!0,e.submittedLinks=!0,e.inError=!0,e.parseErrors(t.response.data)}))},parseErrors:function(t){for(var e in this.transactions)this.transactions.hasOwnProperty(e)&&/^0$|^[1-9]\d*$/.test(e)&&e<=4294967294&&this.resetErrors({index:e});var s,i,a;for(var n in this.successMessage="",this.errorMessage=this.$t("firefly.errors_submission"),void 0===t.errors&&(this.successMessage="",this.errorMessage=t.message),t.errors)if(t.errors.hasOwnProperty(n)){if("group_title"===n){this.groupTitleErrors=t.errors[n];continue}if("group_title"!==n)switch(i=parseInt(n.split(".")[1]),a=n.split(".")[2]){case"amount":case"description":case"date":case"tags":s={index:i,field:a,errors:t.errors[n]},this.setTransactionError(s);break;case"budget_id":s={index:i,field:"budget",errors:t.errors[n]},this.setTransactionError(s);break;case"bill_id":s={index:i,field:"bill",errors:t.errors[n]},this.setTransactionError(s);break;case"piggy_bank_id":s={index:i,field:"piggy_bank",errors:t.errors[n]},this.setTransactionError(s);break;case"category_name":s={index:i,field:"category",errors:t.errors[n]},this.setTransactionError(s);break;case"source_name":case"source_id":s={index:i,field:"source",errors:t.errors[n]},this.setTransactionError(s);break;case"destination_name":case"destination_id":s={index:i,field:"destination",errors:t.errors[n]},this.setTransactionError(s);break;case"foreign_amount":case"foreign_currency":s={index:i,field:"foreign_amount",errors:t.errors[n]},this.setTransactionError(s)}this.transactions[i]}},setTransactionError:function(t){this.transactions[t.index].errors[t.field]=t.errors},resetErrors:function(t){this.transactions[t.index].errors=d(Object(c.a)())}}},u=s(1),p=Object(u.a)(l,(function(){var t=this,e=t.$createElement,s=t._self._c||e;return s("div",[s("Alert",{attrs:{message:t.errorMessage,type:"danger"}}),t._v(" "),s("Alert",{attrs:{message:t.successMessage,type:"success"}}),t._v(" "),s("SplitPills",{attrs:{transactions:t.transactions}}),t._v(" "),s("div",{staticClass:"tab-content"},t._l(this.transactions,(function(e,i){return s("SplitForm",{key:i,attrs:{count:t.transactions.length,transaction:e,"allowed-opposing-types":t.allowedOpposingTypes,"custom-fields":t.customFields,date:t.date,time:t.time,index:i,"transaction-type":t.transactionType,"destination-allowed-types":t.destinationAllowedTypes,"source-allowed-types":t.sourceAllowedTypes,"allow-switch":!1,"submitted-transaction":t.submittedTransaction},on:{"uploaded-attachments":function(e){return t.uploadedAttachment(e)},"set-marker-location":function(e){return t.storeLocation(e)},"set-account":function(e){return t.storeAccountValue(e)},"set-date":function(e){return t.storeDate(e)},"set-time":function(e){return t.storeTime(e)},"set-field":function(e){return t.storeField(e)},"remove-transaction":function(e){return t.removeTransaction(e)},"selected-attachments":function(e){return t.selectedAttachments(e)}}})})),1),t._v(" "),s("div",{staticClass:"row"},[s("div",{staticClass:"col-xl-6 col-lg-6 col-md-12 col-sm-12 col-xs-12"},[t.transactions.length>1?s("div",{staticClass:"card"},[s("div",{staticClass:"card-body"},[s("div",{staticClass:"row"},[s("div",{staticClass:"col"},[s("TransactionGroupTitle",{attrs:{errors:this.groupTitleErrors},on:{"set-group-title":function(e){return t.storeGroupTitle(e)}},model:{value:this.groupTitle,callback:function(e){t.$set(this,"groupTitle",e)},expression:"this.groupTitle"}})],1)])])]):t._e()]),t._v(" "),s("div",{staticClass:"col-xl-6 col-lg-6 col-md-12 col-sm-12 col-xs-12"},[s("div",{staticClass:"card"},[s("div",{staticClass:"card-body"},[s("div",{staticClass:"row"},[s("div",{staticClass:"col"},[s("div",{staticClass:"text-xs d-none d-lg-block d-xl-block"},[t._v("\n \n ")]),t._v(" "),s("button",{staticClass:"btn btn-outline-primary btn-block",on:{click:t.addTransaction}},[s("i",{staticClass:"far fa-clone"}),t._v(" "+t._s(t.$t("firefly.add_another_split"))+"\n ")])]),t._v(" "),s("div",{staticClass:"col"},[s("div",{staticClass:"text-xs d-none d-lg-block d-xl-block"},[t._v("\n \n ")]),t._v(" "),s("button",{staticClass:"btn btn-info btn-block",attrs:{disabled:!t.enableSubmit},on:{click:t.submitTransaction}},[t.enableSubmit?s("span",[s("i",{staticClass:"far fa-save"}),t._v(" "+t._s(t.$t("firefly.update_transaction")))]):t._e(),t._v(" "),t.enableSubmit?t._e():s("span",[s("i",{staticClass:"fas fa-spinner fa-spin"})])])])]),t._v(" "),s("div",{staticClass:"row"},[s("div",{staticClass:"col"},[t._v("\n \n ")]),t._v(" "),s("div",{staticClass:"col"},[s("div",{staticClass:"form-check"},[s("input",{directives:[{name:"model",rawName:"v-model",value:t.createAnother,expression:"createAnother"}],staticClass:"form-check-input",attrs:{id:"createAnother",type:"checkbox"},domProps:{checked:Array.isArray(t.createAnother)?t._i(t.createAnother,null)>-1:t.createAnother},on:{change:function(e){var s=t.createAnother,i=e.target,a=!!i.checked;if(Array.isArray(s)){var n=t._i(s,null);i.checked?n<0&&(t.createAnother=s.concat([null])):n>-1&&(t.createAnother=s.slice(0,n).concat(s.slice(n+1)))}else t.createAnother=a}}}),t._v(" "),s("label",{staticClass:"form-check-label",attrs:{for:"createAnother"}},[s("span",{staticClass:"small"},[t._v(t._s(t.$t("firefly.after_update_create_another")))])])])])])])])])])],1)}),[],!1,null,"749f0a97",null).exports,_=s(2),h=s.n(_);s(16),h.a.config.productionTip=!1;var g=s(19),m={};new h.a({i18n:g,store:i.a,render:function(t){return t(p,{props:m})},beforeCreate:function(){this.$store.commit("initialiseStore"),this.$store.dispatch("updateCurrencyPreference")}}).$mount("#transactions_edit")}},[[422,0,1]]]);
|
||
//# sourceMappingURL=edit.js.map
|