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