alsmanager_lib 3.0.139 → 3.0.140

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 +147 -33
  2. package/package.json +1 -1
package/lib/modules.js CHANGED
@@ -2918,7 +2918,7 @@ function getDevicesSelectSQLite(search_type, inv_code, dev_type, marca, dev_mode
2918
2918
  }
2919
2919
  }
2920
2920
  if (dev_status) {
2921
- where_clause += " du.status = " + dev_status + " and date('now') >= du.date_status";
2921
+ where_clause += " du.status = " + dev_status + " and (date('now') >= du.date_start and date('now') <= du.date_end)";
2922
2922
  if (dev_gestione || no_inv || in_consegna) {
2923
2923
  where_clause += " and ";
2924
2924
  }
@@ -3010,7 +3010,7 @@ function getDevicesSelectMySQL(search_type, inv_code, dev_type, marca, dev_model
3010
3010
  }
3011
3011
  }
3012
3012
  if (dev_status) {
3013
- where_clause += " du.status = :dev_status and CURDATE() >= du.date_status";
3013
+ where_clause += " du.status = :dev_status and (CURDATE() >= du.date_start and CURDATE() <= du.date_end) ";
3014
3014
  if (dev_gestione || no_inv) {
3015
3015
  where_clause += " and ";
3016
3016
  }
@@ -3103,7 +3103,7 @@ function getDevicesSelectMySQL2(search_type, inv_code, dev_type, marca, dev_mode
3103
3103
  }
3104
3104
  }
