-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
104 lines (102 loc) · 5.7 KB
/
code.js
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
$('#content h1').after('<input type="file" id="file" />')
$('#content h1').after('<input type="submit" id="submit"/>')
$('#submit').click(function() {
var data = document.getElementById('file').files[0].getAsText('');
var csv = jQuery.csv()(data);
$(csv).each(function(index) {
$('#activities_0_items_' + (index + 4) + '_row').after(new_row(index + 5));
row = csv[index];
$('#activities_0_items_' + index + '_activity').val(row[5]);
$('#activities_0_items_' + index + '_category').selectOptions(row[6]);
var date = Date.parse(row[0]);
// var date = Date.parseExact(row[0], "dd/MM/yyyy");
// if (date == null) {
// date = Date.parseExact(row[0], "d/MM/yy");
// }
$('#activities_0_items_' + index + '_item_date_string').val(date.toString('dd MMM yyyy'));
$('#activities_0_items_' + index + '_amount').val($.trim(row[1]));
// $('#activities_0_items_' + index + '_currency').val('AUD');
$('#activities_0_items_' + index + '_description').val(row[3]);
$('#activities_0_items_' + index + '_vendor').val(row[2]);
$('#activities_0_items_' + index + '_payment').selectOptions(row[7]);
});
$('#sub[value=Save as draft]').click();
});
jQuery.fn.selectOptions = function(text) {
this.each(
function() {
var optionsLength = this.options.length;
for(var i = 0; i<optionsLength; i++) {
if (this.options[i].text == text) {
this.options[i].selected = true;
return;
};
}
}
);
}
var new_row = function(index) {
return '<tr id="activities_0_items_' + index + '_row">' +
'<td><input id="activities_0_items_' + index + '_activity" name="expense_items[' + index + '][activity]" type="hidden" value="" /></td>' +
'<td><select id="activities_0_items_' + index + '_category" name="expense_items[' + index + '][category]" style="width: 150px;"><option value=""></option>' +
'<option value="EXPAUPGR">Airfare & Upgrades</option>' +
'<option value="EXPCHFEE">Airfare Change Fees</option>' +
'<option value="EXPBENFITNESS">Benefits (Fitness)</option>' +
'<option value="EXPBENTRANSIT">Benefits (Transit)</option>' +
'<option value="EXPBOOKS">Books</option>' +
'<option value="EXPBMEAL">Business Meals</option>' +
'<option value="EXPCRENT">Car Rental</option>' +
'<option value="EXPCONFE">Conference</option>' +
'<option value="EXPCORPAPT">Corporate Apartment</option>' +
'<option value="EXPDSUBS">Dues & Subscriptions</option>' +
'<option value="EXPEMPLACTIVITY">Employee Activities (OZ/China/India ONLY)</option>' +
'<option value="EXPENTERTAIN">Entertainment (OZ/China/India ONLY)</option>' +
'<option value="EXPGAS">Gas</option>' +
'<option value="EXPHSINT">High Speed Internet</option>' +
'<option value="EXPHOTEL">Hotel</option>' +
'<option value="EXPLTRAN">Local Transportation</option>' +
'<option value="EXPMILE">Mileage/Parking/Tolls</option>' +
'<option value="EXPOSUPP">Office Supplies</option>' +
'<option value="EXPOTHER">Other</option>' +
'<option value="EXPPASS">Passport/Visa/Immigration</option>' +
'<option value="EXPSTIPEND">Per Diem/Stipend (pre-approved)</option>' +
'<option value="EXPPSHIP">Postage & Shipping</option>' +
'<option value="EXPSALARYSAC">Salary Sacrifice (OZ/India ONLY)</option>' +
'<option value="EXPTELE">Telephone</option>' +
'<option value="EXPTRNG">Training/Education</option></select></td> ' +
'<td class="date_column">' +
'<input id="activities_0_items_' + index + '_item_date_string" name="expense_items[' + index + '][item_date_string]" onblur="copy_date(0, 4)" size="18" type="text" />' +
'<input id="activities_0_items_' + index + '_item_date_copy" name="expense_items[' + index + '][item_date_copy]" type="hidden" />' +
'</td>' +
'<td><input id="activities_0_items_' + index + '_amount" maxlength="12" name="expense_items[' + index + '][amount]" size="20" type="text" /></td>' +
'<td>' +
'<span class="select-box">' +
'<select id="activities_0_items_' + index + '_currency" name="expense_items[' + index + '][currency]" style="width: 100px;"><option value=""></option>' +
'<option value="AUD" selected="selected">AUD - Australian Dollar</option>' +
'<option value="BRL">BRL - Brazilian Real</option>' +
'<option value="USD">USD - US Dollar</option>' +
'<option value="USN">USN - US Dollar (Next day)</option>' +
'<option value="USS">USS - US Dollar (Same day)</option>' +
'</span>' +
'</td> ' +
'<td><input id="activities_0_items_' + index + '_description" maxlength="255" name="expense_items[' + index + '][description]" size="14" type="text" /></td>' +
'<td><input id="activities_0_items_' + index + '_vendor" maxlength="100" name="expense_items[' + index + '][vendor]" size="10" type="text" /></td>' +
'<td>' +
'<span class="select-box">' +
' <select id="activities_0_items_' + index + '_payment" name="expense_items[' + index + '][payment]" style="width: 120px;"><option value=""></option>' +
' <option value="PMTPERS">Personal Card</option>' +
' <option value="PMTCASH">Personal Cash or Check</option>' +
' <option value="PMTVEND">TW Billed by Vendor</option>' +
' <option value="PMTAMEX">TW Corp. Amex (OZ ONLY)</option>' +
' <option value="PMTCOMP">TW Travel Dept. Paid</option>' +
' <option value="PMTMSTC">US Bank Prepaid Credit Card (US ONLY)</option>' +
' </select>' +
' </span>' +
'</td> ' +
'<td><input id="activities_0_items_' + index + '_attendees" maxlength="255" name="expense_items[' + index + '][attendees]" size="14" type="text" /></td>' +
'<td align="center">' +
' <input id="activities_0_items_' + index + '_personal" name="expense_items[' + index + '][personal]" type="checkbox" value="1" />' +
' <input name="expense_items[' + index + '][personal]" type="hidden" value="0" />' +
' </td>' +
'</tr>';
};