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

📄 inv_opsumout_b.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  inherited;
  mypost:=AdoQry_Body.BeforePost;
  AdoQry_Body.BeforePost:=nil;
  AdoQry_Body.First;
  with AdoQry_Body do
  for i:=0 to recordCount-1 do
  begin
    Tmp_var:=
    min(round(fieldbyname('PoCtrlQty').asfloat)-round(fieldbyname('PoRealQty').asfloat),
    fieldbyname('UseableStore').asfloat);
    if BatchCtrl(AdoQry_Tmp,fieldbyname('ItemCode').asString) then
    begin
      BatchNo:=GiveBatchNo(AdoQry_Tmp,getCode(Cmbx_WhCodeName.text),
                     getCode(Cmbx_Position.text),fieldbyname('ItemCode').asString,
                     Medt_Date.text,Tmp_var);
      if BatchNo='' then
      begin
        next;
        continue;
      end
    end;
    edit;
    fieldbyname('BatchNo').asString:=BatchNo;
    fieldbyname('PooutQty').asfloat:=Tmp_var;
    if fieldbyname('PooutQty').asfloat<0 then fieldbyname('PooutQty').asfloat:=0;
    post;
    next;
  end;
  AdoQry_Body.First;
  DBGridEh.Refresh;
  act_Save.Enabled:=True;
  AdoQry_Body.BeforePost:=mypost;
end;

procedure TFrm_Inv_OpSumOut_B.Act_SaveExecute(Sender: TObject);
begin
  //inherited;
  if AdoQry_Body.State<>dsBrowse then
  AdoQry_Body.Post;
  AdoQry_Body.DisableControls;

  if Not CheckAllSame then
  begin
    DispInfo('不允许正负号同时出现!',1);
    disableall(True);
    AdoQry_Body.EnableControls;
    abort;
  end;

  if CheckNotZero then
  Savedata
  else
  begin
    DispInfo('出库均为零,不能保存!',3);
    AdoQry_Body.EnableControls;    
    act_Save.Enabled:=False;
    exit;
  end;
  AdoQry_Body.EnableControls;
  act_Save.Enabled:=False;
  act_auto.enabled:=False;
  DisableAll(False);
end;

procedure TFrm_Inv_OpSumOut_B.FormActivate(Sender: TObject);
begin
  inherited;
  FPolineNo:=0;
  Act_Save.Enabled:=True;
  ToolButton2.Action:=Act_Save;
  with DBGridEh do
  begin
    ReadOnly:=False;
    Columns[0].ReadOnly:=True;
    Columns[1].ReadOnly:=True;
    Columns[2].ReadOnly:=True;
    Columns[3].ReadOnly:=True;
    Columns[4].ReadOnly:=True;
    Columns[5].ReadOnly:=True;
    Columns[6].ReadOnly:=False;
    Columns[7].ReadOnly:=False;
    Columns[7].Width:=100;
    Columns[8].ReadOnly:=False;
    Columns[8].Width:=100;
  end;
end;

procedure TFrm_Inv_OpSumOut_B.Cmbx_WhCodeNameChange(Sender: TObject);
begin
  inherited;
  refreshall;
end;

procedure TFrm_Inv_OpSumOut_B.Cmbx_PositionChange(Sender: TObject);
begin
  inherited;
  refreshall;
end;

procedure TFrm_Inv_OpSumOut_B.Medt_DateExit(Sender: TObject);
begin
  inherited;
  if not WHClsPeriodCheck(AdoQry_Tmp,GetCode(Cmbx_WhCodeName.Text),Copy((Medt_Date.Text),1,7)) then
    Medt_Date.SetFocus;
end;

procedure TFrm_Inv_OpSumOut_B.AdoQry_BodyAfterScroll(DataSet: TDataSet);
begin
  if (AdoQry_Body.Eof) then AdoQry_Body.Cancel;
  inherited;
end;

procedure TFrm_Inv_OpSumOut_B.DBGridEhKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
var
  BatchStr:string;
begin
  inherited;
  If Word(Key)=VK_F9 then
    with AdoQry_Body do
    begin
      BatchStr:=BatchHint(AdoQry_Tmp.Connection,fieldbyname('ItemCode').asstring,
                '',getCode(Cmbx_WhCodeName.text),getCode(Cmbx_Position.Text));
      if BatchStr<>'' then
      begin
        if not BatchInvCheck(AdoQry_Tmp,BatchStr,'c',
                      getCode(Cmbx_WhCodeName.text),
                      getCode(Cmbx_Position.text),
                      fieldbyname('POOutQty').asFloat) then Abort;
        edit;
        fieldbyname('BatchNo').asstring:=BatchStr;
        post;
      end;
    end;
end;

procedure TFrm_Inv_OpSumOut_B.Cmbx_WhCodeNameExit(Sender: TObject);
begin
  inherited;
  If Cmbx_WhCodeName.Text='' then
  begin
    DispInfo('请选择一个仓库!',1);
    Abort;
  end;
end;

procedure TFrm_Inv_OpSumOut_B.Cmbx_PositionExit(Sender: TObject);
begin
  inherited;
  If Cmbx_Position.Text='' then
  begin
    DispInfo('请选择一个货位',1);
    Cmbx_Position.SetFocus;
    abort;
  end;
end;

function TFrm_Inv_OpSumOut_B.BatchSaveByNo(BillId,BatchNo,ItemCode,
  BillLineRemArk: String; POOutQty: real;Price:Double): Boolean;
var
  I,Tmp_Qty,DisperSionQty:Integer;
  sql_txt:string;
