Commit f5ff51fa8cbc109011e68c76f948611e66606d69

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

Merge branch 'master' into 'master'

Master

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