⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ar_enter_saleinvoice2h.pas

📁 一个MRPII系统源代码版本
💻 PAS
字号:
unit Ar_Enter_SaleInvoice2H;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Entry_Head, Menus, Db, ActnList, AdODB, Grids, DBGridEh, StdCtrls,
  ExtCtrls, ComCtrls, ToolWin, jpeg, ExtPrintReport;

Type
  TFrm_Ar_Enter_SaleInvoice2H = Class(TFrm_Base_Entry_Head)
    AdoQry_HeadInvoiceNo: TStringField;
    AdoQry_HeadCreateDate: TDateTimeField;
    AdoQry_HeadCreateEmployeeCode: TStringField;
    AdoQry_HeadCustomerCode: TStringField;
    AdoQry_HeadCurrencyCode: TStringField;
    AdoQry_HeadExchangeRate: TFloatField;
    AdoQry_HeadSaleTermCode: TStringField;
    AdoQry_HeadTotalTaxAmount: TFloatField;
    AdoQry_HeadRemArk: TStringField;
    AdoQry_HeadCustomerName: TStringField;
    AdoQry_HeadCurrencyName: TStringField;
    AdoQry_HeadPayTermName: TStringField;
    AdoQry_HeadBank: TStringField;
    AdoQry_HeadBankActNo: TStringField;
    AdoQry_HeadEditDate: TDateTimeField;
    AdoQry_HeadEdItEmployeeCode: TStringField;
    AdoQry_HeadcreaterName: TStringField;
    AdoQry_HeadActive: TIntegerField;
    AdoQry_HeadTaxActNo: TStringField;
    AdoQry_HeadSaleTypeCode: TStringField;
    AdoQry_HeadSaleEmployeeCode: TStringField;
    AdoQry_HeadSaleDeptCode: TStringField;
    AdoQry_HeadDeptName: TStringField;
    AdoQry_HeadSaleEmployeeName: TStringField;
    AdoQry_HeadSaleTypeName: TStringField;
    AdoQry_HeadInvoiceNoId: TAutoIncField;
    AdoQry_HeadInvoiceType: TIntegerField;
    AdoQry_HeadBillType: TIntegerField;
    AdoQry_HeadOrderType: TIntegerField;
    AdoQry_HeadActSubjectCode: TStringField;
    AdoQry_HeadCancelAmount: TFloatField;
    AdoQry_HeadTaxRate: TFloatField;
    AdoQry_HeadTotalNoTaxAmount: TFloatField;
    AdoQry_HeadTotalTax: TFloatField;
    AdoQry_HeadTotalTaxAmountC: TFloatField;
    AdoQry_HeadTotalNoTaxAmountC: TFloatField;
    AdoQry_HeadTotalTaxC: TFloatField;
    AdoQry_HeadCancelAmountC: TFloatField;
    AdoQry_HeadBillDate: TDateTimeField;
    AdoQry_HeadISCredence: TIntegerField;
    AdoQry_HeadInAccountDate: TDateTimeField;
    procedure Act_NewExecute(Sender: TObject);
    procedure Act_ModifyExecute(Sender: TObject);
    procedure Act_LookExecute(Sender: TObject);
    procedure DBGridEhGetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
    procedure Act_CancelCheckExecute(Sender: TObject);
    procedure Act_DeleteExecute(Sender: TObject);
    procedure AdoQry_HeadAfterScroll(DataSet: TDataSet);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
  procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
    { Public declarations }
  end;

var
  Frm_Ar_Enter_SaleInvoice2H: TFrm_Ar_Enter_SaleInvoice2H;

implementation

uses //Sal_Enter_ShipOrder_C1, Sal_Enter_ShipOrder,
  Ar_Enter_SaleInvoice2_C1,
  Ar_Enter_SaleInvoice2,Sys_Global;

{$R *.DFM}


procedure TFrm_Ar_Enter_SaleInvoice2H.InitForm(AdOConnection: TAdOConnection;
  ReadOnly: Boolean);
