Commit 9ff0854bf422f4b1988032d09cdbcd62bda876bf

Authored by Jose Pinto
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

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