Commit 46c02023878ddf08d22509d4ac7614c33772af76

Authored by Jose Pinto
1 parent 7424f270a7
Exists in master and in 1 other branch develop

envio vendedor a modal clientes

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