Commit 8dfc6e7d743bf50e05792e0615181e22dc77d7b2
Exists in
master
Merge branch 'master' into 'master'
Master See merge request !22
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(false); | 59 | focaBotoneraLateralService.showSalir(false); |
| 60 | focaBotoneraLateralService.showPausar(true); | 60 | focaBotoneraLateralService.showPausar(true); |
| 61 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 61 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
| 62 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 62 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 63 | }); | 63 | }); |
| 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 | $scope.saveLoading = true; | 113 | $scope.saveLoading = true; |
| 114 | var notaPedido = { | 114 | var notaPedido = { |
| 115 | id: $scope.notaPedido.id, | 115 | id: $scope.notaPedido.id, |
| 116 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | 116 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
| 117 | idVendedor: $scope.notaPedido.vendedor.CodVen, | 117 | idVendedor: $scope.notaPedido.vendedor.CodVen, |
| 118 | idCliente: $scope.notaPedido.cliente.COD, | 118 | idCliente: $scope.notaPedido.cliente.COD, |
| 119 | nombreCliente: $scope.notaPedido.cliente.NOM, | 119 | nombreCliente: $scope.notaPedido.cliente.NOM, |
| 120 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 120 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
| 121 | idProveedor: $scope.notaPedido.proveedor.COD, | 121 | idProveedor: $scope.notaPedido.proveedor.COD, |
| 122 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID | 122 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID |
| 123 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 123 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
| 124 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 124 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
| 125 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 125 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 126 | flete: $scope.notaPedido.flete, | 126 | flete: $scope.notaPedido.flete, |
| 127 | fob: $scope.notaPedido.fob, | 127 | fob: $scope.notaPedido.fob, |
| 128 | bomba: $scope.notaPedido.bomba, | 128 | bomba: $scope.notaPedido.bomba, |
| 129 | kilometros: $scope.notaPedido.kilometros, | 129 | kilometros: $scope.notaPedido.kilometros, |
| 130 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 130 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
| 131 | estado: 0, | 131 | estado: 0, |
| 132 | total: $scope.getTotal() | 132 | total: $scope.getTotal() |
| 133 | }; | 133 | }; |
| 134 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 134 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
| 135 | function(data) { | 135 | function(data) { |
| 136 | // Al guardar los datos de la nota de pedido logueamos la | 136 | // Al guardar los datos de la nota de pedido logueamos la |
| 137 | // actividad para su seguimiento. | 137 | // actividad para su seguimiento. |
| 138 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 138 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
| 139 | focaSeguimientoService.guardarPosicion( | 139 | focaSeguimientoService.guardarPosicion( |
| 140 | 'Nota de pedido', | 140 | 'Nota de pedido', |
| 141 | data.data.id, | 141 | data.data.id, |
| 142 | '' | 142 | '' |
| 143 | ); | 143 | ); |
| 144 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | 144 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, |
| 145 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 145 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
| 146 | 146 | ||
| 147 | if($scope.notaPedido.puntosDescarga) { | 147 | if($scope.notaPedido.puntosDescarga) { |
| 148 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 148 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
| 149 | $scope.notaPedido.puntosDescarga); | 149 | $scope.notaPedido.puntosDescarga); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | var plazos = $scope.plazosPagos; | 152 | var plazos = $scope.plazosPagos; |
| 153 | var plazosACrear = []; | 153 | var plazosACrear = []; |
| 154 | plazos.forEach(function(plazo) { | 154 | plazos.forEach(function(plazo) { |
| 155 | plazosACrear.push({ | 155 | plazosACrear.push({ |
| 156 | idNotaPedido: data.data.id, | 156 | idNotaPedido: data.data.id, |
| 157 | dias: plazo.dias | 157 | dias: plazo.dias |
| 158 | }); | 158 | }); |
| 159 | }); | 159 | }); |
| 160 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 160 | if(plazosACrear.length){ |
| 161 | 161 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | |
| 162 | notaPedidoBusinessService.addEstado(data.data.id, | 162 | } |
| 163 | $scope.notaPedido.vendedor.CodVen); | 163 | |
| 164 | 164 | notaPedidoBusinessService.addEstado(data.data.id, | |
| 165 | focaModalService.alert('Nota pedido creada'); | 165 | $scope.notaPedido.vendedor.CodVen); |
| 166 | |||
| 167 | focaModalService.alert('Nota pedido creada'); | ||
| 166 | $scope.saveLoading = false; | 168 | $scope.saveLoading = false; |
| 167 | $scope.$broadcast('cleanCabecera'); | 169 | $scope.$broadcast('cleanCabecera'); |
| 168 | $scope.$broadcast('addCabecera', { | 170 | $scope.$broadcast('addCabecera', { |
| 169 | label: 'Moneda:', | 171 | label: 'Moneda:', |
| 170 | valor: $scope.notaPedido.moneda.DETALLE | 172 | valor: $scope.notaPedido.moneda.DETALLE |
| 171 | }); | 173 | }); |
| 172 | $scope.$broadcast('addCabecera', { | 174 | $scope.$broadcast('addCabecera', { |
| 173 | label: 'Fecha cotizacion:', | 175 | label: 'Fecha cotizacion:', |
| 174 | valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') | 176 | valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
| 175 | }); | 177 | }); |
| 176 | $scope.$broadcast('addCabecera', { | 178 | $scope.$broadcast('addCabecera', { |
| 177 | label: 'Moneda:', | 179 | label: 'Moneda:', |
| 178 | valor: $scope.notaPedido.moneda.DETALLE | 180 | valor: $scope.notaPedido.moneda.DETALLE |
| 179 | }); | 181 | }); |
| 180 | $scope.$broadcast('addCabecera', { | 182 | $scope.$broadcast('addCabecera', { |
| 181 | label: 'Cotizacion:', | 183 | label: 'Cotizacion:', |
| 182 | valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2') | 184 | valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2') |
| 183 | }); | 185 | }); |
| 184 | crearNotaPedidoService.getNumeroNotaPedido().then( | 186 | crearNotaPedidoService.getNumeroNotaPedido().then( |
| 185 | function(res) { | 187 | function(res) { |
| 186 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 188 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
| 187 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 189 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
| 188 | }, | 190 | }, |
| 189 | function(err) { | 191 | function(err) { |
| 190 | focaModalService.alert( | 192 | focaModalService.alert( |
| 191 | 'La terminal no esta configurada correctamente'); | 193 | 'La terminal no esta configurada correctamente'); |
| 192 | console.info(err); | 194 | console.info(err); |
| 193 | } | 195 | } |
| 194 | ); | 196 | ); |
| 195 | $scope.notaPedido.vendedor = {}; | 197 | $scope.notaPedido.vendedor = {}; |
| 196 | $scope.notaPedido.cliente = {}; | 198 | $scope.notaPedido.cliente = {}; |
| 197 | $scope.notaPedido.proveedor = {}; | 199 | $scope.notaPedido.proveedor = {}; |
| 198 | $scope.notaPedido.domicilio = {}; | 200 | $scope.notaPedido.domicilio = {}; |
| 199 | $scope.notaPedido.flete = null; | 201 | $scope.notaPedido.flete = null; |
| 200 | $scope.notaPedido.fob = null; | 202 | $scope.notaPedido.fob = null; |
| 201 | $scope.notaPedido.bomba = null; | 203 | $scope.notaPedido.bomba = null; |
| 202 | $scope.notaPedido.kilometros = null; | 204 | $scope.notaPedido.kilometros = null; |
| 203 | $scope.articulosTabla = []; | 205 | $scope.articulosTabla = []; |
| 204 | }, | 206 | }, |
| 205 | function(error) { | 207 | function(error) { |
| 206 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 208 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 207 | $scope.saveLoading = false; | 209 | $scope.saveLoading = false; |
| 208 | console.info(error); | 210 | console.info(error); |
| 209 | } | 211 | } |
| 210 | ); | 212 | ); |
| 211 | }; | 213 | }; |
| 212 | 214 | ||
| 213 | $scope.seleccionarNotaPedido = function() { | 215 | $scope.seleccionarNotaPedido = function() { |
| 214 | var modalInstance = $uibModal.open( | 216 | var modalInstance = $uibModal.open( |
| 215 | { | 217 | { |
| 216 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 218 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
| 217 | templateUrl: 'foca-modal-nota-pedido.html', | 219 | templateUrl: 'foca-modal-nota-pedido.html', |
| 218 | controller: 'focaModalNotaPedidoController', | 220 | controller: 'focaModalNotaPedidoController', |
| 219 | size: 'lg', | 221 | size: 'lg', |
| 220 | resolve: {usadoPor: function() {return 'notaPedido';}} | 222 | resolve: {usadoPor: function() {return 'notaPedido';}} |
| 221 | } | 223 | } |
| 222 | ); | 224 | ); |
| 223 | modalInstance.result.then( | 225 | modalInstance.result.then( |
| 224 | function(notaPedido) { | 226 | function(notaPedido) { |
| 225 | $scope.now = new Date(notaPedido.fechaCarga); | 227 | $scope.now = new Date(notaPedido.fechaCarga); |
| 226 | //añado cabeceras | 228 | //añado cabeceras |
| 227 | $scope.notaPedido.id = notaPedido.id; | 229 | $scope.notaPedido.id = notaPedido.id; |
| 228 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 230 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 229 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 231 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 230 | var cabeceras = [ | 232 | var cabeceras = [ |
| 231 | { | 233 | { |
| 232 | label: 'Moneda:', | 234 | label: 'Moneda:', |
| 233 | valor: notaPedido.cotizacion.moneda.DETALLE | 235 | valor: notaPedido.cotizacion.moneda.DETALLE |
| 234 | }, | 236 | }, |
| 235 | { | 237 | { |
| 236 | label: 'Fecha cotizacion:', | 238 | label: 'Fecha cotizacion:', |
| 237 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 239 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
| 238 | 'dd/MM/yyyy') | 240 | 'dd/MM/yyyy') |
| 239 | }, | 241 | }, |
| 240 | { | 242 | { |
| 241 | label: 'Cotizacion:', | 243 | label: 'Cotizacion:', |
| 242 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 244 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
| 243 | '2') | 245 | '2') |
| 244 | }, | 246 | }, |
| 245 | { | 247 | { |
| 246 | label: 'Cliente:', | 248 | label: 'Cliente:', |
| 247 | valor: notaPedido.cliente.NOM | 249 | valor: notaPedido.cliente.NOM |
| 248 | }, | 250 | }, |
| 249 | { | 251 | { |
| 250 | label: 'Domicilio:', | 252 | label: 'Domicilio:', |
| 251 | valor: notaPedido.domicilioStamp | 253 | valor: notaPedido.domicilioStamp |
| 252 | }, | 254 | }, |
| 253 | { | 255 | { |
| 254 | label: 'Vendedor:', | 256 | label: 'Vendedor:', |
| 255 | valor: notaPedido.vendedor.NomVen | 257 | valor: notaPedido.vendedor.NomVen |
| 256 | }, | 258 | }, |
| 257 | { | 259 | { |
| 258 | label: 'Proveedor:', | 260 | label: 'Proveedor:', |
| 259 | valor: notaPedido.proveedor.NOM | 261 | valor: notaPedido.proveedor.NOM |
| 260 | }, | 262 | }, |
| 261 | { | 263 | { |
| 262 | label: 'Precios y condiciones:', | 264 | label: 'Precios y condiciones:', |
| 263 | valor: valorPrecioCondicion() + ' ' + | 265 | valor: valorPrecioCondicion() + ' ' + |
| 264 | notaPedidoBusinessService | 266 | notaPedidoBusinessService |
| 265 | .plazoToString(notaPedido.notaPedidoPlazo) | 267 | .plazoToString(notaPedido.notaPedidoPlazo) |
| 266 | }, | 268 | }, |
| 267 | { | 269 | { |
| 268 | label: 'Flete:', | 270 | label: 'Flete:', |
| 269 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 271 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
| 270 | notaPedido.flete === 1 ? 'Si' : 'No') | 272 | notaPedido.flete === 1 ? 'Si' : 'No') |
| 271 | } | 273 | } |
| 272 | ]; | 274 | ]; |
| 273 | 275 | ||
| 274 | function valorPrecioCondicion() { | 276 | function valorPrecioCondicion() { |
| 275 | if(notaPedido.idPrecioCondicion > 0) { | 277 | if(notaPedido.idPrecioCondicion > 0) { |
| 276 | return notaPedido.precioCondicion.nombre; | 278 | return notaPedido.precioCondicion.nombre; |
| 277 | } else { | 279 | } else { |
| 278 | return 'Ingreso Manual'; | 280 | return 'Ingreso Manual'; |
| 279 | } | 281 | } |
| 280 | } | 282 | } |
| 281 | 283 | ||
| 282 | if(notaPedido.flete === 1) { | 284 | if(notaPedido.flete === 1) { |
| 283 | var cabeceraBomba = { | 285 | var cabeceraBomba = { |
| 284 | label: 'Bomba:', | 286 | label: 'Bomba:', |
| 285 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 287 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
| 286 | }; | 288 | }; |
| 287 | if(notaPedido.kilometros) { | 289 | if(notaPedido.kilometros) { |
| 288 | var cabeceraKilometros = { | 290 | var cabeceraKilometros = { |
| 289 | label: 'Kilometros:', | 291 | label: 'Kilometros:', |
| 290 | valor: notaPedido.kilometros | 292 | valor: notaPedido.kilometros |
| 291 | }; | 293 | }; |
| 292 | cabeceras.push(cabeceraKilometros); | 294 | cabeceras.push(cabeceraKilometros); |
| 293 | } | 295 | } |
| 294 | cabeceras.push(cabeceraBomba); | 296 | cabeceras.push(cabeceraBomba); |
| 295 | } | 297 | } |
| 296 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 298 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
| 297 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, | 299 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, |
| 298 | notaPedido.cotizacion.VENDEDOR); | 300 | notaPedido.cotizacion.VENDEDOR); |
| 299 | if(notaPedido.idPrecioCondicion > 0) { | 301 | if(notaPedido.idPrecioCondicion > 0) { |
| 300 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 302 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
| 301 | } else { | 303 | } else { |
| 302 | $scope.idLista = -1; | 304 | $scope.idLista = -1; |
| 303 | } | 305 | } |
| 304 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); | 306 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); |
| 305 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); | 307 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); |
| 306 | $scope.notaPedido = notaPedido; | 308 | $scope.notaPedido = notaPedido; |
| 307 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; | 309 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; |
| 308 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; | 310 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; |
| 309 | $scope.notaPedido.puntosDescarga = | 311 | $scope.notaPedido.puntosDescarga = |
| 310 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); | 312 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); |
| 311 | addArrayCabecera(cabeceras); | 313 | addArrayCabecera(cabeceras); |
| 312 | 314 | ||
| 313 | }, function() { | 315 | }, function() { |
| 314 | // funcion ejecutada cuando se cancela el modal | 316 | // funcion ejecutada cuando se cancela el modal |
| 315 | } | 317 | } |
| 316 | ); | 318 | ); |
| 317 | }; | 319 | }; |
| 318 | 320 | ||
| 319 | $scope.seleccionarProductos = function() { | 321 | $scope.seleccionarProductos = function() { |
| 320 | if ($scope.idLista === undefined) { | 322 | if ($scope.idLista === undefined) { |
| 321 | focaModalService.alert( | 323 | focaModalService.alert( |
| 322 | 'Primero seleccione una lista de precio y condicion'); | 324 | 'Primero seleccione una lista de precio y condicion'); |
| 323 | return; | 325 | return; |
| 324 | } | 326 | } |
| 325 | var modalInstance = $uibModal.open( | 327 | var modalInstance = $uibModal.open( |
| 326 | { | 328 | { |
| 327 | ariaLabelledBy: 'Busqueda de Productos', | 329 | ariaLabelledBy: 'Busqueda de Productos', |
| 328 | templateUrl: 'modal-busqueda-productos.html', | 330 | templateUrl: 'modal-busqueda-productos.html', |
| 329 | controller: 'modalBusquedaProductosCtrl', | 331 | controller: 'modalBusquedaProductosCtrl', |
| 330 | resolve: { | 332 | resolve: { |
| 331 | parametroProducto: { | 333 | parametroProducto: { |
| 332 | idLista: $scope.idLista, | 334 | idLista: $scope.idLista, |
| 333 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 335 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 334 | simbolo: $scope.notaPedido.moneda.SIMBOLO | 336 | simbolo: $scope.notaPedido.moneda.SIMBOLO |
| 335 | } | 337 | } |
| 336 | }, | 338 | }, |
| 337 | size: 'lg' | 339 | size: 'lg' |
| 338 | } | 340 | } |
| 339 | ); | 341 | ); |
| 340 | modalInstance.result.then( | 342 | modalInstance.result.then( |
| 341 | function(producto) { | 343 | function(producto) { |
| 342 | var newArt = | 344 | var newArt = |
| 343 | { | 345 | { |
| 344 | id: 0, | 346 | id: 0, |
| 345 | codigo: producto.codigo, | 347 | codigo: producto.codigo, |
| 346 | sector: producto.sector, | 348 | sector: producto.sector, |
| 347 | sectorCodigo: producto.sector + '-' + producto.codigo, | 349 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 348 | descripcion: producto.descripcion, | 350 | descripcion: producto.descripcion, |
| 349 | item: $scope.articulosTabla.length + 1, | 351 | item: $scope.articulosTabla.length + 1, |
| 350 | nombre: producto.descripcion, | 352 | nombre: producto.descripcion, |
| 351 | precio: parseFloat(producto.precio.toFixed(4)), | 353 | precio: parseFloat(producto.precio.toFixed(4)), |
| 352 | costoUnitario: producto.costo, | 354 | costoUnitario: producto.costo, |
| 353 | editCantidad: false, | 355 | editCantidad: false, |
| 354 | editPrecio: false, | 356 | editPrecio: false, |
| 355 | rubro: producto.CodRub, | 357 | rubro: producto.CodRub, |
| 356 | exentoUnitario: producto.precio, | 358 | exentoUnitario: producto.precio, |
| 357 | ivaUnitario: producto.IMPIVA, | 359 | ivaUnitario: producto.IMPIVA, |
| 358 | impuestoInternoUnitario: producto.ImpInt, | 360 | impuestoInternoUnitario: producto.ImpInt, |
| 359 | impuestoInterno1Unitario: producto.ImpInt2, | 361 | impuestoInterno1Unitario: producto.ImpInt2, |
| 360 | impuestoInterno2Unitario: producto.ImpInt3, | 362 | impuestoInterno2Unitario: producto.ImpInt3, |
| 361 | precioLista: producto.precio, | 363 | precioLista: producto.precio, |
| 362 | combustible: 1, | 364 | combustible: 1, |
| 363 | facturado: 0, | 365 | facturado: 0, |
| 364 | idArticulo: producto.id | 366 | idArticulo: producto.id |
| 365 | }; | 367 | }; |
| 366 | $scope.articuloACargar = newArt; | 368 | $scope.articuloACargar = newArt; |
| 367 | $scope.cargando = false; | 369 | $scope.cargando = false; |
| 368 | }, function() { | 370 | }, function() { |
| 369 | // funcion ejecutada cuando se cancela el modal | 371 | // funcion ejecutada cuando se cancela el modal |
| 370 | } | 372 | } |
| 371 | ); | 373 | ); |
| 372 | }; | 374 | }; |
| 373 | 375 | ||
| 374 | $scope.seleccionarPuntosDeDescarga = function() { | 376 | $scope.seleccionarPuntosDeDescarga = function() { |
| 375 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 377 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
| 376 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 378 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
| 377 | return; | 379 | return; |
| 378 | }else { | 380 | }else { |
| 379 | var modalInstance = $uibModal.open( | 381 | var modalInstance = $uibModal.open( |
| 380 | { | 382 | { |
| 381 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 383 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
| 382 | templateUrl: 'modal-punto-descarga.html', | 384 | templateUrl: 'modal-punto-descarga.html', |
| 383 | controller: 'focaModalPuntoDescargaController', | 385 | controller: 'focaModalPuntoDescargaController', |
| 384 | size: 'lg', | 386 | size: 'lg', |
| 385 | resolve: { | 387 | resolve: { |
| 386 | filters: { | 388 | filters: { |
| 387 | /*TODO: al traer nota de pedido ya creada | 389 | /*TODO: al traer nota de pedido ya creada |
| 388 | obtener idDomicilio correctamente*/ | 390 | obtener idDomicilio correctamente*/ |
| 389 | idDomicilio: $scope.notaPedido.domicilio.id, | 391 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 390 | idCliente: $scope.notaPedido.cliente.COD, | 392 | idCliente: $scope.notaPedido.cliente.COD, |
| 391 | articulos: $scope.articulosTabla, | 393 | articulos: $scope.articulosTabla, |
| 392 | puntosDescarga: $scope.notaPedido.puntosDescarga | 394 | puntosDescarga: $scope.notaPedido.puntosDescarga |
| 393 | } | 395 | } |
| 394 | } | 396 | } |
| 395 | } | 397 | } |
| 396 | ); | 398 | ); |
| 397 | modalInstance.result.then( | 399 | modalInstance.result.then( |
| 398 | function(puntosDescarga) { | 400 | function(puntosDescarga) { |
| 399 | $scope.notaPedido.puntosDescarga = puntosDescarga; | 401 | $scope.notaPedido.puntosDescarga = puntosDescarga; |
| 400 | }, function() { | 402 | }, function() { |
| 401 | 403 | ||
| 402 | } | 404 | } |
| 403 | ); | 405 | ); |
| 404 | } | 406 | } |
| 405 | }; | 407 | }; |
| 406 | 408 | ||
| 407 | $scope.seleccionarVendedor = function() { | 409 | $scope.seleccionarVendedor = function() { |
| 408 | if(validarNotaRemitada()) { | 410 | if(validarNotaRemitada()) { |
| 409 | var modalInstance = $uibModal.open( | 411 | var modalInstance = $uibModal.open( |
| 410 | { | 412 | { |
| 411 | ariaLabelledBy: 'Busqueda de Vendedores', | 413 | ariaLabelledBy: 'Busqueda de Vendedores', |
| 412 | templateUrl: 'modal-vendedores.html', | 414 | templateUrl: 'modal-vendedores.html', |
| 413 | controller: 'modalVendedoresCtrl', | 415 | controller: 'modalVendedoresCtrl', |
| 414 | size: 'lg' | 416 | size: 'lg' |
| 415 | } | 417 | } |
| 416 | ); | 418 | ); |
| 417 | modalInstance.result.then( | 419 | modalInstance.result.then( |
| 418 | function(vendedor) { | 420 | function(vendedor) { |
| 419 | $scope.$broadcast('addCabecera', { | 421 | $scope.$broadcast('addCabecera', { |
| 420 | label: 'Vendedor:', | 422 | label: 'Vendedor:', |
| 421 | valor: vendedor.NomVen | 423 | valor: vendedor.NomVen |
| 422 | }); | 424 | }); |
| 423 | $scope.notaPedido.vendedor = vendedor; | 425 | $scope.notaPedido.vendedor = vendedor; |
| 424 | }, function() { | 426 | }, function() { |
| 425 | 427 | ||
| 426 | } | 428 | } |
| 427 | ); | 429 | ); |
| 428 | } | 430 | } |
| 429 | }; | 431 | }; |
| 430 | 432 | ||
| 431 | $scope.seleccionarProveedor = function() { | 433 | $scope.seleccionarProveedor = function() { |
| 432 | if(validarNotaRemitada()) { | 434 | if(validarNotaRemitada()) { |
| 433 | var modalInstance = $uibModal.open( | 435 | var modalInstance = $uibModal.open( |
| 434 | { | 436 | { |
| 435 | ariaLabelledBy: 'Busqueda de Proveedor', | 437 | ariaLabelledBy: 'Busqueda de Proveedor', |
| 436 | templateUrl: 'modal-proveedor.html', | 438 | templateUrl: 'modal-proveedor.html', |
| 437 | controller: 'focaModalProveedorCtrl', | 439 | controller: 'focaModalProveedorCtrl', |
| 438 | size: 'lg', | 440 | size: 'lg', |
| 439 | resolve: { | 441 | resolve: { |
| 440 | transportista: function() { | 442 | transportista: function() { |
| 441 | return false; | 443 | return false; |
| 442 | } | 444 | } |
| 443 | } | 445 | } |
| 444 | } | 446 | } |
| 445 | ); | 447 | ); |
| 446 | modalInstance.result.then( | 448 | modalInstance.result.then( |
| 447 | function(proveedor) { | 449 | function(proveedor) { |
| 448 | $scope.notaPedido.proveedor = proveedor; | 450 | $scope.notaPedido.proveedor = proveedor; |
| 449 | $scope.$broadcast('addCabecera', { | 451 | $scope.$broadcast('addCabecera', { |
| 450 | label: 'Proveedor:', | 452 | label: 'Proveedor:', |
| 451 | valor: proveedor.NOM | 453 | valor: proveedor.NOM |
| 452 | }); | 454 | }); |
| 453 | }, function() { | 455 | }, function() { |
| 454 | 456 | ||
| 455 | } | 457 | } |
| 456 | ); | 458 | ); |
| 457 | } | 459 | } |
| 458 | }; | 460 | }; |
| 459 | 461 | ||
| 460 | $scope.seleccionarCliente = function() { | 462 | $scope.seleccionarCliente = function() { |
| 461 | if(validarNotaRemitada()) { | 463 | if(validarNotaRemitada()) { |
| 462 | var modalInstance = $uibModal.open( | 464 | var modalInstance = $uibModal.open( |
| 463 | { | 465 | { |
| 464 | ariaLabelledBy: 'Busqueda de Cliente', | 466 | ariaLabelledBy: 'Busqueda de Cliente', |
| 465 | templateUrl: 'foca-busqueda-cliente-modal.html', | 467 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 466 | controller: 'focaBusquedaClienteModalController', | 468 | controller: 'focaBusquedaClienteModalController', |
| 467 | size: 'lg' | 469 | size: 'lg' |
| 468 | } | 470 | } |
| 469 | ); | 471 | ); |
| 470 | modalInstance.result.then( | 472 | modalInstance.result.then( |
| 471 | function(cliente) { | 473 | function(cliente) { |
| 472 | $scope.abrirModalDomicilios(cliente); | 474 | $scope.abrirModalDomicilios(cliente); |
| 473 | }, function() { | 475 | }, function() { |
| 474 | 476 | ||
| 475 | } | 477 | } |
| 476 | ); | 478 | ); |
| 477 | } | 479 | } |
| 478 | }; | 480 | }; |
| 479 | 481 | ||
| 480 | $scope.abrirModalDomicilios = function(cliente) { | 482 | $scope.abrirModalDomicilios = function(cliente) { |
| 481 | var modalInstanceDomicilio = $uibModal.open( | 483 | var modalInstanceDomicilio = $uibModal.open( |
| 482 | { | 484 | { |
| 483 | ariaLabelledBy: 'Busqueda de Domicilios', | 485 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 484 | templateUrl: 'modal-domicilio.html', | 486 | templateUrl: 'modal-domicilio.html', |
| 485 | controller: 'focaModalDomicilioController', | 487 | controller: 'focaModalDomicilioController', |
| 486 | resolve: { | 488 | resolve: { |
| 487 | idCliente: function() { | 489 | idCliente: function() { |
| 488 | return cliente.cod; | 490 | return cliente.cod; |
| 489 | }, | 491 | }, |
| 490 | esNuevo: function() { return cliente.esNuevo; }, | 492 | esNuevo: function() { return cliente.esNuevo; }, |
| 491 | articulos: function() { | 493 | articulos: function() { |
| 492 | return $scope.articulosTabla; | 494 | return $scope.articulosTabla; |
| 493 | } | 495 | } |
| 494 | }, | 496 | }, |
| 495 | size: 'lg', | 497 | size: 'lg', |
| 496 | } | 498 | } |
| 497 | ); | 499 | ); |
| 498 | modalInstanceDomicilio.result.then( | 500 | modalInstanceDomicilio.result.then( |
| 499 | function(domicilio) { | 501 | function(domicilio) { |
| 500 | $scope.notaPedido.domicilio = domicilio; | 502 | $scope.notaPedido.domicilio = domicilio; |
| 501 | $scope.notaPedido.cliente = { | 503 | $scope.notaPedido.cliente = { |
| 502 | COD: cliente.cod, | 504 | COD: cliente.cod, |
| 503 | CUIT: cliente.cuit, | 505 | CUIT: cliente.cuit, |
| 504 | NOM: cliente.nom | 506 | NOM: cliente.nom |
| 505 | }; | 507 | }; |
| 506 | var domicilioStamp = | 508 | var domicilioStamp = |
| 507 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 509 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
| 508 | domicilio.Localidad + ', ' + domicilio.Provincia; | 510 | domicilio.Localidad + ', ' + domicilio.Provincia; |
| 509 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 511 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
| 510 | 512 | ||
| 511 | $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; | 513 | $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; |
| 512 | 514 | ||
| 513 | $scope.$broadcast('addCabecera', { | 515 | $scope.$broadcast('addCabecera', { |
| 514 | label: 'Cliente:', | 516 | label: 'Cliente:', |
| 515 | valor: cliente.nom | 517 | valor: cliente.nom |
| 516 | }); | 518 | }); |
| 517 | $scope.$broadcast('addCabecera', { | 519 | $scope.$broadcast('addCabecera', { |
| 518 | label: 'Domicilio:', | 520 | label: 'Domicilio:', |
| 519 | valor: domicilioStamp | 521 | valor: domicilioStamp |
| 520 | }); | 522 | }); |
| 521 | }, function() { | 523 | }, function() { |
| 522 | $scope.seleccionarCliente(); | 524 | $scope.seleccionarCliente(); |
| 523 | return; | 525 | return; |
| 524 | } | 526 | } |
| 525 | ); | 527 | ); |
| 526 | }; | 528 | }; |
| 527 | 529 | ||
| 528 | $scope.getTotal = function() { | 530 | $scope.getTotal = function() { |
| 529 | var total = 0; | 531 | var total = 0; |
| 530 | var arrayTempArticulos = $scope.articulosTabla; | 532 | var arrayTempArticulos = $scope.articulosTabla; |
| 531 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 533 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 532 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 534 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 533 | } | 535 | } |
| 534 | return parseFloat(total.toFixed(2)); | 536 | return parseFloat(total.toFixed(2)); |
| 535 | }; | 537 | }; |
| 536 | 538 | ||
| 537 | $scope.getSubTotal = function() { | 539 | $scope.getSubTotal = function() { |
| 538 | if($scope.articuloACargar) { | 540 | if($scope.articuloACargar) { |
| 539 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 541 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 540 | } | 542 | } |
| 541 | }; | 543 | }; |
| 542 | 544 | ||
| 543 | $scope.seleccionarPreciosYCondiciones = function() { | 545 | $scope.seleccionarPreciosYCondiciones = function() { |
| 544 | if(validarNotaRemitada()) { | 546 | if(validarNotaRemitada()) { |
| 545 | var modalInstance = $uibModal.open( | 547 | var modalInstance = $uibModal.open( |
| 546 | { | 548 | { |
| 547 | ariaLabelledBy: 'Busqueda de Precio Condición', | 549 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 548 | templateUrl: 'modal-precio-condicion.html', | 550 | templateUrl: 'modal-precio-condicion.html', |
| 549 | controller: 'focaModalPrecioCondicionController', | 551 | controller: 'focaModalPrecioCondicionController', |
| 550 | size: 'lg' | 552 | size: 'lg' |
| 551 | } | 553 | } |
| 552 | ); | 554 | ); |
| 553 | modalInstance.result.then( | 555 | modalInstance.result.then( |
| 554 | function(precioCondicion) { | 556 | function(precioCondicion) { |
| 555 | var cabecera = ''; | 557 | var cabecera = ''; |
| 556 | var plazosConcat = ''; | 558 | var plazosConcat = ''; |
| 557 | if(!Array.isArray(precioCondicion)) { | 559 | if(!Array.isArray(precioCondicion)) { |
| 558 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 560 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
| 559 | $scope.plazosPagos = precioCondicion.plazoPago; | 561 | $scope.plazosPagos = precioCondicion.plazoPago; |
| 560 | $scope.idLista = precioCondicion.idListaPrecio; | 562 | $scope.idLista = precioCondicion.idListaPrecio; |
| 561 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 563 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 562 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 564 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
| 563 | } | 565 | } |
| 564 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 566 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
| 565 | } else { //Cuando se ingresan los plazos manualmente | 567 | } else { //Cuando se ingresan los plazos manualmente |
| 566 | $scope.notaPedido.idPrecioCondicion = 0; | 568 | $scope.notaPedido.idPrecioCondicion = 0; |
| 567 | //-1, el modal productos busca todos los productos | 569 | //-1, el modal productos busca todos los productos |
| 568 | $scope.idLista = -1; | 570 | $scope.idLista = -1; |
| 569 | $scope.plazosPagos = precioCondicion; | 571 | $scope.plazosPagos = precioCondicion; |
| 570 | for(var j = 0; j < precioCondicion.length; j++) { | 572 | for(var j = 0; j < precioCondicion.length; j++) { |
| 571 | plazosConcat += precioCondicion[j].dias + ' '; | 573 | plazosConcat += precioCondicion[j].dias + ' '; |
| 572 | } | 574 | } |
| 573 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 575 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 574 | } | 576 | } |
| 575 | $scope.articulosTabla = []; | 577 | $scope.articulosTabla = []; |
| 576 | $scope.$broadcast('addCabecera', { | 578 | $scope.$broadcast('addCabecera', { |
| 577 | label: 'Precios y condiciones:', | 579 | label: 'Precios y condiciones:', |
| 578 | valor: cabecera | 580 | valor: cabecera |
| 579 | }); | 581 | }); |
| 580 | }, function() { | 582 | }, function() { |
| 581 | 583 | ||
| 582 | } | 584 | } |
| 583 | ); | 585 | ); |
| 584 | } | 586 | } |
| 585 | }; | 587 | }; |
| 586 | 588 | ||
| 587 | $scope.seleccionarFlete = function() { | 589 | $scope.seleccionarFlete = function() { |
| 588 | if(validarNotaRemitada()) { | 590 | if(validarNotaRemitada()) { |
| 589 | var modalInstance = $uibModal.open( | 591 | var modalInstance = $uibModal.open( |
| 590 | { | 592 | { |
| 591 | ariaLabelledBy: 'Busqueda de Flete', | 593 | ariaLabelledBy: 'Busqueda de Flete', |
| 592 | templateUrl: 'modal-flete.html', | 594 | templateUrl: 'modal-flete.html', |
| 593 | controller: 'focaModalFleteController', | 595 | controller: 'focaModalFleteController', |
| 594 | size: 'lg', | 596 | size: 'lg', |
| 595 | resolve: { | 597 | resolve: { |
| 596 | parametrosFlete: | 598 | parametrosFlete: |
| 597 | function() { | 599 | function() { |
| 598 | return { | 600 | return { |
| 599 | flete: $scope.notaPedido.fob ? 'FOB' : | 601 | flete: $scope.notaPedido.fob ? 'FOB' : |
| 600 | ( $scope.notaPedido.flete ? '1' : | 602 | ( $scope.notaPedido.flete ? '1' : |
| 601 | ($scope.notaPedido.flete === undefined ? | 603 | ($scope.notaPedido.flete === undefined ? |
| 602 | null : '0')), | 604 | null : '0')), |
| 603 | bomba: $scope.notaPedido.bomba ? '1' : | 605 | bomba: $scope.notaPedido.bomba ? '1' : |
| 604 | ($scope.notaPedido.bomba === undefined ? | 606 | ($scope.notaPedido.bomba === undefined ? |
| 605 | null : '0'), | 607 | null : '0'), |
| 606 | kilometros: $scope.notaPedido.kilometros | 608 | kilometros: $scope.notaPedido.kilometros |
| 607 | }; | 609 | }; |
| 608 | } | 610 | } |
| 609 | } | 611 | } |
| 610 | } | 612 | } |
| 611 | ); | 613 | ); |
| 612 | modalInstance.result.then( | 614 | modalInstance.result.then( |
| 613 | function(datos) { | 615 | function(datos) { |
| 614 | $scope.notaPedido.flete = datos.flete; | 616 | $scope.notaPedido.flete = datos.flete; |
| 615 | $scope.notaPedido.fob = datos.FOB; | 617 | $scope.notaPedido.fob = datos.FOB; |
| 616 | $scope.notaPedido.bomba = datos.bomba; | 618 | $scope.notaPedido.bomba = datos.bomba; |
| 617 | $scope.notaPedido.kilometros = datos.kilometros; | 619 | $scope.notaPedido.kilometros = datos.kilometros; |
| 618 | $scope.$broadcast('addCabecera', { | 620 | $scope.$broadcast('addCabecera', { |
| 619 | label: 'Flete:', | 621 | label: 'Flete:', |
| 620 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 622 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
| 621 | }); | 623 | }); |
| 622 | if(datos.flete) { | 624 | if(datos.flete) { |
| 623 | $scope.$broadcast('addCabecera', { | 625 | $scope.$broadcast('addCabecera', { |
| 624 | label: 'Bomba:', | 626 | label: 'Bomba:', |
| 625 | valor: datos.bomba ? 'Si' : 'No' | 627 | valor: datos.bomba ? 'Si' : 'No' |
| 626 | }); | 628 | }); |
| 627 | $scope.$broadcast('addCabecera', { | 629 | $scope.$broadcast('addCabecera', { |
| 628 | label: 'Kilometros:', | 630 | label: 'Kilometros:', |
| 629 | valor: datos.kilometros | 631 | valor: datos.kilometros |
| 630 | }); | 632 | }); |
| 631 | } else { | 633 | } else { |
| 632 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 634 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 633 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 635 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 634 | $scope.notaPedido.bomba = false; | 636 | $scope.notaPedido.bomba = false; |
| 635 | $scope.notaPedido.kilometros = null; | 637 | $scope.notaPedido.kilometros = null; |
| 636 | } | 638 | } |
| 637 | }, function() { | 639 | }, function() { |
| 638 | 640 | ||
| 639 | } | 641 | } |
| 640 | ); | 642 | ); |
| 641 | } | 643 | } |
| 642 | }; | 644 | }; |
| 643 | 645 | ||
| 644 | $scope.seleccionarMoneda = function() { | 646 | $scope.seleccionarMoneda = function() { |
| 645 | if(validarNotaRemitada()) { | 647 | if(validarNotaRemitada()) { |
| 646 | var modalInstance = $uibModal.open( | 648 | var modalInstance = $uibModal.open( |
| 647 | { | 649 | { |
| 648 | ariaLabelledBy: 'Busqueda de Moneda', | 650 | ariaLabelledBy: 'Busqueda de Moneda', |
| 649 | templateUrl: 'modal-moneda.html', | 651 | templateUrl: 'modal-moneda.html', |
| 650 | controller: 'focaModalMonedaController', | 652 | controller: 'focaModalMonedaController', |
| 651 | size: 'lg' | 653 | size: 'lg' |
| 652 | } | 654 | } |
| 653 | ); | 655 | ); |
| 654 | modalInstance.result.then( | 656 | modalInstance.result.then( |
| 655 | function(moneda) { | 657 | function(moneda) { |
| 656 | $scope.abrirModalCotizacion(moneda); | 658 | $scope.abrirModalCotizacion(moneda); |
| 657 | }, function() { | 659 | }, function() { |
| 658 | 660 | ||
| 659 | } | 661 | } |
| 660 | ); | 662 | ); |
| 661 | } | 663 | } |
| 662 | }; | 664 | }; |
| 663 | 665 | ||
| 664 | $scope.abrirModalCotizacion = function(moneda) { | 666 | $scope.abrirModalCotizacion = function(moneda) { |
| 665 | var modalInstance = $uibModal.open( | 667 | var modalInstance = $uibModal.open( |
| 666 | { | 668 | { |
| 667 | ariaLabelledBy: 'Busqueda de Cotización', | 669 | ariaLabelledBy: 'Busqueda de Cotización', |
| 668 | templateUrl: 'modal-cotizacion.html', | 670 | templateUrl: 'modal-cotizacion.html', |
| 669 | controller: 'focaModalCotizacionController', | 671 | controller: 'focaModalCotizacionController', |
| 670 | size: 'lg', | 672 | size: 'lg', |
| 671 | resolve: {idMoneda: function() {return moneda.ID;}} | 673 | resolve: {idMoneda: function() {return moneda.ID;}} |
| 672 | } | 674 | } |
| 673 | ); | 675 | ); |
| 674 | modalInstance.result.then( | 676 | modalInstance.result.then( |
| 675 | function(cotizacion) { | 677 | function(cotizacion) { |
| 676 | var articulosTablaTemp = $scope.articulosTabla; | 678 | var articulosTablaTemp = $scope.articulosTabla; |
| 677 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 679 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
| 678 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 680 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
| 679 | $scope.notaPedido.cotizacion.VENDEDOR; | 681 | $scope.notaPedido.cotizacion.VENDEDOR; |
| 680 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 682 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
| 681 | cotizacion.VENDEDOR; | 683 | cotizacion.VENDEDOR; |
| 682 | } | 684 | } |
| 683 | $scope.articulosTabla = articulosTablaTemp; | 685 | $scope.articulosTabla = articulosTablaTemp; |
| 684 | $scope.notaPedido.moneda = moneda; | 686 | $scope.notaPedido.moneda = moneda; |
| 685 | $scope.notaPedido.cotizacion = cotizacion; | 687 | $scope.notaPedido.cotizacion = cotizacion; |
| 686 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { | 688 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
| 687 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 689 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
| 688 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 690 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
| 689 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 691 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
| 690 | }else { | 692 | }else { |
| 691 | $scope.$broadcast('addCabecera', { | 693 | $scope.$broadcast('addCabecera', { |
| 692 | label: 'Moneda:', | 694 | label: 'Moneda:', |
| 693 | valor: moneda.DETALLE | 695 | valor: moneda.DETALLE |
| 694 | }); | 696 | }); |
| 695 | $scope.$broadcast('addCabecera', { | 697 | $scope.$broadcast('addCabecera', { |
| 696 | label: 'Fecha cotizacion:', | 698 | label: 'Fecha cotizacion:', |
| 697 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 699 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 698 | }); | 700 | }); |
| 699 | $scope.$broadcast('addCabecera', { | 701 | $scope.$broadcast('addCabecera', { |
| 700 | label: 'Cotizacion:', | 702 | label: 'Cotizacion:', |
| 701 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 703 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
| 702 | }); | 704 | }); |
| 703 | } | 705 | } |
| 704 | }, function() { | 706 | }, function() { |
| 705 | 707 | ||
| 706 | } | 708 | } |
| 707 | ); | 709 | ); |
| 708 | }; | 710 | }; |
| 709 | 711 | ||
| 710 | $scope.agregarATabla = function(key) { | 712 | $scope.agregarATabla = function(key) { |
| 711 | if(key === 13) { | 713 | if(key === 13) { |
| 712 | if($scope.articuloACargar.cantidad === undefined || | 714 | if($scope.articuloACargar.cantidad === undefined || |
| 713 | $scope.articuloACargar.cantidad === 0 || | 715 | $scope.articuloACargar.cantidad === 0 || |
| 714 | $scope.articuloACargar.cantidad === null ) { | 716 | $scope.articuloACargar.cantidad === null ) { |
| 715 | focaModalService.alert('El valor debe ser al menos 1'); | 717 | focaModalService.alert('El valor debe ser al menos 1'); |
| 716 | return; | 718 | return; |
| 717 | } | 719 | } |
| 718 | delete $scope.articuloACargar.sectorCodigo; | 720 | delete $scope.articuloACargar.sectorCodigo; |
| 719 | $scope.articulosTabla.push($scope.articuloACargar); | 721 | $scope.articulosTabla.push($scope.articuloACargar); |
| 720 | $scope.cargando = true; | 722 | $scope.cargando = true; |
| 721 | } | 723 | } |
| 722 | }; | 724 | }; |
| 723 | 725 | ||
| 724 | $scope.quitarArticulo = function(key) { | 726 | $scope.quitarArticulo = function(key) { |
| 725 | $scope.articulosTabla.splice(key, 1); | 727 | $scope.articulosTabla.splice(key, 1); |
| 726 | }; | 728 | }; |
| 727 | 729 | ||
| 728 | $scope.editarArticulo = function(key, articulo) { | 730 | $scope.editarArticulo = function(key, articulo) { |
| 729 | if(key === 13) { | 731 | if(key === 13) { |
| 730 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 732 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
| 731 | articulo.cantidad === undefined) { | 733 | articulo.cantidad === undefined) { |
| 732 | focaModalService.alert('El valor debe ser al menos 1'); | 734 | focaModalService.alert('El valor debe ser al menos 1'); |
| 733 | return; | 735 | return; |
| 734 | } | 736 | } |
| 735 | articulo.editCantidad = false; | 737 | articulo.editCantidad = false; |
| 736 | articulo.editPrecio = false; | 738 | articulo.editPrecio = false; |
| 737 | } | 739 | } |
| 738 | }; | 740 | }; |
| 739 | 741 | ||
| 740 | $scope.cambioEdit = function(articulo, propiedad) { | 742 | $scope.cambioEdit = function(articulo, propiedad) { |
| 741 | if(propiedad === 'cantidad') { | 743 | if(propiedad === 'cantidad') { |
| 742 | articulo.editCantidad = true; | 744 | articulo.editCantidad = true; |
| 743 | } else if(propiedad === 'precio') { | 745 | } else if(propiedad === 'precio') { |
| 744 | articulo.editPrecio = true; | 746 | articulo.editPrecio = true; |
| 745 | } | 747 | } |
| 746 | }; | 748 | }; |
| 747 | 749 | ||
| 748 | $scope.resetFilter = function() { | 750 | $scope.resetFilter = function() { |
| 749 | $scope.articuloACargar = {}; | 751 | $scope.articuloACargar = {}; |
| 750 | $scope.cargando = true; | 752 | $scope.cargando = true; |
| 751 | }; | 753 | }; |
| 752 | //Recibe aviso si el teclado está en uso | 754 | //Recibe aviso si el teclado está en uso |
| 753 | $rootScope.$on('usarTeclado', function(event, data) { | 755 | $rootScope.$on('usarTeclado', function(event, data) { |
| 754 | if(data) { | 756 | if(data) { |
| 755 | $scope.mostrarTeclado = true; | 757 | $scope.mostrarTeclado = true; |
| 756 | return; | 758 | return; |
| 757 | } | 759 | } |
| 758 | $scope.mostrarTeclado = false; | 760 | $scope.mostrarTeclado = false; |
| 759 | }); | 761 | }); |
| 760 | 762 | ||
| 761 | $scope.selectFocus = function($event) { | 763 | $scope.selectFocus = function($event) { |
| 762 | // Si el teclado esta en uso no selecciona el valor | 764 | // Si el teclado esta en uso no selecciona el valor |
| 763 | if($scope.mostrarTeclado) { | 765 | if($scope.mostrarTeclado) { |
| 764 | return; | 766 | return; |
| 765 | } | 767 | } |
| 766 | $event.target.select(); | 768 | $event.target.select(); |
| 767 | }; | 769 | }; |
| 768 | 770 | ||
| 769 | $scope.salir = function() { | 771 | $scope.salir = function() { |
| 770 | $location.path('/'); | 772 | $location.path('/'); |
| 771 | }; | 773 | }; |
| 772 | 774 | ||
| 773 | $scope.parsearATexto = function(articulo) { | 775 | $scope.parsearATexto = function(articulo) { |
| 774 | articulo.cantidad = parseFloat(articulo.cantidad); | 776 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 775 | articulo.precio = parseFloat(articulo.precio); | 777 | articulo.precio = parseFloat(articulo.precio); |
| 776 | }; | 778 | }; |
| 777 | 779 | ||
| 778 | function addArrayCabecera(array) { | 780 | function addArrayCabecera(array) { |
| 779 | for(var i = 0; i < array.length; i++) { | 781 | for(var i = 0; i < array.length; i++) { |
| 780 | $scope.$broadcast('addCabecera', { | 782 | $scope.$broadcast('addCabecera', { |
| 781 | label: array[i].label, | 783 | label: array[i].label, |
| 782 | valor: array[i].valor | 784 | valor: array[i].valor |
| 783 | }); | 785 | }); |
| 784 | } | 786 | } |
| 785 | } | 787 | } |
| 786 | 788 | ||
| 787 | function rellenar(relleno, longitud) { | 789 | function rellenar(relleno, longitud) { |
| 788 | relleno = '' + relleno; | 790 | relleno = '' + relleno; |
| 789 | while (relleno.length < longitud) { | 791 | while (relleno.length < longitud) { |
| 790 | relleno = '0' + relleno; | 792 | relleno = '0' + relleno; |
| 791 | } | 793 | } |
| 792 | 794 | ||
| 793 | return relleno; | 795 | return relleno; |
| 794 | } | 796 | } |
| 795 | 797 | ||
| 796 | function validarNotaRemitada() { | 798 | function validarNotaRemitada() { |
| 797 | if(!$scope.notaPedido.idRemito) { | 799 | if(!$scope.notaPedido.idRemito) { |
| 798 | return true; | 800 | return true; |
| 799 | }else{ | 801 | }else{ |
| 800 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 802 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
| 801 | return false; | 803 | return false; |
| 802 | } | 804 | } |
| 803 | } | 805 | } |
| 804 | function formatearPuntosDescarga(puntosDescarga) { | 806 | function formatearPuntosDescarga(puntosDescarga) { |
| 805 | var result = []; | 807 | var result = []; |
| 806 | 808 | ||
| 807 | puntosDescarga.forEach(function(el) { | 809 | puntosDescarga.forEach(function(el) { |
| 808 | var puntoDescarga = result.filter(function(resultPunto) { | 810 | var puntoDescarga = result.filter(function(resultPunto) { |
| 809 | return resultPunto.id == el.idPuntoDescarga; | 811 | return resultPunto.id == el.idPuntoDescarga; |
| 810 | }); | 812 | }); |
| 811 | 813 | ||
| 812 | if(puntoDescarga.length) { | 814 | if(puntoDescarga.length) { |
| 813 | puntoDescarga[0].articulosAgregados.push({ | 815 | puntoDescarga[0].articulosAgregados.push({ |
| 814 | cantidad: el.cantidad, | 816 | cantidad: el.cantidad, |
| 815 | descripcion: el.producto.descripcion, | 817 | descripcion: el.producto.descripcion, |
| 816 | id: el.producto.id | 818 | id: el.producto.id |
| 817 | }); | 819 | }); |
| 818 | }else { | 820 | }else { |
| 819 | result.push({ | 821 | result.push({ |
| 820 | id: el.puntoDescarga.id, | 822 | id: el.puntoDescarga.id, |
| 821 | id_cliente: el.puntoDescarga.id_cliente, | 823 | id_cliente: el.puntoDescarga.id_cliente, |
| 822 | id_da_config_0: el.puntoDescarga.id_da_config_0, | 824 | id_da_config_0: el.puntoDescarga.id_da_config_0, |
| 823 | latitud: el.puntoDescarga.latitud, | 825 | latitud: el.puntoDescarga.latitud, |
| 824 | longitud: el.puntoDescarga.longitud, | 826 | longitud: el.puntoDescarga.longitud, |
| 825 | descripcion: el.puntoDescarga.descripcion, | 827 | descripcion: el.puntoDescarga.descripcion, |
| 826 | articulosAgregados: [ | 828 | articulosAgregados: [ |
| 827 | { | 829 | { |
| 828 | cantidad: el.cantidad, | 830 | cantidad: el.cantidad, |
| 829 | descripcion: el.producto.descripcion, | 831 | descripcion: el.producto.descripcion, |
| 830 | id: el.producto.id | 832 | id: el.producto.id |
| 831 | } | 833 | } |
| 832 | ] | 834 | ] |
| 833 | }); | 835 | }); |
| 834 | } | 836 | } |
| 835 | }); | 837 | }); |
| 836 | return result; | 838 | return result; |
| 837 | } | 839 | } |
| 838 | 840 | ||
| 839 | function salir() { | 841 | function salir() { |
| 840 | var notaPedido = { | 842 | var notaPedido = { |
| 841 | id: 0, | 843 | id: 0, |
| 842 | vendedor: {}, | 844 | vendedor: {}, |
| 843 | cliente: {}, | 845 | cliente: {}, |
| 844 | proveedor: {}, | 846 | proveedor: {}, |
| 845 | domicilio: {dom: ''}, | 847 | domicilio: {dom: ''}, |
| 846 | moneda: $scope.notaPedido.moneda, | 848 | moneda: $scope.notaPedido.moneda, |
| 847 | cotizacion: $scope.notaPedido.cotizacion | 849 | cotizacion: $scope.notaPedido.cotizacion |
| 848 | }; | 850 | }; |
| 849 | if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) { | 851 | if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) { |
| 850 | focaModalService | 852 | focaModalService |
| 851 | .confirm('¿Esta seguro de que desea salir? ' + | 853 | .confirm('¿Esta seguro de que desea salir? ' + |
| 852 | 'Se perderán todos los datos cargados.') | 854 | 'Se perderán todos los datos cargados.') |
| 853 | .then(function(data) { | 855 | .then(function(data) { |
| 854 | if(data) $location.path('/'); | 856 | if(data) $location.path('/'); |
| 855 | }); | 857 | }); |
| 856 | }else { | 858 | }else { |
| 857 | $location.path('/'); | 859 | $location.path('/'); |
| 858 | } | 860 | } |
| 859 | } | 861 | } |
| 860 | } | 862 | } |
| 861 | ]); | 863 | ]); |
| 862 | 864 |