. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
| Server IP : 52.223.31.75 / Your IP : 172.31.32.98 [ Web Server : Apache/2.4.66 () OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux ip-172-31-14-81.eu-central-1.compute.internal 4.14.281-212.502.amzn2.x86_64 #1 SMP Thu May 26 09:52:17 UTC 2022 x86_64 User : apache ( 48) PHP Version : 7.4.33 Disable Function : NONE Domains : 4 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /var/www/ripara.co/admin/js/controllers/ |
Upload File : |
materialAdmin
//=================================================
// Controller Lista Utenti e Inserimento Utente
//=================================================
.controller('clienteCtrl', function($filter, $sce, $scope, ngTableParams, tableService, APIService, animationService) {
this.animationService = animationService;
$scope.elencoCampiP=['Ragione Sociale','Indirizzo', 'Citta', 'Cellulare','Email' ];
$scope.elencoChiaviP = ['ragionesociale','indirizzo','citta','cellulare', 'email'];
$scope.elencoCampiS=['Telefono','Partita Iva' , 'Codice Fiscale', 'Note', 'Sede'];
$scope.elencoChiaviS = ['telefono','piva','codicefiscale','note','sede'];
//questa funzione fixa il problema delle chiavi con spazi o caratteri speciali nell'ordinamento delle tabelle
//utile per le alias colonne es. Numero Chiamante
this.clienteInsert={'idcliente':'', 'ragionesociale':'', 'indirizzo':'', 'citta':'', 'piva':'', 'codicefiscale':'', 'telefono':'', 'cellulare':'', 'email':'', 'note':'', 'sede':'' };
$scope.rawProperty = function(key) {
return function(item) {
if ((key == "EndTime" || key == "StartTime" || key == "AnswerTime" || key == "AlertingTime")) {
return item[key]['sec'];
}
return item[key];
};
};
this.getSedeUtente = function(idsede) {
debugger;
for(var tmp in $scope.clientectrl.sedi){
if($scope.clientectrl.sedi[tmp]['idsede'] == idsede){
return $scope.clientectrl.sedi[tmp];
}
}
return $scope.clientectrl.sedi[0];
}
this.getCitta = function() {
APIService.async({
"method": "getcitta"
}).then(
function(adata) {
if (adata.status) {
$scope.clientectrl.comuni = adata.message;
} else {
$scope.clientectrl.comuni = [];
}
}
);
}
this.submitCliente = function() {
this.clienteInsert.method = "insertcliente";
this.clienteInsert.citta=this.selezione.title;
this.clienteInsert.sede = this.clienteInsert.sede.idsede;
APIService.async(this.clienteInsert).then(function(adata) {
if (adata.status) {
swal(adata.message, "L'utente protrà effettuare l'accesso senza verificare l'account in quanto creato da un'amministratore!", "success")
//aggiorno la lista degli utenti
$scope.clientectrl.getData();
//svuoto i valori precedenti
for (x in $scope.clientectrl.clienteInsert) {
$scope.clientectrl.clienteInsert[x] = "";
}
//nascondo il menu inserimento
$scope.clientectrl.newCliente = 0;
} else {
$scope.clientectrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di aggiornamento dei dati, si prega di aggiornare la pagina!");
}
});
}
//Caricament dati da API REST
this.getData = function (){
APIService.async({method: "getclienti"}).then(function(adata) {
if(adata.status && adata.message.length){
//assegno i dati ricevuti a data
var data = adata.message;
for (var i = data.length - 1; i >= 0; i--) {
for (var k = $scope.clientectrl.sedi.length - 1; k >= 0; k--) {
if(data[i].sede== $scope.clientectrl.sedi[k]['idsede']){
data[i].sede = $scope.clientectrl.sedi[k];
break;
}
}
}
//aggiorno la variabile per ng-repeat della tabella
$scope.clientectrl.data = data;
//instanzio la ng-table
$scope.clientectrl.tableCliente = new ngTableParams({
page: 1, // show first page
count: 10
},
{
total: data.length,// $scope.data.length, // length of data
getData: function($defer, params) {
//controllo se esisteno paramentri che si chiamamo orderby, all'onclick ordino per quel campo
if (params.sorting()['orderBy'] != undefined) {
//aggiungo la substr perchè il primo carattere viene messo random, altrimenti ordinerebbe sempre DESC visto che se è ordinata per una qualsiasi colonna non fa più ordinare per la stessa
var orderedData = $filter('orderBy')(data, $scope.rawProperty(params.sorting()['orderBy'].substr(1)),
$scope.clientectrl.isSortBy);
$scope.clientectrl.isSortBy = !$scope.clientectrl.isSortBy;
//ok ma non funziona con le key con spazi o punti
//var orderedData = $filter('orderBy')(data, params.sorting()['orderBy']);
} else {
var orderedData = data;
}
//verifico se sono definiti filtri
//orderedData = $filter('filterFailed')(orderedData, $scope.showOnlyFailed);
if (params.sorting()['filter'] != undefined) {
var chiave = params.sorting()['filter'].key;
var value = params.sorting()['filter'].value;
var tmpSrc = {};
tmpSrc[chiave] = value;
console.log(chiave + "|||||" +value);
orderedData = $filter('filter')(orderedData, tmpSrc);
}
params.total(orderedData.length); // set total for recalc pagination
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
}else{
if(adata.message.length>1){
animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di carimento dei dati, si prega di aggiornare la pagina!");
}
}
});
};
APIService.async({
"method": "getsedi"
}).then(
function(adata) {
if (adata.status) {
$scope.clientectrl.sedi = adata.message;
} else {
$scope.clientectrl.sedi = [];
}
$scope.clientectrl.getData();
}
);
$scope.comuni=this.getCitta();
//Insert , @Peodacontrollare
this.newCliente = 0;
this.submit = function() {
this.clienteInsert.sede = this.clienteInsert.sede.idsede;
this.clienteInsert.method = "insertcliente";
APIService.async(this.clienteInsert).then(function(adata) {
if(adata.status){
swal(adata.message, "Cliente inserito con successo!", "success")
//aggiorno la lista degli utenti
$scope.clientectrl.getData();
//svuoto i valori precedenti
for(x in $scope.clientectrl.clienteInsert){
$scope.clientectrl.clienteInsert[x] = "";
}
//nascondo il menu inserimento
$scope.clientectrl.newcliente = 0;
}else{
$scope.clientectrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di aggiornamento dei dati, si prega di aggiornare la pagina!");
}
});
}
this.modificaCliente = function (dati) {
dati.$edit = false;
dati.method = "editcliente";
dati.sede = dati.sede.idsede;
debugger;
APIService.async(dati).then(function(adati) {
if(adati.status){
swal(adati.message, "Cliente modificato con successo!", "success");
$scope.clientectrl.getData();
}else{
$scope.clientectrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di aggiornamento dei dati, si prega di aggiornare la pagina!");
}
});
}
$scope.cancellaCliente = function (dati) {
swal({
title: "Sei sicuro di voler cancellare il cliente '"+dati.ragioneSociale+"' ?",
text: "L'azione eseguita sarà irreversibile!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Si, cancellala!",
closeOnConfirm: false
}, function(){
dati.$edit = false;
dati.method = "deletecliente";
APIService.async(dati).then(function(adati) {
if(adati.status){
swal(adati.message, "Cliente eliminato con successo!", "success");
$scope.clientectrl.getData();
}else{
$scope.clientectrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "L'utente ha delle riparazioni assegnate, per tanto non può essere eliminato!");
}
});
});
}
})