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