-
Notifications
You must be signed in to change notification settings - Fork 0
/
ticketData.js
183 lines (139 loc) · 5.83 KB
/
ticketData.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
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
import store from './store/index'
import { imgs } from './asset'
function airportData(iata) {
const airport = store.getters['bookingdat/getAirports'].find(element => element.airportCode == iata)
return { code: iata, name: airport.airportName, address: airport.cityName }
}
function airlineData(airline_id) {
const airline = store.getters['bookingdat/getAirlines'].find(element => element.number == airline_id)
return { name: airline.name, logo: imgs(airline.logo), tail: imgs(airline.tail), iatacode: airline.code }
}
function customDate1(date) {
const newDate = new Date(date)
const month = newDate.toLocaleString('default', { month: 'long' });
const dayName = newDate.toString().split(' ')[0];
return { date: newDate.getDate() + ' '+ month.toUpperCase() + ' | ' + dayName.toUpperCase(),
time: newDate.toLocaleTimeString([], { hour: '2-digit', minute:'2-digit' })
}
}
function customDate2(date) {
const newDate = new Date(date)
const month = newDate.toLocaleString('default', { month: 'short' });
const dayName = newDate.toString().split(' ')[0];
return { date: newDate.getDate() + ' '+ month.toUpperCase() + ' | ' + dayName.toUpperCase(),
time: newDate.toLocaleTimeString([], { hour: '2-digit', minute:'2-digit' })
}
}
function currency() {
var region ='in'
if (region == 'in') { return 'INR '}
else { return 'USD' }
}
function charges(ticket) {
const chargeable_weight = store.getters['bookingdat/getWeight']
if (chargeable_weight != null) {
const airline_cost = chargeable_weight*ticket
return { available: true, rate: ticket, airline_cost: airline_cost, surcharge: (airline_cost*0.02).toFixed(2) + ' @ 2%', total: (airline_cost*1.02).toFixed(1) } ////To be replaced by airline data
} else {
return { available: false, rate: ticket }
}
}
function duration(time) {
let hrs = Math.trunc(time/3600)
if (hrs != 0) {
return hrs + ' hrs '+ (time%3600)/60 + ' min'
} else {
return (time%3600)/60 + ' min'
}
}
function ExpansionData(ticket) {
return {
airline: airlineData(ticket[0]),
source: airportData(ticket[7]),
source_date: customDate2(ticket[4]),
flightid: ticket[3],
flightno: ticket[12],
destination: airportData(ticket[8]),
destination_date: customDate2(ticket[5]),
amount: charges(ticket[2]),
duration: duration(parseInt(ticket[1]))
}
}
function sortedData(ticket) {
return {
source_code: ticket[7],
source_date: customDate2(ticket[4]),
destination_code: ticket[8],
destination_date: customDate2(ticket[5]),
amount: charges(ticket[2]),
duration: duration(parseInt(ticket[1]))
}
}
function unsortedData(ticket) {
return {
airline: airlineData(ticket[0]),
source_code: ticket[7],
source_date: customDate2(ticket[4]),
destination_code: ticket[8],
destination_date: customDate2(ticket[5]),
amount: charges(ticket[2]),
duration: duration(parseInt(ticket[1]))
}
}
function walletData(ticket) {
if (ticket[15] != null) {
return {
airline: airlineData(ticket[0]),
source: airportData(ticket[7]),
source_date: customDate1(ticket[4]),
flightid: ticket[3],
flightno: ticket[12],
destination: airportData(ticket[8]),
destination_date: customDate1(ticket[5]),
cargodetails: { chargeable_weight: ticket[17]+' kg', type: ticket[21] },
rate: currency() + ticket[2]* ticket[17],
duration: duration(parseInt(ticket[1])),
available: true
}
} else {
return {
airline: airlineData(ticket[0]),
source: airportData(ticket[7]),
source_date: customDate1(ticket[4]),
flightid: ticket[3],
flightno: ticket[12],
destination: airportData(ticket[8]),
destination_date: customDate1(ticket[5]),
cargodetails: { chargeable_weight: '--', type: '--' },
rate: currency() + ticket[2] + ' /kg',
duration: duration(parseInt(ticket[1])),
available: false
}
}
}
function transactionData(transaction) {
return {
airline: airlineData(transaction[4]),
transaction_no: transaction[1],
awb: transaction[2],
source: airportData(transaction[6]),
source_date: customDate2(transaction[7]),
flightid: transaction[3],
flightno: transaction[5],
destination: airportData(transaction[8]),
destination_date: customDate2(transaction[9]),
rate: currency() + transaction[18],
cargo: { metric: transaction[11], weight: transaction[12], length: transaction[13],
width: transaction[14], height: transaction[15], quantity: transaction[16],
cargo_type: transaction[19], stackable: transaction[20], turnable: transaction[21]
},
status: transaction[22]
}
}
function quoteData(ticket) {
return [ airlineData(ticket[0]).name, "007", ticket[1], ticket[2],
new Date(ticket[3]).toLocaleTimeString(), new Date(ticket[3]).toLocaleDateString(),
new Date(ticket[4]).toLocaleTimeString(), new Date(ticket[4]).toLocaleDateString(),
ticket[5] ]
}
export { airportData, airlineData, sortedData, unsortedData, ExpansionData, walletData, transactionData, quoteData, customDate1, customDate2 }