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