Commit 78ff0e46100f4f2843c7eca6dd95e5f2f83d1822

Authored by Nicolás Guarnieri
1 parent 99532cb1a9
Exists in master

nuevos campos para guardado de detalles correctamente

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