Commit 89f6e67be5a86472c3d75bf9512d16484795765a

Authored by Jose Pinto
1 parent d42cb1f810

guardo idDomicilio

Showing 1 changed file with 6 additions and 3 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,//TODO
373 idCotizacion: $scope.remito.cotizacion.ID, 372 idCotizacion: $scope.remito.cotizacion.ID,
374 idPrecioCondicion: $scope.remito.idPrecioCondicion, 373 idPrecioCondicion: $scope.remito.idPrecioCondicion,
375 flete: $scope.remito.flete, 374 flete: $scope.remito.flete,
376 fob: $scope.remito.fob, 375 fob: $scope.remito.fob,
377 bomba: $scope.remito.bomba, 376 bomba: $scope.remito.bomba,
378 kilometros: $scope.remito.kilometros, 377 kilometros: $scope.remito.kilometros,
379 domicilioStamp: $scope.remito.domicilioStamp,
380 estado: 0,//TODO 378 estado: 0,//TODO
381 destinoVenta: 0,//TODO 379 destinoVenta: 0,//TODO
382 operacionTipo: 0//TODO 380 operacionTipo: 0//TODO
383 }, 381 },
384 notaPedido: $scope.notaPedido 382 notaPedido: $scope.notaPedido
385 }; 383 };
384
385 if ($scope.remito.domicilio) {
386 save.remito.domicilioStamp = $scope.remito.domicilioStamp;
387 save.remito.idDomicilio = $scope.remito.domicilio.id;
388 }
386 crearRemitoService.crearRemito(save).then( 389 crearRemitoService.crearRemito(save).then(
387 function(data) { 390 function(data) {
388 remitoBusinessService.addArticulos($scope.articulosTabla, 391 remitoBusinessService.addArticulos($scope.articulosTabla,
389 data.data.id, $scope.remito.cotizacion.COTIZACION); 392 data.data.id, $scope.remito.cotizacion.COTIZACION);
390 393
391 focaBotoneraLateralService.endGuardar(true); 394 focaBotoneraLateralService.endGuardar(true);
392 $scope.saveLoading = false; 395 $scope.saveLoading = false;
393 //TODO: updatear plazos 396 //TODO: updatear plazos
394 if($scope.remito.id === 0) { 397 if($scope.remito.id === 0) {
395 var plazos = $scope.plazosPagos; 398 var plazos = $scope.plazosPagos;
396 399
397 for(var j = 0; j < plazos.length; j++) { 400 for(var j = 0; j < plazos.length; j++) {
398 var json = { 401 var json = {
399 idRemito: data.data.id, 402 idRemito: data.data.id,
400 dias: plazos[j].dias 403 dias: plazos[j].dias
401 }; 404 };
402 crearRemitoService.crearPlazosParaRemito(json); 405 crearRemitoService.crearPlazosParaRemito(json);
403 } 406 }
404 } 407 }
405 408
406 init(); 409 init();
407 }, function(error) { 410 }, function(error) {
408 focaModalService.alert('Hubo un error al crear el remito'); 411 focaModalService.alert('Hubo un error al crear el remito');
409 focaBotoneraLateralService.endGuardar(); 412 focaBotoneraLateralService.endGuardar();
410 $scope.saveLoading = false; 413 $scope.saveLoading = false;
411 console.info(error); 414 console.info(error);
412 } 415 }
413 ); 416 );
414 }; 417 };
415 418
416 $scope.seleccionarProductos = function() { 419 $scope.seleccionarProductos = function() {
417 if($scope.idLista === undefined) { 420 if($scope.idLista === undefined) {
418 focaModalService.alert( 421 focaModalService.alert(
419 'Primero seleccione una lista de precio y condicion'); 422 'Primero seleccione una lista de precio y condicion');
420 return; 423 return;
421 } 424 }
422 var modalInstance = $uibModal.open( 425 var modalInstance = $uibModal.open(
423 { 426 {
424 ariaLabelledBy: 'Busqueda de Productos', 427 ariaLabelledBy: 'Busqueda de Productos',
425 templateUrl: 'modal-busqueda-productos.html', 428 templateUrl: 'modal-busqueda-productos.html',
426 controller: 'modalBusquedaProductosCtrl', 429 controller: 'modalBusquedaProductosCtrl',
427 resolve: { 430 resolve: {
428 parametroProducto: { 431 parametroProducto: {
429 idLista: $scope.idLista, 432 idLista: $scope.idLista,
430 cotizacion: $scope.remito.cotizacion.COTIZACION, 433 cotizacion: $scope.remito.cotizacion.COTIZACION,
431 simbolo: $scope.remito.moneda.simbolo 434 simbolo: $scope.remito.moneda.simbolo
432 } 435 }
433 }, 436 },
434 size: 'lg' 437 size: 'lg'
435 } 438 }
436 ); 439 );
437 modalInstance.result.then( 440 modalInstance.result.then(
438 function(producto) { 441 function(producto) {
439 var newArt = 442 var newArt =
440 { 443 {
441 id: 0, 444 id: 0,
442 codigo: producto.codigo, 445 codigo: producto.codigo,
443 sector: producto.sector, 446 sector: producto.sector,
444 sectorCodigo: producto.sector + '-' + producto.codigo, 447 sectorCodigo: producto.sector + '-' + producto.codigo,
445 descripcion: producto.descripcion, 448 descripcion: producto.descripcion,
446 item: $scope.articulosTabla.length + 1, 449 item: $scope.articulosTabla.length + 1,
447 nombre: producto.descripcion, 450 nombre: producto.descripcion,
448 precio: parseFloat(producto.precio.toFixed(4)), 451 precio: parseFloat(producto.precio.toFixed(4)),
449 costoUnitario: producto.costo, 452 costoUnitario: producto.costo,
450 editCantidad: false, 453 editCantidad: false,
451 editPrecio: false, 454 editPrecio: false,
452 rubro: producto.CodRub, 455 rubro: producto.CodRub,
453 exentoUnitario: producto.precio, 456 exentoUnitario: producto.precio,
454 ivaUnitario: producto.IMPIVA, 457 ivaUnitario: producto.IMPIVA,
455 impuestoInternoUnitario: producto.ImpInt, 458 impuestoInternoUnitario: producto.ImpInt,
456 impuestoInterno1Unitario: producto.ImpInt2, 459 impuestoInterno1Unitario: producto.ImpInt2,
457 impuestoInterno2Unitario: producto.ImpInt3, 460 impuestoInterno2Unitario: producto.ImpInt3,
458 precioLista: producto.precio, 461 precioLista: producto.precio,
459 combustible: 1, 462 combustible: 1,
460 facturado: 0 463 facturado: 0
461 }; 464 };
462 $scope.articuloACargar = newArt; 465 $scope.articuloACargar = newArt;
463 $scope.cargando = false; 466 $scope.cargando = false;
464 }, function() { 467 }, function() {
465 // funcion ejecutada cuando se cancela el modal 468 // funcion ejecutada cuando se cancela el modal
466 } 469 }
467 ); 470 );
468 }; 471 };
469 472
470 $scope.seleccionarVendedor = function() { 473 $scope.seleccionarVendedor = function() {
471 if(varlidarRemitoFacturado()) { 474 if(varlidarRemitoFacturado()) {
472 var parametrosModal = { 475 var parametrosModal = {
473 titulo: 'Búsqueda vendedores', 476 titulo: 'Búsqueda vendedores',
474 query: '/vendedor', 477 query: '/vendedor',
475 columnas: [ 478 columnas: [
476 { 479 {
477 propiedad: 'NUM', 480 propiedad: 'NUM',
478 nombre: 'Código', 481 nombre: 'Código',
479 filtro: { 482 filtro: {
480 nombre: 'rellenarDigitos', 483 nombre: 'rellenarDigitos',
481 parametro: 3 484 parametro: 3
482 } 485 }
483 }, 486 },
484 { 487 {
485 propiedad: 'NOM', 488 propiedad: 'NOM',
486 nombre: 'Nombre' 489 nombre: 'Nombre'
487 } 490 }
488 ], 491 ],
489 size: 'md' 492 size: 'md'
490 }; 493 };
491 focaModalService.modal(parametrosModal).then( 494 focaModalService.modal(parametrosModal).then(
492 function(vendedor) { 495 function(vendedor) {
493 $scope.$broadcast('addCabecera',{ 496 $scope.$broadcast('addCabecera',{
494 label: 'Vendedor:', 497 label: 'Vendedor:',
495 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 498 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
496 vendedor.NOM 499 vendedor.NOM
497 }); 500 });
498 $scope.remito.idVendedor = vendedor.id; 501 $scope.remito.idVendedor = vendedor.id;
499 $scope.vendedor = vendedor; 502 $scope.vendedor = vendedor;
500 }, function() { 503 }, function() {
501 504
502 } 505 }
503 ); 506 );
504 } 507 }
505 }; 508 };
506 509
507 $scope.seleccionarProveedor = function() { 510 $scope.seleccionarProveedor = function() {
508 if(varlidarRemitoFacturado()) { 511 if(varlidarRemitoFacturado()) {
509 var parametrosModal = { 512 var parametrosModal = {
510 titulo: 'Búsqueda de Proveedor', 513 titulo: 'Búsqueda de Proveedor',
511 query: '/proveedor', 514 query: '/proveedor',
512 columnas: [ 515 columnas: [
513 { 516 {
514 nombre: 'Código', 517 nombre: 'Código',
515 propiedad: 'COD', 518 propiedad: 'COD',
516 filtro: { 519 filtro: {
517 nombre: 'rellenarDigitos', 520 nombre: 'rellenarDigitos',
518 parametro: 5 521 parametro: 5
519 } 522 }
520 }, 523 },
521 { 524 {
522 nombre: 'Nombre', 525 nombre: 'Nombre',
523 propiedad: 'NOM' 526 propiedad: 'NOM'
524 }, 527 },
525 { 528 {
526 nombre: 'CUIT', 529 nombre: 'CUIT',
527 propiedad: 'CUIT' 530 propiedad: 'CUIT'
528 } 531 }
529 ], 532 ],
530 tipo: 'POST', 533 tipo: 'POST',
531 json: {razonCuitCod: ''} 534 json: {razonCuitCod: ''}
532 }; 535 };
533 focaModalService.modal(parametrosModal).then( 536 focaModalService.modal(parametrosModal).then(
534 function(proveedor) { 537 function(proveedor) {
535 $scope.remito.idProveedor = proveedor.COD; 538 $scope.remito.idProveedor = proveedor.COD;
536 $scope.$broadcast('addCabecera',{ 539 $scope.$broadcast('addCabecera',{
537 label: 'Proveedor:', 540 label: 'Proveedor:',
538 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 541 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
539 proveedor.NOM 542 proveedor.NOM
540 }); 543 });
541 }, function() { 544 }, function() {
542 545
543 } 546 }
544 ); 547 );
545 } 548 }
546 }; 549 };
547 550
548 $scope.seleccionarCliente = function() { 551 $scope.seleccionarCliente = function() {
549 if(!$scope.vendedor) { 552 if(!$scope.vendedor) {
550 focaModalService.alert('Primero seleccione un vendedor'); 553 focaModalService.alert('Primero seleccione un vendedor');
551 return; 554 return;
552 } 555 }
553 556
554 if(varlidarRemitoFacturado()) { 557 if(varlidarRemitoFacturado()) {
555 var modalInstance = $uibModal.open( 558 var modalInstance = $uibModal.open(
556 { 559 {
557 ariaLabelledBy: 'Busqueda de Cliente', 560 ariaLabelledBy: 'Busqueda de Cliente',
558 templateUrl: 'foca-busqueda-cliente-modal.html', 561 templateUrl: 'foca-busqueda-cliente-modal.html',
559 controller: 'focaBusquedaClienteModalController', 562 controller: 'focaBusquedaClienteModalController',
560 resolve: { 563 resolve: {
561 vendedor: function() { return $scope.vendedor; } 564 vendedor: function() { return $scope.vendedor; }
562 }, 565 },
563 size: 'lg' 566 size: 'lg'
564 } 567 }
565 ); 568 );
566 modalInstance.result.then( 569 modalInstance.result.then(
567 function(cliente) { 570 function(cliente) {
568 $scope.abrirModalDomicilios(cliente); 571 $scope.abrirModalDomicilios(cliente);
569 }, function() { 572 }, function() {
570 573
571 } 574 }
572 ); 575 );
573 } 576 }
574 }; 577 };
575 578
576 $scope.abrirModalDomicilios = function(cliente) { 579 $scope.abrirModalDomicilios = function(cliente) {
577 var modalInstanceDomicilio = $uibModal.open( 580 var modalInstanceDomicilio = $uibModal.open(
578 { 581 {
579 ariaLabelledBy: 'Busqueda de Domicilios', 582 ariaLabelledBy: 'Busqueda de Domicilios',
580 templateUrl: 'modal-domicilio.html', 583 templateUrl: 'modal-domicilio.html',
581 controller: 'focaModalDomicilioController', 584 controller: 'focaModalDomicilioController',
582 size: 'lg', 585 size: 'lg',
583 resolve: { 586 resolve: {
584 idCliente: function() { return cliente.cod; }, 587 idCliente: function() { return cliente.cod; },
585 esNuevo: function() { return cliente.esNuevo; } 588 esNuevo: function() { return cliente.esNuevo; }
586 } 589 }
587 } 590 }
588 ); 591 );
589 modalInstanceDomicilio.result.then( 592 modalInstanceDomicilio.result.then(
590 function(domicilio) { 593 function(domicilio) {
591 //$scope.remito.domicilio.id = domicilio.nivel2; 594 $scope.remito.domicilio = domicilio;
592 $scope.remito.cliente = { 595 $scope.remito.cliente = {
593 COD: cliente.cod, 596 COD: cliente.cod,
594 CUIT: cliente.cuit, 597 CUIT: cliente.cuit,
595 NOM: cliente.nom 598 NOM: cliente.nom
596 }; 599 };
597 600
598 601
599 var domicilioStamp = 602 var domicilioStamp =
600 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 603 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
601 domicilio.Localidad + ', ' + domicilio.Provincia; 604 domicilio.Localidad + ', ' + domicilio.Provincia;
602 $scope.remito.domicilioStamp = domicilioStamp; 605 $scope.remito.domicilioStamp = domicilioStamp;
603 606
604 $scope.$broadcast('addCabecera',{ 607 $scope.$broadcast('addCabecera',{
605 label: 'Cliente:', 608 label: 'Cliente:',
606 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom 609 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
607 }); 610 });
608 $scope.$broadcast('addCabecera',{ 611 $scope.$broadcast('addCabecera',{
609 label: 'Domicilio:', 612 label: 'Domicilio:',
610 valor: domicilioStamp 613 valor: domicilioStamp
611 }); 614 });
612 }, function() { 615 }, function() {
613 $scope.seleccionarCliente(); 616 $scope.seleccionarCliente();
614 return; 617 return;
615 } 618 }
616 ); 619 );
617 }; 620 };
618 621
619 $scope.mostrarFichaCliente = function() { 622 $scope.mostrarFichaCliente = function() {
620 $uibModal.open( 623 $uibModal.open(
621 { 624 {
622 ariaLabelledBy: 'Datos del Cliente', 625 ariaLabelledBy: 'Datos del Cliente',
623 templateUrl: 'foca-crear-remito-ficha-cliente.html', 626 templateUrl: 'foca-crear-remito-ficha-cliente.html',
624 controller: 'focaCrearRemitoFichaClienteController', 627 controller: 'focaCrearRemitoFichaClienteController',
625 size: 'lg' 628 size: 'lg'
626 } 629 }
627 ); 630 );
628 }; 631 };
629 632
630 $scope.getTotal = function() { 633 $scope.getTotal = function() {
631 var total = 0; 634 var total = 0;
632 var arrayTempArticulos = $scope.articulosTabla; 635 var arrayTempArticulos = $scope.articulosTabla;
633 for(var i = 0; i < arrayTempArticulos.length; i++) { 636 for(var i = 0; i < arrayTempArticulos.length; i++) {
634 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 637 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
635 } 638 }
636 return parseFloat(total.toFixed(2)); 639 return parseFloat(total.toFixed(2));
637 }; 640 };
638 641
639 $scope.getSubTotal = function() { 642 $scope.getSubTotal = function() {
640 if($scope.articuloACargar) { 643 if($scope.articuloACargar) {
641 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 644 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
642 } 645 }
643 }; 646 };
644 647
645 $scope.seleccionarPreciosYCondiciones = function() { 648 $scope.seleccionarPreciosYCondiciones = function() {
646 if(varlidarRemitoFacturado()) { 649 if(varlidarRemitoFacturado()) {
647 var modalInstance = $uibModal.open( 650 var modalInstance = $uibModal.open(
648 { 651 {
649 ariaLabelledBy: 'Busqueda de Precio Condición', 652 ariaLabelledBy: 'Busqueda de Precio Condición',
650 templateUrl: 'modal-precio-condicion.html', 653 templateUrl: 'modal-precio-condicion.html',
651 controller: 'focaModalPrecioCondicionController', 654 controller: 'focaModalPrecioCondicionController',
652 size: 'lg' 655 size: 'lg'
653 } 656 }
654 ); 657 );
655 modalInstance.result.then( 658 modalInstance.result.then(
656 function(precioCondicion) { 659 function(precioCondicion) {
657 var cabecera = ''; 660 var cabecera = '';
658 var plazosConcat = ''; 661 var plazosConcat = '';
659 if(!Array.isArray(precioCondicion)) { 662 if(!Array.isArray(precioCondicion)) {
660 $scope.remito.idPrecioCondicion = precioCondicion.id; 663 $scope.remito.idPrecioCondicion = precioCondicion.id;
661 $scope.plazosPagos = precioCondicion.plazoPago; 664 $scope.plazosPagos = precioCondicion.plazoPago;
662 $scope.idLista = precioCondicion.idListaPrecio; 665 $scope.idLista = precioCondicion.idListaPrecio;
663 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 666 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
664 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 667 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
665 } 668 }
666 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + 669 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
667 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); 670 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
668 }else { //Cuando se ingresan los plazos manualmente 671 }else { //Cuando se ingresan los plazos manualmente
669 $scope.remito.idPrecioCondicion = 0; 672 $scope.remito.idPrecioCondicion = 0;
670 //-1, el modal productos busca todos los productos 673 //-1, el modal productos busca todos los productos
671 $scope.idLista = -1; 674 $scope.idLista = -1;
672 $scope.plazosPagos = precioCondicion; 675 $scope.plazosPagos = precioCondicion;
673 for(var j = 0; j < precioCondicion.length; j++) { 676 for(var j = 0; j < precioCondicion.length; j++) {
674 plazosConcat += precioCondicion[j].dias + ' '; 677 plazosConcat += precioCondicion[j].dias + ' ';
675 } 678 }
676 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 679 cabecera = 'Ingreso manual ' + plazosConcat.trim();
677 } 680 }
678 $scope.articulosTabla = []; 681 $scope.articulosTabla = [];
679 $scope.$broadcast('addCabecera',{ 682 $scope.$broadcast('addCabecera',{
680 label: 'Precios y condiciones:', 683 label: 'Precios y condiciones:',
681 valor: cabecera 684 valor: cabecera
682 }); 685 });
683 }, function() { 686 }, function() {
684 687
685 } 688 }
686 ); 689 );
687 } 690 }
688 }; 691 };
689 692
690 $scope.seleccionarFlete = function() { 693 $scope.seleccionarFlete = function() {
691 if(varlidarRemitoFacturado()) { 694 if(varlidarRemitoFacturado()) {
692 var modalInstance = $uibModal.open( 695 var modalInstance = $uibModal.open(
693 { 696 {
694 ariaLabelledBy: 'Busqueda de Flete', 697 ariaLabelledBy: 'Busqueda de Flete',
695 templateUrl: 'modal-flete.html', 698 templateUrl: 'modal-flete.html',
696 controller: 'focaModalFleteController', 699 controller: 'focaModalFleteController',
697 size: 'lg', 700 size: 'lg',
698 resolve: { 701 resolve: {
699 parametrosFlete: 702 parametrosFlete:
700 function() { 703 function() {
701 return { 704 return {
702 flete: $scope.remito.flete ? '1' : 705 flete: $scope.remito.flete ? '1' :
703 ($scope.remito.fob ? 'FOB' : 706 ($scope.remito.fob ? 'FOB' :
704 ($scope.remito.flete === undefined ? null : '0')), 707 ($scope.remito.flete === undefined ? null : '0')),
705 bomba: $scope.remito.bomba ? '1' : 708 bomba: $scope.remito.bomba ? '1' :
706 ($scope.remito.bomba === undefined ? null : '0'), 709 ($scope.remito.bomba === undefined ? null : '0'),
707 kilometros: $scope.remito.kilometros 710 kilometros: $scope.remito.kilometros
708 }; 711 };
709 } 712 }
710 } 713 }
711 } 714 }
712 ); 715 );
713 modalInstance.result.then( 716 modalInstance.result.then(
714 function(datos) { 717 function(datos) {
715 $scope.remito.flete = datos.flete; 718 $scope.remito.flete = datos.flete;
716 $scope.remito.fob = datos.FOB; 719 $scope.remito.fob = datos.FOB;
717 $scope.remito.bomba = datos.bomba; 720 $scope.remito.bomba = datos.bomba;
718 $scope.remito.kilometros = datos.kilometros; 721 $scope.remito.kilometros = datos.kilometros;
719 722
720 $scope.$broadcast('addCabecera',{ 723 $scope.$broadcast('addCabecera',{
721 label: 'Flete:', 724 label: 'Flete:',
722 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') 725 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No')
723 }); 726 });
724 if(datos.flete) { 727 if(datos.flete) {
725 $scope.$broadcast('addCabecera',{ 728 $scope.$broadcast('addCabecera',{
726 label: 'Bomba:', 729 label: 'Bomba:',
727 valor: datos.bomba ? 'Si' : 'No' 730 valor: datos.bomba ? 'Si' : 'No'
728 }); 731 });
729 $scope.$broadcast('addCabecera',{ 732 $scope.$broadcast('addCabecera',{
730 label: 'Kilometros:', 733 label: 'Kilometros:',
731 valor: datos.kilometros 734 valor: datos.kilometros
732 }); 735 });
733 }else { 736 }else {
734 $scope.$broadcast('removeCabecera', 'Bomba:'); 737 $scope.$broadcast('removeCabecera', 'Bomba:');
735 $scope.$broadcast('removeCabecera', 'Kilometros:'); 738 $scope.$broadcast('removeCabecera', 'Kilometros:');
736 $scope.remito.fob = false; 739 $scope.remito.fob = false;
737 $scope.remito.bomba = false; 740 $scope.remito.bomba = false;
738 $scope.remito.kilometros = null; 741 $scope.remito.kilometros = null;
739 } 742 }
740 }, function() { 743 }, function() {
741 744
742 } 745 }
743 ); 746 );
744 } 747 }
745 }; 748 };
746 749
747 $scope.seleccionarMoneda = function() { 750 $scope.seleccionarMoneda = function() {
748 if(varlidarRemitoFacturado()) { 751 if(varlidarRemitoFacturado()) {
749 var parametrosModal = { 752 var parametrosModal = {
750 titulo: 'Búsqueda de monedas', 753 titulo: 'Búsqueda de monedas',
751 query: '/moneda', 754 query: '/moneda',
752 columnas: [ 755 columnas: [
753 { 756 {
754 propiedad: 'DETALLE', 757 propiedad: 'DETALLE',
755 nombre: 'Nombre' 758 nombre: 'Nombre'
756 }, 759 },
757 { 760 {
758 propiedad: 'SIMBOLO', 761 propiedad: 'SIMBOLO',
759 nombre: 'Símbolo' 762 nombre: 'Símbolo'
760 } 763 }
761 ], 764 ],
762 size: 'md' 765 size: 'md'
763 }; 766 };
764 focaModalService.modal(parametrosModal).then( 767 focaModalService.modal(parametrosModal).then(
765 function(moneda) { 768 function(moneda) {
766 $scope.abrirModalCotizacion(moneda); 769 $scope.abrirModalCotizacion(moneda);
767 }, function() { 770 }, function() {
768 771
769 } 772 }
770 ); 773 );
771 } 774 }
772 }; 775 };
773 776
774 $scope.seleccionarObservaciones = function() { 777 $scope.seleccionarObservaciones = function() {
775 focaModalService 778 focaModalService
776 .prompt('Ingrese observaciones', $scope.remito.observaciones, true) 779 .prompt('Ingrese observaciones', $scope.remito.observaciones, true)
777 .then(function(observaciones) { 780 .then(function(observaciones) {
778 $scope.remito.observaciones = observaciones; 781 $scope.remito.observaciones = observaciones;
779 }); 782 });
780 }; 783 };
781 784
782 $scope.abrirModalCotizacion = function(moneda) { 785 $scope.abrirModalCotizacion = function(moneda) {
783 var modalInstance = $uibModal.open( 786 var modalInstance = $uibModal.open(
784 { 787 {
785 ariaLabelledBy: 'Busqueda de Cotización', 788 ariaLabelledBy: 'Busqueda de Cotización',
786 templateUrl: 'modal-cotizacion.html', 789 templateUrl: 'modal-cotizacion.html',
787 controller: 'focaModalCotizacionController', 790 controller: 'focaModalCotizacionController',
788 size: 'lg', 791 size: 'lg',
789 resolve: {idMoneda: function() {return moneda.ID;}} 792 resolve: {idMoneda: function() {return moneda.ID;}}
790 } 793 }
791 ); 794 );
792 modalInstance.result.then( 795 modalInstance.result.then(
793 function(cotizacion) { 796 function(cotizacion) {
794 var articulosTablaTemp = $scope.articulosTabla; 797 var articulosTablaTemp = $scope.articulosTabla;
795 for(var i = 0; i < articulosTablaTemp.length; i++) { 798 for(var i = 0; i < articulosTablaTemp.length; i++) {
796 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 799 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
797 $scope.remito.cotizacion.COTIZACION; 800 $scope.remito.cotizacion.COTIZACION;
798 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 801 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
799 cotizacion.COTIZACION; 802 cotizacion.COTIZACION;
800 } 803 }
801 $scope.articulosTabla = articulosTablaTemp; 804 $scope.articulosTabla = articulosTablaTemp;
802 $scope.remito.moneda = moneda; 805 $scope.remito.moneda = moneda;
803 $scope.remito.cotizacion = cotizacion; 806 $scope.remito.cotizacion = cotizacion;
804 if(moneda.DETALLE === 'PESOS ARGENTINOS') { 807 if(moneda.DETALLE === 'PESOS ARGENTINOS') {
805 $scope.$broadcast('removeCabecera', 'Moneda:'); 808 $scope.$broadcast('removeCabecera', 'Moneda:');
806 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 809 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
807 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 810 $scope.$broadcast('removeCabecera', 'Cotizacion:');
808 }else { 811 }else {
809 $scope.$broadcast('addCabecera',{ 812 $scope.$broadcast('addCabecera',{
810 label: 'Moneda:', 813 label: 'Moneda:',
811 valor: moneda.DETALLE 814 valor: moneda.DETALLE
812 }); 815 });
813 $scope.$broadcast('addCabecera',{ 816 $scope.$broadcast('addCabecera',{
814 label: 'Fecha cotizacion:', 817 label: 'Fecha cotizacion:',
815 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 818 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
816 }); 819 });
817 $scope.$broadcast('addCabecera',{ 820 $scope.$broadcast('addCabecera',{
818 label: 'Cotizacion:', 821 label: 'Cotizacion:',
819 valor: $filter('number')(cotizacion.COTIZACION, '2') 822 valor: $filter('number')(cotizacion.COTIZACION, '2')
820 }); 823 });
821 } 824 }
822 }, function() { 825 }, function() {
823 826
824 } 827 }
825 ); 828 );
826 }; 829 };
827 830
828 $scope.agregarATabla = function(key) { 831 $scope.agregarATabla = function(key) {
829 if(key === 13) { 832 if(key === 13) {
830 if($scope.articuloACargar.cantidad === undefined || 833 if($scope.articuloACargar.cantidad === undefined ||
831 $scope.articuloACargar.cantidad === 0 || 834 $scope.articuloACargar.cantidad === 0 ||
832 $scope.articuloACargar.cantidad === null ) { 835 $scope.articuloACargar.cantidad === null ) {
833 focaModalService.alert('El valor debe ser al menos 1'); 836 focaModalService.alert('El valor debe ser al menos 1');
834 return; 837 return;
835 } 838 }
836 delete $scope.articuloACargar.sectorCodigo; 839 delete $scope.articuloACargar.sectorCodigo;
837 $scope.articulosTabla.push($scope.articuloACargar); 840 $scope.articulosTabla.push($scope.articuloACargar);
838 $scope.cargando = true; 841 $scope.cargando = true;
839 } 842 }
840 }; 843 };
841 844
842 $scope.quitarArticulo = function(key) { 845 $scope.quitarArticulo = function(key) {
843 $scope.articulosTabla.splice(key, 1); 846 $scope.articulosTabla.splice(key, 1);
844 }; 847 };
845 848
846 $scope.editarArticulo = function(key, articulo) { 849 $scope.editarArticulo = function(key, articulo) {
847 if(key === 13) { 850 if(key === 13) {
848 if(articulo.cantidad === null || articulo.cantidad === 0 || 851 if(articulo.cantidad === null || articulo.cantidad === 0 ||
849 articulo.cantidad === undefined) { 852 articulo.cantidad === undefined) {
850 focaModalService.alert('El valor debe ser al menos 1'); 853 focaModalService.alert('El valor debe ser al menos 1');
851 return; 854 return;
852 } 855 }
853 articulo.editCantidad = false; 856 articulo.editCantidad = false;
854 articulo.editPrecio = false; 857 articulo.editPrecio = false;
855 } 858 }
856 }; 859 };
857 860
858 $scope.cambioEdit = function(articulo, propiedad) { 861 $scope.cambioEdit = function(articulo, propiedad) {
859 if(propiedad === 'cantidad') { 862 if(propiedad === 'cantidad') {
860 articulo.editCantidad = true; 863 articulo.editCantidad = true;
861 }else if(propiedad === 'precio') { 864 }else if(propiedad === 'precio') {
862 articulo.editPrecio = true; 865 articulo.editPrecio = true;
863 } 866 }
864 }; 867 };
865 868
866 $scope.limpiarFlete = function() { 869 $scope.limpiarFlete = function() {
867 $scope.remito.fleteNombre = ''; 870 $scope.remito.fleteNombre = '';
868 $scope.remito.chofer = ''; 871 $scope.remito.chofer = '';
869 $scope.remito.vehiculo = ''; 872 $scope.remito.vehiculo = '';
870 $scope.remito.kilometros = ''; 873 $scope.remito.kilometros = '';
871 $scope.remito.costoUnitarioKmFlete = ''; 874 $scope.remito.costoUnitarioKmFlete = '';
872 $scope.choferes = ''; 875 $scope.choferes = '';
873 $scope.vehiculos = ''; 876 $scope.vehiculos = '';
874 }; 877 };
875 878
876 $scope.limpiarPantalla = function() { 879 $scope.limpiarPantalla = function() {
877 $scope.limpiarFlete(); 880 $scope.limpiarFlete();
878 $scope.remito.flete = '0'; 881 $scope.remito.flete = '0';
879 $scope.remito.bomba = '0'; 882 $scope.remito.bomba = '0';
880 $scope.remito.precioCondicion = ''; 883 $scope.remito.precioCondicion = '';
881 $scope.articulosTabla = []; 884 $scope.articulosTabla = [];
882 $scope.remito.vendedor.nombre = ''; 885 $scope.remito.vendedor.nombre = '';
883 $scope.remito.cliente = {nombre: ''}; 886 $scope.remito.cliente = {nombre: ''};
884 $scope.remito.domicilio = {dom: ''}; 887 $scope.remito.domicilio = {dom: ''};
885 $scope.domiciliosCliente = []; 888 $scope.domiciliosCliente = [];
886 }; 889 };
887 890
888 $scope.resetFilter = function() { 891 $scope.resetFilter = function() {
889 $scope.articuloACargar = {}; 892 $scope.articuloACargar = {};
890 $scope.cargando = true; 893 $scope.cargando = true;
891 }; 894 };
892 //Recibe aviso si el teclado está en uso 895 //Recibe aviso si el teclado está en uso
893 $rootScope.$on('usarTeclado', function(event, data) { 896 $rootScope.$on('usarTeclado', function(event, data) {
894 if(data) { 897 if(data) {
895 $scope.mostrarTeclado = true; 898 $scope.mostrarTeclado = true;
896 return; 899 return;
897 } 900 }
898 $scope.mostrarTeclado = false; 901 $scope.mostrarTeclado = false;
899 }); 902 });
900 903
901 $scope.selectFocus = function($event) { 904 $scope.selectFocus = function($event) {
902 // Si el teclado esta en uso no selecciona el valor 905 // Si el teclado esta en uso no selecciona el valor
903 if($scope.mostrarTeclado) { 906 if($scope.mostrarTeclado) {
904 return; 907 return;
905 } 908 }
906 $event.target.select(); 909 $event.target.select();
907 }; 910 };
908 911
909 function addArrayCabecera(array) { 912 function addArrayCabecera(array) {
910 for(var i = 0; i < array.length; i++) { 913 for(var i = 0; i < array.length; i++) {
911 $scope.$broadcast('addCabecera',{ 914 $scope.$broadcast('addCabecera',{
912 label: array[i].label, 915 label: array[i].label,
913 valor: array[i].valor 916 valor: array[i].valor
914 }); 917 });
915 } 918 }
916 } 919 }
917 920
918 function rellenar(relleno, longitud) { 921 function rellenar(relleno, longitud) {
919 relleno = '' + relleno; 922 relleno = '' + relleno;
920 while (relleno.length < longitud) { 923 while (relleno.length < longitud) {
921 relleno = '0' + relleno; 924 relleno = '0' + relleno;
922 } 925 }
923 926
924 return relleno; 927 return relleno;
925 } 928 }
926 929
927 function varlidarRemitoFacturado() { 930 function varlidarRemitoFacturado() {
928 if($scope.remito.estado !== 5) { 931 if($scope.remito.estado !== 5) {
929 return true; 932 return true;
930 }else { 933 }else {
931 focaModalService.alert('No se puede editar un remito facturado'); 934 focaModalService.alert('No se puede editar un remito facturado');
932 return false(); 935 return false();
933 } 936 }
934 } 937 }
935 938
936 function salir() { 939 function salir() {
937 var confirmacion = false; 940 var confirmacion = false;
938 941
939 angular.forEach($scope.inicial, function(valor, key) { 942 angular.forEach($scope.inicial, function(valor, key) {
940 if (!angular.equals($scope[key], $scope.inicial[key])) { 943 if (!angular.equals($scope[key], $scope.inicial[key])) {
941 confirmacion = true; 944 confirmacion = true;
942 } 945 }
943 }); 946 });
944 947
945 if (confirmacion) { 948 if (confirmacion) {
946 focaModalService.confirm( 949 focaModalService.confirm(
947 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 950 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
948 ).then(function(data) { 951 ).then(function(data) {
949 if (data) { 952 if (data) {
950 $location.path('/'); 953 $location.path('/');
951 } 954 }
952 }); 955 });
953 } else { 956 } else {
954 $location.path('/'); 957 $location.path('/');
955 } 958 }
956 } 959 }
957 960
958 function enableObservaciones(val) { 961 function enableObservaciones(val) {
959 var boton = $scope.botonera.filter(function(botonObs) { 962 var boton = $scope.botonera.filter(function(botonObs) {
960 return botonObs.label === 'Observaciones'; 963 return botonObs.label === 'Observaciones';
961 }); 964 });
962 965
963 boton[0].disable = !val; 966 boton[0].disable = !val;
964 } 967 }
965 } 968 }