Commit a785aa919fe2e4275b9badab1797b2e31bd7fcae

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master

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