begin
  Application.ProcessMessages;
  inherited;
  If (ReadOnly) Then
  begin
    Act_New.Enabled:=False;
    Act_New.Visible:=False;
    Act_Modify.Enabled:=False;
    Act_Modify.Visible:=False;
    act_Cancelcheck.Enabled:=False;
    act_Cancelcheck.Visible:=False;
    act_Delete.Enabled:=False;
    act_Delete.Visible:=False;
    Pnl_Title.Caption:='专用发票查询';
    Frm_Ar_Enter_SaleInvoice2H.Caption:='专用发票查询';
  end
  Else
  begin
    Act_New.Enabled:=False;
    Act_New.Visible:=False;
    Act_New.Enabled:=True;
    Act_New.Visible:=True;
    Pnl_Title.Caption:='专用发票';
    Frm_Ar_Enter_SaleInvoice2H.Caption:='专用发票';
  end;
  SelectFromSql:=' Select Sa_SaleInvoice.*,Customer.CustomerName,'
                +' Dept.DeptName, '
                +' Employee3.EmployeeName as SaleEmployeeName, '
                +' SaleType.SaleTypeName,  '
                +' Employee1.EmployeeName as createrName, '
                +' Currency.CurrencyName,PayTermName'
                +' From Sa_SaleInvoice '
                +' left join Dept '
                +'   on sa_SaleInvoice.SaleDeptCode=Dept.DeptCode '
                +' left join Employee Employee3 '
                +'   on sa_SaleInvoice.SaleEmployeeCode=Employee3.EmployeeCode '
                +' left join SaleType '
                +'   on sa_SaleInvoice.SaleTypeCode=SaleType.SaleTypeCode '
                +' left Join Customer '
                +'   On Sa_SaleInvoice.CustomerCode=Customer.CustomerCode '
                +' left Join Currency '
                +'   On Sa_SaleInvoice.CurrencyCode=Currency.CurrencyCode '
                +' left Join PayTerm '
                +'   On Sa_SaleInvoice.SaleTermCode=PayTermCode '
                +' left Join Employee Employee1'
                +'   On Sa_SaleInvoice.CreateEmployeeCode=Employee1.EmployeeCode ';
  ConditionUserDefine:=' Sa_SaleInvoice.InvoiceType=1 and OrderType=0';
  OrderByFields:=' CustomerCode,CreateDate,Invoiceno ';
  GetData;
  Lbl_Condition.Caption:='全部';//'开票日期>='+FormatDateTime('YYYY.MM.DD',strtodatetime(GetServerDateTime(dbconnect))-30);
end;

procedure TFrm_Ar_Enter_SaleInvoice2H.Act_NewExecute(Sender: TObject);
begin
  inherited;
    Frm_Ar_Enter_SaleInvoice2_C1:=TFrm_Ar_Enter_SaleInvoice2_C1.Create(Application);
    Frm_Ar_Enter_SaleInvoice2_C1.SetSysParam(UserCode,ModuleCode,MenuId,LoginDate);
    Frm_Ar_Enter_SaleInvoice2_C1.InitForm(DbConnect,False);
end;

procedure TFrm_Ar_Enter_SaleInvoice2H.Act_ModifyExecute(Sender: TObject);
begin
  inherited;
  if AdoQry_Head.RecordCount=0 then exit;
  if AdoQry_Head.fieldbyname('active').asinteger=0 then exit;
  Frm_Ar_Enter_SaleInvoice2:=TFrm_Ar_Enter_SaleInvoice2.Create(Application);
  Frm_Ar_Enter_SaleInvoice2.SetSysParam(UserCode,ModuleCode,MenuId,LoginDate);
  Frm_Ar_Enter_SaleInvoice2.InitForm(DbConnect,'Edit',AdoQry_Head);
  Frm_Ar_Enter_SaleInvoice2.ShowModal;
  if Frm_Ar_Enter_SaleInvoice2<>nil then
    Frm_Ar_Enter_SaleInvoice2.Close;
end;

procedure TFrm_Ar_Enter_SaleInvoice2H.Act_LookExecute(Sender: TObject);
begin
  inherited;
  if AdoQry_Head.RecordCount=0 then exit;
   Frm_Ar_Enter_SaleInvoice2:=TFrm_Ar_Enter_SaleInvoice2.Create(Application);
  Frm_Ar_Enter_SaleInvoice2.SetSysParam(UserCode,ModuleCode,MenuId,LoginDate);
  Frm_Ar_Enter_SaleInvoice2.InitForm(DbConnect,'Query',AdoQry_Head);
  Frm_Ar_Enter_SaleInvoice2.ShowModal;
  if Frm_Ar_Enter_SaleInvoice2<>nil then
    Frm_Ar_Enter_SaleInvoice2.Close;
