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