Commit a13468f7e3238601e1508ab9378b1b76cf0adcdb

Authored by Jose Pinto
1 parent ce0ef7f7b5
Exists in master and in 1 other branch develop

fix modal puntos descarga

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