Commit 973c0baf3b331c026d771fae6fe1cc5b1e838229
1 parent
3c53f4cc0e
Exists in
master
and in
1 other branch
correcciones jshint
Showing
1 changed file
with
7 additions
and
4 deletions
Show diff stats
src/js/controller.js
| 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
| 2 | [ | 2 | [ |
| 3 | '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService', | 3 | '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService', |
| 4 | 'focaModalService', 'notaPedidoBusinessService', '$rootScope', 'focaSeguimientoService', | 4 | 'focaModalService', 'notaPedidoBusinessService', '$rootScope', 'focaSeguimientoService', |
| 5 | function( | 5 | function( |
| 6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, | 6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, |
| 7 | notaPedidoBusinessService, $rootScope, focaSeguimientoService) | 7 | notaPedidoBusinessService, $rootScope, focaSeguimientoService) |
| 8 | { | 8 | { |
| 9 | 9 | ||
| 10 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 10 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
| 11 | 11 | ||
| 12 | $scope.isNumber = angular.isNumber; | 12 | $scope.isNumber = angular.isNumber; |
| 13 | $scope.datepickerAbierto = false; | 13 | $scope.datepickerAbierto = false; |
| 14 | $scope.show = false; | 14 | $scope.show = false; |
| 15 | $scope.cargando = true; | 15 | $scope.cargando = true; |
| 16 | $scope.dateOptions = { | 16 | $scope.dateOptions = { |
| 17 | maxDate: new Date(), | 17 | maxDate: new Date(), |
| 18 | minDate: new Date(2010, 0, 1) | 18 | minDate: new Date(2010, 0, 1) |
| 19 | }; | 19 | }; |
| 20 | 20 | ||
| 21 | $scope.notaPedido = { | 21 | $scope.notaPedido = { |
| 22 | id: 0, | 22 | id: 0, |
| 23 | vendedor: {}, | 23 | vendedor: {}, |
| 24 | cliente: {}, | 24 | cliente: {}, |
| 25 | proveedor: {}, | 25 | proveedor: {}, |
| 26 | domicilio: {dom: ''}, | 26 | domicilio: {dom: ''}, |
| 27 | moneda: {}, | 27 | moneda: {}, |
| 28 | cotizacion: {} | 28 | cotizacion: {} |
| 29 | }; | 29 | }; |
| 30 | var monedaPorDefecto; | 30 | var monedaPorDefecto; |
| 31 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 31 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
| 32 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | 32 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
| 33 | monedaPorDefecto = res.data[0]; | 33 | monedaPorDefecto = res.data[0]; |
| 34 | $scope.notaPedido.moneda = monedaPorDefecto; | 34 | $scope.notaPedido.moneda = monedaPorDefecto; |
| 35 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; | 35 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; |
| 36 | }); | 36 | }); |
| 37 | 37 | ||
| 38 | $scope.cabecera = []; | 38 | $scope.cabecera = []; |
| 39 | $scope.showCabecera = true; | 39 | $scope.showCabecera = true; |
| 40 | 40 | ||
| 41 | $scope.now = new Date(); | 41 | $scope.now = new Date(); |
| 42 | $scope.puntoVenta = '0000'; | 42 | $scope.puntoVenta = '0000'; |
| 43 | $scope.comprobante = '00000000'; | 43 | $scope.comprobante = '00000000'; |
| 44 | $scope.articulosTabla = []; | 44 | $scope.articulosTabla = []; |
| 45 | $scope.idLista = undefined; | 45 | $scope.idLista = undefined; |
| 46 | 46 | ||
| 47 | crearNotaPedidoService.getPrecioCondicion().then( | 47 | crearNotaPedidoService.getPrecioCondicion().then( |
| 48 | function(res) { | 48 | function(res) { |
| 49 | $scope.precioCondiciones = res.data; | 49 | $scope.precioCondiciones = res.data; |
| 50 | } | 50 | } |
| 51 | ); | 51 | ); |
| 52 | 52 | ||
| 53 | crearNotaPedidoService.getNumeroNotaPedido().then( | 53 | crearNotaPedidoService.getNumeroNotaPedido().then( |
| 54 | function(res) { | 54 | function(res) { |
| 55 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 55 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
| 56 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 56 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
| 57 | }, | 57 | }, |
| 58 | function(err) { | 58 | function(err) { |
| 59 | focaModalService.alert('La terminal no esta configurada correctamente'); | 59 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 60 | console.info(err); | 60 | console.info(err); |
| 61 | } | 61 | } |
| 62 | ); | 62 | ); |
| 63 | 63 | ||
| 64 | $scope.crearNotaPedido = function() { | 64 | $scope.crearNotaPedido = function() { |
| 65 | if(!$scope.notaPedido.vendedor.CodVen) { | 65 | if(!$scope.notaPedido.vendedor.CodVen) { |
| 66 | focaModalService.alert('Ingrese Vendedor'); | 66 | focaModalService.alert('Ingrese Vendedor'); |
| 67 | return; | 67 | return; |
| 68 | } else if(!$scope.notaPedido.cliente.COD) { | 68 | } else if(!$scope.notaPedido.cliente.COD) { |
| 69 | focaModalService.alert('Ingrese Cliente'); | 69 | focaModalService.alert('Ingrese Cliente'); |
| 70 | return; | 70 | return; |
| 71 | } else if(!$scope.notaPedido.proveedor.COD) { | 71 | } else if(!$scope.notaPedido.proveedor.COD) { |
| 72 | focaModalService.alert('Ingrese Proveedor'); | 72 | focaModalService.alert('Ingrese Proveedor'); |
| 73 | return; | 73 | return; |
| 74 | } else if(!$scope.notaPedido.moneda.ID) { | 74 | } else if(!$scope.notaPedido.moneda.ID) { |
| 75 | focaModalService.alert('Ingrese Moneda'); | 75 | focaModalService.alert('Ingrese Moneda'); |
| 76 | return; | 76 | return; |
| 77 | } else if(!$scope.notaPedido.cotizacion.ID) { | 77 | } else if(!$scope.notaPedido.cotizacion.ID) { |
| 78 | focaModalService.alert('Ingrese Cotización'); | 78 | focaModalService.alert('Ingrese Cotización'); |
| 79 | return; | 79 | return; |
| 80 | } else if(!$scope.plazosPagos) { | 80 | } else if(!$scope.plazosPagos) { |
| 81 | focaModalService.alert('Ingrese Precios y Condiciones'); | 81 | focaModalService.alert('Ingrese Precios y Condiciones'); |
| 82 | return; | 82 | return; |
| 83 | } else if( | 83 | } else if( |
| 84 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 84 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
| 85 | { | 85 | { |
| 86 | focaModalService.alert('Ingrese Flete'); | 86 | focaModalService.alert('Ingrese Flete'); |
| 87 | return; | 87 | return; |
| 88 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 88 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
| 89 | focaModalService.alert('Ingrese Domicilio'); | 89 | focaModalService.alert('Ingrese Domicilio'); |
| 90 | return; | 90 | return; |
| 91 | } else if($scope.articulosTabla.length === 0) { | 91 | } else if($scope.articulosTabla.length === 0) { |
| 92 | focaModalService.alert('Debe cargar al menos un articulo'); | 92 | focaModalService.alert('Debe cargar al menos un articulo'); |
| 93 | return; | 93 | return; |
| 94 | } | 94 | } |
| 95 | $scope.saveLoading = true; | 95 | $scope.saveLoading = true; |
| 96 | var notaPedido = { | 96 | var notaPedido = { |
| 97 | id: $scope.notaPedido.id, | 97 | id: $scope.notaPedido.id, |
| 98 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | 98 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
| 99 | idVendedor: $scope.notaPedido.vendedor.CodVen, | 99 | idVendedor: $scope.notaPedido.vendedor.CodVen, |
| 100 | idCliente: $scope.notaPedido.cliente.COD, | 100 | idCliente: $scope.notaPedido.cliente.COD, |
| 101 | nombreCliente: $scope.notaPedido.cliente.NOM, | 101 | nombreCliente: $scope.notaPedido.cliente.NOM, |
| 102 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 102 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
| 103 | idProveedor: $scope.notaPedido.proveedor.COD, | 103 | idProveedor: $scope.notaPedido.proveedor.COD, |
| 104 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID | 104 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID |
| 105 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 105 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
| 106 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 106 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
| 107 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 107 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 108 | flete: $scope.notaPedido.flete, | 108 | flete: $scope.notaPedido.flete, |
| 109 | fob: $scope.notaPedido.fob, | 109 | fob: $scope.notaPedido.fob, |
| 110 | bomba: $scope.notaPedido.bomba, | 110 | bomba: $scope.notaPedido.bomba, |
| 111 | kilometros: $scope.notaPedido.kilometros, | 111 | kilometros: $scope.notaPedido.kilometros, |
| 112 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 112 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
| 113 | estado: 0, | 113 | estado: 0, |
| 114 | total: $scope.getTotal() | 114 | total: $scope.getTotal() |
| 115 | }; | 115 | }; |
| 116 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 116 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
| 117 | function(data) { | 117 | function(data) { |
| 118 | // Al guardar los datos de la nota de pedido logueamos la | 118 | // Al guardar los datos de la nota de pedido logueamos la |
| 119 | // actividad para su seguimiento. | 119 | // actividad para su seguimiento. |
| 120 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 120 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
| 121 | focaSeguimientoService.guardarPosicion( | 121 | focaSeguimientoService.guardarPosicion( |
| 122 | data.data.id, | 122 | data.data.id, |
| 123 | 'Nota de pedido', | 123 | 'Nota de pedido', |
| 124 | 'Nº: ' + $filter('comprobante')([ | 124 | 'Nº: ' + $filter('comprobante')([ |
| 125 | $scope.puntoVenta, | 125 | $scope.puntoVenta, |
| 126 | $scope.comprobante | 126 | $scope.comprobante |
| 127 | ]) + '<br/>' + | 127 | ]) + '<br/>' + |
| 128 | 'Vendedor: ' + $scope.notaPedido.vendedor.NomVen + '<br/>' + | 128 | 'Vendedor: ' + $scope.notaPedido.vendedor.NomVen + '<br/>' + |
| 129 | 'Total: ' + $filter('currency')($scope.getTotal()) | 129 | 'Total: ' + $filter('currency')($scope.getTotal()) |
| 130 | ); | 130 | ); |
| 131 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | 131 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, |
| 132 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 132 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
| 133 | var plazos = $scope.plazosPagos; | 133 | var plazos = $scope.plazosPagos; |
| 134 | 134 | ||
| 135 | for(var j = 0; j < plazos.length; j++) { | 135 | for(var j = 0; j < plazos.length; j++) { |
| 136 | var json = { | 136 | var json = { |
| 137 | idPedido: data.data.id, | 137 | idPedido: data.data.id, |
| 138 | dias: plazos[j].dias | 138 | dias: plazos[j].dias |
| 139 | }; | 139 | }; |
| 140 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); | 140 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); |
| 141 | } | 141 | } |
| 142 | notaPedidoBusinessService.addEstado(data.data.id, | 142 | notaPedidoBusinessService.addEstado(data.data.id, |
| 143 | $scope.notaPedido.vendedor.CodVen); | 143 | $scope.notaPedido.vendedor.CodVen); |
| 144 | 144 | ||
| 145 | focaModalService.alert('Nota pedido creada'); | 145 | focaModalService.alert('Nota pedido creada'); |
| 146 | $scope.saveLoading = false; | 146 | $scope.saveLoading = false; |
| 147 | $scope.cabecera = []; | 147 | $scope.cabecera = []; |
| 148 | addCabecera('Moneda:', $scope.notaPedido.moneda.DETALLE); | 148 | addCabecera('Moneda:', $scope.notaPedido.moneda.DETALLE); |
| 149 | addCabecera( | 149 | addCabecera( |
| 150 | 'Fecha cotizacion:', | 150 | 'Fecha cotizacion:', |
| 151 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') | 151 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
| 152 | ); | 152 | ); |
| 153 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.VENDEDOR); | 153 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.VENDEDOR); |
| 154 | crearNotaPedidoService.getNumeroNotaPedido().then( | 154 | crearNotaPedidoService.getNumeroNotaPedido().then( |
| 155 | function(res) { | 155 | function(res) { |
| 156 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 156 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
| 157 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 157 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
| 158 | }, | 158 | }, |
| 159 | function(err) { | 159 | function(err) { |
| 160 | focaModalService.alert( | 160 | focaModalService.alert( |
| 161 | 'La terminal no esta configurada correctamente'); | 161 | 'La terminal no esta configurada correctamente'); |
| 162 | console.info(err); | 162 | console.info(err); |
| 163 | } | 163 | } |
| 164 | ); | 164 | ); |
| 165 | $scope.notaPedido.vendedor = {}; | 165 | $scope.notaPedido.vendedor = {}; |
| 166 | $scope.notaPedido.cliente = {}; | 166 | $scope.notaPedido.cliente = {}; |
| 167 | $scope.notaPedido.proveedor = {}; | 167 | $scope.notaPedido.proveedor = {}; |
| 168 | $scope.notaPedido.domicilio = {}; | 168 | $scope.notaPedido.domicilio = {}; |
| 169 | $scope.notaPedido.flete = null; | 169 | $scope.notaPedido.flete = null; |
| 170 | $scope.notaPedido.fob = null; | 170 | $scope.notaPedido.fob = null; |
| 171 | $scope.notaPedido.bomba = null; | 171 | $scope.notaPedido.bomba = null; |
| 172 | $scope.notaPedido.kilometros = null; | 172 | $scope.notaPedido.kilometros = null; |
| 173 | $scope.articulosTabla = []; | 173 | $scope.articulosTabla = []; |
| 174 | }, | 174 | }, |
| 175 | function(error) { | 175 | function(error) { |
| 176 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 176 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 177 | $scope.saveLoading = false; | 177 | $scope.saveLoading = false; |
| 178 | console.info(error); | 178 | console.info(error); |
| 179 | } | 179 | } |
| 180 | ); | 180 | ); |
| 181 | }; | 181 | }; |
| 182 | 182 | ||
| 183 | $scope.seleccionarNotaPedido = function() { | 183 | $scope.seleccionarNotaPedido = function() { |
| 184 | var modalInstance = $uibModal.open( | 184 | var modalInstance = $uibModal.open( |
| 185 | { | 185 | { |
| 186 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 186 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
| 187 | templateUrl: 'foca-modal-nota-pedido.html', | 187 | templateUrl: 'foca-modal-nota-pedido.html', |
| 188 | controller: 'focaModalNotaPedidoController', | 188 | controller: 'focaModalNotaPedidoController', |
| 189 | size: 'lg', | 189 | size: 'lg', |
| 190 | resolve: {usadoPor: function() {return 'notaPedido';}} | 190 | resolve: {usadoPor: function() {return 'notaPedido';}} |
| 191 | } | 191 | } |
| 192 | ); | 192 | ); |
| 193 | modalInstance.result.then( | 193 | modalInstance.result.then( |
| 194 | function(notaPedido) { | 194 | function(notaPedido) { |
| 195 | $scope.now = new Date(notaPedido.fechaCarga); | 195 | $scope.now = new Date(notaPedido.fechaCarga); |
| 196 | //añado cabeceras | 196 | //añado cabeceras |
| 197 | $scope.notaPedido.id = notaPedido.id; | 197 | $scope.notaPedido.id = notaPedido.id; |
| 198 | removeCabecera('Bomba:'); | 198 | removeCabecera('Bomba:'); |
| 199 | removeCabecera('Kilometros:'); | 199 | removeCabecera('Kilometros:'); |
| 200 | var cabeceras = [ | 200 | var cabeceras = [ |
| 201 | { | 201 | { |
| 202 | label: 'Moneda:', | 202 | label: 'Moneda:', |
| 203 | valor: notaPedido.cotizacion.moneda.DETALLE | 203 | valor: notaPedido.cotizacion.moneda.DETALLE |
| 204 | }, | 204 | }, |
| 205 | { | 205 | { |
| 206 | label: 'Fecha cotizacion:', | 206 | label: 'Fecha cotizacion:', |
| 207 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 207 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
| 208 | 'dd/MM/yyyy') | 208 | 'dd/MM/yyyy') |
| 209 | }, | 209 | }, |
| 210 | { | 210 | { |
| 211 | label: 'Cotizacion:', | 211 | label: 'Cotizacion:', |
| 212 | valor: notaPedido.cotizacion.VENDEDOR | 212 | valor: notaPedido.cotizacion.VENDEDOR |
| 213 | }, | 213 | }, |
| 214 | { | 214 | { |
| 215 | label: 'Cliente:', | 215 | label: 'Cliente:', |
| 216 | valor: notaPedido.cliente.NOM | 216 | valor: notaPedido.cliente.NOM |
| 217 | }, | 217 | }, |
| 218 | { | 218 | { |
| 219 | label: 'Domicilio:', | 219 | label: 'Domicilio:', |
| 220 | valor: notaPedido.domicilioStamp | 220 | valor: notaPedido.domicilioStamp |
| 221 | }, | 221 | }, |
| 222 | { | 222 | { |
| 223 | label: 'Vendedor:', | 223 | label: 'Vendedor:', |
| 224 | valor: notaPedido.vendedor.NomVen | 224 | valor: notaPedido.vendedor.NomVen |
| 225 | }, | 225 | }, |
| 226 | { | 226 | { |
| 227 | label: 'Proveedor:', | 227 | label: 'Proveedor:', |
| 228 | valor: notaPedido.proveedor.NOM | 228 | valor: notaPedido.proveedor.NOM |
| 229 | }, | 229 | }, |
| 230 | { | 230 | { |
| 231 | label: 'Precio condicion:', | 231 | label: 'Precio condicion:', |
| 232 | valor: valorPrecioCondicion() + ' ' + | 232 | valor: valorPrecioCondicion() + ' ' + |
| 233 | notaPedidoBusinessService | 233 | notaPedidoBusinessService |
| 234 | .plazoToString(notaPedido.notaPedidoPlazo) | 234 | .plazoToString(notaPedido.notaPedidoPlazo) |
| 235 | }, | 235 | }, |
| 236 | { | 236 | { |
| 237 | label: 'Flete:', | 237 | label: 'Flete:', |
| 238 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 238 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
| 239 | notaPedido.flete === 1 ? 'Si' : 'No') | 239 | notaPedido.flete === 1 ? 'Si' : 'No') |
| 240 | } | 240 | } |
| 241 | ]; | 241 | ]; |
| 242 | 242 | ||
| 243 | function valorPrecioCondicion() { | 243 | function valorPrecioCondicion() { |
| 244 | if(notaPedido.idPrecioCondicion > 0) { | 244 | if(notaPedido.idPrecioCondicion > 0) { |
| 245 | return notaPedido.precioCondicion.nombre; | 245 | return notaPedido.precioCondicion.nombre; |
| 246 | } else { | 246 | } else { |
| 247 | return 'Ingreso Manual'; | 247 | return 'Ingreso Manual'; |
| 248 | } | 248 | } |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | if(notaPedido.flete === 1) { | 251 | if(notaPedido.flete === 1) { |
| 252 | var cabeceraBomba = { | 252 | var cabeceraBomba = { |
| 253 | label: 'Bomba:', | 253 | label: 'Bomba:', |
| 254 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 254 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
| 255 | }; | 255 | }; |
| 256 | if(notaPedido.kilometros) { | 256 | if(notaPedido.kilometros) { |
| 257 | var cabeceraKilometros = { | 257 | var cabeceraKilometros = { |
| 258 | label: 'Kilometros:', | 258 | label: 'Kilometros:', |
| 259 | valor: notaPedido.kilometros | 259 | valor: notaPedido.kilometros |
| 260 | }; | 260 | }; |
| 261 | cabeceras.push(cabeceraKilometros); | 261 | cabeceras.push(cabeceraKilometros); |
| 262 | } | 262 | } |
| 263 | cabeceras.push(cabeceraBomba); | 263 | cabeceras.push(cabeceraBomba); |
| 264 | } | 264 | } |
| 265 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 265 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
| 266 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, | 266 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, |
| 267 | notaPedido.cotizacion.VENDEDOR); | 267 | notaPedido.cotizacion.VENDEDOR); |
| 268 | if(notaPedido.idPrecioCondicion > 0) { | 268 | if(notaPedido.idPrecioCondicion > 0) { |
| 269 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 269 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
| 270 | } else { | 270 | } else { |
| 271 | $scope.idLista = -1; | 271 | $scope.idLista = -1; |
| 272 | } | 272 | } |
| 273 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); | 273 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); |
| 274 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); | 274 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); |
| 275 | $scope.notaPedido = notaPedido; | 275 | $scope.notaPedido = notaPedido; |
| 276 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; | 276 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; |
| 277 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; | 277 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; |
| 278 | addArrayCabecera(cabeceras); | 278 | addArrayCabecera(cabeceras); |
| 279 | 279 | ||
| 280 | }, function() { | 280 | }, function() { |
| 281 | // funcion ejecutada cuando se cancela el modal | 281 | // funcion ejecutada cuando se cancela el modal |
| 282 | } | 282 | } |
| 283 | ); | 283 | ); |
| 284 | }; | 284 | }; |
| 285 | 285 | ||
| 286 | $scope.seleccionarProductos = function() { | 286 | $scope.seleccionarProductos = function() { |
| 287 | if ($scope.idLista === undefined) { | 287 | if ($scope.idLista === undefined) { |
| 288 | focaModalService.alert( | 288 | focaModalService.alert( |
| 289 | 'Primero seleccione una lista de precio y condicion'); | 289 | 'Primero seleccione una lista de precio y condicion'); |
| 290 | return; | 290 | return; |
| 291 | } | 291 | } |
| 292 | var modalInstance = $uibModal.open( | 292 | var modalInstance = $uibModal.open( |
| 293 | { | 293 | { |
| 294 | ariaLabelledBy: 'Busqueda de Productos', | 294 | ariaLabelledBy: 'Busqueda de Productos', |
| 295 | templateUrl: 'modal-busqueda-productos.html', | 295 | templateUrl: 'modal-busqueda-productos.html', |
| 296 | controller: 'modalBusquedaProductosCtrl', | 296 | controller: 'modalBusquedaProductosCtrl', |
| 297 | resolve: { | 297 | resolve: { |
| 298 | parametroProducto: { | 298 | parametroProducto: { |
| 299 | idLista: $scope.idLista, | 299 | idLista: $scope.idLista, |
| 300 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 300 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 301 | simbolo: $scope.notaPedido.moneda.SIMBOLO | 301 | simbolo: $scope.notaPedido.moneda.SIMBOLO |
| 302 | } | 302 | } |
| 303 | }, | 303 | }, |
| 304 | size: 'lg' | 304 | size: 'lg' |
| 305 | } | 305 | } |
| 306 | ); | 306 | ); |
| 307 | modalInstance.result.then( | 307 | modalInstance.result.then( |
| 308 | function(producto) { | 308 | function(producto) { |
| 309 | var newArt = | 309 | var newArt = |
| 310 | { | 310 | { |
| 311 | id: 0, | 311 | id: 0, |
| 312 | codigo: producto.codigo, | 312 | codigo: producto.codigo, |
| 313 | sector: producto.sector, | 313 | sector: producto.sector, |
| 314 | sectorCodigo: producto.sector + '-' + producto.codigo, | 314 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 315 | descripcion: producto.descripcion, | 315 | descripcion: producto.descripcion, |
| 316 | item: $scope.articulosTabla.length + 1, | 316 | item: $scope.articulosTabla.length + 1, |
| 317 | nombre: producto.descripcion, | 317 | nombre: producto.descripcion, |
| 318 | precio: parseFloat(producto.precio.toFixed(4)), | 318 | precio: parseFloat(producto.precio.toFixed(4)), |
| 319 | costoUnitario: producto.costo, | 319 | costoUnitario: producto.costo, |
| 320 | editCantidad: false, | 320 | editCantidad: false, |
| 321 | editPrecio: false, | 321 | editPrecio: false, |
| 322 | rubro: producto.CodRub, | 322 | rubro: producto.CodRub, |
| 323 | exentoUnitario: producto.precio, | 323 | exentoUnitario: producto.precio, |
| 324 | ivaUnitario: producto.IMPIVA, | 324 | ivaUnitario: producto.IMPIVA, |
| 325 | impuestoInternoUnitario: producto.ImpInt, | 325 | impuestoInternoUnitario: producto.ImpInt, |
| 326 | impuestoInterno1Unitario: producto.ImpInt2, | 326 | impuestoInterno1Unitario: producto.ImpInt2, |
| 327 | impuestoInterno2Unitario: producto.ImpInt3, | 327 | impuestoInterno2Unitario: producto.ImpInt3, |
| 328 | precioLista: producto.precio, | 328 | precioLista: producto.precio, |
| 329 | combustible: 1, | 329 | combustible: 1, |
| 330 | facturado: 0 | 330 | facturado: 0 |
| 331 | }; | 331 | }; |
| 332 | $scope.articuloACargar = newArt; | 332 | $scope.articuloACargar = newArt; |
| 333 | $scope.cargando = false; | 333 | $scope.cargando = false; |
| 334 | }, function() { | 334 | }, function() { |
| 335 | // funcion ejecutada cuando se cancela el modal | 335 | // funcion ejecutada cuando se cancela el modal |
| 336 | } | 336 | } |
| 337 | ); | 337 | ); |
| 338 | }; | 338 | }; |
| 339 | 339 | ||
| 340 | $scope.seleccionarVendedor = function() { | 340 | $scope.seleccionarVendedor = function() { |
| 341 | if(validarNotaRemitada()) { | 341 | if(validarNotaRemitada()) { |
| 342 | var modalInstance = $uibModal.open( | 342 | var modalInstance = $uibModal.open( |
| 343 | { | 343 | { |
| 344 | ariaLabelledBy: 'Busqueda de Vendedores', | 344 | ariaLabelledBy: 'Busqueda de Vendedores', |
| 345 | templateUrl: 'modal-vendedores.html', | 345 | templateUrl: 'modal-vendedores.html', |
| 346 | controller: 'modalVendedoresCtrl', | 346 | controller: 'modalVendedoresCtrl', |
| 347 | size: 'lg' | 347 | size: 'lg' |
| 348 | } | 348 | } |
| 349 | ); | 349 | ); |
| 350 | modalInstance.result.then( | 350 | modalInstance.result.then( |
| 351 | function(vendedor) { | 351 | function(vendedor) { |
| 352 | addCabecera('Vendedor:', vendedor.NomVen); | 352 | addCabecera('Vendedor:', vendedor.NomVen); |
| 353 | $scope.notaPedido.vendedor = vendedor; | 353 | $scope.notaPedido.vendedor = vendedor; |
| 354 | }, function() { | 354 | }, function() { |
| 355 | 355 | ||
| 356 | } | 356 | } |
| 357 | ); | 357 | ); |
| 358 | } | 358 | } |
| 359 | }; | 359 | }; |
| 360 | 360 | ||
| 361 | $scope.seleccionarProveedor = function() { | 361 | $scope.seleccionarProveedor = function() { |
| 362 | if(validarNotaRemitada()) { | 362 | if(validarNotaRemitada()) { |
| 363 | var modalInstance = $uibModal.open( | 363 | var modalInstance = $uibModal.open( |
| 364 | { | 364 | { |
| 365 | ariaLabelledBy: 'Busqueda de Proveedor', | 365 | ariaLabelledBy: 'Busqueda de Proveedor', |
| 366 | templateUrl: 'modal-proveedor.html', | 366 | templateUrl: 'modal-proveedor.html', |
| 367 | controller: 'focaModalProveedorCtrl', | 367 | controller: 'focaModalProveedorCtrl', |
| 368 | size: 'lg', | 368 | size: 'lg', |
| 369 | resolve: { | 369 | resolve: { |
| 370 | transportista: function() { | 370 | transportista: function() { |
| 371 | return false; | 371 | return false; |
| 372 | } | 372 | } |
| 373 | } | 373 | } |
| 374 | } | 374 | } |
| 375 | ); | 375 | ); |
| 376 | modalInstance.result.then( | 376 | modalInstance.result.then( |
| 377 | function(proveedor) { | 377 | function(proveedor) { |
| 378 | $scope.notaPedido.proveedor = proveedor; | 378 | $scope.notaPedido.proveedor = proveedor; |
| 379 | addCabecera('Proveedor:', proveedor.NOM); | 379 | addCabecera('Proveedor:', proveedor.NOM); |
| 380 | }, function() { | 380 | }, function() { |
| 381 | 381 | ||
| 382 | } | 382 | } |
| 383 | ); | 383 | ); |
| 384 | } | 384 | } |
| 385 | }; | 385 | }; |
| 386 | 386 | ||
| 387 | $scope.seleccionarCliente = function() { | 387 | $scope.seleccionarCliente = function() { |
| 388 | if(validarNotaRemitada()) { | 388 | if(validarNotaRemitada()) { |
| 389 | var modalInstance = $uibModal.open( | 389 | var modalInstance = $uibModal.open( |
| 390 | { | 390 | { |
| 391 | ariaLabelledBy: 'Busqueda de Cliente', | 391 | ariaLabelledBy: 'Busqueda de Cliente', |
| 392 | templateUrl: 'foca-busqueda-cliente-modal.html', | 392 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 393 | controller: 'focaBusquedaClienteModalController', | 393 | controller: 'focaBusquedaClienteModalController', |
| 394 | size: 'lg' | 394 | size: 'lg' |
| 395 | } | 395 | } |
| 396 | ); | 396 | ); |
| 397 | modalInstance.result.then( | 397 | modalInstance.result.then( |
| 398 | function(cliente) { | 398 | function(cliente) { |
| 399 | $scope.abrirModalDomicilios(cliente); | 399 | $scope.abrirModalDomicilios(cliente); |
| 400 | }, function() { | 400 | }, function() { |
| 401 | 401 | ||
| 402 | } | 402 | } |
| 403 | ); | 403 | ); |
| 404 | } | 404 | } |
| 405 | }; | 405 | }; |
| 406 | 406 | ||
| 407 | $scope.abrirModalDomicilios = function(cliente) { | 407 | $scope.abrirModalDomicilios = function(cliente) { |
| 408 | var modalInstanceDomicilio = $uibModal.open( | 408 | var modalInstanceDomicilio = $uibModal.open( |
| 409 | { | 409 | { |
| 410 | ariaLabelledBy: 'Busqueda de Domicilios', | 410 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 411 | templateUrl: 'modal-domicilio.html', | 411 | templateUrl: 'modal-domicilio.html', |
| 412 | controller: 'focaModalDomicilioController', | 412 | controller: 'focaModalDomicilioController', |
| 413 | resolve: { idCliente: function() { return cliente.cod; }}, | 413 | resolve: { idCliente: function() { return cliente.cod; }}, |
| 414 | size: 'lg', | 414 | size: 'lg', |
| 415 | } | 415 | } |
| 416 | ); | 416 | ); |
| 417 | modalInstanceDomicilio.result.then( | 417 | modalInstanceDomicilio.result.then( |
| 418 | function(domicilio) { | 418 | function(domicilio) { |
| 419 | $scope.notaPedido.domicilio = domicilio; | 419 | $scope.notaPedido.domicilio = domicilio; |
| 420 | $scope.notaPedido.cliente = { | 420 | $scope.notaPedido.cliente = { |
| 421 | COD: cliente.cod, | 421 | COD: cliente.cod, |
| 422 | CUIT: cliente.cuit, | 422 | CUIT: cliente.cuit, |
| 423 | NOM: cliente.nom | 423 | NOM: cliente.nom |
| 424 | }; | 424 | }; |
| 425 | addCabecera('Cliente:', cliente.nom); | 425 | addCabecera('Cliente:', cliente.nom); |
| 426 | var domicilioStamp = | 426 | var domicilioStamp = |
| 427 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 427 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
| 428 | domicilio.Localidad + ', ' + domicilio.Provincia; | 428 | domicilio.Localidad + ', ' + domicilio.Provincia; |
| 429 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 429 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
| 430 | addCabecera('Domicilio:', domicilioStamp); | 430 | addCabecera('Domicilio:', domicilioStamp); |
| 431 | }, function() { | 431 | }, function() { |
| 432 | $scope.seleccionarCliente(); | 432 | $scope.seleccionarCliente(); |
| 433 | return; | 433 | return; |
| 434 | } | 434 | } |
| 435 | ); | 435 | ); |
| 436 | }; | 436 | }; |
| 437 | 437 | ||
| 438 | $scope.getTotal = function() { | 438 | $scope.getTotal = function() { |
| 439 | var total = 0; | 439 | var total = 0; |
| 440 | var arrayTempArticulos = $scope.articulosTabla; | 440 | var arrayTempArticulos = $scope.articulosTabla; |
| 441 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 441 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 442 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 442 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 443 | } | 443 | } |
| 444 | return parseFloat(total.toFixed(2)); | 444 | return parseFloat(total.toFixed(2)); |
| 445 | }; | 445 | }; |
| 446 | 446 | ||
| 447 | $scope.getSubTotal = function() { | 447 | $scope.getSubTotal = function() { |
| 448 | if($scope.articuloACargar) { | 448 | if($scope.articuloACargar) { |
| 449 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 449 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 450 | } | 450 | } |
| 451 | }; | 451 | }; |
| 452 | 452 | ||
| 453 | $scope.seleccionarPreciosYCondiciones = function() { | 453 | $scope.seleccionarPreciosYCondiciones = function() { |
| 454 | if(validarNotaRemitada()) { | 454 | if(validarNotaRemitada()) { |
| 455 | var modalInstance = $uibModal.open( | 455 | var modalInstance = $uibModal.open( |
| 456 | { | 456 | { |
| 457 | ariaLabelledBy: 'Busqueda de Precio Condición', | 457 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 458 | templateUrl: 'modal-precio-condicion.html', | 458 | templateUrl: 'modal-precio-condicion.html', |
| 459 | controller: 'focaModalPrecioCondicionController', | 459 | controller: 'focaModalPrecioCondicionController', |
| 460 | size: 'lg' | 460 | size: 'lg' |
| 461 | } | 461 | } |
| 462 | ); | 462 | ); |
| 463 | modalInstance.result.then( | 463 | modalInstance.result.then( |
| 464 | function(precioCondicion) { | 464 | function(precioCondicion) { |
| 465 | var cabecera = ''; | 465 | var cabecera = ''; |
| 466 | var plazosConcat = ''; | 466 | var plazosConcat = ''; |
| 467 | if(!Array.isArray(precioCondicion)) { | 467 | if(!Array.isArray(precioCondicion)) { |
| 468 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 468 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
| 469 | $scope.plazosPagos = precioCondicion.plazoPago; | 469 | $scope.plazosPagos = precioCondicion.plazoPago; |
| 470 | $scope.idLista = precioCondicion.idListaPrecio; | 470 | $scope.idLista = precioCondicion.idListaPrecio; |
| 471 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 471 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 472 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 472 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
| 473 | } | 473 | } |
| 474 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 474 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
| 475 | } else { //Cuando se ingresan los plazos manualmente | 475 | } else { //Cuando se ingresan los plazos manualmente |
| 476 | $scope.notaPedido.idPrecioCondicion = 0; | 476 | $scope.notaPedido.idPrecioCondicion = 0; |
| 477 | $scope.idLista = -1; //-1, el modal productos busca todos los productos | 477 | //-1, el modal productos busca todos los productos |
| 478 | $scope.idLista = -1; | ||
| 478 | $scope.plazosPagos = precioCondicion; | 479 | $scope.plazosPagos = precioCondicion; |
| 479 | for(var j = 0; j < precioCondicion.length; j++) { | 480 | for(var j = 0; j < precioCondicion.length; j++) { |
| 480 | plazosConcat += precioCondicion[j].dias + ' '; | 481 | plazosConcat += precioCondicion[j].dias + ' '; |
| 481 | } | 482 | } |
| 482 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 483 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 483 | } | 484 | } |
| 484 | $scope.articulosTabla = []; | 485 | $scope.articulosTabla = []; |
| 485 | addCabecera('Precios y condiciones:', cabecera); | 486 | addCabecera('Precios y condiciones:', cabecera); |
| 486 | }, function() { | 487 | }, function() { |
| 487 | 488 | ||
| 488 | } | 489 | } |
| 489 | ); | 490 | ); |
| 490 | } | 491 | } |
| 491 | }; | 492 | }; |
| 492 | 493 | ||
| 493 | $scope.seleccionarFlete = function() { | 494 | $scope.seleccionarFlete = function() { |
| 494 | if(validarNotaRemitada()) { | 495 | if(validarNotaRemitada()) { |
| 495 | var modalInstance = $uibModal.open( | 496 | var modalInstance = $uibModal.open( |
| 496 | { | 497 | { |
| 497 | ariaLabelledBy: 'Busqueda de Flete', | 498 | ariaLabelledBy: 'Busqueda de Flete', |
| 498 | templateUrl: 'modal-flete.html', | 499 | templateUrl: 'modal-flete.html', |
| 499 | controller: 'focaModalFleteController', | 500 | controller: 'focaModalFleteController', |
| 500 | size: 'lg', | 501 | size: 'lg', |
| 501 | resolve: { | 502 | resolve: { |
| 502 | parametrosFlete: | 503 | parametrosFlete: |
| 503 | function() { | 504 | function() { |
| 504 | return { | 505 | return { |
| 505 | flete: $scope.notaPedido.fob ? 'FOB' : | 506 | flete: $scope.notaPedido.fob ? 'FOB' : |
| 506 | ( $scope.notaPedido.flete ? '1' : | 507 | ( $scope.notaPedido.flete ? '1' : |
| 507 | ($scope.notaPedido.flete === undefined ? null : '0')), | 508 | ($scope.notaPedido.flete === undefined ? |
| 509 | null : '0')), | ||
| 508 | bomba: $scope.notaPedido.bomba ? '1' : | 510 | bomba: $scope.notaPedido.bomba ? '1' : |
| 509 | ($scope.notaPedido.bomba === undefined ? null : '0'), | 511 | ($scope.notaPedido.bomba === undefined ? |
| 512 | null : '0'), | ||
| 510 | kilometros: $scope.notaPedido.kilometros | 513 | kilometros: $scope.notaPedido.kilometros |
| 511 | }; | 514 | }; |
| 512 | } | 515 | } |
| 513 | } | 516 | } |
| 514 | } | 517 | } |
| 515 | ); | 518 | ); |
| 516 | modalInstance.result.then( | 519 | modalInstance.result.then( |
| 517 | function(datos) { | 520 | function(datos) { |
| 518 | $scope.notaPedido.flete = datos.flete; | 521 | $scope.notaPedido.flete = datos.flete; |
| 519 | $scope.notaPedido.fob = datos.FOB; | 522 | $scope.notaPedido.fob = datos.FOB; |
| 520 | $scope.notaPedido.bomba = datos.bomba; | 523 | $scope.notaPedido.bomba = datos.bomba; |
| 521 | $scope.notaPedido.kilometros = datos.kilometros; | 524 | $scope.notaPedido.kilometros = datos.kilometros; |
| 522 | addCabecera('Flete:', datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No')); | 525 | addCabecera('Flete:', datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No')); |
| 523 | if(datos.flete) { | 526 | if(datos.flete) { |
| 524 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); | 527 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); |
| 525 | addCabecera('Kilometros:', datos.kilometros); | 528 | addCabecera('Kilometros:', datos.kilometros); |
| 526 | } else { | 529 | } else { |
| 527 | removeCabecera('Bomba:'); | 530 | removeCabecera('Bomba:'); |
| 528 | removeCabecera('Kilometros:'); | 531 | removeCabecera('Kilometros:'); |
| 529 | $scope.notaPedido.bomba = false; | 532 | $scope.notaPedido.bomba = false; |
| 530 | $scope.notaPedido.kilometros = null; | 533 | $scope.notaPedido.kilometros = null; |
| 531 | } | 534 | } |
| 532 | }, function() { | 535 | }, function() { |
| 533 | 536 | ||
| 534 | } | 537 | } |
| 535 | ); | 538 | ); |
| 536 | } | 539 | } |
| 537 | }; | 540 | }; |
| 538 | 541 | ||
| 539 | $scope.seleccionarMoneda = function() { | 542 | $scope.seleccionarMoneda = function() { |
| 540 | if(validarNotaRemitada()) { | 543 | if(validarNotaRemitada()) { |
| 541 | var modalInstance = $uibModal.open( | 544 | var modalInstance = $uibModal.open( |
| 542 | { | 545 | { |
| 543 | ariaLabelledBy: 'Busqueda de Moneda', | 546 | ariaLabelledBy: 'Busqueda de Moneda', |
| 544 | templateUrl: 'modal-moneda.html', | 547 | templateUrl: 'modal-moneda.html', |
| 545 | controller: 'focaModalMonedaController', | 548 | controller: 'focaModalMonedaController', |
| 546 | size: 'lg' | 549 | size: 'lg' |
| 547 | } | 550 | } |
| 548 | ); | 551 | ); |
| 549 | modalInstance.result.then( | 552 | modalInstance.result.then( |
| 550 | function(moneda) { | 553 | function(moneda) { |
| 551 | $scope.abrirModalCotizacion(moneda); | 554 | $scope.abrirModalCotizacion(moneda); |
| 552 | }, function() { | 555 | }, function() { |
| 553 | 556 | ||
| 554 | } | 557 | } |
| 555 | ); | 558 | ); |
| 556 | } | 559 | } |
| 557 | }; | 560 | }; |
| 558 | 561 | ||
| 559 | $scope.abrirModalCotizacion = function(moneda) { | 562 | $scope.abrirModalCotizacion = function(moneda) { |
| 560 | var modalInstance = $uibModal.open( | 563 | var modalInstance = $uibModal.open( |
| 561 | { | 564 | { |
| 562 | ariaLabelledBy: 'Busqueda de Cotización', | 565 | ariaLabelledBy: 'Busqueda de Cotización', |
| 563 | templateUrl: 'modal-cotizacion.html', | 566 | templateUrl: 'modal-cotizacion.html', |
| 564 | controller: 'focaModalCotizacionController', | 567 | controller: 'focaModalCotizacionController', |
| 565 | size: 'lg', | 568 | size: 'lg', |
| 566 | resolve: {idMoneda: function() {return moneda.ID;}} | 569 | resolve: {idMoneda: function() {return moneda.ID;}} |
| 567 | } | 570 | } |
| 568 | ); | 571 | ); |
| 569 | modalInstance.result.then( | 572 | modalInstance.result.then( |
| 570 | function(cotizacion) { | 573 | function(cotizacion) { |
| 571 | var articulosTablaTemp = $scope.articulosTabla; | 574 | var articulosTablaTemp = $scope.articulosTabla; |
| 572 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 575 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
| 573 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 576 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
| 574 | $scope.notaPedido.cotizacion.VENDEDOR; | 577 | $scope.notaPedido.cotizacion.VENDEDOR; |
| 575 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 578 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
| 576 | cotizacion.VENDEDOR; | 579 | cotizacion.VENDEDOR; |
| 577 | } | 580 | } |
| 578 | $scope.articulosTabla = articulosTablaTemp; | 581 | $scope.articulosTabla = articulosTablaTemp; |
| 579 | $scope.notaPedido.moneda = moneda; | 582 | $scope.notaPedido.moneda = moneda; |
| 580 | $scope.notaPedido.cotizacion = cotizacion; | 583 | $scope.notaPedido.cotizacion = cotizacion; |
| 581 | if(moneda.DETALLE == "PESOS ARGENTINOS"){ | 584 | if(moneda.DETALLE === 'PESOS ARGENTINOS'){ |
| 582 | removeCabecera('Moneda:'); | 585 | removeCabecera('Moneda:'); |
| 583 | removeCabecera('Fecha cotizacion:'); | 586 | removeCabecera('Fecha cotizacion:'); |
| 584 | removeCabecera('Cotizacion:'); | 587 | removeCabecera('Cotizacion:'); |
| 585 | }else{ | 588 | }else{ |
| 586 | addCabecera('Moneda:', moneda.DETALLE); | 589 | addCabecera('Moneda:', moneda.DETALLE); |
| 587 | addCabecera( | 590 | addCabecera( |
| 588 | 'Fecha cotizacion:', | 591 | 'Fecha cotizacion:', |
| 589 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 592 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 590 | ); | 593 | ); |
| 591 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); | 594 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); |
| 592 | } | 595 | } |
| 593 | }, function() { | 596 | }, function() { |
| 594 | 597 | ||
| 595 | } | 598 | } |
| 596 | ); | 599 | ); |
| 597 | }; | 600 | }; |
| 598 | 601 | ||
| 599 | $scope.agregarATabla = function(key) { | 602 | $scope.agregarATabla = function(key) { |
| 600 | if(key === 13) { | 603 | if(key === 13) { |
| 601 | if($scope.articuloACargar.cantidad === undefined || | 604 | if($scope.articuloACargar.cantidad === undefined || |
| 602 | $scope.articuloACargar.cantidad === 0 || | 605 | $scope.articuloACargar.cantidad === 0 || |
| 603 | $scope.articuloACargar.cantidad === null ) { | 606 | $scope.articuloACargar.cantidad === null ) { |
| 604 | focaModalService.alert('El valor debe ser al menos 1'); | 607 | focaModalService.alert('El valor debe ser al menos 1'); |
| 605 | return; | 608 | return; |
| 606 | } | 609 | } |
| 607 | delete $scope.articuloACargar.sectorCodigo; | 610 | delete $scope.articuloACargar.sectorCodigo; |
| 608 | $scope.articulosTabla.push($scope.articuloACargar); | 611 | $scope.articulosTabla.push($scope.articuloACargar); |
| 609 | $scope.cargando = true; | 612 | $scope.cargando = true; |
| 610 | } | 613 | } |
| 611 | }; | 614 | }; |
| 612 | 615 | ||
| 613 | $scope.quitarArticulo = function(key) { | 616 | $scope.quitarArticulo = function(key) { |
| 614 | $scope.articulosTabla.splice(key, 1); | 617 | $scope.articulosTabla.splice(key, 1); |
| 615 | }; | 618 | }; |
| 616 | 619 | ||
| 617 | $scope.editarArticulo = function(key, articulo) { | 620 | $scope.editarArticulo = function(key, articulo) { |
| 618 | if(key === 13) { | 621 | if(key === 13) { |
| 619 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 622 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
| 620 | articulo.cantidad === undefined) { | 623 | articulo.cantidad === undefined) { |
| 621 | focaModalService.alert('El valor debe ser al menos 1'); | 624 | focaModalService.alert('El valor debe ser al menos 1'); |
| 622 | return; | 625 | return; |
| 623 | } | 626 | } |
| 624 | articulo.editCantidad = false; | 627 | articulo.editCantidad = false; |
| 625 | articulo.editPrecio = false; | 628 | articulo.editPrecio = false; |
| 626 | } | 629 | } |
| 627 | }; | 630 | }; |
| 628 | 631 | ||
| 629 | $scope.cambioEdit = function(articulo, propiedad) { | 632 | $scope.cambioEdit = function(articulo, propiedad) { |
| 630 | if(propiedad === 'cantidad') { | 633 | if(propiedad === 'cantidad') { |
| 631 | articulo.editCantidad = true; | 634 | articulo.editCantidad = true; |
| 632 | } else if(propiedad === 'precio') { | 635 | } else if(propiedad === 'precio') { |
| 633 | articulo.editPrecio = true; | 636 | articulo.editPrecio = true; |
| 634 | } | 637 | } |
| 635 | }; | 638 | }; |
| 636 | 639 | ||
| 637 | $scope.resetFilter = function() { | 640 | $scope.resetFilter = function() { |
| 638 | $scope.articuloACargar = {}; | 641 | $scope.articuloACargar = {}; |
| 639 | $scope.cargando = true; | 642 | $scope.cargando = true; |
| 640 | }; | 643 | }; |
| 641 | //Recibe aviso si el teclado está en uso | 644 | //Recibe aviso si el teclado está en uso |
| 642 | $rootScope.$on('usarTeclado', function(event, data) { | 645 | $rootScope.$on('usarTeclado', function(event, data) { |
| 643 | if(data) { | 646 | if(data) { |
| 644 | $scope.mostrarTeclado = true; | 647 | $scope.mostrarTeclado = true; |
| 645 | return; | 648 | return; |
| 646 | } | 649 | } |
| 647 | $scope.mostrarTeclado = false; | 650 | $scope.mostrarTeclado = false; |
| 648 | }); | 651 | }); |
| 649 | 652 | ||
| 650 | $scope.selectFocus = function($event) { | 653 | $scope.selectFocus = function($event) { |
| 651 | // Si el teclado esta en uso no selecciona el valor | 654 | // Si el teclado esta en uso no selecciona el valor |
| 652 | if($scope.mostrarTeclado) { | 655 | if($scope.mostrarTeclado) { |
| 653 | return; | 656 | return; |
| 654 | } | 657 | } |
| 655 | $event.target.select(); | 658 | $event.target.select(); |
| 656 | }; | 659 | }; |
| 657 | 660 | ||
| 658 | $scope.salir = function() { | 661 | $scope.salir = function() { |
| 659 | $location.path('/'); | 662 | $location.path('/'); |
| 660 | }; | 663 | }; |
| 661 | 664 | ||
| 662 | $scope.parsearATexto = function(articulo) { | 665 | $scope.parsearATexto = function(articulo) { |
| 663 | articulo.cantidad = parseFloat(articulo.cantidad); | 666 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 664 | articulo.precio = parseFloat(articulo.precio); | 667 | articulo.precio = parseFloat(articulo.precio); |
| 665 | }; | 668 | }; |
| 666 | 669 | ||
| 667 | function addArrayCabecera(array) { | 670 | function addArrayCabecera(array) { |
| 668 | for(var i = 0; i < array.length; i++) { | 671 | for(var i = 0; i < array.length; i++) { |
| 669 | addCabecera(array[i].label, array[i].valor); | 672 | addCabecera(array[i].label, array[i].valor); |
| 670 | } | 673 | } |
| 671 | } | 674 | } |
| 672 | 675 | ||
| 673 | function addCabecera(label, valor) { | 676 | function addCabecera(label, valor) { |
| 674 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 677 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
| 675 | if(propiedad.length === 1) { | 678 | if(propiedad.length === 1) { |
| 676 | propiedad[0].valor = valor; | 679 | propiedad[0].valor = valor; |
| 677 | } else { | 680 | } else { |
| 678 | $scope.cabecera.push({label: label, valor: valor}); | 681 | $scope.cabecera.push({label: label, valor: valor}); |
| 679 | } | 682 | } |
| 680 | } | 683 | } |
| 681 | 684 | ||
| 682 | function removeCabecera(label) { | 685 | function removeCabecera(label) { |
| 683 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 686 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
| 684 | if(propiedad.length === 1) { | 687 | if(propiedad.length === 1) { |
| 685 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); | 688 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); |
| 686 | } | 689 | } |
| 687 | } | 690 | } |
| 688 | 691 | ||
| 689 | function rellenar(relleno, longitud) { | 692 | function rellenar(relleno, longitud) { |
| 690 | relleno = '' + relleno; | 693 | relleno = '' + relleno; |
| 691 | while (relleno.length < longitud) { | 694 | while (relleno.length < longitud) { |
| 692 | relleno = '0' + relleno; | 695 | relleno = '0' + relleno; |
| 693 | } | 696 | } |
| 694 | 697 | ||
| 695 | return relleno; | 698 | return relleno; |
| 696 | } | 699 | } |
| 697 | 700 | ||
| 698 | function validarNotaRemitada() { | 701 | function validarNotaRemitada() { |
| 699 | if(!$scope.notaPedido.idRemito) { | 702 | if(!$scope.notaPedido.idRemito) { |
| 700 | return true; | 703 | return true; |
| 701 | }else{ | 704 | }else{ |
| 702 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 705 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
| 703 | return false; | 706 | return false; |
| 704 | } | 707 | } |
| 705 | } | 708 | } |
| 706 | } | 709 | } |
| 707 | ]); | 710 | ]); |
| 708 | 711 |