mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-06-13 05:29:24 -04:00
Move 'status' from transactions to splits
This allows for a transaction to clear one account before the other (and mirrors how Gnucash, and I suspect most other pieces of software, do it)
This commit is contained in:
@ -35,11 +35,11 @@ var Big = require('big.js');
|
||||
var models = require('../models');
|
||||
var Security = models.Security;
|
||||
var Account = models.Account;
|
||||
var SplitStatus = models.SplitStatus;
|
||||
var SplitStatusList = models.SplitStatusList;
|
||||
var SplitStatusMap = models.SplitStatusMap;
|
||||
var Split = models.Split;
|
||||
var Transaction = models.Transaction;
|
||||
var TransactionStatus = models.TransactionStatus;
|
||||
var TransactionStatusList = models.TransactionStatusList;
|
||||
var TransactionStatusMap = models.TransactionStatusMap;
|
||||
var Error = models.Error;
|
||||
|
||||
var getAccountDisplayName = require('../utils').getAccountDisplayName;
|
||||
@ -70,6 +70,7 @@ const TransactionRow = React.createClass({
|
||||
for (var i = 0; i < this.props.transaction.Splits.length; i++) {
|
||||
if (this.props.transaction.Splits[i].AccountId == this.props.account.AccountId) {
|
||||
thisAccountSplit = this.props.transaction.Splits[i];
|
||||
status = SplitStatusMap[this.props.transaction.Splits[i].Status];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -89,7 +90,6 @@ const TransactionRow = React.createClass({
|
||||
var amount = security.Symbol + " " + thisAccountSplit.Amount.toFixed(security.Precision);
|
||||
if (this.props.transaction.hasOwnProperty("Balance"))
|
||||
balance = security.Symbol + " " + this.props.transaction.Balance.toFixed(security.Precision);
|
||||
status = TransactionStatusMap[this.props.transaction.Status];
|
||||
number = thisAccountSplit.Number;
|
||||
} else {
|
||||
var amount = security.Symbol + " " + (new Big(0.0)).toFixed(security.Precision);
|
||||
@ -216,19 +216,12 @@ const AddEditTransactionModal = React.createClass({
|
||||
})
|
||||
});
|
||||
},
|
||||
handleStatusChange: function(status) {
|
||||
if (status.hasOwnProperty('StatusId')) {
|
||||
this.setState({
|
||||
transaction: react_update(this.state.transaction, {
|
||||
Status: {$set: status.StatusId}
|
||||
})
|
||||
});
|
||||
}
|
||||
},
|
||||
handleAddSplit: function() {
|
||||
var split = new Split();
|
||||
split.Status = SplitStatus.Entered;
|
||||
this.setState({
|
||||
transaction: react_update(this.state.transaction, {
|
||||
Splits: {$push: [new Split()]}
|
||||
Splits: {$push: [split]}
|
||||
})
|
||||
});
|
||||
},
|
||||
@ -248,6 +241,15 @@ const AddEditTransactionModal = React.createClass({
|
||||
transaction: transaction
|
||||
});
|
||||
},
|
||||
handleUpdateStatus: function(status, split) {
|
||||
var transaction = this.state.transaction;
|
||||
transaction.Splits[split] = react_update(transaction.Splits[split], {
|
||||
Status: {$set: status.StatusId}
|
||||
});
|
||||
this.setState({
|
||||
transaction: transaction
|
||||
});
|
||||
},
|
||||
handleUpdateMemo: function(split) {
|
||||
var transaction = this.state.transaction;
|
||||
transaction.Splits[split] = react_update(transaction.Splits[split], {
|
||||
@ -345,6 +347,10 @@ const AddEditTransactionModal = React.createClass({
|
||||
var j = i;
|
||||
return function() {self.handleUpdateNumber(j);};
|
||||
})();
|
||||
var updateStatusFn = (function() {
|
||||
var j = i;
|
||||
return function(status) {self.handleUpdateStatus(status, j);};
|
||||
})();
|
||||
var updateMemoFn = (function() {
|
||||
var j = i;
|
||||
return function() {self.handleUpdateMemo(j);};
|
||||
@ -374,7 +380,17 @@ const AddEditTransactionModal = React.createClass({
|
||||
value={s.Number}
|
||||
onChange={updateNumberFn}
|
||||
ref={"number-"+i} /></Col>
|
||||
<Col xs={5}><FormControl
|
||||
<Col xs={1}>
|
||||
<Combobox
|
||||
suggest
|
||||
data={SplitStatusList}
|
||||
valueField='StatusId'
|
||||
textField='Name'
|
||||
defaultValue={s.Status}
|
||||
onSelect={updateStatusFn}
|
||||
ref={"status-"+i} />
|
||||
</Col>
|
||||
<Col xs={4}><FormControl
|
||||
type="text"
|
||||
value={s.Memo}
|
||||
onChange={updateMemoFn}
|
||||
@ -424,23 +440,11 @@ const AddEditTransactionModal = React.createClass({
|
||||
ref="description"/>
|
||||
</Col>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<Col componentClass={ControlLabel} xs={2}>Status</Col>
|
||||
<Col xs={10}>
|
||||
<Combobox
|
||||
suggest
|
||||
data={TransactionStatusList}
|
||||
valueField='StatusId'
|
||||
textField='Name'
|
||||
defaultValue={this.state.transaction.Status}
|
||||
onSelect={this.handleStatusChange}
|
||||
ref="status" />
|
||||
</Col>
|
||||
</FormGroup>
|
||||
|
||||
<Grid fluid={true}><Row>
|
||||
<span className="split-header col-xs-1">#</span>
|
||||
<span className="split-header col-xs-5">Memo</span>
|
||||
<span className="split-header col-xs-1">Status</span>
|
||||
<span className="split-header col-xs-4">Memo</span>
|
||||
<span className="split-header col-xs-3">Account</span>
|
||||
<span className="split-header col-xs-2">Amount</span>
|
||||
</Row>
|
||||
@ -680,10 +684,11 @@ module.exports = React.createClass({
|
||||
},
|
||||
handleNewTransactionClicked: function() {
|
||||
var newTransaction = new Transaction();
|
||||
newTransaction.Status = TransactionStatus.Entered;
|
||||
newTransaction.Date = new Date();
|
||||
newTransaction.Splits.push(new Split());
|
||||
newTransaction.Splits.push(new Split());
|
||||
newTransaction.Splits[0].Status = SplitStatus.Entered;
|
||||
newTransaction.Splits[1].Status = SplitStatus.Entered;
|
||||
newTransaction.Splits[0].AccountId = this.props.accounts[this.props.selectedAccount].AccountId;
|
||||
|
||||
this.setState({
|
||||
|
54
js/models.js
54
js/models.js
@ -202,11 +202,32 @@ Account.prototype.isRootAccount = function() {
|
||||
return this.ParentAccountId == empty_account.ParentAccountId;
|
||||
}
|
||||
|
||||
const SplitStatus = {
|
||||
Imported: 1,
|
||||
Entered: 2,
|
||||
Cleared: 3,
|
||||
Reconciled: 4,
|
||||
Voided: 5
|
||||
}
|
||||
var SplitStatusList = [];
|
||||
for (var type in SplitStatus) {
|
||||
if (SplitStatus.hasOwnProperty(type)) {
|
||||
SplitStatusList.push({'StatusId': SplitStatus[type], 'Name': type});
|
||||
}
|
||||
}
|
||||
var SplitStatusMap = {};
|
||||
for (var status in SplitStatus) {
|
||||
if (SplitStatus.hasOwnProperty(status)) {
|
||||
SplitStatusMap[SplitStatus[status]] = status;
|
||||
}
|
||||
}
|
||||
|
||||
function Split() {
|
||||
this.SplitId = -1;
|
||||
this.TransactionId = -1;
|
||||
this.AccountId = -1;
|
||||
this.SecurityId = -1;
|
||||
this.Status = -1;
|
||||
this.Number = "";
|
||||
this.Memo = "";
|
||||
this.Amount = new Big(0.0);
|
||||
@ -219,6 +240,7 @@ Split.prototype.toJSONobj = function() {
|
||||
json_obj.TransactionId = this.TransactionId;
|
||||
json_obj.AccountId = this.AccountId;
|
||||
json_obj.SecurityId = this.SecurityId;
|
||||
json_obj.Status = this.Status;
|
||||
json_obj.Number = this.Number;
|
||||
json_obj.Memo = this.Memo;
|
||||
json_obj.Amount = this.Amount.toFixed();
|
||||
@ -235,6 +257,8 @@ Split.prototype.fromJSONobj = function(json_obj) {
|
||||
this.AccountId = json_obj.AccountId;
|
||||
if (json_obj.hasOwnProperty("SecurityId"))
|
||||
this.SecurityId = json_obj.SecurityId;
|
||||
if (json_obj.hasOwnProperty("Status"))
|
||||
this.Status = json_obj.Status;
|
||||
if (json_obj.hasOwnProperty("Number"))
|
||||
this.Number = json_obj.Number;
|
||||
if (json_obj.hasOwnProperty("Memo"))
|
||||
@ -253,31 +277,10 @@ Split.prototype.isSplit = function() {
|
||||
this.SecurityId != empty_split.SecurityId;
|
||||
}
|
||||
|
||||
const TransactionStatus = {
|
||||
Imported: 1,
|
||||
Entered: 2,
|
||||
Cleared: 3,
|
||||
Reconciled: 4,
|
||||
Voided: 5
|
||||
}
|
||||
var TransactionStatusList = [];
|
||||
for (var type in TransactionStatus) {
|
||||
if (TransactionStatus.hasOwnProperty(type)) {
|
||||
TransactionStatusList.push({'StatusId': TransactionStatus[type], 'Name': type});
|
||||
}
|
||||
}
|
||||
var TransactionStatusMap = {};
|
||||
for (var status in TransactionStatus) {
|
||||
if (TransactionStatus.hasOwnProperty(status)) {
|
||||
TransactionStatusMap[TransactionStatus[status]] = status;
|
||||
}
|
||||
}
|
||||
|
||||
function Transaction() {
|
||||
this.TransactionId = -1;
|
||||
this.UserId = -1;
|
||||
this.Description = "";
|
||||
this.Status = -1;
|
||||
this.Date = new Date();
|
||||
this.Splits = [];
|
||||
}
|
||||
@ -287,7 +290,6 @@ Transaction.prototype.toJSON = function() {
|
||||
json_obj.TransactionId = this.TransactionId;
|
||||
json_obj.UserId = this.UserId;
|
||||
json_obj.Description = this.Description;
|
||||
json_obj.Status = this.Status;
|
||||
json_obj.Date = this.Date.toJSON();
|
||||
json_obj.Splits = [];
|
||||
for (var i = 0; i < this.Splits.length; i++)
|
||||
@ -304,8 +306,6 @@ Transaction.prototype.fromJSON = function(json_input) {
|
||||
this.UserId = json_obj.UserId;
|
||||
if (json_obj.hasOwnProperty("Description"))
|
||||
this.Description = json_obj.Description;
|
||||
if (json_obj.hasOwnProperty("Status"))
|
||||
this.Status = json_obj.Status;
|
||||
if (json_obj.hasOwnProperty("Date")) {
|
||||
this.Date = json_obj.Date
|
||||
if (typeof this.Date === 'string') {
|
||||
@ -541,9 +541,9 @@ module.exports = models = {
|
||||
AccountTypeList: AccountTypeList,
|
||||
SecurityType: SecurityType,
|
||||
SecurityTypeList: SecurityTypeList,
|
||||
TransactionStatus: TransactionStatus,
|
||||
TransactionStatusList: TransactionStatusList,
|
||||
TransactionStatusMap: TransactionStatusMap,
|
||||
SplitStatus: SplitStatus,
|
||||
SplitStatusList: SplitStatusList,
|
||||
SplitStatusMap: SplitStatusMap,
|
||||
|
||||
// Constants
|
||||
BogusPassword: "password"
|
||||
|
Reference in New Issue
Block a user