Commit 202c7b56b3c5a99d8d3769fa3856fd164622beb8

Authored by Nicolás Guarnieri
1 parent eb67b9621b
Exists in master

inicializacion de controler y salir

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