Commit be760b98e6ad410591f63d9b019a1a7c7a51dfa4

Authored by Jose Pinto
1 parent 5048ec50e2
Exists in master

ok idDomicilio

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