Commit 84231635d0481bb24ec18c868accfe2be5a2f9a5
1 parent
8da07a79e7
Exists in
master
espacios, nombre variable
Showing
1 changed file
with
3 additions
and
5 deletions
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 | 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 | 150 | ||
151 | if($scope.notaPedido.puntosDescarga) { | 151 | if($scope.notaPedido.puntosDescarga) { |
152 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 152 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
153 | $scope.notaPedido.puntosDescarga); | 153 | $scope.notaPedido.puntosDescarga); |
154 | } | 154 | } |
155 | 155 | ||
156 | var plazos = $scope.plazosPagos; | 156 | var plazos = $scope.plazosPagos; |
157 | var plazosACrear = []; | 157 | var plazosACrear = []; |
158 | plazos.forEach(function(plazo) { | 158 | plazos.forEach(function(plazo) { |
159 | plazosACrear.push({ | 159 | plazosACrear.push({ |
160 | idNotaPedido: data.data.id, | 160 | idNotaPedido: data.data.id, |
161 | dias: plazo.dias | 161 | dias: plazo.dias |
162 | }); | 162 | }); |
163 | }); | 163 | }); |
164 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 164 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
165 | 165 | ||
166 | notaPedidoBusinessService.addEstado(data.data.id, | 166 | notaPedidoBusinessService.addEstado(data.data.id, |
167 | $scope.notaPedido.vendedor.CodVen); | 167 | $scope.notaPedido.vendedor.CodVen); |
168 | 168 | ||
169 | focaModalService.alert('Nota pedido creada'); | 169 | focaModalService.alert('Nota pedido creada'); |
170 | $scope.saveLoading = false; | 170 | $scope.saveLoading = false; |
171 | $scope.$broadcast('cleanCabecera'); | 171 | $scope.$broadcast('cleanCabecera'); |
172 | $scope.$broadcast('addCabecera', { | 172 | $scope.$broadcast('addCabecera', { |
173 | label: 'Moneda:', | 173 | label: 'Moneda:', |
174 | valor: $scope.notaPedido.moneda.DETALLE | 174 | valor: $scope.notaPedido.moneda.DETALLE |
175 | }); | 175 | }); |
176 | $scope.$broadcast('addCabecera', { | 176 | $scope.$broadcast('addCabecera', { |
177 | label: 'Fecha cotizacion:', | 177 | label: 'Fecha cotizacion:', |
178 | valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') | 178 | valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
179 | }); | 179 | }); |
180 | $scope.$broadcast('addCabecera', { | 180 | $scope.$broadcast('addCabecera', { |
181 | label: 'Moneda:', | 181 | label: 'Moneda:', |
182 | valor: $scope.notaPedido.moneda.DETALLE | 182 | valor: $scope.notaPedido.moneda.DETALLE |
183 | }); | 183 | }); |
184 | $scope.$broadcast('addCabecera', { | 184 | $scope.$broadcast('addCabecera', { |
185 | label: 'Cotizacion:', | 185 | label: 'Cotizacion:', |
186 | valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2') | 186 | valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2') |
187 | }); | 187 | }); |
188 | crearNotaPedidoService.getNumeroNotaPedido().then( | 188 | crearNotaPedidoService.getNumeroNotaPedido().then( |
189 | function(res) { | 189 | function(res) { |
190 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 190 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
191 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 191 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
192 | }, | 192 | }, |
193 | function(err) { | 193 | function(err) { |
194 | focaModalService.alert( | 194 | focaModalService.alert( |
195 | 'La terminal no esta configurada correctamente'); | 195 | 'La terminal no esta configurada correctamente'); |
196 | console.info(err); | 196 | console.info(err); |
197 | } | 197 | } |
198 | ); | 198 | ); |
199 | $scope.notaPedido.vendedor = {}; | 199 | $scope.notaPedido.vendedor = {}; |
200 | $scope.notaPedido.cliente = {}; | 200 | $scope.notaPedido.cliente = {}; |
201 | $scope.notaPedido.proveedor = {}; | 201 | $scope.notaPedido.proveedor = {}; |
202 | $scope.notaPedido.domicilio = {}; | 202 | $scope.notaPedido.domicilio = {}; |
203 | $scope.notaPedido.flete = null; | 203 | $scope.notaPedido.flete = null; |
204 | $scope.notaPedido.fob = null; | 204 | $scope.notaPedido.fob = null; |
205 | $scope.notaPedido.bomba = null; | 205 | $scope.notaPedido.bomba = null; |
206 | $scope.notaPedido.kilometros = null; | 206 | $scope.notaPedido.kilometros = null; |
207 | $scope.articulosTabla = []; | 207 | $scope.articulosTabla = []; |
208 | }, | 208 | }, |
209 | function(error) { | 209 | function(error) { |
210 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 210 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
211 | $scope.saveLoading = false; | 211 | $scope.saveLoading = false; |
212 | console.info(error); | 212 | console.info(error); |
213 | } | 213 | } |
214 | ); | 214 | ); |
215 | }; | 215 | }; |
216 | 216 | ||
217 | $scope.seleccionarNotaPedido = function() { | 217 | $scope.seleccionarNotaPedido = function() { |
218 | var modalInstance = $uibModal.open( | 218 | var modalInstance = $uibModal.open( |
219 | { | 219 | { |
220 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 220 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
221 | templateUrl: 'foca-modal-nota-pedido.html', | 221 | templateUrl: 'foca-modal-nota-pedido.html', |
222 | controller: 'focaModalNotaPedidoController', | 222 | controller: 'focaModalNotaPedidoController', |
223 | size: 'lg', | 223 | size: 'lg', |
224 | resolve: {usadoPor: function() {return 'notaPedido';}} | 224 | resolve: {usadoPor: function() {return 'notaPedido';}} |
225 | } | 225 | } |
226 | ); | 226 | ); |
227 | modalInstance.result.then( | 227 | modalInstance.result.then( |
228 | function(notaPedido) { | 228 | function(notaPedido) { |
229 | $scope.now = new Date(notaPedido.fechaCarga); | 229 | $scope.now = new Date(notaPedido.fechaCarga); |
230 | //añado cabeceras | 230 | //añado cabeceras |
231 | $scope.notaPedido.id = notaPedido.id; | 231 | $scope.notaPedido.id = notaPedido.id; |
232 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 232 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
233 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 233 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
234 | var cabeceras = [ | 234 | var cabeceras = [ |
235 | { | 235 | { |
236 | label: 'Moneda:', | 236 | label: 'Moneda:', |
237 | valor: notaPedido.cotizacion.moneda.DETALLE | 237 | valor: notaPedido.cotizacion.moneda.DETALLE |
238 | }, | 238 | }, |
239 | { | 239 | { |
240 | label: 'Fecha cotizacion:', | 240 | label: 'Fecha cotizacion:', |
241 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 241 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
242 | 'dd/MM/yyyy') | 242 | 'dd/MM/yyyy') |
243 | }, | 243 | }, |
244 | { | 244 | { |
245 | label: 'Cotizacion:', | 245 | label: 'Cotizacion:', |
246 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 246 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
247 | '2') | 247 | '2') |
248 | }, | 248 | }, |
249 | { | 249 | { |
250 | label: 'Cliente:', | 250 | label: 'Cliente:', |
251 | valor: notaPedido.cliente.NOM | 251 | valor: notaPedido.cliente.NOM |
252 | }, | 252 | }, |
253 | { | 253 | { |
254 | label: 'Domicilio:', | 254 | label: 'Domicilio:', |
255 | valor: notaPedido.domicilioStamp | 255 | valor: notaPedido.domicilioStamp |
256 | }, | 256 | }, |
257 | { | 257 | { |
258 | label: 'Vendedor:', | 258 | label: 'Vendedor:', |
259 | valor: notaPedido.vendedor.NomVen | 259 | valor: notaPedido.vendedor.NomVen |
260 | }, | 260 | }, |
261 | { | 261 | { |
262 | label: 'Proveedor:', | 262 | label: 'Proveedor:', |
263 | valor: notaPedido.proveedor.NOM | 263 | valor: notaPedido.proveedor.NOM |
264 | }, | 264 | }, |
265 | { | 265 | { |
266 | label: 'Precios y condiciones:', | 266 | label: 'Precios y condiciones:', |
267 | valor: valorPrecioCondicion() + ' ' + | 267 | valor: valorPrecioCondicion() + ' ' + |
268 | notaPedidoBusinessService | 268 | notaPedidoBusinessService |
269 | .plazoToString(notaPedido.notaPedidoPlazo) | 269 | .plazoToString(notaPedido.notaPedidoPlazo) |
270 | }, | 270 | }, |
271 | { | 271 | { |
272 | label: 'Flete:', | 272 | label: 'Flete:', |
273 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 273 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
274 | notaPedido.flete === 1 ? 'Si' : 'No') | 274 | notaPedido.flete === 1 ? 'Si' : 'No') |
275 | } | 275 | } |
276 | ]; | 276 | ]; |
277 | 277 | ||
278 | function valorPrecioCondicion() { | 278 | function valorPrecioCondicion() { |
279 | if(notaPedido.idPrecioCondicion > 0) { | 279 | if(notaPedido.idPrecioCondicion > 0) { |
280 | return notaPedido.precioCondicion.nombre; | 280 | return notaPedido.precioCondicion.nombre; |
281 | } else { | 281 | } else { |
282 | return 'Ingreso Manual'; | 282 | return 'Ingreso Manual'; |
283 | } | 283 | } |
284 | } | 284 | } |
285 | 285 | ||
286 | if(notaPedido.flete === 1) { | 286 | if(notaPedido.flete === 1) { |
287 | var cabeceraBomba = { | 287 | var cabeceraBomba = { |
288 | label: 'Bomba:', | 288 | label: 'Bomba:', |
289 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 289 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
290 | }; | 290 | }; |
291 | if(notaPedido.kilometros) { | 291 | if(notaPedido.kilometros) { |
292 | var cabeceraKilometros = { | 292 | var cabeceraKilometros = { |
293 | label: 'Kilometros:', | 293 | label: 'Kilometros:', |
294 | valor: notaPedido.kilometros | 294 | valor: notaPedido.kilometros |
295 | }; | 295 | }; |
296 | cabeceras.push(cabeceraKilometros); | 296 | cabeceras.push(cabeceraKilometros); |
297 | } | 297 | } |
298 | cabeceras.push(cabeceraBomba); | 298 | cabeceras.push(cabeceraBomba); |
299 | } | 299 | } |
300 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 300 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
301 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, | 301 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, |
302 | notaPedido.cotizacion.VENDEDOR); | 302 | notaPedido.cotizacion.VENDEDOR); |
303 | if(notaPedido.idPrecioCondicion > 0) { | 303 | if(notaPedido.idPrecioCondicion > 0) { |
304 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 304 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
305 | } else { | 305 | } else { |
306 | $scope.idLista = -1; | 306 | $scope.idLista = -1; |
307 | } | 307 | } |
308 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); | 308 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); |
309 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); | 309 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); |
310 | $scope.notaPedido = notaPedido; | 310 | $scope.notaPedido = notaPedido; |
311 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; | 311 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; |
312 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; | 312 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; |
313 | $scope.notaPedido.puntosDescarga = | 313 | $scope.notaPedido.puntosDescarga = |
314 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); | 314 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); |
315 | addArrayCabecera(cabeceras); | 315 | addArrayCabecera(cabeceras); |
316 | 316 | ||
317 | }, function() { | 317 | }, function() { |
318 | // funcion ejecutada cuando se cancela el modal | 318 | // funcion ejecutada cuando se cancela el modal |
319 | } | 319 | } |
320 | ); | 320 | ); |
321 | }; | 321 | }; |
322 | 322 | ||
323 | $scope.seleccionarProductos = function() { | 323 | $scope.seleccionarProductos = function() { |
324 | if ($scope.idLista === undefined) { | 324 | if ($scope.idLista === undefined) { |
325 | focaModalService.alert( | 325 | focaModalService.alert( |
326 | 'Primero seleccione una lista de precio y condicion'); | 326 | 'Primero seleccione una lista de precio y condicion'); |
327 | return; | 327 | return; |
328 | } | 328 | } |
329 | var modalInstance = $uibModal.open( | 329 | var modalInstance = $uibModal.open( |
330 | { | 330 | { |
331 | ariaLabelledBy: 'Busqueda de Productos', | 331 | ariaLabelledBy: 'Busqueda de Productos', |
332 | templateUrl: 'modal-busqueda-productos.html', | 332 | templateUrl: 'modal-busqueda-productos.html', |
333 | controller: 'modalBusquedaProductosCtrl', | 333 | controller: 'modalBusquedaProductosCtrl', |
334 | resolve: { | 334 | resolve: { |
335 | parametroProducto: { | 335 | parametroProducto: { |
336 | idLista: $scope.idLista, | 336 | idLista: $scope.idLista, |
337 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 337 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
338 | simbolo: $scope.notaPedido.moneda.SIMBOLO | 338 | simbolo: $scope.notaPedido.moneda.SIMBOLO |
339 | } | 339 | } |
340 | }, | 340 | }, |
341 | size: 'lg' | 341 | size: 'lg' |
342 | } | 342 | } |
343 | ); | 343 | ); |
344 | modalInstance.result.then( | 344 | modalInstance.result.then( |
345 | function(producto) { | 345 | function(producto) { |
346 | var newArt = | 346 | var newArt = |
347 | { | 347 | { |
348 | id: 0, | 348 | id: 0, |
349 | codigo: producto.codigo, | 349 | codigo: producto.codigo, |
350 | sector: producto.sector, | 350 | sector: producto.sector, |
351 | sectorCodigo: producto.sector + '-' + producto.codigo, | 351 | sectorCodigo: producto.sector + '-' + producto.codigo, |
352 | descripcion: producto.descripcion, | 352 | descripcion: producto.descripcion, |
353 | item: $scope.articulosTabla.length + 1, | 353 | item: $scope.articulosTabla.length + 1, |
354 | nombre: producto.descripcion, | 354 | nombre: producto.descripcion, |
355 | precio: parseFloat(producto.precio.toFixed(4)), | 355 | precio: parseFloat(producto.precio.toFixed(4)), |
356 | costoUnitario: producto.costo, | 356 | costoUnitario: producto.costo, |
357 | editCantidad: false, | 357 | editCantidad: false, |
358 | editPrecio: false, | 358 | editPrecio: false, |
359 | rubro: producto.CodRub, | 359 | rubro: producto.CodRub, |
360 | exentoUnitario: producto.precio, | 360 | exentoUnitario: producto.precio, |
361 | ivaUnitario: producto.IMPIVA, | 361 | ivaUnitario: producto.IMPIVA, |
362 | impuestoInternoUnitario: producto.ImpInt, | 362 | impuestoInternoUnitario: producto.ImpInt, |
363 | impuestoInterno1Unitario: producto.ImpInt2, | 363 | impuestoInterno1Unitario: producto.ImpInt2, |
364 | impuestoInterno2Unitario: producto.ImpInt3, | 364 | impuestoInterno2Unitario: producto.ImpInt3, |
365 | precioLista: producto.precio, | 365 | precioLista: producto.precio, |
366 | combustible: 1, | 366 | combustible: 1, |
367 | facturado: 0 | 367 | facturado: 0 |
368 | }; | 368 | }; |
369 | $scope.articuloACargar = newArt; | 369 | $scope.articuloACargar = newArt; |
370 | $scope.cargando = false; | 370 | $scope.cargando = false; |
371 | }, function() { | 371 | }, function() { |
372 | // funcion ejecutada cuando se cancela el modal | 372 | // funcion ejecutada cuando se cancela el modal |
373 | } | 373 | } |
374 | ); | 374 | ); |
375 | }; | 375 | }; |
376 | 376 | ||
377 | $scope.seleccionarPuntosDeDescarga = function() { | 377 | $scope.seleccionarPuntosDeDescarga = function() { |
378 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 378 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
379 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 379 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
380 | return; | 380 | return; |
381 | }else{ | 381 | }else { |
382 | var modalInstance = $uibModal.open( | 382 | var modalInstance = $uibModal.open( |
383 | { | 383 | { |
384 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 384 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
385 | templateUrl: 'modal-punto-descarga.html', | 385 | templateUrl: 'modal-punto-descarga.html', |
386 | controller: 'focaModalPuntoDescargaController', | 386 | controller: 'focaModalPuntoDescargaController', |
387 | size: 'lg', | 387 | size: 'lg', |
388 | resolve: { | 388 | resolve: { |
389 | filters: { | 389 | filters: { |
390 | /*TODO: al traer nota de pedido ya creada | 390 | /*TODO: al traer nota de pedido ya creada |
391 | obtener idDomicilio correctamente*/ | 391 | obtener idDomicilio correctamente*/ |
392 | idDomicilio: $scope.notaPedido.domicilio.id, | 392 | idDomicilio: $scope.notaPedido.domicilio.id, |
393 | idCliente: $scope.notaPedido.cliente.COD, | 393 | idCliente: $scope.notaPedido.cliente.COD, |
394 | articulos: $scope.articulosTabla, | 394 | articulos: $scope.articulosTabla, |
395 | puntosDescarga: $scope.notaPedido.puntosDescarga | 395 | puntosDescarga: $scope.notaPedido.puntosDescarga |
396 | } | 396 | } |
397 | } | 397 | } |
398 | } | 398 | } |
399 | ); | 399 | ); |
400 | modalInstance.result.then( | 400 | modalInstance.result.then( |
401 | function(puntosDescarga) { | 401 | function(puntosDescarga) { |
402 | $scope.notaPedido.puntosDescarga = puntosDescarga; | 402 | $scope.notaPedido.puntosDescarga = puntosDescarga; |
403 | }, function() { | 403 | }, function() { |
404 | 404 | ||
405 | } | 405 | } |
406 | ); | 406 | ); |
407 | } | 407 | } |
408 | }; | 408 | }; |
409 | 409 | ||
410 | $scope.seleccionarVendedor = function() { | 410 | $scope.seleccionarVendedor = function() { |
411 | if(validarNotaRemitada()) { | 411 | if(validarNotaRemitada()) { |
412 | var modalInstance = $uibModal.open( | 412 | var modalInstance = $uibModal.open( |
413 | { | 413 | { |
414 | ariaLabelledBy: 'Busqueda de Vendedores', | 414 | ariaLabelledBy: 'Busqueda de Vendedores', |
415 | templateUrl: 'modal-vendedores.html', | 415 | templateUrl: 'modal-vendedores.html', |
416 | controller: 'modalVendedoresCtrl', | 416 | controller: 'modalVendedoresCtrl', |
417 | size: 'lg' | 417 | size: 'lg' |
418 | } | 418 | } |
419 | ); | 419 | ); |
420 | modalInstance.result.then( | 420 | modalInstance.result.then( |
421 | function(vendedor) { | 421 | function(vendedor) { |
422 | $scope.$broadcast('addCabecera', { | 422 | $scope.$broadcast('addCabecera', { |
423 | label: 'Vendedor:', | 423 | label: 'Vendedor:', |
424 | valor: vendedor.NomVen | 424 | valor: vendedor.NomVen |
425 | }); | 425 | }); |
426 | $scope.notaPedido.vendedor = vendedor; | 426 | $scope.notaPedido.vendedor = vendedor; |
427 | }, function() { | 427 | }, function() { |
428 | 428 | ||
429 | } | 429 | } |
430 | ); | 430 | ); |
431 | } | 431 | } |
432 | }; | 432 | }; |
433 | 433 | ||
434 | $scope.seleccionarProveedor = function() { | 434 | $scope.seleccionarProveedor = function() { |
435 | if(validarNotaRemitada()) { | 435 | if(validarNotaRemitada()) { |
436 | var modalInstance = $uibModal.open( | 436 | var modalInstance = $uibModal.open( |
437 | { | 437 | { |
438 | ariaLabelledBy: 'Busqueda de Proveedor', | 438 | ariaLabelledBy: 'Busqueda de Proveedor', |
439 | templateUrl: 'modal-proveedor.html', | 439 | templateUrl: 'modal-proveedor.html', |
440 | controller: 'focaModalProveedorCtrl', | 440 | controller: 'focaModalProveedorCtrl', |
441 | size: 'lg', | 441 | size: 'lg', |
442 | resolve: { | 442 | resolve: { |
443 | transportista: function() { | 443 | transportista: function() { |
444 | return false; | 444 | return false; |
445 | } | 445 | } |
446 | } | 446 | } |
447 | } | 447 | } |
448 | ); | 448 | ); |
449 | modalInstance.result.then( | 449 | modalInstance.result.then( |
450 | function(proveedor) { | 450 | function(proveedor) { |
451 | $scope.notaPedido.proveedor = proveedor; | 451 | $scope.notaPedido.proveedor = proveedor; |
452 | $scope.$broadcast('addCabecera', { | 452 | $scope.$broadcast('addCabecera', { |
453 | label: 'Proveedor:', | 453 | label: 'Proveedor:', |
454 | valor: proveedor.NOM | 454 | valor: proveedor.NOM |
455 | }); | 455 | }); |
456 | }, function() { | 456 | }, function() { |
457 | 457 | ||
458 | } | 458 | } |
459 | ); | 459 | ); |
460 | } | 460 | } |
461 | }; | 461 | }; |
462 | 462 | ||
463 | $scope.seleccionarCliente = function() { | 463 | $scope.seleccionarCliente = function() { |
464 | if(validarNotaRemitada()) { | 464 | if(validarNotaRemitada()) { |
465 | var modalInstance = $uibModal.open( | 465 | var modalInstance = $uibModal.open( |
466 | { | 466 | { |
467 | ariaLabelledBy: 'Busqueda de Cliente', | 467 | ariaLabelledBy: 'Busqueda de Cliente', |
468 | templateUrl: 'foca-busqueda-cliente-modal.html', | 468 | templateUrl: 'foca-busqueda-cliente-modal.html', |
469 | controller: 'focaBusquedaClienteModalController', | 469 | controller: 'focaBusquedaClienteModalController', |
470 | size: 'lg' | 470 | size: 'lg' |
471 | } | 471 | } |
472 | ); | 472 | ); |
473 | modalInstance.result.then( | 473 | modalInstance.result.then( |
474 | function(cliente) { | 474 | function(cliente) { |
475 | $scope.abrirModalDomicilios(cliente); | 475 | $scope.abrirModalDomicilios(cliente); |
476 | }, function() { | 476 | }, function() { |
477 | 477 | ||
478 | } | 478 | } |
479 | ); | 479 | ); |
480 | } | 480 | } |
481 | }; | 481 | }; |
482 | 482 | ||
483 | $scope.abrirModalDomicilios = function(cliente) { | 483 | $scope.abrirModalDomicilios = function(cliente) { |
484 | var modalInstanceDomicilio = $uibModal.open( | 484 | var modalInstanceDomicilio = $uibModal.open( |
485 | { | 485 | { |
486 | ariaLabelledBy: 'Busqueda de Domicilios', | 486 | ariaLabelledBy: 'Busqueda de Domicilios', |
487 | templateUrl: 'modal-domicilio.html', | 487 | templateUrl: 'modal-domicilio.html', |
488 | controller: 'focaModalDomicilioController', | 488 | controller: 'focaModalDomicilioController', |
489 | resolve: { | 489 | resolve: { |
490 | idCliente: function() { | 490 | idCliente: function() { |
491 | return cliente.cod; | 491 | return cliente.cod; |
492 | }, | 492 | }, |
493 | esNuevo: function() { return cliente.esNuevo; }, | 493 | esNuevo: function() { return cliente.esNuevo; }, |
494 | articulos: function() { | 494 | articulos: function() { |
495 | return $scope.articulosTabla; | 495 | return $scope.articulosTabla; |
496 | } | 496 | } |
497 | }, | 497 | }, |
498 | size: 'lg', | 498 | size: 'lg', |
499 | } | 499 | } |
500 | ); | 500 | ); |
501 | modalInstanceDomicilio.result.then( | 501 | modalInstanceDomicilio.result.then( |
502 | function(domicilio) { | 502 | function(domicilio) { |
503 | $scope.notaPedido.domicilio = domicilio; | 503 | $scope.notaPedido.domicilio = domicilio; |
504 | $scope.notaPedido.cliente = { | 504 | $scope.notaPedido.cliente = { |
505 | COD: cliente.cod, | 505 | COD: cliente.cod, |
506 | CUIT: cliente.cuit, | 506 | CUIT: cliente.cuit, |
507 | NOM: cliente.nom | 507 | NOM: cliente.nom |
508 | }; | 508 | }; |
509 | var domicilioStamp = | 509 | var domicilioStamp = |
510 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 510 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
511 | domicilio.Localidad + ', ' + domicilio.Provincia; | 511 | domicilio.Localidad + ', ' + domicilio.Provincia; |
512 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 512 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
513 | 513 | ||
514 | $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; | 514 | $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; |
515 | 515 | ||
516 | $scope.$broadcast('addCabecera', { | 516 | $scope.$broadcast('addCabecera', { |
517 | label: 'Cliente:', | 517 | label: 'Cliente:', |
518 | valor: cliente.nom | 518 | valor: cliente.nom |
519 | }); | 519 | }); |
520 | $scope.$broadcast('addCabecera', { | 520 | $scope.$broadcast('addCabecera', { |
521 | label: 'Domicilio:', | 521 | label: 'Domicilio:', |
522 | valor: domicilioStamp | 522 | valor: domicilioStamp |
523 | }); | 523 | }); |
524 | }, function() { | 524 | }, function() { |
525 | $scope.seleccionarCliente(); | 525 | $scope.seleccionarCliente(); |
526 | return; | 526 | return; |
527 | } | 527 | } |
528 | ); | 528 | ); |
529 | }; | 529 | }; |
530 | 530 | ||
531 | $scope.getTotal = function() { | 531 | $scope.getTotal = function() { |
532 | var total = 0; | 532 | var total = 0; |
533 | var arrayTempArticulos = $scope.articulosTabla; | 533 | var arrayTempArticulos = $scope.articulosTabla; |
534 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 534 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
535 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 535 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
536 | } | 536 | } |
537 | return parseFloat(total.toFixed(2)); | 537 | return parseFloat(total.toFixed(2)); |
538 | }; | 538 | }; |
539 | 539 | ||
540 | $scope.getSubTotal = function() { | 540 | $scope.getSubTotal = function() { |
541 | if($scope.articuloACargar) { | 541 | if($scope.articuloACargar) { |
542 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 542 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
543 | } | 543 | } |
544 | }; | 544 | }; |
545 | 545 | ||
546 | $scope.seleccionarPreciosYCondiciones = function() { | 546 | $scope.seleccionarPreciosYCondiciones = function() { |
547 | if(validarNotaRemitada()) { | 547 | if(validarNotaRemitada()) { |
548 | var modalInstance = $uibModal.open( | 548 | var modalInstance = $uibModal.open( |
549 | { | 549 | { |
550 | ariaLabelledBy: 'Busqueda de Precio Condición', | 550 | ariaLabelledBy: 'Busqueda de Precio Condición', |
551 | templateUrl: 'modal-precio-condicion.html', | 551 | templateUrl: 'modal-precio-condicion.html', |
552 | controller: 'focaModalPrecioCondicionController', | 552 | controller: 'focaModalPrecioCondicionController', |
553 | size: 'lg' | 553 | size: 'lg' |
554 | } | 554 | } |
555 | ); | 555 | ); |
556 | modalInstance.result.then( | 556 | modalInstance.result.then( |
557 | function(precioCondicion) { | 557 | function(precioCondicion) { |
558 | var cabecera = ''; | 558 | var cabecera = ''; |
559 | var plazosConcat = ''; | 559 | var plazosConcat = ''; |
560 | if(!Array.isArray(precioCondicion)) { | 560 | if(!Array.isArray(precioCondicion)) { |
561 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 561 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
562 | $scope.plazosPagos = precioCondicion.plazoPago; | 562 | $scope.plazosPagos = precioCondicion.plazoPago; |
563 | $scope.idLista = precioCondicion.idListaPrecio; | 563 | $scope.idLista = precioCondicion.idListaPrecio; |
564 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 564 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
565 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 565 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
566 | } | 566 | } |
567 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 567 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
568 | } else { //Cuando se ingresan los plazos manualmente | 568 | } else { //Cuando se ingresan los plazos manualmente |
569 | $scope.notaPedido.idPrecioCondicion = 0; | 569 | $scope.notaPedido.idPrecioCondicion = 0; |
570 | //-1, el modal productos busca todos los productos | 570 | //-1, el modal productos busca todos los productos |
571 | $scope.idLista = -1; | 571 | $scope.idLista = -1; |
572 | $scope.plazosPagos = precioCondicion; | 572 | $scope.plazosPagos = precioCondicion; |
573 | for(var j = 0; j < precioCondicion.length; j++) { | 573 | for(var j = 0; j < precioCondicion.length; j++) { |
574 | plazosConcat += precioCondicion[j].dias + ' '; | 574 | plazosConcat += precioCondicion[j].dias + ' '; |
575 | } | 575 | } |
576 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 576 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
577 | } | 577 | } |
578 | $scope.articulosTabla = []; | 578 | $scope.articulosTabla = []; |
579 | $scope.$broadcast('addCabecera', { | 579 | $scope.$broadcast('addCabecera', { |
580 | label: 'Precios y condiciones:', | 580 | label: 'Precios y condiciones:', |
581 | valor: cabecera | 581 | valor: cabecera |
582 | }); | 582 | }); |
583 | }, function() { | 583 | }, function() { |
584 | 584 | ||
585 | } | 585 | } |
586 | ); | 586 | ); |
587 | } | 587 | } |
588 | }; | 588 | }; |
589 | 589 | ||
590 | $scope.seleccionarFlete = function() { | 590 | $scope.seleccionarFlete = function() { |
591 | if(validarNotaRemitada()) { | 591 | if(validarNotaRemitada()) { |
592 | var modalInstance = $uibModal.open( | 592 | var modalInstance = $uibModal.open( |
593 | { | 593 | { |
594 | ariaLabelledBy: 'Busqueda de Flete', | 594 | ariaLabelledBy: 'Busqueda de Flete', |
595 | templateUrl: 'modal-flete.html', | 595 | templateUrl: 'modal-flete.html', |
596 | controller: 'focaModalFleteController', | 596 | controller: 'focaModalFleteController', |
597 | size: 'lg', | 597 | size: 'lg', |
598 | resolve: { | 598 | resolve: { |
599 | parametrosFlete: | 599 | parametrosFlete: |
600 | function() { | 600 | function() { |
601 | return { | 601 | return { |
602 | flete: $scope.notaPedido.fob ? 'FOB' : | 602 | flete: $scope.notaPedido.fob ? 'FOB' : |
603 | ( $scope.notaPedido.flete ? '1' : | 603 | ( $scope.notaPedido.flete ? '1' : |
604 | ($scope.notaPedido.flete === undefined ? | 604 | ($scope.notaPedido.flete === undefined ? |
605 | null : '0')), | 605 | null : '0')), |
606 | bomba: $scope.notaPedido.bomba ? '1' : | 606 | bomba: $scope.notaPedido.bomba ? '1' : |
607 | ($scope.notaPedido.bomba === undefined ? | 607 | ($scope.notaPedido.bomba === undefined ? |
608 | null : '0'), | 608 | null : '0'), |
609 | kilometros: $scope.notaPedido.kilometros | 609 | kilometros: $scope.notaPedido.kilometros |
610 | }; | 610 | }; |
611 | } | 611 | } |
612 | } | 612 | } |
613 | } | 613 | } |
614 | ); | 614 | ); |
615 | modalInstance.result.then( | 615 | modalInstance.result.then( |
616 | function(datos) { | 616 | function(datos) { |
617 | $scope.notaPedido.flete = datos.flete; | 617 | $scope.notaPedido.flete = datos.flete; |
618 | $scope.notaPedido.fob = datos.FOB; | 618 | $scope.notaPedido.fob = datos.FOB; |
619 | $scope.notaPedido.bomba = datos.bomba; | 619 | $scope.notaPedido.bomba = datos.bomba; |
620 | $scope.notaPedido.kilometros = datos.kilometros; | 620 | $scope.notaPedido.kilometros = datos.kilometros; |
621 | $scope.$broadcast('addCabecera', { | 621 | $scope.$broadcast('addCabecera', { |
622 | label: 'Flete:', | 622 | label: 'Flete:', |
623 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 623 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
624 | }); | 624 | }); |
625 | if(datos.flete) { | 625 | if(datos.flete) { |
626 | $scope.$broadcast('addCabecera', { | 626 | $scope.$broadcast('addCabecera', { |
627 | label: 'Bomba:', | 627 | label: 'Bomba:', |
628 | valor: datos.bomba ? 'Si' : 'No' | 628 | valor: datos.bomba ? 'Si' : 'No' |
629 | }); | 629 | }); |
630 | $scope.$broadcast('addCabecera', { | 630 | $scope.$broadcast('addCabecera', { |
631 | label: 'Kilometros:', | 631 | label: 'Kilometros:', |
632 | valor: datos.kilometros | 632 | valor: datos.kilometros |
633 | }); | 633 | }); |
634 | } else { | 634 | } else { |
635 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 635 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
636 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 636 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
637 | $scope.notaPedido.bomba = false; | 637 | $scope.notaPedido.bomba = false; |
638 | $scope.notaPedido.kilometros = null; | 638 | $scope.notaPedido.kilometros = null; |
639 | } | 639 | } |
640 | }, function() { | 640 | }, function() { |
641 | 641 | ||
642 | } | 642 | } |
643 | ); | 643 | ); |
644 | } | 644 | } |
645 | }; | 645 | }; |
646 | 646 | ||
647 | $scope.seleccionarMoneda = function() { | 647 | $scope.seleccionarMoneda = function() { |
648 | if(validarNotaRemitada()) { | 648 | if(validarNotaRemitada()) { |
649 | var modalInstance = $uibModal.open( | 649 | var modalInstance = $uibModal.open( |
650 | { | 650 | { |
651 | ariaLabelledBy: 'Busqueda de Moneda', | 651 | ariaLabelledBy: 'Busqueda de Moneda', |
652 | templateUrl: 'modal-moneda.html', | 652 | templateUrl: 'modal-moneda.html', |
653 | controller: 'focaModalMonedaController', | 653 | controller: 'focaModalMonedaController', |
654 | size: 'lg' | 654 | size: 'lg' |
655 | } | 655 | } |
656 | ); | 656 | ); |
657 | modalInstance.result.then( | 657 | modalInstance.result.then( |
658 | function(moneda) { | 658 | function(moneda) { |
659 | $scope.abrirModalCotizacion(moneda); | 659 | $scope.abrirModalCotizacion(moneda); |
660 | }, function() { | 660 | }, function() { |
661 | 661 | ||
662 | } | 662 | } |
663 | ); | 663 | ); |
664 | } | 664 | } |
665 | }; | 665 | }; |
666 | 666 | ||
667 | $scope.abrirModalCotizacion = function(moneda) { | 667 | $scope.abrirModalCotizacion = function(moneda) { |
668 | var modalInstance = $uibModal.open( | 668 | var modalInstance = $uibModal.open( |
669 | { | 669 | { |
670 | ariaLabelledBy: 'Busqueda de Cotización', | 670 | ariaLabelledBy: 'Busqueda de Cotización', |
671 | templateUrl: 'modal-cotizacion.html', | 671 | templateUrl: 'modal-cotizacion.html', |
672 | controller: 'focaModalCotizacionController', | 672 | controller: 'focaModalCotizacionController', |
673 | size: 'lg', | 673 | size: 'lg', |
674 | resolve: {idMoneda: function() {return moneda.ID;}} | 674 | resolve: {idMoneda: function() {return moneda.ID;}} |
675 | } | 675 | } |
676 | ); | 676 | ); |
677 | modalInstance.result.then( | 677 | modalInstance.result.then( |
678 | function(cotizacion) { | 678 | function(cotizacion) { |
679 | var articulosTablaTemp = $scope.articulosTabla; | 679 | var articulosTablaTemp = $scope.articulosTabla; |
680 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 680 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
681 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 681 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
682 | $scope.notaPedido.cotizacion.VENDEDOR; | 682 | $scope.notaPedido.cotizacion.VENDEDOR; |
683 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 683 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
684 | cotizacion.VENDEDOR; | 684 | cotizacion.VENDEDOR; |
685 | } | 685 | } |
686 | $scope.articulosTabla = articulosTablaTemp; | 686 | $scope.articulosTabla = articulosTablaTemp; |
687 | $scope.notaPedido.moneda = moneda; | 687 | $scope.notaPedido.moneda = moneda; |
688 | $scope.notaPedido.cotizacion = cotizacion; | 688 | $scope.notaPedido.cotizacion = cotizacion; |
689 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { | 689 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
690 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 690 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
691 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 691 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
692 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 692 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
693 | }else { | 693 | }else { |
694 | $scope.$broadcast('addCabecera', { | 694 | $scope.$broadcast('addCabecera', { |
695 | label: 'Moneda:', | 695 | label: 'Moneda:', |
696 | valor: moneda.DETALLE | 696 | valor: moneda.DETALLE |
697 | }); | 697 | }); |
698 | $scope.$broadcast('addCabecera', { | 698 | $scope.$broadcast('addCabecera', { |
699 | label: 'Fecha cotizacion:', | 699 | label: 'Fecha cotizacion:', |
700 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 700 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
701 | }); | 701 | }); |
702 | $scope.$broadcast('addCabecera', { | 702 | $scope.$broadcast('addCabecera', { |
703 | label: 'Cotizacion:', | 703 | label: 'Cotizacion:', |
704 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 704 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
705 | }); | 705 | }); |
706 | } | 706 | } |
707 | }, function() { | 707 | }, function() { |
708 | 708 | ||
709 | } | 709 | } |
710 | ); | 710 | ); |
711 | }; | 711 | }; |
712 | 712 | ||
713 | $scope.agregarATabla = function(key) { | 713 | $scope.agregarATabla = function(key) { |
714 | if(key === 13) { | 714 | if(key === 13) { |
715 | if($scope.articuloACargar.cantidad === undefined || | 715 | if($scope.articuloACargar.cantidad === undefined || |
716 | $scope.articuloACargar.cantidad === 0 || | 716 | $scope.articuloACargar.cantidad === 0 || |
717 | $scope.articuloACargar.cantidad === null ) { | 717 | $scope.articuloACargar.cantidad === null ) { |
718 | focaModalService.alert('El valor debe ser al menos 1'); | 718 | focaModalService.alert('El valor debe ser al menos 1'); |
719 | return; | 719 | return; |
720 | } | 720 | } |
721 | delete $scope.articuloACargar.sectorCodigo; | 721 | delete $scope.articuloACargar.sectorCodigo; |
722 | $scope.articulosTabla.push($scope.articuloACargar); | 722 | $scope.articulosTabla.push($scope.articuloACargar); |
723 | $scope.cargando = true; | 723 | $scope.cargando = true; |
724 | } | 724 | } |
725 | }; | 725 | }; |
726 | 726 | ||
727 | $scope.quitarArticulo = function(key) { | 727 | $scope.quitarArticulo = function(key) { |
728 | $scope.articulosTabla.splice(key, 1); | 728 | $scope.articulosTabla.splice(key, 1); |
729 | }; | 729 | }; |
730 | 730 | ||
731 | $scope.editarArticulo = function(key, articulo) { | 731 | $scope.editarArticulo = function(key, articulo) { |
732 | if(key === 13) { | 732 | if(key === 13) { |
733 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 733 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
734 | articulo.cantidad === undefined) { | 734 | articulo.cantidad === undefined) { |
735 | focaModalService.alert('El valor debe ser al menos 1'); | 735 | focaModalService.alert('El valor debe ser al menos 1'); |
736 | return; | 736 | return; |
737 | } | 737 | } |
738 | articulo.editCantidad = false; | 738 | articulo.editCantidad = false; |
739 | articulo.editPrecio = false; | 739 | articulo.editPrecio = false; |
740 | } | 740 | } |
741 | }; | 741 | }; |
742 | 742 | ||
743 | $scope.cambioEdit = function(articulo, propiedad) { | 743 | $scope.cambioEdit = function(articulo, propiedad) { |
744 | if(propiedad === 'cantidad') { | 744 | if(propiedad === 'cantidad') { |
745 | articulo.editCantidad = true; | 745 | articulo.editCantidad = true; |
746 | } else if(propiedad === 'precio') { | 746 | } else if(propiedad === 'precio') { |
747 | articulo.editPrecio = true; | 747 | articulo.editPrecio = true; |
748 | } | 748 | } |
749 | }; | 749 | }; |
750 | 750 | ||
751 | $scope.resetFilter = function() { | 751 | $scope.resetFilter = function() { |
752 | $scope.articuloACargar = {}; | 752 | $scope.articuloACargar = {}; |
753 | $scope.cargando = true; | 753 | $scope.cargando = true; |
754 | }; | 754 | }; |
755 | //Recibe aviso si el teclado está en uso | 755 | //Recibe aviso si el teclado está en uso |
756 | $rootScope.$on('usarTeclado', function(event, data) { | 756 | $rootScope.$on('usarTeclado', function(event, data) { |
757 | if(data) { | 757 | if(data) { |
758 | $scope.mostrarTeclado = true; | 758 | $scope.mostrarTeclado = true; |
759 | return; | 759 | return; |
760 | } | 760 | } |
761 | $scope.mostrarTeclado = false; | 761 | $scope.mostrarTeclado = false; |
762 | }); | 762 | }); |
763 | 763 | ||
764 | $scope.selectFocus = function($event) { | 764 | $scope.selectFocus = function($event) { |
765 | // Si el teclado esta en uso no selecciona el valor | 765 | // Si el teclado esta en uso no selecciona el valor |
766 | if($scope.mostrarTeclado) { | 766 | if($scope.mostrarTeclado) { |
767 | return; | 767 | return; |
768 | } | 768 | } |
769 | $event.target.select(); | 769 | $event.target.select(); |
770 | }; | 770 | }; |
771 | 771 | ||
772 | $scope.salir = function() { | 772 | $scope.salir = function() { |
773 | $location.path('/'); | 773 | $location.path('/'); |
774 | }; | 774 | }; |
775 | 775 | ||
776 | $scope.parsearATexto = function(articulo) { | 776 | $scope.parsearATexto = function(articulo) { |
777 | articulo.cantidad = parseFloat(articulo.cantidad); | 777 | articulo.cantidad = parseFloat(articulo.cantidad); |
778 | articulo.precio = parseFloat(articulo.precio); | 778 | articulo.precio = parseFloat(articulo.precio); |
779 | }; | 779 | }; |
780 | 780 | ||
781 | function addArrayCabecera(array) { | 781 | function addArrayCabecera(array) { |
782 | for(var i = 0; i < array.length; i++) { | 782 | for(var i = 0; i < array.length; i++) { |
783 | $scope.$broadcast('addCabecera', { | 783 | $scope.$broadcast('addCabecera', { |
784 | label: array[i].label, | 784 | label: array[i].label, |
785 | valor: array[i].valor | 785 | valor: array[i].valor |
786 | }); | 786 | }); |
787 | } | 787 | } |
788 | } | 788 | } |
789 | 789 | ||
790 | function rellenar(relleno, longitud) { | 790 | function rellenar(relleno, longitud) { |
791 | relleno = '' + relleno; | 791 | relleno = '' + relleno; |
792 | while (relleno.length < longitud) { | 792 | while (relleno.length < longitud) { |
793 | relleno = '0' + relleno; | 793 | relleno = '0' + relleno; |
794 | } | 794 | } |
795 | 795 | ||
796 | return relleno; | 796 | return relleno; |
797 | } | 797 | } |
798 | 798 | ||
799 | function validarNotaRemitada() { | 799 | function validarNotaRemitada() { |
800 | if(!$scope.notaPedido.idRemito) { | 800 | if(!$scope.notaPedido.idRemito) { |
801 | return true; | 801 | return true; |
802 | }else{ | 802 | }else{ |
803 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 803 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
804 | return false; | 804 | return false; |
805 | } | 805 | } |
806 | } | 806 | } |
807 | 807 | function formatearPuntosDescarga(puntosDescarga) { | |
808 | function formatearPuntosDescarga(notaPedidoPuntoDescarga) { | ||
809 | var result = []; | 808 | var result = []; |
810 | 809 | ||
811 | notaPedidoPuntoDescarga.forEach(function(el) { | 810 | puntosDescarga.forEach(function(el) { |
812 | var puntoDescarga = result.filter(function(resultPunto) { | 811 | var puntoDescarga = result.filter(function(resultPunto) { |
813 | return resultPunto.id == el.idPuntoDescarga; | 812 | return resultPunto.id == el.idPuntoDescarga; |
814 | }); | 813 | }); |
815 | 814 | ||
816 | if(puntoDescarga.length) { | 815 | if(puntoDescarga.length) { |
817 | puntoDescarga[0].articulosAgregados.push({ | 816 | puntoDescarga[0].articulosAgregados.push({ |
818 | cantidad: el.cantidad, | 817 | cantidad: el.cantidad, |
819 | descripcion: el.producto.descripcion, | 818 | descripcion: el.producto.descripcion, |
820 | id: el.producto.id | 819 | id: el.producto.id |
821 | }); | 820 | }); |
822 | }else { | 821 | }else { |
823 | result.push({ | 822 | result.push({ |
824 | id: el.puntoDescarga.id, | 823 | id: el.puntoDescarga.id, |
825 | id_cliente: el.puntoDescarga.id_cliente, | 824 | id_cliente: el.puntoDescarga.id_cliente, |
826 | id_da_config_0: el.puntoDescarga.id_da_config_0, | 825 | id_da_config_0: el.puntoDescarga.id_da_config_0, |
827 | latitud: el.puntoDescarga.latitud, | 826 | latitud: el.puntoDescarga.latitud, |
828 | longitud: el.puntoDescarga.longitud, | 827 | longitud: el.puntoDescarga.longitud, |
829 | descripcion: el.puntoDescarga.descripcion, | 828 | descripcion: el.puntoDescarga.descripcion, |
830 | articulosAgregados: [ | 829 | articulosAgregados: [ |
831 | { | 830 | { |
832 | cantidad: el.cantidad, | 831 | cantidad: el.cantidad, |
833 | descripcion: el.producto.descripcion, | 832 | descripcion: el.producto.descripcion, |
834 | id: el.producto.id | 833 | id: el.producto.id |
835 | } | 834 | } |
836 | ] | 835 | ] |
837 | }); | 836 | }); |
838 | } | 837 | } |
839 | |||
840 | }); | 838 | }); |
841 | return result; | 839 | return result; |
842 | } | 840 | } |
843 | } | 841 | } |
844 | ]); | 842 | ]); |
845 | 843 |