Commit 9d07c5e47caae34d3e9cc37ec86095c0769a49bc

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

crear nota sin vendedor

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