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