Commit 0b523797232b6a0739108a4c6fe2a77fda1ad799

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'master' into 'develop'

Master

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