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

📄 inv_opoutsale_b.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
// 
unit Inv_OpOutSale_B;
//委外加工领料表体单元
Interface

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

Type
  TFrm_Inv_OpOutSale_B = Class(TFrm_Base_Entry_Body)
    Label2: TLabel;
    Cmbx_WhCodeName: TComboBox;
    Label5: TLabel;
    Cmbx_Position: TComboBox;
    Label9: TLabel;
    Medt_Date: TMaskEdit;
    Label10: TLabel;
    Edt_Memo: TEdit;
    Label4: TLabel;
    Label1: TLabel;
    Lbl_VendorCodeName: TLabel;
    Label3: TLabel;
    Lbl_PoNo: TLabel;
    Label6: TLabel;
    AdoQry_BodyPoLIneNo: TIntegerField;
    AdoQry_BodyItemCode: TStringField;
    AdoQry_BodyItemName: TStringField;
    AdoQry_BodyUomName: TStringField;
    AdoQry_BodyPoCtrlQty: TFloatField;
    AdoQry_BodyPoRealQty: TFloatField;
    AdoQry_BodyPOOutQty: TFloatField;
    Lbl_PoItemName: TLabel;
    AdoQry_Tmp2: TAdoQuery;
    Label7: TLabel;
    Edt_BillNo: TEdit;
    DBText1: TDBText;
    AdoQry_Bodypono: TStringField;
    AdoQry_BodyUseableStore: TFloatField;
    AdoQry_BodyBillLineRemArk: TStringField;
    AdoQry_BodyBomQty: TFloatField;
    AdoQry_BodyBomScrAp_Percent: TFloatField;
    AdoQry_Bodyite_ItemCode: TStringField;
    AdoQry_BodyItemListid: TAutoIncField;
    AdoQry_BodyBatchNo: TStringField;
    AdoQry_Bodyusestyle: TIntegerField;
    AdoQry_Bodysp2Price: TFloatField;
    AdoQry_Bodysp2notaxPrice: TFloatField;
    AdoQry_BodytaxAmount: TFloatField;
    AdoQry_BodynotaxAmount: TFloatField;
    Label8: TLabel;
    lbl_taxpercent: TLabel;
    procedure AdoQry_BodyAfterScroll(DataSet: TDataSet);
    procedure Act_DeleteLineExecute(Sender: TObject);
    procedure Act_InsertLineExecute(Sender: TObject);
    procedure Act_ModifyExecute(Sender: TObject);
    procedure Cmbx_WhCodeNameChange(Sender: TObject);
    procedure Cmbx_WhCodeNameExit(Sender: TObject);
    procedure Cmbx_PositionExit(Sender: TObject);
    procedure Medt_DateExit(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Act_SaveExecute(Sender: TObject);
    procedure Cmbx_PositionChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure AdoQry_BodyBeforePost(DataSet: TDataSet);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    procedure Act_autoExecute(Sender: TObject);
    procedure DBGridEhKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGridEhEnter(Sender: TObject);
    procedure AdoQry_BodyCalcFields(DataSet: TDataSet);
  private
    IsSpecial:boolean;
    Addormodify:boolean;
    Scrollflag:boolean;
    IsOverPlan :Boolean;
    FPoNo :String;
    MaxRecLineCount: integer;
    BillTypeCode :String;
    AllowNegative   :String;
    taxpercent:string;
    function CheckNotZero:boolean;
    function CheckAllSame:boolean;
    procedure refreshall;
    procedure DisableAll(flag:boolean);
    procedure InitCmbx_WhPosition(whCode:string);
    function InitwhposIfSpec:integer;
    procedure SaveData; OverRide;
    procedure set_OverPlan(flag:boolean);
   { 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_OpOutSale_B: TFrm_Inv_OpOutSale_B;

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

{ TFrm_Inv_OpOut_B }

procedure TFrm_Inv_OpOutSale_B.InitCmbx_WhPosition(whCode: string);
begin
  //对货位COMBOBOX的填充
  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_OpOutSale_B.InitControls;
begin
  With AdoQry_Tmp do
  begin
    Close;
    Sql.clear;
    Sql.Add('select '+
            ' PO.VendorCode+'' ''+Vendor.VendorName as VendorCodeName,Vendor.Vendortaxrate_Percent '+
            'from  PO,Vendor '+
            'where PO.VendorCode*=Vendor.VendorCode and Po.PoNo='''+FPoNo+'''');
    Open;
    Lbl_VendorCodeName.Caption:=AdoQry_Tmp.fieldbyname('VendorCodeName').AsString;
    lbl_taxpercent.Caption:=AdoQry_Tmp.fieldbyname('Vendortaxrate_Percent').AsString;
//添加备注 by johnson
{    Close;
    sql.Text:='select PORemArk from po where pono='''+FPoNo+'''';
    open;
    Edt_Memo.Text:=fieldbyname('poremArk').asstring;}
  end;
  inherited;
  TlBtn_Modify.action:=act_auto;
//  toolbutton7.Action :=act_auto;
  Scrollflag:=False;
  //act_Save.Enabled:=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());
end;

procedure TFrm_Inv_OpOutSale_B.InitForm(AdOConnection: TAdOConnection;
  FormStatus: String; AdoQuery: TAdoQuery);
begin
  inherited;
  //设定DBGRID为编辑属性
  with DBGridEh do
  begin
    options:=options+[dgEditing]-[dgRowselect];
  end;
  AdoQry_Tmp2.Connection:=AdoConnection;
  AdoQry_Tmp.EnableBCD:=False;
  AdoQry_Body.EnableBCD:=False;
  AdoQry_Tmp2.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;

procedure TFrm_Inv_OpOutSale_B.AdoQry_BodyAfterScroll(DataSet: TDataSet);
begin
  inherited;
  //如果当前记录移动(订单行号改变),则更新下面的‘当前订单行物料描述’
 With AdoQry_tmp do
 begin
   Close;
   Sql.clear;
   Sql.Add('Select '+
           '  Item.ItemName '+
           'From PoLine,Item '+
           'Where PoLine.PoLineNo='''+AdoQry_Body.fieldbyname('PoLineNo').AsString+''''+
           '  and PoLine.PoNo='''+FPoNo+''''+
           '  and Item.ItemCode=PoLine.ItemCode');
   Open;
   Lbl_PoItemName.Caption:=fieldbyname('ItemName').AsString;
 end;
 if (AdoQry_Body.Eof) and (not Scrollflag) then AdoQry_Body.Cancel;
end;

procedure TFrm_Inv_OpOutSale_B.SetUserParam(Param1, Param2, Param3, Param4,
  Param5, Param6: String);
begin
  inherited;
  FPoNo:=Param2;
  BillTypeCode:=Param3;
  //判断传入参数的正确性
  If UpperCase(Param1)='OverSalE' then
    IsOverPlan:=True
  Else If UpperCase(Param1)='INSalE' then
    IsOverPlan:=False
  Else
  begin
    DispInfo('系统参数传入不正确,请与系统管理员联系!',1);
    Abort;
  end;
end;

procedure TFrm_Inv_OpOutSale_B.SetStatus(CurrentStatus: String;
  var AnswerStatus, EnableControls: String);
begin
  inherited;
{  if (CurrentStatus='Edit') then
  begin
    AnswerStatus:='AllEdit';
    EnableControls:='Cmbx_WhCodeName,Cmbx_Position,Medt_Date,Edt_Memo,';
  end
  else}
  if (CurrentStatus='Add') then
  begin
    AnswerStatus:='Add';
    EnableControls:='Cmbx_WhCodeName,Cmbx_Position,Medt_Date,Edt_Memo,';
    Addormodify:=True;
  end
  else
  begin
    Addormodify:=False;
    EnableControls:='Cmbx_WhCodeName,Cmbx_Position,';
    AnswerStatus:='Alledit';
  end;
end;

procedure TFrm_Inv_OpOutSale_B.Act_DeleteLineExecute(Sender: TObject);
begin
//在删除一行前进行检查,必须限额领料数量和累计领料数量均为0才可以删除
  If  (AdoQry_Body.fieldbyname('PoCtrlQty').AsFloat<>0)
    or (AdoQry_Body.fieldbyname('PoRealQty').AsFloat<>0) then
  begin
    DispInfo('不是新增的行,不允许删除! ',1);
    Abort;
  end;
  inherited;
end;

procedure TFrm_Inv_OpOutSale_B.Act_InsertLineExecute(Sender: TObject);
begin
  if not WHClsPeriodCheck(AdoQry_Tmp,GetCode(Cmbx_WhCodeName.Text),Copy((Medt_Date.Text),1,7)) then
  begin
    Medt_Date.SetFocus;
    abort;
  end;
  Param3:=getCode(Lbl_VendorCodeName.Caption);
  Param5:=GetCode(Cmbx_WhCodeName.Text);
  Param6:=GetCode(Cmbx_Position.Text);
  If Param5='' then
  begin
    DispInfo('请选择一个仓库!',1);
    Abort;
  end;
  If Param6='' then
  begin
    DispInfo('请选择一个货位!',1);
    Abort;
  end;
  taxpercent:=getCode(lbl_taxpercent.Caption);
  Frm_Entry_Detail.SetUserParam(Param1,Param2,Param3,Param4,Param5,Param6);
  Frm_Entry_Detail.SetFormParam(AllowNegative,Medt_Date.text,taxpercent,'','','');
  Scrollflag:=True;
  inherited;
  Scrollflag:=False;
end;

procedure TFrm_Inv_OpOutSale_B.Act_ModifyExecute(Sender: TObject);
begin
{  AdoQry_Body.First;
  with AdoQry_Body do
  for i:=0 to recordCount-1 do
  begin
    edit;
    fieldbyname('PooutQty').asfloat:=
    min(round(fieldbyname('PoCtrlQty').asfloat)-round(fieldbyname('PoRealQty').asfloat),
    fieldbyname('UseableStore').asfloat);
    if fieldbyname('PooutQty').asfloat<0 then fieldbyname('PooutQty').asfloat:=0;
    post;
    next;
  end;
  DBGridEh.Refresh;
  ToolButton2.Enabled:=True;}
end;


procedure TFrm_Inv_OpOutSale_B.SaveData;
var i,m,x :Integer;      //循环控制变量
    HasRec,BeforeSaveError :Boolean;  //HASREC是标志是否有合格记录,
    BillNo :String;  //保存获得的单据号
    Billid :String;  //保存单据头中的字增字段值
    PriceType,ItemListId :Integer;  //价格计算方法
    NeedChangePrice:Boolean;
    Price:double;
begin
//  inherited;
  try
    AdoQry_Tmp.Connection.beginTrans;
    AdoQry_Body.DisableControls;
    AdoQry_Body.First;
    HasRec:=False;
    For I:=0 to AdoQry_Body.RecordCount-1 do
    begin
      If AdoQry_Body.fieldbyname('POOutQty').AsFloat<>0 then
      begin
        HasRec:=True;
        Break;
      end;
      AdoQry_Body.Next;
    end;

    If  not HasRec then
    begin
      DispInfo('新增的单据没有记录,不允许保存!',1);
      disableall(True);
      AdoQry_Body.EnableControls;
      Abort;
    end;
    //全面有效检查
    if AdoQry_Body.State<>dsBrowse then
    AdoQry_Body.Post;

    BeforeSaveError:=True;
    Cmbx_WhCodeNameExit(Cmbx_WhCodeName);
    DateCheck(Medt_Date);
    AdoQry_Body.First;
    //上月是否已经结帐,否,不进行移动加权平均价的计算
    NeedChangePrice:=NeedChangeAveragePrice(AdoQry_tmp,copy(Medt_Date.text,1,7));
    for M:=0 to AdoQry_Body.recordCount-1 do
    begin
      If round(AdoQry_Body.fieldbyname('PoOutQty').AsFloat*1000)/1000=0 then
      begin
        AdoQry_Body.next;
        continue;
      end;
      if not InvQtyCheck
          (NeedChangePrice,
           AdoQry_Body,
           AdoQry_tmp,
           getCode(Cmbx_WhCodeName.text),
           getCode(Cmbx_Position.Text),
           AdoQry_Body.fieldbyname('ItemCode').asstring,
           'PoOutQty',
           AdoQry_Body.fieldbyname('PoOutQty').asfloat,
           False) then
        begin
          disableall(True);
          //AdoQry_Body.Connection.RollBackTrans;
          AdoQry_Body.EnableControls;
          abort;
        end;
       if AdoQry_Body.fieldbyname('BatchNo').asstring<>'' then
         if not BatchInvCheck(AdoQry_Tmp,
                              AdoQry_Body.fieldbyname('BatchNo').asstring,'c',
                              getCode(Cmbx_WhCodeName.Text),
                              getCode(Cmbx_Position.Text),
                              AdoQry_Body.fieldbyname('POOutQty').asfloat) then Abort;
       AdoQry_Body.next;
    end;

⌨️ 快捷键说明

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