end;

procedure TFrm_Ar_Enter_SaleInvoice2H.DBGridEhGetCellParams(
  Sender: TObject; Column: TColumnEh; AFont: TFont; var Background: TColor;
  State: TGridDrawState);
begin
  inherited;
  if AdoQry_Head.RecordCount=0 then exit;
  if AdoQry_Head.fieldbyname('active').asinteger=0 then
   begin
     afont.Color:=clred;
   end;
end;

procedure TFrm_Ar_Enter_SaleInvoice2H.Act_CancelCheckExecute(
  Sender: TObject);
var sqltext:string;
begin
  inherited;
  if AdoQry_Head.RecordCount=0 then exit;
  if AdoQry_Head.fieldbyname('active').asinteger=0 then exit;
  if DispInfo('确认要作废这张专用发票吗?',2)<>'y' then exit;
  sqltext:='select active from  sa_SaleInvoice'
          +'  where Invoiceno='+quotedstr(AdoQry_Head.fieldbyname('Invoiceno').asstring);
  Executesql(AdoQry_tmp,sqltext,0);
  if AdoQry_tmp.RecordCount=0 then
    begin
      DispInfo('这张发票已被别人删除,请刷新!',1);
      abort;
    end;
  try
    dbconnect.beginTrans;
    saveSalInvoiceHistory(dbconnect,AdoQry_Head.fieldbyname('Invoiceno').asstring,userCode,9);
    sqltext:='update sa_SaleInvoice'
            +'  set active=0 '
            +'  where Invoiceno='+quotedstr(AdoQry_Head.fieldbyname('Invoiceno').asstring);
    Executesql(AdoQry_tmp,sqltext,1);
    Executesql(AdoQry_tmp,'update sa_ShipOrder '
                         +' set Invoiceno='+quotedstr('')
                         +' where Shipno in (select distinct Shipno from sa_SaleInvoiceline where Invoiceno='+quotedstr(AdoQry_Head.fieldbyname('Invoiceno').asstring)+')',1);
    AdoQry_Head.Edit;
    AdoQry_Head.fieldbyname('active').asinteger:=0;
    AdoQry_Head.Post;
    dbconnect.CommitTrans;
  except
    if dbconnect.InTransaction then dbconnect.RollBackTrans;
    DispInfo('操作失败,发票'+AdoQry_Head.fieldbyname('Invoiceno').asstring+'没有作废!',1);
    abort;
  end;
  tlbtn_Delete.Action:=act_Delete;
end;


procedure TFrm_Ar_Enter_SaleInvoice2H.Act_DeleteExecute(Sender: TObject);
var sqltext:string;
    TmpAdoQry : TAdoQuery;
