Commit 62999119d6df30774f6a383c37dc9863f1be9b63

Authored by Eric Fernandez
1 parent 6909b1f196
Exists in master

quito modal moneda

Showing 1 changed file with 16 additions and 9 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: vendedor.CodVen + ' - ' + 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: vendedor.CodVen + ' - ' + vendedor.NomVen 456 valor: vendedor.CodVen + ' - ' + vendedor.NomVen
457 }); 457 });
458 $scope.notaPedido.vendedor = vendedor; 458 $scope.notaPedido.vendedor = vendedor;
459 }, function() { 459 }, function() {
460 460
461 } 461 }
462 ); 462 );
463 } 463 }
464 }; 464 };
465 465
466 $scope.seleccionarProveedor = function() { 466 $scope.seleccionarProveedor = function() {
467 if(validarNotaRemitada()) { 467 if(validarNotaRemitada()) {
468 var modalInstance = $uibModal.open( 468 var modalInstance = $uibModal.open(
469 { 469 {
470 ariaLabelledBy: 'Busqueda de Proveedor', 470 ariaLabelledBy: 'Busqueda de Proveedor',
471 templateUrl: 'modal-proveedor.html', 471 templateUrl: 'modal-proveedor.html',
472 controller: 'focaModalProveedorCtrl', 472 controller: 'focaModalProveedorCtrl',
473 size: 'lg', 473 size: 'lg',
474 resolve: { 474 resolve: {
475 transportista: function() { 475 transportista: function() {
476 return false; 476 return false;
477 } 477 }
478 } 478 }
479 } 479 }
480 ); 480 );
481 modalInstance.result.then( 481 modalInstance.result.then(
482 function(proveedor) { 482 function(proveedor) {
483 $scope.notaPedido.proveedor = proveedor; 483 $scope.notaPedido.proveedor = proveedor;
484 $scope.$broadcast('addCabecera', { 484 $scope.$broadcast('addCabecera', {
485 label: 'Proveedor:', 485 label: 'Proveedor:',
486 valor: proveedor.NOM 486 valor: proveedor.NOM
487 }); 487 });
488 }, function() { 488 }, function() {
489 489
490 } 490 }
491 ); 491 );
492 } 492 }
493 }; 493 };
494 494
495 $scope.seleccionarCliente = function() { 495 $scope.seleccionarCliente = function() {
496 if(!$scope.notaPedido.vendedor.CodVen) { 496 if(!$scope.notaPedido.vendedor.CodVen) {
497 focaModalService.alert('Primero seleccione un vendedor'); 497 focaModalService.alert('Primero seleccione un vendedor');
498 return; 498 return;
499 } 499 }
500 if(validarNotaRemitada()) { 500 if(validarNotaRemitada()) {
501 var modalInstance = $uibModal.open( 501 var modalInstance = $uibModal.open(
502 { 502 {
503 ariaLabelledBy: 'Busqueda de Cliente', 503 ariaLabelledBy: 'Busqueda de Cliente',
504 templateUrl: 'foca-busqueda-cliente-modal.html', 504 templateUrl: 'foca-busqueda-cliente-modal.html',
505 controller: 'focaBusquedaClienteModalController', 505 controller: 'focaBusquedaClienteModalController',
506 resolve: { 506 resolve: {
507 vendedor: function() { return $scope.notaPedido.vendedor; } 507 vendedor: function() { return $scope.notaPedido.vendedor; }
508 }, 508 },
509 size: 'lg' 509 size: 'lg'
510 } 510 }
511 ); 511 );
512 modalInstance.result.then( 512 modalInstance.result.then(
513 function(cliente) { 513 function(cliente) {
514 $scope.abrirModalDomicilios(cliente); 514 $scope.abrirModalDomicilios(cliente);
515 $scope.cliente = cliente; 515 $scope.cliente = cliente;
516 }, function() {} 516 }, function() {}
517 ); 517 );
518 } 518 }
519 }; 519 };
520 520
521 $scope.abrirModalDomicilios = function(cliente) { 521 $scope.abrirModalDomicilios = function(cliente) {
522 var modalInstanceDomicilio = $uibModal.open( 522 var modalInstanceDomicilio = $uibModal.open(
523 { 523 {
524 ariaLabelledBy: 'Busqueda de Domicilios', 524 ariaLabelledBy: 'Busqueda de Domicilios',
525 templateUrl: 'modal-domicilio.html', 525 templateUrl: 'modal-domicilio.html',
526 controller: 'focaModalDomicilioController', 526 controller: 'focaModalDomicilioController',
527 resolve: { 527 resolve: {
528 idCliente: function() { return cliente.cod; }, 528 idCliente: function() { return cliente.cod; },
529 esNuevo: function() { return cliente.esNuevo; } 529 esNuevo: function() { return cliente.esNuevo; }
530 }, 530 },
531 size: 'lg', 531 size: 'lg',
532 } 532 }
533 ); 533 );
534 modalInstanceDomicilio.result.then( 534 modalInstanceDomicilio.result.then(
535 function(domicilio) { 535 function(domicilio) {
536 $scope.notaPedido.domicilio = domicilio; 536 $scope.notaPedido.domicilio = domicilio;
537 $scope.notaPedido.cliente = { 537 $scope.notaPedido.cliente = {
538 COD: cliente.cod, 538 COD: cliente.cod,
539 CUIT: cliente.cuit, 539 CUIT: cliente.cuit,
540 NOM: cliente.nom 540 NOM: cliente.nom
541 }; 541 };
542 var domicilioStamp = 542 var domicilioStamp =
543 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 543 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
544 domicilio.Localidad + ', ' + domicilio.Provincia; 544 domicilio.Localidad + ', ' + domicilio.Provincia;
545 $scope.notaPedido.domicilioStamp = domicilioStamp; 545 $scope.notaPedido.domicilioStamp = domicilioStamp;
546 546
547 $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; 547 $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga;
548 548
549 $scope.$broadcast('addCabecera', { 549 $scope.$broadcast('addCabecera', {
550 label: 'Cliente:', 550 label: 'Cliente:',
551 valor: cliente.nom 551 valor: cliente.nom
552 }); 552 });
553 $scope.$broadcast('addCabecera', { 553 $scope.$broadcast('addCabecera', {
554 label: 'Domicilio:', 554 label: 'Domicilio:',
555 valor: domicilioStamp 555 valor: domicilioStamp
556 }); 556 });
557 if(domicilio.verPuntos) { 557 if(domicilio.verPuntos) {
558 delete $scope.notaPedido.domicilio.verPuntos; 558 delete $scope.notaPedido.domicilio.verPuntos;
559 $scope.seleccionarPuntosDeDescarga(); 559 $scope.seleccionarPuntosDeDescarga();
560 }else { 560 }else {
561 crearNotaPedidoService 561 crearNotaPedidoService
562 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) 562 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
563 .then(function(res) { 563 .then(function(res) {
564 if(res.data.length) $scope.seleccionarPuntosDeDescarga(); 564 if(res.data.length) $scope.seleccionarPuntosDeDescarga();
565 }); 565 });
566 } 566 }
567 }, function() { 567 }, function() {
568 $scope.seleccionarCliente(); 568 $scope.seleccionarCliente();
569 return; 569 return;
570 } 570 }
571 ); 571 );
572 }; 572 };
573 573
574 $scope.getTotal = function() { 574 $scope.getTotal = function() {
575 var total = 0; 575 var total = 0;
576 var arrayTempArticulos = $scope.articulosTabla; 576 var arrayTempArticulos = $scope.articulosTabla;
577 for (var i = 0; i < arrayTempArticulos.length; i++) { 577 for (var i = 0; i < arrayTempArticulos.length; i++) {
578 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 578 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
579 } 579 }
580 return parseFloat(total.toFixed(2)); 580 return parseFloat(total.toFixed(2));
581 }; 581 };
582 582
583 $scope.getSubTotal = function() { 583 $scope.getSubTotal = function() {
584 if($scope.articuloACargar) { 584 if($scope.articuloACargar) {
585 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 585 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
586 } 586 }
587 }; 587 };
588 588
589 $scope.seleccionarPreciosYCondiciones = function() { 589 $scope.seleccionarPreciosYCondiciones = function() {
590 if(validarNotaRemitada()) { 590 if(validarNotaRemitada()) {
591 var modalInstance = $uibModal.open( 591 var modalInstance = $uibModal.open(
592 { 592 {
593 ariaLabelledBy: 'Busqueda de Precio Condición', 593 ariaLabelledBy: 'Busqueda de Precio Condición',
594 templateUrl: 'modal-precio-condicion.html', 594 templateUrl: 'modal-precio-condicion.html',
595 controller: 'focaModalPrecioCondicionController', 595 controller: 'focaModalPrecioCondicionController',
596 size: 'lg' 596 size: 'lg'
597 } 597 }
598 ); 598 );
599 modalInstance.result.then( 599 modalInstance.result.then(
600 function(precioCondicion) { 600 function(precioCondicion) {
601 var cabecera = ''; 601 var cabecera = '';
602 var plazosConcat = ''; 602 var plazosConcat = '';
603 if(!Array.isArray(precioCondicion)) { 603 if(!Array.isArray(precioCondicion)) {
604 $scope.notaPedido.idPrecioCondicion = precioCondicion.id; 604 $scope.notaPedido.idPrecioCondicion = precioCondicion.id;
605 $scope.plazosPagos = precioCondicion.plazoPago; 605 $scope.plazosPagos = precioCondicion.plazoPago;
606 $scope.idLista = precioCondicion.idListaPrecio; 606 $scope.idLista = precioCondicion.idListaPrecio;
607 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 607 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
608 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 608 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
609 } 609 }
610 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 610 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
611 } else { //Cuando se ingresan los plazos manualmente 611 } else { //Cuando se ingresan los plazos manualmente
612 $scope.notaPedido.idPrecioCondicion = 0; 612 $scope.notaPedido.idPrecioCondicion = 0;
613 //-1, el modal productos busca todos los productos 613 //-1, el modal productos busca todos los productos
614 $scope.idLista = -1; 614 $scope.idLista = -1;
615 $scope.plazosPagos = precioCondicion; 615 $scope.plazosPagos = precioCondicion;
616 for(var j = 0; j < precioCondicion.length; j++) { 616 for(var j = 0; j < precioCondicion.length; j++) {
617 plazosConcat += precioCondicion[j].dias + ' '; 617 plazosConcat += precioCondicion[j].dias + ' ';
618 } 618 }
619 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 619 cabecera = 'Ingreso manual ' + plazosConcat.trim();
620 } 620 }
621 $scope.articulosTabla = []; 621 $scope.articulosTabla = [];
622 $scope.$broadcast('addCabecera', { 622 $scope.$broadcast('addCabecera', {
623 label: 'Precios y condiciones:', 623 label: 'Precios y condiciones:',
624 valor: cabecera 624 valor: cabecera
625 }); 625 });
626 }, function() { 626 }, function() {
627 627
628 } 628 }
629 ); 629 );
630 } 630 }
631 }; 631 };
632 632
633 $scope.seleccionarFlete = function() { 633 $scope.seleccionarFlete = function() {
634 if(validarNotaRemitada()) { 634 if(validarNotaRemitada()) {
635 var modalInstance = $uibModal.open( 635 var modalInstance = $uibModal.open(
636 { 636 {
637 ariaLabelledBy: 'Busqueda de Flete', 637 ariaLabelledBy: 'Busqueda de Flete',
638 templateUrl: 'modal-flete.html', 638 templateUrl: 'modal-flete.html',
639 controller: 'focaModalFleteController', 639 controller: 'focaModalFleteController',
640 size: 'lg', 640 size: 'lg',
641 resolve: { 641 resolve: {
642 parametrosFlete: 642 parametrosFlete:
643 function() { 643 function() {
644 return { 644 return {
645 flete: $scope.notaPedido.fob ? 'FOB' : 645 flete: $scope.notaPedido.fob ? 'FOB' :
646 ( $scope.notaPedido.flete ? '1' : 646 ( $scope.notaPedido.flete ? '1' :
647 ($scope.notaPedido.flete === undefined ? 647 ($scope.notaPedido.flete === undefined ?
648 null : '0')), 648 null : '0')),
649 bomba: $scope.notaPedido.bomba ? '1' : 649 bomba: $scope.notaPedido.bomba ? '1' :
650 ($scope.notaPedido.bomba === undefined ? 650 ($scope.notaPedido.bomba === undefined ?
651 null : '0'), 651 null : '0'),
652 kilometros: $scope.notaPedido.kilometros 652 kilometros: $scope.notaPedido.kilometros
653 }; 653 };
654 } 654 }
655 } 655 }
656 } 656 }
657 ); 657 );
658 modalInstance.result.then( 658 modalInstance.result.then(
659 function(datos) { 659 function(datos) {
660 $scope.notaPedido.flete = datos.flete; 660 $scope.notaPedido.flete = datos.flete;
661 $scope.notaPedido.fob = datos.FOB; 661 $scope.notaPedido.fob = datos.FOB;
662 $scope.notaPedido.bomba = datos.bomba; 662 $scope.notaPedido.bomba = datos.bomba;
663 $scope.notaPedido.kilometros = datos.kilometros; 663 $scope.notaPedido.kilometros = datos.kilometros;
664 $scope.$broadcast('addCabecera', { 664 $scope.$broadcast('addCabecera', {
665 label: 'Flete:', 665 label: 'Flete:',
666 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') 666 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No')
667 }); 667 });
668 if(datos.flete) { 668 if(datos.flete) {
669 $scope.$broadcast('addCabecera', { 669 $scope.$broadcast('addCabecera', {
670 label: 'Bomba:', 670 label: 'Bomba:',
671 valor: datos.bomba ? 'Si' : 'No' 671 valor: datos.bomba ? 'Si' : 'No'
672 }); 672 });
673 $scope.$broadcast('addCabecera', { 673 $scope.$broadcast('addCabecera', {
674 label: 'Kilometros:', 674 label: 'Kilometros:',
675 valor: datos.kilometros 675 valor: datos.kilometros
676 }); 676 });
677 } else { 677 } else {
678 $scope.$broadcast('removeCabecera', 'Bomba:'); 678 $scope.$broadcast('removeCabecera', 'Bomba:');
679 $scope.$broadcast('removeCabecera', 'Kilometros:'); 679 $scope.$broadcast('removeCabecera', 'Kilometros:');
680 $scope.notaPedido.bomba = false; 680 $scope.notaPedido.bomba = false;
681 $scope.notaPedido.kilometros = null; 681 $scope.notaPedido.kilometros = null;
682 } 682 }
683 }, function() { 683 }, function() {
684 684
685 } 685 }
686 ); 686 );
687 } 687 }
688 }; 688 };
689 689
690 $scope.seleccionarMoneda = function() { 690 $scope.seleccionarMoneda = function() {
691 if(validarNotaRemitada()) { 691 if(validarNotaRemitada()) {
692 var modalInstance = $uibModal.open( 692 var parametrosModal = {
693 { 693 titulo: 'Búsqueda de monedas',
694 ariaLabelledBy: 'Busqueda de Moneda', 694 query: '/moneda',
695 templateUrl: 'modal-moneda.html', 695 columnas: [
696 controller: 'focaModalMonedaController', 696 {
697 size: 'lg' 697 propiedad: 'DETALLE',
698 } 698 nombre: 'Nombre'
699 ); 699 },
700 modalInstance.result.then( 700 {
701 propiedad: 'SIMBOLO',
702 nombre: 'simbolo'
703 }
704 ],
705 size: 'md'
706 };
707 focaModalService.modal(parametrosModal).result.then(
701 function(moneda) { 708 function(moneda) {
702 $scope.abrirModalCotizacion(moneda); 709 $scope.abrirModalCotizacion(moneda);
703 }, function() { 710 }, function() {
704 711
705 } 712 }
706 ); 713 );
707 } 714 }
708 }; 715 };
709 716
710 $scope.abrirModalCotizacion = function(moneda) { 717 $scope.abrirModalCotizacion = function(moneda) {
711 var modalInstance = $uibModal.open( 718 var modalInstance = $uibModal.open(
712 { 719 {
713 ariaLabelledBy: 'Busqueda de Cotización', 720 ariaLabelledBy: 'Busqueda de Cotización',
714 templateUrl: 'modal-cotizacion.html', 721 templateUrl: 'modal-cotizacion.html',
715 controller: 'focaModalCotizacionController', 722 controller: 'focaModalCotizacionController',
716 size: 'lg', 723 size: 'lg',
717 resolve: {idMoneda: function() {return moneda.ID;}} 724 resolve: {idMoneda: function() {return moneda.ID;}}
718 } 725 }
719 ); 726 );
720 modalInstance.result.then( 727 modalInstance.result.then(
721 function(cotizacion) { 728 function(cotizacion) {
722 var articulosTablaTemp = $scope.articulosTabla; 729 var articulosTablaTemp = $scope.articulosTabla;
723 for(var i = 0; i < articulosTablaTemp.length; i++) { 730 for(var i = 0; i < articulosTablaTemp.length; i++) {
724 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 731 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
725 $scope.notaPedido.cotizacion.VENDEDOR; 732 $scope.notaPedido.cotizacion.VENDEDOR;
726 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 733 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
727 cotizacion.VENDEDOR; 734 cotizacion.VENDEDOR;
728 } 735 }
729 $scope.articulosTabla = articulosTablaTemp; 736 $scope.articulosTabla = articulosTablaTemp;
730 $scope.notaPedido.moneda = moneda; 737 $scope.notaPedido.moneda = moneda;
731 $scope.notaPedido.cotizacion = cotizacion; 738 $scope.notaPedido.cotizacion = cotizacion;
732 if(moneda.DETALLE === 'PESOS ARGENTINOS') { 739 if(moneda.DETALLE === 'PESOS ARGENTINOS') {
733 $scope.$broadcast('removeCabecera', 'Moneda:'); 740 $scope.$broadcast('removeCabecera', 'Moneda:');
734 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 741 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
735 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 742 $scope.$broadcast('removeCabecera', 'Cotizacion:');
736 }else { 743 }else {
737 $scope.$broadcast('addCabecera', { 744 $scope.$broadcast('addCabecera', {
738 label: 'Moneda:', 745 label: 'Moneda:',
739 valor: moneda.DETALLE 746 valor: moneda.DETALLE
740 }); 747 });
741 $scope.$broadcast('addCabecera', { 748 $scope.$broadcast('addCabecera', {
742 label: 'Fecha cotizacion:', 749 label: 'Fecha cotizacion:',
743 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 750 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
744 }); 751 });
745 $scope.$broadcast('addCabecera', { 752 $scope.$broadcast('addCabecera', {
746 label: 'Cotizacion:', 753 label: 'Cotizacion:',
747 valor: $filter('number')(cotizacion.VENDEDOR, '2') 754 valor: $filter('number')(cotizacion.VENDEDOR, '2')
748 }); 755 });
749 } 756 }
750 }, function() { 757 }, function() {
751 758
752 } 759 }
753 ); 760 );
754 }; 761 };
755 762
756 $scope.agregarATabla = function(key) { 763 $scope.agregarATabla = function(key) {
757 if(key === 13) { 764 if(key === 13) {
758 if($scope.articuloACargar.cantidad === undefined || 765 if($scope.articuloACargar.cantidad === undefined ||
759 $scope.articuloACargar.cantidad === 0 || 766 $scope.articuloACargar.cantidad === 0 ||
760 $scope.articuloACargar.cantidad === null ) { 767 $scope.articuloACargar.cantidad === null ) {
761 focaModalService.alert('El valor debe ser al menos 1'); 768 focaModalService.alert('El valor debe ser al menos 1');
762 return; 769 return;
763 } 770 }
764 delete $scope.articuloACargar.sectorCodigo; 771 delete $scope.articuloACargar.sectorCodigo;
765 $scope.articulosTabla.push($scope.articuloACargar); 772 $scope.articulosTabla.push($scope.articuloACargar);
766 $scope.cargando = true; 773 $scope.cargando = true;
767 } 774 }
768 }; 775 };
769 776
770 $scope.quitarArticulo = function(key) { 777 $scope.quitarArticulo = function(key) {
771 $scope.articulosTabla.splice(key, 1); 778 $scope.articulosTabla.splice(key, 1);
772 }; 779 };
773 780
774 $scope.editarArticulo = function(key, articulo) { 781 $scope.editarArticulo = function(key, articulo) {
775 if(key === 13) { 782 if(key === 13) {
776 if(articulo.cantidad === null || articulo.cantidad === 0 || 783 if(articulo.cantidad === null || articulo.cantidad === 0 ||
777 articulo.cantidad === undefined) { 784 articulo.cantidad === undefined) {
778 focaModalService.alert('El valor debe ser al menos 1'); 785 focaModalService.alert('El valor debe ser al menos 1');
779 return; 786 return;
780 } 787 }
781 articulo.editCantidad = false; 788 articulo.editCantidad = false;
782 articulo.editPrecio = false; 789 articulo.editPrecio = false;
783 } 790 }
784 }; 791 };
785 792
786 $scope.cambioEdit = function(articulo, propiedad) { 793 $scope.cambioEdit = function(articulo, propiedad) {
787 if(propiedad === 'cantidad') { 794 if(propiedad === 'cantidad') {
788 articulo.editCantidad = true; 795 articulo.editCantidad = true;
789 } else if(propiedad === 'precio') { 796 } else if(propiedad === 'precio') {
790 articulo.editPrecio = true; 797 articulo.editPrecio = true;
791 } 798 }
792 }; 799 };
793 800
794 $scope.resetFilter = function() { 801 $scope.resetFilter = function() {
795 $scope.articuloACargar = {}; 802 $scope.articuloACargar = {};
796 $scope.cargando = true; 803 $scope.cargando = true;
797 }; 804 };
798 //Recibe aviso si el teclado está en uso 805 //Recibe aviso si el teclado está en uso
799 $rootScope.$on('usarTeclado', function(event, data) { 806 $rootScope.$on('usarTeclado', function(event, data) {
800 if(data) { 807 if(data) {
801 $scope.mostrarTeclado = true; 808 $scope.mostrarTeclado = true;
802 return; 809 return;
803 } 810 }
804 $scope.mostrarTeclado = false; 811 $scope.mostrarTeclado = false;
805 }); 812 });
806 813
807 $scope.selectFocus = function($event) { 814 $scope.selectFocus = function($event) {
808 // Si el teclado esta en uso no selecciona el valor 815 // Si el teclado esta en uso no selecciona el valor
809 if($scope.mostrarTeclado) { 816 if($scope.mostrarTeclado) {
810 return; 817 return;
811 } 818 }
812 $event.target.select(); 819 $event.target.select();
813 }; 820 };
814 821
815 $scope.salir = function() { 822 $scope.salir = function() {
816 $location.path('/'); 823 $location.path('/');
817 }; 824 };
818 825
819 $scope.parsearATexto = function(articulo) { 826 $scope.parsearATexto = function(articulo) {
820 articulo.cantidad = parseFloat(articulo.cantidad); 827 articulo.cantidad = parseFloat(articulo.cantidad);
821 articulo.precio = parseFloat(articulo.precio); 828 articulo.precio = parseFloat(articulo.precio);
822 }; 829 };
823 830
824 function addArrayCabecera(array) { 831 function addArrayCabecera(array) {
825 for(var i = 0; i < array.length; i++) { 832 for(var i = 0; i < array.length; i++) {
826 $scope.$broadcast('addCabecera', { 833 $scope.$broadcast('addCabecera', {
827 label: array[i].label, 834 label: array[i].label,
828 valor: array[i].valor 835 valor: array[i].valor
829 }); 836 });
830 } 837 }
831 } 838 }
832 839
833 function rellenar(relleno, longitud) { 840 function rellenar(relleno, longitud) {
834 relleno = '' + relleno; 841 relleno = '' + relleno;
835 while (relleno.length < longitud) { 842 while (relleno.length < longitud) {
836 relleno = '0' + relleno; 843 relleno = '0' + relleno;
837 } 844 }
838 845
839 return relleno; 846 return relleno;
840 } 847 }
841 848
842 function validarNotaRemitada() { 849 function validarNotaRemitada() {
843 if(!$scope.notaPedido.idRemito) { 850 if(!$scope.notaPedido.idRemito) {
844 return true; 851 return true;
845 }else{ 852 }else{
846 focaModalService.alert('No se puede editar una nota de pedido remitada'); 853 focaModalService.alert('No se puede editar una nota de pedido remitada');
847 return false; 854 return false;
848 } 855 }
849 } 856 }
850 function formatearPuntosDescarga(puntosDescarga) { 857 function formatearPuntosDescarga(puntosDescarga) {
851 var result = []; 858 var result = [];
852 859
853 puntosDescarga.forEach(function(el) { 860 puntosDescarga.forEach(function(el) {
854 var puntoDescarga = result.filter(function(resultPunto) { 861 var puntoDescarga = result.filter(function(resultPunto) {
855 return resultPunto.id == el.idPuntoDescarga; 862 return resultPunto.id == el.idPuntoDescarga;
856 }); 863 });
857 864
858 if(puntoDescarga.length) { 865 if(puntoDescarga.length) {
859 puntoDescarga[0].articulosAgregados.push({ 866 puntoDescarga[0].articulosAgregados.push({
860 cantidad: el.cantidad, 867 cantidad: el.cantidad,
861 descripcion: el.producto.descripcion, 868 descripcion: el.producto.descripcion,
862 id: el.producto.id 869 id: el.producto.id
863 }); 870 });
864 }else { 871 }else {
865 result.push({ 872 result.push({
866 id: el.puntoDescarga.id, 873 id: el.puntoDescarga.id,
867 id_cliente: el.puntoDescarga.id_cliente, 874 id_cliente: el.puntoDescarga.id_cliente,
868 id_da_config_0: el.puntoDescarga.id_da_config_0, 875 id_da_config_0: el.puntoDescarga.id_da_config_0,
869 latitud: el.puntoDescarga.latitud, 876 latitud: el.puntoDescarga.latitud,
870 longitud: el.puntoDescarga.longitud, 877 longitud: el.puntoDescarga.longitud,
871 descripcion: el.puntoDescarga.descripcion, 878 descripcion: el.puntoDescarga.descripcion,
872 articulosAgregados: [ 879 articulosAgregados: [
873 { 880 {
874 cantidad: el.cantidad, 881 cantidad: el.cantidad,
875 descripcion: el.producto.descripcion, 882 descripcion: el.producto.descripcion,
876 id: el.producto.id 883 id: el.producto.id
877 } 884 }
878 ] 885 ]
879 }); 886 });
880 } 887 }
881 }); 888 });
882 return result; 889 return result;
883 } 890 }
884 891
885 function salir() { 892 function salir() {
886 var notaPedido = { 893 var notaPedido = {
887 id: 0, 894 id: 0,
888 vendedor: {}, 895 vendedor: {},
889 cliente: {}, 896 cliente: {},
890 proveedor: {}, 897 proveedor: {},
891 domicilio: {dom: ''}, 898 domicilio: {dom: ''},
892 moneda: $scope.notaPedido.moneda, 899 moneda: $scope.notaPedido.moneda,
893 cotizacion: $scope.notaPedido.cotizacion 900 cotizacion: $scope.notaPedido.cotizacion
894 }; 901 };
895 if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) { 902 if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) {
896 focaModalService 903 focaModalService
897 .confirm('¿Esta seguro de que desea salir? ' + 904 .confirm('¿Esta seguro de que desea salir? ' +
898 'Se perderán todos los datos cargados.') 905 'Se perderán todos los datos cargados.')
899 .then(function(data) { 906 .then(function(data) {
900 if(data) $location.path('/'); 907 if(data) $location.path('/');
901 }); 908 });
902 }else { 909 }else {
903 $location.path('/'); 910 $location.path('/');
904 } 911 }
905 } 912 }
906 } 913 }
907 ]); 914 ]);
908 915