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

📄 sfc_enter_mounitmnrequest.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 4 页
字号:
{  SQlText := ' select WhAccessCtrl.WHCode,WHName   '
             +'    from WHAccessCtrl   '
             +'   join Warehouse on WhAccessCtrl.WhCode=Warehouse.WhCode '
             +'   where WhAccessCtrl.EmployeeCode='+QuotedSTr(userCode)
             +'     and ( WhAccessCtrl.WhCode In (select WhCode  from CurrentInv      '
             +'                     where ItemCode in(select distinct ItemCode  from #TmPMoLine Where CheckFlag=1)   ' 
             +'                                         )     '
             +'          or WhAccessCtrl.WhCode in (select WhCode from Item '
             +'                                       where ItemCode in(  select distinct ItemCode  '
             +'                                                            from #TmPMoLine Where CheckFlag=1 )  '
             +'         ) ) '
            + '   Order by WhAccessCtrl.WHCode   ';
}
  ExecuteSql(AdoQry_Tmp,SQlText,0);
  cmbbx_WhCode.Items.clear;
  Cmbbx_WhCode.Items.Add('');
  While Not AdoQry_Tmp.Eof do
  begin
    Cmbbx_WhCode.Items.Add(AdoQry_Tmp.fieldbyname('WhCode').AsString+' '+AdoQry_Tmp.fieldbyname('WhName').AsString);
    AdoQry_Tmp.Next;    
  end;
  Cmbbx_WhCode.ItemIndex := 1;
  cmbbx_WhCodeexit(cmbbx_WhCode);
  InitShiftCmBx(AdoQry_tmp,cmbbx_Shift,True);
  Cmbbx_Shift.ItemIndex := 0;
  ShowDbgrid;
//  InitCmBxText(cmbbx_Shift,Frm_Sfc_Enter_MoUnitMnRequestH.tmp_MoRequestshift);
end;

procedure TFrm_Sfc_Enter_MoUnitMnRequest.SetStatus(CurrentStatus:String;var AnswerStatus,
  EnableControls:String);
begin//指明当前状态,定义Enable=True的控件
  inherited;
 if CurrentStatus='Add' then
 begin
   EnableControls:='';
 end
 else
   EnableControls:='';
end;


procedure TFrm_Sfc_Enter_MoUnitMnRequest.checkcoCurrentqty;
begin
  if AdoQry_Body.fieldbyname('ThisRequestqty').asstring='' then
  begin
    DispInfo('当前数量不能为空!',3);
    dbgrideh.SetFocus ;
    abort;
  end;

  if  (AdoQry_Body.fieldbyname('ThisRequestqty').asfloat<0) then
  begin
    DispInfo('请领数量不能为负数!',3);
    dbgrideh.SetFocus ;
    abort;
  end;

  if  (AdoQry_Body.fieldbyname('ThisRequestQty').AsFloat<>0 ) and 
     ( AdoQry_Body.fieldbyname('ThisRequestqty').asfloat>
      (AdoQry_Body.fieldbyname('moCtrlqty').asFloat-
       AdoQry_Body.fieldbyname('MoRealqty').asfloat-
       AdoQry_Body.fieldbyname('MoRequestQty').AsFloat) )
  then
  begin
    DispInfo('请领数量不能超过实际未领数量!',3);
    dbgrideh.SetFocus ;
    abort;
  end;

  if AdoQry_Body.fieldbyname('ThisRequestqty').asfloat>AdoQry_Body.fieldbyname('onhandInv').asfloat then
  begin
    DispInfo('当前可用库存是'+AdoQry_Body.fieldbyname('onhandInv').asstring+',本次请领数不能超过当前库存!',3);
    dbgrideh.setfocus ;
    abort;
  end;
end;

procedure TFrm_Sfc_Enter_MoUnitMnRequest.DBGridEhKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
var
  tmp_WhCode,tmp_WhPositionCode:string;
begin
 // inherited;
  if key=vk_return then
    keybd_event(vk_tab,vk_tab,0,0);
    if (AdoQry_Body.State in [dsEdit, dsInsert]) and (key=vk_F9) then
    begin
      tmp_WhCode:=getCode(cmbbx_WhCode.text);
      tmp_WhPositionCode:=getCode(cmbbx_WhPositionCode.text);
      AdoQry_Body.fieldbyname('Batchno').asstring:=BatchHint(AdoQry_tmp.Connection,AdoQry_Body.fieldbyname('ItemCode').asstring,'',tmp_WhCode,tmp_WhPositionCode);
    end;
end;

procedure TFrm_Sfc_Enter_MoUnitMnRequest.AdoQry_BodyBeforePost(DataSet: TDataSet);
var
  tmp_WhCode,tmp_WhPositionCode:string;
begin
  inherited;
  if AdoQry_Body.fieldbyname('ThisRequestqty').asstring='' then
     AdoQry_Body.fieldbyname('ThisRequestqty').asstring:='0';
   //进行同向检验及数量库存检验
     //批次号控制
  if (not BatchCtrl(AdoQry_tmp,AdoQry_Body.fieldbyname('ItemCode').asstring)) then
  if Trim(AdoQry_Body.fieldbyname('Batchno').asstring)<>'' then
  begin
    DispInfo('该物料不受批次控制,不能录入批次号',3);
    AdoQry_Body.fieldbyname('Batchno').asstring:='';
    dbgrideh.setfocus;
    abort;
  end ;

    if (BatchCtrl(AdoQry_tmp,AdoQry_Body.fieldbyname('ItemCode').asstring)) and
        ((AdoQry_Body.fieldbyname('thisRequestqty').asstring<>'0') and
        (AdoQry_Body.fieldbyname('thisRequestqty').asstring<>'')) then
    begin
      if (Trim(AdoQry_Body.fieldbyname('Batchno').asstring)='') then
      begin
        DispInfo('请录入批次号',3);
        dbgrideh.setfocus;
        abort;
      end
      else
      begin
        if not BatchNoCheck(AdoQry_tmp,AdoQry_Body.fieldbyname('Batchno').asstring,AdoQry_Body.fieldbyname('ItemCode').asstring,'',medt_Date.text) then
        begin
          dbgrideh.setfocus;
          abort;
        end
        else
        begin
          tmp_WhCode:=getCode(cmbbx_WhCode.text);
          tmp_WhPositionCode:=getCode(cmbbx_WhPositionCode.text);
          //批次库存控制
          if not BatchInvCheck(AdoQry_tmp,AdoQry_Body.fieldbyname('Batchno').asstring,'C',tmp_WhCode,tmp_WhPositionCode,AdoQry_Body.fieldbyname('moRequestqty').asfloat) then
          begin
            dbgrideh.setfocus;
            abort;
          end;
        end;
      end;
    end
    else
    begin
      AdoQry_Body.fieldbyname('Batchno').asstring:='';
    end;
end;

procedure TFrm_Sfc_Enter_MoUnitMnRequest.DBGridEhColExit(Sender: TObject);
var
  tmp_WhCode,tmp_WhPositionCode:string;
begin
  inherited;
  if (AdoQry_Body.State in [dsEdit, dsInsert])
  and (lowercase(dbgrideh.SelectedField.fieldName)='ThisRequestqty')
  then
  begin
