Tecsitel_FactuGES2/Source/Modulos/Recibos de proveedor/Views/uViewRecibosProveedor.pas

308 lines
10 KiB
ObjectPascal

unit uViewRecibosProveedor;
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, uBizRecibosProveedor, cxGridCustomPopupMenu,
cxGridPopupMenu, cxCalendar, cxCurrencyEdit, uViewFiltroBase, TB2Item, TBX,
TB2Toolbar, TBXDkPanels, TB2Dock, dxPgsDlg, uDAInterfaces, uCustomView,
uViewBase;
type
IViewRecibosProveedor = interface(IViewGrid)
['{2E26DF6E-CFCD-41CC-AC4C-FCF3AD0AD0D7}']
function GetRecibos: IBizRecibosProveedor;
procedure SetRecibos(const Value: IBizRecibosProveedor);
property Recibos: IBizRecibosProveedor read GetRecibos write SetRecibos;
procedure FiltrarPorFechas(const Fecha1, Fecha2: Variant);
end;
TfrViewRecibosProveedor = class(TfrViewGrid, IViewRecibosProveedor)
cxStylePendientes: TcxStyle;
cxGridPendientes: TcxGridLevel;
cxGridPagados: TcxGridLevel;
cxStylePagadas: TcxStyle;
cxGridViewREFERENCIA: TcxGridDBColumn;
cxGridViewSITUACION: TcxGridDBColumn;
cxGridViewFECHA_VENCIMIENTO: TcxGridDBColumn;
cxGridViewDESCRIPCION: TcxGridDBColumn;
cxGridViewIMPORTE: TcxGridDBColumn;
cxGridViewNOMBRE_PROVEEDOR: TcxGridDBColumn;
cxGridViewNIF_CIF_PROVEEDOR: TcxGridDBColumn;
cxGridViewREFERENCIA_REMESA: TcxGridDBColumn;
cxGridDevueltos: TcxGridLevel;
cxGridViewOTROS_GASTOS: TcxGridDBColumn;
cxGridViewIMPORTE_TOTAL: TcxGridDBColumn;
cxGridViewFECHA_EMISION: TcxGridDBColumn;
cxStyleDevueltas: TcxStyle;
actProveedor: TAction;
TBXItem2: TTBXItem;
TBXSeparatorItem1: TTBXSeparatorItem;
cxGridViewREFERENCIA_FACTURA_PROV: TcxGridDBColumn;
cxGridViewID_RECIBO_COMPENSADO: TcxGridDBColumn;
cxGridViewREFERENCIA_REC_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 actProveedorExecute(Sender: TObject);
procedure actProveedorUpdate(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: IBizRecibosProveedor;
function GetRecibos: IBizRecibosProveedor;
procedure SetRecibos(const Value: IBizRecibosProveedor);
public
property Recibos: IBizRecibosProveedor read GetRecibos write SetRecibos;
procedure FiltrarPorFechas(const Fecha1, Fecha2: Variant);
procedure AnadirOtrosFiltros; override;
end;
implementation
uses
schRecibosProveedorClient_Intf, uDataModuleRecibosProveedor,
DateUtils, uViewGridBase, uReferenciasUtils, cxVariants;
{$R *.dfm}
{ TfrViewRecibosProveedor }
procedure TfrViewRecibosProveedor.actProveedorExecute(Sender: TObject);
begin
inherited;
if (cxGridViewNOMBRE_PROVEEDOR.GroupIndex < 0) then
begin
cxGridViewNOMBRE_PROVEEDOR.GroupIndex := cxGridView.GroupedColumnCount;
cxGridViewNOMBRE_PROVEEDOR.Visible := False;
end
else
begin
cxGridViewNOMBRE_PROVEEDOR.GroupIndex := -1;
cxGridViewNOMBRE_PROVEEDOR.Visible := True;
end;
end;
procedure TfrViewRecibosProveedor.actProveedorUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewNOMBRE_PROVEEDOR.GroupIndex < 0);
end;
procedure TfrViewRecibosProveedor.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_RecibosCompensadosProvFECHA_VENCIMIENTO);
FFiltro.AddItem(Columna, foBetween, varArrayOf([Fecha1, Fecha2]), VarToStr(Fecha1) + ' and ' + VarToStr(Fecha2));
end;
end;
procedure TfrViewRecibosProveedor.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_PAGADO, CTE_PAGADO);
3 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, CTE_DEVUELTO, CTE_DEVUELTO);
end;
end;
procedure TfrViewRecibosProveedor.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 TfrViewRecibosProveedor.cxGridActiveTabChanged(Sender: TcxCustomGrid;
ALevel: TcxGridLevel);
begin
inherited;
RefrescarFiltro;
end;
procedure TfrViewRecibosProveedor.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) or
(AItemIndex = cxGridViewREFERENCIA_FACTURA_PROV.Index)) and
(VarType(V1) = VarType(V2)) and (VarType(V1) = varString) then
Compare := CompararReferencias(V1, V2)
else
Compare := VarCompare(V1, V2);
end;
procedure TfrViewRecibosProveedor.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 TfrViewRecibosProveedor.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 TfrViewRecibosProveedor.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 TfrViewRecibosProveedor.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 := cxStylePendientes
else if (ASituacion = CTE_PAGADO) then
AStyle := cxStylePagadas
else if (ASituacion = CTE_DEVUELTO) then
AStyle := cxStyleDevueltas;
end;
end;
procedure TfrViewRecibosProveedor.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_RecibosCompensadosProvFECHA_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 TfrViewRecibosProveedor.GetRecibos: IBizRecibosProveedor;
begin
Result := FRecibos;
end;
procedure TfrViewRecibosProveedor.SetRecibos(const Value: IBizRecibosProveedor);
begin
FRecibos := Value;
if Assigned(FRecibos) then
dsDataSource.DataTable := FRecibos.DataTable;
end;
end.