'use strict';
var app = angular.module('App2', ['ngStorage',
'ngRoute',
'ngPagination',
'ngFileUpload',
'ngDialog',
'angucomplete-alt',
'ui.grid',
'ui.grid.edit',
'ui.grid.selection',
'ui.select',
'ui.grid.exporter']);
var app3 = angular.module('App3', ['ngStorage']);
app.directive('uiSelectWrap', uiSelectWrap);
uiSelectWrap.$inject = ['$document', 'uiGridEditConstants'];
function uiSelectWrap($document, uiGridEditConstants) {
return function link($scope, $elm, $attr) {
$document.on('click', docClick);
function docClick(evt) {
if ($(evt.target).closest('.ui-select-container').length === 0) {
$scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
$document.off('click', docClick);
}
}
};
}
app.directive('format', ['$filter', function ($filter) {
return {
require: '?ngModel',
link: function (scope, elem, attrs, ctrl) {
if (!ctrl) return;
ctrl.$formatters.unshift(function (a) {
return $filter(attrs.format)(ctrl.$modelValue)
});
elem.bind('blur', function(event) {
var plainNumber = elem.val().replace(/[^\d|\-+|\.+]/g, '');
elem.val($filter(attrs.format)(plainNumber));
});
}
};
}]);
app.config(function ($routeProvider) {
/*home*/
$routeProvider.when('/', {
controller: 'MainCtrl',
templateUrl: '/templates/home.html'
});
/*ATENCION ESPECIALIZADA PRINCIPAL*/
$routeProvider.when('/consultas', {
controller: 'MainCtrl',
templateUrl: '/templates/consultagral.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
}
});
/*ATENCION ESPECIALIZADA PRINCIPAL*/
$routeProvider.when('/atencionesp', {
controller: 'MainCtrl',
templateUrl: '/templates/atencionesp.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService' ,
'guestService2': 'ventasService',
'guestService3': 'juridicoService'
}
});
/*ATENCION ESPECIALIZADA EDICION*/
$routeProvider.when('/atencionfolio/:folio', {
controller: 'AtencionEspCtrl',
templateUrl: '/templates/AtencionFolio.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService' ,
'guestService2': 'productosService',
'guestService3': 'DaService',
'guestService4':'causaService'
}
});
/*MESA DE CONTROL*/
$routeProvider.when('/mesacontrol', {
controller: 'MesaControlCtrl',
templateUrl: '/templates/mesacontrol.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService'
}
});
/*CONTABILIDAD PRINCIPAL*/
$routeProvider.when('/contabilidad', {
controller: 'MainCtrl',
templateUrl: '/templates/ContMenu.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService'
}
});
/*CONTABILIDAD EDICION*/
$routeProvider.when('/atencioncontabilidad/:folio', {
controller: 'ContabilidadCtrl',
templateUrl: '/templates/contabilidad.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService' ,
'guestService2': 'productosService',
'guestService3': 'DaService',
'guestService4':'causaService'
}
});
/*PREVENSION PRINCIPAL*/
$routeProvider.when('/prevension', {
controller: 'MainCtrl',
templateUrl: '/templates/PrevensionMenu.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService'
}
});
/*PREVENCION EDICION*/
$routeProvider.when('/atencionprevension/:folio', {
controller: 'PrevensionCtrl',
templateUrl: '/templates/prevension.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService' ,
'guestService2': 'productosService',
'guestService3': 'DaService',
'guestService4':'causaService'
}
});
/*VENTAS PRINCIPAL*/
$routeProvider.when('/ventas', {
controller: 'MainCtrl',
templateUrl: '/templates/VentasMenu.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService'
}
});
/*VENTAS EDICION*/
$routeProvider.when('/atencionventas/:cua', {
controller: 'VentasCtrl',
templateUrl: '/templates/ventas.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService' ,
'guestService4':'ventasService'
}
});
/*PREVENSION PRINCIPAL*/
$routeProvider.when('/ventas', {
controller: 'MainCtrl',
templateUrl: '/templates/VentasMenu.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService',
'guestService2': 'ventasService',
'guestService3': 'juridicoService'
}
});
/*JURIDICO PRINCIPAL*/
$routeProvider.when('/juridico', {
controller: 'MainCtrl',
templateUrl: '/templates/JuridicoMenu.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService',
'guestService2': 'juridicoService'
}
});
/*JURIDICO EDICION*/
$routeProvider.when('/atencionjuridico/:cua', {
controller: 'JuridicoCtrl',
templateUrl: '/templates/juridico.html',
resolve: {
'guestService': 'mostrarPrincipal' ,
'guestService1': 'userService' ,
'guestService3': 'DaService',
'guestService4':'causaService'
}
});
/*usuarios*/
$routeProvider.when('/admin_usuarios', {
controller: 'adminUsersCtrl',
templateUrl: '/templates/usuarios.html',
resolve: {
'guestService0': 'userService',
'guestService1': 'perfilService'
}
});
/*perfiles*/
$routeProvider.when('/admin_perfiles', {
controller: 'adminPerfilCtrl',
templateUrl: '/templates/perfiles.html',
resolve: {
'guestService': 'perfilService'
}
});
/*Productos*/
$routeProvider.when('/admin_productos', {
controller: 'adminProductosCtrl',
templateUrl: '/templates/productos.html',
resolve: {
'guestService0': 'productosService',
}
});
/*RECUPERACIONES*/
$routeProvider.when('/recuperaciones', {
controller: 'RecuperacionesCtrl',
templateUrl: '/templates/recuperaciones.html',
resolve: {
'guestService2': 'agentesService'
}
});
$routeProvider.when('/ayuda', {
templateUrl: '/templates/ayuda.html',
});
$routeProvider.otherwise({
redirectTo: '/'
});
});
/*daños*/
/*usuarios*/
app.factory('userService', function ($rootScope, $http, $q, $log) {
var deferred = $q.defer();
$http.post('rest/admin_users')
.success(function (data, status, headers, config) {
$rootScope.cat_users = data;
deferred.resolve();
//console.log(data);
});
return deferred.promise;
});
/*perfiles*/
app.factory('perfilService', function ($rootScope, $http, $q, $log) {
var deferred = $q.defer();
$http.post('rest/admin_perfil')
.success(function (data, status, headers, config) {
$rootScope.cat_perfil = data;
deferred.resolve();
});
return deferred.promise;
});
/*tramite*/
app.factory('productosService', function ($rootScope, $http, $q, $log) {
var deferred = $q.defer();
$http.post('rest/admin_productos')
.success(function (data, status, headers, config) {
$rootScope.cat_productos = data;
deferred.resolve();
console.log(data);
});
return deferred.promise;
});
/*oficinas*/
app.factory('causaService', function ($rootScope, $http, $q, $log) {
var deferred = $q.defer();
$http.post('rest/admin_causas')
.success(function (data, status, headers, config) {
$rootScope.cat_causas = data;
deferred.resolve();
});
return deferred.promise;
});
/*DA*/
app.factory('DaService', function ($rootScope, $http, $q, $log) {
var deferred = $q.defer();
$http.post('rest/admin_da')
.success(function (data, status, headers, config) {
$rootScope.cat_Da = data;
deferred.resolve();
});
return deferred.promise;
});
/*MENU DE VENTAS (AGENTES SUSPENDIDOS)*/
app.factory('ventasService', function ($rootScope, $http, $q, $log, $sessionStorage) {
var deferred = $q.defer();
$http.post('rest/menuventas', $sessionStorage.userLocal)
.success(function (data, status, headers, config) {
$rootScope.menuventas = data;
deferred.resolve();
//console.log(data);
});
return deferred.promise;
});
/*MENU DE juridico (POR CUA AGENTE)*/
app.factory('juridicoService', function ($rootScope, $http, $q, $log) {
var deferred = $q.defer();
$http.post('rest/menujuridico')
.success(function (data, status, headers, config) {
$rootScope.menujuridico = data;
deferred.resolve();
//console.log(data);
});
return deferred.promise;
});
/*Mostrar principal*/
app.factory('mostrarPrincipal', function ($rootScope, $http, $q, $log, $sessionStorage) {
var deferred = $q.defer();
$http.post('rest/admin_principal', $sessionStorage.userLocal)
.success(function (data, status, headers, config) {
$rootScope.cat_principal = data;
deferred.resolve();
//console.log(data);
});
return deferred.promise;
});
app.factory('agentesService', function ($rootScope, $http, $q, $log) {
var deferred = $q.defer();
$http.post('rest/traeagentes')
.success(function (data, status, headers, config) {
$rootScope.agentes = data;
deferred.resolve();
});
return deferred.promise;
});
app.factory('RecPrevService', function ($rootScope, $http, $q, $log) {
var deferred = $q.defer();
$http.post('rest/vistarecprev')
.success(function (data, status, headers, config) {
$rootScope.estatus_facult = data;
deferred.resolve();
});
return deferred.promise;
});
app.factory('RecJurService', function ($rootScope, $http, $q, $log) {
var deferred = $q.defer();
$http.post('rest/vistarecjur')
.success(function (data, status, headers, config) {
$rootScope.estatus_facult = data;
deferred.resolve();
//console.log(data);
});
return deferred.promise;
});
/* controllers*/
app3.controller('gac', function ($scope, $window, $q, $http, $rootScope, $location, $sessionStorage, $timeout) {
$scope.solicAccesAlert = false;
var auth2;
$scope.user = {};
$window.onload = function () {
gapi.load('auth2', initSigninV2);
};
var initSigninV2 = function () {
auth2 = gapi.auth2.getAuthInstance();
auth2.isSignedIn.listen(signinChanged);
auth2.currentUser.listen(userChanged);
if (auth2.isSignedIn.get() == true) {
auth2.signIn();
}
};
//variables de Google
var signinChanged = function (isSignedIn) {
if (isSignedIn) {
var googleUser = auth2.currentUser.get();
var authResponse = googleUser.getAuthResponse();
var profile = googleUser.getBasicProfile();
$scope.user.id = profile.getId();
$scope.user.fullName = profile.getName();
$scope.user.firstName = profile.getGivenName();
$scope.user.lastName = profile.getFamilyName();
$scope.user.photo = profile.getImageUrl();
$scope.user.email = profile.getEmail();
$scope.user.domain = googleUser.getHostedDomain();
$scope.user.timestamp = moment().format('x');
$scope.user.idToken = authResponse.id_token;
$scope.user.expiresAt = authResponse.expires_at;
$scope.$digest();
} else {
$scope.user = {};
$scope.$digest();
}
//console.log($scope.user)
$rootScope.user = $scope.user;
};
var userChanged = function (user) {};
//botton continuar//
$scope.submitLogin = function () {
var deferred = $q.defer();
$http.post('rest/login', $scope.user)
.success(function (data, status, headers, config) {
var salida = [];
angular.forEach(data, function (value, key) {
if (value.email == $scope.user.email && value.activo == 'S')
salida.push(value);
})
//console.log(salida)
deferred.resolve();
if (salida.length > 0) {
$scope.userData = {
'id_user': salida[0].id_usuario,
'name': $scope.user.fullName,
'email': $scope.user.email,
'perfil': salida[0].id_perfil,
'img': $scope.user.photo,
'tk': salida[0].tk
};
$sessionStorage.userLocal = $scope.userData;
loginSuccess();
$window.location.href = ('index.html')
} else {
loginError();
$scope.solicAccesAlert = true;
}
});
return deferred.promise;
}
//botton continuar//
//LANZAR COMUNICADO //
var date = new Date();
var diaActual = date.getDate();
var mesActual = date.getMonth();
if (diaActual >= 17 && diaActual <= 31 && mesActual == 11){
console.log("el comunicado debe mostrarse")
$sessionStorage.ComunicadoVisto = false;
}
else{
console.log("el comunicado no se muestra")
$sessionStorage.ComunicadoVisto = true;
}
//LANZAR COMUNICADO //
});
app.controller('MasterController', function ($scope, $location, $rootScope, $window, $sessionStorage, ngDialog) {
$scope.userActivo = $sessionStorage.userLocal;
//MODAL COMUNICADOS//
$scope.imgActive = 1;
$scope.prev = function(){
$scope.imgActive = $scope.imgActive - 1
}
$scope.next = function(){
$scope.imgActive = $scope.imgActive + 1
}
//MODAL COMUNICADOS//
//console.log($scope.userActivo);
if ($scope.userActivo == undefined) {
console.log("no se ha definido el usuario")
$window.location.href = ('/')
}
//MARCAR LOS MENUS COMO ACTIVOS//
$scope.isActive = function (destination) {
return destination === $location.path();
}
//MARCAR LOS MENUS COMO ACTIVOS//
//MODAL AYUDA//
$scope.clickToOpen2 = function (report) {
//console.log(report)
ngDialog.open({
template: 'templates/ayuda.html',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
width: '50%',
height: '1000'
});
}
});
app.controller('MainCtrl', function ($scope, $rootScope, ngDialog, $log, $http, $routeParams, $location, $route, $q, $window, $timeout, $sessionStorage) {
$scope.principal = $rootScope.cat_principal;
$scope.ventas = $rootScope.menuventas;
$scope.juridico = $rootScope.menujuridico;
$scope.Listusuarios = $rootScope.cat_users;
$scope.picFiles = "";
console.log($scope.principal);
$scope.atenderfolio = function(atencionesp){
$location.path('/atencionfolio/' + atencionesp.folio);
}
$scope.atendercontabilidad = function(contabilidad){
$location.path('/atencioncontabilidad/' + contabilidad.folio);
}
$scope.atenderjuridico = function(juridico){
$location.path('/atencionjuridico/' + juridico.cua);
}
$scope.atenderprevension = function(prevension){
$location.path('/atencionprevension/' + prevension.folio);
}
$scope.atenderventas = function(ventas){
$location.path('/atencionventas/' + ventas.cua);
}
$scope.gridgral = {
exporterOlderExcelCompatibility: true,
//enableSorting: true,
enableRowSelection: true,
enableFullRowSelection: true,
columnDefs: [
{ name: 'folio', displayName: 'Folio', width: '70' },
{ name: 'fecha_ingreso', displayName : 'Fec. Ingreso', width: '120' },
{ name: 'poliza', width: '120' },
{ name: 'cua', displayName : 'CUA', width: '120' },
{ name: 'contratanteasegurado', displayName : 'Contratante/Asegurado', width: '220'},
{ name: 'telefono', displayName : 'Tel.', width: '110'},
{ name: 'email', displayName : 'Correo Elect.', width: '190' },
{ name: 'usuario_asignado', displayName : 'Asignado a:', width: '220' },
{ name: 'fecha_contacto', displayName : 'Fec. Contacto', width: '125' },
{ name: 'ramo', displayName : 'Ramo', width: '95' },
{ name: 'producto', displayName : 'Producto', width: '120' },
{ name: 'daseleccionada', displayName : 'D.A', width: '120' },
{ name: 'descripcion_caso', displayName : 'Descripcion', width: '170' },
{ name: 'importe', displayName: 'Importe', width: '100', cellFilter: 'currency' },
{ name: 'moneda', displayName: 'Moneda', width: '100' },
{ name: 'tipocambio', displayName: 'Tipo Cambio Inicial', width: '149'},
{ name: 'tipocambioapl', displayName: 'Tipo Cambio Aplicado', width: '149'},
{ name: 'conversion', displayName: 'Conversion', width: '120' , cellFilter: 'currency'},
{ name: 'carta', displayName: 'Carta', width: '100' },
{ name: 'identificacion', displayName: 'Identificacion', width: '100' },
{ name: 'evidencia', displayName: 'Evidencia', width: '100' },
{ name: 'cedula', displayName: 'Cedula', width: '100' },
{ name: 'causa', displayName : 'Causa', width: '175' },
{ name: 'estatuspoliza', displayName : 'Estatus Poliza', width: '137' },
{ name: 'estatusagente', displayName : 'Estatus Agente', width: '139' },
{ name: 'motivoagente', displayName : 'Motivo Susp. Agente', width: '179' },
{ name: 'fechasuspension', displayName : 'Fec. Suspension', width: '125' },
{ name: 'clasificacion', displayName : 'Clasificacion', width: '135' },
{ name: 'estatusatencionesp', displayName : 'Estatus Actual', width: '175' },
{ name: 'fecha_solicitud_fianza', displayName : 'Fec. Sol. Fianza', width: '137' },
{ name: 'fecha_pago_fianza', displayName : 'Fec. Pago Fianza', width: '137' },
{ name: 'fecha_descarte_juridico', displayName : 'Fec. Descarte Jur.', width: '137' },
{ name: 'prevensionobservaciones', displayName : 'Observaciones Prev.', width: '195' },
{ name: 'estatusprevension', displayName : 'Estatus Prev.', width: '195' }
],
enableGridMenu: true,
enableSelectAll: true,
exporterMenuExcel: true,
exporterMenupdf: false,
exporterExcelFilename: 'myFile.xlsx',
exporterExcelSheetName: 'Sheet1',
enableFiltering: true,
showHeader: true,
onRegisterApi: function(gridApi){
$scope.gridApi = gridApi;
},
/* SheetJS Service setup */
data: $scope.principal,
filename: "SheetJSAngular",
sheetname: "ng-SheetJS"
};
$scope.onExit = function() {
/* var deferred = $q.defer();
$http.post('/rest/eliminatk', $sessionStorage.userLocal)
.success(function(data, status, headers, config) {
deferred.resolve();
return deferred.promise;
}); */
};
$window.onbeforeunload = $scope.onExit;
});
app.controller('adminUsersCtrl', function ($scope, $http, $rootScope, $parse, Upload, $timeout, ngDialog, $window) {
$scope.Listperfiles = $rootScope.cat_perfil;
$scope.users = $rootScope.cat_users;
//abrir modal nuevos
$scope.NewUsuario = function(){
$scope.usuario = {};
ngDialog.openConfirm({
template: 'newUsuario',
plain: false,
closeByDocument: false,
controllerAs: 'adminUsersCtrl',
className: 'ngdialog-theme-default',
width: '60%',
scope:$scope,
}).then({
});
}
$scope.AgregarUsuario = function(usuario){
$http.post('/rest/create_Usuarios', usuario)
.success(function (data, status, headers, config) {
if(status >= 200){
saveSuccess();
ngDialog.close();
$timeout(function () {
//$rootScope.$apply();
$window.location.reload();//recarga la pagina
}, 2000);
}
})
}
//abrir modal edicion
$scope.EditUsuario = function(users){
$scope.optSelected = users;
$scope.apply;
console.log($scope.optSelected)
ngDialog.open({
template: 'editUsuario',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'adminUsersCtrl',
width: '60%',
scope:$scope,
});
}
$scope.EditarUsuario = function(){
console.log($scope.optSelected)
for (var i = 0; i < $scope.Listperfiles.length; i++) {
if ($scope.Listperfiles[i].perfil == $scope.optSelected.perfil) {
$scope.optSelected.id_perfil =$scope.Listperfiles[i].id_perfil ;
break;
}
}
$http.post('/rest/update_Usuarios', $scope.optSelected)
.success(function (data, status, headers, config) {
if(status >= 200){
saveSuccess();
ngDialog.close();
$timeout(function () {
//$rootScope.$apply();
$window.location.reload();//recarga la pagina
}, 2000);
}
})
}
});
app.controller('adminProductosCtrl', function ($scope, $http, $rootScope, $parse, Upload, $timeout, ngDialog, $window) {
$scope.productos = $rootScope.cat_productos;
//abrir modal nuevos
$scope.NewProducto = function(){
$scope.producto = {};
ngDialog.openConfirm({
template: 'newProducto',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
width: '60%',
scope:$scope,
}).then({
});
}
$scope.AgregarProducto = function(producto){
console.log($scope.producto);
$http.post('/rest/create_producto', producto)
.success(function (data, status, headers, config) {
if(status >= 200){
saveSuccess();
ngDialog.close();
$timeout(function () {
//$rootScope.$apply();
$window.location.reload();//recarga la pagina
}, 2000);
}
})
}
//abrir modal edicion
$scope.EditProducto = function(producto){
$scope.optSelected = producto;
console.log(producto)
ngDialog.open({
template: 'editProducto',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
width: '60%',
scope:$scope,
});
}
$scope.EditarProducto = function(optSelected){
console.log(optSelected)
$http.post('/rest/update_producto', optSelected)
.success(function (data, status, headers, config) {
if(status >= 200){
saveSuccess();
ngDialog.close();
$timeout(function () {
//$rootScope.$apply();
$window.location.reload();//recarga la pagina
}, 2000);
}
})
}
});
app.controller('MesaControlCtrl', function ($scope, $http, $rootScope, $sessionStorage, $parse, Upload, $timeout, ngDialog, $window) {
$scope.principal = $rootScope.cat_principal;
$scope.Listusuarios = $rootScope.cat_users;
$scope.picFiles = [];
$scope.archivosnuevos = [];
//$scope.usuarioseleccionado = {};
//abrir modal nuevos
$scope.nuevofolio = function(){
$scope.mesacontrol = "";
ngDialog.openConfirm({
template: 'NuevoFolio',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
width: '80%',
scope:$scope,
}).then({
});
}
//----------------------------------------------------------------------------------------------------------
$scope.uploadFiles = function (files, errFiles) {
if (files.length>0) {
for (var cont=0; cont< files.length; cont++)
{
$scope.picFiles.push({bucketkey:'na', filename:files[cont].name});
}
$scope.archivosnuevos.push(files);
//$scope.archivosnuevos=files;
}
}
//----------------------------------------------------------------------------------------------------------
$scope.AgregarFolio = function(mesacontrol,userasigned)
{
mesacontrol.userLocal = $sessionStorage.userLocal.id_user;
for (var i=0; i< $scope.Listusuarios.length; i++)
{
if ($scope.Listusuarios[i].nombre === userasigned)
{
mesacontrol.usuario = $scope.Listusuarios[i].id_usuario;
break;
}
}
$window.document.getElementById('botonguardar').disabled = true;
$http.post('/rest/create_folio', mesacontrol)
.success(function (data, status, headers, config) {
if(status >= 500){
console.log("ocurrió un error")
$scope.preloader = false;
ngDialog.openConfirm({
template: 'errDialog',
className: 'ngdialog-theme-default',
width: '55%'
}).then(function () {
console.log("ok")
$location.path('/');
$window.location.reload();
}
)}
else{
//$rootScope.facults.push(data);
if ($scope.archivosnuevos.length > 0) {
console.log("si hay archivos adjuntos")
for (var cont=0; cont<=$scope.archivosnuevos.length; cont++)
{
angular.forEach($scope.archivosnuevos[cont], function (file) {
var datFiles = {
folio: data[0].folio,
archivos: file
};
console.log(data[0].folio);
file.upload = Upload.upload({
url: 'rest/upload_files',
data: {
folio: data[0].folio,
archivos: file
}
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
$scope.result2 = true;
console.log(response.data);
$window.document.getElementById('botonguardar').disabled = false;
altaAlert();
$timeout(function () {
//$rootScope.$apply();
$window.location.reload();//recarga la pagina
}, 9999);
});
});
});
}
//------------------------------------
}
else {
console.log("no hay archivos adjuntos")
$window.document.getElementById('botonguardar').disabled = false;
altaAlert();
ngDialog.close();
$timeout(function () {
//$rootScope.$apply();
$window.location.reload();//recarga la pagina
}, 2000);
}
}
})
}
//abrir modal edicion
$scope.EditFolio = function(folioseleccionado){
// TRAEMOS LOS ARCHIVOS PARA MOSTRARLOS
folioseleccionado.tk = $sessionStorage.userLocal.tk;
$http.post('/rest/traer_nombres_archivos', folioseleccionado)
.success(function (data, status, headers, config) {
if(status >= 200)
{
$scope.picFiles = data;
$scope.mesacontrol = {
'folio':folioseleccionado.folio,
'poliza':folioseleccionado.poliza,
'email':folioseleccionado.email,
'agente':folioseleccionado.nombre_agente,
'cua':folioseleccionado.cua,
'contratanteasegurado':folioseleccionado.contratanteasegurado,
'telefono':folioseleccionado.telefono,
'usuario':folioseleccionado.id_usuario.toString() ,
'userLocal':$sessionStorage.userLocal.id_user
};
$scope.apply;
ngDialog.open({
template: 'editfolio',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
width: '60%',
scope:$scope,
});
}
})
}
$scope.EditarFolio = function(optSelected){
console.log(optSelected)
$http.post('/rest/update_folio', optSelected)
.success(function (data, status, headers, config) {
if(status >= 200){
//$rootScope.facults.push(data);
if ($scope.archivosnuevos.length > 0) {
for (var cont=0; cont<$scope.archivosnuevos.length; cont++)
{
angular.forEach($scope.archivosnuevos[cont], function (file) {
var datFiles = {
folio: data[0].folio,
archivos: file
};
console.log(data[0].folio);
file.upload = Upload.upload({
url: 'rest/upload_files',
data: {
folio: data[0].folio,
archivos: file
}
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
$scope.result2 = true;
altaAlert();
$timeout(function () {
$window.location.reload();//recarga la pagina
}, 90000);
});
});
});
//---------------------------------------------------------------------------------
}
}
else {
console.log("no hay archivos adjuntos")
altaAlert();
ngDialog.close();
$timeout(function () {
//$rootScope.$apply();
$window.location.reload();//recarga la pagina
}, 20000);
}
$scope.picFiles = [];
saveSuccess();
ngDialog.close();
$timeout(function () {
//$rootScope.$apply();
$window.location.reload();//recarga la pagina
}, 20000);
}
})
}
});
app.controller('AtencionEspCtrl', function ($routeParams, $location, $q, $scope, $filter, $http, $rootScope, $sessionStorage, $parse, Upload, $timeout, ngDialog, $window) {
$window.scrollTo(0, 0);
$scope.principal = $rootScope.cat_principal;
$scope.Listusuarios = $rootScope.cat_users;
$scope.Listproductos = $rootScope.cat_productos;
$scope.Listagencias = $rootScope.cat_Da;
$scope.ListCausas = $rootScope.cat_causas;
$scope.picFiles = [];
$scope.archivosnuevos = [];
$scope.notas = [];
$scope.depuracion = [];
$scope.estadoboton = 'Guardar';
for (var i=0; i<$scope.principal.length; i++) {
if ($scope.principal[i].folio == $routeParams.folio) {
$scope.atencionesp = angular.copy($scope.principal[i]);
$scope.atencionesp.importe = parseFloat($scope.atencionesp.importe);
$scope.atencionesp.tipocambio = parseFloat($scope.atencionesp.tipocambio);
$scope.atencionesp.tipocambioapl = parseFloat($scope.atencionesp.tipocambioapl);
$scope.atencionesp.fecha_contacto = $scope.atencionesp.fecha_contacto !== null ? new Date($scope.atencionesp.fecha_contacto) : undefined ;
$scope.atencionesp.fechasuspension = $scope.atencionesp.fechasuspension !== null ? new Date($scope.atencionesp.fechasuspension) : undefined ;
$scope.atencionesp.fechadescarte = $scope.atencionesp.fechadescarte !== null ? new Date($scope.atencionesp.fechadescarte) : undefined ; ;
$scope.atencionesp.carta = $scope.atencionesp.carta != 1 ? false : true;
$scope.atencionesp.identificacion = $scope.atencionesp.identificacion != 1 ? false : true;
$scope.atencionesp.evidenciapago = $scope.atencionesp.evidenciapago != 1 ? false : true;
$scope.atencionesp.cedula = $scope.atencionesp.cedula != 1 ? false : true;
break;
}
}
// ----- CODIGO PARA MANEJAR LOS ARCHIVOS DE EXCEL
$scope.gridNotificaciones = {
enableHorizontalScrollbar: 0,
enableRowSelection: true,
enableFullRowSelection: true,
columnDefs: [
{field: 'CUA', width: '97'},
{field: 'POLIZA', width: '97'},
{field: 'FECHA_DOMICILIOS', displayName: 'Fec. Domicilios', width: '147'},
{field: 'FECHA_GUIAS', displayName: 'Fec. Guias', width: '147'},
{field: 'FECHA_ENVIO', displayName: 'Fec. Envio', width: '147'},
{field: 'ESTATUS_ENTREGA', displayName: 'Estatus Entrega', width: '157'},
{field: 'SOLICITA_CAMBIO', displayName: 'Solicitud de Cambio', width: '157'},
{field: 'POSIBLE_DP', displayName: 'Posible DP', width: '127'},
{name: 'Eliminar', width: '107',
cellTemplate: ''},
],
enableGridMenu: true,
enableSelectAll: true,
exporterMenuExcel: true,
exporterMenupdf: false,
exporterExcelFilename: 'myFile.xlsx',
exporterExcelSheetName: 'Sheet1',
enableFiltering: true,
showHeader: true,
minimumColumnSize: 950,
onRegisterApi: function(gridApi){
$scope.gridApi = gridApi;
},
/* SheetJS Service setup */
data: $scope.notificaciones,
filename: "SheetJSAngular",
sheetname: "ng-SheetJS"
};
// TRAEMOS LA INFORMACION DE LAS NOTIFICACIONES
$http.post('/rest/traer_notificaciones', $scope.atencionesp)
.success(function (data, status, headers, config) {
$scope.polizas = data;
$scope.gridNotificaciones.data = $scope.polizas
})
// TRAEMOS LOS ARCHIVOS PARA MOSTRARLOS
$scope.atencionesp.tk = $sessionStorage.userLocal.tk;
$http.post('/rest/traer_nombres_archivos', $scope.atencionesp)
.success(function (data, status, headers, config) {
if(status >= 200)
{
$scope.picFiles = data;
$http.post('/rest/traer_notas', $scope.atencionesp)
.success(function (data, status, headers, config) {
if(status >= 200)
{
$scope.notas = data;
$scope.num_notas = $scope.notas.length;
$scope.apply;
}}
);
}}
);
$scope.deleteRow = function(row) {
var index = $scope.gridNotificaciones.data.indexOf(row.entity);
$scope.depuracion.push(row.entity);
$scope.gridNotificaciones.data.splice(index, 1);
};
$scope.checklist = function(atencionesp){
ngDialog.openConfirm({
template: 'checklist',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'AtencionEspCtrl',
width: '70%',
scope:$scope,
}).then({
});
}
$scope.abrenotas = function(notas){
console.log(notas)
ngDialog.openConfirm({
template: 'notas',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'AtencionEspCtrl',
width: '90%',
scope:$scope,
}).then({
});
}
$scope.notific = function(){
ngDialog.openConfirm({
template: '/templates/notificaciones.html',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'AtencionEspCtrl',
width: '99%',
scope:$scope,
}).then({
});
}
$scope.sumanum = function(){
$scope.num_notas = $scope.num_notas + 1;
}
//----------------------------------------------------------------------------------------------------------
$scope.uploadFiles = function (files, errFiles) {
if (files.length>0) {
for (var cont=0; cont< files.length; cont++)
{
$scope.picFiles.push({bucketkey:'na', filename:files[cont].name});
}
$scope.archivosnuevos.push(files);
//$scope.archivosnuevos=files;
}
}
//----------------------------------------------------------------------------------------------------------
$scope.EditarFolio = function(atencionesp)
{
// xxxxxxxxxxxxxx VALIDACIONES xxxxxxxxxxxxxxxx
if (!atencionesp.descripcion_caso)
{
obligatorios(': Descripcion');
$window.document.getElementById('descripcion_caso').focus();
return;
}
if (!atencionesp.ramo)
{
obligatorios(': Ramo');
$window.document.getElementById('ramo').focus();
return;
}
if (!atencionesp.moneda)
{
obligatorios(': Moneda');
$window.document.getElementById('moneda').focus();
return;
}
if (!atencionesp.estatuspoliza)
{
obligatorios(': Estatus de la Poliza');
$window.document.getElementById('estatuspoliza').focus();
return;
}
if (!atencionesp.importe)
{
obligatorios(': Importe');
$window.document.getElementById('importe').focus();
return;
}
if (!atencionesp.clasificacion)
{
atencionesp.clasificacion = null;
}
if (!atencionesp.motivoagente)
{
atencionesp.motivoagente = null;
}
if (!atencionesp.fechasuspension)
{
atencionesp.fechasuspension = null;
}
if (!atencionesp.fechadescarte)
{
atencionesp.fechadescarte = null;
}
if (!atencionesp.id_causa)
{
atencionesp.id_causa = null;
}else
{
if(atencionesp.id_causa == 'None')
{
atencionesp.id_causa = null;
}else{
atencionesp.causa = atencionesp.id_causa;
}
}
// xxxxxxxxxxxxxx FIN DE VALIDACIONES xxxxxxxxxxxxxxxx
atencionesp.usuarioalta = $sessionStorage.userLocal.id_user;
atencionesp.usuariomodificacion = $sessionStorage.userLocal.id_user;
atencionesp.fecha_contacto = $filter('date')(atencionesp.fecha_contacto,'yyyy-MM-dd');
atencionesp.fechasuspension = $filter('date')(atencionesp.fechasuspension,'yyyy-MM-dd');
atencionesp.fechadescarte = $filter('date')(atencionesp.fechadescarte,'yyyy-MM-dd');
atencionesp.importe = atencionesp.importe != null ? Number(atencionesp.importe.toString().replace(/[^0-9.-]+/g,"")) : null;
atencionesp.tipocambio = atencionesp.tipocambio != null ? Number(atencionesp.tipocambio.toString().replace(/[^0-9.-]+/g,"")) : null;
atencionesp.tipocambioapl = atencionesp.tipocambioapl != null ? Number(atencionesp.tipocambioapl.toString().replace(/[^0-9.-]+/g,"")) : null;
//CAMBIAMOS EL RAMO POR EL ID RAMO
switch (atencionesp.ramo) {
case 'AUTOS':
atencionesp.ramo = 'AU';
break;
case 'DAÑOS':
atencionesp.ramo = 'DA';
break;
case 'GMM LP':
atencionesp.ramo = 'GP';
break;
case 'GMM LC':
atencionesp.ramo = 'GC';
break;
case 'VIDA LP':
atencionesp.ramo = 'VP';
break;
case 'VIDA LC':
atencionesp.ramo = 'VC';
break;
}
// SUSTITUYE EL PRODUCTO POR EL ID
for (var i=0; i< $scope.Listproductos.length; i++)
{
if ($scope.Listproductos[i].nombre === atencionesp.producto)
{
atencionesp.id_producto = $scope.Listproductos[i].id_producto;
break;
}
}
//SUSTITUYE LA CAUSA POR EL ID
for (var i=0; i< $scope.ListCausas.length; i++)
{
if ($scope.ListCausas[i].causa === atencionesp.causa)
{
atencionesp.id_causa = $scope.ListCausas[i].id_causa;
break;
}
}
//SUSTITUYE LA DA POR EL ID
for (var i=0; i< $scope.Listagencias.length; i++)
{
if ($scope.Listagencias[i].numeroda === atencionesp.daseleccionada.substring(0, 3))
{
atencionesp.id_da = $scope.Listagencias[i].id_da;
break;
}
}
switch (atencionesp.estatusatencionesp) {
case 'ASIGNADO':
atencionesp.estatusatencionesp = '1';
break;
case 'EN ANALISIS':
atencionesp.estatusatencionesp = '2';
break;
case 'EN CONTABILIDAD':
atencionesp.estatusatencionesp = '3';
break;
case 'ENVIADO A CONTABILIDAD':
atencionesp.estatusatencionesp = '3';
break;
case 'EN VALORACIÓN (ÁREA TÉCNICA)':
atencionesp.estatusatencionesp = '4';
break;
case 'EN MANTENIMIENTO (LÍNEA)':
atencionesp.estatusatencionesp = '5';
break;
case 'CERRADO':
atencionesp.estatusatencionesp = '6';
break;
case 'DESCARTADO':
atencionesp.estatusatencionesp = '7';
break;
case 'LOCALIZACIÓN DE LA COBRANZA':
atencionesp.estatusatencionesp = '8';
break;
case 'RECUPERACIÓN DEL IMPORTE':
atencionesp.estatusatencionesp = '9';
break;
case 'ENVIADO A PREVENCION DE FRAUDES':
atencionesp.estatusatencionesp = '10';
break;
default:
atencionesp.estatusatencionesp = '1';
break;
}
var datos = {atencion: $scope.atencionesp , notes: $scope.notas};
//DESHABILITAMOS EL BOTON DE ACEPTAR
$window.document.getElementById('botonguardar').disabled = true;
$scope.estadoboton = 'Guardando';
var deferred = $q.defer();
$http.post('/rest/update_notificaciones', $scope.gridNotificaciones.data)
.success(function (data, status, headers, config) {
deferred.resolve();
})
if($scope.depuracion.length > 0){
$http.post('/rest/depura_cartera', $scope.depuracion)
.success(function (data, status, headers, config) {
deferred.resolve();
})
}
if ($scope.notas.length > 0 ){
$scope.notas[0].folio = atencionesp.folio;
$scope.notas[0].fecha = $filter('date')(new Date(),'yyyy-MM-dd');
$scope.notas[0].id_usuario = atencionesp.usuariomodificacion;
// $scope.notas[1].folio = atencionesp.folio;
// $scope.notas[1].fecha = $filter('date')(new Date(),'yyyy-MM-dd');
// $scope.notas[1].id_usuario = atencionesp.usuariomodificacion;
}
$http.post('/rest/update_atencionesp', $scope.atencionesp)
.success(function (data, status, headers, config) {
if ($scope.notas.length > 0 ) {
$http.post('/rest/update_notas', $scope.notas)
.success(function (data, status, headers, config) {})
}
if(status >= 500){
console.log("ocurrió un error")
$scope.preloader = false;
ngDialog.openConfirm({
template: 'errDialog',
className: 'ngdialog-theme-default',
width: '55%'
}).then(function () {
$window.document.getElementById('botonguardar').disabled = false;
$scope.estadoboton = 'Guardar';
// $location.path('/');
// $window.location.reload();
$window.location=document.referrer;
}
)}
else{
if ($scope.archivosnuevos.length > 0) {
for (var cont=0; cont<$scope.archivosnuevos.length; cont++)
{
angular.forEach($scope.archivosnuevos[cont], function (file) {
file.upload = Upload.upload({
url: 'rest/upload_files',
data: {
folio: data.folio,
archivos: file
}
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
$scope.result2 = true;
console.log(response.data);
altaAlert();
$window.document.getElementById('botonguardar').disabled = false;
$scope.estadoboton = 'Guardar';
$scope.picFiles = "";
$timeout(function () {
//$rootScope.$apply();
//$window.history.back();//recarga la pagina
$window.location = $window.history.referrer;
}, 2000);
});
});
});
}
//----------------------------------------------------------------------------------
}
else {
console.log("no hay archivos adjuntos")
altaAlert();
$timeout(function () {
//$rootScope.$apply();
$scope.picFiles = "";
//$window.history.back();;//recarga la pagina
$window.location=$window.document.referrer;
}, 2000);
}
}
})
}
});
app.controller('ContabilidadCtrl', function ($routeParams, $location, $scope, $filter, $http, $rootScope, $sessionStorage, $parse, Upload, $timeout, ngDialog, $window) {
$scope.principal = $rootScope.cat_principal;
$scope.Listusuarios = $rootScope.cat_users;
$scope.Listproductos = $rootScope.cat_productos;
$scope.Listagencias = $rootScope.cat_Da;
$scope.ListCausas = $rootScope.cat_causas;
$scope.picFiles = [];
$scope.archivosnuevos = [];
$scope.notas = [];
for (var i=0; i<$scope.principal.length; i++) {
if ($scope.principal[i].folio == $routeParams.folio) {
$scope.contabilidad = angular.copy($scope.principal[i]);
$scope.contabilidad.importe = parseFloat($scope.contabilidad.importe);
$scope.contabilidad.tipocambio = parseFloat($scope.contabilidad.tipocambio);
$scope.contabilidad.fecha_contacto = new Date($scope.contabilidad.fecha_contacto);
$scope.contabilidad.fechasuspension = new Date($scope.contabilidad.fechasuspension);
$scope.contabilidad.fechadescarte = new Date($scope.contabilidad.fechadescarte);
$scope.contabilidad.fecha_id_dp = $scope.contabilidad.fecha_id_dp !== null ? new Date($scope.contabilidad.fecha_id_dp) : undefined ;
$scope.contabilidad.fecha_id_recuperacion = $scope.contabilidad.fecha_id_recuperacion !== null ? new Date($scope.contabilidad.fecha_id_recuperacion) : undefined ;
$scope.contabilidad.carta = $scope.contabilidad.carta != 1 ? false : true;
$scope.contabilidad.identificacion = $scope.contabilidad.identificacion != 1 ? false : true;
$scope.contabilidad.evidenciapago = $scope.contabilidad.evidenciapago != 1 ? false : true;
$scope.contabilidad.cedula = $scope.contabilidad.cedula != 1 ? false : true;
$scope.contabilidad.deposito = $scope.contabilidad.deposito != 1 ? false : true;
$scope.contabilidad.transferencia = $scope.contabilidad.transferencia != 1 ? false : true;
$scope.contabilidad.comisiones = $scope.contabilidad.comisiones != 1 ? false : true;
$scope.contabilidad.fianza = $scope.contabilidad.fianza != 1 ? false : true;
}}
// TRAEMOS LOS ARCHIVOS PARA MOSTRARLOS
$scope.contabilidad.tk = $sessionStorage.userLocal.tk;
$http.post('/rest/traer_nombres_archivos', $scope.contabilidad)
.success(function (data, status, headers, config) {
if(status >= 200)
{
$scope.picFiles = data;
$http.post('/rest/traer_notas', $scope.contabilidad)
.success(function (data, status, headers, config) {
if(status >= 200)
{
$scope.notas = data;
$scope.apply;
}}
);
}}
);
$scope.checklist = function(contabilidad){
ngDialog.openConfirm({
template: 'formarecup',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'ContabilidadCtrl',
width: '70%',
scope:$scope,
}).then({
});
}
$scope.notas = function(){
ngDialog.openConfirm({
template: 'notas',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'AtencionEspCtrl',
width: '70%',
scope:$scope,
}).then({
});
}
//----------------------------------------------------------------------------------------------------------
$scope.uploadFiles = function (files, errFiles) {
if (files.length>0) {
for (var cont=0; cont< files.length; cont++)
{
$scope.picFiles.push({bucketkey:'na', filename:files[cont].name});
}
$scope.archivosnuevos.push(files);
//$scope.archivosnuevos=files;
}
}
//----------------------------------------------------------------------------------------------------------
$scope.EditarContabilidad = function(optSelected){
if (!optSelected.fecha_id_dp)
{
optSelected.fecha_id_dp = null;
}
if (!optSelected.fecha_id_recuperacion)
{
optSelected.fecha_id_recuperacion = null;
}
if (!optSelected.estatuscontabilidad)
{
optSelected.estatuscontabilidad = null;
}
if (!optSelected.numero_id_dp)
{
optSelected.numero_id_dp = null;
}
optSelected.id_usuario = $sessionStorage.userLocal.id_user;
optSelected.fecha_id_dp = $filter('date')(optSelected.fecha_id_dp,'yyyy-MM-dd');
optSelected.fecha_id_recuperacion = $filter('date')(optSelected.fecha_id_recuperacion,'yyyy-MM-dd');
optSelected.usuario_asignado = $scope.contabilidad.usuario_asignado
optSelected.cua = $scope.contabilidad.cua
optSelected.nombre_agente = $scope.contabilidad.nombre_agente
switch (optSelected.estatuscontabilidad) {
case 'RECIBIDO':
optSelected.estatuscontabilidad = '1';
break;
case 'ACLARACION':
optSelected.estatuscontabilidad = '2';
break;
case 'ATENDIDO':
optSelected.estatuscontabilidad = '3';
break;
}
console.log(optSelected)
$http.post('/rest/update_contabilidad', optSelected)
.success(function (data, status, headers, config) {
if(status >= 500){
console.log("ocurrió un error")
$scope.preloader = false;
ngDialog.openConfirm({
template: 'errDialog',
className: 'ngdialog-theme-default',
width: '55%'
}).then(function () {
console.log("ok")
$location.path('/');
$window.location.reload();
}
)}
else{
if ($scope.archivosnuevos.length > 0) {
for (var cont=0; cont<$scope.archivosnuevos.length; cont++)
{
angular.forEach($scope.archivosnuevos[cont], function (file) {
file.upload = Upload.upload({
url: 'rest/upload_files',
data: {
folio: data.folio,
archivos: file
}
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
$scope.result2 = true;
console.log(response.data);
altaAlert();
$scope.picFiles = "";
$timeout(function () {
//$rootScope.$apply();
//$window.history.back();
//$window.location.reload();//recarga la pagina
//mostrarPrincipal();
$location.path('/contabilidad');
}, 2000);
});
});
});
}
//----------------------------------------------------------------------------------
}
else {
console.log("no hay archivos adjuntos")
altaAlert();
$timeout(function () {
//$rootScope.$apply();
$scope.picFiles = "";
//mostrarPrincipal();
$location.path('/contabilidad');
//$window.location.reload();//recarga la pagina
}, 2000);
}
}
})
}
});
app.controller('PrevensionCtrl', function ($routeParams, $location, $scope, $filter, $q, $http, $rootScope, $sessionStorage, $parse, Upload, $timeout, ngDialog, $window) {
function devuelveIniciales(iniciales){
var arregloDeSubCadenas = iniciales.split(" ");
var subCadena = "";
var x;
for (x=0;x= 200)
{
$scope.picFiles = data;
$http.post('/rest/traer_notas', $scope.prevension)
.success(function (data, status, headers, config) {
if(status >= 200)
{
$scope.notas = data;
$scope.apply;
}}
);
}}
);
$scope.recuperacion = function(prevension){
$scope.nuevarec = [];
$scope.nuevarec.poliza = $scope.prevension.poliza;
ngDialog.openConfirm({
template: 'formarecup',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'PrevensionCtrl',
width: '82%',
scope:$scope,
}).then({
});
}
$scope.agregarrecuperacion = function(nuevo) {
// if (!nuevo)
// {
// obligatorios(': Skill');
// $window.document.getElementById('skill').focus();
// return;
// }
// if (!nuevo.skill)
// {
// obligatorios(': Skill');
// $window.document.getElementById('skill').focus();
// return;
// }
// if (!nuevo.canal)
// {
// obligatorios(': Canal');
// $window.document.getElementById('canal').focus();
// return;
// }
// if (!nuevo.fecha_alta)
// {
// obligatorios(': Fecha del Perfil');
// $window.document.getElementById('fecha_alta').focus();
// return;
// }
$scope.recuperacionesprev.push({fecha_recuperacion:$filter('date')(nuevo.fecha_recuperacion, 'yyyy-MM-dd', '+05'),
folio_dictamen: nuevo.folio_dictamen, poliza: nuevo.poliza ,montorecuperado: nuevo.montorecuperado,
montoirrecuperable: nuevo.montoirrecuperable, observaciones: nuevo.observaciones});
nuevo.folio_dictamen = '';
nuevo.montorecuperado = '';
nuevo.montoirrecuperable = ''
nuevo.fecha_recuperacion = '';
nuevo.observaciones = '';
};
$scope.notas = function(){
ngDialog.openConfirm({
template: 'notas',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'AtencionEspCtrl',
width: '70%',
scope:$scope,
}).then({
});
}
//----------------------------------------------------------------------------------------------------------
$scope.uploadFiles = function (files, errFiles) {
if (files.length>0) {
for (var cont=0; cont< files.length; cont++)
{
$scope.picFiles.push({bucketkey:'na', filename:files[cont].name});
}
$scope.archivosnuevos.push(files);
//$scope.archivosnuevos=files;
}
}
//----------------------------------------------------------------------------------------------------------
$scope.EditarPrevension = function(optSelected) {
// if (!optSelected.fecha_pago_fianza)
// {
// obligatorios('Fecha de Pago de la fianza');
// $window.document.getElementById('fecha_pago_fianza').focus();
// return;
// }
if (!optSelected.fecha_descarte_juridico)
{
optSelected.fecha_descarte_juridico = null;
}
if (!optSelected.fecha_solicitud_fianza)
{
optSelected.fecha_solicitud_fianza = null;
}
if (!optSelected.fecha_pago_fianza)
{
optSelected.fecha_pago_fianza = null;
}
optSelected.id_usuario = $sessionStorage.userLocal.id_user;
optSelected.fecha_pago_fianza = $filter('date')(optSelected.fecha_pago_fianza,'yyyy-MM-dd');
optSelected.fecha_descarte_juridico = $filter('date')(optSelected.fecha_descarte_juridico,'yyyy-MM-dd');
optSelected.fecha_solicitud_fianza = $filter('date')(optSelected.fecha_solicitud_fianza,'yyyy-MM-dd');
switch (optSelected.estatusprevension) {
case 'RECIBIDO':
optSelected.estatusprevension = '1';
break;
case 'RECUPERADO':
optSelected.estatusprevension = '2';
break;
case 'DESCARTE A JURIDICO':
optSelected.estatusprevension = '3';
break;
case 'DEVUELTO':
optSelected.estatusprevension = '4';
break;
}
$window.document.getElementById('botonguardar').disabled = true;
var deferred = $q.defer();
if ($scope.recuperacionesprev.length > 0){
for (var cont=0; cont<$scope.recuperacionesprev.length; cont++)
{
if(!$scope.recuperacionesprev[cont].fecha_recuperacion)
{
$scope.recuperacionesprev[cont].fecha_recuperacion = null;
}
if(!$scope.recuperacionesprev[cont].montorecuperado)
{
$scope.recuperacionesprev[cont].montorecuperado = null;
}
if(!$scope.recuperacionesprev[cont].montoirrecuperable)
{
$scope.recuperacionesprev[cont].montoirrecuperable = null;
}
if(!$scope.recuperacionesprev[cont].observaciones)
{
$scope.recuperacionesprev[cont].observaciones = null;
}
if(!$scope.recuperacionesprev[cont].folio_dictamen)
{
$scope.recuperacionesprev[cont].folio_dictamen = 0;
}
$scope.recuperacionesprev[cont].agente = optSelected.nombre_agente;
$scope.recuperacionesprev[cont].cua = optSelected.cua;
$http.post('/rest/insert_rec_prev', $scope.recuperacionesprev[cont])
.success(function (data, status, headers, config) {
deferred.resolve();
return deferred.promise;
});
}}
$http.post('/rest/update_prevension', optSelected)
.success(function (data, status, headers, config) {
if(status >= 500){
console.log("ocurrió un error")
$scope.preloader = false;
ngDialog.openConfirm({
template: 'errDialog',
className: 'ngdialog-theme-default',
width: '55%'
}).then(function () {
console.log("ok")
$location.path('/');
$window.location.reload();
$window.document.getElementById('botonguardar').disabled = false;
}
)}
else{
if ($scope.archivosnuevos.length > 0) {
for (var cont=0; cont<$scope.archivosnuevos.length; cont++)
{
angular.forEach($scope.archivosnuevos[cont], function (file) {
file.upload = Upload.upload({
url: 'rest/upload_files',
data: {
folio: data.folio,
archivos: file
}
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
$scope.result2 = true;
$window.document.getElementById('botonguardar').disabled = false;
altaAlert();
$scope.picFiles = "";
$timeout(function () {
//$rootScope.$apply();
//$window.history.back();
//$window.location.reload();//recarga la pagina
//mostrarPrincipal();
$window.document.getElementById('botonguardar').disabled = false;
$location.path('/prevision');
}, 2000);
});
});
});
}
//----------------------------------------------------------------------------------
}
else {
console.log("no hay archivos adjuntos")
altaAlert();
$timeout(function () {
//$rootScope.$apply();
$scope.picFiles = "";
$window.document.getElementById('botonguardar').disabled = false;
$location.path('/prevision');
//$window.location.reload();//recarga la pagina
}, 2000);
}
}
})
}
});
app.controller('JuridicoCtrl', function ($routeParams, $location, $scope, $filter, $q,$http, $rootScope, $sessionStorage, $parse, Upload, $timeout, ngDialog, $window) {
$scope.principal = $rootScope.cat_principal;
$scope.Listusuarios = $rootScope.cat_users;
$scope.Listproductos = $rootScope.cat_productos;
$scope.Listagencias = $rootScope.cat_Da;
$scope.ListCausas = $rootScope.cat_causas;
$scope.picFiles = [];
$scope.archivosnuevos = [];
$scope.notas = [];
$scope.recuperacionesjur = [];
for (var i=0; i<$scope.menujuridico.length; i++) {
if ($scope.menujuridico[i].cua == $routeParams.cua) {
$scope.juridico = angular.copy($scope.menujuridico[i]);
$scope.juridico.importe = parseFloat($scope.juridico.importe);
$scope.juridico.tipocambio = parseFloat($scope.juridico.tipocambio);
$scope.juridico.fecha_descarte_juridico = $scope.juridico.fecha_descarte_juridico !== null ? new Date($scope.juridico.fecha_descarte_juridico) : undefined ;
$scope.juridico.fecha_pago_fianza = $scope.juridico.fecha_pago_fianza !== null ? new Date($scope.juridico.fecha_pago_fianza) : undefined ;
$scope.juridico.fechadescarte = new Date($scope.juridico.fechadescarte);
$scope.juridico.fecha_id_dp = $scope.juridico.fecha_id_dp !== null ? new Date($scope.juridico.fecha_id_dp) : undefined ;
$scope.juridico.fecha_recuperacion = $scope.juridico.fecha_recuperacion !== null ? new Date($scope.juridico.fecha_recuperacion) : undefined ;
$scope.juridico.carta = $scope.juridico.carta != 1 ? false : true;
$scope.juridico.identificacion = $scope.juridico.identificacion != 1 ? false : true;
$scope.juridico.evidenciapago = $scope.juridico.evidenciapago != 1 ? false : true;
$scope.juridico.cedula = $scope.juridico.cedula != 1 ? false : true;
$scope.juridico.deposito = $scope.juridico.deposito != 1 ? false : true;
$scope.juridico.transferencia = $scope.juridico.transferencia != 1 ? false : true;
$scope.juridico.comisiones = $scope.juridico.comisiones != 1 ? false : true;
$scope.juridico.fianza = $scope.juridico.fianza != 1 ? false : true;
$scope.juridico.checkdictamen = $scope.juridico.folio_dictamen != null ? true : false;
$scope.juridico.checknota = $scope.juridico.folio_nota != null ? true : false;
$scope.juridico.fecha_denuncia = $scope.juridico.fecha_denuncia !== null ? new Date($scope.juridico.fecha_denuncia) : undefined ;
$scope.juridico.fecha_cita_ratificacion = $scope.juridico.fecha_cita_ratificacion !== null ? new Date($scope.juridico.fecha_cita_ratificacion) : undefined ;
$scope.juridico.fecha_sello_ult_dictamen = $scope.juridico.fecha_sello_ult_dictamen !== null ? new Date($scope.juridico.fecha_sello_ult_dictamen) : undefined ;
$scope.juridico.fecha_revocacion_cedula = $scope.juridico.fecha_revocacion_cedula !== null ? new Date($scope.juridico.fecha_revocacion_cedula) : undefined ;
// TRAEMOS LAS RECUPERACIONES DEL CASO
$http.post('/rest/traerecuperacionesjur', $scope.juridico)
.success(function(data, status, headers, config) {
$scope.recuperacionesjur = data;
});
}}
if($scope.juridico.prevensionmontodeposito){
$scope.juridico.prevensiondeposito = true;
}
if($scope.juridico.prevensionmontocomisiones){
$scope.juridico.prevensioncomisiones = true;
}
if($scope.juridico.prevensionmontofianza){
$scope.juridico.prevensionfianza = true;
}
// TRAEMOS LOS ARCHIVOS PARA MOSTRARLOS
$scope.juridico.tk = $sessionStorage.userLocal.tk;
$http.post('/rest/traer_nombres_archivoscua', $scope.juridico)
.success(function (data, status, headers, config) {
if(status >= 200)
{
$scope.picFiles = data;
}}
);
$scope.agregarrecuperacion = function(nuevo) {
if (!nuevo)
{
obligatorios(': Fecha de Recuperacion');
return;
}
if (!nuevo.fecha_recuperacion)
{
obligatorios(': Fecha de Recuperacion');
return;
}
if (!nuevo.montorecuperado)
{
obligatorios(': Monto Recuperado');
// $window.document.getElementById('skill').focus();
return;
}
if (!nuevo.descripcion)
{
nuevo.descripcion = ' ';
}
if (!nuevo.tiporecuperacion)
{
obligatorios(': Tipo de Recuperacion');
// $window.document.getElementById('fecha_alta').focus();
return;
}
$scope.recuperacionesjur.push({folio_dictamen: nuevo.folio_dictamen,fecha_recuperacion:$filter('date')(nuevo.fecha_recuperacion, 'yyyy-MM-dd', '+05'), montorecuperado: nuevo.montorecuperado, tiporecuperacion: nuevo.tiporecuperacion, descripcion: nuevo.descripcion, cua: $scope.juridico.cua});
//$rootScope.perfilesusuario.push({id_usuario: 0,skill: nuevo.skill, canal: nuevo.canal , fecha_alta: $filter('date')(nuevo.fecha_alta, 'yyyy-MM-dd', '+05') })
nuevo.fecha_recuperacion = '';
nuevo.folio_dictamen = '';
nuevo.montorecuperado = '';
nuevo.descripcion = '';
nuevo.tiporecuperacion = '';
nuevo.cua = ''
};
$scope.gridpolizas = function(gridpoliza){
ngDialog.openConfirm({
template: 'gridpolizas',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'JuridicoCtrl',
width: '70%',
scope:$scope,
}).then({
});
}
$scope.recuperacion = function(juridico){
$scope.nuevarec = [];
$scope.nuevarec.folio_dictamen = $scope.juridico.folio_dictamen;
ngDialog.openConfirm({
template: 'formarecup',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'JuridicoCtrl',
width: '70%',
scope:$scope,
}).then({
});
}
$scope.notas = function(){
ngDialog.openConfirm({
template: 'notas',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'JuridicoCtrl',
width: '70%',
scope:$scope,
}).then({
});
}
//----------------------------------------------------------------------------------------------------------
$scope.uploadFiles = function (files, errFiles) {
if (files.length>0) {
for (var cont=0; cont< files.length; cont++)
{
$scope.picFiles.push({bucketkey:'na', filename:files[cont].name});
}
$scope.archivosnuevos.push(files);
//$scope.archivosnuevos=files;
}
}
//----------------------------------------------------------------------------------------------------------
$scope.EditarJuridico = function(optSelected) {
if (!optSelected.fecha_descarte_juridico)
{
optSelected.fecha_descarte_juridico = null;
}
if (!optSelected.fecha_recuperacion)
{
optSelected.fecha_recuperacion = null;
}
if (!optSelected.fecha_sello_ult_dictamen)
{
optSelected.fecha_sello_ult_dictamen = null;
}
if (!optSelected.fecha_denuncia)
{
optSelected.fecha_denuncia = null;
}
if (!optSelected.fecha_cita_ratificacion)
{
optSelected.fecha_cita_ratificacion = null;
}
if (!optSelected.fecha_revocacion_cedula)
{
optSelected.fecha_revocacion_cedula = null;
}
optSelected.id_usuario = $sessionStorage.userLocal.id_user;
optSelected.fecha_descarte_juridico = $filter('date')(optSelected.fecha_descarte_juridico,'yyyy-MM-dd','UTC');
optSelected.fecha_recuperacion = $filter('date')(optSelected.fecha_recuperacion,'yyyy-MM-dd','UTC');
optSelected.fecha_sello_ult_dictamen = $filter('date')(optSelected.fecha_sello_ult_dictamen,'yyyy-MM-dd','UTC');
optSelected.fecha_denuncia = $filter('date')(optSelected.fecha_denuncia,'yyyy-MM-dd','UTC');
optSelected.fecha_cita_ratificacion = $filter('date')(optSelected.fecha_cita_ratificacion,'yyyy-MM-dd','UTC');
optSelected.fecha_revocacion_cedula = $filter('date')(optSelected.fecha_revocacion_cedula,'yyyy-MM-dd','UTC');
if(!optSelected.motivo_rechazo){
optSelected.motivo_rechazo = '';
}
if(!optSelected.motivo_devolucion_correccion){
optSelected.motivo_devolucion_correccion = '';
}
if(!optSelected.importe_recuperacion){
optSelected.importe_recuperacion = 0;
}
if(!optSelected.estatusjuridico){
optSelected.estatusjuridico = 'RECIBIDO';
}
switch (optSelected.estatusjuridico) {
case 'RECIBIDO':
optSelected.estatusjuridico = '1';
break;
case 'ACTIVADO':
optSelected.estatusjuridico = '2';
break;
case 'RECHAZADO':
optSelected.estatusjuridico = '3';
break;
}
var deferred = $q.defer();
if ($scope.recuperacionesjur.length > 0){
for (var cont=0; cont<$scope.recuperacionesjur.length; cont++)
{
if (!$scope.recuperacionesjur[cont].agente)
{
$scope.recuperacionesjur[cont].agente = null;
}
$scope.recuperacionesjur[cont].agente = optSelected.agente;
if(!$scope.recuperacionesjur[cont].fecha_recuperacion)
{
$scope.recuperacionesjur[cont].fecha_recuperacion = null;
}
if(!$scope.recuperacionesjur[cont].montorecuperado)
{
$scope.recuperacionesjur[cont].montorecuperado = null;
}
if(!$scope.recuperacionesjur[cont].descripcion)
{
$scope.recuperacionesjur[cont].descripcion = ' ';
}
if(!$scope.recuperacionesjur[cont].tiporecuperacion)
{
$scope.recuperacionesjur[cont].tiporecuperacion = 0;
}
$http.post('/rest/insert_rec_jur', $scope.recuperacionesjur[cont])
.success(function (data, status, headers, config) {
deferred.resolve();
return deferred.promise;
});
}}
console.log(optSelected)
$http.post('/rest/update_juridico', optSelected)
.success(function (data, status, headers, config) {
if(status >= 500){
console.log("ocurrió un error")
$scope.preloader = false;
ngDialog.openConfirm({
template: 'errDialog',
className: 'ngdialog-theme-default',
width: '55%'
}).then(function () {
console.log("ok")
$location.path('/');
$window.location.reload();
}
)}
else{
if ($scope.archivosnuevos.length > 0) {
// altaAlert();
// $timeout(function () {
// //$rootScope.$apply();
// $scope.picFiles = "";
// //mostrarPrincipal();
// $location.path('/juridico');
// //$window.location.reload();//recarga la pagina
// }, 2000);
for (var cont=0; cont<$scope.archivosnuevos.length; cont++)
{
$scope.archivosnuevos[cont].folio = $scope.juridico.cua;
angular.forEach($scope.archivosnuevos[cont], function (file) {
file.upload = Upload.upload({
url: 'rest/upload_filescua',
data: {
folio: data.cua,
archivos: file
}
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
$scope.result2 = true;
altaAlert();
$scope.picFiles = "";
$timeout(function () {
//$rootScope.$apply();
//$window.history.back();
//$window.location.reload();//recarga la pagina
//mostrarPrincipal();
$location.path('/juridico');
}, 2000);
});
});
});
}
//----------------------------------------------------------------------------------
}
else {
console.log("no hay archivos adjuntos")
altaAlert();
$timeout(function () {
//$rootScope.$apply();
$scope.picFiles = "";
//mostrarPrincipal();
$location.path('/juridico');
//$window.location.reload();//recarga la pagina
}, 2000);
}
}
})
}
});
app.controller('RecuperacionesCtrl', function ($routeParams, $location, $scope, $filter, $q, $http, $rootScope, $sessionStorage, $parse, Upload, $timeout, ngDialog, $window) {
$scope.principal = $rootScope.cat_principal;
$scope.Listusuarios = $rootScope.cat_users;
$scope.ListAgentes = $rootScope.agentes;
$scope.picFiles = [];
$scope.archivosnuevos = [];
$scope.notas = [];
$scope.agenteseleccionado = '';
$scope.recuperacionesjur = [];
$scope.recuperacionesprev = [];
$scope.verdocumentos = function(rec){
// TRAEMOS LOS ARCHIVOS PARA MOSTRARLOS
rec.tk = $sessionStorage.userLocal.tk;
$http.post('/rest/traer_nombres_archivoscua', rec)
.success(function (data, status, headers, config) {
if(status >= 200)
{
$scope.picFiles = data;
}}
);
// $scope.nuevarec = [];
// $scope.nuevarec.poliza = $scope.prevension.poliza;
ngDialog.openConfirm({
template: 'verdocs',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'RecuperacionesCtrl',
width: '76%',
scope:$scope,
}).then({
});
}
$scope.buscarec = function(agente) {
// TRAEMOS LAS RECUPERACIONES DE JURIDICO
$scope.buscar = angular.copy($scope.agente);
var deferred = $q.defer();
$http.post('/rest/vistarecjur', $scope.buscar)
.success(function(data, status, headers, config) {
for (var cont=0; cont= 200)
{
$scope.picFiles = data;
}}
);
$scope.checklist = function(ventas){
ngDialog.openConfirm({
template: 'formarecup',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'ContabilidadCtrl',
width: '70%',
scope:$scope,
}).then({
});
}
$scope.notas = function(){
ngDialog.openConfirm({
template: 'notas',
plain: false,
closeByDocument: false,
className: 'ngdialog-theme-default',
controllerAs: 'AtencionEspCtrl',
width: '70%',
scope:$scope,
}).then({
});
}
//----------------------------------------------------------------------------------------------------------
$scope.uploadFiles = function (files, errFiles) {
if (files.length>0) {
for (var cont=0; cont< files.length; cont++)
{
$scope.picFiles.push({bucketkey:'na', filename:files[cont].name});
}
$scope.archivosnuevos.push(files);
//$scope.archivosnuevos=files;
}
}
//----------------------------------------------------------------------------------------------------------
$scope.GuardarVentas = function(optSelected) {
optSelected.id_usuario = $sessionStorage.userLocal.id_user;
optSelected.fecha_carga_cartera = $filter('date')(optSelected.fecha_carga_cartera,'yyyy-MM-dd');
optSelected.fecha_notificacion_cambio_cartera = $filter('date')(optSelected.fecha_notificacion_cambio_cartera,'yyyy-MM-dd');
optSelected.fecha_cambio_cartera = $filter('date')(optSelected.fecha_cambio_cartera,'yyyy-MM-dd');
if (!optSelected.fecha_carga_cartera)
{optSelected.fecha_carga_cartera = null;}
if (!optSelected.fecha_notificacion_cambio_cartera)
{optSelected.fecha_notificacion_cambio_cartera = null;}
if (!optSelected.fecha_cambio_cartera)
{optSelected.fecha_cambio_cartera = null;}
if (!optSelected.clave_puente_da)
{optSelected.clave_puente_da = null;}
if (!optSelected.clave_directa_dp)
{optSelected.clave_directa_dp = null;}
if (!optSelected.traspaso_agente_asignado)
{optSelected.traspaso_agente_asignado = null;}
if (!optSelected.traspaso_peticion)
{optSelected.traspaso_peticion = null;}
if (!optSelected.polizas_no_suceptibles)
{optSelected.polizas_no_suceptibles = null;}
if (!optSelected.total_cartera)
{optSelected.total_cartera = null;}
//DESHABILITAMOS EL BOTON DE ACEPTAR
$window.document.getElementById('botonguardar').disabled = true;
$scope.estadoboton = 'Guardando';
$http.post('/rest/update_ventas', optSelected)
.success(function (data, status, headers, config) {
if(status >= 500){
console.log("ocurrió un error")
$scope.preloader = false;
ngDialog.openConfirm({
template: 'errDialog',
className: 'ngdialog-theme-default',
width: '55%'
}).then(function () {
$window.document.getElementById('botonguardar').disabled = false;
$scope.estadoboton = 'Guardar';
$location.path('/');
$window.location.reload();
}
)}
else{
//#
/* var deferred = $q.defer();
$http.post('/rest/limpia_cartera', $scope.ventas)
.success(function (data, status, headers, config) {
deferred.resolve();
}) */
$http.post('/rest/update_cartera', $scope.gridOptions.data)
.success(function (data, status, headers, config) {
})
$timeout(function () {
//$rootScope.$apply();
}, 10000);
if ($scope.archivosnuevos.length > 0) {
for (var cont=0; cont<$scope.archivosnuevos.length; cont++)
{
$scope.archivosnuevos[cont].folio = $scope.ventas.cua;
angular.forEach($scope.archivosnuevos[cont], function (file) {
file.upload = Upload.upload({
url: 'rest/upload_filescua',
data: {
folio: data.cua,
archivos: file
}
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
$scope.result2 = true;
altaAlert();
$scope.picFiles = "";
$window.document.getElementById('botonguardar').disabled = false;
$scope.estadoboton = 'Guardar';
$timeout(function () {
//$rootScope.$apply();
//$window.history.back();
//$window.location.reload();//recarga la pagina
//mostrarPrincipal();
$location.path('/ventas');
}, 2000);
});
});
});
}
//----------------------------------------------------------------------------------
}
else {
console.log("no hay archivos adjuntos")
altaAlert();
$timeout(function () {
//$rootScope.$apply();
$scope.picFiles = "";
$window.document.getElementById('botonguardar').disabled = false;
$scope.estadoboton = 'Guardar';
$location.path('/prevision');
//$window.location.reload();//recarga la pagina
}, 3000);
}
}
})
}
// ----- CODIGO PARA MANEJAR LOS ARCHIVOS DE EXCEL
$scope.gridOptions = {
exporterOlderExcelCompatibility: true,
enableRowSelection: true,
enableFullRowSelection: true,
columnDefs: [
{field: 'DA', width: '47'},
{field: 'CUA', width: '87'},
{field: 'POLIZA', width: '87'},
{field: 'RAMO', width: '87'},
{field: 'ERROR', width: '87'},
{field: 'FEMISION', width: '87'},
{field: 'FEINIPOL', width: '87'},
{field: 'FEFINPOL', width: '87'},
{field: 'PRIMA_TOTAL', width: '187'},
{field: 'FORMA_PAGO', width: '87'},
{field: 'NOMBRE_AGENTE', width: '287'},
{field: 'NOMBRE_ASEGURADO', width: '287'},
{field: 'FUNCIONARIO', width: '287'},
{field: 'OBSERVACIONES', width: '387'},
],
enableGridMenu: true,
enableSelectAll: true,
exporterMenuExcel: true,
exporterMenupdf: false,
exporterExcelFilename: 'myFile.xlsx',
exporterExcelSheetName: 'Sheet1',
enableFiltering: true,
showHeader: true,
onRegisterApi: function(gridApi){
$scope.gridApi = gridApi;
},
/* SheetJS Service setup */
data: $scope.polizas,
filename: "SheetJSAngular",
sheetname: "ng-SheetJS"
};
$scope.SelectFile = function (File) {
$scope.SelectedFile = File;
};
$scope.CargaExcel = function () {
var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.xls|.xlsx)$/;
if (regex.test($scope.SelectedFile.name.toLowerCase())) {
if (typeof (FileReader) != "undefined") {
var reader = new FileReader();
//For Browsers other than IE.
if (reader.readAsBinaryString) {
reader.onload = function (e) {
$scope.ProcessExcel(e.target.result);
};
$scope.gridOptions.data = $scope.polizas;
reader.readAsBinaryString($scope.SelectedFile);
} else {
//For IE Browser.
reader.onload = function (e) {
var data = "";
var bytes = new Uint8Array(e.target.result);
for (var i = 0; i < bytes.byteLength; i++) {
data += String.fromCharCode(bytes[i]);
}
$scope.ProcessExcel(data);
$scope.gridOptions.data = $scope.polizas;
};
reader.readAsArrayBuffer($scope.SelectedFile);
}
} else {
$window.alert("This browser does not support HTML5.");
}
} else {
$window.alert("Please upload a valid Excel file.");
}
$scope.gridOptions.data = $scope.polizas;
// RELLENAMOS CON NULL SI NO HAY COLUMNAS
for (var i = 0; i < $scope.gridOptions.data.length; i++) {
if (!$scope.gridOptions.data[i].DA)
{
$scope.polizas[i].DA = null;
}
if (!$scope.gridOptions.data[i].CUA)
{
$scope.polizas[i].CUA = null;
}
if (!$scope.gridOptions.data[i].POLIZA)
{
$scope.polizas[i].POLIZA = null;
}
if (!$scope.gridOptions.data[i].RAMO)
{
$scope.polizas[i].RAMO = null;
}
if (!$scope.gridOptions.data[i].ERROR)
{
$scope.polizas[i].ERROR = null;
}
if (!$scope.gridOptions.data[i].FEMISION)
{
$scope.polizas[i].FEMISION = null;
}
if (!$scope.gridOptions.data[i].FEINIPOL)
{
$scope.polizas[i].FEINIPOL = null;
}
if (!$scope.gridOptions.data[i].FEFINPOL)
{
$scope.polizas[i].FEFINPOL = null;
}
if (!$scope.gridOptions.data[i].PRIMA_TOTAL)
{
$scope.polizas[i].PRIMA_TOTAL = null;
}
if (!$scope.gridOptions.data[i].FORMA_PAGO)
{
$scope.polizas[i].FORMA_PAGO = null;
}
if (!$scope.gridOptions.data[i].NOMBRE_AGENTE)
{
$scope.polizas[i].NOMBREAGENTE = null;
}
if (!$scope.gridOptions.data[i].NOMBRE_ASEGURADO)
{
$scope.polizas[i].NOMBRE_ASEGURADO = null;
}
if (!$scope.gridOptions.data[i].FUNCIONARIO)
{
$scope.polizas[i].FUNCIONARIO = null;
}
if (!$scope.gridOptions.data[i].OBSERVACIONES)
{
$scope.polizas[i].OBSERVACIONES = null;
}
}
};
$scope.ProcessExcel = function (data) {
//Read the Excel File data.
var workbook = XLSX.read(data, {
type: 'binary'
});
//Fetch the name of First Sheet.
var firstSheet = workbook.SheetNames[0];
//Read all rows from First Sheet into an JSON array.
var excelRows = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[firstSheet],
{header:0 , raw: true});
//Display the data from Excel file in Table.
$scope.$apply(function () {
$scope.polizas = excelRows;
$scope.IsVisible = true;
console.log($scope.polizas);
});
};
});
// NOTIFICACIONES
app.controller('NotificacionesCtrl', function ($routeParams, $location, $scope, $filter, $http, $rootScope, $sessionStorage, $parse, Upload, $timeout, ngDialog, $window) {
$scope.Listusuarios = $rootScope.cat_users;
// // TRAEMOS LAS NOTIFICACIONES
// $http.post('/rest/traer_notificaciones', $scope.ventas)
// .success(function (data, status, headers, config) {
// $scope.polizas = data;
// $scope.gridOptions.data = $scope.polizas
// })
// ----- CODIGO PARA MANEJAR LOS ARCHIVOS DE EXCEL
$scope.gridOptions = {
enableHorizontalScrollbar: 2,
enableRowSelection: true,
enableFullRowSelection: true,
columnDefs: [
{field: 'DA'},
{field: 'CUA'},
{field: 'POLIZA'},
{field: 'RAMO'},
{field: 'ERROR'},
{field: 'FEMISION'},
{field: 'FEINIPOL'},
{field: 'FEFINPOL'},
{field: 'PRIMA_TOTAL'},
{field: 'FORMA_PAGO'},
{field: 'NOMBRE_AGENTE'},
{field: 'NOMBRE_ASEGURADO'},
{field: 'FUNCIONARIO'},
{field: 'OBSERVACIONES'},
],
enableGridMenu: true,
enableSelectAll: true,
exporterMenuExcel: true,
exporterMenupdf: false,
exporterExcelFilename: 'myFile.xlsx',
exporterExcelSheetName: 'Sheet1',
enableFiltering: true,
showHeader: true,
minimumColumnSize: 950,
onRegisterApi: function(gridApi){
$scope.gridApi = gridApi;
},
/* SheetJS Service setup */
data: $scope.polizas,
filename: "SheetJSAngular",
sheetname: "ng-SheetJS"
};
$scope.SelectFile = function (File) {
$scope.SelectedFile = File;
};
$scope.CargaExcel = function () {
var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.xls|.xlsx)$/;
if (regex.test($scope.SelectedFile.name.toLowerCase())) {
if (typeof (FileReader) != "undefined") {
var reader = new FileReader();
//For Browsers other than IE.
if (reader.readAsBinaryString) {
reader.onload = function (e) {
$scope.ProcessExcel(e.target.result);
};
$scope.gridOptions.data = $scope.polizas;
reader.readAsBinaryString($scope.SelectedFile);
} else {
//For IE Browser.
reader.onload = function (e) {
var data = "";
var bytes = new Uint8Array(e.target.result);
for (var i = 0; i < bytes.byteLength; i++) {
data += String.fromCharCode(bytes[i]);
}
$scope.ProcessExcel(data);
$scope.gridOptions.data = $scope.polizas;
};
reader.readAsArrayBuffer($scope.SelectedFile);
}
} else {
$window.alert("This browser does not support HTML5.");
}
} else {
$window.alert("Please upload a valid Excel file.");
}
$scope.gridOptions.data = $scope.polizas;
};
$scope.ProcessExcel = function (data) {
//Read the Excel File data.
var workbook = XLSX.read(data, {
type: 'binary'
});
//Fetch the name of First Sheet.
var firstSheet = workbook.SheetNames[0];
//Read all rows from First Sheet into an JSON array.
var excelRows = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[firstSheet]);
//Display the data from Excel file in Table.
$scope.$apply(function () {
$scope.polizas = excelRows;
$scope.IsVisible = true;
console.log($scope.polizas);
});
};
});
//DA
app.controller('adminDaCtrl', function ($scope, $rootScope, $log, $http, $routeParams, $location, $route, ngDialog, $timeout, $window) {
$scope.da = $rootScope.cat_Da;
});
app.controller('editUserCtrl', function ($scope, $rootScope, $log, $http, $routeParams, $location, $route) {
$scope.catPerfiles = $rootScope.cat_perfiles;
$scope.catDirecciones = $rootScope.cat_direcc;
$scope.catPuestos = $rootScope.cat_puestos;
$scope.catAspectos = $rootScope.cat_aspectos;
for (var i = 0; i < $rootScope.cat_users.length; i++) {
if ($rootScope.cat_users[i].id_usuario == $routeParams.id_usuario) {
$scope.user = angular.copy($rootScope.cat_users[i]);
}
}
console.log($scope.user)
$scope.submitUpdate = function () {
console.log($scope.user)
$http.post('/rest/update_user', $scope.user)
.success(function (data, status, headers, config) {
for (var i = 0; i < $rootScope.cat_users.length; i++) {
if ($rootScope.cat_users[i].id_usuario == $scope.user.id_usuario) {
$rootScope.cat_users.splice(i, 1);
break;
}
}
$rootScope.cat_users.push(data);
updateUserSuccess();
});
$location.path('/admin_usr');
};
});