Commit 7624ac5935e111af8e901c7caf5b01641b6598c3
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
Master See merge request !14
Showing
1 changed file
Show diff stats
src/js/controller.js
| 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
| 2 | [ | 2 | [ |
| 3 | '$scope', | 3 | '$scope', |
| 4 | '$uibModal', | 4 | '$uibModal', |
| 5 | '$location', | 5 | '$location', |
| 6 | '$filter', | 6 | '$filter', |
| 7 | '$timeout', | 7 | '$timeout', |
| 8 | 'crearNotaPedidoService', | 8 | 'crearNotaPedidoService', |
| 9 | 'focaBotoneraLateralService', | 9 | 'focaBotoneraLateralService', |
| 10 | 'focaModalService', | 10 | 'focaModalService', |
| 11 | 'notaPedidoBusinessService', | 11 | 'notaPedidoBusinessService', |
| 12 | '$rootScope', | 12 | '$rootScope', |
| 13 | 'focaSeguimientoService', | 13 | 'focaSeguimientoService', |
| 14 | function( | 14 | function( |
| 15 | $scope, $uibModal, $location, $filter, $timeout, | 15 | $scope, $uibModal, $location, $filter, $timeout, |
| 16 | crearNotaPedidoService, focaBotoneraLateralService, | 16 | crearNotaPedidoService, focaBotoneraLateralService, |
| 17 | focaModalService, notaPedidoBusinessService, $rootScope, focaSeguimientoService) | 17 | focaModalService, notaPedidoBusinessService, $rootScope, focaSeguimientoService) |
| 18 | { | 18 | { |
| 19 | 19 | ||
| 20 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 20 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
| 21 | 21 | ||
| 22 | $scope.isNumber = angular.isNumber; | 22 | $scope.isNumber = angular.isNumber; |
| 23 | $scope.datepickerAbierto = false; | 23 | $scope.datepickerAbierto = false; |
| 24 | $scope.show = false; | 24 | $scope.show = false; |
| 25 | $scope.cargando = true; | 25 | $scope.cargando = true; |
| 26 | $scope.dateOptions = { | 26 | $scope.dateOptions = { |
| 27 | maxDate: new Date(), | 27 | maxDate: new Date(), |
| 28 | minDate: new Date(2010, 0, 1) | 28 | minDate: new Date(2010, 0, 1) |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | $scope.notaPedido = { | 31 | $scope.notaPedido = { |
| 32 | id: 0, | 32 | id: 0, |
| 33 | vendedor: {}, | 33 | vendedor: {}, |
| 34 | cliente: {}, | 34 | cliente: {}, |
| 35 | proveedor: {}, | 35 | proveedor: {}, |
| 36 | domicilio: {dom: ''}, | 36 | domicilio: {dom: ''}, |
| 37 | moneda: {}, | 37 | moneda: {}, |
| 38 | cotizacion: {} | 38 | cotizacion: {} |
| 39 | }; | 39 | }; |
| 40 | var monedaPorDefecto; | 40 | var monedaPorDefecto; |
| 41 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 41 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
| 42 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | 42 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
| 43 | monedaPorDefecto = res.data[0]; | 43 | monedaPorDefecto = res.data[0]; |
| 44 | $scope.notaPedido.moneda = monedaPorDefecto; | 44 | $scope.notaPedido.moneda = monedaPorDefecto; |
| 45 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; | 45 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; |
| 46 | }); | 46 | }); |
| 47 | 47 | ||
| 48 | $scope.cabecera = []; | 48 | $scope.cabecera = []; |
| 49 | $scope.showCabecera = true; | 49 | $scope.showCabecera = true; |
| 50 | 50 | ||
| 51 | $scope.now = new Date(); | 51 | $scope.now = new Date(); |
| 52 | $scope.puntoVenta = '0000'; | 52 | $scope.puntoVenta = '0000'; |
| 53 | $scope.comprobante = '00000000'; | 53 | $scope.comprobante = '00000000'; |
| 54 | $scope.articulosTabla = []; | 54 | $scope.articulosTabla = []; |
| 55 | $scope.idLista = undefined; | 55 | $scope.idLista = undefined; |
| 56 | 56 | ||
| 57 | //SETEO BOTONERA LATERAL | 57 | //SETEO BOTONERA LATERAL |
| 58 | $timeout(function() { | 58 | $timeout(function() { |
| 59 | focaBotoneraLateralService.showSalir(true); | 59 | focaBotoneraLateralService.showSalir(true); |
| 60 | focaBotoneraLateralService.showPausar(true); | 60 | focaBotoneraLateralService.showPausar(true); |
| 61 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 61 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
| 62 | }); | 62 | }); |
| 63 | 63 | ||
| 64 | crearNotaPedidoService.getPrecioCondicion().then( | 64 | crearNotaPedidoService.getPrecioCondicion().then( |
| 65 | function(res) { | 65 | function(res) { |
| 66 | $scope.precioCondiciones = res.data; | 66 | $scope.precioCondiciones = res.data; |
| 67 | } | 67 | } |
| 68 | ); | 68 | ); |
| 69 | 69 | ||
| 70 | crearNotaPedidoService.getNumeroNotaPedido().then( | 70 | crearNotaPedidoService.getNumeroNotaPedido().then( |
| 71 | function(res) { | 71 | function(res) { |
| 72 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 72 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
| 73 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 73 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
| 74 | }, | 74 | }, |
| 75 | function(err) { | 75 | function(err) { |
| 76 | focaModalService.alert('La terminal no esta configurada correctamente'); | 76 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 77 | console.info(err); | 77 | console.info(err); |
| 78 | } | 78 | } |
| 79 | ); | 79 | ); |
| 80 | 80 | ||
| 81 | $scope.crearNotaPedido = function() { | 81 | $scope.crearNotaPedido = function() { |
| 82 | if(!$scope.notaPedido.vendedor.CodVen) { | 82 | if(!$scope.notaPedido.vendedor.CodVen) { |
| 83 | focaModalService.alert('Ingrese Vendedor'); | 83 | focaModalService.alert('Ingrese Vendedor'); |
| 84 | return; | 84 | return; |
| 85 | } else if(!$scope.notaPedido.cliente.COD) { | 85 | } else if(!$scope.notaPedido.cliente.COD) { |
| 86 | focaModalService.alert('Ingrese Cliente'); | 86 | focaModalService.alert('Ingrese Cliente'); |
| 87 | return; | 87 | return; |
| 88 | } else if(!$scope.notaPedido.proveedor.COD) { | 88 | } else if(!$scope.notaPedido.proveedor.COD) { |
| 89 | focaModalService.alert('Ingrese Proveedor'); | 89 | focaModalService.alert('Ingrese Proveedor'); |
| 90 | return; | 90 | return; |
| 91 | } else if(!$scope.notaPedido.moneda.ID) { | 91 | } else if(!$scope.notaPedido.moneda.ID) { |
| 92 | focaModalService.alert('Ingrese Moneda'); | 92 | focaModalService.alert('Ingrese Moneda'); |
| 93 | return; | 93 | return; |
| 94 | } else if(!$scope.notaPedido.cotizacion.ID) { | 94 | } else if(!$scope.notaPedido.cotizacion.ID) { |
| 95 | focaModalService.alert('Ingrese Cotización'); | 95 | focaModalService.alert('Ingrese Cotización'); |
| 96 | return; | 96 | return; |
| 97 | } else if(!$scope.plazosPagos) { | 97 | } else if(!$scope.plazosPagos) { |
| 98 | focaModalService.alert('Ingrese Precios y Condiciones'); | 98 | focaModalService.alert('Ingrese Precios y Condiciones'); |
| 99 | return; | 99 | return; |
| 100 | } else if( | 100 | } else if( |
| 101 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 101 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
| 102 | { | 102 | { |
| 103 | focaModalService.alert('Ingrese Flete'); | 103 | focaModalService.alert('Ingrese Flete'); |
| 104 | return; | 104 | return; |
| 105 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 105 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
| 106 | focaModalService.alert('Ingrese Domicilio'); | 106 | focaModalService.alert('Ingrese Domicilio'); |
| 107 | return; | 107 | return; |
| 108 | } else if($scope.articulosTabla.length === 0) { | 108 | } else if($scope.articulosTabla.length === 0) { |
| 109 | focaModalService.alert('Debe cargar al menos un articulo'); | 109 | focaModalService.alert('Debe cargar al menos un articulo'); |
| 110 | return; | 110 | return; |
| 111 | } | 111 | } |
| 112 | $scope.saveLoading = true; | 112 | $scope.saveLoading = true; |
| 113 | var notaPedido = { | 113 | var notaPedido = { |
| 114 | id: $scope.notaPedido.id, | 114 | id: $scope.notaPedido.id, |
| 115 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | 115 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
| 116 | idVendedor: $scope.notaPedido.vendedor.CodVen, | 116 | idVendedor: $scope.notaPedido.vendedor.CodVen, |
| 117 | idCliente: $scope.notaPedido.cliente.COD, | 117 | idCliente: $scope.notaPedido.cliente.COD, |
| 118 | nombreCliente: $scope.notaPedido.cliente.NOM, | 118 | nombreCliente: $scope.notaPedido.cliente.NOM, |
| 119 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 119 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
| 120 | idProveedor: $scope.notaPedido.proveedor.COD, | 120 | idProveedor: $scope.notaPedido.proveedor.COD, |
| 121 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID | 121 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID |
| 122 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 122 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
| 123 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 123 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
| 124 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 124 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 125 | flete: $scope.notaPedido.flete, | 125 | flete: $scope.notaPedido.flete, |
| 126 | fob: $scope.notaPedido.fob, | 126 | fob: $scope.notaPedido.fob, |
| 127 | bomba: $scope.notaPedido.bomba, | 127 | bomba: $scope.notaPedido.bomba, |
| 128 | kilometros: $scope.notaPedido.kilometros, | 128 | kilometros: $scope.notaPedido.kilometros, |
| 129 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 129 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
| 130 | estado: 0, | 130 | estado: 0, |
| 131 | total: $scope.getTotal() | 131 | total: $scope.getTotal() |
| 132 | }; | 132 | }; |
| 133 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 133 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
| 134 | function(data) { | 134 | function(data) { |
| 135 | // Al guardar los datos de la nota de pedido logueamos la | 135 | // Al guardar los datos de la nota de pedido logueamos la |
| 136 | // actividad para su seguimiento. | 136 | // actividad para su seguimiento. |
| 137 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 137 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
| 138 | focaSeguimientoService.guardarPosicion( | 138 | focaSeguimientoService.guardarPosicion( |
| 139 | data.data.id, | ||
| 140 | 'Nota de pedido', | 139 | 'Nota de pedido', |
| 141 | 'Nº: ' + $filter('comprobante')([ | 140 | data.data.id, |
| 142 | $scope.puntoVenta, | 141 | '' |
| 143 | $scope.comprobante | ||
| 144 | ]) + '<br/>' + | ||
| 145 | 'Vendedor: ' + $scope.notaPedido.vendedor.NomVen + '<br/>' + | ||
| 146 | 'Total: ' + $filter('currency')($scope.getTotal()) | ||
| 147 | ); | 142 | ); |
| 148 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | 143 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, |
| 149 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 144 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
| 150 | var plazos = $scope.plazosPagos; | 145 | var plazos = $scope.plazosPagos; |
| 151 | 146 | ||
| 152 | for(var j = 0; j < plazos.length; j++) { | 147 | for(var j = 0; j < plazos.length; j++) { |
| 153 | var json = { | 148 | var json = { |
| 154 | idPedido: data.data.id, | 149 | idPedido: data.data.id, |
| 155 | dias: plazos[j].dias | 150 | dias: plazos[j].dias |
| 156 | }; | 151 | }; |
| 157 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); | 152 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); |
| 158 | } | 153 | } |
| 159 | notaPedidoBusinessService.addEstado(data.data.id, | 154 | notaPedidoBusinessService.addEstado(data.data.id, |
| 160 | $scope.notaPedido.vendedor.CodVen); | 155 | $scope.notaPedido.vendedor.CodVen); |
| 161 | 156 | ||
| 162 | focaModalService.alert('Nota pedido creada'); | 157 | focaModalService.alert('Nota pedido creada'); |
| 163 | $scope.saveLoading = false; | 158 | $scope.saveLoading = false; |
| 164 | $scope.$broadcast('cleanCabecera'); | 159 | $scope.$broadcast('cleanCabecera'); |
| 165 | $scope.$broadcast('addCabecera', { | 160 | $scope.$broadcast('addCabecera', { |
| 166 | label: 'Moneda:', | 161 | label: 'Moneda:', |
| 167 | valor: $scope.notaPedido.moneda.DETALLE | 162 | valor: $scope.notaPedido.moneda.DETALLE |
| 168 | }); | 163 | }); |
| 169 | $scope.$broadcast('addCabecera', { | 164 | $scope.$broadcast('addCabecera', { |
| 170 | label: 'Fecha cotizacion:', | 165 | label: 'Fecha cotizacion:', |
| 171 | valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') | 166 | valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
| 172 | }); | 167 | }); |
| 173 | $scope.$broadcast('addCabecera', { | 168 | $scope.$broadcast('addCabecera', { |
| 174 | label: 'Moneda:', | 169 | label: 'Moneda:', |
| 175 | valor: $scope.notaPedido.moneda.DETALLE | 170 | valor: $scope.notaPedido.moneda.DETALLE |
| 176 | }); | 171 | }); |
| 177 | $scope.$broadcast('addCabecera', { | 172 | $scope.$broadcast('addCabecera', { |
| 178 | label: 'Cotizacion:', | 173 | label: 'Cotizacion:', |
| 179 | valor: $scope.notaPedido.cotizacion.VENDEDOR | 174 | valor: $scope.notaPedido.cotizacion.VENDEDOR |
| 180 | }); | 175 | }); |
| 181 | crearNotaPedidoService.getNumeroNotaPedido().then( | 176 | crearNotaPedidoService.getNumeroNotaPedido().then( |
| 182 | function(res) { | 177 | function(res) { |
| 183 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 178 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
| 184 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 179 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
| 185 | }, | 180 | }, |
| 186 | function(err) { | 181 | function(err) { |
| 187 | focaModalService.alert( | 182 | focaModalService.alert( |
| 188 | 'La terminal no esta configurada correctamente'); | 183 | 'La terminal no esta configurada correctamente'); |
| 189 | console.info(err); | 184 | console.info(err); |
| 190 | } | 185 | } |
| 191 | ); | 186 | ); |
| 192 | $scope.notaPedido.vendedor = {}; | 187 | $scope.notaPedido.vendedor = {}; |
| 193 | $scope.notaPedido.cliente = {}; | 188 | $scope.notaPedido.cliente = {}; |
| 194 | $scope.notaPedido.proveedor = {}; | 189 | $scope.notaPedido.proveedor = {}; |
| 195 | $scope.notaPedido.domicilio = {}; | 190 | $scope.notaPedido.domicilio = {}; |
| 196 | $scope.notaPedido.flete = null; | 191 | $scope.notaPedido.flete = null; |
| 197 | $scope.notaPedido.fob = null; | 192 | $scope.notaPedido.fob = null; |
| 198 | $scope.notaPedido.bomba = null; | 193 | $scope.notaPedido.bomba = null; |
| 199 | $scope.notaPedido.kilometros = null; | 194 | $scope.notaPedido.kilometros = null; |
| 200 | $scope.articulosTabla = []; | 195 | $scope.articulosTabla = []; |
| 201 | }, | 196 | }, |
| 202 | function(error) { | 197 | function(error) { |
| 203 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 198 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 204 | $scope.saveLoading = false; | 199 | $scope.saveLoading = false; |
| 205 | console.info(error); | 200 | console.info(error); |
| 206 | } | 201 | } |
| 207 | ); | 202 | ); |
| 208 | }; | 203 | }; |
| 209 | 204 | ||
| 210 | $scope.seleccionarNotaPedido = function() { | 205 | $scope.seleccionarNotaPedido = function() { |
| 211 | var modalInstance = $uibModal.open( | 206 | var modalInstance = $uibModal.open( |
| 212 | { | 207 | { |
| 213 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 208 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
| 214 | templateUrl: 'foca-modal-nota-pedido.html', | 209 | templateUrl: 'foca-modal-nota-pedido.html', |
| 215 | controller: 'focaModalNotaPedidoController', | 210 | controller: 'focaModalNotaPedidoController', |
| 216 | size: 'lg', | 211 | size: 'lg', |
| 217 | resolve: {usadoPor: function() {return 'notaPedido';}} | 212 | resolve: {usadoPor: function() {return 'notaPedido';}} |
| 218 | } | 213 | } |
| 219 | ); | 214 | ); |
| 220 | modalInstance.result.then( | 215 | modalInstance.result.then( |
| 221 | function(notaPedido) { | 216 | function(notaPedido) { |
| 222 | $scope.now = new Date(notaPedido.fechaCarga); | 217 | $scope.now = new Date(notaPedido.fechaCarga); |
| 223 | //añado cabeceras | 218 | //añado cabeceras |
| 224 | $scope.notaPedido.id = notaPedido.id; | 219 | $scope.notaPedido.id = notaPedido.id; |
| 225 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 220 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 226 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 221 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 227 | var cabeceras = [ | 222 | var cabeceras = [ |
| 228 | { | 223 | { |
| 229 | label: 'Moneda:', | 224 | label: 'Moneda:', |
| 230 | valor: notaPedido.cotizacion.moneda.DETALLE | 225 | valor: notaPedido.cotizacion.moneda.DETALLE |
| 231 | }, | 226 | }, |
| 232 | { | 227 | { |
| 233 | label: 'Fecha cotizacion:', | 228 | label: 'Fecha cotizacion:', |
| 234 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 229 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
| 235 | 'dd/MM/yyyy') | 230 | 'dd/MM/yyyy') |
| 236 | }, | 231 | }, |
| 237 | { | 232 | { |
| 238 | label: 'Cotizacion:', | 233 | label: 'Cotizacion:', |
| 239 | valor: notaPedido.cotizacion.VENDEDOR | 234 | valor: notaPedido.cotizacion.VENDEDOR |
| 240 | }, | 235 | }, |
| 241 | { | 236 | { |
| 242 | label: 'Cliente:', | 237 | label: 'Cliente:', |
| 243 | valor: notaPedido.cliente.NOM | 238 | valor: notaPedido.cliente.NOM |
| 244 | }, | 239 | }, |
| 245 | { | 240 | { |
| 246 | label: 'Domicilio:', | 241 | label: 'Domicilio:', |
| 247 | valor: notaPedido.domicilioStamp | 242 | valor: notaPedido.domicilioStamp |
| 248 | }, | 243 | }, |
| 249 | { | 244 | { |
| 250 | label: 'Vendedor:', | 245 | label: 'Vendedor:', |
| 251 | valor: notaPedido.vendedor.NomVen | 246 | valor: notaPedido.vendedor.NomVen |
| 252 | }, | 247 | }, |
| 253 | { | 248 | { |
| 254 | label: 'Proveedor:', | 249 | label: 'Proveedor:', |
| 255 | valor: notaPedido.proveedor.NOM | 250 | valor: notaPedido.proveedor.NOM |
| 256 | }, | 251 | }, |
| 257 | { | 252 | { |
| 258 | label: 'Precio condicion:', | 253 | label: 'Precio condicion:', |
| 259 | valor: valorPrecioCondicion() + ' ' + | 254 | valor: valorPrecioCondicion() + ' ' + |
| 260 | notaPedidoBusinessService | 255 | notaPedidoBusinessService |
| 261 | .plazoToString(notaPedido.notaPedidoPlazo) | 256 | .plazoToString(notaPedido.notaPedidoPlazo) |
| 262 | }, | 257 | }, |
| 263 | { | 258 | { |
| 264 | label: 'Flete:', | 259 | label: 'Flete:', |
| 265 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 260 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
| 266 | notaPedido.flete === 1 ? 'Si' : 'No') | 261 | notaPedido.flete === 1 ? 'Si' : 'No') |
| 267 | } | 262 | } |
| 268 | ]; | 263 | ]; |
| 269 | 264 | ||
| 270 | function valorPrecioCondicion() { | 265 | function valorPrecioCondicion() { |
| 271 | if(notaPedido.idPrecioCondicion > 0) { | 266 | if(notaPedido.idPrecioCondicion > 0) { |
| 272 | return notaPedido.precioCondicion.nombre; | 267 | return notaPedido.precioCondicion.nombre; |
| 273 | } else { | 268 | } else { |
| 274 | return 'Ingreso Manual'; | 269 | return 'Ingreso Manual'; |
| 275 | } | 270 | } |
| 276 | } | 271 | } |
| 277 | 272 | ||
| 278 | if(notaPedido.flete === 1) { | 273 | if(notaPedido.flete === 1) { |
| 279 | var cabeceraBomba = { | 274 | var cabeceraBomba = { |
| 280 | label: 'Bomba:', | 275 | label: 'Bomba:', |
| 281 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 276 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
| 282 | }; | 277 | }; |
| 283 | if(notaPedido.kilometros) { | 278 | if(notaPedido.kilometros) { |
| 284 | var cabeceraKilometros = { | 279 | var cabeceraKilometros = { |
| 285 | label: 'Kilometros:', | 280 | label: 'Kilometros:', |
| 286 | valor: notaPedido.kilometros | 281 | valor: notaPedido.kilometros |
| 287 | }; | 282 | }; |
| 288 | cabeceras.push(cabeceraKilometros); | 283 | cabeceras.push(cabeceraKilometros); |
| 289 | } | 284 | } |
| 290 | cabeceras.push(cabeceraBomba); | 285 | cabeceras.push(cabeceraBomba); |
| 291 | } | 286 | } |
| 292 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 287 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
| 293 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, | 288 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, |
| 294 | notaPedido.cotizacion.VENDEDOR); | 289 | notaPedido.cotizacion.VENDEDOR); |
| 295 | if(notaPedido.idPrecioCondicion > 0) { | 290 | if(notaPedido.idPrecioCondicion > 0) { |
| 296 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 291 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
| 297 | } else { | 292 | } else { |
| 298 | $scope.idLista = -1; | 293 | $scope.idLista = -1; |
| 299 | } | 294 | } |
| 300 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); | 295 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); |
| 301 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); | 296 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); |
| 302 | $scope.notaPedido = notaPedido; | 297 | $scope.notaPedido = notaPedido; |
| 303 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; | 298 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; |
| 304 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; | 299 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; |
| 305 | addArrayCabecera(cabeceras); | 300 | addArrayCabecera(cabeceras); |
| 306 | 301 | ||
| 307 | }, function() { | 302 | }, function() { |
| 308 | // funcion ejecutada cuando se cancela el modal | 303 | // funcion ejecutada cuando se cancela el modal |
| 309 | } | 304 | } |
| 310 | ); | 305 | ); |
| 311 | }; | 306 | }; |
| 312 | 307 | ||
| 313 | $scope.seleccionarProductos = function() { | 308 | $scope.seleccionarProductos = function() { |
| 314 | if ($scope.idLista === undefined) { | 309 | if ($scope.idLista === undefined) { |
| 315 | focaModalService.alert( | 310 | focaModalService.alert( |
| 316 | 'Primero seleccione una lista de precio y condicion'); | 311 | 'Primero seleccione una lista de precio y condicion'); |
| 317 | return; | 312 | return; |
| 318 | } | 313 | } |
| 319 | var modalInstance = $uibModal.open( | 314 | var modalInstance = $uibModal.open( |
| 320 | { | 315 | { |
| 321 | ariaLabelledBy: 'Busqueda de Productos', | 316 | ariaLabelledBy: 'Busqueda de Productos', |
| 322 | templateUrl: 'modal-busqueda-productos.html', | 317 | templateUrl: 'modal-busqueda-productos.html', |
| 323 | controller: 'modalBusquedaProductosCtrl', | 318 | controller: 'modalBusquedaProductosCtrl', |
| 324 | resolve: { | 319 | resolve: { |
| 325 | parametroProducto: { | 320 | parametroProducto: { |
| 326 | idLista: $scope.idLista, | 321 | idLista: $scope.idLista, |
| 327 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 322 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 328 | simbolo: $scope.notaPedido.moneda.SIMBOLO | 323 | simbolo: $scope.notaPedido.moneda.SIMBOLO |
| 329 | } | 324 | } |
| 330 | }, | 325 | }, |
| 331 | size: 'lg' | 326 | size: 'lg' |
| 332 | } | 327 | } |
| 333 | ); | 328 | ); |
| 334 | modalInstance.result.then( | 329 | modalInstance.result.then( |
| 335 | function(producto) { | 330 | function(producto) { |
| 336 | var newArt = | 331 | var newArt = |
| 337 | { | 332 | { |
| 338 | id: 0, | 333 | id: 0, |
| 339 | codigo: producto.codigo, | 334 | codigo: producto.codigo, |
| 340 | sector: producto.sector, | 335 | sector: producto.sector, |
| 341 | sectorCodigo: producto.sector + '-' + producto.codigo, | 336 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 342 | descripcion: producto.descripcion, | 337 | descripcion: producto.descripcion, |
| 343 | item: $scope.articulosTabla.length + 1, | 338 | item: $scope.articulosTabla.length + 1, |
| 344 | nombre: producto.descripcion, | 339 | nombre: producto.descripcion, |
| 345 | precio: parseFloat(producto.precio.toFixed(4)), | 340 | precio: parseFloat(producto.precio.toFixed(4)), |
| 346 | costoUnitario: producto.costo, | 341 | costoUnitario: producto.costo, |
| 347 | editCantidad: false, | 342 | editCantidad: false, |
| 348 | editPrecio: false, | 343 | editPrecio: false, |
| 349 | rubro: producto.CodRub, | 344 | rubro: producto.CodRub, |
| 350 | exentoUnitario: producto.precio, | 345 | exentoUnitario: producto.precio, |
| 351 | ivaUnitario: producto.IMPIVA, | 346 | ivaUnitario: producto.IMPIVA, |
| 352 | impuestoInternoUnitario: producto.ImpInt, | 347 | impuestoInternoUnitario: producto.ImpInt, |
| 353 | impuestoInterno1Unitario: producto.ImpInt2, | 348 | impuestoInterno1Unitario: producto.ImpInt2, |
| 354 | impuestoInterno2Unitario: producto.ImpInt3, | 349 | impuestoInterno2Unitario: producto.ImpInt3, |
| 355 | precioLista: producto.precio, | 350 | precioLista: producto.precio, |
| 356 | combustible: 1, | 351 | combustible: 1, |
| 357 | facturado: 0 | 352 | facturado: 0 |
| 358 | }; | 353 | }; |
| 359 | $scope.articuloACargar = newArt; | 354 | $scope.articuloACargar = newArt; |
| 360 | $scope.cargando = false; | 355 | $scope.cargando = false; |
| 361 | }, function() { | 356 | }, function() { |
| 362 | // funcion ejecutada cuando se cancela el modal | 357 | // funcion ejecutada cuando se cancela el modal |
| 363 | } | 358 | } |
| 364 | ); | 359 | ); |
| 365 | }; | 360 | }; |
| 366 | 361 | ||
| 367 | $scope.seleccionarVendedor = function() { | 362 | $scope.seleccionarVendedor = function() { |
| 368 | if(validarNotaRemitada()) { | 363 | if(validarNotaRemitada()) { |
| 369 | var modalInstance = $uibModal.open( | 364 | var modalInstance = $uibModal.open( |
| 370 | { | 365 | { |
| 371 | ariaLabelledBy: 'Busqueda de Vendedores', | 366 | ariaLabelledBy: 'Busqueda de Vendedores', |
| 372 | templateUrl: 'modal-vendedores.html', | 367 | templateUrl: 'modal-vendedores.html', |
| 373 | controller: 'modalVendedoresCtrl', | 368 | controller: 'modalVendedoresCtrl', |
| 374 | size: 'lg' | 369 | size: 'lg' |
| 375 | } | 370 | } |
| 376 | ); | 371 | ); |
| 377 | modalInstance.result.then( | 372 | modalInstance.result.then( |
| 378 | function(vendedor) { | 373 | function(vendedor) { |
| 379 | $scope.$broadcast('addCabecera', { | 374 | $scope.$broadcast('addCabecera', { |
| 380 | label: 'Vendedor:', | 375 | label: 'Vendedor:', |
| 381 | valor: vendedor.NomVen | 376 | valor: vendedor.NomVen |
| 382 | }); | 377 | }); |
| 383 | $scope.notaPedido.vendedor = vendedor; | 378 | $scope.notaPedido.vendedor = vendedor; |
| 384 | }, function() { | 379 | }, function() { |
| 385 | 380 | ||
| 386 | } | 381 | } |
| 387 | ); | 382 | ); |
| 388 | } | 383 | } |
| 389 | }; | 384 | }; |
| 390 | 385 | ||
| 391 | $scope.seleccionarProveedor = function() { | 386 | $scope.seleccionarProveedor = function() { |
| 392 | if(validarNotaRemitada()) { | 387 | if(validarNotaRemitada()) { |
| 393 | var modalInstance = $uibModal.open( | 388 | var modalInstance = $uibModal.open( |
| 394 | { | 389 | { |
| 395 | ariaLabelledBy: 'Busqueda de Proveedor', | 390 | ariaLabelledBy: 'Busqueda de Proveedor', |
| 396 | templateUrl: 'modal-proveedor.html', | 391 | templateUrl: 'modal-proveedor.html', |
| 397 | controller: 'focaModalProveedorCtrl', | 392 | controller: 'focaModalProveedorCtrl', |
| 398 | size: 'lg', | 393 | size: 'lg', |
| 399 | resolve: { | 394 | resolve: { |
| 400 | transportista: function() { | 395 | transportista: function() { |
| 401 | return false; | 396 | return false; |
| 402 | } | 397 | } |
| 403 | } | 398 | } |
| 404 | } | 399 | } |
| 405 | ); | 400 | ); |
| 406 | modalInstance.result.then( | 401 | modalInstance.result.then( |
| 407 | function(proveedor) { | 402 | function(proveedor) { |
| 408 | $scope.notaPedido.proveedor = proveedor; | 403 | $scope.notaPedido.proveedor = proveedor; |
| 409 | $scope.$broadcast('addCabecera', { | 404 | $scope.$broadcast('addCabecera', { |
| 410 | label: 'Proveedor:', | 405 | label: 'Proveedor:', |
| 411 | valor: proveedor.NOM | 406 | valor: proveedor.NOM |
| 412 | }); | 407 | }); |
| 413 | }, function() { | 408 | }, function() { |
| 414 | 409 | ||
| 415 | } | 410 | } |
| 416 | ); | 411 | ); |
| 417 | } | 412 | } |
| 418 | }; | 413 | }; |
| 419 | 414 | ||
| 420 | $scope.seleccionarCliente = function() { | 415 | $scope.seleccionarCliente = function() { |
| 421 | if(validarNotaRemitada()) { | 416 | if(validarNotaRemitada()) { |
| 422 | var modalInstance = $uibModal.open( | 417 | var modalInstance = $uibModal.open( |
| 423 | { | 418 | { |
| 424 | ariaLabelledBy: 'Busqueda de Cliente', | 419 | ariaLabelledBy: 'Busqueda de Cliente', |
| 425 | templateUrl: 'foca-busqueda-cliente-modal.html', | 420 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 426 | controller: 'focaBusquedaClienteModalController', | 421 | controller: 'focaBusquedaClienteModalController', |
| 427 | size: 'lg' | 422 | size: 'lg' |
| 428 | } | 423 | } |
| 429 | ); | 424 | ); |
| 430 | modalInstance.result.then( | 425 | modalInstance.result.then( |
| 431 | function(cliente) { | 426 | function(cliente) { |
| 432 | $scope.abrirModalDomicilios(cliente); | 427 | $scope.abrirModalDomicilios(cliente); |
| 433 | }, function() { | 428 | }, function() { |
| 434 | 429 | ||
| 435 | } | 430 | } |
| 436 | ); | 431 | ); |
| 437 | } | 432 | } |
| 438 | }; | 433 | }; |
| 439 | 434 | ||
| 440 | $scope.abrirModalDomicilios = function(cliente) { | 435 | $scope.abrirModalDomicilios = function(cliente) { |
| 441 | var modalInstanceDomicilio = $uibModal.open( | 436 | var modalInstanceDomicilio = $uibModal.open( |
| 442 | { | 437 | { |
| 443 | ariaLabelledBy: 'Busqueda de Domicilios', | 438 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 444 | templateUrl: 'modal-domicilio.html', | 439 | templateUrl: 'modal-domicilio.html', |
| 445 | controller: 'focaModalDomicilioController', | 440 | controller: 'focaModalDomicilioController', |
| 446 | resolve: { idCliente: function() { return cliente.cod; }}, | 441 | resolve: { idCliente: function() { return cliente.cod; }}, |
| 447 | size: 'lg', | 442 | size: 'lg', |
| 448 | } | 443 | } |
| 449 | ); | 444 | ); |
| 450 | modalInstanceDomicilio.result.then( | 445 | modalInstanceDomicilio.result.then( |
| 451 | function(domicilio) { | 446 | function(domicilio) { |
| 452 | $scope.notaPedido.domicilio = domicilio; | 447 | $scope.notaPedido.domicilio = domicilio; |
| 453 | $scope.notaPedido.cliente = { | 448 | $scope.notaPedido.cliente = { |
| 454 | COD: cliente.cod, | 449 | COD: cliente.cod, |
| 455 | CUIT: cliente.cuit, | 450 | CUIT: cliente.cuit, |
| 456 | NOM: cliente.nom | 451 | NOM: cliente.nom |
| 457 | }; | 452 | }; |
| 458 | var domicilioStamp = | 453 | var domicilioStamp = |
| 459 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 454 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
| 460 | domicilio.Localidad + ', ' + domicilio.Provincia; | 455 | domicilio.Localidad + ', ' + domicilio.Provincia; |
| 461 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 456 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
| 462 | 457 | ||
| 463 | $scope.$broadcast('addCabecera', { | 458 | $scope.$broadcast('addCabecera', { |
| 464 | label: 'Cliente:', | 459 | label: 'Cliente:', |
| 465 | valor: cliente.nom | 460 | valor: cliente.nom |
| 466 | }); | 461 | }); |
| 467 | $scope.$broadcast('addCabecera', { | 462 | $scope.$broadcast('addCabecera', { |
| 468 | label: 'Domicilio:', | 463 | label: 'Domicilio:', |
| 469 | valor: domicilioStamp | 464 | valor: domicilioStamp |
| 470 | }); | 465 | }); |
| 471 | }, function() { | 466 | }, function() { |
| 472 | $scope.seleccionarCliente(); | 467 | $scope.seleccionarCliente(); |
| 473 | return; | 468 | return; |
| 474 | } | 469 | } |
| 475 | ); | 470 | ); |
| 476 | }; | 471 | }; |
| 477 | 472 | ||
| 478 | $scope.getTotal = function() { | 473 | $scope.getTotal = function() { |
| 479 | var total = 0; | 474 | var total = 0; |
| 480 | var arrayTempArticulos = $scope.articulosTabla; | 475 | var arrayTempArticulos = $scope.articulosTabla; |
| 481 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 476 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 482 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 477 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 483 | } | 478 | } |
| 484 | return parseFloat(total.toFixed(2)); | 479 | return parseFloat(total.toFixed(2)); |
| 485 | }; | 480 | }; |
| 486 | 481 | ||
| 487 | $scope.getSubTotal = function() { | 482 | $scope.getSubTotal = function() { |
| 488 | if($scope.articuloACargar) { | 483 | if($scope.articuloACargar) { |
| 489 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 484 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 490 | } | 485 | } |
| 491 | }; | 486 | }; |
| 492 | 487 | ||
| 493 | $scope.seleccionarPreciosYCondiciones = function() { | 488 | $scope.seleccionarPreciosYCondiciones = function() { |
| 494 | if(validarNotaRemitada()) { | 489 | if(validarNotaRemitada()) { |
| 495 | var modalInstance = $uibModal.open( | 490 | var modalInstance = $uibModal.open( |
| 496 | { | 491 | { |
| 497 | ariaLabelledBy: 'Busqueda de Precio Condición', | 492 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 498 | templateUrl: 'modal-precio-condicion.html', | 493 | templateUrl: 'modal-precio-condicion.html', |
| 499 | controller: 'focaModalPrecioCondicionController', | 494 | controller: 'focaModalPrecioCondicionController', |
| 500 | size: 'lg' | 495 | size: 'lg' |
| 501 | } | 496 | } |
| 502 | ); | 497 | ); |
| 503 | modalInstance.result.then( | 498 | modalInstance.result.then( |
| 504 | function(precioCondicion) { | 499 | function(precioCondicion) { |
| 505 | var cabecera = ''; | 500 | var cabecera = ''; |
| 506 | var plazosConcat = ''; | 501 | var plazosConcat = ''; |
| 507 | if(!Array.isArray(precioCondicion)) { | 502 | if(!Array.isArray(precioCondicion)) { |
| 508 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 503 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
| 509 | $scope.plazosPagos = precioCondicion.plazoPago; | 504 | $scope.plazosPagos = precioCondicion.plazoPago; |
| 510 | $scope.idLista = precioCondicion.idListaPrecio; | 505 | $scope.idLista = precioCondicion.idListaPrecio; |
| 511 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 506 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 512 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 507 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
| 513 | } | 508 | } |
| 514 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 509 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
| 515 | } else { //Cuando se ingresan los plazos manualmente | 510 | } else { //Cuando se ingresan los plazos manualmente |
| 516 | $scope.notaPedido.idPrecioCondicion = 0; | 511 | $scope.notaPedido.idPrecioCondicion = 0; |
| 517 | //-1, el modal productos busca todos los productos | 512 | //-1, el modal productos busca todos los productos |
| 518 | $scope.idLista = -1; | 513 | $scope.idLista = -1; |
| 519 | $scope.plazosPagos = precioCondicion; | 514 | $scope.plazosPagos = precioCondicion; |
| 520 | for(var j = 0; j < precioCondicion.length; j++) { | 515 | for(var j = 0; j < precioCondicion.length; j++) { |
| 521 | plazosConcat += precioCondicion[j].dias + ' '; | 516 | plazosConcat += precioCondicion[j].dias + ' '; |
| 522 | } | 517 | } |
| 523 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 518 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 524 | } | 519 | } |
| 525 | $scope.articulosTabla = []; | 520 | $scope.articulosTabla = []; |
| 526 | $scope.$broadcast('addCabecera', { | 521 | $scope.$broadcast('addCabecera', { |
| 527 | label: 'Precios y condiciones:', | 522 | label: 'Precios y condiciones:', |
| 528 | valor: cabecera | 523 | valor: cabecera |
| 529 | }); | 524 | }); |
| 530 | }, function() { | 525 | }, function() { |
| 531 | 526 | ||
| 532 | } | 527 | } |
| 533 | ); | 528 | ); |
| 534 | } | 529 | } |
| 535 | }; | 530 | }; |
| 536 | 531 | ||
| 537 | $scope.seleccionarFlete = function() { | 532 | $scope.seleccionarFlete = function() { |
| 538 | if(validarNotaRemitada()) { | 533 | if(validarNotaRemitada()) { |
| 539 | var modalInstance = $uibModal.open( | 534 | var modalInstance = $uibModal.open( |
| 540 | { | 535 | { |
| 541 | ariaLabelledBy: 'Busqueda de Flete', | 536 | ariaLabelledBy: 'Busqueda de Flete', |
| 542 | templateUrl: 'modal-flete.html', | 537 | templateUrl: 'modal-flete.html', |
| 543 | controller: 'focaModalFleteController', | 538 | controller: 'focaModalFleteController', |
| 544 | size: 'lg', | 539 | size: 'lg', |
| 545 | resolve: { | 540 | resolve: { |
| 546 | parametrosFlete: | 541 | parametrosFlete: |
| 547 | function() { | 542 | function() { |
| 548 | return { | 543 | return { |
| 549 | flete: $scope.notaPedido.fob ? 'FOB' : | 544 | flete: $scope.notaPedido.fob ? 'FOB' : |
| 550 | ( $scope.notaPedido.flete ? '1' : | 545 | ( $scope.notaPedido.flete ? '1' : |
| 551 | ($scope.notaPedido.flete === undefined ? | 546 | ($scope.notaPedido.flete === undefined ? |
| 552 | null : '0')), | 547 | null : '0')), |
| 553 | bomba: $scope.notaPedido.bomba ? '1' : | 548 | bomba: $scope.notaPedido.bomba ? '1' : |
| 554 | ($scope.notaPedido.bomba === undefined ? | 549 | ($scope.notaPedido.bomba === undefined ? |
| 555 | null : '0'), | 550 | null : '0'), |
| 556 | kilometros: $scope.notaPedido.kilometros | 551 | kilometros: $scope.notaPedido.kilometros |
| 557 | }; | 552 | }; |
| 558 | } | 553 | } |
| 559 | } | 554 | } |
| 560 | } | 555 | } |
| 561 | ); | 556 | ); |
| 562 | modalInstance.result.then( | 557 | modalInstance.result.then( |
| 563 | function(datos) { | 558 | function(datos) { |
| 564 | $scope.notaPedido.flete = datos.flete; | 559 | $scope.notaPedido.flete = datos.flete; |
| 565 | $scope.notaPedido.fob = datos.FOB; | 560 | $scope.notaPedido.fob = datos.FOB; |
| 566 | $scope.notaPedido.bomba = datos.bomba; | 561 | $scope.notaPedido.bomba = datos.bomba; |
| 567 | $scope.notaPedido.kilometros = datos.kilometros; | 562 | $scope.notaPedido.kilometros = datos.kilometros; |
| 568 | $scope.$broadcast('addCabecera', { | 563 | $scope.$broadcast('addCabecera', { |
| 569 | label: 'Flete:', | 564 | label: 'Flete:', |
| 570 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 565 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
| 571 | }); | 566 | }); |
| 572 | if(datos.flete) { | 567 | if(datos.flete) { |
| 573 | $scope.$broadcast('addCabecera', { | 568 | $scope.$broadcast('addCabecera', { |
| 574 | label: 'Bomba:', | 569 | label: 'Bomba:', |
| 575 | valor: datos.bomba ? 'Si' : 'No' | 570 | valor: datos.bomba ? 'Si' : 'No' |
| 576 | }); | 571 | }); |
| 577 | $scope.$broadcast('addCabecera', { | 572 | $scope.$broadcast('addCabecera', { |
| 578 | label: 'Kilometros:', | 573 | label: 'Kilometros:', |
| 579 | valor: datos.kilometros | 574 | valor: datos.kilometros |
| 580 | }); | 575 | }); |
| 581 | } else { | 576 | } else { |
| 582 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 577 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 583 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 578 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 584 | $scope.notaPedido.bomba = false; | 579 | $scope.notaPedido.bomba = false; |
| 585 | $scope.notaPedido.kilometros = null; | 580 | $scope.notaPedido.kilometros = null; |
| 586 | } | 581 | } |
| 587 | }, function() { | 582 | }, function() { |
| 588 | 583 | ||
| 589 | } | 584 | } |
| 590 | ); | 585 | ); |
| 591 | } | 586 | } |
| 592 | }; | 587 | }; |
| 593 | 588 | ||
| 594 | $scope.seleccionarMoneda = function() { | 589 | $scope.seleccionarMoneda = function() { |
| 595 | if(validarNotaRemitada()) { | 590 | if(validarNotaRemitada()) { |
| 596 | var modalInstance = $uibModal.open( | 591 | var modalInstance = $uibModal.open( |
| 597 | { | 592 | { |
| 598 | ariaLabelledBy: 'Busqueda de Moneda', | 593 | ariaLabelledBy: 'Busqueda de Moneda', |
| 599 | templateUrl: 'modal-moneda.html', | 594 | templateUrl: 'modal-moneda.html', |
| 600 | controller: 'focaModalMonedaController', | 595 | controller: 'focaModalMonedaController', |
| 601 | size: 'lg' | 596 | size: 'lg' |
| 602 | } | 597 | } |
| 603 | ); | 598 | ); |
| 604 | modalInstance.result.then( | 599 | modalInstance.result.then( |
| 605 | function(moneda) { | 600 | function(moneda) { |
| 606 | $scope.abrirModalCotizacion(moneda); | 601 | $scope.abrirModalCotizacion(moneda); |
| 607 | }, function() { | 602 | }, function() { |
| 608 | 603 | ||
| 609 | } | 604 | } |
| 610 | ); | 605 | ); |
| 611 | } | 606 | } |
| 612 | }; | 607 | }; |
| 613 | 608 | ||
| 614 | $scope.abrirModalCotizacion = function(moneda) { | 609 | $scope.abrirModalCotizacion = function(moneda) { |
| 615 | var modalInstance = $uibModal.open( | 610 | var modalInstance = $uibModal.open( |
| 616 | { | 611 | { |
| 617 | ariaLabelledBy: 'Busqueda de Cotización', | 612 | ariaLabelledBy: 'Busqueda de Cotización', |
| 618 | templateUrl: 'modal-cotizacion.html', | 613 | templateUrl: 'modal-cotizacion.html', |
| 619 | controller: 'focaModalCotizacionController', | 614 | controller: 'focaModalCotizacionController', |
| 620 | size: 'lg', | 615 | size: 'lg', |
| 621 | resolve: {idMoneda: function() {return moneda.ID;}} | 616 | resolve: {idMoneda: function() {return moneda.ID;}} |
| 622 | } | 617 | } |
| 623 | ); | 618 | ); |
| 624 | modalInstance.result.then( | 619 | modalInstance.result.then( |
| 625 | function(cotizacion) { | 620 | function(cotizacion) { |
| 626 | var articulosTablaTemp = $scope.articulosTabla; | 621 | var articulosTablaTemp = $scope.articulosTabla; |
| 627 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 622 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
| 628 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 623 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
| 629 | $scope.notaPedido.cotizacion.VENDEDOR; | 624 | $scope.notaPedido.cotizacion.VENDEDOR; |
| 630 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 625 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
| 631 | cotizacion.VENDEDOR; | 626 | cotizacion.VENDEDOR; |
| 632 | } | 627 | } |
| 633 | $scope.articulosTabla = articulosTablaTemp; | 628 | $scope.articulosTabla = articulosTablaTemp; |
| 634 | $scope.notaPedido.moneda = moneda; | 629 | $scope.notaPedido.moneda = moneda; |
| 635 | $scope.notaPedido.cotizacion = cotizacion; | 630 | $scope.notaPedido.cotizacion = cotizacion; |
| 636 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { | 631 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
| 637 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 632 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
| 638 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 633 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
| 639 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 634 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
| 640 | }else { | 635 | }else { |
| 641 | $scope.$broadcast('addCabecera', { | 636 | $scope.$broadcast('addCabecera', { |
| 642 | label: 'Moneda:', | 637 | label: 'Moneda:', |
| 643 | valor: moneda.DETALLE | 638 | valor: moneda.DETALLE |
| 644 | }); | 639 | }); |
| 645 | $scope.$broadcast('addCabecera', { | 640 | $scope.$broadcast('addCabecera', { |
| 646 | label: 'Fecha cotizacion:', | 641 | label: 'Fecha cotizacion:', |
| 647 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 642 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 648 | }); | 643 | }); |
| 649 | $scope.$broadcast('addCabecera', { | 644 | $scope.$broadcast('addCabecera', { |
| 650 | label: 'Cotizacion:', | 645 | label: 'Cotizacion:', |
| 651 | valor: cotizacion.VENDEDOR | 646 | valor: cotizacion.VENDEDOR |
| 652 | }); | 647 | }); |
| 653 | } | 648 | } |
| 654 | }, function() { | 649 | }, function() { |
| 655 | 650 | ||
| 656 | } | 651 | } |
| 657 | ); | 652 | ); |
| 658 | }; | 653 | }; |
| 659 | 654 | ||
| 660 | $scope.agregarATabla = function(key) { | 655 | $scope.agregarATabla = function(key) { |
| 661 | if(key === 13) { | 656 | if(key === 13) { |
| 662 | if($scope.articuloACargar.cantidad === undefined || | 657 | if($scope.articuloACargar.cantidad === undefined || |
| 663 | $scope.articuloACargar.cantidad === 0 || | 658 | $scope.articuloACargar.cantidad === 0 || |
| 664 | $scope.articuloACargar.cantidad === null ) { | 659 | $scope.articuloACargar.cantidad === null ) { |
| 665 | focaModalService.alert('El valor debe ser al menos 1'); | 660 | focaModalService.alert('El valor debe ser al menos 1'); |
| 666 | return; | 661 | return; |
| 667 | } | 662 | } |
| 668 | delete $scope.articuloACargar.sectorCodigo; | 663 | delete $scope.articuloACargar.sectorCodigo; |
| 669 | $scope.articulosTabla.push($scope.articuloACargar); | 664 | $scope.articulosTabla.push($scope.articuloACargar); |
| 670 | $scope.cargando = true; | 665 | $scope.cargando = true; |
| 671 | } | 666 | } |
| 672 | }; | 667 | }; |
| 673 | 668 | ||
| 674 | $scope.quitarArticulo = function(key) { | 669 | $scope.quitarArticulo = function(key) { |
| 675 | $scope.articulosTabla.splice(key, 1); | 670 | $scope.articulosTabla.splice(key, 1); |
| 676 | }; | 671 | }; |
| 677 | 672 | ||
| 678 | $scope.editarArticulo = function(key, articulo) { | 673 | $scope.editarArticulo = function(key, articulo) { |
| 679 | if(key === 13) { | 674 | if(key === 13) { |
| 680 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 675 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
| 681 | articulo.cantidad === undefined) { | 676 | articulo.cantidad === undefined) { |
| 682 | focaModalService.alert('El valor debe ser al menos 1'); | 677 | focaModalService.alert('El valor debe ser al menos 1'); |
| 683 | return; | 678 | return; |
| 684 | } | 679 | } |
| 685 | articulo.editCantidad = false; | 680 | articulo.editCantidad = false; |
| 686 | articulo.editPrecio = false; | 681 | articulo.editPrecio = false; |
| 687 | } | 682 | } |
| 688 | }; | 683 | }; |
| 689 | 684 | ||
| 690 | $scope.cambioEdit = function(articulo, propiedad) { | 685 | $scope.cambioEdit = function(articulo, propiedad) { |
| 691 | if(propiedad === 'cantidad') { | 686 | if(propiedad === 'cantidad') { |
| 692 | articulo.editCantidad = true; | 687 | articulo.editCantidad = true; |
| 693 | } else if(propiedad === 'precio') { | 688 | } else if(propiedad === 'precio') { |
| 694 | articulo.editPrecio = true; | 689 | articulo.editPrecio = true; |
| 695 | } | 690 | } |
| 696 | }; | 691 | }; |
| 697 | 692 | ||
| 698 | $scope.resetFilter = function() { | 693 | $scope.resetFilter = function() { |
| 699 | $scope.articuloACargar = {}; | 694 | $scope.articuloACargar = {}; |
| 700 | $scope.cargando = true; | 695 | $scope.cargando = true; |
| 701 | }; | 696 | }; |
| 702 | //Recibe aviso si el teclado está en uso | 697 | //Recibe aviso si el teclado está en uso |
| 703 | $rootScope.$on('usarTeclado', function(event, data) { | 698 | $rootScope.$on('usarTeclado', function(event, data) { |
| 704 | if(data) { | 699 | if(data) { |
| 705 | $scope.mostrarTeclado = true; | 700 | $scope.mostrarTeclado = true; |
| 706 | return; | 701 | return; |
| 707 | } | 702 | } |
| 708 | $scope.mostrarTeclado = false; | 703 | $scope.mostrarTeclado = false; |
| 709 | }); | 704 | }); |
| 710 | 705 | ||
| 711 | $scope.selectFocus = function($event) { | 706 | $scope.selectFocus = function($event) { |
| 712 | // Si el teclado esta en uso no selecciona el valor | 707 | // Si el teclado esta en uso no selecciona el valor |
| 713 | if($scope.mostrarTeclado) { | 708 | if($scope.mostrarTeclado) { |
| 714 | return; | 709 | return; |
| 715 | } | 710 | } |
| 716 | $event.target.select(); | 711 | $event.target.select(); |
| 717 | }; | 712 | }; |
| 718 | 713 | ||
| 719 | $scope.salir = function() { | 714 | $scope.salir = function() { |
| 720 | $location.path('/'); | 715 | $location.path('/'); |
| 721 | }; | 716 | }; |
| 722 | 717 | ||
| 723 | $scope.parsearATexto = function(articulo) { | 718 | $scope.parsearATexto = function(articulo) { |
| 724 | articulo.cantidad = parseFloat(articulo.cantidad); | 719 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 725 | articulo.precio = parseFloat(articulo.precio); | 720 | articulo.precio = parseFloat(articulo.precio); |
| 726 | }; | 721 | }; |
| 727 | 722 | ||
| 728 | function addArrayCabecera(array) { | 723 | function addArrayCabecera(array) { |
| 729 | for(var i = 0; i < array.length; i++) { | 724 | for(var i = 0; i < array.length; i++) { |
| 730 | $scope.$broadcast('addCabecera', { | 725 | $scope.$broadcast('addCabecera', { |
| 731 | label: array[i].label, | 726 | label: array[i].label, |
| 732 | valor: array[i].valor | 727 | valor: array[i].valor |
| 733 | }); | 728 | }); |
| 734 | } | 729 | } |
| 735 | } | 730 | } |
| 736 | 731 | ||
| 737 | function rellenar(relleno, longitud) { | 732 | function rellenar(relleno, longitud) { |
| 738 | relleno = '' + relleno; | 733 | relleno = '' + relleno; |
| 739 | while (relleno.length < longitud) { | 734 | while (relleno.length < longitud) { |
| 740 | relleno = '0' + relleno; | 735 | relleno = '0' + relleno; |
| 741 | } | 736 | } |
| 742 | 737 | ||
| 743 | return relleno; | 738 | return relleno; |
| 744 | } | 739 | } |
| 745 | 740 | ||
| 746 | function validarNotaRemitada() { | 741 | function validarNotaRemitada() { |
| 747 | if(!$scope.notaPedido.idRemito) { | 742 | if(!$scope.notaPedido.idRemito) { |
| 748 | return true; | 743 | return true; |
| 749 | }else{ | 744 | }else{ |
| 750 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 745 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
| 751 | return false; | 746 | return false; |
| 752 | } | 747 | } |
| 753 | } | 748 | } |
| 754 | } | 749 | } |
| 755 | ]); | 750 | ]); |
| 756 | 751 |