-
Notifications
You must be signed in to change notification settings - Fork 311
/
SalesQuotation.tsx
400 lines (343 loc) · 16.8 KB
/
SalesQuotation.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
import * as React from "react";
import * as ReactDOM from "react-dom";
import {observer} from "mobx-react";
import * as d3 from "d3";
import Config = require("Config");
import {autorun} from 'mobx';
import * as accounting from "accounting";
import SelectCustomer from "../Shared/Components/SelectCustomer";
import SelectPaymentTerm from "../Shared/Components/SelectPaymentTerm";
import SelectLineItem from "../Shared/Components/SelectLineItem";
import SelectLineMeasurement from "../Shared/Components/SelectLineMeasurement";
import SalesQuotationLine from "../Shared/Stores/Quotations/SalesQuotationLine";
import SalesQuotationStore from "../Shared/Stores/Quotations/SalesQuotationStore";
let quotationId = window.location.search.split("?id=")[1];
let store = new SalesQuotationStore(quotationId);
@observer
class ValidationErrors extends React.Component<any, {}>{
render() {
if (store.validationErrors !== undefined && store.validationErrors.length > 0) {
var errors = [];
store.validationErrors.map(function (item, index) {
errors.push(<li key={index}>{item}</li>);
});
return (
<div>
<ul>
{errors}
</ul>
</div>
);
}
return null;
}
}
@observer
class SaveQuotationButton extends React.Component<any, {}>{
saveNewSalesQuotation(e) {
store.saveNewQuotation();
}
//className = {!store.salesInvoice.posted && store.editMode
render() {
return (
<input type="button" value="Save" onClick={this.saveNewSalesQuotation.bind(this) }
className={(store.salesQuotation.statusId == 0 || store.salesQuotation.statusId == undefined) && store.editMode
? "btn btn-sm btn-primary btn-flat pull-left"
: "btn btn-sm btn-primary btn-flat pull-left inactiveLink"}
/>
);
}
}
class CancelQuotationButton extends React.Component<any, {}>{
cancelOnClick() {
let baseUrl = location.protocol
+ "//" + location.hostname
+ (location.port && ":" + location.port)
+ "/";
window.location.href = baseUrl + 'quotations';
}
render() {
return (
<button type="button" className="btn btn-sm btn-default btn-flat pull-left" onClick={ this.cancelOnClick.bind(this) }>
Close
</button>
);
}
}
@observer
class SalesQuotationHeader extends React.Component<any, {}>{
onChangeQuotationDate(e) {
store.changedQuotationDate(e.target.value);
}
onChangeCustomer(e) {
alert('');
}
onChangeReferenceNo(e) {
store.changedReferenceNo(e.target.value);
}
render() {
return (
<div className="box">
<div className="box-header with-border">
<h3 className="box-title">Customer Information - <span>{store.salesQuotation.customerId}</span></h3>
<div className="box-tools pull-right">
<button type="button" className="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i className="fa fa-minus"></i>
</button>
</div>
</div>
<div className="box-body">
<div className="col-md-6">
<div className="row">
<div className="col-sm-2">Customer</div>
<div className="col-sm-10"><SelectCustomer store={store} selected={store.salesQuotation.customerId} /></div>
</div>
<div className="row">
<div className="col-sm-2">Payment Term</div>
<div className="col-sm-10"><SelectPaymentTerm store={store} selected={store.salesQuotation.paymentTermId} /></div>
</div>
</div>
<div className="col-md-6">
<div className="row">
<div className="col-sm-2">Date</div>
<div className="col-sm-10"><input type="date" className="form-control pull-right" onChange={this.onChangeQuotationDate.bind(this) }
value={store.salesQuotation.quotationDate !== undefined ? store.salesQuotation.quotationDate.substring(0, 10) : new Date(Date.now()).toISOString().substring(0, 10) } /></div>
</div>
<div className="row">
<div className="col-sm-2">Reference no.</div>
<div className="col-sm-10"><input type="text" className="form-control" value={store.salesQuotation.referenceNo || ''} onChange={this.onChangeReferenceNo.bind(this) } /></div>
</div>
<div className="row">
<div className="col-sm-2">Status</div>
<div className="col-sm-10"><label>{store.salesQuotationStatus}</label></div>
</div>
</div>
</div>
</div>
);
}
}
@observer
class SalesQuotationLines extends React.Component<any, {}>{
addLineItem() {
if (store.validationLine()) {
var itemId, measurementId, quantity, amount, discount, code;
itemId = (document.getElementById("optNewItemId") as HTMLInputElement).value;
measurementId = (document.getElementById("optNewMeasurementId") as HTMLInputElement).value;
quantity = (document.getElementById("txtNewQuantity") as HTMLInputElement).value;
amount = (document.getElementById("txtNewAmount") as HTMLInputElement).value;
discount = (document.getElementById("txtNewDiscount") as HTMLInputElement).value;
code = (document.getElementById("txtNewCode") as HTMLInputElement).value;
//console.log(`itemId: ${itemId} | measurementId: ${measurementId} | quantity: ${quantity} | amount: ${amount} | discount: ${discount}`);
store.addLineItem(0, itemId, measurementId, quantity, amount, discount, code);
(document.getElementById("optNewItemId") as HTMLInputElement).value = "";
(document.getElementById("txtNewCode") as HTMLInputElement).value = "";
(document.getElementById("optNewMeasurementId") as HTMLInputElement).value = "";
(document.getElementById("txtNewQuantity") as HTMLInputElement).value = "1";
(document.getElementById("txtNewAmount") as HTMLInputElement).value = "";
(document.getElementById("txtNewDiscount") as HTMLInputElement).value = "";
}
}
onClickRemoveLineItem(i, e) {
store.removeLineItem(i);
}
onChangeQuantity(e) {
store.updateLineItem(e.target.name, "quantity", e.target.value);
}
onChangeAmount(e) {
store.updateLineItem(e.target.name, "amount", e.target.value);
}
onChangeDiscount(e) {
store.updateLineItem(e.target.name, "discount", e.target.value);
}
onChangeCode(e) {
store.updateLineItem(e.target.name, "code", e.target.value);
}
onFocusOutItem(e,isNew,i) {
var isExisting = false;
for (var x = 0; x < store.commonStore.items.length; x++) {
if (store.commonStore.items[x].code == i.target.value) {
isExisting = true;
if (isNew) {
(document.getElementById("optNewItemId") as HTMLInputElement).value = store.commonStore.items[x].id;
(document.getElementById("optNewMeasurementId") as HTMLInputElement).value = store.commonStore.items[x].sellMeasurementId;
(document.getElementById("txtNewAmount") as HTMLInputElement).value = store.commonStore.items[x].price;
(document.getElementById("txtNewQuantity") as HTMLInputElement).value = "1";
document.getElementById("txtNewCode").style.borderColor = "";
}
else {
store.updateLineItem(e, "itemId", store.commonStore.items[x].id);
store.updateLineItem(e, "measurementId", store.commonStore.items[x].sellMeasurementId);
store.updateLineItem(e, "amount", store.commonStore.items[x].price);
store.updateLineItem(e, "quantity", 1);
i.target.style.borderColor = "";
}
}
}
if (!isExisting)
if (isNew) {
(document.getElementById("optNewItemId") as HTMLInputElement).value = "";
(document.getElementById("optNewMeasurementId") as HTMLInputElement).value = "";
(document.getElementById("txtNewAmount") as HTMLInputElement).value = "";
(document.getElementById("txtNewQuantity") as HTMLInputElement).value = "";
document.getElementById("txtNewCode").style.borderColor = '#FF0000';
//document.getElementById("txtNewCode").appendChild(span);
// document.getElementById("txtNewCode").style.border = 'solid';
}
else {
//store.updateLineItem(e, "itemId", "");
//store.updateLineItem(e, "measurementId", "");
//store.updateLineItem(e, "amount", "");
//store.updateLineItem(e, "quantity", "");
i.target.style.borderColor = "red";
//i.target.appendChild(span);
// i.target.style.border = "solid";
}
}
render() {
var lineItems = [];
for (var i = 0; i < store.salesQuotation.salesQuotationLines.length; i++) {
//var initialCode = this.onloadCode(store.salesQuotation.salesQuotationLines[i].itemId); // this is for initial value of code
lineItems.push(
<tr key={i}>
<td><SelectLineItem store={store} row={i} selected={store.salesQuotation.salesQuotationLines[i].itemId} /></td>
<td><input className="form-control" type="text" name={i} value={store.salesQuotation.salesQuotationLines[i].code} onBlur={this.onFocusOutItem.bind(this, i, false)} onChange={this.onChangeCode.bind(this) } /></td>
<td><SelectLineMeasurement row={i} store={store} selected={store.salesQuotation.salesQuotationLines[i].measurementId} /></td>
<td><input className="form-control" type="text" name={i} value={store.salesQuotation.salesQuotationLines[i].quantity} onChange={this.onChangeQuantity.bind(this) } /></td>
<td><input className="form-control" type="text" name={i} value={store.salesQuotation.salesQuotationLines[i].amount} onChange={this.onChangeAmount.bind(this) } /></td>
<td><input className="form-control" type="text" name={i} value={store.salesQuotation.salesQuotationLines[i].discount} onChange={this.onChangeDiscount.bind(this) } /></td>
<td>{store.getLineTotal(i) }</td>
<td>
<button type="button" className="btn btn-box-tool" onClick={this.onClickRemoveLineItem.bind(this, i) }>
<i className="fa fa-fw fa-times"></i>
</button>
</td>
</tr>
);
}
return (
<div className="box">
<div className="box-header with-border">
<h3 className="box-title">Line Items</h3>
<div className="box-tools pull-right">
<button type="button" className="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i className="fa fa-minus"></i>
</button>
</div>
</div>
<div className="box-body table-responsive">
<table className="table table-hover">
<thead>
<tr>
<td>Item</td>
<td>Code</td>
<td>Measurement</td>
<td>Quantity</td>
<td>Amount</td>
<td>Discount</td>
<td>Line Total</td>
<td></td>
</tr>
</thead>
<tbody>
{lineItems}
<tr>
<td><SelectLineItem store={store} controlId="optNewItemId" /></td>
<td><input className="form-control" type="text" id="txtNewCode" onBlur={this.onFocusOutItem.bind(this, i, true) } /></td>
<td><SelectLineMeasurement store={store} controlId="optNewMeasurementId" /></td>
<td><input className="form-control" type="text" id="txtNewQuantity" /></td>
<td><input className="form-control" type="text" id="txtNewAmount" /></td>
<td><input className="form-control" type="text" id="txtNewDiscount" /></td>
<td></td>
<td>
<button type="button" className="btn btn-box-tool" onClick={this.addLineItem}>
<i className="fa fa-fw fa-check"></i>
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
);
}
}
@observer
class SalesQuotationTotals extends React.Component<any, {}>{
render() {
return (
<div className="box">
<div className="box-body">
<div className="row">
<div className="col-md-2"><label>Running Total: </label></div>
<div className="col-md-2">{accounting.formatMoney(store.RTotal, { symbol: "", format: "%s%v" }) }</div>
<div className="col-md-2"><label>Tax Total: </label></div>
<div className="col-md-2">{accounting.formatMoney(store.TTotal, { symbol: "", format: "%s%v" }) }</div>
<div className="col-md-2"><label>Grand Total: </label></div>
<div className="col-md-2">{accounting.formatMoney(store.GTotal, { symbol: "", format: "%s%v" }) }</div>
</div>
</div>
</div>
);
}
}
@observer
class BookButton extends React.Component<any, {}>{
bookOnClick(e) {
store.bookQuotation();
}
render() {
return (
<input type="button" value="Book" onClick={ this.bookOnClick.bind(this) }
className={store.salesQuotation.statusId == 0 && !store.editMode
? "btn btn-sm btn-primary btn-flat btn-danger pull-right"
: "btn btn-sm btn-primary btn-flat btn-danger pull-right inactiveLink"} />
);
}
}
@observer
class EditButton extends React.Component<any, {}> {
onClickEditButton() {
// Remove " disabledControl" from current className
var nodes = document.getElementById("divSalesQuotationForm").getElementsByTagName('*');
for (var i = 0; i < nodes.length; i++) {
var subStringLength = nodes[i].className.length - " disabledControl".length;
nodes[i].className = nodes[i].className.substring(0, subStringLength);
}
store.changedEditMode(true);
}
render() {
return (
<a href="#" id="linkEdit" onClick={this.onClickEditButton}
className={store.salesQuotation.statusId == 0 && !store.editMode
? "btn"
: "btn inactiveLink"}>
<i className="fa fa-edit"></i>
Edit
</a>
);
}
}
export default class SalesQuotation extends React.Component<any, {}> {
render() {
return (
<div>
<div id="divActionsTop">
<EditButton/>
</div>
<div id="divSalesQuotationForm">
<ValidationErrors />
<SalesQuotationHeader />
<SalesQuotationLines />
<SalesQuotationTotals />
</div>
<div>
<SaveQuotationButton />
<CancelQuotationButton />
<BookButton />
</div>
</div>
);
}
}
ReactDOM.render(<SalesQuotation />, document.getElementById("divSalesQuotation"));