mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-02 02:18:20 +00:00
2 lines
18 KiB
JavaScript
Executable File
Vendored
2 lines
18 KiB
JavaScript
Executable File
Vendored
(window.webpackJsonp=window.webpackJsonp||[]).push([[8],{335:function(t,e,n){t.exports=n(461)},461:function(t,e,n){"use strict";n.r(e);var i=n(30),s=n(14),a=n(68),r=n(46),o=n(69),c=n(66),d=n(29);function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function l(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function p(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?l(Object(n),!0).forEach((function(e){h(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function h(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var _=Object(s.b)("transactions/create"),f=(_.mapState,_.mapGetters),m=(_.mapActions,_.mapMutations),y={name:"Create",components:{SplitForm:c.a,Alert:a.a,SplitPills:r.a,TransactionGroupTitle:o.a},created:function(){this.getAllowedOpposingTypes(),this.getAccountToTransaction(),this.getCustomFields(),this.addTransaction()},data:function(){return{errorMessage:"",successMessage:"",customFields:{},enableSubmit:!0,createAnother:!1,resetFormAfter:!1,submittedTransaction:!1,submittedLinks:!1,submittedAttachments:!1,inError:!1,submittedAttCount:{},groupTitleErrors:[],returnedGroupId:0,returnedGroupTitle:"",accountToTransaction:{},allowedOpposingTypes:{},defaultSourceAllowedTypes:["Asset account","Loan","Debt","Mortgage","Revenue account"],defaultDestinationAllowedTypes:["Asset account","Loan","Debt","Mortgage","Expense account"],sourceAllowedTypes:["Asset account","Loan","Debt","Mortgage","Revenue account"],destinationAllowedTypes:["Asset account","Loan","Debt","Mortgage","Expense account"],date:new Date,time:new Date}},computed:p({},f(["transactionType","transactions","groupTitle"])),watch:{submittedTransaction:function(){this.finalizeSubmit()},submittedLinks:function(){this.finalizeSubmit()},submittedAttachments:function(){this.finalizeSubmit()}},methods:p(p({},m(["setGroupTitle","addTransaction","deleteTransaction","setTransactionError","setTransactionType","resetErrors","updateField","resetTransactions"])),{},{removeTransaction:function(t){this.$store.commit("transactions/create/deleteTransaction",t)},finalizeSubmit:function(){var t=this;if(this.submittedTransaction&&this.submittedAttachments&&this.submittedLinks){var e;if(!1===this.createAnother&&!1===this.inError)return void(window.location.href=(null!==(e=window.previousURL)&&void 0!==e?e:"/")+"?transaction_group_id="+this.returnedGroupId+"&message=created");for(var n in!1===this.inError&&(this.errorMessage="",this.successMessage=this.$t("firefly.transaction_stored_link",{ID:this.returnedGroupId,title:this.returnedGroupTitle})),this.enableSubmit=!0,this.submittedTransaction=!1,this.submittedLinks=!1,this.submittedAttachments=!1,this.inError=!1,this.transactions)this.transactions.hasOwnProperty(n)&&/^0$|^[1-9]\d*$/.test(n)&&n<=4294967294&&this.transactions.hasOwnProperty(n)&&this.updateField({index:n,field:"transaction_journal_id",value:0});this.submittedAttCount=[],this.resetFormAfter&&(this.resetTransactions(),setTimeout((function(){return t.addTransaction()}),50))}},submitTransaction:function(){var t=this;this.enableSubmit=!1;var e=this.convertData();axios.post("./api/v1/transactions",e).then((function(n){t.submittedTransaction=!0,t.submitTransactionLinks(e,n),t.submitAttachments(e,n),t.returnedGroupId=parseInt(n.data.data.id),t.returnedGroupTitle=null===n.data.data.attributes.group_title?n.data.data.attributes.transactions[0].description:n.data.data.attributes.group_title})).catch((function(e){t.enableSubmit=!0,t.submittedTransaction=!0,t.submittedAttachments=!0,t.submittedLinks=!0,t.inError=!0,t.parseErrors(e.response.data)}))},submitAttachments:function(t,e){var n=e.data.data.attributes.transactions;for(var i in t.transactions)t.transactions.hasOwnProperty(i)&&/^0$|^[1-9]\d*$/.test(i)&&i<=4294967294&&n.hasOwnProperty(i)&&this.updateField({index:i,field:"transaction_journal_id",value:n[i].transaction_journal_id})},uploadedAttachment:function(t){var e="str"+t;this.submittedAttCount[e]=1,Object.keys(this.submittedAttCount).length===this.transactions.length&&(this.submittedAttachments=!0)},storeLocation:function(t){var e=t.hasMarker?t.zoomLevel:null,n=t.hasMarker?t.lat:null,i=t.hasMarker?t.lng:null;this.updateField({index:t.index,field:"zoom_level",value:e}),this.updateField({index:t.index,field:"latitude",value:n}),this.updateField({index:t.index,field:"longitude",value:i})},storeAccountValue:function(t){this.updateField({index:t.index,field:t.direction+"_account_id",value:t.id}),this.updateField({index:t.index,field:t.direction+"_account_type",value:t.type}),this.updateField({index:t.index,field:t.direction+"_account_name",value:t.name}),this.updateField({index:t.index,field:t.direction+"_account_currency_id",value:t.currency_id}),this.updateField({index:t.index,field:t.direction+"_account_currency_code",value:t.currency_code}),this.updateField({index:t.index,field:t.direction+"_account_currency_symbol",value:t.currency_symbol}),this.calculateTransactionType(t.index)},storeField:function(t){this.updateField(t)},storeDate:function(t){this.date=t.date},storeTime:function(t){this.time=t.time},storeGroupTitle:function(t){this.setGroupTitle({groupTitle:t})},calculateTransactionType:function(t){if(0===t){var e=this.transactions[0].source_account_type,n=this.transactions[0].destination_account_type;if(null===e||null===n)return void this.setTransactionType("any");if(""===e||""===n)return void this.setTransactionType("any");var i=this.accountToTransaction[e];if(void 0!==i){var s=i[n];if(void 0!==i[n])return void this.setTransactionType(s)}"Asset account"!==e&&this.updateField({index:0,field:"destination_account_id",value:null}),"Asset account"!==n&&this.updateField({index:0,field:"source_account_id",value:null}),this.setTransactionType("any")}},submitTransactionLinks:function(t,e){var n=[],i=e.data.data.attributes.transactions,s=0;for(var a in t.transactions)if(t.transactions.hasOwnProperty(a)&&/^0$|^[1-9]\d*$/.test(a)&&a<=4294967294){var r=t.transactions[a];if(i.hasOwnProperty(a)){var o=i[a];for(var c in r.links)if(r.links.hasOwnProperty(c)&&/^0$|^[1-9]\d*$/.test(c)&&c<=4294967294){var d=r.links[c];s++,0===d.outward_id&&(d.outward_id=o.transaction_journal_id),0===d.inward_id&&(d.inward_id=o.transaction_journal_id),n.push(axios.post("./api/v1/transaction_links",d).then((function(t){})))}}}0!==s?Promise.all(n).then((function(){this.submittedLinks=!0})):this.submittedLinks=!0},parseErrors:function(t){for(var e in this.transactions)this.resetErrors({index:e});var n,i,s;for(var a 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(a)){if("group_title"===a){this.groupTitleErrors=t.errors[a];continue}if("group_title"!==a)switch(i=parseInt(a.split(".")[1]),s=a.split(".")[2]){case"amount":case"description":case"date":case"tags":n={index:i,field:s,errors:t.errors[a]},this.setTransactionError(n);break;case"budget_id":n={index:i,field:"budget",errors:t.errors[a]},this.setTransactionError(n);break;case"bill_id":n={index:i,field:"bill",errors:t.errors[a]},this.setTransactionError(n);break;case"piggy_bank_id":n={index:i,field:"piggy_bank",errors:t.errors[a]},this.setTransactionError(n);break;case"category_name":n={index:i,field:"category",errors:t.errors[a]},this.setTransactionError(n);break;case"source_name":case"source_id":n={index:i,field:"source",errors:t.errors[a]},this.setTransactionError(n);break;case"destination_name":case"destination_id":n={index:i,field:"destination",errors:t.errors[a]},this.setTransactionError(n);break;case"foreign_amount":case"foreign_currency":n={index:i,field:"foreign_amount",errors:t.errors[a]},this.setTransactionError(n)}this.transactions[i]}},convertData:function(){var t={transactions:[]};for(var e in this.groupTitle.length>0&&(t.group_title=this.groupTitle),this.transactions)this.transactions.hasOwnProperty(e)&&/^0$|^[1-9]\d*$/.test(e)&&e<=4294967294&&t.transactions.push(this.convertSplit(e,this.transactions[e]));return t.transactions.length>1&&""!==t.transactions[0].description&&(t.group_title=t.transactions[0].description),t.transactions.length>1&&(t=this.synchronizeAccounts(t)),t},synchronizeAccounts:function(t){for(var e in t.transactions)t.transactions.hasOwnProperty(e)&&/^0$|^[1-9]\d*$/.test(e)&&e<=4294967294&&("Transfer"===this.transactionType&&(t.transactions[e].source_name=null,t.transactions[e].destination_name=null,e>0&&(t.transactions[e].source_id=t.transactions[0].source_id,t.transactions[e].destination_id=t.transactions[0].destination_id)),"Deposit"===this.transactionType&&(t.transactions[e].destination_name=null,e>0&&(t.transactions[e].destination_id=t.transactions[0].destination_id)),"Withdrawal"===this.transactionType&&(t.transactions[e].source_name=null,e>0&&(t.transactions[e].source_id=t.transactions[0].source_id)));return t},switchAccounts:function(t){var e=this.transactions[t].source_account_id,n=this.transactions[t].source_account_name,i=this.transactions[t].source_account_type,s=this.transactions[t].destination_account_id,a=this.transactions[t].destination_account_name,r=this.transactions[t].destination_account_type;this.updateField({index:0,field:"source_account_id",value:s}),this.updateField({index:0,field:"source_account_name",value:a}),this.updateField({index:0,field:"source_account_type",value:r}),this.updateField({index:0,field:"destination_account_id",value:e}),this.updateField({index:0,field:"destination_account_name",value:n}),this.updateField({index:0,field:"destination_account_type",value:i}),this.calculateTransactionType(0)},convertSplit:function(t,e){var n,i,s,a,r="invalid";if(this.time instanceof Date&&!isNaN(this.time)&&this.date instanceof Date&&!isNaN(this.date)){var o=new Date(this.date);o.setHours(this.time.getHours()),o.setMinutes(this.time.getMinutes()),o.setSeconds(this.time.getSeconds()),r=Object(d.c)(o)}var c,l,p,h={description:e.description,date:r,type:this.transactionType,source_id:null!==(n=e.source_account_id)&&void 0!==n?n:null,source_name:null!==(i=e.source_account_name)&&void 0!==i?i:null,destination_id:null!==(s=e.destination_account_id)&&void 0!==s?s:null,destination_name:null!==(a=e.destination_account_name)&&void 0!==a?a:null,currency_id:e.currency_id,amount:e.amount,budget_id:e.budget_id,category_name:e.category,interest_date:e.interest_date,book_date:e.book_date,process_date:e.process_date,due_date:e.due_date,payment_date:e.payment_date,invoice_date:e.invoice_date,internal_reference:e.internal_reference,external_url:e.external_url,notes:e.notes,external_id:e.external_id,zoom_level:e.zoom_level,longitude:e.longitude,latitude:e.latitude,tags:[],order:0,reconciled:!1};if(0!==e.tags.length)for(var _ in e.tags)if(e.tags.hasOwnProperty(_)&&/^0$|^[1-9]\d*$/.test(_)&&_<=4294967294){var f=e.tags[_];"object"===u(f)&&null!==f&&h.tags.push(f.text),"string"==typeof f&&h.tags.push(f)}0!==e.piggy_bank_id&&(h.piggy_bank_id=e.piggy_bank_id),0!==e.bill_id&&(h.bill_id=e.bill_id),0!==e.foreign_currency_id&&""!==e.foreign_amount&&(h.foreign_currency_id=e.foreign_currency_id),""!==e.foreign_amount&&(h.foreign_amount=e.foreign_amount),c=this.transactionType?this.transactionType.toLowerCase():"any",l=this.transactions[0].source_account_type,p=this.transactions[0].destination_account_type,h.currency_id=e.source_account_currency_id,"any"===c&&["asset","Asset account","Loan","Debt","Mortgage"].includes(l)&&(c="withdrawal"),"any"===c&&["asset","Asset account","Loan","Debt","Mortgage"].includes(p)&&(c="deposit",h.currency_id=e.destination_account_currency_id),h.type=c;var m=[];for(var y in e.links)if(e.links.hasOwnProperty(y)&&/^0$|^[1-9]\d*$/.test(y)&&y<=4294967294){var v=e.links[y],b=v.link_type_id.split("-"),g="outward"===b[1]?0:parseInt(v.transaction_journal_id),T="inward"===b[1]?0:parseInt(v.transaction_journal_id),A={link_type_id:parseInt(b[0]),inward_id:g,outward_id:T};m.push(A)}return h.links=m,h},getAllowedOpposingTypes:function(){var t=this;axios.get("./api/v1/configuration/firefly.allowed_opposing_types").then((function(e){t.allowedOpposingTypes=e.data.data.value}))},getAccountToTransaction:function(){var t=this;axios.get("./api/v1/configuration/firefly.account_to_transaction").then((function(e){t.accountToTransaction=e.data.data.value}))},getCustomFields:function(){var t=this;axios.get("./api/v1/preferences/transaction_journal_optional_fields").then((function(e){t.customFields=e.data.data.attributes.data}))},setDestinationAllowedTypes:function(t){0!==t.length?this.destinationAllowedTypes=t:this.destinationAllowedTypes=this.defaultDestinationAllowedTypes},setSourceAllowedTypes:function(t){0!==t.length?this.sourceAllowedTypes=t:this.sourceAllowedTypes=this.defaultSourceAllowedTypes}})},v=n(4),b=Object(v.a)(y,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",[n("alert",{attrs:{message:t.errorMessage,type:"danger"}}),t._v(" "),n("alert",{attrs:{message:t.successMessage,type:"success"}}),t._v(" "),n("SplitPills",{attrs:{transactions:t.transactions}}),t._v(" "),n("div",{staticClass:"tab-content"},t._l(this.transactions,(function(e,i){return n("SplitForm",{key:i,attrs:{"allowed-opposing-types":t.allowedOpposingTypes,count:t.transactions.length,"custom-fields":t.customFields,date:t.date,"destination-allowed-types":t.destinationAllowedTypes,index:i,"source-allowed-types":t.sourceAllowedTypes,"submitted-transaction":t.submittedTransaction,time:t.time,transaction:e,"transaction-type":t.transactionType},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)},"switch-accounts":function(e){return t.switchAccounts(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)},"set-dest-types":function(e){return t.setDestinationAllowedTypes(e)},"set-src-types":function(e){return t.setSourceAllowedTypes(e)}}})})),1),t._v(" "),n("div",{staticClass:"row"},[n("div",{staticClass:"col-xl-6 col-lg-6 col-md-12 col-sm-12 col-xs-12"},[t.transactions.length>1?n("div",{staticClass:"card"},[n("div",{staticClass:"card-body"},[n("div",{staticClass:"row"},[n("div",{staticClass:"col"},[n("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(" "),n("div",{staticClass:"col-xl-6 col-lg-6 col-md-12 col-sm-12 col-xs-12"},[n("div",{staticClass:"card card-primary"},[n("div",{staticClass:"card-body"},[n("div",{staticClass:"row"},[n("div",{staticClass:"col"},[n("div",{staticClass:"text-xs d-none d-lg-block d-xl-block"},[t._v("\n \n ")]),t._v(" "),n("button",{staticClass:"btn btn-outline-primary btn-block",on:{click:t.addTransaction}},[n("i",{staticClass:"far fa-clone"}),t._v(" "+t._s(t.$t("firefly.add_another_split"))+"\n ")])]),t._v(" "),n("div",{staticClass:"col"},[n("div",{staticClass:"text-xs d-none d-lg-block d-xl-block"},[t._v("\n \n ")]),t._v(" "),n("button",{staticClass:"btn btn-success btn-block",attrs:{disabled:!t.enableSubmit},on:{click:t.submitTransaction}},[t.enableSubmit?n("span",[n("i",{staticClass:"far fa-save"}),t._v(" "+t._s(t.$t("firefly.store_transaction")))]):t._e(),t._v(" "),t.enableSubmit?t._e():n("span",[n("i",{staticClass:"fas fa-spinner fa-spin"})])])])]),t._v(" "),n("div",{staticClass:"row"},[n("div",{staticClass:"col"},[t._v("\n \n ")]),t._v(" "),n("div",{staticClass:"col"},[n("div",{staticClass:"form-check"},[n("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 n=t.createAnother,i=e.target,s=!!i.checked;if(Array.isArray(n)){var a=t._i(n,null);i.checked?a<0&&(t.createAnother=n.concat([null])):a>-1&&(t.createAnother=n.slice(0,a).concat(n.slice(a+1)))}else t.createAnother=s}}}),t._v(" "),n("label",{staticClass:"form-check-label",attrs:{for:"createAnother"}},[n("span",{staticClass:"small"},[t._v(t._s(t.$t("firefly.create_another")))])])]),t._v(" "),n("div",{staticClass:"form-check"},[n("input",{directives:[{name:"model",rawName:"v-model",value:t.resetFormAfter,expression:"resetFormAfter"}],staticClass:"form-check-input",attrs:{id:"resetFormAfter",disabled:!t.createAnother,type:"checkbox"},domProps:{checked:Array.isArray(t.resetFormAfter)?t._i(t.resetFormAfter,null)>-1:t.resetFormAfter},on:{change:function(e){var n=t.resetFormAfter,i=e.target,s=!!i.checked;if(Array.isArray(n)){var a=t._i(n,null);i.checked?a<0&&(t.resetFormAfter=n.concat([null])):a>-1&&(t.resetFormAfter=n.slice(0,a).concat(n.slice(a+1)))}else t.resetFormAfter=s}}}),t._v(" "),n("label",{staticClass:"form-check-label",attrs:{for:"resetFormAfter"}},[n("span",{staticClass:"small"},[t._v(t._s(t.$t("firefly.reset_after")))])])])])])])])])])],1)}),[],!1,null,"6df98ad4",null).exports,g=n(8),T=n.n(g);n(41),T.a.config.productionTip=!1;var A=n(43),w={};new T.a({i18n:A,store:i.a,render:function(t){return t(b,{props:w})},beforeCreate:function(){this.$store.commit("initialiseStore"),this.$store.dispatch("updateCurrencyPreference")}}).$mount("#transactions_create")}},[[335,0,1]]]);
|
||
//# sourceMappingURL=create.js.map
|