Commit 75a3e5aa9117b8fec15558a80e682d422ee68235

Authored by Nicolás Guarnieri
1 parent 9ff0854bf4

agregado codigo en la cabecera

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