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

📄 inv_enter_mounitmnrequestauditing1.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 5 页
字号:
            begin
              if tmp_reMain>0 then
              begin
                edit;
                fieldbyname('InvBillqty').asfloat:=tmp_reMain;
              end;
            end;
          end
          else
          begin
            if onhandInv<tmp_reMain then
            begin
              if BatchCtrl(AdoQry_tmp,fieldbyname('ItemCode').asstring) then
              begin
                //如果是批处理控制,则根据处入来的数量OUTQTY与批处理库存中最佳数量比效,
               //取最佳批次号
                outqty:=onhandInv;
                Batchno:=GiveBatchNo(AdoQry_tmp,
                        getCode(Cmbbx_WhCode.text),
                        getCode(cmbbx_WhPositionCode.text),
                        AdoQry_Body.fieldbyname('ItemCode').asstring,
                        medt_Date.text,
                        outqty,
                        AdoQry_Body.fieldbyname('Batchno').asstring);
                if Batchno='' then
                begin
                // edit;
                // fieldbyname('moRequestqty').asfloat:=0;
                end
                else
                begin
                  edit;
                  fieldbyname('InvBillqty').asfloat:=outqty;
                  fieldbyname('Batchno').asstring:=Batchno;
                end;
              end
              else
              begin
                edit;
                fieldbyname('InvBillqty').asfloat:=onhandInv;
              end;
            end
            else
            begin
              if tmp_reMain>0 then
              begin
                if BatchCtrl(AdoQry_tmp,fieldbyname('ItemCode').asstring) then
                begin
                  //如果是批处理控制,则根据处入来的数量OUTQTY与批处理库存中最佳数量比效,
                  //取最佳批次号
                  outqty:=tmp_reMain;
                  Batchno:=GiveBatchNo(AdoQry_tmp,
                          getCode(Cmbbx_WhCode.text),
                          getCode(cmbbx_WhPositionCode.text),
                          AdoQry_Body.fieldbyname('ItemCode').asstring,
                          medt_Date.text,
                          outqty,
                          AdoQry_Body.fieldbyname('Batchno').asstring);
                  if Batchno='' then
                  begin
                  // edit;
                  // fieldbyname('moRequestqty').asfloat:=0;
                  end
                  else
                  begin
                    edit;
                    fieldbyname('InvBillqty').asfloat:=outqty;
                    fieldbyname('Batchno').asstring:=Batchno;
                  end;
                end
                else
                begin
                  edit;
                  fieldbyname('InvBillqty').asfloat:=tmp_reMain;
                end;
              end;
            end;
          end;
        end;}
      end;
      end;
      next;
    end;
    First;
    enablecontrols;
  end;
end;


procedure TFrm_Inv_Enter_MoUnitMnRequestAuditing1.Act_CheckExecute(
  Sender: TObject);
var
  M,tmp_Backflush:integer;
  NeedChangePrice,BeforeSaveError:boolean;
  tmp_WhCode,tmp_WhPositionCode,tmp_fields:string;
  ThisRequestQty , TotalRequestQty:double;
  TmpAdoQry:TAdoQuery;
  sqltext:string;
  Change:boolean;