3105
3105
  if (dev_status) {
3106
- where_clause += " du.status = " + dev_status + " and CURDATE() >= du.date_status";
3106
+ where_clause += " du.status = :dev_status and (CURDATE() >= du.date_start and CURDATE() <= du.date_end) ";
3107
3107
  if (dev_gestione || no_inv || in_consegna) {
3108
3108
  where_clause += " and ";
3109
3109
  }
@@ -3720,10 +3720,10 @@ function queryDeviceStatusSQLite(id_device, date_ref) {
3720
3720
  if (date_ref) {
3721
3721
  switch (date_ref) {
3722
3722
  case "current":
3723
- query += "and date('now') >= du.date_status ";
3723
+ query += "and (date('now') >= du.date_start and date('now') <= du.date_end)";
3724
3724
  break;
3725
3725
  default:
3726
- query += "and '" + date_ref + "' >= du.date_status ";
3726
+ query += "and ('" + date_ref + "' >= du.date_start and '" + date_ref + "' <= du.date_end)";
3727
3727
  break;
3728
3728
 
3729
3729
  }
@@ -3737,10 +3737,10 @@ function queryDeviceStatusMySQL(id_device, date_ref) {
3737
3737
  if (date_ref) {
3738
3738
  switch (date_ref) {
3739
3739
  case "current":
3740
- query += "and (CURDATE() >= du.date_status ";
3740
+ query += "and (CURDATE() >= du.date_start and CURDATE() <= du.date_end) ";
3741
3741
  break;
3742
3742
  default:
3743
- query += "and :date_ref >= du.date_status ";
3743
+ query += "and (:date_ref >= du.date_start and :date_ref <= du.date_end) ";
3744
3744
  break;
3745
3745
 
3746
3746
  }
@@ -3754,10 +3754,10 @@ function queryDeviceStatusMySQL2(id_device, date_ref) {
3754
3754
  if (date_ref) {
3755
3755
  switch (date_ref) {
3756
3756
  case "current":
3757
- query += "and CURDATE() >= du.date_status ";
3757
+ query += "and (CURDATE() >= du.date_start and CURDATE() <= du.date_end) ";
3758
3758
  break;
3759
3759
  default:
3760
- query += "and '" + date_ref + "' >= du.date_status ";
3760
+ query += "and ('" + date_ref + "' >= du.date_start and '" + date_ref + "' <= du.date_end)";
3761
3761
  break;
3762
3762
 
3763
3763
  }
@@ -3785,35 +3785,37 @@ function queryDeviceStatus(db_used, id_device, date_ref) {
3785
3785
  //End Get Device Status
3786
3786
  // Manage insertDeviceStatus
3787
3787
  function insertDeviceStatusSQLite(id_device, dev_status, start_date) {
3788
- var query = "insert into device_usage (date_status, id_device, status) ";
3788
+ var query = "insert into device_usage (date_start, date_end, id_device, status) ";
3789
3789
  query += "values (";
3790
3790
  if ((!start_date || start_date == '') || start_date == "TODAY") {
3791
- query += "date('now'),";
3791
+ query += "date('now'), ";
3792
3792
  }
3793
3793
  else {
3794
- query += "'" + start_date + "',";
3794
+ query += "'" + start_date + "', ";
3795
3795
  }
3796
+ query += "'2999-12-31', ";
3796
3797
  query += id_device + ",";
3797
3798
  query += dev_status;
3798
3799
  query += ")";
3799
3800
  return query;
3800
3801
  }
3801
3802
  function insertDeviceStatusMySQL(id_device, dev_status, start_date) {
3802
- var query = "insert into device_usage (date_status, id_device, status) ";
3803
+ var query = "insert into device_usage (date_start, date_end, id_device, status) ";
3803
3804
  query += "values (";
3804
3805
  if ((!start_date || start_date == '') || start_date == "TODAY") {
3805
- query += "CURDATE(),";
3806
+ query += "CURDATE(), ";
3806
3807
  }
3807
3808
  else {
3808
- query += ":start_date,";
3809
+ query += ":start_date, ";
3809
3810
  }
3811
+ query += "'2999-12-31', ";
3810
3812
  query += ":id_device,";
3811
3813
  query += ":dev_status";
3812
3814
  query += ")";
3813
3815
  return query;
3814
3816
  }
3815
3817
  function insertDeviceStatusMySQL2(id_device, dev_status, start_date) {
3816
- var query = "insert into device_usage (date_status, id_device, status) ";
3818
+ var query = "insert into device_usage (date_start, date_end, id_device, status) ";
3817
3819
  query += "values (";
3818
3820
  if ((!start_date || start_date == '') || start_date == "TODAY") {
3819
3821
  query += "CURDATE(),";
@@ -3821,6 +3823,7 @@ function insertDeviceStatusMySQL2(id_device, dev_status, start_date) {
3821
3823
  else {
3822
3824
  query += "'" + start_date + "',";
3823
3825
  }
3826
+ query += "'2999-12-31', ";
3824
3827
  query += id_device + ",";
3825
3828
  query += dev_status;
3826
3829
  query += ")";
@@ -3844,7 +3847,71 @@ function insertDeviceStatus(db_used, id_device, dev_status, start_date) {
3844
3847
  return query;
3845
3848
  }
3846
3849
  //end insert device status
3847
- // Remove device status
3850
+ // Manage updateDeviceStatus
3851
+ function updateDeviceStatusSQLite(id_device, dev_status, start_date) {
3852
+ var query = "update device_usage (date_start, date_end, id_device, status) ";
3853
+ query += "values (";
3854
+ if ((!start_date || start_date == '') || start_date == "TODAY") {
3855
+ query += "date('now'), ";
3856
+ }
3857
+ else {
3858
+ query += "'" + start_date + "', ";
3859
+ }
3860
+ query += "'2999-12-31', ";
3861
+ query += id_device + ",";
3862
+ query += dev_status;
3863
+ query += ")";
3864
+ return query;
3865
+ }
3866
+ function insertDeviceStatusMySQL(id_device, dev_status, start_date) {
3867
+ var query = "insert into device_usage (date_start, date_end, id_device, status) ";
3868
+ query += "values (";
3869
+ if ((!start_date || start_date == '') || start_date == "TODAY") {
3870
+ query += "CURDATE(), ";
3871
+ }
3872
+ else {
3873
+ query += ":start_date, ";
3874
+ }
3875
+ query += "'2999-12-31', ";
3876
+ query += ":id_device,";
3877
+ query += ":dev_status";
3878
+ query += ")";
3879
+ return query;
3880
+ }
3881
+ function insertDeviceStatusMySQL2(id_device, dev_status, start_date) {
3882
+ var query = "insert into device_usage (date_start, date_end, id_device, status) ";
3883
+ query += "values (";
3884
+ if ((!start_date || start_date == '') || start_date == "TODAY") {
3885
+ query += "CURDATE(),";
3886
+ }
3887
+ else {
3888
+ query += "'" + start_date + "',";
3889
+ }
3890
+ query += "'2999-12-31', ";
3891
+ query += id_device + ",";
3892
+ query += dev_status;
3893
+ query += ")";
3894
+ return query;
3895
+ }
3896
+ function insertDeviceStatus(db_used, id_device, dev_status, start_date) {
3897
+ var query = "";
3898
+ if (db_used) {
3899
+ switch (db_used) {
3900
+ case 'SQLITE':
3901
+ query = insertDeviceStatusSQLite(id_device, dev_status, start_date);
3902
+ break;
3903
+ case 'MYSQL':
3904
+ query = insertDeviceStatusMySQL(id_device, dev_status, start_date);
3905
+ break;
3906
+ case 'MYSQL2':
3907
+ query = insertDeviceStatusMySQL2(id_device, dev_status, start_date);
3908
+ break;
3909
+ }
3910
+ }
3911
+ return query;
3912
+ }
3913
+ //end update device status
3914
+ // Remove device status - DA RIVEDERE -
3848
3915
  function removeDeviceStatusSQLite(id_device, dev_status) {
3849
3916
  var query = "delete from device_usage ";
3850
3917
  query += "where id_device = " + id_device + " and date_status = ";
@@ -3915,7 +3982,7 @@ function insertDeviceSQLite(dev) {
3915
3982
  if (dev.peso_g)
3916
3983
  peso = dev.peso_g;
3917
3984
 
3918
- query = "insert into devices (inv_ict3_number, inv_tn_number, inv_pnrr_number, inv_tndigit_number, type, manifacturer, model, serial_no, note, num_objects, no_inventario, peso_g) ";
3985
+ query = "insert into devices (inv_ict3_number, inv_tn_number, inv_pnrr_number, inv_tndigit_number, type, manifacturer, model, serial_no, note, num_objects, no_inventario, peso_g, part_of, is_unused) ";
3919
3986
  query += "values (";
3920
3987
  query += "'" + String(inventario).trim() + "',";
3921
3988
  query += "'" + String(inv_comune).trim() + "',";
@@ -3928,13 +3995,15 @@ function insertDeviceSQLite(dev) {
3928
3995
  query += "'" + String(note).trim() + "',";
3929
3996
  query += dev.num_objects + ", ";
3930
3997
  query += dev.no_inv + ", ";
3931
- query += peso;
3998
+ query += peso + ", ";
3999
+ query += "'" + dev.part_of + "', ";
4000
+ query += dev.is_unused;
3932
4001
  query += ")";
3933
4002
  }
3934
4003
  return query;
3935
4004
  }
3936
4005
  function insertDeviceMySQL() {
3937
- var query = "insert into devices (inv_ict3_number, inv_tn_number, inv_pnrr_number, inv_tndigit_number, type, manifacturer, model, serial_no, note, num_objects, no_inventario) ";
4006
+ var query = "insert into devices (inv_ict3_number, inv_tn_number, inv_pnrr_number, inv_tndigit_number, type, manifacturer, model, serial_no, note, num_objects, no_inventario, peso_g, part_of, is_unused) ";
3938
4007
  query += "values (";
3939
4008
  query += ":inventario, ";
3940
4009
  query += ":inv_comune, ";
@@ -3947,7 +4016,9 @@ function insertDeviceMySQL() {
3947
4016
  query += ":note, ";
3948
4017
  query += ":num_objects, ";
3949
4018
  query += ":no_inv, ";
3950
- query += ":peso_g ";
4019
+ query += ":peso_g, ";
4020
+ query += ":part_of, ";
4021
+ query += ":is_unused, ";
3951
4022
  query += ")";
3952
4023
  return query;
3953
4024
  }
@@ -4019,7 +4090,9 @@ function updateDeviceSQLite(deviceObj) {
4019
4090
  query += "note = '" + note.trim() + "',";
4020
4091
  query += "num_objects = " + dev.num_objects + ", ";
4021
4092
  query += "no_inventario = " + dev.no_inv + ", ";
4022
- query += "peso_g = " + peso + " ";
4093
+ query += "peso_g = " + peso + ", ";
4094
+ query += "part_of = '" + part_of + "', ";
4095
+ query += "is_unused = " + is_unused + " ";
4023
4096
  query += " where id = " + dev.id;
4024
4097
  }
4025
4098
  return query;
@@ -4038,7 +4111,9 @@ function updateDeviceMySQL() {
4038
4111
  query += "note = :note, ";
4039
4112
  query += "num_objects = :num_objects, ";
4040
4113
  query += "no_inventario = :no_inv, ";
4041
- query += "peso_g = :peso_g ";
4114
+ query += "peso_g = :peso_g, ";
4115
+ query += "part_of = :part_of, ";
4116
+ query += "is_unused = :is_unused ";
4042
4117
  query += " where id = :id_device";
4043
4118
  return query;
4044
4119
  }
@@ -4115,6 +4190,8 @@ function getDeviceMySQLPayload(dev) {
4115
4190
  "num_objects": retValue.num_objects,
4116
4191
  "no_inv": retValue.no_inv,
4117
4192
  "peso_g": retValue.peso_g,
4193
+ "part_of": retValue.part_of,
4194
+ "is_unused": retValue.is_unused,
4118
4195
  "id_device": dev.id
4119
4196
  };
4120
4197
  }
@@ -4152,7 +4229,38 @@ function removeDevice(db_used, id_device) {
4152
4229
  return query;
4153
4230
  }
4154
4231
 
4155
- //End remove device
4232
+ //End set unused device
4233
+ // Remove Device
4234
+ function updateUnusedDeviceSQLite(id_device, unused_switch) {
4235
+ var query = "update devices set is_unused = " + unused_switch + " ";
4236
+ query += "where id = " + id_device;
4237
+ return query;
4238
+ }
4239
+
4240
+ function updateUnusedDeviceMySQL() {
4241
+ var query = "update devices set is_unused = :unused_switch ";
4242
+ query += "where id = :id_device";
4243
+ return query;
4244
+ }
4245
+ function updateUnusedDevice(db_used, id_device, unused_switch) {
4246
+ var query = "";
4247
+ if (db_used) {
4248
+ switch (db_used) {
4249
+ case 'SQLITE':
4250
+ query = updateUnusedDeviceSQLite(id_device, unused_switch);
4251
+ break;
4252
+ case 'MYSQL':
4253
+ query = updateUnusedDeviceMySQL();
4254
+ break;
4255
+ case 'MYSQL2':
4256
+ query = updateUnusedDeviceSQLite(id_device, unused_switch);
4257
+ break;
4258
+ }
4259
+ }
4260
+ return query;
4261
+ }
4262
+
4263
+ //End set unused device
4156
4264
  //Get Last Id
4157
4265
  function queryLastDeviceIdSQLite() {
4158
4266
  return "select seq as id from sqlite_sequence where name = 'devices'";
@@ -12568,7 +12676,7 @@ function getLastSiteForDevice(db_used,id_device) {
12568
12676
 
12569
12677
 
12570
12678
  // end of source//Get Devices for Statistics
12571
- function queryStatisticSQLite(list_types) {
12679
+ function queryStatisticSQLite(list_types, exclude_unused) {
12572
12680
  var query = "select type as Tipo, count(*) as Numero from devices ";
12573
12681
  query += "where type in (";
12574
12682
  for (let i = 0; i < list_types.length; i++) {
@@ -12578,10 +12686,13 @@ function queryStatisticSQLite(list_types) {
12578
12686
  }
12579
12687
  }
12580
12688
  query += ") and (is_removed is null or is_removed = 0) ";
12689
+ if (exclude_unused && exclude_unused == 1) {
12690
+ query += "and (is_unused is null or is_unused = 0) ";
12691
+ }
12581
12692
  query += "group by Tipo";
12582
12693
  return query;
12583
12694
  }
12584
- function queryStatisticMySQL(list_types) {
12695
+ function queryStatisticMySQL(list_types, exclude_unused) {
12585
12696
  var query = "select type as Tipo, count(*) as Numero from devices ";
12586
12697
  query += "where type in (";
12587
12698
  for (let i = 0; i < list_types.length; i++) {
@@ -12591,21 +12702,24 @@ function queryStatisticMySQL(list_types) {
12591
12702
  }
12592
12703
  }
12593
12704
  query += ") and (is_removed is null or is_removed = 0) ";
12705
+ if (exclude_unused && exclude_unused == 1) {
12706
+ query += "and (is_unused is null or is_unused = 0) ";
12707
+ }
12594
12708
  query += "group by Tipo";
12595
12709
  return query;
12596
12710
  }
12597
- function queryStatistic(db_used,list_types) {
12711
+ function queryStatistic(db_used,list_types, exclude_unused) {
12598
12712
  var query = "";
12599
12713
  if (db_used) {
12600
12714
  switch (db_used) {
12601
12715
  case 'SQLITE':
12602
- query = queryStatisticSQLite(list_types);
12716
+ query = queryStatisticSQLite(list_types, exclude_unused);
12603
12717
  break;
12604
12718
  case 'MYSQL':
12605
- query = queryStatisticMySQL(list_types);
12719
+ query = queryStatisticMySQL(list_types, exclude_unused);
12606
12720
  break;
12607
12721
  case 'MYSQL2':
12608
- query = queryStatisticSQLite(list_types);
12722
+ query = queryStatisticSQLite(list_types, exclude_unused);
12609
12723
  break;
12610
12724
  }
12611
12725
  }
@@ -12837,7 +12951,7 @@ function queryStatisticsDeviceStatusSQLite() {
12837
12951
  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 ";
12838
12952
  query += "left join device_usage ds on d.id = ds.id_device ";
12839
12953
  query += "join status_description sd on sd.id = Stato "
12840
- query += "where date('now') >= ds.date_status or Stato = 0 ";
12954
+ query += "where (date('now') >= ds.date_start and date('now') <= ds.date_end) or ds.status = 0 ";
12841
12955
  query += "and (is_removed is null or is_removed = 0) ";
12842
12956
  query += "group by Stato";
12843
12957
  return query;
@@ -12846,7 +12960,7 @@ function queryStatisticsDeviceStatusMySQL() {
12846
12960
  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 ";
12847
12961
  query += "left join device_usage ds on d.id = ds.id_device ";
12848
12962
  query += "join status_description sd on sd.id = Stato "
12849
- query += "where CURDATE() >= ds.date_status or Stato = 0 ";
12963
+ query += "where (CURDATE() >= ds.date_start and CURDATE() <= ds.date_end) or ds.status = 0 ";
12850
12964
  query += "and (is_removed is null or is_removed = 0) ";
12851
12965
  query += "group by Stato";
12852
12966
  return query;
@@ -12855,7 +12969,7 @@ function queryStatisticsDeviceStatusMySQL2() {
12855
12969
  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 ";
12856
12970
  query += "left join device_usage ds on d.id = ds.id_device ";
12857
12971
  query += "join status_description sd on sd.id = Stato "
12858
- query += "where CURDATE() >= ds.date_status or Stato = 0 ";
12972
+ query += "where (CURDATE() >= ds.date_start and CURDATE() <= ds.date_end) or ds.status = 0 ";
12859
12973
  query += "and (is_removed is null or is_removed = 0) ";
12860
12974
  query += "group by Stato";
12861
12975
  return query;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  ".": "./lib/modules.js",
5
5
  "./dbconn": "./lib/dbconn.js"
6
6
  },
7
- "version": "3.0.139",
7
+ "version": "3.0.140",
8
8
  "description": "Funzioni per ALSManager",
9
9
  "license": "ISC",
10
10
  "author": "Luca Cattani",