📄 inv_global.pas
字号:
+' MoRealQty=MoRealQty+'+InvBillQty
+' Where MONo='''+MONo+''''
+' And MoLineNo='+IntToStr(MoLineNo)+''
+' And Ite_ItemCode='''+Ite_ItemCode+''''
+' And ItemCode='''+ItemCode+'''';
AdoQry_Tmp.ExecSQL;
//更新InvBillSfcQty
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Update InvInBillLine Set'
+' InvBillSfcQty=InvBillSfcQty+'+InvBillQty
+' Where InvBillId='+MoveBillId+''
+' And InvBillLineNo='+MoveBillLineNo+'';
AdoQry_Tmp.ExecSQL;
AdoQry_MoveBillLine.Next;
Inc(InvBillLineNo);
end
else
begin
Abort;
end;
end;
//
HaveRecord:=0;
AdoQry_MnItemList.First;
while not AdoQry_MnItemList.Eof do
begin
if AdoQry_MnItemList.fieldbyname('BomQty').AsFloat<>0 then
HaveRecord:=1;
AdoQry_MnItemList.Next;
end;
if HaveRecord=0 then
Break;
AdoQry_MoveBill.Next;
end;
except
Result:=False;
end;
end;
{是否需要进行批次控制}
function BatchCtrl(AdoQry:TAdoQuery;ItemCode:String):Boolean;
begin
AdoQry.Close;
AdoQry.SQL.Text:='Select BatchCtrl'
+' From Item'
+' Where ItemCode='''+ItemCode+'''';
AdoQry.Open;
Result:=True;
if AdoQry.fieldbyname('BatchCtrl').AsString='0' then
Result:=False;
end;
{批次号有效性检查}
function BatchNoCheck(AdoQry:TAdoQuery;BatchNo,ItemCode,VendorCode,CurrentDate:String):Boolean;
begin
AdoQry.Close;
AdoQry.SQL.Text:='Select Batchline.UsefulCtrl,Batch.ItemCode,BatchLine.BatchNo'
+',BatchLine.BatchStatus'
+',BatchLine.VendorCode,BatchLine.UsefulDate,BatchLine.FirstInDate'
+' From BatchLine Join Batch On BatchLine.BatchId=Batch.BatchId'
+' Where BatchLine.BatchNo='''+BatchNo+'''';
AdoQry.Open;
Result:=True;
if AdoQry.fieldbyname('BatchNo').AsString='' then
begin
DispInfo('该批次号不存在!',1);
Result:=False;
end
else
begin
if(AdoQry.fieldbyname('BatchStatus').AsString='1')then
begin
DispInfo('该批次已经关闭,不允许出入库!',1);
Result:=False;
end
else if(VendorCode<>'')and(VendorCode<>AdoQry.fieldbyname('VendorCode').AsString)then
begin
DispInfo('该批次号对应的供应商不正确!',1);
Result:=False;
end
else if(ItemCode<>AdoQry.fieldbyname('ItemCode').AsString)then
begin
DispInfo('该批次号对应的物料不正确!',1);
Result:=False;
end
else if(AdoQry.fieldbyname('UsefulCtrl').AsString='1')
and(AdoQry.fieldbyname('UsefulDate').AsString<>'')
and(AdoQry.fieldbyname('FirstInDate').AsString<>'')then
begin
if FormatDateTime('yyyymmdd',AdoQry.fieldbyname('FirstInDate').AsDateTime
+AdoQry.fieldbyname('UsefulDate').AsInteger)
<FormatDateTime('yyyymmdd',StrToDateTime(CurrentDate))then
begin
DispInfo('该批次已超过有效期,不允许出入库!',1);
Result:=False;
end;
end;
end;
end;
{批次库存检查}
function BatchInvCheck(AdoQry:TAdoQuery;BatchNo,IO,WhCode,WhPositionCode:String;Qty:Double):Boolean;
begin
AdoQry.Close;
if(IO='R')or(IO='r')then
begin
AdoQry.SQL.Text:='Select InvQty,InvQty+'+FloatTostr(Qty)+' As BatchInvQty'
+' From BatchCurrentInv'
+' Where BatchNo='''+BatchNo+''''
+' And WhCode='''+WhCode+''''
+' And WhPositionCode='''+WhPositionCode+'''';
end
else if(IO='C')or(IO='c')then
begin
AdoQry.SQL.Text:='Select InvQty,InvQty-('+FloatTostr(Qty)+') As BatchInvQty'
+' From BatchCurrentInv'
+' Where BatchNo='''+BatchNo+''''
+' And WhCode='''+WhCode+''''
+' And WhPositionCode='''+WhPositionCode+'''';
end;
AdoQry.Open;
if ((AdoQry.fieldbyname('BatchInvQty').AsString='')and((IO='C')or(IO='c')))
or((AdoQry.fieldbyname('BatchInvQty').AsString='')and((IO='R')or(IO='r'))and(Qty<0))
or(AdoQry.fieldbyname('BatchInvQty').AsFloat<0) then
begin
DispInfo('该批次当前库存为:'+AdoQry.fieldbyname('InvQty').AsString
+#13+#10+'批次库存不足!',1);
Result:=False;
end
else
Result:=True;
end;
{批次提示}
function BatchHint(AdOConnection:TAdOConnection;ItemCode,VendorCode,WhCode,WhPositionCode:String):String;
begin
with TFrm_Inv_BatchHint.Create(nil) do
begin
InitForm(AdOConnection,ItemCode,VendorCode,WhCode,WhPositionCode);
if ShowModal=mrOk then
Result:=AdoQry_Tmp.fieldbyname('BatchNo').AsString;
Release;
end;
end;
{更改批次库存}
procedure ChangeBatchInv(AdoQry:TAdoQuery;BatchNo,IO,CurrentDate,WhCode,WhPositionCode:String;Qty:Double);
begin
AdoQry.Close;
AdoQry.SQL.Text:='Select BatchNo'
+' From BatchCurrentInv'
+' Where BatchNo='''+BatchNo+''''
+' And WhCode='''+WhCode+''''
+' And WhPositionCode='''+WhPositionCode+'''';
AdoQry.Open;
if AdoQry.fieldbyname('BatchNo').AsString='' then
begin
AdoQry.Close;
AdoQry.SQL.Text:='Insert BatchCurrentInv(BatchNo,WhCode,WhPositionCode,InvQty)'
+' Values('''+BatchNo+''','''+WhCode+''','''+WhPositionCode+''',0)';
AdoQry.ExecSQL;
end;
if(IO='R')or(IO='r')then
begin
AdoQry.Close;
AdoQry.SQL.Text:='Update BatchLine Set'
+' BatchInv=BatchInv+'+FloatTostr(Qty)+''
+',CurrentInDate='''+CurrentDate+''''
+',FirstInDate=IsNull(FirstInDate,'''+CurrentDate+''')'
+' Where BatchNo='''+BatchNo+'''';
AdoQry.ExecSQL;
AdoQry.Close;
AdoQry.SQL.Text:='Update BatchCurrentInv Set'
+' InvQty=InvQty+'+FloatTostr(Qty)+''
+' Where BatchNo='''+BatchNo+''''
+' And WhCode='''+WhCode+''''
+' And WhPositionCode='''+WhPositionCode+'''';
AdoQry.ExecSQL;
end
else if(IO='C')or(IO='c')then
begin
AdoQry.Close;
AdoQry.SQL.Text:='Update BatchLine Set'
+' BatchInv=BatchInv-('+FloatTostr(Qty)+')'
+',CurrentOutDate='''+CurrentDate+''''
+',FirstOutDate=IsNull(FirstOutDate,'''+CurrentDate+''')'
+' Where BatchNo='''+BatchNo+'''';
AdoQry.ExecSQL;
AdoQry.Close;
AdoQry.SQL.Text:='Update BatchCurrentInv Set'
+' InvQty=InvQty-('+FloatTostr(Qty)+')'
+' Where BatchNo='''+BatchNo+''''
+' And WhCode='''+WhCode+''''
+' And WhPositionCode='''+WhPositionCode+'''';
AdoQry.ExecSQL;
end;
end;
function GiveBatchNo(AdoQry:TAdoQuery;WHCode,WhPositionCode,ItemCode,CurrentDate:String;
var Qty:Double;BatchNo:String=''):String;
begin
Result:='';
if BatchNo<>'' then
begin
AdoQry.Close;
AdoQry.SQL.Text:='Select InvQty,InvQty-('+FloatTostr(Qty)+') As BatchInvQty'
+' From BatchCurrentInv'
+' Where BatchNo='''+BatchNo+''''
+' And WhCode='''+WhCode+''''
+' And WhPositionCode='''+WhPositionCode+'''';
AdoQry.Open;
if (AdoQry.fieldbyname('BatchInvQty').AsString='')
or(AdoQry.fieldbyname('BatchInvQty').AsFloat<0) then
begin
Result:='';
end
else
Result:=BatchNo;
end;
if Result='' then
begin
AdoQry.Close;
AdoQry.SQL.Text:='Select BatchNo,InvQty'
+' From BatchCurrentInv'
+' Where WHCode='''+WHCode+''''
+' And WhPositionCode='''+WhPositionCode+''''
+' And InvQty>='+FloatToStr(Qty)+''
+' And BatchNo In '
+'('
+' Select BatchNo From BatchLine'
+' Join Batch On BatchLine.BatchId=Batch.BatchId'
+' Where ItemCode='''+ItemCode+''''
+' And BatchStatus=0'
+' And((UsefulCtrl=0)Or((UsefulCtrl=1)'
+' And((FirstInDate-Convert(Datetime,'''+CurrentDate+''',102))<=UsefulDate)))'
+')'
+' Order By InvQty';
AdoQry.Open;
if AdoQry.fieldbyname('BatchNo').AsString='' then
begin
AdoQry.Close;
AdoQry.SQL.Text:='Select BatchNo,InvQty'
+' From BatchCurrentInv'
+' Where WHCode='''+WHCode+''''
+' And WhPositionCode='''+WhPositionCode+''''
+' And InvQty<'+FloatToStr(Qty)+''
+' And BatchNo In '
+'('
+' Select BatchNo From BatchLine'
+' Join Batch On BatchLine.BatchId=Batch.BatchId'
+' Where ItemCode='''+ItemCode+''''
+' And BatchStatus=0'
+' And((UsefulCtrl=0)Or((UsefulCtrl=1)'
+' And((FirstInDate-Convert(Datetime,'''+CurrentDate+''',102))<=UsefulDate)))'
+')'
+' Order By InvQty DESC';
AdoQry.Open;
if AdoQry.fieldbyname('BatchNo').AsString='' then
begin
Qty:=0;
Result:='';
end
else
begin
Qty:=AdoQry.fieldbyname('InvQty').AsFloat;
Result:=AdoQry.fieldbyname('BatchNo').AsString;
end;
end
else
begin
Result:=AdoQry.fieldbyname('BatchNo').AsString;
end;
end;
end;
Function GetPrice(AdoQry:TAdoQuery;ItemCode:string;PriceType:integer):double;
begin
Result:=0;
case PriceType of
{0:begin //移动加权平均价
end;
1:begin //计划价(StandardPrice)中取标准SpPrice价
Executesql(AdoQry_tmp,' select SPPrice from StandardPrice where ItemCode='''+ItemCode+''''
+' spstArtMonth='''+stArtMonth+'''',0);
Result:=AdoQry_tmp.fieldbyname('SPPrice').asfloat;
end; }
2:begin //全月平均法
Result:=0;
end;
3:begin //标准价格主文件(Sc_PriceMaster)中取标准Price价(标准成本价)
Executesql(AdoQry,'select Price from Sc_PriceMaster where ItemCode='''+ItemCode+'''',0);
Result:=AdoQry.fieldbyname('Price').asfloat;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -