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

📄 ap_enter_purchasepayment.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 4 页
字号:
    begin
       DispInfo('金额不能为零!',3);
       Edt_PayAmount.SetFocus ;
       abort;
    end;
    if Trim(Edt_PayDate.text)='' then
    begin
       DispInfo('付款日期不能为空!',3);
       Edt_PayDate.SetFocus ;
       abort;
    end;
    Edt_PayInputdateExit(Edt_PayInputdate);
  end;
  if AdoQry_Body.State <>dsBrowse	 then
     AdoQry_Body.Post;
  Total:=0;
  with AdoQry_Body do
  begin
    First;
    while not eof do
    begin
      //if fieldbyname('ApPayFlag').asinteger=0 then
        Total:=Total+fieldbyname('ThisApPayAmount').asfloat;
     next;
    end;
    if status='Add' then
    begin
      if Total-strtofloat(Trim(Edt_PayAmount.text))>0.01 then
      begin
        DispInfo('本次核销总金额不能大于付款金额',3);
        Edt_PayAmount.SetFocus ;
        abort;
      end;
    end;
    if Status='AllEdit' then
    begin
      if  Total=0 then
      begin
        DispInfo('本次核销总金额不能零',3);
        abort;
      end;
      if Total-strtofloat(Trim(Edt_NoPayedAmount.text))>0.01 then
      //if floattostr(Total)>Trim(Edt_NoPayedAmount.text) then
      begin
        DispInfo('本次核销总金额不能大于未核销金额:',3);
        dbgrideh.SetFocus ;
        abort;
      end;
    end;
  end;
end;

procedure TFrm_Ap_Enter_PurchasePayment.previewPay;//模拟付款:测试付款金额是否等于选定核销发票额;
var
  PayAmount,BillAmount,TmpAmount:double;
begin
  if not  dataChange then exit;
  PayAmount:=strtofloat(Edt_PayAmount.text);
  // AdoQry_Body.DisableControls ;
  with AdoQry_Body do
  begin
    First;
    while not eof do
    begin
      edit;
      fieldbyname('ThisApPayAmount').asstring:='0';
      post;
      next;
    end;
  end;
  try
    with AdoQry_Body do
    begin
      First;
      while not eof do
      begin
        if PayAmount<=0 then break;
        if  AdoQry_Body.fieldbyname('ThisApPayAmount').Value<>0 then
        begin
           next;
           continue;
        end;
        TmpAmount:= AdoQry_Body. fieldbyname('NoApPayAmount').asfloat;
        if PayAmount>=AdoQry_Body.fieldbyname('NoApPayAmount').asfloat then
        begin
          AdoQry_Body.edit;
          //AdoQry_Body.fieldbyname('ThisApPayAmount').asfloat:=0.00;
          AdoQry_Body.fieldbyname('ThisApPayAmount').Value:=TmpAmount;
          AdoQry_Body.post;
          PayAmount:=PayAmount-AdoQry_Body.fieldbyname('NoApPayAmount').asfloat ;

        end
        else
        begin
          AdoQry_Body.edit;
          //AdoQry_Body.fieldbyname('ThisApPayAmount').asfloat:=0.00;
          AdoQry_Body.fieldbyname('ThisApPayAmount').Value:=PayAmount;
          AdoQry_Body.post;
          PayAmount:=0 ;
        end;

        next;
      end;
    end;
    //AdoQry_Body.UpdateBatch ;
    //dbgrideh.Refresh ;
  finally
    //AdoQry_Body.EnableControls ;
  end;
  //dataChange:=False;
end;

procedure TFrm_Ap_Enter_PurchasePayment.Edt_PayAmountExit(Sender: TObject);
begin
  inherited;
  if Trim(Edt_PayAmount.text)='' then
  begin
    DispInfo('付款金额不能为空!',3);
    Edt_PayAmount.setfocus;
    abort;
  end;
  floatcheck(Edt_PayAmount);

  Edt_NoPayedAmount.text:=Edt_PayAmount.text;
  if PayMode<>2 then
  begin
    if not  dbgrideh.ReadOnly then
      dbgrideh.ReadOnly:=True;
    dbgrideh.Columns[6].ReadOnly :=True;
    previewPay;                     //模拟付款:测试付款金额是否等于选定核销发票额;
    if dbgrideh.Columns[7].Visible  then
      dbgrideh.Columns[7].Visible:=False;
  end
  else
  begin
    if dbgrideh.ReadOnly then
      dbgrideh.ReadOnly:=False;
    dbgrideh.Columns[6].ReadOnly :=False;
    if not  dbgrideh.Columns[7].Visible  then
      dbgrideh.Columns[7].Visible:=True;
  end;
  LEdt_PayModeCode.setfocus;
