Commit 5048ec50e29684095a673eb581d8d8ddebd9cbe0

Authored by Jose Pinto
1 parent 89f6e67be5

quito validacion

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