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