Commit bbe6f8622136ff109b22430680af14c972d1ef93

Authored by Benjamin Rodriguez
1 parent a3f97a9777
Exists in master and in 1 other branch develop

crear nota sin vendedor

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