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