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

📄 gl_enter_monthcheck.pas

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

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Dialog, Db, AdODB, StdCtrls, Mask,variants;

Type
  TFrm_Gl_Enter_MonthCheck = Class(TFrm_Base_Dialog)
    Medt_LastMonth: TMaskEdit;
    MEdt_ThisMonth: TMaskEdit;
    Label1: TLabel;
    Label2: TLabel;
    Btn_CancelMonthCheck: TButton;
    procedure btn_CancelClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure btn_okClick(Sender: TObject);
    procedure Btn_CancelMonthCheckClick(Sender: TObject);
  private
    { Private declarations }
  public
    Function ExistsNoATCredence(Month:String ; ATFlag : Integer):Boolean;
     //判断当月是否有没审核或过帐的凭证,AtFlag : 0 :审核标志 1:过帐标志
    Function ISallCredenced(Month:String;SType:Integer):Boolean; 
    {判断所有业务是否已生成凭证 sType :业务类型
     0 : 库存业务 1 :应收业务
     2 :应付业务 3 :固定资产业务
    }
    Function MonthSum(Month:String):Boolean; //月结处理
    Function CancelMonthSum(Month:String):Boolean; //取消月结
    { Public declarations }
  end;

var
  Frm_Gl_Enter_MonthCheck: TFrm_Gl_Enter_MonthCheck;

implementation
uses Sys_Global;
{$R *.DFM}

procedure TFrm_Gl_Enter_MonthCheck.btn_CancelClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TFrm_Gl_Enter_MonthCheck.FormActivate(Sender: TObject);
var yy,mm,dd : Word;
begin
  inherited;
  ExecuteSql(AdoQry_Tmp,' select * from Gl_AccountPeriod',0 );
  If AdoQry_Tmp.Locate('CurrentPeriod',1,[]) then 
  begin
    yy := AdoQry_tmp.fieldbyname('AccountPeriodYear').AsInteger;
    mm := AdoQry_Tmp.fieldbyname('AccountPeriodMonth').AsInteger;
    dd := 1;
    MEdt_ThisMonth.Text := FormatDateTime('yyyy.mm',EnCodeDate(yy,mm,dd));
    DeCodeDate(IncMonth(EnCodeDate(yy,mm,dd),-1),yy,mm,dd);
    If AdoQry_Tmp.Locate('AccountPeriodYear;AccountPeriodMonth',varArrayOf([yy,mm]),[])  then
    begin
      yy := AdoQry_tmp.fieldbyname('AccountPeriodYear').AsInteger;
      mm := AdoQry_Tmp.fieldbyname('AccountPeriodMonth').AsInteger;
      dd := 1;
      MEdt_LastMonth.Text := FormatDateTime('yyyy.mm',EnCodeDate(yy,mm,dd));
    end;    
  end;
end;

procedure TFrm_Gl_Enter_MonthCheck.btn_okClick(Sender: TObject);
var Month : String;
    NextMonth : String;
begin
  inherited;
  Month := MEdt_ThisMonth.Text ;
  If DispInfo('确认要月结吗?',2)<>'y' then Exit;
  NextMonth := FormatDateTime('yyyy.mm',IncMonth(StrToDateTime(Month+'.01'),1));  
  ExecuteSQl(AdoQry_Tmp,'select FCurrecy from Gl_AccountSubject '
                      +'  join Currency on Gl_AccountSubject.FCurrecy=Currency.CurrencyCode '
                      +'   and Currency.IsMaster=0 '
                      +'  where Not Exists(select ExchMonth from ExchRate '
                      +'                    where Gl_AccountSubject.FCurrecy=ExchRate.CurrencyCode '
                      +'                      and Convert(int,SubString(ExchRate.ExchMonth,1,4))='+Copy(NextMonth,1,4)
                      +'                      and Convert(int,SubString(ExchRate.ExchMonth,6,2))='+Copy(NextMonth,6,2) +')'
                      ,0);
  If AdoQry_Tmp.RecordCount>0 then 
  begin
    DispInfo('货币'+AdoQry_Tmp.fieldbyname('FCurrecy').AsString+'无'+NextMonth+'月份的汇率!',1);
    Abort;    
  end;                      
  
  If ExistsNoAtCredence(Month,0) then 
  begin
    DispInfo(Month+'月还有没审核的凭证,不能月结!',3);
    Abort;
  end;
  If ExistsNoAtCredence(Month,1) then 
  begin
    DispInfo(Month+'月还有没过帐的凭证,不能月结!',3);
    Abort;
  end;
  If Not ISallCredenced(Month,0) then 
  begin
    if DispInfo('库存业务未全生成记账凭证,是否继续月结?',2)<>'y' then 
    Abort;
  end;
  If Not ISallCredenced(Month,1) then 
  begin
    if DispInfo('应收业务未全生成记账凭证,是否继续月结?',2)<>'y' then 
    Abort;
  end;
  If Not ISallCredenced(Month,2) then 
  begin
    if DispInfo('应付业务未全生成记账凭证,是否继续月结?',2)<>'y' then 
    Abort;
  end;
  If Not ISallCredenced(Month,3) then 
  begin
    if DispInfo('固定资产业务未全生成记账凭证,是否继续月结?',2)<>'y' then 
    Abort;
  end;
  If MonthSum(Month) then 
  begin
    DispInfo('月结完毕!',3);
    btn_Ok.Enabled := False;
    Abort;
  end
  else  begin
    DispInfo('月结失败,请重试!',1);
    Abort;
  end;
  
  
end;

function TFrm_Gl_Enter_MonthCheck.ExistsNoATCredence(Month: String;
  ATFlag: Integer): Boolean;
begin
  Result := False;
  ExecuteSql(AdoQry_Tmp,'select * from Gl_Credence '
                      +'  where '+IIFString(AtFlag=0,'AssessFlag=0','TallyFlag=0')
                      +'    and DatePArt(yy,CredenceDate)='+Copy(Month,1,4)
                      +'    and DatePArt(mm,CredenceDate)='+copy(Month,6,2),
             0);
  If  AdoQry_Tmp.RecordCount>0 then Result := True;
end;

function TFrm_Gl_Enter_MonthCheck.ISallCredenced(Month: String;
  SType: Integer): Boolean;
