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