Commit ba7b7b0da1aa3e7788dcc452eb12220e9e8cb008

Authored by Luigi

Merge branch 'master' into 'develop'

Master

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