Tecsitel_FactuGES2/Source/Modulos/Recibos de cliente/Views/uViewRecibosCliente.pas

304 lines
10 KiB
ObjectPascal

unit uViewRecibosCliente;
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, uBizRecibosCliente, cxGridCustomPopupMenu,
cxGridPopupMenu, cxCalendar, cxCurrencyEdit, uViewFiltroBase, TB2Item, TBX,
TB2Toolbar, TBXDkPanels, TB2Dock, dxPgsDlg, uDAInterfaces, uCustomView,
uViewBase;
type
IViewRecibosCliente = interface(IViewGrid)
['{27D0229A-6340-4F03-B97A-7776E9166F2F}']
function GetRecibos: IBizRecibosCliente;
procedure SetRecibos(const Value: IBizRecibosCliente);
property Recibos: IBizRecibosCliente read GetRecibos write SetRecibos;
procedure FiltrarPorFechas(const Fecha1, Fecha2: Variant);
end;
TfrViewRecibosCliente = class(TfrViewGrid, IViewRecibosCliente)
cxStylePendientes: TcxStyle;
cxGridPendientes: TcxGridLevel;
cxGridPagados: TcxGridLevel;
cxStylePagados: TcxStyle;
cxGridViewREFERENCIA: TcxGridDBColumn;
cxGridViewSITUACION: TcxGridDBColumn;
cxGridViewFECHA_VENCIMIENTO: TcxGridDBColumn;
cxGridViewDESCRIPCION: TcxGridDBColumn;
cxGridViewIMPORTE: TcxGridDBColumn;
cxGridViewNOMBRE_CLIENTE: TcxGridDBColumn;
cxGridViewNIF_CIF_CLIENTE: TcxGridDBColumn;
cxGridViewREFERENCIA_REMESA: TcxGridDBColumn;
cxGridDevueltos: TcxGridLevel;
cxGridViewOTROS_GASTOS: TcxGridDBColumn;
cxGridViewIMPORTE_TOTAL: TcxGridDBColumn;
cxGridViewFECHA_EMISION: TcxGridDBColumn;
cxStyleDevueltos: TcxStyle;
actCliente: TAction;
TBXItem2: TTBXItem;
TBXSeparatorItem1: TTBXSeparatorItem;
cxGridViewREFERENCIA_REC_COMPENSADO: TcxGridDBColumn;
cxGridViewID_RECIBO_COMPENSADO: TcxGridDBColumn;
cxGridViewDATOS_BANCARIOS: TcxGridDBColumn;
procedure cxGridViewICONOCustomDrawCell(Sender: TcxCustomGridTableView;
ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
var ADone: Boolean);
procedure cxGridViewStylesGetContentStyle(Sender: TcxCustomGridTableView;
ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem;
out AStyle: TcxStyle);
procedure cxGridActiveTabChanged(Sender: TcxCustomGrid; ALevel: TcxGridLevel);
procedure cxGridViewIMPORTE_TOTALGetDisplayText(Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: string);
procedure actClienteExecute(Sender: TObject);
procedure actClienteUpdate(Sender: TObject);
procedure cxGridViewID_RECIBO_COMPENSADOCustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
procedure cxGridViewDataControllerCompare(
ADataController: TcxCustomDataController; ARecordIndex1, ARecordIndex2,
AItemIndex: Integer; const V1, V2: Variant; var Compare: Integer);
private
//Filtros relativos a la vista
procedure AnadirFiltroSituaciones;
procedure AnadirFiltroFechas;
protected
FRecibos: IBizRecibosCliente;
function GetRecibos: IBizRecibosCliente;
procedure SetRecibos(const Value: IBizRecibosCliente);
public
property Recibos: IBizRecibosCliente read GetRecibos write SetRecibos;
procedure FiltrarPorFechas(const Fecha1, Fecha2: Variant);
procedure AnadirOtrosFiltros; override;
end;
implementation
uses
schRecibosClienteClient_Intf, uDataModuleRecibosCliente, DateUtils,
uReferenciasUtils, cxVariants;
{$R *.dfm}
{ TfrViewRecibosCliente }
procedure TfrViewRecibosCliente.actClienteExecute(Sender: TObject);
begin
if (cxGridViewNOMBRE_CLIENTE.GroupIndex < 0) then
begin
cxGridViewNOMBRE_CLIENTE.GroupIndex := cxGridView.GroupedColumnCount;
cxGridViewNOMBRE_CLIENTE.Visible := False;
end
else
begin
cxGridViewNOMBRE_CLIENTE.GroupIndex := -1;
cxGridViewNOMBRE_CLIENTE.Visible := True;
end;
end;
procedure TfrViewRecibosCliente.actClienteUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewNOMBRE_CLIENTE.GroupIndex < 0);
end;
procedure TfrViewRecibosCliente.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(fld_RecibosClienteFECHA_VENCIMIENTO);
FFiltro.AddItem(Columna, foBetween, varArrayOf([Fecha1, Fecha2]), VarToStr(Fecha1) + ' and ' + VarToStr(Fecha2));
end;
end;
procedure TfrViewRecibosCliente.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_COBRADO, CTE_COBRADO);
3 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, CTE_DEVUELTO, CTE_DEVUELTO);
end;
end;
procedure TfrViewRecibosCliente.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 TfrViewRecibosCliente.cxGridActiveTabChanged(Sender: TcxCustomGrid;
ALevel: TcxGridLevel);
begin
inherited;
RefrescarFiltro;
end;
procedure TfrViewRecibosCliente.cxGridViewDataControllerCompare(
ADataController: TcxCustomDataController; ARecordIndex1, ARecordIndex2,
AItemIndex: Integer; const V1, V2: Variant; var Compare: Integer);
begin
inherited;
if ((AItemIndex = cxGridViewREFERENCIA.Index) or
(AItemIndex = cxGridViewREFERENCIA_REMESA.Index) or
(AItemIndex = cxGridViewREFERENCIA_REC_COMPENSADO.Index)) and
(VarType(V1) = VarType(V2)) and (VarType(V1) = varString) then
Compare := CompararReferencias(V1, V2)
else
Compare := VarCompare(V1, V2);
end;
procedure TfrViewRecibosCliente.cxGridViewICONOCustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
{var
R : TRect;}
begin
inherited;
{ R := AViewInfo.ContentBounds;
ACanvas.FillRect(R);
if (Pos('-', AViewInfo.GridRecord.DisplayTexts[cxGridViewIMPORTE_TOTAL.Index]) > 0) then
ACanvas.DrawImage(PngImageList, R.Left, R.Top, 3)
else
ACanvas.DrawImage(PngImageList, R.Left, R.Top, 2);
ADone := True;}
end;
procedure TfrViewRecibosCliente.cxGridViewID_RECIBO_COMPENSADOCustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
R : TRect;
begin
inherited;
if not VarIsNull(AViewInfo.Value) then
begin
R := AViewInfo.ContentBounds;
ACanvas.FillRect(R);
ACanvas.DrawImage(GridPNGImageList, R.Left, R.Top, 1);
ADone := True;
end;
end;
procedure TfrViewRecibosCliente.cxGridViewIMPORTE_TOTALGetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: string);
var
ImporteTotal : Double;
begin
//Se encarga de mostrar el campo calculado de importe total
ImporteTotal := -1;
if not VarIsNull(ARecord.Values[cxGridViewIMPORTE.Index]) then
if not VarIsNull(ARecord.Values[cxGridViewOTROS_GASTOS.Index]) then
ImporteTotal := ARecord.Values[cxGridViewIMPORTE.Index] + ARecord.Values[cxGridViewOTROS_GASTOS.Index]
else
ImporteTotal := ARecord.Values[cxGridViewIMPORTE.Index];
if (ImporteTotal <> -1) then
begin
AText := FormatCurr(',0.00 €;-,0.00 €', FloatToCurr(ImporteTotal));
ARecord.Values[cxGridViewIMPORTE_TOTAL.Index] := ImporteTotal;
cxGridViewIMPORTE_TOTAL.EditValue := ImporteTotal;
cxGridViewIMPORTE_TOTAL.DataBinding.Field.Value := ImporteTotal;
end;
end;
procedure TfrViewRecibosCliente.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 := UPPERCASE(VarToStr(ARecord.DisplayTexts[IndiceCol]));
if (ASituacion = CTE_PENDIENTE) then
AStyle.TextColor := cxStylePendientes.TextColor
else if (ASituacion = CTE_COBRADO) then
AStyle.TextColor := cxStylePagados.TextColor
else if (ASituacion = CTE_DEVUELTO) then
AStyle.TextColor := cxStyleDevueltos.TextColor;
end;
end;
procedure TfrViewRecibosCliente.FiltrarPorFechas(const Fecha1, Fecha2: Variant);
var
Columna: TcxGridDBColumn;
begin
with cxGridView.DataController.Filter do
begin
BeginUpdate;
try
Options := [fcoCaseInsensitive, fcoSoftCompare];
Root.Clear;
if not VarIsNull(Fecha1)
and not VarIsNull(Fecha2) then
begin
Columna := (cxGridView as TcxGridDBTableView).GetColumnByFieldName(fld_RecibosClienteFECHA_VENCIMIENTO);
Root.AddItem(Columna, foBetween, varArrayOf([Fecha1, Fecha2]), VarToStr(Fecha1) + ' and ' + VarToStr(Fecha2));
Active := True;
end
else
Active := False;
finally
EndUpdate;
end;
end;
end;
function TfrViewRecibosCliente.GetRecibos: IBizRecibosCliente;
begin
Result := FRecibos;
end;
procedure TfrViewRecibosCliente.SetRecibos(const Value: IBizRecibosCliente);
begin
FRecibos := Value;
if Assigned(FRecibos) then
dsDataSource.DataTable := FRecibos.DataTable;
end;
end.