Commit 1e29528203d22ed3f32fc2e1dcde1a5a02fe1570

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master

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