end;

procedure TFrm_Ap_Enter_PurchasePayment.LEdt_PayModeCodeButtonClick(
  Sender: TObject);
begin
  inherited;
  CommonHint(Sender,AdoQry_Tmp,'PayModeName','付款方式名称','PayModeCode',
      '付款方式代码','PayMode');
end;

procedure TFrm_Ap_Enter_PurchasePayment.LEdt_PayModeCodeKeyDown(
  Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=120 then
    CommonHint(Sender,AdoQry_Tmp,'PayModeName','付款方式名称','PayModeCode',
      '付款方式代码','PayMode');
end;

procedure TFrm_Ap_Enter_PurchasePayment.LEdt_PayModeCodeExit(
  Sender: TObject);
begin
  inherited;
  if activecontrol.Name='ToolButton4' then
    abort;
  if flag=1 then
  begin
    if Trim(LEdt_PayModeCode.text)='' then
    begin
      DispInfo('付款方式代码不能为空!',3);
      LEdt_PayModeCode.SetFocus ;
      abort;
    end;
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.text:='select PayModeName from PayMode where PayModeCode='''+Trim(LEdt_PayModeCode.text)+'''';
      open;
      if recordCount<>0 then
        Edt_PayModeName.text:=fieldbyname('PayModeName').asstring
      else
      begin
        DispInfo('付款方式代码不存在!',3);
        LEdt_PayModeCode.setfocus;
        abort;
      end;
    end;
  end;
end;

procedure TFrm_Ap_Enter_PurchasePayment.Edt_ExchRateKeyDown(
  Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=13 then
    Edt_PayAmount.setfocus;
end;

procedure TFrm_Ap_Enter_PurchasePayment.AdoQry_BodyApPayFlagChange(
  Sender: TField);
var
  aa:real;
begin
  inherited;
  aa:=0;
  if Trim(Edt_Total.text)='' then
    Edt_Total.text:='0';
  if sender.AsInteger =0 then
    aa:= strtofloat(Edt_Total.text)+AdoQry_Body.fieldbyname('ApInvoiceAmount').asfloat
  else
    if strtofloat(Trim(Edt_Total.text))<>0 then
      aa:= strtofloat(Edt_Total.text)-AdoQry_Body.fieldbyname('ApInvoiceAmount').asfloat;
  Edt_Total.text:=formatfloat('#.##',aa);
end;

procedure TFrm_Ap_Enter_PurchasePayment.FormDestroy(Sender: TObject);
begin
  inherited;
  Frm_Ap_Enter_PurchasePayment:=nil;
end;

function TFrm_Ap_Enter_PurchasePayment.TotalPay: double;
begin
  Result:=0.0;
  with AdoQry_Body do
  begin
    First;
    while not eof do
    begin
      if fieldbyname('ThisApPayAmount').asfloat<>0.00 then
       Result:=Result+fieldbyname('ThisApPayAmount').asfloat;
      next;
    end;
  end;
end;

function TFrm_Ap_Enter_PurchasePayment.GetApPayAmount(PayJournalId:string): double; //获取付款匹配总金额
begin
  Result:=0.00;
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.text:=' select sum(isnull(PayedAmount,0)) as PayedAmount from PayJournalline'+
              ' where PayJournalId='+PayJournalId;
    open;
    Result:=fieldbyname('PayedAmount').asfloat;
  end;
end;

procedure TFrm_Ap_Enter_PurchasePayment.SaveBodydataForPayMode1;
begin
  MatchPay ;                     //增加一张付款记录时发票匹配过程函数
end;


procedure TFrm_Ap_Enter_PurchasePayment.SaveBodydataForPayMode2;
begin
  with AdoQry_Body do
  begin
    First;
    while not eof do
    begin
      if fieldbyname('ThisApPayAmount').asfloat<>0.00 then
      begin
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.clear;
        AdoQry_tmp.SQL.text:='insert into PayJournalLine '+
            '  (PayJournalId,'+
            '   ApInvoiceId,'+
            '   PayedAmount,'+
            '   ApPayedDate) '+
            'Values '+
            '  ('+PayBillid+','+
            '   '+AdoQry_Body.fieldbyname('ApInvoiceId').asstring+','+
            '   '+AdoQry_Body.fieldbyname('ThisApPayAmount').asstring+','+
            '   '''+Edt_PayDate.Text+''''+')';
        AdoQry_tmp.execSQL;
        if fieldbyname('NoApPayAmount').asfloat=fieldbyname('ThisApPayAmount').asfloat   then
        begin
          AdoQry_tmp.Close;
          AdoQry_tmp.SQL.clear ;
          AdoQry_tmp.SQL.text:=' update ApInvoice set ApPayFlag=0 ,'
                              +' ApPayedAmount=ApPayedAmount+'+ AdoQry_Body.fieldbyname('ThisApPayAmount').asstring
                              +' ,ApPayedAmountC =ApPayedAmountC+'+
                                   floattostr(AdoQry_Body.fieldbyname('ThisApPayAmount').asfloat*strtofloat(Edt_ExchRate.text))
                              +' where ApInvoiceId='+AdoQry_Body.fieldbyname('ApInvoiceId').asstring;
          AdoQry_tmp.execSQL;
        end
        else
        begin
          AdoQry_tmp.Close;
          AdoQry_tmp.SQL.clear ;
          AdoQry_tmp.SQL.text:=' update ApInvoice set ApPayFlag=1 ,'
                              +' ApPayedAmount=ApPayedAmount+'+ AdoQry_Body.fieldbyname('ThisApPayAmount').asstring
                              +' ,ApPayedAmountC =ApPayedAmountC+'+
                                   floattostr(AdoQry_Body.fieldbyname('ThisApPayAmount').asfloat*strtofloat(Edt_ExchRate.text))
                              +' where ApInvoiceId='+AdoQry_Body.fieldbyname('ApInvoiceId').asstring;
          AdoQry_tmp.execSQL;
        end;
      end;
      next;
    end;
  end;
end;

procedure TFrm_Ap_Enter_PurchasePayment.MatchPay;
var
  //SQL_Txt:string;
  //Temp_var:real;
  PayAmount:double;
  ApPayFlag:integer;
  ThisApPayAmount:double;
begin
  if Status='Add' then
    PayAmount:=strtofloat(Edt_PayAmount.text)
  else
    PayAmount:=strtofloat(Edt_NoPayedAmount.text); 
  with AdoQry_Body do
  begin
    First;
    while not eof do
    begin
      if PayAmount=0  then break;
      if PayAmount>=fieldbyname('NoApPayAmount').asfloat then
      begin
        ThisApPayAmount:= fieldbyname('NoApPayAmount').asfloat;
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.clear;
        AdoQry_tmp.SQL.text:='insert into PayJournalLine '+
            '  (PayJournalId,'+
            '   ApInvoiceId,'+
            '   PayedAmount,'+
            '   ApPayedDate) '+
            'Values '+
            '  ('+PayBillid+','+
            '   '+AdoQry_Body.fieldbyname('ApInvoiceId').asstring+','+
            '   '+floattostr(ThisApPayAmount)+','+
            '   '''+Edt_PayDate.Text+''''+')';
        AdoQry_tmp.execSQL;
        AdoQry_tmp.Close;
        AdoQry_tmp.SQL.clear ;
        AdoQry_tmp.SQL.text:=' update ApInvoice set ApPayFlag=0 ,'
                            +' ApPayedAmount=ApPayedAmount+'+ floattostr(ThisApPayAmount)
                            +' ,ApPayedAmountC =ApPayedAmountC+'+
                                   floattostr(ThisApPayAmount*strtofloat(Edt_ExchRate.text))

                            +' where ApInvoiceId='+AdoQry_Body.fieldbyname('ApInvoiceId').asstring;
        AdoQry_tmp.execSQL;
        edit;
        fieldbyname('ThisApPayAmount').asfloat:=ThisApPayAmount;
        post;
        PayAmount:=PayAmount-ThisApPayAmount;
      end
      else
      begin
        ThisApPayAmount:= PayAmount;
        AdoQry_tmp.Close;

⌨️ 快捷键说明

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