Commit 033b78dab57dcb044a59cfe04f2916bd0cd6a1ad

Authored by Eric
1 parent 6ee3d8210a
Exists in master

fix guardar

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