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