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