unit U_YFFKList;

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;

type
  TfrmYFFKList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    Label1: TLabel;
    ComTaiTou: TEdit;
    v2Column4: TcxGridDBColumn;
    ADOQueryMain: TADOQuery;
    CDS_HZ: TClientDataSet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    v2ComTaiTou: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    v2P_Spec: TcxGridDBColumn;
    v2YFName: TcxGridDBColumn;
    v2ps: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxSplitter1: TcxSplitter;
    DataSource1: TDataSource;
    YForder_Sub: TClientDataSet;
    v1FKTaitou: TcxGridDBColumn;
    v2KHType: TcxGridDBColumn;
    Label4: TLabel;
    KHType: TComboBox;
    FactoryName: TComboBox;
    TFP: TToolButton;
    cxTabControl1: TcxTabControl;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv2CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TFPClick(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure cxTabControl1Change(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fDParameters1:string;
    { Public declarations }
    RKFlag,FCYID:String;

  end;

var
  frmYFFKList: TfrmYFFKList;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp, U_YSSKList_KPFK;

{$R *.dfm}



procedure TfrmYFFKList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      Filtered:=False;
      sql.Add(' exec P_YFFK_List10 :begdate,:Enddate,:Flag,:FStatus') ;
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime));
      Parameters.ParamByName('Enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1));
      Parameters.ParamByName('Flag').Value:=Trim(fDParameters1);
      if cxTabControl1.TabIndex=0 then
      Parameters.ParamByName('FStatus').Value:='0';
      if cxTabControl1.TabIndex=1 then
      Parameters.ParamByName('FStatus').Value:='1';
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  //ToolButton2.Click;
end;


procedure TfrmYFFKList.FormDestroy(Sender: TObject);
begin
  frmYFFKList:=nil;
end;

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

procedure TfrmYFFKList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('应付付款统计1',Tv2,'财务管理');
  WriteCxGrid('应付付款统计2',Tv1,'财务管理');
  Close;
end;
procedure TfrmYFFKList.FormShow(Sender: TObject);
var fsj:string;
begin
  ReadCxGrid('应付付款统计1',Tv2,'财务管理');
  ReadCxGrid('应付付款统计2',Tv1,'财务管理');
  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
  begdate.DateTime:=Enddate.DateTime-7;
  fsj:='select distinct (A.FactoryName) name from YF_Money_CR A where A.CRType=''应付款登记'' ';
  SInitComBoxBySql(ADOQueryCmd,FactoryName,False,fsj);
  {  if Trim(DParameters5)='开票' then
  begin
    v2BQKP.Hidden:=False;
    v2BQKP.Visible:=True;
    v2WKP.Hidden:=False;
    v2WKP.Visible:=True;
  end else
  begin
    v2BQKP.Hidden:=True;
    v2BQKP.Visible:=False;
    v2WKP.Hidden:=True;
    v2WKP.Visible:=False;
  end;
  if Trim(DParameters9)='支付台头' then
  begin
    v2GSTT.Hidden:=False;
    v2GSTT.Visible:=True;
    Label1.Visible:=True;
    ComTaiTou.Visible:=True;
  end else
  begin
    v2GSTT.Hidden:=True;
    v2GSTT.Visible:=False;
    Label1.Visible:=False;
    ComTaiTou.Visible:=False;
  end;
}
  //InitGrid();
end;

procedure TfrmYFFKList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmYFFKList.ToolButton2Click(Sender: TObject);
var
  fsj:string;
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,Trim(SGetFilters(Panel1,1,2)));
  SCreateCDS20(ADOQueryMain,CDS_HZ);
  SInitCDSData20(ADOQueryMain,CDS_HZ);
end;

procedure TfrmYFFKList.FactoryNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYFFKList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv2,ADOQueryMain,'应付款付款统计列表');
end;

procedure TfrmYFFKList.Tv2CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_HZ.IsEmpty then exit;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select AA.* ');
      sql.add(' from (select A.*,cast(Money as decimal(18,2)) yfk,cast(0 as decimal(18,2)) fk,cast(0 as decimal(18,2)) yfkye');
      sql.Add(' from YF_Money_CR A');
      sql.Add(' where A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
      sql.Add(' and A.CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
      sql.Add(' and A.CRType=''应付款登记'' ');
      sql.Add(' and A.status=''2'' ');
      sql.add(' union all');
      sql.Add(' select  A.*,cast(0 as decimal(18,2)) yfk,cast(Money as decimal(18,2)) fk,cast(0 as decimal(18,2)) yfkye');
      sql.Add(' from YF_Money_CR A');
      sql.Add(' where A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
      sql.Add(' and A.CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
      sql.Add(' and A.CRType=''付款登记'' ');
      sql.Add(' and A.status=''2'' ) AA');
      sql.add(' where AA.FactoryName='''+trim(CDS_HZ.fieldbyname('FactoryName').AsString)+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryCmd,YForder_Sub);
    SInitCDSData20(ADOQueryCmd,YForder_Sub);
end;

procedure TfrmYFFKList.TFPClick(Sender: TObject);
begin
  frmYSSKList_KPFK:=TfrmYSSKList_KPFK.Create(self);
  with frmYSSKList_KPFK do
  begin
    frmYSSKList_KPFK.FFactoryName:=trim(self.CDS_HZ.fieldbyname('FactoryName').AsString);
    if showmodal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmYFFKList.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  TFP.Click;
end;

procedure TfrmYFFKList.cxTabControl1Change(Sender: TObject);
begin
  initgrid();
end;

end.
