unit U_GYSFKListView;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin,
  StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP,ShellAPI,IniFiles, cxCheckBox, cxCalendar,
  cxButtonEdit, cxTextEdit, cxPC, cxDropDownEdit, BtnEdit, Menus, Buttons;

type
  TfrmGYSFKListView = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ADOQueryMain: TADOQuery;
    Label3: TLabel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    CheckBox1: TCheckBox;
    FactoryNameGYS: TEdit;
    v2Column5: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    cxGrid1: TcxGrid;
    Tv3: TcxGridDBTableView;
    v2Column3: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    v2Column13: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    DataSource3: TDataSource;
    cxGridPopupMenu3: TcxGridPopupMenu;
    ClientDataSet3: TClientDataSet;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Tv3CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    { Private declarations }

    procedure InitGrid();

  public
    FKHNO:string;
    { Public declarations }

  end;

var
  frmGYSFKListView: TfrmGYSFKListView;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp, U_GYSListSelJJ,U_RTFun,U_GYSFKInPut,U_FjList,U_BankMoneyGYSInPut;

{$R *.dfm}



procedure TfrmGYSFKListView.InitGrid();
var
  fsj:string;
begin
  fsj:=SGetWhereFinds(Panel1,1,2);
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' select CRTime=Convert(varchar(7),A.CRTime,120),A.SKDate,A.FactoryNo,A.BZType,A.YFName,A.Payment,A.Note,A.YFID,A.Money,A.ConNo ');
      sql.Add(',FactoryName=(select KHNameJC from KH_Main KM where KM.KHNO=A.FactoryNo)');
      sql.Add(',SDQty=(select Count(*) from TP_File TF where TF.WBID=A.YFID and TF.TFType=''付款管理''  )');
      sql.Add(',B.BankNo,B.BankName,B.HuMingJC,A.GSNO,A.BKNO,A.ShuidanMoney,A.ShouXuMoney,A.JSMoney,A.Filler,A.FillTime');
      sql.Add('  from YS_Money_CR A');
      sql.Add(' left join KH_Sub_Bank B on A.BKNO=B.BKNO');
      sql.Add(' left join KH_Main C on B.KHMainId=C.KHMainId');
      sql.Add(' where A.FactoryNo='''+Trim(FKHNO)+'''');
      if CheckBox1.Checked then
      begin
        sql.Add('and A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
        sql.Add(' and CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
      end else
      begin
        sql.Add(' and A.CRTime>=''2000-01-01'' ');
        sql.Add(' and CRTime<''2500-01-01'' ');
      end;
      sql.Add(' and A.CRType=''付款登记'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  try
    ADOQueryTemp.DisableControls;
    with ADOQueryTemp do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add('select CRTime,A.Note,A.YFID,A.JSMoney,A.FKType ');
      sql.Add(',A.FactoryNo,A.CRType,A.CRFlag,A.YFName,A.ConNo');
      sql.Add(',FactoryName=(select KHNameJC from KH_Main KM where KM.KHNO=A.FactoryNo and Valid=''Y'' )');
      sql.Add(',SDQty=(select Count(*) from TP_File TF where TF.WBID=A.YFID and TF.TFType=''供应商费用管理''  )');
      sql.Add(',Case when isnull(A.BZType,'''')=''￥'' then JSMoney else Null end as MoneyRMB ');
      sql.Add(',Case when isnull(A.BZType,'''')=''$'' then JSMoney else Null end as MoneyMJ ');
      sql.Add(',A.FillTime,A.Filler,A.Editer,A.EditTime');
      sql.Add('  from YS_Money_CR A');
      sql.Add(' left join KH_Sub_Bank B on A.BKNO=B.BKNO');
      sql.Add(' left join KH_Main C on B.KHMainId=C.KHMainId');
      sql.Add(' where A.FactoryNo='''+Trim(FKHNO)+'''');
      if CheckBox1.Checked then
      begin
        sql.Add(' and A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
        sql.Add(' and CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
      end else
      begin
        sql.Add(' and A.CRTime>=''2000-01-01'' ');
        sql.Add(' and CRTime<''2500-01-01'' ');
      end;
      sql.Add(' and A.CRType=''供应商费用管理'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,ClientDataSet3);
    SInitCDSData20(ADOQueryTemp,ClientDataSet3);
  finally
    ADOQueryTemp.EnableControls;

  end;
end;


procedure TfrmGYSFKListView.FormDestroy(Sender: TObject);
begin
  frmGYSFKListView:=nil;
end;

procedure TfrmGYSFKListView.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=caFree;
end;

procedure TfrmGYSFKListView.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('供应商付款列表JJ',Tv2,'财务管理');
  WriteCxGrid('供应商费用列表JJ',Tv3,'财务管理');
  Close;
end;
procedure TfrmGYSFKListView.FormShow(Sender: TObject);
var
  Fdate,FbegYear,FendYear:String;
  FBegdate,FEndDate:TDateTime;
begin
  ReadCxGrid('供应商付款列表JJ',Tv2,'财务管理');
  ReadCxGrid('供应商费用列表JJ',Tv3,'财务管理');
  Fdate:=Trim(FormatDateTime('yyyy-MM-dd',SGetServerDate(ADOQueryTemp)));
  if Copy(Fdate,6,2)>='02' then
  begin
    FbegYear:=Copy(Fdate,1,4);
    FendYear:=IntToStr(Strtoint(FbegYear)+1);
  end else
  begin
    FendYear:=Copy(Fdate,1,4);
    FbegYear:=IntToStr(Strtoint(FendYear)+1);
  end;
  FBegdate:=StrToDate(FbegYear+'-02-01');
  FEndDate:=StrToDate(FendYear+'-01-31');
  begdate.Date:=FBegdate;
  Enddate.Date:=FEndDate;
  InitGrid();
end;

procedure TfrmGYSFKListView.TBRafreshClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  InitGrid();
end;

procedure TfrmGYSFKListView.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmGYSFKListView.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  try
    frmGYSFKInPut:=TfrmGYSFKInPut.Create(Application);
    with frmGYSFKInPut do
    begin
      FMainId:=Trim(Self.CDS_HZ.fieldbyname('YFID').AsString);
      ToolButton4.Visible:=False;
      Panel1.Enabled:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmGYSFKInPut.Free;
  end;
end;

procedure TfrmGYSFKListView.Tv3CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  try
    frmBankMoneyGYSInPut:=TfrmBankMoneyGYSInPut.Create(Application);
    with frmBankMoneyGYSInPut do
    begin
      FMainId:=Trim(Self.CDS_HZ.fieldbyname('YFID').AsString);
      ToolButton4.Visible:=False;
      Panel1.Enabled:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmBankMoneyGYSInPut.Free;
  end;
end;

end.
