📄 inv_enter_whtowh.pas
字号:
unit Inv_Enter_WhToWh;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Entry_Body, Db, ActnList, AdODB, Grids, DBGridEh, ExtCtrls,
ComCtrls, ToolWin, StdCtrls, Mask, ExtEdit, DBCtrls, ExtPrintReport, jpeg,
linkedit;
Type
TFrm_Inv_Enter_WhToWh = Class(TFrm_Base_Entry_Body)
Label1: TLabel;
CmBx_Warehouse: TComboBox;
Label4: TLabel;
Label7: TLabel;
Edt_BillNo: TEdit;
Label8: TLabel;
MEdt_BillDate: TMaskEdit;
Label3: TLabel;
Label5: TLabel;
CmBx_WhPosition: TComboBox;
Edt_RemArk: TEdit;
CmBx_OWhPosition: TComboBox;
Label2: TLabel;
CmBx_OWarehouse: TComboBox;
Label6: TLabel;
LEdt_DeptCode: TLinkEdit;
Edt_DeptName: TEdit;
Label9: TLabel;
LEdt_ToDeptCode: TLinkEdit;
Edt_ToDeptName: TEdit;
procedure FormCreate(Sender: TObject);
procedure CmBx_WarehouseChange(Sender: TObject);
procedure CmBx_OWhPositionChange(Sender: TObject);
procedure CmBx_OWhPositionExit(Sender: TObject);
procedure MEdt_BillDateExit(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Act_PreviewExecute(Sender: TObject);
procedure Act_PrintExecute(Sender: TObject);
procedure CmBx_OWarehouseExit(Sender: TObject);
procedure CmBx_OWarehouseChange(Sender: TObject);
procedure Act_InsertLineExecute(Sender: TObject);
procedure LEdt_DeptCodeKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure LEdt_DeptCodeButtonClick(Sender: TObject);
procedure LEdt_ToDeptCodeKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure LEdt_ToDeptCodeButtonClick(Sender: TObject);
procedure LEdt_DeptCodeExit(Sender: TObject);
procedure LEdt_ToDeptCodeExit(Sender: TObject);
private
{ Private declarations }
procedure SaveCheck; //存盘检查;
Function GetInvOutBillNo:string ; //获得InvOutBillNO;
procedure WhToWhBillPrint(DBConnection:TAdoConnection;WHCode,BillNo,BillTypeCode,ModuleCode:string;
Preview,MultiBill,PrintPrinted:Boolean;PrintCondition:string);//模块代码 ModuleCode唯一的
public
{ Public declarations }
procedure SetStatus(CurrentStatus:String;var AnswerStatus,
EnableControls:String); Override;
procedure InitControls; Override;
procedure SaveHeadData; Override;
procedure SaveData; Override;
end;
var
Frm_Inv_Enter_WhToWh: TFrm_Inv_Enter_WhToWh;
implementation
uses Sys_Global,Inv_Enter_WhToWh_D,Inv_Global, Inv_BillPrint, Base_Common,
Inv_WhToWh_P;
{$R *.DFM}
{ TFrm_Inv_SaleMaterial_B }
procedure TFrm_Inv_Enter_WhToWh.InitControls;
var
Bill_ID:String;
begin
inherited;
InitUsableWHCmBx(AdoQry_tmp,UserCode,CmBx_Warehouse,False);
InitUsableWHCmBx(AdoQry_tmp,UserCode,CmBx_OWarehouse,False);
//取得单据ID
if Status<>'Add' then
begin
AdoQry_tmp.Close;
AdoQry_tmp.SQL.Text:='Select InvBillId From InvOutBill'
+' Where InvBillNo='''+AdoQry_Head.fieldbyname('InvOutBillNo').AsString+''''
+' And WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+'''';
AdoQry_tmp.Open;
Bill_ID:=AdoQry_tmp.fieldbyname('InvBillId').AsString;
end
else
Bill_ID:='-1';
//设置表体AdoQry_Body 当前SQL语句(注意要能与表头关联)
AdoQry_Body.Close;
AdoQry_Body.SQL.Text:='Select InvOutBillLine.POLineNo'
+',InvOutBillLine.ItemCode'
+',Item.ItemName'
+',Uom.UomName'
+',InvOutBillLine.InvBillQty'
+',InvOutBillLine.BatchNo'
+',InvOutBillLine.InvBillLineNo'
+',InvOutBillLine.BillLineRemArk'
+' From InvOutBillLine'
+' Join Item On InvOutBillLine.ItemCode=Item.ItemCode'
+' Join Uom On Item.UomCode=Uom.UomCode'
+' Where InvOutBillLine.InvBillId='+Bill_ID+'';
AdoQry_Body.Open;
AdoQry_Body.Sort:='POLineNo';
with AdoQry_Head do
begin//把根据表头当前数据初始化,表头控件
InitCmBxText(CmBx_Warehouse,fieldbyname('WHCode').AsString);
CmBx_Warehouse.OnChange(CmBx_Warehouse);
InitCmBxText(CmBx_oWarehouse,fieldbyname('ToWHCode').AsString);
CmBx_OWarehouse.OnChange(CmBx_OWarehouse);
if Status<>'Add' then
Edt_BillNo.Text:=fieldbyname('BillNo').AsString
else
Edt_BillNo.Text:='';
if Status<>'Add' then
MEdt_BillDate.Text:=fieldbyname('BillDate').AsString
else
MEdt_BillDate.Text:=FormatDateTime('yyyy.mm.dd',Now);
if Status<>'Add' then
Edt_RemArk.Text:=fieldbyname('RemArk').AsString
else
Edt_RemArk.Text:='';
if Status<>'Add' then
begin
LEdt_DeptCode.text:=fieldbyname('DeptCode').asstring;
LEdt_DeptCode.OnExit (LEdt_ToDeptCode);
LEdt_ToDeptCode.text:=fieldbyname('ToDeptCode').asstring;
LEdt_ToDeptCode.onExit(LEdt_ToDeptCode);
end
else
begin
LEdt_DeptCode.text:='';
LEdt_ToDeptCode.text:='';
end;
end;
end;
procedure TFrm_Inv_Enter_WhToWh.SaveData;
var
Bill_No,Bill_Id,DispStr,Tempstr:String;
Bill_LineNo:Integer;
NeedChangePrice:Boolean;
OBill_No,IBill_No:string;
begin
//SaveCheck;
inherited;
DispStr:=' 单据保存失败,请稍后再试 ';
DBConnect.beginTrans;
try
if(Status='Add')then
begin
if AdoQry_Body.RecordCount=0 then
begin
DispStr:=' 新增的单据没有记录,不允许保存 ';
Abort;
end;
OBill_No:=GetNo(DBConnect,AdoQry_Head.fieldbyname('WHCode').AsString+
'C'+FormatDateTime('yymm',AdoQry_Head.fieldbyname('BillDate').
AsDateTime),'InvBill');
{OBill_No:=GetNo(DBConnect,
//AdoQry_Head.fieldbyname('WHCode').AsString+
getCode(CmBx_Warehouse.text)+
'C'+
//FormatDateTime('yymm',AdoQry_Head.fieldbyname('BillDate'). AsDateTime),
copy(MEdt_BillDate.text,1,7),
'InvBill');}
// AdoQry_Head.fieldbyname('InvBillNo').AsString:=Bill_No;
AdoQry_tmp.Close;
AdoQry_tmp.SQL.clear ;
AdoQry_tmp.SQL.Text:='Insert InvOutBill'+
'(InvBillNo,WHCode,DeptCode,InvBillDate,InvBillMonth,BillTypeCode,BillType2Code,InvBillWHChck,'+
'EmployeeCode,WH_EmployeeCode,OWhPositionCode,WhPositionCode,InvBillRemArk)'+
'Values('
+''''+OBill_No+''''
+','''+getCode(CmBx_Warehouse.text)+''''
//+','''+AdoQry_Head.fieldbyname('InvBillDate').AsString+''''
//+','''+FormatDateTime('yyyy.mm',AdoQry_Head.fieldbyname('BillDate').
// AsDateTime)+''''
+','''+LEdt_DeptCode.text+''''
+','''+MEdt_BillDate.text+''''
+','''+copy(MEdt_BillDate.text,1,7)+''''
+','+'''0299'''+','+'''099'''+',1'
+','''+UserCode+''''
+','''+UserCode+''''
{+','''+AdoQry_Head.fieldbyname('OWhPositionCode').AsString+''''
+','''+AdoQry_Head.fieldbyname('WhPositionCode').AsString+''''
+','''+AdoQry_Head.fieldbyname('InvBillRemArk').AsString+''''}
+','''+getCode(CmBx_OWhPosition.text)+''''
+','''+getCode(CmBx_WhPosition.text)+''''
+','''+Edt_RemArk.text+''''
+')';
AdoQry_tmp.ExecSQL;
AdoQry_tmp.Close;
AdoQry_tmp.SQL.Text:='Select @@identity as Bill_Id';
AdoQry_tmp.Open;
Bill_Id:=AdoQry_tmp.fieldbyname('Bill_Id').AsString;
end;
//ChangeInvStatus(AdoQry_tmp,AdoQry_Head.fieldbyname('WHCode').AsString,
// FormatDateTime('yy.mm',AdoQry_Head.fieldbyname('InvBillDate').AsDateTime));
//NeedChangePrice:=NeedChangeAveragePrice(AdoQry_tmp,FormatDateTime('yyyy.mm',
// AdoQry_Head.fieldbyname('InvBillDate').AsDateTime));
ChangeInvStatus(AdoQry_tmp,getCode(CmBx_Warehouse.text),copy(MEdt_BillDate.text,1,7));
NeedChangePrice:=NeedChangeAveragePrice(AdoQry_tmp,copy(MEdt_BillDate.text,1,7));
AdoQry_Body.DisableControls ;
AdoQry_Body.First;
Bill_LineNo:=1;
while(not AdoQry_Body.Eof)do
begin
AdoQry_tmp.Close;
AdoQry_tmp.SQL.Text:='Insert InvOutBillLine'+
'(InvBillId,InvBillLineNo,ItemCode,InvBillQty,BillLineRemArk,BatchNo)'+
'Values('
+''''+Bill_Id+''''
+','+IntToStr(Bill_LineNo)+''
+','''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''
+','+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+','''+AdoQry_Body.fieldbyname('BillLineRemArk').AsString+''''
+','''+AdoQry_Body.fieldbyname('BatchNo').AsString+''''
+')';
AdoQry_tmp.ExecSQL;
Tempstr:=UpdateInv(AdoQry_tmp,
//AdoQry_Head.fieldbyname('WHCode').AsString,
//AdoQry_Head.fieldbyname('WhPositionCode').AsString,
getCode(CmBx_Warehouse.text),getCode(CmBx_WhPosition.text),
AdoQry_Body.fieldbyname('ItemCode').AsString,
'(-('+AdoQry_Body.fieldbyname('InvBillQty').AsString+'))',
NeedChangePrice,True);
if Tempstr<>'' then
begin
DispStr:=Tempstr;
Abort;
end;
if AdoQry_Body.fieldbyname('BatchNo').AsString<>'' then
begin
if not BatchInvCheck(AdoQry_tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
'C',
//AdoQry_Head.fieldbyname('WHCode').AsString,
//AdoQry_Head.fieldbyname('WhPositionCode').AsString,
getCode(CmBx_Warehouse.text),
getCode(CmBx_WhPosition.text),
AdoQry_Body.fieldbyname('InvBillQty').AsFloat)then
Abort;
ChangeBatchInv(AdoQry_tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
'C',MEdt_BillDate.Text,
//AdoQry_Head.fieldbyname('WHCode').AsString,
//AdoQry_Head.fieldbyname('WhPositionCode').AsString,
getCode(CmBx_Warehouse.text),
getCode(CmBx_WhPosition.text),
AdoQry_Body.fieldbyname('InvBillQty').AsFloat);
end;
AdoQry_Body.Next;
Bill_LineNo:=Bill_LineNo+1;
end;
//更新本厂的移动加权平均
if True then
begin
AdoQry_tmp.Close;
AdoQry_tmp.Sql.clear ;
AdoQry_tmp.SQL.Text:='Insert AveragePrice(WHCode,ItemCode)'
+' Select Distinct '''+GetCode(CmBx_Warehouse.Text)+''',ItemCode'
+' From InvInBillLine'
+' Where InvBillId='+Bill_Id+''
+' And ItemCode Not In'
+'(Select ItemCode'
+' From AveragePrice'
+' Where WHCode='''+GetCode(CmBx_Warehouse.Text)+''')';
AdoQry_tmp.ExecSQL;
AdoQry_tmp.Close;
AdoQry_tmp.Sql.clear ;
AdoQry_tmp.SQL.Text:='Update AveragePrice Set'
+' ApAmount=ApAmount+l.Amount'
+',AveragePrice=Case When ApQty=0 Then AveragePrice'
+' Else (ApAmount+l.Amount)/ApQty end'
+' From (Select ItemCode,Sum(InvBillNoTaxAmount) As Amount'
+' From InvInBillLine'
+' Where InvBillId='+Bill_Id+''
+' Group By ItemCode) l'
+' Where AveragePrice.WHCode='''+GetCode(CmBx_Warehouse.Text)+''''
+' And AveragePrice.ItemCode=l.ItemCode';
AdoQry_tmp.ExecSQL;
end;
if(Status='Add')then
begin
if AdoQry_Body.RecordCount=0 then
begin
DispStr:=' 新增的单据没有记录,不允许保存 ';
Abort;
end;
IBill_No:=GetNo(DBConnect,
AdoQry_Head.fieldbyname('WHCode').AsString+
//getCode(CmBx_Warehouse.text)+
'R'+
FormatDateTime('yymm',AdoQry_Head.fieldbyname('BillDate'). AsDateTime),
//copy(MEdt_BillDate.text,1,7),
'InvBill');
AdoQry_tmp.Close;
AdoQry_tmp.SQL.clear ;
AdoQry_tmp.SQL.Text:='Insert InvInBill'+
'(InvBillNo,WHCode,DeptCode,InvBillDate,InvBillMonth,BillTypeCode,BillType2Code,InvBillWHChck,'+
'EmployeeCode,WH_EmployeeCode,OWhPositionCode,WhPositionCode,InvBillRemArk)'+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -