alsmanager_lib 3.0.223 → 3.0.225

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 +275 -0
  2. package/package.json +1 -1
package/lib/modules.js CHANGED
@@ -4413,7 +4413,50 @@ function queryDeviceByIdentificativo(db_used, identificativo) {
4413
4413
  return query;
4414
4414
  }
4415
4415
  //End Get Device by Identificativo
4416
+ // Manage Devices annotations
4417
+ function getDeviceAnnotationsByIdDevice(id_device) {
4418
+ var query = "select da.id, da.date_annotation, da.annotation, a.name from device_annotations da ";
4419
+ query += "join annotation_types a on a.id = da.annotation_type ";
4420
+ query += "where id_device = " + id_device + " ";
4421
+ query += "order by date_annotation";
4422
+ return query;
4423
+ }
4424
+ function insertDeviceAnnotation(id_device, date_annot, annot, annot_type) {
4425
+ var query = "insert into device_annotations (id_device, date_annotation, annotation, annotation_type) values (";
4426
+ var dt_str = convertDateToStringDB(date_annot);
4427
+ query += id_device + ", ";
4428
+ query += "'" + dt_str + "', ";
4429
+ query += "'" + annot + "', ";
4430
+ query += annot_type;
4431
+ query += ")";
4432
+ return query;
4433
+ }
4434
+ function updateDeviceAnnotation(id_annot, date_annot, annot, annot_type) {
4435
+ var query = "update device_annotations set ";
4436
+ var dt_str = convertDateToStringDB(date_annot);
4437
+ query += "date_annotation = '" + dt_str + "', ";
4438
+ query += "annotation = '" + annot + "', ";
4439
+ query += "annotation_type = " + annotation_type + " ";
4440
+ query += "where id = " + id_annot;
4441
+ return query;
4442
+ }
4443
+ function removeDeviceAnnotation(id_annot) {
4444
+ var query = "delete from device_annotations ";
4445
+ query += "where id = " + id_annot;
4446
+ return query;
4447
+ }
4416
4448
 
4449
+ function selectAnnotationTypes() {
4450
+ var query = "select id, name, description from annotation_types ";
4451
+ return query;
4452
+ }
4453
+
4454
+ function selectAnnotationTypesInfos(id_annot_type) {
4455
+ var query = "select id, name, description from annotation_types ";
4456
+ query += "where id = " + id_annot_type;
4457
+ return query;
4458
+ }
4459
+ //End Manage Devices annotations
4417
4460
 
4418
4461
 
4419
4462
  //Get Device Status
@@ -12649,7 +12692,224 @@ function existBeneAbbinato(db_used, id_device, id_bene) {
12649
12692
  return query;
12650
12693
  }
12651
12694
  // end of source
12695
+ // Manage updateBeneconsumoSite
12696
+ function verifyPrevBeneconsumoSiteSQLite(id_benecons) {
12697
+ var query = "select count(id_site) as numero from beniconsumo_site ";
12698
+ query += "where id_beneconsumo = " + id_benecons;
12699
+ return query;
12700
+ }
12701
+ function verifyPrevBeneconsumoSiteMySQL(id_benecons) {
12702
+ var query = "select count(id_site) as numero from beniconsumo_site ";
12703
+ query += "where id_beneconsumo = :id_benecons";
12704
+ return query;
12705
+ }
12652
12706
 
12707
+ function verifyPrevBeneconsumoSite(db_used, id_benecons) {
12708
+ var query = "";
12709
+ if (db_used) {
12710
+ switch (db_used) {
12711
+ case 'SQLITE':
12712
+ query = verifyPrevBeneconsumoSiteSQLite(id_benecons);
12713
+ break;
12714
+ case 'MYSQL':
12715
+ query = verifyPrevBeneconsumoSiteMySQL(id_benecons);
12716
+ break;
12717
+ case 'MYSQL2':
12718
+ query = verifyPrevBeneconsumoSiteSQLite(id_benecons);
12719
+ break;
12720
+ }
12721
+ }
12722
+ return query;
12723
+ }
12724
+
12725
+ function removeBeneconsumoSiteSQLite(id_site, id_place, id_benecons) {
12726
+ var query = "delete from beniconsumo_site ";
12727
+ query += "where id_beneconsumo = " + id_benecons + " and date_in = (select max(date_in) from beniconsumo_site where id_beneconsumo = " + id_benecons + ")";
12728
+ return query;
12729
+ }
12730
+ function removeBeneconsumoSiteMySQL(id_site, id_place, id_benecons) {
12731
+ var query = "delete from beniconsumo_site ";
12732
+ query += "where id_beneconsumo = :id_benecons and date_in = (select max(date_in) from beniconsumo_site where id_beneconsumo = :id_benecons)";
12733
+ return query;
12734
+ }
12735
+ function removeBeneconsumoSite(db_used, id_site, id_place, id_benecons) {
12736
+ var query = "";
12737
+ if (db_used) {
12738
+ switch (db_used) {
12739
+ case 'SQLITE':
12740
+ query = removeBeneconsumoSiteSQLite(id_site, id_place, id_benecons);
12741
+ break;
12742
+ case 'MYSQL':
12743
+ query = removeBeneconsumoSiteMySQL(id_site, id_place, id_benecons);
12744
+ break;
12745
+ case 'MYSQL2':
12746
+ query = removeBeneconsumoSiteSQLite(id_site, id_place, id_benecons);
12747
+ break;
12748
+ }
12749
+ }
12750
+ return query;
12751
+ }
12752
+
12753
+
12754
+ function updateBeneconsumoSiteAfterRemoveSQLite(id_benecons) {
12755
+ var query = "update beniconsumo_site set date_out = '2999-12-31' ";
12756
+ query += "where id_beneconsumo = " + id_benecons + " and date_in = (select max(date_in) from beniconsumo_site where id_beneconsumo = " + id_benecons + ")";
12757
+ return query;
12758
+ }
12759
+ function updateBeneconsumoSiteAfterRemoveMySQL(id_benecons) {
12760
+ var query = "update beniconsumo_site set date_out = '2999-12-31' ";
12761
+ query += "where id_beneconsumo = :id_benecons and date_in = (select max(date_in) from beniconsumo_site where id_beneconsumo = :id_benecons)";
12762
+ return query;
12763
+ }
12764
+ function updateBeneconsumoSiteAfterRemove(db_used, id_benecons) {
12765
+ var query = "";
12766
+ if (db_used) {
12767
+ switch (db_used) {
12768
+ case 'SQLITE':
12769
+ query = updateBeneconsumoSiteAfterRemoveSQLite(id_benecons);
12770
+ break;
12771
+ case 'MYSQL':
12772
+ query = updateBeneconsumoSiteAfterRemoveMySQL(id_benecons);
12773
+ break;
12774
+ case 'MYSQL2':
12775
+ query = updateBeneconsumoSiteAfterRemoveSQLite(id_benecons);
12776
+ break;
12777
+ }
12778
+ }
12779
+ return query;
12780
+ }
12781
+
12782
+
12783
+ function updateBeneconsumoSiteSQLite(id_benecons) {
12784
+ var query = "update beniconsumo_site set date_out = date('now','-1 day') ";
12785
+ query += "where id_beneconsumo = " + id_benecons + " and date_in = (select max(date_in) from beniconsumo_site where id_beneconsumo = " + id_benecons + ")";
12786
+ return query;
12787
+ }
12788
+ function updateBeneconsumoSiteMySQL(id_benecons) {
12789
+ var query = "update beniconsumo_site set date_out = DATE_SUB(CURDATE(), INTERVAL 1 DAY) ";
12790
+ query += "where id_beneconsumo = :id_benecons and date_in = (select max(date_in) from beniconsumo_site where id_beneconsumo = :id_benecons)";
12791
+ return query;
12792
+ }
12793
+ function updateBeneconsumoSiteMySQL2(id_benecons) {
12794
+ var query = "update beniconsumo_site set date_out = DATE_SUB(CURDATE(), INTERVAL 1 DAY) ";
12795
+ query += "where id_beneconsumo = " + id_benecons + " and date_in = (select max(date_in) from beniconsumo_site where id_beneconsumo = " + id_benecons + ")";
12796
+ return query;
12797
+ }
12798
+ function updateBeneconsumoSite(db_used, id_benecons) {
12799
+ var query = "";
12800
+ if (db_used) {
12801
+ switch (db_used) {
12802
+ case 'SQLITE':
12803
+ query = updateBeneconsumoSiteSQLite(id_benecons);
12804
+ break;
12805
+ case 'MYSQL':
12806
+ query = updateBeneconsumoSiteMySQL(id_benecons);
12807
+ break;
12808
+ case 'MYSQL2':
12809
+ query = updateBeneconsumoSiteMySQL2(id_benecons);
12810
+ break;
12811
+ }
12812
+ }
12813
+ return query;
12814
+ }
12815
+ // end manage updateBeneconsumoSite
12816
+
12817
+ // Manage insertBeneconsumoSite
12818
+ function insertBeneconsumoSiteSQLite(id_benecons, id_place, id_site, start_date) {
12819
+ var query = "insert into beniconsumo_site (date_in, date_out, id_beneconsumo, id_site, id_place) ";
12820
+ query += "values (";
12821
+ if ((!start_date || start_date == '') || start_date == "TODAY") {
12822
+ query += "date('now'),";
12823
+ }
12824
+ else {
12825
+ query += "'" + start_date + "',";
12826
+ }
12827
+ query += "'2999-12-31',";
12828
+ query += id_benecons + ",";
12829
+ query += id_site + ",";
12830
+ query += "'" + id_place + "'";
12831
+ query += ")";
12832
+ return query;
12833
+ }
12834
+ function insertBeneconsumoSiteMySQL(id_benecons, id_place, id_site, start_date) {
12835
+ var query = "insert into beniconsumo_site (date_in, date_out, id_beneconsumo, id_site, id_place) ";
12836
+ query += "values (";
12837
+ if ((!start_date || start_date == '') || start_date == "TODAY") {
12838
+ query += "CURDATE(),";
12839
+ }
12840
+ else {
12841
+ query += ":start_date,";
12842
+ }
12843
+ query += "'2999-12-31',";
12844
+ query += ":id_benecons,";
12845
+ query += ":id_site,";
12846
+ query += ":id_place";
12847
+ query += ")";
12848
+ return query;
12849
+ }
12850
+ function insertBeneconsumoSiteMySQL2(id_benecons, id_place, id_site, start_date) {
12851
+ var query = "insert into beniconsumo_site (date_in, date_out, id_beneconsumo, id_site, id_place) ";
12852
+ query += "values (";
12853
+ if ((!start_date || start_date == '') || start_date == "TODAY") {
12854
+ query += "CURDATE(),";
12855
+ }
12856
+ else {
12857
+ query += "'" + start_date + "',";
12858
+ }
12859
+ query += "'2999-12-31',";
12860
+ query += id_benecons + ",";
12861
+ query += id_site + ",";
12862
+ query += "'" + id_place + "'";
12863
+ query += ")";
12864
+ return query;
12865
+ }
12866
+ function insertBeneconsumoSite(db_used, id_benecons, id_place, id_site, start_date) {
12867
+ var query = "";
12868
+ if (db_used) {
12869
+ switch (db_used) {
12870
+ case 'SQLITE':
12871
+ query = insertBeneconsumoSiteSQLite(id_benecons, id_place, id_site, start_date);
12872
+ break;
12873
+ case 'MYSQL':
12874
+ query = insertBeneconsumoSiteMySQL(id_benecons, id_place, id_site, start_date);
12875
+ break;
12876
+ case 'MYSQL2':
12877
+ query = insertBeneconsumoSiteMySQL2(id_benecons, id_place, id_site, start_date);
12878
+ break;
12879
+ }
12880
+ }
12881
+ return query;
12882
+ }
12883
+ // end manage updateDevicesSite
12884
+ //
12885
+ function removeBeniconsumoFromAllSitesSQLite(id_benecons) {
12886
+ var query = "delete from beniconsumo_site ";
12887
+ query += "where id_beneconsumo = " + id_benecons;
12888
+ return query;
12889
+ }
12890
+ function removeBeniconsumoFromAllSitesMySQL(id_benecons) {
12891
+ var query = "delete from beniconsumo_site ";
12892
+ query += "where id_beneconsumo = :id_benecons";
12893
+ return query;
12894
+ }
12895
+ function removeBeniconsumoFromAllSites(db_used, id_benecons) {
12896
+ var query = "";
12897
+ if (db_used) {
12898
+ switch (db_used) {
12899
+ case 'SQLITE':
12900
+ query = removeBeniconsumoFromAllSitesSQLite(id_benecons);
12901
+ break;
12902
+ case 'MYSQL':
12903
+ query = removeBeniconsumoFromAllSitesMySQL(id_benecons);
12904
+ break;
12905
+ case 'MYSQL2':
12906
+ query = removeBeniconsumoFromAllSitesSQLite(id_benecons);
12907
+ break;
12908
+ }
12909
+ }
12910
+ return query;
12911
+ }
12912
+ //
12653
12913
 
