Commit a826c8538f141f19cd27de3c30e3b5f588a419d6

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master

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