ArqueoTpv.cs
1 //#define ewTools //Descomentar esta línea para activar las operaciones relativas a medición de rendimiento
2 using System;
3 using System.Collections.Generic;
4 using System.Data;
5 using System.Linq;
6 using System.Windows.Forms;
7 using System.Threading.Tasks;
8 using System.IO;
9 
10 using sage.ew.db;
11 using sage.ew.functions;
12 using sage.ew.global;
13 using sage.ew.netvfp;
14 using sage.ew.tpv.Forms;
15 using sage.ew.docventatpv;
16 using sage.ew.ewbase;
17 using sage.ew.formul.Forms;
18 using sage.ew.listados.Clases;
19 using sage.ew.listados.Listados;
20 using sage.ew.interficies;
21 using sage.ew.tpv.Clases;
22 using sage.ew.docsven;
24 using Sage.ES.S50.Addons;
25 
26 namespace sage.ew.tpv
27 {
46  {
47  #region PROPIEDADES PROTECTED
48 
49 
53  protected internal string _lcUsuario = Convert.ToString(EW_GLOBAL._GetVariable("wc_usuario"));
54 
55 
59  protected internal string _lcUsuarioTablas = Convert.ToString(EW_GLOBAL._GetVariable("wc_usuario")).Trim().ToUpper() + "#" + Environment.MachineName.Trim().ToUpper() + "#" + Environment.UserName.Trim();
60 
61 
65  protected internal bool _llDivisa = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_divisa"));
66 
67 
71  protected internal string _lcMoneda_Empresa = Convert.ToString(EW_GLOBAL._GetVariable("wc_moneda"));
72 
73 
77  protected internal int _lnDigitos = Convert.ToInt32(EW_GLOBAL._GetLenCampo(KeyDiccionarioLenCampos.wn_digitos));
78 
79 
83  protected internal string _lcEmpresaActiva = Convert.ToString(EW_GLOBAL._GetVariable("wc_empresa"));
84 
85 
89  protected internal string _lcEjercicioActivo = Convert.ToString(EW_GLOBAL._GetVariable("wc_any"));
90 
91 
95  protected internal string _lcCajaActiva = Convert.ToString(EW_GLOBAL._GetVariable("wc_cajatpv"));
96 
97 
101  protected internal string _lcLetraCajaActiva = Convert.ToString(EW_GLOBAL._GetVariable("wc_letratpv"));
102 
103 
107  protected internal bool _llFactSer = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_factser"));
108 
109 
113  protected internal bool _lNetOffLine = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_netoffline"));
114 
115 
119  protected internal bool _llejercicioautomatico = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_Hera")) && Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_ejercicioautomatico")); // 104028
120 
121 
125  protected internal Dictionary<string, Dictionary<string, object>> _dicMonedas = new Dictionary<string, Dictionary<string, object>>();
126 
127 
131  protected internal Dictionary<string, decimal> _dicCotizacion = new Dictionary<string, decimal>();
132 
133 
137  protected internal Dictionary<string, string> _dicMoneda = new Dictionary<string, string>();
138 
139 
143  protected string _cMensaje_Error = string.Empty;
144 
145 
149  protected bool _lEstadoConsulta = false;
150 
151 
155  protected DateTime? _FechaDesde = null;
156 
157 
161  protected DateTime? _FechaHasta = null;
162 
163 
167  protected string _CajaDesde = string.Empty;
168 
169 
173  protected string _CajaHasta = string.Empty;
174 
175 
179  protected bool _TodasCajas = false;
180 
181 
182  #endregion PROPIEDADES PROTECTED
183 
184 
185  #region PROPIEDADES PRIVADAS
186 
187 
191  private DataTable _oDtArqueo = null;
192 
193 
197  private DocPrintArqueo _oDocPrintTPV = null;
198 
199 
203  private bool _lMostrarMensajes = true;
204 
205 
209  private bool _lArqueoCargado = false;
210 
211 
215  private int _nNumero = 0;
216 
217 
221  private string _cCaja = "";
222 
223 
227  private DateTime _dFecha = DateTime.Today;
228 
229  private decimal _nImporteTotalVentas = 0.0M; // Importe total de ventas en el arqueo: incluye tiquets + albaranes + facturas
230 
231  private int _nNumero_Tiquets = 0; // Nº de tiquets en el arqueo ...
232  private string _nNumero_Tiquet_Inicial = ""; // Nº de tiquet inicial ...
233  private string _nNumero_Tiquet_Final = ""; // Nº de tiquet final ...
234  private string _nLetra_Tiquet_Inicial = ""; // Letra de tiquet inicial ...
235  private string _nLetra_Tiquet_Final = ""; // Letra de tiquet final ...
236 
237  private DateTime _dFecha_Inicial = new DateTime(1900, 1, 1); // Fecha inicial del periodo de ventas incluidas en el arqueo ...
238  private DateTime _dFecha_Final = new DateTime(1900, 1, 1); // Fecha final del periodo de ventas incluidas en el arqueo ...
239 
240  private decimal _nImporteTotalOperCaja = 0.0M; // Incluye reposiciones+cobros tiquets+vales efectuados+entregas a cuenta alb.+entregas a cuenta ped.+cobros facturas+cobros varios+pagos facturas+pagos varios+retiros caja en negativo
241 
242  private decimal _nImporteArqueo = 0.0M; // Importe arqueo calculado ...
243 
244  private decimal _nImporteEfectivoArqueo = 0.0M; // Importe efectivo en caja calculado ...
245 
246  private decimal _nImporteTecleado = 0.0M; // Importe tecleado por el usuario. Campo solo válido cuando consultamos una arqueo cerrado ...
247  private decimal _nImporteDiferencia = 0.0M; // Diferencia entrre los dos anteriores. Campo solo válido cuando consultamos una arqueo cerrado ...
248  private decimal _nImporteRetirado = 0.0M; // Importe retirado de caja al cerrar el arqueo. Campo solo válido cuando consultamos una arqueo cerrado ...
249  private decimal _nImporteRepEnCaja = 0.0M; // Importe dejado en caja al cerrar el arqueo. Campo solo válido cuando consultamos una arqueo cerrado ...
250 
251  private decimal _nImporteDesgFamilias = 0.0M; // Total importe del desglose de ventas por familias ....
252 
253  private decimal _nDesgIvaTic_TotalBases = 0.0M; // Suma total de todas las bases imponibles del desglose de IVA tiquets ...
254  private decimal _nDesgIvaTic_TotalIvas = 0.0M; // Suma total de todas los ivas del desglose de IVA tiquets ...
255  private decimal _nDesgIvaTic_TotalTotal = 0.0M; // Suma total de todos los totales del desglose de IVA tiquets ...
256 
257  private String _cObservaciones = String.Empty; //Campo observaciones
258 
259  //PE-77346
260  private Dictionary<string, ewDocVentaTPV> _nDocsVenta;
261  private Dictionary<string, ewDocIva> _nDocsIva;
262 
263  private string _TituloMantenimiento = "Arqueo de caja";
264 
265  //T115439
266  private Boolean _lAvisoIva = false;
267 
268 
269  #endregion PROPIEDADES PRIVADAS
270 
271 
272  #region PROPIEDADES PUBLICAS
273 
274 
278  public Dictionary<string, string> _Cajas = new Dictionary<string, string>();
279 
280 
284  public Dictionary<string, string> _Numeros = new Dictionary<string, string>();
285 
286 
290  public Boolean _AvisoIva
291  {
292  get
293  {
294  return _lAvisoIva;
295  }
296  }
297 
298 
302  public DataTable _ArqueoDataTable
303  {
304  get
305  {
306  if (_oDtArqueo == null) _oDtArqueo = _MontaArqueo();
307  return _oDtArqueo;
308  }
309  }
310 
311 
315  public DialogResult? _DialogResult = null;
316 
317 
321  public bool _Cargar_Todo_Arqueo_Al_Asignar_Numero = true;
322 
323 
327  public bool _Error = false;
328 
329 
333  public formul.FormBase _oLinkForm = null;
334 
335 
339  public Dictionary<string, string> _Monedas
340  {
341  get
342  {
343  return _dicMoneda;
344  }
345  }
346 
347 
351  public decimal _Cotizacion(String lcMoneda)
352  {
353  decimal lnCotizacion;
354 
355  // PE-87745 - Bloquear per paralelisme
356  lock (_dicCotizacion)
357  {
358 
359  if (_dicCotizacion.ContainsKey(lcMoneda))
360  {
361  lnCotizacion = _dicCotizacion[lcMoneda];
362  }
363  else
364  {
365  lnCotizacion = Divisa._Ultima_Cotizacion(lcMoneda);
366  _dicCotizacion.Add(lcMoneda, lnCotizacion);
367  }
368  }
369 
370  return lnCotizacion;
371  }
372 
373 
377  public Dictionary<string, object> _Moneda(String lcMoneda)
378  {
379  Dictionary<string, object> loDicMoneda;
380 
381  // PE-87745 - Bloquear per paralelisme
382  lock (_dicMonedas)
383  {
384 
385  if (_dicMonedas.ContainsKey(lcMoneda))
386  {
387  loDicMoneda = _dicMonedas[lcMoneda];
388  }
389  else
390  {
391  loDicMoneda = DB.SQLREGValor("moneda", "codigo", lcMoneda);
392  _dicMonedas.Add(lcMoneda, loDicMoneda);
393  }
394 
395  }
396  return loDicMoneda;
397  }
398 
399 
403  public int _Numero
404  {
405  get
406  {
407  return this._nNumero;
408  }
409  set
410  {
411  // Esto está hecho así por si nos interesa cargar todo el arqueo o no.
412  // Si quisieramos consultar un apartado concreto de un arqueo (con nº 0 o diferente de 0), podemos poner la propiedad pública this._Cargar_Todo_Arqueo_Al_Asignar_Numero a false
413  // y llamar al método público que carga en alguno de los datatables publicos internos la parte del arqueo que nos interese.
414  // Como lo normal es cargar el arqueo entero, esta propiedad se inicializa a true.
415 
416  // Resetamos las propiedades del objeto ...
417  if(this._Cargar_Todo_Arqueo_Al_Asignar_Numero) this._DescargarDatos();
418 
419  this._nNumero = value;
420 
421  // Cargar todos los datos del arqueo.
422  // Si hay numero declarado !=0, cargará los datos del arqueo que hemos pedido, si no hay nº cargará todos los datos como si fuese a realizar un arqueo nuevo ...
423  if (this._Cargar_Todo_Arqueo_Al_Asignar_Numero) this._Load();
424  //}
425  }
426  }
427 
428 
432  public string _Observaciones
433  {
434  get { return this._cObservaciones; }
435  set { this._cObservaciones = value; }
436  }
437 
438 
442  public string _Caja
443  {
444  get { return this._lcCajaActiva; }
445  set { this._lcCajaActiva = value; }
446  }
447 
448 
452  public DateTime _Fecha
453  {
454  get { return this._dFecha; }
455  set { this._dFecha = value; }
456  }
457 
458 
459  // CAMPOS DEL APARTADO I. VENTAS
460 
464  public decimal _ImporteTotalVentas
465  {
466  get { return this._nImporteTotalVentas; }
467  }
468 
469 
473  public int _Numero_Tiquets
474  {
475  get { return this._nNumero_Tiquets; }
476  }
477 
478 
482  public string _Numero_Tiquet_Inicial
483  {
484  get { return this._nNumero_Tiquet_Inicial; }
485  }
486 
487 
491  public string _Numero_Tiquet_Final
492  {
493  get { return this._nNumero_Tiquet_Final; }
494  }
495 
496 
500  public string _Letra_Tiquet_Inicial
501  {
502  get { return this._nLetra_Tiquet_Inicial; }
503  }
504 
505 
509  public string _Letra_Tiquet_Final
510  {
511  get { return this._nLetra_Tiquet_Final; }
512  }
513 
514 
515  // CAMPOS DEL APARTADO II. OPERACIONES DE CAJA
516 
521  public decimal _ImporteTotalOperCaja
522  {
523  get { return this._nImporteTotalOperCaja; }
524  }
525 
526 
527  // CAMPOS DEL APARTADO III. ARQUEO DE CAJA
528 
532  public decimal _ImporteArqueo
533  {
534  get { return this._nImporteArqueo; }
535  }
536 
537 
541  public decimal _ImporteEfectivoArqueo
542  {
543  get { return this._nImporteEfectivoArqueo; }
544  }
545 
546 
550  public decimal _ImporteTecleado
551  {
552  get { return this._nImporteTecleado; }
553  set
554  {
555  this._nImporteTecleado = value;
556  this._nImporteDiferencia = this._nImporteTecleado - this._nImporteEfectivoArqueo;
557  }
558  }
559 
560 
564  public decimal _ImporteDiferencia
565  {
566  get { return this._nImporteDiferencia; }
567  }
568 
569 
573  public decimal _ImporteRepEnCaja
574  {
575  get { return this._nImporteRepEnCaja; }
576  set
577  {
578  this._nImporteRepEnCaja = value;
579  this._nImporteTecleado = value + this._nImporteRetirado;
580  this._nImporteDiferencia = this._nImporteTecleado - this._nImporteEfectivoArqueo;
581  }
582  }
583 
584 
588  public decimal _ImporteRetirado
589  {
590  get { return this._nImporteRetirado; }
591  set
592  {
593  this._nImporteRetirado = value;
594  this._nImporteTecleado = value + this._nImporteRepEnCaja;
595  this._nImporteDiferencia = this._nImporteTecleado - this._nImporteEfectivoArqueo;
596  }
597  }
598 
599 
603  public decimal _ImporteDesgFamilias
604  {
605  get { return this._nImporteDesgFamilias; }
606  }
607 
608 
612  public decimal _DesgIvaTic_TotalBases
613  {
614  get { return this._nDesgIvaTic_TotalBases; }
615  }
616 
617 
621  public decimal _DesgIvaTic_TotalIvas
622  {
623  get { return this._nDesgIvaTic_TotalIvas; }
624  }
625 
626 
630  public decimal _DesgIvaTic_TotalTotal
631  {
632  get { return this._nDesgIvaTic_TotalTotal; }
633  }
634 
635 
639  public string _Mensaje_Error
640  {
641  get { return _cMensaje_Error; }
642  set { _cMensaje_Error = value;}
643  }
644 
645 
646  // Datatables donde guardaremos los diferentes apartados ...
647 
649 
653  public DataTable _dtVentas_Tiquets;
654 
655 
659  public DataTable _dtVentas_Albaranes;
660 
661 
665  public DataTable _dtVentas_Facturas;
666 
667 
669 
673  public DataTable _dtOperCaja_Reposiciones;
674 
675 
679  public DataTable _dtOperCaja_Retiradas;
680 
681 
685  public DataTable _dtOperCaja_Cobros_Tiquets;
686 
687 
692 
693 
698 
699 
704 
705 
709  public DataTable _dtOperCaja_Cobros_Varios;
710 
711 
715  public DataTable _dtOperCaja_Cobros_Facturas;
716 
717 
721  public DataTable _dtOperCaja_Pagos_Varios;
722 
723 
727  public DataTable _dtOperCaja_Pagos_Facturas;
728 
729 
731 
735  public DataTable _dtArqueo_Caja;
736 
737 
739 
743  public DataTable _dtDesg_Familias;
744 
745 
747 
751  public DataTable _dtDesg_Iva;
752 
753 
757  public bool _Estado_Consulta
758  {
759  get { return _lEstadoConsulta; }
760  set { _lEstadoConsulta = value; }
761  }
762 
763 
767  public bool _DesgloseFamilias = (Convert.ToBoolean(DB.SQLValor("CONFTPV", "EMPRESA", Convert.ToString(EW_GLOBAL._GetVariable("wc_empresa")), "DESGFAM", "TPV")));
768 
769 
773  public Dictionary<string, object> _Addons { get; } = new Dictionary<string, object>();
774 
775 
776  #region IDocumentoImprimible
777 
778 
782  public IDocPrint _DocPrint
783  {
784  get
785  {
786  if (_oDocPrintTPV == null)
787  {
788  _oDocPrintTPV = new DocPrintArqueo((IDocumentoImprimible)this);
789  }
790  return _oDocPrintTPV;
791  }
792  set
793  {
794  if (value is DocPrintArqueo) _oDocPrintTPV = (DocPrintArqueo)value;
795  }
796  }
797 
798 
802  public string _Empresa
803  {
804  get
805  {
806  return _lcEmpresaActiva;
807  }
808  set
809  {
810  ;
811  }
812  }
813 
814 
819  {
820  get
821  {
822  return _Fecha.ToString(EW_GLOBAL._CustomFormatDate);
823  }
824  }
825 
826 
830  public string _Nombre
831  {
832  get
833  {
834  return "Arqueo de caja";
835  }
836  }
837 
838 
842  public string _ReportBase
843  {
844  get
845  {
846  return ((DocPrintArqueo)_DocPrint)._TipoImpresion == sage.ew.tpv.Clases.DocPrintTPV.TipoImpresion.Ticket ? "arqueoticket.report" : "arqueo.report";
847  }
848  set
849  {
850  ;
851  }
852  }
853 
854 
858  public string _ReportTitlePreview
859  {
860  get
861  {
862  return _Nombre;
863  }
864  set
865  {
866  ;
867  }
868  }
869 
870 
876  public bool _Show_Print(int tnAbrirEn = 1)
877  {
878  throw new NotImplementedException();
879  }
880 
881 
886  public Dictionary<string, object> _Obtener_Filtros_SageReports(Dictionary<string, object> tdicParametros = null)
887  {
888  Dictionary<string, object> loFiltros = new Dictionary<string, object>();
889  String lcBase, lcPercentIva, lcImporteIva, lcTotal, lcTitulo;
890  Decimal lnTotalBase, lnTotalImporteIva, lnTotalTotal;
891  Boolean lConsolidacion, lConsultaArqueos, lTipoArqueoConsulta;
892  ewMascara loMascaraImport = new ewMascara(EW_GLOBAL._GetMascara(KeyDiccionarioMascara.wc_total));
893  String lcCadenaFormat = "{0:" + loMascaraImport._Mascara_Net + "}";
894 
895  lcBase = lcPercentIva = lcImporteIva = lcTotal = "";
896  lnTotalBase = lnTotalImporteIva = lnTotalTotal = 0;
897 
898  lTipoArqueoConsulta = tdicParametros.ContainsKey("TipoArqueoConsulta") ? Convert.ToBoolean(tdicParametros["TipoArqueoConsulta"]) : false;
899  lConsolidacion = tdicParametros.ContainsKey("Consolidacion") ? Convert.ToBoolean(tdicParametros["Consolidacion"]) : false;
900  lConsultaArqueos = tdicParametros.ContainsKey("ConsultaArqueos") ? Convert.ToBoolean(tdicParametros["ConsultaArqueos"]) : false;
901  lcTitulo = tdicParametros.ContainsKey("Titulo") ? Convert.ToString(tdicParametros["Titulo"]) : _Nombre;
902 
903  //if (!lConsolidacion && !lConsultaArqueos && _Numeros.Count == 0)
904  // CCR 123263 - Añadir el desglose de Iva
905  if (_dtDesg_Iva != null && _dtDesg_Iva.Rows.Count > 0)
906  {
907  foreach (DataRow ldrFilaIva in _dtDesg_Iva.Rows)
908  {
909  lcBase += String.Format("{0}{1}", !String.IsNullOrEmpty(lcBase) ? Environment.NewLine : String.Empty, String.Format(lcCadenaFormat, ldrFilaIva["baseiva"]));
910  lcPercentIva += String.Format("{0}{1}", !String.IsNullOrEmpty(lcPercentIva) ? Environment.NewLine : String.Empty, String.Format(lcCadenaFormat, ldrFilaIva["iva_tan"]));
911  lcImporteIva += String.Format("{0}{1}", !String.IsNullOrEmpty(lcImporteIva) ? Environment.NewLine : String.Empty, String.Format(lcCadenaFormat, ldrFilaIva["impiva"]));
912  lcTotal += String.Format("{0}{1}", !String.IsNullOrEmpty(lcTotal) ? Environment.NewLine : String.Empty, String.Format(lcCadenaFormat, ldrFilaIva["imptotal"]));
913 
914  lnTotalBase += Convert.ToDecimal(ldrFilaIva["baseiva"]);
915  lnTotalImporteIva += Convert.ToDecimal(ldrFilaIva["impiva"]);
916  lnTotalTotal += Convert.ToDecimal(ldrFilaIva["imptotal"]);
917  }
918  }
919  else
920  {
921  lcTotal = lcImporteIva = lcBase = String.Format(lcCadenaFormat, 0);
922  }
923 
924  loFiltros.Add("wc_AvisoIva", _AvisoIva ? "1" : "0"); //T115439
925  loFiltros.Add("wc_Base", lcBase);
926  loFiltros.Add("wc_PercentIva", lcPercentIva);
927  loFiltros.Add("wc_ImporteIva", lcImporteIva);
928  loFiltros.Add("wc_Total", lcTotal);
929  loFiltros.Add("wc_TotalBase", String.Format(lcCadenaFormat, lnTotalBase));
930  loFiltros.Add("wc_TotalImporteIva", String.Format(lcCadenaFormat, lnTotalImporteIva));
931  loFiltros.Add("wc_TotalTotal", String.Format(lcCadenaFormat, lnTotalTotal));
932  loFiltros.Add("wc_MostrarIva", "1");
933 
934  loFiltros.Add("wc_Titulo", String.Format("{1} {0}", !lConsolidacion && !lConsultaArqueos ? lTipoArqueoConsulta ? "(Consulta)" : "(Definitivo)" : String.Empty, lcTitulo));
935  loFiltros.Add("wc_ImporteRepEnCaja", String.Format(lcCadenaFormat, _ImporteRepEnCaja));
936  loFiltros.Add("wc_ImporteRetirado", String.Format(lcCadenaFormat, _ImporteRetirado));
937  loFiltros.Add("wc_ImporteTecleado", String.Format(lcCadenaFormat, _ImporteTecleado));
938 
939  return loFiltros;
940  }
941 
942 
947  public DataTable _Obtener_Datos_SageReports(Dictionary<string, object> tdicParametros = null)
948  {
949  DataTable loDT;
950 
951  loDT = _ArqueoDataTable;
952 
953  if (loDT is DataTable)
954  {
955  loDT = _ArqueoDataTable.Copy();
956 
957  if (loDT.Rows.Count > 0)
958  {
959  DataRow loRow = loDT.Rows[loDT.Rows.Count - 1];
960 
961  if (String.IsNullOrEmpty(Convert.ToString(loRow[0])) && String.IsNullOrEmpty(Convert.ToString(loRow[1])))
962  {
963  loDT.Rows.Remove(loRow);
964  }
965  }
966  }
967  return loDT;
968  }
969 
970 
971  #endregion IDocumentoImprimible
972 
973 
974  #endregion PROPIEDADES PUBLICAS
975 
976 
977  #region CONSTRUCTORES
978 
979 
983  public ArqueoTpv()
984  {
985 #if ewTools
986  EwTools._Start();
987  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
988 #endif
989 
990  // Cargar las extensiones para arqueo TPV que encuentre en los Addons activos.
991  //
992  this._Addons_Cargar();
993 
994  this._DescargarDatos();
995 
996 #if ewTools
997  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
998 #endif
999  }
1000 
1001 
1006  public ArqueoTpv(int tnNumero)
1007  {
1008 #if ewTools
1009  EwTools._Start();
1010  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
1011 #endif
1012  // Cargar las extensiones para arqueo TPV que encuentre en los Addons activos.
1013  //
1014  this._Addons_Cargar();
1015 
1016  // Asignamos el código de arqueo, esta simple asignación ya hace que se descargue el objeto y se ejecute el _Load() y cargue todos los datos de un arqueo existente (caso
1017  // de que tnNumero!=0, o cargue todos los datos de una arqueo nuevo, caso de tnNumero=0. Importante asignar a la propiedad pública _Numero y no a la privada _nNumero, la
1018  // programación está hecha en la propiedad pública, no en la privada, la privada es para uso interrno y nos puede interesar asignarla sin tener que desencadenar todos
1019  // los procesos.
1020  //
1021  // Ojo! Todo lo anterior está condicionado a que la propiedad pública this._Cargar_Todo_Arqueo_Al_Asignar_Numero esté a true (por defecto lo está). Si estuviese a false
1022  // haría la asignación y nada más. La razón de esta última operativa es que tras asignar número se permita llamar a alguno de los métodos publicos del objeto que realiza la carga
1023  // de alguno de los apartados únicamente, es para extraer información concreta de algún apartado del arqueo sin tener que cargarlo todo.
1024  this._Numero = tnNumero;
1025 
1026 #if ewTools
1027  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
1028 #endif
1029  }
1030 
1031 
1036  public ArqueoTpv(dynamic toForm)
1037  {
1038 #if ewTools
1039  EwTools._Start();
1040  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
1041 #endif
1042 
1043  // Cargar las extensiones para arqueo TPV que encuentre en los Addons activos.
1044  //
1045  this._Addons_Cargar();
1046 
1047  this._oLinkForm = toForm;
1048 
1049 #if ewTools
1050  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
1051 #endif
1052  }
1053 
1054 
1055  #endregion CONSTRUCTORES
1056 
1057 
1058  #region METODOS PUBLICOS
1059 
1060 
1065  public Dictionary<string, object> _Obtener_DatosGen_Arqueo_Cerrado(string tcEjercicio, string tcEmpresa, int tnNumero)
1066  {
1067  Dictionary<string, object> loDic = new Dictionary<string, object>();
1068 
1069  loDic = DB.SQLREGValor("arqueos", new string[] {"empresa","ejercicio","numero"}, new string[] {tcEmpresa, tcEjercicio, Convert.ToString(tnNumero) },"tpv");
1070  return loDic;
1071  }
1072 
1073 
1078  public void _DescargarDatos()
1079  {
1080 #if ewTools
1081  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
1082 #endif
1083 
1084  this._Addons_DescargarDatos(TipoExecute.Before);
1085 
1086  // Reseteamos todas las propiedades privadas ...
1087  this._nNumero = 0;
1088 
1089  // Caja ..
1090  this._cCaja = "";
1091 
1092  this._nImporteTotalVentas = 0.0M; // Importe total de ventas en el arqueo: incluye tiquets + albaranes + facturas
1093  this._nNumero_Tiquets = 0; // Nº de tiquets en el arqueo ...
1094  this._nNumero_Tiquet_Inicial = ""; // Nº de tiquet inicial ...
1095  this._nNumero_Tiquet_Final = ""; // Nº de tiquet final ...
1096  this._nLetra_Tiquet_Inicial = ""; // Letra de tiquet inicial ...
1097  this._nLetra_Tiquet_Final = ""; // Letra de tiquet final ...
1098  this._dFecha_Inicial = new DateTime(1900, 1, 1); // Fecha inicial del periodo de ventas incluidas en el arqueo ...
1099  this._dFecha_Final = new DateTime(1900, 1, 1); // Fecha final del periodo de ventas incluidas en el arqueo ...
1100 
1101  this._nImporteTotalOperCaja = 0.0M; // Incluye reposiciones+cobros tiquets+vales efectuados+entregas a cuenta alb.+entregas a cuenta ped.+cobros facturas+cobros varios+pagos facturas+pagos varios+retiros caja en negativo
1102 
1103  this._nImporteArqueo = 0.0M; // Importe arqueo calculado ...
1104  this._nImporteEfectivoArqueo = 0.0M; // Importe efectivo en caja calculado ...
1105  this._nImporteTecleado = 0.0M; // Importe tecleado por el usuario. Campo solo válido cuando consultamos una arqueo cerrado ...
1106  this._nImporteDiferencia = 0.0M; // Diferencia entrre los dos anteriores. Campo solo válido cuando consultamos una arqueo cerrado ...
1107  this._nImporteRetirado = 0.0M; // Importe retirado de caja al cerrar el arqueo. Campo solo válido cuando consultamos una arqueo cerrado ...
1108  this._nImporteRepEnCaja = 0.0M; // Importe dejado en caja al cerrar el arqueo. Campo solo válido cuando consultamos una arqueo cerrado ...
1109 
1110  this._nImporteDesgFamilias = 0.0M; // Total importe del desglose de ventas por familias ....
1111 
1112  this._nDesgIvaTic_TotalBases = 0.0M; // Suma total de todas las bases imponibles del desglose de IVA tiquets ...
1113  this._nDesgIvaTic_TotalIvas = 0.0M; // Suma total de todas los ivas del desglose de IVA tiquets ...
1114  this._nDesgIvaTic_TotalTotal = 0.0M; // Suma total de todos los totales del desglose de IVA tiquets ...
1115 
1116  // Datatables que tiene las ventas en los diferentes tipos de documentos y monedas ...
1117  this._dtVentas_Tiquets = null;
1118  this._dtVentas_Albaranes = null;
1119  this._dtVentas_Facturas = null;
1120 
1122  this._dtOperCaja_Reposiciones = null;
1123  this._dtOperCaja_Retiradas = null;
1124  this._dtOperCaja_Cobros_Tiquets = null;
1125  this._dtOperCaja_Vales_Efectuados = null;
1126  this._dtOperCaja_Entregas_Cuenta_Albaranes = null;
1127  this._dtOperCaja_Entregas_Cuenta_Pedidos = null;
1128 
1129  this._dtOperCaja_Cobros_Varios = null;
1130  this._dtOperCaja_Cobros_Facturas = null;
1131  this._dtOperCaja_Pagos_Varios = null;
1132  this._dtOperCaja_Pagos_Facturas = null;
1133 
1135  this._dtArqueo_Caja = null;
1136  this._dtDesg_Familias = null;
1137  this._dtDesg_Iva = null;
1138 
1139  this._lArqueoCargado = false;
1140 
1141  //PE-77346
1142  this._nDocsVenta = new Dictionary<string, ewDocVentaTPV>();
1143  this._nDocsIva = new Dictionary<string, ewDocIva>();
1144 
1145  this._Addons_DescargarDatos(TipoExecute.After);
1146 
1147 #if ewTools
1148  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
1149 #endif
1150  }
1151 
1152 
1159  public bool _Load()
1160  {
1161 #if ewTools
1162  EwTools._Restart();
1163  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
1164 #endif
1165 
1166  this._Addons_Load(TipoExecute.Before);
1167 
1168 
1169  DB._Persist = false; // PE-87745 - per fer paralelisme ha d'estar a false
1170  bool llRetorno = false;
1171  DataTable ldt_Cursor = new DataTable();
1172 
1173  //PE-77346
1174  this._nDocsVenta = new Dictionary<string, ewDocVentaTPV>();
1175  this._nDocsIva = new Dictionary<string, ewDocIva>();
1176 
1177  this._Error = false;
1178  this._Mensaje_Error = "";
1179 
1180  Boolean lbListado = this._Cajas.Count > 0 || this._Numeros.Count > 0;
1181 
1182  // Buscamos el registro de TPV!ARQUEOS
1183  String lcSql ;
1184 
1185  // 104028
1186  if (!lbListado)
1187  {
1188  if (_llejercicioautomatico) lcSql = "select * from " + DB.SQLDatabase("tpv", "arqueos") + " where empresa=" + DB.SQLString(this._lcEmpresaActiva) + " and numero=" + DB.SQLString(this._nNumero);
1189  else lcSql = "select * from " + DB.SQLDatabase("tpv", "arqueos") + " where empresa=" + DB.SQLString(this._lcEmpresaActiva) + " and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " and numero=" + DB.SQLString(this._nNumero);
1190  }
1191  else
1192  {
1193  if (_llejercicioautomatico) lcSql = String.Format("SELECT SUM(tecleado) as tecleado, SUM(repencaja) as repencaja, SUM(tecleado) as repencaja FROM {0} WHERE empresa = {1} AND {2}", DB.SQLDatabase("tpv", "arqueos"), DB.SQLString(this._lcEmpresaActiva), _makeId("", " and numero=" + DB.SQLString(this._nNumero), "numero"));
1194  else lcSql = String.Format("SELECT SUM(tecleado) as tecleado, SUM(repencaja) as repencaja, SUM(tecleado) as repencaja FROM {0} WHERE empresa = {1} AND ejercicio = {2} AND {3}",DB.SQLDatabase("tpv", "arqueos"), DB.SQLString(this._lcEmpresaActiva), DB.SQLString(this._lcEjercicioActivo), _makeId("", " and numero=" + DB.SQLString(this._nNumero), "numero"));
1195  }
1196  // fi 104028
1197  llRetorno = DB.SQLExec(lcSql, ref ldt_Cursor);
1198 
1199 
1200  if (llRetorno || lbListado)
1201  {
1202  if (!lbListado)
1203  {
1204  this._cCaja = this._nNumero != 0 && ldt_Cursor.Rows.Count > 0 ? Convert.ToString(ldt_Cursor.Rows[0]["caja"]) : this._lcCajaActiva;
1205  this._dFecha = this._nNumero != 0 && ldt_Cursor.Rows.Count > 0 ? Convert.ToDateTime(ldt_Cursor.Rows[0]["fecha"]) : this._dFecha;
1206  }
1207 
1208 #if ewTools
1209  EwTools._WriteTrace(EwTools.eMethodStatus.Procesando,"Inicio paralelismo");
1210 #endif
1211 
1212  // PE-87745 - Paralelisme
1213  decimal lnTotalRepo = 0.0M, lnTotalTickets = 0.0M, lnTotalVales = 0.0M, lnTotalEntAlb = 0.0M, lnTotalEntPed = 0.0M, lnTotalCFac = 0.0M, lnTotalCVar = 0.0M;
1214  decimal lnTotalPFac = 0.0M, lnTotalPVar = 0.0M, lnTotalRet = 0.0M;
1215 
1216  String lcMsgNumTickets = "", lcMsgImpTickets = "", lcMsgRepo = "", lcMsgTickets = "", lcMsgVales = "", lcMsgEntAlb = "", lcMsgEntPed = "", lcMsgCFas = "", lcMsgCVar = "";
1217  String lcMsgPFac = "", lcMsgPVar = "", lcMsgRet = "";
1218 
1219  DataTable ldReposiciones = new DataTable();
1220  DataTable ldCobrosTiquets = new DataTable();
1221  DataTable ldVales = new DataTable();
1222  DataTable ldEntAlbaran = new DataTable();
1223  DataTable ldEntPedidos = new DataTable();
1224  DataTable ldCobrosFac = new DataTable();
1225  DataTable ldCobrosVarios = new DataTable();
1226  DataTable ldPagosFacturas = new DataTable();
1227  DataTable ldPagosVarios = new DataTable();
1228  DataTable ldRetiros = new DataTable();
1229 
1230  Parallel.Invoke(
1231  () => this._nNumero_Tiquets = this._Obtener_Numero_Tiquets(ref this._nNumero_Tiquet_Inicial, ref this._nNumero_Tiquet_Final, ref lcMsgNumTickets, ref this._nLetra_Tiquet_Inicial, ref this._nLetra_Tiquet_Final), //PE-90183
1232 
1233  // I-VENTAS
1234  () => this._Obtener_DataTables_Importe_Tiquets_Albaranes_Facturas(ref this._dFecha_Inicial, ref this._dFecha_Final, ref lcMsgImpTickets),
1235 
1236  // II-OPERACIONES CAJA
1237  () => ldReposiciones = this._Obtener_DataTable_OperCaja_Reposiciones(ref lnTotalRepo, ref lcMsgRepo),
1238  () => ldCobrosTiquets = this._Obtener_DataTable_OperCaja_Cobros_Tiquets(ref lnTotalTickets, ref lcMsgTickets),
1239  () => ldVales = this._Obtener_DataTable_OperCaja_Vales_Efectuados(ref lnTotalVales, ref lcMsgVales),
1240  () => ldEntAlbaran = this._Obtener_DataTable_OperCaja_Entregas_Cuenta_Albaranes(ref lnTotalEntAlb, ref lcMsgEntAlb),
1241  () => ldEntPedidos = this._Obtener_DataTable_OperCaja_Entregas_Cuenta_Pedidos(ref lnTotalEntPed, ref lcMsgEntPed),
1242  () => ldCobrosFac = this._Obtener_DataTable_OperCaja_Cobros_Facturas(ref lnTotalCFac, ref lcMsgCFas),
1243  () => ldCobrosVarios = this._Obtener_DataTable_OperCaja_Cobros_Varios(ref lnTotalCVar, ref lcMsgCVar),
1244  () => ldPagosFacturas = this._Obtener_DataTable_OperCaja_Pagos_Facturas(ref lnTotalPFac, ref lcMsgPFac),
1245  () => ldPagosVarios = this._Obtener_DataTable_OperCaja_Pagos_Varios(ref lnTotalPVar, ref lcMsgPVar),
1246  () => ldRetiros = this._Obtener_DataTable_OperCaja_Retiros(ref lnTotalRet, ref lcMsgRet));
1247 
1248 #if ewTools
1249  EwTools._WriteTrace(EwTools.eMethodStatus.Procesando, "Fin paralelismo");
1250 #endif
1251 
1252  // Actualizar campo Total Operaciones Caja del objeto ...
1253  this._nImporteTotalOperCaja = lnTotalRepo + lnTotalTickets + lnTotalVales + lnTotalEntAlb + lnTotalEntPed + lnTotalCFac + lnTotalCVar + lnTotalPFac + lnTotalPVar + lnTotalRet;
1254 
1255  this._dtOperCaja_Reposiciones = ldReposiciones;
1256  this._dtOperCaja_Cobros_Tiquets = ldCobrosTiquets;
1257  this._dtOperCaja_Vales_Efectuados = ldVales;
1258  this._dtOperCaja_Entregas_Cuenta_Albaranes = ldEntAlbaran;
1259  this._dtOperCaja_Entregas_Cuenta_Pedidos = ldEntPedidos;
1260  this._dtOperCaja_Cobros_Facturas = ldCobrosFac;
1261  this._dtOperCaja_Cobros_Varios = ldCobrosVarios;
1262  this._dtOperCaja_Pagos_Facturas = ldPagosFacturas;
1263  this._dtOperCaja_Pagos_Varios = ldPagosVarios;
1264  this._dtOperCaja_Retiradas = ldRetiros;
1265 
1266  _MessageBox(lcMsgNumTickets);
1267  _MessageBox(lcMsgImpTickets);
1268  _MessageBox(lcMsgRepo);
1269  _MessageBox(lcMsgTickets);
1270  _MessageBox(lcMsgVales);
1271  _MessageBox(lcMsgEntAlb);
1272  _MessageBox(lcMsgEntPed);
1273  _MessageBox(lcMsgCFas);
1274  _MessageBox(lcMsgCVar);
1275  _MessageBox(lcMsgPFac);
1276  _MessageBox(lcMsgPVar);
1277  _MessageBox(lcMsgRet);
1278 
1279  // III-ARQUEO DE CAJA
1280  // Estos 3 campos tendran valor si estamos en un arqueo ya cerrado, sino estaran a 0
1281 
1282  // 90664
1283  if ((this._nNumero != 0 || lbListado) && ldt_Cursor.Rows.Count > 0 && ldt_Cursor.Rows[0]["tecleado"] != DBNull.Value)
1284  this._nImporteTecleado = Convert.ToDecimal(ldt_Cursor.Rows[0]["tecleado"]);
1285 
1286  if ((this._nNumero != 0 || lbListado) && ldt_Cursor.Rows.Count > 0 && ldt_Cursor.Rows[0]["repencaja"] != DBNull.Value)
1287  this._nImporteRepEnCaja = Convert.ToDecimal(ldt_Cursor.Rows[0]["repencaja"]);
1288 
1289  if ((this._nNumero != 0 || lbListado) && ldt_Cursor.Rows.Count > 0 && ldt_Cursor.Rows[0]["tecleado"] != DBNull.Value && ldt_Cursor.Rows[0]["repencaja"] != DBNull.Value)
1290  this._nImporteRetirado = Convert.ToDecimal(ldt_Cursor.Rows[0]["tecleado"]) - Convert.ToDecimal(ldt_Cursor.Rows[0]["repencaja"]);
1291 
1292  // fi 90664
1293 
1294 #if ewTools
1295  EwTools._WriteTrace(EwTools.eMethodStatus.Llamando, "_Obtener_DataTable_Arqueo_Caja");
1296 #endif
1297 
1298  // Obtener datatable de cuadre de arqueo de caja ...
1299  this._Obtener_DataTable_Arqueo_Caja();
1300 
1301 #if ewTools
1302  EwTools._WriteTrace(EwTools.eMethodStatus.Volviendo, "_Obtener_DataTable_Arqueo_Caja");
1303 #endif
1304 
1305  this._nImporteDiferencia = this._nImporteEfectivoArqueo - this._nImporteTecleado;
1306 
1307 #if ewTools
1308  EwTools._WriteTrace(EwTools.eMethodStatus.Llamando, "_Obtener_DataTable_Desg_Familias");
1309 #endif
1310 
1311  // IV-DESGLOSE FAMILIAS
1312  this._nImporteDesgFamilias = this._Obtener_DataTable_Desg_Familias();
1313 
1314 #if ewTools
1315  EwTools._WriteTrace(EwTools.eMethodStatus.Volviendo, "_Obtener_DataTable_Desg_Familias");
1316 #endif
1317 
1318 #if ewTools
1319  EwTools._WriteTrace(EwTools.eMethodStatus.Llamando, "_Obtener_DataTable_Desg_Iva_Tiquets");
1320 #endif
1321 
1322  // Desglose IVA
1323  // Dentro de este método se actualizan 3 propiedades del objeto Arqueo que guardan las el total bases, el total ivas i el total total del desglose de IVA
1324  this._Obtener_DataTable_Desg_Iva_Tiquets();
1325 
1326 #if ewTools
1327  EwTools._WriteTrace(EwTools.eMethodStatus.Volviendo, "_Obtener_DataTable_Desg_Iva_Tiquets");
1328 #endif
1329 
1330  this._lArqueoCargado = true;
1331  }
1332 
1333  DB._Persist = false;
1334 
1335 #if ewTools
1336  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
1337 #endif
1338 
1339  this._Addons_Load(TipoExecute.After);
1340 
1341  // Devuelve true si todo fue ok, false caso contrario.
1342  return (this._Error == false);
1343  }
1344 
1345 
1350  public void _Load_Observaciones()
1351  {
1352  DataTable ldt_Cursor = new DataTable();
1353  bool llRetorno;
1354 
1355  // Si no tenemos numero o hay más de un arqueo no realizar la consulta
1356  if (this._nNumero == 0 && this._Numeros.Count > 1)
1357  {
1358  this._cObservaciones = "";
1359  return;
1360  }
1361 
1362  String lcCond = this._nNumero != 0 ? " numero=" + DB.SQLString(this._nNumero) : _makeId("", " and numero=" + DB.SQLString(this._nNumero), "numero");
1363 
1364  String lcSql ;
1365  lcSql = String.Format("select observacio FROM {0} WHERE empresa = {1} AND ejercicio = {2} and {3}", DB.SQLDatabase("tpv", "arqueos"), DB.SQLString(this._lcEmpresaActiva), DB.SQLString(this._lcEjercicioActivo), lcCond);
1366  llRetorno = DB.SQLExec(lcSql, ref ldt_Cursor);
1367 
1368  if (llRetorno && ldt_Cursor.Rows.Count > 0)
1369  this._cObservaciones = Convert.ToString(ldt_Cursor.Rows[0]["observacio"]);
1370 
1371  return;
1372  }
1373 
1374 
1380  public virtual bool _Save()
1381  {
1382  bool llRetorno = false, llConsultaOk = false;
1383  DataTable ldt_Arqueo = new DataTable();
1384  string lcNumero = "";
1385 
1386  this._Error = false;
1387  this._Mensaje_Error = "";
1388 
1389  this._Addons_Save(TipoExecute.Before);
1390 
1391  if (this._lArqueoCargado == false)
1392  {
1393  this._MessageBox("(_Save) No se ha cargado todavía ningun arqueo.\n\nPrimero debe cargarse en el objeto una arqueo.");
1394  return false;
1395  }
1396 
1397  if (this._nNumero != 0)
1398  {
1399  this._MessageBox("(_Save) No se puede cerrar un arqueo que ya está cerrado.\n\nPrimero se debe desarquear.");
1400  return false;
1401  }
1402 
1403  // Miramos si hay tiquets aparcados, si es así, no permitimos continuar ...
1404  int lnNumTicAparcados = this._Numero_Tiquets_Aparcados();
1405 
1406  if (lnNumTicAparcados > 0)
1407  {
1408  this._MessageBox("(_Save) Existen tickets aparcados.\n\nNo es posible cerrar el arqueo.");
1409  return false;
1410  }
1411 
1412  // Obtener nuevo número de arqueo ...
1413  do
1414  {
1415  // Obtener nuevo contador ...
1416  lcNumero = FUNCTIONS._SumaNumero(this._lcEmpresaActiva, "arqueo", "conftick", "tpv");
1417  if (this._lNetOffLine)
1418  // Modo desconectat del servidor de la xarxa, treballem en local
1419  lcNumero = this._lcLetraCajaActiva.Trim().PadLeft(2, '0') + this._lcCajaActiva.Substring(2, 2).Trim().PadLeft(2, '0') + lcNumero.Trim();
1420 
1421  // Si el arqueo ya existe, vamos al siguiente número de contador ...
1422  llConsultaOk = DB.SQLExec("select numero from " + DB.SQLDatabase("tpv", "arqueos") + " " +
1423  "where empresa=" + DB.SQLString(this._lcEmpresaActiva) + " and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " and " +
1424  "numero=" + DB.SQLString(Convert.ToInt32(lcNumero)), ref ldt_Arqueo);
1425  if (ldt_Arqueo.Rows.Count == 0)
1426  break;
1427  }
1428  while (true);
1429 
1430  // Lo asignamos a la propiedad privada, de esta forma no se disparan todos los eventos que sí se disparan al asignar la propiedad pública ..
1431  this._nNumero = Convert.ToInt32(lcNumero);
1432 
1433  // Crear registro en tabla TPV!ARQUEOS ...
1434  //PE-86774 Añadir numinit, numfint
1435  llRetorno = DB.SQLExec("insert into " + DB.SQLDatabase("tpv", "arqueos") + " " +
1436  "(usuario,empresa,ejercicio,caja,fecha,hora,numero, numinit, numfint ,tecleado, observacio, repencaja, letraini, letrafin) values (" +
1437  DB.SQLString(this._lcUsuarioTablas) + ", " +
1438  DB.SQLString(this._lcEmpresaActiva) + ", " +
1439  DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + ", " +
1440  DB.SQLString(this._lcCajaActiva) + ", " +
1441  DB.SQLString(this._dFecha) + ", " +
1442  DB.SQLString(DateTime.Now) + ", " +
1443  DB.SQLString(this._nNumero) + ", " +
1444  //PE-86774 Añadir numinit, numfint
1445  DB.SQLString(this._nNumero_Tiquet_Inicial.Replace("T", "")) + ", " +
1446  DB.SQLString(this._nNumero_Tiquet_Final.Replace("T", "")) + ", " +
1447  DB.SQLString(this._nImporteTecleado) + ", " +
1448  DB.SQLString(this._cObservaciones) + ", " +
1449  DB.SQLString(this._nImporteRepEnCaja) + ", "+
1450  DB.SQLString(this._nLetra_Tiquet_Inicial) + ", " + //PE-90183
1451  DB.SQLString(this._nLetra_Tiquet_Final) + ")"); //PE-90183
1452  if (!llRetorno)
1453  {
1454  this._MessageBox("(_Save) Error al insertar registro en la tabla tpv!arqueos.");
1455  this._DesArquear();
1456  return false;
1457  }
1458 
1459  // PE-87745 - Unificar los UPDATE en una sola instrucción
1460 
1461 
1462 
1463  // Marcar registros de TPV!C_ALBVEN
1464  llRetorno = DB.SQLExec("update " + DB.SQLDatabase("tpv", "c_albven") + " " +
1465  "set arqueo=" + DB.SQLString(this._nNumero) + " " +
1466  "from " + DB.SQLDatabase("tpv", "c_albven") + " a " +
1467  "inner join " + DB.SQLDatabase("gestion", "c_albven") + " b " +
1468  "on a.empresa = b.empresa " +
1469  " and a.numero = b.numero " +
1470  " and a.letra = b.letra " +
1471  " and a.ejercicio = " + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
1472  "where a.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
1473  "and a.arqueo=0 " +
1474  "and b.fecha<=" + DB.SQLString(this._dFecha) + " " +
1475  "and a.caja=" + DB.SQLString(this._lcCajaActiva) + "; "+
1476 
1477  // Marcar registros de TPV!TIKETS
1478  "update " + DB.SQLDatabase("tpv", "tikets") + " " +
1479  "set arqueo=" + DB.SQLString(this._nNumero) + " " +
1480  "where ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
1481  "and empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
1482  "and arqueo=0 " +
1483  "and fecha<=" + DB.SQLString(this._dFecha) + " " +
1484  "and caja=" + DB.SQLString(this._lcCajaActiva) + "; "+
1485 
1486  // Marcar registros de TPV!VALES
1487  "update " + DB.SQLDatabase("tpv", "vales") + " " +
1488  "set arqueo=" + DB.SQLString(this._nNumero) + " " +
1489  "where ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
1490  "and empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
1491  "and arqueo=0 " +
1492  "and fecha<=" + DB.SQLString(this._dFecha) + " " +
1493  "and caja=" + DB.SQLString(this._lcCajaActiva) + "; "+
1494 
1495  // Marcar registros de TPV!REPOSI
1496  "update " + DB.SQLDatabase("tpv", "reposi") + " " +
1497  "set arqueo=" + DB.SQLString(this._nNumero) + " " +
1498  "where empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
1499  "and caja=" + DB.SQLString(this._lcCajaActiva) + " " +
1500  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
1501  "and arqueo=0 " +
1502  "and fecha<=" + DB.SQLString(this._dFecha) + "; " +
1503 
1504  // Marcar registros de TPV!COB_PAGO
1505  "update " + DB.SQLDatabase("tpv", "cob_pago") + " " +
1506  "set arqueo=" + DB.SQLString(this._nNumero) + " " +
1507  "where empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
1508  "and caja=" + DB.SQLString(this._lcCajaActiva) + " " +
1509  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
1510  "and arqueo=0 " +
1511  "and operacion='R' " +
1512  "and fecha<=" + DB.SQLString(this._dFecha));
1513  if (!llRetorno)
1514  {
1515  this._MessageBox("(_Save) Error al actualizar campo ARQUEO.");
1516  // Si hubo algun error ejecuto desarqueo para que desmarque lo que pudiera haber marcado hasta ese momento ...
1517  this._DesArquear();
1518  return false;
1519  }
1520 
1521 
1522  // Guardar datos en TPV!D_ARQUEO
1523 
1524  // Primero borramos cualquier resto que pudiera haber del arqueo ...
1525  llRetorno = DB.SQLExec("delete from " + DB.SQLDatabase("tpv", "d_arqueo") + " " +
1526  "where empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
1527  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
1528  "and arqueo=" + DB.SQLString(this._nNumero));
1529  if (!llRetorno)
1530  {
1531  this._MessageBox("(_Save) Error al borrar registro de tpv!d_arqueo.");
1532  this._DesArquear();
1533  return false;
1534  }
1535 
1536 
1537  // PE-87745 - Paralelisme
1538  bool llVentaTickets = false, llVentaAlbaranes = false, llVentaFacturas = false, llCobrosFacturas=false, llCobrosTickets = false, llCobrosVarios = false;
1539  bool llEntregasCuenta = false, llEntregasPedido = false, llPagosFacturas = false, llPagosVarios = false, llReposiciones = false, llRetiradas = false;
1540  bool llVales = false, llFormasCobros = false;
1541 
1542  Parallel.Invoke(
1543  () => llVentaTickets = _Guardar_Arqueo(_dtVentas_Tiquets, " VT"),
1544  () => llVentaAlbaranes = _Guardar_Arqueo(_dtVentas_Albaranes, " VA"),
1545  () => llVentaFacturas = _Guardar_Arqueo(_dtVentas_Facturas, " VF"),
1546  () => llCobrosFacturas = _Guardar_Arqueo(_dtOperCaja_Cobros_Facturas, " CF"),
1547  () => llCobrosTickets = _Guardar_Arqueo(_dtOperCaja_Cobros_Tiquets, " CT"),
1548  () => llCobrosVarios = _Guardar_Arqueo(_dtOperCaja_Cobros_Varios, " CV"),
1549  () => llEntregasCuenta = _Guardar_Arqueo(_dtOperCaja_Entregas_Cuenta_Albaranes, " EC"),
1550  () => llEntregasPedido = _Guardar_Arqueo(_dtOperCaja_Entregas_Cuenta_Pedidos, " EP"),
1551  () => llPagosFacturas = _Guardar_Arqueo(_dtOperCaja_Pagos_Facturas, " PF"),
1552  () => llPagosVarios = _Guardar_Arqueo(_dtOperCaja_Pagos_Varios, " PV"),
1553  () => llReposiciones = _Guardar_Arqueo(_dtOperCaja_Reposiciones, " RP"),
1554  () => llRetiradas = _Guardar_Arqueo(_dtOperCaja_Retiradas, " RT"),
1555  () => llVales = _Guardar_Arqueo(_dtOperCaja_Vales_Efectuados, " VE"),
1556  () => llFormasCobros = _Guardar_Formas_Cobro());
1557 
1558  // Registros de ventas de tiquets en las diferentes monedas detectadas ...
1559  if (!llVentaTickets)
1560  {
1561  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo VT.");
1562  this._DesArquear();
1563  return false;
1564  }
1565 
1566  // Registros de ventas de albaranes en las diferentes monedas detectadas ...
1567  if (!llVentaAlbaranes)
1568  {
1569  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo VA.");
1570  this._DesArquear();
1571  return false;
1572  }
1573 
1574  // Registros de ventas de facturas en las diferentes monedas detectadas ...
1575  if (!llVentaFacturas)
1576  {
1577  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo VA.");
1578  this._DesArquear();
1579  return false;
1580  }
1581 
1582  // Registros de cobros de facturas en las diferentes monedas detectadas ...
1583  if (!llCobrosFacturas)
1584  {
1585  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo CF.");
1586  this._DesArquear();
1587  return false;
1588  }
1589 
1590  // Registros de cobros de tiquets en las diferentes monedas detectadas ...
1591  if (!llCobrosTickets)
1592  {
1593  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo CT.");
1594  this._DesArquear();
1595  return false;
1596  }
1597 
1598  // Registros de cobros varios en las diferentes monedas detectadas ...
1599  if (!llCobrosVarios)
1600  {
1601  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo CV.");
1602  this._DesArquear();
1603  return false;
1604  }
1605 
1606  // Registros de entregas a cuenta de albaranes en las diferentes monedas detectadas ...
1607  if (!llEntregasCuenta)
1608  {
1609  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo EC.");
1610  this._DesArquear();
1611  return false;
1612  }
1613 
1614  // Registros de entregas a cuenta de pedidos en las diferentes monedas detectadas ...
1615  if (!llEntregasPedido)
1616  {
1617  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo EP.");
1618  this._DesArquear();
1619  return false;
1620  }
1621 
1622  // Registros de pagos de facturas en las diferentes monedas detectadas ...
1623  if (!llPagosFacturas)
1624  {
1625  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo PF.");
1626  this._DesArquear();
1627  return false;
1628  }
1629 
1630  // Registros de pagos varios en las diferentes monedas detectadas ...
1631  if (!llPagosVarios)
1632  {
1633  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo PV.");
1634  this._DesArquear();
1635  return false;
1636  }
1637 
1638  // Registros de reposiciones en las diferentes monedas detectadas ...
1639  if (!llReposiciones)
1640  {
1641  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo RP.");
1642  this._DesArquear();
1643  return false;
1644  }
1645 
1646  // Registros de retiradas en las diferentes monedas detectadas ...
1647  if (!llRetiradas)
1648  {
1649  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo RT.");
1650  this._DesArquear();
1651  return false;
1652  }
1653 
1654  // Registros de vales efectuados
1655  if (!llVales)
1656  {
1657  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo VE.");
1658  this._DesArquear();
1659  return false;
1660  }
1661 
1662  // Registros de arqueo de caja (formas de cobro efectivo) en las diferentes monedas detectadas ...
1663  if (!llFormasCobros)
1664  {
1665  this._MessageBox("(_Save) Error al insertar registro en tpv!d_arqueo (formas cobro efectivo).");
1666  this._DesArquear();
1667  return false;
1668  }
1669 
1670  if (this._Error == true)
1671  {
1672  llRetorno = false;
1673  this._MessageBox(this._Mensaje_Error);
1674  // Si hubo algun error ejecuto desarqueo para que desmarque lo que pudiera haber marcado hasta ese momento ...
1675  this._DesArquear();
1676  return false;
1677  }
1678 
1679  //CCR128982
1680  if (!this._Error) _UpdateOffLine(2);
1681 
1682  this._Addons_Save(TipoExecute.After);
1683 
1684 
1685  return (this._Error == false);
1686  }
1687 
1688 
1693  public virtual bool _Save_Observaciones()
1694  {
1695  bool llRetorno;
1696 
1697  // Si no tenemos numero o hay más de un arqueo no realizar la consulta
1698  if (this._nNumero == 0 && this._Numeros.Count > 1)
1699  return false;
1700 
1701  String lcNumero = Convert.ToString(this._nNumero);
1702  if (this._nNumero == 0)
1703  {
1704  KeyValuePair<string, string> itemFirst = _Numeros.First();
1705  lcNumero = itemFirst.Value;
1706  }
1707 
1708 
1709  llRetorno = DB.SQLExec("update " + DB.SQLDatabase("tpv", "arqueos") + " " +
1710  "set observacio=" + DB.SQLString(this._cObservaciones) + " " +
1711  "where ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
1712  "and empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
1713  "and numero=" + DB.SQLString(lcNumero));
1714 
1715  if (!llRetorno)
1716  {
1717  this._MessageBox("(_Save) Error al actualizar observaciones del ARQUEO.");
1718  return false;
1719  }
1720  return true;
1721  }
1722 
1723 
1724  // 90664
1728  public void _Arquear()
1729  {
1730  //this._DescargarDatos();
1731 
1732  this._Addons_Arquear(TipoExecute.Before);
1733 
1734  this._Load();
1735  this._Save();
1736 
1737  this._Addons_Arquear(TipoExecute.After);
1738  }
1739 
1740 
1744  public DataTable _DataTableCierreCaja(Dictionary<string, string> monedas = null)
1745  {
1746 
1747  //String tcCodigo;
1749  //DataTable dtArqueo = new DataTable();
1750 
1751  //tcCodigo = "*";
1752 
1755 
1756  //dtArqueo.Columns.Add("ini");
1757  //dtArqueo.Columns.Add("descripcion");
1758  //dtArqueo.Columns.Add("total");
1759  //dtArqueo.Columns.Add("tipo_fila");
1760  //dtArqueo.Columns.Add("tipo_navegacion");
1761 
1762  //if (monedas != null)
1763  //{
1764  // foreach (KeyValuePair<string, string> moneda in monedas)
1765  // {
1766  // if (tcCodigo == "*" || tcCodigo == moneda.Key)
1767  // {
1768  // dtArqueo.Columns.Add(String.Format("Importe {0}", moneda.Value));
1769  // }
1770  // }
1771  //}
1772 
1773  //T115439
1774  DataTable dtArqueo = new DataTable();
1775 
1776  dtArqueo.Columns.Add("ini");
1777  dtArqueo.Columns.Add("descripcion");
1778  dtArqueo.Columns.Add("total");
1779  dtArqueo.Columns.Add("tipo_fila");
1780  dtArqueo.Columns.Add("tipo_navegacion");
1781  dtArqueo.Columns.Add("moneda");
1782 
1783  return dtArqueo;
1784 
1785  }
1786 
1787 
1791  public DataTable _MontaArqueo()
1792  {
1793  Boolean llShowTotal = false;
1794  Int32 iFactSimpl;
1795  Decimal iTotal, iTotalFacturas, iTotalAlbaranes, iRetirosCaja, iTotalDesgloseFamilia, iImporteTecleado, iTotalTickets;
1796 
1797  this._Addons_MontaArqueo(TipoExecute.Before);
1798 
1799  //PE-86776
1800  ewMascara _oMascaraImport = new ewbase.ewMascara(ew.global.EW_GLOBAL._GetMascara(KeyDiccionarioMascara.wc_total));
1801  ewMascara _oMascaraPorcent = new ewbase.ewMascara(ew.global.EW_GLOBAL._GetMascara(KeyDiccionarioMascara.wc_tpc));
1802 
1803  String lcCadenaFormat = "{0:" + _oMascaraImport._Mascara_Net + "}";
1804 
1805  _oDtArqueo = _DataTableCierreCaja(this._Monedas);
1806 
1807  if (this._dtVentas_Facturas != null)
1808  {
1809  // PE-90183 - En el caso de trabajar con series de documentos, presentar la letra inicial y final de los tickets.
1810  String lcTicketIni = this._Numero_Tiquet_Inicial;
1811  String lcTicketFin = this._Numero_Tiquet_Final;
1812  if (_llFactSer)
1813  {
1814  lcTicketIni = String.IsNullOrEmpty(this._Letra_Tiquet_Inicial) || String.IsNullOrWhiteSpace(this._Letra_Tiquet_Inicial) ? lcTicketIni : new String(' ', 3) + this._Letra_Tiquet_Inicial + "-" + lcTicketIni.Trim();
1815  lcTicketFin = String.IsNullOrEmpty(this._Letra_Tiquet_Final) || String.IsNullOrWhiteSpace(this._Letra_Tiquet_Final) ? lcTicketFin : new String(' ', 3) + this._Letra_Tiquet_Final + "-" + lcTicketFin.Trim();
1816  }
1817 
1818 
1819  iFactSimpl = this._Numero_Tiquets;
1820  //Ventas
1821  _oDtArqueo.Rows.Add(_addRow(new Object[] { "I.", "VENTAS", "", 1, Navegacion.No }));
1822  _oDtArqueo.Rows.Add(_addRow(new Object[] { "", String.Format("Nº de Facturas Simplificadas:{0}", iFactSimpl), "", 0, Navegacion.VentasTickets }));
1823  _oDtArqueo.Rows.Add(_addRow(new Object[] { "", String.Format("Factura simplificada inicial:{0}", lcTicketIni), "", 0, Navegacion.VentasTickets }));
1824  _oDtArqueo.Rows.Add(_addRow(new Object[] { "", String.Format("Factura simplificada final:{0}", lcTicketFin), "", 0, Navegacion.VentasTickets }));
1825  _AddBlank();
1826 
1827  //T115439 Diferenciamos por moneda
1828  foreach (var loDicMoneda in _dicMonedas)
1829  {
1830  llShowTotal = false;
1831  iTotalTickets = iTotalFacturas = iTotalAlbaranes = 0;
1832  String lcMoneda = Convert.ToString(loDicMoneda.Key);
1833  String lcNombreMoneda = Convert.ToString(loDicMoneda.Value["nombre"]).Trim();
1834 
1835  List<DataRow> loRowsTiquets = (from loRowTiquets in this._dtVentas_Tiquets.AsEnumerable()
1836  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1837  select loRowTiquets).ToList();
1838 
1839  foreach (DataRow row in loRowsTiquets)
1840  {
1841  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.VentasTickets));
1842  iTotalTickets += Convert.ToDecimal(row["importediv"]);
1843  llShowTotal = true;
1844  }
1845 
1846  List<DataRow> loRowsAlbaranes = (from loRowTiquets in this._dtVentas_Albaranes.AsEnumerable()
1847  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1848  select loRowTiquets).ToList();
1849 
1850  foreach (DataRow row in loRowsAlbaranes)
1851  {
1852  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.VentasAlbaranes));
1853  iTotalAlbaranes += Convert.ToDecimal(row["importediv"]);
1854  llShowTotal = true;
1855  }
1856 
1857  List<DataRow> loRowsFacturas = (from loRowTiquets in this._dtVentas_Facturas.AsEnumerable()
1858  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1859  select loRowTiquets).ToList();
1860 
1861  foreach (DataRow row in loRowsFacturas)
1862  {
1863  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.VentasFacturas));
1864  iTotalFacturas += Convert.ToDecimal(row["importediv"]);
1865  llShowTotal = true;
1866  }
1867 
1868  Decimal lnTotal = iTotalFacturas + iTotalAlbaranes + iTotalTickets;
1869  if (llShowTotal)
1870  {
1871  _oDtArqueo.Rows.Add(_addRow(new Object[] { "", String.Format("Total ({0}) . . .", lcNombreMoneda), String.Format(lcCadenaFormat, lnTotal), 2, Navegacion.No }));
1872  _AddBlank();
1873  }
1874  }
1875 
1876  //Operaciones caja
1877  _oDtArqueo.Rows.Add(_addRow(new Object[] { "II.", "OPERACIONES CAJA", "", 1, Navegacion.No }));
1878 
1879  //T115439 Diferenciamos por moneda
1880  foreach (var loDicMoneda in _dicMonedas)
1881  {
1882  String lcMoneda = Convert.ToString(loDicMoneda.Key);
1883  String lcNombreMoneda = Convert.ToString(loDicMoneda.Value["nombre"]).Trim();
1884  llShowTotal = false;
1885 
1886  List<DataRow> loRowsReposiciones = (from loRowTiquets in this._dtOperCaja_Reposiciones.AsEnumerable()
1887  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1888  select loRowTiquets).ToList();
1889 
1890  iTotal = 0;
1891  //Reposiciones caja
1892  foreach (DataRow row in loRowsReposiciones)
1893  {
1894  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaReposiciones));
1895  iTotal += Convert.ToDecimal(row["importediv"]);
1896  llShowTotal = true;
1897  }
1898 
1899  List<DataRow> loRowsCobrosTickets = (from loRowTiquets in this._dtOperCaja_Cobros_Tiquets.AsEnumerable()
1900  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1901  select loRowTiquets).ToList();
1902 
1903  //Cobros facturas simplificadas
1904  foreach (DataRow row in loRowsCobrosTickets)
1905  {
1906  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaCobrosTickets));
1907  iTotal += Convert.ToDecimal(row["importediv"]);
1908  llShowTotal = true;
1909  }
1910 
1911  List<DataRow> loRowsVales = (from loRowTiquets in this._dtOperCaja_Vales_Efectuados.AsEnumerable()
1912  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1913  select loRowTiquets).ToList();
1914 
1915  foreach (DataRow row in loRowsVales)
1916  {
1917  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaValesEjecutados));
1918  iTotal += Convert.ToDecimal(row["importediv"]);
1919  llShowTotal = true;
1920  }
1921 
1922  List<DataRow> loRowsEntregasAlbaranes = (from loRowTiquets in this._dtOperCaja_Entregas_Cuenta_Albaranes.AsEnumerable()
1923  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1924  select loRowTiquets).ToList();
1925 
1926  //ENTREGAS A CUENTA
1927  foreach (DataRow row in loRowsEntregasAlbaranes)
1928  {
1929  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaEntregasCuentaAlbaranes));
1930  iTotal += Convert.ToDecimal(row["importediv"]);
1931  llShowTotal = true;
1932  }
1933 
1934  List<DataRow> loRowsEntregasPedidos = (from loRowTiquets in this._dtOperCaja_Entregas_Cuenta_Pedidos.AsEnumerable()
1935  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1936  select loRowTiquets).ToList();
1937 
1938  //ENTREGAS A CUENTA (PEDIDOS) - 91929
1939  foreach (DataRow row in loRowsEntregasPedidos)
1940  {
1941  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaEntregasCuentaPedidos));
1942  iTotal += Convert.ToDecimal(row["importediv"]);
1943  llShowTotal = true;
1944  }
1945 
1946  List<DataRow> loRowsCobrosVarios = (from loRowTiquets in this._dtOperCaja_Cobros_Varios.AsEnumerable()
1947  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1948  select loRowTiquets).ToList();
1949 
1950  //COBROS VAIOS
1951  foreach (DataRow row in loRowsCobrosVarios)
1952  {
1953  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaCobrosVarios));
1954  iTotal += Convert.ToDecimal(row["importediv"]);
1955  llShowTotal = true;
1956  }
1957 
1958  List<DataRow> loRowsCobrosFacturas = (from loRowTiquets in this._dtOperCaja_Cobros_Facturas.AsEnumerable()
1959  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1960  select loRowTiquets).ToList();
1961 
1962  //COBROS FACTURAS
1963  foreach (DataRow row in loRowsCobrosFacturas)
1964  {
1965  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaCobrosFacturas));
1966  iTotal += Convert.ToDecimal(row["importediv"]);
1967  llShowTotal = true;
1968  }
1969 
1970  List<DataRow> loRowsPagosVarios = (from loRowTiquets in this._dtOperCaja_Pagos_Varios.AsEnumerable()
1971  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1972  select loRowTiquets).ToList();
1973 
1974  //COBROS VARIOS
1975  foreach (DataRow row in loRowsPagosVarios)
1976  {
1977  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaPagosVarios));
1978  iTotal += Convert.ToDecimal(row["importediv"]);
1979  llShowTotal = true;
1980  }
1981 
1982  List<DataRow> loRowsPagosFacturas = (from loRowTiquets in this._dtOperCaja_Pagos_Facturas.AsEnumerable()
1983  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1984  select loRowTiquets).ToList();
1985 
1986  //RETIROS CAJA
1987  foreach (DataRow row in loRowsPagosFacturas)
1988  {
1989  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaPagosFacturas));
1990  iTotal += Convert.ToDecimal(row["importediv"]);
1991  llShowTotal = true;
1992  }
1993 
1994  List<DataRow> loRowsRetiros = (from loRowTiquets in this._dtOperCaja_Retiradas.AsEnumerable()
1995  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
1996  select loRowTiquets).ToList();
1997 
1998  foreach (DataRow row in loRowsRetiros)
1999  {
2000  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaRetiradas));
2001  iTotal += Convert.ToDecimal(row["importediv"]);
2002  llShowTotal = true;
2003  }
2004 
2005  if (llShowTotal)
2006  {
2007  _oDtArqueo.Rows.Add(_addRow(new Object[] { "", String.Format("Total ({0}) . . .", lcNombreMoneda), String.Format(lcCadenaFormat, iTotal), 2, Navegacion.No }));
2008  _AddBlank();
2009  }
2010  }
2011 
2012  //Arqueo caja
2013  _AddBlank();
2014  _oDtArqueo.Rows.Add(_addRow(new Object[] { "III.", "ARQUEO CAJA", "", 1, Navegacion.No }));
2015 
2016  //T115439 Diferenciamos por moneda
2017  foreach (var loDicMoneda in _dicMonedas)
2018  {
2019  String lcMoneda = Convert.ToString(loDicMoneda.Key);
2020  String lcNombreMoneda = Convert.ToString(loDicMoneda.Value["nombre"]).Trim();
2021  llShowTotal = false;
2022 
2023  List<DataRow> loRowsTotalFormaCobro = (from loRowTiquets in this._dtArqueo_Caja.AsEnumerable()
2024  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
2025  select loRowTiquets).ToList();
2026 
2027  iRetirosCaja = 0;
2028  foreach (DataRow row in loRowsTotalFormaCobro)
2029  {
2030  // 88164
2031  if (row[0].ToString() == "__")
2032  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.OperCajaValesEjecutados));
2033  else
2034  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.Caja));
2035  // fi 88164
2036 
2037  iRetirosCaja += Convert.ToDecimal(row["importediv"]);
2038  llShowTotal = true;
2039  }
2040 
2041  if (llShowTotal)
2042  {
2043  _oDtArqueo.Rows.Add(_addRow(new Object[] { "", String.Format("Total ({0}) . . .", lcNombreMoneda), String.Format(lcCadenaFormat, iRetirosCaja), 2, Navegacion.No }));
2044  if (lcMoneda != EW_GLOBAL._Empresa._Moneda ) _oDtArqueo.Rows.Add(_addRow(new Object[] { "", "", "", 0, Navegacion.No }));
2045  }
2046 
2047  if (lcMoneda == EW_GLOBAL._Empresa._Moneda)
2048  {
2049  iImporteTecleado = this._Afegir_Total_Tecleado_Diferencia(ref _oDtArqueo, lcCadenaFormat);
2050  this._ImporteRepEnCaja = this._ImporteRepEnCaja;
2051  this._ImporteTecleado = iImporteTecleado;
2052  _AddBlank();
2053  }
2054  }
2055 
2056  // PE-89939 - Mostrar el desglose por familias según la propiedad
2057  if (this._DesgloseFamilias)
2058  {
2059  _AddBlank();
2060  _oDtArqueo.Rows.Add(_addRow(new Object[] { "IV.", "DESGLOSE POR FAMILIAS", "", 1, Navegacion.No }));
2061 
2062  //T115439 Diferenciamos por moneda
2063  foreach (var loDicMoneda in _dicMonedas)
2064  {
2065  String lcMoneda = Convert.ToString(loDicMoneda.Key);
2066  String lcNombreMoneda = Convert.ToString(loDicMoneda.Value["nombre"]).Trim();
2067 
2068  //Desglose por familia
2069  iTotalDesgloseFamilia = 0;
2070  llShowTotal = false;
2071 
2072  List<DataRow> loRowsFamilia = (from loRowTiquets in this._dtDesg_Familias.AsEnumerable()
2073  where Convert.ToString(loRowTiquets["moneda"]) == Convert.ToString(lcMoneda)
2074  select loRowTiquets).ToList();
2075 
2076  foreach (DataRow row in loRowsFamilia)
2077  {
2078  _oDtArqueo.Rows.Add(_addRow(row, Navegacion.Familias));
2079  iTotalDesgloseFamilia += Convert.ToDecimal(row["importediv"]);
2080  llShowTotal = true;
2081  }
2082 
2083  if (llShowTotal)
2084  {
2085  _oDtArqueo.Rows.Add(_addRow(new Object[] { "", String.Format("Total ({0}) . . .", lcNombreMoneda), String.Format(lcCadenaFormat, iTotalDesgloseFamilia), 2, Navegacion.No }));
2086  _AddBlank();
2087  }
2088  }
2089  }
2090  }
2091 
2092  //gridCierreCaja.AutoGenerateColumns = false;
2093  //gridCierreCaja.DataSource = dtArqueo;
2094 
2095  this._Addons_MontaArqueo(TipoExecute.After);
2096 
2097  return _oDtArqueo;
2098  }
2099 
2100 
2107  public virtual decimal _Afegir_Total_Tecleado_Diferencia(ref DataTable tdtTable, string tcCadenaFormat)
2108  {
2109  tdtTable.Rows.Add(_addRow(new Object[] { "", "Tecleado", String.Format(tcCadenaFormat, this._ImporteTecleado), 2, Navegacion.No }));
2110  tdtTable.Rows.Add(_addRow(new Object[] { "", "Diferencia", String.Format(tcCadenaFormat, this._ImporteTecleado - this._ImporteEfectivoArqueo), 2, Navegacion.No })); //PE-90300
2111 
2112  return this._ImporteTecleado;
2113  }
2114 
2115 
2120  public virtual bool _DesArquear()
2121  {
2122  bool llRetorno = false;
2123  DataTable ldt_Cursor = new DataTable();
2124  DataTable ldt_CurMax = new DataTable();
2125  //string lcAuxi1 = "", lcAuxi2 = "", lcAuxi3 = "", lcAuxi4 = "";
2126  //int lnAuxi1 = 0, lnAuxi2 = 0, lnLinea = 0;
2127  //DateTime ldAuxi1;
2128  string lcOperarioTpv = Convert.ToString(EW_GLOBAL._GetVariable("wc_operariotpv"));
2129 
2130  this._Error = false;
2131  this._Mensaje_Error = "";
2132 
2133  this._Addons_DesArquear(TipoExecute.Before);
2134 
2135  // 90188
2136  //if (!this._lArqueoCargado)
2137  //{
2138  // this._MessageBox("No se puede desarquear un arqueo sin haber carga anter un arqueo ya existente.");
2139  // return false;
2140  //}
2141  // fi 90188
2142 
2143  // Comproobar que estamos en un arqueo con número, es decir, cerrado con anterioridad ...
2144  if (this._nNumero == 0)
2145  {
2146  this._MessageBox("No se puede desarquear un arqueo sin haber asignado número al arqueo. Debe estar situado en un arqueo ya cerrado con anterioridad.");
2147  return false;
2148  }
2149 
2150  // Comprobar que el usuario tenga permisos para desarquear ...
2151  if (this._lcUsuario != "SUPERVISOR")
2152  {
2153  if (!string.IsNullOrWhiteSpace(lcOperarioTpv))
2154  {
2155  if (!Convert.ToBoolean(DB.SQLValor("opc_user", "opctpv='08' and operario", lcOperarioTpv, "valor", "comunes")))
2156  {
2157  this._MessageBox("El operario de TPV '" + lcOperarioTpv + "' no tiene permisos para desarquear.","",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
2158  return false;
2159  }
2160  }
2161  }
2162 
2163  _UpdateOffLine(2); //CCR128982
2164 
2165  // Desmarcar registros de TPV!C_ALBVEN
2166  llRetorno = DB.SQLExec("update " + DB.SQLDatabase("tpv", "c_albven") + " " +
2167  "set usuario = " + DB.SQLString(this._lcUsuarioTablas) + ", " +
2168  "arqueo=0 " +
2169  "where arqueo=" + DB.SQLString(this._nNumero) + " " +
2170  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2171  "and empresa=" + DB.SQLString(this._lcEmpresaActiva));
2172  if (!llRetorno)
2173  {
2174  this._MessageBox("(_Desarquear) Error al poner a 0 el campo ARQUEO de tpv!c_albven.");
2175  return false;
2176  }
2177 
2178  // Desmarcar registros de TPV!TIKETS
2179  llRetorno = DB.SQLExec("update " + DB.SQLDatabase("tpv", "tikets") + " " +
2180  "set usuario = " + DB.SQLString(this._lcUsuarioTablas) + ", " +
2181  "arqueo=0 " +
2182  "where arqueo=" + DB.SQLString(this._nNumero) + " " +
2183  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2184  "and empresa=" + DB.SQLString(this._lcEmpresaActiva));
2185  if (!llRetorno)
2186  {
2187  this._MessageBox("(_Desarquear) Error al poner a 0 el campo ARQUEO de tpv!tikets.");
2188  }
2189 
2190 
2191  // Desmarcar registros de TPV!VALES
2192  llRetorno = DB.SQLExec("update " + DB.SQLDatabase("tpv", "vales") + " " +
2193  "set usuario = " + DB.SQLString(this._lcUsuarioTablas) + ", " +
2194  "arqueo=0 " +
2195  "where arqueo=" + DB.SQLString(this._nNumero) + " " +
2196  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2197  "and empresa=" + DB.SQLString(this._lcEmpresaActiva));
2198  if (!llRetorno)
2199  {
2200  this._MessageBox("(_Desarquear) Error al poner a 0 el campo ARQUEO de tpv!vales.");
2201  }
2202 
2203  /*
2204 
2205  // Desmarcar registros de TPV!REPOSI, en este caso no es tan facil pues al dejar el campo ARQUEO a 0, podria petar el indice primario, por tal como está
2206  // construida la clave primaria de esta tabla (EMPRESA,CAJA,MONEDA,OPERARIO,LINEA,ARQUEO,FECHA)
2207  llRetorno = DB.SQLExec("select * from " + DB.SQLDatabase("tpv", "reposi") + " " +
2208  "where arqueo=" + DB.SQLString(this._nNumero) + " " +
2209  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2210  "and empresa=" + DB.SQLString(this._lcEmpresaActiva), ref ldt_Cursor);
2211  if (!llRetorno)
2212  {
2213  this._MessageBox("(_Desarquear) Error al seleccionar las reposiciones a actualizar de tpv!reposi.");
2214  }
2215 
2216 
2217  // A todas las reposiciones correspondientes al arqueo hay que actualizar el campo LINEA antes de poner el campo ARQUEO a 0, para prevenir posibles petadas
2218  // del índice primario.
2219  foreach (DataRow r in ldt_Cursor.Rows)
2220  {
2221  lcAuxi1 = Convert.ToString(r["empresa"]);
2222  lcAuxi2 = Convert.ToString(r["caja"]);
2223  lcAuxi3 = Convert.ToString(r["moneda"]);
2224  lcAuxi4 = Convert.ToString(r["operario"]);
2225  lnAuxi1 = Convert.ToInt32(r["linea"]);
2226  lnAuxi2 = Convert.ToInt32(r["arqueo"]);
2227  ldAuxi1 = Convert.ToDateTime(r["fecha"]);
2228 
2229  lnLinea = lnAuxi1;
2230 
2231  ldt_CurMax.Reset();
2232 
2233  llRetorno = DB.SQLExec("select max(linea) as linea from " + DB.SQLDatabase("tpv", "reposi") + " " +
2234  "where empresa=" + DB.SQLString(lcAuxi1) + " " +
2235  "and caja=" + DB.SQLString(lcAuxi2) + " " +
2236  "and moneda=" + DB.SQLString(lcAuxi3) + " " +
2237  "and operario=" + DB.SQLString(lcAuxi4) + " " +
2238  "and fecha=" + DB.SQLString(ldAuxi1), ref ldt_CurMax);
2239  if (!llRetorno)
2240  {
2241  this._MessageBox("(_Desarquear) Error al seleccionar la máxima linia en las reposiciones de tpv!reposi.");
2242  }
2243 
2244  lnLinea = ldt_CurMax.Rows.Count > 0 ? Convert.ToInt32(ldt_CurMax.Rows[0]["linea"]) + 1 : 1;
2245 
2246  // Actualizar el campo LINEA del registro de TPV!REPOSI
2247  llRetorno = DB.SQLExec("update " + DB.SQLDatabase("tpv", "reposi") + " " +
2248  "set usuario = " + DB.SQLString(this._lcUsuarioTablas) + ", " +
2249  "linea=" + DB.SQLString(lnLinea) + " " +
2250  "where empresa=" + DB.SQLString(lcAuxi1) + " " +
2251  "and caja=" + DB.SQLString(lcAuxi2) + " " +
2252  "and moneda=" + DB.SQLString(lcAuxi3) + " " +
2253  "and operario=" + DB.SQLString(lcAuxi4) + " " +
2254  "and fecha=" + DB.SQLString(ldAuxi1) + " " +
2255  "and linea=" + DB.SQLString(lnAuxi1) + " " +
2256  "and arqueo=" + DB.SQLString(lnAuxi2));
2257  if (!llRetorno)
2258  {
2259  this._MessageBox("(_Desarquear) Error al actualizar el campo LINIA de las reposiciones de tpv!reposi.");
2260  }
2261  }
2262  */
2263 
2264  // Ahora sí, ya podemos poner el campo ARQUEO a 0 en TPV!REPOSI que seguro que ya no petará el índice.
2265  llRetorno = DB.SQLExec("update " + DB.SQLDatabase("tpv", "reposi") + " " +
2266  "set usuario = " + DB.SQLString(this._lcUsuarioTablas) + ", " +
2267  "arqueo=0 " +
2268  "where arqueo=" + DB.SQLString(this._nNumero) + " " +
2269  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2270  "and empresa=" + DB.SQLString(this._lcEmpresaActiva));
2271  if (!llRetorno)
2272  {
2273  this._MessageBox("(_Desarquear) Error al poner a 0 el campo ARQUEO de tpv!reposi.");
2274  }
2275 
2276  // Continuamos con las siguientes tablas ...
2277 
2278  // Desmarcar registros de TPV!COB_PAGO
2279  llRetorno = DB.SQLExec("update " + DB.SQLDatabase("tpv", "cob_pago") + " " +
2280  "set usuario = " + DB.SQLString(this._lcUsuarioTablas) + ", " +
2281  "arqueo=0 " +
2282  "where arqueo=" + DB.SQLString(this._nNumero) + " " +
2283  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2284  "and empresa=" + DB.SQLString(this._lcEmpresaActiva));
2285  if (!llRetorno)
2286  {
2287  this._MessageBox("(_Desarquear) Error al poner a 0 el campo ARQUEO de tpv!cob_pago.");
2288  }
2289 
2290  // Borrar registro de tpv!d_arqueo
2291  llRetorno = DB.SQLExec("delete from " + DB.SQLDatabase("tpv", "d_arqueo") + " " +
2292  "where empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
2293  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2294  "and arqueo=" + DB.SQLString(this._nNumero));
2295  if (!llRetorno)
2296  {
2297  this._MessageBox("(_Desarquear) Error al borrar registros de tpv!d_arqueo.");
2298  }
2299 
2300 
2301  // Borrar registro de TPV!ARQUEOS
2302  llRetorno = DB.SQLExec("delete from " + DB.SQLDatabase("tpv", "arqueos") + " " +
2303  "where empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
2304  "and ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2305  "and numero=" + DB.SQLString(this._nNumero));
2306  if (!llRetorno)
2307  {
2308  this._MessageBox("(_Desarquear) Error al borrar registro de tpv!arqueos.");
2309  }
2310 
2311  // Si no hubo ningún error intento retroceder el número ...
2312  if (this._Error == false)
2313  FUNCTIONS._RestaNumero(this._lcEmpresaActiva, this._nNumero, "arqueo", "conftick", "tpv");
2314 
2315  this._Addons_DesArquear(TipoExecute.After);
2316 
2317  return (this._Error == false);
2318  }
2319 
2320 
2325  public virtual void _Obtener_DataTable_Arqueo_Caja()
2326  {
2327 #if ewTools
2328  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
2329 #endif
2330 
2331  DataTable ldt_tmp_tic = new DataTable();
2332  DataTable ldt_tmp_rep = new DataTable();
2333  DataTable ldt_tmp_ret = new DataTable();
2334  bool llConsulta1_Ok = false;
2335  bool llConsulta2_Ok = false;
2336  bool llConsulta3_Ok = false;
2337  int lnDecimales_MonedaEmpresa = Convert.ToInt32(DB.SQLValor("moneda", "codigo", this._lcMoneda_Empresa, "DECIMALES"));
2338  decimal lnTotal = 0.0M;
2339 
2340  this._Addons_Obtener_DataTable_Arqueo_Caja(TipoExecute.Before);
2341 
2342  // Inicializar propiedad del objeto que guarda el importe del arqueo y el importe del total efectivo en caja ...
2343  this._nImporteArqueo = 0.0M;
2344  this._nImporteEfectivoArqueo = 0.0M;
2345 
2346  DataRow row;
2347  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
2348  int lnDecimalesMascara;
2349 
2350  object[,] la_array_cursor = { { "fcobro", "string", 2, "Y" }, { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
2351  this._dtArqueo_Caja = DBfunctions._Crear_DtTable(la_array_cursor);
2352 
2353  // 87748
2354  string lcCondicion = string.Empty;
2355  if (!string.IsNullOrWhiteSpace(_CajaDesde))
2356  lcCondicion = lcCondicion + " and tikets.caja >= " + DB.SQLString(_CajaDesde);
2357 
2358  if (!string.IsNullOrWhiteSpace(_CajaHasta))
2359  lcCondicion = lcCondicion + " and tikets.caja <= " + DB.SQLString(_CajaHasta);
2360 
2361  if (_FechaDesde != null)
2362  lcCondicion = lcCondicion + " and tikets.fecha >= " + DB.SQLString(_FechaDesde);
2363 
2364  if (_FechaHasta != null)
2365  lcCondicion = lcCondicion + " and tikets.fecha <= " + DB.SQLString(_FechaHasta);
2366 
2367  if (string.IsNullOrWhiteSpace(lcCondicion))
2368  lcCondicion = "and " + _makeId("tikets", "tikets.arqueo=" + DB.SQLString(this._nNumero) + (this._nNumero == 0 ? " and tikets.fecha<=" + DB.SQLString(this._dFecha) + " and tikets.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
2369  // fi 87748
2370 
2371  // Consulta de cobros en caja en efectivo ...
2372  llConsulta1_Ok = DB.SQLExec("select tikets.forma_cob as fcobro, tikets.moneda, " +
2373  "Sum(tikets.entrega-tikets.cambio_e) as importediv, " +
2374  "max(" + DB.SQLNvl("fcobros.efectivo", "0") + ") as efectivo, " +
2375  DB.SQLNvl("Sum(Round(" + DB.SQLIif("moneda.cme=1", "(tikets.entrega-tikets.cambio_e)/tikets.cotizacion", "(tikets.entrega-tikets.cambio_e)*tikets.cotizacion") + "," + lnDecimales_MonedaEmpresa.ToString() + "))", 0) + " as importe " +
2376  "from ((" + DB.SQLDatabase("tpv", "tikets") + " inner join " + DB.SQLDatabase("gestion", "moneda") + " on tikets.moneda=moneda.codigo) " +
2377  "left join " + DB.SQLDatabase("tpv", "f_cobros") + " fcobros on tikets.forma_cob = fcobros.codigo) " +
2378  "where tikets.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2379  "and tikets.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
2380  lcCondicion +
2381  "group by tikets.forma_cob,tikets.moneda", ref ldt_tmp_tic);
2382  if (!llConsulta1_Ok)
2383  {
2384  this._MessageBox("(_Load) Error en consulta de cobros en efectivo en _Obtener_DataTable_Arqueo_Caja().");
2385  }
2386 
2387  // 87748
2388  lcCondicion = string.Empty;
2389  if (!string.IsNullOrWhiteSpace(_CajaDesde))
2390  lcCondicion = lcCondicion + " and reposi.caja >= " + DB.SQLString(_CajaDesde);
2391 
2392  if (!string.IsNullOrWhiteSpace(_CajaHasta))
2393  lcCondicion = lcCondicion + " and reposi.caja <= " + DB.SQLString(_CajaHasta);
2394 
2395  if (_FechaDesde != null)
2396  lcCondicion = lcCondicion + " and reposi.fecha >= " + DB.SQLString(_FechaDesde);
2397 
2398  if (_FechaHasta != null)
2399  lcCondicion = lcCondicion + " and reposi.fecha <= " + DB.SQLString(_FechaHasta);
2400 
2401  if (string.IsNullOrWhiteSpace(lcCondicion))
2402  lcCondicion = "and " + _makeId("reposi", "reposi.arqueo=" + DB.SQLString(this._nNumero) + (this._nNumero == 0 ? " and reposi.fecha<=" + DB.SQLString(this._dFecha) + " and reposi.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
2403  // fi 87748
2404 
2405  // Consulta de reposiciones ...
2406  llConsulta2_Ok = DB.SQLExec("select " + DB.SQLNvl("f_cobros.codigo", "space(2)") + " as fcobro, reposi.moneda, " +
2407  "max(" + DB.SQLNvl("f_cobros.efectivo", "0") + ") as efectivo, " +
2408  "Sum(reposi.reposicion) as importediv, " +
2409  DB.SQLNvl("Sum(" + DB.SQLIif("moneda.cme=1", "reposi.reposicion/reposi.cambio", "reposi.reposicion*reposi.cambio") + ")", 0) + " as importe " +
2410  "from ((" + DB.SQLDatabase("tpv", "reposi") + " inner join " + DB.SQLDatabase("gestion", "moneda") + " on reposi.moneda=moneda.codigo) " +
2411  "left join " + DB.SQLDatabase("tpv", "f_cobros") + " on f_cobros.moneda = reposi.moneda and f_cobros.efectivo=1) " +
2412  "where reposi.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2413  "and reposi.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
2414  lcCondicion +
2415  "group by f_cobros.codigo, reposi.moneda", ref ldt_tmp_rep);
2416  if (!llConsulta2_Ok)
2417  {
2418  this._MessageBox("(_Load) Error en consulta de reposiciones en _Obtener_DataTable_Arqueo_Caja().");
2419  }
2420 
2421  // 87748
2422  lcCondicion = string.Empty;
2423  if (!string.IsNullOrWhiteSpace(_CajaDesde))
2424  lcCondicion = lcCondicion + " and cob_pago.caja >= " + DB.SQLString(_CajaDesde);
2425 
2426  if (!string.IsNullOrWhiteSpace(_CajaHasta))
2427  lcCondicion = lcCondicion + " and cob_pago.caja <= " + DB.SQLString(_CajaHasta);
2428 
2429  if (_FechaDesde != null)
2430  lcCondicion = lcCondicion + " and cob_pago.fecha >= " + DB.SQLString(_FechaDesde);
2431 
2432  if (_FechaHasta != null)
2433  lcCondicion = lcCondicion + " and cob_pago.fecha <= " + DB.SQLString(_FechaHasta);
2434 
2435  if (string.IsNullOrWhiteSpace(lcCondicion))
2436  lcCondicion = "and " + _makeId("cob_pago", "cob_pago.arqueo=" + DB.SQLString(this._nNumero) + (this._nNumero == 0 ? " and cob_pago.fecha<=" + DB.SQLString(this._dFecha) + " and cob_pago.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
2437  // fi 87748
2438 
2439  // Consulta de retiradas ...
2440  llConsulta3_Ok = DB.SQLExec("select " + DB.SQLNvl("f_cobros.codigo", "space(2)") + " as fcobro, cob_pago.moneda, " +
2441  "max(" + DB.SQLNvl("f_cobros.efectivo", "0") + ") as efectivo, " +
2442  "Sum(cob_pago.importediv)*-1 as importediv, " +
2443  "Sum(cob_pago.importe)*-1 as importe " +
2444  "from (" + DB.SQLDatabase("tpv", "cob_pago") + " " +
2445  "left join " + DB.SQLDatabase("tpv", "f_cobros") + " on f_cobros.moneda = cob_pago.moneda and f_cobros.efectivo=1 ) " +
2446  "where cob_pago.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
2447  "and cob_pago.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
2448  "and cob_pago.operacion='R' " +
2449  lcCondicion +
2450  "group by f_cobros.codigo,cob_pago.moneda", ref ldt_tmp_ret);
2451  if (!llConsulta3_Ok)
2452  {
2453  this._MessageBox("(_Load) Error en consulta de retiradas en _Obtener_DataTable_Arqueo_Caja().");
2454  }
2455 
2456  if (llConsulta1_Ok == true && llConsulta2_Ok == true && llConsulta3_Ok == true)
2457  {
2458  decimal lnEfectivoTickets = ldt_tmp_tic.AsEnumerable().Where(lin => lin["importe"] != null && Convert.ToInt32(lin["efectivo"]) == 1 && Convert.ToString(lin["moneda"]) == EW_GLOBAL._Empresa._Moneda).Sum(lin => Convert.ToDecimal(lin["importe"]));
2459  decimal lnEfectivoReposiciones = ldt_tmp_rep.AsEnumerable().Where(lin => lin["importe"] != null && Convert.ToString(lin["moneda"]) == EW_GLOBAL._Empresa._Moneda).Sum(lin => Convert.ToDecimal(lin["importe"]));
2460 
2461  // Este importe ya viene en negativo al ser una retirada ...
2462  decimal lnEfectivoRetiros = ldt_tmp_ret.AsEnumerable().Where(lin => lin["importe"] != null && Convert.ToString(lin["moneda"]) == EW_GLOBAL._Empresa._Moneda).Sum(lin => Convert.ToDecimal(lin["importe"]));
2463 
2464  // Total import en efectivo en caja ...
2465  decimal lnImporteEfectivo = lnEfectivoTickets + lnEfectivoReposiciones + lnEfectivoRetiros;
2466 
2467  this._nImporteEfectivoArqueo = lnImporteEfectivo;
2468 
2469  // Primero haremos el FULLJOIN de tmp_tic i tmp_rep, el resultado del mismo lo guardaremos en el DataTable temporal ldt_PrimerFullJoin
2470  DataTable ldt_PrimerFullJoin = ldt_tmp_tic.Clone();
2471 
2472  // Creamos también el DataTable que guardaremos el resultado del FULL JOIN total ...
2473  DataTable ldt_ResFullJoin = ldt_tmp_tic.Clone();
2474 
2475  try
2476  {
2477 
2478  // Para hacer un FULL JOIN de dos tablas comn LINK, primero haremos el LEFT JOIN de la primera con la segunda, y luego para simular el RIGHT JOIN de la segunda con la primera
2479  // haremos otro LEFT JOIN invirtiendo el orden de las dos tablas, la que estaba a la izquierda pasa a la derecha y la que estaba a la derecha pasa a la izquierda.
2480  // Una vez tenemos los dos resultados los unimos con un UNION y tenemos el resultado del FULL JOIN de las dos primeras tablas.
2481  var loPrimerFullJoinLeft = from tic in ldt_tmp_tic.AsEnumerable()
2482  join rep in ldt_tmp_rep.AsEnumerable()
2483  on new { a = tic.Field<string>("fcobro"), b = tic.Field<string>("moneda") } equals
2484  new { a = rep.Field<string>("fcobro"), b = rep.Field<string>("moneda") } into temp
2485  from itemright in temp.DefaultIfEmpty()
2486  select new
2487  {
2488  fcobro = tic.Field<string>("fcobro"),
2489  moneda = tic.Field<string>("moneda"),
2490  importediv = tic.Field<decimal>("importediv") + (itemright == null ? 0.0M : itemright.Field<decimal>("importediv")),
2491  importe = tic.Field<decimal>("importe") + (itemright == null ? 0.0M : itemright.Field<decimal>("importe"))
2492  };
2493 
2494  // Este segundo JOIN es identico al primero excepto que hemos "girado" el orden de las tablas, la de la izquierda pasa a la derecha y la de la derecha pasa a la izquierda ...
2495  var loPrimerFullJoinRight = from rep in ldt_tmp_rep.AsEnumerable()
2496  join tic in ldt_tmp_tic.AsEnumerable()
2497  on new { a = rep.Field<string>("fcobro"), b = rep.Field<string>("moneda") } equals
2498  new { a = tic.Field<string>("fcobro"), b = tic.Field<string>("moneda") } into temp
2499  from itemright in temp.DefaultIfEmpty()
2500  select new
2501  {
2502  fcobro = rep.Field<string>("fcobro"),
2503  moneda = rep.Field<string>("moneda"),
2504  importediv = rep.Field<decimal>("importediv") + (itemright == null ? 0.0M : itemright.Field<decimal>("importediv")),
2505  importe = rep.Field<decimal>("importe") + (itemright == null ? 0.0M : itemright.Field<decimal>("importe"))
2506  };
2507 
2508  // Aqui unimos los resultados de las dos consultas anteriores y tenemos ya el resultado del primer FULL JOIN, recordar que el Union() de Linq excluye del resultado
2509  // los registros duplicados.
2510  var loPrimerFullJoin = loPrimerFullJoinLeft.Union(loPrimerFullJoinRight);
2511 
2512  // Guardamos los resultados de este primer FULL JOIN en el DataTable ldt_PrimerFullJoin.
2513  foreach (var r in loPrimerFullJoin)
2514  {
2515  row = ldt_PrimerFullJoin.NewRow();
2516  row["fcobro"] = r.fcobro;
2517  row["moneda"] = r.moneda;
2518  row["importediv"] = r.importe;
2519  row["importe"] = r.importediv;
2520  ldt_PrimerFullJoin.Rows.Add(row);
2521  }
2522  }
2523  catch (Exception oE)
2524  {
2525  this._MessageBox("(_Load) Error en primer FULL JOIN en _Obtener_DataTable_Arqueo_Caja().\n\n" + oE.Message);
2526  }
2527 
2528  // Hasta aqui tenemos hecho el primer FULL JOIN de las dos primeras tablas tmp_tic i tmp_rep, y tenemos us resultado en el DataTable ldt_PrimerFullJoin, haremos
2529  // el FULL JOIN de este datatable con el tmp_ret
2530 
2531  // LEFT JOIN entre los DataTable ldt_PrimerFullJoin y ldt_tmp_ret
2532  try
2533  {
2534  var loSegundoFullJoinLeft = from ticrep in ldt_PrimerFullJoin.AsEnumerable()
2535  join ret in ldt_tmp_ret.AsEnumerable()
2536  on new { a = ticrep.Field<string>("fcobro"), b = ticrep.Field<string>("moneda") } equals
2537  new { a = ret.Field<string>("fcobro"), b = ret.Field<string>("moneda") } into temp
2538  from itemright in temp.DefaultIfEmpty()
2539  select new
2540  {
2541  fcobro = ticrep.Field<string>("fcobro"),
2542  moneda = ticrep.Field<string>("moneda"),
2543  importediv = ticrep.Field<decimal>("importediv") + (itemright == null ? 0.0M : itemright.Field<decimal>("importediv")),
2544  importe = ticrep.Field<decimal>("importe") + (itemright == null ? 0.0M : itemright.Field<decimal>("importe"))
2545  };
2546 
2547  // RIGHT JOIN entre los DataTable ldt_PrimerFullJoin y ldt_tmp_ret, para ellos hacemos un LEFT JOIN entre ldt_tmp_ret y ldt_PrimerFullJoin ...
2548  var loSegundoFullJoinRight = from ret in ldt_tmp_ret.AsEnumerable()
2549  join ticrep in ldt_PrimerFullJoin.AsEnumerable()
2550  on new { a = ret.Field<string>("fcobro"), b = ret.Field<string>("moneda") } equals
2551  new { a = ticrep.Field<string>("fcobro"), b = ticrep.Field<string>("moneda") } into temp
2552  from itemright in temp.DefaultIfEmpty()
2553  select new
2554  {
2555  fcobro = ret.Field<string>("fcobro"),
2556  moneda = ret.Field<string>("moneda"),
2557  importediv = ret.Field<decimal>("importediv") + (itemright == null ? 0.0M : itemright.Field<decimal>("importediv")),
2558  importe = ret.Field<decimal>("importe") + (itemright == null ? 0.0M : itemright.Field<decimal>("importe"))
2559  };
2560 
2561  // Unimos los resultados de las dos consultas anteriores, recordar que el Union() de Linq excluye del resultado
2562  // los registros duplicados
2563  var loSegundoFullJoin = loSegundoFullJoinLeft.Union(loSegundoFullJoinRight);
2564 
2565  // Añadir registros de la consulta al DataTable ldt_ResFullJoin donde guardamos el resultado del FULL JOIN de los tres DataTables que teniamos originalmente ...
2566  foreach (var r in loSegundoFullJoin)
2567  {
2568  row = ldt_ResFullJoin.NewRow();
2569  row["fcobro"] = r.fcobro;
2570  row["moneda"] = r.moneda;
2571  row["importediv"] = r.importe;
2572  row["importe"] = r.importediv;
2573  ldt_ResFullJoin.Rows.Add(row);
2574  }
2575  }
2576  catch (Exception oE)
2577  {
2578  this._MessageBox("(_Load) Error en segundo FULL JOIN en _Obtener_DataTable_Arqueo_Caja().\n\n" + oE.Message);
2579  }
2580 
2581  try
2582  {
2583 
2584  if (ldt_ResFullJoin.Rows.Count > 0)
2585  {
2586  foreach (DataRow r in ldt_ResFullJoin.Rows)
2587  {
2588  string lcMoneda = Convert.ToString(r["moneda"]);
2589  if (string.IsNullOrWhiteSpace(lcMoneda))
2590  lcMoneda = this._lcMoneda_Empresa;
2591 
2592  //PE-77346
2593  //loDicMoneda = DB.SQLREGValor("moneda", "codigo", lcMoneda);
2594  loDicMoneda = _Moneda(lcMoneda);
2595  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
2596 
2597  row = this._dtArqueo_Caja.NewRow();
2598 
2599  row["descripcion"] = Convert.ToString(DB.SQLValor("f_cobros", "codigo", Convert.ToString(r["fcobro"]), "nombre", "tpv"));
2600 
2601  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
2602 
2603  row["moneda"] = lcMoneda;
2604 
2605  //PE-77346
2606  //row["importe"] = Divisa._DivExacto(Divisa._Ultima_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
2607  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
2608 
2609  row["fcobro"] = Convert.ToString(r["fcobro"]);
2610  this._dtArqueo_Caja.Rows.Add(row);
2611  lnTotal = lnTotal + Convert.ToDecimal(r["importe"]);
2612  }
2613  }
2614 
2615 
2616  // Consulta de valoes si no la hemos hecho antes ...
2617  if (this._dtOperCaja_Vales_Efectuados.Rows.Count == 0)
2618  {
2619  String lcMsgError = "";
2620  decimal lnTotalVales = 0.0M;
2621  this._dtOperCaja_Vales_Efectuados = this._Obtener_DataTable_OperCaja_Vales_Efectuados(ref lnTotalVales, ref lcMsgError);
2622  this._MessageBox(lcMsgError);
2623  }
2624 
2625 
2626  // Vales efectuados ...
2627  foreach (DataRow r in this._dtOperCaja_Vales_Efectuados.Rows)
2628  {
2629  if (Convert.ToDecimal(r["importe"]) != 0)
2630  {
2631  string lcMoneda = Convert.ToString(r["moneda"]);
2632  if (string.IsNullOrWhiteSpace(lcMoneda)) lcMoneda = this._lcMoneda_Empresa;
2633  loDicMoneda = _Moneda(lcMoneda);
2634  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
2635 
2636  row = this._dtArqueo_Caja.NewRow();
2637  row["descripcion"] = "Vales efectuados";
2638  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
2639  row["moneda"] = lcMoneda;
2640 
2641  //PE-77346
2642  //row["importe"] = Divisa._DivExacto(Divisa._Ultima_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
2643  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
2644  row["fcobro"] = "__";
2645 
2646  this._dtArqueo_Caja.Rows.Add(row);
2647  lnTotal = lnTotal + Convert.ToDecimal(r["importe"]);
2648  }
2649  }
2650 
2651  // Actualizar el campo ImporteArqueo del objeto arqueo ...
2652  this._nImporteArqueo = lnTotal;
2653  }
2654  catch (Exception oE)
2655  {
2656  this._MessageBox("(_Load) Error en procesos finales en _Obtener_DataTable_Arqueo_Caja().\n\n" + oE.Message);
2657  }
2658  }
2659 
2660  this._Addons_Obtener_DataTable_Arqueo_Caja(TipoExecute.After);
2661 
2662 #if ewTools
2663  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
2664 #endif
2665  }
2666 
2667 
2671  public void _Print(TiposDeArqueos teTipoDeArqueo, string tcFileXMLDatos, string tcCaption = "")
2672  {
2673  ArqueoTpv loArqueo = new ArqueoTpv();
2674  String lcArqueos = "";
2675  String lcArqueosFecha = "";
2676  Dictionary<string, object> loDicRegArqueo;
2677  DateTime ldFechaArqueo = new DateTime();
2678 
2679  this._Addons_Print(TipoExecute.Before, teTipoDeArqueo, tcFileXMLDatos, tcCaption);
2680 
2681  // PE-90528 - Pasar los números y fechas de los arqueos
2682  foreach (KeyValuePair<string, string> itemNum in this._Numeros)
2683  {
2684 
2685  // Esto lo hacemos para evitar tener que hacer el loArqueo._Numero = Convert.ToInt32(itemNum.Value); que habia hasta ahora,
2686  // lo que hacia que para obtener solo la fecha del arqueo (poco más abajo), cargase todo el arqueo por lo que tardaba muchisimo.
2687  loDicRegArqueo = loArqueo._Obtener_DatosGen_Arqueo_Cerrado(this._lcEjercicioActivo, this._lcEmpresaActiva, Convert.ToInt32(itemNum.Value));
2688 
2689  ldFechaArqueo = Convert.ToDateTime(loDicRegArqueo["fecha"]);
2690 
2691  lcArqueos += itemNum.Value + "|";
2692  lcArqueosFecha += ldFechaArqueo.ToString("d") + "|";
2693  }
2694 
2695 
2696  if (this._Numeros.Count == 0 && this._Numero > 0)
2697  {
2698  lcArqueos += this._Numero + "|";
2699  lcArqueosFecha += this._Fecha.ToString("d") + "|";
2700  }
2701 
2702  //PE-91451
2703  string lcFileXmlIvas = _Obtener_XML_desglose_iva();
2704 
2705 
2706  //PE-93563 Convertim la data a cadena
2707  string lcFecha_Final = _dFecha_Final.ToString("dd/MM/yyyy");
2708 
2709  // PE-94823 - Pasar la selección de dispositivo a un método
2710  int lnDispositivo = this._Seleccionar_Dispositivo("¿ Desea imprimir por impresora o por ticket ?", tcCaption);
2711 
2712  if (lnDispositivo < 0)
2713  return;
2714 
2715  // Preparem els paràmtres per a imprimir l'arqueo
2716  object[] loParameImp = new object[15]
2717  {
2718  _Numero, // Número de arqueo
2719  _Caja, // Caja
2720  Convert.ToInt16(teTipoDeArqueo), // Tipo de arqueo 1 = Consula. 2 = Definitivo.
2721  "000", // Moneda
2722  1, // Todas las monedas
2723  lcFecha_Final, // Fecha final del arqueo
2724  _ImporteRepEnCaja, // Reposición en caja
2725  _ImporteRetirado, // Importe retirado
2726  _ImporteTecleado, // Importe tecleado
2727  tcFileXMLDatos, // Nombre del fichero XML con los datos del arqueo
2728  lcArqueos, // Listado con los números de arqueo
2729  lcArqueosFecha, // Listado con las fechas de los arqueos
2730  tcCaption, // Caption de la opción
2731  lcFileXmlIvas, // Nombre del fichero XML con los datos de iva
2732  lnDispositivo // Impresion por impresora (1) o por tickets (2)
2733  };
2734 
2735  NETVFP._Ejecutar_Funcion_VFP("Imprimir_Arqueo_Net", loParameImp);
2736 
2737  this._Addons_Print(TipoExecute.After, teTipoDeArqueo, tcFileXMLDatos, tcCaption);
2738 
2739  return;
2740  }
2741 
2742 
2746  public void _Print_Consolida(string tcFileXMLDatos, string tcCaption, string tcCajaIni, string tcCajaFin, DateTime dFechaIni, DateTime dFechaFin, Boolean tlTodasCajas = false)
2747  {
2748  //PE-91451
2749  string lcFileXmlIvas = _Obtener_XML_desglose_iva();
2750 
2751  //PE-93563 Convertim la data a cadena
2752  string lcFechaIni = dFechaIni.ToString("dd/MM/yyyy");
2753  string lcFechaFin = dFechaFin.ToString("dd/MM/yyyy");
2754 
2755  // PE-94823 - Pasar la selección de dispositivo a un método
2756  int lnDispositivo = this._Seleccionar_Dispositivo("¿ Desea imprimir por impresora o por ticket ?", tcCaption);
2757 
2758  this._Addons_Print_Consolida(TipoExecute.Before, tcFileXMLDatos, tcCaption, tcCajaIni, tcCajaFin, dFechaIni, dFechaFin, tlTodasCajas);
2759 
2760  if (lnDispositivo < 0)
2761  return;
2762 
2763  // Preparem els paràmtres per a imprimir l'arqueo
2764  object[] loParameImp = new object[9]
2765  {
2766  tcFileXMLDatos, // Nombre del fichero XML con los datos del arqueo
2767  tcCaption, // Caption de la opción
2768  tcCajaIni, // Caja inicial
2769  tcCajaFin, // Caja final
2770  lcFechaIni, // Fecha inicial
2771  lcFechaFin, // Fecha final
2772  tlTodasCajas, // Todas las cajas
2773  lcFileXmlIvas, // Nombre del fichero XML con los datos de iva
2774  lnDispositivo // Impresion por impresora (1) o por tickets (2)
2775 
2776  };
2777  NETVFP._Ejecutar_Funcion_VFP("Imprimir_Consolida_Net", loParameImp);
2778 
2779  this._Addons_Print_Consolida(TipoExecute.After, tcFileXMLDatos, tcCaption, tcCajaIni, tcCajaFin, dFechaIni, dFechaFin, tlTodasCajas);
2780 
2781  return;
2782  }
2783 
2784 
2788  public void _MessageBox(string tcMensaje, string tcTitulo = "", MessageBoxButtons toButtons = MessageBoxButtons.OK, MessageBoxIcon toIcon = MessageBoxIcon.Error, MessageBoxDefaultButton toDefaultButton = MessageBoxDefaultButton.Button1)
2789  {
2790  if (string.IsNullOrEmpty(tcMensaje))
2791  return;
2792 
2793  this._Error = true;
2794 
2795  if (string.IsNullOrWhiteSpace(tcTitulo))
2796  tcTitulo = this._TituloMantenimiento;
2797 
2798  if (this._oLinkForm == null)
2799  this._Mensaje_Error = tcMensaje;
2800  else
2801  if (this._lMostrarMensajes == true)
2802  this._oLinkForm._MessageBox(tcMensaje, toButtons, toIcon, toDefaultButton, DialogResult.OK);
2803 
2804  }
2805 
2806 
2813  public string _CreateFileTemporalXML(string tcFileName, DataTable ldTable)
2814  {
2815  string lcFileNameIva = tcFileName;
2816 
2817  // Obtener la ruta de inicio
2818  string lcDir = EW_GLOBAL._GetVariable("wc_PathInicio").ToString();
2819 
2820  // Si la ruta está vacía cogemos la carpeta temp
2821  if (String.IsNullOrEmpty(lcDir))
2822  {
2823  lcDir = System.IO.Path.GetTempPath();
2824  lcFileNameIva = lcDir + lcFileNameIva;
2825  }
2826  else
2827  lcDir = Path.Combine(lcDir + "\\temp\\");
2828 
2829  // Volcar el datatable en el fichero XML
2830  ldTable.WriteXml(lcDir + tcFileName, XmlWriteMode.IgnoreSchema);
2831 
2832  // Devolver el fichero
2833  return lcFileNameIva;
2834  }
2835 
2836 
2841  public ewDocIva getDocIva(String lcEmpresa, String lcNumero, String lcLetra)
2842  {
2843 #if ewTools
2844  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
2845 #endif
2846  String tcClave;
2847  ewDocIva DocIva;
2848 
2849  using (ewDocVentaTPV loEwDocVentaTpv = new ewDocVentaTPV())
2850  {
2851  loEwDocVentaTpv._Load(lcEmpresa, lcNumero, lcLetra);
2852 
2853  //loEwDocVentaTpv = getDocVenta(lcEmpresa, lcNumero, lcLetra);
2854  tcClave = String.Format("{0}_{1}_{2}", lcEmpresa, lcNumero, lcLetra);
2855 
2856  if (this._nDocsIva.ContainsKey(tcClave))
2857  {
2858  DocIva = this._nDocsIva[tcClave];
2859  }
2860  else
2861  {
2862  DocIva = new ewDocIva();
2863  DocIva.ldt_TablaIva = loEwDocVentaTpv._Calcular_Iva(ref DocIva.lnTotalSinIva, ref DocIva.lnTotalConIva, ref DocIva.lnTotalPronto, ref DocIva.lnTotalRecFinan, ref DocIva.lnRetencionDoc, ref DocIva.lnTotalPuntoVerde, ref DocIva.leTipoRetFiscNoFisc, ref DocIva.lnRetencionDocPorcen, false);
2864  this._nDocsIva.Add(tcClave, DocIva);
2865  }
2866 
2867  //T115439
2868  if (!_lAvisoIva) _lAvisoIva = loEwDocVentaTpv._Cabecera._Divisa != EW_GLOBAL._Empresa._Moneda;
2869  }
2870 #if ewTools
2871  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
2872 #endif
2873  return DocIva;
2874  }
2875 
2876 
2880  public virtual void _Show()
2881  {
2882  frmArqueo loForm = new frmArqueo();
2883 
2884  loForm._LoadArqueoOnLoad = false;
2885  loForm._Listados = false;
2886  loForm._Arqueo = this;
2887 
2888  // Si tenemos números de arqueos y cajas, definir la propiedad en modo consulta
2889  this._Estado_Consulta = this._Numeros.Count > 0 && this._Cajas.Count > 0;
2890 
2891  loForm._ShowDialog(); //Bug 114218 Cambiar .ShowDialog() por ._ShowDialog()
2892  }
2893 
2894 
2898  public virtual void _Navegar_Tickets(String tcDivisa = "")
2899  {
2900  //this._detalle_arqueo("l_cajas", 1);
2901  this._detalle_arqueo("Tickets", string.Empty, "L_CAJAS", tcDivisa: tcDivisa);
2902  }
2903 
2904 
2908  public virtual void _Navegar_Albaranes(String tcDivisa = "")
2909  {
2910  // this._detalle_arqueo("l_cajas", 2);
2911  this._detalle_arqueo("Albaranes", string.Empty, "L_CAJAS", tcDivisa: tcDivisa);
2912  }
2913 
2914 
2918  public virtual void _Navegar_Facturas(String tcDivisa = "")
2919  {
2920  //this._detalle_arqueo("l_cajas", 3);
2921  this._detalle_arqueo("Facturas", string.Empty, "L_CAJAS", tcDivisa: tcDivisa);
2922  }
2923 
2924 
2928  public virtual void _Navegar_Reposiciones(String tcDivisa = "")
2929  {
2930  //this._detalle_arqueo("l_reposi");
2931  this._detalle_arqueo("Reposiciones", string.Empty, "L_REPOSI", tcDivisa: tcDivisa);
2932  }
2933 
2934 
2938  public virtual void _Navegar_Cobros_Tickets(String tcDivisa = "")
2939  {
2940  //this._detalle_arqueo("l_opcaja");
2941  this._detalle_arqueo("Cobros Tickets", string.Empty, "L_OPCAJA", 1, tcDivisa: tcDivisa);
2942  }
2943 
2944 
2948  public virtual void _Navegar_Vales_Efectuados()
2949  {
2950  //this._detalle_arqueo("l_opcaja", 9);
2951  this._detalle_arqueo("Vales efectuad.", string.Empty, "L_OPCAJA", 9);
2952  }
2953 
2954 
2958  public virtual void _Navegar_Entregas_Cuenta_Albaranes(String tcDivisa = "")
2959  {
2960  //this._detalle_arqueo("l_opcaja", 2);
2961  this._detalle_arqueo("Entregas a cta.", string.Empty, "L_OPCAJA", 2, tcDivisa: tcDivisa);
2962  }
2963 
2964 
2968  public virtual void _Navegar_Entregas_Cuenta_Pedidos(String tcDivisa = "")
2969  {
2970  //this._detalle_arqueo("l_opcaja", 10);
2971  this._detalle_arqueo("Entregas a cta. Pedidos", string.Empty, "L_OPCAJA", 10, tcDivisa: tcDivisa);
2972  }
2973 
2974 
2978  public virtual void _Navegar_Cobros_Facturas(String tcDivisa = "")
2979  {
2980  //this._detalle_arqueo("l_opcaja", 4);
2981  this._detalle_arqueo("Cobros Facturas", string.Empty, "L_OPCAJA", 4, tcDivisa: tcDivisa);
2982  }
2983 
2984 
2988  public virtual void _Navegar_Cobros_Varios()
2989  {
2990  //this._detalle_arqueo("l_opcaja", 3);
2991  this._detalle_arqueo("Cobros Varios", string.Empty, "L_OPCAJA", 3);
2992  }
2993 
2994 
2998  public virtual void _Navegar_Pagos_Facturas(String tcDivisa = "")
2999  {
3000  //this._detalle_arqueo("l_opcaja", 10);
3001  this._detalle_arqueo("Pagos Facturas", string.Empty, "L_OPCAJA", 6, tcDivisa: tcDivisa);
3002  }
3003 
3004 
3008  public virtual void _Navegar_Pagos_Varios()
3009  {
3010  //this._detalle_arqueo("l_opcaja", 5);
3011  this._detalle_arqueo("Pagos Varios", string.Empty, "L_OPCAJA", 5);
3012  }
3013 
3014 
3018  public virtual void _Navegar_Retiros(String tcDivisa = "")
3019  {
3020  //this._detalle_arqueo("l_retiros");
3021  this._detalle_arqueo("Retiros", string.Empty, "L_RETIROS", tcDivisa: tcDivisa);
3022  }
3023 
3024 
3028  public virtual void _Navegar_Ventas_Familias(string tcDescripcion, String tcDivisa = "")
3029  {
3030  //this._detalle_arqueo("ven_ca");
3031  this._detalle_arqueo("Ventas Familia", tcDescripcion, "VEN_CA", tcDivisa: tcDivisa);
3032  }
3033 
3034 
3038  public virtual void _Navegar_Operaciones_Caja(string tcDescripcion, String tcDivisa = "")
3039  {
3040  this._detalle_arqueo("Caja", tcDescripcion, "L_OPCAJA", 0, tcDivisa: tcDivisa);
3041  }
3042 
3043 
3047  public virtual void _Navegar_Creditos()
3048  {
3049  this._detalle_arqueo("Credit", string.Empty, "CREDIT_TPV");
3050  }
3051 
3052 
3056  public virtual void _Navegar_Abonos()
3057  {
3058  this._detalle_arqueo("Abonos", string.Empty, "L_ABONOS");
3059  }
3060 
3061 
3065  public string _ObtenerCaja(String tcCampo = "", String tcEmpresa = "")
3066  {
3067  DataTable ldt_Cursor = new DataTable();
3068  String lcRetorno = "";
3069  tcCampo = String.IsNullOrEmpty(tcCampo) ? "caja" : tcCampo;
3070  tcEmpresa = String.IsNullOrEmpty(tcEmpresa) ? this._lcEmpresaActiva : tcEmpresa;
3071 
3072  String lcSql = "select " + tcCampo + " as codigo from " + DB.SQLDatabase("tpv", "caj_fcob") + " where empresa=" + DB.SQLString(tcEmpresa);
3073  bool llRetorno = DB.SQLExec(lcSql, ref ldt_Cursor);
3074  if (llRetorno)
3075  lcRetorno = Convert.ToString(ldt_Cursor.Rows[0]["codigo"]);
3076 
3077  return lcRetorno;
3078  }
3079 
3080 
3081  #endregion METODOS PUBLICOS
3082 
3083 
3084  #region MÉTODOS PROTECTED
3085 
3086 
3091  protected virtual int _Obtener_Numero_Tiquets(ref string tnNumTicIni, ref string tnNumTicFin, ref string tcMsgError, ref string tnLetraTicIni, ref string tnLetraTicFin)
3092  {
3093  int lnNumTic = 0;
3094  DataTable ldt_Cursor = new DataTable();
3095  bool llConsulta_Ok = false;
3096 
3097  // 87748
3098  string lcCondicion = string.Empty;
3099  if (!string.IsNullOrWhiteSpace(_CajaDesde))
3100  lcCondicion = lcCondicion + " and t.caja >= " + DB.SQLString(_CajaDesde);
3101 
3102  if (!string.IsNullOrWhiteSpace(_CajaHasta))
3103  lcCondicion = lcCondicion + " and t.caja <= " + DB.SQLString(_CajaHasta);
3104 
3105  if (_FechaDesde != null)
3106  lcCondicion = lcCondicion + " and g.fecha >= " + DB.SQLString(_FechaDesde);
3107 
3108  if (_FechaHasta != null)
3109  lcCondicion = lcCondicion + " and g.fecha <= " + DB.SQLString(_FechaHasta);
3110 
3111  if (string.IsNullOrWhiteSpace(lcCondicion))
3112  lcCondicion = "and " + _makeId("t", "t.arqueo = " + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? "and t.aparcado=0 and g.fecha<=" + DB.SQLString(this._dFecha) + " and t.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
3113  // fi 87748
3114 
3115  string lcEjercicio = string.Empty;
3116  if (!_llejercicioautomatico) lcEjercicio = " and t.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
3117 
3118  if (string.IsNullOrWhiteSpace(_CajaDesde) && string.IsNullOrWhiteSpace(_CajaHasta))
3119  lcCondicion = lcCondicion + " and t.caja !='' ";
3120 
3121  llConsulta_Ok = DB.SQLExec("select t.empresa,t.letra, t.numero " +
3122  "from ((" + DB.SQLDatabase("gestion", "c_albven") + " g inner join " + DB.SQLDatabase("tpv", "c_albven") + " t " +
3123  "on g.empresa=t.empresa and g.numero=t.numero and g.letra=t.letra " + lcEjercicio + ") " + // 104028
3124  " inner join " + DB.SQLDatabase("gestion", "d_albven") + " d " +
3125  "on g.empresa=d.empresa and g.numero=d.numero and g.letra=d.letra) " +
3126  "where t.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
3127  lcEjercicio + // 104028
3128  lcCondicion + // 87748
3129  "and t.tipo_doc=1 " +
3130  "group by t.empresa, t.letra, t.numero " +
3131  "order by t.empresa, t.letra, t.numero ", ref ldt_Cursor);
3132 
3133  if (llConsulta_Ok == true)
3134  {
3135  lnNumTic = ldt_Cursor.Rows.Count;
3136  if (ldt_Cursor.Rows.Count > 0)
3137  {
3138  tnNumTicIni = Convert.ToString(ldt_Cursor.Rows[0]["numero"]);
3139  tnNumTicFin = Convert.ToString(ldt_Cursor.Rows[ldt_Cursor.Rows.Count - 1]["numero"]);
3140 
3141  tnLetraTicIni = Convert.ToString(ldt_Cursor.Rows[0]["letra"]);
3142  tnLetraTicFin = Convert.ToString(ldt_Cursor.Rows[ldt_Cursor.Rows.Count - 1]["letra"]);
3143  }
3144  else
3145  {
3146  tnNumTicIni = new String(' ', 12);
3147  tnNumTicFin = new String(' ', 12);
3148  tnLetraTicIni = new String(' ', 2);
3149  tnLetraTicFin = new String(' ', 2);
3150  }
3151  }
3152  else
3153  {
3154  lnNumTic = 0;
3155  tnNumTicIni = new String(' ', 12);
3156  tnNumTicFin = new String(' ', 12);
3157  tnLetraTicIni = new String(' ', 2);
3158  tnLetraTicFin = new String(' ', 2);
3159 
3160  tcMsgError = "(_Load) Error en consulta de _Obtener_Numero_Tiquets().";
3161  }
3162 
3163  return lnNumTic;
3164  }
3165 
3166 
3171  protected virtual void _Obtener_DataTables_Importe_Tiquets_Albaranes_Facturas(ref DateTime tdFechaIni, ref DateTime tdFechaFin, ref string tcMsgError)
3172  {
3173  DataTable ldt_tmp_AlbD = new DataTable();
3174  bool llConsulta_Ok = false;
3175  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
3176  int lnDecimalesMascara;
3177  DataRow row;
3178  String tcDivisa, tcMoneda;
3179  tdFechaIni = DateTime.Today;
3180  tdFechaFin = DateTime.Today;
3181 
3182  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
3183  this._nImporteTotalVentas = 0;
3184 
3185  this._dtVentas_Tiquets = DBfunctions._Crear_DtTable(la_array_cursor);
3186  this._dtVentas_Albaranes = DBfunctions._Crear_DtTable(la_array_cursor);
3187  this._dtVentas_Facturas = DBfunctions._Crear_DtTable(la_array_cursor);
3188  _dicMoneda = new Dictionary<string, string>();
3189 
3190  // 87748
3191  string lcCondicion = string.Empty;
3192  if (!string.IsNullOrWhiteSpace(_CajaDesde))
3193  lcCondicion = lcCondicion + " and t.caja >= " + DB.SQLString(_CajaDesde);
3194 
3195  if (!string.IsNullOrWhiteSpace(_CajaHasta))
3196  lcCondicion = lcCondicion + " and t.caja <= " + DB.SQLString(_CajaHasta);
3197 
3198  if (_FechaDesde != null)
3199  lcCondicion = lcCondicion + " and g.fecha >= " + DB.SQLString(_FechaDesde);
3200 
3201  if (_FechaHasta != null)
3202  lcCondicion = lcCondicion + " and g.fecha <= " + DB.SQLString(_FechaHasta);
3203 
3204  if (string.IsNullOrWhiteSpace(lcCondicion))
3205  lcCondicion = "and " + _makeId("t", "t.arqueo = " + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? "and t.aparcado=0 and g.fecha<=" + DB.SQLString(this._dFecha) + " and t.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
3206  // fi 87748
3207 
3208  string lcEjercicio = string.Empty;
3209  if (!_llejercicioautomatico) lcEjercicio = " and t.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
3210 
3211  if (string.IsNullOrWhiteSpace(_CajaDesde) && string.IsNullOrWhiteSpace(_CajaHasta))
3212  lcCondicion = lcCondicion + " and t.caja !='' ";
3213 
3214  //String tcSql = "select t.Tipo_Doc, g.Empresa, g.Numero, g.Letra, g.Divisa, g.cambio, g.pronto, g.iva_inc, cli.recargo, g.Fecha, " +
3215  // "d.impdiviva as importediv, d.importeiva as importe , g.Totaldoc, g.Totaldiv " +
3216  // "from " + DB.SQLDatabase("gestion", "c_albven") + " g inner join " + DB.SQLDatabase("tpv", "c_albven") + " t " +
3217  // "on g.Empresa=t.empresa and g.Numero=t.numero and g.Letra=t.Letra " + lcEjercicio + // 104028
3218  // "inner join " + DB.SQLDatabase("gestion", "d_albven") + " d ON g.Empresa=d.empresa and g.Numero=d.numero and g.letra=d.letra " +
3219  // "inner join " + DB.SQLDatabase("gestion", "clientes") + " cli on g.cliente=cli.codigo " +
3220  // "where t.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
3221  // lcCondicion + // 87748
3222  // lcEjercicio; // 104028
3223 
3224  String tcSql = "select t.Tipo_Doc, g.Empresa, g.Numero, g.Letra, g.Divisa, g.Totaldoc as importe, g.Totaldiv as importediv, g.Fecha " +
3225  "from " + DB.SQLDatabase("gestion", "c_albven") + " g inner join " + DB.SQLDatabase("tpv", "c_albven") + " t " +
3226  "on g.Empresa=t.empresa and g.Numero=t.numero and g.Letra=t.Letra " + lcEjercicio + // 104028
3227  "inner join " + DB.SQLDatabase("gestion", "clientes") + " cli on g.cliente=cli.codigo " +
3228  "where t.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
3229  lcCondicion + // 87748
3230  lcEjercicio; // 104028
3231 
3232  llConsulta_Ok = DB.SQLExec(tcSql, ref ldt_tmp_AlbD);
3233 
3234  if (llConsulta_Ok == true)
3235  {
3236  try
3237  {
3238  tdFechaIni = ldt_tmp_AlbD.Rows.Count > 0 ? ldt_tmp_AlbD.AsEnumerable().Min(lin => Convert.ToDateTime(lin["fecha"])) : this._dFecha;
3239  tdFechaFin = ldt_tmp_AlbD.Rows.Count > 0 ? ldt_tmp_AlbD.AsEnumerable().Max(lin => Convert.ToDateTime(lin["fecha"])) : this._dFecha;
3240 
3241  if (ldt_tmp_AlbD.Rows.Count > 0)
3242  {
3243  DataTable ldt_TmpAlb = ldt_tmp_AlbD.Clone();
3244 
3245  var lc_Consulta = from venta in ldt_tmp_AlbD.AsEnumerable()
3246  group venta by new
3247  {
3248  tipo_doc = venta["tipo_doc"],
3249  empresa = venta["empresa"],
3250  numero = venta["numero"],
3251  letra = venta["letra"],
3252  divisa = venta["divisa"],
3253  //cambio = venta["cambio"],
3254  //pronto = venta["pronto"],
3255  //iva_inc = venta["iva_inc"],
3256  //recargo = venta["recargo"],
3257  //fecha = venta["fecha"]
3258  } into g
3259  select new
3260  {
3261  tipo_doc = g.Key.tipo_doc,
3262  empresa = g.Key.empresa,
3263  numero = g.Key.numero,
3264  letra = g.Key.letra,
3265  divisa = g.Key.divisa,
3266  //cambio = g.Key.cambio,
3267  //pronto = g.Key.pronto,
3268  //iva_inc = g.Key.iva_inc,
3269  //recargo = g.Key.recargo,
3270  //fecha = g.Key.fecha,
3271  importediv = g.Sum(venta => venta.Field<decimal>("importediv")),
3272  importe = g.Sum(venta => venta.Field<decimal>("importe"))
3273  };
3274 
3275  var la_registros = lc_Consulta.ToArray();
3276 
3277  foreach (var r in la_registros)
3278  {
3279  row = ldt_TmpAlb.NewRow();
3280  row["tipo_doc"] = r.tipo_doc;
3281  row["empresa"] = r.empresa;
3282  row["numero"] = r.numero;
3283  row["letra"] = r.letra;
3284  row["divisa"] = r.divisa;
3285  //row["cambio"] = r.cambio;
3286  //row["pronto"] = r.pronto;
3287  //row["iva_inc"] = r.iva_inc;
3288  //row["recargo"] = r.recargo;
3289  //row["fecha"] = r.fecha;
3290  row["importediv"] = r.importediv;
3291  row["importe"] = r.importe;
3292  ldt_TmpAlb.Rows.Add(row);
3293  }
3294 
3295  //this._Importe_Documento(ldt_TmpAlb, "Importe", "ImporteDiv");
3296 
3297  var lc_Consulta2 = from venta in ldt_TmpAlb.AsEnumerable()
3298  group venta by new
3299  {
3300  tipo_doc = venta["tipo_doc"],
3301  divisa = venta["divisa"]
3302  } into g
3303  select new
3304  {
3305  tipo_doc = g.Key.tipo_doc,
3306  divisa = g.Key.divisa,
3307  importediv = g.Sum(venta => venta.Field<decimal>("importediv")),
3308  importe = g.Sum(venta => venta.Field<decimal>("importe"))
3309  };
3310 
3311  var la_registros2 = lc_Consulta2.ToArray();
3312 
3313 
3314  // Generar DataTable de ventas de tiquets con la siguiente información (moneda, definicion, importediv, importe)
3315 
3316 
3317  foreach (var r in la_registros2)
3318  {
3319 
3320  if (Convert.ToDecimal(r.importe) != 0)
3321  {
3322  string lcMoneda = Convert.ToString(r.divisa);
3323  if (string.IsNullOrWhiteSpace(lcMoneda)) lcMoneda = this._lcMoneda_Empresa;
3324  //PE-77346, Llamaba varias veces dentro del mismo bucle a la funcion, asi que se guarda el valor, y se utiliza tantas veces como se necesite
3325 
3326  loDicMoneda = _Moneda(lcMoneda);
3327  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
3328 
3329  tcDivisa = Convert.ToString(r.divisa);
3330  tcMoneda = getSimboloMoneda(loDicMoneda);//Convert.ToString(loDicMoneda["moneda"]).Trim();
3331  if (!_dicMoneda.ContainsKey(tcDivisa)) _dicMoneda.Add(tcDivisa, tcMoneda);
3332 
3333  if (Convert.ToInt32(r.tipo_doc) == 1)
3334  {
3335  row = this._dtVentas_Tiquets.NewRow();
3336 
3337  row["descripcion"] = String.Format("Importe factura simplificada ({0})", tcMoneda);
3338  row["importediv"] = FUNCTIONS._Round(r.importediv, lnDecimalesMascara);
3339  row["moneda"] = tcDivisa;
3340  row["importe"] = r.importe;
3341  this._dtVentas_Tiquets.Rows.Add(row);
3342 
3343  this._nImporteTotalVentas = this._nImporteTotalVentas + Convert.ToDecimal(row["importe"]);
3344  }
3345  else if (Convert.ToInt32(r.tipo_doc) == 2)
3346  {
3347  row = this._dtVentas_Albaranes.NewRow();
3348  row["descripcion"] = String.Format("Importe albaranes ({0})", tcMoneda);
3349  row["importediv"] = FUNCTIONS._Round(r.importediv, lnDecimalesMascara);
3350  row["moneda"] = tcDivisa;
3351  row["importe"] = r.importe;
3352  this._dtVentas_Albaranes.Rows.Add(row);
3353 
3354  this._nImporteTotalVentas = this._nImporteTotalVentas + Convert.ToDecimal(row["importe"]);
3355  }
3356  else if (Convert.ToInt32(r.tipo_doc) == 3)
3357  {
3358  row = this._dtVentas_Facturas.NewRow();
3359 
3360  row["descripcion"] = String.Format("Importe facturas ({0})", tcMoneda);
3361  row["importediv"] = FUNCTIONS._Round(r.importediv, lnDecimalesMascara);
3362  row["moneda"] = tcDivisa;
3363  row["importe"] = r.importe;
3364  this._dtVentas_Facturas.Rows.Add(row);
3365 
3366  this._nImporteTotalVentas = this._nImporteTotalVentas + Convert.ToDecimal(row["importe"]);
3367  }
3368  }
3369 
3370  }
3371  }
3372  }
3373  catch (Exception oE)
3374  {
3375  tcMsgError = "(_Load) Error en procesos internos en _Obtener_DataTables_Importe_Tiquets_Albaranes_Facturas().\n\n" + oE.Message;
3376  }
3377  }
3378  else
3379  {
3380  tcMsgError = "(_Load) Error en consulta de _Obtener_DataTables_Importe_Tiquets_Albaranes_Facturas().";
3381  }
3382  }
3383 
3384 
3389  protected virtual DataTable _Obtener_DataTable_OperCaja_Reposiciones(ref decimal lnTotalRepo, ref string tcMsgError)
3390  {
3391 #if ewTools
3392  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
3393 #endif
3394 
3395  DataTable ldt_CurReposi = new DataTable();
3396  DataTable ldtReposiciones = new DataTable();
3397  bool llConsulta_Ok = false;
3398  DataRow row;
3399  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
3400  int lnDecimalesMascara;
3401  decimal lnTotal = 0.0M;
3402 
3403  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
3404  ldtReposiciones = DBfunctions._Crear_DtTable(la_array_cursor);
3405 
3406  // 87748
3407  string lcCondicion = string.Empty;
3408  if (!string.IsNullOrWhiteSpace(_CajaDesde))
3409  lcCondicion = lcCondicion + " and rep.caja >= " + DB.SQLString(_CajaDesde);
3410 
3411  if (!string.IsNullOrWhiteSpace(_CajaHasta))
3412  lcCondicion = lcCondicion + " and rep.caja <= " + DB.SQLString(_CajaHasta);
3413 
3414  if (_FechaDesde != null)
3415  lcCondicion = lcCondicion + " and rep.fecha >= " + DB.SQLString(_FechaDesde);
3416 
3417  if (_FechaHasta != null)
3418  lcCondicion = lcCondicion + " and rep.fecha <= " + DB.SQLString(_FechaHasta);
3419 
3420  if (string.IsNullOrWhiteSpace(lcCondicion))
3421  lcCondicion = "and " + _makeId("rep", "rep.arqueo=" + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? "and rep.fecha<=" + DB.SQLString(this._dFecha) + " and rep.caja=" + DB.SQLString(this._lcCajaActiva) : "") + " ");
3422  // fi 87748
3423 
3424  string lcEjercicio = string.Empty;
3425  if (!_llejercicioautomatico) lcEjercicio = " and rep.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
3426 
3427  llConsulta_Ok = DB.SQLExec("select sum(rep.reposicion) as importediv, rep.moneda, sum(rep.reposicion/rep.cambio) as importe " +
3428  "from " + DB.SQLDatabase("tpv", "reposi") + " rep " +
3429  "where rep.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
3430  lcEjercicio + // 104028
3431  lcCondicion +
3432  "group by rep.moneda", ref ldt_CurReposi);
3433  if (llConsulta_Ok == true)
3434  {
3435  if (ldt_CurReposi.Rows.Count > 0)
3436  {
3437  try
3438  {
3439  // Generar DataTable de reposiciones con la siguiente información (moneda, definicion, importediv, importe)
3440  foreach (DataRow r in ldt_CurReposi.Rows)
3441  {
3442  string lcMoneda = Convert.ToString(r["moneda"]);
3443  if (string.IsNullOrWhiteSpace(lcMoneda))
3444  lcMoneda = this._lcMoneda_Empresa;
3445  loDicMoneda = DB.SQLREGValor("moneda", "codigo", lcMoneda);
3446  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
3447 
3448  if (Convert.ToDecimal(r["importe"]) != 0)
3449  {
3450  row = ldtReposiciones.NewRow();
3451 
3452  //Bug 116469
3453  //row["descripcion"] = "Reposiciones caja (" + Convert.ToString(loDicMoneda["moneda"]).Trim() + ")";
3454  row["descripcion"] = "Reposiciones caja (" + getSimboloMoneda(loDicMoneda) + ")";
3455 
3456  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
3457 
3458  row["moneda"] = lcMoneda;
3459 
3460  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
3461 
3462  ldtReposiciones.Rows.Add(row);
3463 
3464  lnTotal = lnTotal + Convert.ToDecimal(r["importe"]);
3465 
3466  }
3467  }
3468  }
3469  catch (Exception oE)
3470  {
3471  tcMsgError = "(_Load) Error en procesos internos _Obtener_DataTable_OperCaja_Reposiciones()..\n\n" + oE.Message;
3472  }
3473  }
3474  }
3475  else
3476  {
3477  tcMsgError = "(_Load) Error en consulta en _Obtener_DataTable_OperCaja_Reposiciones().";
3478  }
3479  lnTotalRepo = lnTotal;
3480 
3481 #if ewTools
3482  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
3483 #endif
3484 
3485  return ldtReposiciones;
3486  }
3487 
3492  protected virtual DataTable _Obtener_DataTable_OperCaja_Vales_Efectuados(ref decimal tnTotalVales, ref string tcMsgError)
3493  {
3494 #if ewTools
3495  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
3496 #endif
3497 
3498 
3499  DataTable ldt_CurVales = new DataTable();
3500  DataTable ltdVales = new DataTable();
3501  bool llConsulta_Ok = false;
3502  DataRow row;
3503  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
3504  int lnDecimalesMascara;
3505  decimal lnTotal = 0.0M;
3506 
3507  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
3508  ltdVales = DBfunctions._Crear_DtTable(la_array_cursor);
3509 
3510  // 87748
3511  string lcCondicion = string.Empty;
3512  if (!string.IsNullOrWhiteSpace(_CajaDesde))
3513  lcCondicion = lcCondicion + " and vales.caja >= " + DB.SQLString(_CajaDesde);
3514 
3515  if (!string.IsNullOrWhiteSpace(_CajaHasta))
3516  lcCondicion = lcCondicion + " and vales.caja <= " + DB.SQLString(_CajaHasta);
3517 
3518  if (_FechaDesde != null)
3519  lcCondicion = lcCondicion + " and vales.fecha >= " + DB.SQLString(_FechaDesde);
3520 
3521  if (_FechaHasta != null)
3522  lcCondicion = lcCondicion + " and vales.fecha <= " + DB.SQLString(_FechaHasta);
3523 
3524  if (string.IsNullOrWhiteSpace(lcCondicion))
3525  lcCondicion = "and " + _makeId("vales", " vales.arqueo=" + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? "and vales.fecha<=" + DB.SQLString(this._dFecha) + " and vales.caja=" + DB.SQLString(this._lcCajaActiva) : " and vales.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)))) + " ";
3526  // FI 87748
3527 
3528  llConsulta_Ok = DB.SQLExec("select vales.empresa, sum(vales.importe) as importediv, sum(vales.importe) as importe " +
3529  "from " + DB.SQLDatabase("tpv", "vales") + " " +
3530  "where vales.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
3531  "and vales.arqueo != -1 " + // 95025
3532  lcCondicion +
3533  "group by vales.empresa", ref ldt_CurVales);
3534 
3535  if (llConsulta_Ok == true)
3536  {
3537  if (ldt_CurVales.Rows.Count > 0)
3538  {
3539  try
3540  {
3541  // Generar DataTable de vales la siguiente información (moneda, definicion, importediv, importe), en los vales son siempre en la moneda de la empresa ...
3542  foreach (DataRow r in ldt_CurVales.Rows)
3543  {
3544  string lcMoneda = Convert.ToString(this._lcMoneda_Empresa);
3545  //pe-77346
3546  loDicMoneda = _Moneda(lcMoneda);
3547  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
3548 
3549  if (Convert.ToDecimal(r["importe"]) != 0)
3550  {
3551  row = ltdVales.NewRow();
3552 
3553  //Bug 116469
3554  //row["descripcion"] = "Vales efectuados (" + Convert.ToString(loDicMoneda["moneda"]).Trim() + ")";
3555  row["descripcion"] = "Vales efectuados (" + getSimboloMoneda(loDicMoneda) + ")";
3556 
3557  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]) * -1, lnDecimalesMascara);
3558 
3559  row["moneda"] = lcMoneda;
3560 
3561  row["importe"] = Divisa._DivExacto(Divisa._Ultima_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
3562 
3563  ltdVales.Rows.Add(row);
3564 
3565  lnTotal = lnTotal + Convert.ToDecimal(row["importe"]);
3566  }
3567  }
3568  }
3569  catch (Exception oE)
3570  {
3571  tcMsgError = "(_Load) Error en procesos internos en _Obtener_DataTable_OperCaja_Vales_Efectuados().\n\n" + oE.Message;
3572  }
3573  }
3574  }
3575  else
3576  {
3577  tcMsgError = "(_Load) Error en consulta en _Obtener_DataTable_OperCaja_Vales_Efectuados().";
3578  }
3579  tnTotalVales = lnTotal;
3580 
3581 #if ewTools
3582  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
3583 #endif
3584 
3585  return ltdVales;
3586  }
3587 
3588 
3593  protected virtual DataTable _Obtener_DataTable_OperCaja_Cobros_Tiquets(ref decimal tnTotalCobros, ref string tcMsgError)
3594  {
3595 #if ewTools
3596  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
3597 #endif
3598 
3599 
3600  DataTable ldt_Tikets = new DataTable();
3601  DataTable ldtCobrosTiquets = new DataTable();
3602  bool llConsulta_Ok = false;
3603  DataRow row;
3604  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
3605  int lnDecimalesMascara;
3606  decimal lnTotal = 0.0M;
3607 
3608  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
3609  ldtCobrosTiquets = DBfunctions._Crear_DtTable(la_array_cursor);
3610 
3611  // 87748
3612  string lcCondicion = string.Empty;
3613  if (!string.IsNullOrWhiteSpace(_CajaDesde))
3614  lcCondicion = lcCondicion + " and tikets.caja >= " + DB.SQLString(_CajaDesde);
3615 
3616  if (!string.IsNullOrWhiteSpace(_CajaHasta))
3617  lcCondicion = lcCondicion + " and tikets.caja <= " + DB.SQLString(_CajaHasta);
3618 
3619  if (_FechaDesde != null)
3620  lcCondicion = lcCondicion + " and tikets.fecha >= " + DB.SQLString(_FechaDesde);
3621 
3622  if (_FechaHasta != null)
3623  lcCondicion = lcCondicion + " and tikets.fecha <= " + DB.SQLString(_FechaHasta);
3624 
3625  if (string.IsNullOrWhiteSpace(lcCondicion))
3626  lcCondicion = "and " + _makeId("tikets", " tikets.arqueo = " + this._nNumero + (this._nNumero == 0 ? " and tikets.fecha<=" + DB.SQLString(this._dFecha) + " and tikets.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
3627  // fi 87748
3628 
3629  string lcEjercicio = string.Empty;
3630  if (!_llejercicioautomatico) lcEjercicio = " and tikets.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
3631 
3632  llConsulta_Ok = DB.SQLExec("select Sum(tikets.entrega-tikets.cambio_e) as importediv, tikets.moneda, tikets.tipo, " +
3633  DB.SQLNvl("Sum((tikets.entrega-tikets.cambio_e)/tikets.cotizacion)", 0) + " as importe " +
3634  "from " + DB.SQLDatabase("tpv", "tikets") + " " +
3635  "where tikets.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
3636  lcEjercicio + // 104028
3637  "and tikets.tipo=1 " +
3638  lcCondicion +
3639  "group by tikets.tipo,tikets.moneda", ref ldt_Tikets);
3640  if (llConsulta_Ok == true)
3641  {
3642  if (ldt_Tikets.Rows.Count > 0)
3643  {
3644  try
3645  {
3646  // Generar DataTable de retiradas con la siguiente información (moneda, definicion, importediv, importe)
3647  foreach (DataRow r in ldt_Tikets.Rows)
3648  {
3649  string lcMoneda = Convert.ToString(r["moneda"]);
3650  if (string.IsNullOrWhiteSpace(lcMoneda))
3651  lcMoneda = this._lcMoneda_Empresa;
3652  loDicMoneda = _Moneda(lcMoneda);
3653  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
3654 
3655  row = ldtCobrosTiquets.NewRow();
3656 
3657  //Bug 116469
3658  //row["descripcion"] = "Cobros Facturas Simplif. (" + Convert.ToString(loDicMoneda["moneda"]).Trim() + ")";
3659  row["descripcion"] = "Cobros Facturas Simplif. (" + getSimboloMoneda(loDicMoneda) + ")";
3660 
3661  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
3662 
3663  row["moneda"] = lcMoneda;
3664 
3665  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
3666 
3667  ldtCobrosTiquets.Rows.Add(row);
3668 
3669  lnTotal = lnTotal + Convert.ToDecimal(r["importe"]);
3670  }
3671  }
3672  catch (Exception oE)
3673  {
3674  tcMsgError = "(_Load) Error en procesos internos en _Obtener_DataTable_OperCaja_Cobros_Tiquets().\n\n" + oE.Message;
3675  }
3676  }
3677  }
3678  else
3679  {
3680  tcMsgError = "(_Load) Error en consulta en _Obtener_DataTable_OperCaja_Cobros_Tiquets().";
3681  }
3682  tnTotalCobros = lnTotal;
3683 
3684 #if ewTools
3685  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
3686 #endif
3687 
3688  return ldtCobrosTiquets;
3689  }
3690 
3691 
3696  protected virtual DataTable _Obtener_DataTable_OperCaja_Entregas_Cuenta_Albaranes(ref decimal tnTotalEntAlbaran, ref string tcMsgError)
3697  {
3698 #if ewTools
3699  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
3700 #endif
3701 
3702  DataTable ldt_Entregas = new DataTable();
3703  DataTable ltdEntAlbaran = new DataTable();
3704  bool llConsulta_Ok = false;
3705  DataRow row;
3706  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
3707  int lnDecimalesMascara;
3708  decimal lnTotal = 0.0M;
3709 
3710  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
3711  ltdEntAlbaran = DBfunctions._Crear_DtTable(la_array_cursor);
3712 
3713  // 87748
3714  string lcCondicion = string.Empty;
3715  if (!string.IsNullOrWhiteSpace(_CajaDesde))
3716  lcCondicion = lcCondicion + " and tikets.caja >= " + DB.SQLString(_CajaDesde);
3717 
3718  if (!string.IsNullOrWhiteSpace(_CajaHasta))
3719  lcCondicion = lcCondicion + " and tikets.caja <= " + DB.SQLString(_CajaHasta);
3720 
3721  if (_FechaDesde != null)
3722  lcCondicion = lcCondicion + " and tikets.fecha >= " + DB.SQLString(_FechaDesde);
3723 
3724  if (_FechaHasta != null)
3725  lcCondicion = lcCondicion + " and tikets.fecha <= " + DB.SQLString(_FechaHasta);
3726 
3727  if (string.IsNullOrWhiteSpace(lcCondicion))
3728  lcCondicion = "and " + _makeId("tikets", " tikets.arqueo=" + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? " and tikets.fecha<=" + DB.SQLString(this._dFecha) + " and tikets.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
3729  // fi 87748
3730 
3731  string lcEjercicio = string.Empty;
3732  if (!_llejercicioautomatico) lcEjercicio = " and tikets.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
3733 
3734  llConsulta_Ok = DB.SQLExec("select Sum(tikets.entrega-tikets.cambio_e) as importediv, tikets.moneda, tikets.tipo, " +
3735  DB.SQLNvl("Sum((tikets.entrega-tikets.cambio_e)/tikets.cotizacion)", 0) + " as importe " +
3736  "from " + DB.SQLDatabase("tpv", "tikets") + " " +
3737  "where tikets.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
3738  lcEjercicio + // 104028
3739  "and tikets.tipo=2 " +
3740  lcCondicion +
3741  "group by tikets.tipo,tikets.moneda", ref ldt_Entregas);
3742  if (llConsulta_Ok == true)
3743  {
3744  if (ldt_Entregas.Rows.Count > 0)
3745  {
3746  try
3747  {
3748  // Generar DataTable de retiradas con la siguiente información (moneda, definicion, importediv, importe)
3749  foreach (DataRow r in ldt_Entregas.Rows)
3750  {
3751 
3752  string lcMoneda = Convert.ToString(r["moneda"]);
3753  if (string.IsNullOrWhiteSpace(lcMoneda))
3754  lcMoneda = this._lcMoneda_Empresa;
3755 
3756  loDicMoneda = _Moneda(lcMoneda);
3757  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
3758 
3759  if (Convert.ToDecimal(r["importe"]) != 0)
3760  {
3761  row = ltdEntAlbaran.NewRow();
3762 
3763  //Bug 116469
3764  //row["descripcion"] = "Entregas a cuenta (" + Convert.ToString(loDicMoneda["moneda"]).Trim() + ")";
3765  row["descripcion"] = "Entregas a cuenta (" + getSimboloMoneda(loDicMoneda) + ")";
3766 
3767  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
3768 
3769  row["moneda"] = lcMoneda;
3770 
3771  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
3772 
3773  ltdEntAlbaran.Rows.Add(row);
3774 
3775  lnTotal = lnTotal + Convert.ToDecimal(r["importe"]);
3776  }
3777  }
3778  }
3779  catch (Exception oE)
3780  {
3781  tcMsgError = "(_Load) Error en procesos internos en _Obtener_DataTable_OperCaja_Entregas_Cuenta_Albaranes().\n\n" + oE.Message;
3782  }
3783 
3784  }
3785  }
3786  else
3787  {
3788  tcMsgError = "(_Load) Error en consulta en _Obtener_DataTable_OperCaja_Entregas_Cuenta_Albaranes().";
3789  }
3790  tnTotalEntAlbaran = lnTotal;
3791 
3792 #if ewTools
3793  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
3794 #endif
3795 
3796  return ltdEntAlbaran;
3797  }
3798 
3799 
3804  protected virtual DataTable _Obtener_DataTable_OperCaja_Entregas_Cuenta_Pedidos(ref decimal tnTotalEntPedidos, ref string tcMsgError)
3805  {
3806 #if ewTools
3807  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
3808 #endif
3809 
3810  DataTable ldt_Entregas = new DataTable();
3811  DataTable ltdEntPedidos = new DataTable();
3812  bool llConsulta_Ok = false;
3813  DataRow row;
3814  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
3815  int lnDecimalesMascara;
3816  decimal lnTotal = 0.0M;
3817 
3818  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
3819  ltdEntPedidos = DBfunctions._Crear_DtTable(la_array_cursor);
3820 
3821  // 87748
3822  string lcCondicion = string.Empty;
3823  if (!string.IsNullOrWhiteSpace(_CajaDesde))
3824  lcCondicion = lcCondicion + " and tikets.caja >= " + DB.SQLString(_CajaDesde);
3825 
3826  if (!string.IsNullOrWhiteSpace(_CajaHasta))
3827  lcCondicion = lcCondicion + " and tikets.caja <= " + DB.SQLString(_CajaHasta);
3828 
3829  if (_FechaDesde != null)
3830  lcCondicion = lcCondicion + " and tikets.fecha >= " + DB.SQLString(_FechaDesde);
3831 
3832  if (_FechaHasta != null)
3833  lcCondicion = lcCondicion + " and tikets.fecha <= " + DB.SQLString(_FechaHasta);
3834 
3835  if (string.IsNullOrWhiteSpace(lcCondicion))
3836  lcCondicion = "and " + _makeId("tikets", " tikets.arqueo=" + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? " and tikets.fecha<=" + DB.SQLString(this._dFecha) + " and tikets.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
3837  // fi 87748
3838 
3839  string lcEjercicio = string.Empty;
3840  if (!_llejercicioautomatico) lcEjercicio = " and tikets.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
3841 
3842  llConsulta_Ok = DB.SQLExec("select Sum(tikets.entrega-tikets.cambio_e) as importediv, tikets.moneda, tikets.tipo, " +
3843  DB.SQLNvl("Sum((tikets.entrega-tikets.cambio_e)/tikets.cotizacion)", 0) + " as importe " +
3844  "from " + DB.SQLDatabase("tpv", "tikets") + " " +
3845  "where tikets.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
3846  lcEjercicio + // 104028
3847  "and tikets.tipo=10 " +
3848  lcCondicion +
3849  "group by tikets.tipo,tikets.moneda", ref ldt_Entregas);
3850  if (llConsulta_Ok == true)
3851  {
3852  if (ldt_Entregas.Rows.Count > 0)
3853  {
3854  try
3855  {
3856  foreach (DataRow r in ldt_Entregas.Rows)
3857  {
3858  string lcMoneda = Convert.ToString(r["moneda"]);
3859  if (string.IsNullOrWhiteSpace(lcMoneda))
3860  lcMoneda = this._lcMoneda_Empresa;
3861  //PE-77346
3862  loDicMoneda = _Moneda(lcMoneda);
3863  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
3864 
3865  if (Convert.ToDecimal(r["importe"]) != 0)
3866  {
3867  row = ltdEntPedidos.NewRow();
3868 
3869  //Bug 116469
3870  //row["descripcion"] = "Entregas a cuenta pedidos (" + Convert.ToString(loDicMoneda["moneda"]).Trim() + ")";
3871  row["descripcion"] = "Entregas a cuenta pedidos (" + getSimboloMoneda(loDicMoneda) + ")";
3872 
3873  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
3874 
3875  row["moneda"] = lcMoneda;
3876 
3877  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
3878 
3879  ltdEntPedidos.Rows.Add(row);
3880 
3881  lnTotal = lnTotal + Convert.ToDecimal(r["importe"]);
3882  }
3883  }
3884  }
3885  catch (Exception oE)
3886  {
3887  tcMsgError = "(_Load) Error en procesos internos en _Obtener_DataTable_OperCaja_Entregas_Cuenta_Pedidos().\n\n" + oE.Message;
3888  }
3889  }
3890  }
3891  else
3892  {
3893  tcMsgError = "(_Load) Error en consulta en _Obtener_DataTable_OperCaja_Entregas_Cuenta_Pedidos().";
3894  }
3895  tnTotalEntPedidos = lnTotal;
3896 
3897 #if ewTools
3898  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
3899 #endif
3900 
3901  return ltdEntPedidos;
3902  }
3903 
3904 
3909  protected virtual DataTable _Obtener_DataTable_OperCaja_Pagos_Facturas(ref decimal tnTotalPagosFacturas, ref string tcMsgError)
3910  {
3911 #if ewTools
3912  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
3913 #endif
3914 
3915  DataTable ldt_PagosFacturas = new DataTable();
3916  DataTable ltdPagosFacturas = new DataTable();
3917  bool llConsulta_Ok = false;
3918  DataRow row;
3919  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
3920  int lnDecimalesMascara;
3921  decimal lnTotal = 0.0M;
3922 
3923  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
3924  ltdPagosFacturas = DBfunctions._Crear_DtTable(la_array_cursor);
3925 
3926  // 87748
3927  string lcCondicion = string.Empty;
3928  if (!string.IsNullOrWhiteSpace(_CajaDesde))
3929  lcCondicion = lcCondicion + " and tikets.caja >= " + DB.SQLString(_CajaDesde);
3930 
3931  if (!string.IsNullOrWhiteSpace(_CajaHasta))
3932  lcCondicion = lcCondicion + " and tikets.caja <= " + DB.SQLString(_CajaHasta);
3933 
3934  if (_FechaDesde != null)
3935  lcCondicion = lcCondicion + " and tikets.fecha >= " + DB.SQLString(_FechaDesde);
3936 
3937  if (_FechaHasta != null)
3938  lcCondicion = lcCondicion + " and tikets.fecha <= " + DB.SQLString(_FechaHasta);
3939 
3940  if (string.IsNullOrWhiteSpace(lcCondicion))
3941  lcCondicion = "and " + _makeId("tikets", "tikets.arqueo=" + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? " and tikets.fecha<=" + DB.SQLString(this._dFecha) + " and tikets.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
3942  // fi 87748
3943 
3944  string lcEjercicio = string.Empty;
3945  if (!_llejercicioautomatico) lcEjercicio = " and tikets.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
3946 
3947  llConsulta_Ok = DB.SQLExec("select Sum(tikets.entrega-tikets.cambio_e) as importediv, tikets.moneda, tikets.tipo, " +
3948  DB.SQLNvl("Sum((tikets.entrega-tikets.cambio_e)/tikets.cotizacion)", 0) + " as importe " +
3949  "from " + DB.SQLDatabase("tpv", "tikets") + " " +
3950  "where tikets.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
3951  lcEjercicio + // 104028
3952  "and tikets.tipo=6 " +
3953  lcCondicion +
3954  "group by tikets.tipo,tikets.moneda", ref ldt_PagosFacturas);
3955  if (llConsulta_Ok == true)
3956  {
3957  if (ldt_PagosFacturas.Rows.Count > 0)
3958  {
3959  try
3960  {
3961  foreach (DataRow r in ldt_PagosFacturas.Rows)
3962  {
3963  string lcMoneda = Convert.ToString(r["moneda"]);
3964  if (string.IsNullOrWhiteSpace(lcMoneda))
3965  lcMoneda = this._lcMoneda_Empresa;
3966  //PE-77346
3967  loDicMoneda = _Moneda(lcMoneda);
3968  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
3969 
3970  if (Convert.ToDecimal(r["importe"]) != 0)
3971  {
3972  row = ltdPagosFacturas.NewRow();
3973 
3974  //Bug 116469
3975  //row["descripcion"] = "Pagos facturas (" + Convert.ToString(loDicMoneda["moneda"]).Trim() + ")";
3976  row["descripcion"] = "Pagos facturas (" + getSimboloMoneda(loDicMoneda) + ")";
3977 
3978  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
3979 
3980  row["moneda"] = lcMoneda;
3981 
3982  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
3983 
3984  ltdPagosFacturas.Rows.Add(row);
3985 
3986  lnTotal = lnTotal + Convert.ToDecimal(r["importe"]);
3987  }
3988  }
3989  }
3990  catch (Exception oE)
3991  {
3992  tcMsgError = "(_Load) Error en procesos internos en _Obtener_DataTable_OperCaja_Pagos_Facturas().\n\n" + oE.Message;
3993  }
3994  }
3995  }
3996  else
3997  {
3998  tcMsgError = "(_Load) Error en consulta en _Obtener_DataTable_OperCaja_Pagos_Facturas().";
3999  }
4000  tnTotalPagosFacturas = lnTotal;
4001 
4002 #if ewTools
4003  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
4004 #endif
4005 
4006  return ltdPagosFacturas;
4007  }
4008 
4009 
4014  protected virtual DataTable _Obtener_DataTable_OperCaja_Cobros_Facturas(ref decimal tnTotalCobrosFacturas, ref string tcMsgError)
4015  {
4016 #if ewTools
4017  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
4018 #endif
4019 
4020  DataTable ldt_CobrosFacturas = new DataTable();
4021  DataTable ltdCobrosFacturas = new DataTable();
4022  bool llConsulta_Ok = false;
4023  DataRow row;
4024  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
4025  int lnDecimalesMascara;
4026  decimal lnTotal = 0.0M;
4027 
4028  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
4029  ltdCobrosFacturas = DBfunctions._Crear_DtTable(la_array_cursor);
4030 
4031  // 87748
4032  string lcCondicion = string.Empty;
4033  if (!string.IsNullOrWhiteSpace(_CajaDesde))
4034  lcCondicion = lcCondicion + " and tikets.caja >= " + DB.SQLString(_CajaDesde);
4035 
4036  if (!string.IsNullOrWhiteSpace(_CajaHasta))
4037  lcCondicion = lcCondicion + " and tikets.caja <= " + DB.SQLString(_CajaHasta);
4038 
4039  if (_FechaDesde != null)
4040  lcCondicion = lcCondicion + " and tikets.fecha >= " + DB.SQLString(_FechaDesde);
4041 
4042  if (_FechaHasta != null)
4043  lcCondicion = lcCondicion + " and tikets.fecha <= " + DB.SQLString(_FechaHasta);
4044 
4045  if (string.IsNullOrWhiteSpace(lcCondicion))
4046  lcCondicion = "and " + _makeId("tikets", " tikets.arqueo=" + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? " and tikets.fecha<=" + DB.SQLString(this._dFecha) + " and tikets.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
4047  // fi 87748
4048 
4049  string lcEjercicio = string.Empty;
4050  if (!_llejercicioautomatico) lcEjercicio = " and tikets.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
4051 
4052  llConsulta_Ok = DB.SQLExec("select Sum(tikets.entrega-tikets.cambio_e) as importediv, tikets.moneda, tikets.tipo, " +
4053  DB.SQLNvl("Sum((tikets.entrega-tikets.cambio_e)/tikets.cotizacion)", 0) + " as importe " +
4054  "from " + DB.SQLDatabase("tpv", "tikets") + " " +
4055  "where tikets.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
4056  lcEjercicio + // 104028
4057  "and tikets.tipo=4 " +
4058  lcCondicion +
4059  "group by tikets.tipo,tikets.moneda", ref ldt_CobrosFacturas);
4060  if (llConsulta_Ok == true)
4061  {
4062  if (ldt_CobrosFacturas.Rows.Count > 0)
4063  {
4064  try
4065  {
4066  foreach (DataRow r in ldt_CobrosFacturas.Rows)
4067  {
4068  string lcMoneda = Convert.ToString(r["moneda"]);
4069  if (string.IsNullOrWhiteSpace(lcMoneda))
4070  lcMoneda = this._lcMoneda_Empresa;
4071  //PE-77346
4072  loDicMoneda = _Moneda(lcMoneda);
4073  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
4074 
4075  if (Convert.ToDecimal(r["importe"]) != 0)
4076  {
4077  row = ltdCobrosFacturas.NewRow();
4078 
4079  //Bug 116469
4080  //row["descripcion"] = "Cobros facturas (" + Convert.ToString(loDicMoneda["moneda"]).Trim() + ")";
4081  row["descripcion"] = "Cobros facturas (" + getSimboloMoneda(loDicMoneda) + ")";
4082 
4083  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
4084 
4085  row["moneda"] = lcMoneda;
4086 
4087  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
4088 
4089  ltdCobrosFacturas.Rows.Add(row);
4090 
4091  lnTotal = lnTotal + Convert.ToDecimal(r["importe"]);
4092  }
4093  }
4094  }
4095  catch (Exception oE)
4096  {
4097  tcMsgError = "(_Load) Error en procesos internso en _Obtener_DataTable_OperCaja_Cobros_Facturas().\n\n" + oE.Message;
4098  }
4099  }
4100  }
4101  else
4102  {
4103  tcMsgError = "(_Load) Error en consulta en _Obtener_DataTable_OperCaja_Cobros_Facturas().";
4104  }
4105  tnTotalCobrosFacturas = lnTotal;
4106 
4107 #if ewTools
4108  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
4109 #endif
4110 
4111  return ltdCobrosFacturas;
4112  }
4113 
4114 
4119  protected virtual DataTable _Obtener_DataTable_OperCaja_Cobros_Varios(ref decimal tnTotalCobrosVarios, ref string tcMsgError)
4120  {
4121 #if ewTools
4122  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
4123 #endif
4124 
4125  DataTable ldt_CobrosVarios = new DataTable();
4126  DataTable ldtCobrosVarios = new DataTable();
4127  bool llConsulta_Ok = false;
4128  DataRow row;
4129  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
4130  int lnDecimalesMascara;
4131  decimal lnTotal = 0.0M;
4132 
4133  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
4134  ldtCobrosVarios = DBfunctions._Crear_DtTable(la_array_cursor);
4135 
4136  // 87748
4137  string lcCondicion = string.Empty;
4138  if (!string.IsNullOrWhiteSpace(_CajaDesde))
4139  lcCondicion = lcCondicion + " and tikets.caja >= " + DB.SQLString(_CajaDesde);
4140 
4141  if (!string.IsNullOrWhiteSpace(_CajaHasta))
4142  lcCondicion = lcCondicion + " and tikets.caja <= " + DB.SQLString(_CajaHasta);
4143 
4144  if (_FechaDesde != null)
4145  lcCondicion = lcCondicion + " and tikets.fecha >= " + DB.SQLString(_FechaDesde);
4146 
4147  if (_FechaHasta != null)
4148  lcCondicion = lcCondicion + " and tikets.fecha <= " + DB.SQLString(_FechaHasta);
4149 
4150  if (string.IsNullOrWhiteSpace(lcCondicion))
4151  lcCondicion = "and " + _makeId("tikets", "tikets.arqueo =" + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? " and tikets.fecha<=" + DB.SQLString(this._dFecha) + " and tikets.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
4152  // fi 87748
4153 
4154  string lcEjercicio = string.Empty;
4155  if (!_llejercicioautomatico) lcEjercicio = " and tikets.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
4156 
4157  llConsulta_Ok = DB.SQLExec("select Sum(tikets.entrega-tikets.cambio_e) as importediv, tikets.moneda, tikets.tipo, " +
4158  DB.SQLNvl("Sum((tikets.entrega-tikets.cambio_e)/tikets.cotizacion)", 0) + " as importe " +
4159  "from " + DB.SQLDatabase("tpv", "tikets") + " " +
4160  "where tikets.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
4161  lcEjercicio + // 104028
4162  "and tikets.tipo=3 " +
4163  lcCondicion +
4164  "group by tikets.tipo,tikets.moneda", ref ldt_CobrosVarios);
4165  if (llConsulta_Ok == true)
4166  {
4167  if (ldt_CobrosVarios.Rows.Count > 0)
4168  {
4169  try
4170  {
4171  foreach (DataRow r in ldt_CobrosVarios.Rows)
4172  {
4173  string lcMoneda = Convert.ToString(r["moneda"]);
4174  if (string.IsNullOrWhiteSpace(lcMoneda))
4175  lcMoneda = this._lcMoneda_Empresa;
4176  //PE-77346
4177  loDicMoneda = _Moneda(lcMoneda);
4178  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
4179 
4180  if (Convert.ToDecimal(r["importe"]) != 0)
4181  {
4182  row = ldtCobrosVarios.NewRow();
4183 
4184  //Bug 116469
4185  //row["descripcion"] = "Cobros varios (" + Convert.ToString(loDicMoneda["moneda"]).Trim() + ")";
4186  row["descripcion"] = "Cobros varios (" + getSimboloMoneda(loDicMoneda) + ")";
4187 
4188  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
4189 
4190  row["moneda"] = lcMoneda;
4191 
4192  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
4193 
4194  ldtCobrosVarios.Rows.Add(row);
4195 
4196  lnTotal = lnTotal + Convert.ToDecimal(r["importe"]);
4197  }
4198  }
4199  }
4200  catch (Exception oE)
4201  {
4202  tcMsgError = "(_Load) Error en procesos internos en _Obtener_DataTable_OperCaja_Cobros_Varios().\n\n" + oE.Message;
4203  }
4204  }
4205  }
4206  else
4207  {
4208  tcMsgError = "(_Load) Error en consulta en _Obtener_DataTable_OperCaja_Cobros_Varios().";
4209  }
4210  tnTotalCobrosVarios = lnTotal;
4211 
4212 #if ewTools
4213  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
4214 #endif
4215 
4216  return ldtCobrosVarios;
4217  }
4218 
4219 
4224  protected virtual DataTable _Obtener_DataTable_OperCaja_Pagos_Varios(ref decimal tnTotalPagosVarios, ref string tcMsgError)
4225  {
4226 #if ewTools
4227  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
4228 #endif
4229 
4230  DataTable ldt_PagosVarios = new DataTable();
4231  DataTable ldtPagosVarios = new DataTable();
4232  bool llConsulta_Ok = false;
4233  DataRow row;
4234  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
4235  int lnDecimalesMascara;
4236  decimal lnTotal = 0.0M;
4237 
4238  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
4239  ldtPagosVarios = DBfunctions._Crear_DtTable(la_array_cursor);
4240 
4241  // 87748
4242  string lcCondicion = string.Empty;
4243  if (!string.IsNullOrWhiteSpace(_CajaDesde))
4244  lcCondicion = lcCondicion + " and tikets.caja >= " + DB.SQLString(_CajaDesde);
4245 
4246  if (!string.IsNullOrWhiteSpace(_CajaHasta))
4247  lcCondicion = lcCondicion + " and tikets.caja <= " + DB.SQLString(_CajaHasta);
4248 
4249  if (_FechaDesde != null)
4250  lcCondicion = lcCondicion + " and tikets.fecha >= " + DB.SQLString(_FechaDesde);
4251 
4252  if (_FechaHasta != null)
4253  lcCondicion = lcCondicion + " and tikets.fecha <= " + DB.SQLString(_FechaHasta);
4254 
4255  if (string.IsNullOrWhiteSpace(lcCondicion))
4256  lcCondicion = "and " + _makeId("tikets", " tikets.arqueo=" + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? " and tikets.fecha<=" + DB.SQLString(this._dFecha) + " and tikets.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
4257  // fi 87748
4258 
4259  string lcEjercicio = string.Empty;
4260  if (!_llejercicioautomatico) lcEjercicio = " and tikets.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
4261 
4262  llConsulta_Ok = DB.SQLExec("select Sum(tikets.entrega-tikets.cambio_e) as importediv, tikets.moneda, tikets.tipo, " +
4263  DB.SQLNvl("Sum((tikets.entrega-tikets.cambio_e)/tikets.cotizacion)", 0) + " as importe " +
4264  "from " + DB.SQLDatabase("tpv", "tikets") + " " +
4265  "where tikets.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
4266  lcEjercicio + // 104028
4267  "and tikets.tipo=5 " +
4268  lcCondicion +
4269  "group by tikets.tipo,tikets.moneda", ref ldt_PagosVarios);
4270  if (llConsulta_Ok == true)
4271  {
4272  if (ldt_PagosVarios.Rows.Count > 0)
4273  {
4274  try
4275  {
4276  foreach (DataRow r in ldt_PagosVarios.Rows)
4277  {
4278  string lcMoneda = Convert.ToString(r["moneda"]);
4279  if (string.IsNullOrWhiteSpace(lcMoneda))
4280  lcMoneda = this._lcMoneda_Empresa;
4281  //PE-77346
4282  loDicMoneda = _Moneda(lcMoneda);
4283  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
4284 
4285  if (Convert.ToDecimal(r["importe"]) != 0)
4286  {
4287  row = ldtPagosVarios.NewRow();
4288 
4289  //Bug 116469
4290  //row["descripcion"] = "Pagos varios (" + Convert.ToString(loDicMoneda["moneda"]).Trim() + ")";
4291  row["descripcion"] = "Pagos varios (" + getSimboloMoneda(loDicMoneda) + ")";
4292 
4293  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
4294 
4295  row["moneda"] = lcMoneda;
4296 
4297  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
4298 
4299  ldtPagosVarios.Rows.Add(row);
4300 
4301  lnTotal = lnTotal + Convert.ToDecimal(r["importe"]);
4302  }
4303  }
4304  }
4305  catch (Exception oE)
4306  {
4307  tcMsgError = "(_Load) Error en procesos internos en _Obtener_DataTable_OperCaja_Pagos_Varios().\n\n" + oE.Message;
4308  }
4309  }
4310  }
4311  else
4312  {
4313  tcMsgError = "(_Load) Error en consulta en _Obtener_DataTable_OperCaja_Pagos_Varios().";
4314  }
4315  tnTotalPagosVarios = lnTotal;
4316 
4317 #if ewTools
4318  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
4319 #endif
4320 
4321  return ldtPagosVarios;
4322  }
4323 
4324 
4329  protected virtual DataTable _Obtener_DataTable_OperCaja_Retiros(ref decimal tnTotalRetiros, ref string tcMsgError)
4330  {
4331 #if ewTools
4332  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
4333 #endif
4334 
4335 
4336  DataTable ldt_Retiros = new DataTable();
4337  DataTable ldtRetiros = new DataTable();
4338  bool llConsulta_Ok = false;
4339  DataRow row;
4340  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
4341  int lnDecimalesMascara;
4342  decimal lnTotal = 0.0M;
4343 
4344  object[,] la_array_cursor = { { "descripcion", "string", 50, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
4345  ldtRetiros = DBfunctions._Crear_DtTable(la_array_cursor);
4346 
4347  // 87748
4348  string lcCondicion = string.Empty;
4349  if (!string.IsNullOrWhiteSpace(_CajaDesde))
4350  lcCondicion = lcCondicion + " and cpag.caja >= " + DB.SQLString(_CajaDesde);
4351 
4352  if (!string.IsNullOrWhiteSpace(_CajaHasta))
4353  lcCondicion = lcCondicion + " and cpag.caja <= " + DB.SQLString(_CajaHasta);
4354 
4355  if (_FechaDesde != null)
4356  lcCondicion = lcCondicion + " and cpag.fecha >= " + DB.SQLString(_FechaDesde);
4357 
4358  if (_FechaHasta != null)
4359  lcCondicion = lcCondicion + " and cpag.fecha <= " + DB.SQLString(_FechaHasta);
4360 
4361  if (string.IsNullOrWhiteSpace(lcCondicion))
4362  lcCondicion = "and " + _makeId("cpag", " cpag.arqueo=" + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? " and cpag.fecha<=" + DB.SQLString(this._dFecha) + " and cpag.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
4363  // fi 87748
4364 
4365  string lcEjercicio = string.Empty;
4366  if (!_llejercicioautomatico) lcEjercicio = " and cpag.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " "; // 104028
4367 
4368  llConsulta_Ok = DB.SQLExec("select cpag.Moneda, Sum(cpag.importediv) as importediv, " +
4369  "Sum(cpag.importe) as importe " +
4370  "from " + DB.SQLDatabase("tpv", "cob_pago") + " cpag " +
4371  "where cpag.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
4372  lcEjercicio + // 104028
4373  "and cpag.operacion='R' " +
4374  lcCondicion +
4375  "group by cpag.moneda", ref ldt_Retiros);
4376  if (llConsulta_Ok == true)
4377  {
4378  if (ldt_Retiros.Rows.Count > 0)
4379  {
4380  try
4381  {
4382  foreach (DataRow r in ldt_Retiros.Rows)
4383  {
4384  string lcMoneda = Convert.ToString(r["moneda"]);
4385  if (string.IsNullOrWhiteSpace(lcMoneda))
4386  lcMoneda = this._lcMoneda_Empresa;
4387  //PE-77346
4388  loDicMoneda = _Moneda(lcMoneda);
4389  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
4390 
4391  if (Convert.ToDecimal(r["importe"]) != 0)
4392  {
4393  row = ldtRetiros.NewRow();
4394 
4395  //Bug 116469
4396  //row["descripcion"] = "Retiros caja (" + Convert.ToString(loDicMoneda["moneda"]).Trim() + ")";
4397  row["descripcion"] = "Retiros caja (" + getSimboloMoneda(loDicMoneda) + ")";
4398 
4399  row["importediv"] = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara) * -1;
4400 
4401  row["moneda"] = lcMoneda;
4402 
4403  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
4404 
4405  ldtRetiros.Rows.Add(row);
4406 
4407  lnTotal = lnTotal + Convert.ToDecimal(row["importe"]);
4408  }
4409  }
4410  }
4411  catch (Exception oE)
4412  {
4413  tcMsgError = "(_Load) Error en procesos internos en _Obtener_DataTable_OperCaja_Retiros().\n\n" + oE.Message;
4414  }
4415  }
4416  }
4417  else
4418  {
4419  tcMsgError = "(_Load) Error en consulta en _Obtener_DataTable_OperCaja_Retiros().";
4420  }
4421  tnTotalRetiros = lnTotal;
4422 
4423 #if ewTools
4424  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
4425 #endif
4426 
4427  return ldtRetiros;
4428  }
4429 
4430 
4435  protected virtual decimal _Obtener_DataTable_Desg_Familias()
4436  {
4437 #if ewTools
4438  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
4439 #endif
4440 
4441  decimal lnTotal = 0.0M;
4442  DataTable ldt_tmp_AlbD = new DataTable();
4443  bool llConsulta_Ok = false;
4444 
4445  object[,] la_array_cursor = { { "descripcion", "string", 100, "Y" }, { "moneda", "string", 3, "Y" }, { "importe", "decimal", 0, "y" }, { "importediv", "decimal", 0, "Y" } };
4446  this._nImporteDesgFamilias = 0.0M;
4447  this._dtDesg_Familias = DBfunctions._Crear_DtTable(la_array_cursor);
4448 
4449  // 87748
4450  string lcCondicion = string.Empty;
4451  if (!string.IsNullOrWhiteSpace(_CajaDesde))
4452  lcCondicion = lcCondicion + " and t.caja >= " + DB.SQLString(_CajaDesde);
4453 
4454  if (!string.IsNullOrWhiteSpace(_CajaHasta))
4455  lcCondicion = lcCondicion + " and t.caja <= " + DB.SQLString(_CajaHasta);
4456 
4457  if (_FechaDesde != null)
4458  lcCondicion = lcCondicion + " and g.fecha >= " + DB.SQLString(_FechaDesde);
4459 
4460  if (_FechaHasta != null)
4461  lcCondicion = lcCondicion + " and g.fecha <= " + DB.SQLString(_FechaHasta);
4462 
4463  if (string.IsNullOrWhiteSpace(lcCondicion))
4464  lcCondicion = "and " + _makeId("t", "t.arqueo=" + DB.SQLString(this._nNumero) + (this._nNumero == 0 ? " and g.fecha<=" + DB.SQLString(this._dFecha) + " and t.aparcado=0 and t.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
4465  // fi 87748
4466 
4467  if (string.IsNullOrWhiteSpace(_CajaDesde) && string.IsNullOrWhiteSpace(_CajaHasta))
4468  lcCondicion += " and t.caja !='' ";
4469 
4470  //PE-77346 Se añade el nombre de la familia para ahorrarnos un consulta
4471  String tcSql = "select MAX(d.familia) AS familia, MAX(f.nombre) AS nombre, MAX(g.Divisa) As divisa, sum(d.impdiviva) as importediv, sum(d.importeiva) as importe, " +
4472  " g.empresa, g.numero, g.letra, MAX(g.pronto) AS pronto, MAX(d.dto1) AS dto1, MAX(d.dto2) AS dto2, MAX(d.precioiva) AS precio, MAX(d.prediviva) AS preciodiv, " +
4473  " MAX(d.unidades) AS unidades, MAX(d.peso) AS peso, MAX(d.cajas) AS cajas, MAX(d.tipoprec) AS tipoprec " +
4474  "from " + DB.SQLDatabase("gestion", "c_albven") + " g inner join " + DB.SQLDatabase("tpv", "c_albven") + " t " +
4475  "on g.Empresa=t.empresa and g.Numero=t.numero and g.Letra=t.Letra and t.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
4476  "inner join " + DB.SQLDatabase("gestion", "d_albven") + " d ON g.Empresa=d.empresa and g.Numero=d.numero and g.letra=d.letra " +
4477  "left join " + DB.SQLDatabase("gestion", "familias") + " f ON f.codigo = d.familia " +
4478  "where t.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
4479  "and t.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
4480  "and d.tipo_iva != ' ' " +
4481  lcCondicion +
4482  "group by g.empresa, g.numero, g.letra, d.linia";
4483 
4484  llConsulta_Ok = DB.SQLExec(tcSql, ref ldt_tmp_AlbD);
4485 
4486  if (llConsulta_Ok == true)
4487  {
4488 
4489  if (ldt_tmp_AlbD.Rows.Count > 0)
4490  {
4491  try
4492  {
4493  lnTotal = DesgloseFamilias(ldt_tmp_AlbD);
4494  }
4495  catch (Exception oE)
4496  {
4497  this._MessageBox("(_Load) Error en procesos internos en _Obtener_DataTable_Desg_Familias().\n\n" + oE.Message);
4498  }
4499  }
4500  }
4501  else
4502  {
4503  this._MessageBox("(_Load) Error en consulta de reposiciones en _Obtener_DataTable_Desg_Familias().");
4504  }
4505 
4506 #if ewTools
4507  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
4508 #endif
4509 
4510  return lnTotal;
4511  }
4512 
4513 
4518  protected virtual void _Obtener_DataTable_Desg_Iva_Tiquets()
4519  {
4520 #if ewTools
4521  EwTools._WriteTrace(EwTools.eMethodStatus.Inicio);
4522 #endif
4523 
4524  DataTable ldt_Cursor = new DataTable();
4525  bool llConsulta_Ok = false, llExisteTipoIva = false;
4526  DataRow rowPeuIva;
4527  string lcEmpresa = "", lcNumero = "", lcLetra = "", lcCodigoIva = "";
4528  DataRow[] la_Rows;
4529 
4530  this._nDesgIvaTic_TotalBases = 0.0M;
4531  this._nDesgIvaTic_TotalIvas = 0.0M;
4532  this._nDesgIvaTic_TotalTotal = 0.0M;
4533 
4534  // Crear datatable que retornaremos ...
4535  object[,] la_array_cursor = { { "codigo", "string", 2, "Y" }, { "baseiva", "decimal", 0, "Y" }, { "iva_tan", "decimal", 0, "y" }, { "impiva", "decimal", 0, "y" },
4536  { "imptotal", "decimal", 0, "Y" } };
4537  this._dtDesg_Iva = DBfunctions._Crear_DtTable(la_array_cursor);
4538 
4539 
4540  // 87748
4541  string lcCondicion = string.Empty;
4542  if (!string.IsNullOrWhiteSpace(_CajaDesde))
4543  lcCondicion = lcCondicion + " and tpv.caja >= " + DB.SQLString(_CajaDesde);
4544 
4545  if (!string.IsNullOrWhiteSpace(_CajaHasta))
4546  lcCondicion = lcCondicion + " and tpv.caja <= " + DB.SQLString(_CajaHasta);
4547 
4548  if (_FechaDesde != null)
4549  lcCondicion = lcCondicion + " and ges.fecha >= " + DB.SQLString(_FechaDesde);
4550 
4551  if (_FechaHasta != null)
4552  lcCondicion = lcCondicion + " and ges.fecha <= " + DB.SQLString(_FechaHasta);
4553 
4554  if (string.IsNullOrWhiteSpace(lcCondicion))
4555  lcCondicion = "and " + _makeId("tpv", "tpv.arqueo=" + DB.SQLString(this._nNumero) + " " + (this._nNumero == 0 ? " and ges.fecha<=" + DB.SQLString(this._dFecha) + " and tpv.aparcado=0 and tpv.caja=" + DB.SQLString(this._lcCajaActiva) : "")) + " ";
4556  // fi 87748
4557 
4558  if (string.IsNullOrWhiteSpace(_CajaDesde) && string.IsNullOrWhiteSpace(_CajaHasta))
4559  lcCondicion = lcCondicion + " and tpv.caja !='' ";
4560 
4561  // Consulta de tiquets ...
4562  String tcSql = "select ges.empresa, ges.numero, ges.letra " +
4563  "from " + DB.SQLDatabase("gestion", "c_albven") + " ges inner join " + DB.SQLDatabase("tpv", "c_albven") + " tpv " +
4564  "on ges.empresa=tpv.empresa and ges.numero=tpv.numero and ges.letra=tpv.letra and tpv.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
4565  "where tpv.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
4566  "and tpv.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
4567  lcCondicion +
4568  "and tpv.tipo_doc=1 ";
4569  llConsulta_Ok = DB.SQLExec(tcSql, ref ldt_Cursor);
4570 
4571  if (llConsulta_Ok == true)
4572  {
4573  try
4574  {
4575  ewDocIva docIva;
4576 
4577  // Vamos recorriendo el DataTable de tiquets ...
4578  foreach (DataRow r in ldt_Cursor.Rows)
4579  {
4580  lcEmpresa = Convert.ToString(r["empresa"]);
4581  lcNumero = Convert.ToString(r["numero"]);
4582  lcLetra = Convert.ToString(r["letra"]);
4583 
4584 #if ewTools
4585  EwTools._WriteTrace(EwTools.eMethodStatus.Procesando, "Empresa: "+lcEmpresa + " " + lcLetra + " - " + lcNumero);
4586 #endif
4587 
4588  docIva = this.getDocIva(lcEmpresa, lcNumero, lcLetra);
4589 
4590  // Recorremos el DataTable del pie de IVA del documento de venta y acumulamos cada registro de tipo de IVA detectado en el DataTable que retornamos ...
4591  foreach (DataRow r2 in docIva.ldt_TablaIva.Rows)
4592  {
4593  lcCodigoIva = Convert.ToString(r2["codigo"]);
4594 
4595  // Buscamos el código de IVA en el DataTable de retorno ...
4596  la_Rows = this._dtDesg_Iva.Select("codigo=" + DB.SQLString(lcCodigoIva));
4597 
4598  llExisteTipoIva = (la_Rows.Length != 0) ? true : false;
4599 
4600  if (!llExisteTipoIva)
4601  {
4602  // Si no existe, creamos el registro ...
4603  rowPeuIva = this._dtDesg_Iva.NewRow();
4604  rowPeuIva["codigo"] = r2["codigo"];
4605  rowPeuIva["iva_tan"] = r2["iva_tan"];
4606  }
4607  else
4608  // Si el tipo de IVA ya existe, obtenemos una referencia a la fila del DataTable de retorno que contiene dicho tipo de IVA ...
4609  rowPeuIva = la_Rows[0];
4610 
4611  // Acumulamos base,iva,importe total
4612  rowPeuIva["baseiva"] = Convert.ToDecimal(rowPeuIva["baseiva"]) + Convert.ToDecimal(r2["baseiva"]);
4613  rowPeuIva["impiva"] = Convert.ToDecimal(rowPeuIva["impiva"]) + Convert.ToDecimal(r2["impiva"]);
4614  rowPeuIva["imptotal"] = Convert.ToDecimal(rowPeuIva["imptotal"]) + Convert.ToDecimal(r2["baseiva"]) + Convert.ToDecimal(r2["impiva"]);
4615 
4616  // Actualizar las propiedades del objeto que
4617  this._nDesgIvaTic_TotalBases = this._nDesgIvaTic_TotalBases + Convert.ToDecimal(r2["baseiva"]);
4618  this._nDesgIvaTic_TotalIvas = this._nDesgIvaTic_TotalIvas + Convert.ToDecimal(r2["impiva"]);
4619  this._nDesgIvaTic_TotalTotal = this._nDesgIvaTic_TotalTotal + Convert.ToDecimal(r2["baseiva"]) + Convert.ToDecimal(r2["impiva"]); ;
4620 
4621  if (!llExisteTipoIva)
4622  // Si el tipo de IVA no existia, añadimos el registro ...
4623  this._dtDesg_Iva.Rows.Add(rowPeuIva);
4624  }
4625 
4626 #if ewTools
4627  EwTools._WriteTrace(EwTools.eMethodStatus.Procesando, "Fin Empresa: " + lcEmpresa + " " + lcLetra + " - " + lcNumero);
4628 #endif
4629  }
4630  }
4631  catch (Exception oE)
4632  {
4633  this._MessageBox("(_Load) Error en procesos internos en _Obtener_DataTable_Desg_Iva_Tiquets().\n\n" + oE.Message);
4634  }
4635  }
4636  else
4637  {
4638  this._MessageBox("(_Load) Error en consulta de reposiciones en _Obtener_DataTable_Desg_Iva_Tiquets().");
4639  }
4640 
4641 #if ewTools
4642  EwTools._WriteTrace(EwTools.eMethodStatus.Fin);
4643 #endif
4644  }
4645 
4646 
4651  protected virtual string _Obtener_XML_desglose_iva()
4652  {
4653  //Creo un datatable de strings
4654  DataTable ldtCopyDatatableIva = new DataTable();
4655  ldtCopyDatatableIva.TableName = "DesgloseIva";
4656  Type loTipoString = typeof(String);
4657  ldtCopyDatatableIva.Columns.Add(new DataColumn("codigo", loTipoString));
4658  ldtCopyDatatableIva.Columns.Add(new DataColumn("baseiva", loTipoString));
4659  ldtCopyDatatableIva.Columns.Add(new DataColumn("iva_tan", loTipoString));
4660  ldtCopyDatatableIva.Columns.Add(new DataColumn("impiva", loTipoString));
4661  ldtCopyDatatableIva.Columns.Add(new DataColumn("imptotal", loTipoString));
4662 
4663  foreach (DataRow ldrFilaIva in this._dtDesg_Iva.Rows)
4664  {
4665  DataRow ldrNewRow = ldtCopyDatatableIva.NewRow();
4666  ldrNewRow["codigo"] = "@!" + ldrFilaIva["codigo"].ToString();
4667  ldrNewRow["baseiva"] = "@!" + ldrFilaIva["baseiva"].ToString().Replace(".", "").Replace(',', '.');
4668  ldrNewRow["iva_tan"] = "@!" + ldrFilaIva["iva_tan"].ToString().Replace(".", "").Replace(',', '.');
4669  ldrNewRow["impiva"] = "@!" + ldrFilaIva["impiva"].ToString().Replace(".", "").Replace(',', '.');
4670  ldrNewRow["imptotal"] = "@!" + ldrFilaIva["imptotal"].ToString().Replace(".", "").Replace(',', '.');
4671  ldtCopyDatatableIva.Rows.Add(ldrNewRow);
4672  }
4673 
4674  // Volcamos los datos a un fichero XML temporal para que Eurowin los pueda capturar
4675  //string lcFileNameIva = System.IO.Path.GetTempPath() + "Arqueo_desglose_iva_tmp.xml";
4676  //ldtCopyDatatableIva.WriteXml(lcDir + "Arq_iva.xml", XmlWriteMode.IgnoreSchema);
4677 
4678  // PE-94078 - Crear el fichero XML en la carpeta <euroterm>\temp
4679  string lcFileNameIva = this._CreateFileTemporalXML("Arq_iva.xml", ldtCopyDatatableIva);
4680  return lcFileNameIva;
4681  }
4682 
4683 
4689  protected object[] _addRow(object[] row)
4690  {
4691  //DataRowView listItem;
4692  //String tcCodigo;
4693  //Object[] arr;
4694 
4695  //tcCodigo = "*";
4696 
4697  //int i = 5;
4698  //if (tcCodigo == "*")
4699  //{
4700  // arr = new Object[i + this._Monedas.Count];
4701  //}
4702  //else
4703  //{
4704  // arr = new Object[i + 1];
4705 
4706  //}
4707 
4708  Object[] arr = new Object[6];
4709 
4710  arr[0] = row[0];
4711  arr[1] = row[1];
4712  arr[2] = row[2];
4713  arr[3] = row[3];
4714  arr[4] = Convert.ToInt16(row[4]);
4715  arr[5] = "";
4716 
4717  //foreach (KeyValuePair<string, string> moneda in this._Monedas)
4718  //{
4719  // if (tcCodigo == "*" || tcCodigo == moneda.Key)
4720  // {
4721  // arr[i++] = "";
4722  // }
4723  //}
4724 
4725  return arr;
4726  }
4727 
4728 
4735  protected object[] _addRow(DataRow toRow, Navegacion toNav)
4736  {
4737  //DataRowView listItem;
4738  //String tcCodigo;
4739  //Object[] arr;
4740 
4742  //ewMascara _oMascaraImport = new ewbase.ewMascara(ew.global.EW_GLOBAL._GetMascara("wc_total"));
4743  //ewMascara _oMascaraPorcent = new ewbase.ewMascara(ew.global.EW_GLOBAL._GetMascara("wc_tpc"));
4744 
4745  //String lcCadenaFormat = "{0:" + _oMascaraImport._Mascara_Net + "}";
4746 
4747  //tcCodigo = "*";
4748 
4749  //int i = 5;
4750  //if (tcCodigo == "*")
4751  //{
4752  // arr = new Object[i + this._Monedas.Count];
4753  //}
4754  //else
4755  //{
4756  // arr = new Object[i + 1];
4757 
4758  //}
4759 
4760  //arr[0] = "";
4761  //arr[1] = row["descripcion"];
4762  //arr[2] = String.Format(lcCadenaFormat, row["importe"]);
4763  //arr[3] = 0;
4764  //arr[4] = Convert.ToInt16(nav);
4765 
4766  //foreach (KeyValuePair<string, string> moneda in this._Monedas)
4767  //{
4768  // if (tcCodigo == "*" || tcCodigo == moneda.Key)
4769  // {
4770  // arr[i++] = (Convert.ToString(row["moneda"]) == Convert.ToString(moneda.Key)) ? String.Format(lcCadenaFormat, row["importediv"]) : "";
4771  // }
4772  //}
4773 
4774  String lcCadenaFormat;
4775  ewMascara _oMascaraImport;
4776  Dictionary<string, object> loDicMoneda;
4777  Object[] arr = new Object[6];
4778  String lcDivisa = Convert.ToString(toRow["moneda"]).Trim();
4779 
4780  if (String.IsNullOrEmpty(lcDivisa)) lcDivisa = EW_GLOBAL._Empresa._Moneda;
4781  loDicMoneda = _Moneda(lcDivisa);
4782 
4783  String lcMascara = Convert.ToString(loDicMoneda["grantotal"]).Trim();
4784  if (String.IsNullOrEmpty(lcMascara)) EW_GLOBAL._GetMascara(KeyDiccionarioMascara.wc_total);
4785 
4786  _oMascaraImport = new ewbase.ewMascara(lcMascara);
4787  lcCadenaFormat = "{0:" + _oMascaraImport._Mascara_Net + "}";
4788 
4789  arr[0] = "";
4790  arr[1] = toRow["descripcion"];
4791  arr[2] = String.Format(lcCadenaFormat, toRow["importediv"]);
4792  arr[3] = 0;
4793  arr[4] = Convert.ToInt16(toNav);
4794  arr[5] = lcDivisa;
4795 
4796  return arr;
4797  }
4798 
4799 
4804  protected void _Addons_Cargar()
4805  {
4806  // Si no hay addons cargados en el diccionario de la global, salimos
4808  return;
4809 
4811  //if (_Addons.Count > 0)
4812  // return;
4813 
4814  // Recorrido por los addons disponibles para ir cargando sus extensiones en el diccionario de extensiones para el documento actual
4816  .Instance
4817  .Commands
4818  .CargarExtensionesArqueoTpv(this, "arqueotpv");
4819  }
4820 
4821 
4829  protected void _Addons_Messagebox(string tcAddon, string tcMetodo, string tcMessage)
4830  {
4831  FUNCTIONS._MessageBox("Se ha producido la siguiente incidencia en la ejecución del método " + tcMetodo + " del addon " + tcAddon + ": " + Environment.NewLine + Environment.NewLine + tcMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, DialogResult.OK);
4832  }
4833 
4834 
4840  protected void _Addons_Arquear(TipoExecute teBeforeAfter)
4841  {
4842  _ExtensionArqueoTpv loExtension = null;
4843 
4844  // Recorrido por los addons disponibles, para ejecutar el método deseado en las extensiones
4845  foreach (KeyValuePair<string, object> loItem in this._Addons)
4846  {
4847  try
4848  {
4849  if (loItem.Value is _ExtensionArqueoTpv)
4850  {
4851  // Obtenemos el objeto de extensiones y lo configuramos
4852  loExtension = (_ExtensionArqueoTpv)loItem.Value;
4853  loExtension._eBeforeAfter = teBeforeAfter;
4854  loExtension._Arquear();
4855  }
4856  }
4857  catch (Exception loEx)
4858  {
4859  DB.Registrar_Error(loEx);
4860  this._Addons_Messagebox(loItem.Key, "Arquear", loEx.Message);
4861  }
4862  }
4863 
4864  return;
4865  }
4866 
4867 
4873  protected void _Addons_DesArquear(TipoExecute teBeforeAfter)
4874  {
4875  _ExtensionArqueoTpv loExtension = null;
4876 
4877  // Recorrido por los addons disponibles, para ejecutar el método deseado en las extensiones
4878  foreach (KeyValuePair<string, object> loItem in this._Addons)
4879  {
4880  try
4881  {
4882  if (loItem.Value is _ExtensionArqueoTpv)
4883  {
4884  // Obtenemos el objeto de extensiones y lo configuramos
4885  loExtension = (_ExtensionArqueoTpv)loItem.Value;
4886  loExtension._eBeforeAfter = teBeforeAfter;
4887  loExtension._DesArquear();
4888  }
4889  }
4890  catch (Exception loEx)
4891  {
4892  DB.Registrar_Error(loEx);
4893  this._Addons_Messagebox(loItem.Key, "DesArquear", loEx.Message);
4894  }
4895  }
4896 
4897  return;
4898  }
4899 
4900 
4906  protected bool _Addons_Load(TipoExecute teBeforeAfter)
4907  {
4908  _ExtensionArqueoTpv loExtension = null;
4909 
4910  // Recorrido por los addons disponibles, para ejecutar el método deseado en las extensiones
4911  foreach (KeyValuePair<string, object> loItem in this._Addons)
4912  {
4913  try
4914  {
4915  if (loItem.Value is _ExtensionArqueoTpv)
4916  {
4917  // Obtenemos el objeto de extensiones y lo configuramos
4918  loExtension = (_ExtensionArqueoTpv)loItem.Value;
4919  loExtension._eBeforeAfter = teBeforeAfter;
4920  if (!loExtension._Load())
4921  {
4922  if (!string.IsNullOrWhiteSpace(loExtension._Error_Message))
4923  this._Mensaje_Error = loExtension._Error_Message;
4924  return false;
4925  }
4926  }
4927  }
4928  catch (Exception loEx)
4929  {
4930  DB.Registrar_Error(loEx);
4931  this._Addons_Messagebox(loItem.Key, "Load", loEx.Message);
4932  }
4933  }
4934 
4935  return true;
4936  }
4937 
4938 
4944  protected bool _Addons_Save(TipoExecute teBeforeAfter)
4945  {
4946  _ExtensionArqueoTpv loExtension = null;
4947 
4948  // Recorrido por los addons disponibles, para ejecutar el método deseado en las extensiones
4949  foreach (KeyValuePair<string, object> loItem in this._Addons)
4950  {
4951  try
4952  {
4953  if (loItem.Value is _ExtensionArqueoTpv)
4954  {
4955  // Obtenemos el objeto de extensiones y lo configuramos
4956  loExtension = (_ExtensionArqueoTpv)loItem.Value;
4957  loExtension._eBeforeAfter = teBeforeAfter;
4958  if (!loExtension._Save())
4959  {
4960  if (!string.IsNullOrWhiteSpace(loExtension._Error_Message))
4961  this._Mensaje_Error = loExtension._Error_Message;
4962  return false;
4963  }
4964  }
4965  }
4966  catch (Exception loEx)
4967  {
4968  DB.Registrar_Error(loEx);
4969  this._Addons_Messagebox(loItem.Key, "Save", loEx.Message);
4970  }
4971  }
4972 
4973  return true;
4974  }
4975 
4976 
4982  protected bool _Addons_DescargarDatos(TipoExecute teBeforeAfter)
4983  {
4984  _ExtensionArqueoTpv loExtension = null;
4985 
4986  // Recorrido por los addons disponibles, para ejecutar el método deseado en las extensiones
4987  foreach (KeyValuePair<string, object> loItem in this._Addons)
4988  {
4989  try
4990  {
4991  if (loItem.Value is _ExtensionArqueoTpv)
4992  {
4993  // Obtenemos el objeto de extensiones y lo configuramos
4994  loExtension = (_ExtensionArqueoTpv)loItem.Value;
4995  loExtension._eBeforeAfter = teBeforeAfter;
4996  loExtension._DescargarDatos();
4997  }
4998  }
4999  catch (Exception loEx)
5000  {
5001  DB.Registrar_Error(loEx);
5002  this._Addons_Messagebox(loItem.Key, "DescargarDatos", loEx.Message);
5003  }
5004  }
5005 
5006  return true;
5007  }
5008 
5009 
5015  protected DataTable _Addons_MontaArqueo(TipoExecute teBeforeAfter)
5016  {
5017  DataTable ldtDataTable = null;
5018  _ExtensionArqueoTpv loExtension = null;
5019 
5020  // Recorrido por los addons disponibles, para ejecutar el método deseado en las extensiones
5021  foreach (KeyValuePair<string, object> loItem in this._Addons)
5022  {
5023  try
5024  {
5025  if (loItem.Value is _ExtensionArqueoTpv)
5026  {
5027  // Obtenemos el objeto de extensiones y lo configuramos
5028  loExtension = (_ExtensionArqueoTpv)loItem.Value;
5029  loExtension._eBeforeAfter = teBeforeAfter;
5030  loExtension._MontaArqueo();
5031  }
5032  }
5033  catch (Exception loEx)
5034  {
5035  DB.Registrar_Error(loEx);
5036  this._Addons_Messagebox(loItem.Key, "MontarArqueo", loEx.Message);
5037  }
5038  }
5039 
5040  return ldtDataTable;
5041  }
5042 
5043 
5050  {
5051  _ExtensionArqueoTpv loExtension = null;
5052 
5053  // Recorrido por los addons disponibles, para ejecutar el método deseado en las extensiones
5054  foreach (KeyValuePair<string, object> loItem in this._Addons)
5055  {
5056  try
5057  {
5058  if (loItem.Value is _ExtensionArqueoTpv)
5059  {
5060  // Obtenemos el objeto de extensiones y lo configuramos
5061  loExtension = (_ExtensionArqueoTpv)loItem.Value;
5062  loExtension._eBeforeAfter = teBeforeAfter;
5063  loExtension._Obtener_DataTable_Arqueo_Caja();
5064  }
5065  }
5066  catch (Exception loEx)
5067  {
5068  DB.Registrar_Error(loEx);
5069  this._Addons_Messagebox(loItem.Key, "Obtener_DataTable_Arqueo_Caja", loEx.Message);
5070  }
5071  }
5072 
5073  return;
5074  }
5075 
5076 
5085  protected void _Addons_Print(TipoExecute teBeforeAfter, TiposDeArqueos teTipoDeArqueo, string tcFileXMLDatos, string tcCaption)
5086  {
5087  _ExtensionArqueoTpv loExtension = null;
5088 
5089  // Recorrido por los addons disponibles, para ejecutar el método deseado en las extensiones
5090  foreach (KeyValuePair<string, object> loItem in this._Addons)
5091  {
5092  try
5093  {
5094  if (loItem.Value is _ExtensionArqueoTpv)
5095  {
5096  // Obtenemos el objeto de extensiones y lo configuramos
5097  loExtension = (_ExtensionArqueoTpv)loItem.Value;
5098  loExtension._eBeforeAfter = teBeforeAfter;
5099  loExtension._Print(teTipoDeArqueo, tcFileXMLDatos, tcCaption);
5100  }
5101  }
5102  catch (Exception loEx)
5103  {
5104  DB.Registrar_Error(loEx);
5105  this._Addons_Messagebox(loItem.Key, "Print", loEx.Message);
5106  }
5107  }
5108 
5109  return;
5110  }
5111 
5112 
5125  protected void _Addons_Print_Consolida(TipoExecute teBeforeAfter, string tcFileXMLDatos, string tcCaption,
5126  string tcCajaIni, string tcCajaFin, DateTime dFechaIni, DateTime dFechaFin,
5127  Boolean tlTodasCajas)
5128  {
5129  _ExtensionArqueoTpv loExtension = null;
5130 
5131  // Recorrido por los addons disponibles, para ejecutar el método deseado en las extensiones
5132  foreach (KeyValuePair<string, object> loItem in this._Addons)
5133  {
5134  try
5135  {
5136  if (loItem.Value is _ExtensionArqueoTpv)
5137  {
5138  // Obtenemos el objeto de extensiones y lo configuramos
5139  loExtension = (_ExtensionArqueoTpv)loItem.Value;
5140  loExtension._eBeforeAfter = teBeforeAfter;
5141  loExtension._Print_Consolida(tcFileXMLDatos, tcCaption, tcCajaIni, tcCajaFin, dFechaIni, dFechaFin, tlTodasCajas);
5142  }
5143  }
5144  catch (Exception loEx)
5145  {
5146  DB.Registrar_Error(loEx);
5147  this._Addons_Messagebox(loItem.Key, "Print_Consolida", loEx.Message);
5148  }
5149  }
5150 
5151  return;
5152  }
5153 
5154 
5155  #endregion MÉTODOS PROTECTED
5156 
5157 
5158  #region METODOS PRIVADOS
5159 
5160 
5164  private void _detalle_arqueo(String tcTipo, Int16 tiTipo = 0)
5165  {
5166  // Preparem els paràmtres per navegar
5167  object[] loParameImp;
5168  if (tiTipo == 0)
5169  {
5170  loParameImp = new object[5] { tcTipo, this._dFecha_Inicial, this._dFecha_Final, this._Caja, this._Caja };
5171  }
5172  else
5173  {
5174  loParameImp = new object[6] { tcTipo, this._dFecha_Inicial, this._dFecha_Final, this._Caja, this._Caja, tiTipo };
5175  }
5176 
5177  //PE-86776
5178  NETVFP._Abrir_Formulario_VFP(tcTipo, loParameImp);
5179 
5180  }
5181 
5182 
5186  private void _detalle_arqueo(string tcNavegacion, string tcDescripcion, string tcListado = "", int tcOpCajaOpcion = 0, String tcDivisa = "")
5187  {
5188  // 88164
5189  string lcMoneda; ;
5190  object[] loParameImp;
5191  string lcListaArqueos = string.Empty;
5192  string lcDolar = string.Empty;
5193 
5194  //T115439
5195  lcMoneda = String.IsNullOrEmpty(tcDivisa.Trim()) ? EW_GLOBAL._GetVariable("wc_moneda").ToString() : tcDivisa;
5196 
5197  if (_FechaDesde == null && _FechaHasta == null)
5198  {
5199  // Inicialitzo els valors
5200  if (tcNavegacion == "Credit" || tcNavegacion == "Abonos")
5201  {
5202  _FechaDesde = Convert.ToDateTime(EW_GLOBAL._GetVariable("wd_PeriodoIni"));
5203  _FechaHasta = _Fecha;
5204  }
5205  else
5206  {
5207  // 88818
5208  if (_Fecha.Year.ToString() == Convert.ToString(EW_GLOBAL._GetVariable("wc_any")))
5209  {
5210  _FechaDesde = _Fecha;
5211  _FechaHasta = _Fecha;
5212  }
5213  else
5214  {
5215  _FechaDesde = Convert.ToDateTime(EW_GLOBAL._GetVariable("wd_PeriodoIni"));
5216  _FechaHasta = Convert.ToDateTime(EW_GLOBAL._GetVariable("wd_PeriodoFin"));
5217 
5218  }
5219 
5220  // fi 88818
5221  }
5222 
5223 
5224  // PE-90460 - Para el listado de abonos y créditos se tiene de pasar el array de arqueos.
5225  // PE-90454 - Pasar el parámetro con la lista de arqueos
5226  foreach (KeyValuePair<string, string> itemNum in _Numeros)
5227  {
5228  lcListaArqueos = lcListaArqueos + lcDolar + itemNum.Value;
5229 
5230  if (string.IsNullOrWhiteSpace(lcDolar)) lcDolar = "$";
5231 
5232  }
5233 
5234 
5235  // Arqueig de caixa
5236  loParameImp = new object[10]
5237  {
5238  tcNavegacion, // tipo de navegacion
5239  _Numero, // numero de arqueo
5240  _Caja, // Caja Inicial
5241  _Caja, // Caja final
5242  false, // Todas las cajas
5243  tcDescripcion, // Descripción
5244  _FechaDesde, // Fecha Inicial
5245  _FechaHasta, // Fecha Final
5246  lcMoneda, // Moneda
5247  lcListaArqueos // Array de arqueos
5248  };
5249 
5250  // Restauro els valors
5251  _FechaDesde = null;
5252  _FechaHasta = null;
5253  }
5254  else
5255  {
5256  // Consolidació d'aquejos
5257  loParameImp = new object[10]
5258  {
5259  tcNavegacion, // tipo de navegacion
5260  false, // numero de arqueo
5261  _CajaDesde, // Caja Inicial
5262  _CajaHasta, // Caja final
5263  _TodasCajas, // Todas las cajas
5264  tcDescripcion, // Descripción
5265  _FechaDesde, // Fecha Inicial
5266  _FechaHasta, // Fecha Final
5267  lcMoneda, // Moneda
5268  "" // Array de arqueos
5269  };
5270  }
5271 
5272  if (String.IsNullOrEmpty(tcListado))
5273  NETVFP._Ejecutar_Funcion_VFP("Navegacion_Arqueo_Net", loParameImp);
5274  else
5275  // PE-91609 - Imprimir listado arqueos .NET
5276  this._detalle_arqueo_net(tcListado, loParameImp, tcOpCajaOpcion);
5277 
5278  // fi 88164
5279 
5280  }
5281 
5282 
5289  private void _detalle_arqueo_net(string tcListado, object[] toParameImp, int tcOpCajaOpcion)
5290  {
5291  DateTime ldFechaDesde, ldFechaHasta;
5292  string lcCajaDesde, lcCajaHasta, lcListaArqueos, lcDescripcion;
5293  bool llTodasCajas = false;
5294  int lnNumero = -1;
5295  Dictionary<string, object> _DicArqueos = new Dictionary<string, object>();
5296  List<string> loLista = new List<string>();
5297 
5298  String lcNavegacion = Convert.ToString(toParameImp[0]);
5299  lnNumero = toParameImp[1] is bool ? -1 : Convert.ToInt16(toParameImp[1]);
5300  lcCajaDesde = Convert.ToString(toParameImp[2]);
5301  lcCajaHasta = Convert.ToString(toParameImp[3]);
5302  llTodasCajas = Convert.ToBoolean(toParameImp[4]);
5303  lcDescripcion = Convert.ToString(toParameImp[5]);
5304  ldFechaDesde = Convert.ToDateTime(toParameImp[6]);
5305  ldFechaHasta = Convert.ToDateTime(toParameImp[7]);
5306  lcListaArqueos = Convert.ToString(toParameImp[9]);
5307 
5308  String lcDivisa = Convert.ToString(toParameImp[8]);
5309 
5310  // Definir un diccionario con lo arqueos
5311  if (!String.IsNullOrEmpty(lcListaArqueos))
5312  {
5313  loLista = lcListaArqueos.Split('$').ToList();
5314  if (loLista.Count > 0)
5315  _DicArqueos.Add("ArqueoLista", loLista);
5316  }
5317 
5318 
5319  // Crear un objeto con el listado
5320  FormListado loListado = new FormListado(tcListado.Trim().ToUpper());
5321 
5322 
5323  if (!String.IsNullOrEmpty(lcDivisa) && lcDivisa != Convert.ToString(EW_GLOBAL._GetVariable("wc_moneda")) && loListado._Opciones.ContainsKey("cmbdivisa"))
5324  {
5325  ((sage.ew.txtbox.txtDivisaBase)loListado._Opciones["cmbdivisa"])._Codigo = lcDivisa;
5326  }
5327 
5328  // Definir los filtros y opciones según el listado
5329  switch (tcListado)
5330  {
5331  case "L_CAJAS":
5332  ((sage.ew.listados.Listados.VentasCajas)loListado._Listado)._nArqueo = lnNumero;
5333  ((sage.ew.listados.Listados.VentasCajas)loListado._Listado)._nArqueos = _DicArqueos;
5334  ((sage.ew.listados.Listados.VentasCajas)loListado._Listado)._lIvaIncluido = true;
5335 
5336  if (loListado._Opciones.ContainsKey("chTicket") && loListado._Opciones.ContainsKey("chAlbaran") && loListado._Opciones.ContainsKey("chFactura"))
5337  {
5338  ((sage.ew.objetos.ewcheckbox)loListado._Opciones["chTicket"]).Checked = false;
5339  ((sage.ew.objetos.ewcheckbox)loListado._Opciones["chAlbaran"]).Checked = false;
5340  ((sage.ew.objetos.ewcheckbox)loListado._Opciones["chFactura"]).Checked = false;
5341 
5342  // Marcar la opción según si és ticke, albaran o factura
5343  switch (lcNavegacion)
5344  {
5345  case "Tickets":
5346  ((sage.ew.objetos.ewcheckbox)loListado._Opciones["chTicket"]).Checked = true;
5347  break;
5348  case "Albaranes":
5349  ((sage.ew.objetos.ewcheckbox)loListado._Opciones["chAlbaran"]).Checked = true;
5350  break;
5351  case "Facturas":
5352  ((sage.ew.objetos.ewcheckbox)loListado._Opciones["chFactura"]).Checked = true;
5353  break;
5354 
5355  }
5356  }
5357 
5358  if (loListado._Opciones.ContainsKey("chIncluirticketsapar"))
5359  {
5360  ((sage.ew.objetos.ewcheckbox)loListado._Opciones["chIncluirticketsapar"]).Checked = false;
5361  }
5362 
5363  break;
5364 
5365  case "L_OPCAJA": // operaciones caja
5366  ((sage.ew.listados.Listados.OperacionesCaja)loListado._Listado)._nArqueo = lnNumero;
5367  ((sage.ew.listados.Listados.OperacionesCaja)loListado._Listado)._nArqueos = _DicArqueos;
5368 
5369  // Añadir el filtro según la forma de cobro
5370  if (loListado._Filtros.ContainsKey("txtFormaCobroDesdeHasta") && !String.IsNullOrEmpty(lcDescripcion))
5371  {
5372  ((sage.ew.listados.Listados.OperacionesCaja)loListado._Listado)._llIncluirVales = false;
5373 
5374  String lcCodigo = Convert.ToString(DB.SQLValor("F_COBROS", "NOMBRE", Convert.ToString(lcDescripcion), "CODIGO", "TPV"));
5375  if (!String.IsNullOrEmpty(lcCodigo))
5376  {
5377  ConfiguradorFiltroVisual loFiltroCobro = new ConfiguradorFiltroVisual();
5378  loFiltroCobro._Unico = Convert.ToString(lcCodigo);
5379 
5380  ((IEwFiltro)loListado._Filtros["txtFormaCobroDesdeHasta"])._SetValuesFrom_ConfiguradorFiltroVisual(loFiltroCobro);
5381  }
5382  }
5383 
5384 
5385  if (loListado._Filtros.ContainsKey("txtSeleccionTipoDesdeHasta") && tcOpCajaOpcion > 0)
5386  {
5388  loFiltroTipo._Unico = Convert.ToString(tcOpCajaOpcion);
5389 
5390  ((IEwFiltro)loListado._Filtros["txtSeleccionTipoDesdeHasta"])._SetValuesFrom_ConfiguradorFiltroVisual(loFiltroTipo);
5391  }
5392 
5393 
5394  break;
5395 
5396  case "L_REPOSI": // reposiciones
5397  ((sage.ew.listados.Listados.Reposiciones)loListado._Listado)._nArqueo = lnNumero;
5398  ((sage.ew.listados.Listados.Reposiciones)loListado._Listado)._nArqueos = _DicArqueos;
5399 
5400  if (loListado._Opciones.ContainsKey("cmbOperarioCajacombo"))
5401  ((sage.ew.objetos.ewcombobox)loListado._Opciones["cmbOperarioCajacombo"]).SelectedIndex = 1;
5402 
5403  break;
5404 
5405 
5406  case "L_RETIROS": // retiros
5407  ((sage.ew.listados.Listados.Retiros)loListado._Listado)._nArqueo = lnNumero;
5408  ((sage.ew.listados.Listados.Retiros)loListado._Listado)._nArqueos = _DicArqueos;
5409 
5410  // Opción caja
5411  if (loListado._Opciones.ContainsKey("cmbOperarioCajacombo"))
5412  ((sage.ew.objetos.ewcombobox)loListado._Opciones["cmbOperarioCajacombo"]).SelectedIndex = 1; // Caja
5413 
5414  break;
5415 
5416 
5417  case "VEN_CA": // Ventas Familia
5418 
5419  VentasClienteArticulo loVentasClienteArticulo = (VentasClienteArticulo)loListado._Listado;
5420  loVentasClienteArticulo._nArqueo = lnNumero;
5421  loVentasClienteArticulo._nArqueos = _DicArqueos;
5422  loVentasClienteArticulo._lMostrarSoloArtSinCodif = false;
5423  loVentasClienteArticulo._DescuentoProntoPago = true; // Activamos la opción para que tenga en cuenta el pronto pago al calcular los importes
5424 
5425  // Definir el filtro de la familia
5426  if (loListado._Filtros.ContainsKey("txtFamiliaDesdeHasta") && !String.IsNullOrEmpty(lcDescripcion))
5427  {
5428  int lnLenFamilia = Convert.ToInt32(EW_GLOBAL._GetLenCampo(KeyDiccionarioLenCampos.wn_familia)); //PE-94117
5429  String lcCodigo = lcDescripcion.Substring(0, lnLenFamilia);
5430  if (!String.IsNullOrEmpty(lcCodigo))
5431  {
5432  // PE-94944
5433  string lcFamiliaArtSinCodif = "SIN CODIFICAR";
5434  if (lcCodigo != lcFamiliaArtSinCodif.Substring(0, lnLenFamilia))
5435  {
5436  // Si la familia sobre la que estamos situado es una familia concreta, acotaremos el listado de ventas cliente/artículo por familias
5437  ConfiguradorFiltroVisual loFiltroCobro = new ConfiguradorFiltroVisual();
5438  loFiltroCobro._Unico = Convert.ToString(lcCodigo);
5439 
5440  ((IEwFiltro)loListado._Filtros["txtFamiliaDesdeHasta"])._SetValuesFrom_ConfiguradorFiltroVisual(loFiltroCobro);
5441  }
5442  else
5443  {
5444  // Si la familia sobre la que estamos situado es "SIN CODIFICAR" el importe mostrado corresponde al importe acumulado en ventas de artículos sin codificar por tanto marcaremos en el objeto
5445  // de negocio del listado de ventas cliente/articulo que estamos en este caso especial (recordar que visualmente no se puede acotar este listado de esta manera, no es posible
5446  // decirle visualmente que únicamente se muestren las ventas de artículos sin codificar).
5447  loVentasClienteArticulo._lMostrarSoloArtSinCodif = true;
5448  }
5449 
5450  }
5451  }
5452 
5453  // Añadir el filtro de caja para poder realizar la acotación
5454  if (!loListado._Filtros.ContainsKey("txtCajaDesdeHasta"))
5455  {
5456  sage.ew.txtbox.UserControls.txtCajaDesdeHasta loCaja = new txtbox.UserControls.txtCajaDesdeHasta();
5457  loListado._Filtros.Add("txtCajaDesdeHasta", loCaja);
5458  }
5459 
5460  // Ordenado por cliente
5461  if (loListado._Opciones.ContainsKey("cmbArticuloClienteco"))
5462  ((sage.ew.objetos.ewcombobox)loListado._Opciones["cmbArticuloClienteco"]).SelectedIndex = 1; // cliente
5463 
5464  // Iva incluido
5465  if (loListado._Opciones.ContainsKey("txtSelIva"))
5466  ((sage.ew.txtbox.UserControls.txtSelIva)loListado._Opciones["txtSelIva"])._lIvaIncluido = true;
5467 
5468  break;
5469 
5470 
5471  case "CREDIT_TPV": // crédito
5472  ((sage.ew.listados.Listados.VentasCredito)loListado._Listado)._nArqueo = lnNumero;
5473  ((sage.ew.listados.Listados.VentasCredito)loListado._Listado)._nArqueos = _DicArqueos;
5474  ((sage.ew.listados.Listados.VentasCredito)loListado._Listado)._lIvaIncluido = true;
5475  ((sage.ew.listados.Listados.VentasCredito)loListado._Listado)._nAcreditoAparcados = 0;
5476 
5477  if (loListado._Opciones.ContainsKey("chTicket") && loListado._Opciones.ContainsKey("chAlbaran") && loListado._Opciones.ContainsKey("chFactura"))
5478  {
5479  ((sage.ew.objetos.ewcheckbox)loListado._Opciones["chTicket"]).Checked = true;
5480  ((sage.ew.objetos.ewcheckbox)loListado._Opciones["chAlbaran"]).Checked = true;
5481  ((sage.ew.objetos.ewcheckbox)loListado._Opciones["chFactura"]).Checked = false;
5482  }
5483 
5484  break;
5485 
5486 
5487  case "L_ABONOS": // abonos
5488  ((sage.ew.listados.Listados.LineasAbonos)loListado._Listado)._nArqueo = lnNumero;
5489  ((sage.ew.listados.Listados.LineasAbonos)loListado._Listado)._nArqueos = _DicArqueos;
5490  ((sage.ew.listados.Listados.LineasAbonos)loListado._Listado)._lIvaIncluido = true;
5491 
5492  if (loListado._Opciones.ContainsKey("cmbOperarioCajacombo"))
5493  ((sage.ew.objetos.ewcombobox)loListado._Opciones["cmbOperarioCajacombo"]).SelectedIndex = 0; // Operario
5494 
5495 
5496  break;
5497 
5498 
5499  }
5500 
5501  // Opción desglosado
5502  if (loListado._Opciones.ContainsKey("cmbAgrupadoDesglosad"))
5503  ((sage.ew.objetos.ewcombobox)loListado._Opciones["cmbAgrupadoDesglosad"]).SelectedIndex = 1; // Desglosado
5504 
5505 
5506  // Definir el filtro de caja
5508  if (!String.IsNullOrEmpty(lcCajaDesde) && lcCajaDesde == lcCajaHasta)
5509  loFiltroCaja._Unico = lcCajaDesde;
5510  else
5511  {
5512  loFiltroCaja._Desde = lcCajaDesde;
5513  loFiltroCaja._Hasta = lcCajaHasta;
5514  }
5515 
5516  // Definir el filtro de fecha
5517  ConfiguradorFiltroVisual loFiltroFecha = new ConfiguradorFiltroVisual();
5518  if (ldFechaDesde == ldFechaHasta)
5519  loFiltroFecha._Unico = Convert.ToString(ldFechaDesde);
5520  else
5521  {
5522  loFiltroFecha._Desde = Convert.ToString(ldFechaDesde);
5523  loFiltroFecha._Hasta = Convert.ToString(ldFechaHasta);
5524  }
5525 
5526 
5527  // Definir el filtro de caja
5528  if (loListado._Filtros.ContainsKey("txtCajaDesdeHasta"))
5529  {
5530  ((IEwFiltro)loListado._Filtros["txtCajaDesdeHasta"])._SetValuesFrom_ConfiguradorFiltroVisual(loFiltroCaja);
5531  sage.ew.txtbox.UserControls.txtCajaDesdeHasta loControlCaja = (sage.ew.txtbox.UserControls.txtCajaDesdeHasta)loListado._Filtros["txtCajaDesdeHasta"];
5532  loControlCaja._Todos = llTodasCajas;
5533  }
5534 
5535  // Definir el filtro de fecha
5536  if (loListado._Filtros.ContainsKey("txtFechaDesdeHasta"))
5537  ((IEwFiltro)loListado._Filtros["txtFechaDesdeHasta"])._SetValuesFrom_ConfiguradorFiltroVisual(loFiltroFecha);
5538 
5539  loListado._ShowResult();
5540  }
5541 
5542 
5550  private String _makeId(string tcPrefix, String tcDefault, String tcFieldName = "arqueo")
5551  {
5552  String lcNumeros = String.Empty;
5553  String lcCajas = String.Empty;
5554 
5555  if (_Cajas.Count > 0 || _Numeros.Count > 0)
5556  {
5557  if (!String.IsNullOrEmpty(tcPrefix)) tcPrefix = String.Format("{0}.", tcPrefix);
5558  foreach (KeyValuePair<string, string> item in _Cajas)
5559  {
5560  if (!String.IsNullOrEmpty(lcCajas)) lcCajas += " OR ";
5561  lcCajas += String.Format("{0}caja = '{1}' ", tcPrefix, item.Value);
5562  foreach (KeyValuePair<string, string> itemNum in _Numeros)
5563  {
5564  if (!String.IsNullOrEmpty(lcNumeros)) lcNumeros += " OR ";
5565  lcNumeros += String.Format("{0}{1} = '{2}' ", tcPrefix, tcFieldName, itemNum.Value);
5566  }
5567  lcCajas = String.Format("{0} AND ({1})", lcCajas, lcNumeros);
5568  lcNumeros = String.Empty;
5569  }
5570  lcCajas = String.Format("({0})", lcCajas);
5571  }
5572  else
5573  {
5574  lcCajas = tcDefault;
5575  }
5576  return lcCajas;
5577  }
5578 
5579 
5584  private void _UpdateOffLine(Int32 tnEstado)
5585  {
5586  String lcSql = "";
5587 
5588  //Marcar registros de TPV!C_ALBVEN
5589  if (DB.SQLExisteCampo("TPV", "C_ALBVEN", "COM_ESTADO"))
5590  {
5591  lcSql = string.Format("UPDATE {0} SET COM_ESTADO = {6} , COM_FECHA = CURRENT_TIMESTAMP FROM {0} a INNER JOIN {1} b ON a.EMPRESA = b.EMPRESA AND a.NUMERO = b.NUMERO AND a.LETRA = b.LETRA AND a.EJERCICIO = {2} WHERE a.COM_ESTADO = 1 AND a.ARQUEO = {3} AND a.EMPRESA = {4} AND a.CAJA = {5} ", DB.SQLDatabase("TPV", "C_ALBVEN"), DB.SQLDatabase("GESTION", "C_ALBVEN"), DB.SQLString(this._lcEjercicioActivo.PadRight(15)), DB.SQLString(this._nNumero), DB.SQLString(this._lcEmpresaActiva), DB.SQLString(this._lcCajaActiva), tnEstado);
5592  DB.SQLExec(lcSql);
5593  }
5594 
5595  //Marcar registros de TPV!TIKETS
5596  if (DB.SQLExisteCampo("TPV", "TIKETS", "COM_ESTADO"))
5597  {
5598  lcSql = string.Format("UPDATE {0} SET COM_ESTADO = {5} , COM_FECHA = CURRENT_TIMESTAMP WHERE COM_ESTADO = 1 AND ARQUEO = {1} AND EMPRESA = {2} AND CAJA = {3} AND EJERCICIO = {4} ", DB.SQLDatabase("TPV", "TIKETS"), DB.SQLString(this._nNumero), DB.SQLString(this._lcEmpresaActiva), DB.SQLString(this._lcCajaActiva), DB.SQLString(this._lcEjercicioActivo.PadRight(15)), tnEstado);
5599  DB.SQLExec(lcSql);
5600  }
5601 
5602  //Marcar registros de TPV!VALES
5603  if (DB.SQLExisteCampo("TPV", "VALES", "COM_ESTADO"))
5604  {
5605  lcSql = string.Format("UPDATE {0} SET COM_ESTADO = {5} , COM_FECHA = CURRENT_TIMESTAMP WHERE COM_ESTADO = 1 AND ARQUEO = {1} AND EMPRESA = {2} AND CAJA = {3} AND EJERCICIO = {4} ", DB.SQLDatabase("TPV", "VALES"), DB.SQLString(this._nNumero), DB.SQLString(this._lcEmpresaActiva), DB.SQLString(this._lcCajaActiva), DB.SQLString(this._lcEjercicioActivo.PadRight(15)), tnEstado);
5606  DB.SQLExec(lcSql);
5607  }
5608 
5609  //Marcar registros de TPV!REPOSI
5610  if (DB.SQLExisteCampo("TPV", "REPOSI", "COM_ESTADO"))
5611  {
5612  lcSql = string.Format("UPDATE {0} SET COM_ESTADO = {5} , COM_FECHA = CURRENT_TIMESTAMP WHERE COM_ESTADO = 1 AND ARQUEO = {1} AND EMPRESA = {2} AND CAJA = {3} AND EJERCICIO = {4} ", DB.SQLDatabase("TPV", "REPOSI"), DB.SQLString(this._nNumero), DB.SQLString(this._lcEmpresaActiva), DB.SQLString(this._lcCajaActiva), DB.SQLString(this._lcEjercicioActivo.PadRight(15)), tnEstado);
5613  DB.SQLExec(lcSql);
5614  }
5615 
5616  // Marcar registros de TPV!COB_PAGO
5617  if (DB.SQLExisteCampo("TPV", "COB_PAGO", "COM_ESTADO"))
5618  {
5619  lcSql = string.Format("UPDATE {0} SET COM_ESTADO = {5}, COM_FECHA = CURRENT_TIMESTAMP WHERE COM_ESTADO = 1 AND ARQUEO = {1} AND EMPRESA = {2} AND CAJA = {3} AND EJERCICIO = {4} AND OPERACION ='R' ", DB.SQLDatabase("TPV", "COB_PAGO"), DB.SQLString(this._nNumero), DB.SQLString(this._lcEmpresaActiva), DB.SQLString(this._lcCajaActiva), DB.SQLString(this._lcEjercicioActivo.PadRight(15)), tnEstado);
5620  DB.SQLExec(lcSql);
5621  }
5622  }
5623 
5624 
5629  private void _AddBlank(Boolean tlValidate = true)
5630  {
5631  Boolean lOk = true;
5632 
5633  if (tlValidate)
5634  {
5635  if (_oDtArqueo.Rows.Count > 0)
5636  {
5637  lOk = Convert.ToString(_oDtArqueo.Rows[_oDtArqueo.Rows.Count - 1][0]) != "" || Convert.ToString(_oDtArqueo.Rows[_oDtArqueo.Rows.Count - 1][1]) != "" || Convert.ToString(_oDtArqueo.Rows[_oDtArqueo.Rows.Count - 1][2]) != "" || Convert.ToInt32(_oDtArqueo.Rows[_oDtArqueo.Rows.Count - 1][3]) != 0;
5638  }
5639  }
5640 
5641  if (lOk) _oDtArqueo.Rows.Add(_addRow(new Object[] { "", "", "", 0, Navegacion.No }));
5642  }
5643 
5644 
5649  private void AgruparVentas(ref DataTable tdtDetalleVentasArqueo)
5650  {
5651  var query = from gventas in tdtDetalleVentasArqueo.AsEnumerable()
5652  orderby gventas.Field<string>("FAMILIA"),
5653  gventas.Field<string>("NOMBRE"),
5654  gventas.Field<string>("DIVISA")
5655  group gventas by new
5656  {
5657  familia = gventas.Field<string>("FAMILIA"),
5658  nombre = gventas.Field<string>("NOMBRE"),
5659  divisa = gventas.Field<string>("DIVISA")
5660  } into gnventas
5661  select new
5662  {
5663  familia = gnventas.Key.familia,
5664  nombre = gnventas.Key.nombre,
5665  divisa = gnventas.Key.divisa,
5666  importe = gnventas.Sum(sum => sum.Field<decimal>("IMPORTE")),
5667  importediv = gnventas.Sum(sum => sum.Field<decimal>("IMPORTEDIV"))
5668  };
5669 
5670  tdtDetalleVentasArqueo = query.__CopyToDataTable();
5671  }
5672 
5673 
5679  private decimal DesgloseFamilias(DataTable tdtDetalleVentasArqueo)
5680  {
5681  decimal lnTotal = 0.0M, lnTotalDiv = 0.0M, lnImporteDiv = 0.0M;
5682 
5683  DataRow row;
5684  Dictionary<string, object> loDicMoneda = new Dictionary<string, object>();
5685  int lnDecimalesMascara;
5686  string lcFamilia;
5687  string lcMonedaEmp = Convert.ToString(_lcMoneda_Empresa);
5688  loDicMoneda = _Moneda(lcMonedaEmp);
5689  string lcMascara = Convert.ToString(loDicMoneda["grantotal"]);
5690 
5691  FUNCTIONS._CalcularVentasProntoPago(ref tdtDetalleVentasArqueo, lcMascara, new List<string>() { "divisa", "preciodiv", "importediv" });
5692 
5693  AgruparVentas(ref tdtDetalleVentasArqueo);
5694 
5695  foreach (DataRow r in tdtDetalleVentasArqueo.Rows)
5696  {
5697  if (Convert.ToDecimal(r["importe"]) != 0)
5698  {
5699  string lcMoneda = Convert.ToString(r["divisa"]);
5700 
5701  if (string.IsNullOrWhiteSpace(lcMoneda)) lcMoneda = this._lcMoneda_Empresa;
5702  //PE-77346 Se guardan los valores de la moneda en memoria pues la sql se repite constantemente
5703  loDicMoneda = _Moneda(lcMoneda);
5704  lnDecimalesMascara = Divisa._Decimals_Mascara(Convert.ToString(loDicMoneda["grantotal"]));
5705  lcFamilia = Convert.ToString(r["familia"]);
5706 
5707  row = this._dtDesg_Familias.NewRow();
5708 
5709  if (string.IsNullOrWhiteSpace(lcFamilia))
5710  row["descripcion"] = "SIN CODIFICAR";
5711  else
5712  row["descripcion"] = String.Format("{0} {1} {2}", lcFamilia, Convert.ToString(r["nombre"]).Trim(), "(" + getSimboloMoneda(loDicMoneda) + ")");
5713 
5714  row["moneda"] = r["divisa"];
5715 
5716  lnImporteDiv = FUNCTIONS._Round(Convert.ToDecimal(r["importediv"]), lnDecimalesMascara);
5717  row["importediv"] = lnImporteDiv;
5718 
5719  //PE-77346 Se guardan los valores de la cotización en memoria pues la sql se repite constantemente
5720  row["importe"] = Divisa._DivExacto(_Cotizacion(lcMoneda), Convert.ToDecimal(row["importediv"]), lcMoneda);
5721 
5722  this._dtDesg_Familias.Rows.Add(row);
5723 
5724  lnTotal = lnTotal + Convert.ToDecimal(row["importe"]);
5725  lnTotalDiv = lnTotalDiv + lnImporteDiv;
5726  }
5727  }
5728 
5729  // Esto de cuadrar las ventas por familias con las ventas totales sumandos tiquets, albaranes, facturas el standar solo lo hace cuando estamos
5730  // consultando lo pendiente de arquear. Cuando consultamos un arqueo ya cerrado no lo hace, por tanto, seguiremos el mismo criterio.
5731  if (_Numeros.Count == 0)
5732  // Controlar y corregir descuadres entre total ventas y total desglose familias ...
5733  if (_nImporteTotalVentas != lnTotal && lnTotal != 0)
5734  {
5735  decimal lnDif = Math.Abs(this._nImporteTotalVentas - lnTotal);
5736  if (this._nImporteTotalVentas < lnTotal)
5737  lnDif = lnDif * -1;
5738  decimal lnImporte2 = Convert.ToDecimal(_dtDesg_Familias.Rows[_dtDesg_Familias.Rows.Count - 1]["importe"]) + lnDif;
5739 
5740  _dtDesg_Familias.Rows[_dtDesg_Familias.Rows.Count - 1]["importe"] = lnImporte2;
5741 
5742  if (_llDivisa)
5743  {
5744  decimal _nImporteTotalVentasDiv = _nImporteTotalVentas;
5745  decimal lnDifDiv = Math.Abs(_nImporteTotalVentasDiv - lnTotalDiv);
5746 
5747  if (_nImporteTotalVentasDiv < lnTotalDiv)
5748  lnDifDiv = lnDifDiv * -1;
5749 
5750  decimal lnImporteDivisaDif = Convert.ToDecimal(_dtDesg_Familias.Rows[_dtDesg_Familias.Rows.Count - 1]["importediv"]) + lnDifDiv;
5751  }
5752  else
5753  _dtDesg_Familias.Rows[_dtDesg_Familias.Rows.Count - 1]["importediv"] = lnImporte2;
5754 
5755  lnTotal = lnTotal + lnDif;
5756  }
5757 
5758  return lnTotal;
5759  }
5760 
5761 
5769  private bool _Importe_Documento(DataTable ldt_Cursor, string tcCampoImporteDiv, string tcCampoImporte = "")
5770  {
5771  string lcEmpresa = "", lcNumero = "", lcLetra = "";
5772  bool llRetorno = true;
5773  ewDocIva docIva;
5774 
5775  foreach (DataRow r in ldt_Cursor.Rows)
5776  {
5777  lcEmpresa = Convert.ToString(r["empresa"]);
5778  lcNumero = Convert.ToString(r["numero"]);
5779  lcLetra = Convert.ToString(r["letra"]);
5780 
5781  if (Convert.ToDecimal(r["pronto"]) > 0.0M || !Convert.ToBoolean(r["iva_inc"]) || Convert.ToBoolean(r["recargo"]) || lcNumero.Substring(lcNumero.Length - 1, 1).ToUpper() != "T")
5782  {
5783 
5784  docIva = this.getDocIva(lcEmpresa, lcNumero, lcLetra);
5785  r[tcCampoImporteDiv] = docIva.lnTotalConIva;
5786 
5787  if (!string.IsNullOrWhiteSpace(tcCampoImporte))
5788  r[tcCampoImporte] = Divisa._DivExacto(Convert.ToDecimal(r["cambio"]), docIva.lnTotalConIva, Convert.ToString(r["divisa"]));
5789 
5790  if (this._llDivisa && !string.IsNullOrWhiteSpace(tcCampoImporte) && tcCampoImporte.ToLower().Trim() == "importediv" && Convert.ToString(r["divisa"]) != this._lcMoneda_Empresa)
5791  {
5792  docIva.lnImporteDiv = Convert.ToDecimal(r[tcCampoImporteDiv]);
5793  r[tcCampoImporte] = docIva.lnTotalConIva;
5794  r[tcCampoImporteDiv] = docIva.lnImporteDiv;
5795  }
5796 
5797  }
5798  }
5799 
5800  return llRetorno;
5801  }
5802 
5803 
5808  private int _Numero_Tiquets_Aparcados()
5809  {
5810  int lnNumTic = 0;
5811 
5812  //DateTime ldFechaActual = System.DateTime.Today;
5813  lnNumTic = this._Numero_Tiquets_Aparcados(this._Fecha); // 90570
5814 
5815  return lnNumTic;
5816  }
5817 
5818 
5823  private int _Numero_Tiquets_Aparcados(DateTime tdFechaFin)
5824  {
5825  int lnNumTic = 0;
5826  DataTable ldt_Cursor = new DataTable();
5827  bool llConsulta_Ok = false;
5828 
5829  String lcSql = "select count(a.numero) as total from " + DB.SQLDatabase("tpv", "c_albven") + " a inner join " + DB.SQLDatabase("gestion", "c_albven") + " b " +
5830  "on a.empresa=b.empresa and a.numero=b.numero and a.letra=b.letra and a.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
5831  "where a.ejercicio=" + DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + " " +
5832  "and a.empresa=" + DB.SQLString(this._lcEmpresaActiva) + " " +
5833  "and a.caja=" + DB.SQLString(this._lcCajaActiva) + " " +
5834  "and b.fecha<=" + DB.SQLString(tdFechaFin) + " " +
5835  "and a.aparcado=1";
5836 
5837  llConsulta_Ok = DB.SQLExec(lcSql, ref ldt_Cursor);
5838  if (llConsulta_Ok == true)
5839  lnNumTic = ldt_Cursor.Rows.Count > 0 ? Convert.ToInt32(ldt_Cursor.Rows[0]["total"]) : 0;
5840 
5841  return lnNumTic;
5842  }
5843 
5844 
5851  private bool _Guardar_Arqueo(DataTable dtVentas, String tcTipo)
5852  {
5853  bool llRetorno = true;
5854  tcTipo = tcTipo.PadLeft(3);
5855 
5856  // Registros de ventas de tiquets en las diferentes monedas detectadas ...
5857  foreach (DataRow r in dtVentas.Rows)
5858  {
5859  llRetorno = DB.SQLExec("insert into " + DB.SQLDatabase("tpv", "d_arqueo") + " " +
5860  "(usuario,arqueo,ejercicio,empresa,importe,importediv,moneda,tipo) values (" +
5861  DB.SQLString(this._lcUsuarioTablas) + ", " +
5862  DB.SQLString(this._nNumero) + ", " +
5863  DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + ", " +
5864  DB.SQLString(this._lcEmpresaActiva) + ", " +
5865  DB.SQLString(Convert.ToDecimal(r["importe"])) + ", " +
5866  DB.SQLString(Convert.ToDecimal(r["importediv"])) + ", " +
5867  DB.SQLString(Convert.ToString(r["moneda"])) + ", "+
5868  DB.SQLString(tcTipo)+")");
5869  if (!llRetorno)
5870  return false;
5871  }
5872  return llRetorno;
5873  }
5874 
5875 
5880  private bool _Guardar_Formas_Cobro()
5881  {
5882  bool llRetorno = true;
5883 
5884  foreach (DataRow r in this._dtArqueo_Caja.Rows)
5885  {
5886  llRetorno = DB.SQLExec("insert into " + DB.SQLDatabase("tpv", "d_arqueo") + " " +
5887  "(usuario,arqueo,ejercicio,empresa,importe,importediv,moneda,tipo) values (" +
5888  DB.SQLString(this._lcUsuarioTablas) + ", " +
5889  DB.SQLString(this._nNumero) + ", " +
5890  DB.SQLString(this._lcEjercicioActivo.PadRight(15)) + ", " +
5891  DB.SQLString(this._lcEmpresaActiva) + ", " +
5892  DB.SQLString(Convert.ToDecimal(r["importe"])) + ", " +
5893  DB.SQLString(Convert.ToDecimal(r["importediv"])) + ", " +
5894  DB.SQLString(Convert.ToString(r["moneda"])) + " , " +
5895  DB.SQLString("O" + Convert.ToString(r["fcobro"])) + ")");
5896  if (!llRetorno)
5897  return false;
5898  }
5899  return llRetorno;
5900  }
5901 
5902 
5907  private int _Seleccionar_Dispositivo(string lcMsg, string lcCaption)
5908  {
5909  //PE-90152 Seleccionar impresora
5910  int lnDispositivo = 0;
5911  frmSeleccionarImpresora lofrmSeleccionarImpresora = new frmSeleccionarImpresora();
5912 
5913  lofrmSeleccionarImpresora._Label = lcMsg;
5914  lofrmSeleccionarImpresora._Caption = lcCaption;
5915  lofrmSeleccionarImpresora._ShowDialog(); //Bug 114218 Cambiar .ShowDialog() por ._ShowDialog()
5916 
5917  switch (lofrmSeleccionarImpresora.DialogResult)
5918  {
5919  case DialogResult.No: // Impresora
5920  this._DialogResult = DialogResult.OK;
5921  lnDispositivo = 1;
5922  break;
5923 
5924  case DialogResult.Yes: // Ticket
5925  this._DialogResult = DialogResult.OK;
5926  lnDispositivo = 2;
5927  break;
5928 
5929  case DialogResult.Cancel: // Cancelar -> no fem res
5930  this._DialogResult = DialogResult.None;
5931  lnDispositivo = -1;
5932  break;
5933  }
5934 
5935  return lnDispositivo;
5936  }
5937 
5938 
5944  private string getSimboloMoneda(Dictionary<string, object> tdicMoneda)
5945  {
5946  string lcSimbolo = "";
5947  if (tdicMoneda.ContainsKey("simbolo"))
5948  {
5949  lcSimbolo = Convert.ToString(tdicMoneda["simbolo"]).TrimEnd();
5950  if(String.IsNullOrWhiteSpace(lcSimbolo) && tdicMoneda.ContainsKey("abrev"))
5951  lcSimbolo = Convert.ToString(tdicMoneda["abrev"]).TrimEnd();
5952  }
5953  return lcSimbolo;
5954  }
5955 
5956 
5957  #endregion METODOS PRIVADOS
5958 
5959 
5963  public class ewDocIva
5964  {
5968  public decimal lnTotalSinIva = 0;
5969 
5970 
5974  public decimal lnTotalConIva = 0;
5975 
5976 
5980  public decimal lnTotalPronto = 0;
5981 
5982 
5986  public decimal lnImporteDiv = 0;
5987 
5988 
5992  public decimal lnTotalRecFinan = 0;
5993 
5994 
5995 
5999  public TipoRetencionVentas leTipoRetFiscNoFisc = TipoRetencionVentas.Fiscal;
6000 
6001 
6005  public decimal lnRetencionDocPorcen = 0;
6006 
6007 
6011  public decimal lnRetencionDoc = 0;
6012 
6013 
6017  public DataTable ldt_TablaIva = new DataTable();
6018 
6019 
6023  public decimal lnTotalPuntoVerde = 0;
6024  }
6025  }
6026 
6030  public enum TiposDeArqueos
6031  {
6035  Consulta = 1,
6039  Definitivo = 2
6040  }
6041 
6042 
6046  public enum Navegacion
6047  {
6051  No = 0,
6055  VentasTickets = 1,
6059  VentasAlbaranes = 2,
6063  VentasFacturas = 3,
6091  OperCajaPagosVarios = 10,
6095  OperCajaPagosFacturas = 11,
6099  OperCajaRetiradas = 12,
6103  Caja = 13,
6107  Familias = 14,
6120  }
6121 }
Interficie para los controles tipo filtro
Definition: IEwFiltro.cs:13
virtual void _Navegar_Albaranes(String tcDivisa="")
PE-77621
Definition: ArqueoTpv.cs:2908
sage.ew.listados.Clases.IListados _Listado
Contendra el objeto del listado invocado (se carga en el metodo _Valid)
Definition: FormFiltro.cs:138
void _Addons_Messagebox(string tcAddon, string tcMetodo, string tcMessage)
Método para mostrar mensajes en la ejecución de addons (PE-97109)
Definition: ArqueoTpv.cs:4829
void _Load_Observaciones()
PE-89588 - Método para cargar las observaciones de un arqueo
Definition: ArqueoTpv.cs:1350
ArqueoTpv()
Constructor
Definition: ArqueoTpv.cs:983
DataTable _dtOperCaja_Entregas_Cuenta_Pedidos
Datatable Entregas a cuenta pedidos
Definition: ArqueoTpv.cs:703
DataTable _dtOperCaja_Retiradas
Datatable Retiros
Definition: ArqueoTpv.cs:679
virtual void _Show()
Método Show
Definition: ArqueoTpv.cs:2880
TipoImpresion
enum para los tipos de impresión
Definition: DocPrintTPV.cs:36
Dictionary< string, object > _nArqueos
PE-91609
static AddonsController Instance
Instancia al objeto singleton Addons
bool _Addons_DescargarDatos(TipoExecute teBeforeAfter)
Ejecutar la extensión de los addons para el _DescargarDatos().
Definition: ArqueoTpv.cs:4982
override bool _Load(string tcEmpresa, string tcNumero, string tcLetra="", string tcEjercicio="GESTION")
Carga un documento existente
Dictionary< string, object > _Opciones
Referencia pública a las opciones del listado
Definition: FormFiltro.cs:99
bool _Load()
Carga los datos de un arqueo: 1) Si la propiedad _nNumero está a 0, se calcula un arqueo nuevo con to...
Definition: ArqueoTpv.cs:1159
virtual DataTable _Obtener_DataTable_OperCaja_Vales_Efectuados(ref decimal tnTotalVales, ref string tcMsgError)
Obtener DataTable del apartado de Operaciones de Caja - Subapartado vales efectuados ...
Definition: ArqueoTpv.cs:3492
decimal lnRetencionDocPorcen
% Retencion
Definition: ArqueoTpv.cs:6005
Clase sage.ew.objetos.ewcombobox
Clase para listado de ventas por cliente/artículo (ven_ca.scx de FOX)
Argumentos para los eventos lanzados por el addons en caso de error
Interfaz para la clase de arqueo de caja TPV
Definition: IArqueoTpv.cs:13
DataTable _dtVentas_Albaranes
Datatable Albaranes
Definition: ArqueoTpv.cs:659
bool _Addons_Load(TipoExecute teBeforeAfter)
Ejecutar la extensión de los addons para el _Load().
Definition: ArqueoTpv.cs:4906
void _MessageBox(string tcMensaje, string tcTitulo="", MessageBoxButtons toButtons=MessageBoxButtons.OK, MessageBoxIcon toIcon=MessageBoxIcon.Error, MessageBoxDefaultButton toDefaultButton=MessageBoxDefaultButton.Button1)
PE-87745 - Centralizar mensajes de aviso.
Definition: ArqueoTpv.cs:2788
virtual void _ShowDialog()
PE92638 Fa el ShowDialog però abans comprova l&#39;accès al formulari
Definition: clsFormul.cs:4664
decimal lnTotalPuntoVerde
Total de punto verde
Definition: ArqueoTpv.cs:6023
void _Print_Consolida(string tcFileXMLDatos, string tcCaption, string tcCajaIni, string tcCajaFin, DateTime dFechaIni, DateTime dFechaFin, Boolean tlTodasCajas=false)
PE-90528 Imprimir consolidación del arqueo
Definition: ArqueoTpv.cs:2746
bool _Show_Print(int tnAbrirEn=1)
_Show_Print
Definition: ArqueoTpv.cs:876
void _Addons_DesArquear(TipoExecute teBeforeAfter)
Ejecutar la extensión de los addons para desarquear.
Definition: ArqueoTpv.cs:4873
Extensión de listados para consultar líneas de abonos (PE-81807) (PE-83188)
Definition: LineasAbonos.cs:19
OperCajaEntregasCuentaAlbaranes = 7
Clase documento de venta TPV
Definition: DocVentaTpv.cs:47
void _Addons_Print(TipoExecute teBeforeAfter, TiposDeArqueos teTipoDeArqueo, string tcFileXMLDatos, string tcCaption)
Ejecutar la extensión de los addons para el _Print().
Definition: ArqueoTpv.cs:5085
virtual void _Navegar_Entregas_Cuenta_Pedidos(String tcDivisa="")
PE-77621
Definition: ArqueoTpv.cs:2968
virtual void _Navegar_Pagos_Facturas(String tcDivisa="")
PE-77621
Definition: ArqueoTpv.cs:2998
bool _Listados
PE-77469 Variable que no estable la opción de listado para ocultar o mostrar botones ...
Definition: frmArqueo.cs:103
PE-82361 Formulario responsable de la carga y visualización de los listados (filtros y resultados) ...
Definition: FormListado.cs:45
String _Label
Indiquem la pregunta del formulari
ewMascara()
Crea una nueva instancia de la classe ewMascara.
Definition: clsEwBase.cs:6261
virtual void _Obtener_DataTables_Importe_Tiquets_Albaranes_Facturas(ref DateTime tdFechaIni, ref DateTime tdFechaFin, ref string tcMsgError)
Obtener DataTable del apartado de Ventas ...
Definition: ArqueoTpv.cs:3171
virtual void _Navegar_Creditos()
PE-88164
Definition: ArqueoTpv.cs:3047
Clase auxiliar para la reconversión de filtros de negocio en objetos visuales
DataTable ldt_TablaIva
Datatable IVA
Definition: ArqueoTpv.cs:6017
DataTable _dtOperCaja_Pagos_Varios
Datatable Pagos Varios
Definition: ArqueoTpv.cs:721
Formulario de arqueo de caja
Definition: frmArqueo.cs:26
virtual void _Navegar_Abonos()
PE-88164
Definition: ArqueoTpv.cs:3056
bool _ShowResult(string tlOpcion="")
Metodo para ademas de abrir los resultados, propagar acciones adicionales al propio formulario de res...
KeyDiccionarioMascara
Clave para diccionario de máscaras
String _Caption
Indiquem el titol del formulari
Navegacion
Enumerados para los diferentes tipos de navegación desde el grid
Definition: ArqueoTpv.cs:6046
Clase sage.ew.objetos.ewcheckbox
DataTable _dtVentas_Tiquets
I. VENTAS.
Definition: ArqueoTpv.cs:653
DataTable _dtDesg_Familias
IV. DESGLOSE DE VENTAS POR FAMILIA.
Definition: ArqueoTpv.cs:743
virtual bool _Save()
Cierra un arqueo cargado previamente en pantalla. Es necesario que hay un arqueo cargado en el objeto...
Definition: ArqueoTpv.cs:1380
virtual void _Navegar_Vales_Efectuados()
PE-77621
Definition: ArqueoTpv.cs:2948
KeyDiccionarioLenCampos
Clave del diccionario LenCampos
Definition: Diccionarios.cs:11
void _Arquear()
Arquear la caja
Definition: ArqueoTpv.cs:1728
decimal lnRetencionDoc
Importe de Retencion
Definition: ArqueoTpv.cs:6011
virtual void _Navegar_Tickets(String tcDivisa="")
PE-77621
Definition: ArqueoTpv.cs:2898
virtual bool _DesArquear()
Desarquea un arqueo ya cerrado y descarga el objeto dejando vacio para ser cargado posteriormente con...
Definition: ArqueoTpv.cs:2120
DataTable _dtOperCaja_Reposiciones
II. OPERACIONES DE CAJA.
Definition: ArqueoTpv.cs:673
DataTable _dtOperCaja_Entregas_Cuenta_Albaranes
Datatable Entregas a cuenta albaranes
Definition: ArqueoTpv.cs:697
DataTable _dtArqueo_Caja
III. ARQUEO DE CAJA.
Definition: ArqueoTpv.cs:735
void _DescargarDatos()
Vacía las propiedades de la clase y deja el objeto preparado para ser cargado de nuevo.
Definition: ArqueoTpv.cs:1078
OperCajaEntregasCuentaPedidos = 15
decimal _Cotizacion(String lcMoneda)
Definition: ArqueoTpv.cs:351
virtual DataTable _Obtener_DataTable_OperCaja_Reposiciones(ref decimal lnTotalRepo, ref string tcMsgError)
Obtener DataTable del apartado de Operaciones de Caja - Subapartado reposiciones ...
Definition: ArqueoTpv.cs:3389
decimal lnTotalRecFinan
Recargo financiero
Definition: ArqueoTpv.cs:5992
decimal lnTotalConIva
Con IVA
Definition: ArqueoTpv.cs:5974
virtual void _Navegar_Cobros_Facturas(String tcDivisa="")
PE-77621
Definition: ArqueoTpv.cs:2978
Clase para consultar las reposiciones (transformada en PE-83189)
Definition: Reposiciones.cs:17
DataTable _dtOperCaja_Cobros_Varios
Datatable Cobros Varios
Definition: ArqueoTpv.cs:709
virtual void _Navegar_Ventas_Familias(string tcDescripcion, String tcDivisa="")
PE-77621
Definition: ArqueoTpv.cs:3028
string _CreateFileTemporalXML(string tcFileName, DataTable ldTable)
PE-94078 Método para crear un fichero XML en &#39;euroterm\temp&#39;
Definition: ArqueoTpv.cs:2813
virtual decimal _Obtener_DataTable_Desg_Familias()
Rellena la propiedad del objeto DataTable _dtDesg_Familias que contiene el desglose de ventas por fam...
Definition: ArqueoTpv.cs:4435
virtual void _Navegar_Reposiciones(String tcDivisa="")
PE-77621
Definition: ArqueoTpv.cs:2928
virtual DataTable _Obtener_DataTable_OperCaja_Pagos_Facturas(ref decimal tnTotalPagosFacturas, ref string tcMsgError)
Obtener DataTable del apartado de Operaciones de Caja - Subapartado pagos facturas ...
Definition: ArqueoTpv.cs:3909
TipoRetencionVentas
Enumeración para identificar los tipos de retención en ventas
Definition: clsRetencion.cs:23
static decimal _Ultima_Cotizacion(string tcMoneda)
Ens retorna la cotització d&#39;una moneda respecte a la moneda de la empresa a la data actual...
Definition: Divisa.cs:1095
virtual void _Navegar_Retiros(String tcDivisa="")
PE-77621
Definition: ArqueoTpv.cs:3018
bool _Addons_Save(TipoExecute teBeforeAfter)
Ejecutar la extensión de los addons para el _Save().
Definition: ArqueoTpv.cs:4944
virtual DataTable _Obtener_DataTable_OperCaja_Pagos_Varios(ref decimal tnTotalPagosVarios, ref string tcMsgError)
Obtener DataTable del apartado de Operaciones de Caja - Subapartado pagos varios ...
Definition: ArqueoTpv.cs:4224
Clase derivada de DocPrint para la impresión de TPV
Definition: DocPrintTPV.cs:26
void _Addons_Print_Consolida(TipoExecute teBeforeAfter, string tcFileXMLDatos, string tcCaption, string tcCajaIni, string tcCajaFin, DateTime dFechaIni, DateTime dFechaFin, Boolean tlTodasCajas)
Ejecutar la extensión de los addons para el _Print_Consolida().
Definition: ArqueoTpv.cs:5125
virtual void _Navegar_Cobros_Varios()
PE-77621
Definition: ArqueoTpv.cs:2988
DataTable _dtVentas_Facturas
Datatable Facturas
Definition: ArqueoTpv.cs:665
ArqueoTpv(int tnNumero)
Constructor
Definition: ArqueoTpv.cs:1006
bool HasAddonsLoaded()
Indica si tiene addons cargados
_TipoDocCab _Cabecera
Cabecera
Definition: DocsVen.cs:2626
object [] _addRow(object[] row)
Construeix un nou objecte fila
Definition: ArqueoTpv.cs:4689
DataTable _Obtener_Datos_SageReports(Dictionary< string, object > tdicParametros=null)
Obtener los datos de los arqueos
Definition: ArqueoTpv.cs:947
DataTable _Addons_MontaArqueo(TipoExecute teBeforeAfter)
Ejecutar la extensión de los addons para el _MontarArqueo().
Definition: ArqueoTpv.cs:5015
TipoExecute _eBeforeAfter
Nos determina en que momento se ejecuta el método. El método se puede ejecutar antes del código de la...
Clase para el listado de Operaciones por Caja
virtual DataTable _Obtener_DataTable_OperCaja_Cobros_Varios(ref decimal tnTotalCobrosVarios, ref string tcMsgError)
Obtener DataTable del apartado de Operaciones de Caja - Subapartado cobros varios ...
Definition: ArqueoTpv.cs:4119
DataTable _dtOperCaja_Cobros_Tiquets
Datatable Cobros Tiquets
Definition: ArqueoTpv.cs:685
virtual string _Obtener_XML_desglose_iva()
//PE-91451 Generamos un fichero XML con los datos de resumen de iva
Definition: ArqueoTpv.cs:4651
virtual void _Navegar_Cobros_Tickets(String tcDivisa="")
_Navegar_Cobros_Tickets PE-77621
Definition: ArqueoTpv.cs:2938
virtual decimal _Afegir_Total_Tecleado_Diferencia(ref DataTable tdtTable, string tcCadenaFormat)
Metode virtual per a afegir el tecleado i la diferencia al arqueig
Definition: ArqueoTpv.cs:2107
virtual void _Obtener_DataTable_Arqueo_Caja()
Rellena la propiedad del objeto DatTable _dtArqueo_Caja que contiene el cuadre de caja...
Definition: ArqueoTpv.cs:2325
TipoRetencionVentas leTipoRetFiscNoFisc
Tipo de retención (fiscal, no fiscal)
Definition: ArqueoTpv.cs:5999
bool _DescuentoProntoPago
Tener en cuenta el descuento de pronto pago en el cálculo del importe de líneas de las ventas Utiliza...
Clase que permite extender la funcionalidad de la clase ArqueoTpv
Dictionary< string, object > _Filtros
Referencia pública a los filtros del listado
Definition: FormFiltro.cs:116
decimal lnTotalSinIva
Sin IVA
Definition: ArqueoTpv.cs:5968
dynamic _Arqueo
Devuelve la clase ArqueTPV
Definition: frmArqueo.cs:175
DataTable _dtOperCaja_Pagos_Facturas
Datatable Pagos Facturas
Definition: ArqueoTpv.cs:727
Clase base de los controles de divida
Clase para el listado de Retiros
Definition: Retiros.cs:17
virtual void _Navegar_Entregas_Cuenta_Albaranes(String tcDivisa="")
PE-77621
Definition: ArqueoTpv.cs:2958
TipoExecute
Tipos de ejecución de los métodos
Definition: IDocModulos.cs:16
TiposDeArqueos
Tipos de arqueo
Definition: ArqueoTpv.cs:6030
Proporciona características adicionales de las máscaras de Eurowin
Definition: clsEwBase.cs:6212
IAddonsManager AddonsManager
Gestor de Addons
virtual bool _Save_Observaciones()
PE-89588 - Método para guardar las observaciones
Definition: ArqueoTpv.cs:1693
DataTable _MontaArqueo()
Metodo que monta un DataTable con los datos del Arqueo para mostrarlos en el Datagrid ...
Definition: ArqueoTpv.cs:1791
void _Addons_Cargar()
Método para cargar en el diccionario _Addons todas las extensiones de arqueo tpv que tengan los Addon...
Definition: ArqueoTpv.cs:4804
Definición de la interfície necesaria para las páginas(tabPage) a utilizar en formularios de tipo For...
Definition: IDocPrint.cs:16
DataTable _Calcular_Iva(ref decimal tnTotalSinIva, ref decimal tnTotalConIva, ref decimal tnTotalPronto, ref decimal tnTotalRecFinan, ref decimal tnRetencionDoc, ref decimal tnTotalPuntoVerde, ref TipoRetencionVentas teTipoRetFiscNoFisc, ref decimal tnRetencionDocPorcen)
Ens retorna un datatable amb els diferents imports de l&#39;iva
Definition: DocsVen.cs:5891
CommandManager Commands
Comandos de addons
static decimal _DivExacto(decimal tnCambio, decimal tnImporte=0, string tcToMoneda="", bool tlCalcDivisa=false, string tcMascaraResultado="")
Función para convertir un importe expresado en moneda diferente a la moneda de la empresa a la moneda...
Definition: Divisa.cs:999
virtual DataTable _Obtener_DataTable_OperCaja_Entregas_Cuenta_Albaranes(ref decimal tnTotalEntAlbaran, ref string tcMsgError)
Obtener DataTable del apartado de Operaciones de Caja - Subapartado entregas a cuenta albaranes ...
Definition: ArqueoTpv.cs:3696
DataTable _DataTableCierreCaja(Dictionary< string, string > monedas=null)
Establece el tipo definitivo
Definition: ArqueoTpv.cs:1744
object [] _addRow(DataRow toRow, Navegacion toNav)
Construeix un nou objecte fila amb navegació
Definition: ArqueoTpv.cs:4735
Interfaz Addons
Definition: IAddons.cs:11
void _Print(TiposDeArqueos teTipoDeArqueo, string tcFileXMLDatos, string tcCaption="")
Imprimir el arqueo
Definition: ArqueoTpv.cs:2671
virtual void _Navegar_Pagos_Varios()
PE-77621
Definition: ArqueoTpv.cs:3008
string _Mascara_Net
Máscara convertida en formato .Net
Definition: clsEwBase.cs:6235
virtual DataTable _Obtener_DataTable_OperCaja_Entregas_Cuenta_Pedidos(ref decimal tnTotalEntPedidos, ref string tcMsgError)
Obtener DataTable del apartado de Operaciones de Caja - Subapartado entregas a cuenta pedidos ...
Definition: ArqueoTpv.cs:3804
Clase de negocio para la DIVISA (Moneda)
Definition: Divisa.cs:76
virtual void _Navegar_Operaciones_Caja(string tcDescripcion, String tcDivisa="")
88164
Definition: ArqueoTpv.cs:3038
Dictionary< string, object > _Obtener_DatosGen_Arqueo_Cerrado(string tcEjercicio, string tcEmpresa, int tnNumero)
Obtiene datos generales de un arqueo extrayendolos directamente de la bd en el registro de la tabla T...
Definition: ArqueoTpv.cs:1065
Definición de la interficie que deben cumplir los documentos de cualquier tipo para poder interactuar...
Definition: IDocPrint.cs:376
ArqueoTpv(dynamic toForm)
PE-87745 - Constructor passant per parametre el formulari
Definition: ArqueoTpv.cs:1036
Clase Arqueo TPV: Para crear un arqueo nuevo para consultar lo pendiente de arquear: ...
Definition: ArqueoTpv.cs:45
bool _lMostrarSoloArtSinCodif
Mostrar sólo conceptos varios
ewDocIva getDocIva(String lcEmpresa, String lcNumero, String lcLetra)
Metodo que calcula el IVA del documento y lo guarda en memoria
Definition: ArqueoTpv.cs:2841
virtual DataTable _Obtener_DataTable_OperCaja_Retiros(ref decimal tnTotalRetiros, ref string tcMsgError)
Obtener DataTable del apartado de Operaciones de Caja - Subapartado retiros ...
Definition: ArqueoTpv.cs:4329
virtual DataTable _Obtener_DataTable_OperCaja_Cobros_Tiquets(ref decimal tnTotalCobros, ref string tcMsgError)
Obtener DataTable del apartado de Operaciones de Caja - Cobros de tiquets ...
Definition: ArqueoTpv.cs:3593
virtual int _Obtener_Numero_Tiquets(ref string tnNumTicIni, ref string tnNumTicFin, ref string tcMsgError, ref string tnLetraTicIni, ref string tnLetraTicFin)
Retorna el nº de tiquets, nº tiquet inicial i nº tiquet final ...
Definition: ArqueoTpv.cs:3091
Calcula y guarda el arqueo
Clase utilizada para guardar los valores del iva de cada documento
Definition: ArqueoTpv.cs:5963
virtual void _Obtener_DataTable_Desg_Iva_Tiquets()
Rellena la propiedad del objeto DataTable _dtDesg_Iva que contiene el desglose de IVA de los tiquets ...
Definition: ArqueoTpv.cs:4518
void _Addons_Arquear(TipoExecute teBeforeAfter)
Ejecutar la extensión de los addons para arquear.
Definition: ArqueoTpv.cs:4840
Boolean _LoadArqueoOnLoad
_LoadArqueoOnLoad
Definition: frmArqueo.cs:108
Dictionary< string, object > _Obtener_Filtros_SageReports(Dictionary< string, object > tdicParametros=null)
Obtener los filtros de los arqueos
Definition: ArqueoTpv.cs:886
string _ObtenerCaja(String tcCampo="", String tcEmpresa="")
PE-90528 - Método para consulta las cajas de una empresa
Definition: ArqueoTpv.cs:3065
Clase para la impresión de arqueo
Definition: DocPrintTPV.cs:332
void CargarExtensionesArqueoTpv(IAddons oArqueoTpv, string tipoArqueoTpv)
Carga las extensiones de arqueo TPV
decimal lnTotalPronto
Protopago
Definition: ArqueoTpv.cs:5980
Dictionary< string, object > _Moneda(String lcMoneda)
Definition: ArqueoTpv.cs:377
PE-94454 Definición del combo para seleccionar IVA incluido o no
Definition: txtSelIva.cs:18
virtual DataTable _Obtener_DataTable_OperCaja_Cobros_Facturas(ref decimal tnTotalCobrosFacturas, ref string tcMsgError)
Obtener DataTable del apartado de Operaciones de Caja - Subapartado cobros de facturas ...
Definition: ArqueoTpv.cs:4014
DataTable _dtDesg_Iva
V. DESGLOSE DE IVA DE LAS VENTAS DE TIQUETS.
Definition: ArqueoTpv.cs:751
DataTable _dtOperCaja_Cobros_Facturas
Datatable Cobros Facturas
Definition: ArqueoTpv.cs:715
void _Addons_Obtener_DataTable_Arqueo_Caja(TipoExecute teBeforeAfter)
Ejecutar la extensión de los addons para el _Obtener_DataTable_Arqueo_Caja().
Definition: ArqueoTpv.cs:5049
DataTable _dtOperCaja_Vales_Efectuados
Datatable Vales Efectuados
Definition: ArqueoTpv.cs:691
virtual void _Navegar_Facturas(String tcDivisa="")
PE-77621
Definition: ArqueoTpv.cs:2918
static int _Decimals_Mascara(string tcMascara)
Busca el numero de decimals de la máscara
Definition: Divisa.cs:1347