alsmanager_lib 1.0.60 → 1.0.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/modules.js +123 -32
  2. package/package.json +1 -1
package/lib/modules.js CHANGED
@@ -1126,6 +1126,12 @@ function getDevicesSelectMySQL(search_type, inv_code, dev_type, marca, is_PNRR,
1126
1126
  }
1127
1127
  if (is_PNRR && is_PNRR > 0) {
1128
1128
  where_clause += " (d.inv_pnrr_number <> '' and inv_pnrr_number is not null) ";
1129
+ if (dev_status) {
1130
+ where_clause += " and ";
1131
+ }
1132
+ }
1133
+ if (dev_status) {
1134
+ where_clause += " du.status = :dev_status and CURRDATE() >= du.date_status";
1129
1135
  }
1130
1136
  }
1131
1137
  }
@@ -1492,11 +1498,11 @@ function queryDeviceStatusSQLite(id_device, date_ref) {
1492
1498
  switch (date_ref) {
1493
1499
  case "current":
1494
1500
  query += " and ";
1495
- query += " (date('now') >= du.date_status and date('now') <= du.date_end)";
1501
+ query += " (date('now') >= du.date_status";
1496
1502
  break;
1497
1503
  default:
1498
1504
  query += " and ";
1499
- query += " ('" + date_ref + "' >= du.date_status and '" + date_ref + "' <= du.date_end)";
1505
+ query += " ('" + date_ref + "' >= du.date_status)";
1500
1506
  break;
1501
1507
 
1502
1508
  }
@@ -1510,11 +1516,11 @@ function queryDeviceStatusMySQL(id_device, date_ref) {
1510
1516
  switch (date_ref) {
1511
1517
  case "current":
1512
1518
  query += " and ";
1513
- query += " (CURDATE() >= du.date_status and CURDATE() <= du.date_end)";
1519
+ query += " (CURDATE() >= du.date_status)";
1514
1520
  break;
1515
1521
  default:
1516
1522
  query += " and ";
1517
- query += " (:date_ref >= du.date_status and :date_ref <= du.date_end)";
1523
+ query += " (:date_ref >= du.date_status)";
1518
1524
  break;
1519
1525
 
1520
1526
  }
@@ -1538,12 +1544,12 @@ function queryDeviceStatus(db_used, id_device, date_ref) {
1538
1544
  //End Get Device Status
1539
1545
  // Insert device status
1540
1546
  function updateDeviceStatusSQLite(id_device) {
1541
- var query = "update device_usage set date_end = date('now','-1 day') ";
1542
- query += "where id_device = " + id_device + " and date_in = (select max(date_in) from device_usage where id_device = " + id_device + ")";
1547
+ var query = "update device_usage set date_end = date('now') ";
1548
+ query += "where id_device = " + id_device + " and date_status = (select max(date_status) from device_usage where id_device = " + id_device + ")";
1543
1549
  return query;
1544
1550
  }
1545
1551
  function updateDeviceStatusMySQL(id_device) {
1546
- var query = "update device_usage set date_end = date('now','-1 day') ";
1552
+ var query = "update device_usage set date_end = CURDATE() ";
1547
1553
  query += "where id_device = :id_device and date_status = (select max(date_status) from device_usage where id_device = :id_device)";
1548
1554
  return query;
1549
1555
  }
@@ -1565,7 +1571,7 @@ function updateDeviceStatus(db_used, id_device) {
1565
1571
  // end manage updateDevicesStatus
1566
1572
  // Manage insertDeviceStatus
1567
1573
  function insertDeviceStatusSQLite(id_device, dev_status, start_date) {
1568
- var query = "insert into device_usage (date_status, date_end, id_device, status) ";
1574
+ var query = "insert into device_usage (date_status, id_device, status) ";
1569
1575
  query += "values (";
1570
1576
  if ((!start_date || start_date == '') || start_date == "TODAY") {
1571
1577
  query += "date('now'),";
@@ -1573,14 +1579,13 @@ function insertDeviceStatusSQLite(id_device, dev_status, start_date) {
1573
1579
  else {
1574
1580
  query += "'" + start_date + "',";
1575
1581
  }
1576
- query += "'2999-12-31',";
1577
1582
  query += id_device + ",";
1578
1583
  query += dev_status;
1579
1584
  query += ")";
1580
1585
  return query;
1581
1586
  }
1582
1587
  function insertDeviceStatusMySQL(id_device, dev_status, start_date) {
1583
- var query = "insert into device_usage (date_status, date_end, id_device, status) ";
1588
+ var query = "insert into device_usage (date_status, id_device, status) ";
1584
1589
  query += "values (";
1585
1590
  if ((!start_date || start_date == '') || start_date == "TODAY") {
1586
1591
  query += "CURDATE(),";
@@ -1588,7 +1593,6 @@ function insertDeviceStatusMySQL(id_device, dev_status, start_date) {
1588
1593
  else {
1589
1594
  query += ":start_date,";
1590
1595
  }
1591
- query += "'2999-12-31',";
1592
1596
  query += ":id_device,";
1593
1597
  query += ":dev_status";
1594
1598
  query += ")";
@@ -2396,10 +2400,10 @@ function getBeniDaInventariOnDescriptionMySQL(table_name, search_string, include
2396
2400
  query += "from :table_name imp ";
2397
2401
  }
2398
2402
  }
2399
- if (inv_code && table_name) {
2403
+ if (search_string && table_name) {
2400
2404
  if (table_name != "devices" && is_pnrr != 1 && is_dismissione != 1) {
2401
- query += " where Inventario = '" + inv_code +"' or ";
2402
- query += " Precedente = '" + inv_code +"' ";
2405
+ query += " where Inventario = '" + search_string +"' or ";
2406
+ query += " Precedente = '" + search_string +"' ";
2403
2407
  if (!include_imp || include_imp == 0) {
2404
2408
  query += "and d.id is null"
2405
2409
  }
@@ -2420,10 +2424,10 @@ function getBeniDaInventariOnDescription(db_used, table_name, search_string, inc
2420
2424
  if (db_used) {
2421
2425
  switch (db_used) {
2422
2426
  case 'SQLITE':
2423
- query = getBeniDaInventariOnDescriptionSQLite(table_name, inv_code, include_imp, is_pnrr, is_dismissione);
2427
+ query = getBeniDaInventariOnDescriptionSQLite(table_name, search_string, include_imp, is_pnrr, is_dismissione);
2424
2428
  break;
2425
2429
  case 'MYSQL':
2426
- query = getBeniDaInventariOnDescriptionMySQL(table_name, inv_code, include_imp, is_pnrr, is_dismissione);
2430
+ query = getBeniDaInventariOnDescriptionMySQL(table_name, search_string, include_imp, is_pnrr, is_dismissione);
2427
2431
  break;
2428
2432
  }
2429
2433
  }
@@ -3183,7 +3187,7 @@ function queryDeviceTypes() {
3183
3187
  return query;
3184
3188
  }
3185
3189
  // Define getDevicesNotAllocatedCombo
3186
- function getDevicesNotAllocatedComboSQLite() {
3190
+ function getDevicesNotAllocatedComboSQLite(ordered_by) {
3187
3191
  var query = "SELECT d.id, d.type as Tipo, d.manifacturer as Marca, d.model as Modello, ";
3188
3192
  query += "case ";
3189
3193
  query += "when d.inv_ict3_number != '' and d.inv_ict3_number is not null then concat(d.inv_ict3_number, ' - ', d.type, ' - ', d.manifacturer, ' - ', d.model) ";
@@ -3198,11 +3202,16 @@ function getDevicesNotAllocatedComboSQLite() {
3198
3202
  query += "where (d.is_removed is null or d.is_removed = 0) "
3199
3203
  query += "and (ds.id_place is null ";
3200
3204
  query += "or (ds.date_in <= date('now') and ds.date_out >= date('now') and sd.type = 'MAGAZZINO')) ";
3201
- query += "order by d.inv_ict3_number";
3205
+ if (ordered_by && ordered_by == "ID") {
3206
+ query += "order by d.id desc";
3207
+ }
3208
+ else {
3209
+ query += "order by d.inv_ict3_number";
3210
+ }
3202
3211
  return query;
3203
3212
  }
3204
3213
 
3205
- function getDevicesNotAllocatedComboMySQL() {
3214
+ function getDevicesNotAllocatedComboMySQL(ordered_by) {
3206
3215
  var query = "SELECT d.id, d.type as Tipo, d.manifacturer as Marca, d.model as Modello, ";
3207
3216
  query += "case ";
3208
3217
  query += "when d.inv_ict3_number != '' and d.inv_ict3_number is not null then concat(d.inv_ict3_number, ' - ', d.type, ' - ', d.manifacturer, ' - ', d.model) ";
@@ -3217,18 +3226,23 @@ function getDevicesNotAllocatedComboMySQL() {
3217
3226
  query += "where (d.is_removed is null or d.is_removed = 0) "
3218
3227
  query += "and (ds.id_place is null ";
3219
3228
  query += "or (ds.date_in <= CURDATE() and ds.date_out >= CURDATE() and sd.type = 'MAGAZZINO')) ";
3220
- query += "order by d.inv_ict3_number";
3229
+ if (ordered_by && ordered_by == "ID") {
3230
+ query += "order by d.id desc";
3231
+ }
3232
+ else {
3233
+ query += "order by d.inv_ict3_number";
3234
+ }
3221
3235
  return query;
3222
3236
  }
3223
- function getDevicesNotAllocatedCombo(db_used) {
3237
+ function getDevicesNotAllocatedCombo(db_used,ordered_by) {
3224
3238
  var query = "";
3225
3239
  if (db_used) {
3226
3240
  switch (db_used) {
3227
3241
  case 'SQLITE':
3228
- query = getDevicesNotAllocatedComboSQLite();
3242
+ query = getDevicesNotAllocatedComboSQLite(ordered_by);
3229
3243
  break;
3230
3244
  case 'MYSQL':
3231
- query = getDevicesNotAllocatedComboMySQL();
3245
+ query = getDevicesNotAllocatedComboMySQL(ordered_by);
3232
3246
  break;
3233
3247
  }
3234
3248
  }
@@ -3236,7 +3250,7 @@ function getDevicesNotAllocatedCombo(db_used) {
3236
3250
  }
3237
3251
  // End getDevicesNotAllocatedCombo
3238
3252
  // Define getDevicesAllocatedCombo
3239
- function getDevicesAllocatedComboSQLite(id_site, id_place) {
3253
+ function getDevicesAllocatedComboSQLite(id_site, id_place, ordered_by) {
3240
3254
  var query = "SELECT d.id, d.type as Tipo, d.manifacturer as Marca, d.model as Modello, ";
3241
3255
  query += "case ";
3242
3256
  query += "when d.inv_ict3_number != '' and d.inv_ict3_number is not null then concat(d.inv_ict3_number, ' - ', d.type, ' - ', d.manifacturer, ' - ', d.model) ";
@@ -3251,10 +3265,15 @@ function getDevicesAllocatedComboSQLite(id_site, id_place) {
3251
3265
  query += "where (d.is_removed is null or d.is_removed = 0) "
3252
3266
  query += "and (ds.id_place is not null ";
3253
3267
  query += "or (ds.date_in <= date('now') and ds.date_out >= date('now') and ds.id_site <> " + id_site + " and ds.id_place <> '" + id_place + "')) ";
3254
- query += "order by d.inv_ict3_number";
3268
+ if (ordered_by && ordered_by == "ID") {
3269
+ query += "order by d.id desc";
3270
+ }
3271
+ else {
3272
+ query += "order by d.inv_ict3_number";
3273
+ }
3255
3274
  return query;
3256
3275
  }
3257
- function getDevicesAllocatedComboMySQL(id_site, id_place) {
3276
+ function getDevicesAllocatedComboMySQL(id_site, id_place, ordered_by) {
3258
3277
  var query = "SELECT d.id, d.type as Tipo, d.manifacturer as Marca, d.model as Modello, ";
3259
3278
  query += "case ";
3260
3279
  query += "when d.inv_ict3_number != '' and d.inv_ict3_number is not null then concat(d.inv_ict3_number, ' - ', d.type, ' - ', d.manifacturer, ' - ', d.model) ";
@@ -3269,18 +3288,23 @@ function getDevicesAllocatedComboMySQL(id_site, id_place) {
3269
3288
  query += "where (d.is_removed is null or d.is_removed = 0) "
3270
3289
  query += "and (ds.id_place is not null ";
3271
3290
  query += "or (ds.date_in <= CURDATE() and ds.date_out >= CURDATE() and ds.id_site <> :id_site and ds.id_place <> :id_place)) ";
3272
- query += "order by d.inv_ict3_number";
3291
+ if (ordered_by && ordered_by == "ID") {
3292
+ query += "order by d.id desc";
3293
+ }
3294
+ else {
3295
+ query += "order by d.inv_ict3_number";
3296
+ }
3273
3297
  return query;
3274
3298
  }
3275
- function getDevicesAllocatedCombo(db_used, id_site, id_place) {
3299
+ function getDevicesAllocatedCombo(db_used, id_site, id_place, ordered_by) {
3276
3300
  var query = "";
3277
3301
  if (db_used) {
3278
3302
  switch (db_used) {
3279
3303
  case 'SQLITE':
3280
- query = getDevicesAllocatedComboSQLite(id_site, id_place);
3304
+ query = getDevicesAllocatedComboSQLite(id_site, id_place, ordered_by);
3281
3305
  break;
3282
3306
  case 'MYSQL':
3283
- query = getDevicesAllocatedComboMySQL(id_site, id_place);
3307
+ query = getDevicesAllocatedComboMySQL(id_site, id_place, ordered_by);
3284
3308
  break;
3285
3309
  }
3286
3310
  }
@@ -6808,10 +6832,14 @@ function verifyPrevDeviceSite(db_used, id_device) {
6808
6832
  }
6809
6833
 
6810
6834
  function removeDeviceSiteSQLite(id_site, id_place, id_device) {
6811
-
6835
+ var query = "delete from device_site ";
6836
+ query += "where id_device = " + id_device + " and date_in = (select max(date_in) from device_site where id_device = " + id_device + ")";
6837
+ return query;
6812
6838
  }
6813
6839
  function removeDeviceSiteMySQL(id_site, id_place, id_device) {
6814
-
6840
+ var query = "delete from device_site ";
6841
+ query += "where id_device = :id_device and date_in = (select max(date_in) from device_site where id_device = :id_device)";
6842
+ return query;
6815
6843
  }
6816
6844
  function removeDeviceSite(db_used,id_site, id_place, id_device) {
6817
6845
  var query = "";
@@ -6828,6 +6856,32 @@ function removeDeviceSite(db_used,id_site, id_place, id_device) {
6828
6856
  return query;
6829
6857
  }
6830
6858
 
6859
+ function updateDeviceSiteAfterRemoveSQLite(id_device) {
6860
+ var query = "update device_site set date_out = '2999-12-31' ";
6861
+ query += "where id_device = " + id_device + " and date_in = (select max(date_in) from device_site where id_device = " + id_device + ")";
6862
+ return query;
6863
+ }
6864
+ function updateDeviceSiteAfterRemoveMySQL(id_device) {
6865
+ var query = "update device_site set date_out = '2999-12-31' ";
6866
+ query += "where id_device = :id_device and date_in = (select max(date_in) from device_site where id_device = :id_device)";
6867
+ return query;
6868
+ }
6869
+ function updateDeviceSiteAfterRemove(db_used,id_device) {
6870
+ var query = "";
6871
+ if (db_used) {
6872
+ switch (db_used) {
6873
+ case 'SQLITE':
6874
+ query = updateDeviceSiteAfterRemoveSQLite(id_device);
6875
+ break;
6876
+ case 'MYSQL':
6877
+ query = updateDeviceSiteAfterRemoveMySQL(id_device);
6878
+ break;
6879
+ }
6880
+ }
6881
+ return query;
6882
+ }
6883
+
6884
+
6831
6885
  function updateDeviceSiteSQLite(id_device) {
6832
6886
  var query = "update device_site set date_out = date('now','-1 day') ";
6833
6887
  query += "where id_device = " + id_device + " and date_in = (select max(date_in) from device_site where id_device = " + id_device + ")";
@@ -6901,6 +6955,34 @@ function insertDeviceSite(db_used,id_device, id_place, id_site, start_date) {
6901
6955
  return query;
6902
6956
  }
6903
6957
  // end manage updateDevicesSite
6958
+ //
6959
+ function removeDeviceFromAllSitesSQLite(id_device) {
6960
+ var query = "delete from device_site ";
6961
+ query += "where id_device = " + id_device;
6962
+ return query;
6963
+ }
6964
+ function removeDeviceFromAllSitesMySQL(id_device) {
6965
+ var query = "delete from device_site ";
6966
+ query += "where id_device = :id_device";
6967
+ return query;
6968
+ }
6969
+ function removeDeviceFromAllSites(db_used, id_device) {
6970
+ var query = "";
6971
+ if (db_used) {
6972
+ switch (db_used) {
6973
+ case 'SQLITE':
6974
+ query = removeDeviceFromAllSitesSQLite(id_device);
6975
+ break;
6976
+ case 'MYSQL':
6977
+ query = removeDeviceFromAllSitesMySQL(id_device);
6978
+ break;
6979
+ }
6980
+ }
6981
+ return query;
6982
+ }
6983
+
6984
+
6985
+
6904
6986
  //Get Sites for Combo
6905
6987
  function getSitesSelectComboSQLite(id_place, tipo_aula) {
6906
6988
  var query = "select s.id, concat(p.name, ' - ', sd.name, ' - ', s.mark) as Descrizione from sites s ";
@@ -7433,6 +7515,13 @@ function queryStatisticsDeviceStatusSQLite() {
7433
7515
  return query;
7434
7516
  }
7435
7517
  function queryStatisticsDeviceStatusMySQL() {
7518
+ var query = "select case when ds.status is null then 0 else ds.status end as Stato, sd.name as Descrizione, count(*) as Numero from devices d ";
7519
+ query += "left join device_usage ds on d.id = ds.id_device ";
7520
+ query += "join status_description sd on sd.id = Stato "
7521
+ query += "where CURDATE() >= ds.date_status or Stato = 0 ";
7522
+ query += "and (is_removed is null or is_removed = 0) ";
7523
+ query += "group by Stato";
7524
+ return query;
7436
7525
  }
7437
7526
  function queryStatisticsDeviceStatus(db_used) {
7438
7527
  var query = "";
@@ -7931,6 +8020,8 @@ module.exports = {
7931
8020
  insertDeviceSite,
7932
8021
  updateDeviceSite,
7933
8022
  removeDeviceSite,
8023
+ updateDeviceSiteAfterRemove,
8024
+ removeDeviceFromAllSites,
7934
8025
  queryPlaces,
7935
8026
  queryFloorsByPlace,
7936
8027
  queryFunzioneByPlaceAndFloor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alsmanager_lib",
3
- "version": "1.0.60",
3
+ "version": "1.0.62",
4
4
  "description": "Funzioni per ALSManager",
5
5
  "license": "ISC",
6
6
  "author": "Luca Cattani",