unit uViewFacturasCliente; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uViewGrid, uViewPreview, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, dxPSGlbl, dxPSUtl, dxPSEngn, dxPrnPg, dxBkgnd, dxWrap, dxPrnDev, dxPSCompsProvider, dxPSFillPatterns, dxPSEdgePatterns, cxImageComboBox, cxTextEdit, ImgList, PngImageList, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, dxPSCore, dxPScxCommon, dxPScxGrid6Lnk, ActnList, uDADataTable, cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGrid, cxImage, Grids, DBGrids, uBizFacturasCliente, cxGridCustomPopupMenu, cxGridPopupMenu, cxCalendar, cxCurrencyEdit, uViewFiltroBase, TB2Item, TBX, TB2Toolbar, TBXDkPanels, TB2Dock, dxPgsDlg, uDAInterfaces, uCustomView, uViewBase; type IViewFacturasCliente = interface(IViewGrid) ['{927A005F-5D71-4C37-B9E7-10292F9D467C}'] function GetFacturas: IBizFacturaCliente; procedure SetFacturas(const Value: IBizFacturaCliente); property Facturas: IBizFacturaCliente read GetFacturas write SetFacturas; end; TfrViewFacturasCliente = class(TfrViewGrid, IViewFacturasCliente) PngImageList: TPngImageList; cxGridViewNOMBRE: TcxGridDBColumn; cxGridViewREFERENCIA: TcxGridDBColumn; cxGridViewFECHA_FACTURA: TcxGridDBColumn; cxGridViewSITUACION: TcxGridDBColumn; cxGridViewBASE_IMPONIBLE: TcxGridDBColumn; cxGridViewIMPORTE_DESCUENTO: TcxGridDBColumn; cxGridViewDESCUENTO: TcxGridDBColumn; cxGridViewIMPORTE_IVA: TcxGridDBColumn; cxGridViewIMPORTE_TOTAL: TcxGridDBColumn; cxGridViewIVA: TcxGridDBColumn; cxGridViewNIF_CIF: TcxGridDBColumn; cxGridViewCALLE: TcxGridDBColumn; cxGridViewPROVINCIA: TcxGridDBColumn; cxGridViewCODIGO_POSTAL: TcxGridDBColumn; cxGridViewPOBLACION: TcxGridDBColumn; cxStylePagada: TcxStyle; cxGridPendientes: TcxGridLevel; cxStyleAbono: TcxStyle; cxGridParcialmentePagadas: TcxGridLevel; cxGridViewREFERENCIA_COMISION: TcxGridDBColumn; cxStylePendientes: TcxStyle; cxStyleParciales: TcxStyle; actCliente: TAction; actProvincia: TAction; TBXItem2: TTBXItem; TBXSeparatorItem1: TTBXSeparatorItem; TBXItem3: TTBXItem; TBXSeparatorItem2: TTBXSeparatorItem; cxGridViewTIPO: TcxGridDBColumn; cxGridViewTIENDA: TcxGridDBColumn; cxGridViewNOMBRE_COMERCIAL: TcxGridDBColumn; cxGridViewNOMBRE_CLIENTE: TcxGridDBColumn; cxGridViewIMPORTE_RE: TcxGridDBColumn; cxGridViewRE: TcxGridDBColumn; cxGridViewREF_CONTRATO: TcxGridDBColumn; cxGridViewFECHA_VENCIMIENTO: TcxGridDBColumn; cxGridViewREF_CLI_CONTRATO: TcxGridDBColumn; cxGridViewIMPORTE_RETENIDO: TcxGridDBColumn; cxGridViewPROCEDENCIA_CLIENTE: TcxGridDBColumn; actProcedencia: TAction; TBXSeparatorItem3: TTBXSeparatorItem; TBXItem4: TTBXItem; cxGridViewTIPO_OPERACION: TcxGridDBColumn; cxGridPagadas: TcxGridLevel; cxGridViewAGENTE: TcxGridDBColumn; cxGridViewDELEGACION: TcxGridDBColumn; actComercial: TAction; actDelegacion: TAction; TBXSeparatorItem4: TTBXSeparatorItem; TBXItem5: TTBXItem; TBXSeparatorItem5: TTBXSeparatorItem; TBXItem6: TTBXItem; cxGridViewFAC_PRO_GRADEN: TcxGridDBColumn; actTienda: TAction; TBXSeparatorItem6: TTBXSeparatorItem; TBXItem7: TTBXItem; cxGridViewREFERENCIA_CLIENTE: TcxGridDBColumn; cxStyleProforma: TcxStyle; cxGridProformas: TcxGridLevel; cxGridViewPAIS: TcxGridDBColumn; cxGridViewIDIOMA: TcxGridDBColumn; actPais: TAction; TBXSeparatorItem7: TTBXSeparatorItem; TBXItem8: TTBXItem; procedure cxGridViewStylesGetContentStyle(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle); procedure cxGridActiveTabChanged(Sender: TcxCustomGrid; ALevel: TcxGridLevel); procedure actClienteExecute(Sender: TObject); procedure actProvinciaExecute(Sender: TObject); procedure actProvinciaUpdate(Sender: TObject); procedure actClienteUpdate(Sender: TObject); procedure actProcedenciaExecute(Sender: TObject); procedure actProcedenciaUpdate(Sender: TObject); procedure actComercialExecute(Sender: TObject); procedure actComercialUpdate(Sender: TObject); procedure actDelegacionExecute(Sender: TObject); procedure actDelegacionUpdate(Sender: TObject); procedure actTiendaExecute(Sender: TObject); procedure actTiendaUpdate(Sender: TObject); procedure actPaisExecute(Sender: TObject); procedure actPaisUpdate(Sender: TObject); private //Filtros relativos a la vista procedure AnadirFiltroSituaciones; procedure AnadirFiltroFechas; protected FFacturas: IBizFacturaCliente; function GetFacturas: IBizFacturaCliente; procedure SetFacturas(const Value: IBizFacturaCliente); public procedure AnadirOtrosFiltros; override; procedure ConfigView; override; property Facturas: IBizFacturaCliente read GetFacturas write SetFacturas; end; implementation uses uDataModuleFacturasCliente, schFacturasClienteClient_Intf, DateUtils, uViewGridBase, uFactuGES_App; {$R *.dfm} { TfrViewFacturasCliente } procedure TfrViewFacturasCliente.actClienteExecute(Sender: TObject); begin if (cxGridViewNOMBRE.GroupIndex < 0) then begin cxGridViewNOMBRE.GroupIndex := cxGridView.GroupedColumnCount; cxGridViewNOMBRE.Visible := False; end else begin cxGridViewNOMBRE.GroupIndex := -1; cxGridViewNOMBRE.Visible := True; end; end; procedure TfrViewFacturasCliente.actClienteUpdate(Sender: TObject); begin inherited; (Sender as TAction).Checked := not (cxGridViewNOMBRE.GroupIndex < 0); end; procedure TfrViewFacturasCliente.actComercialExecute(Sender: TObject); begin if (cxGridViewAGENTE.GroupIndex < 0) then begin cxGridViewAGENTE.GroupIndex := cxGridView.GroupedColumnCount; cxGridViewAGENTE.Visible := False; end else begin cxGridViewAGENTE.GroupIndex := -1; cxGridViewAGENTE.Visible := True; end; end; procedure TfrViewFacturasCliente.actComercialUpdate(Sender: TObject); begin inherited; (Sender as TAction).Checked := not (cxGridViewAGENTE.GroupIndex < 0); end; procedure TfrViewFacturasCliente.actDelegacionExecute(Sender: TObject); begin if (cxGridViewDELEGACION.GroupIndex < 0) then begin cxGridViewDELEGACION.GroupIndex := cxGridView.GroupedColumnCount; cxGridViewDELEGACION.Visible := False; end else begin cxGridViewDELEGACION.GroupIndex := -1; cxGridViewDELEGACION.Visible := True; end; end; procedure TfrViewFacturasCliente.actDelegacionUpdate(Sender: TObject); begin inherited; (Sender as TAction).Checked := not (cxGridViewDELEGACION.GroupIndex < 0); end; procedure TfrViewFacturasCliente.actPaisExecute(Sender: TObject); begin if (cxGridViewPAIS.GroupIndex < 0) then begin cxGridViewPAIS.GroupIndex := cxGridView.GroupedColumnCount; cxGridViewPAIS.Visible := False; end else begin cxGridViewPAIS.GroupIndex := -1; cxGridViewPAIS.Visible := True; end; end; procedure TfrViewFacturasCliente.actPaisUpdate(Sender: TObject); begin inherited; (Sender as TAction).Checked := not (cxGridViewPAIS.GroupIndex < 0); end; procedure TfrViewFacturasCliente.actProcedenciaExecute(Sender: TObject); begin if (cxGridViewPROCEDENCIA_CLIENTE.GroupIndex < 0) then begin cxGridViewPROCEDENCIA_CLIENTE.GroupIndex := cxGridView.GroupedColumnCount; cxGridViewPROCEDENCIA_CLIENTE.Visible := False; end else begin cxGridViewPROCEDENCIA_CLIENTE.GroupIndex := -1; cxGridViewPROCEDENCIA_CLIENTE.Visible := True; end; end; procedure TfrViewFacturasCliente.actProcedenciaUpdate(Sender: TObject); begin inherited; (Sender as TAction).Checked := not (cxGridViewPROCEDENCIA_CLIENTE.GroupIndex < 0); end; procedure TfrViewFacturasCliente.actProvinciaExecute(Sender: TObject); begin if (cxGridViewPROVINCIA.GroupIndex < 0) then begin cxGridViewPROVINCIA.GroupIndex := cxGridView.GroupedColumnCount; cxGridViewPROVINCIA.Visible := False; end else begin cxGridViewPROVINCIA.GroupIndex := -1; cxGridViewPROVINCIA.Visible := True; end; end; procedure TfrViewFacturasCliente.actProvinciaUpdate(Sender: TObject); begin inherited; (Sender as TAction).Checked := not (cxGridViewPROVINCIA.GroupIndex < 0); end; procedure TfrViewFacturasCliente.actTiendaExecute(Sender: TObject); begin if (cxGridViewTIENDA.GroupIndex < 0) then begin cxGridViewTIENDA.GroupIndex := cxGridView.GroupedColumnCount; cxGridViewTIENDA.Visible := False; end else begin cxGridViewTIENDA.GroupIndex := -1; cxGridViewTIENDA.Visible := True; end; end; procedure TfrViewFacturasCliente.actTiendaUpdate(Sender: TObject); begin inherited; (Sender as TAction).Checked := not (cxGridViewTIENDA.GroupIndex < 0); end; procedure TfrViewFacturasCliente.AnadirFiltroFechas; var Columna: TcxGridDBColumn; Fecha1, Fecha2: Variant; FFiltro : TcxFilterCriteriaItemList; begin Fecha1 := frViewFiltroBase1.edtFechaIniFiltro.EditValue; Fecha2 := frViewFiltroBase1.edtFechaFinFiltro.EditValue; if not VarIsNull(Fecha1) and not VarIsNull(Fecha2) then begin cxGridView.DataController.Filter.Options := [fcoCaseInsensitive, fcoSoftCompare]; FFiltro := AddFilterGrid(fboAnd); Columna := (cxGridView as TcxGridDBTableView).GetColumnByFieldName('FECHA_FACTURA'); FFiltro.AddItem(Columna, foBetween, varArrayOf([Fecha1, Fecha2]), VarToStr(Fecha1) + ' and ' + VarToStr(Fecha2)); end; end; procedure TfrViewFacturasCliente.AnadirFiltroSituaciones; var FFiltro : TcxFilterCriteriaItemList; begin FFiltro := AddFilterGrid(fboAnd); case cxGrid.ActiveLevel.Index of 0 : FFiltro.AddItem(cxGridViewTIPO, foNotEqual, CTE_TIPO_PROFORMA, CTE_TIPO_PROFORMA); 1 : Begin FFiltro.AddItem(cxGridViewSITUACION, foEqual, CTE_PENDIENTE, CTE_PENDIENTE); FFiltro.AddItem(cxGridViewTIPO, foNotEqual, CTE_TIPO_PROFORMA, CTE_TIPO_PROFORMA); End; 2 : Begin FFiltro.AddItem(cxGridViewSITUACION, foEqual, CTE_PARCIAMENTE_PAGADA, CTE_PARCIAMENTE_PAGADA); FFiltro.AddItem(cxGridViewTIPO, foNotEqual, CTE_TIPO_PROFORMA, CTE_TIPO_PROFORMA); End; 3 : Begin FFiltro.AddItem(cxGridViewSITUACION, foEqual, CTE_PAGADA, CTE_PAGADA); FFiltro.AddItem(cxGridViewTIPO, foNotEqual, CTE_TIPO_PROFORMA, CTE_TIPO_PROFORMA); End; 4 : FFiltro.AddItem(cxGridViewTIPO, foEqual, CTE_TIPO_PROFORMA, CTE_TIPO_PROFORMA); end; end; procedure TfrViewFacturasCliente.AnadirOtrosFiltros; begin inherited; AnadirFiltroSituaciones; AnadirFiltroFechas; //Finalmente activamos el filtro si tenemos algo if cxGridView.DataController.Filter.IsEmpty then cxGridView.DataController.Filter.Active := False else cxGridView.DataController.Filter.Active := True; cxGrid.ActiveLevel.GridView := cxGridView; end; procedure TfrViewFacturasCliente.ConfigView; begin inherited; //Para que nos filtre la pestaņa todas y quite las facturas proforma AnadirOtrosFiltros; cxGridViewTIENDA.Visible := True; cxGridViewTIENDA.VisibleForCustomization := True; actTienda.Visible := True; cxGridViewAGENTE.Visible := False; cxGridViewAGENTE.VisibleForCustomization := False; actComercial.Visible := False; cxGridViewDELEGACION.Visible := False; cxGridViewDELEGACION.VisibleForCustomization := False; actDelegacion.Visible := False; cxGridViewFAC_PRO_GRADEN.Visible := False; cxGridViewFAC_PRO_GRADEN.VisibleForCustomization := False; //FILTRO DE EMPRESAS TIENDA if (AppFactuGES.EmpresaActiva.ID = CTE_EMPRESA_ABETO) then begin cxGridViewTIENDA.Visible := False; cxGridViewTIENDA.VisibleForCustomization := False; actTienda.Visible := False; end; //FILTRO DE EMPRESAS COMERCIALES if ((AppFactuGES.EmpresaActiva.ID = CTE_EMPRESA_ABETO) or (AppFactuGES.EmpresaActiva.ID = CTE_EMPRESA_GRADEN)) then begin cxGridViewAGENTE.Visible := True; cxGridViewAGENTE.VisibleForCustomization := True; actComercial.Visible := True; cxGridViewDELEGACION.Visible := True; cxGridViewDELEGACION.VisibleForCustomization := True; actDelegacion.Visible := True; cxGridViewFAC_PRO_GRADEN.Visible := True; cxGridViewFAC_PRO_GRADEN.VisibleForCustomization := True; end; end; procedure TfrViewFacturasCliente.cxGridActiveTabChanged(Sender: TcxCustomGrid; ALevel: TcxGridLevel); begin inherited; RefrescarFiltro; end; procedure TfrViewFacturasCliente.cxGridViewStylesGetContentStyle( Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle); var IndiceCol: Integer; ASituacion: string; begin inherited; if Assigned(ARecord) then begin IndiceCol := cxGridViewSITUACION.Index; ASituacion := VarToStr(ARecord.DisplayTexts[IndiceCol]); if (ASituacion = CTE_PAGADA) then AStyle := cxStylePagada else if (ASituacion = CTE_PENDIENTE) then AStyle := cxStylePendientes; IndiceCol := cxGridViewIMPORTE_TOTAL.Index; if (Pos('-', ARecord.DisplayTexts[IndiceCol]) > 0) then AStyle := cxStyleAbono; IndiceCol := (Sender as TcxGridDBTableView).GetColumnByFieldName(fld_FacturasClienteTIPO).Index; if (ARecord.Values[IndiceCol] = CTE_TIPO_PROFORMA) then AStyle := cxStyleProforma; end; end; function TfrViewFacturasCliente.GetFacturas: IBizFacturaCliente; begin Result := FFacturas; end; procedure TfrViewFacturasCliente.SetFacturas(const Value: IBizFacturaCliente); begin FFacturas := Value; if Assigned(FFacturas) then dsDataSource.DataTable := FFacturas.DataTable; end; end.