Commit 0728456c47fbb5dc9b0e719e0a3867e4f4a44cb0
1 parent
7fe99e5f3f
Exists in
develop
Fix
Para no mostrar listas duplicadas
Showing
1 changed file
with
9 additions
and
2 deletions
Show diff stats
src/js/controller.js
| 1 | angular.module('focaModalPrecioCondicion') | 1 | angular.module('focaModalPrecioCondicion') |
| 2 | .controller('focaModalPrecioCondicionController', | 2 | .controller('focaModalPrecioCondicionController', |
| 3 | [ | 3 | [ |
| 4 | '$timeout', | 4 | '$timeout', |
| 5 | '$filter', | 5 | '$filter', |
| 6 | '$scope', | 6 | '$scope', |
| 7 | '$uibModal', | 7 | '$uibModal', |
| 8 | '$uibModalInstance', | 8 | '$uibModalInstance', |
| 9 | 'focaModalService', | 9 | 'focaModalService', |
| 10 | 'focaModalPrecioCondicionService', | 10 | 'focaModalPrecioCondicionService', |
| 11 | 'parametros', | 11 | 'parametros', |
| 12 | function ( | 12 | function ( |
| 13 | $timeout, $filter, $scope, $uibModal, $uibModalInstance, | 13 | $timeout, $filter, $scope, $uibModal, $uibModalInstance, |
| 14 | focaModalService, focaModalPrecioCondicionService, parametros | 14 | focaModalService, focaModalPrecioCondicionService, parametros |
| 15 | ) { | 15 | ) { |
| 16 | $scope.plazos = [ | 16 | $scope.plazos = [ |
| 17 | { | 17 | { |
| 18 | dias: 0, | 18 | dias: 0, |
| 19 | idCliente: parametros.idCliente, | 19 | idCliente: parametros.idCliente, |
| 20 | activo: true | 20 | activo: true |
| 21 | } | 21 | } |
| 22 | ]; | 22 | ]; |
| 23 | $scope.remito = parametros.remito; | 23 | $scope.remito = parametros.remito; |
| 24 | $scope.notaPedido = parametros.notaPedido; | 24 | $scope.notaPedido = parametros.notaPedido; |
| 25 | $scope.openModalListaDePrecios = false; | 25 | $scope.openModalListaDePrecios = false; |
| 26 | $scope.associatedList = true; | 26 | $scope.associatedList = true; |
| 27 | $scope.listaDePreciosAlternativa = null; | 27 | $scope.listaDePreciosAlternativa = null; |
| 28 | 28 | ||
| 29 | onInit(); | 29 | onInit(); |
| 30 | 30 | ||
| 31 | function onInit() { | 31 | function onInit() { |
| 32 | //Metodo para traer la lista de precio asociada al cliente | 32 | //Metodo para traer la lista de precio asociada al cliente |
| 33 | focaModalPrecioCondicionService.getListaPrecio(parametros.idListaPrecio) | 33 | focaModalPrecioCondicionService.getListaPrecio(parametros.idListaPrecio) |
| 34 | .then(function (res) { | 34 | .then(function (res) { |
| 35 | $scope.listaDePreciosAsociada = res.data[0]; | 35 | $scope.listaDePreciosAsociada = res.data[0]; |
| 36 | }) | 36 | }) |
| 37 | .catch(function (e) { console.error(e) }); | 37 | .catch(function (e) { console.error(e) }); |
| 38 | focaModalPrecioCondicionService.getPlazosByIdCliente(parametros.idCliente) | 38 | focaModalPrecioCondicionService.getPlazosByIdCliente(parametros.idCliente) |
| 39 | .then(function (res) { | 39 | .then(function (res) { |
| 40 | res.data.forEach(function (item) { | 40 | res.data.forEach(function (item) { |
| 41 | $scope.plazos.push(item); | 41 | $scope.plazos.push(item); |
| 42 | }); | 42 | }); |
| 43 | }) | 43 | }) |
| 44 | .catch(function (e) { console.error(e) }); | 44 | .catch(function (e) { console.error(e) }); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | //#region Metodos para la lista de precios | 47 | //#region Metodos para la lista de precios |
| 48 | $scope.openListaDePrecios = function () { | 48 | $scope.openListaDePrecios = function () { |
| 49 | var datos = null; | 49 | var datos = []; |
| 50 | focaModalPrecioCondicionService.getAllListaPrecio() | 50 | focaModalPrecioCondicionService.getAllListaPrecio() |
| 51 | .then(function (res) { | 51 | .then(function (res) { |
| 52 | datos = res.data; | 52 | datos = res.data.reduce(function (acc, current) { |
| 53 | var x = acc.find(function (item) { return item.ID === current.ID }); | ||
| 54 | if (!x) { | ||
| 55 | return acc.concat([current]); | ||
| 56 | } else { | ||
| 57 | return acc; | ||
| 58 | } | ||
| 59 | }, []); | ||
| 53 | focaModalService.modal({ | 60 | focaModalService.modal({ |
| 54 | titulo: 'Lista de precios', | 61 | titulo: 'Lista de precios', |
| 55 | data: datos, | 62 | data: datos, |
| 56 | size: 'md', | 63 | size: 'md', |
| 57 | columnas: [ | 64 | columnas: [ |
| 58 | { | 65 | { |
| 59 | propiedad: 'ID', | 66 | propiedad: 'ID', |
| 60 | nombre: 'Codigo' | 67 | nombre: 'Codigo' |
| 61 | }, | 68 | }, |
| 62 | { | 69 | { |
| 63 | propiedad: 'DES', | 70 | propiedad: 'DES', |
| 64 | NOMBRE: 'Nombre' | 71 | NOMBRE: 'Nombre' |
| 65 | } | 72 | } |
| 66 | ], | 73 | ], |
| 67 | }).then(function (res) { | 74 | }).then(function (res) { |
| 68 | focaModalService.confirm('¿Desea cambiar la lista de precios?\n'+ | 75 | focaModalService.confirm('¿Desea cambiar la lista de precios?\n'+ |
| 69 | 'Se perderan los productos ingresados').then(function (data){ | 76 | 'Se perderan los productos ingresados').then(function (data){ |
| 70 | if (data) { | 77 | if (data) { |
| 71 | if ($scope.notaPedido) { | 78 | if ($scope.notaPedido) { |
| 72 | if ($scope.notaPedido.articulosNotaPedido.length > 0) { | 79 | if ($scope.notaPedido.articulosNotaPedido.length > 0) { |
| 73 | $scope.notaPedido.articulosNotaPedido = []; | 80 | $scope.notaPedido.articulosNotaPedido = []; |
| 74 | } | 81 | } |
| 75 | } else if ($scope.remito) { | 82 | } else if ($scope.remito) { |
| 76 | if ($scope.remito.articulosRemito.length > 0) { | 83 | if ($scope.remito.articulosRemito.length > 0) { |
| 77 | $scope.remito.articulosRemito = []; | 84 | $scope.remito.articulosRemito = []; |
| 78 | } | 85 | } |
| 79 | } | 86 | } |
| 80 | $scope.associatedList = false; | 87 | $scope.associatedList = false; |
| 81 | $scope.listaDePreciosAlternativa = res; | 88 | $scope.listaDePreciosAlternativa = res; |
| 82 | } | 89 | } |
| 83 | }); | 90 | }); |
| 84 | }).catch(function (e) { | 91 | }).catch(function (e) { |
| 85 | console.error(e); | 92 | console.error(e); |
| 86 | }); | 93 | }); |
| 87 | }); | 94 | }); |
| 88 | }; | 95 | }; |
| 89 | $scope.selectListaDePrecios = function () { | 96 | $scope.selectListaDePrecios = function () { |
| 90 | $scope.associatedList = true; | 97 | $scope.associatedList = true; |
| 91 | }; | 98 | }; |
| 92 | $scope.verListaProductos = function (id) { | 99 | $scope.verListaProductos = function (id) { |
| 93 | $uibModal.open( | 100 | $uibModal.open( |
| 94 | { | 101 | { |
| 95 | ariaLabelledBy: 'Busqueda de Productos', | 102 | ariaLabelledBy: 'Busqueda de Productos', |
| 96 | templateUrl: 'modal-busqueda-productos.html', | 103 | templateUrl: 'modal-busqueda-productos.html', |
| 97 | controller: 'modalBusquedaProductosCtrl', | 104 | controller: 'modalBusquedaProductosCtrl', |
| 98 | resolve: { | 105 | resolve: { |
| 99 | parametroProducto: { | 106 | parametroProducto: { |
| 100 | idLista: parseInt(id), | 107 | idLista: parseInt(id), |
| 101 | cotizacion: 1, | 108 | cotizacion: 1, |
| 102 | simbolo: '$', | 109 | simbolo: '$', |
| 103 | soloMostrar: true | 110 | soloMostrar: true |
| 104 | } | 111 | } |
| 105 | }, | 112 | }, |
| 106 | size: 'md' | 113 | size: 'md' |
| 107 | } | 114 | } |
| 108 | ); | 115 | ); |
| 109 | }; | 116 | }; |
| 110 | //#endregion | 117 | //#endregion |
| 111 | 118 | ||
| 112 | //#region Metodos para los plazos | 119 | //#region Metodos para los plazos |
| 113 | $scope.addPlazo = function (key) { | 120 | $scope.addPlazo = function (key) { |
| 114 | if (key != 13) return; | 121 | if (key != 13) return; |
| 115 | if ($scope.plazos.length === 100) return; | 122 | if ($scope.plazos.length === 100) return; |
| 116 | for (var i = 1; i < $scope.plazos.length; i++) { | 123 | for (var i = 1; i < $scope.plazos.length; i++) { |
| 117 | if ($scope.plazos[0].dias == $scope.plazos[i].dias && $scope.plazos[i].activo == true) { | 124 | if ($scope.plazos[0].dias == $scope.plazos[i].dias && $scope.plazos[i].activo == true) { |
| 118 | focaModalService.alert("Ya existe un plazo con este valor"); | 125 | focaModalService.alert("Ya existe un plazo con este valor"); |
| 119 | return; | 126 | return; |
| 120 | } | 127 | } |
| 121 | } | 128 | } |
| 122 | $scope.plazos.unshift({ dias: 0, idCliente: parametros.idCliente, activo: true }); | 129 | $scope.plazos.unshift({ dias: 0, idCliente: parametros.idCliente, activo: true }); |
| 123 | $scope.focused = 1; | 130 | $scope.focused = 1; |
| 124 | }; | 131 | }; |
| 125 | $scope.deletePlazo = function (index) { | 132 | $scope.deletePlazo = function (index) { |
| 126 | $scope.plazos[index].activo = false; | 133 | $scope.plazos[index].activo = false; |
| 127 | }; | 134 | }; |
| 128 | $scope.validateMinMax = function (plazo, min, max) { | 135 | $scope.validateMinMax = function (plazo, min, max) { |
| 129 | plazo.dias = parseInt(plazo.dias); | 136 | plazo.dias = parseInt(plazo.dias); |
| 130 | if (plazo.dias === null || plazo.dias === undefined || isNaN(plazo.dias)) { | 137 | if (plazo.dias === null || plazo.dias === undefined || isNaN(plazo.dias)) { |
| 131 | plazo.dias = '0'; | 138 | plazo.dias = '0'; |
| 132 | return; | 139 | return; |
| 133 | } | 140 | } |
| 134 | if (parseInt(plazo.dias) < min) { | 141 | if (parseInt(plazo.dias) < min) { |
| 135 | plazo.dias = '0'; | 142 | plazo.dias = '0'; |
| 136 | return; | 143 | return; |
| 137 | } | 144 | } |
| 138 | if (parseInt(plazo.dias) > max) { | 145 | if (parseInt(plazo.dias) > max) { |
| 139 | plazo.dias = '365'; | 146 | plazo.dias = '365'; |
| 140 | return; | 147 | return; |
| 141 | } | 148 | } |
| 142 | }; | 149 | }; |
| 143 | //#endregion | 150 | //#endregion |
| 144 | 151 | ||
| 145 | $scope.closeModalPrecioCondicion = function () { | 152 | $scope.closeModalPrecioCondicion = function () { |
| 146 | $uibModalInstance.dismiss('cancel'); | 153 | $uibModalInstance.dismiss('cancel'); |
| 147 | }; | 154 | }; |
| 148 | $scope.guardarPrecioCondicion = function () { | 155 | $scope.guardarPrecioCondicion = function () { |
| 149 | $scope.plazos.shift(); | 156 | $scope.plazos.shift(); |
| 150 | focaModalPrecioCondicionService.createPlazo($scope.plazos) | 157 | focaModalPrecioCondicionService.createPlazo($scope.plazos) |
| 151 | .then(function () { | 158 | .then(function () { |
| 152 | var precioCondicion = { | 159 | var precioCondicion = { |
| 153 | listaPrecio: $scope.associatedList ? $scope.listaDePreciosAsociada : $scope.listaDePreciosAlternativa, | 160 | listaPrecio: $scope.associatedList ? $scope.listaDePreciosAsociada : $scope.listaDePreciosAlternativa, |
| 154 | plazoPago: $filter('filter')($scope.plazos, { activo: true }, true) | 161 | plazoPago: $filter('filter')($scope.plazos, { activo: true }, true) |
| 155 | }; | 162 | }; |
| 156 | $uibModalInstance.close(precioCondicion); | 163 | $uibModalInstance.close(precioCondicion); |
| 157 | }) | 164 | }) |
| 158 | .catch(function (e) { console.error(e) }) | 165 | .catch(function (e) { console.error(e) }) |
| 159 | }; | 166 | }; |
| 160 | } | 167 | } |
| 161 | ]); | 168 | ]); |
| 162 | 169 |