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

📄 ap_pay_d.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
        break;
        DispInfo('发票匹配中出错!',1);
      end;
    end;
  end;
end;

procedure TFrm_Ap_Pay_D.MatchPay_negative(VendorCodeS:string;CurrPay: real);
var
  Bill_Tmp_Qry,Temp_Ap_Qry:TAdoQuery;
  SQL_Txt:string;
  Temp_var,r,var_Amount,aaaa:real;
begin
  Temp_var:=0.0;
  Bill_tmp_Qry:=TAdoQuery.Create(nil);
  Bill_tmp_Qry.Connection:=AdoQry_Maintain.Connection;
  Temp_Ap_Qry:=TAdoQuery.Create(nil);
  Temp_Ap_Qry.Connection:=AdoQry_Tmp.Connection;
  AdoQry_Tmp.Close;
  AdoQry_Tmp.sql.clear;
  sql_txt:='select PayJournalId,PayBillNO '+
                 ' from PayJournal'+
                 ' where PayBillNo='+
                 format('''%s''',[edt_PayBillno.Text]);
  AdoQry_Tmp.sql.Add(sql_txt);
  AdoQry_Tmp.Prepared;
  AdoQry_Tmp.open;
  lc_PayId:=AdoQry_Tmp.fieldbyname('PayJournalId').asstring;

  R:=GetApInvoiced(edt_VendorCode.text);
  CurrPay:=abs(CurrPay);
  if R<0 then
    var_Amount:=CurrPay+R
  else
    var_Amount:=CurrPay;
  if var_Amount>0 then
  begin
    with Temp_Ap_Qry do
    begin
      sql.clear;
      sql.Add('select ApInvoiceId,ApPayedAmount,'+
                '       ApPayFlag ,    '+
                '    ApInvoiceInputDate '+
                'from   ApInvoice     '+
                'where  ApPayflag<>2 and '+
                'VendorCode='+
                format('''%s''',[VendorCodeS]));
      Prepared;
      open;
      Sort:='ApInvoiceInputDate';
      last;
      while not bof do
      begin
        if (var_Amount>fieldbyname('ApPayedAmount').asfloat) then
        begin
          aaaa:=fieldbyname('ApPayedAmount').asfloat;
          edit;
          var_Amount:=var_Amount-(fieldbyname('ApPayedAmount').asfloat);
          fieldbyname('ApPayedAmount').asfloat:=0.0;
          fieldbyname('ApPayflag').asinteger:=2;
          post;
          MArk_File(strtoint(lc_PayId),
          fieldbyname('ApInvoiceId').asinteger,-(aaaa),
          edt_Paydate.Text);
          Prior;
        end
        else
        begin
          if (var_Amount=fieldbyname('ApPayedAmount').asfloat) then
          begin
            aaaa:=fieldbyname('ApPayedAmount').asfloat;
            edit;
            var_Amount:=var_Amount-(fieldbyname('ApPayedAmount').asfloat);
            fieldbyname('ApPayedAmount').asfloat:=0.0;
            fieldbyname('ApPayflag').asinteger:=2;
            post;
            MArk_File(strtoint(lc_PayId),
            fieldbyname('ApInvoiceId').asinteger,-(aaaa),
            edt_Paydate.Text);
            exit;
          end
          else
          if (var_Amount<fieldbyname('ApPayedAmount').asfloat) then
          begin
            edit;
            aaaa:=fieldbyname('ApPayedAmount').asfloat;//暂时存在
            fieldbyname('ApPayedAmount').asfloat:=
            fieldbyname('ApPayedAmount').asfloat-(var_Amount);
            fieldbyname('ApPayflag').asinteger:=1;
            post;
            MArk_File(strtoint(lc_PayId),
            fieldbyname('ApInvoiceId').asinteger,-(var_Amount),
            edt_Paydate.Text);
            Update;
            free;
            break;
          end;
        end;
      end;
    end;
  end;

end;


procedure TFrm_Ap_Pay_D.MArk_File(ApId, InvoiceId: integer;
  PayedAmout: real; PayedDate: string);
var
  Temp_Qry:TAdoQuery;
  SQL_Txt:string;
