📄 inv_global.pas
字号:
end;
Common_Report.Release;
AdoQry_BillTmp.free;
AdoQry_Tmp.Free;
end;
Function GetPONo(VendorCode:string;
PoType:String;
AdoConnection:TAdoConnection):String;
begin
Frm_Inv_PoHeadHint:=TFrm_Inv_PoHeadHint.Create(Application);
Frm_Inv_PoHeadHint.initform(VendorCode,PoType,AdoConnection);
Frm_Inv_PoHeadHint.Showmodal;
if Frm_Inv_PoHeadHint.modalResult=mrok then
Result:=Frm_Inv_PoHeadHint.AdoQry_tmp.fieldbyname('PoNo').asstring
else
Result:='';
Frm_Inv_PoHeadHint.Release;
end;
Function GetOtherPrice(ItemCode:string;
PriceType:String;
AdoConnection:TAdoConnection):String;
begin
Frm_Inv_OtherPrice_Hint:=TFrm_Inv_OtherPrice_Hint.Create(Application);
Frm_Inv_OtherPrice_Hint.initform(ItemCode,AdoConnection);
Frm_Inv_OtherPrice_Hint.Showmodal;
if Frm_Inv_OtherPrice_Hint.modalResult=mrok then
begin
if PriceType='NoTaxPrice' then
Result:=Frm_Inv_OtherPrice_Hint.AdoQry_tmp.fieldbyname('NoTaxPrice').asstring
else
Result:=Frm_Inv_OtherPrice_Hint.AdoQry_tmp.fieldbyname('Price').asstring;
end
else
Result:='';
Frm_Inv_OtherPrice_Hint.Release;
end;
procedure InvDataChangeCheck(AdoQuery:TAdoQuery;CheckMonth:String);
begin
AdoQuery.Close;
AdoQuery.SQL.Text:='Select Count(*) As CountInt From InvStatus'
+' Where InvStatusName='''+FormatDateTime('yymm',StrToDateTime(CheckMonth+'.01'))
+''' and InvStatus=1';
AdoQuery.Open;
if AdoQuery.fieldbyname('CountInt').AsInteger>0 then
begin
DispInfo(CheckMonth+' 月份的数据发生过改变,但没有重新进行月末计算'
+#10+#13+'本报表的金额可能不正确!',3);
end;
end;
function DefaultWHCheck(AdoQuery:TAdoQuery;WHCode,ItemCode:String):Boolean;
begin
AdoQuery.Close;
AdoQuery.SQL.Text:='Select Item.WHCode,Item.OnlyDefaultWH,Warehouse.WHName'
+' From Item Join Warehouse On Item.WHCode=Warehouse.WHCode'
+' Where ItemCode='''+ItemCode+'''';
AdoQuery.Open;
Result:=True;
if (AdoQuery.fieldbyname('WHCode').AsString<>WHCode)and
(AdoQuery.fieldbyname('WHCode').AsString<>'') then
begin
if AdoQuery.fieldbyname('OnlyDefaultWH').AsString='1' then
begin
DispInfo('该物料只能使用缺省仓库:'+AdoQuery.fieldbyname('WHName').AsString,1);
Result:=False;
end
else
DispInfo('该物料的缺省仓库应该是:'+AdoQuery.fieldbyname('WHName').AsString,3);
end;
end;
function MoInBackFlush(AdOConnection:TAdOConnection;
MoNo,UserCode,CurrentDate,ShiftType:String;
MoLineNo:Integer;MoInQty:Double):Boolean;
var
WHCode,WhPositionCode,InvBillNo,DeptCode,InvBillID,ItemCode,Ite_ItemCode,
MoveBillLineNo,InvBillQty,InvBillNoTaxPrice,MoveBillId:String;
InvBillLineNo,PriceType,HaveRecord:Integer;
AdoQry_MoveBill,AdoQry_MoveBillLine,AdoQry_Tmp,AdoQry_MnItemList:TAdoQuery;
NeedChangePrice:Boolean;
begin
Result:=True;
try
AdoQry_MoveBill:=TAdoQuery.Create(nil);
AdoQry_MoveBill.Connection:=AdOConnection;
AdoQry_MoveBill.EnableBCD:=False;
AdoQry_MoveBillLine:=TAdoQuery.Create(nil);
AdoQry_MoveBillLine.Connection:=AdOConnection;
AdoQry_MoveBillLine.EnableBCD:=False;
AdoQry_Tmp:=TAdoQuery.Create(nil);
AdoQry_Tmp.Connection:=AdOConnection;
AdoQry_Tmp.EnableBCD:=False;
AdoQry_MnItemList:=TAdoQuery.Create(nil);
AdoQry_MnItemList.Connection:=AdOConnection;
AdoQry_MnItemList.LockType:=ltBatchOptimistic;
AdoQry_MnItemList.EnableBCD:=False;
NeedChangePrice:=NeedChangeAveragePrice(AdoQry_Tmp,FormatDateTime('yyyy.mm',
StrToDateTime(CurrentDate)));
//部门
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select DeptCode'
+' From Mo'
+' Where MoNo='''+MoNo+'''';
AdoQry_Tmp.Open;
DeptCode:=AdoQry_Tmp.fieldbyname('DeptCode').AsString;
//取得原材料清单
AdoQry_MnItemList.Close;
AdoQry_MnItemList.SQL.Text:='Select MNItemList.Ite_ItemCode'
+',MNItemList.ItemCode'
+',MNItemList.BomQty'
+',(MNItemList.BomQty+MNItemList.BomScrAp_Percent/100)'
+'*'+FloatToStr(MoInQty)+' As InvBillQty'
+' From MNItemList'
+' Join Item On MNItemList.ItemCode=Item.ItemCode'
+' Where MNItemList.MoNo='''+MoNo+''''
+' And MNItemList.MoLineNo='+IntToStr(MoLineNo)+'';
AdoQry_MnItemList.Open;
AdoQry_MnItemList.First;
while not AdoQry_MnItemList.Eof do
begin
AdoQry_MnItemList.Edit;
AdoQry_MnItemList.fieldbyname('BomQty').AsString:=
AdoQry_MnItemList.fieldbyname('InvBillQty').AsString;
AdoQry_MnItemList.Post;
AdoQry_MnItemList.Next;
end;
//取得拉试货位移动单表头(表体没被充完的)
AdoQry_MoveBill.Close;
AdoQry_MoveBill.SQL.Text:='Select InvBillId,WHCode,WhPositionCode'
+' From InvInBill'
+' Where InvBillId In '
+'(Select InvInBillLine.InvBillId'
+' From InvInBillLine'
+' Join InvInBill On InvInBillLine.InvBillId=InvInBill.InvBillId'
+' Where InvInBill.MoNo='''+MoNo+''''
+' And InvInBill.MoLineNo='+IntToStr(MoLineNo)
+' And InvInBill.BillTypeCode=''1101'''
+' And InvInBillLine.InvBillQty>InvBillSfcQty'
+')';
AdoQry_MoveBill.Open;
//每张拉试货位移动单产生一张领料单
while not AdoQry_MoveBill.Eof do
begin
MoveBillId:=AdoQry_MoveBill.fieldbyname('InvBillId').AsString;
//取得拉式货位
WhPositionCode:=AdoQry_MoveBill.fieldbyname('WhPositionCode').AsString;
//当前仓库
WHCode:=AdoQry_MoveBill.fieldbyname('WHCode').AsString;
//当前仓库计价方式
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select PriceType From Warehouse'
+' Where WHCode='''+WHCode+'''';
AdoQry_Tmp.Open;
PriceType:=AdoQry_Tmp.fieldbyname('PriceType').AsInteger;
//设置仓库更新标志
ChangeInvStatus(AdoQry_Tmp,WHCode,FormatDateTime('yy.mm',StrToDateTime(CurrentDate)));
//取得单据号
InvBillNo:=GetNo(AdOConnection,WHCode+'C'+FormatDateTime('yymm',
StrToDateTime(CurrentDate)),'InvBill');
//产生表头
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Insert InvOutBill (InvBillNo,WHCode,InvBillDate'
+',InvBillMonth,DeptCode,MoNo,MoLineNo,BillTypeCode,EmployeeCode'
+',WH_EmployeeCode,WhPositionCode,ShiftType,InvBillRemArk,InvBillWHChck)'
+' Values('
+' '''+InvBillNo+''''
+','''+WHCode+''''
+','''+CurrentDate+''''
+','''+FormatDateTime('yyyy.mm',StrToDateTime(CurrentDate))+''''
+','''+DeptCode+''''
+','''+MoNo+''''
+','+IntToStr(MoLineNo)+''
+','''+'0201'+''''
+','''+UserCode+''''
+','''+UserCode+''''
+','''+WhPositionCode+''''
+','''+ShiftType+''''
+','''+'拉式领料单'+''''
+','+'1'+''
+')';
AdoQry_Tmp.ExecSQL;
//取得ID号
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select @@IDENTITY As InvBillID';
AdoQry_Tmp.Open;
InvBillID:=AdoQry_Tmp.fieldbyname('InvBillID').AsString;
InvBillLineNo:=1;
AdoQry_MoveBillLine.Close;
AdoQry_MoveBillLine.SQL.Text:='Select InvBillLineNo,ItemCode,BatchNo'
+',InvBillQty-InvBillSfcQty As BillQty'
+' From InvInBillLine'
+' Where InvBillId='+MoveBillId+''
+' And InvBillQty>InvBillSfcQty';
AdoQry_MoveBillLine.Open;
AdoQry_MoveBillLine.First;
while not AdoQry_MoveBillLine.Eof do
begin
if AdoQry_MnItemList.Locate('ItemCode',
AdoQry_MoveBillLine.fieldbyname('ItemCode').AsString,[]) then
begin
Ite_ItemCode:=AdoQry_MnItemList.fieldbyname('Ite_ItemCode').AsString;
ItemCode:=AdoQry_MnItemList.fieldbyname('ItemCode').AsString;
MoveBillLineNo:=AdoQry_MoveBillLine.fieldbyname('InvBillLineNo').AsString;
if AdoQry_MnItemList.fieldbyname('BomQty').AsFloat<
AdoQry_MoveBillLine.fieldbyname('BillQty').AsFloat then
begin
InvBillQty:=AdoQry_MnItemList.fieldbyname('BomQty').AsString;
AdoQry_MnItemList.Edit;
AdoQry_MnItemList.fieldbyname('BomQty').AsFloat:=0;
AdoQry_MnItemList.Post;
end
else
begin
InvBillQty:=AdoQry_MoveBillLine.fieldbyname('BillQty').AsString;
AdoQry_MnItemList.Edit;
AdoQry_MnItemList.fieldbyname('BomQty').AsFloat:=
AdoQry_MnItemList.fieldbyname('BomQty').AsFloat-
AdoQry_MoveBillLine.fieldbyname('BillQty').AsFloat;
AdoQry_MnItemList.Post;
end;
if InvBillQty='0' then
begin
AdoQry_MoveBillLine.Next;
Continue;
end;
//取得当前加权价
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select Case When ApQty=0 Then AveragePrice'
+' Else ApAmount/ApQty end As AveragePrice'
+' From AveragePrice'
+' Where WHCode='''+WHCode+''''
+' And ItemCode='''+ItemCode+'''';
AdoQry_Tmp.Open;
InvBillNoTaxPrice:=AdoQry_Tmp.fieldbyname('AveragePrice').AsString;
if InvBillNoTaxPrice='' then
InvBillNoTaxPrice:='0';
//产生表体
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Insert InvOutBillLine(InvBillId,InvBillLineNo'
+',MoNo,MoLineNo,ItemCode,InvBillQty,BillLineRemArk,InvBillNoTaxPrice'
+',InvBillNoTaxAmount,Ite_ItemCode)'
+' Values('
+''+InvBillID+''
+','''+IntToStr(InvBillLineNo)+''''
+','''+MoNo+''''
+','+IntToStr(MoLineNo)+''
+','''+ItemCode+''''
+','+InvBillQty+''
+','''+'拉式领料单'+''''
+','+InvBillNoTaxPrice+''
+','+InvBillQty+'*'+InvBillNoTaxPrice+''
+','''+Ite_ItemCode+''''
+')';
AdoQry_Tmp.ExecSQL;
//更新库存
{考虑批次,原来的货位移动单已经考虑批次了,我们的算法应该是一样的,
只需要更新批次库存就可以了}
if UpdateInv(AdoQry_Tmp,WHCode,WhPositionCode,ItemCode,
'(-('+InvBillQty+'))',NeedChangePrice,True)<>'' then
Abort;
if AdoQry_MoveBillLine.fieldbyname('BatchNo').AsString<>'' then
begin
if not BatchInvCheck(AdoQry_Tmp,AdoQry_MoveBillLine.fieldbyname('BatchNo').AsString,
'C',WHCode,WhPositionCode,StrToFloat(InvBillQty))then
Abort;
ChangeBatchInv(AdoQry_Tmp,AdoQry_MoveBillLine.fieldbyname('BatchNo').AsString,
'C',CurrentDate,WHCode,WhPositionCode,StrToFloat(InvBillQty));
end;
//更新当前物料拉式库存
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Update Item Set'
+' BackFlushAllocInv=BackFlushAllocInv-('+InvBillQty+')'
+' Where ItemCode='''+ItemCode+'''';
AdoQry_Tmp.ExecSQL;
//更新加权价
if PriceType=0 then
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Update AveragePrice Set'
+' ApAmount=ApAmount-(Case When ApQty=0 Then AveragePrice'
+' Else ApAmount/ApQty end)*('+InvBillQty+')'
+' Where WHCode='''+WHCode+''''
+' And ItemCode='''+ItemCode+'''';
AdoQry_Tmp.ExecSQL;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Update AveragePrice Set'
+' ApQty=ApQty-('+InvBillQty+') '
+' Where WHCode='''+WHCode+''''
+' And ItemCode='''+ItemCode+'''';
AdoQry_Tmp.ExecSQL;
end;
//更新物料清单实际使用材料量
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Update MNItemList Set'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -