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

📄 arinvoicespostform.pas

📁 功能全面的商业财会系统源码,清晰,很有参考价值.扩展性强.
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  ModalResult := mrOK;
  screen.cursor := crHourglass;
  ProgressBar1.max := qryARInv.RecordCount;
  ProgressBar1.step := 1;
  tblCurrency.Active := true;
  tblJV.Active := true;
  tblJV2.Active := true;
  tblJVDet.Active := true;
  tblARInvDet.Active := true;
  tblItem.Active := true;
  try
    qryARInv.First;
    while not qryARInv.EOF do begin
      with tblARInv do begin   //Update tblARInv.
        try
          Edit;
          FieldValues['Posted'] := true;
          Post;
        except raise; end;
      end;

      if tblCBalance.Locate('CustomerID', qryARInvBillToID.value, []) = true then begin   //Update tblCBalance.
        try
          tblCBalance.Edit;
          tblCBalanceBalance.AsCurrency := tblCBalanceBalance.value + qryARInvInvoiceAmount.value;
          tblCBalance.Post;
        except raise; end;
      end else begin
        try
          tblCBalance.Insert;
          tblCBalanceCustomerID.value := qryARInvBillToID.value;
          tblCBalanceBalance.AsCurrency := qryARInvInvoiceAmount.value;
          tblCBalance.Post;
        except raise; end;
      end;

      if qryARInvTax1Code.value = qryARInvTaxableAmtCode1.value then Tax1Amount := frmBS1.RoundIt(qryARInvTaxableAmount1.value * qryARInvTax1Rate.value)/100
      else if qryARInvTax1Code.value = qryARInvTaxableAmtCode2.value then Tax1Amount := frmBS1.RoundIt(qryARInvTaxableAmount2.value * qryARInvTax1Rate.value)/100
      else if qryARInvTax1Code.value = qryARInvTaxableAmtCode3.value then Tax1Amount := frmBS1.RoundIt(qryARInvTaxableAmount3.value * qryARInvTax1Rate.value)/100
      else Tax1Amount := 0;
      if qryARInvTax2Code.value = qryARInvTaxableAmtCode1.value then Tax2Amount := frmBS1.RoundIt(qryARInvTaxableAmount1.value * qryARInvTax2Rate.value)/100
      else if qryARInvTax2Code.value = qryARInvTaxableAmtCode2.value then Tax2Amount := frmBS1.RoundIt(qryARInvTaxableAmount2.value * qryARInvTax2Rate.value)/100
      else if qryARInvTax2Code.value = qryARInvTaxableAmtCode3.value then Tax2Amount := frmBS1.RoundIt(qryARInvTaxableAmount3.value * qryARInvTax2Rate.value)/100
      else Tax2Amount := 0;

      try   //Create JV.
        tblJV.Insert;
          tblJVCtl.Edit;
          tblJVJVID.Value := tblJVCtlNextJVID.Value;
          tblJVCtlNextJVID.Value := tblJVCtlNextJVID.Value + 1;
          if (tblJVCtlNextJVNumber.Value < 1001) or (tblJVCtlNextJVNumber.Value > 10000000) then tblJVCtlNextJVNumber.Value := 1001;   //Start auto-assigned numbers here.
          while true do begin
            if tblJV2.Locate('GLYear;GLPeriod;JVNumber', VarArrayOf([qryARInvGLYear.value,qryARInvGLPeriod.value,tblJVCtlNextJVNumber.Value]), []) = true then tblJVCtlNextJVNumber.Value := tblJVCtlNextJVNumber.Value + 1
            else break;   //Exit loop.
          end;
          tblJVJVNumber.Value := tblJVCtlNextJVNumber.Value;
          tblJVCtlNextJVNumber.Value := tblJVCtlNextJVNumber.Value + 1;
          tblJVCtl.Post;
        tblJVGLYear.value := qryARInvGLYear.value;
        tblJVGLPeriod.value := qryARInvGLPeriod.value;
        tblJVSource.value := 'AR';
        tblJVTransType.value := 'Inv';
        tblJVTransDate.value := Date;
        tblJVTransDescription.value := 'AR Invoice ' + qryARInvInvoiceNo.value;
        tblJVCustomerID.value := qryARInvBillToID.value;
        tblJVARInvoiceID.value := qryARInvARInvoiceID.value;
        if qryARInvInvoiceAmount.AsCurrency > 0 then tblJVJVAmount.AsCurrency := qryARInvInvoiceAmount.value
        else                                         tblJVJVAmount.AsCurrency := -qryARInvInvoiceAmount.value;
        TotalDebits := 0;   //Accumulate total debits to adjust JV amount later if neccessary.
        tblJVPosted.value := false;
        tblJVAutoReverse.value := false;
        tblJV.Post;
      except raise; end;

      tblARInvDet.First;   //Create JV detail.
      TotalExchange := 0;
      While not tblARInvDet.eof do begin
        try   //Revenue accounts.
          tblJVDet.Insert;
          tblJVDetJVID.Value := tblJVJVID.Value;
          tblJVDetSeq.Value := tblARInvDetSeq.Value;
          if (qryARInvExchangeRate.value = 0) or (qryARInvExchangeRate.value = 1) then tblJVDetGLAmount.AsCurrency := -tblARInvDetExtAmount.Value
          //else tblJVDetGLAmount.AsCurrency := -tblARInvDetExtAmount.Value * qryARInvExchangeRate.value;   //Prevent Delphi 2 bug: rounds .5 down.
          else begin
            tblJVDetGLAmount.AsCurrency := frmBS1.RoundIt(-tblARInvDetExtAmount.Value * qryARInvExchangeRate.value * 100)/100;
            TotalExchange := TotalExchange + (-tblJVDetGLAmount.Value - tblARInvDetExtAmount.Value);
          end;
          if tblJVDetGLAmount.AsCurrency >0 then TotalDebits := TotalDebits + tblJVDetGLAmount.value;
          tblJVDetGLAccount.Value := tblARInvDetSalesGLAccount.Value;
          tblJVDet.Post;
        except raise; end;
        tblARInvDet.next;
      end;
      if Tax1Amount <> 0 then begin   //Tax 1.
        try
          tblJVDet.Insert;
          tblJVDetJVID.Value := tblJVJVID.Value;
          tblJVDetSeq.Value := tblARInvDetSeq.Value + 1;
          if (qryARInvExchangeRate.value = 0) or (qryARInvExchangeRate.value = 1) then tblJVDetGLAmount.AsCurrency := -Tax1Amount
          //else tblJVDetGLAmount.AsCurrency := -Tax1Amount * qryARInvExchangeRate.value;   //Prevent Delphi 2 bug: rounds .5 down.
          else begin
            tblJVDetGLAmount.AsCurrency := frmBS1.RoundIt(-Tax1Amount * qryARInvExchangeRate.value * 100)/100;
            TotalExchange := TotalExchange + (-tblJVDetGLAmount.Value - Tax1Amount);
          end;
          if tblJVDetGLAmount.AsCurrency >0 then TotalDebits := TotalDebits + tblJVDetGLAmount.value;
          tblJVDetGLAccount.Value := qryARInvTax1GLAccount.value;
          tblJVDet.Post;
        except raise; end;
      end;
      if Tax2Amount <> 0 then begin   //Tax 2.
        try
          tblJVDet.Insert;
          tblJVDetJVID.Value := tblJVJVID.Value;
          tblJVDetSeq.Value := tblARInvDetSeq.Value + 2;
          if (qryARInvExchangeRate.value = 0) or (qryARInvExchangeRate.value = 1) then tblJVDetGLAmount.AsCurrency := -Tax2Amount
          //else tblJVDetGLAmount.AsCurrency := -Tax2Amount * qryARInvExchangeRate.value;   //Prevent Delphi 2 bug: rounds .5 down.
          else begin
            tblJVDetGLAmount.AsCurrency := frmBS1.RoundIt(-Tax2Amount * qryARInvExchangeRate.value * 100)/100;
            TotalExchange := TotalExchange + (-tblJVDetGLAmount.Value - Tax2Amount);
          end;
          if tblJVDetGLAmount.AsCurrency >0 then TotalDebits := TotalDebits + tblJVDetGLAmount.value;
          tblJVDetGLAccount.Value := qryARInvTax2GLAccount.value;
          tblJVDet.Post;
        except raise; end;
      end;
      try   //AR GLAccount.
        tblJVDet.Insert;
        tblJVDetJVID.Value := tblJVJVID.Value;
        tblJVDetSeq.Value := tblARInvDetSeq.Value + 3;
        tblJVDetGLAmount.AsCurrency := qryARInvInvoiceAmount.Value;
        if tblJVDetGLAmount.AsCurrency >0 then TotalDebits := TotalDebits + tblJVDetGLAmount.value;
        tblJVDetGLAccount.Value := qryARInvARGLAccount.value;
        tblJVDet.Post;
      except raise; end;
      if TotalExchange <> 0 then begin   //AR Exchange.
        try
          tblJVDet.Insert;
          tblJVDetJVID.Value := tblJVJVID.Value;
          tblJVDetSeq.Value := tblARInvDetSeq.Value + 4;
          tblJVDetGLAmount.AsCurrency := TotalExchange;
          if tblJVDetGLAmount.AsCurrency >0 then TotalDebits := TotalDebits + tblJVDetGLAmount.value;
          tblJVDetGLAccount.Value := qryARInvGainLossExchangeGLAccount.value;
          tblJVDet.Post;
        except raise; end;
        //try
        //  tblJV.Edit;
        //  if TotalExchange >0 then tblJVJVAmount.AsCurrency := tblJVJVAmount.value + TotalExchange
        //  else tblJVJVAmount.AsCurrency := tblJVJVAmount.value - TotalExchange;
        //  tblJV.Post;
        //except raise; end;
      end;
      if tblJVJVAmount.AsCurrency <> TotalDebits then begin   //Update JV amount if necessary.
        try
          tblJV.Edit;
          tblJVJVAmount.AsCurrency := TotalDebits;
          tblJV.Post;
        except raise; end;
      end;

      ProgressBar1.StepIt;
      qryARInv.next;
    end;
  finally
    DbiSaveChanges(tblJVCtl.handle);
    DbiSaveChanges(tblJV.handle);
    DbiSaveChanges(tblJVDet.handle);
    DbiSaveChanges(tblARInv.handle);
    DbiSaveChanges(tblCBalance.handle);
    tblJVCtl.Close;
    tblARInv.Close;
    tblCBalance.Close;
    screen.cursor := crDefault;
  end;

  if (license = '') and (frmBS1.tblCompanyCompanyName.value <> 'Sample Data') then begin
    qryARInv.close;
    qryARInv.SQL[1] := 'WHERE I.Posted = true';
    qryARInv.open;
    frmBS1.DemoLimitWarning(qryARInv.RecordCount, 'invoice');
  end;
end;

procedure TfrmARInvoicesPost.tblARInvDetCalcFields(DataSet: TDataSet);
begin
  tblARInvDetExtAmount.AsCurrency := frmBS1.RoundIt(tblARInvDetQuantity.value * tblARInvDetUnitPrice.value * 100)/100;
end;

end.

⌨️ 快捷键说明

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