Commit a3433aed55f81cfdf310f64c7ca4e3e61282fbe2

Authored by Jose Pinto
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master

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