begin
  inherited;
  if AdoQry_Head.RecordCount=0 then exit;
  if DispInfo('确认要删除这张专用发票吗?',2)<>'y' then exit;
  If AdoQry_Head.fieldbyname('ISCredence').AsInteger = 1 then
  begin
    DispInfo('已做凭证处理,不能删除!',3);
    Exit;
  end;  
  TmpAdoQry := TAdoQuery.Create(self);
  TmpAdoQry.Connection := Dbconnect;
  TmpAdoQry.EnableBCD := False;
  SqlText := 'Select distinct InvBillId from Sa_SaleInvoiceLine '
            +' where InvoiceNo='+QuotedStr(AdoQry_Head.fieldbyname('InvoiceNO').AsString);
  ExecuteSQl(TmpAdoQry,SqlText,0)  ;
  Try
    dbconnect.beginTrans;
    While Not TmpAdoQry.Eof do
    begin
      SQlText := 'Update InvOutBill '
                +'   set InvoiceNo = '''' '
                +' Where InvBillId='+TmpAdoQry.fieldbyname('InvBillId').AsString;
      ExecuteSql(AdoQry_Tmp,SqlText,1);
      TmpAdoQry.next;
    end;
    saveSalInvoiceHistory(dbconnect,AdoQry_Head.fieldbyname('Invoiceno').asstring,userCode,2);
    SqlText := 'select * from Sa_SaleInvoiceLine '
              +' where InvoiceNo='+QuotedStr(AdoQry_Head.fieldbyname('InvoiceNo').AsString);
    ExecuteSql(TmpAdoQry,SqlText,0);
    While Not TmpAdoQry.Eof do
    begin
      SaveSalInvoiceLineHistory(dbconnect,AdoQry_Head.fieldbyname('InvoiceNo').AsString,
                                          TmpAdoQry.fieldbyname('InvBillId').AsInteger,
                                          TmpAdoQry.fieldbyname('InvBillLineNo').AsString,
                                          userCode,
                                          2);
      TmpAdoQry.Next;                                          
    end;
    SqlText := ' Delete From Sa_SaleInvoiceLine '
              +'  where InvoiceNo='+QuotedStr(AdoQry_Head.fieldbyname('InvoiceNo').AsString)
              +' Delete from Sa_SaleInvoice '
              +'  where InvoiceNo='+QuotedStr(AdoQry_Head.fieldbyname('InvoiceNo').AsString);
    ExecuteSql(AdoQry_Tmp,SqlText,1);
    TmpAdoQry.Free;
    dbconnect.CommitTrans;
    AdoQry_Head.Delete;
  Except 
    If dbconnect.InTransaction then dbconnect.RollBackTrans;
    If Assigned(TmpAdoQry) then TmpAdoQry.Free;
    DispInfo('删除失败,可能数据已被引用!',3);
    Abort;
  end;
{  if AdoQry_Head.RecordCount=0 then exit;
  if AdoQry_Head.fieldbyname('active').asinteger=1 then exit;
  if DispInfo('确认要弃废这张专用发票吗?',2)<>'y' then exit;
  sqltext:='select active from  sa_SaleInvoice'
          +'  where Invoiceno='+quotedstr(AdoQry_Head.fieldbyname('Invoiceno').asstring);
  Executesql(AdoQry_tmp,sqltext,0);
  if AdoQry_tmp.RecordCount=0 then
    begin
    DispInfo('这张发票已被别人删除,请刷新!',1);
    abort;
    end;
  Executesql(AdoQry_tmp,' select InvBillId from InvOutBill '
                       +' where InvBillId in (select distinct InvBillId from sa_SaleInvoiceline where Invoiceno='
                                              +quotedstr(AdoQry_Head.fieldbyname('Invoiceno').asstring)+')'
                       +'  and  Invoiceno<>'+quotedstr(''),0                                            );
  if AdoQry_tmp.RecordCount>0 then
   begin
    DispInfo('发票'+AdoQry_Head.fieldbyname('Invoiceno').asstring+'对应的销售发货单已有开票,不能弃废!',1);
    abort;
   end;
  try
    dbconnect.beginTrans;
    saveSalInvoiceHistory(dbconnect,AdoQry_Head.fieldbyname('Invoiceno').asstring,userCode,10);
    sqltext:='update sa_SaleInvoice'
            +'  set active=1 '
            +'  where Invoiceno='+quotedstr(AdoQry_Head.fieldbyname('Invoiceno').asstring);
    Executesql(AdoQry_tmp,sqltext,1);
    Executesql(AdoQry_tmp,'update InvOutBill '
                         +' set Invoiceno='+quotedstr(AdoQry_Head.fieldbyname('Invoiceno').asstring)
                         +' where InvBillId in (select distinct InvBillId from sa_SaleInvoiceline where Invoiceno='+quotedstr(AdoQry_Head.fieldbyname('Invoiceno').asstring)+')',1);
    AdoQry_Head.Edit;
    AdoQry_Head.fieldbyname('active').asinteger:=1;
    AdoQry_Head.Post;
    dbconnect.CommitTrans;
  except
    if dbconnect.InTransaction then dbconnect.RollBackTrans;
      DispInfo('操作失败,发票'+AdoQry_Head.fieldbyname('Invoiceno').asstring+'没有弃废!',1);
      abort;
  end;
  tlbtn_Delete.Action:=act_Cancelcheck;
}
end;


procedure TFrm_Ar_Enter_SaleInvoice2H.AdoQry_HeadAfterScroll(
  DataSet: TDataSet);
begin
  inherited;
{  if AdoQry_Head.RecordCount=0 then exit;
  if AdoQry_Head.fieldbyname('active').asinteger=0 then
    tlbtn_Delete.Action:=act_Delete
  else
    tlbtn_Delete.Action:=act_Cancelcheck;
}
end;

procedure TFrm_Ar_Enter_SaleInvoice2H.FormCreate(Sender: TObject);
begin
  inherited;
//  tlbtn_Delete.Action:=act_Cancelcheck;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -