AsistenteTiposIVA.cs
1 using sage.ew.db;
2 using sage.ew.contabilidad;
3 using sage.ew.formul.Classes;
4 using sage.ew.functions;
5 using sage.ew.global;
6 using sage.ew.objetos;
7 using System;
8 using System.Collections.Generic;
9 using System.ComponentModel;
10 using System.Data;
11 using System.Linq;
12 using System.Text;
13 using System.Threading;
14 using System.Windows.Forms;
15 
16 namespace sage.ew.articulo.Clases
17 {
21  public class DatosIva
22  {
26  public string _IvaRep = Convert.ToString(EW_GLOBAL._GetVariable("wc_IvaRep", "477"));
30  public string _IvaSop = Convert.ToString(EW_GLOBAL._GetVariable("wc_IvaSop", "472"));
34  public string _IvaRecSop = Convert.ToString(EW_GLOBAL._GetVariable("wc_recsop", "472"));
38  public string _IvaRecRep = Convert.ToString(EW_GLOBAL._GetVariable("wc_recrep", "477"));
42  public string _IvaPendSop = Convert.ToString(EW_GLOBAL._GetVariable("wc_pendedsop", ""));
46  public string _IvaPendRep = Convert.ToString(EW_GLOBAL._GetVariable("wc_pendevrep", ""));
50  public string _IvaRecPendSop = Convert.ToString(EW_GLOBAL._GetVariable("wc_recsopcdev", ""));
54  public string _IvaRecPendRep = Convert.ToString(EW_GLOBAL._GetVariable("wc_recrepcdev", ""));
58  public string _IvaProrrataSop = Convert.ToString(EW_GLOBAL._GetVariable("wc_prtivsopnd", ""));
62  public string _IvaProrrataPendSop = Convert.ToString(EW_GLOBAL._GetVariable("wc_prtivsndpd", ""));
63 
67  public string _IvaRep3 = Convert.ToString(EW_GLOBAL._GetVariable("wc_IvaRep", "477")).Substring(0, 3);
71  public string _IvaSop3 = Convert.ToString(EW_GLOBAL._GetVariable("wc_IvaSop", "472")).Substring(0, 3);
75  public string _IvaRecSop3 = Convert.ToString(EW_GLOBAL._GetVariable("wc_recsop", "472")).Substring(0, 3);
79  public string _IvaRecRep3 = Convert.ToString(EW_GLOBAL._GetVariable("wc_recrep", "477")).Substring(0, 3);
83  public string _IvaPendSop3 = Convert.ToString(EW_GLOBAL._GetVariable("wc_pendedsop", "")).Substring(0, 3);
87  public string _IvaPendRep3 = Convert.ToString(EW_GLOBAL._GetVariable("wc_pendevrep", "")).Substring(0, 3);
91  public string _IvaRecPendSop3 = Convert.ToString(EW_GLOBAL._GetVariable("wc_recsopcdev", "")).Substring(0, 3);
95  public string _IvaRecPendRep3 = Convert.ToString(EW_GLOBAL._GetVariable("wc_recrepcdev", "")).Substring(0, 3);
99  public string _IvaProrrataSop3 = Convert.ToString(EW_GLOBAL._GetVariable("wc_prtivsopnd", "")).Substring(0, 3);
103  public string _IvaProrrataPendSop3 = Convert.ToString(EW_GLOBAL._GetVariable("wc_prtivsndpd", "")).Substring(0, 3);
104 
108  public static Int32 _LenCodigo = DB.SQLAnchuraCampo("GESTION", "TIPO_IVA", "CODIGO");
109 
113  public static Int32 _LenNombre = DB.SQLAnchuraCampo("GESTION", "TIPO_IVA", "NOMBRE");
114 
118  public enum TipoImpuesto
119  {
123  IVA = 0,
127  IGIC = 1,
131  NO_SELECCIONADO = 99
132  }
133 
137  public enum TipoCuenta
138  {
142  [Description("soportado")]
143  SOPORTADO,
147  [Description("repercutido")]
148  REPERCUTIDO,
152  [Description("recargo soportado")]
153  RECARGO_SOPORTADO,
157  [Description("recargo repercutido")]
158  RECARGO_REPERCUTIDO,
162  [Description("soportado pendiente de devengo")]
163  PTE_SOPORTADO,
167  [Description("repercutido pendiente de devengo")]
168  PTE_REPERCUTIDO,
172  [Description("recargo soportado pendiente de devengo")]
173  PTE_RECARGO_SOPORTADO,
177  [Description("recargo repercutido pendiente de devengo")]
178  PTE_RECARGO_REPERCUTIDO,
182  [Description("soportado")]
183  PRORRATA_SOPORTADO,
187  [Description("soportado pendiente de devengo")]
188  PTE_PRORRATA_SOPORTADO
189  }
190 
191  private string _cCodigoPropuesto;
192  private string _cCodigo;
193  private string _cCodigoTipoImp;
194  private string _cNombre;
195  private string _cNombreDefecto;
196  private static DataTable _oTiposImpuesto = null;
197  private TipoIVA _oTipoIva = null;
198 
199  private Decimal _nPorcentaje;
200  private Decimal _nRecargo;
201  private TipoIVA.TipoImpuesto _oTipo;
202  private bool _bDeducible = true;
203  private bool _bAplicaRecargo = false;
204  private bool _bIGICImplicito = false;
205  private bool _bIVAServicios = false;
206  private bool _bNoSujeto = false;
207  private bool _bIGIC0 = false;
208  private bool _bBienesInversion = false;
209 
210  //Cuentas
211  private string _cCuentaSoportado;
212  private string _cCuentaRepercutido;
213  private string _cCuentaRecargoSoportado;
214  private string _cCuentaRecargoRepercutido;
215  //Criterio caja
216  private string _cCuentaSoportadoPte;
217  private string _cCuentaRepercutidoPte;
218  private string _cCuentaRecargoSoportadoPte;
219  private string _cCuentaRecargoRepercutidoPte;
220  //Prorrata
221  private string _cCuentaSoportadoProrrata;
222  private string _cCuentaSoportadoProrrataPte;
223  //Cuenta propuestas
224  private string _cCuentaPropuestaSoportado;
225  private string _cCuentaPropuestaRepercutido;
226  private string _cCuentaPropuestaRecargoSoportado;
227  private string _cCuentaPropuestaRecargoRepercutido;
228  private string _cCuentaPropuestaSoportadoPte;
229  private string _cCuentaPropuestaRepercutidoPte;
230  private string _cCuentaPropuestaRecargoSoportadoPte;
231  private string _cCuentaPropuestaRecargoRepercutidoPte;
232  private string _cCuentaPropuestaSoportadoProrrata;
233  private string _cCuentaPropuestaSoportadoProrrataPte;
234 
235  private List<string> _oCuentasPropuestas = new List<string>();
236  private string _cErrorMessage;
237  private string _cAditionalMessage;
238 
242  private Boolean _bCriterioCaja = FUNCTIONS._UtilizaCriterioCaja();
243 
244  private BackgroundWorker _oWorker;
245 
249  public String _DescripcionTipoImp
250  {
251  get
252  {
253  DataRow loRow = _ObtenerTipoImp();
254 
255  if (loRow is DataRow)
256  {
257  _cCodigoTipoImp = Convert.ToString(loRow["CODIGO"]);
258 
259  return Convert.ToString(loRow["DESCRIP"]);
260  }
261  else
262  {
263  _cCodigoTipoImp = "0";
264 
265  return String.Empty;
266  }
267  }
268  }
269 
273  public TipoIVA _TipoIva
274  {
275  get
276  {
277  if (_oTipoIva == null) _oTipoIva = new TipoIVA();
278  return _oTipoIva;
279  }
280  set
281  {
282  _oTipoIva = value;
283  }
284  }
285 
289  public String _CodigoTipoImp
290  {
291  get
292  {
293  return _cCodigoTipoImp;
294  }
295  set
296  {
297  if (_cCodigoTipoImp != value)
298  {
299  _cCodigoTipoImp = value;
300 
301  List<DataRow> loList = (from loRow in _TiposImpuesto.AsEnumerable()
302  where Convert.ToString(loRow["CODIGO"]) == _cCodigoTipoImp
303  select loRow).ToList();
304 
305  if (loList.Count > 0)
306  {
307  _Porcentaje = Convert.ToDecimal(loList.First()["PORC_IMP"]);
308  _Recargo = Convert.ToDecimal(loList.First()["PORC_REC"]);
309  _IGICImplicito = Convert.ToBoolean(loList.First()["IGIC_IMPLI"]);
310  _NoSujeto = Convert.ToBoolean(loList.First()["NOSUJETO"]);
311  if (this._Tipo == TipoIVA.TipoImpuesto.IVA)
312  {
313  _IVA0 = Convert.ToBoolean(loList.First()["CERO"]);
314  }
315  else
316  {
317  _IGIC0 = Convert.ToBoolean(loList.First()["CERO"]);
318  }
319 
320  }
321  else
322  {
323  _Porcentaje = _Recargo = 0;
324  _IGICImplicito = _NoSujeto = false;
325  }
326  }
327  }
328  }
329 
333  public String _Codigo
334  {
335  get
336  {
337  if (String.IsNullOrEmpty(_cCodigo))
338  {
339  _cCodigo = _CodigoPropuesto;
340  }
341  return _cCodigo;
342  }
343  set
344  {
345  _cCodigo = value.PadLeft(_LenCodigo, '0');
346  }
347  }
348 
352  public String _CodigoPropuesto
353  {
354  get
355  {
356  if (String.IsNullOrEmpty(_cCodigoPropuesto))
357  {
358  _cCodigoPropuesto = _ObtenerCodigo();
359  }
360  return _cCodigoPropuesto;
361  }
362  }
363 
367  public String _Nombre
368  {
369  get
370  {
371  if (String.IsNullOrEmpty(_cNombre)) _cNombre = _NombreXDefecto;
372  return _cNombre;
373  }
374  set
375  {
376  _cNombre = value;
377  if (String.IsNullOrEmpty(_cNombre.Trim())) _cNombreDefecto = "";
378  }
379  }
380 
384  private String _NombreXDefecto
385  {
386  get
387  {
388  if(String.IsNullOrEmpty(_cNombreDefecto)) _cNombreDefecto = String.Format("{0} {1}% {2}", _oTipo, _Porcentaje, _AplicaRecargo && _Recargo > 0 ? String.Format("({0}%)", _Recargo) : "");
389  return _cNombreDefecto;
390  }
391  }
392 
396  public void _RefreshNombre()
397  {
398  if(_cNombre == _cNombreDefecto) _cNombreDefecto = _cNombre = "";
399  }
400 
404  public Decimal _Porcentaje
405  {
406  get
407  {
408  return _nPorcentaje;
409  }
410  set
411  {
412  _nPorcentaje = value;
413  }
414  }
415 
419  public Decimal _Recargo
420  {
421  get
422  {
423  return _AplicaRecargo ? _nRecargo : 0;
424  }
425  set
426  {
427  _nRecargo = value;
428  }
429  }
430 
434  public TipoIVA.TipoImpuesto _Tipo
435  {
436  get
437  {
438  return _oTipo;
439  }
440  set
441  {
442  _oTipo = value;
443  }
444  }
445 
449  public Boolean _Deducible
450  {
451  get
452  {
453  return _bDeducible;
454  }
455  set
456  {
457  _bDeducible = value;
458  }
459  }
460 
464  public Boolean _Servicios
465  {
466  get
467  {
468  return _bIVAServicios;
469  }
470  set
471  {
472  _bIVAServicios = value;
473  }
474  }
475 
479  public Boolean _NoSujeto
480  {
481  get
482  {
483  return _bNoSujeto;
484  }
485  set
486  {
487  _bNoSujeto = value;
488  }
489  }
490 
494  public Boolean _BienesInversion
495  {
496  get
497  {
498  return _bBienesInversion;
499  }
500  set
501  {
502  _bBienesInversion = value;
503  }
504  }
505 
523  public Boolean _IGIC0
524  {
525  get
526  {
527  return _bIGIC0;
528  }
529  set
530  {
531  _bIGIC0 = value;
532  }
533  }
534 
535 
553  public Boolean _IVA0
554  {
555  get
556  {
557  return _bIGIC0;
558  }
559  set
560  {
561  _bIGIC0 = value;
562  }
563  }
564 
568  public static DataTable _TiposImpuesto
569  {
570  get
571  {
572  if (_oTiposImpuesto == null)
573  {
574  String lcSql;
575 
576  _oTiposImpuesto = new DataTable();
577  lcSql = String.Format("SELECT '(' + CONVERT(VARCHAR, PORC_IMP) + ') ' + DESCRIP as TITULO, * FROM {0} WHERE ACTIVO = 1 ", DB.SQLDatabase("COMUNES", "TIPOSIMP"));
578  DB.SQLExec(lcSql, ref _oTiposImpuesto);
579 
580  List<DataRow> loListImpli = (from loRow in _oTiposImpuesto.AsEnumerable()
581  where Convert.ToBoolean(loRow["IGIC_IMPLI"])
582  select loRow).ToList();
583 
584  loListImpli.ForEach(r => r["TITULO"] = String.Format("{0} - Implícito", Convert.ToString(r["TITULO"]).Trim()));
585  }
586  return _oTiposImpuesto;
587  }
588  }
589 
593  public Boolean _IsPersonalizado
594  {
595  get
596  {
597  return _cCodigoTipoImp == "0";
598  }
599  }
600 
604  public Boolean _AplicaRecargo
605  {
606  get
607  {
608  return _Tipo == TipoIVA.TipoImpuesto.IVA ? _bAplicaRecargo : false;
609  }
610  set
611  {
612  _bAplicaRecargo = value;
613  }
614  }
615 
619  public String _CuentaSoportado
620  {
621  get
622  {
623  if (String.IsNullOrEmpty(_cCuentaSoportado))
624  {
625  _cCuentaSoportado = _CuentaPropuestaSoportado;
626  }
627  return _cCuentaSoportado;
628  }
629  set
630  {
631  _cCuentaSoportado = value.Trim();
632  }
633  }
634 
638  public String _CuentaPropuestaSoportado
639  {
640  get
641  {
642  if (String.IsNullOrEmpty(_cCuentaPropuestaSoportado))
643  {
644  _cCuentaPropuestaSoportado = _ObtenerCuenta(_IvaSop);
645  }
646  return _cCuentaPropuestaSoportado;
647  }
648  }
649 
653  public String _CuentaRepercutido
654  {
655  get
656  {
657  if (String.IsNullOrEmpty(_cCuentaRepercutido))
658  {
659  _cCuentaRepercutido = _CuentaPropuestaRepercutido;
660  }
661  return _cCuentaRepercutido;
662  }
663  set
664  {
665  _cCuentaRepercutido = value.Trim();
666  }
667  }
668 
672  public String _CuentaPropuestaRepercutido
673  {
674  get
675  {
676  if (String.IsNullOrEmpty(_cCuentaPropuestaRepercutido))
677  {
678  _cCuentaPropuestaRepercutido = _ObtenerCuenta(_IvaRep);
679  }
680  return _cCuentaPropuestaRepercutido;
681  }
682  }
683 
687  public String _CuentaRecargoRepercutido
688  {
689  get
690  {
691  if (String.IsNullOrEmpty(_cCuentaRecargoRepercutido))
692  {
693  _cCuentaRecargoRepercutido = _CuentaPropuestaRecargoRepercutido;
694  }
695  return _cCuentaRecargoRepercutido;
696  }
697  set
698  {
699  _cCuentaRecargoRepercutido = value.Trim();
700  }
701  }
702 
706  public String _CuentaPropuestaRecargoRepercutido
707  {
708  get
709  {
710  if (String.IsNullOrEmpty(_cCuentaPropuestaRecargoRepercutido))
711  {
712  _cCuentaPropuestaRecargoRepercutido = _ObtenerCuenta(_IvaRecRep);
713  }
714  return _cCuentaPropuestaRecargoRepercutido;
715  }
716  }
717 
721  public String _CuentaRecargoSoportado
722  {
723  get
724  {
725  if (String.IsNullOrEmpty(_cCuentaRecargoSoportado))
726  {
727  _cCuentaRecargoSoportado = _CuentaPropuestaRecargoSoportado;
728  }
729 
730  return _cCuentaRecargoSoportado;
731  }
732  set
733  {
734  _cCuentaRecargoSoportado = value.Trim();
735  }
736  }
737 
741  public String _CuentaPropuestaRecargoSoportado
742  {
743  get
744  {
745  if (String.IsNullOrEmpty(_cCuentaPropuestaRecargoSoportado))
746  {
747  _cCuentaPropuestaRecargoSoportado = _ObtenerCuenta(_IvaRecSop);
748  }
749  return _cCuentaPropuestaRecargoSoportado;
750  }
751  }
752 
756  public String _CuentaSoportadoPte
757  {
758  get
759  {
760  if (String.IsNullOrEmpty(_cCuentaSoportadoPte))
761  {
762  _cCuentaSoportadoPte = _CuentaPropuestaSoportadoPte;
763  }
764  return _cCuentaSoportadoPte;
765  }
766  set
767  {
768  _cCuentaSoportadoPte = value.Trim();
769  }
770  }
771 
775  public String _CuentaPropuestaSoportadoPte
776  {
777  get
778  {
779  if (String.IsNullOrEmpty(_cCuentaPropuestaSoportadoPte))
780  {
781  _cCuentaPropuestaSoportadoPte = _ObtenerCuenta(_IvaPendSop);
782  }
783  return _cCuentaPropuestaSoportadoPte;
784  }
785  }
786 
790  public String _CuentaRepercutidoPte
791  {
792  get
793  {
794  if (String.IsNullOrEmpty(_cCuentaRepercutidoPte))
795  {
796  _cCuentaRepercutidoPte = _CuentaPropuestaRepercutidoPte;
797  }
798  return _cCuentaRepercutidoPte;
799  }
800  set
801  {
802  _cCuentaRepercutidoPte = value.Trim();
803  }
804  }
805 
809  public String _CuentaPropuestaRepercutidoPte
810  {
811  get
812  {
813  if (String.IsNullOrEmpty(_cCuentaPropuestaRepercutidoPte))
814  {
815  _cCuentaPropuestaRepercutidoPte = _ObtenerCuenta(_IvaRecPendRep);
816  }
817  return _cCuentaPropuestaRepercutidoPte;
818  }
819  }
820 
824  public String _CuentaRecargoRepercutidoPte
825  {
826  get
827  {
828  if (String.IsNullOrEmpty(_cCuentaRecargoRepercutidoPte))
829  {
830  _cCuentaRecargoRepercutidoPte = _CuentaPropuestaRecargoRepercutidoPte;
831  }
832  return _cCuentaRecargoRepercutidoPte;
833  }
834  set
835  {
836  _cCuentaRecargoRepercutidoPte = value.Trim();
837  }
838  }
839 
843  public String _CuentaPropuestaRecargoRepercutidoPte
844  {
845  get
846  {
847  if (String.IsNullOrEmpty(_cCuentaPropuestaRecargoRepercutidoPte))
848  {
849  _cCuentaPropuestaRecargoRepercutidoPte = _ObtenerCuenta(_IvaRecPendRep);
850  }
851  return _cCuentaPropuestaRecargoRepercutidoPte;
852  }
853  }
854 
858  public String _CuentaRecargoSoportadoPte
859  {
860  get
861  {
862  if (String.IsNullOrEmpty(_cCuentaRecargoSoportadoPte))
863  {
864  _cCuentaRecargoSoportadoPte = _CuentaPropuestaRecargoSoportadoPte;
865  }
866 
867  return _cCuentaRecargoSoportadoPte;
868  }
869  set
870  {
871  _cCuentaRecargoSoportadoPte = value.Trim();
872  }
873  }
874 
878  public String _CuentaPropuestaRecargoSoportadoPte
879  {
880  get
881  {
882  if (String.IsNullOrEmpty(_cCuentaPropuestaRecargoSoportadoPte))
883  {
884  _cCuentaPropuestaRecargoSoportadoPte = _ObtenerCuenta(_IvaRecPendSop);
885  }
886  return _cCuentaPropuestaRecargoSoportadoPte;
887  }
888  }
889 
893  public String _CuentaSoportadoProrrata
894  {
895  get
896  {
897  if (String.IsNullOrEmpty(_cCuentaSoportadoProrrata))
898  {
899  _cCuentaSoportadoProrrata = _CuentaPropuestaSoportadoProrrata;
900  }
901  return _cCuentaSoportadoProrrata;
902  }
903  set
904  {
905  _cCuentaSoportadoProrrata = value.Trim();
906  }
907  }
908 
912  public String _CuentaPropuestaSoportadoProrrata
913  {
914  get
915  {
916  if (String.IsNullOrEmpty(_cCuentaPropuestaSoportadoProrrata))
917  {
918  _cCuentaPropuestaSoportadoProrrata = _ObtenerCuenta(_IvaProrrataSop);
919  }
920  return _cCuentaPropuestaSoportadoProrrata;
921  }
922  }
923 
927  public String _CuentaSoportadoProrrataPte
928  {
929  get
930  {
931  if (String.IsNullOrEmpty(_cCuentaSoportadoProrrataPte))
932  {
933  _cCuentaSoportadoProrrataPte = _CuentaPropuestaSoportadoProrrataPte;
934  }
935  return _cCuentaSoportadoProrrataPte;
936  }
937  set
938  {
939  _cCuentaSoportadoProrrataPte = value.Trim();
940  }
941  }
942 
946  public String _CuentaPropuestaSoportadoProrrataPte
947  {
948  get
949  {
950  if (String.IsNullOrEmpty(_cCuentaPropuestaSoportadoProrrataPte))
951  {
952  _cCuentaPropuestaSoportadoProrrataPte = _ObtenerCuenta(_IvaProrrataPendSop);
953  }
954  return _cCuentaPropuestaSoportadoProrrataPte;
955  }
956  }
957 
961  public String _ErroMessage
962  {
963  get
964  {
965  return _cErrorMessage;
966  }
967  private set
968  {
969  _cErrorMessage = value;
970  }
971  }
972 
976  public Boolean _Prorrata
977  {
978  get
979  {
980  return Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_prorrata_aplicar"));
981  }
982  }
983 
987  public Boolean _IGICImplicito
988  {
989  get
990  {
991  return _bIGICImplicito;
992  }
993  set
994  {
995  _bIGICImplicito = value;
996  }
997  }
998 
1002  public Boolean _CriterioCaja
1003  {
1004  get
1005  {
1006  return _bCriterioCaja;
1007  }
1008  }
1009 
1010  private String _ObtenerCuenta(TipoCuenta toTipoCuenta)
1011  {
1012  String tcCuenta;
1013 
1014  switch (toTipoCuenta)
1015  {
1016  case TipoCuenta.SOPORTADO:
1017  tcCuenta = _IvaSop;
1018  break;
1019  case TipoCuenta.REPERCUTIDO:
1020  tcCuenta = _IvaRep;
1021  break;
1022  case TipoCuenta.RECARGO_SOPORTADO:
1023  tcCuenta = _IvaRecSop;
1024  break;
1025  case TipoCuenta.RECARGO_REPERCUTIDO:
1026  tcCuenta = _IvaRecRep;
1027  break;
1028  case TipoCuenta.PTE_SOPORTADO:
1029  tcCuenta = _IvaPendSop;
1030  break;
1031  case TipoCuenta.PTE_REPERCUTIDO:
1032  tcCuenta = _IvaPendRep;
1033  break;
1034  case TipoCuenta.PTE_RECARGO_SOPORTADO:
1035  tcCuenta = _IvaRecPendSop;
1036  break;
1037  case TipoCuenta.PTE_RECARGO_REPERCUTIDO:
1038  tcCuenta = _IvaRecPendSop;
1039  break;
1040  case TipoCuenta.PRORRATA_SOPORTADO:
1041  tcCuenta = _IvaProrrataSop;
1042  break;
1043  case TipoCuenta.PTE_PRORRATA_SOPORTADO:
1044  tcCuenta = _IvaProrrataPendSop;
1045  break;
1046  default:
1047  tcCuenta = "";
1048  break;
1049  }
1050 
1051  return _ObtenerCuenta(tcCuenta);
1052  }
1053 
1054  private String _ObtenerCuenta(String tcCuenta)
1055  {
1056  String lcSql;
1057  DataTable loDt = new DataTable();
1058  Boolean lbAdd = true;
1059 
1060  lcSql = String.Format("SELECT CODIGO as CODIGO FROM {0} WHERE LEFT(CODIGO, 3 ) = {1} ", DB.SQLDatabase("GESTION", "CUENTAS"), DB.SQLString(tcCuenta.Substring(0, 3)));
1061  DB.SQLExec(lcSql, ref loDt);
1062 
1063  while (lbAdd)
1064  {
1065  tcCuenta = Convert.ToString(Convert.ToInt64(tcCuenta) + 1);
1066 
1067  List<String> loList = (from loRow in loDt.AsEnumerable()
1068  where Convert.ToString(loRow["CODIGO"]).Trim() == tcCuenta.Trim()
1069  select Convert.ToString(loRow["CODIGO"])).ToList();
1070 
1071  if (loList.Count == 0)
1072  {
1073  loList = (from lcCuenta in _oCuentasPropuestas
1074  where lcCuenta.Trim() == tcCuenta.Trim()
1075  select lcCuenta).ToList();
1076 
1077  if (loList.Count == 0)
1078  {
1079  _oCuentasPropuestas.Add(tcCuenta.Trim());
1080  lbAdd = false;
1081  }
1082  }
1083  }
1084 
1085  return tcCuenta;
1086  }
1087 
1091  public BackgroundWorker _BackgroundWorker
1092  {
1093  get
1094  {
1095  return _oWorker;
1096  }
1097  set
1098  {
1099  _oWorker = value;
1100  }
1101  }
1102 
1107  public Boolean _Finalizar()
1108  {
1109  Int32 lnContMax = 3;
1110  Int32 lnContProcess = 0;
1111 
1112  if (_Prorrata ) lnContMax = lnContMax + (_CriterioCaja ? 2 : 1);
1113  if (_CriterioCaja) lnContMax = lnContMax + 2;
1114  if (_AplicaRecargo && _Recargo > 0) lnContMax = lnContMax + (_CriterioCaja ? 4 : 2);
1115 
1116  _cErrorMessage = "";
1117 
1118  _SetProcess(ref lnContProcess, ref lnContMax, "Creando cuentas contables");
1119 
1120  try
1121  {
1122  if (_CuentaSoportado == _CuentaPropuestaSoportado)
1123  {
1124  if (!_CreaCuenta(ref _cCuentaSoportado, ref lnContProcess, lnContMax, TipoCuenta.SOPORTADO))
1125  {
1126  throw new Exception(String.Format("Se ha producido un problema al crear la cuenta de {0}", TipoCuenta.SOPORTADO.__GetDescription()));
1127  }
1128  }
1129 
1130  if (_CuentaRepercutido == _CuentaPropuestaRepercutido)
1131  {
1132  if(!_CreaCuenta(ref _cCuentaRepercutido, ref lnContProcess, lnContMax, TipoCuenta.REPERCUTIDO))
1133  {
1134  throw new Exception(String.Format("Se ha producido un problema al crear la cuenta de {0}", TipoCuenta.REPERCUTIDO.__GetDescription()));
1135  }
1136  }
1137 
1138  //Cuentas de recargo
1139  if (_AplicaRecargo && _Recargo > 0)
1140  {
1141  if (_CuentaRecargoSoportado == _CuentaPropuestaRecargoSoportado)
1142  {
1143  if (!_CreaCuenta(ref _cCuentaRecargoSoportado, ref lnContProcess, lnContMax, TipoCuenta.RECARGO_SOPORTADO))
1144  {
1145  throw new Exception(String.Format("Se ha producido un problema al crear la cuenta de {0}", TipoCuenta.RECARGO_SOPORTADO.__GetDescription()));
1146  }
1147  }
1148 
1149  if (_CuentaRecargoRepercutido == _CuentaPropuestaRecargoRepercutido)
1150  {
1151  if (!_CreaCuenta(ref _cCuentaRecargoRepercutido, ref lnContProcess, lnContMax, TipoCuenta.RECARGO_REPERCUTIDO))
1152  {
1153  throw new Exception(String.Format("Se ha producido un problema al crear la cuenta de {0}", TipoCuenta.RECARGO_REPERCUTIDO.__GetDescription()));
1154  }
1155  }
1156  }
1157 
1158  // Cuentas de criterio de caja
1159  if (_CriterioCaja)
1160  {
1161  if (_CuentaSoportadoPte == _CuentaPropuestaSoportadoPte)
1162  {
1163  if (!_CreaCuenta(ref _cCuentaSoportadoPte, ref lnContProcess, lnContMax, TipoCuenta.PTE_SOPORTADO))
1164  {
1165  throw new Exception(String.Format("Se ha producido un problema al crear la cuenta de {0}", TipoCuenta.PTE_SOPORTADO.__GetDescription()));
1166  }
1167  }
1168 
1169  if (_CuentaRepercutidoPte == _CuentaPropuestaRepercutidoPte)
1170  {
1171  if(!_CreaCuenta(ref _cCuentaRepercutidoPte, ref lnContProcess, lnContMax, TipoCuenta.PTE_REPERCUTIDO))
1172  {
1173  throw new Exception(String.Format("Se ha producido un problema al crear la cuenta de {0}", TipoCuenta.PTE_REPERCUTIDO.__GetDescription()));
1174  }
1175  }
1176 
1177  //Cuentas de recargo
1178  if (_AplicaRecargo && _Recargo > 0)
1179  {
1180  if (_CuentaRecargoSoportadoPte == _CuentaPropuestaRecargoSoportadoPte)
1181  {
1182  if(!_CreaCuenta(ref _cCuentaRecargoSoportadoPte, ref lnContProcess, lnContMax, TipoCuenta.PTE_RECARGO_SOPORTADO))
1183  {
1184  throw new Exception(String.Format("Se ha producido un problema al crear la cuenta de {0}", TipoCuenta.PTE_RECARGO_SOPORTADO.__GetDescription()));
1185  }
1186  }
1187 
1188  if (_CuentaRecargoRepercutidoPte == _CuentaPropuestaRecargoRepercutidoPte)
1189  {
1190  if(!_CreaCuenta(ref _cCuentaRecargoRepercutidoPte, ref lnContProcess, lnContMax, TipoCuenta.PTE_RECARGO_REPERCUTIDO))
1191  {
1192  throw new Exception(String.Format("Se ha producido un problema al crear la cuenta de {0}", TipoCuenta.PTE_RECARGO_REPERCUTIDO.__GetDescription()));
1193  }
1194  }
1195  }
1196  }
1197 
1198  //Cuentas de prorrata
1199  if (_Prorrata)
1200  {
1201  if (_CuentaSoportadoProrrata == _CuentaPropuestaSoportadoProrrata)
1202  {
1203  if (!_CreaCuenta(ref _cCuentaSoportadoProrrata, ref lnContProcess, lnContMax, TipoCuenta.PRORRATA_SOPORTADO))
1204  {
1205  throw new Exception(String.Format("Se ha producido un problema al crear la cuenta de {0}", TipoCuenta.PRORRATA_SOPORTADO.__GetDescription()));
1206  }
1207  }
1208 
1209  // Cuentas de criterio de caja
1210  if (_CriterioCaja)
1211  {
1212  if (_CuentaSoportadoProrrataPte == _CuentaPropuestaSoportadoProrrataPte)
1213  {
1214  if (!_CreaCuenta(ref _cCuentaSoportadoProrrataPte, ref lnContProcess, lnContMax, TipoCuenta.PTE_PRORRATA_SOPORTADO))
1215  {
1216  throw new Exception(String.Format("Se ha producido un problema al crear la cuenta de {0}", TipoCuenta.PTE_PRORRATA_SOPORTADO.__GetDescription()));
1217  }
1218  }
1219  }
1220  }
1221 
1222  _SetProcess(ref lnContProcess, ref lnContMax, "", "Cuentas contables creadas correctamente.");
1223 
1224  if (!_CreaIva(lnContMax))
1225  {
1226  throw new Exception(String.Format("Se ha producido un problema al crear el tipo de {0}", _oTipo));
1227  }
1228 
1229  }
1230  catch (Exception loEx)
1231  {
1232  _cErrorMessage = loEx.Message;
1233  _SetProcess(ref lnContMax, ref lnContMax, "", String.Format("Se ha producido un error: {0}", _cErrorMessage));
1234 
1235  return false;
1236  }
1237 
1238  return true;
1239  }
1240 
1241  private void _SetProcess(ref Int32 lnContProcess, ref Int32 lnContMax, String tcTexto, String tcTextoTextBox = "")
1242  {
1243  if (!String.IsNullOrEmpty(tcTexto)) lnContProcess++;
1244  _BackgroundWorker.ReportProgress(lnContProcess, new InfoProgresBar(lnContProcess, lnContMax, tcTexto, tcTextoTextBox));
1245 
1246  //Paramos el thread para que refresque
1247  Thread.Sleep(300);
1248  }
1249 
1250  private Boolean _CreaIva(Int32 tnContMax)
1251  {
1252  Boolean bCreated = false;
1253  Int32 lnCont = 1;
1254  String lcCodigoTmp;
1255  Int32 lnContMax = tnContMax - 1;
1256 
1257  _SetProcess(ref lnContMax, ref tnContMax, String.Format("Creando tipo de {0}", _oTipo), "");
1258 
1259  while (!bCreated && lnCont < 10)
1260  {
1261  lnCont++;
1262  lcCodigoTmp = _Codigo;
1263  _cAditionalMessage = "";
1264 
1265  _TipoIva = new TipoIVA();
1266  _TipoIva._Codigo = _Codigo;
1267 
1268  if (!_TipoIva._Existe_Registro())
1269  {
1270  _TipoIva._Nombre = _Nombre;
1271  _TipoIva._IVA = _Porcentaje;
1272  _TipoIva._Recargo = _Recargo;
1273  _TipoIva._IVA_Deducible = _Deducible;
1274  _TipoIva._IVA_Servicios = _Servicios;
1275  _TipoIva._IVA_Exento = _NoSujeto;
1276  _TipoIva._IVA_BienesInversion = _BienesInversion;
1277  _TipoIva._Tipo = _Tipo;
1278  _TipoIva._IGICImplicito = _Tipo == TipoIVA.TipoImpuesto.IGIC ? _IGICImplicito : false;
1279  if (_Tipo == TipoIVA.TipoImpuesto.IGIC)
1280  _TipoIva._IGIC_Sujeto0 = _IGIC0;
1281  else
1282  _TipoIva._IVA_Sujeto0 = _IVA0;
1283 
1284 
1285  DataRow loRow = _ObtenerTipoImp();
1286 
1287  if(loRow is DataRow) _TipoIva._Tipo_Imp = Convert.ToInt32(loRow["CODIGO"]);
1288 
1289  //Cuentas
1290  _TipoIva._Cta_IVA_Sop = _CuentaSoportado;
1291  _TipoIva._Cta_IVA_Rep = _CuentaRepercutido;
1292 
1293  if (_AplicaRecargo && _Recargo > 0)
1294  {
1295  _TipoIva._Cta_REC_Sop = _CuentaRecargoSoportado;
1296  _TipoIva._Cta_REC_Rep = _CuentaRecargoRepercutido;
1297  }
1298 
1299  if(_CriterioCaja)
1300  {
1301  _TipoIva._Pendedsop = _CuentaSoportadoPte;
1302  _TipoIva._Pendevrep = _CuentaRepercutidoPte;
1303 
1304  if (_AplicaRecargo && _Recargo > 0)
1305  {
1306  _TipoIva._Recsopcdev = _CuentaRecargoSoportadoPte;
1307  _TipoIva._Recrepcdev = _CuentaRecargoRepercutidoPte;
1308  }
1309  }
1310 
1311  if (_Prorrata)
1312  {
1313  _TipoIva._Cta_IVA_Sop_Nodeduc = _CuentaSoportadoProrrata;
1314  if (_CriterioCaja) _TipoIva._Pendedsop_Nodeduc = _CuentaSoportadoProrrataPte;
1315  }
1316 
1317  if (DB._EsPenultimoEjercicio()) _TipoIva._OnMessageTraspasoPenultimoEjercicio += Cuenta__OnMessageTraspasoPenultimoEjercicio;
1318 
1319  if (_TipoIva._Save_Before())
1320  {
1321  if (!_TipoIva._Save())
1322  {
1323  _Codigo = _ObtenerCodigo();
1324 
1325  _cErrorMessage = String.Format("No se ha podido crear el tipo de {0} con código {1}, se asignará el nuevo código {2}.", _oTipo, lcCodigoTmp, _Codigo);
1326  _SetProcess(ref lnContMax, ref tnContMax, "", _cErrorMessage);
1327  }
1328  else
1329  {
1330  bCreated = true;
1331  }
1332  }
1333  else
1334  {
1335  lnCont = 10;
1336 
1337  _cErrorMessage = String.Format("No se ha podido crear el tipo de {0} con código {1}, se ha producido un error al validar los datos : {2}", _oTipo, lcCodigoTmp, _TipoIva._Error_Message);
1338  _SetProcess(ref lnContMax, ref tnContMax, "", _cErrorMessage);
1339  }
1340 
1341  if (DB._EsPenultimoEjercicio()) _TipoIva._OnMessageTraspasoPenultimoEjercicio -= Cuenta__OnMessageTraspasoPenultimoEjercicio;
1342 
1343  }
1344  else
1345  {
1346  _Codigo = _ObtenerCodigo();
1347  _cErrorMessage = String.Format("No se ha podido crear el tipo de {0} con código {1}, se asignará el nuevo código {2}.", _oTipo, lcCodigoTmp, _Codigo);
1348  _SetProcess(ref lnContMax, ref tnContMax, "", _cErrorMessage);
1349  }
1350  }
1351 
1352  if (bCreated)
1353  {
1354  _SetProcess(ref lnContMax, ref tnContMax, "", String.Format("Tipo de {0} creado correctamente con código {1}.", _oTipo, _Codigo));
1355  if (!string.IsNullOrEmpty(_cAditionalMessage)) _SetProcess(ref lnContMax, ref tnContMax, "", _cAditionalMessage);
1356  }
1357 
1358  return bCreated;
1359  }
1360 
1361  private DataRow _ObtenerTipoImp()
1362  {
1363  List<DataRow> loTipos = (from loRow in _TiposImpuesto.AsEnumerable()
1364  where
1365  Convert.ToDecimal(loRow["PORC_IMP"]) == _Porcentaje &&
1366  Convert.ToInt32(loRow["TIPO"]) == Convert.ToInt32(_oTipo) &&
1367  Convert.ToBoolean(loRow["NOSUJETO"]) == _NoSujeto &&
1368  Convert.ToBoolean(loRow["IGIC_IMPLI"]) == _IGICImplicito &&
1369  Convert.ToBoolean(loRow["CERO"]) == (_Tipo == TipoIVA.TipoImpuesto.IVA ? _IVA0 :_IGIC0)
1370  select loRow).ToList();
1371 
1372  return loTipos.Count > 0 ? loTipos.First() : null;
1373  }
1374 
1375  private Boolean _CreaCuenta(ref String tcCuenta, ref Int32 tnContProcess, Int32 tnContMax, TipoCuenta toTipo )
1376  {
1377  Cuenta loCuenta;
1378  Boolean bCreated = false;
1379  String tcCuentaTmp, lcNombre = "";
1380  Int32 lnCont = 1;
1381 
1382  _SetProcess(ref tnContProcess, ref tnContMax, String.Format("Creando cuenta {0}", tcCuenta));
1383 
1384  while (!bCreated && lnCont < 10)
1385  {
1386  _cAditionalMessage = "";
1387  tcCuentaTmp = tcCuenta;
1388  lnCont++;
1389 
1390  loCuenta = new Cuenta(tcCuenta);
1391 
1392  if (!loCuenta._Existe_Registro())
1393  {
1394  lcNombre = String.Format("{0} {1}", _oTipo, toTipo.__GetDescription());
1395  loCuenta._Nombre = lcNombre.ToUpper();
1396  //Añadimos el mensaje si se traspasa al año siguiente
1397  if (DB._EsPenultimoEjercicio()) loCuenta._OnMessageTraspasoPenultimoEjercicio += Cuenta__OnMessageTraspasoPenultimoEjercicio;
1398 
1399  if (!loCuenta._Save())
1400  {
1401  tcCuenta = _ObtenerCuenta(toTipo);
1402  _cErrorMessage = String.Format("No se ha podido crear la cuenta {0}, se asignará la cuenta {1}.", tcCuentaTmp, tcCuenta);
1403  _SetProcess(ref tnContProcess, ref tnContMax, "", _cErrorMessage);
1404  }
1405  else
1406  {
1407  bCreated = true;
1408  }
1409  }
1410  else
1411  {
1412  tcCuenta = _ObtenerCuenta(toTipo);
1413 
1414  _cErrorMessage = String.Format("No se ha podido crear la cuenta {0} porque ya existe, se asignará la cuenta {1}.", tcCuentaTmp, tcCuenta);
1415  _SetProcess(ref tnContProcess, ref tnContMax, "", _cErrorMessage);
1416  }
1417 
1418  if (DB._EsPenultimoEjercicio()) loCuenta._OnMessageTraspasoPenultimoEjercicio -= Cuenta__OnMessageTraspasoPenultimoEjercicio;
1419 
1420  }
1421 
1422  if (bCreated)
1423  {
1424  _SetProcess(ref tnContProcess, ref tnContMax, "", String.Format("Cuenta {0} {1} creada correctamente.", tcCuenta, lcNombre));
1425  if(!string.IsNullOrEmpty(_cAditionalMessage)) _SetProcess(ref tnContProcess, ref tnContMax, "", _cAditionalMessage);
1426  }
1427 
1428  return bCreated;
1429  }
1430 
1431  private bool Cuenta__OnMessageTraspasoPenultimoEjercicio(enumerations.AccionTraspasoUltimoEjercicio toAccion, bool tbIsNew, string tcNextEjer, string tcMessage)
1432  {
1433  _cAditionalMessage = tcMessage;
1434 
1435  return true;
1436  }
1437 
1438  private String _ObtenerCodigo()
1439  {
1440  String lcMax = "1";
1441  String lcSql = "";
1442  DataTable loDt = new DataTable();
1443 
1444  lcSql = String.Format("SELECT CODIGO FROM {0} WHERE CODIGO <> '' ORDER BY CODIGO ASC ", DB.SQLDatabase("GESTION", "TIPO_IVA"));
1445  DB.SQLExec(lcSql, ref loDt);
1446 
1447  if (loDt.Rows.Count > 0)
1448  {
1449  foreach (DataRow loRow in loDt.Rows)
1450  {
1451  lcMax = Convert.ToString(loRow["CODIGO"]);
1452  lcMax = _ObtenerSiguiente(lcMax);
1453 
1454  Boolean lbExist = (from loRowCodigo in loDt.AsEnumerable()
1455  where Convert.ToString(loRowCodigo["CODIGO"]) == lcMax
1456  select loRowCodigo).Count() > 0;
1457 
1458  if (!lbExist) return lcMax;
1459  }
1460  }
1461  else
1462  {
1463  lcMax = lcMax.PadLeft(_LenCodigo, '0');
1464  }
1465 
1466  return lcMax;
1467  }
1468 
1474  public Boolean _ValidaCodigo(String tcCodigo)
1475  {
1476  String lcSql = "";
1477  DataTable loDt = new DataTable();
1478 
1479  lcSql = String.Format("SELECT CODIGO FROM {0} WHERE CODIGO = {1}", DB.SQLDatabase("GESTION", "TIPO_IVA"), DB.SQLString(tcCodigo));
1480  DB.SQLExec(lcSql, ref loDt);
1481 
1482  return loDt.Rows.Count == 0;
1483  }
1484 
1485  private String _ObtenerSiguiente(String tcNum)
1486  {
1487  String tcNewNum = tcNum;
1488 
1489  if (!_ObtenerSiguienteNum(ref tcNewNum))
1490  {
1491  tcNewNum = _ObtenerSiguiente(tcNum.ToCharArray());
1492  }
1493 
1494  return tcNewNum;
1495  }
1496 
1497  private bool _ObtenerSiguienteNum(ref String tcNum)
1498  {
1499  Int32 lnTmp, lnMax = 0;
1500  Int32 lnLenght = tcNum.Length;
1501 
1502  lnMax = (Int32)Math.Pow(10, tcNum.Length) - 1;
1503 
1504  if (Int32.TryParse(tcNum, out lnTmp) && (lnTmp + 1) <= lnMax)
1505  {
1506  tcNum = Convert.ToString(lnTmp + 1);
1507  tcNum = tcNum.PadLeft(lnLenght, '0');
1508 
1509  return true;
1510  }
1511 
1512  return false;
1513  }
1514 
1515  private String _ObtenerSiguiente(Char[] loChars)
1516  {
1517  if (loChars.Length > 0)
1518  {
1519  String lcNum = new String(loChars);
1520  String lcNumTmp, lcPrefix, lcNextPrefix;
1521 
1522  lcNumTmp = lcNum.Substring(1);
1523  lcPrefix = lcNum.Substring(0, 1);
1524  Char[] loPrefix = lcPrefix.ToCharArray();
1525 
1526  if (lcPrefix == "9")
1527  {
1528  lcNextPrefix = "A";
1529  }
1530  else if (Char.IsLetter(lcPrefix.ToCharArray()[0]) && lcPrefix.ToCharArray()[0] < (Char)'Z')
1531  {
1532  loPrefix[0] = (Char)(loPrefix[0] + 1);
1533  lcNextPrefix = new String(loPrefix);
1534  }
1535  else if(Char.IsLetter(lcPrefix.ToCharArray()[0]) && lcPrefix.ToCharArray()[0] == (Char)'Z')
1536  {
1537  lcNextPrefix = "Z";
1538  }
1539  else
1540  {
1541  lcNextPrefix = Convert.ToString(Convert.ToInt32(lcPrefix) + 1);
1542  }
1543 
1544  if (!String.IsNullOrEmpty(lcNumTmp))
1545  {
1546  if (!_ObtenerSiguienteNum(ref lcNumTmp))
1547  {
1548  if (lcNextPrefix == "Z")
1549  {
1550  return "Z" + _ObtenerSiguiente(lcNumTmp.ToCharArray());
1551  }
1552  else
1553  {
1554  return lcNextPrefix + "0".PadRight(loChars.Length - 1, '0');
1555  }
1556  }
1557  else
1558  {
1559  return lcPrefix + lcNumTmp;
1560  }
1561  }
1562  else
1563  {
1564  return lcNextPrefix;
1565  }
1566  }
1567 
1568  return new String(loChars);
1569  }
1570 
1576  public static DataTable _ObtenerTipos(TipoImpuesto toTipoImpuesto)
1577  {
1578  DataTable loDt = (from loRow in _TiposImpuesto.AsEnumerable()
1579  where Convert.ToInt32(loRow["TIPO"]) == Convert.ToInt32(toTipoImpuesto)
1580  select loRow).CopyToDataTable();
1581 
1582  DataRow loRowPersonalizado = loDt.NewRow();
1583  loRowPersonalizado["CODIGO"] = 0;
1584  loRowPersonalizado["TITULO"] = "Personalizado";
1585  loDt.Rows.Add(loRowPersonalizado);
1586 
1587  return loDt;
1588  }
1589 
1596  public Boolean _ComprobarIva(String tcValorCandidato, TipoCuenta toTipoCuenta)
1597  {
1598  _cErrorMessage = "";
1599 
1600  String lcCuentaPropuesta, lcPrefijo;
1601 
1602  switch(toTipoCuenta)
1603  {
1604  case TipoCuenta.SOPORTADO:
1605  lcCuentaPropuesta = _CuentaPropuestaSoportado;
1606  lcPrefijo = _IvaSop3;
1607  break;
1608  case TipoCuenta.REPERCUTIDO:
1609  lcCuentaPropuesta = _CuentaPropuestaRepercutido;
1610  lcPrefijo = _IvaRep3;
1611  break;
1612  case TipoCuenta.RECARGO_SOPORTADO:
1613  lcCuentaPropuesta = _CuentaPropuestaRecargoSoportado;
1614  lcPrefijo = _IvaRecSop3;
1615  break;
1616  case TipoCuenta.RECARGO_REPERCUTIDO:
1617  lcCuentaPropuesta = _CuentaPropuestaRecargoRepercutido;
1618  lcPrefijo = _IvaRecRep3;
1619  break;
1620  case TipoCuenta.PTE_SOPORTADO:
1621  lcCuentaPropuesta = _CuentaPropuestaSoportadoPte;
1622  lcPrefijo = _IvaPendSop3;
1623  break;
1624  case TipoCuenta.PTE_REPERCUTIDO:
1625  lcCuentaPropuesta = _CuentaPropuestaRepercutidoPte;
1626  lcPrefijo = _IvaPendRep3;
1627  break;
1628  case TipoCuenta.PTE_RECARGO_SOPORTADO:
1629  lcCuentaPropuesta = _CuentaPropuestaRecargoSoportadoPte;
1630  lcPrefijo = _IvaRecPendSop3;
1631  break;
1632  case TipoCuenta.PTE_RECARGO_REPERCUTIDO:
1633  lcCuentaPropuesta = _CuentaPropuestaRecargoRepercutidoPte;
1634  lcPrefijo = _IvaRecPendSop3;
1635  break;
1636  case TipoCuenta.PRORRATA_SOPORTADO:
1637  lcCuentaPropuesta = _CuentaPropuestaSoportadoProrrata;
1638  lcPrefijo = "";
1639  break;
1640  case TipoCuenta.PTE_PRORRATA_SOPORTADO:
1641  lcCuentaPropuesta = _CuentaPropuestaSoportadoProrrataPte;
1642  lcPrefijo = "";
1643  break;
1644  default:
1645  lcCuentaPropuesta = lcPrefijo = "";
1646  break;
1647  }
1648 
1649  if (!String.IsNullOrEmpty(tcValorCandidato) && tcValorCandidato != lcCuentaPropuesta)
1650  {
1651  if (!String.IsNullOrEmpty(lcPrefijo) && !tcValorCandidato.StartsWith(lcPrefijo))
1652  {
1653  _cErrorMessage = String.Format("La cuenta debe comenzar por {0}.", lcPrefijo);
1654  }
1655  else if(!_Existe_Codigo(tcValorCandidato))
1656  {
1657  _cErrorMessage = String.Format("La cuenta {0} no existe.", tcValorCandidato);
1658  }
1659  else if (_CuentaAsignada(tcValorCandidato))
1660  {
1661  _cErrorMessage = _ErroMessage;
1662  }
1663  else if (_ComprobarIvas(toTipoCuenta, tcValorCandidato))
1664  {
1665  _cErrorMessage = _ErroMessage;
1666  }
1667  }
1668 
1669  return String.IsNullOrEmpty(_cErrorMessage);
1670  }
1671 
1672  private Boolean _CuentaAsignada(String tcValorCandidato)
1673  {
1674  if (tcValorCandidato == _CuentaSoportado)
1675  {
1676  _cErrorMessage = String.Format("La cuenta {0} ya esta asignada a la cuenta de {1} soportado.", tcValorCandidato, _Tipo);
1677  }
1678  else if (tcValorCandidato == _CuentaRepercutido)
1679  {
1680  _cErrorMessage = String.Format("La cuenta {0} ya esta asignada a la cuenta de {1} repercutido.", tcValorCandidato, _Tipo);
1681  }
1682  else if (_AplicaRecargo && tcValorCandidato == _CuentaRecargoSoportado)
1683  {
1684  _cErrorMessage = String.Format("La cuenta {0} ya esta asignada a la cuenta de recargo soportado.", tcValorCandidato);
1685  }
1686  else if (_AplicaRecargo && tcValorCandidato == _CuentaRecargoRepercutido)
1687  {
1688  _cErrorMessage = String.Format("La cuenta {0} ya esta asignada a la cuenta de recargo repercutido.", tcValorCandidato);
1689  }
1690  else if (_CriterioCaja && tcValorCandidato == _CuentaSoportadoPte)
1691  {
1692  _cErrorMessage = String.Format("La cuenta {0} ya esta asignada a la cuenta de soportado pendiente de devengo.", tcValorCandidato);
1693  }
1694  else if (_CriterioCaja && tcValorCandidato == _CuentaRepercutidoPte)
1695  {
1696  _cErrorMessage = String.Format("La cuenta {0} ya esta asignada a la cuenta de repercutido pendiente de devengo.", tcValorCandidato);
1697  }
1698  else if (_CriterioCaja && _AplicaRecargo && tcValorCandidato == _CuentaRecargoSoportadoPte)
1699  {
1700  _cErrorMessage = String.Format("La cuenta {0} ya esta asignada a la cuenta de recargo soportado pendiente de devengo.", tcValorCandidato);
1701  }
1702  else if (_CriterioCaja && _AplicaRecargo && tcValorCandidato == _CuentaRecargoRepercutidoPte)
1703  {
1704  _cErrorMessage = String.Format("La cuenta {0} ya esta asignada a la cuenta de recargo repercutido pendiente de devengo.", tcValorCandidato);
1705  }
1706  else if (_Prorrata && tcValorCandidato == _cCuentaSoportadoProrrata)
1707  {
1708  _cErrorMessage = String.Format("La cuenta {0} ya esta asignada a la cuenta de soportado no deducible.", tcValorCandidato);
1709  }
1710  else if (_Prorrata && _CriterioCaja && tcValorCandidato == _CuentaSoportadoProrrataPte)
1711  {
1712  _cErrorMessage = String.Format("La cuenta {0} ya esta asignada a la cuenta de soportado no deducible pendiente de devengo.", tcValorCandidato);
1713  }
1714 
1715  return !String.IsNullOrEmpty(_cErrorMessage);
1716  }
1717 
1718  private bool _Existe_Codigo(string tcValorCandidato)
1719  {
1720  Cuenta loCuenta = new Cuenta();
1721  loCuenta._Codigo = tcValorCandidato;
1722  return loCuenta._Existe_Registro();
1723  }
1724 
1725  private Boolean _ComprobarIvas(TipoCuenta toTipoCuenta, String tcValorCandidato)
1726  {
1727  String lcMessage = "";
1728  Boolean lbOk = true;
1729  String lcTipo = Convert.ToString(_Tipo);
1730 
1731  switch (toTipoCuenta)
1732  {
1733  case TipoCuenta.SOPORTADO:
1734  lbOk = _TipoIva._Comprobar_Ctas_Iva(lcTipo, tcValorCandidato, "", "", "", "", "", "", "", out lcMessage);
1735  break;
1736  case TipoCuenta.REPERCUTIDO:
1737  lbOk = _TipoIva._Comprobar_Ctas_Iva(lcTipo, "", tcValorCandidato, "", "", "", "", "", "", out lcMessage);
1738  break;
1739  case TipoCuenta.RECARGO_SOPORTADO:
1740  lbOk = _TipoIva._Comprobar_Ctas_Iva(lcTipo, "", "", tcValorCandidato, "", "", "", "", "", out lcMessage);
1741  break;
1742  case TipoCuenta.RECARGO_REPERCUTIDO:
1743  lbOk = _TipoIva._Comprobar_Ctas_Iva(lcTipo, "", "", "", tcValorCandidato, "", "", "", "", out lcMessage);
1744  break;
1745  case TipoCuenta.PTE_SOPORTADO:
1746  lbOk = _TipoIva._Comprobar_Ctas_Iva(lcTipo, "", "", "", "", tcValorCandidato, "", "", "", out lcMessage);
1747  break;
1748  case TipoCuenta.PTE_REPERCUTIDO:
1749  lbOk = _TipoIva._Comprobar_Ctas_Iva(lcTipo, "", "", "", "", "", tcValorCandidato, "", "", out lcMessage);
1750  break;
1751  case TipoCuenta.PTE_RECARGO_SOPORTADO:
1752  lbOk = _TipoIva._Comprobar_Ctas_Iva(lcTipo, "", "", "", "", "", "", tcValorCandidato, "", out lcMessage);
1753  break;
1754  case TipoCuenta.PTE_RECARGO_REPERCUTIDO:
1755  lbOk = _TipoIva._Comprobar_Ctas_Iva(lcTipo, "", "", "", "", "", "", "", tcValorCandidato, out lcMessage);
1756  break;
1757  }
1758 
1759  _ErroMessage = lcMessage;
1760 
1761  return lbOk;
1762  }
1763 
1767  public DatosIva()
1768  {
1769  _oTipo = Convert.ToString(EW_GLOBAL._GetVariable("wc_iva")) == "IVA" ? TipoIVA.TipoImpuesto.IVA : TipoIVA.TipoImpuesto.IGIC; ;
1770  }
1771  }
1772 
1777  : UserControl
1778  {
1782  protected DatosIva _oDatos;
1786  protected String _cErrorMessage = "";
1787 
1791  public virtual DatosIva _DatosIva
1792  {
1793  get
1794  {
1795  return _oDatos;
1796  }
1797  set
1798  {
1799  _oDatos = value;
1800  }
1801  }
1802 
1806  public String _ErrorMessage
1807  {
1808  get
1809  {
1810  return _cErrorMessage;
1811  }
1812  }
1813 
1818  public virtual Boolean _ValidaSiguiente()
1819  {
1820  return true;
1821  }
1822 
1827  public virtual void _RemoveBinding()
1828  {
1829 
1830  }
1831  }
1832 
1836  public interface IDatosAsiententeIva
1837  {
1841  DatosIva _DatosIva { get; set; }
1842 
1846  String _ErrorMessage { get; }
1847 
1852  Boolean _ValidaSiguiente();
1853 
1857  void _RemoveBinding();
1858  }
1859 }
void _RefreshNombre()
Refrescar nombre
TipoImpuesto
Tipo de impuesto
Definition: clsTipoIVA.cs:117
DatosIva _oDatos
Clase base para guardar los datos del usuario
Boolean _Finalizar()
Genera el tipo de IVA y las cuentas a partir de los datos de DatosIVA
virtual void _RemoveBinding()
Metodo para eliminar los Binding al pasar de paginas
override bool _Save()
Guarda el registro actual
Interface para los UserControls del asistente de IVA
TipoCuenta
Indica el tipo de cuenta
Clase base para los UserControls del asistente de IVA
Calse para guardar los datos del asistente de IVA
virtual bool _Existe_Registro()
Nos indica si existe el registro en la Base de Datos
Definition: clsEwBase.cs:3649
override string _Nombre
Bug 157602
override string _Codigo
Campo clave del mantenimiento
Clase de negocio del mantenimiento de cuentas contables
static DataTable _ObtenerTipos(TipoImpuesto toTipoImpuesto)
Obtiene los registros de TIPOSIMP
Boolean _ComprobarIva(String tcValorCandidato, TipoCuenta toTipoCuenta)
Compueba la cuenta asignada
virtual Boolean _ValidaSiguiente()
Metodo para validar antes del siguiente paso
Clase para el traspaso de info en las barras de progreso
Definition: ProcessBar.cs:433
OnMessageTraspasoPenultimoEjercicioHandler _OnMessageTraspasoPenultimoEjercicio
Evento para acceder a los mensajes de traspaso al siguiente ejercicio con objetos sin Formulario ...
Definition: clsEwBase.cs:1665
Boolean _ValidaCodigo(String tcCodigo)
Valida que no exista el código del IVA
Lisatdo base para los listados de IVA Repercutido, Soportado ...
Definition: IVA.cs:30