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.
Noviseda_FactuGES2/Source/Modulos/Albaranes de cliente/Views/uViewAlbaranesCliente.pas
roberto f2c4e7954f #408: Informe de comisiones de vendedor ordenar por referencia de factura
#409: Sacar en pedidos de cliente y albaranes de cliente la provincia
#410: Sacar nombre comercial en etiquetas y albaranes y pedidos
#411: Cuando sea un abono que salga en grande en el informe
#412: Cuando una factura es más de dos hojas que no repita el pie de importes
#413: Poder filtrar por provincia en todos los documentos
Version 1.0.8

git-svn-id: https://192.168.0.254/svn/Proyectos.Noviseda_FactuGES2/trunk@134 f33bb606-9f5c-448d-9c99-757f00063c96
2010-07-12 15:44:32 +00:00

379 lines
13 KiB
ObjectPascal

unit uViewAlbaranesCliente;
interface
uses
Types, 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,
uBizAlbaranesCliente, cxCurrencyEdit, Forms, uViewFiltroBase, ComCtrls, Tabs,
cxPC, ActnList, TB2Item, SpTBXItem, TB2Dock, TB2Toolbar, SpTBXDkPanels, dxPgsDlg,
uDAInterfaces, uCustomView, uViewBase, cxLookAndFeels, cxLookAndFeelPainters,
dxPSPDFExportCore, dxPSPDFExport, cxDrawTextUtils, dxPSPrVwStd, dxPSPrVwAdv,
dxPScxEditorProducers, dxPScxExtEditorProducers, dxPScxPageControlProducer;
type
IViewAlbaranesCliente = interface(IViewGrid)
['{C0B0D9D9-2E0E-4CA5-88C8-B8C71CFAD59B}']
function GetAlbaranes: IBizAlbaranCliente;
procedure SetAlbaranes(const Value: IBizAlbaranCliente);
property Albaranes: IBizAlbaranCliente read GetAlbaranes write SetAlbaranes;
end;
TfrViewAlbaranesCliente = class(TfrViewGrid, IViewAlbaranesCliente)
cxGridViewREF_FACTURA: TcxGridDBColumn;
cxGridViewREFERENCIA: TcxGridDBColumn;
cxGridViewFECHA_ALBARAN: TcxGridDBColumn;
cxGridViewINCIDENCIAS_ACTIVAS: TcxGridDBColumn;
cxGridViewNOMBRE: TcxGridDBColumn;
cxGridViewSITUACION: TcxGridDBColumn;
cxGridViewCALLE: TcxGridDBColumn;
cxGridViewCODIGO_POSTAL: TcxGridDBColumn;
cxGridViewPOBLACION: TcxGridDBColumn;
cxGridViewPROVINCIA: TcxGridDBColumn;
cxGridViewPERSONA_CONTACTO: TcxGridDBColumn;
cxGridViewTELEFONO: TcxGridDBColumn;
cxGridViewFECHA_ENVIO: TcxGridDBColumn;
cxGridViewFECHA_RECEPCION: TcxGridDBColumn;
cxGridViewREF_PEDIDO: TcxGridDBColumn;
cxGridViewNOMBRE_ALMACEN: TcxGridDBColumn;
cxGridLevelPendientes: TcxGridLevel;
cxGridLevelEnviados: TcxGridLevel;
cxGridLevelServidos: TcxGridLevel;
cxGridLevelProximosAEnviar: TcxGridLevel;
cxStyleProximosAEnviar: TcxStyle;
cxStylePENDIENTES: TcxStyle;
cxStyleENVIADOS: TcxStyle;
cxStyleSERVIDOS: TcxStyle;
cxGridViewIMPORTE_TOTAL: TcxGridDBColumn;
actClientes: TAction;
actAlmacenes: TAction;
TBXItem2: TSpTBXItem;
TBXItem3: TSpTBXItem;
TBXSeparatorItem1: TSpTBXSeparatorItem;
TBXSeparatorItem2: TSpTBXSeparatorItem;
cxGridViewFECHA_PREVISTA_ENVIO: TcxGridDBColumn;
cxStyleRETRASADOS: TcxStyle;
cxGridViewINCIDENCIAS: TcxGridDBColumn;
procedure cxGridActiveTabChanged(Sender: TcxCustomGrid; ALevel:
TcxGridLevel);
procedure cxGridViewStylesGetContentStyle(Sender: TcxCustomGridTableView;
ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out
AStyle: TcxStyle);
procedure actClientesExecute(Sender: TObject);
procedure actClientesUpdate(Sender: TObject);
procedure actAlmacenesExecute(Sender: TObject);
procedure actAlmacenesUpdate(Sender: TObject);
procedure cxGridViewINCIDENCIAS_ACTIVASGetCellHint(
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 OnFiltroListaPropertiesChange(Sender: TObject);
procedure OnFiltroListaPropertiesInitPopup(Sender: TObject);
procedure CustomViewCreate(Sender: TObject);
procedure CustomViewDestroy(Sender: TObject);
procedure CustomViewShow(Sender: TObject);
private
//Filtros relativos a la vista
procedure AnadirFiltroSituaciones;
procedure AnadirFiltroFechas;
procedure AnadirFiltroProvincia;
protected
FProvincias : TStringList;
FAlbaranes: IBizAlbaranCliente;
function GetAlbaranes: IBizAlbaranCliente;
procedure SetAlbaranes(const Value: IBizAlbaranCliente);
procedure CargarProvincias;
public
procedure AnadirOtrosFiltros; override;
property Albaranes: IBizAlbaranCliente read GetAlbaranes write SetAlbaranes;
end;
implementation
uses
SysUtils, DateUtils, variants, windows, uDataModuleAlbaranesCliente, schAlbaranesClienteClient_Intf,
uViewGridBase, uReferenciasUtils, cxVariants, uProvinciasPoblacionesController, uStringsUtils;
{$R *.dfm}
procedure TfrViewAlbaranesCliente.actAlmacenesExecute(Sender: TObject);
begin
if (cxGridViewNOMBRE_ALMACEN.GroupIndex < 0) then
begin
cxGridViewNOMBRE_ALMACEN.GroupIndex := cxGridView.GroupedColumnCount;
cxGridViewNOMBRE_ALMACEN.Visible := False;
end
else
begin
cxGridViewNOMBRE_ALMACEN.GroupIndex := -1;
cxGridViewNOMBRE_ALMACEN.Visible := True;
end;
end;
procedure TfrViewAlbaranesCliente.actAlmacenesUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewNOMBRE_ALMACEN.GroupIndex < 0);
end;
procedure TfrViewAlbaranesCliente.actClientesExecute(Sender: TObject);
begin
inherited;
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 TfrViewAlbaranesCliente.actClientesUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Checked := not (cxGridViewNOMBRE.GroupIndex < 0);
end;
procedure TfrViewAlbaranesCliente.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_PREVISTA_ENVIO');
FFiltro.AddItem(Columna, foBetween, varArrayOf([Fecha1, Fecha2]), VarToStr(Fecha1) + ' and ' + VarToStr(Fecha2));
// FFiltro.BoolOperatorKind := fboOr;
// Columna := (cxGridView as TcxGridDBTableView).GetColumnByFieldName('FECHA_ALBARAN');
// FFiltro.AddItem(Columna, foBetween, varArrayOf([Fecha1, Fecha2]), VarToStr(Fecha1) + ' and ' + VarToStr(Fecha2));
end;
end;
procedure TfrViewAlbaranesCliente.AnadirFiltroProvincia;
var
FFiltro : TcxFilterCriteriaItemList;
begin
//Solo se aplica este filtro en el caso de tener activo el panel de detalle de filtro
//y sobre la lista de pedidos
if frViewFiltroBase1.Visible then
begin
if (VarToStr(frViewFiltroBase1.eLista.EditValue) <> 'Todos') then
begin
FFiltro := AddFilterGrid(fboAnd);
FFiltro.AddItem(cxGridViewPROVINCIA, foEqual, VarToStr(frViewFiltroBase1.eLista.EditValue), VarToStr(frViewFiltroBase1.eLista.EditValue));
end;
end;
end;
procedure TfrViewAlbaranesCliente.AnadirFiltroSituaciones;
var
FFiltro : TcxFilterCriteriaItemList;
begin
FFiltro := AddFilterGrid(fboAnd);
case cxGrid.ActiveLevel.Index of
1 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, SITUACION_ALBARAN_PENDIENTE, SITUACION_ALBARAN_PENDIENTE);
2 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, SITUACION_ALBARAN_ENVIADO, SITUACION_ALBARAN_ENVIADO);
3 : FFiltro.AddItem(cxGridViewSITUACION, foEqual, SITUACION_ALBARAN_SERVIDO, SITUACION_ALBARAN_SERVIDO);
4 : begin
FFiltro.AddItem(cxGridViewSITUACION, foEqual, SITUACION_ALBARAN_PENDIENTE, SITUACION_ALBARAN_PENDIENTE);
FFiltro := AddFilterGrid(fboAnd);
FFiltro.AddItem(cxGridViewFECHA_PREVISTA_ENVIO, foNotEqual, null, 'NO_NULO');
FFiltro := AddFilterGrid(fboAnd);
FFiltro.AddItem(cxGridViewFECHA_PREVISTA_ENVIO, foLess, DateOf(Now), 'RETRASADOS');
end;
end;
end;
procedure TfrViewAlbaranesCliente.AnadirOtrosFiltros;
begin
inherited;
AnadirFiltroSituaciones;
AnadirFiltroFechas;
AnadirFiltroProvincia;
//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 TfrViewAlbaranesCliente.CargarProvincias;
var
i : integer;
begin
with TProvinciasPoblacionesController.Create do
try
FProvincias := DarListaProvincias;
with frViewFiltroBase1.eLista.Properties.Items do
begin
BeginUpdate;
try
Clear;
Add('Todos'); //Case 0
for i := 0 to FProvincias.Count - 1 do
Add(FProvincias.Names[i]);
frViewFiltroBase1.eLista.ItemIndex := 0;
finally
EndUpdate;
end;
end;
finally
Free;
end;
end;
procedure TfrViewAlbaranesCliente.CustomViewCreate(Sender: TObject);
begin
inherited;
FProvincias := NIL;
end;
procedure TfrViewAlbaranesCliente.CustomViewDestroy(Sender: TObject);
begin
frViewFiltroBase1.eLista.Properties.OnChange := Nil;
frViewFiltroBase1.eLista.Properties.OnInitPopup := Nil;
if Assigned(FProvincias) then
FreeANDNIL(FProvincias);
inherited;
end;
procedure TfrViewAlbaranesCliente.CustomViewShow(Sender: TObject);
begin
inherited;
frViewFiltroBase1.eLista.Properties.OnChange := OnFiltroListaPropertiesChange;
frViewFiltroBase1.eLista.Properties.OnInitPopup := OnFiltroListaPropertiesInitPopup;
end;
procedure TfrViewAlbaranesCliente.cxGridActiveTabChanged(Sender: TcxCustomGrid; ALevel: TcxGridLevel);
begin
inherited;
RefrescarFiltro;
end;
procedure TfrViewAlbaranesCliente.cxGridViewDataControllerCompare(
ADataController: TcxCustomDataController; ARecordIndex1, ARecordIndex2,
AItemIndex: Integer; const V1, V2: Variant; var Compare: Integer);
begin
inherited;
if ((AItemIndex = cxGridViewREFERENCIA.Index) or
(AItemIndex = cxGridViewREF_FACTURA.Index) or
(AItemIndex = cxGridViewREF_PEDIDO.Index)) and
(VarType(V1) = VarType(V2)) and (VarType(V1) = varString) then
Compare := CompararReferencias(V1, V2)
else
Compare := VarCompare(V1, V2);
end;
procedure TfrViewAlbaranesCliente.cxGridViewINCIDENCIAS_ACTIVASGetCellHint(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
ACellViewInfo: TcxGridTableDataCellViewInfo; const AMousePos: TPoint;
var AHintText: TCaption; var AIsHintMultiLine: Boolean;
var AHintTextRect: TRect);
begin
inherited;
if (not VarIsNull(ARecord.Values[Sender.Index])) and
(ARecord.Values[Sender.Index] = '1') then
begin
AIsHintMultiLine := True;
AHintText := VarToStr(ARecord.Values[cxGridViewINCIDENCIAS.Index]);
end;
end;
procedure TfrViewAlbaranesCliente.cxGridViewStylesGetContentStyle(Sender:
TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem:
TcxCustomGridTableItem; out AStyle: TcxStyle);
var
IndiceCol: Integer;
ASituacion: string;
begin
inherited;
if Assigned(ARecord) then
begin
if Assigned((Sender as TcxGridDBTableView).GetColumnByFieldName(fld_AlbaranesClienteSITUACION)) then
begin
IndiceCol := (Sender as TcxGridDBTableView).GetColumnByFieldName(fld_AlbaranesClienteSITUACION).Index;
ASituacion := VarToStr(ARecord.DisplayTexts[IndiceCol]);
if ASituacion = SITUACION_ALBARAN_PENDIENTE then
begin
if not VarIsNull(ARecord.Values[cxGridViewFECHA_PREVISTA_ENVIO.Index]) then
if (StrToDate(ARecord.DisplayTexts[cxGridViewFECHA_PREVISTA_ENVIO.Index]) < DateOf(Now)) then
AStyle.TextColor := cxStyleRETRASADOS.TextColor
else
AStyle.TextColor := cxStylePENDIENTES.TextColor
else
AStyle.TextColor := cxStylePENDIENTES.TextColor;
end
else if ASituacion = SITUACION_ALBARAN_ENVIADO then
AStyle.TextColor := cxStyleENVIADOS.TextColor
else if ASituacion = SITUACION_ALBARAN_SERVIDO then
AStyle.TextColor := cxStyleSERVIDOS.TextColor;
end;
end;
end;
function TfrViewAlbaranesCliente.GetAlbaranes: IBizAlbaranCliente;
begin
Result := FAlbaranes;
end;
procedure TfrViewAlbaranesCliente.OnFiltroListaPropertiesChange(Sender: TObject);
begin
inherited;
RefrescarFiltro;
end;
procedure TfrViewAlbaranesCliente.OnFiltroListaPropertiesInitPopup(Sender: TObject);
begin
inherited;
ShowHourglassCursor;
try
if not Assigned(FProvincias) then
CargarProvincias;
finally
HideHourglassCursor;
end;
end;
procedure TfrViewAlbaranesCliente.SetAlbaranes(const Value: IBizAlbaranCliente);
begin
FAlbaranes := Value;
if Assigned(FAlbaranes) then
dsDataSource.DataTable := FAlbaranes.DataTable;
end;
end.