Commit d7c76f29c4b65bfbd7d1765fd3c6a37ecf3d201f
Exists in
master
Merge branch 'master' into 'master'
Master See merge request !47
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 | 'APP', | 14 | 'APP', |
15 | 'focaLoginService', | 15 | 'focaLoginService', |
16 | function( | 16 | function( |
17 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, | 17 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, |
18 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, | 18 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, |
19 | $rootScope, focaSeguimientoService, APP, focaLoginService) | 19 | $rootScope, focaSeguimientoService, APP, focaLoginService) |
20 | { | 20 | { |
21 | config(); | 21 | config(); |
22 | 22 | ||
23 | function config() { | 23 | function config() { |
24 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA | 24 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA |
25 | $scope.isNumber = angular.isNumber; | 25 | $scope.isNumber = angular.isNumber; |
26 | $scope.datepickerAbierto = false; | 26 | $scope.datepickerAbierto = false; |
27 | $scope.show = false; | 27 | $scope.show = false; |
28 | $scope.cargando = true; | 28 | $scope.cargando = true; |
29 | $scope.now = new Date(); | 29 | $scope.now = new Date(); |
30 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 30 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
31 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 31 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
32 | $scope.dateOptions = { | 32 | $scope.dateOptions = { |
33 | maxDate: new Date(), | 33 | maxDate: new Date(), |
34 | minDate: new Date(2010, 0, 1) | 34 | minDate: new Date(2010, 0, 1) |
35 | }; | 35 | }; |
36 | 36 | ||
37 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | ||
38 | var monedaPorDefecto; | ||
39 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | ||
40 | monedaPorDefecto = res.data[0]; | ||
41 | |||
42 | $scope.notaPedido.moneda = monedaPorDefecto; | ||
43 | $scope.inicial.notaPedido.moneda = $scope.notaPedido.moneda; | ||
44 | |||
45 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; | ||
46 | $scope.inicial.notaPedido.cotizacion = $scope.notaPedido.cotizacion; | ||
47 | }); | ||
48 | |||
49 | //SETEO BOTONERA LATERAL | 37 | //SETEO BOTONERA LATERAL |
50 | $timeout(function() { | 38 | $timeout(function() { |
51 | focaBotoneraLateralService.showSalir(false); | 39 | focaBotoneraLateralService.showSalir(false); |
52 | focaBotoneraLateralService.showPausar(true); | 40 | focaBotoneraLateralService.showPausar(true); |
53 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 41 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
54 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 42 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
55 | }); | 43 | }); |
56 | 44 | ||
57 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR | 45 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR |
58 | if (APP === 'distribuidor') { | 46 | if (APP === 'distribuidor') { |
59 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; | 47 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
60 | $scope.botonera = crearNotaPedidoService.getBotonera($scope.idVendedor); | 48 | $scope.botonera = crearNotaPedidoService.getBotonera($scope.idVendedor); |
61 | } else { | 49 | } else { |
62 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 50 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
63 | } | 51 | } |
64 | 52 | ||
65 | init(); | 53 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
54 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | ||
55 | $scope.monedaDefecto = res.data[0]; | ||
56 | $scope.cotizacionDefecto = $scope.monedaDefecto.cotizaciones[0]; | ||
57 | |||
58 | init(); | ||
59 | }); | ||
66 | } | 60 | } |
67 | 61 | ||
68 | function init() { | 62 | function init() { |
69 | $scope.$broadcast('cleanCabecera'); | 63 | $scope.$broadcast('cleanCabecera'); |
70 | 64 | ||
71 | $scope.notaPedido = { | 65 | $scope.notaPedido = { |
72 | id: 0, | 66 | id: 0, |
73 | cliente: {}, | 67 | cliente: {}, |
74 | proveedor: {}, | 68 | proveedor: {}, |
75 | domicilio: {dom: ''}, | 69 | domicilio: {dom: ''}, |
76 | vendedor: {} | 70 | vendedor: {}, |
71 | moneda: $scope.monedaDefecto, | ||
72 | cotizacion: $scope.cotizacionDefecto | ||
77 | }; | 73 | }; |
78 | 74 | ||
79 | $scope.articulosTabla = []; | 75 | $scope.articulosTabla = []; |
80 | $scope.idLista = undefined; | 76 | $scope.idLista = undefined; |
81 | 77 | ||
82 | crearNotaPedidoService.getNumeroNotaPedido().then( | 78 | crearNotaPedidoService.getNumeroNotaPedido().then( |
83 | function(res) { | 79 | function(res) { |
84 | $scope.puntoVenta = $filter('rellenarDigitos')( | 80 | $scope.puntoVenta = $filter('rellenarDigitos')( |
85 | res.data.sucursal, 4 | 81 | res.data.sucursal, 4 |
86 | ); | 82 | ); |
87 | 83 | ||
88 | $scope.comprobante = $filter('rellenarDigitos')( | 84 | $scope.comprobante = $filter('rellenarDigitos')( |
89 | res.data.numeroNotaPedido, 8 | 85 | res.data.numeroNotaPedido, 8 |
90 | ); | 86 | ); |
91 | }, | 87 | }, |
92 | function(err) { | 88 | function(err) { |
93 | focaModalService.alert('La terminal no esta configurada correctamente'); | 89 | focaModalService.alert('La terminal no esta configurada correctamente'); |
94 | console.info(err); | 90 | console.info(err); |
95 | } | 91 | } |
96 | ); | 92 | ); |
97 | 93 | ||
98 | if (APP === 'distribuidor') { | 94 | if (APP === 'distribuidor') { |
99 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( | 95 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( |
100 | function(res) { | 96 | function(res) { |
101 | var vendedor = res.data; | 97 | var vendedor = res.data; |
102 | $scope.$broadcast('addCabecera', { | 98 | $scope.$broadcast('addCabecera', { |
103 | label: 'Vendedor:', | 99 | label: 'Vendedor:', |
104 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 100 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
105 | vendedor.NOM | 101 | vendedor.NOM |
106 | }); | 102 | }); |
107 | 103 | ||
108 | $scope.notaPedido.vendedor = vendedor; | 104 | $scope.notaPedido.vendedor = vendedor; |
109 | $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor; | 105 | $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor; |
110 | } | 106 | } |
111 | ); | 107 | ); |
112 | } | 108 | } |
113 | 109 | ||
114 | $scope.inicial = { | 110 | $scope.inicial = { |
115 | notaPedido: angular.copy($scope.notaPedido), | 111 | notaPedido: angular.copy($scope.notaPedido), |
116 | articulosTabla: angular.copy($scope.articulosTabla), | 112 | articulosTabla: angular.copy($scope.articulosTabla), |
117 | idLista: angular.copy($scope.idLista) | 113 | idLista: angular.copy($scope.idLista) |
118 | }; | 114 | }; |
119 | } | 115 | } |
120 | 116 | ||
121 | $scope.crearNotaPedido = function() { | 117 | $scope.crearNotaPedido = function() { |
122 | if(!$scope.notaPedido.vendedor.id) { | 118 | if(!$scope.notaPedido.vendedor.id) { |
123 | focaModalService.alert('Ingrese Vendedor'); | 119 | focaModalService.alert('Ingrese Vendedor'); |
124 | return; | 120 | return; |
125 | } else if(!$scope.notaPedido.cliente.COD) { | 121 | } else if(!$scope.notaPedido.cliente.COD) { |
126 | focaModalService.alert('Ingrese Cliente'); | 122 | focaModalService.alert('Ingrese Cliente'); |
127 | return; | 123 | return; |
128 | } else if(!$scope.notaPedido.proveedor.COD) { | 124 | } else if(!$scope.notaPedido.proveedor.COD) { |
129 | focaModalService.alert('Ingrese Proveedor'); | 125 | focaModalService.alert('Ingrese Proveedor'); |
130 | return; | 126 | return; |
131 | } else if(!$scope.notaPedido.moneda.ID) { | 127 | } else if(!$scope.notaPedido.moneda.ID) { |
132 | focaModalService.alert('Ingrese Moneda'); | 128 | focaModalService.alert('Ingrese Moneda'); |
133 | return; | 129 | return; |
134 | } else if(!$scope.notaPedido.cotizacion.ID) { | 130 | } else if(!$scope.notaPedido.cotizacion.ID) { |
135 | focaModalService.alert('Ingrese Cotización'); | 131 | focaModalService.alert('Ingrese Cotización'); |
136 | return; | 132 | return; |
137 | } else if(!$scope.plazosPagos) { | 133 | } else if(!$scope.plazosPagos) { |
138 | focaModalService.alert('Ingrese Precios y Condiciones'); | 134 | focaModalService.alert('Ingrese Precios y Condiciones'); |
139 | return; | 135 | return; |
140 | } else if( | 136 | } else if( |
141 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 137 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
142 | { | 138 | { |
143 | focaModalService.alert('Ingrese Flete'); | 139 | focaModalService.alert('Ingrese Flete'); |
144 | return; | 140 | return; |
145 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 141 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
146 | focaModalService.alert('Ingrese Domicilio'); | 142 | focaModalService.alert('Ingrese Domicilio'); |
147 | return; | 143 | return; |
148 | } else if($scope.articulosTabla.length === 0) { | 144 | } else if($scope.articulosTabla.length === 0) { |
149 | focaModalService.alert('Debe cargar al menos un articulo'); | 145 | focaModalService.alert('Debe cargar al menos un articulo'); |
150 | return; | 146 | return; |
151 | } | 147 | } |
152 | focaBotoneraLateralService.startGuardar(); | 148 | focaBotoneraLateralService.startGuardar(); |
153 | $scope.saveLoading = true; | 149 | $scope.saveLoading = true; |
154 | var notaPedido = { | 150 | var notaPedido = { |
155 | id: $scope.notaPedido.id, | 151 | id: $scope.notaPedido.id, |
156 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | 152 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
157 | idVendedor: $scope.notaPedido.vendedor.id, | 153 | idVendedor: $scope.notaPedido.vendedor.id, |
158 | idCliente: $scope.notaPedido.cliente.COD, | 154 | idCliente: $scope.notaPedido.cliente.COD, |
159 | nombreCliente: $scope.notaPedido.cliente.NOM, | 155 | nombreCliente: $scope.notaPedido.cliente.NOM, |
160 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 156 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
161 | idProveedor: $scope.notaPedido.proveedor.COD, | 157 | idProveedor: $scope.notaPedido.proveedor.COD, |
162 | idDomicilio: $scope.notaPedido.domicilio.id, | 158 | idDomicilio: $scope.notaPedido.domicilio.id, |
163 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 159 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
164 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 160 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
165 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 161 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
166 | flete: $scope.notaPedido.flete, | 162 | flete: $scope.notaPedido.flete, |
167 | fob: $scope.notaPedido.fob, | 163 | fob: $scope.notaPedido.fob, |
168 | bomba: $scope.notaPedido.bomba, | 164 | bomba: $scope.notaPedido.bomba, |
169 | kilometros: $scope.notaPedido.kilometros, | 165 | kilometros: $scope.notaPedido.kilometros, |
170 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 166 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
171 | observaciones: $scope.notaPedido.observaciones, | 167 | observaciones: $scope.notaPedido.observaciones, |
172 | estado: 0, | 168 | estado: 0, |
173 | total: $scope.getTotal() | 169 | total: $scope.getTotal() |
174 | }; | 170 | }; |
175 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 171 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
176 | function(data) { | 172 | function(data) { |
177 | // Al guardar los datos de la nota de pedido logueamos la | 173 | // Al guardar los datos de la nota de pedido logueamos la |
178 | // actividad para su seguimiento. | 174 | // actividad para su seguimiento. |
179 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 175 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
180 | focaSeguimientoService.guardarPosicion( | 176 | focaSeguimientoService.guardarPosicion( |
181 | 'Nota de pedido', | 177 | 'Nota de pedido', |
182 | data.data.id, | 178 | data.data.id, |
183 | '' | 179 | '' |
184 | ); | 180 | ); |
185 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | 181 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, |
186 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 182 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
187 | 183 | ||
188 | if($scope.notaPedido.puntosDescarga) { | 184 | if($scope.notaPedido.puntosDescarga) { |
189 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 185 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
190 | $scope.notaPedido.puntosDescarga); | 186 | $scope.notaPedido.puntosDescarga); |
191 | } | 187 | } |
192 | 188 | ||
193 | var plazos = $scope.plazosPagos; | 189 | var plazos = $scope.plazosPagos; |
194 | var plazosACrear = []; | 190 | var plazosACrear = []; |
195 | plazos.forEach(function(plazo) { | 191 | plazos.forEach(function(plazo) { |
196 | plazosACrear.push({ | 192 | plazosACrear.push({ |
197 | idNotaPedido: data.data.id, | 193 | idNotaPedido: data.data.id, |
198 | dias: plazo.dias | 194 | dias: plazo.dias |
199 | }); | 195 | }); |
200 | }); | 196 | }); |
201 | 197 | ||
202 | if (plazosACrear.length) { | 198 | if (plazosACrear.length) { |
203 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 199 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
204 | } | 200 | } |
205 | 201 | ||
206 | notaPedidoBusinessService.addEstado(data.data.id, | 202 | notaPedidoBusinessService.addEstado(data.data.id, |
207 | $scope.notaPedido.vendedor.id); | 203 | $scope.notaPedido.vendedor.id); |
208 | 204 | ||
209 | focaBotoneraLateralService.endGuardar(true); | 205 | focaBotoneraLateralService.endGuardar(true); |
210 | $scope.saveLoading = false; | 206 | $scope.saveLoading = false; |
211 | 207 | ||
212 | init(); | 208 | init(); |
213 | }, function(error) { | 209 | }, function(error) { |
214 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 210 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
215 | focaBotoneraLateralService.endGuardar(); | 211 | focaBotoneraLateralService.endGuardar(); |
216 | $scope.saveLoading = false; | 212 | $scope.saveLoading = false; |
217 | console.info(error); | 213 | console.info(error); |
218 | } | 214 | } |
219 | ); | 215 | ); |
220 | }; | 216 | }; |
221 | 217 | ||
222 | $scope.seleccionarNotaPedido = function() { | 218 | $scope.seleccionarNotaPedido = function() { |
223 | var modalInstance = $uibModal.open( | 219 | var modalInstance = $uibModal.open( |
224 | { | 220 | { |
225 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 221 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
226 | templateUrl: 'foca-modal-nota-pedido.html', | 222 | templateUrl: 'foca-modal-nota-pedido.html', |
227 | controller: 'focaModalNotaPedidoController', | 223 | controller: 'focaModalNotaPedidoController', |
228 | size: 'lg', | 224 | size: 'lg', |
229 | resolve: { | 225 | resolve: { |
230 | usadoPor: function() {return 'notaPedido';}, | 226 | usadoPor: function() {return 'notaPedido';}, |
231 | idVendedor: function() { | 227 | idVendedor: function() { |
232 | if(APP === 'distribuidor') | 228 | if(APP === 'distribuidor') |
233 | return $scope.notaPedido.vendedor.id; | 229 | return $scope.notaPedido.vendedor.id; |
234 | else | 230 | else |
235 | return null; | 231 | return null; |
236 | } | 232 | } |
237 | } | 233 | } |
238 | } | 234 | } |
239 | ); | 235 | ); |
240 | modalInstance.result.then( | 236 | modalInstance.result.then( |
241 | function(notaPedido) { | 237 | function(notaPedido) { |
242 | $scope.now = new Date(notaPedido.fechaCarga); | 238 | $scope.now = new Date(notaPedido.fechaCarga); |
243 | //añado cabeceras | 239 | //añado cabeceras |
244 | $scope.notaPedido.id = notaPedido.id; | 240 | $scope.notaPedido.id = notaPedido.id; |
245 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 241 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
246 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 242 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
247 | var cabeceras = [ | 243 | var cabeceras = [ |
248 | { | 244 | { |
249 | label: 'Moneda:', | 245 | label: 'Moneda:', |
250 | valor: notaPedido.cotizacion.moneda.DETALLE | 246 | valor: notaPedido.cotizacion.moneda.DETALLE |
251 | }, | 247 | }, |
252 | { | 248 | { |
253 | label: 'Fecha cotizacion:', | 249 | label: 'Fecha cotizacion:', |
254 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 250 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
255 | 'dd/MM/yyyy') | 251 | 'dd/MM/yyyy') |
256 | }, | 252 | }, |
257 | { | 253 | { |
258 | label: 'Cotizacion:', | 254 | label: 'Cotizacion:', |
259 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 255 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
260 | '2') | 256 | '2') |
261 | }, | 257 | }, |
262 | { | 258 | { |
263 | label: 'Cliente:', | 259 | label: 'Cliente:', |
264 | valor: notaPedido.cliente.NOM | 260 | valor: notaPedido.cliente.NOM |
265 | }, | 261 | }, |
266 | { | 262 | { |
267 | label: 'Domicilio:', | 263 | label: 'Domicilio:', |
268 | valor: notaPedido.domicilioStamp | 264 | valor: notaPedido.domicilioStamp |
269 | }, | 265 | }, |
270 | { | 266 | { |
271 | label: 'Vendedor:', | 267 | label: 'Vendedor:', |
272 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + | 268 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + |
273 | ' - ' + notaPedido.vendedor.NOM | 269 | ' - ' + notaPedido.vendedor.NOM |
274 | }, | 270 | }, |
275 | { | 271 | { |
276 | label: 'Proveedor:', | 272 | label: 'Proveedor:', |
277 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + | 273 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + |
278 | ' - ' + notaPedido.proveedor.NOM | 274 | ' - ' + notaPedido.proveedor.NOM |
279 | }, | 275 | }, |
280 | { | 276 | { |
281 | label: 'Precios y condiciones:', | 277 | label: 'Precios y condiciones:', |
282 | valor: valorPrecioCondicion() + ' ' + | 278 | valor: valorPrecioCondicion() + ' ' + |
283 | notaPedidoBusinessService | 279 | notaPedidoBusinessService |
284 | .plazoToString(notaPedido.notaPedidoPlazo) | 280 | .plazoToString(notaPedido.notaPedidoPlazo) |
285 | }, | 281 | }, |
286 | { | 282 | { |
287 | label: 'Flete:', | 283 | label: 'Flete:', |
288 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 284 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
289 | notaPedido.flete === 1 ? 'Si' : 'No') | 285 | notaPedido.flete === 1 ? 'Si' : 'No') |
290 | } | 286 | } |
291 | ]; | 287 | ]; |
292 | 288 | ||
293 | function valorPrecioCondicion() { | 289 | function valorPrecioCondicion() { |
294 | if(notaPedido.idPrecioCondicion > 0) { | 290 | if(notaPedido.idPrecioCondicion > 0) { |
295 | return notaPedido.precioCondicion.nombre; | 291 | return notaPedido.precioCondicion.nombre; |
296 | } else { | 292 | } else { |
297 | return 'Ingreso Manual'; | 293 | return 'Ingreso Manual'; |
298 | } | 294 | } |
299 | } | 295 | } |
300 | 296 | ||
301 | if(notaPedido.flete === 1) { | 297 | if(notaPedido.flete === 1) { |
302 | var cabeceraBomba = { | 298 | var cabeceraBomba = { |
303 | label: 'Bomba:', | 299 | label: 'Bomba:', |
304 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 300 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
305 | }; | 301 | }; |
306 | if(notaPedido.kilometros) { | 302 | if(notaPedido.kilometros) { |
307 | var cabeceraKilometros = { | 303 | var cabeceraKilometros = { |
308 | label: 'Kilometros:', | 304 | label: 'Kilometros:', |
309 | valor: notaPedido.kilometros | 305 | valor: notaPedido.kilometros |
310 | }; | 306 | }; |
311 | cabeceras.push(cabeceraKilometros); | 307 | cabeceras.push(cabeceraKilometros); |
312 | } | 308 | } |
313 | cabeceras.push(cabeceraBomba); | 309 | cabeceras.push(cabeceraBomba); |
314 | } | 310 | } |
315 | 311 | ||
316 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 312 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
317 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, | 313 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, |
318 | notaPedido.cotizacion.VENDEDOR); | 314 | notaPedido.cotizacion.VENDEDOR); |
319 | 315 | ||
320 | if(notaPedido.idPrecioCondicion > 0) { | 316 | if(notaPedido.idPrecioCondicion > 0) { |
321 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 317 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
322 | } else { | 318 | } else { |
323 | $scope.idLista = -1; | 319 | $scope.idLista = -1; |
324 | } | 320 | } |
325 | 321 | ||
326 | $scope.puntoVenta = $filter('rellenarDigitos')( | 322 | $scope.puntoVenta = $filter('rellenarDigitos')( |
327 | notaPedido.sucursal, 4 | 323 | notaPedido.sucursal, 4 |
328 | ); | 324 | ); |
329 | 325 | ||
330 | $scope.comprobante = $filter('rellenarDigitos')( | 326 | $scope.comprobante = $filter('rellenarDigitos')( |
331 | notaPedido.numeroNotaPedido, 8 | 327 | notaPedido.numeroNotaPedido, 8 |
332 | ); | 328 | ); |
333 | 329 | ||
334 | $scope.notaPedido = notaPedido; | 330 | $scope.notaPedido = notaPedido; |
335 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; | 331 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; |
336 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; | 332 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; |
337 | $scope.notaPedido.puntosDescarga = | 333 | $scope.notaPedido.puntosDescarga = |
338 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); | 334 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); |
339 | addArrayCabecera(cabeceras); | 335 | addArrayCabecera(cabeceras); |
340 | 336 | ||
341 | }, function() { | 337 | }, function() { |
342 | // funcion ejecutada cuando se cancela el modal | 338 | // funcion ejecutada cuando se cancela el modal |
343 | } | 339 | } |
344 | ); | 340 | ); |
345 | }; | 341 | }; |
346 | 342 | ||
347 | $scope.seleccionarProductos = function() { | 343 | $scope.seleccionarProductos = function() { |
348 | if ($scope.idLista === undefined) { | 344 | if ($scope.idLista === undefined) { |
349 | focaModalService.alert( | 345 | focaModalService.alert( |
350 | 'Primero seleccione una lista de precio y condicion'); | 346 | 'Primero seleccione una lista de precio y condicion'); |
351 | return; | 347 | return; |
352 | } | 348 | } |
353 | var modalInstance = $uibModal.open( | 349 | var modalInstance = $uibModal.open( |
354 | { | 350 | { |
355 | ariaLabelledBy: 'Busqueda de Productos', | 351 | ariaLabelledBy: 'Busqueda de Productos', |
356 | templateUrl: 'modal-busqueda-productos.html', | 352 | templateUrl: 'modal-busqueda-productos.html', |
357 | controller: 'modalBusquedaProductosCtrl', | 353 | controller: 'modalBusquedaProductosCtrl', |
358 | resolve: { | 354 | resolve: { |
359 | parametroProducto: { | 355 | parametroProducto: { |
360 | idLista: $scope.idLista, | 356 | idLista: $scope.idLista, |
361 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 357 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
362 | simbolo: $scope.notaPedido.moneda.SIMBOLO | 358 | simbolo: $scope.notaPedido.moneda.SIMBOLO |
363 | } | 359 | } |
364 | }, | 360 | }, |
365 | size: 'lg' | 361 | size: 'lg' |
366 | } | 362 | } |
367 | ); | 363 | ); |
368 | modalInstance.result.then( | 364 | modalInstance.result.then( |
369 | function(producto) { | 365 | function(producto) { |
370 | var newArt = | 366 | var newArt = |
371 | { | 367 | { |
372 | id: 0, | 368 | id: 0, |
373 | codigo: producto.codigo, | 369 | codigo: producto.codigo, |
374 | sector: producto.sector, | 370 | sector: producto.sector, |
375 | sectorCodigo: producto.sector + '-' + producto.codigo, | 371 | sectorCodigo: producto.sector + '-' + producto.codigo, |
376 | descripcion: producto.descripcion, | 372 | descripcion: producto.descripcion, |
377 | item: $scope.articulosTabla.length + 1, | 373 | item: $scope.articulosTabla.length + 1, |
378 | nombre: producto.descripcion, | 374 | nombre: producto.descripcion, |
379 | precio: parseFloat(producto.precio.toFixed(4)), | 375 | precio: parseFloat(producto.precio.toFixed(4)), |
380 | costoUnitario: producto.costo, | 376 | costoUnitario: producto.costo, |
381 | editCantidad: false, | 377 | editCantidad: false, |
382 | editPrecio: false, | 378 | editPrecio: false, |
383 | rubro: producto.CodRub, | 379 | rubro: producto.CodRub, |
384 | exentoUnitario: producto.precio, | 380 | exentoUnitario: producto.precio, |
385 | ivaUnitario: producto.IMPIVA, | 381 | ivaUnitario: producto.IMPIVA, |
386 | impuestoInternoUnitario: producto.ImpInt, | 382 | impuestoInternoUnitario: producto.ImpInt, |
387 | impuestoInterno1Unitario: producto.ImpInt2, | 383 | impuestoInterno1Unitario: producto.ImpInt2, |
388 | impuestoInterno2Unitario: producto.ImpInt3, | 384 | impuestoInterno2Unitario: producto.ImpInt3, |
389 | precioLista: producto.precio, | 385 | precioLista: producto.precio, |
390 | combustible: 1, | 386 | combustible: 1, |
391 | facturado: 0, | 387 | facturado: 0, |
392 | idArticulo: producto.id | 388 | idArticulo: producto.id |
393 | }; | 389 | }; |
394 | $scope.articuloACargar = newArt; | 390 | $scope.articuloACargar = newArt; |
395 | $scope.cargando = false; | 391 | $scope.cargando = false; |
396 | }, function() { | 392 | }, function() { |
397 | // funcion ejecutada cuando se cancela el modal | 393 | // funcion ejecutada cuando se cancela el modal |
398 | } | 394 | } |
399 | ); | 395 | ); |
400 | }; | 396 | }; |
401 | 397 | ||
402 | $scope.seleccionarPuntosDeDescarga = function() { | 398 | $scope.seleccionarPuntosDeDescarga = function() { |
403 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 399 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
404 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 400 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
405 | return; | 401 | return; |
406 | }else { | 402 | }else { |
407 | var modalInstance = $uibModal.open( | 403 | var modalInstance = $uibModal.open( |
408 | { | 404 | { |
409 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 405 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
410 | templateUrl: 'modal-punto-descarga.html', | 406 | templateUrl: 'modal-punto-descarga.html', |
411 | controller: 'focaModalPuntoDescargaController', | 407 | controller: 'focaModalPuntoDescargaController', |
412 | size: 'lg', | 408 | size: 'lg', |
413 | resolve: { | 409 | resolve: { |
414 | filters: { | 410 | filters: { |
415 | idDomicilio: $scope.notaPedido.domicilio.id, | 411 | idDomicilio: $scope.notaPedido.domicilio.id, |
416 | idCliente: $scope.notaPedido.cliente.COD, | 412 | idCliente: $scope.notaPedido.cliente.COD, |
417 | articulos: $scope.articulosTabla, | 413 | articulos: $scope.articulosTabla, |
418 | puntosDescarga: $scope.notaPedido.puntosDescarga | 414 | puntosDescarga: $scope.notaPedido.puntosDescarga |
419 | } | 415 | } |
420 | } | 416 | } |
421 | } | 417 | } |
422 | ); | 418 | ); |
423 | modalInstance.result.then( | 419 | modalInstance.result.then( |
424 | function(puntosDescarga) { | 420 | function(puntosDescarga) { |
425 | $scope.notaPedido.puntosDescarga = puntosDescarga; | 421 | $scope.notaPedido.puntosDescarga = puntosDescarga; |
426 | 422 | ||
427 | //AGREGO PUNTOS DE DESCARGA A CABECERA | 423 | //AGREGO PUNTOS DE DESCARGA A CABECERA |
428 | var puntosStamp = ''; | 424 | var puntosStamp = ''; |
429 | puntosDescarga.forEach(function(punto, idx, arr) { | 425 | puntosDescarga.forEach(function(punto, idx, arr) { |
430 | puntosStamp += punto.descripcion; | 426 | puntosStamp += punto.descripcion; |
431 | if((idx + 1) !== arr.length) puntosStamp += ', '; | 427 | if((idx + 1) !== arr.length) puntosStamp += ', '; |
432 | }); | 428 | }); |
433 | 429 | ||
434 | $scope.$broadcast('addCabecera', { | 430 | $scope.$broadcast('addCabecera', { |
435 | label: 'Puntos de descarga:', | 431 | label: 'Puntos de descarga:', |
436 | valor: puntosStamp | 432 | valor: puntosStamp |
437 | }); | 433 | }); |
438 | }, function() { | 434 | }, function() { |
439 | $scope.abrirModalDomicilios($scope.cliente); | 435 | $scope.abrirModalDomicilios($scope.cliente); |
440 | } | 436 | } |
441 | ); | 437 | ); |
442 | } | 438 | } |
443 | }; | 439 | }; |
444 | 440 | ||
445 | $scope.seleccionarVendedor = function() { | 441 | $scope.seleccionarVendedor = function() { |
446 | if(validarNotaRemitada()) { | 442 | if(validarNotaRemitada()) { |
447 | var parametrosModal = { | 443 | var parametrosModal = { |
448 | titulo: 'Búsqueda vendedores', | 444 | titulo: 'Búsqueda vendedores', |
449 | query: '/vendedor', | 445 | query: '/vendedor', |
450 | columnas: [ | 446 | columnas: [ |
451 | { | 447 | { |
452 | propiedad: 'NUM', | 448 | propiedad: 'NUM', |
453 | nombre: 'Código', | 449 | nombre: 'Código', |
454 | filtro: { | 450 | filtro: { |
455 | nombre: 'rellenarDigitos', | 451 | nombre: 'rellenarDigitos', |
456 | parametro: 3 | 452 | parametro: 3 |
457 | } | 453 | } |
458 | }, | 454 | }, |
459 | { | 455 | { |
460 | propiedad: 'NOM', | 456 | propiedad: 'NOM', |
461 | nombre: 'Nombre' | 457 | nombre: 'Nombre' |
462 | } | 458 | } |
463 | ], | 459 | ], |
464 | size: 'md' | 460 | size: 'md' |
465 | }; | 461 | }; |
466 | focaModalService.modal(parametrosModal).then( | 462 | focaModalService.modal(parametrosModal).then( |
467 | function(vendedor) { | 463 | function(vendedor) { |
468 | $scope.$broadcast('addCabecera', { | 464 | $scope.$broadcast('addCabecera', { |
469 | label: 'Vendedor:', | 465 | label: 'Vendedor:', |
470 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 466 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
471 | vendedor.NOM | 467 | vendedor.NOM |
472 | }); | 468 | }); |
473 | $scope.notaPedido.vendedor = vendedor; | 469 | $scope.notaPedido.vendedor = vendedor; |
474 | }, function() { | 470 | }, function() { |
475 | 471 | ||
476 | } | 472 | } |
477 | ); | 473 | ); |
478 | } | 474 | } |
479 | }; | 475 | }; |
480 | 476 | ||
481 | $scope.seleccionarProveedor = function() { | 477 | $scope.seleccionarProveedor = function() { |
482 | if(validarNotaRemitada()) { | 478 | if(validarNotaRemitada()) { |
483 | var parametrosModal = { | 479 | var parametrosModal = { |
484 | titulo: 'Búsqueda de Proveedor', | 480 | titulo: 'Búsqueda de Proveedor', |
485 | query: '/proveedor', | 481 | query: '/proveedor', |
486 | columnas: [ | 482 | columnas: [ |
487 | { | 483 | { |
488 | nombre: 'Código', | 484 | nombre: 'Código', |
489 | propiedad: 'COD', | 485 | propiedad: 'COD', |
490 | filtro: { | 486 | filtro: { |
491 | nombre: 'rellenarDigitos', | 487 | nombre: 'rellenarDigitos', |
492 | parametro: 5 | 488 | parametro: 5 |
493 | } | 489 | } |
494 | }, | 490 | }, |
495 | { | 491 | { |
496 | nombre: 'Nombre', | 492 | nombre: 'Nombre', |
497 | propiedad: 'NOM' | 493 | propiedad: 'NOM' |
498 | }, | 494 | }, |
499 | { | 495 | { |
500 | nombre: 'CUIT', | 496 | nombre: 'CUIT', |
501 | propiedad: 'CUIT' | 497 | propiedad: 'CUIT' |
502 | } | 498 | } |
503 | ], | 499 | ], |
504 | tipo: 'POST', | 500 | tipo: 'POST', |
505 | json: {razonCuitCod: ''} | 501 | json: {razonCuitCod: ''} |
506 | }; | 502 | }; |
507 | focaModalService.modal(parametrosModal).then( | 503 | focaModalService.modal(parametrosModal).then( |
508 | function(proveedor) { | 504 | function(proveedor) { |
509 | $scope.notaPedido.proveedor = proveedor; | 505 | $scope.notaPedido.proveedor = proveedor; |
510 | $scope.$broadcast('addCabecera', { | 506 | $scope.$broadcast('addCabecera', { |
511 | label: 'Proveedor:', | 507 | label: 'Proveedor:', |
512 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 508 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
513 | proveedor.NOM | 509 | proveedor.NOM |
514 | }); | 510 | }); |
515 | }, function() { | 511 | }, function() { |
516 | 512 | ||
517 | } | 513 | } |
518 | ); | 514 | ); |
519 | } | 515 | } |
520 | }; | 516 | }; |
521 | 517 | ||
522 | $scope.seleccionarCliente = function() { | 518 | $scope.seleccionarCliente = function() { |
523 | if(!$scope.notaPedido.vendedor.NUM) { | 519 | if(!$scope.notaPedido.vendedor.NUM) { |
524 | focaModalService.alert('Primero seleccione un vendedor'); | 520 | focaModalService.alert('Primero seleccione un vendedor'); |
525 | return; | 521 | return; |
526 | } | 522 | } |
527 | if(validarNotaRemitada()) { | 523 | if(validarNotaRemitada()) { |
528 | var modalInstance = $uibModal.open( | 524 | var modalInstance = $uibModal.open( |
529 | { | 525 | { |
530 | ariaLabelledBy: 'Busqueda de Cliente', | 526 | ariaLabelledBy: 'Busqueda de Cliente', |
531 | templateUrl: 'foca-busqueda-cliente-modal.html', | 527 | templateUrl: 'foca-busqueda-cliente-modal.html', |
532 | controller: 'focaBusquedaClienteModalController', | 528 | controller: 'focaBusquedaClienteModalController', |
533 | resolve: { | 529 | resolve: { |
534 | vendedor: function() { return $scope.notaPedido.vendedor; } | 530 | vendedor: function() { return $scope.notaPedido.vendedor; } |
535 | }, | 531 | }, |
536 | size: 'lg' | 532 | size: 'lg' |
537 | } | 533 | } |
538 | ); | 534 | ); |
539 | modalInstance.result.then( | 535 | modalInstance.result.then( |
540 | function(cliente) { | 536 | function(cliente) { |
541 | $scope.abrirModalDomicilios(cliente); | 537 | $scope.abrirModalDomicilios(cliente); |
542 | $scope.cliente = cliente; | 538 | $scope.cliente = cliente; |
543 | }, function() {} | 539 | }, function() {} |
544 | ); | 540 | ); |
545 | } | 541 | } |
546 | }; | 542 | }; |
547 | 543 | ||
548 | $scope.abrirModalDomicilios = function(cliente) { | 544 | $scope.abrirModalDomicilios = function(cliente) { |
549 | var modalInstanceDomicilio = $uibModal.open( | 545 | var modalInstanceDomicilio = $uibModal.open( |
550 | { | 546 | { |
551 | ariaLabelledBy: 'Busqueda de Domicilios', | 547 | ariaLabelledBy: 'Busqueda de Domicilios', |
552 | templateUrl: 'modal-domicilio.html', | 548 | templateUrl: 'modal-domicilio.html', |
553 | controller: 'focaModalDomicilioController', | 549 | controller: 'focaModalDomicilioController', |
554 | resolve: { | 550 | resolve: { |
555 | idCliente: function() { return cliente.cod; }, | 551 | idCliente: function() { return cliente.cod; }, |
556 | esNuevo: function() { return cliente.esNuevo; } | 552 | esNuevo: function() { return cliente.esNuevo; } |
557 | }, | 553 | }, |
558 | size: 'lg', | 554 | size: 'lg', |
559 | } | 555 | } |
560 | ); | 556 | ); |
561 | modalInstanceDomicilio.result.then( | 557 | modalInstanceDomicilio.result.then( |
562 | function(domicilio) { | 558 | function(domicilio) { |
563 | $scope.notaPedido.domicilio = domicilio; | 559 | $scope.notaPedido.domicilio = domicilio; |
564 | $scope.notaPedido.cliente = { | 560 | $scope.notaPedido.cliente = { |
565 | COD: cliente.cod, | 561 | COD: cliente.cod, |
566 | CUIT: cliente.cuit, | 562 | CUIT: cliente.cuit, |
567 | NOM: cliente.nom | 563 | NOM: cliente.nom |
568 | }; | 564 | }; |
569 | var domicilioStamp = | 565 | var domicilioStamp = |
570 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 566 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
571 | domicilio.Localidad + ', ' + domicilio.Provincia; | 567 | domicilio.Localidad + ', ' + domicilio.Provincia; |
572 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 568 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
573 | 569 | ||
574 | $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; | 570 | $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; |
575 | 571 | ||
576 | $scope.$broadcast('addCabecera', { | 572 | $scope.$broadcast('addCabecera', { |
577 | label: 'Cliente:', | 573 | label: 'Cliente:', |
578 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom | 574 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom |
579 | }); | 575 | }); |
580 | $scope.$broadcast('addCabecera', { | 576 | $scope.$broadcast('addCabecera', { |
581 | label: 'Domicilio:', | 577 | label: 'Domicilio:', |
582 | valor: domicilioStamp | 578 | valor: domicilioStamp |
583 | }); | 579 | }); |
584 | if(domicilio.verPuntos) { | 580 | if(domicilio.verPuntos) { |
585 | delete $scope.notaPedido.domicilio.verPuntos; | 581 | delete $scope.notaPedido.domicilio.verPuntos; |
586 | $scope.seleccionarPuntosDeDescarga(); | 582 | $scope.seleccionarPuntosDeDescarga(); |
587 | }else { | 583 | }else { |
588 | crearNotaPedidoService | 584 | crearNotaPedidoService |
589 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 585 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
590 | .then(function(res) { | 586 | .then(function(res) { |
591 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); | 587 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); |
592 | }); | 588 | }); |
593 | } | 589 | } |
594 | }, function() { | 590 | }, function() { |
595 | $scope.seleccionarCliente(); | 591 | $scope.seleccionarCliente(); |
596 | return; | 592 | return; |
597 | } | 593 | } |
598 | ); | 594 | ); |
599 | }; | 595 | }; |
600 | 596 | ||
601 | $scope.getTotal = function() { | 597 | $scope.getTotal = function() { |
602 | var total = 0; | 598 | var total = 0; |
603 | var arrayTempArticulos = $scope.articulosTabla; | 599 | |
604 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 600 | if ($scope.articulosTabla) { |
605 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 601 | var arrayTempArticulos = $scope.articulosTabla; |
602 | for (var i = 0; i < arrayTempArticulos.length; i++) { | ||
603 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | ||
604 | } | ||
606 | } | 605 | } |
606 | |||
607 | return parseFloat(total.toFixed(2)); | 607 | return parseFloat(total.toFixed(2)); |
608 | }; | 608 | }; |
609 | 609 | ||
610 | $scope.getSubTotal = function() { | 610 | $scope.getSubTotal = function() { |
611 | if($scope.articuloACargar) { | 611 | if($scope.articuloACargar) { |
612 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 612 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
613 | } | 613 | } |
614 | }; | 614 | }; |
615 | 615 | ||
616 | $scope.seleccionarPreciosYCondiciones = function() { | 616 | $scope.seleccionarPreciosYCondiciones = function() { |
617 | if(validarNotaRemitada()) { | 617 | if(validarNotaRemitada()) { |
618 | var modalInstance = $uibModal.open( | 618 | var modalInstance = $uibModal.open( |
619 | { | 619 | { |
620 | ariaLabelledBy: 'Busqueda de Precio Condición', | 620 | ariaLabelledBy: 'Busqueda de Precio Condición', |
621 | templateUrl: 'modal-precio-condicion.html', | 621 | templateUrl: 'modal-precio-condicion.html', |
622 | controller: 'focaModalPrecioCondicionController', | 622 | controller: 'focaModalPrecioCondicionController', |
623 | size: 'lg' | 623 | size: 'lg' |
624 | } | 624 | } |
625 | ); | 625 | ); |
626 | modalInstance.result.then( | 626 | modalInstance.result.then( |
627 | function(precioCondicion) { | 627 | function(precioCondicion) { |
628 | var cabecera = ''; | 628 | var cabecera = ''; |
629 | var plazosConcat = ''; | 629 | var plazosConcat = ''; |
630 | if(!Array.isArray(precioCondicion)) { | 630 | if(!Array.isArray(precioCondicion)) { |
631 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 631 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
632 | $scope.plazosPagos = precioCondicion.plazoPago; | 632 | $scope.plazosPagos = precioCondicion.plazoPago; |
633 | $scope.idLista = precioCondicion.idListaPrecio; | 633 | $scope.idLista = precioCondicion.idListaPrecio; |
634 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 634 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
635 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 635 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
636 | } | 636 | } |
637 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 637 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
638 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 638 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
639 | } else { //Cuando se ingresan los plazos manualmente | 639 | } else { //Cuando se ingresan los plazos manualmente |
640 | $scope.notaPedido.idPrecioCondicion = 0; | 640 | $scope.notaPedido.idPrecioCondicion = 0; |
641 | //-1, el modal productos busca todos los productos | 641 | //-1, el modal productos busca todos los productos |
642 | $scope.idLista = -1; | 642 | $scope.idLista = -1; |
643 | $scope.plazosPagos = precioCondicion; | 643 | $scope.plazosPagos = precioCondicion; |
644 | for(var j = 0; j < precioCondicion.length; j++) { | 644 | for(var j = 0; j < precioCondicion.length; j++) { |
645 | plazosConcat += precioCondicion[j].dias + ' '; | 645 | plazosConcat += precioCondicion[j].dias + ' '; |
646 | } | 646 | } |
647 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 647 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
648 | } | 648 | } |
649 | $scope.articulosTabla = []; | 649 | $scope.articulosTabla = []; |
650 | $scope.$broadcast('addCabecera', { | 650 | $scope.$broadcast('addCabecera', { |
651 | label: 'Precios y condiciones:', | 651 | label: 'Precios y condiciones:', |
652 | valor: cabecera | 652 | valor: cabecera |
653 | }); | 653 | }); |
654 | }, function() { | 654 | }, function() { |
655 | 655 | ||
656 | } | 656 | } |
657 | ); | 657 | ); |
658 | } | 658 | } |
659 | }; | 659 | }; |
660 | 660 | ||
661 | $scope.seleccionarFlete = function() { | 661 | $scope.seleccionarFlete = function() { |
662 | if(validarNotaRemitada()) { | 662 | if(validarNotaRemitada()) { |
663 | var modalInstance = $uibModal.open( | 663 | var modalInstance = $uibModal.open( |
664 | { | 664 | { |
665 | ariaLabelledBy: 'Busqueda de Flete', | 665 | ariaLabelledBy: 'Busqueda de Flete', |
666 | templateUrl: 'modal-flete.html', | 666 | templateUrl: 'modal-flete.html', |
667 | controller: 'focaModalFleteController', | 667 | controller: 'focaModalFleteController', |
668 | size: 'lg', | 668 | size: 'lg', |
669 | resolve: { | 669 | resolve: { |
670 | parametrosFlete: | 670 | parametrosFlete: |
671 | function() { | 671 | function() { |
672 | return { | 672 | return { |
673 | flete: $scope.notaPedido.fob ? 'FOB' : | 673 | flete: $scope.notaPedido.fob ? 'FOB' : |
674 | ( $scope.notaPedido.flete ? '1' : | 674 | ( $scope.notaPedido.flete ? '1' : |
675 | ($scope.notaPedido.flete === undefined ? | 675 | ($scope.notaPedido.flete === undefined ? |
676 | null : '0')), | 676 | null : '0')), |
677 | bomba: $scope.notaPedido.bomba ? '1' : | 677 | bomba: $scope.notaPedido.bomba ? '1' : |
678 | ($scope.notaPedido.bomba === undefined ? | 678 | ($scope.notaPedido.bomba === undefined ? |
679 | null : '0'), | 679 | null : '0'), |
680 | kilometros: $scope.notaPedido.kilometros | 680 | kilometros: $scope.notaPedido.kilometros |
681 | }; | 681 | }; |
682 | } | 682 | } |
683 | } | 683 | } |
684 | } | 684 | } |
685 | ); | 685 | ); |
686 | modalInstance.result.then( | 686 | modalInstance.result.then( |
687 | function(datos) { | 687 | function(datos) { |
688 | $scope.notaPedido.flete = datos.flete; | 688 | $scope.notaPedido.flete = datos.flete; |
689 | $scope.notaPedido.fob = datos.FOB; | 689 | $scope.notaPedido.fob = datos.FOB; |
690 | $scope.notaPedido.bomba = datos.bomba; | 690 | $scope.notaPedido.bomba = datos.bomba; |
691 | $scope.notaPedido.kilometros = datos.kilometros; | 691 | $scope.notaPedido.kilometros = datos.kilometros; |
692 | $scope.$broadcast('addCabecera', { | 692 | $scope.$broadcast('addCabecera', { |
693 | label: 'Flete:', | 693 | label: 'Flete:', |
694 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 694 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
695 | }); | 695 | }); |
696 | if(datos.flete) { | 696 | if(datos.flete) { |
697 | $scope.$broadcast('addCabecera', { | 697 | $scope.$broadcast('addCabecera', { |
698 | label: 'Bomba:', | 698 | label: 'Bomba:', |
699 | valor: datos.bomba ? 'Si' : 'No' | 699 | valor: datos.bomba ? 'Si' : 'No' |
700 | }); | 700 | }); |
701 | $scope.$broadcast('addCabecera', { | 701 | $scope.$broadcast('addCabecera', { |
702 | label: 'Kilometros:', | 702 | label: 'Kilometros:', |
703 | valor: datos.kilometros | 703 | valor: datos.kilometros |
704 | }); | 704 | }); |
705 | } else { | 705 | } else { |
706 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 706 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
707 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 707 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
708 | $scope.notaPedido.bomba = false; | 708 | $scope.notaPedido.bomba = false; |
709 | $scope.notaPedido.kilometros = null; | 709 | $scope.notaPedido.kilometros = null; |
710 | } | 710 | } |
711 | }, function() { | 711 | }, function() { |
712 | 712 | ||
713 | } | 713 | } |
714 | ); | 714 | ); |
715 | } | 715 | } |
716 | }; | 716 | }; |
717 | 717 | ||
718 | $scope.seleccionarMoneda = function() { | 718 | $scope.seleccionarMoneda = function() { |
719 | if(validarNotaRemitada()) { | 719 | if(validarNotaRemitada()) { |
720 | var parametrosModal = { | 720 | var parametrosModal = { |
721 | titulo: 'Búsqueda de monedas', | 721 | titulo: 'Búsqueda de monedas', |
722 | query: '/moneda', | 722 | query: '/moneda', |
723 | columnas: [ | 723 | columnas: [ |
724 | { | 724 | { |
725 | propiedad: 'DETALLE', | 725 | propiedad: 'DETALLE', |
726 | nombre: 'Nombre' | 726 | nombre: 'Nombre' |
727 | }, | 727 | }, |
728 | { | 728 | { |
729 | propiedad: 'SIMBOLO', | 729 | propiedad: 'SIMBOLO', |
730 | nombre: 'Símbolo' | 730 | nombre: 'Símbolo' |
731 | } | 731 | } |
732 | ], | 732 | ], |
733 | size: 'md' | 733 | size: 'md' |
734 | }; | 734 | }; |
735 | focaModalService.modal(parametrosModal).then( | 735 | focaModalService.modal(parametrosModal).then( |
736 | function(moneda) { | 736 | function(moneda) { |
737 | $scope.abrirModalCotizacion(moneda); | 737 | $scope.abrirModalCotizacion(moneda); |
738 | }, function() { | 738 | }, function() { |
739 | 739 | ||
740 | } | 740 | } |
741 | ); | 741 | ); |
742 | } | 742 | } |
743 | }; | 743 | }; |
744 | 744 | ||
745 | $scope.seleccionarObservaciones = function() { | 745 | $scope.seleccionarObservaciones = function() { |
746 | focaModalService | 746 | focaModalService |
747 | .prompt('Ingrese observaciones', $scope.notaPedido.observaciones, true) | 747 | .prompt('Ingrese observaciones', $scope.notaPedido.observaciones, true) |
748 | .then(function(observaciones) { | 748 | .then(function(observaciones) { |
749 | $scope.notaPedido.observaciones = observaciones; | 749 | $scope.notaPedido.observaciones = observaciones; |
750 | }); | 750 | }); |
751 | }; | 751 | }; |
752 | 752 | ||
753 | $scope.abrirModalCotizacion = function(moneda) { | 753 | $scope.abrirModalCotizacion = function(moneda) { |
754 | var modalInstance = $uibModal.open( | 754 | var modalInstance = $uibModal.open( |
755 | { | 755 | { |
756 | ariaLabelledBy: 'Busqueda de Cotización', | 756 | ariaLabelledBy: 'Busqueda de Cotización', |
757 | templateUrl: 'modal-cotizacion.html', | 757 | templateUrl: 'modal-cotizacion.html', |
758 | controller: 'focaModalCotizacionController', | 758 | controller: 'focaModalCotizacionController', |
759 | size: 'lg', | 759 | size: 'lg', |
760 | resolve: {idMoneda: function() {return moneda.ID;}} | 760 | resolve: { |
761 | idMoneda: function() { | ||
762 | return moneda.ID; | ||
763 | } | ||
764 | } | ||
761 | } | 765 | } |
762 | ); | 766 | ); |
763 | modalInstance.result.then( | 767 | modalInstance.result.then( |
764 | function(cotizacion) { | 768 | function(cotizacion) { |
765 | var articulosTablaTemp = $scope.articulosTabla; | 769 | var articulosTablaTemp = $scope.articulosTabla; |
770 | |||
766 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 771 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
767 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 772 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
768 | $scope.notaPedido.cotizacion.VENDEDOR; | 773 | $scope.notaPedido.cotizacion.VENDEDOR; |
769 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 774 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
770 | cotizacion.VENDEDOR; | 775 | cotizacion.VENDEDOR; |
771 | } | 776 | } |
777 | |||
772 | $scope.articulosTabla = articulosTablaTemp; | 778 | $scope.articulosTabla = articulosTablaTemp; |
773 | $scope.notaPedido.moneda = moneda; | 779 | $scope.notaPedido.moneda = moneda; |
780 | $scope.monedaDefecto = moneda; | ||
781 | $scope.cotizacionDefecto = cotizacion; | ||
774 | $scope.notaPedido.cotizacion = cotizacion; | 782 | $scope.notaPedido.cotizacion = cotizacion; |
783 | |||
775 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { | 784 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
776 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 785 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
777 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 786 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
778 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 787 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
779 | }else { | 788 | } else { |
780 | $scope.$broadcast('addCabecera', { | 789 | $scope.$broadcast('addCabecera', { |
781 | label: 'Moneda:', | 790 | label: 'Moneda:', |
782 | valor: moneda.DETALLE | 791 | valor: moneda.DETALLE |
783 | }); | 792 | }); |
784 | $scope.$broadcast('addCabecera', { | 793 | $scope.$broadcast('addCabecera', { |
785 | label: 'Fecha cotizacion:', | 794 | label: 'Fecha cotizacion:', |
786 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 795 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
787 | }); | 796 | }); |
788 | $scope.$broadcast('addCabecera', { | 797 | $scope.$broadcast('addCabecera', { |
789 | label: 'Cotizacion:', | 798 | label: 'Cotizacion:', |
790 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 799 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
791 | }); | 800 | }); |
792 | } | 801 | } |
793 | }, function() { | 802 | }, function() { |
794 | 803 | ||
795 | } | 804 | } |
796 | ); | 805 | ); |
797 | }; | 806 | }; |
798 | 807 | ||
799 | $scope.agregarATabla = function(key) { | 808 | $scope.agregarATabla = function(key) { |
800 | if(key === 13) { | 809 | if(key === 13) { |
801 | if($scope.articuloACargar.cantidad === undefined || | 810 | if($scope.articuloACargar.cantidad === undefined || |
802 | $scope.articuloACargar.cantidad === 0 || | 811 | $scope.articuloACargar.cantidad === 0 || |
803 | $scope.articuloACargar.cantidad === null ) { | 812 | $scope.articuloACargar.cantidad === null ) { |
804 | focaModalService.alert('El valor debe ser al menos 1'); | 813 | focaModalService.alert('El valor debe ser al menos 1'); |
805 | return; | 814 | return; |
806 | } | 815 | } |
807 | delete $scope.articuloACargar.sectorCodigo; | 816 | delete $scope.articuloACargar.sectorCodigo; |
808 | $scope.articulosTabla.push($scope.articuloACargar); | 817 | $scope.articulosTabla.push($scope.articuloACargar); |
809 | $scope.cargando = true; | 818 | $scope.cargando = true; |
810 | } | 819 | } |
811 | }; | 820 | }; |
812 | 821 | ||
813 | $scope.quitarArticulo = function(key) { | 822 | $scope.quitarArticulo = function(key) { |
814 | $scope.articulosTabla.splice(key, 1); | 823 | $scope.articulosTabla.splice(key, 1); |
815 | }; | 824 | }; |
816 | 825 | ||
817 | $scope.editarArticulo = function(key, articulo) { | 826 | $scope.editarArticulo = function(key, articulo) { |
818 | if(key === 13) { | 827 | if(key === 13) { |
819 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 828 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
820 | articulo.cantidad === undefined) { | 829 | articulo.cantidad === undefined) { |
821 | focaModalService.alert('El valor debe ser al menos 1'); | 830 | focaModalService.alert('El valor debe ser al menos 1'); |
822 | return; | 831 | return; |
823 | } | 832 | } |
824 | articulo.editCantidad = false; | 833 | articulo.editCantidad = false; |
825 | articulo.editPrecio = false; | 834 | articulo.editPrecio = false; |
826 | } | 835 | } |
827 | }; | 836 | }; |
828 | 837 | ||
829 | $scope.cambioEdit = function(articulo, propiedad) { | 838 | $scope.cambioEdit = function(articulo, propiedad) { |
830 | if(propiedad === 'cantidad') { | 839 | if(propiedad === 'cantidad') { |
831 | articulo.editCantidad = true; | 840 | articulo.editCantidad = true; |
832 | } else if(propiedad === 'precio') { | 841 | } else if(propiedad === 'precio') { |
833 | articulo.editPrecio = true; | 842 | articulo.editPrecio = true; |
834 | } | 843 | } |
835 | }; | 844 | }; |
836 | 845 | ||
837 | $scope.resetFilter = function() { | 846 | $scope.resetFilter = function() { |
838 | $scope.articuloACargar = {}; | 847 | $scope.articuloACargar = {}; |
839 | $scope.cargando = true; | 848 | $scope.cargando = true; |
840 | }; | 849 | }; |
841 | //Recibe aviso si el teclado está en uso | 850 | //Recibe aviso si el teclado está en uso |
842 | $rootScope.$on('usarTeclado', function(event, data) { | 851 | $rootScope.$on('usarTeclado', function(event, data) { |
843 | if(data) { | 852 | if(data) { |
844 | $scope.mostrarTeclado = true; | 853 | $scope.mostrarTeclado = true; |
845 | return; | 854 | return; |
846 | } | 855 | } |
847 | $scope.mostrarTeclado = false; | 856 | $scope.mostrarTeclado = false; |
848 | }); | 857 | }); |
849 | 858 | ||
850 | $scope.selectFocus = function($event) { | 859 | $scope.selectFocus = function($event) { |
851 | // Si el teclado esta en uso no selecciona el valor | 860 | // Si el teclado esta en uso no selecciona el valor |
852 | if($scope.mostrarTeclado) { | 861 | if($scope.mostrarTeclado) { |
853 | return; | 862 | return; |
854 | } | 863 | } |
855 | $event.target.select(); | 864 | $event.target.select(); |
856 | }; | 865 | }; |
857 | 866 | ||
858 | $scope.salir = function() { | 867 | $scope.salir = function() { |
859 | $location.path('/'); | 868 | $location.path('/'); |
860 | }; | 869 | }; |
861 | 870 | ||
862 | $scope.parsearATexto = function(articulo) { | 871 | $scope.parsearATexto = function(articulo) { |
863 | articulo.cantidad = parseFloat(articulo.cantidad); | 872 | articulo.cantidad = parseFloat(articulo.cantidad); |
864 | articulo.precio = parseFloat(articulo.precio); | 873 | articulo.precio = parseFloat(articulo.precio); |
865 | }; | 874 | }; |
866 | 875 | ||
867 | function addArrayCabecera(array) { | 876 | function addArrayCabecera(array) { |
868 | for(var i = 0; i < array.length; i++) { | 877 | for(var i = 0; i < array.length; i++) { |
869 | $scope.$broadcast('addCabecera', { | 878 | $scope.$broadcast('addCabecera', { |
870 | label: array[i].label, | 879 | label: array[i].label, |
871 | valor: array[i].valor | 880 | valor: array[i].valor |
872 | }); | 881 | }); |
873 | } | 882 | } |
874 | } | 883 | } |
875 | 884 | ||
876 | function validarNotaRemitada() { | 885 | function validarNotaRemitada() { |
877 | if(!$scope.notaPedido.idRemito) { | 886 | if(!$scope.notaPedido.idRemito) { |
878 | return true; | 887 | return true; |
879 | }else{ | 888 | }else{ |
880 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 889 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
881 | return false; | 890 | return false; |
882 | } | 891 | } |
883 | } | 892 | } |
884 | 893 | ||
885 | function formatearPuntosDescarga(puntosDescarga) { | 894 | function formatearPuntosDescarga(puntosDescarga) { |
886 | var result = []; | 895 | var result = []; |
887 | 896 | ||
888 | puntosDescarga.forEach(function(el) { | 897 | puntosDescarga.forEach(function(el) { |
889 | var puntoDescarga = result.filter(function(resultPunto) { | 898 | var puntoDescarga = result.filter(function(resultPunto) { |
890 | return resultPunto.id === el.idPuntoDescarga; | 899 | return resultPunto.id === el.idPuntoDescarga; |
891 | }); | 900 | }); |
892 | 901 | ||
893 | if(puntoDescarga.length) { | 902 | if(puntoDescarga.length) { |
894 | puntoDescarga[0].articulosAgregados.push({ | 903 | puntoDescarga[0].articulosAgregados.push({ |
895 | cantidad: el.cantidad, | 904 | cantidad: el.cantidad, |
896 | descripcion: el.producto.descripcion, | 905 | descripcion: el.producto.descripcion, |
897 | id: el.producto.id | 906 | id: el.producto.id |
898 | }); | 907 | }); |
899 | }else { | 908 | }else { |
900 | result.push({ | 909 | result.push({ |
901 | id: el.puntoDescarga.id, | 910 | id: el.puntoDescarga.id, |
902 | id_cliente: el.puntoDescarga.id_cliente, | 911 | id_cliente: el.puntoDescarga.id_cliente, |
903 | id_da_config_0: el.puntoDescarga.id_da_config_0, | 912 | id_da_config_0: el.puntoDescarga.id_da_config_0, |
904 | latitud: el.puntoDescarga.latitud, | 913 | latitud: el.puntoDescarga.latitud, |
905 | longitud: el.puntoDescarga.longitud, | 914 | longitud: el.puntoDescarga.longitud, |
906 | descripcion: el.puntoDescarga.descripcion, | 915 | descripcion: el.puntoDescarga.descripcion, |
907 | articulosAgregados: [ | 916 | articulosAgregados: [ |
908 | { | 917 | { |
909 | cantidad: el.cantidad, | 918 | cantidad: el.cantidad, |
910 | descripcion: el.producto.descripcion, | 919 | descripcion: el.producto.descripcion, |
911 | id: el.producto.id | 920 | id: el.producto.id |
912 | } | 921 | } |
913 | ] | 922 | ] |
914 | }); | 923 | }); |
915 | } | 924 | } |
916 | }); | 925 | }); |
917 | return result; | 926 | return result; |
918 | } | 927 | } |
919 | 928 | ||
920 | function salir() { | 929 | function salir() { |
921 | var confirmacion = false; | 930 | var confirmacion = false; |
922 | 931 | ||
923 | angular.forEach($scope.inicial, function(valor, key) { | 932 | angular.forEach($scope.inicial, function(valor, key) { |
924 | if (!angular.equals($scope[key], $scope.inicial[key])) { | 933 | if (!angular.equals($scope[key], $scope.inicial[key])) { |
925 | confirmacion = true; | 934 | confirmacion = true; |
926 | } | 935 | } |
927 | }); | 936 | }); |
928 | 937 | ||
929 | if (confirmacion) { | 938 | if (confirmacion) { |
930 | focaModalService.confirm( | 939 | focaModalService.confirm( |
931 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 940 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |