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