-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPostnlScreen.qml
304 lines (260 loc) · 9.19 KB
/
PostnlScreen.qml
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
import QtQuick 2.1
import qb.components 1.0
import BasicUIControls 1.0;
import SimpleXmlListModel 1.0
import FileIO 1.0
Screen {
id: postnlScreen
screenTitle: "Recente PostNL pakketten"
property string actualModelText
property string lastupdate : "even geduld...."
property bool postnlLoaded : false
property bool showReceived : true
property string sentParcels
property string receivedParcels
property string shipmentSender
FileIO {
id: postnlInboxFile
source: "file:///tmp/postnl/POSTNL-Inbox.json"
}
FileIO {
id: lastupdateFile
source: "file:///tmp/postnl/lastupdate.log"
}
function formatDeliveryDate(dateString) {
return dateString.substring(0, 10) + " " + dateString.substring(11,16);
}
function formatDelivery(status, deliveryDate, pickupPoint) {
if (status == 'Delivered') {
return "Afgeleverd op " + deliveryDate;
} else {
if (status == 'ReturnToSender') {
return " ";
} else {
if (pickupPoint.length > 1) {
return "Af te halen bij " + pickupPoint;
} else {
return "Onderweg, aflevering vanaf " + deliveryDate;
}
}
}
}
onShown: {
// add settingsscreen button
addCustomTopRightButton("Instellingen");
if (app.postnlShowHistoryInMonths == 1) {
actualModelText = "pakketten van de afgelopen maand: (" + lastupdate + ")"
} else {
actualModelText = "pakketten van de afgelopen " + app.postnlShowHistoryInMonths + " maanden: (" + lastupdate + ")"
}
}
onCustomButtonClicked: {
if (app.postnlConfigurationScreen) app.postnlConfigurationScreen.show();
}
function refreshScreen() {
refreshPostnlModel();
}
function refreshPostnlModel() {
var lastupdateText = lastupdateFile.read();
lastupdate = lastupdateText.substring(0,16) + " ";
// clear Tile
app.tileDate = "";
app.tileTime = "";
app.tileBarcode = "Geen pakketten verwacht";
app.tileSender = "";
app.tileParcelName = "";
// read inbox
var postNLData = JSON.parse(postnlInboxFile.read());
if (postNLData['receiver'].length > 0) {
//format tile when parcel is coming
if ((postNLData['receiver'][0]['delivery']['status'] !== 'Delivered') && (postNLData['receiver'][0]['shipmentType'] !== 'Pending')) {
if (postNLData['receiver'][0]['delivery']['timeframe']['from']) {
app.tileDate = postNLData['receiver'][0]['delivery']['timeframe']['from'].substring(0,10);
app.tileTime = postNLData['receiver'][0]['delivery']['timeframe']['from'].substring(11,16) + " - " + postNLData['receiver'][0]['delivery']['timeframe']['to'].substring(11,16);
} else {
if (postNLData['receiver'][0]['deliveryLocation']['name']) {
app.tileDate = " ";
app.tileTime = "ophalen bij " + postNLData['receiver'][0]['deliveryLocation']['name'];
} else {
app.tileDate = " ";
app.tileTime = " ";
}
}
app.tileBarcode = postNLData['receiver'][0]['barcode'];
if (postNLData['receiver'][0]['sender']['companyName']) {
app.tileSender = postNLData['receiver'][0]['sender']['companyName'];
}
if (app.enableUseCustomParcelName == true && postNLData['receiver'][0]['trackedShipment']['title']) {
app.tileParcelName = postNLData['receiver'][0]['trackedShipment']['title'];
}
}
}
// fill screen
receivedParcels = "<item>";
sentParcels = "<item>";
var shipmentDate = "";
shipmentSender = "";
var shipmentTitle = "";
var tileParcelName = "";
var pickupPoint = "";
// calculate cut off date showing parcels
var now = new Date();
var thisMonth = now.getMonth();
now.setMonth(thisMonth - app.postnlShowHistoryInMonths); // x months in the past
var strMon = now.getMonth() + 1;
if (strMon < 10) {
strMon = "0" + strMon;
}
var strDay = now.getDate();
if (strDay < 10) {
strDay = "0" + strDay;
}
var cutoffDate = now.getFullYear() + "-" + strMon + "-" + strDay;
// get incoming shipments
for (var i = 0; i < postNLData['receiver'].length; i++) {
if (postNLData['receiver'][i]['shipmentType'] !== 'Pending') {
// determine date
pickupPoint = "";
if (postNLData['receiver'][i]['delivery']['status'] == 'Delivered') {
shipmentDate = formatDeliveryDate(postNLData['receiver'][i]['delivery']['deliveryDate']);
shipmentTitle = "Ontvangen van ";
} else {
if (postNLData['receiver'][i]['delivery']['timeframe']['from']) {
shipmentDate = formatDeliveryDate(postNLData['receiver'][i]['delivery']['timeframe']['from']);
} else {
shipmentDate = "";
}
if (postNLData['receiver'][i]['delivery']['status'] == 'ReturnToSender') {
shipmentTitle = "Retour afzender ";
} else {
if (postNLData['receiver'][i]['delivery']['status'] == 'InTransit') {
shipmentTitle = "Zending ontvangen door PostNL, van ";
if (postNLData['receiver'][i]['deliveryLocation']) {
if (postNLData['receiver'][i]['deliveryLocation']['name']) pickupPoint = postNLData['receiver'][i]['deliveryLocation']['name'];
}
} else {
shipmentTitle = "Te ontvangen van ";
}
}
}
if ((cutoffDate < shipmentDate.substring(0,10)) || (postNLData['receiver'][i]['delivery']['status'] == 'InTransit')) {
// determine sender
if (postNLData['receiver'][i]['sender']) {
if (postNLData['receiver'][i]['sender']['companyName']) {
shipmentSender = postNLData['receiver'][i]['sender']['companyName'] + " (" + postNLData['receiver'][i]['sender']['town'] + ")";
} else {
shipmentSender = postNLData['receiver'][i]['sender']['lastName'] + " (" + postNLData['receiver'][i]['sender']['town'] + ")";
}
} else {
shipmentSender = "onbekende afzender";
}
shipmentSender = shipmentSender.replace(String.fromCharCode(38), "-");
if (app.enableUseCustomParcelName == true && postNLData['receiver'][i]['trackedShipment']['title']) {
tileParcelName = postNLData['receiver'][i]['trackedShipment']['title'] + " - " + postNLData['receiver'][i]['barcode'];
} else {
tileParcelName = postNLData['receiver'][i]['barcode'];
}
pickupPoint =
receivedParcels = receivedParcels + "<parcel><deliveryDate>" + shipmentDate + "</deliveryDate><deliveryInfo>" + formatDelivery(postNLData['receiver'][i]['delivery']['status'], shipmentDate, pickupPoint) + "</deliveryInfo><barcode>" + tileParcelName + "</barcode><senderInfo>" + shipmentTitle + shipmentSender + "</senderInfo></parcel>";
}
}
}
// add outgoing shipments
for (var j = 0; j < postNLData['sender'].length; j++) {
pickupPoint = "";
if (postNLData['sender'][j]['delivery']['deliveryDate']) {
shipmentDate = formatDeliveryDate(postNLData['sender'][j]['delivery']['deliveryDate']);
} else {
if (postNLData['sender'][j]['delivery']['timeframe']['from']) {
shipmentDate = formatDeliveryDate(postNLData['sender'][j]['delivery']['timeframe']['from']);
} else {
shipmentDate = "";
}
}
if (cutoffDate < shipmentDate.substring(0,10)) {
sentParcels = sentParcels + "<parcel><deliveryDate>" + shipmentDate + "</deliveryDate><deliveryInfo>" + formatDelivery(postNLData['sender'][j]['delivery']['status'], shipmentDate, pickupPoint) + "</deliveryInfo><barcode>" + postNLData['sender'][j]['barcode'] + "</barcode><senderInfo>" + "Verstuurd naar " + postNLData['sender'][j]['originalReceiver']['street'] + " " + postNLData['sender'][j]['originalReceiver']['houseNumber'] + ", " + postNLData['sender'][j]['originalReceiver']['town'] + "</senderInfo></parcel>";
}
}
receivedParcels = receivedParcels + "</item>";
sentParcels = sentParcels + "</item>";
postnlModel.xml = receivedParcels;
showReceived = true;
postnlSimpleList.initialView();
postnlLoaded = true;
}
Item {
id: header
height: isNxt ? 55 : 45
width: parent.width
StandardButton {
id: showParcelType
height: isNxt ? 40 : 32
text: (showReceived) ? "Ontvangen " : "Verstuurde "
fontPixelSize: isNxt ? 25 : 20
color: colors.background
anchors {
bottom: parent.bottom
left: parent.left
leftMargin : 10
}
onClicked: {
if (showReceived) {
showReceived = false;
postnlModel.xml = sentParcels;
} else {
showReceived = true;
postnlModel.xml = receivedParcels;
}
postnlSimpleList.initialView();
}
}
Text {
id: headerText
text: actualModelText
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 25 : 20
anchors {
left: showParcelType.right
leftMargin: isNxt ? 16 : 12
top: showParcelType.top
topMargin : isNxt ? 4 : 3
}
}
}
SimpleXmlListModel {
id: postnlModel
query: "/item/parcel"
roles: ({
deliveryDate: "string",
deliveryInfo: "string",
barcode: "string",
senderInfo: "string"
})
}
Rectangle {
id: content
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - 20
height: isNxt ? parent.height - 74 : parent.height - 49
y: isNxt ? 64 : 51
x: 10
radius: 3
PostnlSimpleList {
id: postnlSimpleList
delegate: PostnlScreenDelegate{}
dataModel: postnlModel
itemHeight: isNxt ? 30 : 23
itemsPerPage: 7
anchors.top: parent.top
downIcon: "qrc:/tsc/arrowScrolldown.png"
buttonsHeight: isNxt ? 180 : 144
buttonsVisible: true
scrollbarVisible: true
}
Throbber {
id: refreshThrobber
anchors.centerIn: parent
visible: !postnlLoaded
}
}
}