Commit 8205060d717fa9f841d7ce676ee71e1ec8bd44b3

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

rellenar dígitos en mobile

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