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