. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
| Server IP : 52.223.31.75 / Your IP : 172.31.6.220 [ 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 Riparazioni
//=================================================
.controller('riparazioneCtrl', function($filter,$log, $sce, $state, $scope, ngTableParams, tableService, APIService, animationService, growlService) {
// ACL
if($scope.thisPagesNames.indexOf($state.current.nomePagina) < 0){
// OuttaHere!
$state.go("home");
growlService.growl($scope.outtaHere, 'danger');
}
self = this;
$scope.anni = [];
$scope.annoCorrente = new Date().getFullYear();
for (var i = 2016; i <= $scope.annoCorrente; i++) {
$scope.anni.push(i);
}
this.caricaAnno = function(anno){
self.getData(anno);
$('#'+anno).attr('disabled', 'disabled');
$('#'+anno).attr('class', 'btn btn-warning');
}
$scope.convertiData = function(dateRicevuta, si){
if(dateRicevuta){
if(si){
var d = new Date(dateRicevuta.replace("-","/").replace("-","/"));
var n = -d.getTimezoneOffset();
}else{
var n =0;
}
var tmp = new Date((dateRicevuta.replace("-","/").replace("-","/")));
tmp.setTime(tmp.getTime()+ (n*60*1000));
return (tmp.getDate()<10?'0':'') + tmp.getDate() + "/" + (tmp.getMonth()<9?'0':'') + (tmp.getMonth()+1) + "/" + tmp.getFullYear() + " - " + (tmp.getHours()<10?'0':'') + tmp.getHours() + ":" + (tmp.getMinutes()<10?'0':'') + tmp.getMinutes() + ":" + (tmp.getSeconds()<10?'0':'') + tmp.getSeconds();
}
return "";
}
this.animationService = animationService;
this.growlService = growlService;
//@Peo elenco campi principali
$scope.elencoCampiP = ['Cliente', 'Device', 'Data Ingresso', 'Ultimo Aggiornamento', 'Stato', 'Codice Tracking - Imei', 'Loggato come'];
$scope.elencoChiaviP = ['ragionesociale', 'modello', 'dataingresso', 'lastupdate', 'stato', 'tracking','name_user_insert'];
//@Peo elenco campi secondari
$scope.elencoCampiS = ['Accessori Consegnati', 'Descrizione Riparazione', 'Data Riconsegna', 'Seriale / Imei'];
$scope.elencoChiaviS = ['accessoriconsegnati', 'descrizioneriparazione', 'datariconsegna', 'serialeimei'];
$scope.elencoCampiT = ['Foto', 'Preventivo', 'Costo Riparazione', 'Note'];
$scope.elencoChiaviT = ['fotoriparazione', 'preventivoriparazione', 'totalecostoriparazione', 'note'];
//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.selezionecliente=null;
this.selezionemarca=null;
this.selezionedevice=null;
this.selezionecategoria=null;
this.selezionecomune=null;
this.selezionecategoriainsert=null;
this.selezioneclienteinsert=null;
this.aselezionedeviceinsert=null;
this.riparazioneInsert = {
'iddevice': '',
'dataingresso': '',
'descrizioneproblema': '',
'accessoriconsegnati': '',
'descrizioneriparazione': '',
'serialeimei': '',
'datariconsegna': '',
'fotoriparazione': '',
'preventivoriparazione': '',
'totalecostoriparazione': '',
'note': '',
'sede': '',
'prodotti':[]
};
this.selezionecategoriaupdate=null;
this.selezioneclienteupdate=null;
this.aselezionedeviceupdate=null;
this.riparazioneUpdate = {
'iddevice': '',
'dataingresso': '',
'descrizioneproblema': '',
'accessoriconsegnati': '',
'descrizioneriparazione': '',
'serialeimei': '',
'datariconsegna': '',
'fotoriparazione': '',
'preventivoriparazione': '',
'totalecostoriparazione': '',
'note': '',
'sede': '',
'id_user':'',
'prodotti':[]
};
this.clienteInsert = {
'idcliente': '',
'ragionesociale': '',
'indirizzo': '',
'citta': '',
'piva': '',
'codicefiscale': '',
'telefono': '',
'cellulare': '',
'email': '',
'note': '',
'sede': ''
};
APIService.async({
"method": "getsedi"
}).then(
function(adata) {
if (adata.status) {
$scope.ripctrl.sedi = adata.message;
} else {
$scope.ripctrl.sedi = [];
}
}
);
$scope.getSedeIndirizzo = function (aidsede) {
var idsede = aidsede['idsede'];
for(var tmp in $scope.ripctrl.sedi){
if($scope.ripctrl.sedi[tmp]['idsede'] == idsede){
return $scope.ripctrl.sedi[tmp]['descrizione'].split("<br>");
}
}
return $scope.ripctrl.sedi[0]['descrizione'].split("<br>");
}
this.azzeradate = function() {
for (i in this.riparazioneInsert)
if (i=="dataingresso")
this.riparazioneInsert[i] = new Date();
else if(i=="datariconsegna")
this.riparazioneInsert[i] = new Date(0);
}
this.controllaconsegnato=function(data){
if (data=="")
return false;
else
return true;
}
this.azzeradate();
this.clearAggiungi = function() {
this.newRiparazione = 0;
this.newCliente = 0;
this.newDevice = 0;
this.newMarca = 0;
this.newCategoria = 0;
}
this.getMarche = function() {
APIService.async({
"method": "getmarche"
}).then(
function(adata) {
if (adata.status) {
$scope.ripctrl.marche = adata.message;
} else {
$scope.ripctrl.marche = [];
}
}
);
}
this.getCategor = function() {
APIService.async({
"method": "getcategor"
}).then(
function(adata) {
if (adata.status) {
$scope.ripctrl.categor = adata.message;
} else {
$scope.ripctrl.categor = [];
}
}
);
}
this.getUsers = function() {
APIService.async({
"method": "getdipendenti"
}).then(
function(adata) {
if (adata.status) {
for (var i = adata.message.length - 1; i >= 0; i--) {
adata.message[i]['completo'] = adata.message[i]['firstname'] +" "+adata.message[i]['lastname'] ;
}
$scope.ripctrl.users = adata.message;
} else {
$scope.ripctrl.users = [];
}
}
);
}
this.getDevices = function() {
APIService.async({
"method": "getdevices"
}).then(
function(adata) {
if (adata.status) {
$scope.ripctrl.devices = adata.message;
} else {
$scope.ripctrl.devices = [];
}
}
);
}
this.getProdotti = function(id) {
$scope.prodotti = [];
this.prodottiIds = [];
APIService.async({
"method": "getprodotto",
"deviceid": id
}).then(
function(adata) {
if (adata.status) {
$scope.ripctrl.prodotti = adata.message;
//carico gli id in un array per ottimizzare la ricerca
for(x in adata.message){
$scope.ripctrl.prodottiIds.push(adata.message[x]['idprodotto']);
}
} else {
$scope.ripctrl.prodotti = [];
}
}
);
}
this.getProdottiRiparazione = function(idriparazione) {
APIService.async({
"method": "getprodottiriparazione",
"idriparazione": idriparazione
}).then(
function(adata) {
if (adata.status) {
//prodotti
for(var rip in $scope.ripctrl.data){
if($scope.ripctrl.data[rip]['idriparazione'] == idriparazione){
$scope.ripctrl.data[rip]['prodotti'] = adata.message;
$scope.ripctrl.editRiparazioneProdottoAggiungi($scope.ripctrl.data[rip]);
}
}
}
}
);
}
this.getCronoRiparazione = function(idriparazione) {
APIService.async({
"method": "getstatiriparazione",
"idriparazione": idriparazione
}).then(
function(adata) {
if (adata.status) {
//prodotti
for(var rip in $scope.ripctrl.data){
if($scope.ripctrl.data[rip]['idriparazione'] == idriparazione){
$scope.ripctrl.data[rip]['crono'] = adata.message;
}
}
}
}
);
}
this.getStati = function() {
APIService.async({
"method": "getstati"
}).then(
function(adata) {
if (adata.status) {
$scope.ripctrl.stati = adata.message;
} else {
$scope.ripctrl.stati = [];
}
}
);
}
this.getCitta = function() {
APIService.async({
"method": "getcitta"
}).then(
function(adata) {
if (adata.status) {
$scope.ripctrl.comuni = adata.message;
} else {
$scope.ripctrl.comuni = [];
}
}
);
}
this.getCliente = function(idcliente) {
APIService.async({
"method": "getcliente"
}).then(
function(adata) {
debugger;
if (adata.status) {
$scope.ripctrl.cliente = adata.message;
return ripctrl.cliente;
} else {
$scope.ripctrl.cliente = [];
}
}
);
}
this.getClienti = function() {
if($scope.clienti.length == 0){
APIService.async({
"method": "getclienti"
}).then(
function(adata) {
if (adata.status) {
// for (var i = adata.message.length - 1; i >= 0; i--) {
// for (var k = $scope.ripctrl.sedi.length - 1; k >= 0; k--) {
// if(adata.message[i].sede== $scope.ripctrl.sedi[k]['idsede']){
// adata.message[i].sede = $scope.ripctrl.sedi[k];
// break;
// }
// }
// }
$scope.ripctrl.clienti = adata.message;
$scope.clienti = adata.message;
} else {
$scope.ripctrl.clienti = [];
}
}
);
}
}
$scope.rawProperty = function(key) {
return function(item) {
if ((key == "EndTime" || key == "StartTime" || key == "AnswerTime" || key == "AlertingTime")) {
return item[key]['sec'];
}
return item[key];
};
};
this.getStatoName = function(id){
for(x in this.stati){
if(this.stati[x].idstato == id){
return this.stati[x].nomestato;
}
}
}
this.checkData = function(datariconsegna) {
var x= new Date();
var y= new Date(0);
if (datariconsegna==x || datariconsegna=="0000-00-00 00:00:00" || datariconsegna=="1970-01-01 00:00:00")
{
return false
}
return true;
}
$scope.stampaOra = function(x){
var tmp = x.split(" ");
return tmp[1].substr(0,5);
}
$scope.tmpSrc = {};
//Caricament dati da API REST
this.getData = function(anno) {
APIService.async({
method: "getriparazioni",
anno: anno
}).then(function(adata) {
if (adata.status && adata.message.length) {
//cambio colore
$('#'+anno).attr('class', 'btn btn-success');
//assegno i dati ricevuti a data
var data = adata.message;
//aggiorno la variabile per ng-repeat della tabella
$scope.ripctrl.data = data;
//aggiungo tracking
for(dato in data){
data[dato]['tracking'] =data[dato]['idcliente']+"-"+$scope.ripctrl.getCodice(data[dato].dataingresso);
for(var sede in $scope.ripctrl.sedi){
if($scope.ripctrl.sedi[sede].idsede == data[dato]["sede"]){
data[dato]["sede"] = $scope.ripctrl.sedi[sede];
break;
}
}
}
//instanzio la ng-table
$scope.ripctrl.tableRiparazione = 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 && params.sorting()['orderBy']) {
//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.ripctrl.isSortBy);
$scope.ripctrl.isSortBy = !$scope.ripctrl.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;
//setto i valori per le date
if((chiave == "dataingresso" || chiave == "lastupdate")&& value){
var tmp = value;
value = tmp.getFullYear() + "-" + (tmp.getMonth()<9?'0':'') + (tmp.getMonth()+1) + "-" + (tmp.getDate()<10?'0':'') + tmp.getDate();// + " " + (tmp.getHours()<10?'0':'') + tmp.getHours() + ":" + (tmp.getMinutes()<10?'0':'') + tmp.getMinutes() + ":" + (tmp.getSeconds()<10?'0':'') + tmp.getSeconds();
}
//cerco tracking o imei/seriale
if(chiave == "tracking" && value){
if(value){
//cerca in tutte le field
$scope.tmpSrc["$"] = value;
}else{
delete $scope.tmpSrc[chiave];
}
}else{
if(value){
$scope.tmpSrc[chiave] = value;
}else{
delete $scope.tmpSrc[chiave];
}
}
console.log(chiave + "|||||" + value);
orderedData = $filter('filter')(orderedData, $scope.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.status && adata.message.length == 0 ){
growlService.growl('Non sono presenti riparazioni nell\'anno richiesto!', 'success')
}else{
animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di carimento dei dati, si prega di aggiornare la pagina!");
}
});
};
// search function to match full text
$scope.localSearch = function(str, people) {
var matches = [];
people.forEach(function(person) {
var fullName = person.nome_comune;
matches.push(fullName.originalObject.nome_comune);
});
return matches;
};
$scope.devices = this.getDevices();
$scope.clienti = [];
this.getClienti();
$scope.comuni = this.getCitta();
$scope.stati = this.getStati();
$scope.marche = this.getMarche();
$scope.categor = this.getCategor();
$scope.users = this.getUsers();
// $scope.prodotti = this.getProdotti();
this.clearAggiungi();
this.getData(new Date().getFullYear());
$scope.clientisearchinsert = [];
$scope.cambiaselectclientesearchinsert = function(x){
var first = true;
// $scope.clientisearchinsert = [];
$('#selezioneclienteinsert').empty(); //remove all child nodes
var val = x.nomeclientesearchinsert;
if(val.length > 2){
$scope.clienti.forEach(x => {
if(x.ragionesociale.toLowerCase().indexOf(val.toLowerCase()) > -1 || x.telefono.indexOf(val) > -1){
if(first){
$scope.ripctrl.riparazioneInsert.cliente=x.idcliente;
first = false;
}
var valore = (x.ragionesociale + (x.citta?' - '+x.citta:'') + (x.telefono?' - '+x.telefono:''))
var newOption = $('<option value="'+x.idcliente+'">'+valore+'</option>');
$('#selezioneclienteinsert').append(newOption);
$scope.clientisearchinsert.push(x);
}
})
}
$('#selezioneclienteinsert').prop('disabled', false);
$('#selezioneclienteinsert').trigger("chosen:updated");
}
this.getCodice = function(dat){
return new Date(dat.replace("-","/").replace("-","/")).getTime();
}
//per update
this.totalecostoriparazioneUpdate = "EURO 0,00";
this.aggiornaTotaleCostoUpdate = function(){
$scope.totalecostoriparazioneUpdate = "";
var tmp = 0;
for (var i = $scope.ripctrl.prodottiAggiuntiUpdate.length - 1; i >= 0; i--) {
tmp+=(parseInt($scope.ripctrl.riparazioneUpdate.prodotti[i].quantita)*parseFloat($scope.ripctrl.prodottiAggiuntiUpdate[i].costo));
}
$scope.ripctrl.riparazioneUpdate.totalecostoriparazione= tmp;
$scope.ripctrl.totalecostoriparazioneUpdate = "EURO " + tmp;//(tmp%1==0)?tmp+",00":(tmp.split(".").join(","));
}
this.prodottiAggiuntiUpdate = [];
this.prodottiAggiuntiInsert = [];
this.prodottiIds = [];
//funzione chiamata quando click sul pulsante edit riparazione nella riga della tabella
this.editRiparazioneProdottoAggiungi = function(item){
$scope.ripctrl.riparazioneUpdate = {};
for(ae in item){
$scope.ripctrl.riparazioneUpdate[ae] = item[ae];
}
$scope.ripctrl.riparazioneUpdate.sedes = this.getSedeUtente(item.sede);
//svuoto i prodotti aggiunti
$scope.ripctrl.prodottiAggiuntiUpdate = [];
var prodotti = $scope.ripctrl.riparazioneUpdate.prodotti;
$scope.ripctrl.riparazioneUpdate.prodotti = [];
//visualizzo il cliente nel box in fase di editaxzione
for(cli in $scope.ripctrl.clienti){
if($scope.ripctrl.clienti[cli]['idcliente'] == item.idcliente){
$scope.ripctrl.riparazioneUpdate.cliente = $scope.ripctrl.clienti[cli];
break;
}
}
//visualizzo il cliente nel box in fase di editaxzione
for(dev in $scope.ripctrl.devices){
if($scope.ripctrl.devices[dev]['iddevice'] == item.iddevice){
$scope.ripctrl.riparazioneUpdate.device=$scope.ripctrl.devices[dev];
$scope.ripctrl.getProdotti(item.iddevice);
break;
}
}
//per ogni prodotto presente nella riparazione in editazione
for(prod in prodotti){
$scope.ripctrl.riparazioneUpdate.prodotti.push({'id':prodotti[prod].idprodotto, 'quantita':prodotti[prod].quantita});
$scope.ripctrl.prodottiAggiuntiUpdate.push(prodotti[prod]);
}
//aggiorno il prezzo dell'update //aggiorno costo totale
$scope.ripctrl.aggiornaTotaleCostoUpdate();
}
//aggiunge un prodotto quando si selezione un nuovo prodotto in fase di editazione prodotto
this.aggiungiProdottoUpdate = function ($item) {
if($item && $item.originalObject && ($scope.ripctrl.prodottiIds.indexOf($item.originalObject.idprodotto)>-1)){
var superato = 0;
for (var i = $scope.ripctrl.riparazioneUpdate.prodotti.length - 1; i >= 0; i--) {
if($scope.ripctrl.riparazioneUpdate.prodotti[i].id == $item.originalObject.idprodotto){
$scope.ripctrl.riparazioneUpdate.prodotti[i].quantita++;
superato = 1;
}
}
if(superato==0){
$scope.ripctrl.riparazioneUpdate.prodotti.push({'id':$item.originalObject.idprodotto, 'quantita':1});
$scope.ripctrl.prodottiAggiuntiUpdate.push($item.originalObject);
}
//azzero
$scope.$broadcast('angucomplete-alt:clearInput','prodottiUpdate');
//aggiorno costo totale
$scope.ripctrl.aggiornaTotaleCostoUpdate();
}
}
//rimuove un prodotto quando si selezione un nuovo prodotto in fase di editazione prodotto
this.rimuoviProdottoUpdate = function ($item) {
for (var i = $scope.ripctrl.riparazioneUpdate.prodotti.length - 1; i >= 0; i--) {
if($scope.ripctrl.riparazioneUpdate.prodotti[i].id == $item.idprodotto && $scope.ripctrl.riparazioneUpdate.prodotti[i].quantita > 1){
$scope.ripctrl.riparazioneUpdate.prodotti[i].quantita--;
}else if($scope.ripctrl.riparazioneUpdate.prodotti[i].id == $item.idprodotto){
$scope.ripctrl.riparazioneUpdate.prodotti.splice(i,1);
$scope.ripctrl.prodottiAggiuntiUpdate.splice(i,1);
}
}
//aggiorno costo totale
$scope.ripctrl.aggiornaTotaleCostoUpdate();
}
//per insert riparazione
this.totalecostoriparazioneInsert = "EURO 0,00";
this.aggiornaTotaleCosto = function(){
$scope.totalecostoriparazioneInsert = "";
var tmp = 0;
for (var i = $scope.ripctrl.prodottiAggiuntiInsert.length - 1; i >= 0; i--) {
tmp+=(parseInt($scope.ripctrl.riparazioneInsert.prodotti[i].quantita)*parseFloat($scope.ripctrl.prodottiAggiuntiInsert[i].costo));
}
$scope.ripctrl.riparazioneInsert.totalecostoriparazione= tmp;
$scope.ripctrl.totalecostoriparazioneInsert = "EURO " + tmp;//(tmp%1==0)?tmp+",00":(tmp.split(".").join(","));
}
this.aggiungiProdotto = function ($item) {
if($item && $item.originalObject && ($scope.ripctrl.prodottiIds.indexOf($item.originalObject.idprodotto)>-1)){
var superato = 0;
for (var i = $scope.ripctrl.riparazioneInsert.prodotti.length - 1; i >= 0; i--) {
if($scope.ripctrl.riparazioneInsert.prodotti[i].id == $item.originalObject.idprodotto){
$scope.ripctrl.riparazioneInsert.prodotti[i].quantita++;
superato = 1;
}
}
if(superato==0){
$scope.ripctrl.riparazioneInsert.prodotti.push({'id':$item.originalObject.idprodotto, 'quantita':1});
$scope.ripctrl.prodottiAggiuntiInsert.push($item.originalObject);
}
//azzero
$scope.$broadcast('angucomplete-alt:clearInput','prodottiInsert');
//aggiorno costo totale
$scope.ripctrl.aggiornaTotaleCosto();
}
}
//fine per insert riparazione
this.rimuoviProdotto = function ($item) {
for (var i = $scope.ripctrl.riparazioneInsert.prodotti.length - 1; i >= 0; i--) {
if($scope.ripctrl.riparazioneInsert.prodotti[i].id == $item.idprodotto && $scope.ripctrl.riparazioneInsert.prodotti[i].quantita > 1){
$scope.ripctrl.riparazioneInsert.prodotti[i].quantita--;
}else if($scope.ripctrl.riparazioneInsert.prodotti[i].id == $item.idprodotto){
$scope.ripctrl.riparazioneInsert.prodotti.splice(i,1);
$scope.ripctrl.prodottiAggiuntiInsert.splice(i,1);
}
}
//aggiorno costo totale
$scope.ripctrl.aggiornaTotaleCosto();
}
this.submitCliente = function() {
this.clienteInsert.method = "insertcliente";
this.clienteInsert.sede = this.clienteInsert.sede.idsede;
if (this.selezionecomune!=null) this.clienteInsert.citta = this.selezionecomune.title;
APIService.async(this.clienteInsert).then(function(adata) {
debugger;
if (adata.status) {
swal("Cliente creato con successo!", "success")
//aggiorno la lista degli utenti
$scope.ripctrl.clienti = adata.message;
$scope.clienti = adata.message;
//svuoto i valori precedenti
for (x in $scope.ripctrl.clienteInsert) {
$scope.ripctrl.clienteInsert[x] = "";
}
//aggiorno cliuente in scheda ripartazione Insert
var idcliente = adata.message[adata.message.length-1].idcliente;
//visualizzo il cliente nel box in fase di inserimento
for(cli in $scope.ripctrl.clienti){
if($scope.ripctrl.clienti[cli]['idcliente'] == idcliente){
debugger;
$scope.ripctrl.selezioneclienteinsert = $scope.ripctrl.clienti[cli];
break;
}
}
//nascondo il menu inserimento
$scope.ripctrl.newCliente = 0;
} else {
$scope.ripctrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di aggiornamento dei dati, si prega di aggiornare la pagina!");
}
});
}
this.selezionedeviceinsert = function(item){
if(item && item.originalObject){
$scope.ripctrl.aselezionedeviceinsert = item;
$scope.ripctrl.prodotti = $scope.prodotti = $scope.ripctrl.getProdotti(item.originalObject.iddevice);
$scope.ripctrl.riparazioneInsert.iddevice = item.originalObject.iddevice;
}
}
this.getSedeUtente = function(idsede) {
for(var tmp in $scope.ripctrl.sedi){
if($scope.ripctrl.sedi[tmp]['idsede'] == idsede){
return $scope.ripctrl.sedi[tmp];
}
}
return $scope.ripctrl.sedi[0];
}
this.submitRiparazione = function() {
var send = this.riparazioneInsert;
// send.iddevice=send.device.iddevice;
send.method = "insertriparazione";
if(send.cliente != null){
send.idcliente=send.cliente;
}else{
swal("Devi selezionare il cliente!","Compila correttamente il form e riprova!", "error");
return;
}
if(userInfo.user_type_id != 830830) {
send.idsede = userInfo.sede;
}else if(this.riparazioneInsert.sedes!=null && "idsede" in this.riparazioneInsert.sedes){
send.sede = this.riparazioneInsert.sedes.idsede;
}else{
swal("Devi selezionare la sede!","Compila correttamente il form e riprova!", "error");
return;
}
if(send.user != null && "id_user" in send.user){
send.id_user=send.user.id_user;
}else{
swal("Devi selezionare l'utente di ripara che inserisce la pratica!","Compila correttamente il form e riprova!", "error");
return;
}
console.log("riparazioneInsert____",send);
APIService.async(send).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")
//azzero il campo di inserimento utente
$scope.ripctrl.selezioneutentecambiostatoInsert=null;
//azzero il cliente
$scope.ripctrl.selezioneclienteinsert = null;
//aggiorno la lista degli utenti
$scope.ripctrl.getData(new Date().getFullYear());
//svuoto i valori precedenti
for (x in $scope.ripctrl.riparazioneInsert) {
if(x=="prodotti"){
$scope.ripctrl.riparazioneInsert[x] = [];
}else{
$scope.ripctrl.riparazioneInsert[x] = "";
}
}
$scope.ripctrl.prodottiAggiuntiInsert = [];
//nascondo il menu inserimento
$scope.ripctrl.newRiparazione = 0;
//$scope.ripctrl.riparazioneInsert.sede = null;
$scope.ripctrl.riparazioneInsert.idcliente = null;
$scope.ripctrl.selezioneutentecambiostatoInsert = null;
$scope.ripctrl.riparazioneInsert.dataingresso = new Date();
} else {
$scope.ripctrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di aggiornamento dei dati, si prega di aggiornare la pagina!");
}
});
}
xxx = $scope;
//funzione richiama api per editazione riparazione
$scope.modificaRiparazione = function() {
var dati = $scope.ripctrl.riparazioneUpdate;
if(userInfo.user_type_id != 830830) {
dati.idsede = userInfo.sede;
}else if(dati.sedes != null && "idsede" in dati.sedes){
dati.sede = dati.sedes.idsede;
}else{
swal("Devi selezionare la sede!","Compila correttamente il form e riprova!", "error");
return;
}
if(dati.user != null && "id_user" in dati.user){
dati.id_user=dati.user.id_user;
}else{
swal("Devi selezionare l'utente riparazione'!","Compila correttamente il form e riprova!", "error");
return;
}
dati.method = "editriparazione";
//select attive
dati.idcliente=dati.cliente.idcliente;
dati.iddevice=dati.device.iddevice;
APIService.async(dati).then(function(adati) {
if (adati.status) {
swal(adati.message, "Riparazione modificato con successo!", "success");
$scope.ripctrl.updateRiparazione = 0;
$scope.ripctrl.riparazioneUpdate = {};
$scope.ripctrl.getData(new Date().getFullYear());
} else {
$scope.ripctrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di aggiornamento dei dati, si prega di aggiornare la pagina!");
}
});
}
this.cancellaRiparazione = function (dati) {
swal({
title: "Sei sicuro di voler cancellare la riparazione? L'utente non potrà più visulizzare il tracciamento sul sito!",
text: "L'azione eseguita sarà irreversibile!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Si, cancellala!",
closeOnConfirm: false
}, function(){
dati.$edit = false;
dati.method = "deleteriparazione";
debugger;
APIService.async(dati).then(function(adati) {
if (adati.status) {
swal(adati.message, "Riparazione eliminata con successo!", "success");
$scope.ripctrl.getData(new Date().getFullYear());
} else {
$scope.ripctrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di aggiornamento dei dati, si prega di aggiornare la pagina!");
}
});
});
}
//datetimepicker
})
.controller('DatepickerDemoCtrl', function ($scope) {
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.toggleMin = function() {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.open = function($event, opened) {
$event.preventDefault();
$event.stopPropagation();
$scope[opened] = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
})
.controller('DatepickerCtrl', function ($scope) {
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.clear = function() {
$scope.dt = null;
};
$scope.options = {
customClass: getDayClass,
minDate: new Date(),
showWeeks: true
};
// Disable weekend selection
function disabled(data) {
var date = data.date,
mode = data.mode;
return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
}
$scope.toggleMin = function() {
$scope.options.minDate = $scope.options.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.setDate = function(year, month, day) {
$scope.dt = new Date(year, month, day);
};
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
var afterTomorrow = new Date(tomorrow);
afterTomorrow.setDate(tomorrow.getDate() + 1);
$scope.events = [
{
date: tomorrow,
status: 'full'
},
{
date: afterTomorrow,
status: 'partially'
}
];
function getDayClass(data) {
var date = data.date,
mode = data.mode;
if (mode === 'day') {
var dayToCheck = new Date(date).setHours(0,0,0,0);
for (var i = 0; i < $scope.events.length; i++) {
var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);
if (dayToCheck === currentDay) {
return $scope.events[i].status;
}
}
}
return '';
}
})
.controller('TimepickerCtrl', function ($scope, $log) {
$scope.today = function() {
$scope.w.dataingresso = new Date();
};
$scope.toggleMin = function() {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.open = function($event, opened) {
$event.preventDefault();
$event.stopPropagation();
$scope[opened] = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
//timepicker
$scope.hstep = 1;
$scope.mstep = 15;
$scope.options = {
hstep: [1, 2, 3],
mstep: [1, 5, 10, 15, 25, 30]
};
$scope.toggleMode = function() {
$scope.ismeridian = ! $scope.ismeridian;
};
$scope.changed = function () {
};
this.aggiornaImgInsert= function(){
//setto l'immagine in real time
var fileInput = $('#foto-input');
var file = fileInput[0].files[0];
this.deviceInsert.upload = file;
var imageType = /image.*/;
if (file.type.match(imageType)) {
var reader = new FileReader();
reader.addEventListener("load", function () {
$scope.dectrl.deviceInsert.previewImage = this.result;
$('#mock').click();
}, false);
reader.readAsDataURL(file);
} else {
alert("File non supportato!");
}
}
debugger;
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate', 'yyyy-MM-dd hh:mm'];
$scope.format = $scope.formats[4];
});
materialAdmin
.directive('lazyLoadOptions', [function() {
return {
restrict: 'EA',
require: 'ngModel',
scope: {
options: '=',
lazyLoadFrom: '&'
},
link: function($scope, $element, $attrs, $ngModel){
// Ajax loading notification
$scope.options = [
{
ragionesociale: "Loading..."
}
];
// Control var to prevent infinite loop
$scope.loaded = false;
$element.bind('mousedown', function() {
// If the select hasn't been loaded, load data from promise
if(!$scope.loaded) {
$scope.lazyLoadFrom().then(function(data) {
$scope.options = data;
// Prevent the load from occurring again
$scope.loaded = true;
// Blur the element to collapse it
$element[0].blur();
// Click the element to re-open it (use timeout to escape digest cycle)
setTimeout(function(){
var e = document.createEvent("MouseEvents");
e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
$element[0].dispatchEvent(e);
}, 1);
}, function(reason){
// Error handling here
console.error(reason);
});
}
});
}
}
}])