📄 inv_otheroutaudit_b.pas
字号:
unit Inv_OtherOutAudit_B;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Entry_Body, Db, ActnList, AdODB, Grids, DBGridEh, ExtCtrls,math,
ComCtrls, ToolWin, Mask, StdCtrls, ExtEdit, Base_Check_Body;
Type
TFrm_Inv_OtherOutAudit_B = Class(TFrm_Base_Check_Body)
Cmbx_WhCodeName: TComboBox;
Cmbx_OutType: TComboBox;
Cmbx_Position: TComboBox;
Cmbx_BillType2CodeName: TComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edt_Memo: TEdit;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Edt_BillNo: TEdit;
Label10: TLabel;
Medt_Date: TMaskEdit;
AdoQry_BodyInvBillId: TBCDField;
AdoQry_BodyInvBillLineNo: TStringField;
AdoQry_BodyInvBillQty: TFloatField;
AdoQry_BodyItemCode: TStringField;
AdoQry_BodyItemName: TStringField;
AdoQry_BodyUomName: TStringField;
Lbl_OutName: TLabel;
Edt_OutCode: TExtEdit;
AdoQry_BodyUseableStore: TFloatField;
AdoQry_BodyInvBillSfcqty: TFloatField;
AdoQry_BodyBillLineRemArk: TStringField;
procedure Medt_DateExit(Sender: TObject);
procedure Act_CheckExecute(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Act_PreviewExecute(Sender: TObject);
procedure Act_PrintExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Cmbx_WhCodeNameChange(Sender: TObject);
procedure AdoQry_BodyAfterScroll(DataSet: TDataSet);
procedure AdoQry_BodyBeforePost(DataSet: TDataSet);
procedure Act_autoExecute(Sender: TObject);
private
BillTypeCode,PriceType :string;
procedure InitCmbx_WhPosition(whCode:string);
procedure InitCmbx_BillType2CodeName;
{ Private declarations }
public
procedure InitForm(AdOConnection:TAdOConnection;FormStatus:String;
AdoQuery:TAdoQuery);OverRide;
procedure InitControls;Override;
Protected
// procedure SaveData;Override;
end;
var
Frm_Inv_OtherOutAudit_B: TFrm_Inv_OtherOutAudit_B;
implementation
Uses Sys_Global,Inv_OtherOutAudit_H,Inv_Global;
{$R *.DFM}
{ TFrm_Inv_OtherOut_B }
procedure TFrm_Inv_OtherOutAudit_B.InitCmbx_BillType2CodeName;
begin
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select BillType2Code,BillType2Name '+
' from BillType2 '+
' where io2=1 ');
open;
cmbx_BillType2CodeName.clear;
if not Eof then
begin
First;
while not Eof do
begin
cmbx_BillType2CodeName.Items.Add(fieldbyname('BillType2Code').asstring+' '+fieldbyname('BillType2Name').asstring);
Next;
end;
end;
end;
end;
procedure TFrm_Inv_OtherOutAudit_B.InitCmbx_WhPosition(whCode: string);
begin
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select P.WhPositionCode,P.WhPositionName '+
' from WhPosition P,Warehouse W '+
' where P.WhCode='''+WhCode+''''+
' and p.whCode=W.whCode' );
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_OtherOutAudit_B.InitControls;
var InvBillId : double;
TmpFields : string;
i:integer;
begin
inherited;
InitUsableWHCmbx(AdoQry_Tmp,UserCode,Cmbx_WhCodeName,False);
InitCmbx_WhPosition(getCode(Cmbx_WhCodeName.text));
InitCmbx_BillType2CodeName;
InvBillId:=AdoQry_Head.fieldbyname('InvBillid').AsFloat;
Cmbx_Position.ItemIndex:=0;
tmpfields:=getInvfield(AdoQry_tmp,getCode(Cmbx_WhCodeName.text),getCode(Cmbx_Position.text),'CurrentInv');
with AdoQry_Body do
begin
Close;
sql.clear;
sql.Add('select B.InvBillId,B.InvBillLineNo,B.InvBillQty,B.ItemCode,B.InvBillSfcqty, '+
' I.ItemName,U.UomName,'+
' case when c.'+tmpfields+' is Null then 0 else '+
' c.'+tmpfields+' end as UseableStore,B.BillLineRemArk '+
' from InvOutBillLine B,Item I,Uom U,CurrentInv c'+
' where B.InvBillId='+floattostr(InvBillId)+
' and B.ItemCode=I.ItemCode '+
' and I.UomCode=U.UomCode '+
' and c.ItemCode=B.ItemCode '+
' and c.whCode='''+getCode(Cmbx_WhCodeName.text)+''' '+
' and c.WhPositionCode='''+getCode(Cmbx_Position.text)+''' '+
' Order by B.InvBillLineNo');
open;
First;
for i:=0 to RecordCount-1 do
begin
edit;
fieldbyname('InvBillqty').asinteger:=0;
post;
next;
end;
end;
with AdoQry_Head do
begin
InitCmBxText(Cmbx_WhCodeName,GetCode(fieldbyname('WhCodeName').asstring));
InitCmBxText(Cmbx_Position,GetCode(fieldbyname('WhPositionName').asstring));
InitCmBxText(Cmbx_BillType2CodeName,GetCode(fieldbyname('BillType2CodeName').asstring));
InitCmBxText(Cmbx_OutType,fieldbyname('OutType').asstring);
Edt_OutCode.text:=fieldbyname('OutCode').asstring;
Lbl_OutName.Caption:=fieldbyname('OutName').asstring;
Edt_Memo.Text:=fieldbyname('InvBillRemArk').AsString;
medt_Date.text:=FormatDateTime('yyyy.mm.dd',Now);
Edt_BillNo.Text:=fieldbyname('InvBillNo').AsString;
end;
with AdoQry_Tmp do
begin
Close;
sql.text:='select InvBillRemArk from InvOutBill '+
' where InvBillId='+floattostr(InvBillId);
open;
Edt_Memo.Text:=fieldbyname('InvBillRemArk').asstring;
end;
end;
procedure TFrm_Inv_OtherOutAudit_B.InitForm(AdOConnection: TAdOConnection;
FormStatus: String; AdoQuery: TAdoQuery);
begin
inherited;
BillTypeCode:=Param1;
TlBtn_Check.Enabled:=True;
PriceType:=Param2;
end;
procedure TFrm_Inv_OtherOutAudit_B.Medt_DateExit(Sender: TObject);
begin
inherited;
If not WHClsPeriodCheck(AdoQry_Tmp,GetCode(Cmbx_WhCodeName.text),
Copy(Medt_Date.Text,1,7)) then
begin
Medt_Date.SetFocus;
Abort;
end
end;
procedure TFrm_Inv_OtherOutAudit_B.Act_CheckExecute(Sender: TObject);
var BeforeSaveError:boolean;
ItemInvField,CurrentInvField,Billno,BillId :String;
M:Integer;
begin
inherited;
AdoQry_Body.Connection.beginTrans;
try
//全面有效检查
BeforeSaveError:=True;
//检查日期、库存
medt_Date.onexit(medt_Date);
ItemInvField:=GetInvField(AdoQry_Tmp,getCode(Cmbx_WhCodeName.text),GetCode(Cmbx_Position.Text),'Item');
CurrentInvField:=GetInvField(AdoQry_Tmp,getCode(Cmbx_WhCodeName.text),GetCode(Cmbx_Position.Text),'CurrentInv');
AdoQry_Body.First;
for M:=0 to AdoQry_Body.recordCount-1 do
begin
if not InvQtyCheck
(False,
AdoQry_Body,
AdoQry_tmp,
getCode(Cmbx_WhCodeName.text),
getCode(Cmbx_Position.Text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
'InvBillQty',
AdoQry_Body.fieldbyname('InvBillQty').asfloat,
False) then
abort;
AdoQry_Body.next;
end;
//真正开始存盘
BeforeSaveError:=False;
//取单据号
Billno:=Trim(Edt_BillNo.Text);
//记录本仓库数据发生改变
ChangeInvStatus(AdoQry_tmp,getCode(Cmbx_WhCodeName.text),copy(Medt_Date.text,1,7));
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.clear;
AdoQry_Tmp.Sql.Add('select InvBillId from InvOutBill where InvBillNo='''+BillNo+'''');
AdoQry_tmp.Open;
BillId:=AdoQry_Tmp.fieldbyname('InvBillId').ASString;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.clear;
AdoQry_Tmp.Sql.Add('UpDate InvOutBill Set '+
'InvBillDate='''+Medt_Date.Text+''','+
'InvBillMonth='''+copy(medt_Date.text,1,7)+''','+
'Wh_EmployeeCode='''+UserCode+''','+
'InvBillWhChck=1,'+
'InvBillRemArk='''+Trim(Edt_Memo.Text)+''''+
' Where InvBillId='''+BillId+'''');
AdoQry_Tmp.ExecSql;
with AdoQry_Body do
begin
First;
for M:=0 to recordCount-1 do
begin
if NeedChangeAveragePrice(AdoQry_tmp,copy(Medt_Date.text,1,7)) then
begin
If PriceType='0' then
begin
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_Tmp.Sql.Add('UpDate AveragePrice'+
' Set ApQty=ApQty-('+
AdoQry_Body.fieldbyname('InvBillQty').AsString+'),'+
'ApAmount=round(ApAmount/Apqty*(Apqty+'+fieldbyname('InvBillQty').AsString+'),2)'+
' where whCode='''+getCode(Cmbx_WhCodeName.Text)+''' and '+
' ItemCode='''+fieldbyname('ItemCode').AsString+'''');
AdoQry_Tmp.ExecSQL;
end;
end;
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('Update InvOutBillLine'+
' Set InvBillNoTaxPrice='+
'(Select AveragePrice From AveragePrice Where '+
'WhCode='''+GetCode(Cmbx_WhCodeName.Text)+''' and '+
'ItemCode='''+fieldbyname('ItemCode').AsString+''')'+
' where InvBillId='+BillId+
' and InvBillLineNo='''+fieldbyname('InvBillLineNo').AsString+'''');
AdoQry_Tmp.ExecSQL;
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('Update InvOutBillLine '+
'Set InvBillNoTaxAmount=round((InvBillQty*InvBillNoTaxPrice),2), '+
' BillLineRemArk='''+AdoQry_Body.fieldbyname('BillLineRemArk').asstring+''' '+
'Where InvBillId='+BillId+
' and InvBillLineNo='''+fieldbyname('InvBillLineNo').AsString+'''');
AdoQry_tmp.ExecSQL;
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('Update CurrentInv '+
'Set '+
CurrentInvField+'='+CurrentInvField+'-('+fieldbyname('InvBillQty').Asstring+') '+
' Where WhCode='''+GetCode(Cmbx_WhCodeName.Text)+''''+
' and ItemCode='''+fieldbyname('ItemCode').AsString+''''+
' and WhPositionCode='''+GetCode(Cmbx_Position.Text)+'''');
AdoQry_tmp.ExecSQL;
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('Update Item '+
'Set '+
ItemInvField+'='+ItemInvField+'-('+fieldbyname('InvBillQty').Asstring+') '+
'Where ItemCode='''+fieldbyname('ItemCode').AsString+'''');
AdoQry_tmp.ExecSQL;
next;
end;
end;
AdoQry_Body.Connection.CommitTrans;
Edt_Memo.Enabled:=False;
Medt_Date.Enabled:=False;
TlBtn_Check.Enabled:=False;
except
begin
AdoQry_Body.Connection.RollBackTrans;
if not BeforeSaveError then
DispInfo(' 单据核定失败,请稍后再试! ',1);
end;
end;
Act_Check.Enabled:=False;
end;
procedure TFrm_Inv_OtherOutAudit_B.FormClose(Sender: TObject;
var Action: TCloseAction);
var OldSort :String;
begin
inherited;
OldSort:=AdoQry_Head.Sort;
AdoQry_Head.Close;
AdoQry_Head.Open;
AdoQry_Head.Sort:=OldSort;
with AdoQry_Tmp do
begin
Close;
sql.text:='update InvOutBill '+
' set InvBillRemArk='''+Edt_Memo.Text+''''+
' where InvBillId='+inttostr(AdoQry_Head.fieldbyname('InvBillId').asinteger);
execsql;
end;
end;
procedure TFrm_Inv_OtherOutAudit_B.Act_PreviewExecute(Sender: TObject);
begin
// inherited;
BillPrint(AdoQry_Tmp.Connection,GetCode(Cmbx_WhCodeName.text),Edt_BillNo.text,Param1,ModuleCode,True,False,True,'');
end;
procedure TFrm_Inv_OtherOutAudit_B.Act_PrintExecute(Sender: TObject);
begin
// inherited;
BillPrint(AdoQry_Tmp.Connection,GetCode(Cmbx_WhCodeName.text),Edt_BillNo.text,Param1,ModuleCode,False,False,True,'');
end;
procedure TFrm_Inv_OtherOutAudit_B.FormCreate(Sender: TObject);
begin
inherited;
TlBtn_CancelCheck.Action:=act_auto;
end;
procedure TFrm_Inv_OtherOutAudit_B.FormActivate(Sender: TObject);
begin
inherited;
Act_Check.Enabled:=True;
//ToolButton4.Left:=TlBtn_Excel.Left;
//ToolButton13.Left:=ToolButton4.Left;
end;
procedure TFrm_Inv_OtherOutAudit_B.Cmbx_WhCodeNameChange(Sender: TObject);
begin
inherited;
Cmbx_Position.ItemIndex:=0;
end;
procedure TFrm_Inv_OtherOutAudit_B.AdoQry_BodyAfterScroll(
DataSet: TDataSet);
begin
inherited;
if AdoQry_Body.eof then AdoQry_Body.Prior;
end;
procedure TFrm_Inv_OtherOutAudit_B.AdoQry_BodyBeforePost(
DataSet: TDataSet);
var BeforeSaveError:boolean;
ItemInvField,CurrentInvField,Billno,BillId :String;
M:Integer;
begin
inherited;
if not InvQtyCheck
(False,
AdoQry_Body,
AdoQry_tmp,
getCode(Cmbx_WhCodeName.text),
getCode(Cmbx_Position.Text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
'InvBillQty',
AdoQry_Body.fieldbyname('InvBillQty').asfloat,
False) then
abort;
if AdoQry_Body.fieldbyname('InvBillqty').asfloat>min(
AdoQry_Body.fieldbyname('InvBillSfcqty').asfloat,
AdoQry_Body.fieldbyname('UseableStore').asfloat) then
begin
DispInfo('本次领料数量不能大于未领料数量!',1);
abort;
end;
end;
procedure TFrm_Inv_OtherOutAudit_B.Act_autoExecute(Sender: TObject);
var
I:integer;
begin
inherited;
with AdoQry_Body do
begin
First;
for i:=0 to AdoQry_Body.recordCount-1 do
begin
edit;
fieldbyname('InvBillqty').asinteger:=
min(fieldbyname('InvBillSfcqty').asinteger,fieldbyname('UseableStore').asinteger);
post;
next;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -