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

📄 ar_enter_noinvoiceshiporder_d.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
unit Ar_Enter_NoInvoiceShipOrder_D;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Detail, Db, AdODB, ExtCtrls, StdCtrls, ExtEdit, Mask, linkedit;

Type
  TFrm_Ar_Enter_NoInvoiceShipOrder_D = Class(TFrm_Base_Detail)
    Label4: TLabel;
    medt_InvBillDate: TMaskEdit;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    edt_rate: TEdit;
    Label8: TLabel;
    edt_InvBillNo: TEdit;
    Label11: TLabel;
    Edt_InvBillAmount: TEdit;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    medt_Createdate: TMaskEdit;
    Label16: TLabel;
    edt_remArk: TEdit;
    edt_CustomerName: TEdit;
    edt_CurrencyName: TEdit;
    edt_DeptName: TEdit;
    edt_SaleEmployeeName: TEdit;
    edt_CreateEmployeeName: TEdit;
    edt_CustomerCode: TLinkEdit;
    edt_CurrencyCode: TLinkEdit;
    edt_DeptCode: TLinkEdit;
    edt_SaleEmployeeCode: TLinkEdit;
    edt_CreateEmployeeCode: TLinkEdit;
    Label1: TLabel;
    Medt_InvBillMonth: TMaskEdit;
    Label17: TLabel;
    Edt_WhCode: TLinkEdit;
    Edt_WhName: TEdit;
    Label18: TLabel;
    Edt_WhPositionCode: TLinkEdit;
    Edt_WhPositionName: TEdit;
    Label19: TLabel;
    Edt_SaleTypeName: TEdit;
    Edt_SaleTypeCode: TLinkEdit;
    Label20: TLabel;
    Edt_ShipAddressName: TEdit;
    Edt_ShipAddresSCode: TLinkEdit;
    Label21: TLabel;
    Edt_ShipModeName: TEdit;
    Edt_ShipModeCode: TLinkEdit;
    Label22: TLabel;
    Edt_PayTermName: TEdit;
    Edt_PayTermCode: TLinkEdit;
    Label2: TLabel;
    Edt_InvBillNoTaxAmount: TEdit;
    Label3: TLabel;
    Edt_InvBillAmountC: TEdit;
    Label9: TLabel;
    Edt_InvBillNoTaxAmountC: TEdit;
    Label10: TLabel;
    Edt_RemArk1: TEdit;
    Label23: TLabel;
    Edt_RemArk2: TEdit;
    procedure edt_BtCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edt_SaleEmployeeCodeExit(Sender: TObject);
    procedure edt_CreateEmployeeCodeExit(Sender: TObject);
    procedure edt_DeptCodeExit(Sender: TObject);
    procedure edt_CustomerCodeExit(Sender: TObject);
    procedure edt_BtCodeExit(Sender: TObject);
    procedure edt_CurrencyCodeExit(Sender: TObject);
    procedure edt_BtCodeButtonClick(Sender: TObject);
    procedure edt_BtCodeChange(Sender: TObject);
    procedure Edt_WhCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edt_WhCodeExit(Sender: TObject);
    procedure Edt_WhCodeButtonClick(Sender: TObject);
    procedure Edt_WhPositionCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edt_WhPositionCodeExit(Sender: TObject);
    procedure Edt_WhPositionCodeButtonClick(Sender: TObject);
    procedure Edt_SaleTypeCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edt_SaleTypeCodeButtonClick(Sender: TObject);
    procedure Edt_SaleTypeCodeExit(Sender: TObject);
    procedure Edt_ShipAddresSCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edt_ShipAddresSCodeButtonClick(Sender: TObject);
    procedure Edt_ShipAddresSCodeExit(Sender: TObject);
    procedure Edt_PayTermCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edt_PayTermCodeExit(Sender: TObject);
    procedure Edt_ShipModeCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edt_ShipModeCodeExit(Sender: TObject);
    procedure Edt_PayTermCodeButtonClick(Sender: TObject);
    procedure Edt_ShipModeCodeButtonClick(Sender: TObject);
    procedure Edt_InvBillNoTaxAmountExit(Sender: TObject);
    procedure Edt_InvBillNoTaxAmountCExit(Sender: TObject);
    procedure btn_okClick(Sender: TObject);
    procedure medt_InvBillDateExit(Sender: TObject);
  private
    { Private declarations }
  public
    TmpAmount:String;
    ExchRate : Double;
    procedure InitControls; Override;
    procedure SaveData;Override;
    procedure SetStatus(CurrentStatus:String;var EnableControls:String); Override;
    function  getCancelmode(customerCode:string):integer;
    function  getreMainAmount(Gatheringno:string):double;
    procedure CancelGathering(Gatheringno:string);
    function  existsArgatherline(Gatheringno,Billno:string):boolean;
    { Public declarations }
  end;

var
  Frm_Ar_Enter_NoInvoiceShipOrder_D: TFrm_Ar_Enter_NoInvoiceShipOrder_D;

implementation
uses Sys_Global;
{$R *.DFM}

{ TFrm_Ar_Enter_Gathering_D }
function  TFrm_Ar_Enter_NoInvoiceShipOrder_D.existsArgatherline(Gatheringno,Billno:string):boolean;
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  Result:=False;
  AdoQry:=TAdoQuery.Create(nil);
  AdoQry.Connection:=dbconnect;
  try
    sqltext:='select Gatheringno from Ar_Gatheringline '
            +' where Gatheringno='+quotedstr(Gatheringno)
            +'   and Billno='+quotedstr(Billno);
    Executesql(AdoQry,sqltext,0)          ;
    if not AdoQry.Eof then 
      Result:=True;
  finally
    AdoQry.Free;
  end;
end;


procedure TFrm_Ar_Enter_NoInvoiceShipOrder_D.CancelGathering(Gatheringno:string);
var AdoQry:TAdoQuery;
    sqltext:string;
    TotalreMainAmount:double; {收款单据总余额}
    thiSCancelAmount:double;{此次核销金额}
begin
  TotalreMainAmount:=-1;
  thiSCancelAmount:=0;
  AdoQry:=TAdoQuery.Create(nil);
  AdoQry.Connection:=dbconnect;
  AdoQry.EnableBCD:=False;
  try
    TotalreMainAmount:=getreMainAmount(Gatheringno);{获得当前收款票据的余额}
    if TotalreMainAmount<=0 then exit;
    sqltext:=' select  sa_SaleInvoice.Invoiceno, sa_SaleInvoice.SaleDeptCode,'
             +'        sa_SaleInvoice.SaleEmployeeCode, '
             +'        sa_SaleInvoice.Billdate,      '
             +'        sa_SaleInvoice.TotaltaxAmount, '
             +'        sa_SaleInvoice.TotaltaxAmount-sa_SaleInvoice.CancelAmount as reMainAmount'
             +'  from  sa_SaleInvoice '
             +' where  isnull(sa_SaleInvoice.CancelAmount,0)<TotaltaxAmount '
             +'   and  customerCode='+quotedstr(edt_CustomerCode.text)
             +'   and  active=1 ';
    Executesql(AdoQry,sqltext,0); {获得当前客户的未全核销的销售发票}
    while (not AdoQry.Eof) and (TotalreMainAmount>0)  do
      begin
        thiSCancelAmount:=AdoQry.fieldbyname('reMainAmount').asfloat;
        if AdoQry.fieldbyname('reMainAmount').asfloat>=TotalreMainAmount then
        thiSCancelAmount:=TotalreMainAmount;
        {thiSCancelAmount为此次核销金额}
//        sqltext:='select * from Ar_gather'
        if existsArgatherline(Gatheringno,AdoQry.fieldbyname('Invoiceno').asstring) then
          //判断在收款票据表体中是否存在该销售发票的记录
          begin
            sqltext:='update Ar_Gatheringline'
                    +'   set thiSCancelAmount=thiSCancelAmount+'+floattostr(thiSCancelAmount)
                    +' where Gatheringno='+quotedstr(Gatheringno)
                    +'   and Billno='+quotedstr(AdoQry.fieldbyname('Invoiceno').asstring);
            Executesql(AdoQry_tmp,sqltext,1)                    ;
          end
        else 
          begin
            sqltext:='insert into Ar_Gatheringline(Gatheringno,Billno,SaleDeptCode,SaleEmployeeCode,Billdate,TotalAmount,reMainTotalAmount,thiSCancelAmount)'
                    +' Values('+quotedstr(Gatheringno)+','
                               +quotedstr(AdoQry.fieldbyname('Invoiceno').asstring)+','
                               +quotedstr(AdoQry.fieldbyname('SaleDeptCode').asstring)+','
                               +quotedstr(AdoQry.fieldbyname('SaleEmployeeCode').asstring)+','
                               +quotedstr(AdoQry.fieldbyname('Billdate').asstring)+','
                               +floattostr(AdoQry.fieldbyname('TotaltaxAmount').asfloat)+','
                               +floattostr(AdoQry.fieldbyname('reMainAmount').asfloat)+','
                               +floattostr(thiSCancelAmount)+')';
            Executesql(AdoQry_tmp,sqltext,1);{插入记录到收款票据表体}
          end;
        sqltext:='update sa_SaleInvoice'
                +' set CancelAmount=isnull(CancelAmount,0)+'+floattostr(thiSCancelAmount)
                +' where Invoiceno='+quotedstr(AdoQry.fieldbyname('Invoiceno').asstring);
        Executesql(AdoQry_tmp,sqltext,1); {累加销售发票的核销金额}

        sqltext:='update Ar_Gathering '
                +' set TotalCancelAmount=TotalCancelAmount+'+floattostr(thiSCancelAmount)
                +' where Gatheringno='+quotedstr(Gatheringno);
        Executesql(AdoQry_tmp,sqltext,1);{累加收款票据的总核销金额}
        
        TotalreMainAmount:=TotalreMainAmount-thiSCancelAmount;{扣减总余额数}
        AdoQry.Next;
      end;
  finally
    AdoQry.Free;
  end;
end;

function  TFrm_Ar_Enter_NoInvoiceShipOrder_D.getreMainAmount(Gatheringno:string):double;
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  Result:=-1;
  AdoQry:=TAdoQuery.Create(nil);
  AdoQry.Connection:=dbconnect;
  try
    sqltext:='select TotaltaxAmount-isnull(TotalCancelAmount,0) as reMainAmount from Ar_Gathering '
            +' where Gatheringno='+quotedstr(Gatheringno);
    Executesql(AdoQry,sqltext,0)          ;
    if not AdoQry.Eof then 
      Result:=AdoQry.fieldbyname('reMainAmount').asfloat;
  finally
    AdoQry.Free;
  end;
end;

function TFrm_Ar_Enter_NoInvoiceShipOrder_D.getCancelmode(customerCode:string):integer;
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  Result:=-1;
  AdoQry:=TAdoQuery.Create(nil);
  AdoQry.Connection:=dbconnect;
  try
    sqltext:='select SalInvoiceCancelmode from customer '
            +' where customerCode='+quotedstr(customerCode);
    Executesql(AdoQry,sqltext,0)          ;
    if not AdoQry.Eof then 
      Result:=AdoQry.fieldbyname('SalInvoiceCancelmode').asinteger;
  finally
    AdoQry.Free;
  end;
end;

