Commit 63cd9dcc69410d08a678cb23210828714afd10b6

Authored by Eric
1 parent 033b78dab5
Exists in master

boton checked

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