Commit 623837821555f2f0d37b3c7f96b2b6d2e1989f16
1 parent
e53a1547fa
Exists in
master
fix, cargar sucursal al editar pedido
Showing
1 changed file
with
1 additions
and
11 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
2 | [ | 2 | [ |
3 | '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService', | 3 | '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService', |
4 | 'focaModalService', 'notaPedidoBusinessService', '$rootScope', 'focaSeguimientoService', | 4 | 'focaModalService', 'notaPedidoBusinessService', '$rootScope', 'focaSeguimientoService', |
5 | function( | 5 | function( |
6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, | 6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, |
7 | notaPedidoBusinessService, $rootScope, focaSeguimientoService) | 7 | notaPedidoBusinessService, $rootScope, focaSeguimientoService) |
8 | { | 8 | { |
9 | $scope.botonera = [ | 9 | $scope.botonera = [ |
10 | {texto: 'Vendedor', accion: function() { | 10 | {texto: 'Vendedor', accion: function() { |
11 | validarNotaRemitada($scope.seleccionarVendedor);}}, | 11 | validarNotaRemitada($scope.seleccionarVendedor);}}, |
12 | {texto: 'Cliente', accion: function() { | 12 | {texto: 'Cliente', accion: function() { |
13 | validarNotaRemitada($scope.seleccionarCliente);}}, | 13 | validarNotaRemitada($scope.seleccionarCliente);}}, |
14 | {texto: 'Proveedor', accion: function() { | 14 | {texto: 'Proveedor', accion: function() { |
15 | validarNotaRemitada($scope.seleccionarProveedor);}}, | 15 | validarNotaRemitada($scope.seleccionarProveedor);}}, |
16 | {texto: 'Moneda', accion: function() { | 16 | {texto: 'Moneda', accion: function() { |
17 | validarNotaRemitada($scope.abrirModalMoneda);}}, | 17 | validarNotaRemitada($scope.abrirModalMoneda);}}, |
18 | {texto: 'Precios y condiciones', accion: function() { | 18 | {texto: 'Precios y condiciones', accion: function() { |
19 | validarNotaRemitada($scope.abrirModalListaPrecio);}}, | 19 | validarNotaRemitada($scope.abrirModalListaPrecio);}}, |
20 | {texto: 'Flete', accion: function() { | 20 | {texto: 'Flete', accion: function() { |
21 | validarNotaRemitada($scope.abrirModalFlete);}}, | 21 | validarNotaRemitada($scope.abrirModalFlete);}}, |
22 | {texto: '', accion: function() {}}, | 22 | {texto: '', accion: function() {}}, |
23 | {texto: '', accion: function() {}} | 23 | {texto: '', accion: function() {}} |
24 | ]; | 24 | ]; |
25 | 25 | ||
26 | $scope.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.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); | 289 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); |
289 | $scope.notaPedido = notaPedido; | 290 | $scope.notaPedido = notaPedido; |
290 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; | 291 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; |
291 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; | 292 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; |
292 | addArrayCabecera(cabeceras); | 293 | addArrayCabecera(cabeceras); |
293 | 294 | ||
294 | }, function() { | 295 | }, function() { |
295 | // funcion ejecutada cuando se cancela el modal | 296 | // funcion ejecutada cuando se cancela el modal |
296 | } | 297 | } |
297 | ); | 298 | ); |
298 | }; | 299 | }; |
299 | 300 | ||
300 | $scope.seleccionarArticulo = function() { | 301 | $scope.seleccionarArticulo = function() { |
301 | if ($scope.idLista === undefined) { | 302 | if ($scope.idLista === undefined) { |
302 | focaModalService.alert( | 303 | focaModalService.alert( |
303 | 'Primero seleccione una lista de precio y condicion'); | 304 | 'Primero seleccione una lista de precio y condicion'); |
304 | return; | 305 | return; |
305 | } | 306 | } |
306 | var modalInstance = $uibModal.open( | 307 | var modalInstance = $uibModal.open( |
307 | { | 308 | { |
308 | ariaLabelledBy: 'Busqueda de Productos', | 309 | ariaLabelledBy: 'Busqueda de Productos', |
309 | templateUrl: 'modal-busqueda-productos.html', | 310 | templateUrl: 'modal-busqueda-productos.html', |
310 | controller: 'modalBusquedaProductosCtrl', | 311 | controller: 'modalBusquedaProductosCtrl', |
311 | resolve: { | 312 | resolve: { |
312 | parametroProducto: { | 313 | parametroProducto: { |
313 | idLista: $scope.idLista, | 314 | idLista: $scope.idLista, |
314 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 315 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
315 | simbolo: $scope.notaPedido.moneda.SIMBOLO | 316 | simbolo: $scope.notaPedido.moneda.SIMBOLO |
316 | } | 317 | } |
317 | }, | 318 | }, |
318 | size: 'lg' | 319 | size: 'lg' |
319 | } | 320 | } |
320 | ); | 321 | ); |
321 | modalInstance.result.then( | 322 | modalInstance.result.then( |
322 | function(producto) { | 323 | function(producto) { |
323 | var newArt = | 324 | var newArt = |
324 | { | 325 | { |
325 | id: 0, | 326 | id: 0, |
326 | codigo: producto.codigo, | 327 | codigo: producto.codigo, |
327 | sector: producto.sector, | 328 | sector: producto.sector, |
328 | sectorCodigo: producto.sector + '-' + producto.codigo, | 329 | sectorCodigo: producto.sector + '-' + producto.codigo, |
329 | descripcion: producto.descripcion, | 330 | descripcion: producto.descripcion, |
330 | item: $scope.articulosTabla.length + 1, | 331 | item: $scope.articulosTabla.length + 1, |
331 | nombre: producto.descripcion, | 332 | nombre: producto.descripcion, |
332 | precio: parseFloat(producto.precio.toFixed(4)), | 333 | precio: parseFloat(producto.precio.toFixed(4)), |
333 | costoUnitario: producto.costo, | 334 | costoUnitario: producto.costo, |
334 | editCantidad: false, | 335 | editCantidad: false, |
335 | editPrecio: false, | 336 | editPrecio: false, |
336 | rubro: producto.CodRub, | 337 | rubro: producto.CodRub, |
337 | exentoUnitario: producto.precio, | 338 | exentoUnitario: producto.precio, |
338 | ivaUnitario: producto.IMPIVA, | 339 | ivaUnitario: producto.IMPIVA, |
339 | impuestoInternoUnitario: producto.ImpInt, | 340 | impuestoInternoUnitario: producto.ImpInt, |
340 | impuestoInterno1Unitario: producto.ImpInt2, | 341 | impuestoInterno1Unitario: producto.ImpInt2, |
341 | impuestoInterno2Unitario: producto.ImpInt3, | 342 | impuestoInterno2Unitario: producto.ImpInt3, |
342 | precioLista: producto.precio, | 343 | precioLista: producto.precio, |
343 | combustible: 1, | 344 | combustible: 1, |
344 | facturado: 0 | 345 | facturado: 0 |
345 | }; | 346 | }; |
346 | $scope.articuloACargar = newArt; | 347 | $scope.articuloACargar = newArt; |
347 | $scope.cargando = false; | 348 | $scope.cargando = false; |
348 | }, function() { | 349 | }, function() { |
349 | // funcion ejecutada cuando se cancela el modal | 350 | // funcion ejecutada cuando se cancela el modal |
350 | } | 351 | } |
351 | ); | 352 | ); |
352 | }; | 353 | }; |
353 | 354 | ||
354 | $scope.seleccionarVendedor = function() { | 355 | $scope.seleccionarVendedor = function() { |
355 | var modalInstance = $uibModal.open( | 356 | var modalInstance = $uibModal.open( |
356 | { | 357 | { |
357 | ariaLabelledBy: 'Busqueda de Vendedores', | 358 | ariaLabelledBy: 'Busqueda de Vendedores', |
358 | templateUrl: 'modal-vendedores.html', | 359 | templateUrl: 'modal-vendedores.html', |
359 | controller: 'modalVendedoresCtrl', | 360 | controller: 'modalVendedoresCtrl', |
360 | size: 'lg' | 361 | size: 'lg' |
361 | } | 362 | } |
362 | ); | 363 | ); |
363 | modalInstance.result.then( | 364 | modalInstance.result.then( |
364 | function(vendedor) { | 365 | function(vendedor) { |
365 | addCabecera('Vendedor:', vendedor.NomVen); | 366 | addCabecera('Vendedor:', vendedor.NomVen); |
366 | $scope.notaPedido.vendedor = vendedor; | 367 | $scope.notaPedido.vendedor = vendedor; |
367 | }, function() { | 368 | }, function() { |
368 | 369 | ||
369 | } | 370 | } |
370 | ); | 371 | ); |
371 | }; | 372 | }; |
372 | 373 | ||
373 | $scope.seleccionarProveedor = function() { | 374 | $scope.seleccionarProveedor = function() { |
374 | var modalInstance = $uibModal.open( | 375 | var modalInstance = $uibModal.open( |
375 | { | 376 | { |
376 | ariaLabelledBy: 'Busqueda de Proveedor', | 377 | ariaLabelledBy: 'Busqueda de Proveedor', |
377 | templateUrl: 'modal-proveedor.html', | 378 | templateUrl: 'modal-proveedor.html', |
378 | controller: 'focaModalProveedorCtrl', | 379 | controller: 'focaModalProveedorCtrl', |
379 | size: 'lg', | 380 | size: 'lg', |
380 | resolve: { | 381 | resolve: { |
381 | transportista: function() { | 382 | transportista: function() { |
382 | return false; | 383 | return false; |
383 | } | 384 | } |
384 | } | 385 | } |
385 | } | 386 | } |
386 | ); | 387 | ); |
387 | modalInstance.result.then( | 388 | modalInstance.result.then( |
388 | function(proveedor) { | 389 | function(proveedor) { |
389 | $scope.notaPedido.proveedor = proveedor; | 390 | $scope.notaPedido.proveedor = proveedor; |
390 | addCabecera('Proveedor:', proveedor.NOM); | 391 | addCabecera('Proveedor:', proveedor.NOM); |
391 | }, function() { | 392 | }, function() { |
392 | 393 | ||
393 | } | 394 | } |
394 | ); | 395 | ); |
395 | }; | 396 | }; |
396 | 397 | ||
397 | $scope.seleccionarCliente = function() { | 398 | $scope.seleccionarCliente = function() { |
398 | 399 | ||
399 | var modalInstance = $uibModal.open( | 400 | var modalInstance = $uibModal.open( |
400 | { | 401 | { |
401 | ariaLabelledBy: 'Busqueda de Cliente', | 402 | ariaLabelledBy: 'Busqueda de Cliente', |
402 | templateUrl: 'foca-busqueda-cliente-modal.html', | 403 | templateUrl: 'foca-busqueda-cliente-modal.html', |
403 | controller: 'focaBusquedaClienteModalController', | 404 | controller: 'focaBusquedaClienteModalController', |
404 | size: 'lg' | 405 | size: 'lg' |
405 | } | 406 | } |
406 | ); | 407 | ); |
407 | modalInstance.result.then( | 408 | modalInstance.result.then( |
408 | function(cliente) { | 409 | function(cliente) { |
409 | $scope.abrirModalDomicilios(cliente); | 410 | $scope.abrirModalDomicilios(cliente); |
410 | }, function() { | 411 | }, function() { |
411 | 412 | ||
412 | } | 413 | } |
413 | ); | 414 | ); |
414 | }; | 415 | }; |
415 | 416 | ||
416 | $scope.abrirModalDomicilios = function(cliente) { | 417 | $scope.abrirModalDomicilios = function(cliente) { |
417 | var modalInstanceDomicilio = $uibModal.open( | 418 | var modalInstanceDomicilio = $uibModal.open( |
418 | { | 419 | { |
419 | ariaLabelledBy: 'Busqueda de Domicilios', | 420 | ariaLabelledBy: 'Busqueda de Domicilios', |
420 | templateUrl: 'modal-domicilio.html', | 421 | templateUrl: 'modal-domicilio.html', |
421 | controller: 'focaModalDomicilioController', | 422 | controller: 'focaModalDomicilioController', |
422 | resolve: { idCliente: function() { return cliente.cod; }}, | 423 | resolve: { idCliente: function() { return cliente.cod; }}, |
423 | size: 'lg', | 424 | size: 'lg', |
424 | } | 425 | } |
425 | ); | 426 | ); |
426 | modalInstanceDomicilio.result.then( | 427 | modalInstanceDomicilio.result.then( |
427 | function(domicilio) { | 428 | function(domicilio) { |
428 | $scope.notaPedido.domicilio = domicilio; | 429 | $scope.notaPedido.domicilio = domicilio; |
429 | $scope.notaPedido.cliente = { | 430 | $scope.notaPedido.cliente = { |
430 | COD: cliente.cod, | 431 | COD: cliente.cod, |
431 | CUIT: cliente.cuit, | 432 | CUIT: cliente.cuit, |
432 | NOM: cliente.nom | 433 | NOM: cliente.nom |
433 | }; | 434 | }; |
434 | addCabecera('Cliente:', cliente.nom); | 435 | addCabecera('Cliente:', cliente.nom); |
435 | var domicilioStamp = | 436 | var domicilioStamp = |
436 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 437 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
437 | domicilio.Localidad + ', ' + domicilio.Provincia; | 438 | domicilio.Localidad + ', ' + domicilio.Provincia; |
438 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 439 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
439 | addCabecera('Domicilio:', domicilioStamp); | 440 | addCabecera('Domicilio:', domicilioStamp); |
440 | }, function() { | 441 | }, function() { |
441 | $scope.seleccionarCliente(); | 442 | $scope.seleccionarCliente(); |
442 | return; | 443 | return; |
443 | } | 444 | } |
444 | ); | 445 | ); |
445 | }; | 446 | }; |
446 | 447 | ||
447 | $scope.mostrarFichaCliente = function() { | ||
448 | $uibModal.open( | ||
449 | { | ||
450 | ariaLabelledBy: 'Datos del Cliente', | ||
451 | templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', | ||
452 | controller: 'focaCrearNotaPedidoFichaClienteController', | ||
453 | size: 'lg' | ||
454 | } | ||
455 | ); | ||
456 | }; | ||
457 | |||
458 | $scope.getTotal = function() { | 448 | $scope.getTotal = function() { |
459 | var total = 0; | 449 | var total = 0; |
460 | var arrayTempArticulos = $scope.articulosTabla; | 450 | var arrayTempArticulos = $scope.articulosTabla; |
461 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 451 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
462 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 452 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
463 | } | 453 | } |
464 | return parseFloat(total.toFixed(2)); | 454 | return parseFloat(total.toFixed(2)); |
465 | }; | 455 | }; |
466 | 456 | ||
467 | $scope.getSubTotal = function() { | 457 | $scope.getSubTotal = function() { |
468 | if($scope.articuloACargar) { | 458 | if($scope.articuloACargar) { |
469 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 459 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
470 | } | 460 | } |
471 | }; | 461 | }; |
472 | 462 | ||
473 | $scope.abrirModalListaPrecio = function() { | 463 | $scope.abrirModalListaPrecio = function() { |
474 | var modalInstance = $uibModal.open( | 464 | var modalInstance = $uibModal.open( |
475 | { | 465 | { |
476 | ariaLabelledBy: 'Busqueda de Precio Condición', | 466 | ariaLabelledBy: 'Busqueda de Precio Condición', |
477 | templateUrl: 'modal-precio-condicion.html', | 467 | templateUrl: 'modal-precio-condicion.html', |
478 | controller: 'focaModalPrecioCondicionController', | 468 | controller: 'focaModalPrecioCondicionController', |
479 | size: 'lg' | 469 | size: 'lg' |
480 | } | 470 | } |
481 | ); | 471 | ); |
482 | modalInstance.result.then( | 472 | modalInstance.result.then( |
483 | function(precioCondicion) { | 473 | function(precioCondicion) { |
484 | var cabecera = ''; | 474 | var cabecera = ''; |
485 | var plazosConcat = ''; | 475 | var plazosConcat = ''; |
486 | if(!Array.isArray(precioCondicion)) { | 476 | if(!Array.isArray(precioCondicion)) { |
487 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 477 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
488 | $scope.plazosPagos = precioCondicion.plazoPago; | 478 | $scope.plazosPagos = precioCondicion.plazoPago; |
489 | $scope.idLista = precioCondicion.idListaPrecio; | 479 | $scope.idLista = precioCondicion.idListaPrecio; |
490 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 480 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
491 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 481 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
492 | } | 482 | } |
493 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 483 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
494 | } else { //Cuando se ingresan los plazos manualmente | 484 | } else { //Cuando se ingresan los plazos manualmente |
495 | $scope.notaPedido.idPrecioCondicion = 0; | 485 | $scope.notaPedido.idPrecioCondicion = 0; |
496 | $scope.idLista = -1; //-1, el modal productos busca todos los productos | 486 | $scope.idLista = -1; //-1, el modal productos busca todos los productos |
497 | $scope.plazosPagos = precioCondicion; | 487 | $scope.plazosPagos = precioCondicion; |
498 | for(var j = 0; j < precioCondicion.length; j++) { | 488 | for(var j = 0; j < precioCondicion.length; j++) { |
499 | plazosConcat += precioCondicion[j].dias + ' '; | 489 | plazosConcat += precioCondicion[j].dias + ' '; |
500 | } | 490 | } |
501 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 491 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
502 | } | 492 | } |
503 | $scope.articulosTabla = []; | 493 | $scope.articulosTabla = []; |
504 | addCabecera('Precios y condiciones:', cabecera); | 494 | addCabecera('Precios y condiciones:', cabecera); |
505 | }, function() { | 495 | }, function() { |
506 | 496 | ||
507 | } | 497 | } |
508 | ); | 498 | ); |
509 | }; | 499 | }; |
510 | 500 | ||
511 | $scope.abrirModalFlete = function() { | 501 | $scope.abrirModalFlete = function() { |
512 | var modalInstance = $uibModal.open( | 502 | var modalInstance = $uibModal.open( |
513 | { | 503 | { |
514 | ariaLabelledBy: 'Busqueda de Flete', | 504 | ariaLabelledBy: 'Busqueda de Flete', |
515 | templateUrl: 'modal-flete.html', | 505 | templateUrl: 'modal-flete.html', |
516 | controller: 'focaModalFleteController', | 506 | controller: 'focaModalFleteController', |
517 | size: 'lg', | 507 | size: 'lg', |
518 | resolve: { | 508 | resolve: { |
519 | parametrosFlete: | 509 | parametrosFlete: |
520 | function() { | 510 | function() { |
521 | return { | 511 | return { |
522 | flete: $scope.notaPedido.fob ? 'FOB' : | 512 | flete: $scope.notaPedido.fob ? 'FOB' : |
523 | ( $scope.notaPedido.flete ? '1' : | 513 | ( $scope.notaPedido.flete ? '1' : |
524 | ($scope.notaPedido.flete === undefined ? null : '0')), | 514 | ($scope.notaPedido.flete === undefined ? null : '0')), |
525 | bomba: $scope.notaPedido.bomba ? '1' : | 515 | bomba: $scope.notaPedido.bomba ? '1' : |
526 | ($scope.notaPedido.bomba === undefined ? null : '0'), | 516 | ($scope.notaPedido.bomba === undefined ? null : '0'), |
527 | kilometros: $scope.notaPedido.kilometros | 517 | kilometros: $scope.notaPedido.kilometros |
528 | }; | 518 | }; |
529 | } | 519 | } |
530 | } | 520 | } |
531 | } | 521 | } |
532 | ); | 522 | ); |
533 | modalInstance.result.then( | 523 | modalInstance.result.then( |
534 | function(datos) { | 524 | function(datos) { |
535 | $scope.notaPedido.flete = datos.flete; | 525 | $scope.notaPedido.flete = datos.flete; |
536 | $scope.notaPedido.fob = datos.FOB; | 526 | $scope.notaPedido.fob = datos.FOB; |
537 | $scope.notaPedido.bomba = datos.bomba; | 527 | $scope.notaPedido.bomba = datos.bomba; |
538 | $scope.notaPedido.kilometros = datos.kilometros; | 528 | $scope.notaPedido.kilometros = datos.kilometros; |
539 | addCabecera('Flete:', datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No')); | 529 | addCabecera('Flete:', datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No')); |
540 | if(datos.flete) { | 530 | if(datos.flete) { |
541 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); | 531 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); |
542 | addCabecera('Kilometros:', datos.kilometros); | 532 | addCabecera('Kilometros:', datos.kilometros); |
543 | } else { | 533 | } else { |
544 | removeCabecera('Bomba:'); | 534 | removeCabecera('Bomba:'); |
545 | removeCabecera('Kilometros:'); | 535 | removeCabecera('Kilometros:'); |
546 | $scope.notaPedido.bomba = false; | 536 | $scope.notaPedido.bomba = false; |
547 | $scope.notaPedido.kilometros = null; | 537 | $scope.notaPedido.kilometros = null; |
548 | } | 538 | } |
549 | }, function() { | 539 | }, function() { |
550 | 540 | ||
551 | } | 541 | } |
552 | ); | 542 | ); |
553 | }; | 543 | }; |
554 | 544 | ||
555 | $scope.abrirModalMoneda = function() { | 545 | $scope.abrirModalMoneda = function() { |
556 | var modalInstance = $uibModal.open( | 546 | var modalInstance = $uibModal.open( |
557 | { | 547 | { |
558 | ariaLabelledBy: 'Busqueda de Moneda', | 548 | ariaLabelledBy: 'Busqueda de Moneda', |
559 | templateUrl: 'modal-moneda.html', | 549 | templateUrl: 'modal-moneda.html', |
560 | controller: 'focaModalMonedaController', | 550 | controller: 'focaModalMonedaController', |
561 | size: 'lg' | 551 | size: 'lg' |
562 | } | 552 | } |
563 | ); | 553 | ); |
564 | modalInstance.result.then( | 554 | modalInstance.result.then( |
565 | function(moneda) { | 555 | function(moneda) { |
566 | $scope.abrirModalCotizacion(moneda); | 556 | $scope.abrirModalCotizacion(moneda); |
567 | }, function() { | 557 | }, function() { |
568 | 558 | ||
569 | } | 559 | } |
570 | ); | 560 | ); |
571 | }; | 561 | }; |
572 | 562 | ||
573 | $scope.abrirModalCotizacion = function(moneda) { | 563 | $scope.abrirModalCotizacion = function(moneda) { |
574 | var modalInstance = $uibModal.open( | 564 | var modalInstance = $uibModal.open( |
575 | { | 565 | { |
576 | ariaLabelledBy: 'Busqueda de Cotización', | 566 | ariaLabelledBy: 'Busqueda de Cotización', |
577 | templateUrl: 'modal-cotizacion.html', | 567 | templateUrl: 'modal-cotizacion.html', |
578 | controller: 'focaModalCotizacionController', | 568 | controller: 'focaModalCotizacionController', |
579 | size: 'lg', | 569 | size: 'lg', |
580 | resolve: {idMoneda: function() {return moneda.ID;}} | 570 | resolve: {idMoneda: function() {return moneda.ID;}} |
581 | } | 571 | } |
582 | ); | 572 | ); |
583 | modalInstance.result.then( | 573 | modalInstance.result.then( |
584 | function(cotizacion) { | 574 | function(cotizacion) { |
585 | var articulosTablaTemp = $scope.articulosTabla; | 575 | var articulosTablaTemp = $scope.articulosTabla; |
586 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 576 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
587 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 577 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
588 | $scope.notaPedido.cotizacion.VENDEDOR; | 578 | $scope.notaPedido.cotizacion.VENDEDOR; |
589 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 579 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
590 | cotizacion.VENDEDOR; | 580 | cotizacion.VENDEDOR; |
591 | } | 581 | } |
592 | $scope.articulosTabla = articulosTablaTemp; | 582 | $scope.articulosTabla = articulosTablaTemp; |
593 | $scope.notaPedido.moneda = moneda; | 583 | $scope.notaPedido.moneda = moneda; |
594 | $scope.notaPedido.cotizacion = cotizacion; | 584 | $scope.notaPedido.cotizacion = cotizacion; |
595 | addCabecera('Moneda:', moneda.DETALLE); | 585 | addCabecera('Moneda:', moneda.DETALLE); |
596 | addCabecera( | 586 | addCabecera( |
597 | 'Fecha cotizacion:', | 587 | 'Fecha cotizacion:', |
598 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 588 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
599 | ); | 589 | ); |
600 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); | 590 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); |
601 | }, function() { | 591 | }, function() { |
602 | 592 | ||
603 | } | 593 | } |
604 | ); | 594 | ); |
605 | }; | 595 | }; |
606 | 596 | ||
607 | $scope.agregarATabla = function(key) { | 597 | $scope.agregarATabla = function(key) { |
608 | if(key === 13) { | 598 | if(key === 13) { |
609 | if($scope.articuloACargar.cantidad === undefined || | 599 | if($scope.articuloACargar.cantidad === undefined || |
610 | $scope.articuloACargar.cantidad === 0 || | 600 | $scope.articuloACargar.cantidad === 0 || |
611 | $scope.articuloACargar.cantidad === null ) { | 601 | $scope.articuloACargar.cantidad === null ) { |
612 | focaModalService.alert('El valor debe ser al menos 1'); | 602 | focaModalService.alert('El valor debe ser al menos 1'); |
613 | return; | 603 | return; |
614 | } | 604 | } |
615 | delete $scope.articuloACargar.sectorCodigo; | 605 | delete $scope.articuloACargar.sectorCodigo; |
616 | $scope.articulosTabla.push($scope.articuloACargar); | 606 | $scope.articulosTabla.push($scope.articuloACargar); |
617 | $scope.cargando = true; | 607 | $scope.cargando = true; |
618 | } | 608 | } |
619 | }; | 609 | }; |
620 | 610 | ||
621 | $scope.quitarArticulo = function(key) { | 611 | $scope.quitarArticulo = function(key) { |
622 | $scope.articulosTabla.splice(key, 1); | 612 | $scope.articulosTabla.splice(key, 1); |
623 | }; | 613 | }; |
624 | 614 | ||
625 | $scope.editarArticulo = function(key, articulo) { | 615 | $scope.editarArticulo = function(key, articulo) { |
626 | if(key === 13) { | 616 | if(key === 13) { |
627 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 617 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
628 | articulo.cantidad === undefined) { | 618 | articulo.cantidad === undefined) { |
629 | focaModalService.alert('El valor debe ser al menos 1'); | 619 | focaModalService.alert('El valor debe ser al menos 1'); |
630 | return; | 620 | return; |
631 | } | 621 | } |
632 | articulo.editCantidad = false; | 622 | articulo.editCantidad = false; |
633 | articulo.editPrecio = false; | 623 | articulo.editPrecio = false; |
634 | } | 624 | } |
635 | }; | 625 | }; |
636 | 626 | ||
637 | $scope.cambioEdit = function(articulo, propiedad) { | 627 | $scope.cambioEdit = function(articulo, propiedad) { |
638 | if(propiedad === 'cantidad') { | 628 | if(propiedad === 'cantidad') { |
639 | articulo.editCantidad = true; | 629 | articulo.editCantidad = true; |
640 | } else if(propiedad === 'precio') { | 630 | } else if(propiedad === 'precio') { |
641 | articulo.editPrecio = true; | 631 | articulo.editPrecio = true; |
642 | } | 632 | } |
643 | }; | 633 | }; |
644 | 634 | ||
645 | $scope.resetFilter = function() { | 635 | $scope.resetFilter = function() { |
646 | $scope.articuloACargar = {}; | 636 | $scope.articuloACargar = {}; |
647 | $scope.cargando = true; | 637 | $scope.cargando = true; |
648 | }; | 638 | }; |
649 | //Recibe aviso si el teclado está en uso | 639 | //Recibe aviso si el teclado está en uso |
650 | $rootScope.$on('usarTeclado', function(event, data) { | 640 | $rootScope.$on('usarTeclado', function(event, data) { |
651 | if(data) { | 641 | if(data) { |
652 | $scope.mostrarTeclado = true; | 642 | $scope.mostrarTeclado = true; |
653 | return; | 643 | return; |
654 | } | 644 | } |
655 | $scope.mostrarTeclado = false; | 645 | $scope.mostrarTeclado = false; |
656 | }); | 646 | }); |
657 | 647 | ||
658 | $scope.selectFocus = function($event) { | 648 | $scope.selectFocus = function($event) { |
659 | // Si el teclado esta en uso no selecciona el valor | 649 | // Si el teclado esta en uso no selecciona el valor |
660 | if($scope.mostrarTeclado) { | 650 | if($scope.mostrarTeclado) { |
661 | return; | 651 | return; |
662 | } | 652 | } |
663 | $event.target.select(); | 653 | $event.target.select(); |
664 | }; | 654 | }; |
665 | 655 | ||
666 | $scope.salir = function() { | 656 | $scope.salir = function() { |
667 | $location.path('/'); | 657 | $location.path('/'); |
668 | }; | 658 | }; |
669 | 659 | ||
670 | $scope.parsearATexto = function(articulo) { | 660 | $scope.parsearATexto = function(articulo) { |
671 | articulo.cantidad = parseFloat(articulo.cantidad); | 661 | articulo.cantidad = parseFloat(articulo.cantidad); |
672 | articulo.precio = parseFloat(articulo.precio); | 662 | articulo.precio = parseFloat(articulo.precio); |
673 | }; | 663 | }; |
674 | 664 | ||
675 | function addArrayCabecera(array) { | 665 | function addArrayCabecera(array) { |
676 | for(var i = 0; i < array.length; i++) { | 666 | for(var i = 0; i < array.length; i++) { |
677 | addCabecera(array[i].label, array[i].valor); | 667 | addCabecera(array[i].label, array[i].valor); |
678 | } | 668 | } |
679 | } | 669 | } |
680 | 670 | ||
681 | function addCabecera(label, valor) { | 671 | function addCabecera(label, valor) { |
682 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 672 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
683 | if(propiedad.length === 1) { | 673 | if(propiedad.length === 1) { |
684 | propiedad[0].valor = valor; | 674 | propiedad[0].valor = valor; |
685 | } else { | 675 | } else { |
686 | $scope.cabecera.push({label: label, valor: valor}); | 676 | $scope.cabecera.push({label: label, valor: valor}); |
687 | } | 677 | } |
688 | } | 678 | } |
689 | 679 | ||
690 | function removeCabecera(label) { | 680 | function removeCabecera(label) { |
691 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 681 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
692 | if(propiedad.length === 1) { | 682 | if(propiedad.length === 1) { |
693 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); | 683 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); |
694 | } | 684 | } |
695 | } | 685 | } |
696 | 686 | ||
697 | function rellenar(relleno, longitud) { | 687 | function rellenar(relleno, longitud) { |
698 | relleno = '' + relleno; | 688 | relleno = '' + relleno; |
699 | while (relleno.length < longitud) { | 689 | while (relleno.length < longitud) { |
700 | relleno = '0' + relleno; | 690 | relleno = '0' + relleno; |
701 | } | 691 | } |
702 | 692 | ||
703 | return relleno; | 693 | return relleno; |
704 | } | 694 | } |
705 | 695 | ||
706 | function validarNotaRemitada(funcion) { | 696 | function validarNotaRemitada(funcion) { |
707 | if($scope.notaPedido.idRemito) { | 697 | if($scope.notaPedido.idRemito) { |
708 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 698 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
709 | } | 699 | } |
710 | else { | 700 | else { |
711 | funcion(); | 701 | funcion(); |
712 | } | 702 | } |
713 | } | 703 | } |
714 | } | 704 | } |
715 | ]); | 705 | ]); |