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

📄 sfc_mnrequestoverplan_b.pas

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


procedure TFrm_Sfc_MnRequestOverPlan_B.InitControls;
var
  tmpfields:string;
begin//初始化Form上的控件
  inherited;
  //单据类型
  Isinsert:=False;  //由于在插入记录时基类会触发本onEXIT事件,为了避免这一件事件执行,所以加入本变量控制
  if (showflag=True) and (status<>'Add') then
    exit;
  checkbox1.Checked:=False;
  checkbox2.checked:=False;
  BillTypeCode:=Param2;
  lbl_Mono.Caption:=AdoQry_Head.fieldbyname('mono').asstring;
  lbl_MoLineno.Caption:=AdoQry_Head.fieldbyname('MoLineno').asstring;
  lbl_Item.Caption:=AdoQry_Head.fieldbyname('ItemCode').asstring+' '+Frm_Sfc_MnRequest.AdoQry_Head.fieldbyname('ItemName').asstring;
  lbl_qty.Caption:=AdoQry_Head.fieldbyname('moqty').asstring;
  lbl_Noqty.Caption:=AdoQry_Head.fieldbyname('MoNoFinishqty').asstring;
  cmbbx_Shift.text:=Frm_Sfc_MnRequest.tmp_MoRequestshift;
  lbl_Dept.Caption:=Frm_Sfc_MnRequest.tmp_DeptCode;
  medt_Date.text:=LoginDate;
  oldWhPosition:='#@%^';
  initUsablewhcmbx(AdoQry_tmp,userCode,cmbbx_WhCode,False);
  InitShiftCmBx(AdoQry_tmp,cmbbx_Shift,True);
  cmbbx_WhCodeexit(cmbbx_WhCode);
  tmpfields:=getInvfield(AdoQry_tmp,getCode(cmbbx_WhCode.text),getCode(cmbbx_WhPositionCode.text),'CurrentInv');

  IOType:=0;
  cmbx_WipWaster.ItemIndex :=0;
  if status='ReadOnly' then
  begin
    cmbbx_WhCode.Enabled:=False;
    cmbbx_WhPositionCode.Enabled:=False;
    medt_Date.Enabled:=False;
    Act_Save.Enabled :=False;
    Act_auto.Enabled :=False;
  end
  else
  begin
    Act_auto.Enabled :=True;
    act_Save.Enabled :=True;
    Extedt_Billno.text:='';
  end;
  InitCmBxText(cmbbx_Shift,Frm_Sfc_MnRequest.tmp_MoRequestshift);
end;

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

procedure TFrm_Sfc_MnRequestOverPlan_B.checkIOType;
begin
  if IoType<>0 then
  if AdoQry_Body.fieldbyname('moRequestqty').asfloat*IoType<0 then
  begin
    DispInfo('同一请领,不能出现正负数量混合的情况!',1);
    abort;
  end;
end;

procedure TFrm_Sfc_MnRequestOverPlan_B.checkcoCurrentqty;
var
  tmp_MoRequestqty,tmp_onhandInv:real;
begin
  tmp_MoRequestqty:=AdoQry_Body.fieldbyname('moRequestqty').asfloat;
  tmp_onhandInv:=AdoQry_Body.fieldbyname('onhandInv').asfloat;
  if AdoQry_Body.fieldbyname('moRequestqty').asstring='' then
  begin
    DispInfo('当前数量不能为空!',1);
    abort;
  end;
  if tmp_MoRequestqty>tmp_onhandInv then
  begin
    DispInfo('当前可用库存是:'+AdoQry_Body.fieldbyname('onhandInv').asstring,1);
    abort;
  end;
end;

procedure TFrm_Sfc_MnRequestOverPlan_B.Act_autoExecute(Sender: TObject);
var
  M:integer;
  tmp_onhandInv,tmp_MoCtrlqty,tmp_MoRealqty,tmp_MoRequestqty:real;
