Commit 1b7e84ec68c91ab218eebf4275bf0d07ed192230

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

titulo correcto

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