unit U_FdInviceList;

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, cxDropDownEdit, cxPC, RM_e_Xls, Menus;

type
  TfrmFdInviceList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    Tfind: TToolButton;
    Label1: TLabel;
    P_CodeName: TEdit;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    InvoiceNo: TEdit;
    Label2: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_FP: TDataSource;
    CDS_FP: TClientDataSet;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Label4: TLabel;
    P_Spec: TEdit;
    Label5: TLabel;
    FactoryName: TEdit;
    cxTabControl1: TcxTabControl;
    ToolButton3: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    RMXLSExport1: TRMXLSExport;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    Label9: TLabel;
    ToFactoryName: TEdit;
    V2Column1: TcxGridDBColumn;
    V2Column2: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    V2Column5: TcxGridDBColumn;
    V2Column6: TcxGridDBColumn;
    V2Column7: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TfindClick(Sender: TObject);
    procedure InvoiceNoChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
  private
    { Private declarations }
    canshu1,canshu2:string;
    procedure InitGrid();
    procedure SetStatus();
  public
    fInvoiceFlag:string;
    { Public declarations }
  end;

var
  frmFdInviceList: TfrmFdInviceList;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp, U_FDINVOICE_Sub_X, U_FjList10;

{$R *.dfm}

procedure TfrmFdInviceList.SetStatus();
begin
 
end;

procedure TfrmFdInviceList.InitGrid();
begin
  try
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.* ,B.*');
      sql.Add(' ,P_CodeName=cast((select distinct '',''+P_CodeName  from FD_Invoicesub X where X.invoiceNo=A.invoiceNo for xml path('''')) as varchar(80))');
      sql.Add(' ,P_Spec=cast((select distinct '',''+P_Spec  from FD_Invoicesub X where X.invoiceNo=A.invoiceNo for xml path('''')) as varchar(80))');
      sql.Add(' ,isfj=cast(case when isnull((select count(WBID) from TP_File X where X.WBID=A.invoiceNo and X.TFType=''发票''),0)>0 then 1 else 0 end as bit) ');
      sql.Add(' from FD_Invoice A  ');
      sql.Add(' left join FD_Invoicesub B on A.InvoiceNo=B.InvoiceNo');
      sql.add(' where A.InvoiceDate>='''+formatdatetime('yyyy-MM-dd',begdate.datetime)+''' ');
      sql.Add(' and A.InvoiceDate<'''+formatdateTime('yyyy-MM-dd',enddate.DateTime+1)+''' ');
      sql.Add(' and InvoiceFlag='''+fInvoiceFlag+''' ');
      if cxTabControl1.TabIndex=0 then
      sql.add(' and A.Chkstatus=''0''');
      if cxTabControl1.TabIndex=1 then
      sql.add(' and A.Chkstatus=''1''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_FP);
    SInitCDSData20(ADOQueryMain,CDS_FP);
  finally
 
  end;
  Tfind.Click;
end;


procedure TfrmFdInviceList.FormDestroy(Sender: TObject);
begin
  frmFdInviceList:=nil;
end;

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

procedure TfrmFdInviceList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption,Tv1,'财务管理');
  Close;
end;
procedure TfrmFdInviceList.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption,Tv1,'财务管理');
  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
  begdate.DateTime:=Enddate.DateTime-30;
  
  SetStatus();
  InitGrid();
end;

procedure TfrmFdInviceList.TBRafreshClick(Sender: TObject);
begin
  begdate.SetFocus;
  InitGrid();
end;

procedure TfrmFdInviceList.TfindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_FP);
    SInitCDSData20(ADOQueryMain,CDS_FP);
  end;
end;

procedure TfrmFdInviceList.InvoiceNoChange(Sender: TObject);
begin
  Tfind.Click;
end;

procedure TfrmFdInviceList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  initGrid();
end;

procedure TfrmFdInviceList.ToolButton3Click(Sender: TObject);
begin
  if CDS_FP.IsEmpty then Exit;
  try
    frmFjList10:=TfrmFjList10.Create(Application);
    with frmFjList10 do
    begin
    //  PState:=1;
   //   if Trim(canshu1)<>'高权限'  then cxButton1.Visible:=false;
      fkeyNO:=Trim(Self.CDS_FP.fieldbyname('InvoiceNo').AsString);
      fType:='发票';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmFjList10.Free;
  end;
end;

procedure TfrmFdInviceList.FormCreate(Sender: TObject);
begin
  canshu1:=trim(DParameters1);
end;

procedure TfrmFdInviceList.N1Click(Sender: TObject);
begin
  CDS_FP.DisableControls;
  while CDS_FP.Locate('SSel',False,[]) do
  begin
      CDS_FP.Edit;
      CDS_FP.FieldByName('SSel').Value:=True;
      CDS_FP.Post;
  end;
  CDS_FP.EnableControls
end;

procedure TfrmFdInviceList.N2Click(Sender: TObject);
begin
  CDS_FP.DisableControls;
  while CDS_FP.Locate('SSel',True,[]) do
  begin
      CDS_FP.Edit;
      CDS_FP.FieldByName('SSel').Value:=False;
      CDS_FP.Post;
  end;
  CDS_FP.EnableControls
end;

end.