begin
  inherited;
  //自动获取
  with AdoQry_Body do
  begin
    AdoQry_Body.First;
    for M:=0 to recordCount-1 do
    begin
      tmp_onhandInv:=fieldbyname('onhandInv').asfloat;
      tmp_MoCtrlqty:=fieldbyname('moCtrlqty').asfloat;
      tmp_MoRealqty:=fieldbyname('MoRealqty').asfloat;
      tmp_MoRequestqty:=fieldbyname('moRequestqty').asfloat;
      //当限额数量-实领数量〈当前库存,则请领数量=限额数量-实领数量
      //否则,请领数量=当前库存
      if tmp_onhandInv>
         (tmp_MoCtrlqty-
          tmp_MoRealqty)
      then
      begin
        edit;
        fieldbyname('moRequestqty').asfloat:=
             fieldbyname('moCtrlqty').asfloat-
             fieldbyname('MoRealqty').asfloat
      end
      else
      begin
        edit;
        fieldbyname('moRequestqty').asfloat:=
             fieldbyname('onhandInv').asfloat;
      end;
      AdoQry_Body.next;
    end;
  end;
end;

procedure TFrm_Sfc_MnRequestOverPlan_B.FormCreate(Sender: TObject);
begin
  inherited;
  IsAfterprint:=False;
  Frm_Entry_Detail:=TFrm_Sfc_MnRequestOverPlan_D.Create(Self);//设置弹出Detail
  SetFocus_Control:=cmbbx_WhCode;
end;


procedure TFrm_Sfc_MnRequestOverPlan_B.Act_PreviewExecute(Sender: TObject);
begin
  //保存前打印,调用过程INITPRINT,窗体Frm_Sfc_MnOut_NotSave_P,保存打印调用Frm_Sfc_MnOut_P
  if Trim(Extedt_Billno.text)<>'' then
     BillPrint(AdoQry_Tmp.Connection,GetCode(cmbbx_WhCode.Text),Extedt_Billno.Text,Param2,ModuleCode,True,False,True,'')
  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_MnRequestOverPlan_B.Act_PrintExecute(Sender: TObject);
begin
//保存前打印,调用过程INITPRINT,窗体Frm_Sfc_MnOut_NotSave_P,保存打印调用Frm_Sfc_MnOut_P
  IsAfterprint:=True;
  if Trim(Extedt_Billno.text)<>'' then
    BillPrint(AdoQry_Tmp.Connection,GetCode(cmbbx_WhCode.Text),Extedt_Billno.Text,Param2,ModuleCode,False,False,True,'')
  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,'Print',ModuleCode,'');
    initprint;
    Frm_Sfc_MnOut_NotSave_P.SetDBConnect(AdoQry_tmp.Connection);
    Frm_Sfc_MnOut_NotSave_P.release;
   end;
   IsAfterprint:=False;
end;

procedure TFrm_Sfc_MnRequestOverPlan_B.Act_ExcelExecute(Sender: TObject);
begin
  inherited;
  //
end;

procedure TFrm_Sfc_MnRequestOverPlan_B.cmbbx_WhCodeChange(Sender: TObject);
begin
  inherited;
  //调用初始化货位过程
  initcmbbx_WhPositionCode(getCode(cmbbx_WhCode.text));
end;

procedure TFrm_Sfc_MnRequestOverPlan_B.FormActivate(Sender: TObject);
begin
    if IsAfterprint=False then
    begin
      inherited;
    //初始化仓库
      initUsablewhcmbx(AdoQry_tmp,userCode,cmbbx_WhCode,False);
      ToolButton4.left:=TlBtn_Print.Left+ToolButton4.Width;
   end;
end;

procedure TFrm_Sfc_MnRequestOverPlan_B.cmbbx_WhCodeExit(Sender: TObject);
var
  tmp_WhCode,tmp_WhPositionCode:string;
begin
  inherited;
  if Isinsert then exit;   //由于在插入记录时基类会触发本onEXIT事件,为了避免这一件事件执行,所以加入本变量控制
  initcmbbx_WhPositionCode(getCode(cmbbx_WhCode.text));
  //如果独立订单,则让货位显示在'冻结货位'上 ,WhPositionType=2表示冻结货位
  if AdoQry_Head.fieldbyname('moSpecial').asinteger=1 then
  begin
    tmp_WhCode:=getCode(cmbbx_WhCode.text);
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.Add('select WhPositionCode,WhPositionName '+
              ' from WhPosition  '+
              ' where whCode='''+tmp_WhCode+''' and WhPositionType=2');
      open;
      tmp_WhPositionCode:=fieldbyname('WhPositionCode').asstring;
    end;
  end;

  //定位货位
  InitCmBxText(cmbbx_WhPositionCode,tmp_WhPositionCode);
  //调用初始化仓管员过程
  InitCmbbx_WhEmployee(getCode(cmbbx_WhCode.text));
  if Trim(cmbbx_WhPositionCode.text)<>'' then
     cmbbx_WhPositionCode.OnExit(sender);
end;

procedure TFrm_Sfc_MnRequestOverPlan_B.SaveData;
var
  M:integer;
  tmp_qty:real;
  save_ItemListid,Billno,Billid,Billid1:string;
  saveplace:tBookmArk;
begin
 // inherited; 不能放开这个INHERITED
  AdoQry_Body.DisableControls;
  saveplace:=AdoQry_Body.GetBookmArk;
  with AdoQry_Body do
  begin
    First;
    for M:=0 to recordCount-1 do
    begin
      tmp_qty:=tmp_qty+fieldbyname('moRequestqty').asfloat;
      next;
    end;
    if tmp_qty=0.0 then
    begin
      gotoBookmArk(saveplace);
      freeBookmArk(saveplace);
      enablecontrols;
      DispInfo('请领数量都为零,不允许保存!',1);
      abort;
    end;
  end;
  AdoQry_Body.Connection.beginTrans;
  try
    AdoQry_Body.First;
    for M:=0 to AdoQry_Body.recordCount-1 do
    begin
      if AdoQry_Body.fieldbyname('moRequestqty').asstring<>'0' then
      begin
       //当前物料库存检验
        if not InvQtyCheck
            (False,
             AdoQry_Body,
             AdoQry_tmp,
             getCode(cmbbx_WhCode.text),
             getCode(cmbbx_WhPositionCode.text),
             AdoQry_Body.fieldbyname('ItemCode').asstring,
             'moRequestqty',
             AdoQry_Body.fieldbyname('moRequestqty').asfloat,
             False) then
         begin
           AdoQry_Body.gotoBookmArk(saveplace);
           AdoQry_Body.freeBookmArk(saveplace);
           AdoQry_Body.enablecontrols;
           abort;
         end;
         //如果是批次控制,则进行批库存检验
        if AdoQry_Body.fieldbyname('Batchno').asstring<>'' then
        begin
          if  not BatchInvCheck(AdoQry_tmp,
                                AdoQry_Body.fieldbyname('Batchno').asstring,
                                'C',
                                getCode(cmbbx_WhCode.text),
                                getCode(cmbbx_WhPositionCode.text),
                                AdoQry_Body.fieldbyname('moRequestqty').asfloat) then
         begin
           AdoQry_Body.gotoBookmArk(saveplace);
           AdoQry_Body.freeBookmArk(saveplace);
           AdoQry_Body.enablecontrols;
           abort;
         end;
        end;
      end;
      AdoQry_Body.next;
    end;
    //产生单据号
    Billno:=getno(AdoQry_Body.Connection,getCode(cmbbx_WhCode.text)+'C'+copy(medt_Date.text,3,2)+copy(medt_Date.text,6,2),'InvBill');
   //增加InvOutBill
    AdoQry_tmp.Close;
    AdoQry_tmp.sql.clear;
    AdoQry_tmp.sql.Add(
      'insert InvOutBill'+
                 '(InvBillno,'+
                 'whCode,'+
                 'InvBilldate,'+
                 'InvBillMonth,'+
                 'DeptCode,'+
                 'mono,'+
                 'MoLineno,'+
                 'BillTypeCode,'+
                 'EmployeeCode,'+
                 'Sfc_EmployeeCode,'+
                 'WhPositionCode,'+
                 'OverPlan,'+
                 'shiftType,'+
                 'WipWaster,'+
                 'InvBillremArk)'+
         'Values('''+Billno+''','+
                ''''+getCode(cmbbx_WhCode.text)+''','+
                ''''+medt_Date.text+''','+
                ''''+copy(medt_Date.text,1,7)+''','+
                ''''+getCode(lbl_Dept.Caption)+''','+
                ''''+lbl_Mono.Caption+''','+
                lbl_MoLineno.Caption+','+
                ''''+BillTypeCode+''','+
                ''''+userCode+''','+
                ''''+userCode+''','+
                ''''+getCode(cmbbx_WhPositionCode.text)+''','+
                '1,'+
                ''''+cmbbx_Shift.text+''','+

⌨️ 快捷键说明

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