2016-02-12 20:36:59 -05:00
|
|
|
var React = require('react');
|
|
|
|
var ReactDOM = require('react-dom');
|
2015-08-05 21:25:25 -04:00
|
|
|
|
2016-02-12 20:36:59 -05:00
|
|
|
var react_update = require('react-addons-update');
|
|
|
|
|
|
|
|
var ReactBootstrap = require('react-bootstrap');
|
2015-08-29 09:50:16 -04:00
|
|
|
var Alert = ReactBootstrap.Alert;
|
2015-08-05 21:25:25 -04:00
|
|
|
var Modal = ReactBootstrap.Modal;
|
2015-08-11 07:00:58 -04:00
|
|
|
var Pagination = ReactBootstrap.Pagination;
|
2015-08-05 21:25:25 -04:00
|
|
|
var Label = ReactBootstrap.Label;
|
|
|
|
var Table = ReactBootstrap.Table;
|
|
|
|
var Grid = ReactBootstrap.Grid;
|
|
|
|
var Row = ReactBootstrap.Row;
|
|
|
|
var Col = ReactBootstrap.Col;
|
2016-02-09 21:30:07 -05:00
|
|
|
var Panel = ReactBootstrap.Panel;
|
2016-09-27 11:30:39 -04:00
|
|
|
var Form = ReactBootstrap.Form;
|
|
|
|
var FormGroup = ReactBootstrap.FormGroup;
|
|
|
|
var FormControl = ReactBootstrap.FormControl;
|
|
|
|
var InputGroup = ReactBootstrap.InputGroup;
|
|
|
|
var ControlLabel = ReactBootstrap.ControlLabel;
|
|
|
|
var HelpBlock = ReactBootstrap.HelpBlock;
|
2015-08-11 07:00:58 -04:00
|
|
|
var Button = ReactBootstrap.Button;
|
2016-02-12 20:36:59 -05:00
|
|
|
var ButtonGroup = ReactBootstrap.ButtonGroup;
|
2015-08-11 07:00:58 -04:00
|
|
|
var ButtonToolbar = ReactBootstrap.ButtonToolbar;
|
2016-02-02 21:46:27 -05:00
|
|
|
var ProgressBar = ReactBootstrap.ProgressBar;
|
2016-02-12 20:36:59 -05:00
|
|
|
var Glyphicon = ReactBootstrap.Glyphicon;
|
|
|
|
|
2016-02-15 11:28:44 -05:00
|
|
|
var ReactWidgets = require('react-widgets')
|
|
|
|
var DateTimePicker = ReactWidgets.DateTimePicker;
|
|
|
|
var Combobox = ReactWidgets.Combobox;
|
|
|
|
var DropdownList = ReactWidgets.DropdownList;
|
2016-02-02 21:46:27 -05:00
|
|
|
|
2016-02-13 17:06:32 -05:00
|
|
|
var Big = require('big.js');
|
|
|
|
|
2016-10-05 13:45:09 -04:00
|
|
|
var models = require('../models');
|
2016-02-13 16:31:12 -05:00
|
|
|
var Security = models.Security;
|
|
|
|
var Account = models.Account;
|
2017-05-31 08:23:19 -04:00
|
|
|
var SplitStatus = models.SplitStatus;
|
|
|
|
var SplitStatusList = models.SplitStatusList;
|
|
|
|
var SplitStatusMap = models.SplitStatusMap;
|
2016-02-13 16:31:12 -05:00
|
|
|
var Split = models.Split;
|
|
|
|
var Transaction = models.Transaction;
|
|
|
|
var Error = models.Error;
|
|
|
|
|
2016-10-05 13:45:09 -04:00
|
|
|
var getAccountDisplayName = require('../utils').getAccountDisplayName;
|
2016-02-13 16:41:44 -05:00
|
|
|
|
2016-10-05 13:45:09 -04:00
|
|
|
var AccountCombobox = require('./AccountCombobox');
|
2015-08-05 21:25:25 -04:00
|
|
|
|
2017-06-07 19:12:53 -04:00
|
|
|
class TransactionRow extends React.Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.onClick = this.handleClick.bind(this);
|
|
|
|
}
|
|
|
|
handleClick(e) {
|
2015-08-05 21:25:25 -04:00
|
|
|
const refs = ["date", "number", "description", "account", "status", "amount"];
|
|
|
|
for (var ref in refs) {
|
2016-02-12 20:36:59 -05:00
|
|
|
if (this.refs[refs[ref]] == e.target) {
|
2017-05-24 19:47:18 -04:00
|
|
|
this.props.onSelect(this.props.transaction.TransactionId, refs[ref]);
|
2015-08-05 21:25:25 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
render() {
|
2015-08-05 21:25:25 -04:00
|
|
|
var date = this.props.transaction.Date;
|
|
|
|
var dateString = date.getFullYear() + "/" + (date.getMonth()+1) + "/" + date.getDate();
|
|
|
|
var number = ""
|
|
|
|
var accountName = "";
|
|
|
|
var status = "";
|
2016-10-05 13:36:47 -04:00
|
|
|
var security = this.props.securities[this.props.account.SecurityId];
|
2017-05-24 19:47:18 -04:00
|
|
|
var balance = security.Symbol + " " + "?"
|
2015-08-05 21:25:25 -04:00
|
|
|
|
|
|
|
if (this.props.transaction.isTransaction()) {
|
|
|
|
var thisAccountSplit;
|
|
|
|
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];
|
2017-05-31 08:23:19 -04:00
|
|
|
status = SplitStatusMap[this.props.transaction.Splits[i].Status];
|
2015-08-05 21:25:25 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.props.transaction.Splits.length == 2) {
|
|
|
|
var otherSplit = this.props.transaction.Splits[0];
|
|
|
|
if (otherSplit.AccountId == this.props.account.AccountId)
|
|
|
|
var otherSplit = this.props.transaction.Splits[1];
|
2016-02-02 21:46:27 -05:00
|
|
|
|
|
|
|
if (otherSplit.AccountId == -1)
|
2016-10-05 13:36:47 -04:00
|
|
|
var accountName = "Unbalanced " + this.props.securities[otherSplit.SecurityId].Symbol + " transaction";
|
2016-02-02 21:46:27 -05:00
|
|
|
else
|
2016-10-05 13:36:47 -04:00
|
|
|
var accountName = getAccountDisplayName(this.props.accounts[otherSplit.AccountId], this.props.accounts);
|
2015-08-05 21:25:25 -04:00
|
|
|
} else {
|
|
|
|
accountName = "--Split Transaction--";
|
|
|
|
}
|
|
|
|
|
2015-08-26 07:38:13 -04:00
|
|
|
var amount = security.Symbol + " " + thisAccountSplit.Amount.toFixed(security.Precision);
|
2017-05-24 19:47:18 -04:00
|
|
|
if (this.props.transaction.hasOwnProperty("Balance"))
|
|
|
|
balance = security.Symbol + " " + this.props.transaction.Balance.toFixed(security.Precision);
|
2015-08-05 21:25:25 -04:00
|
|
|
number = thisAccountSplit.Number;
|
|
|
|
} else {
|
2015-08-26 07:38:13 -04:00
|
|
|
var amount = security.Symbol + " " + (new Big(0.0)).toFixed(security.Precision);
|
2015-08-05 21:25:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<tr>
|
2017-06-07 19:12:53 -04:00
|
|
|
<td ref="date" onClick={this.onClick}>{dateString}</td>
|
|
|
|
<td ref="number" onClick={this.onClick}>{number}</td>
|
|
|
|
<td ref="description" onClick={this.onClick}>{this.props.transaction.Description}</td>
|
|
|
|
<td ref="account" onClick={this.onClick}>{accountName}</td>
|
|
|
|
<td ref="status" onClick={this.onClick}>{status}</td>
|
|
|
|
<td ref="amount" onClick={this.onClick}>{amount}</td>
|
2015-08-21 06:54:17 -04:00
|
|
|
<td>{balance}</td>
|
2015-08-05 21:25:25 -04:00
|
|
|
</tr>);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class AmountInput extends React.Component {
|
|
|
|
getInitialState(props) {
|
|
|
|
if (!props)
|
|
|
|
return {
|
|
|
|
LastGoodAmount: "0",
|
|
|
|
Amount: "0"
|
|
|
|
}
|
2015-08-05 21:25:25 -04:00
|
|
|
|
2015-08-26 07:16:57 -04:00
|
|
|
// Ensure we can edit this without screwing up other copies of it
|
2015-08-26 07:38:13 -04:00
|
|
|
var a;
|
|
|
|
if (props.security)
|
|
|
|
a = props.value.toFixed(props.security.Precision);
|
|
|
|
else
|
|
|
|
a = props.value.toString();
|
|
|
|
|
2015-08-26 07:16:57 -04:00
|
|
|
return {
|
|
|
|
LastGoodAmount: a,
|
|
|
|
Amount: a
|
|
|
|
};
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.onChange = this.handleChange.bind(this);
|
|
|
|
this.state = this.getInitialState();
|
|
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2015-08-26 07:38:13 -04:00
|
|
|
if ((!nextProps.value.eq(this.props.value) &&
|
|
|
|
!nextProps.value.eq(this.getValue())) ||
|
|
|
|
nextProps.security !== this.props.security) {
|
2017-06-07 19:12:53 -04:00
|
|
|
this.setState(this.getInitialState(nextProps));
|
2015-08-26 07:16:57 -04:00
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
componentDidMount() {
|
|
|
|
ReactDOM.findDOMNode(this.refs.amount).onblur = this.handleBlur.bind(this);
|
|
|
|
}
|
|
|
|
handleBlur() {
|
2015-08-26 07:38:13 -04:00
|
|
|
var a;
|
|
|
|
if (this.props.security)
|
|
|
|
a = (new Big(this.getValue())).toFixed(this.props.security.Precision);
|
|
|
|
else
|
|
|
|
a = (new Big(this.getValue())).toString();
|
2015-08-26 07:16:57 -04:00
|
|
|
this.setState({
|
2015-08-26 07:38:13 -04:00
|
|
|
Amount: a
|
2015-08-26 07:16:57 -04:00
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleChange() {
|
2016-09-27 11:30:39 -04:00
|
|
|
this.setState({Amount: ReactDOM.findDOMNode(this.refs.amount).value});
|
2015-08-26 07:16:57 -04:00
|
|
|
if (this.props.onChange)
|
|
|
|
this.props.onChange();
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
getValue() {
|
2015-08-26 07:16:57 -04:00
|
|
|
try {
|
2016-09-27 11:30:39 -04:00
|
|
|
var value = ReactDOM.findDOMNode(this.refs.amount).value;
|
2015-08-26 07:16:57 -04:00
|
|
|
var ret = new Big(value);
|
|
|
|
this.setState({LastGoodAmount: value});
|
|
|
|
return ret;
|
|
|
|
} catch(err) {
|
|
|
|
return new Big(this.state.LastGoodAmount);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
render() {
|
2015-08-26 07:38:13 -04:00
|
|
|
var symbol = "?";
|
|
|
|
if (this.props.security)
|
|
|
|
symbol = this.props.security.Symbol;
|
|
|
|
|
2015-08-26 07:16:57 -04:00
|
|
|
return (
|
2016-09-27 11:30:39 -04:00
|
|
|
<FormGroup validationState={this.props.validationState}>
|
|
|
|
<InputGroup>
|
|
|
|
<InputGroup.Addon>{symbol}</InputGroup.Addon>
|
|
|
|
<FormControl type="text"
|
|
|
|
value={this.state.Amount}
|
|
|
|
onChange={this.onChange}
|
|
|
|
ref="amount"/>
|
|
|
|
</InputGroup>
|
|
|
|
</FormGroup>
|
2015-08-26 07:16:57 -04:00
|
|
|
);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
2015-08-26 07:16:57 -04:00
|
|
|
|
2017-06-07 19:12:53 -04:00
|
|
|
class AddEditTransactionModal extends React.Component {
|
|
|
|
getInitialState(props) {
|
2015-08-05 21:25:25 -04:00
|
|
|
// Ensure we can edit this without screwing up other copies of it
|
2017-06-07 19:12:53 -04:00
|
|
|
if (props)
|
|
|
|
var t = props.transaction.deepCopy();
|
|
|
|
else
|
|
|
|
var t = new Transaction();
|
|
|
|
|
2015-08-29 09:50:16 -04:00
|
|
|
return {
|
|
|
|
errorAlert: [],
|
|
|
|
transaction: t
|
|
|
|
};
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = this.getInitialState();
|
|
|
|
this.onCancel = this.handleCancel.bind(this);
|
|
|
|
this.onDescriptionChange = this.handleDescriptionChange.bind(this);
|
|
|
|
this.onDateChange = this.handleDateChange.bind(this);
|
|
|
|
this.onAddSplit = this.handleAddSplit.bind(this);
|
|
|
|
this.onDeleteSplit = this.handleDeleteSplit.bind(this);
|
|
|
|
this.onUpdateNumber = this.handleUpdateNumber.bind(this);
|
|
|
|
this.onUpdateStatus = this.handleUpdateStatus.bind(this);
|
|
|
|
this.onUpdateMemo = this.handleUpdateMemo.bind(this);
|
|
|
|
this.onUpdateAccount = this.handleUpdateAccount.bind(this);
|
|
|
|
this.onUpdateAmount = this.handleUpdateAmount.bind(this);
|
|
|
|
this.onSubmit = this.handleSubmit.bind(this);
|
|
|
|
this.onDelete = this.handleDelete.bind(this);
|
|
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2015-08-26 07:16:57 -04:00
|
|
|
if (nextProps.show && !this.props.show) {
|
2017-06-07 19:12:53 -04:00
|
|
|
this.setState(this.getInitialState(nextProps));
|
2015-08-26 07:16:57 -04:00
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleCancel() {
|
2015-08-05 21:25:25 -04:00
|
|
|
if (this.props.onCancel != null)
|
|
|
|
this.props.onCancel();
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleDescriptionChange() {
|
2015-08-05 21:25:25 -04:00
|
|
|
this.setState({
|
2016-02-12 20:36:59 -05:00
|
|
|
transaction: react_update(this.state.transaction, {
|
2016-09-27 11:30:39 -04:00
|
|
|
Description: {$set: ReactDOM.findDOMNode(this.refs.description).value}
|
2015-08-26 07:16:57 -04:00
|
|
|
})
|
2015-08-05 21:25:25 -04:00
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleDateChange(date, string) {
|
2015-08-05 21:25:25 -04:00
|
|
|
if (date == null)
|
|
|
|
return;
|
|
|
|
this.setState({
|
2016-02-12 20:36:59 -05:00
|
|
|
transaction: react_update(this.state.transaction, {
|
2015-08-26 07:16:57 -04:00
|
|
|
Date: {$set: date}
|
|
|
|
})
|
2015-08-05 21:25:25 -04:00
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleAddSplit() {
|
2017-05-31 08:23:19 -04:00
|
|
|
var split = new Split();
|
|
|
|
split.Status = SplitStatus.Entered;
|
2015-08-26 21:02:06 -04:00
|
|
|
this.setState({
|
2016-02-12 20:36:59 -05:00
|
|
|
transaction: react_update(this.state.transaction, {
|
2017-05-31 08:23:19 -04:00
|
|
|
Splits: {$push: [split]}
|
2015-08-26 21:02:06 -04:00
|
|
|
})
|
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleDeleteSplit(split) {
|
2015-08-05 21:25:25 -04:00
|
|
|
this.setState({
|
2016-02-12 20:36:59 -05:00
|
|
|
transaction: react_update(this.state.transaction, {
|
2015-08-26 07:16:57 -04:00
|
|
|
Splits: {$splice: [[split, 1]]}
|
|
|
|
})
|
2015-08-05 21:25:25 -04:00
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleUpdateNumber(split) {
|
2015-08-26 07:16:57 -04:00
|
|
|
var transaction = this.state.transaction;
|
2016-02-12 20:36:59 -05:00
|
|
|
transaction.Splits[split] = react_update(transaction.Splits[split], {
|
2016-09-27 11:30:39 -04:00
|
|
|
Number: {$set: ReactDOM.findDOMNode(this.refs['number-'+split]).value}
|
2015-08-26 07:16:57 -04:00
|
|
|
});
|
2015-08-05 21:25:25 -04:00
|
|
|
this.setState({
|
|
|
|
transaction: transaction
|
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleUpdateStatus(status, split) {
|
2017-05-31 08:23:19 -04:00
|
|
|
var transaction = this.state.transaction;
|
|
|
|
transaction.Splits[split] = react_update(transaction.Splits[split], {
|
|
|
|
Status: {$set: status.StatusId}
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
transaction: transaction
|
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleUpdateMemo(split) {
|
2015-08-26 07:16:57 -04:00
|
|
|
var transaction = this.state.transaction;
|
2016-02-12 20:36:59 -05:00
|
|
|
transaction.Splits[split] = react_update(transaction.Splits[split], {
|
2016-09-27 11:30:39 -04:00
|
|
|
Memo: {$set: ReactDOM.findDOMNode(this.refs['memo-'+split]).value}
|
2015-08-26 07:16:57 -04:00
|
|
|
});
|
2015-08-05 21:25:25 -04:00
|
|
|
this.setState({
|
|
|
|
transaction: transaction
|
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleUpdateAccount(account, split) {
|
2015-08-26 07:16:57 -04:00
|
|
|
var transaction = this.state.transaction;
|
2016-02-12 20:36:59 -05:00
|
|
|
transaction.Splits[split] = react_update(transaction.Splits[split], {
|
2016-02-02 21:46:27 -05:00
|
|
|
SecurityId: {$set: -1},
|
2015-08-26 07:16:57 -04:00
|
|
|
AccountId: {$set: account.AccountId}
|
|
|
|
});
|
2015-08-05 21:25:25 -04:00
|
|
|
this.setState({
|
|
|
|
transaction: transaction
|
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleUpdateAmount(split) {
|
2015-08-26 07:16:57 -04:00
|
|
|
var transaction = this.state.transaction;
|
2016-02-12 20:36:59 -05:00
|
|
|
transaction.Splits[split] = react_update(transaction.Splits[split], {
|
2015-08-26 07:16:57 -04:00
|
|
|
Amount: {$set: new Big(this.refs['amount-'+split].getValue())}
|
|
|
|
});
|
2015-08-05 21:25:25 -04:00
|
|
|
this.setState({
|
|
|
|
transaction: transaction
|
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleSubmit() {
|
2015-08-29 09:50:16 -04:00
|
|
|
var errorString = ""
|
2016-10-05 13:36:47 -04:00
|
|
|
var imbalancedSecurityList = this.state.transaction.imbalancedSplitSecurities(this.props.accounts);
|
2015-08-29 09:50:16 -04:00
|
|
|
if (imbalancedSecurityList.length > 0)
|
|
|
|
errorString = "Transaction must balance"
|
|
|
|
for (var i = 0; i < this.state.transaction.Splits.length; i++) {
|
|
|
|
var s = this.state.transaction.Splits[i];
|
2016-10-05 13:36:47 -04:00
|
|
|
if (!(s.AccountId in this.props.accounts)) {
|
2015-08-29 09:50:16 -04:00
|
|
|
errorString = "All accounts must be valid"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errorString.length > 0) {
|
|
|
|
this.setState({
|
|
|
|
errorAlert: (<Alert className='saving-transaction-alert' bsStyle='danger'><strong>Error Saving Transaction:</strong> {errorString}</Alert>)
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-05 21:25:25 -04:00
|
|
|
if (this.props.onSubmit != null)
|
|
|
|
this.props.onSubmit(this.state.transaction);
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleDelete() {
|
2015-08-05 21:25:25 -04:00
|
|
|
if (this.props.onDelete != null)
|
|
|
|
this.props.onDelete(this.state.transaction);
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
render() {
|
2015-08-05 21:25:25 -04:00
|
|
|
var editing = this.props.transaction != null && this.props.transaction.isTransaction();
|
|
|
|
var headerText = editing ? "Edit" : "Create New";
|
|
|
|
var buttonText = editing ? "Save Changes" : "Create Transaction";
|
|
|
|
var deleteButton = [];
|
|
|
|
if (editing) {
|
|
|
|
deleteButton = (
|
2017-06-07 19:12:53 -04:00
|
|
|
<Button key={1} onClick={this.onDelete} bsStyle="danger">Delete Transaction</Button>
|
2015-08-05 21:25:25 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-05 13:36:47 -04:00
|
|
|
var imbalancedSecurityList = this.state.transaction.imbalancedSplitSecurities(this.props.accounts);
|
2015-08-29 09:50:16 -04:00
|
|
|
var imbalancedSecurityMap = {};
|
|
|
|
for (i = 0; i < imbalancedSecurityList.length; i++)
|
|
|
|
imbalancedSecurityMap[imbalancedSecurityList[i]] = i;
|
|
|
|
|
2017-06-07 19:12:53 -04:00
|
|
|
var splits = [];
|
2015-08-05 21:25:25 -04:00
|
|
|
for (var i = 0; i < this.state.transaction.Splits.length; i++) {
|
|
|
|
var self = this;
|
|
|
|
var s = this.state.transaction.Splits[i];
|
2015-08-26 07:38:13 -04:00
|
|
|
var security = null;
|
2016-02-12 20:36:59 -05:00
|
|
|
var amountValidation = undefined;
|
2015-08-29 09:50:16 -04:00
|
|
|
var accountValidation = "";
|
2016-10-05 13:36:47 -04:00
|
|
|
if (s.AccountId in this.props.accounts) {
|
|
|
|
security = this.props.securities[this.props.accounts[s.AccountId].SecurityId];
|
2015-08-29 09:50:16 -04:00
|
|
|
} else {
|
2016-10-05 13:36:47 -04:00
|
|
|
if (s.SecurityId in this.props.securities) {
|
|
|
|
security = this.props.securities[s.SecurityId];
|
2016-02-02 21:46:27 -05:00
|
|
|
}
|
2015-08-29 09:50:16 -04:00
|
|
|
accountValidation = "has-error";
|
|
|
|
}
|
2016-02-02 21:46:27 -05:00
|
|
|
if (security != null && security.SecurityId in imbalancedSecurityMap)
|
|
|
|
amountValidation = "error";
|
2015-08-05 21:25:25 -04:00
|
|
|
|
|
|
|
// Define all closures for calling split-updating functions
|
|
|
|
var deleteSplitFn = (function() {
|
|
|
|
var j = i;
|
2017-06-07 19:12:53 -04:00
|
|
|
return function() {self.onDeleteSplit(j);};
|
2015-08-05 21:25:25 -04:00
|
|
|
})();
|
|
|
|
var updateNumberFn = (function() {
|
|
|
|
var j = i;
|
2017-06-07 19:12:53 -04:00
|
|
|
return function() {self.onUpdateNumber(j);};
|
2015-08-05 21:25:25 -04:00
|
|
|
})();
|
2017-05-31 08:23:19 -04:00
|
|
|
var updateStatusFn = (function() {
|
|
|
|
var j = i;
|
2017-06-07 19:12:53 -04:00
|
|
|
return function(status) {self.onUpdateStatus(status, j);};
|
2017-05-31 08:23:19 -04:00
|
|
|
})();
|
2015-08-05 21:25:25 -04:00
|
|
|
var updateMemoFn = (function() {
|
|
|
|
var j = i;
|
2017-06-07 19:12:53 -04:00
|
|
|
return function() {self.onUpdateMemo(j);};
|
2015-08-05 21:25:25 -04:00
|
|
|
})();
|
|
|
|
var updateAccountFn = (function() {
|
|
|
|
var j = i;
|
2017-06-07 19:12:53 -04:00
|
|
|
return function(account) {self.onUpdateAccount(account, j);};
|
2015-08-05 21:25:25 -04:00
|
|
|
})();
|
|
|
|
var updateAmountFn = (function() {
|
|
|
|
var j = i;
|
2017-06-07 19:12:53 -04:00
|
|
|
return function() {self.onUpdateAmount(j);};
|
2015-08-05 21:25:25 -04:00
|
|
|
})();
|
|
|
|
|
|
|
|
var deleteSplitButton = [];
|
|
|
|
if (this.state.transaction.Splits.length > 2) {
|
|
|
|
deleteSplitButton = (
|
|
|
|
<Col xs={1}><Button onClick={deleteSplitFn}
|
|
|
|
bsStyle="danger">
|
|
|
|
<Glyphicon glyph='trash' /></Button></Col>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
splits.push((
|
2016-02-13 16:34:09 -05:00
|
|
|
<Row key={s.SplitId == -1 ? (i+999) : s.SplitId}>
|
2016-09-27 11:30:39 -04:00
|
|
|
<Col xs={1}><FormControl
|
2015-08-05 21:25:25 -04:00
|
|
|
type="text"
|
|
|
|
value={s.Number}
|
|
|
|
onChange={updateNumberFn}
|
|
|
|
ref={"number-"+i} /></Col>
|
2017-05-31 08:23:19 -04:00
|
|
|
<Col xs={1}>
|
|
|
|
<Combobox
|
|
|
|
suggest
|
|
|
|
data={SplitStatusList}
|
|
|
|
valueField='StatusId'
|
|
|
|
textField='Name'
|
|
|
|
defaultValue={s.Status}
|
|
|
|
onSelect={updateStatusFn}
|
|
|
|
ref={"status-"+i} />
|
|
|
|
</Col>
|
|
|
|
<Col xs={4}><FormControl
|
2015-08-05 21:25:25 -04:00
|
|
|
type="text"
|
|
|
|
value={s.Memo}
|
|
|
|
onChange={updateMemoFn}
|
|
|
|
ref={"memo-"+i} /></Col>
|
|
|
|
<Col xs={3}><AccountCombobox
|
|
|
|
accounts={this.props.accounts}
|
2016-10-05 13:36:47 -04:00
|
|
|
accountChildren={this.props.accountChildren}
|
2015-08-05 21:25:25 -04:00
|
|
|
value={s.AccountId}
|
|
|
|
includeRoot={false}
|
2016-02-12 20:36:59 -05:00
|
|
|
onChange={updateAccountFn}
|
2015-08-29 09:50:16 -04:00
|
|
|
ref={"account-"+i}
|
|
|
|
className={accountValidation}/></Col>
|
2015-08-26 07:16:57 -04:00
|
|
|
<Col xs={2}><AmountInput type="text"
|
2015-08-05 21:25:25 -04:00
|
|
|
value={s.Amount}
|
2015-08-26 07:16:57 -04:00
|
|
|
security={security}
|
2015-08-05 21:25:25 -04:00
|
|
|
onChange={updateAmountFn}
|
2015-08-29 09:50:16 -04:00
|
|
|
ref={"amount-"+i}
|
2016-09-27 11:30:39 -04:00
|
|
|
validationState={amountValidation}/></Col>
|
2015-08-05 21:25:25 -04:00
|
|
|
{deleteSplitButton}
|
|
|
|
</Row>
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-06-07 19:12:53 -04:00
|
|
|
<Modal show={this.props.show} onHide={this.onCancel} bsSize="large">
|
2015-08-05 21:25:25 -04:00
|
|
|
<Modal.Header closeButton>
|
|
|
|
<Modal.Title>{headerText} Transaction</Modal.Title>
|
|
|
|
</Modal.Header>
|
|
|
|
<Modal.Body>
|
2016-09-27 11:30:39 -04:00
|
|
|
<Form horizontal
|
2017-06-07 19:12:53 -04:00
|
|
|
onSubmit={this.onSubmit}>
|
2016-09-27 11:30:39 -04:00
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Date</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<DateTimePicker
|
|
|
|
time={false}
|
|
|
|
defaultValue={this.state.transaction.Date}
|
2017-06-07 19:12:53 -04:00
|
|
|
onChange={this.onDateChange} />
|
2016-09-27 11:30:39 -04:00
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Description</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<FormControl type="text"
|
|
|
|
value={this.state.transaction.Description}
|
2017-06-07 19:12:53 -04:00
|
|
|
onChange={this.onDescriptionChange}
|
2016-09-27 11:30:39 -04:00
|
|
|
ref="description"/>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
|
2015-08-05 21:25:25 -04:00
|
|
|
<Grid fluid={true}><Row>
|
|
|
|
<span className="split-header col-xs-1">#</span>
|
2017-05-31 08:23:19 -04:00
|
|
|
<span className="split-header col-xs-1">Status</span>
|
|
|
|
<span className="split-header col-xs-4">Memo</span>
|
2015-08-05 21:25:25 -04:00
|
|
|
<span className="split-header col-xs-3">Account</span>
|
|
|
|
<span className="split-header col-xs-2">Amount</span>
|
|
|
|
</Row>
|
|
|
|
{splits}
|
2015-08-26 21:02:06 -04:00
|
|
|
<Row>
|
|
|
|
<span className="col-xs-11"></span>
|
2017-06-07 19:12:53 -04:00
|
|
|
<Col xs={1}><Button onClick={this.onAddSplit}
|
2015-08-26 21:02:06 -04:00
|
|
|
bsStyle="success">
|
|
|
|
<Glyphicon glyph='plus-sign' /></Button></Col>
|
|
|
|
</Row>
|
2015-08-29 09:50:16 -04:00
|
|
|
<Row>{this.state.errorAlert}</Row>
|
2015-08-05 21:25:25 -04:00
|
|
|
</Grid>
|
2016-09-27 11:30:39 -04:00
|
|
|
</Form>
|
2015-08-05 21:25:25 -04:00
|
|
|
</Modal.Body>
|
|
|
|
<Modal.Footer>
|
2015-08-11 07:00:58 -04:00
|
|
|
<ButtonGroup>
|
2017-06-07 19:12:53 -04:00
|
|
|
<Button onClick={this.onCancel} bsStyle="warning">Cancel</Button>
|
2015-08-05 21:25:25 -04:00
|
|
|
{deleteButton}
|
2017-06-07 19:12:53 -04:00
|
|
|
<Button onClick={this.onSubmit} bsStyle="success">{buttonText}</Button>
|
2015-08-05 21:25:25 -04:00
|
|
|
</ButtonGroup>
|
|
|
|
</Modal.Footer>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
2015-08-05 21:25:25 -04:00
|
|
|
|
2016-02-15 11:28:44 -05:00
|
|
|
const ImportType = {
|
|
|
|
OFX: 1,
|
2017-06-04 16:01:42 -04:00
|
|
|
OFXFile: 2,
|
|
|
|
Gnucash: 3
|
2016-02-15 11:28:44 -05:00
|
|
|
};
|
|
|
|
var ImportTypeList = [];
|
|
|
|
for (var type in ImportType) {
|
|
|
|
if (ImportType.hasOwnProperty(type)) {
|
2017-06-04 16:01:42 -04:00
|
|
|
var name = ImportType[type] == ImportType.OFX ? "Direct OFX" : type;
|
|
|
|
var name = ImportType[type] == ImportType.OFXFile ? "OFX/QFX File" : type; //QFX is a special snowflake
|
2016-02-15 11:28:44 -05:00
|
|
|
ImportTypeList.push({'TypeId': ImportType[type], 'Name': name});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 19:12:53 -04:00
|
|
|
class ImportTransactionsModal extends React.Component {
|
|
|
|
getInitialState() {
|
2017-06-04 16:01:42 -04:00
|
|
|
var startDate = new Date();
|
|
|
|
startDate.setMonth(startDate.getMonth() - 1);
|
|
|
|
return {
|
2016-02-02 21:46:27 -05:00
|
|
|
importFile: "",
|
2017-06-05 21:01:04 -04:00
|
|
|
importType: ImportType.OFX,
|
2017-06-04 16:01:42 -04:00
|
|
|
startDate: startDate,
|
|
|
|
endDate: new Date(),
|
|
|
|
password: "",
|
|
|
|
};
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = this.getInitialState();
|
|
|
|
this.onCancel = this.handleCancel.bind(this);
|
|
|
|
this.onImportChange = this.handleImportChange.bind(this);
|
|
|
|
this.onTypeChange = this.handleTypeChange.bind(this);
|
|
|
|
this.onPasswordChange = this.handlePasswordChange.bind(this);
|
|
|
|
this.onStartDateChange = this.handleStartDateChange.bind(this);
|
|
|
|
this.onEndDateChange = this.handleEndDateChange.bind(this);
|
|
|
|
this.onSubmit = this.handleSubmit.bind(this);
|
|
|
|
this.onImportTransactions = this.handleImportTransactions.bind(this);
|
|
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.show && !this.props.show) {
|
|
|
|
this.setState(this.getInitialState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handleCancel() {
|
2016-02-02 21:46:27 -05:00
|
|
|
if (this.props.onCancel != null)
|
|
|
|
this.props.onCancel();
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleImportChange() {
|
2016-09-27 11:30:39 -04:00
|
|
|
this.setState({importFile: ReactDOM.findDOMNode(this.refs.importfile).value});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleTypeChange(type) {
|
2016-02-15 11:28:44 -05:00
|
|
|
this.setState({importType: type.TypeId});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handlePasswordChange() {
|
2017-06-04 16:01:42 -04:00
|
|
|
this.setState({password: ReactDOM.findDOMNode(this.refs.password).value});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleStartDateChange(date, string) {
|
2017-06-04 16:01:42 -04:00
|
|
|
if (date == null)
|
|
|
|
return;
|
|
|
|
this.setState({
|
|
|
|
startDate: date
|
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleEndDateChange(date, string) {
|
2017-06-04 16:01:42 -04:00
|
|
|
if (date == null)
|
|
|
|
return;
|
|
|
|
this.setState({
|
|
|
|
endDate: date
|
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleSubmit() {
|
2016-02-02 21:46:27 -05:00
|
|
|
if (this.props.onSubmit != null)
|
|
|
|
this.props.onSubmit(this.props.account);
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleImportTransactions() {
|
2017-06-04 16:01:42 -04:00
|
|
|
if (this.state.importType == ImportType.OFX) {
|
|
|
|
this.props.onImportOFX(this.props.account, this.state.password, this.state.startDate, this.state.endDate);
|
|
|
|
} else if (this.state.importType == ImportType.OFXFile) {
|
|
|
|
this.props.onImportOFXFile(ReactDOM.findDOMNode(this.refs.importfile), this.props.account);
|
|
|
|
} else if (this.state.importType == ImportType.Gnucash) {
|
|
|
|
this.props.onImportGnucash(ReactDOM.findDOMNode(this.refs.importfile));
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
render() {
|
2016-02-15 11:28:44 -05:00
|
|
|
var accountNameLabel = "Performing global import:"
|
|
|
|
if (this.props.account != null && this.state.importType != ImportType.Gnucash)
|
2016-10-05 13:36:47 -04:00
|
|
|
accountNameLabel = "Importing to '" + getAccountDisplayName(this.props.account, this.props.accounts) + "' account:";
|
2016-02-15 11:28:44 -05:00
|
|
|
|
|
|
|
// Display the progress bar if an upload/import is in progress
|
2016-02-02 21:46:27 -05:00
|
|
|
var progressBar = [];
|
2017-06-04 16:01:42 -04:00
|
|
|
if (this.props.imports.importing && this.props.imports.uploadProgress == 100) {
|
|
|
|
progressBar = (<ProgressBar now={this.props.imports.uploadProgress} active label="Importing transactions..." />);
|
|
|
|
} else if (this.props.imports.importing) {
|
|
|
|
progressBar = (<ProgressBar now={this.props.imports.uploadProgress} active label={`Uploading... ${this.props.imports.uploadProgress}%`} />);
|
2016-02-09 21:30:07 -05:00
|
|
|
}
|
|
|
|
|
2016-02-15 11:28:44 -05:00
|
|
|
// Create panel, possibly displaying error or success messages
|
2016-02-09 21:30:07 -05:00
|
|
|
var panel = [];
|
2017-06-04 16:01:42 -04:00
|
|
|
if (this.props.imports.importFailed) {
|
|
|
|
panel = (<Panel header="Error Importing Transactions" bsStyle="danger">{this.props.imports.errorMessage}</Panel>);
|
|
|
|
} else if (this.props.imports.importFinished) {
|
2016-02-09 21:30:07 -05:00
|
|
|
panel = (<Panel header="Successfully Imported Transactions" bsStyle="success">Your import is now complete.</Panel>);
|
|
|
|
}
|
|
|
|
|
2016-02-15 11:28:44 -05:00
|
|
|
// Display proper buttons, possibly disabling them if an import is in progress
|
2016-02-09 21:30:07 -05:00
|
|
|
var button1 = [];
|
|
|
|
var button2 = [];
|
2017-06-04 16:01:42 -04:00
|
|
|
if (!this.props.imports.importFinished && !this.props.imports.importFailed) {
|
|
|
|
var importingDisabled = this.props.imports.importing || (this.state.importType != ImportType.OFX && this.state.importFile == "") || (this.state.importType == ImportType.OFX && this.state.password == "");
|
2017-06-07 19:12:53 -04:00
|
|
|
button1 = (<Button onClick={this.onCancel} disabled={this.props.imports.importing} bsStyle="warning">Cancel</Button>);
|
|
|
|
button2 = (<Button onClick={this.onImportTransactions} disabled={importingDisabled} bsStyle="success">Import</Button>);
|
2016-02-09 21:30:07 -05:00
|
|
|
} else {
|
2017-06-07 19:12:53 -04:00
|
|
|
button1 = (<Button onClick={this.onSubmit} disabled={this.props.imports.importing} bsStyle="success">OK</Button>);
|
2016-02-09 21:30:07 -05:00
|
|
|
}
|
2017-06-04 16:01:42 -04:00
|
|
|
var inputDisabled = (this.props.imports.importing || this.props.imports.importFailed || this.props.imports.importFinished) ? true : false;
|
2016-02-15 11:28:44 -05:00
|
|
|
|
|
|
|
// Disable OFX/QFX imports if no account is selected
|
|
|
|
var disabledTypes = false;
|
|
|
|
if (this.props.account == null)
|
2017-06-04 16:01:42 -04:00
|
|
|
disabledTypes = [ImportTypeList[ImportType.OFX - 1], ImportTypeList[ImportType.OFXFile - 1]];
|
|
|
|
|
|
|
|
var importForm = [];
|
|
|
|
if (this.state.importType == ImportType.OFX) {
|
|
|
|
importForm = (
|
|
|
|
<div>
|
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>OFX Password</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<FormControl type="password"
|
|
|
|
value={this.state.password}
|
|
|
|
placeholder="Password..."
|
|
|
|
ref="password"
|
2017-06-07 19:12:53 -04:00
|
|
|
onChange={this.onPasswordChange} />
|
2017-06-04 16:01:42 -04:00
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Start Date</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<DateTimePicker
|
|
|
|
time={false}
|
|
|
|
defaultValue={this.state.startDate}
|
2017-06-07 19:12:53 -04:00
|
|
|
onChange={this.onStartDateChange} />
|
2017-06-04 16:01:42 -04:00
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>End Date</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<DateTimePicker
|
|
|
|
time={false}
|
|
|
|
defaultValue={this.state.endDate}
|
2017-06-07 19:12:53 -04:00
|
|
|
onChange={this.onEndDateChange} />
|
2017-06-04 16:01:42 -04:00
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
importForm = (
|
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>File</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<FormControl type="file"
|
|
|
|
ref="importfile"
|
|
|
|
disabled={inputDisabled}
|
|
|
|
value={this.state.importFile}
|
2017-06-07 19:12:53 -04:00
|
|
|
onChange={this.onImportChange} />
|
2017-06-04 16:01:42 -04:00
|
|
|
<HelpBlock>Select a file to upload.</HelpBlock>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
);
|
|
|
|
}
|
2016-02-15 11:28:44 -05:00
|
|
|
|
2016-02-02 21:46:27 -05:00
|
|
|
return (
|
2017-06-07 19:12:53 -04:00
|
|
|
<Modal show={this.props.show} onHide={this.onCancel}>
|
2016-02-02 21:46:27 -05:00
|
|
|
<Modal.Header closeButton>
|
|
|
|
<Modal.Title>Import Transactions</Modal.Title>
|
|
|
|
</Modal.Header>
|
|
|
|
<Modal.Body>
|
2017-06-07 19:12:53 -04:00
|
|
|
<Form horizontal onSubmit={this.onImportTransactions}
|
2016-02-02 21:46:27 -05:00
|
|
|
encType="multipart/form-data"
|
|
|
|
ref="importform">
|
2017-06-04 16:01:42 -04:00
|
|
|
<FormGroup>
|
|
|
|
<Col xs={12}>
|
|
|
|
<ControlLabel>{accountNameLabel}</ControlLabel>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Import Type</Col>
|
|
|
|
<Col xs={10}>
|
2016-02-15 11:28:44 -05:00
|
|
|
<DropdownList
|
|
|
|
data={ImportTypeList}
|
|
|
|
valueField='TypeId'
|
|
|
|
textField='Name'
|
2017-06-07 19:12:53 -04:00
|
|
|
onSelect={this.onTypeChange}
|
2016-02-15 11:28:44 -05:00
|
|
|
defaultValue={this.state.importType}
|
|
|
|
disabled={disabledTypes}
|
|
|
|
ref="importtype" />
|
2017-06-04 16:01:42 -04:00
|
|
|
</Col>
|
2016-09-27 11:30:39 -04:00
|
|
|
</FormGroup>
|
2017-06-04 16:01:42 -04:00
|
|
|
{importForm}
|
|
|
|
</Form>
|
2016-02-02 21:46:27 -05:00
|
|
|
{progressBar}
|
2016-02-09 21:30:07 -05:00
|
|
|
{panel}
|
2016-02-02 21:46:27 -05:00
|
|
|
</Modal.Body>
|
|
|
|
<Modal.Footer>
|
|
|
|
<ButtonGroup>
|
2016-02-09 21:30:07 -05:00
|
|
|
{button1}
|
|
|
|
{button2}
|
2016-02-02 21:46:27 -05:00
|
|
|
</ButtonGroup>
|
|
|
|
</Modal.Footer>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
2016-02-02 21:46:27 -05:00
|
|
|
|
2017-06-07 19:12:53 -04:00
|
|
|
class AccountRegister extends React.Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
2017-05-24 19:47:18 -04:00
|
|
|
newTransaction: null,
|
2015-08-11 07:00:58 -04:00
|
|
|
height: 0
|
2015-08-05 21:25:25 -04:00
|
|
|
};
|
2017-06-07 19:12:53 -04:00
|
|
|
this.onEditTransaction = this.handleEditTransaction.bind(this);
|
|
|
|
this.onEditingCancel = this.handleEditingCancel.bind(this);
|
|
|
|
this.onNewTransactionClicked = this.handleNewTransactionClicked.bind(this);
|
|
|
|
this.onSelectPage = this.handleSelectPage.bind(this);
|
|
|
|
this.onImportComplete = this.handleImportComplete.bind(this);
|
|
|
|
this.onUpdateTransaction = this.handleUpdateTransaction.bind(this);
|
|
|
|
this.onDeleteTransaction = this.handleDeleteTransaction.bind(this);
|
|
|
|
}
|
|
|
|
resize() {
|
2016-02-12 20:36:59 -05:00
|
|
|
var div = ReactDOM.findDOMNode(this);
|
2015-08-11 07:13:40 -04:00
|
|
|
this.setState({height: div.parentElement.clientHeight - 64});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2017-05-24 19:47:18 -04:00
|
|
|
if (!nextProps.transactionPage.upToDate && nextProps.selectedAccount != -1) {
|
|
|
|
nextProps.onFetchTransactionPage(nextProps.accounts[nextProps.selectedAccount], nextProps.transactionPage.pageSize, nextProps.transactionPage.page);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
componentDidMount() {
|
2015-08-11 07:00:58 -04:00
|
|
|
this.resize();
|
|
|
|
var self = this;
|
|
|
|
$(window).resize(function() {self.resize();});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleEditTransaction(transaction) {
|
2017-05-24 19:47:18 -04:00
|
|
|
this.props.onSelectTransaction(transaction.TransactionId);
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleEditingCancel() {
|
2015-08-05 21:25:25 -04:00
|
|
|
this.setState({
|
2017-05-24 19:47:18 -04:00
|
|
|
newTransaction: null
|
2015-08-05 21:25:25 -04:00
|
|
|
});
|
2017-05-24 19:47:18 -04:00
|
|
|
this.props.onUnselectTransaction();
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleNewTransactionClicked() {
|
2015-08-11 07:00:58 -04:00
|
|
|
var newTransaction = new Transaction();
|
|
|
|
newTransaction.Date = new Date();
|
|
|
|
newTransaction.Splits.push(new Split());
|
|
|
|
newTransaction.Splits.push(new Split());
|
2017-05-31 08:23:19 -04:00
|
|
|
newTransaction.Splits[0].Status = SplitStatus.Entered;
|
|
|
|
newTransaction.Splits[1].Status = SplitStatus.Entered;
|
2016-10-05 13:36:47 -04:00
|
|
|
newTransaction.Splits[0].AccountId = this.props.accounts[this.props.selectedAccount].AccountId;
|
2015-08-11 07:00:58 -04:00
|
|
|
|
|
|
|
this.setState({
|
2017-05-24 19:47:18 -04:00
|
|
|
newTransaction: newTransaction
|
2015-08-11 07:00:58 -04:00
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleSelectPage(eventKey) {
|
2017-02-18 21:50:48 -05:00
|
|
|
var newpage = eventKey - 1;
|
2015-08-11 07:00:58 -04:00
|
|
|
// Don't do pages that don't make sense
|
|
|
|
if (newpage < 0)
|
|
|
|
newpage = 0;
|
2017-05-22 20:36:36 -04:00
|
|
|
if (newpage >= this.props.transactionPage.numPages)
|
|
|
|
newpage = this.props.transactionPage.numPages - 1;
|
|
|
|
if (newpage != this.props.transactionPage.page) {
|
2016-10-05 13:36:47 -04:00
|
|
|
if (this.props.selectedAccount != -1) {
|
2017-05-22 20:36:36 -04:00
|
|
|
this.props.onFetchTransactionPage(this.props.accounts[this.props.selectedAccount], this.props.pageSize, newpage);
|
2015-08-11 07:00:58 -04:00
|
|
|
}
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleImportComplete() {
|
2017-06-04 16:01:42 -04:00
|
|
|
this.props.onCloseImportModal();
|
|
|
|
this.props.onFetchAllAccounts();
|
2017-05-22 20:36:36 -04:00
|
|
|
this.props.onFetchTransactionPage(this.props.accounts[this.props.selectedAccount], this.props.pageSize, this.props.transactionPage.page);
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleDeleteTransaction(transaction) {
|
2017-05-24 19:47:18 -04:00
|
|
|
this.props.onDeleteTransaction(transaction);
|
|
|
|
this.props.onUnselectTransaction();
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleUpdateTransaction(transaction) {
|
2015-08-05 21:25:25 -04:00
|
|
|
if (transaction.TransactionId != -1) {
|
2017-05-24 19:47:18 -04:00
|
|
|
this.props.onUpdateTransaction(transaction);
|
2015-08-05 21:25:25 -04:00
|
|
|
} else {
|
2017-05-24 19:47:18 -04:00
|
|
|
this.props.onCreateTransaction(transaction);
|
2015-08-05 21:25:25 -04:00
|
|
|
}
|
2017-05-24 19:47:18 -04:00
|
|
|
this.props.onUnselectTransaction();
|
|
|
|
this.setState({
|
|
|
|
newTransaction: null
|
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
render() {
|
2015-08-05 21:25:25 -04:00
|
|
|
var name = "Please select an account";
|
2017-06-07 19:12:53 -04:00
|
|
|
var register = [];
|
2015-08-08 07:24:22 -04:00
|
|
|
|
2016-10-05 13:36:47 -04:00
|
|
|
if (this.props.selectedAccount != -1) {
|
|
|
|
name = this.props.accounts[this.props.selectedAccount].Name;
|
2015-08-08 07:24:22 -04:00
|
|
|
|
2015-08-05 21:25:25 -04:00
|
|
|
var transactionRows = [];
|
2017-05-22 20:36:36 -04:00
|
|
|
for (var i = 0; i < this.props.transactionPage.transactions.length; i++) {
|
2017-05-24 19:47:18 -04:00
|
|
|
var transactionId = this.props.transactionPage.transactions[i];
|
|
|
|
var transaction = this.props.transactions[transactionId];
|
2015-08-05 21:25:25 -04:00
|
|
|
transactionRows.push((
|
|
|
|
<TransactionRow
|
2017-05-24 19:47:18 -04:00
|
|
|
key={transactionId}
|
|
|
|
transaction={transaction}
|
2016-10-05 13:36:47 -04:00
|
|
|
account={this.props.accounts[this.props.selectedAccount]}
|
2015-08-05 21:25:25 -04:00
|
|
|
accounts={this.props.accounts}
|
|
|
|
securities={this.props.securities}
|
2017-05-24 19:47:18 -04:00
|
|
|
onSelect={this.props.onSelectTransaction}/>
|
2015-08-05 21:25:25 -04:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2015-08-11 07:13:40 -04:00
|
|
|
var style = {height: this.state.height + "px"};
|
2015-08-05 21:25:25 -04:00
|
|
|
register = (
|
2015-08-11 07:13:40 -04:00
|
|
|
<div style={style} className="transactions-register">
|
2015-08-05 21:25:25 -04:00
|
|
|
<Table bordered striped condensed hover>
|
|
|
|
<thead><tr>
|
|
|
|
<th>Date</th>
|
|
|
|
<th>#</th>
|
|
|
|
<th>Description</th>
|
|
|
|
<th>Account</th>
|
|
|
|
<th>Status</th>
|
|
|
|
<th>Amount</th>
|
|
|
|
<th>Balance</th>
|
|
|
|
</tr></thead>
|
|
|
|
<tbody>
|
|
|
|
{transactionRows}
|
|
|
|
</tbody>
|
2015-08-11 07:00:58 -04:00
|
|
|
</Table>
|
2015-08-11 07:13:40 -04:00
|
|
|
</div>
|
2015-08-05 21:25:25 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-05 13:36:47 -04:00
|
|
|
var disabled = (this.props.selectedAccount == -1) ? true : false;
|
2015-08-11 07:00:58 -04:00
|
|
|
|
2017-05-24 19:47:18 -04:00
|
|
|
var transactionSelected = false;
|
|
|
|
var selectedTransaction = new Transaction();
|
|
|
|
if (this.state.newTransaction != null) {
|
|
|
|
selectedTransaction = this.state.newTransaction;
|
|
|
|
transactionSelected = true;
|
|
|
|
} else if (this.props.transactionPage.selection != -1) {
|
|
|
|
selectedTransaction = this.props.transactions[this.props.transactionPage.selection];
|
|
|
|
transactionSelected = true;
|
|
|
|
}
|
|
|
|
|
2015-08-05 21:25:25 -04:00
|
|
|
return (
|
2015-08-11 07:13:40 -04:00
|
|
|
<div className="transactions-container">
|
2015-08-05 21:25:25 -04:00
|
|
|
<AddEditTransactionModal
|
2017-05-24 19:47:18 -04:00
|
|
|
show={transactionSelected}
|
|
|
|
transaction={selectedTransaction}
|
2015-08-05 21:25:25 -04:00
|
|
|
accounts={this.props.accounts}
|
2016-10-05 13:36:47 -04:00
|
|
|
accountChildren={this.props.accountChildren}
|
2017-06-07 19:12:53 -04:00
|
|
|
onCancel={this.onEditingCancel}
|
|
|
|
onSubmit={this.onUpdateTransaction}
|
|
|
|
onDelete={this.onDeleteTransaction}
|
2016-10-05 13:36:47 -04:00
|
|
|
securities={this.props.securities} />
|
2016-02-02 21:46:27 -05:00
|
|
|
<ImportTransactionsModal
|
2017-06-04 16:01:42 -04:00
|
|
|
imports={this.props.imports}
|
|
|
|
show={this.props.imports.showModal}
|
2016-10-05 13:36:47 -04:00
|
|
|
account={this.props.accounts[this.props.selectedAccount]}
|
2016-02-02 21:46:27 -05:00
|
|
|
accounts={this.props.accounts}
|
2017-06-04 16:01:42 -04:00
|
|
|
onCancel={this.props.onCloseImportModal}
|
|
|
|
onHide={this.props.onCloseImportModal}
|
2017-06-07 19:12:53 -04:00
|
|
|
onSubmit={this.onImportComplete}
|
2017-06-04 16:01:42 -04:00
|
|
|
onImportOFX={this.props.onImportOFX}
|
|
|
|
onImportOFXFile={this.props.onImportOFXFile}
|
|
|
|
onImportGnucash={this.props.onImportGnucash} />
|
2015-08-11 07:21:40 -04:00
|
|
|
<div className="transactions-register-toolbar">
|
2015-08-11 07:00:58 -04:00
|
|
|
Transactions for '{name}'
|
|
|
|
<ButtonToolbar className="pull-right">
|
|
|
|
<ButtonGroup>
|
|
|
|
<Pagination
|
|
|
|
className="skinny-pagination"
|
2016-09-27 11:30:39 -04:00
|
|
|
prev next first last ellipsis
|
2017-05-22 20:36:36 -04:00
|
|
|
items={this.props.transactionPage.numPages}
|
|
|
|
maxButtons={Math.min(5, this.props.transactionPage.numPages)}
|
|
|
|
activePage={this.props.transactionPage.page + 1}
|
2017-06-07 19:12:53 -04:00
|
|
|
onSelect={this.onSelectPage} />
|
2015-08-11 07:00:58 -04:00
|
|
|
</ButtonGroup>
|
|
|
|
<ButtonGroup>
|
|
|
|
<Button
|
2017-06-07 19:12:53 -04:00
|
|
|
onClick={this.onNewTransactionClicked}
|
2015-08-11 07:00:58 -04:00
|
|
|
bsStyle="success"
|
|
|
|
disabled={disabled}>
|
|
|
|
<Glyphicon glyph='plus-sign' /> New Transaction
|
|
|
|
</Button>
|
2016-02-02 21:46:27 -05:00
|
|
|
<Button
|
2017-06-04 16:01:42 -04:00
|
|
|
onClick={this.props.onOpenImportModal}
|
2016-02-15 11:28:44 -05:00
|
|
|
bsStyle="primary">
|
2016-02-02 21:46:27 -05:00
|
|
|
<Glyphicon glyph='import' /> Import
|
|
|
|
</Button>
|
2015-08-11 07:00:58 -04:00
|
|
|
</ButtonGroup>
|
|
|
|
</ButtonToolbar>
|
2015-08-11 07:21:40 -04:00
|
|
|
</div>
|
2015-08-05 21:25:25 -04:00
|
|
|
{register}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AccountRegister;
|