AbetoDesign_FactuGES2/Source/Modulos/Facturas de cliente/Views/uViewFacturasCliente.pas

383 lines
12 KiB
ObjectPascal

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;
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);
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, 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.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
1 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, CTE_PENDIENTE, CTE_PENDIENTE);
2 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, CTE_PARCIAMENTE_PAGADA, CTE_PARCIAMENTE_PAGADA);
3 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, CTE_PAGADA, CTE_PAGADA);
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;
//FILTRO DE EMPRESAS
if (AppFactuGES.EmpresaActiva.ID = CTE_EMPRESA_ABETO) then
begin
cxGridViewFAC_PRO_GRADEN.Visible := True;
cxGridViewFAC_PRO_GRADEN.VisibleForCustomization := True;
cxGridViewTIENDA.Visible := False;
cxGridViewTIENDA.VisibleForCustomization := False;
cxGridViewAGENTE.Visible := True;
cxGridViewAGENTE.VisibleForCustomization := True;
cxGridViewDELEGACION.Visible := True;
cxGridViewDELEGACION.VisibleForCustomization := True;
actComercial.Visible := True;
actDelegacion.Visible := True;
actTienda.Visible := False;
end
else
begin
cxGridViewFAC_PRO_GRADEN.Visible := False;
cxGridViewFAC_PRO_GRADEN.VisibleForCustomization := False;
cxGridViewTIENDA.Visible := True;
cxGridViewTIENDA.VisibleForCustomization := True;
cxGridViewAGENTE.Visible := False;
cxGridViewAGENTE.VisibleForCustomization := False;
cxGridViewDELEGACION.Visible := False;
cxGridViewDELEGACION.VisibleForCustomization := False;
actComercial.Visible := False;
actDelegacion.Visible := False;
actTienda.Visible := 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;
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.