AbetoDesign_FactuGES2/Source/Modulos/Contratos de cliente/Views/uViewContratosCliente.pas
2024-04-24 09:04:40 +00:00

516 lines
18 KiB
ObjectPascal
Raw Blame History

unit uViewContratosCliente;
interface
uses
uViewGrid, cxStyles, cxCustomData, cxGraphics, cxFilter,
cxData, cxDataStorage, cxEdit, DB, cxDBData, dxPSGlbl, dxPSUtl, dxPSEngn,
dxPrnPg, dxBkgnd, dxWrap, dxPrnDev, dxPSCompsProvider, dxPSFillPatterns,
dxPSEdgePatterns, cxImageComboBox, ImgList, Controls, PngImageList,
cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxGridCustomPopupMenu, cxGridPopupMenu, dxPSCore, dxPScxCommon, dxPScxGrid6Lnk,
uDADataTable, cxGridLevel, cxClasses, cxControls, cxGridCustomView, Classes,
cxGrid, uBizContratosCliente, cxCurrencyEdit, Forms, uViewFiltroBase, ActnList, TB2Item,
TBX, TB2Toolbar, TBXDkPanels, TB2Dock, dxPgsDlg, uDAInterfaces, Windows,
uCustomView, uViewBase, cxTextEdit;
type
IViewContratosCliente = interface(IViewGrid)
['{89FCCB14-46E9-4B45-BADD-847C881CCE1A}']
function GetContratos: IBizContratoCliente;
procedure SetContratos(const Value: IBizContratoCliente);
property Contratos: IBizContratoCliente read GetContratos write SetContratos;
end;
TfrViewContratosCliente = class(TfrViewGrid, IViewContratosCliente)
cxGridViewREFERENCIA: TcxGridDBColumn;
cxGridViewINCIDENCIASACTIVAS: TcxGridDBColumn;
cxGridViewNOMBRE: TcxGridDBColumn;
cxGridViewSITUACION: TcxGridDBColumn;
cxGridViewFECHA_CONTRATO: TcxGridDBColumn;
cxGridViewIMPORTE_TOTAL: TcxGridDBColumn;
cxGridLevelPendientes: TcxGridLevel;
cxGridLevelTerminados: TcxGridLevel;
cxStylePENDIENTESYFACTURADASPLUS: TcxStyle;
actCliente: TAction;
TBXSeparatorItem2: TTBXSeparatorItem;
TBXItem3: TTBXItem;
cxGridViewNIF_CIF: TcxGridDBColumn;
cxGridViewINCIDENCIAS: TcxGridDBColumn;
cxStyleTERMINADO: TcxStyle;
cxGridViewTIPO_CONTRATO: TcxGridDBColumn;
cxGridViewREFERENCIA_CLIENTE: TcxGridDBColumn;
cxGridViewFACTURA_ASOCIADA: TcxGridDBColumn;
cxStylePENDIENTES: TcxStyle;
cxGridViewIMPORTE_IVA: TcxGridDBColumn;
cxGridViewIVA: TcxGridDBColumn;
cxGridViewBASE_IMPONIBLE: TcxGridDBColumn;
cxGridViewNOMBRE_COMERCIAL_CLIENTE: TcxGridDBColumn;
cxGridViewPROCEDENCIA_CLIENTE: TcxGridDBColumn;
TBXSeparatorItem1: TTBXSeparatorItem;
TBXItem2: TTBXItem;
actProcedencia: TAction;
cxGridViewVENDEDOR: TcxGridDBColumn;
cxGridViewBASE_IMPONIBLE_FACTURAS: TcxGridDBColumn;
cxStylePENDIENTESYFACTURADASOK: TcxStyle;
cxGridViewTIENDA: TcxGridDBColumn;
cxGridLevelPendientesRevisar: TcxGridLevel;
cxStylePENDIENTESREVISION: TcxStyle;
cxGridViewENVIADA_REVISADA: TcxGridDBColumn;
cxGridLevelCancelados: TcxGridLevel;
cxGridViewPROVINCIA: TcxGridDBColumn;
actProvincia: TAction;
TBXSeparatorItem3: TTBXSeparatorItem;
TBXItem4: TTBXItem;
cxGridViewAGENTE: TcxGridDBColumn;
cxGridViewDELEGACION: TcxGridDBColumn;
actComercial: TAction;
actDelegacion: TAction;
TBXSeparatorItem4: TTBXSeparatorItem;
TBXSeparatorItem5: TTBXSeparatorItem;
TBXItem5: TTBXItem;
TBXItem6: TTBXItem;
cxGridViewINSTALADOR: TcxGridDBColumn;
actInstalador: TAction;
TBXSeparatorItem6: TTBXSeparatorItem;
TBXItem7: TTBXItem;
actTienda: TAction;
TBXSeparatorItem7: TTBXSeparatorItem;
TBXItem8: TTBXItem;
cxGridViewPAIS: TcxGridDBColumn;
cxGridViewIDIOMA: TcxGridDBColumn;
actPais: TAction;
TBXSeparatorItem8: TTBXSeparatorItem;
TBXItem9: TTBXItem;
procedure cxGridActiveTabChanged(Sender: TcxCustomGrid; ALevel:
TcxGridLevel);
procedure cxGridViewStylesGetContentStyle(Sender: TcxCustomGridTableView;
ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out
AStyle: TcxStyle);
procedure actClienteExecute(Sender: TObject);
procedure actClienteUpdate(Sender: TObject);
procedure cxGridViewICONOCustomDrawCell(Sender: TcxCustomGridTableView;
ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
var ADone: Boolean);
procedure cxGridViewINCIDENCIASACTIVASGetCellHint(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
ACellViewInfo: TcxGridTableDataCellViewInfo; const AMousePos: TPoint;
var AHintText: TCaption; var AIsHintMultiLine: Boolean;
var AHintTextRect: TRect);
procedure cxGridViewDataControllerCompare(
ADataController: TcxCustomDataController; ARecordIndex1, ARecordIndex2,
AItemIndex: Integer; const V1, V2: Variant; var Compare: Integer);
procedure actProcedenciaExecute(Sender: TObject);
procedure actProcedenciaUpdate(Sender: TObject);
procedure actProvinciaExecute(Sender: TObject);
procedure actProvinciaUpdate(Sender: TObject);
procedure actComercialExecute(Sender: TObject);
procedure actComercialUpdate(Sender: TObject);
procedure actDelegacionExecute(Sender: TObject);
procedure actDelegacionUpdate(Sender: TObject);
procedure actInstaladorExecute(Sender: TObject);
procedure actInstaladorUpdate(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
FContratos: IBizContratoCliente;
function GetContratos: IBizContratoCliente;
procedure SetContratos(const Value: IBizContratoCliente);
public
procedure AnadirOtrosFiltros; override;
procedure ConfigView; override;
property Contratos: IBizContratoCliente read GetContratos write SetContratos;
end;
implementation
uses
SysUtils, variants, uDataModuleContratosCliente, schContratosClienteClient_Intf,
uViewGridBase, uFactuGES_App,
//uReferenciasUtils,
cxVariants;
{$R *.dfm}
procedure TfrViewContratosCliente.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 TfrViewContratosCliente.actClienteUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewNOMBRE.GroupIndex < 0);
end;
procedure TfrViewContratosCliente.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 TfrViewContratosCliente.actComercialUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewAGENTE.GroupIndex < 0);
end;
procedure TfrViewContratosCliente.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 TfrViewContratosCliente.actDelegacionUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewDELEGACION.GroupIndex < 0);
end;
procedure TfrViewContratosCliente.actInstaladorExecute(Sender: TObject);
begin
if (cxGridViewINSTALADOR.GroupIndex < 0) then
begin
cxGridViewINSTALADOR.GroupIndex := cxGridView.GroupedColumnCount;
cxGridViewINSTALADOR.Visible := False;
end
else
begin
cxGridViewINSTALADOR.GroupIndex := -1;
cxGridViewINSTALADOR.Visible := True;
end;
end;
procedure TfrViewContratosCliente.actInstaladorUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewINSTALADOR.GroupIndex < 0);
(Sender as TAction).Enabled := (AppFactuGES.EmpresaActiva.ID = CTE_EMPRESA_ABETO);
(Sender as TAction).Visible := (AppFactuGES.EmpresaActiva.ID = CTE_EMPRESA_ABETO);
end;
procedure TfrViewContratosCliente.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 TfrViewContratosCliente.actPaisUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewPAIS.GroupIndex < 0);
end;
procedure TfrViewContratosCliente.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 TfrViewContratosCliente.actProcedenciaUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewPROCEDENCIA_CLIENTE.GroupIndex < 0);
end;
procedure TfrViewContratosCliente.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 TfrViewContratosCliente.actProvinciaUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewPROVINCIA.GroupIndex < 0);
end;
procedure TfrViewContratosCliente.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 TfrViewContratosCliente.actTiendaUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewTIENDA.GroupIndex < 0);
end;
procedure TfrViewContratosCliente.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_CONTRATO');
FFiltro.AddItem(Columna, foBetween, varArrayOf([Fecha1, Fecha2]), VarToStr(Fecha1) + ' and ' + VarToStr(Fecha2));
end;
end;
procedure TfrViewContratosCliente.AnadirFiltroSituaciones;
var
FFiltro : TcxFilterCriteriaItemList;
begin
FFiltro := AddFilterGrid(fboAnd);
case cxGrid.ActiveLevel.Index of
1 : FFiltro.AddItem(cxGridViewENVIADA_REVISADA, foEqual, '2', '2');
2 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, SITUACION_CONTRATO_PENDIENTE, SITUACION_CONTRATO_PENDIENTE);
3 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, SITUACION_CONTRATO_TERMINADO, SITUACION_CONTRATO_TERMINADO);
4 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, SITUACION_CONTRATO_CANCELADO, SITUACION_CONTRATO_CANCELADO);
end;
end;
procedure TfrViewContratosCliente.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 TfrViewContratosCliente.ConfigView;
begin
inherited;
cxGridLevelPendientesRevisar.Visible := False;
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;
cxGridViewINSTALADOR.Visible := False;
cxGridViewINSTALADOR.VisibleForCustomization := False;
actInstalador.Visible := False;
//FILTRO DE EMPRESAS TIENDA
if (AppFactuGES.EmpresaActiva.ID = CTE_EMPRESA_ABETO) then
begin
cxGridLevelPendientesRevisar.Visible := True;
cxGridViewTIENDA.Visible := False;
cxGridViewTIENDA.VisibleForCustomization := False;
actTienda.Visible := False;
cxGridViewINSTALADOR.Visible := True;
cxGridViewINSTALADOR.VisibleForCustomization := True;
actInstalador.Visible := True;
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;
end;
end;
procedure TfrViewContratosCliente.cxGridActiveTabChanged(Sender: TcxCustomGrid; ALevel: TcxGridLevel);
begin
inherited;
RefrescarFiltro;
end;
procedure TfrViewContratosCliente.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 TfrViewContratosCliente.cxGridViewICONOCustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
{var
R : TRect;}
begin
inherited;
{ R := AViewInfo.ContentBounds;
ACanvas.FillRect(R);
if (cxGridView.DataController.DisplayTexts[AViewInfo.GridRecord.RecordIndex,
cxGridViewINCIDENCIASACTIVAS.Index] = 'Sin incidencias') then
ACanvas.DrawImage(GridPNGImageList, R.Left + 2, R.Top + 2, 1)
else
ACanvas.DrawImage(GridPNGImageList, R.Left + 2, R.Top + 2, 2);
ADone := True;}
end;
procedure TfrViewContratosCliente.cxGridViewINCIDENCIASACTIVASGetCellHint(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
ACellViewInfo: TcxGridTableDataCellViewInfo; const AMousePos: TPoint;
var AHintText: TCaption; var AIsHintMultiLine: Boolean;
var AHintTextRect: TRect);
begin
inherited;
if (ARecord.DisplayTexts[Sender.Index] <> 'Sin incidencias') then
begin
AIsHintMultiLine := True;
if not VarIsNull(ARecord.Values[cxGridViewINCIDENCIAS.Index]) then
AHintText := ARecord.Values[cxGridViewINCIDENCIAS.Index];
end;
end;
procedure TfrViewContratosCliente.cxGridViewStylesGetContentStyle(Sender:
TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem:
TcxCustomGridTableItem; out AStyle: TcxStyle);
var
IndiceCol: Integer;
IndiceCol2: Integer;
IndiceCol3: Integer;
IndiceCol4: Integer;
ASituacion: string;
AFacturas: string;
begin
inherited;
if Assigned(ARecord) then
begin
IndiceCol := (Sender as TcxGridDBTableView).GetColumnByFieldName(fld_ContratosClienteSITUACION).Index;
IndiceCol2 := (Sender as TcxGridDBTableView).GetColumnByFieldName(fld_ContratosClienteFACTURA_ASOCIADA).Index;
IndiceCol3 := (Sender as TcxGridDBTableView).GetColumnByFieldName(fld_ContratosClienteBASE_IMPONIBLE_FACTURAS).Index;
IndiceCol4 := (Sender as TcxGridDBTableView).GetColumnByFieldName(fld_ContratosClienteBASE_IMPONIBLE).Index;
ASituacion := VarToStr(ARecord.DisplayTexts[IndiceCol]);
AFacturas := VarToStr(ARecord.DisplayTexts[IndiceCol2]);
//Por aqui pasa muchas veces con distintos componentes del gird, de hecho algunos no tienen el elemento AStyle y si le asignamos algo por defecto como estaba
//peta estrepitosamente, hay que asegurarse que el componente que se dibuja tiene AStyle, en el resto no falla, porque no asignamos estile si no cumple ninguna
//situaci<63>n, as<61> asignamos un estile por defecto y lo cambiamos seg<65>n condiciones.
if Assigned(AStyle) then
begin
AStyle.TextColor := cxStylePENDIENTESREVISION.TextColor;
if ASituacion = SITUACION_CONTRATO_PENDIENTE then
begin
if (AFacturas = '') then
AStyle.TextColor := cxStylePENDIENTES.TextColor
else if (ARecord.Values[IndiceCol3] < ARecord.Values[IndiceCol4]) then
AStyle.TextColor := cxStylePENDIENTESYFACTURADASPLUS.TextColor
else if (ARecord.Values[IndiceCol3] >= ARecord.Values[IndiceCol4]) then
AStyle.TextColor := cxStylePENDIENTESYFACTURADASOK.TextColor
else
AStyle.TextColor := cxStylePENDIENTES.TextColor;
end
else if (ASituacion = SITUACION_CONTRATO_TERMINADO)
or (ASituacion = SITUACION_CONTRATO_CANCELADO) then
AStyle.TextColor := cxStyleTERMINADO.TextColor;
end;
end;
end;
function TfrViewContratosCliente.GetContratos: IBizContratoCliente;
begin
Result := FContratos;
end;
procedure TfrViewContratosCliente.SetContratos(const Value: IBizContratoCliente);
begin
FContratos := Value;
if Assigned(FContratos) then
dsDataSource.DataTable := FContratos.DataTable;
end;
end.