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