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