procedure TFrm_Ar_Enter_NoInvoiceShipOrder_D.InitControls;
var i:integer;
begin
  inherited;
  if (Add) then
    begin
  //    SetFocus_Control:=Edt_CustomerCode;
      medt_InvBilldate.Text:=formatdatetime('yyyy.mm.dd',strtodatetime(GetServerDateTime(dbconnect)));
      MEdt_InvBillMonth.Text := Copy(Medt_InvBillDate.Text,1,7);
      medt_Createdate.Text:=medt_InvBilldate.Text;
      edt_CustomerCode.Enabled:=True;
      edt_InvBillno.Enabled:=True;
      edt_CreateEmployeeCode.Text:=userCode;
      if  (CheckAllTypeOrderNoSet(DbConnect,3)) then
      Edt_InvBillNo.Text := GetAllTypeOrderNo(DbConnect,3); {自动获得单据号}
      with AdoQry_Tmp do
      begin
        Close;
        SQL.clear;
        SQL.Add('Select EmployeeCode,EmployeeName From Employee Where EmployeeCode='''+userCode+'''');
        Open;
        edt_CreateEmployeeName.Text:=fieldbyname('EmployeeName').asstring;
      end;
    end
  else
    begin
 //     SetFocus_Control:=edt_CurrencyCode;
    end;
  with AdoQry_Maintain do
    begin
      if not Add then 
      edt_InvBillno.Text:=AdoQry_Maintain.fieldbyname('InvBillno').asstring;
      edt_CustomerCode.Text:=fieldbyname('customerCode').asstring;
      edt_CustomerName.Text:=fieldbyname('customerName').asstring;
      edt_CurrencyCode.Text:=fieldbyname('currencyCode').asstring;
      edt_CurrencyName.Text:=fieldbyname('currencyName').asstring;
      Edt_WhCode.Text := fieldbyname('WhCode').AsString;
      Edt_WhName.Text := fieldbyname('WhName').AsString;
      Edt_WhPositionCode.Text := fieldbyname('WhPositionCode').AsString;
      Edt_WhPositionName.Text := fieldbyname('WhPositionName').AsString;
      edt_DeptCode.Text:=fieldbyname('DeptCode').asstring;
      edt_DeptName.text:=fieldbyname('DeptName').asstring;
      Edt_SaleTypeCode.Text := fieldbyname('SaleType').AsString;
      Edt_SaleTypeName.Text := fieldbyname('SaleTypeName').AsString;
      Edt_ShipAddresSCode.Text := fieldbyname('ShipAddresSCode').AsString;
      Edt_ShipAddressName.Text := fieldbyname('ShipAddressName').AsString;
      Edt_ShipModeCode.Text := fieldbyname('ShipModeCode').AsString;
      Edt_ShipModeName.Text := fieldbyname('ShipModeName').AsString;
      Edt_PayTermCode.Text := fieldbyname('PayTermCode').AsString;
      Edt_PayTermName.Text := fieldbyname('PayTermName').AsString;
      edt_SaleEmployeeCode.Text:=fieldbyname('SaleEmployeeCode').asstring;
      edt_SaleEmployeeName.text:=fieldbyname('EmployeeName').asstring;
      if status<>'Add' then 
      begin
        edt_CreateEmployeeCode.Text:=fieldbyname('Sal_EmployeeCode').asstring;
        edt_CreateEmployeeName.text:=fieldbyname('createEmployeeName').asstring;
        medt_Createdate.Text:=AdoQry_Maintain.fieldbyname('InvBillcreateTime').asstring;
        medt_InvBilldate.Text := AdoQry_Maintain.fieldbyname('InvBilldate').asstring;
        MEdt_InvBillMonth.Text := AdoQry_Maintain.fieldbyname('InvBillMonth').AsString;         
        
      end;
      edt_rate.Text:=AdoQry_Maintain.fieldbyname('InvBillTaxRate').asString;
      edt_InvBillAmount.Text:=floattostr(AdoQry_Maintain.fieldbyname('TotalInvBillAmount').asfloat);
      edt_InvBillAmountC.Text:=floattostr(AdoQry_Maintain.fieldbyname('TotalInvBillAmountC').asfloat);
      edt_InvBillNoTaxAmount.Text:=floattostr(AdoQry_Maintain.fieldbyname('TotalInvBillNoTaxAmount').asfloat);
      edt_InvBillNoTaxAmountC.Text:=floattostr(AdoQry_Maintain.fieldbyname('TotalInvBillNoTaxAmountC').asfloat);
      edt_remArk.Text:=AdoQry_Maintain.fieldbyname('InvBillRemArk').asstring;    
      if Add then 
      Edt_RemArk.Text := '系统初始化';
      edt_remArk1.Text:=AdoQry_Maintain.fieldbyname('RemArk').asstring;    
      edt_remArk2.Text:=AdoQry_Maintain.fieldbyname('RemArk1').asstring;    
      
      if not Add then
      begin
        edt_InvBillNo.Enabled:=False;
        medt_Createdate.Enabled:=False;
        medt_InvBilldate.Enabled:=False;
//        edt_CustomerCode.Enabled:=False;
      end;
      medt_Createdate.Enabled:=False;
      edt_CreateEmployeeCode.Enabled:=False;
    end;

end;

procedure TFrm_Ar_Enter_NoInvoiceShipOrder_D.SaveData;
var sqltext:string;
    AdoQry:TAdoQuery;
begin
  inherited;
  AdoQry:=TAdoQuery.Create(nil);
  AdoQry.Connection:=dbconnect;

⌨️ 快捷键说明

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