frmDocVenGiros.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using sage.ew.objetos;
10 using sage.ew.global;
11 using sage.ew.cliente;
12 using sage.ew.usuario;
13 using sage.ew.interficies;
14 using sage.ew.functions;
15 using sage.ew.ewbase.Clases;
16 
17 
18 namespace sage.ew.formul.Forms
19 {
23  public partial class frmDocVenGiros : FormDialog
24  {
25  #region PROPIEDADES PRIVADAS
26 
27 
31  private BindingList<LineaGiro> _Giros = null;
32 
33 
37  private dynamic _oDocumento;
38 
39 
43  private bool _lHera = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_hera"));
44 
45 
49  eTipoDocumentoGeneral _TipoDocumentoGeneral;
50 
51 
52  #endregion PROPIEDADES PRIVADAS
53 
54 
55  #region PROPIEDADES PÚBLICAS
56 
57 
61  public dynamic _Documento
62  {
63  get
64  {
65  return _oDocumento;
66  }
67  set
68  {
69  _oDocumento = value;
70 
71  // Ponemos a la pantalla el mismo tipo de documento general (ventas, compras) según el documento asociado.
72  //
73  this._TipoDocumentoGeneral = (eTipoDocumentoGeneral)_oDocumento._TipoDocumentoGeneral;
74 
75  _Refresh();
76  }
77  }
78 
79 
80  #endregion PROPIEDADES PÚBLICAS
81 
82 
83  #region CONSTRUCTOR
84 
85 
89  public frmDocVenGiros()
90  {
91  InitializeComponent();
92 
93  this._Pantalla = "ALB_FPAG";
94 
95  if (!this.DesignMode)
96  {
97  this.subscripcioEventos();
98  }
99 
100  return;
101  }
102 
103 
104  #endregion CONSTRUCTOR
105 
106 
107  #region MÉTODOS PRIVADOS
108 
109 
113  private void subscripcioEventos()
114  {
115  this.girosDocum._ManteGrid._DataSource_Row_Delete_Event += new objetos.UserControls.Mantegrid._DataSource_Row_Delete_Event_Handler(evento_girosMante__DataSource_Row_Delete_Event);
116  this.girosDocum._ManteGrid._DataSource_Row_New_Event += new objetos.UserControls.Mantegrid._DataSource_Row_New_Event_Handler(evento_girosMante__DataSource_Row_New_Event);
117 
118  return;
119  }
120 
121 
125  private void cancelarSubscripcioEventos()
126  {
127  this.girosDocum._ManteGrid._DataSource_Row_Delete_Event -= new objetos.UserControls.Mantegrid._DataSource_Row_Delete_Event_Handler(evento_girosMante__DataSource_Row_Delete_Event);
128  this.girosDocum._ManteGrid._DataSource_Row_New_Event -= new objetos.UserControls.Mantegrid._DataSource_Row_New_Event_Handler(evento_girosMante__DataSource_Row_New_Event);
129 
130  return;
131  }
132 
133 
138  private void evento_girosMante__DataSource_Row_New_Event(int tnInsertLinea)
139  {
140  int lnMaxNumGiro = 0;
141  int lnMaxGiro = 0;
142 
143  LineaGiro loLineaGiro = null;
144 
145  if (this._Giros.Count > 0)
146  {
147  lnMaxNumGiro = (from query in _Giros select query._NumGiro).Max();
148  lnMaxGiro = (from query in _Giros select query._Giro).Max();
149  loLineaGiro = new LineaGiro() { _NumGiro = lnMaxNumGiro + 1, _Giro = lnMaxGiro+30, _Porcentaje=0 };
150  }
151  else
152  {
153  loLineaGiro = new LineaGiro() { _NumGiro = 1, _Giro = 0, _Porcentaje = 100 };
154  }
155 
156  _Giros.Add(loLineaGiro);
157 
158  this.girosDocum._ManteGrid._Grid.DataSource = _Giros;
159 
160  return;
161  }
162 
163 
168  private void evento_girosMante__DataSource_Row_Delete_Event(DataGridViewRow trRowDelete)
169  {
170  if (this.girosDocum._ManteGrid._Grid.CurrentRow.Index >= 0)
171  {
172  this._Giros.RemoveAt(this.girosDocum._ManteGrid._Grid.CurrentRow.Index);
173  this.girosDocum._ManteGrid._Grid.DataSource = _Giros;
174  }
175 
176  return;
177  }
178 
179 
184  private void setGiros(BindingList<LineaGiro> girosDocumento)
185  {
186  _Giros = new BindingList<LineaGiro>();
187  int numGiro = 0;
188  foreach (LineaGiro loGiro in girosDocumento)
189  {
190  numGiro++;
191  _Giros.Add(new LineaGiro { _NumGiro = numGiro, _Giro = loGiro._Giro, _Porcentaje = loGiro._Porcentaje });
192  }
193 
194  BindingList<ILineaGiro> lstLineaGiro = new BindingList<ILineaGiro>();
195  foreach (ILineaGiro loGiro in this._Giros)
196  lstLineaGiro.Add(loGiro);
197 
198  girosDocum._LineasGiros = lstLineaGiro;
199 
200  girosDocum._ManteGrid._Grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
201 
202  girosDocum._CheckMeses.Checked = this._Documento._Cabecera._GirosMesesCompletos;
203 
204  return;
205  }
206 
207 
211  private void ajustes_Pantalla()
212  {
213  if (this._TipoDocumentoGeneral == eTipoDocumentoGeneral.Compras)
214  {
215  // Comentado con J.Suñé, en el caso de compras la visualizacion de nombre de banco y cuenta bancaria al final no acaba repercutiendo en nada en esta pantalla, no guarda nada en C_ALBCOM relacionado
216  // con el banco (caso contrario es en ventas que sí que llena el campo C_ALBVEN.BANC_CLI), lo hacemos invisibles. De sobrarnos el tiempo si que podríamos haber hecho el modificar el nombre
217  // de la propiedad _Cliente de txtCuentaBancaria, y hacerlo util para ventas y compras, pero no es el caso. Así que se decide eliminar visualmente estos dos controles por que no tienen
218  // trascendencia en esta pantalla al no guardar nada en la tabla que sea consecuencia de su manipulación.
219  //
220  this.cmbBancos.Visible = false;
221  this.txtCuentaBancaria.Visible = false;
222  this.ewLblBanco.Visible = false;
223  this.ewLblCuentaBancaria.Visible = false;
224 
225  this.girosDocum.Anchor = AnchorStyles.None;
226  this.Height -= (this.girosDocum.Top - this.ewLblBanco.Top);
227 
228  this.girosDocum.Top = this.ewLblBanco.Top;
229 
230  this.girosDocum.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
231 
232 
233  this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2;
234  this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2;
235  }
236 
237  return;
238  }
239 
240 
246  private void frmDocVenGiros_Load(object sender, EventArgs e)
247  {
248  if (this.DesignMode)
249  return;
250 
251  // Ajustes en pantalla caso de trabajar con documento de compras puesto que se ocultan algunos controles y se resituan otros.
252  //
253  this.ajustes_Pantalla();
254 
255  this._Refresh();
256 
257  if (this._Documento != null && this._Documento._EnUso || (this._lHera && this._Documento._Cabecera._Exportar != null)) //PE-100144
258  {
259  this._ReadOnly = true;
260  this.girosDocum._ReadOnly = true;
261  }
262 
263  if (this._TipoDocumentoGeneral == eTipoDocumentoGeneral.Ventas)
264  {
265  // PE-92757. Comprobar permiso "No modificar formas de pago en albaranes de venta"
266  if (this._NivelAcceso == _TiposAccesosPantalla.Completo)
267  {
268  if (Usuario._This._Opcesp("0039"))
269  {
270  // Bloqueamos la pantalla
271  this.Text = this.Text + " (Sólo lectura)";
272  this._ReadOnly = true;
273  this.girosDocum._ReadOnly = true;
274  }
275  }
276  }
277 
278  return;
279  }
280 
281 
285  private void btDocCancelar1_Click(object sender, EventArgs e)
286  {
287  this.DialogResult = DialogResult.Cancel;
288 
289  return;
290  }
291 
292 
296  private void btDocAceptar1_Click(object sender, EventArgs e)
297  {
298 
299  if (this._Giros.Count > 0)
300  {
301  bool llGirosPrc0 = false;
302  decimal lnPrcAcum = 0.0M;
303  foreach (LineaGiro loGiro in this._Giros)
304  {
305  if (loGiro._Porcentaje == 0)
306  {
307  llGirosPrc0 = true;
308  break;
309  }
310  lnPrcAcum += loGiro._Porcentaje;
311  }
312 
313  bool llOk = true;
314  string lcMensajeError = "";
315 
316  if (llGirosPrc0)
317  {
318  lcMensajeError = "Tiene días de giro con % reparto importe a cero. Tiene que eliminar los mismos, o asignar un porcentaje de reparto.";
319  llOk = false;
320  }
321  else
322  {
323  if (FUNCTIONS._Round(lnPrcAcum, 2) != 100)
324  {
325  lcMensajeError = "La suma de los porcentajes reparto importe de cada registro no corresponde al 100%. Ajuste los % de reparto importe.";
326  llOk = false;
327  }
328  }
329  if (!llOk)
330  {
331  FUNCTIONS._MessageBox(lcMensajeError, "Giros", MessageBoxButtons.OK, MessageBoxIcon.Stop);
332  this.DialogResult = DialogResult.None;
333  return;
334  }
335  }
336  else
337  {
338  // No se controlaba antes de hacer esta modificiación si vaciabamos la lista de giros.
339  //
340  //FUNCTIONS._MessageBox("Tiene que declarar por lo menos un giro.", "Giros", MessageBoxButtons.OK, MessageBoxIcon.Stop);
341  //this.DialogResult = DialogResult.None;
342  //return;
343  }
344 
345  if (this._TipoDocumentoGeneral == eTipoDocumentoGeneral.Ventas)
346  {
347  int lnBancCli = Convert.ToInt32(this.cmbBancos.SelectedValue);
348  _Documento._Cabecera._Banc_Cli = (lnBancCli==0 ? 1:lnBancCli); // PE-85300
349  }
350 
351  // Hacemos esto por que nos pueden haber cambiado los giros.
352  //
353  BindingList<LineaGiro> lstGirosNew = new BindingList<LineaGiro>();
354  BindingList<int> lstGirosAnt = new BindingList<int>();
355  foreach (LineaGiro loLineaGiro in this._Giros)
356  {
357  lstGirosNew.Add(new LineaGiro() { _NumGiro = loLineaGiro._NumGiro, _Giro = loLineaGiro._Giro, _Porcentaje = loLineaGiro._Porcentaje });
358  lstGirosAnt.Add(loLineaGiro._Giro);
359  }
360 
361  // Mientras no se elimine la propiedad _Giros se deben llevar las dos propiedades _Giros y _GirosPrc en paralelo.
362  //
363  _Documento._GirosPrc = lstGirosNew;
364  _Documento._Giros = lstGirosAnt;
365  this._Documento._Cabecera._GirosMesesCompletos = this.girosDocum._CheckMeses.Checked;
366  this.DialogResult = DialogResult.OK;
367 
368  return;
369  }
370 
371 
375  private void listBancos_SelectedIndexChanged(object sender, EventArgs e)
376  {
377  if (this.DesignMode)
378  return;
379 
380  txtCuentaBancaria._Banco = Convert.ToString(cmbBancos.SelectedValue);
381 
382  return;
383  }
384 
385 
389  private void cmbBancos_SelectedIndexChanged(object sender, EventArgs e)
390  {
391  if (this.DesignMode)
392  return;
393 
394  txtCuentaBancaria._Banco = Convert.ToString(cmbBancos.SelectedValue);
395 
396  return;
397  }
398 
399 
400  #endregion MÉTODOS PRIVADOS
401 
402 
403  #region MÉTODOS PROTECTED OVERRIDE
404 
405 
410  protected override void OnClosing(CancelEventArgs e)
411  {
412  this.cancelarSubscripcioEventos();
413 
414  base.OnClosing(e);
415 
416  return;
417  }
418 
419 
420  #endregion MÉTODOS PROTECTED OVERRIDE
421 
422 
423  #region MÉTODOS PÚBLICOS
424 
425 
429  public void _Refresh()
430  {
431  Dictionary<string, object> obj;
432 
433  if (_Documento != null)
434  {
435  dynamic _oCuenta = null;
436  string lcCodigoCuenta = string.Empty;
437 
438  switch (this._TipoDocumentoGeneral)
439  {
440  case eTipoDocumentoGeneral.Ventas:
441  this.ewLblCuenta.Text = "Cliente";
442  _oCuenta = _Documento._Cabecera._oCliente;
443 
444  if (_lHera) //PE-84762: si es hera obtenemos el código de cliente ERP para mostrar
445  lcCodigoCuenta = (new Cliente(_oCuenta._Codigo))._Codigo_Equivalente_ERP();
446  else
447  lcCodigoCuenta = _oCuenta._Codigo;
448  break;
449 
450  case eTipoDocumentoGeneral.Compras:
451  this.ewLblCuenta.Text = "Proveedor";
452  _oCuenta = _Documento._Cabecera._oProveedor;
453  lcCodigoCuenta = _oCuenta._Codigo;
454  break;
455  }
456 
457  _oCuenta._Load();
458 
459  this.txtCuenta.Text = String.Format("{0} - {1}", lcCodigoCuenta, _oCuenta._Nombre);
460  this.txtCuenta.ReadOnly = true;
461 
462 
463  setGiros(_Documento._GirosPrc);
464 
465  if (this._TipoDocumentoGeneral == eTipoDocumentoGeneral.Ventas)
466  {
467  txtCuentaBancaria._Cliente = _Documento._Cabecera._oCliente;
468 
469  cmbBancos.ValueMember = "CODIGO";
470  cmbBancos.DisplayMember = "BANCO";
471  cmbBancos.DataSource = _oCuenta._Bancos();
472 
473  obj = _oCuenta._Banco_Predeterminado();
474  if (obj != null)
475  {
476  //PE-103867: Comprobar si ya hay un Banc_Cli en la cabecera y seleccionar este
477  if (_Documento._Cabecera._Banc_Cli != 0)
478  cmbBancos.SelectedValue = _Documento._Cabecera._Banc_Cli;
479  else
480  cmbBancos.SelectedValue = Convert.ToString(obj["codigo"]);
481 
482  txtCuentaBancaria._Banco = Convert.ToString(cmbBancos.SelectedValue);
483  }
484  }
485  }
486 
487  return;
488  }
489 
490 
491  #endregion MÉTODOS PÚBLICOS
492  }
493 }
int _NumGiro
Número de giro, campo virtual, 1, 2, 3, etc. No se graba en base de datos, será un correlativo que se...
Definition: LineaGiro.cs:18
Clase de negocio para visualizar los giros.
Definition: LineaGiro.cs:12
static sage.ew.usuario.Usuario _This
Instancia estática del objeto usuario con los datos del usuario actual (wc_usuario) ...
Definition: clsUsuario.cs:341
_ReadOnly
_ReadOnly
Definition: clsPerfiles.cs:671
void _Refresh()
Refrescar los datos del formulario
decimal _Porcentaje
Porcentaje del importe de la factura a aplicar en el giro.
Definition: LineaGiro.cs:30
override void OnClosing(CancelEventArgs e)
Cierre del formulario
int _Giro
Días de giro
Definition: LineaGiro.cs:24
eTipoDocumentoGeneral
Enumeración pública para definir las diferentes categorias que tenemos de documentos (ventas...
Definition: General.cs:13
_TiposAccesosPantalla
Tipos de accesos a las pantallas
Definition: clsFormul.cs:338
Clase FormDialog basada en FormBase
Definition: FormDialog.cs:17
Interface para usar en el usercontrol de giros que aparece en el mantenimiento de clientes...
Definition: ILineaGiro.cs:14
bool _Opcesp(string tcCodigo)
Método que nos devuelve "true" en caso que el usuario actual tenga acceso a la opción especial con có...
Definition: clsUsuario.cs:1521
Clase formulario giros documento utilizado en albarán de venta y en albarán de compra.
Definición de la clase Usuario
Definition: clsUsuario.cs:113