Commit 2349f4fe584ae90fcddbee4a4c6554a836d5b993

Authored by Nicolás Guarnieri
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master

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