This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
LuisLeon_FactuGES2/Source/Modulos/Facturas proforma/Views/uViewFacturasProforma.pas

295 lines
9.8 KiB
ObjectPascal

unit uViewFacturasProforma;
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, uBizFacturasProforma, cxGridCustomPopupMenu,
cxGridPopupMenu, cxCalendar, cxCurrencyEdit, uViewFiltroBase, TB2Item, TBX,
TB2Toolbar, TBXDkPanels, TB2Dock, dxPgsDlg, uDAInterfaces, uCustomView,
uViewBase;
type
IViewFacturasProforma = interface(IViewGrid)
['{EEB1FAD2-A0F8-4D45-9D38-3100CA0A4D2D}']
function GetFacturas: IBizFacturaProforma;
procedure SetFacturas(const Value: IBizFacturaProforma);
property Facturas: IBizFacturaProforma read GetFacturas write SetFacturas;
end;
TfrViewFacturasProforma = class(TfrViewGrid, IViewFacturasProforma)
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;
cxGridPagadas: TcxGridLevel;
cxStylePendientes: TcxStyle;
cxStyleParciales: TcxStyle;
actCliente: TAction;
actProvincia: TAction;
TBXItem2: TTBXItem;
TBXSeparatorItem1: TTBXSeparatorItem;
TBXItem3: TTBXItem;
TBXSeparatorItem2: TTBXSeparatorItem;
cxGridViewFECHA_VENCIMIENTO: TcxGridDBColumn;
cxGridViewRE: TcxGridDBColumn;
cxGridViewIMPORTE_RE: TcxGridDBColumn;
cxGridViewREFERENCIA_FACTURA_FINAL: TcxGridDBColumn;
cxGridViewREF_PED_CLIENTE: TcxGridDBColumn;
cxGridViewREF_PED_DEL_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 cxGridViewDataControllerCompare(
ADataController: TcxCustomDataController; ARecordIndex1, ARecordIndex2,
AItemIndex: Integer; const V1, V2: Variant; var Compare: Integer);
procedure cxGridViewNUM_COPIASCustomDrawHeader(Sender: TcxGridTableView;
ACanvas: TcxCanvas; AViewInfo: TcxGridColumnHeaderViewInfo;
var ADone: Boolean);
procedure cxGridViewNUM_CORREOSCustomDrawHeader(Sender: TcxGridTableView;
ACanvas: TcxCanvas; AViewInfo: TcxGridColumnHeaderViewInfo;
var ADone: Boolean);
private
//Filtros relativos a la vista
procedure AnadirFiltroSituaciones;
procedure AnadirFiltroFechas;
protected
FFacturas: IBizFacturaProforma;
function GetFacturas: IBizFacturaProforma;
procedure SetFacturas(const Value: IBizFacturaProforma);
public
procedure AnadirOtrosFiltros; override;
property Facturas: IBizFacturaProforma read GetFacturas write SetFacturas;
end;
implementation
uses
uDataModuleFacturasProforma, DateUtils, uViewGridBase, uReferenciasUtils,
cxVariants, schFacturasProformaClient_Intf;
{$R *.dfm}
{ TfrViewFacturasProforma }
procedure TfrViewFacturasProforma.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 TfrViewFacturasProforma.actClienteUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewNOMBRE.GroupIndex < 0);
end;
procedure TfrViewFacturasProforma.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 TfrViewFacturasProforma.actProvinciaUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewPROVINCIA.GroupIndex < 0);
end;
procedure TfrViewFacturasProforma.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 TfrViewFacturasProforma.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_PAGADA, CTE_PAGADA);
end;
end;
procedure TfrViewFacturasProforma.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 TfrViewFacturasProforma.cxGridActiveTabChanged(Sender: TcxCustomGrid;
ALevel: TcxGridLevel);
begin
inherited;
RefrescarFiltro;
end;
procedure TfrViewFacturasProforma.cxGridViewDataControllerCompare(
ADataController: TcxCustomDataController; ARecordIndex1, ARecordIndex2,
AItemIndex: Integer; const V1, V2: Variant; var Compare: Integer);
begin
inherited;
if (AItemIndex = cxGridViewREFERENCIA.Index) and
(VarType(V1) = VarType(V2)) and (VarType(V1) = varString) then
Compare := CompararReferencias(V1, V2)
else
Compare := VarCompare(V1, V2);
end;
procedure TfrViewFacturasProforma.cxGridViewNUM_COPIASCustomDrawHeader(
Sender: TcxGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean);
var
R : TRect;
begin
inherited;
with AViewInfo do
begin
LookAndFeelPainter.DrawHeader(ACanvas, Bounds, TextAreaBounds, Neighbors,
Borders, ButtonState, AlignmentHorz, AlignmentVert, MultiLine,
False, '', Params.Font, Params.TextColor, Params.Color);
R := AViewInfo.ContentBounds;
ACanvas.FillRect(R);
ACanvas.DrawImage(GridPNGImageList, R.Left + 2, R.Top, 1);
end;
ADone := True;
end;
procedure TfrViewFacturasProforma.cxGridViewNUM_CORREOSCustomDrawHeader(
Sender: TcxGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean);
var
R : TRect;
begin
inherited;
with AViewInfo do
begin
LookAndFeelPainter.DrawHeader(ACanvas, Bounds, TextAreaBounds, Neighbors,
Borders, ButtonState, AlignmentHorz, AlignmentVert, MultiLine,
False, '', Params.Font, Params.TextColor, Params.Color);
R := AViewInfo.ContentBounds;
ACanvas.FillRect(R);
ACanvas.DrawImage(GridPNGImageList, R.Left + 2, R.Top, 2);
end;
ADone := True;
end;
procedure TfrViewFacturasProforma.cxGridViewStylesGetContentStyle(
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
var
IndiceCol: Integer;
ASituacion: string;
begin
inherited;
if Assigned(ARecord) then
begin
//ESTILO SITUACIONES
if Assigned((Sender as TcxGridDBTableView).GetColumnByFieldName(fld_FacturasProformaSITUACION)) then
begin
IndiceCol := (Sender as TcxGridDBTableView).GetColumnByFieldName(fld_FacturasProformaSITUACION).Index;
ASituacion := VarToStr(ARecord.DisplayTexts[IndiceCol]);
if (ASituacion = CTE_PAGADA) then
AStyle := cxStylePagada
else if (ASituacion = CTE_PENDIENTE) then
AStyle := cxStylePendientes;
IndiceCol := (Sender as TcxGridDBTableView).GetColumnByFieldName(fld_FacturasProformaIMPORTE_TOTAL).Index;
if (Pos('-', ARecord.DisplayTexts[IndiceCol]) > 0) then
AStyle := cxStyleAbono;
end;
end;
end;
function TfrViewFacturasProforma.GetFacturas: IBizFacturaProforma;
begin
Result := FFacturas;
end;
procedure TfrViewFacturasProforma.SetFacturas(const Value: IBizFacturaProforma);
begin
FFacturas := Value;
if Assigned(FFacturas) then
dsDataSource.DataTable := FFacturas.DataTable;
end;
end.