Commit 74fd97c1c69d010275c80d19b1dcb414b167c420

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

Merge branch 'master' into 'master'

Master

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