Skip to content

Commit 1a18fa3

Browse files
committed
Inventory Transfer
1 parent 94b875c commit 1a18fa3

17 files changed

+469
-64
lines changed

AuthService.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class AuthService {
2424
user = JSON.parse(tkn);
2525

2626
resolve(user);
27+
28+
console.log("LOGIN_SUCCESS", JSON.stringify({token: token, user: user}));
2729
},
2830
error: reject
2931
});

ChangePasswordForm.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
"use strict";
2+
3+
import React from 'react';
4+
var Modal = require('../components/Modal');
5+
var userService = require('./user/UserService');
6+
var lib = require('../components/functions');
7+
8+
class ChangePasswordForm extends React.Component {
9+
10+
constructor(props) {
11+
super(props);
12+
this.state = {
13+
user: props.user
14+
};
15+
}
16+
17+
render() {
18+
var $this = this;
19+
var user = $this.state.user;
20+
21+
var header = (
22+
<h3 className="modal-title text-primary">Change Password</h3>
23+
);
24+
25+
var body = (
26+
27+
<form onSubmit={e => {e.preventDefault(); $this.onSubmit.call($this)}}>
28+
29+
<div className="form-group">
30+
<label htmlFor="username">Current Password</label>
31+
<input type="password" className="form-control" id="currentPassword" placeholder="Current Password"
32+
name="currentPassword" value={user.currentPassword} onChange={$this.onChange.bind($this)}/>
33+
</div>
34+
35+
<div className="form-group">
36+
<label htmlFor="password">New Password</label>
37+
<input type="password" className="form-control" id="password" placeholder="New Password"
38+
name="password" value={user.password} onChange={$this.onChange.bind($this)}/>
39+
</div>
40+
41+
<div className="form-group">
42+
<label htmlFor="password">Retype New Password</label>
43+
<input type="password" className="form-control" placeholder="Retype New Password"
44+
id="retypePassword" name="retypePassword" value={user.retypePassword}
45+
onChange={$this.onChange.bind($this)}/>
46+
</div>
47+
48+
<input type="submit" style={{display: 'none'}}/>
49+
50+
</form>
51+
);
52+
53+
var footer = (
54+
<div>
55+
<span className="btn btn-primary pull-right"
56+
onClick={$this.onSubmit.bind($this)}>Change</span>
57+
<span className="btn btn-danger pull-right" style={{marginRight: '10px'}}
58+
onClick={$this.props.onClose}>Cancel</span>
59+
</div>
60+
);
61+
62+
return (
63+
64+
<Modal title={header}
65+
body={body}
66+
footer={footer}
67+
onClose={$this.props.onClose} isOpen={$this.props.isOpen}/>
68+
69+
);
70+
}
71+
72+
onSubmit() {
73+
var $this = this;
74+
userService.changePassword($this.state.user)
75+
.then(() => $this.setState({user: {}}))
76+
;
77+
}
78+
79+
onChange(e) {
80+
var $this = this;
81+
var user = $this.state.user || {};
82+
user[e.target.name] = e.target.value;
83+
$this.setState({
84+
user: user
85+
});
86+
}
87+
}
88+
89+
ChangePasswordForm.defaultProps = {
90+
user: {},
91+
isOpen: false,
92+
onClose: null,
93+
};
94+
95+
module.exports = ChangePasswordForm;

Events.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var Events = {
22
UNIT_CREATED: 'UNIT_CREATED',
33
UNIT_UPDATED: 'UNIT_UPDATED',
44
UNIT_DELETED: 'UNIT_DELETED',
5+
USER_LOGGED_IN: 'USER_LOGGED_IN',
56
};
67

78
module.exports = Events;

inventory/AddRemoveEditProducts.js

Lines changed: 121 additions & 39 deletions
Large diffs are not rendered by default.

inventory/InventoryService.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ class InventoryService {
222222
});
223223
});
224224
}
225+
226+
transferTo(req) {
227+
228+
}
229+
230+
bringFrom(req) {
231+
232+
}
225233
}
226234

227235
module.exports = new InventoryService();

navbar/NavbarCollapse.js

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,44 @@ import React from 'react';
44
import { Link, browserHistory } from 'react-router'
55
var Uris = require('../Uris');
66
var authService = require('../AuthService');
7+
var userService = require('../user/UserService');
8+
var ChangePasswordForm = require('../ChangePasswordForm');
79

