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