begin
  Temp_Qry:=TAdoQuery.Create(nil);
  Temp_Qry.Connection:=AdoQry_Maintain.Connection;
  SQL_Txt:='insert into PayJournalLine('+
                       'PayJournalId, '+
                       'ApInvoiceId, '+
                       'PayedAmount, '+
                       'ApPayedDate) '+
           'Values('+format('''%s''',[inttostr(ApId)])+','+
           format('''%s''',[inttostr(InvoiceId)])+','+
           format('%f',[PayedAmout])+','+
           format('''%s''',[PayedDate])+')';
  with Temp_Qry do
  begin
    sql.clear;
    sql.Add(sql_txt);
    Prepared;
    execsql;
  end;
    Sql_Txt:='insert into PayJournalLineLog'
          +'(PayJournalId,'
          +' ApInvoiceId,'
          +' PayedAmount,'
          +' ApPayedDate,'
          +' PayInputdate)'
          +'Values('+format('''%s''',[inttostr(ApId)])+','
          +format('''%s''',[inttostr(InvoiceId)])+','
          +format('%f',[PayedAmout])+','
          +format('''%s''',[PayedDate])+','
          +format('''%s''',[Edt_input.text])+')';
  with Temp_Qry do
  begin
    Close;
    sql.clear;
    sql.Add(Sql_Txt);
    Prepared;
    execsql;
  end;
end;


procedure TFrm_Ap_Pay_D.edt_PayAmountExit(Sender: TObject);
var
  S:string;
begin
  inherited;
  if activecontrol.Name='btn_Cancel' then
  begin
   Close;
   exit;
  end;

  try
  if (edt_PayAmount.Text='') then
  begin
    DispInfo('请检查输入金额!',1);
    edt_PayAmount.SetFocus;
    exit;
  end;
  except
    DispInfo('请检查输入金额!',1);
    edt_PayAmount.SetFocus;
  end;
end;

procedure TFrm_Ap_Pay_D.btn_CancelClick(Sender: TObject);
begin
  inherited;
  Close;
  Frm_Ap_Pay.repaint;
end;

procedure TFrm_Ap_Pay_D.edt_VendorCode1Exit(Sender: TObject);
begin
  inherited;
  VendorCodeCheck(edt_VendorCode);
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select Vendor.VendorCode,'+
            ' Vendor.currencyCode,'+
            ' currency.currencyName'+
            ' from Vendor join '+
            ' currency on currency.currencyCode=Vendor.currencyCode '+
            ' where Vendor.VendorCode='+
            ' '''+edt_VendorCode.text+''' ');
    Prepared;
    open;
    if not eof then
    begin
      edt_CurrencyCode.Text:=fieldbyname('currencyCode').asstring;
      Lbl_CURRENCYName.Caption:=fieldbyname('currencyName').asstring;
    end;
  end;
end;

procedure TFrm_Ap_Pay_D.btn_okClick(Sender: TObject);
begin
  if edt_PayAmount.Text='' then
  begin
    DispInfo('输入不完整!',1);
    abort;
  end;
  inherited;
  Frm_Ap_Pay.repaint;
end;

function TFrm_Ap_Pay_D.ApCheckout(Month: String): Boolean;      //convert(varchAr(7),ApParamValuec,102)
var
  str,str1:string;
begin
  With AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select ApParamValuec '+
                    ' from ApParam '+
                    ' where ApParamCode=''clsperiod''');
    open;
    str:=fieldbyname('ApParamValuec').asstring;
    if str<>'' then
    begin
      str:=datetostr(incMonth(strtodate(str+'.01'),1));
//      str:=str+'.01';
      str1:=datetimetostr(strtodatetime(str)+62);
      str1:=copy(str1,1,7)+'.01';
      if (strtodate(Month)>strtodate(str)) and
         (strtodate(Month)<strtodate(str1)) then Result:=False
      else Result:=True;
    end;
  end;
end;

procedure TFrm_Ap_Pay_D.Edt_inputExit(Sender: TObject);
begin
  inherited;
  if activecontrol.Name='btn_Cancel' then
  begin
    btn_Cancel.Click;
    abort;
  end;
  if ApCheckout(Edt_input.Text) then
  begin
    DispInfo('不允许增加已结帐月份记录!',1);
    Edt_input.SetFocus;
    exit;
  end;
end;

procedure TFrm_Ap_Pay_D.Delete_Old_MatchPay(VendorCodeS: string;
  CurrPay: real);
