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