Commit 9d4ac61c3484363e2c7abd79382910b1a3129036
Exists in
master
and in
1 other branch
Merge branch 'master' into 'develop'
Master(efernandez) See merge request !90
Showing
1 changed file
Show diff stats
src/js/controller.js
| 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
| 2 | [ | 2 | [ |
| 3 | '$scope', | 3 | '$scope', |
| 4 | '$uibModal', | 4 | '$uibModal', |
| 5 | '$location', | 5 | '$location', |
| 6 | '$filter', | 6 | '$filter', |
| 7 | '$timeout', | 7 | '$timeout', |
| 8 | 'crearNotaPedidoService', | 8 | 'crearNotaPedidoService', |
| 9 | 'focaBotoneraLateralService', | 9 | 'focaBotoneraLateralService', |
| 10 | 'focaModalService', | 10 | 'focaModalService', |
| 11 | 'notaPedidoBusinessService', | 11 | 'notaPedidoBusinessService', |
| 12 | '$rootScope', | 12 | '$rootScope', |
| 13 | 'focaSeguimientoService', | 13 | 'focaSeguimientoService', |
| 14 | 'APP', | 14 | 'APP', |
| 15 | 'focaLoginService', | 15 | 'focaLoginService', |
| 16 | '$localStorage', | 16 | '$localStorage', |
| 17 | function( | 17 | function( |
| 18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, | 18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, |
| 19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, | 19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, |
| 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) | 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) |
| 21 | { | 21 | { |
| 22 | config(); | 22 | config(); |
| 23 | var cotizacionPArgentino = {}; | 23 | var cotizacionPArgentino = {}; |
| 24 | 24 | ||
| 25 | function config() { | 25 | function config() { |
| 26 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA | 26 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA |
| 27 | $scope.tmpCantidad = Number; | 27 | $scope.tmpCantidad = Number; |
| 28 | $scope.tmpPrecio = Number; | 28 | $scope.tmpPrecio = Number; |
| 29 | $scope.notaPedido = {}; | 29 | $scope.notaPedido = {}; |
| 30 | $scope.isNumber = angular.isNumber; | 30 | $scope.isNumber = angular.isNumber; |
| 31 | $scope.datepickerAbierto = false; | 31 | $scope.datepickerAbierto = false; |
| 32 | $scope.show = false; | 32 | $scope.show = false; |
| 33 | $scope.cargando = true; | 33 | $scope.cargando = true; |
| 34 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 34 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
| 35 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 35 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
| 36 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 36 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
| 37 | $scope.dateOptions = { | 37 | $scope.dateOptions = { |
| 38 | maxDate: new Date(), | 38 | maxDate: new Date(), |
| 39 | minDate: new Date(2010, 0, 1) | 39 | minDate: new Date(2010, 0, 1) |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | //SETEO BOTONERA LATERAL | 42 | //SETEO BOTONERA LATERAL |
| 43 | $timeout(function() { | 43 | $timeout(function() { |
| 44 | focaBotoneraLateralService.showSalir(false); | 44 | focaBotoneraLateralService.showSalir(false); |
| 45 | focaBotoneraLateralService.showPausar(true); | 45 | focaBotoneraLateralService.showPausar(true); |
| 46 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 46 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
| 47 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 47 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 48 | }); | 48 | }); |
| 49 | 49 | ||
| 50 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR | 50 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR |
| 51 | if (APP === 'distribuidor') { | 51 | if (APP === 'distribuidor') { |
| 52 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; | 52 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | crearNotaPedidoService.getParametros().then(function(res) { | 55 | crearNotaPedidoService.getParametros().then(function(res) { |
| 56 | var parametros = JSON.parse(res.data[0].jsonText); | 56 | var parametros = JSON.parse(res.data[0].jsonText); |
| 57 | if ($localStorage.notaPedido) { | 57 | if ($localStorage.notaPedido) { |
| 58 | $timeout(function() { getLSNotaPedido();} ); | 58 | $timeout(function() { getLSNotaPedido();} ); |
| 59 | } else { | 59 | } else { |
| 60 | for (var property in parametros) { | 60 | for (var property in parametros) { |
| 61 | $scope.notaPedido[property] = parametros[property]; | 61 | $scope.notaPedido[property] = parametros[property]; |
| 62 | $scope.inicial[property] = parametros[property]; | 62 | $scope.inicial[property] = parametros[property]; |
| 63 | } | 63 | } |
| 64 | setearNotaPedido($scope.notaPedido); | 64 | setearNotaPedido($scope.notaPedido); |
| 65 | } | 65 | } |
| 66 | }); | 66 | }); |
| 67 | 67 | ||
| 68 | init(); | 68 | init(); |
| 69 | 69 | ||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | function init() { | 72 | function init() { |
| 73 | $scope.$broadcast('cleanCabecera'); | 73 | $scope.$broadcast('cleanCabecera'); |
| 74 | 74 | ||
| 75 | $scope.notaPedido = { | 75 | $scope.notaPedido = { |
| 76 | id: 0, | 76 | id: 0, |
| 77 | cliente: {}, | 77 | cliente: {}, |
| 78 | proveedor: {}, | 78 | proveedor: {}, |
| 79 | domicilio: {dom: ''}, | 79 | domicilio: {dom: ''}, |
| 80 | vendedor: {}, | 80 | vendedor: {}, |
| 81 | fechaCarga: new Date(), | 81 | fechaCarga: new Date(), |
| 82 | cotizacion: {}, | 82 | cotizacion: {}, |
| 83 | articulosNotaPedido: [], | 83 | articulosNotaPedido: [], |
| 84 | notaPedidoPlazo: [], | 84 | notaPedidoPlazo: [], |
| 85 | notaPedidoPuntoDescarga: [] | 85 | notaPedidoPuntoDescarga: [] |
| 86 | }; | 86 | }; |
| 87 | $scope.idLista = undefined; | 87 | $scope.idLista = undefined; |
| 88 | 88 | ||
| 89 | crearNotaPedidoService.getNumeroNotaPedido().then( | 89 | crearNotaPedidoService.getNumeroNotaPedido().then( |
| 90 | function(res) { | 90 | function(res) { |
| 91 | $scope.puntoVenta = $filter('rellenarDigitos')( | 91 | $scope.puntoVenta = $filter('rellenarDigitos')( |
| 92 | res.data.sucursal, 4 | 92 | res.data.sucursal, 4 |
| 93 | ); | 93 | ); |
| 94 | 94 | ||
| 95 | $scope.comprobante = $filter('rellenarDigitos')( | 95 | $scope.comprobante = $filter('rellenarDigitos')( |
| 96 | res.data.numeroNotaPedido, 8 | 96 | res.data.numeroNotaPedido, 8 |
| 97 | ); | 97 | ); |
| 98 | }, | 98 | }, |
| 99 | function(err) { | 99 | function(err) { |
| 100 | focaModalService.alert('La terminal no esta configurada correctamente'); | 100 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 101 | console.info(err); | 101 | console.info(err); |
| 102 | } | 102 | } |
| 103 | ); | 103 | ); |
| 104 | 104 | ||
| 105 | if (APP === 'distribuidor') { | 105 | if (APP === 'distribuidor') { |
| 106 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( | 106 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( |
| 107 | function(res) { | 107 | function(res) { |
| 108 | var vendedor = res.data; | 108 | var vendedor = res.data; |
| 109 | $scope.$broadcast('addCabecera', { | 109 | $scope.$broadcast('addCabecera', { |
| 110 | label: 'Vendedor:', | 110 | label: 'Vendedor:', |
| 111 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 111 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
| 112 | vendedor.NOM | 112 | vendedor.NOM |
| 113 | }); | 113 | }); |
| 114 | 114 | ||
| 115 | $scope.notaPedido.vendedor = vendedor; | 115 | $scope.notaPedido.vendedor = vendedor; |
| 116 | $scope.inicial.vendedor = $scope.notaPedido.vendedor; | 116 | $scope.inicial.vendedor = $scope.notaPedido.vendedor; |
| 117 | } | 117 | } |
| 118 | ); | 118 | ); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | $scope.inicial = angular.copy($scope.notaPedido); | 121 | $scope.inicial = angular.copy($scope.notaPedido); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | $scope.$watch('notaPedido', function(newValue) { | 124 | $scope.$watch('notaPedido', function(newValue) { |
| 125 | focaBotoneraLateralService.setPausarData({ | 125 | focaBotoneraLateralService.setPausarData({ |
| 126 | label: 'notaPedido', | 126 | label: 'notaPedido', |
| 127 | val: newValue | 127 | val: newValue |
| 128 | }); | 128 | }); |
| 129 | }, true); | 129 | }, true); |
| 130 | 130 | ||
| 131 | $scope.crearNotaPedido = function() { | 131 | $scope.crearNotaPedido = function() { |
| 132 | if (!$scope.notaPedido.cliente.COD) { | 132 | if (!$scope.notaPedido.cliente.COD) { |
| 133 | focaModalService.alert('Ingrese Cliente'); | 133 | focaModalService.alert('Ingrese Cliente'); |
| 134 | return; | 134 | return; |
| 135 | } else if ($scope.notaPedido.idRemito === -1) { | 135 | } else if ($scope.notaPedido.idRemito === -1) { |
| 136 | focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido'); | 136 | focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido'); |
| 137 | return; | 137 | return; |
| 138 | } else if (!$scope.notaPedido.proveedor.COD) { | 138 | } else if (!$scope.notaPedido.proveedor.COD) { |
| 139 | focaModalService.alert('Ingrese Proveedor'); | 139 | focaModalService.alert('Ingrese Proveedor'); |
| 140 | return; | 140 | return; |
| 141 | } else if (!$scope.notaPedido.cotizacion.ID) { | 141 | } else if (!$scope.notaPedido.cotizacion.ID) { |
| 142 | focaModalService.alert('Ingrese Cotización'); | 142 | focaModalService.alert('Ingrese Cotización'); |
| 143 | return; | 143 | return; |
| 144 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { | 144 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { |
| 145 | focaModalService.alert('Ingrese Moneda'); | 145 | focaModalService.alert('Ingrese Moneda'); |
| 146 | return; | 146 | return; |
| 147 | } else if (!$scope.notaPedido.notaPedidoPlazo) { | 147 | } else if (!$scope.notaPedido.notaPedidoPlazo) { |
| 148 | focaModalService.alert('Ingrese Precios y Condiciones'); | 148 | focaModalService.alert('Ingrese Precios y Condiciones'); |
| 149 | return; | 149 | return; |
| 150 | } else if ( | 150 | } else if ( |
| 151 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 151 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
| 152 | { | 152 | { |
| 153 | focaModalService.alert('Ingrese Flete'); | 153 | focaModalService.alert('Ingrese Flete'); |
| 154 | return; | 154 | return; |
| 155 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 155 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
| 156 | focaModalService.alert('Ingrese Domicilio'); | 156 | focaModalService.alert('Ingrese Domicilio'); |
| 157 | return; | 157 | return; |
| 158 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { | 158 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { |
| 159 | focaModalService.alert('Debe cargar al menos un articulo'); | 159 | focaModalService.alert('Debe cargar al menos un articulo'); |
| 160 | return; | 160 | return; |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | focaBotoneraLateralService.startGuardar(); | 163 | focaBotoneraLateralService.startGuardar(); |
| 164 | $scope.saveLoading = true; | 164 | $scope.saveLoading = true; |
| 165 | var notaPedido = { | 165 | var notaPedido = { |
| 166 | id: $scope.notaPedido.id, | 166 | id: $scope.notaPedido.id, |
| 167 | fechaCarga: new Date($scope.notaPedido.fechaCarga) | 167 | fechaCarga: new Date($scope.notaPedido.fechaCarga) |
| 168 | .toISOString().slice(0, 19).replace('T', ' '), | 168 | .toISOString().slice(0, 19).replace('T', ' '), |
| 169 | idVendedor: $scope.notaPedido.vendedor.id, | 169 | idVendedor: $scope.notaPedido.vendedor.id, |
| 170 | idCliente: $scope.notaPedido.cliente.COD, | 170 | idCliente: $scope.notaPedido.cliente.COD, |
| 171 | nombreCliente: $scope.notaPedido.cliente.NOM, | 171 | nombreCliente: $scope.notaPedido.cliente.NOM, |
| 172 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 172 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
| 173 | idProveedor: $scope.notaPedido.proveedor.COD, | 173 | idProveedor: $scope.notaPedido.proveedor.COD, |
| 174 | idDomicilio: $scope.notaPedido.domicilio.id, | 174 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 175 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 175 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
| 176 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 176 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
| 177 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 177 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 178 | flete: $scope.notaPedido.flete, | 178 | flete: $scope.notaPedido.flete, |
| 179 | fob: $scope.notaPedido.fob, | 179 | fob: $scope.notaPedido.fob, |
| 180 | bomba: $scope.notaPedido.bomba, | 180 | bomba: $scope.notaPedido.bomba, |
| 181 | kilometros: $scope.notaPedido.kilometros, | 181 | kilometros: $scope.notaPedido.kilometros, |
| 182 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 182 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
| 183 | observaciones: $scope.notaPedido.observaciones, | 183 | observaciones: $scope.notaPedido.observaciones, |
| 184 | estado: 0, | 184 | estado: 0, |
| 185 | total: $scope.getTotal() | 185 | total: $scope.getTotal() |
| 186 | }; | 186 | }; |
| 187 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 187 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
| 188 | function(data) { | 188 | function(data) { |
| 189 | // Al guardar los datos de la nota de pedido logueamos la | 189 | // Al guardar los datos de la nota de pedido logueamos la |
| 190 | // actividad para su seguimiento. | 190 | // actividad para su seguimiento. |
| 191 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 191 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
| 192 | focaSeguimientoService.guardarPosicion( | 192 | focaSeguimientoService.guardarPosicion( |
| 193 | 'Nota de pedido', | 193 | 'Nota de pedido', |
| 194 | data.data.id, | 194 | data.data.id, |
| 195 | '' | 195 | '' |
| 196 | ); | 196 | ); |
| 197 | notaPedidoBusinessService.addArticulos( | 197 | notaPedidoBusinessService.addArticulos( |
| 198 | $scope.notaPedido.articulosNotaPedido, | 198 | $scope.notaPedido.articulosNotaPedido, |
| 199 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 199 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
| 200 | 200 | ||
| 201 | if ($scope.notaPedido.notaPedidoPuntoDescarga) { | 201 | if ($scope.notaPedido.notaPedidoPuntoDescarga) { |
| 202 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 202 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
| 203 | $scope.notaPedido.notaPedidoPuntoDescarga); | 203 | $scope.notaPedido.notaPedidoPuntoDescarga); |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | var plazos = $scope.notaPedido.notaPedidoPlazo; | 206 | var plazos = $scope.notaPedido.notaPedidoPlazo; |
| 207 | var plazosACrear = []; | 207 | var plazosACrear = []; |
| 208 | plazos.forEach(function(plazo) { | 208 | plazos.forEach(function(plazo) { |
| 209 | plazosACrear.push({ | 209 | plazosACrear.push({ |
| 210 | idNotaPedido: data.data.id, | 210 | idNotaPedido: data.data.id, |
| 211 | dias: plazo.dias | 211 | dias: plazo.dias |
| 212 | }); | 212 | }); |
| 213 | }); | 213 | }); |
| 214 | 214 | ||
| 215 | if (plazosACrear.length) { | 215 | if (plazosACrear.length) { |
| 216 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 216 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | notaPedidoBusinessService.addEstado(data.data.id, | 219 | notaPedidoBusinessService.addEstado(data.data.id, |
| 220 | $scope.notaPedido.vendedor.id); | 220 | $scope.notaPedido.vendedor.id); |
| 221 | 221 | ||
| 222 | focaBotoneraLateralService.endGuardar(true); | 222 | focaBotoneraLateralService.endGuardar(true); |
| 223 | $scope.saveLoading = false; | 223 | $scope.saveLoading = false; |
| 224 | 224 | ||
| 225 | config(); | 225 | config(); |
| 226 | }, function(error) { | 226 | }, function(error) { |
| 227 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 227 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 228 | focaBotoneraLateralService.endGuardar(); | 228 | focaBotoneraLateralService.endGuardar(); |
| 229 | $scope.saveLoading = false; | 229 | $scope.saveLoading = false; |
| 230 | console.info(error); | 230 | console.info(error); |
| 231 | }); | 231 | }); |
| 232 | }; | 232 | }; |
| 233 | 233 | ||
| 234 | $scope.seleccionarNotaPedido = function() { | 234 | $scope.seleccionarNotaPedido = function() { |
| 235 | var modalInstance = $uibModal.open( | 235 | var modalInstance = $uibModal.open( |
| 236 | { | 236 | { |
| 237 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 237 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
| 238 | templateUrl: 'foca-modal-nota-pedido.html', | 238 | templateUrl: 'foca-modal-nota-pedido.html', |
| 239 | controller: 'focaModalNotaPedidoController', | 239 | controller: 'focaModalNotaPedidoController', |
| 240 | size: 'lg', | 240 | size: 'lg', |
| 241 | resolve: { | 241 | resolve: { |
| 242 | usadoPor: function() {return 'notaPedido';}, | 242 | usadoPor: function() {return 'notaPedido';}, |
| 243 | idVendedor: function() { | 243 | idVendedor: function() { |
| 244 | if (APP === 'distribuidor') | 244 | if (APP === 'distribuidor') |
| 245 | return $scope.notaPedido.vendedor.id; | 245 | return $scope.notaPedido.vendedor.id; |
| 246 | else | 246 | else |
| 247 | return null; | 247 | return null; |
| 248 | } | 248 | } |
| 249 | } | 249 | } |
| 250 | } | 250 | } |
| 251 | ); | 251 | ); |
| 252 | modalInstance.result.then(setearNotaPedido); | 252 | modalInstance.result.then(setearNotaPedido); |
| 253 | }; | 253 | }; |
| 254 | 254 | ||
| 255 | $scope.seleccionarProductos = function() { | 255 | $scope.seleccionarProductos = function() { |
| 256 | |||
| 256 | if ($scope.idLista === undefined) { | 257 | if ($scope.idLista === undefined) { |
| 257 | focaModalService.alert( | 258 | focaModalService.alert( |
| 258 | 'Primero seleccione una lista de precio y condicion'); | 259 | 'Primero seleccione una lista de precio y condicion'); |
| 259 | return; | 260 | return; |
| 261 | } else if (!validarNotaRemitada()) { | ||
| 262 | return; | ||
| 260 | } | 263 | } |
| 264 | |||
| 261 | var modalInstance = $uibModal.open( | 265 | var modalInstance = $uibModal.open( |
| 262 | { | 266 | { |
| 263 | ariaLabelledBy: 'Busqueda de Productos', | 267 | ariaLabelledBy: 'Busqueda de Productos', |
| 264 | templateUrl: 'modal-busqueda-productos.html', | 268 | templateUrl: 'modal-busqueda-productos.html', |
| 265 | controller: 'modalBusquedaProductosCtrl', | 269 | controller: 'modalBusquedaProductosCtrl', |
| 266 | resolve: { | 270 | resolve: { |
| 267 | parametroProducto: { | 271 | parametroProducto: { |
| 268 | idLista: $scope.idLista, | 272 | idLista: $scope.idLista, |
| 269 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 273 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 270 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO | 274 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO |
| 271 | } | 275 | } |
| 272 | }, | 276 | }, |
| 273 | size: 'lg' | 277 | size: 'lg' |
| 274 | } | 278 | } |
| 275 | ); | 279 | ); |
| 276 | modalInstance.result.then( | 280 | modalInstance.result.then( |
| 277 | function(producto) { | 281 | function(producto) { |
| 278 | var newArt = | 282 | var newArt = |
| 279 | { | 283 | { |
| 280 | id: 0, | 284 | id: 0, |
| 281 | codigo: producto.codigo, | 285 | codigo: producto.codigo, |
| 282 | sector: producto.sector, | 286 | sector: producto.sector, |
| 283 | sectorCodigo: producto.sector + '-' + producto.codigo, | 287 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 284 | descripcion: producto.descripcion, | 288 | descripcion: producto.descripcion, |
| 285 | item: $scope.notaPedido.articulosNotaPedido.length + 1, | 289 | item: $scope.notaPedido.articulosNotaPedido.length + 1, |
| 286 | nombre: producto.descripcion, | 290 | nombre: producto.descripcion, |
| 287 | precio: parseFloat(producto.precio.toFixed(4)), | 291 | precio: parseFloat(producto.precio.toFixed(4)), |
| 288 | costoUnitario: producto.costo, | 292 | costoUnitario: producto.costo, |
| 289 | editCantidad: false, | 293 | editCantidad: false, |
| 290 | editPrecio: false, | 294 | editPrecio: false, |
| 291 | rubro: producto.CodRub, | 295 | rubro: producto.CodRub, |
| 292 | ivaUnitario: producto.IMPIVA, | 296 | ivaUnitario: producto.IMPIVA, |
| 293 | impuestoInternoUnitario: producto.ImpInt, | 297 | impuestoInternoUnitario: producto.ImpInt, |
| 294 | impuestoInterno1Unitario: producto.ImpInt2, | 298 | impuestoInterno1Unitario: producto.ImpInt2, |
| 295 | impuestoInterno2Unitario: producto.ImpInt3, | 299 | impuestoInterno2Unitario: producto.ImpInt3, |
| 296 | precioLista: producto.precio, | 300 | precioLista: producto.precio, |
| 297 | combustible: 1, | 301 | combustible: 1, |
| 298 | facturado: 0, | 302 | facturado: 0, |
| 299 | idArticulo: producto.id, | 303 | idArticulo: producto.id, |
| 300 | tasaIva: producto.tasaIVA | 304 | tasaIva: producto.tasaIVA |
| 301 | }; | 305 | }; |
| 302 | 306 | ||
| 303 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; | 307 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; |
| 304 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; | 308 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; |
| 305 | 309 | ||
| 306 | $scope.articuloACargar = newArt; | 310 | $scope.articuloACargar = newArt; |
| 307 | $scope.cargando = false; | 311 | $scope.cargando = false; |
| 308 | }, function() { | 312 | }, function() { |
| 309 | // funcion ejecutada cuando se cancela el modal | 313 | // funcion ejecutada cuando se cancela el modal |
| 310 | } | 314 | } |
| 311 | ); | 315 | ); |
| 312 | }; | 316 | }; |
| 313 | 317 | ||
| 314 | $scope.seleccionarPuntosDeDescarga = function() { | 318 | $scope.seleccionarPuntosDeDescarga = function() { |
| 315 | if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 319 | if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
| 316 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 320 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
| 317 | return; | 321 | return; |
| 318 | } else { | 322 | } else { |
| 319 | var modalInstance = $uibModal.open( | 323 | var modalInstance = $uibModal.open( |
| 320 | { | 324 | { |
| 321 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 325 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
| 322 | templateUrl: 'modal-punto-descarga.html', | 326 | templateUrl: 'modal-punto-descarga.html', |
| 323 | controller: 'focaModalPuntoDescargaController', | 327 | controller: 'focaModalPuntoDescargaController', |
| 324 | size: 'lg', | 328 | size: 'lg', |
| 325 | resolve: { | 329 | resolve: { |
| 326 | filters: { | 330 | filters: { |
| 327 | idDomicilio: $scope.notaPedido.domicilio.id, | 331 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 328 | idCliente: $scope.notaPedido.cliente.COD, | 332 | idCliente: $scope.notaPedido.cliente.COD, |
| 329 | articulos: $scope.notaPedido.articulosNotaPedido, | 333 | articulos: $scope.notaPedido.articulosNotaPedido, |
| 330 | puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, | 334 | puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, |
| 331 | domicilio: $scope.notaPedido.domicilio | 335 | domicilio: $scope.notaPedido.domicilio |
| 332 | } | 336 | } |
| 333 | } | 337 | } |
| 334 | } | 338 | } |
| 335 | ); | 339 | ); |
| 336 | modalInstance.result.then( | 340 | modalInstance.result.then( |
| 337 | function(puntoDescarga) { | 341 | function(puntoDescarga) { |
| 338 | 342 | ||
| 339 | puntoDescarga.forEach(function(punto) { | 343 | puntoDescarga.forEach(function(punto) { |
| 340 | $scope.notaPedido.notaPedidoPuntoDescarga.push( | 344 | $scope.notaPedido.notaPedidoPuntoDescarga.push( |
| 341 | { | 345 | { |
| 342 | puntoDescarga: punto | 346 | puntoDescarga: punto |
| 343 | } | 347 | } |
| 344 | ) | 348 | ) |
| 345 | }); | 349 | }); |
| 346 | 350 | ||
| 347 | $scope.$broadcast('addCabecera', { | 351 | $scope.$broadcast('addCabecera', { |
| 348 | label: 'Puntos de descarga:', | 352 | label: 'Puntos de descarga:', |
| 349 | valor: getCabeceraPuntoDescarga(puntoDescarga) | 353 | valor: getCabeceraPuntoDescarga(puntoDescarga) |
| 350 | }); | 354 | }); |
| 351 | }, function() { | 355 | }, function() { |
| 352 | $scope.abrirModalDomicilios($scope.cliente); | 356 | $scope.abrirModalDomicilios($scope.cliente); |
| 353 | } | 357 | } |
| 354 | ); | 358 | ); |
| 355 | } | 359 | } |
| 356 | }; | 360 | }; |
| 357 | 361 | ||
| 358 | $scope.seleccionarProveedor = function() { | 362 | $scope.seleccionarProveedor = function() { |
| 359 | $scope.abrirModalProveedores(function() { | 363 | $scope.abrirModalProveedores(function() { |
| 360 | if (validarNotaRemitada()) { | 364 | if (validarNotaRemitada()) { |
| 361 | var modalInstance = $uibModal.open( | 365 | var modalInstance = $uibModal.open( |
| 362 | { | 366 | { |
| 363 | ariaLabelledBy: 'Busqueda de Flete', | 367 | ariaLabelledBy: 'Busqueda de Flete', |
| 364 | templateUrl: 'modal-flete.html', | 368 | templateUrl: 'modal-flete.html', |
| 365 | controller: 'focaModalFleteController', | 369 | controller: 'focaModalFleteController', |
| 366 | size: 'lg', | 370 | size: 'lg', |
| 367 | resolve: { | 371 | resolve: { |
| 368 | parametrosFlete: | 372 | parametrosFlete: |
| 369 | function() { | 373 | function() { |
| 370 | return { | 374 | return { |
| 371 | flete: $scope.notaPedido.fob ? 'FOB' : | 375 | flete: $scope.notaPedido.fob ? 'FOB' : |
| 372 | ( $scope.notaPedido.flete ? '1' : | 376 | ( $scope.notaPedido.flete ? '1' : |
| 373 | ($scope.notaPedido.flete === undefined ? | 377 | ($scope.notaPedido.flete === undefined ? |
| 374 | null : '0')), | 378 | null : '0')), |
| 375 | bomba: $scope.notaPedido.bomba ? '1' : | 379 | bomba: $scope.notaPedido.bomba ? '1' : |
| 376 | ($scope.notaPedido.bomba === undefined ? | 380 | ($scope.notaPedido.bomba === undefined ? |
| 377 | null : '0'), | 381 | null : '0'), |
| 378 | kilometros: $scope.notaPedido.kilometros | 382 | kilometros: $scope.notaPedido.kilometros |
| 379 | }; | 383 | }; |
| 380 | } | 384 | } |
| 381 | } | 385 | } |
| 382 | } | 386 | } |
| 383 | ); | 387 | ); |
| 384 | modalInstance.result.then( | 388 | modalInstance.result.then( |
| 385 | function(datos) { | 389 | function(datos) { |
| 386 | $scope.notaPedido.flete = datos.flete; | 390 | $scope.notaPedido.flete = datos.flete; |
| 387 | $scope.notaPedido.fob = datos.FOB; | 391 | $scope.notaPedido.fob = datos.FOB; |
| 388 | $scope.notaPedido.bomba = datos.bomba; | 392 | $scope.notaPedido.bomba = datos.bomba; |
| 389 | $scope.notaPedido.kilometros = datos.kilometros; | 393 | $scope.notaPedido.kilometros = datos.kilometros; |
| 390 | $scope.$broadcast('addCabecera', { | 394 | $scope.$broadcast('addCabecera', { |
| 391 | label: 'Flete:', | 395 | label: 'Flete:', |
| 392 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 396 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
| 393 | }); | 397 | }); |
| 394 | if (datos.flete) { | 398 | if (datos.flete) { |
| 395 | $scope.$broadcast('addCabecera', { | 399 | $scope.$broadcast('addCabecera', { |
| 396 | label: 'Bomba:', | 400 | label: 'Bomba:', |
| 397 | valor: datos.bomba ? 'Si' : 'No' | 401 | valor: datos.bomba ? 'Si' : 'No' |
| 398 | }); | 402 | }); |
| 399 | $scope.$broadcast('addCabecera', { | 403 | $scope.$broadcast('addCabecera', { |
| 400 | label: 'Kilometros:', | 404 | label: 'Kilometros:', |
| 401 | valor: datos.kilometros | 405 | valor: datos.kilometros |
| 402 | }); | 406 | }); |
| 403 | } else { | 407 | } else { |
| 404 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 408 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 405 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 409 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 406 | $scope.notaPedido.bomba = false; | 410 | $scope.notaPedido.bomba = false; |
| 407 | $scope.notaPedido.kilometros = null; | 411 | $scope.notaPedido.kilometros = null; |
| 408 | } | 412 | } |
| 409 | 413 | ||
| 410 | $filter('filter')($scope.botonera, | 414 | $filter('filter')($scope.botonera, |
| 411 | { label: 'Proveedor'})[0].checked = true; | 415 | { label: 'Proveedor'})[0].checked = true; |
| 412 | }, function() { | 416 | }, function() { |
| 413 | $scope.seleccionarTransportista(); | 417 | $scope.seleccionarTransportista(); |
| 414 | } | 418 | } |
| 415 | ); | 419 | ); |
| 416 | } | 420 | } |
| 417 | }); | 421 | }); |
| 418 | }; | 422 | }; |
| 419 | 423 | ||
| 420 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { | 424 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { |
| 421 | if (APP === 'distribuidor' || ocultarVendedor) { | 425 | if (APP === 'distribuidor' || ocultarVendedor) { |
| 422 | callback(); | 426 | callback(); |
| 423 | return; | 427 | return; |
| 424 | } | 428 | } |
| 425 | 429 | ||
| 426 | if (validarNotaRemitada()) { | 430 | if (validarNotaRemitada()) { |
| 427 | var parametrosModal = { | 431 | var parametrosModal = { |
| 428 | titulo: 'Búsqueda vendedores', | 432 | titulo: 'Búsqueda vendedores', |
| 429 | query: '/vendedor', | 433 | query: '/vendedor', |
| 430 | columnas: [ | 434 | columnas: [ |
| 431 | { | 435 | { |
| 432 | propiedad: 'NUM', | 436 | propiedad: 'NUM', |
| 433 | nombre: 'Código', | 437 | nombre: 'Código', |
| 434 | filtro: { | 438 | filtro: { |
| 435 | nombre: 'rellenarDigitos', | 439 | nombre: 'rellenarDigitos', |
| 436 | parametro: 3 | 440 | parametro: 3 |
| 437 | } | 441 | } |
| 438 | }, | 442 | }, |
| 439 | { | 443 | { |
| 440 | propiedad: 'NOM', | 444 | propiedad: 'NOM', |
| 441 | nombre: 'Nombre' | 445 | nombre: 'Nombre' |
| 442 | } | 446 | } |
| 443 | ], | 447 | ], |
| 444 | size: 'md' | 448 | size: 'md' |
| 445 | }; | 449 | }; |
| 446 | focaModalService.modal(parametrosModal).then( | 450 | focaModalService.modal(parametrosModal).then( |
| 447 | function(vendedor) { | 451 | function(vendedor) { |
| 448 | $scope.$broadcast('addCabecera', { | 452 | $scope.$broadcast('addCabecera', { |
| 449 | label: 'Vendedor:', | 453 | label: 'Vendedor:', |
| 450 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 454 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
| 451 | vendedor.NOM | 455 | vendedor.NOM |
| 452 | }); | 456 | }); |
| 453 | $scope.notaPedido.vendedor = vendedor; | 457 | $scope.notaPedido.vendedor = vendedor; |
| 454 | deleteCliente(); | 458 | deleteCliente(); |
| 455 | callback(); | 459 | callback(); |
| 456 | }, function() {} | 460 | }, function() {} |
| 457 | ); | 461 | ); |
| 458 | } | 462 | } |
| 459 | }; | 463 | }; |
| 460 | 464 | ||
| 461 | $scope.seleccionarCliente = function(ocultarVendedor) { | 465 | $scope.seleccionarCliente = function(ocultarVendedor) { |
| 462 | $scope.seleccionarVendedor(function() { | 466 | $scope.seleccionarVendedor(function() { |
| 463 | if (validarNotaRemitada()) { | 467 | if (validarNotaRemitada()) { |
| 464 | var modalInstance = $uibModal.open( | 468 | var modalInstance = $uibModal.open( |
| 465 | { | 469 | { |
| 466 | ariaLabelledBy: 'Busqueda de Cliente', | 470 | ariaLabelledBy: 'Busqueda de Cliente', |
| 467 | templateUrl: 'foca-busqueda-cliente-modal.html', | 471 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 468 | controller: 'focaBusquedaClienteModalController', | 472 | controller: 'focaBusquedaClienteModalController', |
| 469 | resolve: { | 473 | resolve: { |
| 470 | vendedor: function() { return $scope.notaPedido.vendedor; }, | 474 | vendedor: function() { return $scope.notaPedido.vendedor; }, |
| 471 | cobrador: function() { return null; } | 475 | cobrador: function() { return null; } |
| 472 | }, | 476 | }, |
| 473 | size: 'lg' | 477 | size: 'lg' |
| 474 | } | 478 | } |
| 475 | ); | 479 | ); |
| 476 | modalInstance.result.then( | 480 | modalInstance.result.then( |
| 477 | function(cliente) { | 481 | function(cliente) { |
| 478 | $scope.abrirModalDomicilios(cliente); | 482 | $scope.abrirModalDomicilios(cliente); |
| 479 | $scope.cliente = cliente; | 483 | $scope.cliente = cliente; |
| 480 | }, function() { | 484 | }, function() { |
| 481 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); | 485 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); |
| 482 | } | 486 | } |
| 483 | ); | 487 | ); |
| 484 | } | 488 | } |
| 485 | }, ocultarVendedor); | 489 | }, ocultarVendedor); |
| 486 | }; | 490 | }; |
| 487 | 491 | ||
| 488 | $scope.abrirModalProveedores = function(callback) { | 492 | $scope.abrirModalProveedores = function(callback) { |
| 489 | if (validarNotaRemitada()) { | 493 | if (validarNotaRemitada()) { |
| 490 | var parametrosModal = { | 494 | var parametrosModal = { |
| 491 | titulo: 'Búsqueda de Proveedor', | 495 | titulo: 'Búsqueda de Proveedor', |
| 492 | query: '/proveedor', | 496 | query: '/proveedor', |
| 493 | columnas: [ | 497 | columnas: [ |
| 494 | { | 498 | { |
| 495 | nombre: 'Código', | 499 | nombre: 'Código', |
| 496 | propiedad: 'COD', | 500 | propiedad: 'COD', |
| 497 | filtro: { | 501 | filtro: { |
| 498 | nombre: 'rellenarDigitos', | 502 | nombre: 'rellenarDigitos', |
| 499 | parametro: 5 | 503 | parametro: 5 |
| 500 | } | 504 | } |
| 501 | }, | 505 | }, |
| 502 | { | 506 | { |
| 503 | nombre: 'Nombre', | 507 | nombre: 'Nombre', |
| 504 | propiedad: 'NOM' | 508 | propiedad: 'NOM' |
| 505 | }, | 509 | }, |
| 506 | { | 510 | { |
| 507 | nombre: 'CUIT', | 511 | nombre: 'CUIT', |
| 508 | propiedad: 'CUIT' | 512 | propiedad: 'CUIT' |
| 509 | } | 513 | } |
| 510 | ], | 514 | ], |
| 511 | tipo: 'POST', | 515 | tipo: 'POST', |
| 512 | json: {razonCuitCod: ''} | 516 | json: {razonCuitCod: ''} |
| 513 | }; | 517 | }; |
| 514 | focaModalService.modal(parametrosModal).then( | 518 | focaModalService.modal(parametrosModal).then( |
| 515 | function(proveedor) { | 519 | function(proveedor) { |
| 516 | $scope.notaPedido.proveedor = proveedor; | 520 | $scope.notaPedido.proveedor = proveedor; |
| 517 | $scope.$broadcast('addCabecera', { | 521 | $scope.$broadcast('addCabecera', { |
| 518 | label: 'Proveedor:', | 522 | label: 'Proveedor:', |
| 519 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 523 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
| 520 | proveedor.NOM | 524 | proveedor.NOM |
| 521 | }); | 525 | }); |
| 522 | callback(); | 526 | callback(); |
| 523 | }, function() { | 527 | }, function() { |
| 524 | 528 | ||
| 525 | } | 529 | } |
| 526 | ); | 530 | ); |
| 527 | } | 531 | } |
| 528 | }; | 532 | }; |
| 529 | 533 | ||
| 530 | $scope.abrirModalDomicilios = function(cliente) { | 534 | $scope.abrirModalDomicilios = function(cliente) { |
| 531 | var modalInstanceDomicilio = $uibModal.open( | 535 | var modalInstanceDomicilio = $uibModal.open( |
| 532 | { | 536 | { |
| 533 | ariaLabelledBy: 'Busqueda de Domicilios', | 537 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 534 | templateUrl: 'modal-domicilio.html', | 538 | templateUrl: 'modal-domicilio.html', |
| 535 | controller: 'focaModalDomicilioController', | 539 | controller: 'focaModalDomicilioController', |
| 536 | resolve: { | 540 | resolve: { |
| 537 | idCliente: function() { return cliente.cod; }, | 541 | idCliente: function() { return cliente.cod; }, |
| 538 | esNuevo: function() { return cliente.esNuevo; } | 542 | esNuevo: function() { return cliente.esNuevo; } |
| 539 | }, | 543 | }, |
| 540 | size: 'lg', | 544 | size: 'lg', |
| 541 | } | 545 | } |
| 542 | ); | 546 | ); |
| 543 | modalInstanceDomicilio.result.then( | 547 | modalInstanceDomicilio.result.then( |
| 544 | function(domicilio) { | 548 | function(domicilio) { |
| 545 | $scope.notaPedido.domicilio = domicilio; | 549 | $scope.notaPedido.domicilio = domicilio; |
| 546 | $scope.notaPedido.cliente = { | 550 | $scope.notaPedido.cliente = { |
| 547 | COD: cliente.cod, | 551 | COD: cliente.cod, |
| 548 | CUIT: cliente.cuit, | 552 | CUIT: cliente.cuit, |
| 549 | NOM: cliente.nom, | 553 | NOM: cliente.nom, |
| 550 | MOD: cliente.mod | 554 | MOD: cliente.mod |
| 551 | }; | 555 | }; |
| 552 | var domicilioStamp = | 556 | var domicilioStamp = |
| 553 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 557 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
| 554 | domicilio.Localidad + ', ' + domicilio.Provincia; | 558 | domicilio.Localidad + ', ' + domicilio.Provincia; |
| 555 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 559 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
| 556 | 560 | ||
| 557 | $scope.$broadcast('addCabecera', { | 561 | $scope.$broadcast('addCabecera', { |
| 558 | label: 'Cliente:', | 562 | label: 'Cliente:', |
| 559 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom | 563 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom |
| 560 | }); | 564 | }); |
| 561 | 565 | ||
| 562 | $scope.$broadcast('addCabecera', { | 566 | $scope.$broadcast('addCabecera', { |
| 563 | label: 'Domicilio:', | 567 | label: 'Domicilio:', |
| 564 | valor: domicilioStamp | 568 | valor: domicilioStamp |
| 565 | }); | 569 | }); |
| 566 | 570 | ||
| 567 | if (domicilio.verPuntos) { | 571 | if (domicilio.verPuntos) { |
| 568 | delete $scope.notaPedido.domicilio.verPuntos; | 572 | delete $scope.notaPedido.domicilio.verPuntos; |
| 569 | $scope.seleccionarPuntosDeDescarga(); | 573 | $scope.seleccionarPuntosDeDescarga(); |
| 570 | } | 574 | } |
| 571 | 575 | ||
| 572 | // Seteo checked en botonera | 576 | // Seteo checked en botonera |
| 573 | $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true; | 577 | $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true; |
| 574 | 578 | ||
| 575 | }, function() { | 579 | }, function() { |
| 576 | $scope.seleccionarCliente(true); | 580 | $scope.seleccionarCliente(true); |
| 577 | return; | 581 | return; |
| 578 | } | 582 | } |
| 579 | ); | 583 | ); |
| 580 | }; | 584 | }; |
| 581 | 585 | ||
| 582 | $scope.getTotal = function() { | 586 | $scope.getTotal = function() { |
| 583 | var total = 0; | 587 | var total = 0; |
| 584 | if ($scope.notaPedido.articulosNotaPedido) { | 588 | if ($scope.notaPedido.articulosNotaPedido) { |
| 585 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; | 589 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; |
| 586 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 590 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 587 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 591 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 588 | } | 592 | } |
| 589 | } | 593 | } |
| 590 | return parseFloat(total.toFixed(2)); | 594 | return parseFloat(total.toFixed(2)); |
| 591 | }; | 595 | }; |
| 592 | 596 | ||
| 593 | $scope.getSubTotal = function() { | 597 | $scope.getSubTotal = function() { |
| 594 | if ($scope.articuloACargar) { | 598 | if ($scope.articuloACargar) { |
| 595 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 599 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 596 | } | 600 | } |
| 597 | }; | 601 | }; |
| 598 | 602 | ||
| 599 | $scope.seleccionarPreciosYCondiciones = function() { | 603 | $scope.seleccionarPreciosYCondiciones = function() { |
| 604 | |||
| 605 | if (!validarNotaRemitada()) { | ||
| 606 | return; | ||
| 607 | } | ||
| 608 | |||
| 600 | if (!$scope.notaPedido.cliente.COD) { | 609 | if (!$scope.notaPedido.cliente.COD) { |
| 601 | focaModalService.alert('Primero seleccione un cliente'); | 610 | focaModalService.alert('Primero seleccione un cliente'); |
| 602 | return; | 611 | return; |
| 603 | } | 612 | } |
| 604 | if ($scope.notaPedido.articulosNotaPedido.length !== 0) { | 613 | if ($scope.notaPedido.articulosNotaPedido.length !== 0) { |
| 605 | focaModalService.confirm('Se perderan los productos ingresados') | 614 | focaModalService.confirm('Se perderan los productos ingresados') |
| 606 | .then(function(data) { | 615 | .then(function(data) { |
| 607 | if (data) { | 616 | if (data) { |
| 608 | abrirModal(); | 617 | abrirModal(); |
| 609 | } | 618 | } |
| 610 | }); | 619 | }); |
| 611 | } else if (validarNotaRemitada()) { | 620 | } else if (validarNotaRemitada()) { |
| 612 | abrirModal(); | 621 | abrirModal(); |
| 613 | } | 622 | } |
| 614 | function abrirModal() { | 623 | function abrirModal() { |
| 615 | var modalInstance = $uibModal.open( | 624 | var modalInstance = $uibModal.open( |
| 616 | { | 625 | { |
| 617 | ariaLabelledBy: 'Busqueda de Precio Condición', | 626 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 618 | templateUrl: 'modal-precio-condicion.html', | 627 | templateUrl: 'modal-precio-condicion.html', |
| 619 | controller: 'focaModalPrecioCondicionController', | 628 | controller: 'focaModalPrecioCondicionController', |
| 620 | size: 'lg', | 629 | size: 'lg', |
| 621 | resolve: { | 630 | resolve: { |
| 622 | idListaPrecio: function() { | 631 | idListaPrecio: function() { |
| 623 | return $scope.notaPedido.cliente.MOD || null; | 632 | return $scope.notaPedido.cliente.MOD || null; |
| 624 | } | 633 | } |
| 625 | } | 634 | } |
| 626 | } | 635 | } |
| 627 | ); | 636 | ); |
| 628 | 637 | ||
| 629 | modalInstance.result.then( | 638 | modalInstance.result.then( |
| 630 | function(precioCondicion) { | 639 | function(precioCondicion) { |
| 631 | var cabecera = ''; | 640 | var cabecera = ''; |
| 632 | var plazosConcat = ''; | 641 | var plazosConcat = ''; |
| 633 | if (!Array.isArray(precioCondicion)) { | 642 | if (!Array.isArray(precioCondicion)) { |
| 634 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; | 643 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; |
| 635 | $scope.notaPedido.precioCondicion = precioCondicion; | 644 | $scope.notaPedido.precioCondicion = precioCondicion; |
| 636 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 645 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
| 637 | $scope.idLista = precioCondicion.idListaPrecio; | 646 | $scope.idLista = precioCondicion.idListaPrecio; |
| 638 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { | 647 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 639 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 648 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
| 640 | } | 649 | } |
| 641 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 650 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
| 642 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 651 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
| 643 | } else { //Cuando se ingresan los plazos manualmente | 652 | } else { //Cuando se ingresan los plazos manualmente |
| 644 | $scope.notaPedido.idPrecioCondicion = 0; | 653 | $scope.notaPedido.idPrecioCondicion = 0; |
| 645 | //-1, el modal productos busca todos los productos | 654 | //-1, el modal productos busca todos los productos |
| 646 | $scope.idLista = -1; | 655 | $scope.idLista = -1; |
| 647 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; | 656 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; |
| 648 | for (var j = 0; j < precioCondicion.length; j++) { | 657 | for (var j = 0; j < precioCondicion.length; j++) { |
| 649 | plazosConcat += precioCondicion[j].dias + ' '; | 658 | plazosConcat += precioCondicion[j].dias + ' '; |
| 650 | } | 659 | } |
| 651 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 660 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 652 | } | 661 | } |
| 653 | $scope.notaPedido.articulosNotaPedido = []; | 662 | $scope.notaPedido.articulosNotaPedido = []; |
| 654 | $scope.$broadcast('addCabecera', { | 663 | $scope.$broadcast('addCabecera', { |
| 655 | label: 'Precios y condiciones:', | 664 | label: 'Precios y condiciones:', |
| 656 | valor: cabecera | 665 | valor: cabecera |
| 657 | }); | 666 | }); |
| 658 | 667 | ||
| 659 | $filter('filter')($scope.botonera, | 668 | $filter('filter')($scope.botonera, |
| 660 | { label: 'Precios y Condiciones'})[0].checked = true; | 669 | { label: 'Precios y Condiciones'})[0].checked = true; |
| 661 | }, function() { | 670 | }, function() { |
| 662 | 671 | ||
| 663 | } | 672 | } |
| 664 | ); | 673 | ); |
| 665 | } | 674 | } |
| 666 | }; | 675 | }; |
| 667 | 676 | ||
| 668 | $scope.seleccionarMoneda = function() { | 677 | $scope.seleccionarMoneda = function() { |
| 669 | if (validarNotaRemitada()) { | 678 | if (validarNotaRemitada()) { |
| 670 | var parametrosModal = { | 679 | var parametrosModal = { |
| 671 | titulo: 'Búsqueda de monedas', | 680 | titulo: 'Búsqueda de monedas', |
| 672 | query: '/moneda', | 681 | query: '/moneda', |
| 673 | columnas: [ | 682 | columnas: [ |
| 674 | { | 683 | { |
| 675 | propiedad: 'DETALLE', | 684 | propiedad: 'DETALLE', |
| 676 | nombre: 'Nombre' | 685 | nombre: 'Nombre' |
| 677 | }, | 686 | }, |
| 678 | { | 687 | { |
| 679 | propiedad: 'SIMBOLO', | 688 | propiedad: 'SIMBOLO', |
| 680 | nombre: 'Símbolo' | 689 | nombre: 'Símbolo' |
| 681 | } | 690 | } |
| 682 | ], | 691 | ], |
| 683 | size: 'md' | 692 | size: 'md' |
| 684 | }; | 693 | }; |
| 685 | focaModalService.modal(parametrosModal).then( | 694 | focaModalService.modal(parametrosModal).then( |
| 686 | function(moneda) { | 695 | function(moneda) { |
| 687 | 696 | ||
| 688 | if (moneda.ID !== 1) { | 697 | if (moneda.ID !== 1) { |
| 689 | $scope.abrirModalCotizacion(moneda); | 698 | $scope.abrirModalCotizacion(moneda); |
| 690 | return; | 699 | return; |
| 691 | } | 700 | } |
| 692 | 701 | ||
| 693 | crearNotaPedidoService.getCotizacionByIdMoneda(1) | 702 | crearNotaPedidoService.getCotizacionByIdMoneda(1) |
| 694 | .then(function (res) { | 703 | .then(function (res) { |
| 695 | 704 | ||
| 696 | cotizacionPArgentino = res.data[0].cotizaciones[0]; | 705 | cotizacionPArgentino = res.data[0].cotizaciones[0]; |
| 697 | cotizacionPArgentino.moneda = moneda; | 706 | cotizacionPArgentino.moneda = moneda; |
| 698 | 707 | ||
| 699 | actualizarCabeceraMoneda(cotizacionPArgentino); | 708 | actualizarCabeceraMoneda(cotizacionPArgentino); |
| 700 | $scope.notaPedido.cotizacion = cotizacionPArgentino; | 709 | $scope.notaPedido.cotizacion = cotizacionPArgentino; |
| 701 | }); | 710 | }); |
| 702 | } | 711 | } |
| 703 | ); | 712 | ); |
| 704 | } | 713 | } |
| 705 | }; | 714 | }; |
| 706 | 715 | ||
| 707 | $scope.seleccionarObservaciones = function() { | 716 | $scope.seleccionarObservaciones = function() { |
| 708 | var observacion = { | 717 | var observacion = { |
| 709 | titulo: 'Ingrese Observaciones', | 718 | titulo: 'Ingrese Observaciones', |
| 710 | value: $scope.notaPedido.observaciones, | 719 | value: $scope.notaPedido.observaciones, |
| 711 | maxlength: 155, | 720 | maxlength: 155, |
| 712 | textarea: true | 721 | textarea: true |
| 713 | }; | 722 | }; |
| 714 | 723 | ||
| 715 | focaModalService | 724 | focaModalService |
| 716 | .prompt(observacion) | 725 | .prompt(observacion) |
| 717 | .then(function(observaciones) { | 726 | .then(function(observaciones) { |
| 718 | $scope.notaPedido.observaciones = observaciones; | 727 | $scope.notaPedido.observaciones = observaciones; |
| 719 | }); | 728 | }); |
| 720 | }; | 729 | }; |
| 721 | 730 | ||
| 722 | $scope.abrirModalCotizacion = function(moneda) { | 731 | $scope.abrirModalCotizacion = function(moneda) { |
| 723 | var modalInstance = $uibModal.open( | 732 | var modalInstance = $uibModal.open( |
| 724 | { | 733 | { |
| 725 | ariaLabelledBy: 'Busqueda de Cotización', | 734 | ariaLabelledBy: 'Busqueda de Cotización', |
| 726 | templateUrl: 'modal-cotizacion.html', | 735 | templateUrl: 'modal-cotizacion.html', |
| 727 | controller: 'focaModalCotizacionController', | 736 | controller: 'focaModalCotizacionController', |
| 728 | size: 'lg', | 737 | size: 'lg', |
| 729 | resolve: { | 738 | resolve: { |
| 730 | idMoneda: function() { | 739 | idMoneda: function() { |
| 731 | return moneda.ID; | 740 | return moneda.ID; |
| 732 | } | 741 | } |
| 733 | } | 742 | } |
| 734 | } | 743 | } |
| 735 | ); | 744 | ); |
| 736 | modalInstance.result.then( | 745 | modalInstance.result.then( |
| 737 | function(cotizacion) { | 746 | function(cotizacion) { |
| 738 | 747 | ||
| 739 | cotizacion.moneda = moneda; | 748 | cotizacion.moneda = moneda; |
| 740 | actualizarCabeceraMoneda(cotizacion); | 749 | actualizarCabeceraMoneda(cotizacion); |
| 741 | 750 | ||
| 742 | $scope.notaPedido.cotizacion = cotizacion; | 751 | $scope.notaPedido.cotizacion = cotizacion; |
| 743 | $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true; | 752 | $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true; |
| 744 | }, function() { | 753 | }, function() { |
| 745 | 754 | ||
| 746 | } | 755 | } |
| 747 | ); | 756 | ); |
| 748 | }; | 757 | }; |
| 749 | 758 | ||
| 750 | function actualizarCabeceraMoneda (cotizacion) { | 759 | function actualizarCabeceraMoneda (cotizacion) { |
| 751 | 760 | ||
| 752 | $scope.notaPedido.articulosNotaPedido.forEach(function(art) { | 761 | $scope.notaPedido.articulosNotaPedido.forEach(function(art) { |
| 753 | art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); | 762 | art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); |
| 754 | art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); | 763 | art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); |
| 755 | }); | 764 | }); |
| 756 | 765 | ||
| 757 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 766 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { |
| 758 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 767 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
| 759 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 768 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
| 760 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 769 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
| 761 | } else { | 770 | } else { |
| 762 | $scope.$broadcast('addCabecera', { | 771 | $scope.$broadcast('addCabecera', { |
| 763 | label: 'Moneda:', | 772 | label: 'Moneda:', |
| 764 | valor: cotizacion.moneda.DETALLE | 773 | valor: cotizacion.moneda.DETALLE |
| 765 | }); | 774 | }); |
| 766 | $scope.$broadcast('addCabecera', { | 775 | $scope.$broadcast('addCabecera', { |
| 767 | label: 'Fecha cotizacion:', | 776 | label: 'Fecha cotizacion:', |
| 768 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 777 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 769 | }); | 778 | }); |
| 770 | $scope.$broadcast('addCabecera', { | 779 | $scope.$broadcast('addCabecera', { |
| 771 | label: 'Cotizacion:', | 780 | label: 'Cotizacion:', |
| 772 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 781 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
| 773 | }); | 782 | }); |
| 774 | } | 783 | } |
| 775 | } | 784 | } |
| 776 | 785 | ||
| 777 | $scope.agregarATabla = function(key) { | 786 | $scope.agregarATabla = function(key) { |
| 778 | if (key === 13) { | 787 | if (key === 13) { |
| 779 | if ($scope.articuloACargar.cantidad === undefined || | 788 | if ($scope.articuloACargar.cantidad === undefined || |
| 780 | $scope.articuloACargar.cantidad === 0 || | 789 | $scope.articuloACargar.cantidad === 0 || |
| 781 | $scope.articuloACargar.cantidad === null ) { | 790 | $scope.articuloACargar.cantidad === null ) { |
| 782 | focaModalService.alert('El valor debe ser al menos 1'); | 791 | focaModalService.alert('El valor debe ser al menos 1'); |
| 783 | return; | 792 | return; |
| 784 | } | 793 | } |
| 785 | delete $scope.articuloACargar.sectorCodigo; | 794 | delete $scope.articuloACargar.sectorCodigo; |
| 786 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); | 795 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); |
| 787 | $scope.cargando = true; | 796 | $scope.cargando = true; |
| 788 | } | 797 | } |
| 789 | }; | 798 | }; |
| 790 | 799 | ||
| 791 | $scope.quitarArticulo = function(key) { | 800 | $scope.quitarArticulo = function(key) { |
| 792 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); | 801 | if (validarNotaRemitada()) { |
| 802 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); | ||
| 803 | } | ||
| 793 | }; | 804 | }; |
| 794 | 805 | ||
| 795 | $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) { | 806 | $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) { |
| 796 | if (key === 13) { | 807 | if (key === 13) { |
| 797 | if (!articulo.cantidad || !articulo.precio) { | 808 | if (!articulo.cantidad || !articulo.precio) { |
| 798 | focaModalService.alert('Los valores deben ser al menos 1'); | 809 | focaModalService.alert('Los valores deben ser al menos 1'); |
| 799 | return; | 810 | return; |
| 800 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { | 811 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { |
| 801 | focaModalService.alert('Los valores no pueden ser negativos'); | 812 | focaModalService.alert('Los valores no pueden ser negativos'); |
| 802 | return; | 813 | return; |
| 803 | } | 814 | } |
| 804 | articulo.cantidad = tmpCantidad; | 815 | articulo.cantidad = tmpCantidad; |
| 805 | articulo.precio = tmpPrecio; | 816 | articulo.precio = tmpPrecio; |
| 806 | $scope.getTotal(); | 817 | $scope.getTotal(); |
| 807 | articulo.editCantidad = articulo.editPrecio = false; | 818 | articulo.editCantidad = articulo.editPrecio = false; |
| 808 | } | 819 | } |
| 809 | }; | 820 | }; |
| 810 | 821 | ||
| 811 | $scope.cancelarEditar = function(articulo) { | 822 | $scope.cancelarEditar = function(articulo) { |
| 812 | $scope.tmpCantidad = articulo.cantidad; | 823 | $scope.tmpCantidad = articulo.cantidad; |
| 813 | $scope.tmpPrecio = articulo.precio; | 824 | $scope.tmpPrecio = articulo.precio; |
| 814 | articulo.editCantidad = articulo.editPrecio = false; | 825 | articulo.editCantidad = articulo.editPrecio = false; |
| 815 | }; | 826 | }; |
| 816 | 827 | ||
| 817 | $scope.cambioEdit = function(articulo, propiedad) { | 828 | $scope.cambioEdit = function(articulo, propiedad) { |
| 818 | if (propiedad === 'cantidad') { | 829 | if (propiedad === 'cantidad') { |
| 819 | articulo.editCantidad = true; | 830 | articulo.editCantidad = true; |
| 820 | } else if (propiedad === 'precio') { | 831 | } else if (propiedad === 'precio') { |
| 821 | articulo.editPrecio = true; | 832 | articulo.editPrecio = true; |
| 822 | } | 833 | } |
| 823 | }; | 834 | }; |
| 824 | 835 | ||
| 825 | $scope.resetFilter = function() { | 836 | $scope.resetFilter = function() { |
| 826 | $scope.articuloACargar = {}; | 837 | $scope.articuloACargar = {}; |
| 827 | $scope.cargando = true; | 838 | $scope.cargando = true; |
| 828 | }; | 839 | }; |
| 829 | //Recibe aviso si el teclado está en uso | 840 | //Recibe aviso si el teclado está en uso |
| 830 | $rootScope.$on('usarTeclado', function(event, data) { | 841 | $rootScope.$on('usarTeclado', function(event, data) { |
| 831 | if (data) { | 842 | if (data) { |
| 832 | $scope.mostrarTeclado = true; | 843 | $scope.mostrarTeclado = true; |
| 833 | return; | 844 | return; |
| 834 | } | 845 | } |
| 835 | $scope.mostrarTeclado = false; | 846 | $scope.mostrarTeclado = false; |
| 836 | }); | 847 | }); |
| 837 | 848 | ||
| 838 | $scope.selectFocus = function($event) { | 849 | $scope.selectFocus = function($event) { |
| 839 | // Si el teclado esta en uso no selecciona el valor | 850 | // Si el teclado esta en uso no selecciona el valor |
| 840 | if ($scope.mostrarTeclado) { | 851 | if ($scope.mostrarTeclado) { |
| 841 | return; | 852 | return; |
| 842 | } | 853 | } |
| 843 | $event.target.select(); | 854 | $event.target.select(); |
| 844 | }; | 855 | }; |
| 845 | 856 | ||
| 846 | $scope.salir = function() { | 857 | $scope.salir = function() { |
| 847 | $location.path('/'); | 858 | $location.path('/'); |
| 848 | }; | 859 | }; |
| 849 | 860 | ||
| 850 | $scope.parsearATexto = function(articulo) { | 861 | $scope.parsearATexto = function(articulo) { |
| 851 | articulo.cantidad = parseFloat(articulo.cantidad); | 862 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 852 | articulo.precio = parseFloat(articulo.precio); | 863 | articulo.precio = parseFloat(articulo.precio); |
| 853 | }; | 864 | }; |
| 854 | 865 | ||
| 855 | // TODO: quitar watch usar función de articulos pedido cuando se haga | 866 | // TODO: quitar watch usar función de articulos pedido cuando se haga |
| 856 | $scope.$watch('notaPedido.articulosNotaPedido', function() { | 867 | $scope.$watch('notaPedido.articulosNotaPedido', function() { |
| 857 | if ($scope.notaPedido.articulosNotaPedido.length) { | 868 | if ($scope.notaPedido.articulosNotaPedido.length) { |
| 858 | $filter('filter')($scope.botonera, | 869 | $filter('filter')($scope.botonera, |
| 859 | { label: 'Productos'})[0].checked = true; | 870 | { label: 'Productos'})[0].checked = true; |
| 860 | } else { | 871 | } else { |
| 861 | $filter('filter')($scope.botonera, | 872 | $filter('filter')($scope.botonera, |
| 862 | { label: 'Productos'})[0].checked = false; | 873 | { label: 'Productos'})[0].checked = false; |
| 863 | } | 874 | } |
| 864 | }, true); | 875 | }, true); |
| 865 | 876 | ||
| 866 | function setearNotaPedido(notaPedido) { | 877 | function setearNotaPedido(notaPedido) { |
| 867 | //añado cabeceras | 878 | //añado cabeceras |
| 868 | $scope.notaPedido = notaPedido; | 879 | $scope.notaPedido = notaPedido; |
| 869 | if (!$scope.notaPedido.domicilio) { | 880 | if (!$scope.notaPedido.domicilio) { |
| 870 | $scope.notaPedido.domicilio = { | 881 | $scope.notaPedido.domicilio = { |
| 871 | id: $scope.notaPedido.idDomicilio | 882 | id: $scope.notaPedido.idDomicilio |
| 872 | }; | 883 | }; |
| 873 | } | 884 | } |
| 874 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 885 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 875 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 886 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 876 | $scope.$broadcast('cleanCabecera'); | 887 | $scope.$broadcast('cleanCabecera'); |
| 877 | 888 | ||
| 878 | var cabeceras = []; | 889 | var cabeceras = []; |
| 879 | 890 | ||
| 880 | if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 891 | if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { |
| 881 | cabeceras.push({ | 892 | cabeceras.push({ |
| 882 | label: 'Moneda:', | 893 | label: 'Moneda:', |
| 883 | valor: notaPedido.cotizacion.moneda.DETALLE | 894 | valor: notaPedido.cotizacion.moneda.DETALLE |
| 884 | }); | 895 | }); |
| 885 | cabeceras.push({ | 896 | cabeceras.push({ |
| 886 | label: 'Fecha cotizacion:', | 897 | label: 'Fecha cotizacion:', |
| 887 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 898 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
| 888 | 'dd/MM/yyyy') | 899 | 'dd/MM/yyyy') |
| 889 | }); | 900 | }); |
| 890 | cabeceras.push({ | 901 | cabeceras.push({ |
| 891 | label: 'Cotizacion:', | 902 | label: 'Cotizacion:', |
| 892 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 903 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
| 893 | '2') | 904 | '2') |
| 894 | }); | 905 | }); |
| 895 | } | 906 | } |
| 896 | 907 | ||
| 897 | if (notaPedido.cotizacion.moneda) { | 908 | if (notaPedido.cotizacion.moneda) { |
| 898 | $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true; | 909 | $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true; |
| 899 | } | 910 | } |
| 900 | 911 | ||
| 901 | if (notaPedido.vendedor.NUM) { | 912 | if (notaPedido.vendedor.NUM) { |
| 902 | cabeceras.push({ | 913 | cabeceras.push({ |
| 903 | label: 'Vendedor:', | 914 | label: 'Vendedor:', |
| 904 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + | 915 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + |
| 905 | ' - ' + notaPedido.vendedor.NOM | 916 | ' - ' + notaPedido.vendedor.NOM |
| 906 | }); | 917 | }); |
| 907 | } | 918 | } |
| 908 | 919 | ||
| 909 | if (notaPedido.cliente.COD) { | 920 | if (notaPedido.cliente.COD) { |
| 910 | cabeceras.push({ | 921 | cabeceras.push({ |
| 911 | label: 'Cliente:', | 922 | label: 'Cliente:', |
| 912 | valor: notaPedido.cliente.NOM | 923 | valor: notaPedido.cliente.NOM |
| 913 | }); | 924 | }); |
| 914 | cabeceras.push({ | 925 | cabeceras.push({ |
| 915 | label: 'Domicilio:', | 926 | label: 'Domicilio:', |
| 916 | valor: notaPedido.domicilioStamp | 927 | valor: notaPedido.domicilioStamp |
| 917 | }); | 928 | }); |
| 918 | 929 | ||
| 919 | $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true; | 930 | $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true; |
| 920 | } | 931 | } |
| 921 | 932 | ||
| 922 | if (notaPedido.proveedor.COD) { | 933 | if (notaPedido.proveedor.COD) { |
| 923 | cabeceras.push({ | 934 | cabeceras.push({ |
| 924 | label: 'Proveedor:', | 935 | label: 'Proveedor:', |
| 925 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + | 936 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + |
| 926 | ' - ' + notaPedido.proveedor.NOM | 937 | ' - ' + notaPedido.proveedor.NOM |
| 927 | }); | 938 | }); |
| 928 | 939 | ||
| 929 | $filter('filter')($scope.botonera, { label: 'Proveedor'})[0].checked = true; | 940 | $filter('filter')($scope.botonera, { label: 'Proveedor'})[0].checked = true; |
| 930 | } | 941 | } |
| 931 | 942 | ||
| 932 | if (notaPedido.notaPedidoPlazo.length) { | 943 | if (notaPedido.notaPedidoPlazo.length) { |
| 933 | cabeceras.push({ | 944 | cabeceras.push({ |
| 934 | label: 'Precios y condiciones:', | 945 | label: 'Precios y condiciones:', |
| 935 | valor: valorPrecioCondicion() + ' ' + | 946 | valor: valorPrecioCondicion() + ' ' + |
| 936 | notaPedidoBusinessService | 947 | notaPedidoBusinessService |
| 937 | .plazoToString(notaPedido.notaPedidoPlazo) | 948 | .plazoToString(notaPedido.notaPedidoPlazo) |
| 938 | }); | 949 | }); |
| 939 | 950 | ||
| 940 | $filter('filter')($scope.botonera, | 951 | $filter('filter')($scope.botonera, |
| 941 | { label: 'Precios y condiciones'})[0].checked = true; | 952 | { label: 'Precios y condiciones'})[0].checked = true; |
| 942 | } | 953 | } |
| 943 | 954 | ||
| 944 | if (notaPedido.flete !== undefined) { | 955 | if (notaPedido.flete !== undefined) { |
| 945 | cabeceras.push({ | 956 | cabeceras.push({ |
| 946 | label: 'Flete:', | 957 | label: 'Flete:', |
| 947 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 958 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
| 948 | notaPedido.flete === 1 ? 'Si' : 'No') | 959 | notaPedido.flete === 1 ? 'Si' : 'No') |
| 949 | }); | 960 | }); |
| 950 | } | 961 | } |
| 951 | 962 | ||
| 952 | function valorPrecioCondicion() { | 963 | function valorPrecioCondicion() { |
| 953 | if (notaPedido.idPrecioCondicion > 0) { | 964 | if (notaPedido.idPrecioCondicion > 0) { |
| 954 | return notaPedido.precioCondicion.nombre; | 965 | return notaPedido.precioCondicion.nombre; |
| 955 | } else { | 966 | } else { |
| 956 | return 'Ingreso Manual'; | 967 | return 'Ingreso Manual'; |
| 957 | } | 968 | } |
| 958 | } | 969 | } |
| 959 | 970 | ||
| 960 | if (notaPedido.flete === 1) { | 971 | if (notaPedido.flete === 1) { |
| 961 | var cabeceraBomba = { | 972 | var cabeceraBomba = { |
| 962 | label: 'Bomba:', | 973 | label: 'Bomba:', |
| 963 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 974 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
| 964 | }; | 975 | }; |
| 965 | if (notaPedido.kilometros) { | 976 | if (notaPedido.kilometros) { |
| 966 | var cabeceraKilometros = { | 977 | var cabeceraKilometros = { |
| 967 | label: 'Kilometros:', | 978 | label: 'Kilometros:', |
| 968 | valor: notaPedido.kilometros | 979 | valor: notaPedido.kilometros |
| 969 | }; | 980 | }; |
| 970 | cabeceras.push(cabeceraKilometros); | 981 | cabeceras.push(cabeceraKilometros); |
| 971 | } | 982 | } |
| 972 | cabeceras.push(cabeceraBomba); | 983 | cabeceras.push(cabeceraBomba); |
| 973 | } | 984 | } |
| 974 | 985 | ||
| 975 | if (notaPedido.idPrecioCondicion > 0) { | 986 | if (notaPedido.idPrecioCondicion > 0) { |
| 976 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 987 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
| 977 | } else if (notaPedido.idPrecioCondicion) { | 988 | } else if (notaPedido.idPrecioCondicion) { |
| 978 | $scope.idLista = -1; | 989 | $scope.idLista = -1; |
| 979 | } | 990 | } |
| 980 | 991 | ||
| 981 | $scope.puntoVenta = $filter('rellenarDigitos')( | 992 | $scope.puntoVenta = $filter('rellenarDigitos')( |
| 982 | notaPedido.sucursal, 4 | 993 | notaPedido.sucursal, 4 |
| 983 | ); | 994 | ); |
| 984 | 995 | ||
| 985 | $scope.comprobante = $filter('rellenarDigitos')( | 996 | $scope.comprobante = $filter('rellenarDigitos')( |
| 986 | notaPedido.numeroNotaPedido, 8 | 997 | notaPedido.numeroNotaPedido, 8 |
| 987 | ); | 998 | ); |
| 988 | 999 | ||
| 989 | if (notaPedido.notaPedidoPuntoDescarga.length) { | 1000 | if (notaPedido.notaPedidoPuntoDescarga.length) { |
| 990 | var puntos = []; | 1001 | var puntos = []; |
| 991 | notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga) { | 1002 | notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga) { |
| 992 | puntos.push(notaPedidoPuntoDescarga.puntoDescarga); | 1003 | puntos.push(notaPedidoPuntoDescarga.puntoDescarga); |
| 993 | }); | 1004 | }); |
| 994 | cabeceras.push({ | 1005 | cabeceras.push({ |
| 995 | label: 'Puntos de descarga: ', | 1006 | label: 'Puntos de descarga: ', |
| 996 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) | 1007 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) |
| 997 | }); | 1008 | }); |
| 998 | } | 1009 | } |
| 999 | 1010 | ||
| 1000 | if ($scope.notaPedido.articulosNotaPedido.length) { | 1011 | if ($scope.notaPedido.articulosNotaPedido.length) { |
| 1001 | $scope.notaPedido.articulosNotaPedido.forEach(function (articulo) { | 1012 | $scope.notaPedido.articulosNotaPedido.forEach(function (articulo) { |
| 1002 | articulo.precio = | 1013 | articulo.precio = |
| 1003 | (articulo.precio / $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); | 1014 | (articulo.precio / $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); |
| 1004 | }); | 1015 | }); |
| 1005 | } | 1016 | } |
| 1006 | 1017 | ||
| 1007 | addArrayCabecera(cabeceras); | 1018 | addArrayCabecera(cabeceras); |
| 1008 | } | 1019 | } |
| 1009 | 1020 | ||
| 1010 | function getCabeceraPuntoDescarga(puntoDescarga) { | 1021 | function getCabeceraPuntoDescarga(puntoDescarga) { |
| 1011 | var puntosStamp = ''; | 1022 | var puntosStamp = ''; |
| 1012 | puntoDescarga.forEach(function(punto, idx, arr) { | 1023 | puntoDescarga.forEach(function(punto, idx, arr) { |
| 1013 | puntosStamp += punto.descripcion; | 1024 | puntosStamp += punto.descripcion; |
| 1014 | if ((idx + 1) !== arr.length) puntosStamp += ', '; | 1025 | if ((idx + 1) !== arr.length) puntosStamp += ', '; |
| 1015 | }); | 1026 | }); |
| 1016 | return puntosStamp; | 1027 | return puntosStamp; |
| 1017 | } | 1028 | } |
| 1018 | 1029 | ||
| 1019 | function addArrayCabecera(array) { | 1030 | function addArrayCabecera(array) { |
| 1020 | for (var i = 0; i < array.length; i++) { | 1031 | for (var i = 0; i < array.length; i++) { |
| 1021 | $scope.$broadcast('addCabecera', { | 1032 | $scope.$broadcast('addCabecera', { |
| 1022 | label: array[i].label, | 1033 | label: array[i].label, |
| 1023 | valor: array[i].valor | 1034 | valor: array[i].valor |
| 1024 | }); | 1035 | }); |
| 1025 | } | 1036 | } |
| 1026 | } | 1037 | } |
| 1027 | 1038 | ||
| 1028 | function validarNotaRemitada() { | 1039 | function validarNotaRemitada() { |
| 1029 | if (!$scope.notaPedido.idRemito) { | 1040 | if (!$scope.notaPedido.idRemito) { |
| 1030 | return true; | 1041 | return true; |
| 1031 | } else { | 1042 | } else { |
| 1032 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 1043 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
| 1033 | return false; | 1044 | return false; |
| 1034 | } | 1045 | } |
| 1035 | } | 1046 | } |
| 1036 | 1047 | ||
| 1037 | function salir() { | 1048 | function salir() { |
| 1038 | var confirmacion = false; | 1049 | var confirmacion = false; |
| 1039 | 1050 | ||
| 1040 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { | 1051 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { |
| 1041 | confirmacion = true; | 1052 | confirmacion = true; |
| 1042 | } | 1053 | } |
| 1043 | 1054 | ||
| 1044 | if (confirmacion) { | 1055 | if (confirmacion) { |
| 1045 | focaModalService.confirm( | 1056 | focaModalService.confirm( |
| 1046 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 1057 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 1047 | ).then(function(data) { | 1058 | ).then(function(data) { |
| 1048 | if (data) { | 1059 | if (data) { |
| 1049 | $location.path('/'); | 1060 | $location.path('/'); |
| 1050 | } | 1061 | } |
| 1051 | }); | 1062 | }); |
| 1052 | } else { | 1063 | } else { |
| 1053 | $location.path('/'); | 1064 | $location.path('/'); |
| 1054 | } | 1065 | } |
| 1055 | } | 1066 | } |
| 1056 | 1067 | ||
| 1057 | function getLSNotaPedido() { | 1068 | function getLSNotaPedido() { |
| 1058 | var notaPedido = JSON.parse($localStorage.notaPedido || null); | 1069 | var notaPedido = JSON.parse($localStorage.notaPedido || null); |
| 1059 | if (notaPedido) { | 1070 | if (notaPedido) { |
| 1060 | delete $localStorage.notaPedido; | 1071 | delete $localStorage.notaPedido; |
| 1061 | setearNotaPedido(notaPedido); | 1072 | setearNotaPedido(notaPedido); |
| 1062 | } | 1073 | } |
| 1063 | } | 1074 | } |
| 1064 | 1075 | ||
| 1065 | function deleteCliente() { | 1076 | function deleteCliente() { |
| 1066 | $scope.notaPedido.domicilioStamp = ''; | 1077 | $scope.notaPedido.domicilioStamp = ''; |
| 1067 | $scope.notaPedido.notaPedidoPuntoDescarga = []; | 1078 | $scope.notaPedido.notaPedidoPuntoDescarga = []; |
| 1068 | $scope.notaPedido.domicilio = {dom: ''}; | 1079 | $scope.notaPedido.domicilio = {dom: ''}; |
| 1069 | $scope.notaPedido.cliente = {}; | 1080 | $scope.notaPedido.cliente = {}; |
| 1070 | $scope.$broadcast('removeCabecera', 'Cliente:'); | 1081 | $scope.$broadcast('removeCabecera', 'Cliente:'); |
| 1071 | $scope.$broadcast('removeCabecera', 'Domicilio:'); | 1082 | $scope.$broadcast('removeCabecera', 'Domicilio:'); |
| 1072 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); | 1083 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); |
| 1073 | $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = false; | 1084 | $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = false; |
| 1074 | } | 1085 | } |
| 1075 | } | 1086 | } |
| 1076 | ]); | 1087 | ]); |
| 1077 | 1088 |