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

📄 inv_purchinaudit_b.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
                            ' where whCode='''+getCode(lbl_WhCode.Caption)+''' and '+
                           '       ItemCode='''+fieldbyname('ItemCode').asstring+''''+
                           ' update AveragePrice '+
                           '  set AveragePrice=ApAmount/Apqty '+
                           ' where whCode='''+getCode(lbl_WhCode.Caption)+''' and '+
                           '       ItemCode='''+fieldbyname('ItemCode').asstring+'''');
        AdoQry_tmp.execsql;

        //更改InvBillline
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.clear;
        AdoQry_tmp.sql.Add('update InvInBillline'+
                              ' set InvBillnotaxPricec='+fieldbyname('InvBillnotaxPrice').asstring+','+
                                  ' InvBillnotaxAmountc='+fieldbyname('InvBillnotaxAmount').asstring+','+
                                  ' InvBillPricec='+fieldbyname('InvBillPrice').asstring+','+
                                  ' InvBillAmountc='+fieldbyname('InvBillAmount').asstring+','+
                                  ' InvBillnotaxPrice='+fieldbyname('InvBillnotaxPrice').asstring+'*'+fExchRate+','+
                                  ' InvBillnotaxAmount=round('+fieldbyname('InvBillnotaxAmount').asstring+'*'+fExchRate+',2),'+
                                  ' InvBillPrice='+fieldbyname('InvBillPrice').asstring+'*'+fExchRate+','+
                                  ' InvBillAmount=round('+fieldbyname('InvBillAmount').asstring+'*'+fExchRate+',2)'+
                            ' where InvBillid='+fieldbyname('InvBillid').asstring+
                            '   and InvBilllineno='+fieldbyname('InvBilllineno').asstring);
        AdoQry_tmp.ExecSQL;
        Amount:=Amount+fieldbyname('InvBillAmount').asfloat;
        next;
      end;
    end;

    //如果外协加工
    if BillTypeCode='0103' then
    begin
      //取当前单据号的后一单
      Billno:= copy( Trim(AdoQry_Head.fieldbyname('InvBillno').asstring),1,5)+
              copy(inttostr(100001+strtoint(copy(Trim(AdoQry_Head.fieldbyname('InvBillno').asstring),length(Trim(AdoQry_Head.fieldbyname('InvBillno').asstring))-4,5))),2,5);

      with AdoQry_tmp do
      begin
        Close;
        sql.clear;
        sql.Add('select InvBillid '+
                ' from InvInBill '+
                ' where whCode='''+getCode(lbl_WhCode.Caption)+''' and '+
                '       InvBillno='''+Billno+'''');
        open;
        Billid:=fieldbyname('InvBillid').asstring;
      end;


      //更新OPBill数据表的单价,金额
      with AdoQry_tmp do
      begin
        Close;
        sql.clear;
        sql.Add('update opBill '+
                '   set opBillnotaxPrice=opAp.opAveragePrice, '+
                      ' opBillnotaxAmount=round(opAp.opAveragePrice*opBill.opBillqty,2) '+
                ' from opAveragePrice opAp '+
                ' where opAp.VendorCode='''+getCode(lbl_Vendor.Caption)+''' and '+
                      ' opAp.ItemCode=opBill.ItemCode and '+
                      ' opBill.InvBillid='+Billid);
        execsql;
      end;
      //更新OPAveragePRICE数据表,供应商的移动加权平均价

      with AdoQry_tmp do
      begin
        Close;
        sql.clear;
        sql.Add(' update opAveragePrice set '+
                '   opApqty=opApqty-opb.qty, '+
                '   opApAmount=opApAmount-opb.Amount '+
                ' from (select ItemCode,sum(opBillqty) as qty,sum(opBillnotaxAmount) as Amount '+
                       ' from opBill where InvBillid='+Billid+
                       ' group by ItemCode) opb '+
                ' where opAveragePrice.VendorCode='''+getCode(lbl_Vendor.Caption)+''' and '+
                     '  opAveragePrice.ItemCode=opb.ItemCode ');

        execsql;
      end;
      //计算材料费  InvBillline
      with AdoQry_tmp do
      begin
        Close;
        sql.clear;
        sql.Add('update InvInBillline set '+
                  ' InvBillnotaxAmount=opb.Amount '+
                'from (select InvBillid,InvBilllineno,sum(opBillnotaxAmount) as Amount '+
                      ' from opBill '+
                      'where InvBillid='+Billid+
                      '  group by InvBillid,InvBilllineno ) opb '+
                ' where InvInBillline.InvBillid=opb.InvBillid '+
                '   and InvInBillline.InvBilllineno= opb.InvBilllineno ');

        execsql;
      end;
      //更新本厂的移动加权平均

      with AdoQry_tmp do
      begin
        Close;
        sql.clear;
        sql.Add('update AveragePrice set '+
                 ' ApAmount=ApAmount+l.Amount,'+
                 ' AveragePrice='+
                 ' case '+
                 '   when Apqty=0 then 0 '+
                 '   else (ApAmount+l.Amount)/Apqty '+
                 ' end '+
                 'from (select ItemCode,sum(InvBillnotaxAmount) as Amount '+
                        ' from InvInBillline '+
                        ' where InvBillid='+Billid+
                        '   group by ItemCode) l '+
                 ' where AveragePrice.whCode='''+getCode(lbl_WhCode.Caption)+''' and '+
                      '  AveragePrice.ItemCode=l.ItemCode ');
        execsql;
      end;
    end;

    //更改当前应付款
    if BillTypeCode='0102' then
      currency:=getCode(lbl_Currency.Caption)
    else
      currency:='00';



    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.Add('if not exists (select VendorCode '+
                              ' from CurrentAp '+
                              ' where VendorCode='''+getCode(lbl_Vendor.Caption)+''' and '+
                                   '  currencyCode='''+currency+''') '+
              ' insert CurrentAp(VendorCode,currencyCode) '+
                        ' Values('''+getCode(lbl_Vendor.Caption)+''','''+currency+''') '+
              ' update CurrentAp '+
              '    set ApNoInvoice=ApNoInvoice+'+floattostr(round(Amount*100)/100)+
              ' where VendorCode='''+getCode(lbl_Vendor.Caption)+''' and '+
              '       currencyCode='''+currency+'''');
       execsql;
    end;
    //存盘成功
    AdoQry_Body.Connection.CommitTrans;
    //状态控制--------------------
    act_Save.enabled:=False;
    act_Modify.enabled:=False;
    AdoQry_Head.edit;
    AdoQry_Head.fieldbyname('InvBillwhchck').asinteger:=1;
    //--------------
  except
    begin
      AdoQry_Body.Connection.RollBackTrans;
      DispInfo(' 存盘不成功,请稍后再试! ',1);
    end;
  end;
end;



procedure TFrm_Inv_PurchInAudit_B.Act_QuitExecute(Sender: TObject);
begin
//  inherited;
  Close;
end;

procedure TFrm_Inv_PurchInAudit_B.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
 { if(Act_Save.Enabled)then
  begin
    if(DispInfo('数据有改动,需要保存吗?',2)='y')then
    begin
      Act_SaveExecute(Sender);
      Self.ModalResult:=mrOk;
    end
    else
    begin
      if(AdoQry_Head.State in [dsInsert,dsEdit])then
        AdoQry_Head.Cancel;
      Self.ModalResult:=mrCancel;
    end;
  end
  else
  begin
    if(AdoQry_Head.State in [dsInsert,dsEdit])then
      AdoQry_Head.Cancel;
    Self.ModalResult:=mrOk;
  end;}
end;

procedure TFrm_Inv_PurchInAudit_B.Extedt_InvBilltaxrateExit(
  Sender: TObject);
var
  InvBilltaxrate,InvBillqty,InvBillPrice,InvBillAmount,InvBillnotaxPrice,InvBillnotaxAmount:real;
begin
  inherited;
  floatcheck(sender);
  InvBillqty:=0.0;
  InvBillPrice:=0.0;
  InvBillAmount:=0;
  InvBillnotaxPrice:=0.0;
  InvBillnotaxAmount:=0.0;
  InvBilltaxrate:=strtofloat(Extedt_InvBilltaxrate.text);
  if (oldInvBilltaxrate<>Extedt_InvBilltaxrate.text) then
  begin
    if DispInfo('税率改变,将改变含税价及含税金额,真的要更改吗?',2)='y' then
    with AdoQry_Body do
    begin
      disablecontrols;
      First;
      while not eof do
      begin
              //数量
        InvBillqty:=fieldbyname('InvBillqty').asfloat;
          //含税金额
           {  如果输入含税金额,则
           含税单价=含税金额/数量
           不含税金额=含税金额/(1+税率/100)
           不含税单价=不含税金额/数量}
        InvBillAmount:=fieldbyname('InvBillAmount').asfloat;
        //含税单价
        InvBillPrice:=InvBillAmount/InvBillqty;

        //不含税金额
        InvBillnotaxAmount:=round(InvBillAmount/(1+InvBilltaxrate/100)*100)/100;
        //不含税单价
        InvBillnotaxPrice:=InvBillnotaxAmount/InvBillqty;

        edit;
        fieldbyname('InvBillPrice').asfloat:=InvBillPrice;
        fieldbyname('InvBillnotaxAmount').asfloat:=InvBillnotaxAmount;
        fieldbyname('InvBillnotaxPrice').asfloat:=InvBillnotaxPrice;
        next;
      end;
      First;
      enablecontrols;
      oldInvBilltaxrate:=Extedt_InvBilltaxrate.text;
      twincontrol(sender).setfocus;
    end
    else
    begin
      twincontrol(sender).setfocus;
    end
  end;
end;

procedure TFrm_Inv_PurchInAudit_B.FormActivate(Sender: TObject);
begin
  inherited;
  if BillTypeCode='0101' then
  begin
    Caption:='采购入库核价';
    pnl_title.Caption:='采购入库核价';
  end
  else if BillTypeCode='0102' then
  begin
    Caption:='进口采购入库核价';
    pnl_title.Caption:='进口采购入库核价';
  end
  else
  begin
    Caption:='委外加工入库核价';
    pnl_title.Caption:='委外加工入库核价';
  end;

    if status='ReadOnly' then
    act_Save.enabled:=False
  else
    act_Save.Enabled:=True;
end;

procedure TFrm_Inv_PurchInAudit_B.Act_SaveExecute(Sender: TObject);
begin
  inherited;
  Extedt_memo.Enabled :=False;
  Extedt_InvBilltaxrate.Enabled :=False;
end;

procedure TFrm_Inv_PurchInAudit_B.Act_PreviewExecute(Sender: TObject);
begin
//  inherited;
   if ((BillTypeCode='0102') and (GetCode(lbl_Currency.Caption)<>'00')) then
  begin
    try
      with TFrm_Inv_PurchaseIn_P_CC.Create(self) do
      begin
        showmodal;
        if modalResult=mrok then
        begin
          if RadioGroupprint.ItemIndex=0 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,True,False,True,'');
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,True,False,True,'C');
          end;

          if RadioGroupprint.ItemIndex=1 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,True,False,True,'');
          end;

          if RadioGroupprint.ItemIndex=2 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,True,False,True,'C');
          end;
        end;
      end;
    finally
      Frm_Inv_PurchaseIn_P_CC.Free;
    end;
  end
  else
    if (BillTypeCode='0103') then
        try
      with TFrm_Inv_PurchaseIn_P_OO.Create(self) do
      begin
        showmodal;
        if modalResult=mrok then
        begin
          if RadioGroupprint.ItemIndex=0 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,True,False,True,'');
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,True,False,True,'B');
          end;

          if RadioGroupprint.ItemIndex=1 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,True,False,True,'');
          end;

          if RadioGroupprint.ItemIndex=2 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,True,False,True,'B');
          end;
        end;
      end;
    finally
      Frm_Inv_PurchaseIn_P_CC.Free;
    end
    else
     begin
      BillPrint(AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption) ,Extedt_Billno.text,Param1,ModuleCode,True,False,True,'');
     end;
end;

procedure TFrm_Inv_PurchInAudit_B.Act_PrintExecute(Sender: TObject);
begin
//  inherited;
      if ((BillTypeCode='0102') and (GetCode(lbl_Currency.Caption)<>'00')) then
  begin
    try
      with TFrm_Inv_PurchaseIn_P_CC.Create(self) do
      begin
        showmodal;
        if modalResult=mrok then
        begin
          if RadioGroupprint.ItemIndex=0 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,False,False,True,'');
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,False,False,True,'C');
          end;

          if RadioGroupprint.ItemIndex=1 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,False,False,True,'');
          end;

          if RadioGroupprint.ItemIndex=2 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,False,False,True,'C');
          end;
        end;
      end;
    finally
      Frm_Inv_PurchaseIn_P_CC.Free;
    end;
  end
  else
    if (BillTypeCode='0103') then
        try
      with TFrm_Inv_PurchaseIn_P_OO.Create(self) do
      begin
        showmodal;
        if modalResult=mrok then
        begin
          if RadioGroupprint.ItemIndex=0 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,False,False,True,'');
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,False,False,True,'B');
          end;

          if RadioGroupprint.ItemIndex=1 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,False,False,True,'');
          end;

          if RadioGroupprint.ItemIndex=2 then
          begin
            BillPrint(self.AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption),Extedt_Billno.text,Param1,ModuleCode,False,False,True,'B');
          end;
        end;
      end;
    finally
      Frm_Inv_PurchaseIn_P_CC.Free;
    end
    else
     begin
      BillPrint(AdoQry_Tmp.Connection,GetCode(lbl_WhCode.Caption) ,Extedt_Billno.text,Param1,ModuleCode,False,False,True,'');
     end;

end;

end.

⌨️ 快捷键说明

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