Commit eb67b9621b5a9563385d3014ee4bea79cd87b535

Authored by Nicolás Guarnieri
1 parent 75a3e5aa91
Exists in master

bien seleccion de variables

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