-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPurchasesPastDue_example.html
112 lines (86 loc) · 3.91 KB
/
PurchasesPastDue_example.html
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
<!doctype html><html lang="en"> <head>
<meta charset="utf-8"> <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Expires" content="0"/><meta http-equiv="Pragma" content="no-cache"/> <title> Pastdue </title>
<style type="text/css">
/*---------------------------------------------------------------------------------------------*/
/*CSS Reset */ * { margin: 1; padding: 1 }
tr, th, td, table { border-collapse: collapse; border-width: 1px; border-style: solid; border-color: #DDD;
padding: 2px; white-space: nowrap; font-family: 'Lucida Console'; font-size: 12px }
th { text-align: left; background-color: #DDD; border-color: #AAA }
/*----------------------------------------------------------------------------------------------*/</style></head><body>
<div id="divContent" style=" top: 1px;
left: 1px; right: 1px;
bottom: 1px "></div>
<!--=================================================================================================--></body><script>
const Console_Show_Qry = 0; // (0/1) --- Show Query text in console
var RestURL = "http://localhost:8888/";
window.onload = function()
{
divContent.innerHTML = "";
RunQrys(
[{
Db: "MDB://C:\\Data\\Sample.mdb",
Qry: `SELECT CustName, Phone, Description, Price, AmountPaid, Price - AmountPaid AS Balance, PurchDate
FROM Purchases LEFT JOIN Customers
ON Purchases.CustomerID = Customers.CustomerID
WHERE Price - AmountPaid > 0
AND NOW() - PurchDate > 30`
}],
Each_CallBackFn = function(Data)
{
if (Data.ConData.RecordCount === 0)
divContent.innerHTML += "No PDM files locked. <br>\r\n";
else
divContent.innerHTML += "PDM files locked: <br>\r\n" + ToTable(Data) + "<br>\r\n";
},
Final_CallBackFn = function(Datas)
{
//
});
}
// ----------------------------------------- Table helper functions -------
function ToTable(Data) // Values_2D-Array => table
{
let TH = "<tr>"
+ Data.ConData.Names.reduce((a,v) => `${a}<th>${v}</th>`, '')
+ "</tr>\r\n"; // Table header
return ''
+ "<table>\r\n" + TH
+ Data.ConData.Values.reduce((a,v) => a + "<tr>\r\n" + v.reduce((a2,v2) => `${a2}<td>${v2}</td>`, '')
+ "</tr>\r\n", '')
+ "</table>\r\n";
}
// ----------------------------------------- Query helper functions --------
function RunQrys(Datas, Each_CallBackFn, Final_CallBackFn, Each_Sync)
{
var QrysLeft = Datas.length;
Datas.forEach(function(Data, Index)
{
Data.Con = new XMLHttpRequest();
Data.Con.onreadystatechange = function()
{
if (Data.Con.readyState == 4 && Data.Con.status == 200)
{
if (Console_Show_Qry)
{
console.log("Received: ", Data.Con.responseText);
}
Data.ConData = JSON.parse(Data.Con.responseText);
Data.Done = true;
QrysLeft--;
if (Each_CallBackFn) Each_CallBackFn(Data);
if (QrysLeft <= 0)
{
if (Final_CallBackFn) Final_CallBackFn(Datas);
}
}
};
Data.Con.open("POST", RestURL, !Each_Sync);
Data.Con.send(Data.Db + "\r\n //// \r\n" + Data.Qry);
if (Console_Show_Qry)
{
console.info(location.href, Data, Data.Db, Data.Qry);
}
});
}
/*---------------------------------------------------------------------------------------------------*/</script></html>