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