Commit 1cbfbb395d54dc393f5838895327e4ad104a6ffd

Authored by Eric
1 parent 4c42f95cad
Exists in master

nose quien se la mando asi

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