Commit b24e934250b10a49f87dbaf953ca8545ac46f828

Authored by Eric
1 parent 8f5686788e
Exists in master

codigo innecesario

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