8-
class UserApp extends React.Component {
10+
var lib = require('../../components/functions');
11+
12+
var ee = require('../EventEmitter');
13+
var Events = require('../user/Events');
14+
15+
var handlers = {};
16+
17+
class NavbarCollapse extends React.Component {
918
constructor(props) {
1019
super(props);
1120
this.state = {
1221
user: authService.currentUser()
1322
};
23+
this.componentDidMount.bind(this);
24+
this.componentWillUnmount.bind(this);
25+
}
26+
27+
componentDidMount() {
28+
var $this = this;
29+
console.log("$THIS");
30+
31+
handlers[Events.PASSWORD_CHANGED] = (id) => {
32+
$this.setState({
33+
isModalOpen: false,
34+
user: lib.exclude($this.state.user, ['currentPassword', 'password', 'retypePassword'])
35+
});
36+
};
37+
38+
Object.keys(handlers).forEach(key => ee.on(key, handlers[key]));
39+
}
40+
41+
componentWillUnmount() {
42+
var $this = this;
43+
44+
Object.keys(handlers).forEach(key => ee.removeListener(key, handlers[key]));
1445
}
1546

1647
render() {
@@ -59,24 +90,46 @@ class UserApp extends React.Component {
5990
<ul className="nav navbar-nav navbar-right">
6091
<li className="dropdown">
6192
<a href="#" className="dropdown-toggle" data-toggle="dropdown" role="button"
62-
aria-haspopup="true" aria-expanded="false">{user.name} <span
93+
aria-haspopup="true" aria-expanded="false">{user.username} <span
6394
className="caret"></span></a>
6495
<ul className="dropdown-menu">
65-
<li><a>Update Info</a></li>
96+
<li><a onClick={$this.changePassword.bind($this)}>Change Password</a></li>
6697
<li role="separator" className="divider"></li>
67-
<li onClick={$this.logout}><a >Logout</a></li>
98+
<li onClick={$this.logout.bind($this)}><a >Logout</a></li>
6899
</ul>
69100
</li>
70101
</ul>
102+
103+
{
104+
($this.state.createModal || (() => null))()
105+
}
106+
71107
</div>
72108
);
73109
}
74110

75111
logout() {
112+
var $this = this;
76113
console.log('logout');
77114
authService.logout()
78-
.then(() => location.href = Uris.toAbsoluteUri(Uris.LOGIN_URI));
115+
.then(() => location.href = Uris.toAbsoluteUri(Uris.LOGIN_URI))
116+
;
117+
}
118+
119+
changePassword() {
120+
var $this = this;
121+
$this.setState({
122+
isModalOpen: true,
123+
createModal: () => {
124+
return (
125+
<ChangePasswordForm isOpen={!!$this.state.isModalOpen}
126+
onClose={() => $this.setState({isModalOpen: false})}
127+
user={$this.state.user}
128+
/>
129+
);
130+
}
131+
});
79132
}
80133
}
81134

82-
module.exports = UserApp;
135+
module.exports = NavbarCollapse;

pages/LoginForm.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class LoginForm extends React.Component {
1111
var $this = this;
1212
var user = $this.props.user;
1313
return (
14-
<form onSubmit={$this.props.onSubmit}>
14+
<form method="post" onSubmit={e => {
15+
e.preventDefault();
16+
$this.props.onSubmit(user);
17+
}}>
1518
<div className="form-group">
1619
<label htmlFor="username">Username</label>
1720
<input type="text" className="form-control" id="username" placeholder="Username"
@@ -22,6 +25,7 @@ class LoginForm extends React.Component {
2225
<input type="password" className="form-control" id="password" placeholder="Password"
2326
name="password" value={user.password} onChange={$this.props.onChange}/>
2427
</div>
28+
<input type="submit" style={{display: 'none'}}/>
2529
</form>
2630
);
2731
}

sell/Create.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var lib = require('../../components/functions');
1515

1616
var Uris = require('../Uris');
1717

18+
var authService = require('../AuthService');
19+
1820
var Events = {
1921
SUBMIT_REQUESTED: 'SUBMIT_REQUESTED',
2022
SUBMIT_SUCCESSFULL: 'SUBMIT_SUCCESSFULL',
@@ -71,6 +73,7 @@ module.exports = CreateSell = React.createClass({
7173
consumerName: '',
7274
consumerMobile: '',
7375
sellDate: new Date(),
76+
createdBy: authService.currentUser(),
7477
remarks: ''
7578
},
7679
sellUnitsByProductId: {},
@@ -141,6 +144,8 @@ module.exports = CreateSell = React.createClass({
141144
return newState;
142145
}, {});
143146

147+
state.sellUnitsByProductId = $this.interceptSellUnits(state.sellUnitsByProductId, state.productsUnitWisePrice);
148+
144149
$this.setState(state);
145150
})
146151
;
@@ -263,7 +268,7 @@ module.exports = CreateSell = React.createClass({
263268
onSaleUnitsChange: function (newSellUnitsByProductId) {
264269
var $this = this;
265270
$this.setState({
266-
sellUnitsByProductId: newSellUnitsByProductId,
271+
sellUnitsByProductId: $this.interceptSellUnits(newSellUnitsByProductId, $this.state.productsUnitWisePrice),
267272
});
268273
},
269274
submit: function (e) {
@@ -326,4 +331,21 @@ module.exports = CreateSell = React.createClass({
326331
onClick={$this.closeModal}>Ok</button>
327332
);
328333
},
334+
interceptSellUnits: function (sellUnitsByProductId, productsUnitWisePrice) {
335+
var $this = this;
336+
for (var x in sellUnitsByProductId) {
337+
var su = sellUnitsByProductId[x] || {};
338+
339+
var priceByUnitIds = productsUnitWisePrice[su.productId] || {};
340+
341+
if (Object.keys(priceByUnitIds).length == 1) {
342+
su.unitId = Object.keys(priceByUnitIds).reduce((unitId, id) => unitId || id, null);
343+
}
344+
345+
su.unitPrice = priceByUnitIds[su.unitId] || undefined;
346+
su.total = su.quantity * su.unitPrice;
347+
}
348+
349+
return sellUnitsByProductId;
350+
}
329351
});

sell/CreateSellGrid.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ module.exports = CreateSellGrid = React.createClass({
116116
serial: serial++,
117117
productId: (productsById[unit.productId] || {}).name,
118118
quantity: (
119-
<input className="form-control" type="number" style={{width: '100px'}}
119+
<input className="form-control" type="number" style={{width: '100px', textAlign: 'right'}}
120120
name="quantity" value={unit.quantity}
121121
onChange={function (e) {
122122
$this.onChange(e, unit);
@@ -147,7 +147,7 @@ module.exports = CreateSellGrid = React.createClass({
147147
/>
148148
),
149149
total: (
150-
<input className="form-control" type="number" style={{width: '120px'}}
150+
<input className="form-control" type="number" style={{width: '120px', textAlign: 'right'}}
151151
name="total" value={unit.total} readOnly={true}
152152
/>
153153
),
@@ -164,8 +164,17 @@ module.exports = CreateSellGrid = React.createClass({
164164

165165
sUnits.push({
166166
productId: <strong>Total</strong>,
167-
quantity: <strong>{totalCounter.quantity}</strong>,
168-
total: <strong>{totalCounter.total}</strong>,
167+
quantity: (
168+
<input className="form-control" type="number" style={{width: '100px', textAlign: 'right'}}
169+
value={totalCounter.quantity}
170+
onChange={function (e) {
171+
$this.onChange(e, unit);
172+
}}/>
173+
),
174+
total: (
175+
<input className="form-control" type="number" style={{width: '120px', textAlign: 'right'}}
176+
value={totalCounter.total} readOnly={true}/>
177+
),
169178
});
170179

171180
return (

sell/CreateSellHeader.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ module.exports = CreateSellHeader = React.createClass({
4242

4343
<div className="col-sm-8">
4444
<DateTimePicker id="sellDate"
45-
name="sellDate" value={sell.sellDate}
46-
onChange={date => $this.props.onChange({target: {name: 'sellDate', value: date}})}/>
45+
name="sellDate"
46+
value={sell.sellDate}
47+
time={false}/>
4748
</div>
4849
</div>
4950

0 commit comments

Comments
 (0)