📄 inv_purchasein_d.pas
字号:
unit Inv_PurchaseIn_D;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Entry_Detail, Db, AdODB, ExtCtrls, StdCtrls, ExtEdit;
Type
TFrm_Inv_PurchaseIn_D = Class(TFrm_Base_Entry_Detail)
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label8: TLabel;
Lbl_ItemName: TLabel;
Edt_BillQty: TEdit;
Edt_PoLineNo: TEdit;
Label1: TLabel;
Lbl_PoNo: TLabel;
Lbl_UomName: TLabel;
Lbl_ItemCode: TLabel;
edt_memo: TEdit;
Label6: TLabel;
Label7: TLabel;
Edt_BatchNo: TEdit;
procedure Edt_BillQtyExit(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Edt_PoLineNoExit(Sender: TObject);
procedure Edt_PoLineNoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edt_BatchNoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edt_BatchNoExit(Sender: TObject);
procedure btn_okClick(Sender: TObject);
private
{ Private declarations }
flag:integer;
LineCount:Integer;
Ffdays:Integer;//比订单要求的“约定交货期”提前多少天到货可以接受
Fbdays:Integer;//比订单要求的“约定交货期”滞后多少天到货可以接受
Foqty:Double;//比订单要求的“约定交货量”超过百分之多少可以接受
WHCode,WhPositionCode,CurrentDate:string;
public
{ Public declarations }
procedure InitControls; Override;
procedure SaveBodyData; Override;
procedure SetStatus(CurrentStatus:String;var EnableControls:String); Override;
procedure SetFormParam(FrmParam1,FrmParam2,FrmParam3,FrmParam4,FrmParam5,
FrmParam6:String);Override;
end;
var
Frm_Inv_PurchaseIn_D: TFrm_Inv_PurchaseIn_D;
implementation
uses Sys_Global,Inv_PoHint,Inv_Global;
{$R *.DFM}
{ TFrm_Inv_SaleMaterial_D }
procedure TFrm_Inv_PurchaseIn_D.InitControls;
begin//初始化控件值
inherited;
Lbl_PoNo.Caption:=AdoQry_Head.fieldbyname('PoNo').AsString;
with AdoQry_Body do
begin
Edt_PoLineNo.Text:=fieldbyname('POLineNo').AsString;
Lbl_ItemCode.Caption:=fieldbyname('ItemCode').AsString;
Lbl_ItemName.Caption:=fieldbyname('ItemName').AsString;
Lbl_UomName.Caption:=fieldbyname('UomName').AsString;
edt_memo.text:=fieldbyname('BilllineremArk').AsString;
Edt_BatchNo.Text:=fieldbyname('BatchNo').AsString;
if (Status='Add')and(AdoQry_Body.IsEmpty) then
begin
Edt_BillQty.Text:='0';
end
else
begin
Edt_BillQty.Text:=fieldbyname('InvBillQty').AsString;
end;
end;
flag:=0;
end;
procedure TFrm_Inv_PurchaseIn_D.SaveBodyData;
begin//写入缓存
inherited;
with AdoQry_Body do
begin
fieldbyname('POLineNo').AsString:=Edt_PoLineNo.Text;
fieldbyname('ItemCode').AsString:=Lbl_ItemCode.Caption;
fieldbyname('ItemName').AsString:=Lbl_ItemName.Caption;
fieldbyname('UomName').AsString:=Lbl_UomName.Caption;
fieldbyname('InvBillQty').AsString:=Edt_BillQty.Text;
fieldbyname('BatchNo').AsString:=Edt_BatchNo.Text;
fieldbyname('BillLineremArk').AsString:=edt_memo.text;
fieldbyname('InvBillSfcQty').AsString:='0';
Post;
end;
end;
procedure TFrm_Inv_PurchaseIn_D.SetStatus(CurrentStatus: String;
var EnableControls: String);
begin
inherited;
if CurrentStatus='Add' then
begin
if LineCount=-1 then
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select BillLines'
+' From BillType'
+' Where BillTypeCode='''+Param1+'''';
AdoQry_Tmp.Open;
LineCount:=AdoQry_Tmp.fieldbyname('BillLines').AsInteger;
end;
if AdoQry_Body.RecordCount>=LineCount then
begin
EnableControls:='None';
DispInfo('本单据最多只允许输入'+IntToStr(LineCount)+'条单据行',3);
end;
end;
end;
procedure TFrm_Inv_PurchaseIn_D.Edt_BillQtyExit(Sender: TObject);
var
tmp_Poqty,tmp_SumQty:real;
BookmArk:TBookmArk;
i:integer;
tmp_ItemCode:string;
NeedChangePrice:Boolean;
begin
inherited;
if (ActiveControl.Name='btn_Cancel') or (ActiveControl.Name='Edt_PoLineNo') then
Abort;
if Trim(Edt_BillQty.text)= '' then
begin
DispInfo(' 入库数量不能为空!',3);
Edt_BillQty.SetFocus;
Abort;
end;
FloatCheck(Sender);
if TEdit(Sender).Text='0' then
begin
DispInfo(' 入库数量不能等于零!',3);
TWinControl(Sender).SetFocus;
Abort;
end;
NeedChangePrice:=NeedChangeAveragePrice(AdoQry_Tmp,FormatDateTime('yyyy.mm',
AdoQry_Head.fieldbyname('InvBillDate').AsDateTime));
if not InvQtyCheck(NeedChangePrice,AdoQry_Body,AdoQry_Tmp,WHCode,WhPositionCode,
Lbl_ItemCode.Caption,'InvBillQty',StrToFloat(TEdit(Sender).Text),
True,Status='Add') then
begin
TWinControl(Sender).SetFocus;
Abort;
end;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select PoQty,PoRealInQty+PoInQty As SumQty'
+' From PoLine'
+' Where PoNo='''+Lbl_PoNo.Caption+''''
+' And PoLineNo='''+Edt_PoLineNo.Text+'''';
AdoQry_Tmp.Open;
tmp_Poqty:=AdoQry_Tmp.fieldbyname('PoQty').AsFloat;
tmp_SumQty:=AdoQry_Tmp.fieldbyname('SumQty').AsFloat;
if UpperCase(Param2)<>'Over' then
if (round(tmp_Poqty*(1+Foqty/100)))<
(tmp_SumQty+StrToFloat(TEdit(Sender).Text)) then
begin
TWinControl(Sender).SetFocus;
DispInfo(' 累计交货数量超过规定的限额,拒绝收货! ',3);
Abort;
end;
if StrToFloat(TEdit(Sender).Text)<0 then
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select PoRealInQty From PoLine'
+' Where PoNo='''+Lbl_PoNo.Caption+''''
+' And PoLineNo='''+Edt_PoLineNo.Text+'''';
AdoQry_Tmp.Open;
tmp_Poqty:=AdoQry_Tmp.fieldbyname('PoRealInQty').AsFloat;
If (tmp_Poqty+StrToFloat(TEdit(Sender).Text))<0 then
begin
DispInfo('冲消的数量不能大于累计入库数量!',1);
TEdit(Sender).SetFocus;
end;
end;
//控制正,负方向一致,同一张单据只能有一个方向
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select ItemCode From PoLine'
+' Where PoNo='''+Lbl_PoNo.Caption+''''
+' And PoLineNo='''+Edt_PoLineNo.Text+'''';
AdoQry_Tmp.Open;
tmp_ItemCode:=AdoQry_Tmp.fieldbyname('ItemCode').AsString;
BookmArk:=AdoQry_Body.GetBookmArk;
AdoQry_Body.EnableControls;
AdoQry_Body.First;
for I:=0 to AdoQry_Body.RecordCount-1 do
begin
if ((strtofloat(Edt_BillQty.text)*AdoQry_Body.fieldbyname('InvBillqty').asfloat<0)
and(AdoQry_Body.fieldbyname('ItemCode').asstring<>tmp_ItemCode))then
begin
DispInfo('同一请领,不能出现正负数量混合的情况!',1);
Edt_BillQty.setfocus;
AdoQry_Body.GotoBookmArk(BookmArk);
AdoQry_Body.FreeBookmArk (BookmArk);
AdoQry_Body.EnableControls;
abort;
end;
AdoQry_Body.next;
end;
AdoQry_Body.GotoBookmArk(BookmArk);
AdoQry_Body.FreeBookmArk (BookmArk);
AdoQry_Body.EnableControls;
end;
procedure TFrm_Inv_PurchaseIn_D.FormCreate(Sender: TObject);
begin
inherited;
LineCount:=-1;
flag:=0;
SetFocus_Control:=Edt_PoLineNo;
end;
procedure TFrm_Inv_PurchaseIn_D.Edt_PoLineNoExit(Sender: TObject);
var
BookMArk:TBookMArk;
tmp_Poqty,tmp_SumQty:real;
begin
inherited;
if(ActiveControl.Name='btn_Cancel')then
Abort;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:=' Select poline.PoNo,poline.PoLineDate,poline.ItemCode,poline.PoLineStatus,Item.iScheck'
+' From PoLine,Item'
+' Where poline.ItemCode=Item.ItemCode'
+' and poline.PoNo='''+Trim(Lbl_PoNo.Caption)+''''
+' And poline.PoLineNo='+Trim(Edt_PoLineNo.Text)+'';
AdoQry_Tmp.Open;
if (AdoQry_Tmp.fieldbyname('PoNo').AsString='')or
(AdoQry_Tmp.fieldbyname('PoLineStatus').AsString<>'6')then
begin
DispInfo('该订单行不存在或不处于下达状态',3);
TWinControl(Sender).SetFocus;
Abort;
end;
{ if AdoQry_Tmp.fieldbyname('iScheck').asinteger=1 then
begin
DispInfo('物料代码必须是不必检的,请重新输入!',3);
TWinControl(Sender).SetFocus;
abort;
end;}
Lbl_ItemCode.Caption:=AdoQry_Tmp.fieldbyname('ItemCode').AsString;
if UpperCase(Param2)<>'Over' then
begin
if(AdoQry_Head.fieldbyname('InvBillDate').AsDateTime+Ffdays<
AdoQry_Tmp.fieldbyname('PoLineDate').AsDateTime)then
begin
TWinControl(Sender).SetFocus;
DispInfo(' 交货日期早于规定的时间,拒绝收货! ',3);
Abort;
end;
if(AdoQry_Head.fieldbyname('InvBillDate').AsDateTime-Fbdays>
AdoQry_Tmp.fieldbyname('PoLineDate').AsDateTime)then
begin
TWinControl(Sender).SetFocus;
DispInfo(' 交货日期晚于规定的时间,拒绝收货! ',3);
Abort;
end;
end
else
begin
if(AdoQry_Head.fieldbyname('InvBillDate').AsDateTime+Ffdays>=
AdoQry_Tmp.fieldbyname('PoLineDate').AsDateTime)
and(AdoQry_Head.fieldbyname('InvBillDate').AsDateTime-Fbdays<=
AdoQry_Tmp.fieldbyname('PoLineDate').AsDateTime)then
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select PoQty,PoRealInQty+PoInQty As SumQty'
+' From PoLine'
+' Where PoNo='''+Lbl_PoNo.Caption+''''
+' And PoLineNo='''+Edt_PoLineNo.Text+'''';
AdoQry_Tmp.Open;
tmp_Poqty:=AdoQry_Tmp.fieldbyname('PoQty').AsFloat;
tmp_SumQty:=AdoQry_Tmp.fieldbyname('SumQty').AsFloat;
if round(tmp_Poqty*(1+Foqty/100))>tmp_SumQty then
begin
DispInfo('该订单行交货期,交货数量正常,不应使用超订单功能!',3);
Abort;
end;
end;
end;
BookMArk:=AdoQry_Body.GetBookmArk;
if Status='Add' then
begin
AdoQry_Body.First;
while not AdoQry_Body.Eof do
begin
if AdoQry_Body.fieldbyname('POLineNo').AsString=TEdit(Sender).Text then
begin
AdoQry_Body.GotoBookmArk(BookmArk);
AdoQry_Body.FreeBookmArk(BookmArk);
TWinControl(Sender).SetFocus;
DispInfo(' 同一张单据中不能有相同的采购订单行号! ',3);
Abort;
end;
AdoQry_Body.Next;
end;
end
else
begin
if AdoQry_Body.fieldbyname('POLineNo').AsString<>TEdit(Sender).Text then
begin
AdoQry_Body.First;
while not AdoQry_Body.Eof do
begin
if AdoQry_Body.fieldbyname('POLineNo').AsString=TEdit(Sender).Text then
begin
AdoQry_Body.GotoBookmArk(BookmArk);
AdoQry_Body.FreeBookmArk(BookmArk);
TWinControl(Sender).SetFocus;
DispInfo(' 同一张单据中不能有相同的采购订单行号! ',3);
Abort;
end;
AdoQry_Body.Next;
end;
end;
end;
AdoQry_Body.GotoBookmArk(BookmArk);
AdoQry_Body.FreeBookmArk(BookmArk);
if not DefaultWHCheck(AdoQry_Tmp,WHCode,Lbl_ItemCode.Caption) then
begin
TWinControl(sender).SetFocus;
Abort;
end;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select ItemName,UomName'
+' From Item Join Uom On Item.UomCode=Uom.UomCode'
+' Where Item.ItemCode='''+Lbl_ItemCode.Caption+'''';
AdoQry_Tmp.Open;
Lbl_ItemName.Caption:=AdoQry_Tmp.fieldbyname('ItemName').AsString;
Lbl_UomName.Caption:=AdoQry_Tmp.fieldbyname('UomName').AsString;
if flag=0 then
begin
with AdoQry_Tmp do
begin
Close;
sql.clear ;
sql.text:='Select poline.PoNo,poline.POQty-poline.PORealInQty as qty,Item.iScheck'
+' From PoLine,Item'
+' Where poline.ItemCode=Item.ItemCode'
+' and poline.PoNo='''+Trim(Lbl_PoNo.Caption)+''''
+' And poline.PoLineNo='+Trim(Edt_PoLineNo.Text)+''
+' and Item.iScheck<>1';
open;
Edt_BillQty.text:=fieldbyname('qty').asstring;
end;
end;
if not BatchCtrl(AdoQry_Tmp,Lbl_ItemCode.Caption) then
begin
Edt_BatchNo.Text:='';
Edt_BatchNo.ReadOnly:=True;
end
else
begin
Edt_BatchNo.ReadOnly:=False;
end;
end;
procedure TFrm_Inv_PurchaseIn_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,
StrToDateTime(CurrentDate)-Fbdays,StrToDateTime(CurrentDate)+Ffdays,1+Foqty/100);
if ShowModal=mrOk then
TEdit(Sender).Text:=POLineNo;
Release;
end;
TWinControl(Sender).SetFocus;
end;
end;
procedure TFrm_Inv_PurchaseIn_D.SetFormParam(FrmParam1, FrmParam2, FrmParam3,
FrmParam4, FrmParam5, FrmParam6: String);
begin
inherited;
WHCode:=FrmParam1;
CurrentDate:=FrmParam2;
Ffdays:=StrToInt(FrmParam3);//比订单要求的“约定交货期”提前多少天到货可以接受
Fbdays:=StrToInt(FrmParam4);//比订单要求的“约定交货期”滞后多少天到货可以接受
Foqty:=StrToFloat(FrmParam5);//比订单要求的“约定交货量”超过百分之多少可以接受
WhPositionCode:=FrmParam6;
end;
procedure TFrm_Inv_PurchaseIn_D.Edt_BatchNoKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
inherited;
if(Key=120)and(TEdit(Sender).ReadOnly=False)then
TEdit(Sender).Text:=BatchHint(DBConnect,Lbl_ItemCode.Caption
,AdoQry_Head.fieldbyname('VendorCode').AsString
,AdoQry_Head.fieldbyname('WHCode').AsString
,AdoQry_Head.fieldbyname('WhPositionCode').AsString);
end;
procedure TFrm_Inv_PurchaseIn_D.Edt_BatchNoExit(Sender: TObject);
begin
inherited;
if(ActiveControl.Name='btn_Cancel')then
Abort;
if TEdit(Sender).ReadOnly=False then
begin
if not BatchNoCheck(AdoQry_Tmp,TEdit(Sender).Text,Lbl_ItemCode.Caption
,AdoQry_Head.fieldbyname('VendorCode').AsString
,CurrentDate) then
begin
TWinControl(Sender).SetFocus;
Abort;
end;
end;
end;
procedure TFrm_Inv_PurchaseIn_D.btn_okClick(Sender: TObject);
begin
try
strtofloat(Edt_BillQty.text);
except
DispInfo(' 数值非法! ',1);
Edt_BillQty.setfocus;
abort;
end;
if strtofloat(Edt_BillQty.text)=0 then
begin
DispInfo(' 入库数量不能等于零!',3);
Edt_BillQty.SetFocus;
Abort;
end;
if strtofloat(Edt_BillQty.text)>0 then
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:=' Select Item.iScheck'
+' From PoLine,Item'
+' Where poline.ItemCode=Item.ItemCode'
+' and poline.PoNo='''+Trim(Lbl_PoNo.Caption)+''''
+' And poline.PoLineNo='+Trim(Edt_PoLineNo.Text)+'';
AdoQry_Tmp.Open;
if AdoQry_Tmp.fieldbyname('iScheck').asinteger=1 then
begin
DispInfo('物料代码必须是不必检的,请重新输入!',3);
Edt_PoLineNo.SetFocus;
abort;
end;
end;
flag:=1;
inherited;
flag:=0;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -