Commit e5fcb246e0f2d1faa56632ab07b787e251c6c77c

Authored by Marcelo Puebla
1 parent 3db8d570e2
Exists in develop

Fix

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