var
var_Amount:real;
Temp_Ap_Qry:TAdoQuery;
aaaa:real;
R:real;
begin
  Temp_Ap_Qry:=TAdoQuery.Create(nil);
  Temp_Ap_Qry.Connection:=AdoQry_Tmp.Connection;
  R:=GetApInvoiced(edt_VendorCode.text);
  if R<0 then
  var_Amount:=CurrPay+R
  else
  var_Amount:=CurrPay;
  with Temp_Ap_Qry do
  begin
    sql.clear;
    sql.Add('select ApPayedAmount,'+
              '       ApPayFlag ,    '+
              '    ApInvoiceInputDate '+
              'from   ApInvoice     '+
              'where  ApPayflag<>2 and '+
              'VendorCode='+
              format('''%s''',[VendorCodeS]));
    Prepared;
    open;
    Sort:='ApInvoiceInputDate';
    last;
    while not bof do
    begin
      if (var_Amount>fieldbyname('ApPayedAmount').asfloat) then
      begin
        edit;
        var_Amount:=var_Amount-(fieldbyname('ApPayedAmount').asfloat);
        fieldbyname('ApPayedAmount').asfloat:=0.0;
        fieldbyname('ApPayflag').asinteger:=2;
        post;
        Prior;
      end
      else
      begin
        if (var_Amount=fieldbyname('ApPayedAmount').asfloat) then
        begin
          edit;
          var_Amount:=var_Amount-(fieldbyname('ApPayedAmount').asfloat);
          fieldbyname('ApPayedAmount').asfloat:=0.0;
          fieldbyname('ApPayflag').asinteger:=2;
          post;
          exit;
        end
        else
        if (var_Amount<fieldbyname('ApPayedAmount').asfloat) then
        begin
          edit;
          aaaa:=fieldbyname('ApPayedAmount').asfloat;//暂时存在
          fieldbyname('ApPayedAmount').asfloat:=
          fieldbyname('ApPayedAmount').asfloat-(var_Amount);
          fieldbyname('ApPayflag').asinteger:=1;
          post;
          Update;
          free;
          break;
      end;
      end;
    end;
  end;
end;


function TFrm_Ap_Pay_D.GetApInvoiced(VendorCode:string): real;
var
  S:string;
begin
  S:=' select VendorCode,ApInvoiced from CurrentAp where VendorCode = '+Quotedstr(VendorCode);
  AdoQry_tmp.Close;
  AdoQry_tmp.SQL.clear;
  AdoQry_tmp.SQL.Add(s);
  AdoQry_tmp.Open;
  Result:=AdoQry_tmp.fieldbyname('ApInvoiced').asfloat;
end;

procedure TFrm_Ap_Pay_D.Add_CurrentAp(VendorCodeS: string; CurrPay: real);
var
  S:string;
begin
  S:=  'update CurrentAp '+
       ' set ApInvoiced = ApInvoiced -('+(floattostr(CurrPay))+') '  +
       ' where VendorCode = '+quotedstr(VendorCodeS);
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.Add(s);
  AdoQry_Tmp.Prepared;
  AdoQry_Tmp.ExecSQL;
end;

procedure TFrm_Ap_Pay_D.Delete_CurrentAp(VendorCodeS: string;
  CurrPay: real);
var
  S:string;
begin
  S:=  ' update CurrentAp '+
       ' set ApInvoiced = ApInvoiced +'+floattostr(CurrPay)  +
       ' where VendorCode ='+quotedstr(VendorCodeS);
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.Add(s);
  AdoQry_Tmp.Prepared;
  AdoQry_Tmp.ExecSQL;
end;

procedure TFrm_Ap_Pay_D.edt_VendorCodeExit(Sender: TObject);
begin
  inherited;
  VendorCodeCheck(edt_VendorCode);
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select Vendor.VendorCode,'+
            ' Vendor.currencyCode,'+
            ' currency.currencyName'+
            ' from Vendor join '+
            ' currency on currency.currencyCode=Vendor.currencyCode '+
            ' where Vendor.VendorCode='+
            ' '''+Trim(edt_VendorCode.text)+''' ');
    Prepared;
    open;
    if not eof then
    begin
      edt_CurrencyCode.Text:=fieldbyname('currencyCode').asstring;
      Lbl_CURRENCYName.Caption:=fieldbyname('currencyName').asstring;
    end;
  end;
end;

procedure TFrm_Ap_Pay_D.edt_VendorCodeButtonClick(Sender: TObject);
begin
  inherited;
  CommonHint(Sender,AdoQry_Tmp,'VendorName','供应商名称','VendorCode',
     '供应商代码','Vendor','VendorUsable=1');
end;

end.

⌨️ 快捷键说明

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