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

📄 ap_invoice.pas

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

procedure TFrm_Ap_Invoice.Act_LocateExecute(Sender: TObject);
begin
  inherited;
  TlBtn_Qury.enabled:=True;
end;

procedure TFrm_Ap_Invoice.FormShow(Sender: TObject);
begin
  inherited;
  TLBtn_Save.enabled:=False;
  TLBtn_PerSave.enabled:=False;  
  ReadOnly(2);
end;

procedure TFrm_Ap_Invoice.InputInvInBillNoToApInvoice;
var
  ApInvoiceId:String ;// 发票ID;
begin
  ApInvoiceId:=IntToStr(Lc_CurrApInvoiceId);
  AdoQry_Main.First;
  while not AdoQry_Main.Eof do
  begin
    if AdoQry_Main.fieldbyname('InvBillFinChck').asinteger=1 then
    begin
      //如果CHECED,则得到入库单的ID
      with AdoQry_Tmp do
      begin
        Close;
        Sql.clear ;
        Sql.Add('Select InvBillId '+
                'from InvInBill '+
                'where InvBillNo='''+AdoQry_Main.fieldbyname('InvBillNo').asstring+''' '+
                '  And whCode='''+GetCode(Trim(AdoQry_Main.fieldbyname('WHCodeName').asstring))+''' ' );
        open;
      end;
      if not AdoQry_Tmp.eof then
      begin
        //已经查到了入库单的ID
        with AdoQry_ApInvoiceline do
        begin
          Close;
          sql.clear;
          sql.Add('insert into ApInvoiceLine '+
                  ' (ApInvoiceId, '+
                  '  InvBillId) '+
                  'Values '+
                  '  ('+ApInvoiceId+', '+
                  '   '+IntToStr(AdoQry_Tmp.fieldbyname('InvBillId').AsInteger)+')');
          execsql;
        end;
      end;
    end;
    AdoQry_Main.next;
  end;
end;

procedure TFrm_Ap_Invoice.SaveApInvoice;
var
  i:integer;
begin
  i:=0;
  if  CmBx_ApInvoiceType.text='发票' then
    i:=0;
  if  CmBx_ApInvoiceType.text='收据' then
    i:=1;
  if (flag1<>1) and (flag=3)  and (i<>2) then
  //if (flag=3) and (i<>2) then
    i:=2;
  with AdoQry_ApInvoice do
  begin
    Close;
    sql.clear;
    sql.Add('set noCount on '+
            'insert into ApInvoice '+
            '  (ApInvoiceNo, '+
            '   ApInvoicedate, '+
            '   EmployeeCode, '+
            '   ApInvoiceInputDate, '+
            '   VendorCode, '+
            '   CurrencyCode, '+
            '   ExchRate,'+
            '   ApInvoiceAmount, '+
            '   ApInvoiceTax, '+
            //'    ApPayedAmount,'+
            //'   ApPayFlag,'+
            '   ApInvoiceAmountc,'+
            '   ApInvoiceTaxc,'+
            '   ApInvoiceType ,'+
            '   ApInvoiceRemArk) '+
            'Values '+
            '  ('''+Trim(Edt_ApInvoiceNo.text)+''', '+
            '   '''+Trim(Medt_ApInvoicedate.text)+''', '+
            '   '''+Trim(Lbl_EmployeeCode.text)+''','+
            '   '''+Trim(Medt_ApInvoiceInputDate.text)+''','+
            '   '''+Trim(ExtEdt_VendorCode.text)+''','+
            '   '''+Trim(Lbl_CurrencyCode.text)+''','+
            floattostr(ExchRate)+','+
            '   '+Edt_ApInvoiceAmount.text+','+
            '   '+Trim(Edt_ApInvoiceTax.text)+','+
            //' 0,'+
            //'0,'+
            floattostr(strtofloat(Trim(Edt_ApInvoiceAmount.text))*ExchRate)+','+
            floattostr(strtofloat(Trim(Edt_ApInvoiceTax.Text))*ExchRate)+','+

            ' '''+inttostr(i)+''', '+
            '   '''+Trim(Edt_ApInvoiceRemArk.text)+''') '+
            'SELECT @@IDENTITY AS CurrIdentity '+
            '');
    open;
    if not eof then
    begin
      //取得存盘后的ID
      Lc_CurrApInvoiceId:=fieldbyname('CurrIdentity').AsInteger;
    end;
    Close;
  end;
end;

procedure TFrm_Ap_Invoice.UpdateCurrentAp;
var
  Total:double;
  sqlstr:string;
  I:integer;
begin
  i:=0;
  //得到总金额
  Total:=strtofloat((Edt_ApInvoiceAmount.text));
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select Count(*) as a from CurrentAp '
            +'where VendorCode='''+Trim(ExtEdt_VendorCode.text)+''' ');
    open;
    i:=fieldbyname('a').asinteger;
    Close;
  end;
  //更新当前应付款
  if i=0 then
  begin
    sqlstr:='insert into CurrentAp (VendorCode,CurrencyCode)'
            +'select VendorCode ,CurrencyCode '
            +'from Vendor where VendorCode='''+Trim(ExtEdt_VendorCode.text)+''' ';
  end
  else
  begin
    sqlstr:='update CurrentAp '+
              'set ApInvoiced=ApInvoiced+'+FloatTostr(Total)+', '+
              '    ApNoInvoice=ApNoInvoice-('+FloatTostr(Total)+') '+
              'where CurrentAp.VendorCode='''+Trim(ExtEdt_VendorCode.text)+''' ';
  end;
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add(sqlstr);
    execsql;
  end;
end;

procedure TFrm_Ap_Invoice.UpdateInvInBill;
var
  i:integer;
begin
  i:=1;
  //if flag=4 then
  //  i:=2;
  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='''+inttostr(i)+''' '+
                '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.Edt_ApInvoiceTaxExit(Sender: TObject);
begin
  if (activecontrol.Name ='TlBtn_Cancel') or (activecontrol.Name ='TlBtn_Exit') then
    abort;
  if Flag=1 then
  begin
    try
      strtofloat(Trim(Edt_ApInvoiceTax.text));
      Edt_ApInvoiceAmount.text:=formatfloat('0.##',strtofloat(Trim(Edt_ApInvoiceNoTax.text))
                              +strtofloat(Trim(Edt_ApInvoiceTax.text))) ;
     { if fisrt<>0 then
        Lbl_Diff.Caption:= floattostr(strtofloat(Edt_ApInvoiceNoTax.text)-strtofloat(Trim(Label18.Caption)));
     // clcaAp;
     fisrt:=fisrt+1;}
    except
      DispInfo('  '+'输入数据非法!'+'  ',1);
      Edt_ApInvoiceTax.setfocus;
      abort;
    end;
  end;
  inherited;
end;

procedure TFrm_Ap_Invoice.Act_CancelExecute(Sender: TObject);
begin
  inherited;
  if  DispInfo('取消此操作吗?',2)='y' then
  begin
    if (isperSaveBillNo(Trim(Edt_ApInvoiceNo.text)) and (Trim(Edt_ApInvoiceNo.text)<>'')) then
    begin
        if  DispInfo('删除此张暂存发票吗?',2)='y' then
        begin
          if  not DbConnect.InTransaction then
            DbConnect.beginTrans ;
          try
            //判断此发票是否为暂存票据;
            DeleteApInvoice(Trim(Edt_ApInvoiceNo.text));
            DbConnect.CommitTrans;
            DispInfo('删除成功!',3);
            flag:=0;
            Listbox1.clear;
            Label18.Caption:='0';
            Lbl_Diff.Caption:='0';
            Pnl_Hint.Caption:='';
          except
            DbConnect.RollBackTrans ;
            DispInfo('删除失败!',1);
            abort;
          end;
        end;
    end;
    ReadOnly(2);
    GetFieldValue('');
    clearedit;
    TlBtn_New.enabled:=True;
    TLBtn_Save.enabled:=False;
    TLBtn_PerSave.enabled:=False;
    TlBtn_Delete.enabled:=False;
    TlBtn_Qury.Enabled:=True;
    TlBtn_Cancel.Enabled:=False;
    tlbtn_look.enabled:=False;
    Pnl_Hint.Caption:='';
    flag:=0;
    Label18.Caption:='0';
    Listbox1.Items.clear;
    edit2.text:='';
    dbgrideh1.setfocus;
  end;
end;

procedure TFrm_Ap_Invoice.ReadOnly(I:integer);
begin
  case i of
    1: begin
        Edt_ApInvoiceNo.ReadOnly:=False;
        Medt_ApInvoiceDate.Enabled:=True;
        //Lbl_EmployeeCode.ReadOnly:=False;
        Medt_ApInvoiceInputDate.Enabled:=True;
        ExtEdt_VendorCode.Enabled:=True;
        ExtEdt_VendorCode.ReadOnly:=False;
        //Lbl_CurrencyCode.ReadOnly:=False;
        Edt_ApInvoiceNoTax.ReadOnly :=False;
        Edt_ApInvoiceAmount.ReadOnly:=False;
        Edt_ApInvoiceTax.ReadOnly:=False;
        Edt_ApInvoiceRemArk.ReadOnly:=False;
        CmBx_ApInvoiceType.Enabled :=True;
        Dbgrideh1.ReadOnly :=False;
        Listbox1.Enabled :=True;
        edit2.ReadOnly :=False;
      end;
    2:begin
        Edt_ApInvoiceNo.ReadOnly:=True;
        Medt_ApInvoiceDate.enabled:=False;
        //Lbl_EmployeeCode.ReadOnly:=True;
        Medt_ApInvoiceInputDate.enabled:=False;
        ExtEdt_VendorCode.enabled:=False;
        //Lbl_CurrencyCode.ReadOnly:=True;
        Edt_ApInvoiceNoTax.ReadOnly :=True;
        Edt_ApInvoiceAmount.ReadOnly:=True;
        Edt_ApInvoiceTax.ReadOnly:=True;
        Edt_ApInvoiceRemArk.ReadOnly:=True;
        CmBx_ApInvoiceType.Enabled :=False;
        Dbgrideh1.ReadOnly :=True;
        Listbox1.Enabled :=True;
        edit2.ReadOnly :=True;
      end;
  end;
end;

procedure TFrm_Ap_Invoice.GetNoInvoiceBill;
begin
  with AdoQry_Main do
  begin

    Close;
    sql.clear;
    sql.Add('select InvInBill.WhCode+'' ''+ Warehouse.WHName  as whCodeName ,'+
                    ' InvInBill.InvBillid as InvBillid ,'+
                    ' InvInBill.InvBillDate,'+
                    ' InvInBill.InvBillNo  , '+
                    ' sum(isnull(InvInBillLine.InvBillNoTaxAmountc,0)) as InvBillNoTaxAmount ,'+
                    ' InvInBill.InvBillFinChck '+
                    ' from InvInBill left join  Warehouse '+
                    '   on InvInBill.WhCode=Warehouse.WhCode '+
                    ' left join InvInBillLine '+
                    '   on InvInBill.InvBillid=InvInBillLine.InvBillid '+
                    ' where InvInBill.VendorCode='''+Trim(ExtEdt_VendorCode.text)+''''+
                    '   and ((InvInBill.BillTypeCode =''0101'' )' +
                    '   or (InvInBill.BillTypeCode=''0103'' )' +
                    '   or (InvInBill.BillTypeCode=''0102'' )' +
                    '   or ( (BillTypeCode=''0199'' )  and InvInBill.BillType2Code in ( select BillType2Code from BillType2 where ChangeAp=1  ) and InvInBill.VendorCode is  not null  ))'+
                    //' and InvInBill.InvBillStkChck=1 ' +           //已核价
                    '   and InvInBill.InvBillValuation<>1' +         //非暂估价
                    '   and InvInBill.InvBillFinChck<>1'+             //未开发票
                    '   group by InvInBill.WhCode+'' ''+ Warehouse.WHName,InvInBill.InvBillid ,Warehouse.WHName,InvInBill.InvBillDate,InvInBill.InvBillNo,InvInBill.VendorCode,InvInBill.InvBillFinChck '+
                    ' Order by InvInBill.WhCode+'' ''+ Warehouse.WHName,InvInBill.InvBillNo');
    open;

    if AdoQry_Main.recordCount= 0 then
    begin
      Edt_ApInvoiceAmount.text:='0';
      Edt_ApInvoiceTax.text:='0';
      Edt_ApInvoiceRemArk.text:='';
      Edt_ApInvoiceNoTax.text:='0';
      Label18.Caption:='0';
      Lbl_Diff.Caption:='0';
      Listbox1.Items.clear;
      edit2.text:='';
      DispInfo('没有入库单!',3);
      ExtEdt_VendorCode.setfocus;
      abort;
    end;
    Pnl_Hint.Caption:='提示:入库单的行数:'+Inttostr(AdoQry_Main.recordCount);
    //Lbl_CurrencyCode.enabled:=False;
    tlbtn_look.enabled:=(AdoQry_Main.recordCount>0);
  end;
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add(' select Vendor.VendorName,'+
                    ' Vendor.CurrencyCode,'+
                    ' Vendor.VendorTaxRate_Percent ,'+
                    ' Currency.CurrencyName '+
                    ' from Vendor left  join Currency '+
                    '   on Vendor.CurrencyCode= Currency.CurrencyCode '+
                    ' where Vendor.VendorCode='''+Trim(ExtEdt_VendorCode.text)+'''');
    open;
    TaxRate_Percent:= fieldbyname('VendorTaxRate_Percent').asinteger;
    Lbl_VendorName.text:=fieldbyname('VendorName').asstring;
    Lbl_CurrencyCode.text:=fieldbyname('CurrencyCode').asstring;
    Lbl_CurrencyName.text:=fieldbyname('CurrencyName').asstring;
    Lbl_TaxRate_Percent.text:=inttostr(fieldbyname('VendorTaxRate_Percent').asinteger);
    Close;
  end;
end;

procedure TFrm_Ap_Invoice.GetCurrencyName(Sender: TObject);
begin
  inherited;
  GetNoInvoiceBill;
end;

procedure TFrm_Ap_Invoice.VendorCodeCheck(Sender: TObject);
begin
  inherited;
  GetNoInvoiceBill;
end;

procedure TFrm_Ap_Invoice.clcaAp;
begin
  if (Trim(Edt_ApInvoiceAmount.text)<>'') and (Trim(Edt_ApInvoicetax.text)<>'') then
    Edt_ApInvoiceNoTax.text:=formatfloat('0.##',strtofloat(Trim(Edt_ApInvoiceAmount.text))
                              -strtofloat(Trim(Edt_ApInvoiceTax.text))) ;
  if (Trim(Edt_ApInvoiceAmount.text)<>'') and (Trim(Edt_ApInvoiceNotax.text)<>'') then
    Edt_ApInvoiceTax.text:=formatfloat('0.##',strtofloat(Trim(Edt_ApInvoiceAmount.text))
                              -strtofloat(Trim(Edt_ApInvoiceNoTax.text))) ;
  if (Trim(Edt_ApInvoiceNoTax.text)<>'') and (Trim(Edt_ApInvoicetax.text)<>'') then
    Edt_ApInvoiceAmount.text:=formatfloat('0.##',strtofloat(Trim(Edt_ApInvoiceNoTax.text))
                              +strtofloat(Trim(Edt_ApInvoiceTax.text))) ;

end;

procedure TFrm_Ap_Invoice.Edt_ApInvoiceAmountExit(Sender: TObject);
begin
  if (activecontrol.Name ='TlBtn_Cancel') or (activecontrol.Name ='TlBtn_Exit') then
    abort;
  if Flag=1 then
  begin
    if length(Trim(Edt_ApInvoiceAmount.text))=0 then
    begin

⌨️ 快捷键说明

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