begin
  Result:=True;
  Tmp_Qty:=round(PoOutQty);
  with AdoQry_Tmp do
  begin
    Close;
    sql.text:='select O.PolineNo,'+
              '       O.Ite_ItemCode,'+
              '       O.ItemListID,'+
              '       O.ItemCode,pl.pono,'+
              '       round(O.PoCtrlQty,0)PoCtrlQty,'+
              '       round(O.PoRealQty,0)PoRealQty'+
              '  from opItemList O,Poline PL'+
              ' where O.pono=PL.pono and '+
              '       O.PolineNo=PL.PolineNo and '+
              '       pl.PoLineStatus=6 and '+
              '       o.pono='''+getCode(Lbl_PoNo.Caption)+''' and '+
              '       O.ItemCode='''+ItemCode+''' '+
              ' Order By O.ItemCode,Pl.PoLineDate,Pl.PolineNo ';
    open;
    if PoOutQty>0 then
      First
    else
      Last;
    for I:=0 to RecordCount-1 do
    begin
      If PoOutQty>0 then
      begin
        DisperSionQty:=round(fieldbyname('PoCtrlQty').asFloat-fieldbyname('PorealQty').asFloat);
        if DisperSionQty<=0 then
        begin
          next;
          continue;
        end;
        If DisperSionQty<Tmp_Qty then
        begin
          AdoQry_tmp2.Close;//更新opItemList
          AdoQry_tmp2.sql.text:='update opItemList '+
                    '   set PoRealQty=round(PoCtrlQty,0), '+
                    '       BillLineRemArk='''+BillLineRemArk+''' '+
                    ' where ItemListID='''+fieldbyname('ItemListID').AsString+'''';
          AdoQry_tmp2.execsql;
          Scll(AdoQry_tmp2,fieldbyname('ItemCode').asstring,'POScLL',fieldbyname('pono').asstring,fieldbyname('polineno').asinteger);

          //更新InvOutBillLine中的记录
          AdoQry_tmp2.Close;
          AdoQry_tmp2.sql.clear;
          AdoQry_tmp2.sql.Add('insert InvOutBillline'+
                                  '(InvBillid,'+
                                  'BatchNo,'+
                                  'InvBilllineno,'+
                                  'ItemCode,'+
                                  'ite_ItemCode,'+
                                  'pono,'+
                                  'polineno,'+
                                  'InvBillNoTaxPrice,'+
                                  'InvBillNoTaxAmount,'+
                                  'InvBillqty,BillLineReMArk) '+
                            'Select '+Billid+','+
                                    ''''+BatchNo+''','+
                                    inttostr(FPolineNo+1)+','+
                                    ''''+ItemCode+''','+
                                    ''''+fieldbyname('ite_ItemCode').asstring+''','+
                                    ''''+lbl_Pono.Caption+''','+
                                    ''''+fieldbyname('polineno').asstring+''','+
                                    floattostr(Price)+','+
                                    'round('+Inttostr(DisperSionQty)+
                                    '*'+floattostr(Price)+',2),'+
                                    Inttostr(DisperSionQty)+','+
                                    ' '''+BillLineReMArk+'''');

          AdoQry_tmp2.ExecSQL;
          FPolineNo:=FPolineNo+1;
          Tmp_Qty:=Tmp_Qty-DisperSionQty;
          Next;
        end
        else
        begin
          AdoQry_tmp2.Close;
          AdoQry_tmp2.sql.text:='update opItemList '+
                    '   set PoRealQty=PoRealQty+'+Inttostr(Tmp_Qty)+','+
                    '       BillLineRemArk='''+BillLineRemArk+''' '+
                    ' where ItemListID='+fieldbyname('ItemListID').AsString;
          AdoQry_tmp2.execsql;
          Scll(AdoQry_tmp2,fieldbyname('ItemCode').asstring,'POScLL',fieldbyname('pono').asstring,fieldbyname('polineno').asinteger);

          //更新InvOutBillLine中的记录
          AdoQry_tmp2.Close;
          AdoQry_tmp2.sql.clear;
          AdoQry_tmp2.sql.Add('insert InvOutBillline'+
                                  '(InvBillid,'+
                                  'BatchNo,'+
                                  'InvBilllineno,'+
                                  'ItemCode,'+
                                  'ite_ItemCode,'+
                                  'pono,'+
                                  'polineno,'+
                                  'InvBillNoTaxPrice,'+
                                  'InvBillNoTaxAmount,'+
                                  'InvBillqty,BillLineReMArk) '+
                            'Select '+Billid+','+
                                    ''''+BatchNo+''','+
                                    inttostr(FPolineNo+1)+','+
                                    ''''+ItemCode+''','+
                                    ''''+fieldbyname('ite_ItemCode').asstring+''','+
                                    ''''+lbl_Pono.Caption+''','+
                                    ''''+fieldbyname('polineno').asstring+''','+
                                    floattostr(Price)+','+
                                    'round('+Inttostr(Tmp_Qty)+
                                    '*'+floattostr(Price)+',2),'+
                                    Inttostr(Tmp_Qty)+','+
                                    ' '''+BillLineReMArk+'''');
          AdoQry_tmp2.execsql;
          FPolineNo:=FPolineNo+1;
          Exit;
        end;
      end
      else
      begin
        if fieldbyname('PoRealQty').asInteger<=0 then
        begin
          Prior;
          continue;
        end;
        If fieldbyname('PoRealQty').asInteger<Abs(Tmp_Qty) then
        begin
          AdoQry_tmp2.Close;
          AdoQry_tmp2.sql.text:='update opItemList '+
                    '   set PoRealQty=0, '+
                    '       BillLineRemArk='''+BillLineRemArk+''' '+
                    ' where ItemListID='+fieldbyname('ItemListID').AsString;
          AdoQry_tmp2.ExecSQL;
          Scll(AdoQry_tmp2,fieldbyname('ItemCode').asstring,'POScLL',fieldbyname('pono').asstring,fieldbyname('polineno').asinteger);

          //更新InvOutBillLine中的记录
          AdoQry_tmp2.Close;
          AdoQry_tmp2.sql.clear;
          AdoQry_tmp2.sql.Add('insert InvOutBillline'+
                                  '(InvBillid,'+
                                  'BatchNo,'+
                                  'InvBilllineno,'+
                                  'ItemCode,'+
                                  'ite_ItemCode,'+
                                  'pono,'+
                                  'polineno,'+
                                  'InvBillNoTaxPrice,'+
                                  'InvBillNoTaxAmount,'+
                                  'InvBillqty,BillLineReMArk) '+
                            'Select '+Billid+','+
                                    ''''+BatchNo+''','+
                                    inttostr(FPolineNo+1)+','+
                                    ''''+ItemCode+''','+
                                    ''''+fieldbyname('ite_ItemCode').asstring+''','+
                                    ''''+lbl_Pono.Caption+''','+
                                    ''''+fieldbyname('polineno').asstring+''','+
                                    floattostr(Price)+','+
                                    'round('+Inttostr(DisperSionQty)+
                                    '*'+floattostr(Price)+',2),'+
                                    Inttostr(-(fieldbyname('PoRealQty').asinteger))+','+
                                    ' '''+BillLineReMArk+'''');
          AdoQry_tmp2.ExecSQL;
          FPolineNo:=FPolineNo+1;
          Tmp_Qty:=Tmp_Qty+fieldbyname('PoRealQty').asinteger;
          Prior;
        end
        else
        begin
          AdoQry_tmp2.Close;
          AdoQry_tmp2.sql.text:='update opItemList '+
                    '   set poRealQty=PorealQty-'+InttoStr(Abs(Tmp_Qty))+','+
                    '       BillLineRemArk='''+BillLineRemArk+''' '+
                    ' where ItemListID='+fieldbyname('ItemListID').AsString;
          AdoQry_tmp2.execsql;
//调用一线的程序
          Scll(AdoQry_tmp2,fieldbyname('ItemCode').asstring,'POScLL',fieldbyname('pono').asstring,fieldbyname('polineno').asinteger);
          //更新InvOutBillLine中的记录
          AdoQry_tmp2.Close;
          AdoQry_tmp2.sql.clear;
          sql_txt:='insert InvOutBillline'+
                                  '(InvBillid,'+
                                  'BatchNo,'+
                                  'InvBilllineno,'+
                                  'ItemCode,'+
                                  'ite_ItemCode,'+
                                  'pono,'+
                                  'polineno,'+
                                    'InvBillNoTaxAmount,'+
                               'InvBillNoTaxPrice,'+
                                   'InvBillqty,BillLineReMArk) '+
                            'Select '+Billid+','+
                                    ''''+BatchNo+''','+
                                    inttostr(FPolineNo+1)+','+
                                    ''''+ItemCode+''','+
                                    ''''+fieldbyname('ite_ItemCode').asstring+''','+
                                    ''''+lbl_Pono.Caption+''','+
                                    ''''+fieldbyname('polineno').asstring+''','+
                                    floattostr(Price)+','+
                                    'round('+Inttostr(Tmp_Qty)+
                                    '*'+floattostr(Price)+',2),'+
                                    Inttostr(Tmp_Qty)+','+
                                    ' '''+BillLineReMArk+'''';
          AdoQry_tmp2.sql.Add(sql_txt);
          AdoQry_tmp2.ExecSQL;
          FPolineNo:=FPolineNo+1;
          exit;
        end;
      end;
    end;
  end;
end;

procedure TFrm_Inv_OpSumOut_B.Btn_QryOpCurrentInvClick(Sender: TObject);
begin
  inherited;
  Frm_Sys_Hint:=TFrm_Sys_Hint.Create(nil);
  Frm_Sys_Hint.InitForm(DBConnect,
              'select O.ItemCode+'' ''+I.ItemName 物料标识,'+
              '       O1.InvBlncQty 上月结存,'+
              '       O.OpInv 库存数量 '+
              'from OpCurrentInv O left join Item I on o.ItemCode=i.ItemCode'+
              '  left join OpMonthSum o1 on o.ItemCode=o1.ItemCode and o.VendorCode=o1.VendorCode '+
              '     and o1.InvMonth='''+formatdatetime('yyyy.mm',incMonth(strtodatetime(medt_Date.text),-1))+''' '+
              ' where O.ItemCode=I.ItemCode and '+
              '       O.VendorCode='''+getCode(Lbl_VendorCodeName.Caption)+''' '+
              ' Order by O.ItemCode ');
  Frm_Sys_Hint.ShowModal;
  Frm_Sys_Hint.Release;
end;

procedure TFrm_Inv_OpSumOut_B.DBGridEhEnter(Sender: TObject);
begin
  Medt_DateExit(sender);
  inherited;

end;

end.

⌨️ 快捷键说明

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