//    checkbodyIOType;
    checkcoCurrentqty;
  end;

  if (AdoQry_Body.State in [dsEdit, dsInsert])
    and (dbgrideh.SelectedField.fieldName='Batchno') then
  begin

    if (not BatchCtrl(AdoQry_tmp,AdoQry_Body.fieldbyname('ItemCode').asstring)) then
    if  (Trim(dbgrideh.SelectedField.Value)<>'') then
    begin
      DispInfo('该物料不受批次控制,不能录入批次号',1);
      dbgrideh.setfocus;
      abort;
    end;

    if (BatchCtrl(AdoQry_tmp,AdoQry_Body.fieldbyname('ItemCode').asstring)) and
       ((AdoQry_Body.fieldbyname('ThisRequestqty').asstring<>'0') and
        (AdoQry_Body.fieldbyname('ThisRequestqty').asstring<>''))  then
    begin
      if  (Trim(dbgrideh.SelectedField.Value)='') or
          (dbgrideh.SelectedField.Value=Null) then
      begin
        DispInfo('请录入批次号',1);
        dbgrideh.setfocus;
        abort;
      end
      else
      begin
        if not BatchNoCheck(AdoQry_tmp,dbgrideh.SelectedField.Value,AdoQry_Body.fieldbyname('ItemCode').asstring,'',medt_Date.text) then
        begin
          dbgrideh.setfocus;
          abort
        end
        else
        begin
          tmp_WhCode:=getCode(cmbbx_WhCode.text);
          tmp_WhPositionCode:=getCode(cmbbx_WhPositionCode.text);
          if  not BatchInvCheck(AdoQry_tmp,dbgrideh.SelectedField.Value,'C',tmp_WhCode,tmp_WhPositionCode,AdoQry_Body.fieldbyname('moRequestqty').asfloat) then
          begin
            dbgrideh.setfocus;
            abort;
          end;
        end;
      end;
    end
  end;
end;

procedure TFrm_Sfc_Enter_MoUnitMnRequest.Act_autoExecute(Sender: TObject);
var
  M:integer;
  Batchno:string;
  outqty:double;
begin
  inherited;
  if (activecontrol.Name='cmbbx_WhPositionCode') or
     (activecontrol.Name='cmbbx_WhCode') or
     (activecontrol.Name='cmbbx_WhEmployee') then
  medt_Date.setfocus;

  with AdoQry_Body do
  begin
    AdoQry_Body.First;
    for M:=0 to recordCount-1 do
    begin
{      If fieldbyname('IsTotal').AsInteger = 1 then
      begin
        Next;
        Continue;
      end;
}
      if fieldbyname('onhandInv').asfloat>(fieldbyname('moCtrlqty').asfloat-fieldbyname('MoRealqty').asfloat-fieldbyname('MoRequestQty').AsFloat)   then
      begin
        if BatchCtrl(AdoQry_tmp,fieldbyname('ItemCode').asstring) then
        begin
              //批次处理自动获取,如果批次最佳数量小于限额数量-实领数量,则取批次最佳数量
          outqty:=IIfValue(fieldbyname('moCtrlqty').asfloat-
                  fieldbyname('MoRealqty').asfloat-
                  fieldbyname('MoRequestQty').AsFloat>0,
                  fieldbyname('moCtrlqty').asfloat-
                  fieldbyname('MoRealqty').asfloat-
                  fieldbyname('MoRequestQty').AsFloat,0);
          Batchno:=GiveBatchNo(AdoQry_tmp,
                      getCode(cmbbx_WhCode.text),
                      getCode(cmbbx_WhPositionCode.text),
                      AdoQry_Body.fieldbyname('ItemCode').asstring,
                      medt_Date.text,
                      outqty);
          edit;
          fieldbyname('ThisRequestqty').asfloat:=outqty;
          fieldbyname('Batchno').asstring:=Batchno;
        end
        else
        begin
          edit;
          fieldbyname('ThisRequestqty').asfloat:=IIfValue(fieldbyname('moCtrlqty').asfloat-
                  fieldbyname('MoRealqty').asfloat-
                  fieldbyname('MoRequestQty').AsFloat>0,
                  fieldbyname('moCtrlqty').asfloat-
                  fieldbyname('MoRealqty').asfloat-
                  fieldbyname('MoRequestQty').AsFloat,0);
        end;
      end
      else
      begin
        if BatchCtrl(AdoQry_tmp,fieldbyname('ItemCode').asstring) then
        begin
             //批次处理的自动获取 ,如果批次库存小于当前库存,则取批次库存
          outqty:=fieldbyname('onhandInv').asfloat;
          Batchno:=GiveBatchNo(AdoQry_tmp,
                        getCode(cmbbx_WhCode.text),
                        getCode(cmbbx_WhPositionCode.text),
                        AdoQry_Body.fieldbyname('ItemCode').asstring,
                        medt_Date.text,
                        outqty);
          edit;
          fieldbyname('ThisRequestqty').asfloat:=outqty;
          fieldbyname('Batchno').asstring:=Batchno;
        end
        else
        begin
          edit;
          fieldbyname('ThisRequestqty').asfloat:=fieldbyname('onhandInv').asfloat;
        end;
      end;
      AdoQry_Body.next;
    end;
  end;

end;

procedure TFrm_Sfc_Enter_MoUnitMnRequest.FormCreate(Sender: TObject);
begin
  inherited;
  IsAfterprint:=False;
  TlBtn_InsertLine.Action:=Act_Auto;
  SetFocus_Control:=cmbbx_WhCode;
end;

procedure TFrm_Sfc_Enter_MoUnitMnRequest.Act_PreviewExecute(Sender: TObject);
var FrmActivate : TNotifyEvent;
begin
//  Pnl_Head.Enabled := False;
  FrmActivate := OnActivate;
  OnActivate := Nil;
  Button1.Enabled := True;
  ExtPrintReport.Subtitle2 := '仓库:'+Cmbbx_WhCode.Text +' 货位:'+Cmbbx_WhPositionCode.Text
                           +' 仓管员:'+Cmbbx_WhEmployee.Text +' 单据号:'+ExtEdt_BillNo.Text ;
  ExtPrintReport.Subtitle3 := '领料部门:'+Edt_Dept.Text +'班别:'+Cmbbx_Shift.Text 
                           +' 日期:'+Medt_Date.Text ;
  ExtPrintReport.Subtitle4 := '备注:'+ExtEdt_MeMo.Text; 
  ExecuteSql(AdoQry_Tmp,'Select EmployeeName from Employee '
                       +' where EmployeeCode='+QuotedStr(UserCode),0)    ;
  ExtPrintReport.Foot1 := '发货人:               提货人:               制单人:'+UserCode+' '+AdoQry_Tmp.fieldbyname('EmployeeName').AsString;
  inherited;
  OnActivate := FrmActivate;
  //如果未保存打印,则调用Frm_Sfc_MnOut_NotSave_P,否则调用Frm_Sfc_MnOut_P
{  if Trim(Extedt_Billno.text)<>'' then
  begin
    BillPrint(AdoQry_Tmp.Connection,GetCode(cmbbx_WhCode.Text),Extedt_Billno.Text,Param2,ModuleCode,True,False,True,'');
  end
  else
   begin
    Application.CreateForm(TFrm_Sfc_MnOut_NotSave_P,Frm_Sfc_MnOut_NotSave_P);
    Frm_Sfc_MnOut_NotSave_P.SetFormParam('',getCode(cmbbx_WhCode.text),Param2,'Preview',ModuleCode,'');
    initprint;
    Frm_Sfc_MnOut_NotSave_P.SetDBConnect(AdoQry_tmp.Connection);
    Frm_Sfc_MnOut_NotSave_P.release;
   end;
}   
end;

procedure TFrm_Sfc_Enter_MoUnitMnRequest.Act_PrintExecute(Sender: TObject);
begin
//  pnl_Head.Enabled := False;
  Button1.Enabled := True;
  ExtPrintReport.Subtitle2 := '仓库:'+Cmbbx_WhCode.Text +' 货位:'+Cmbbx_WhPositionCode.Text
                           +' 仓管员:'+Cmbbx_WhEmployee.Text +' 单据号:'+ExtEdt_BillNo.Text ;
  ExtPrintReport.Subtitle3 := '领料部门:'+Edt_Dept.Text +'班别:'+Cmbbx_Shift.Text 
                           +' 日期:'+Medt_Date.Text ;
  ExtPrintReport.Subtitle4 := '备注:'+ExtEdt_MeMo.Text;                                                      
  ExecuteSql(AdoQry_Tmp,'Select EmployeeName from Employee '
                       +' where EmployeeCode='+QuotedStr(UserCode),0)    ;
  ExtPrintReport.Foot1 := '发货人:               提货人:               制单人:'+UserCode+' '+AdoQry_Tmp.fieldbyname('EmployeeName').AsString;

⌨️ 快捷键说明

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