📄 inv_opout_d.pas
字号:
//陈自峰
unit Inv_OpOut_D;
//委外加工领料明细单元
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Entry_Detail, Db, AdODB, ExtCtrls, StdCtrls, ExtEdit;
Type
TFrm_Inv_OpOut_D = Class(TFrm_Base_Entry_Detail)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Lbl_PoRealQty: TLabel;
Lbl_PoCtrlQty: TLabel;
Lbl_UomName: TLabel;
Lbl_ItemName: TLabel;
Lbl_PoNo: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Edt_PoLineNo: TEdit;
ExtEdt_ItemCode: TExtEdit;
Edt_PoOutQty: TEdit;
Label4: TLabel;
lbl_useable: TLabel;
Label5: TLabel;
edt_remArk: TEdit;
Label6: TLabel;
Edit_BatchNo: TEdit;
procedure FormActivate(Sender: TObject);
procedure IntegerCheck(Sender: TObject);
procedure ItemCodeCheck(Sender: TObject);
procedure FloatCheck(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ExtEdt_ItemCodeExit(Sender: TObject);
procedure Edit_BatchNoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit_BatchNoExit(Sender: TObject);
procedure Edt_PoLineNoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
BillDate:String;
BillLines :Integer;
FPoNo :String; //单据号
WhCode :String; //仓库代码
Position :String; //仓位
IsOverPlan :Boolean; //标志是否超计划
PriOutQty :Double;
AllowNegative :String; //是否允许负数
FUom:string;
function ItemCheckRepeat(ItemCode,PoLineNo,pono:string):boolean;
procedure SaveBodyData; Override;
{ Private declarations }
public
procedure SetUserParam(Param1,Param2,Param3,Param4,Param5,Param6:string);OverRide;
procedure SetFormParam(FrmParam1,FrmParam2,FrmParam3,FrmParam4,FrmParam5,FrmParam6:string);OverRide;
procedure InitControls; Override;
procedure SetStatus(CurrentStatus:String;var EnableControls:String); OverRide;
{ Public declarations }
end;
var
Frm_Inv_OpOut_D: TFrm_Inv_OpOut_D;
implementation
uses Sys_Global,Inv_OpOut_B, Inv_OpOut_H,Inv_Global,Inv_PoHint;
{$R *.DFM}
{ TFrm_Inv_OpOut_D }
procedure TFrm_Inv_OpOut_D.SetStatus(CurrentStatus: String;
var EnableControls: String);
begin
inherited;
if (CurrentStatus='AllEdit') then
begin
EnableControls:='Edt_PoOutQty,edt_remArk,Edit_BatchNo,';
end
else if (CurrentStatus='Add') then
begin
EnableControls:='Edt_PoOutQty,Edt_PoLineNo,ExtEdt_ItemCode,edt_remArk,Edit_BatchNo,';
end;
end;
procedure TFrm_Inv_OpOut_D.FormActivate(Sender: TObject);
begin
inherited;
PriOutQty:=0;
end;
procedure TFrm_Inv_OpOut_D.InitControls;
begin
IF Status='Add' then
SetFocus_Control:=Edt_PoLineNo
else
SetFocus_Control:=Edt_PoOutQty;
inherited;
with AdoQry_Body do
if Pnl_Add.Caption='修改' then
begin
Lbl_PoRealQty.Caption:=fieldbyname('PoRealQty').AsString;
Lbl_PoCtrlQty.Caption:=fieldbyname('PoCtrlQty').AsString;
Lbl_UomName.Caption:=fieldbyname('UomName').AsString;
Edit_BatchNo.Text:=fieldbyname('BatchNo').asstring;
Lbl_ItemName.Caption:=fieldbyname('ItemName').AsString;
Lbl_PoNo.Caption:=FPoNo;
Edt_PoLineNo.Text:=fieldbyname('PoLineNo').AsString;
ExtEdt_ItemCode.Text:=fieldbyname('ItemCode').AsString;
Edt_PoOutQty.Text:=fieldbyname('PoOutQty').AsString;
lbl_useable.Caption:=fieldbyname('UseableStore').asstring;
end
else
begin
Lbl_PoRealQty.Caption:='0';
Lbl_PoCtrlQty.Caption:='0';
Lbl_UomName.Caption:='';
Lbl_ItemName.Caption:='';
Lbl_PoNo.Caption:=FPoNo;
Edt_PoLineNo.Text:='';
ExtEdt_ItemCode.Text:='';
Edt_PoOutQty.Text:='';
lbl_useable.Caption:='';
end;
If UpperCase(Param1)='OverPlan' then
begin
Caption:='委外加工超订单领料';
end
Else
begin
Caption:='委外加工领料';
end;
end;
procedure TFrm_Inv_OpOut_D.SaveBodyData;
var
i,NotZeroRecord:Integer;
Book1:TBookMArk;
begin
inherited;
with AdoQry_Body do
begin
Book1:=GetBookmArk;
First;
for i:=0 to RecordCount-1 do
begin
if fieldbyname('POOutQty').asinteger<>0 then
NotZeroRecord:=NotZeroRecord+1;
Next;
end;
GotoBookmArk(Book1);
end;
if NotZeroRecord>=BillLines then
begin
DispInfo('本单据最多只允许输入'+inttostr(BillLines)+'条单据行',1);
abort;
end
else
with AdoQry_Body do
begin
insert;
fieldbyname('PoLineNo').AsString:=Edt_PoLineNo.Text;
fieldbyname('UomName').AsString:=FUom;
fieldbyname('ItemName').AsString:=Lbl_ItemName.Caption;
fieldbyname('PoCtrlQty').AsString:=Lbl_PoCtrlQty.Caption;
fieldbyname('PoRealQty').AsString:=Lbl_PoRealQty.Caption;
fieldbyname('ItemCode').AsString:=ExtEdt_ItemCode.Text;
fieldbyname('UseableStore').AsString:=lbl_useable.Caption;
fieldbyname('PoOutQty').AsString:=Edt_PoOutQty.Text;
fieldbyname('BatchNo').asstring:=Edit_BatchNo.text;
fieldbyname('BillLineRemArk').asstring:=edt_remArk.Text;
Post;
end;
edt_remArk.Text:='';
end;
procedure TFrm_Inv_OpOut_D.IntegerCheck(Sender: TObject);
begin
inherited;
//
With AdoQry_Tmp do
begin
Close; //检查订单行号是否存在。
Sql.clear;
Sql.Add('Select Count(*) as RecCount from Poline Where PoNo='''+FPoNo+''''+
' and PoLineNo='+Trim(Edt_PoLineNo.Text));
Open;
If fieldbyname('RecCount').AsInteger<=0 then
begin
DispInfo('该采购订单行号不存在!',1);
Edt_PoLineNo.SetFocus;
Abort;
end;
Close;
sql.clear;
sql.Add('select POLineStatus from poline where PoNo='''+FPoNo+''' and '+
' PoLineNo='+Trim(Edt_PoLineNo.Text));
open;
If fieldbyname('POLineStatus').asstring<>'6' then
begin
DispInfo('不能输入非下达状态的订单行!',1);
Edt_PoLineNo.SetFocus;
Abort;
end;
end;
end;
procedure TFrm_Inv_OpOut_D.ItemCodeCheck(Sender: TObject);
begin
inherited;
//物料的领料查询
With AdoQry_Tmp do
begin
Close;
Sql.clear;
Sql.Add('Select Count(*) as RecCount from OPItemList Where PoNo='''+FPoNo+''''+
' and PoLineNo='+Trim(Edt_PoLineNo.Text)+
' and ItemCode='''+Trim(ExtEdt_ItemCode.Text)+'''');
Open;
If fieldbyname('RecCount').AsInteger>0 then
begin
DispInfo('该物料的领料记录已经存在,不允许增加!',1);
ExtEdt_ItemCode.SetFocus;
Abort;
end;
end;
Lbl_PoCtrlQty.Caption:='0';
Lbl_PoRealQty.Caption:='0';
end;
procedure TFrm_Inv_OpOut_D.FloatCheck(Sender: TObject);
begin
inherited;
if not InvQtyCheck(False,
AdoQry_Body,AdoQry_tmp,WhCode,Position,
Trim(ExtEdt_ItemCode.Text),'POOutQty',
StrToFloat(Edt_PoOutQty.Text),False,Status='Add') then
abort;
If (Status<>'Add') and (Not IsOverPlan)
And (StrToFloat(Edt_PoOutQty.Text)>
(StrToFloat(Lbl_PoCtrlQty.Caption)-StrToFloat(Lbl_PoRealQty.Caption))) then
begin
DispInfo('本次领料数量不能超过未领数量!',1);
Edt_PoOutQty.SetFocus;
Abort;
end;
If (StrToFloat(Lbl_PoRealQty.Caption)+StrToFloat(Edt_PoOutQty.Text)<0)
and (StrToFloat(Edt_PoOutQty.Text)<0) then
begin
DispInfo('冲消的数量不能大于累计领料数量!',1);
Edt_PoOutQty.SetFocus;
Abort;
end;
//如果已经存在负数输入正数,或者已经存在正数输入负数,或者原单据无正无负,但是与上条输入异号
IF ((UpperCase(AllowNegative)='YES') and (StrToFloat(Edt_PoOutQty.Text)>0))
Or ((UpperCase(AllowNegative)='NO') and (StrToFloat(Edt_PoOutQty.Text)<0))
Or ((UpperCase(AllowNegative)='NONE') and (PriOutQty*StrToFloat(Edt_PoOutQty.Text)<0)) then
begin
DispInfo('同一张领料单,不允许出现正负数混合的情况!',1);
Edt_PoOutQty.SetFocus;
Abort;
end;
if strtofloat(Edt_PoOutQty.text)>strtofloat(lbl_useable.Caption) then
begin
DispInfo('本次领料数量不能大于当前库存!',1);
Edt_PoOutQty.SetFocus;
Abort;
end;
If StrToFloat(Edt_PoOutQty.Text)<>0 then PriOutQty:=StrToFloat(Edt_PoOutQty.Text);
end;
procedure TFrm_Inv_OpOut_D.SetFormParam(FrmParam1, FrmParam2, FrmParam3,
FrmParam4, FrmParam5, FrmParam6: String);
begin
inherited;
AllowNegative:=FrmParam1;
BillDate:=FrmParam2;
end;
procedure TFrm_Inv_OpOut_D.FormCreate(Sender: TObject);
begin
inherited;
SetFocus_Control:=Edt_PoOutQty;
end;
procedure TFrm_Inv_OpOut_D.ExtEdt_ItemCodeExit(Sender: TObject);
var
tmpfields:string;
begin
inherited;
InOutItemCodeCheck(sender);
if not DefaultWHCheck(AdoQry_tmp,getCode(WhCode) ,Extedt_ItemCode.text) then
begin
twincontrol(sender).setfocus;
abort;
end;
if ItemCheckRepeat(ExtEdt_ItemCode.text,Edt_PoLineNo.text,Lbl_PoNo.Caption) then
begin
DispInfo('该订单行下已经存在该物料,请重新输入!',1);
Twincontrol(sender).setfocus;
abort;
end;
if not BatchCtrl(AdoQry_Tmp,ExtEdt_ItemCode.Text) then
begin
Edit_BatchNo.Text:='';
Edit_BatchNo.Color:=clMenu;
Edit_BatchNo.Enabled:=False;
end
else
begin
Edit_BatchNo.Color:=clwindow;
Edit_BatchNo.Enabled:=True;
end;
if Pnl_Add.Caption='增加' then
begin
tmpfields:=getInvfield(AdoQry_tmp,whCode,Position,'CurrentInv');
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='select c.'+tmpfields+
' as useablestore,U.UomName '+
' from CurrentInv c,Item I,Uom U '+
' where c.whCode='''+whCode+''' and '+
' c.ItemCode='''+ExtEdt_ItemCode.Text+''' and '+
' c.WhPositionCode='''+position+''' and c.'+
tmpfields+'>0 and '+
' I.ItemCode=c.ItemCode and '+
' U.UomCode=I.UomCode ';
AdoQry_Tmp.Open;
if (AdoQry_Tmp.IsEmpty) and (activecontrol.Name<>'btn_Cancel') then
begin
DispInfo('该物料的当前库存数量为零,不允许领料!',1);
ExtEdt_ItemCode.SetFocus;
exit;
end
else
begin
lbl_useable.Caption:=AdoQry_Tmp.fieldbyname('useablestore').asstring;
FUom:=AdoQry_Tmp.fieldbyname('UomName').asstring;
end;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='select U.UomName '+
' from Item I,Uom U '+
' where I.ItemCode='''+ExtEdt_ItemCode.text+''' and '+
' U.UomCode=I.UomCode';
AdoQry_Tmp.Open;
if not AdoQry_Tmp.IsEmpty then
Lbl_UomName.Caption:=AdoQry_Tmp.fieldbyname('UomName').asstring;
end;
end;
function TFrm_Inv_OpOut_D.ItemCheckRepeat(ItemCode,POLineNo,pono:string): boolean;
var
i:integer;
sql_Txt:string;
begin
sql_txt:='select * from opItemList '+
' where ItemCode='''+ItemCode+''' and '+
' pono='''+pono+''' and '+
' polineno='''+polineno+'''';
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add(sql_txt);
open;
end;
if AdoQry_Tmp.IsEmpty then
begin
AdoQry_Body.First;
for i:=0 to AdoQry_Body.recordCount-1 do
begin
if (AdoQry_Body.fieldbyname('ItemCode').asstring=ItemCode) and
(AdoQry_Body.fieldbyname('PoLIneNo').asstring=PoLIneNo) then
begin
Result:=True;
exit;
end;
AdoQry_Body.next;
end;
Result:=False;
end
else
Result:=True;
end;
procedure TFrm_Inv_OpOut_D.Edit_BatchNoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
If Key=VK_F9 then
Edit_BatchNo.text:=BatchHint(AdoQry_Tmp.Connection,ExtEdt_ItemCode.Text,
'',WhCode,Position);
end;
procedure TFrm_Inv_OpOut_D.Edit_BatchNoExit(Sender: TObject);
begin
inherited;
if not BatchNoCheck(AdoQry_Tmp,Edit_BatchNo.Text,ExtEdt_ItemCode.text,'',
BillDate)then
begin
Edit_BatchNo.setfocus;
Abort;
end;
if not BatchInvCheck(AdoQry_Tmp,Edit_BatchNo.text,'c',WhCode,Position,strtofloat(Edt_PoOutQty.text)) then
begin
Edit_BatchNo.setfocus;
Abort;
end;
end;
procedure TFrm_Inv_OpOut_D.Edt_PoLineNoKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
inherited;
if(Key=120)then
begin
with TFrm_Inv_PoHint.Create(Self) do
begin
InitForm(DBConnect,Lbl_PoNo.Caption,TEdit(Sender).Text,
now-10000,now+10000,1+100000/100);
if ShowModal=mrOk then
TEdit(Sender).Text:=POLineNo;
Release;
end;
TWinControl(Sender).SetFocus;
end;
end;
procedure TFrm_Inv_OpOut_D.SetUserParam(Param1, Param2, Param3, Param4,
Param5, Param6: string);
begin
inherited;
If UpperCase(Param1)='OverPlan' then
IsOverPlan:=True
Else If UpperCase(Param1)='InPlan' then
IsOverPlan:=False
Else
begin
DispInfo('系统参数传入不正确,请与系统管理员联系!',1);
Abort;
end;
BillLines:=StrToInt(Param4);
FPoNo:=Param2;
WhCode:=Param5;
Position:=Param6;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -