mirror of
				https://github.com/aclindsa/moneygo.git
				synced 2025-11-04 02:23:26 -05:00 
			
		
		
		
	Add symbols for securities
This commit is contained in:
		@@ -16,6 +16,7 @@ const (
 | 
				
			|||||||
type Security struct {
 | 
					type Security struct {
 | 
				
			||||||
	SecurityId int64
 | 
						SecurityId int64
 | 
				
			||||||
	Name       string
 | 
						Name       string
 | 
				
			||||||
 | 
						Symbol     string
 | 
				
			||||||
	// Number of decimal digits (to the right of the decimal point) this
 | 
						// Number of decimal digits (to the right of the decimal point) this
 | 
				
			||||||
	// security is precise to
 | 
						// security is precise to
 | 
				
			||||||
	Precision int
 | 
						Precision int
 | 
				
			||||||
@@ -30,11 +31,13 @@ var security_map = map[int64]*Security{
 | 
				
			|||||||
	1: &Security{
 | 
						1: &Security{
 | 
				
			||||||
		SecurityId: 1,
 | 
							SecurityId: 1,
 | 
				
			||||||
		Name:       "USD",
 | 
							Name:       "USD",
 | 
				
			||||||
 | 
							Symbol:     "$",
 | 
				
			||||||
		Precision:  2,
 | 
							Precision:  2,
 | 
				
			||||||
		Type:       Banknote},
 | 
							Type:       Banknote},
 | 
				
			||||||
	2: &Security{
 | 
						2: &Security{
 | 
				
			||||||
		SecurityId: 2,
 | 
							SecurityId: 2,
 | 
				
			||||||
		Name:       "SPY",
 | 
							Name:       "SPY",
 | 
				
			||||||
 | 
							Symbol:     "SPY",
 | 
				
			||||||
		Precision:  5,
 | 
							Precision:  5,
 | 
				
			||||||
		Type:       Stock},
 | 
							Type:       Stock},
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,13 +49,13 @@ const TransactionRow = React.createClass({
 | 
				
			|||||||
				accountName = "--Split Transaction--";
 | 
									accountName = "--Split Transaction--";
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			var amount = "$" + thisAccountSplit.Amount.toFixed(security.Precision);
 | 
								var amount = security.Symbol + " " + thisAccountSplit.Amount.toFixed(security.Precision);
 | 
				
			||||||
			var balance = "$" + this.props.transaction.Balance.toFixed(security.Precision);
 | 
								var balance = security.Symbol + " " + this.props.transaction.Balance.toFixed(security.Precision);
 | 
				
			||||||
			status = TransactionStatusMap[this.props.transaction.Status];
 | 
								status = TransactionStatusMap[this.props.transaction.Status];
 | 
				
			||||||
			number = thisAccountSplit.Number;
 | 
								number = thisAccountSplit.Number;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			var amount = "$" + (new Big(0.0)).toFixed(security.Precision);
 | 
								var amount = security.Symbol + " " + (new Big(0.0)).toFixed(security.Precision);
 | 
				
			||||||
			var balance = "$" + (new Big(0.0)).toFixed(security.Precision);
 | 
								var balance = security.Symbol + " " + (new Big(0.0)).toFixed(security.Precision);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return (
 | 
							return (
 | 
				
			||||||
@@ -74,7 +74,12 @@ const TransactionRow = React.createClass({
 | 
				
			|||||||
const AmountInput = React.createClass({
 | 
					const AmountInput = React.createClass({
 | 
				
			||||||
	_getInitialState: function(props) {
 | 
						_getInitialState: function(props) {
 | 
				
			||||||
		// Ensure we can edit this without screwing up other copies of it
 | 
							// Ensure we can edit this without screwing up other copies of it
 | 
				
			||||||
		var a = props.value.toFixed(this.props.security.Precision);
 | 
							var a;
 | 
				
			||||||
 | 
							if (props.security)
 | 
				
			||||||
 | 
								a = props.value.toFixed(props.security.Precision);
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								a = props.value.toString();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return {
 | 
							return {
 | 
				
			||||||
			LastGoodAmount: a,
 | 
								LastGoodAmount: a,
 | 
				
			||||||
			Amount: a
 | 
								Amount: a
 | 
				
			||||||
@@ -84,7 +89,9 @@ const AmountInput = React.createClass({
 | 
				
			|||||||
		 return this._getInitialState(this.props);
 | 
							 return this._getInitialState(this.props);
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	componentWillReceiveProps: function(nextProps) {
 | 
						componentWillReceiveProps: function(nextProps) {
 | 
				
			||||||
		if (!nextProps.value.eq(this.props.value) && !nextProps.value.eq(this.getValue())) {
 | 
							if ((!nextProps.value.eq(this.props.value) &&
 | 
				
			||||||
 | 
									!nextProps.value.eq(this.getValue())) ||
 | 
				
			||||||
 | 
									nextProps.security !== this.props.security) {
 | 
				
			||||||
			this.setState(this._getInitialState(nextProps));
 | 
								this.setState(this._getInitialState(nextProps));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
@@ -92,8 +99,13 @@ const AmountInput = React.createClass({
 | 
				
			|||||||
		this.refs.amount.getInputDOMNode().onblur = this.onBlur;
 | 
							this.refs.amount.getInputDOMNode().onblur = this.onBlur;
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	onBlur: function() {
 | 
						onBlur: function() {
 | 
				
			||||||
 | 
							var a;
 | 
				
			||||||
 | 
							if (this.props.security)
 | 
				
			||||||
 | 
								a = (new Big(this.getValue())).toFixed(this.props.security.Precision);
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								a = (new Big(this.getValue())).toString();
 | 
				
			||||||
		this.setState({
 | 
							this.setState({
 | 
				
			||||||
			Amount: (new Big(this.getValue())).toFixed(this.props.security.Precision)
 | 
								Amount: a
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	onChange: function() {
 | 
						onChange: function() {
 | 
				
			||||||
@@ -112,10 +124,15 @@ const AmountInput = React.createClass({
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	render: function() {
 | 
						render: function() {
 | 
				
			||||||
 | 
							var symbol = "?";
 | 
				
			||||||
 | 
							if (this.props.security)
 | 
				
			||||||
 | 
								symbol = this.props.security.Symbol;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return (
 | 
							return (
 | 
				
			||||||
			<Input type="text"
 | 
								<Input type="text"
 | 
				
			||||||
				value={this.state.Amount}
 | 
									value={this.state.Amount}
 | 
				
			||||||
				onChange={this.onChange}
 | 
									onChange={this.onChange}
 | 
				
			||||||
 | 
									addonBefore={symbol}
 | 
				
			||||||
				ref="amount"/>
 | 
									ref="amount"/>
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -230,7 +247,9 @@ const AddEditTransactionModal = React.createClass({
 | 
				
			|||||||
		for (var i = 0; i < this.state.transaction.Splits.length; i++) {
 | 
							for (var i = 0; i < this.state.transaction.Splits.length; i++) {
 | 
				
			||||||
			var self = this;
 | 
								var self = this;
 | 
				
			||||||
			var s = this.state.transaction.Splits[i];
 | 
								var s = this.state.transaction.Splits[i];
 | 
				
			||||||
			var security = this.props.security_map[this.props.account_map[s.AccountId].SecurityId];
 | 
								var security = null;
 | 
				
			||||||
 | 
								if (this.props.account_map[s.AccountId])
 | 
				
			||||||
 | 
									security = this.props.security_map[this.props.account_map[s.AccountId].SecurityId];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Define all closures for calling split-updating functions
 | 
								// Define all closures for calling split-updating functions
 | 
				
			||||||
			var deleteSplitFn = (function() {
 | 
								var deleteSplitFn = (function() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -92,6 +92,7 @@ for (var type in SecurityType) {
 | 
				
			|||||||
function Security() {
 | 
					function Security() {
 | 
				
			||||||
	this.SecurityId = -1;
 | 
						this.SecurityId = -1;
 | 
				
			||||||
	this.Name = "";
 | 
						this.Name = "";
 | 
				
			||||||
 | 
						this.Symbol = "";
 | 
				
			||||||
	this.Precision = -1;
 | 
						this.Precision = -1;
 | 
				
			||||||
	this.Type = -1;
 | 
						this.Type = -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -100,6 +101,7 @@ Security.prototype.toJSON = function() {
 | 
				
			|||||||
	var json_obj = {};
 | 
						var json_obj = {};
 | 
				
			||||||
	json_obj.SecurityId = this.SecurityId;
 | 
						json_obj.SecurityId = this.SecurityId;
 | 
				
			||||||
	json_obj.Name = this.Name;
 | 
						json_obj.Name = this.Name;
 | 
				
			||||||
 | 
						json_obj.Symbol = this.Symbol;
 | 
				
			||||||
	json_obj.Precision = this.Precision;
 | 
						json_obj.Precision = this.Precision;
 | 
				
			||||||
	json_obj.Type = this.Type;
 | 
						json_obj.Type = this.Type;
 | 
				
			||||||
	return JSON.stringify(json_obj);
 | 
						return JSON.stringify(json_obj);
 | 
				
			||||||
@@ -112,6 +114,8 @@ Security.prototype.fromJSON = function(json_input) {
 | 
				
			|||||||
		this.SecurityId = json_obj.SecurityId;
 | 
							this.SecurityId = json_obj.SecurityId;
 | 
				
			||||||
	if (json_obj.hasOwnProperty("Name"))
 | 
						if (json_obj.hasOwnProperty("Name"))
 | 
				
			||||||
		this.Name = json_obj.Name;
 | 
							this.Name = json_obj.Name;
 | 
				
			||||||
 | 
						if (json_obj.hasOwnProperty("Symbol"))
 | 
				
			||||||
 | 
							this.Symbol = json_obj.Symbol;
 | 
				
			||||||
	if (json_obj.hasOwnProperty("Precision"))
 | 
						if (json_obj.hasOwnProperty("Precision"))
 | 
				
			||||||
		this.Precision = json_obj.Precision;
 | 
							this.Precision = json_obj.Precision;
 | 
				
			||||||
	if (json_obj.hasOwnProperty("Type"))
 | 
						if (json_obj.hasOwnProperty("Type"))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user