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

📄 inv_opsumout_b.pas

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

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Entry_Body, ExtPrintReport, Db, ActnList, AdODB, Grids, DBGridEh,
  ExtCtrls, ComCtrls, ToolWin, Mask, StdCtrls,dbGrids,Math, DBCtrls,
  Buttons, jpeg;

Type
  TFrm_Inv_OpSumOut_B = Class(TFrm_Base_Entry_Body)
    Lbl_PoNo: TLabel;
    Lbl_VendorCodeName: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Cmbx_WhCodeName: TComboBox;
    Cmbx_Position: TComboBox;
    Label5: TLabel;
    Label9: TLabel;
    Label7: TLabel;
    Edt_BillNo: TEdit;
    Medt_Date: TMaskEdit;
    Label10: TLabel;
    Edt_Memo: TEdit;
    Label4: TLabel;
    Label6: TLabel;
    DBText1: TDBText;
    AdoQry_tmp2: TAdoQuery;
    Btn_QryOpCurrentInv: TBitBtn;
    procedure AdoQry_BodyBeforePost(DataSet: TDataSet);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Act_autoExecute(Sender: TObject);
    procedure Act_SaveExecute(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Cmbx_WhCodeNameChange(Sender: TObject);
    procedure Cmbx_PositionChange(Sender: TObject);
    procedure Medt_DateExit(Sender: TObject);
    procedure AdoQry_BodyAfterScroll(DataSet: TDataSet);
    procedure DBGridEhKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Cmbx_WhCodeNameExit(Sender: TObject);
    procedure Cmbx_PositionExit(Sender: TObject);
    procedure Btn_QryOpCurrentInvClick(Sender: TObject);
    procedure DBGridEhEnter(Sender: TObject);
  private
    FPoLineNo:Integer;
    IsSpecial:boolean;
    Addormodify:boolean;
    Scrollflag:boolean;
    IsOverPlan :Boolean;
    FPoNo :String;
    MaxRecLineCount: integer;
    BillTypeCode :String;
    AllowNegative   :String;
    Function BatchSaveByNo(BillId,BatchNo,ItemCode,BillLineRemArk:String;POOutQty:real;Price:Double):Boolean;
    function CheckNotZero:boolean;
    function CheckAllSame:boolean;
    procedure refreshall;
    procedure DisableAll(flag:boolean);
    procedure InitCmbx_WhPosition(whCode:string);
    function InitwhposIfSpec:integer;
    procedure SaveData; OverRide;
   { Private declarations }
  public
    procedure InitForm(AdOConnection:TAdOConnection;FormStatus:String;
      AdoQuery:TAdoQuery);OverRide;
    procedure InitControls;Override;
    procedure SetUserParam(Param1,Param2,Param3,Param4,Param5,Param6:String);OverRide;
    procedure SetStatus(CurrentStatus:String;var AnswerStatus,
      EnableControls:String);OverRide;
    { Public declarations }
  end;

var
  Frm_Inv_OpSumOut_B: TFrm_Inv_OpSumOut_B;

implementation
uses Sys_Global,Inv_Global,Sys_Hint;
{$R *.DFM}

{ TFrm_Inv_OpSumOut_B }

function TFrm_Inv_OpSumOut_B.CheckAllSame: boolean;
var
  i:integer;
  flag:boolean;
begin
  AdoQry_Body.First;
  for i:=0 to AdoQry_Body.RecordCount-1 do
  begin
    if AdoQry_Body.fieldbyname('POOutQty').asfloat<>0 then
    begin
      if AdoQry_Body.fieldbyname('POOutQty').asfloat>0 then
      flag:=True
      else flag:=False;
      break;
    end;
    AdoQry_Body.next;
  end;
  AdoQry_Body.First;
  for i:=0 to AdoQry_Body.RecordCount-1 do
  begin
    if AdoQry_Body.fieldbyname('POOutQty').asfloat<>0 then
    begin
      if ((flag) and (AdoQry_Body.fieldbyname('POOutQty').asfloat<0)) or
      ((not flag) and (AdoQry_Body.fieldbyname('POOutQty').asfloat>0)) then
      begin
        Result:=False;
        exit;
      end;
    end;
    AdoQry_Body.next;
  end;
  Result:=True;
end;

function TFrm_Inv_OpSumOut_B.CheckNotZero: boolean;
var
  I:integer;
begin
  AdoQry_Body.First;
  for i:=0 to AdoQry_Body.RecordCount-1 do
  begin
    if AdoQry_Body.fieldbyname('POOutQty').asfloat<>0 then
    begin
      Result:=True;
      exit;
    end;
    AdoQry_Body.next;
  end;
  Result:=False;
end;

procedure TFrm_Inv_OpSumOut_B.DisableAll(flag: boolean);
begin
  Cmbx_WhCodeName.Enabled:=flag;
  Cmbx_Position.Enabled:=flag;
  //Edt_BillNo.Enabled:=flag;
  //act_Save.Enabled:=flag;
  Act_Modify.Enabled:=flag;
  Medt_Date.Enabled:=flag;
  Edt_Memo.Enabled:=flag;
  DBGridEh.ReadOnly:=not flag;
end;

procedure TFrm_Inv_OpSumOut_B.InitCmbx_WhPosition(whCode: string);
begin
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select P.WhPositionCode,P.WhPositionName '+
            ' from WhPosition P '+
            ' where P.WhCode='''+WhCode+''''+
            '   and P.BackFlushWhP=0 '+
            ' and p.WhPositionType<>1');
    open;
    cmbx_Position.clear;
    if not Eof then
    begin
      First;
      while not Eof do
      begin
        cmbx_Position.Items.Add(fieldbyname('WhPositionCode').asstring+' '+fieldbyname('WhPositionName').asstring);
        Next;
      end;
    end;
  end;
end;

procedure TFrm_Inv_OpSumOut_B.InitControls;
begin
  inherited;
  TlBtn_Modify.action:=act_auto;
  Scrollflag:=False;
  if AdoQry_Head.fieldbyname('PoSpecial').asinteger=1 then
  IsSpecial:=True
  else IsSpecial:=False;
  if showflag=True then
    exit;
  InitUsableWHCmbx(AdoQry_Tmp,UserCode,Cmbx_WhCodeName,False);
  InitCmbx_WhPosition(getCode(Cmbx_WhCodeName.text));
  Cmbx_Position.ItemIndex:=InitwhposIfSpec;
  Edt_BillNo.Text:='';
  refreshall;
  With AdoQry_Tmp do
  begin
    Close;
    Sql.clear;
    Sql.Add('select '+
          ' Count(*) As RecCount '+
          'from OpItemList OP '+
          ' Where Op.PoNo='''+FPoNo+''''+
          //' and Op.PoCtrlQty<=Op.PoRealQty '+
          ' and POOutQty<0 ');
    Open;
    If fieldbyname('RecCount').AsInteger>0 then
      AllowNegative:='YES'
    Else
    begin
      Close;
      Sql.clear;
      Sql.Add('select '+
               ' Count(*) As RecCount '+
              'from OpItemList OP '+
             ' Where Op.PoNo='''+FPoNo+''''+
             //'   and Op.PoCtrlQty<=Op.PoRealQty '+
               ' and POOutQty>0 ');
      Open;
      If fieldbyname('RecCount').AsInteger>0 then
        AllowNegative:='NO'
      Else  AllowNegative:='NONE';
    end;
  end;
  Lbl_PoNo.Caption:=FPoNo;
  Medt_Date.Text:=FormatDateTime('YYYY.MM.DD',Now());
  With AdoQry_Tmp do
  begin
    Close;
    Sql.clear;
    Sql.Add('select '+
            ' PO.VendorCode+'' ''+Vendor.VendorName as VendorCodeName '+
            'from  PO,Vendor '+
            'where PO.VendorCode*=Vendor.VendorCode and Po.PoNo='''+FPoNo+'''');
    Open;
    Lbl_VendorCodeName.Caption:=AdoQry_Tmp.fieldbyname('VendorCodeName').AsString;
  end;
end;

procedure TFrm_Inv_OpSumOut_B.InitForm(AdOConnection: TAdOConnection;
  FormStatus: String; AdoQuery: TAdoQuery);
begin
  inherited;
  AdoQry_tmp2.Connection:=AdOConnection;
  with DBGridEh do
  begin
    options:=options+[dgEditing]-[dgRowselect];
  end;
  AdoQry_Tmp.EnableBCD:=False;
  AdoQry_Body.EnableBCD:=False;
  With AdoQry_Tmp do
  begin
    Close;
    Sql.clear;
    Sql.Add('Select BillLINES From BillType Where BillTypeCode='''+BillTypeCode+'''');
    Open;
    MaxRecLineCount:=fieldbyname('BillLINES').AsInteger;
    Param4:=IntToStr(MaxRecLineCount);
  end;
  SetFocus_Control:=Cmbx_WhCodeName;
end;

function TFrm_Inv_OpSumOut_B.InitwhposIfSpec: integer;
var
  i:integer;
  Str:string;
  Ado_tmp:TAdoQuery;
begin
  if IsSpecial then
  begin
    Ado_tmp:=TAdoQuery.Create(nil);
    Ado_tmp.Connection:=AdoQry_Body.Connection;
    Ado_tmp.SQL.text:='select WhPositionCode '+
                      '  from WhPosition '+
                      ' where WHCode='''+getCode(Cmbx_WhCodeName.Text)+''' and '+
                      '       WhPositionType=2';
    Ado_tmp.Open;
    Str:=Ado_tmp.fieldbyname('WhPositionCode').asstring;
    For i:=0 to Cmbx_Position.Items.Count-1 do
    if getCode(Cmbx_Position.Items[i])=Trim(str) then
    begin
      Result:=i;
      exit;
    end;
  end
  else  Result:=0;
end;

procedure TFrm_Inv_OpSumOut_B.refreshall;
var
  tmpfields,sql_txt:string;
  i:integer;
  mypost:TDataSetNotifyEvent;
  tmp_WhCode,tmp_WhPositionCode:string;
begin
  inherited;
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:='Select WhPositionCode+'' ''+WhPositionName As WhPositionCodeName'
      +' From WhPosition'
      +' Where WHCode='''+GetCode(Cmbx_WhCodeName.Text)+''''
      +' And WhPositionType<>1 '
      +' And BackFlushWHP<>1'
      +' Order By WhPositionCode';
  AdoQry_Tmp.Open;
  AdoQry_Tmp.First;
  Cmbx_Position.clear;
  while not AdoQry_Tmp.Eof do
  begin
    Cmbx_Position.Items.Add(AdoQry_Tmp.fieldbyname('WhPositionCodeName').AsString);
    AdoQry_Tmp.Next;
  end;
  {if Status='ReadOnly' then
    InitCmBxText(CmBx_WhPosition,AdoQry_Head.fieldbyname('WhPositionCode').AsString)
  else}
  Cmbx_Position.Itemindex:=0;
 { If IsSpecial then
  begin
    tmp_WhCode:=GetCode(CmBx_Warehouse.Text);
    with AdoQry_Tmp do
    begin
      Close;
      SQL.clear;
      SQL.Add('Select WhPosition.WhPositionCode,WhPosition.WhPositionName '+
              ' From WhPosition '+
              ' Where WhPosition.WHCode='''+tmp_WhCode+''''+
              ' And WhPositionType=2  ');
      open;
      tmp_WhPositionCode:=fieldbyname('WhPositionCode').AsString;
    end;
    InitCmBxText(CmBx_WhPosition,tmp_WhPositionCode);
  end;}
  mypost:=AdoQry_Body.BeforePost;
  AdoQry_Body.BeforePost:=nil;
  With AdoQry_Body do
  begin
    tmpfields:=getInvfield(AdoQry_tmp,getCode(Cmbx_WhCodeName.text),getCode(Cmbx_Position.text),'CurrentInv');
    Close;
    Sql.clear;
    sql_txt:='select '+
          //'        op.ItemListId,'+
          '        op.pono,Op.ItemCode, '+
          '        Item.ItemName,Uom.UomName, '+
          '        op.pono BatchNo, '+
          '        Sum(Round(Op.PoCtrlQty,0))PoCtrlQty,Sum(Round(Op.PoRealQty,0))PoRealQty, '+
          '        case when c.'+tmpfields+' is Null then 0 else '+
          '        c.'+tmpfields+' end UseableStore,Op.PoOutQty,op.pono BillLineRemArk '+
          'from OpItemList OP '+
          ' Left join CurrentInv c '+
          '   on c.whCode='''+getCode(Cmbx_WhCodeName.text)+''''+
          '      and c.WhPositionCode='''+getCode(cmbx_Position.text)+''''+
          '      and c.ItemCode=op.ItemCode '+
          ' Join Item on Item.ItemCode=Op.ItemCode '+
          ' join Uom  on Uom.UomCode=Item.UomCode '+
          ' join poline on poline.pono=op.pono and '+
          '      poline.polineno=op.polineno '+
    ' where poline.POLineStatus=6 and '+
          ' Op.PoNo='''+FPoNo+''' and '+
          ' round(op.PoCtrlQty,0)-round(op.PoRealQty,0)>=0 and '+
          ' (Item.whCode='''+getCode(Cmbx_WhCodeName.text)+''' or '+
          ' C.'+tmpfields+'>0)'+
          ' Group by op.pono,Op.ItemCode,'+//op.ItemListId,'+
          '          Item.ItemName,Uom.UomName,'+
          '          Op.poOutQty,'+
          '          c.'+tmpfields;
    SQL.Add(sql_txt);
    Open;
    for i:=0 to recordCount-1 do
    begin
      edit;
      fieldbyname('BatchNo').asstring:='';
      fieldbyname('POOutQty').asString:='0';
      fieldbyname('BillLineRemArk').asstring:='';
      //fieldbyname('PoCtrlQty').asfloat:=round(fieldbyname('PoCtrlQty').asfloat);
      post;
      next;
    end;
    First;
  end;
  AdoQry_Body.BeforePost:=mypost;
end;

procedure TFrm_Inv_OpSumOut_B.SaveData;
var i:Integer;      //循环控制变量
    BeforeSaveError :Boolean;  //HASREC是标志是否有合格记录,
    Billid :String;  //保存单据头中的字增字段值
    PriceType,ItemListId :Integer;  //价格计算方法
    NeedChangePrice:Boolean;
    Price:double;
    BillNo :String;  //保存获得的单据号
begin
  inherited;
  if AdoQry_Head.state<>dsBrowse then
    AdoQry_Head.post;
  if AdoQry_Body.state<>dsBrowse then
    AdoQry_Body.post;
  BeforeSaveError:=True;
  Cmbx_WhCodeNameExit(Cmbx_WhCodeName);
  DateCheck(Medt_Date);
  AdoQry_Body.DisableControls ;    
  AdoQry_Body.First;
  //上月是否已经结帐,否,不进行移动加权平均价的计算
  NeedChangePrice:=NeedChangeAveragePrice(AdoQry_tmp,copy(Medt_Date.text,1,7));
  //是否为独立订单
  With  AdoQry_Tmp do
  begin
    Close;
    Sql.clear;
    Sql.Add('Select PriceType from Warehouse where  WHCode='''+GetCode(Cmbx_WhCodeName.Text)+'''');
    Open;

⌨️ 快捷键说明

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