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

📄 ap_invoice.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 5 页
字号:
           edit2.text:=copy(UpperCase(Trim(edit2.text)),1,3);
           //edit1.setfocus;
           edit2.setfocus;
           edit2.SelStArt:=4;
           edit2.sellength:=0;
           abort;
         end;
          AdoQry_Main.Next;
      end;
  end;
end;

procedure TFrm_Ap_Invoice.UnDeleteInvInBill;
begin
  AdoQry_Main.First;
  while not AdoQry_Main.Eof do
  begin
    if AdoQry_Main.fieldbyname('InvBillFinChck').asinteger=1 then
    begin
      with AdoQry_Tmp do
      begin
        Close;
        sql.clear;
        sql.Add('update InvInBill '+
                'set InvBillFinChck=0 '+
                'where InvBillNo='''+AdoQry_Main.fieldbyname('InvBillNo').asstring+''' '+
                '  And VendorCode='''+Trim(ExtEdt_VendorCode.text)+''' '+
                '  And WHCode='''+GetCode(Trim(AdoQry_Main.fieldbyname('WHCodeName').asstring))+''' ');
        ExecSql;
      end;
    end;
    AdoQry_Main.next;
  end;

end;

procedure TFrm_Ap_Invoice.AdoQry_MainBeforeOpen(DataSet: TDataSet);
begin
  inherited;
  FreeFields:='InvBillNoTaxAmount,' ;
end;

procedure TFrm_Ap_Invoice.DBGridEh1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  if DbgridEh1.SelectedField=AdoQry_Main.fieldbyname('InvBillFinChck')  then
  begin
    edit2.text:='';
  end;

end;

procedure TFrm_Ap_Invoice.LookforInvInBill;
begin
  WhCodestr:=getCode(AdoQry_Main.fieldbyname('WhCodeName').asstring);
  InvInBillnoStr:=AdoQry_Main.fieldbyname('InvBillNo').asstring;
  if (InvInBillnostr<>'') AND (WhCodestr<>'') then
  begin
    Frm_Ap_Invoice_D:=TFrm_Ap_Invoice_D.Create(self);
    Frm_Ap_Invoice_D.getdata(InvInBillnostr,WhCodestr);
    Frm_Ap_Invoice_D.ShowModal;
  end;
end;

function TFrm_Ap_Invoice.HasPersave: String;
var
  str:string;
begin
  str:='';
  With AdoQry_Tmp do
  begin
    Close;
    Sql.clear ;
    Sql.Add ('Select ApInvoiceNo  '+
                     ' from ApInvoice '+
                     ' where ApInvoiceType=2 and EmployeeCode='''+userCode+'''');
    open;
    If not eof then
      Str:=fieldbyname('ApInvoiceNo').AsString;
    Close;
  end;
  Result:=str;
end;

procedure TFrm_Ap_Invoice.GetPerSaveInvoiceBill(PerSaveApInvoiceNo:String);
begin
  //flag:=3;// 暂存标志;
  clearEdit;
  ReadOnly(1);
  TlBtn_New.enabled:=False;
  TLBtn_Save.enabled:=True;
  TLBtn_PerSave.enabled:=True;
  TlBtn_Delete.enabled:=False;
  TlBtn_Qury.Enabled:=False;
  TlBtn_Cancel.Enabled:=True;
  with  AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select ApInvoice.*,'+
            '  ApInvoiceLine.InvBillid as InvBillid,'+
            '  Vendor.VendorName, '+
            '  Vendor.VendorTaxRate_Percent , '+
            '  Currency.CurrencyName ,'+
            '  Employee.EmployeeName '+
            'from ApInvoice left join  ApInvoiceLine '+
            '  on ApInvoice.ApInvoiceId=ApInvoiceLine.ApInvoiceId '+
            '  left join Vendor '+
            '  on ApInvoice.VendorCode= Vendor.VendorCode '+
            '  left join Currency '+
            '  on ApInvoice.CurrencyCode=Currency.CurrencyCode '+
            '  left join Employee '+
            '  on ApInvoice.EmployeeCode=Employee.EmployeeCode '+
            'where ApInvoice.ApInvoiceNo='''+PerSaveApInvoiceNo+''' ');
    open;
    //把得到的数据显示出来
    case fieldbyname('ApInvoiceType').asinteger of
      0: CmBx_ApInvoiceType.text:='发票';
      1: CmBx_ApInvoiceType.text:='收据';
      //2: CmBx_ApInvoiceType.text:='暂存';
    end;
    Edt_ApInvoiceNo.text:=fieldbyname('ApInvoiceNo').asstring;
    Medt_ApInvoiceDate.text:=formatdatetime('yyyy.mm.dd',fieldbyname('ApInvoiceDate').asdatetime);
    Lbl_EmployeeCode.text:=fieldbyname('EmployeeCode').asstring;
    Lbl_EmployeeName.text:=fieldbyname('EmployeeName').asstring;
    Medt_ApInvoiceInputDate.text:=formatdatetime('yyyy.mm.dd',fieldbyname('ApInvoiceInputDate').asdatetime);
    ExtEdt_VendorCode.text:=fieldbyname('VendorCode').asstring;
    Lbl_VendorName.text:=fieldbyname('VendorName').asstring;
    Lbl_CurrencyCode.text:=fieldbyname('CurrencyCode').asstring;
    Lbl_CurrencyName.text:=fieldbyname('CurrencyName').asstring;
    Edt_ApInvoiceAmount.text:=fieldbyname('ApInvoiceAmount').asstring;
    Edt_ApInvoiceTax.text:=fieldbyname('ApInvoiceTax').asstring;
    Lbl_TaxRate_Percent.text:=inttostr(fieldbyname('VendorTaxRate_Percent').asinteger);
    Edt_ApInvoiceNoTax.text:=floattostr(fieldbyname('ApInvoiceAmount').asfloat-fieldbyname('ApInvoiceTax').asfloat);
    Edt_ApInvoiceRemArk.text:=fieldbyname('ApInvoiceRemArk').asstring;
  end;
  if flag=3 then
    GetPerSaveAndNoApInvInBill(Trim(PerSaveApInvoiceNo))
  else
  GetPerSaveInvInBill(Trim(PerSaveApInvoiceNo));
  if not  AdoQry_Main.Eof then  AdoQry_Main.First ;
  with CmBx_ApInvoiceType do
  begin
    Items.clear;
    Items.Add('发票');
    Items.Add('收据');
    ItemIndex :=0;
  end;
  AdoQry_TMP.Close;
  Pnl_Hint.Caption:='提示:入库单的行数:'+Inttostr(AdoQry_Main.recordCount);
  //Lbl_CurrencyCode.enabled:=False;
end;

procedure TFrm_Ap_Invoice.TlBtn_PerSaveClick(Sender: TObject);
var
  I:integer;
  Yearstr,Monthstr,newMonth:string;
  j:integer;
begin
  inherited;
  j:=0;
 // TlBtn_PerSave.enabled:=False;
 // TlBtn_Save.enabled:=False;
  try
    DateSeparator:='.';
    Shortdateformat:='yyyy.mm.dd';
    StrToDate(Medt_ApInvoiceInputDate.Text);
  except
    DispInfo('   日期非法!  ',1);
    Medt_ApInvoiceInputDate.SetFocus;
    Abort;
  end;
  try
    DateSeparator:='.';
    Shortdateformat:='yyyy.mm.dd';
    StrToDate(Medt_ApInvoicedate.Text);
  except
    DispInfo('   日期非法!  ',1);
    Medt_ApInvoicedate.SetFocus;
    Abort;
  end;
  Edt_ApInvoiceAmountExit(Sender);
  Edt_ApInvoiceTaxExit(sender);
  Edt_ApInvoiceNoTaxExit(sender);
  if ApCheckout(copy(Trim(Medt_ApInvoiceInputDate.text),1,7)) then
  begin
    Yearstr:=copy(Trim(Medt_ApInvoiceInputDate.text),1,4);
    if copy(Trim(Medt_ApInvoiceInputDate.text),6,1)='0' then
      Monthstr:=copy(Trim(Medt_ApInvoiceInputDate.text),7,1)
    else
      Monthstr:=copy(Trim(Medt_ApInvoiceInputDate.text),6,2);
    DispInfo(Yearstr+'年'+Monthstr+'月已经结账,不能再录入发票!',3) ;
    Medt_ApInvoiceInputDate.setfocus;
    abort;
  end;
  if curApMonth<>'' then
  begin
    newMonth:=copy(Trim(Medt_ApInvoiceInputDate.text),1,7);
    if newMonth>nextMonth(curApMonth) then
    begin
      DispInfo('不能跨月录入发票',3);
      exit;
    end;
  end;

  //对所有的控件进行检查
  for i:=0 to ControlCount-1 do
  begin//按OK按钮时进行全部检查
    if(not Controls[i].Enabled)then
      continue;
    if Controls[i] is TEdit then
    begin
      if Assigned(TEdit(Controls[i]).OnExit) then
        TEdit(Controls[i]).OnExit(Controls[i]);
    end
    else if Controls[i] is TMaskEdit then
    begin
      if Assigned(TMaskEdit(Controls[i]).OnExit) then
        TMaskEdit(Controls[i]).OnExit(Controls[i]);
    end
    else if Controls[i] is TCombobox then
    begin
      if Assigned(TCombobox(Controls[i]).OnExit) then
        TCombobox(Controls[i]).OnExit(Controls[i]);
    end
  end;
  if AdoQry_Main.IsEmpty  then
  begin
    DispInfo('没有行数据,不能保存!',1);
    Abort;
  end;
  AdoQry_Main.First;
  while not AdoQry_Main.eof do
  begin
    if  AdoQry_Main.fieldbyname ('InvBillfinchck').asinteger=1    then
      j:=j+1;
    AdoQry_Main.next;
  end;
  if j=0 then
  begin
    DispInfo('没有行数据,不能保存!',1);
    Abort;
  end;
  //开始事物
  DbConnect.beginTrans;
  try
    IF HasPersave<>'' THEN
    begin
      if DispInfo('要暂存当前单据,必须删除以前的暂存当前单据.暂存当前单据吗?',2)='y' then
      begin
        //删除以前的暂存当前单据
        DeleteApInvoice(PerSaveApInvoiceNo);
      end
      else
       abort;
    end;
    flag:=3;    //设置暂存标志;
    //把发票的资料写入ApInvoice表中;
    SaveApInvoice;
    //把匹配的入库单据号写入ApInvoiceLine表中 ;
    InputInvInBillNoToApInvoice;
    //开始事物提交
    DbConnect.CommitTrans;
    if  (Trim(edit2.text)<>'') then
    begin
    end
    else
    begin
      edit2.text:='';
    end;
    flag:=0;
    DispInfo('暂存存盘成功!',3);
  except
    DbConnect.RollBackTrans;
    DispInfo('暂存存盘失败!',1);
    Abort;    //停止
  end;
  Listbox1.Items.clear;
  edit2.text:='';
  Label18.Caption:='0';
  GetPerSaveInvoiceBill(Trim(Edt_ApInvoiceNo.text));
  // GetFieldValue(Trim(Edt_ApInvoiceNo.text));
  ReadOnly(2);
  TLBtn_Save.Enabled:=False;
  TLBtn_PerSave.Enabled:=False;
  TLBtn_New.Enabled:=False;
  TLBtn_Delete.Enabled:=False;
  TLBtn_Qury.Enabled:=False;
  TlBtn_Cancel.Enabled:=False;
  Pnl_Hint.Caption :='';
end;

procedure TFrm_Ap_Invoice.DeleteApInvoice(ApInvoiceNo:string);
begin
  //删除ApInvoiceline;
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add('delete ApInvoiceline '+
            'from ApInvoiceLine  left join ApInvoice '+
            ' on ApInvoice.ApInvoiceId=ApInvoiceLine.ApInvoiceId');
    sql.Add('where ApInvoice.ApInvoiceNo='''+ApInvoiceNo+'''');
    execsql;
  end;
  //删除ApInvoice;
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add('delete  from ApInvoice ');
    sql.Add('where ApInvoice.ApInvoiceNo='''+ApInvoiceNo+'''');
    execsql;
  end;
end;

{procedure TFrm_Ap_Invoice.UpdatePerSaveInvInBill;
begin

end;}

function TFrm_Ap_Invoice.isequal: boolean;
var
  Total:Real ;// 发票中不含税金额 ;
  Sum1:Real  ;  //已匹配的单据金额之和;
begin
  //进行金额匹配的核对
  Total:=strtofloat((Edt_ApInvoiceAmount.text))-strtofloat((Edt_ApInvoiceTax.text));
  sum1:=0.00;
  //取得已经选中的总金额的总数
  AdoQry_Main.First;
  while not AdoQry_Main.Eof do
  begin
    if AdoQry_Main.fieldbyname('InvBillFinChck').asinteger=1 then
      sum1:=sum1+AdoQry_Main.fieldbyname('InvBillNoTaxAmount').asfloat;
    AdoQry_Main.Next;
  end;
  if (ErrRange-abs(sum1-Total)<0)  then
    Result:=False
  else
    Result:=True;
end;

procedure TFrm_Ap_Invoice.UnUpdateCurrentAp;
var
  Total:double;
begin
  //得到去掉税额的金额
  Total:=strtofloat((Edt_ApInvoiceAmount.text))-strtofloat((Edt_ApInvoiceTax.text));
  //更新当前应付款
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add('update CurrentAp '+
            'set ApInvoiced=ApInvoiced-('+FloatTostr(Total)+'), '+
            '    ApNoInvoice=ApNoInvoice+'+FloatTostr(Total)+' '+
            'where CurrentAp.VendorCode='''+Trim(ExtEdt_VendorCode.text)+''' ');
    execsql;
  end;
end;

function TFrm_Ap_Invoice.IsPrePay: double;
begin
  Result:=0.00;
  With AdoQry_Tmp do
  begin
    Close;
    Sql.clear;
    Sql.Add ('Select  ApInvoiced '+
                      ' From CurrentAp '+
                      ' where VendorCode='''+Trim(ExtEdt_VendorCode.text)+'''');
    Open;
    if fieldbyname('ApInvoiced').AsFloat>=0.00 then
    {Sql.Add ('Select  ApSumPayed '+
                      ' From ApSum '+
                      ' where VendorCode='''+Trim(ExtEdt_VendorCode.text)+'''');
    Open;
    if fieldbyname('ApSumPayed').AsFloat>=0.00 then}

      Result:=0.00
    else
      Result:= fieldbyname('ApInvoiced').AsFloat;
  end;
end;

procedure TFrm_Ap_Invoice.MatchPay(VendorCodeS:string;CurrPay: real);
var
  Bill_Tmp_Qry:TAdoQuery;
  SQL_Txt,lc_PayId:string;
  Temp_var:real;
begin
  Temp_var:=0.0;
  Bill_tmp_Qry:=TAdoQuery.Create(nil);
  Bill_tmp_Qry.Connection:=AdoQry_Main.Connection;
  sql_Txt:='select PayJournal.PayJournalId as PayJournalId '
                   +',PayJournal.VendorCode as VendorCode '
                   +',PayJo

⌨️ 快捷键说明

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