Commit 3d91189ca07b7e3f0b84467ac29bb9042b5afcb7

Authored by Jose Pinto
1 parent 875485e9b6
Exists in master and in 1 other branch develop

codigo y nombre vendedor al seleccionarlo

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