Commit 042bc9319347741a3927b63eadd1da8198a64219

Authored by Luigi
1 parent 556b440b88
Exists in master and in 1 other branch develop

Eliminacion de espacio

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