12654
12914
 
12655
12915
  // Code added here will be run once
@@ -17084,6 +17344,9 @@ function getNotesByIdDevice(id_device) {
17084
17344
  query += "UNION ";
17085
17345
  query += "select CONCAT('INTERVENTO n. ', di.id) as Tipo, di.date_start as Data, di.note_intervento as note from device_interventi di ";
17086
17346
  query += "where di.id_device = " + id_device + " and di.note_intervento is not null ";
17347
+ query += "UNION ";
17348
+ query += "select 'ANNOTAZIONI' as Tipo, da.date_annotation as Data, da.annotation as note from device_annotation da ";
17349
+ query += "where da.id_device = " + id_device + " and da.annotation is not null ";
17087
17350
  return query;
17088
17351
  }
17089
17352
 
@@ -17114,6 +17377,12 @@ module.exports = {
17114
17377
  getDevicesSelectBySite,
17115
17378
  queryDeviceById,
17116
17379
  queryDeviceByIdentificativo,
17380
+ getDeviceAnnotationsByIdDevice,
17381
+ insertDeviceAnnotation,
17382
+ updateDeviceAnnotation,
17383
+ removeDeviceAnnotation,
17384
+ selectAnnotationTypes,
17385
+ selectAnnotationTypesInfos,
17117
17386
  queryDeviceForConsegneById,
17118
17387
  getDevicesCounterBySite,
17119
17388
  getDevicesCounterByPlace,
@@ -17273,8 +17542,14 @@ module.exports = {
17273
17542
  updateBeneConsumo,
17274
17543
  removeBeneConsumo,
17275
17544
  existBeneAbbinato,
17545
+ verifyPrevBeneconsumoSite,
17546
+ removeBeneconsumoSite,
17547
+ updateBeneconsumoSiteAfterRemove,
17548
+ updateBeneconsumoSite,
17276
17549
  insertBeneConsumoAbbinato,
17277
17550
  updateBeneConsumoAbbinato,
17551
+ insertBeneconsumoSite,
17552
+ removeBeniconsumoFromAllSites,
17278
17553
  insertConnectionSet,
17279
17554
  updateConnectionSet,
17280
17555
  removeConnectionSet,
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.223",
7
+ "version": "3.0.225",
8
8
  "description": "Funzioni per ALSManager",
9
9
  "license": "ISC",
10
10
  "author": "Luca Cattani",