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

📄 inv_enter_homemadeckinvin.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  CurrencyCode{币种..进口入库时用},PoTaxRate_Percent{税率},
  fExchRate,Bill_Id,Bill_Id_0103,DispStr,Tempstr:string;
  Bill_LineNo,i:Integer;
  AdoQry_Tmp1:TAdoQuery;
  NeedChangePrice:Boolean;
begin
  inherited;
  PoTaxRate_Percent:='0';
  DBGridEhColExit(dbgrideh);
  if Edt_PoNO.Enabled=False then
    Edt_PoNO.Enabled :=True;
  PoCodeCheck(Edt_PoNO);
  Edt_PoNO.Enabled:=False ;
  fExchRate:='1';
  CurrencyCode:='00';
  DispStr:='单据保存失败,请稍后再试';
  //先从PO中取出币种及税率
  DBGridEhColExit(DBGridEh);
  if AdoQry_Body.RecordCount=0 then
  begin
    DispStr:=' 新增的单据没有记录,不允许保存 ';
    DispInfo(DispStr,3) ;
    Abort;
  end;
  with AdoQry_Body do
  begin
    First;
    while not eof do
    begin
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=' select MoLineStatus from  MoLine '
        +' Where mONo='''+Trim(Edt_PoNO.Text)+''''
        +' And MoLineNo='+AdoQry_Body.fieldbyname('POLineNo').AsString ;

      AdoQry_Tmp.open;
      if AdoQry_Tmp.fieldbyname('MoLineStatus').asinteger=7  then
      begin
        DispInfo('生产订单号:'+Edt_PoNO.Text+'中'+AdoQry_Body.fieldbyname('POLineNo').AsString+
                  '已关闭不能入库!',3);
        abort;
      end;
      next;
    end;
    AdoQry_tmp.Close;
  end;
  AdoQry_Body.DisableControls ;
  DBConnect.beginTrans;
  try
    NeedChangePrice:=NeedChangeAveragePrice(AdoQry_Tmp,Copy(MEdt_BillDate.Text,1,7));
    if UpperCase(Param2)='Over' then
      OverPlan:='1'
    else
      OverPlan:='0';
    if(Status<>'Add')and(not FFromCheckIn)then
    begin
    end
    else
    begin
      //begin--------------------------------------------
      Bill_No:=GetNo(DBConnect,GetCode(CmBx_Warehouse.Text)+'R'
        +FormatDateTime('yymm',StrToDate(MEdt_BillDate.Text)),'InvBill');
      edt_Billno.Text:=Bill_No;
      if(not FFromCheckIn)then
      begin
        AdoQry_Head.fieldbyname('InvBillNo').AsString:=Bill_No;
        FromCheckIn:='0';
      end
      else
      begin
        FromCheckIn:='1';
      end;
      InvBillWHChck:='1';

      AdoQry_Tmp.Close;
      AdoQry_tmp.sql.clear;
      AdoQry_Tmp.SQL.Text:='Insert InvInBill'
        +'(InvBillNo,WHCode,InvBillDate,InvBillMonth,CurrencyCode,InvBillTaxRate'
        +',BillTypeCode,EmployeeCode,WH_EmployeeCode,DeptCode,WhPositionCode'
        +',moNo,InvBillWHChck,InvBillRemArk,FromCheckIn,OverPlan,VendorBillNo)'
        +' Values('
        +' '''+Bill_No+''''
        +','''+GetCode(CmBx_Warehouse.Text)+''''
        +','''+FormatDateTime('yyyy.mm.dd',StrToDate(MEdt_BillDate.Text))+''''
        +','''+FormatDateTime('yyyy.mm',StrToDate(MEdt_BillDate.Text))+''''
        +','''+CurrencyCode+''''
        +','+PoTaxRate_Percent
        +','''+Param1+''''
        +','''+UserCode+''''
        +','''+UserCode+''''
        +','''+ExtEdt_VendorCode.Text+''''
        +','''+GetCode(Cmbx_WhPosition.Text)+''''
        +','''+edt_Pono.Text+''''
        +','+InvBillwhchck
        +','''+Edt_RemArk.Text+''''
        +','+FromCheckIn
        +','+OverPlan
        +','''+Edt_VendorBillNo.Text+''''
        +')';
      AdoQry_Tmp.ExecSQL;
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:='Select @@identity as Bill_Id';
      AdoQry_Tmp.Open;
      Bill_Id:=AdoQry_Tmp.fieldbyname('Bill_Id').AsString;
    end;//更新库存标记
    ChangeInvStatus(AdoQry_Tmp,GetCode(CmBx_Warehouse.Text),
      FormatDateTime('yy.mm',StrToDate(MEdt_BillDate.Text)));

    AdoQry_Body.First;
    Bill_LineNo:=1;
    while(not AdoQry_Body.Eof)do
    begin
      //检查库存
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:='Insert InvInBillLine(InvBillId,InvBillLineNo'
        +',ItemCode,InvBillQty,MONO,MoLineNO,BillLineRemArk,BatchNo,InvBillSfcQty)'
        +' Values('
        +' '''+Bill_Id+''''
        +','+IntToStr(Bill_LineNo)+''
        +','''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''
        +','+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
        +','''+edt_Pono.Text+''''
        +','+AdoQry_Body.fieldbyname('PoLineNo').AsString+''
        +','''+AdoQry_Body.fieldbyname('BillLineRemArk').AsString+''''
        +','''+AdoQry_Body.fieldbyname('BatchNo').AsString+''''
        +','''+AdoQry_Body.fieldbyname('InvBillSfcQty').AsString+''''
        +')';
      AdoQry_Tmp.ExecSQL;

      Tempstr:=UpdateInv(AdoQry_Tmp,GetCode(CmBx_Warehouse.Text),
        GetCode(Cmbx_WhPosition.Text),
        AdoQry_Body.fieldbyname('ItemCode').AsString,
        AdoQry_Body.fieldbyname('InvBillQty').AsString,
        NeedChangePrice,True);
      if Tempstr<>'' then
      begin
        DispStr:=Tempstr;
        Abort;
      end;
      //批次处理
      if AdoQry_Body.fieldbyname('BatchNo').AsString<>'' then
      begin
        if not BatchInvCheck(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
          'R',GetCode(CmBx_Warehouse.Text),GetCode(Cmbx_WhPosition.Text),
          AdoQry_Body.fieldbyname('InvBillQty').AsFloat)then
          Abort;
        ChangeBatchInv(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
          'R',MEdt_BillDate.Text,GetCode(CmBx_Warehouse.Text),
          GetCode(Cmbx_WhPosition.Text),
          AdoQry_Body.fieldbyname('InvBillQty').AsFloat);
      end;
      //更改MNItemList的记录
      AdoQry_tmp.Close;
      AdoQry_tmp.sql.clear;
      AdoQry_tmp.sql.text:=
        'update MoLine '+
        '  set MoRealInQty=MoRealInqty+'+AdoQry_Body.fieldbyname('InvBillQty').asstring+
        '     ,MoNoFinishQty=MoNoFinishQty-('+AdoQry_Body.fieldbyname('InvBillQty').Asstring+') '+
        ' where mono='''+Edt_PoNO.text+''' and '+
        '       MoLineno='+AdoQry_Body.fieldbyname('poLineNo').asstring+' and '+
        '       ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').asstring+'''';
      AdoQry_tmp.execsql;
      //生产采购订单过程调用,参数说明:P1:AdoQuery控件名称,P2: 业务类型:POCheck:待检入库;POIN:采购入库;MoIn:生产入库
      //P3:订单号 MONO或PONO,P4:订单行号 MoLineNo或POLineNo
      MOPOOperation(AdoQry_tmp,'MoIn',Edt_PoNO.text,AdoQry_Body.fieldbyname('polineno').asinteger);

      { --------------------------------------------------------------
       单据保存时,会判断MoLine的MoRealInQty是否超过MOQty,
       如果是,则关闭该订单行,即MoLineStatus=7
       现在改成  从MrpParam表中读取参数,如果用户定义为自动
       关闭,则执行以上的操作,否则什么都不做
       select MrpParamValueN from MrpParam where MrpParamCode='autoCloseMo',
       如果=1表示自动关闭,=0表示手工关闭
       ---------------------------------------------------------------}
      AdoQry_tmp.Close;
      AdoQry_tmp.sql.clear;
      AdoQry_tmp.SQL.text:=
        ' select MrpParamValueN from MrpParam where MrpParamCode=''autoCloseMo''';
      AdoQry_tmp.open;
      if AdoQry_tmp.fieldbyname('MrpParamValueN').Asinteger=1 then
      begin
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.clear;
        AdoQry_tmp.SQL.text:=
        'update MoLine set MoLineStatus=7 where MONo='''+Edt_PoNO.text+''''+
           'and MoLineNo='+AdoQry_Body.fieldbyname('poLineNo').asstring+
           'and ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').asstring+''''+
           'and MoNoFinishQty<=0';
        AdoQry_tmp.execsql;
      end;
      AdoQry_tmp.Close;
      AdoQry_tmp.sql.text:=' select BackFlush from MoLine '+
                          ' where MONo='''+Edt_PoNO.text+''''+
                          ' and MoLineNo='+AdoQry_Body.fieldbyname('poLineNo').asstring;
      AdoQry_tmp.Open ;

      if AdoQry_tmp.fieldbyname('BackFlush').asinteger=1 then
      begin
        If Not MoInBackFlush(AdoQry_Body.Connection,
                             Edt_PoNO.text,
                             UserCode,MEdt_BillDate.Text,' ',
                             AdoQry_Body.fieldbyname('polineno').asInteger,
                             AdoQry_Body.fieldbyname('InvBillQty').asfloat) then
        abort;
      end;

      AdoQry_Body.Next;
      Bill_LineNo:=Bill_LineNo+1;
    end;

    if FFromCheckIn then
    begin
      if AdoQry_Head.State<>dsBrowse then
        AdoQry_Head.Post;
      AdoQry_Head.First;
      for i:=0 to AdoQry_Head.RecordCount-1 do
      begin
        if AdoQry_Head.fieldbyname('ReceiveStatus').AsInteger=1 then
        begin
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:='Update OnCheckBillLine'
            +' Set OnCheckStatus=1'
            +' Where OnCheckBillId='+AdoQry_Head.fieldbyname('OnCheckBillId').AsString
            +' And OnCheckBillLineNo='''+AdoQry_Head.fieldbyname('OnCheckBillLIneNo').AsString+'''';
          AdoQry_Tmp.ExecSql;

          Tempstr:=UpdateInv(AdoQry_Tmp,AdoQry_Head.fieldbyname('WHCode').AsString,
            AdoQry_Head.fieldbyname('WhPositionCode').AsString,
            AdoQry_Head.fieldbyname('ItemCode').AsString,
            '(-('+AdoQry_Head.fieldbyname('OnCheckQty').AsString+'))',
            NeedChangePrice,True);
          if Tempstr<>'' then
          begin
            DispStr:=Tempstr;
            Abort;
          end;
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:='Update MoLine Set'
            +' MoOnCheckQty=MoOnCheckQty-('+AdoQry_Head.fieldbyname('OnCheckQty').AsString+')'
            +' Where mONo='''+Edt_PoNO.Text+''''
            +' And MoLineNo='+AdoQry_Head.fieldbyname('POLineNo').AsString;
          AdoQry_Tmp.ExecSql;
         //判断是否关闭了待检单
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:='select OnCheckStatus from OnCheckBillLine'
            +' Where OnCheckBillId='+AdoQry_Head.fieldbyname('OnCheckBillId').AsString
            +' And OnCheckBillLineNo='''+AdoQry_Head.fieldbyname('OnCheckBillLIneNo').AsString+'''';
          AdoQry_Tmp.open;
          if AdoQry_Tmp.fieldbyname('OnCheckStatus').AsInteger<>1 then
          begin
             DispInfo('待检单:'+AdoQry_Head.fieldbyname('OnCheckBillId').AsString+',行号: '
             +AdoQry_Head.fieldbyname('OnCheckBillLIneNo').AsString+'没有关闭成功!,请联系软件提供者,谢谢!',1);
             DBConnect.RollBackTrans;
             Act_Save.Enabled:=False;
             DispInfo(DispStr,3);
             Abort;
          end;
        end;
        AdoQry_Head.Next;
      end;
      with AdoQry_Head do
      begin
        OldSort:=Sort;
        Close;
        Open;
        Sort:=OldSort;
        AdoQry_Head.Edit;
      end;
    end;
    //调用过程更改 Mrp 有关报表
    AdoQry_Body.First;
    while(not AdoQry_Body.Eof)do
    begin
      MOPOOperation(AdoQry_Tmp,'POIN',edt_Pono.Text,AdoQry_Body.fieldbyname('PoLineNo').AsInteger);
      AdoQry_Body.next;
    end;
    AdoQry_Body.First;

    //当PoLine中存在PoreferencedPrice=1的物料就为暂估价处理,
    //更新InvInBill中InvBillValuation=1
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.Text:='If Exists (Select PoLine.PoreferencedPrice'
      +' From InvInBillLine'
      +' Left Join PoLine On InvInBillLine.PoNo=PoLine.PoNo'
      +' And InvInBillLine.PoLineNo=PoLine.PoLineNo'
      +' And InvInBillLine.ItemCode=PoLine.ItemCode'
      +' Where InvInBillLine.InvBillId='+Bill_Id
      +' And PoLine.PoreferencedPrice=1)'
      +' Update InvInBill Set'
      +' InvBillValuation=1'
      +' Where InvBillId='+Bill_Id;
    AdoQry_Tmp.ExecSQL;

    //计算价格,金额,更新加权价
    AdoQry_Tmp1:=TAdoQuery.Create(nil);
    AdoQry_Tmp1.Connection:=DBConnect;
    AdoQry_Tmp1.EnableBCD:=False;
    AdoQry_Tmp1.Close;
    AdoQry_Tmp1.SQL.Text:='Select'
      +' InvInBillLine.InvBillId'
      +',InvInBillLine.InvBillLineNo'
      +',InvInBillLine.ItemCode'
      +',InvInBillLine.InvBillQty'
      +',PoLine.PoreferencedPrice'
      +',PoLine.PoTaxPrice As InvBillPrice'
      +',PoLine.PoNoTaxPrice As InvBillNoTaxPrice'
      +',PoLine.PoreferencedPrice'
      +' From InvInBillLine'
      +' Join PoLine on InvInBillLine.PoNo=PoLine.PoNo'
      +' And InvInBillLine.PoLineno=PoLine.PoLineno'
      +' And InvInBillLine.ItemCode=PoLine.ItemCode'
      +' Where InvInBillLine.InvBillId='+Bill_Id;
    AdoQry_Tmp1.Open;
    AdoQry_Tmp1.First;
    while not AdoQry_Tmp1.eof do
    begin
      //计算加权平均价
      if True then
      begin
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.clear;
        AdoQry_Tmp.SQL.Text:='If Not Exists (Select ApQty From AveragePrice'
          +' Where WHCode='''+GetCode(CmBx_Warehouse.Text)+''''
          +' And ItemCode='''+AdoQry_Tmp1.fieldbyname('ItemCode').AsString+''')'
          +' Insert AveragePrice(WHCode,ItemCode)'
          +' Values('

⌨️ 快捷键说明

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