var SqlText : String;
begin
  Result := True;
  Case SType of
    0 : SqlText := 'select InvBillNo from InvInBill '
                  +' where ISCredence = 0 '
                  +'   and (InvBillWhChck=1 or BillTypeCode=''1201'')'
                  +'    and BillType2Code Not In (''099'',''098'') '
                  +'    and DatePArt(yy,convert(DateTime,InvBillMonth+''.01''))='+Copy(Month,1,4)
                  +'    and DatePArt(mm,convert(DateTime,InvBillMonth+''.01''))='+Copy(Month,6,2)
                  +' union '
                  +'select InvBillNo from InvOutBill '
                  +' where ISCredence=0 '
                  +'    and (InvBillWhChCk =1 or BillTypeCode=''0299'') '
                  +'    and BillType2Code Not In (''099'',''098'') '
                  +'    and DatePArt(yy,convert(DateTime,InvBillMonth+''.01''))='+Copy(Month,1,4)
                  +'    and DatePArt(mm,convert(DateTime,InvBillMonth+''.01''))='+Copy(Month,6,2);
    1 : SqlText := 'select InvoiceNo from Sa_SaleInvoice '
                 +'  where ISCredence=0 '
                 +'    and InvoiceType1<>1 '
                 +'    and DatePArt(yy,InAccountDate)='+Copy(Month,1,4)
                 +'    and DatePArt(mm,InAccountDate)='+Copy(Month,6,2)
                 +' union '
                 +' select GatheringNo from Ar_Gathering '
                 +' where  ISCredence=0 '
                 +'    and DatePArt(yy,InAccountDate)='+Copy(Month,1,4)
                 +'    and DatePArt(mm,InAccountDate)='+Copy(Month,6,2);
    2 : SqlText := 'select ApInvoiceNo from ApInvoice'
                 +' where  ApInvoice.ISCredence=0                                         '
                 +'  and DatePArt(yy,ApInvoice.ApInvoiceInputDate)='+Copy(Month,1,4)
                 +'  and DatePArt(mm,ApInvoice.ApInvoiceInputDate)= '+Copy(Month,6,2)
                 +' union '
                 +' select PayBillNo from PayJournal'
                 +' where  ISCredence=0                                         '
                 +'  and DatePArt(yy,PayInputDate)='+Copy(Month,1,4)
                 +'  and DatePArt(mm,PayInputDate)= '+Copy(Month,6,2);
    3 : SQlText := ' select AssetCode from Ad_AssetCard '
                 +'   where ISCredence=0 '
                 +'  and DatePArt(yy,InAccountDate)='+Copy(Month,1,4)
                 +'  and DatePArt(mm,InAccountDate)= '+Copy(Month,6,2)
                 +' union '
                 +' select AssetCode from Ad_Depreciation '
                 +' where ISCredence=0 '
                 +'   and DatePArt(yy,Convert(datetime,DepreciationMonth+''.01''))= '+Copy(Month,1,4)
                 +'   and DatePArt(mm,Convert(datetime,DepreciationMonth+''.01''))= '+Copy(Month,6,2)
                 +' union '
                 +' select AssetCode from Ad_Depreciation_Subject '
                 +' where ISCredence=0 '
                 +'  and DatePArt(yy,Convert(datetime,DepreciationMonth+''.01''))=' +Copy(Month,1,4)
                   +'   and DatePArt(mm,Convert(datetime,DepreciationMonth+''.01''))='+Copy(Month,6,2);
  end;    
  ExecuteSql(AdoQry_Tmp,SqlText,0);
  If AdoQry_Tmp.RecordCount>0 then Result := False;
end;

function TFrm_Gl_Enter_MonthCheck.MonthSum(Month: String): Boolean;
var NextMonth : String; //月结月份的下一个月
    SqlText : String;
    Balance10:double;
    Balance20:double;
    Balance30:double;
    Balance40:double;
    Balance50:double;
begin
  Result := False;
  Try
    Screen.Cursor := CrHourGlass;
    try
      dbconnect.beginTrans;
      NextMonth := FormatDateTime('yyyy.mm',IncMonth(StrToDateTime(Month+'.01'),1));  
      SqlText := '  select Gl_AccountSubjectBalance.KmId,      '
                +'         '+Copy(NextMonth,1,4)+' as AccountPeriodYear,'
                +'         '+Copy(NextMonth,6,2)+' as AccountPeriodMonth,'
                +'   case when (      case when KmProperty=1 then case when BalanceDirection=1 then FirstBalance '
                +'                                          else -FirstBalance '
                +'                                     end '
                +'              else case when BalanceDirection=2 then FirstBalance '
                +'                        else -FirstBalance '
                +'                   end '
                +'         end        '
                +'         +case when KmProperty=1 then DebitBalance  '
                +'                           else -DebitBalance                   '
                +'           end                                       '
                +'         -case when KmProperty=1 then CreditBalance '
                +'                           else -CreditBalance                  '
                +'           end) <0 then case when KmProperty=1 then 2 else 1 end '
                +'        else KMProperty  '
                +'   end BalanceDirection,    '                                  
                +'      abs(   case when KmProperty=1 then case when BalanceDirection=1 then FirstBalance '
                +'                                          else -FirstBalance '
                +'                                     end '
                +'              else case when BalanceDirection=2 then FirstBalance '
                +'                        else -FirstBalance '

⌨️ 快捷键说明

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