begin
  inherited;
  if AdoQry_Body.state<>dsBrowse then
    AdoQry_Body.post;
  DBGridEh.setfocus;
  //DBGridEhColExit(DBGridEh);
  Change:=False;
  with AdoQry_Body do
  begin
    First;
    while not eof do
    begin
      if fieldbyname('ThisRequestQty').ASfloat>=0.00 then
      begin
        Change:=True;
        break;
      end;
      next;
    end;
  end;
  if not Change  then
  begin
     DispInfo('至少要有一项物料的实领数量大于等于零!',3);
    abort;
  end;
  with AdoQry_Body do
  begin
    First;
    while not eof do
    begin
      checkcoCurrentqty;
      next;
    end;
  end;
  if medt_Date.enabled then
    medt_Date.onexit(medt_Date);
  tmp_WhCode:=getCode(cmbbx_WhCode.text);
  tmp_WhPositionCode:=getCode(cmbbx_WhPositionCode.text);
  TmpAdoQry:=TAdoQuery.Create(nil);
  TmpAdoQry.Connection :=AdoQry_tmp.Connection ;
  AdoQry_Body.DisableControls  ;
  //全面有效检查
  BeforeSaveError:=True;
  //检查日期、库存
  //增加一个变量,用于判断是否为拉式生产订单补退料
  {with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select BackFlush from MoLine '+
            '  where mono='''+AdoQry_Head.fieldbyname('mono').asstring+''''+
            '    and MoLineno='+AdoQry_Head.fieldbyname('MoLineno').asstring);
    open;
    tmp_Backflush:=fieldbyname('Backflush').asinteger;
  end;}

  NeedChangePrice:=NeedChangeAveragePrice(AdoQry_tmp,copy(MEdt_Date.text,1,7));
  AdoQry_Body.First;
  for M:=0 to AdoQry_Body.recordCount-1 do
  begin
    if AdoQry_Body.fieldbyname('ThisRequestQty').asstring<>'0' then
    begin
      if not InvQtyCheck
          (NeedChangePrice,
          AdoQry_Body,
           AdoQry_tmp,
           getCode(Cmbbx_WhCode.text),
           getCode(cmbbx_WhPositionCode.text),
           AdoQry_Body.fieldbyname('ItemCode').asstring,
           'ThisRequestQty',
           AdoQry_Body.fieldbyname('ThisRequestQty').asfloat,
           False) then
        abort;
      if AdoQry_Body.fieldbyname('Batchno').asstring<>'' then
      begin
        if  not BatchInvCheck(AdoQry_tmp,
                              AdoQry_Body.fieldbyname('Batchno').asstring,
                              'C',
                              tmp_WhCode,
                              tmp_WhPositionCode,
                              AdoQry_Body.fieldbyname('ThisRequestQty').asfloat) then
          abort;
      end;
    end;
    AdoQry_Body.next;
  end;
    //真正开始存盘
  BeforeSaveError:=False;
  DBGridEh.Enabled :=False;
  AdoQry_Head.Connection.beginTrans;
  try
     //记录本仓库数据发生改变
    ChangeInvStatus(AdoQry_tmp,getCode(cmbbx_WhCode.text),copy(medt_Date.text,1,7));
     //更改InvInBill
    AdoQry_tmp.Close;
    AdoQry_tmp.sql.clear;
    AdoQry_tmp.sql.Add(
       'update InvOutBill set'+
       '  InvBilldate='''+medt_Date.text+''','+
       '  InvBillMonth='''+copy(medt_Date.text,1,7)+''','+
       '  InvBillwhchck=1,'+
       '  wh_EmployeeCode='''+userCode+''','+
       '  InvBillremArk='''+Extedt_memo.text+''''+
       ' where InvBillid='+InvBillid);
    AdoQry_tmp.execsql;

    with AdoQry_Body do
    begin
      First;
      for M:=0 to recordCount-1 do
      begin
        //对实领数量不为零的数据进行处理
        if fieldbyname('ThisRequestQty').asfloat<>0.0 then
        begin
          //如果是加权平均,则按加权平均计算
          if True then
          begin
          if PriceType=0 then
          begin
            AdoQry_tmp.Close;
            AdoQry_tmp.sql.clear;
            AdoQry_tmp.sql.Add(
              ' if not exists (select ItemCode from AveragePrice '+
                               ' where whCode='''+getCode(cmbbx_WhCode.text)+''''+
                                '  and ItemCode='''+fieldbyname('ItemCode').asstring+''')'+
              ' insert AveragePrice(whCode,ItemCode,Apqty) '+
              '   Values('''+getCode(cmbbx_WhCode.text)+''','+
                        ''''+fieldbyname('ItemCode').asstring+''','+
                        '-('+fieldbyname('ThisRequestQty').asstring+')) '+
              ' else '+
              ' update AveragePrice set '+
              '  Apqty=Apqty-('+fieldbyname('ThisRequestQty').asstring+'),'+
              //旧单价*新数量
              '  ApAmount=case when Apqty=0 then AveragePrice*(Apqty-('+fieldbyname('ThisRequestQty').asstring+')) '+
              '                else (ApAmount/Apqty)*(Apqty-('+fieldbyname('ThisRequestQty').asstring+')) end '+
              ' where whCode='''+getCode(Cmbbx_WhCode.text)+''''+
              '   and ItemCode='''+fieldbyname('ItemCode').asstring+'''');
            AdoQry_tmp.execsql;
          end;
        end;
        //更改当前库存  更改Item表的库存数据
        if UpdateInv(AdoQry_tmp,
                tmp_WhCode,
                tmp_WhPositionCode,
                AdoQry_Body.fieldbyname('ItemCode').asstring,
                '(-('+AdoQry_Body.fieldbyname('ThisRequestQty').asstring+'))',
                NeedChangePrice,True)<>'' then
          abort;

        //更改批次库存数量
        if fieldbyname('Batchno').asstring<>'' then
        begin
          ChangeBatchInv(AdoQry_tmp,fieldbyname('Batchno').asstring,'C',medt_Date.text,tmp_WhCode,tmp_WhPositionCode,AdoQry_Body.fieldbyname('ThisRequestQty').asfloat);
        end;
        TotalRequestQty := AdoQry_Body.fieldbyname('ThisRequestQty').AsFloat;
        If AdoQry_Body.fieldbyname('OnHandInv').AsFloat<TotalRequestQty Then
        TotalRequestQty := AdoQry_Body.fieldbyname('OnHandInv').AsFloat;
        ExecuteSQl(TmpAdoQry,'select * from '+tmpTable
                  +' where ItemCode='+QuotedStr(AdoQry_Body.fieldbyname('ItemCode').AsString)
                  +'   and IsTotal=0 ',0);
        TmpAdoQry.First;
        While Not TmpAdoQry.Eof do
        begin
          If TotalRequestQty=0 then Break;
          {If (TmpAdoQry.fieldbyname('MoRequestQty').AsFloat-TmpAdoQry.fieldbyname('MoRealQty').AsFloat) >= TotalRequestQty then
          begin
            ThisRequestQty := TotalRequestQty;
         //   TotalRequestQty := TotalRequestQty-TmpAdoQry.fieldbyname('MoCtrlQty').AsFloat;
            TotalRequestQty := 0;
          end
          else
          begin
            ThisRequestQty := TmpAdoQry.fieldbyname('MoRequestQty').AsFloat-TmpAdoQry.fieldbyname('MoRealQty').AsFloat;
            TotalRequestQty := TotalRequestQty-TmpAdoQry.fieldbyname('MoCtrlQty').AsFloat-TmpAdoQry.fieldbyname('MoRealQty').AsFloat;
          end;}
          //02.10.28
          If TmpAdoQry.fieldbyname('MoRequestQty').AsFloat>= TotalRequestQty then
          begin
            ThisRequestQty := TotalRequestQty;
            //TotalRequestQty := TotalRequestQty-TmpAdoQry.fieldbyname('MoCtrlQty').AsFloat;
            TotalRequestQty := 0;
          end
          else
          begin
            ThisRequestQty := TmpAdoQry.fieldbyname('MoRequestQty').AsFloat;
            TotalRequestQty := TotalRequestQty-ThisRequestQty;
          end; //02.10.28

          //更改InvOutBillline
          AdoQry_tmp.Close;
          AdoQry_tmp.sql.clear;
          AdoQry_tmp.sql.Add(
            'update InvOutBillline set '+
              //' BilllineremArk='''+AdoQry_Body.fieldbyname('remArk').asstring+''','+
              //' Batchno='''+fieldbyname('Batchno').asstring+''','+
              ' InvBillqty='+floattostr(ThisRequestQty)+','+
              ' InvBillnotaxPrice=isnull((select isnull(AveragePrice,0) '+
                                  ' from AveragePrice '+
                                  ' where whCode='''+getCode(cmbbx_WhCode.text)+''''+
                                  '   and ItemCode='''+fieldbyname('ItemCode').asstring+'''),0),'+
              ' InvBillnotaxAmount=isnull((select isnull(AveragePrice,0) '+
                                  ' from AveragePrice '+
                                  ' where whCode='''+getCode(cmbbx_WhCode.text)+''''+
                                  '   and ItemCode='''+TmpAdoQry.fieldbyname('ItemCode').asstring+'''),0)*'+floattostr(ThisRequestQty)+
              ' where InvBillid='+AdoQry_Head.fieldbyname('InvBillid').asstring+
              '   and mono='''+TmpAdoQry.fieldbyname('mono').asstring+''''+
              '   and MoLineNo='''+TmpAdoQry.fieldbyname('MoLineno').asstring+''''+
              '   and ItemCode='''+TmpAdoQry.fieldbyname('ItemCode').asstring+''''+
              '   and ItemListid='+TmpAdoQry.fieldbyname('ItemListid').asstring);
          AdoQry_tmp.execsql;
          //更改#MnItemList1
          AdoQry_tmp.Close;
          AdoQry_tmp.sql.clear;
          AdoQry_tmp.sql.Add(
            'update '+tmpTable+' set '+
              ' ThisRequestQty='+floattostr(ThisRequestQty)+' '+
              ' where mono='''+TmpAdoQry.fieldbyname('mono').asstring+''''+
              '   and MoLineNo='''+TmpAdoQry.fieldbyname('MoLineno').asstring+''''+
              '   and ItemCode='''+TmpAdoQry.fieldbyname('ItemCode').asstring+''''+
              '   and ItemListid='+TmpAdoQry.fieldbyname('ItemListid').asstring);
          AdoQry_tmp.execsql;

          ExecuteSql(AdoQry_Tmp,SqlText,1);
          {SqlText := 'update MnItemList '
                    +'   set MoRequestQty = IsNull(MoRequestQty,0)+'+FloatToStr(ThisRequestQty)
                    +' where ItemListId='+TmpAdoQry.fieldbyname('ItemListId').AsString;
          ExecuteSql(AdoQry_Tmp,SqlText,1);}
            //更改MNItemList的记录
            AdoQry_tmp.Close;
            AdoQry_tmp.sql.clear;

⌨️ 快捷键说明

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