📄 mrp_enter_newpassmo.pas
字号:
AdoQry_Head.Post;
AdoQry_Head.BeforeEdit:=Tmpbeforeedit;
end;
function TFrm_Mrp_Enter_NewPassMo.existssonItem(ItemCode:string):boolean;
var sqltext:string;
AdoQry:TAdoQuery;
begin
Result:=True;
SqlText:=' Select * From Bom '
+' Where ite_ItemCode='+quotedstr(ItemCode)
+' And Bomstatus in (0,2)';
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
try
AdoQry.Close;
AdoQry.SQL.Text:=SqlText;
AdoQry.Open;
if AdoQry.RecordCount=0 then Result:=False;
finally
AdoQry.Free;
end;
end;
function TFrm_Mrp_Enter_NewPassMo.existsnoPassmo(mono: string;
MoLineno: integer): boolean;
var sqltext:string;
AdoQry:TAdoQuery;
begin
Result:=True;
SqlText:=' Select * From MoLine '
+' Where MoNo='''+mono+''''
+' And MoLineNo='''+IntToStr(MoLineno)+''''
+' And MoLineStatus=5 ';
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
try
AdoQry.Close;
AdoQry.SQL.Text:=SqlText;
AdoQry.Open;
if AdoQry.RecordCount=0 then Result:=False
else isBackflush:=AdoQry.fieldbyname('Backflush').asinteger;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_NewPassMo.PassMoLine(mono: string;
MoLineno: integer);
var sqltext:string;
AdoQry:TAdoQuery;
begin
SqlText:=' Update MoLine '
+' set MoLineStatus=6,'
+' PassEmployeeCode='+quotedstr(userCode)+','
+' confirmtime=getdate() '
+' Where MoNo='''+mono+''''
+' And MoLineNo='''+inttostr(MoLineno)+''''
+' And MoLineStatus=5 ';
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
try
AdoQry.Close;
AdoQry.SQL.Text:=SqlText;
AdoQry.execsql;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_NewPassMo.PassbyProductMoLine(mono: string;
MoLineno: integer);
var sqltext:string;
AdoQry:TAdoQuery;
begin
SqlText:=' Update MoLine '
+' set MoLineStatus=6,'
+' PassEmployeeCode='+quotedstr(userCode)+','
+' confirmtime=getdate() '
+' Where MoNo='''+mono+''''
+' And ParentMoLineNo='''+inttostr(MoLineno)+''''
+' And MoLineStatus=5 ';
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
try
AdoQry.Close;
AdoQry.SQL.Text:=SqlText;
AdoQry.execsql;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_NewPassMo.savebyProducthistory(mono: string;
MoLineno: integer);
var sqltext:string;
AdoQry:TAdoQuery;
begin
SqlText:=' select * from MoLine '
+' Where MoNo='''+mono+''''
+' And ParentMoLineNo='''+inttostr(MoLineno)+''''
+' And MoLineStatus=5 '
+' and byProduct=1 ';
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
try
AdoQry.Close;
AdoQry.SQL.Text:=SqlText;
AdoQry.open;
AdoQry.First;
while not AdoQry.Eof do
begin
saveMoLineHistory(dbconnect,AdoQry.fieldbyname('mono').asstring,AdoQry.fieldbyname('MoLineno').asinteger,userCode,3);
AdoQry.next;
end;
finally
AdoQry.Free;
end;
end;
function TFrm_Mrp_Enter_NewPassMo.checkCurrentonhandInv(mono: string;
MoLineno: integer; var haveInv: integer; var strWhName: string): boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
try
sqltext:='Select mnItemList.ItemCode,BatchCtrl,Sum(MoCtrlQty) As MOCtrlQty '
+' into #themnItemList '
+' From MNItemList,Item '
+' Where MoNO='+quotedstr(mono)
+' and MoLineno='+inttostr(MoLineno)
+' and mnItemList.ItemCode=Item.ItemCode '
+' Group By mnItemList.ItemCode,Item.BatchCtrl ';
//汇总领料清单中各物料要领量总数
Executesql(AdoQry,sqltext,1);
sqltext:=' Select CurrentInv.ItemCode,Sum(OnHandInv) As OnHandInv '
+' into #theCurrentInv '
+' From CurrentInv,#themnItemList '
+' Where CurrentInv.ItemCode =#TheMNItemList.ItemCode '
+' And CurrentInv.WHCode In (Select Distinct WHCode '
+' From WhPosition '
+' Where WhPositionType=0 And BackFlushWHP=1 And DeptCode='+quotedstr(getDeptCode(mono))+' )'
+' And CurrentInv.WHCode+CurrentInv.WhPositionCode Not In (Select WHCode+WhPositionCode '
+' From WhPosition '
+' Where BackFlushWHP=1) '
+' And CurrentInv.WHCode+CurrentInv.WhPositionCode In (Select WHCode+WhPositionCode '
+' From WhPosition '
+' Where WhPositionType=0 ) '
+' Group By CurrentInv.ItemCode ';
{ sqltext:='Select Item.ItemCode,(Item.CurrentOnHandInv-Item.BackFlushAllocInv)-#theMNItemList.MoCtrlQty As ReMainInv '
+' From Item '
+' Join #theMNItemList On Item.ItemCode=#theMNItemList.ItemCode '
+' Where (Item.CurrentOnHandInv-Item.BackFlushAllocInv)<#theMNItemList.MoCtrlQty ';}
//判断当前库存数是否够领量数,如果选出的记录数大于0则表示有子项不够库存
Executesql(AdoQry,sqltext,1);
sqltext:='Select Batch.ItemCode,sum(BatchCurrentInv.InvQty) as onhandInv '
+' into #tmpBatchCurrentInv '
+' From BatchLine '
+' Join Batch On Batch.BatchId=BatchLine.BatchId '
+' join BatchCurrentInv on Batchline.Batchno=BatchCurrentInv.Batchno '
+' join #themnItemList on Batch.ItemCode=#themnItemList.ItemCode '
+' Where BatchStatus=0 '
+' And (BatchLine.UsefulCtrl=0 Or (DateDiff(dd,FirstInDate,GetDate())<=UsefulDate ) ) '
+' And BatchCurrentInv.WHCode In (Select Distinct WHCode '
+' From WhPosition '
+' Where WhPositionType=0 And BackFlushWHP=1 And DeptCode='+quotedstr(getDeptCode(mono))+' )'
+' And BatchCurrentInv.WHCode+BatchCurrentInv.WhPositionCode Not In (Select WHCode+WhPositionCode '
+' From WhPosition '
+' Where BackFlushWHP=1) '
+' And BatchCurrentInv.WHCode+BatchCurrentInv.WhPositionCode In (Select WHCode+WhPositionCode '
+' From WhPosition '
+' Where WhPositionType=0 ) '
+' group by Batch.ItemCode ';
Executesql(AdoQry,sqltext,1);
sqltext:='Select #TheMNItemList.ItemCode '
+' into #themnItem '
+' From #TheMNItemList '
+' Join #TheCurrentInv On #TheMNItemList.ItemCode=#TheCurrentInv.ItemCode '
+' Where (#TheCurrentInv.OnHandInv-#TheMNItemList.MoCtrlQty)>=0 '
+' And BatchCtrl=0 '
+' Union '
+' Select #TheMNItemList.ItemCode As ReMainInv '
+' From #TheMNItemList '
+' Join #TMpBatchCurrentInv On #TheMNItemList.ItemCode=#TmpBatchCurrentInv.ItemCode '
+' Where (#TmpBatchCurrentInv.OnHandInv-#TheMNItemList.MoCtrlQty)>=0 '
+' And BatchCtrl=1 ';
Executesql(AdoQry,sqltext,1);
sqltext:='Select #TheMNItemList.ItemCode '
+' From #TheMNItemList '
+' Where ItemCode Not In (select ItemCode from #themnItem) ';
Executesql(AdoQry,sqltext,0);
if AdoQry.RecordCount>0 then
begin
haveInv:=0;
tmpCode:=AdoQry.fieldbyname('ItemCode').asstring;
exit;
end
else
begin
haveInv:=1;
Result:=True;
end;
{ sqltext:='Select #TheMNItemList.ItemCode '
+' into #tmPmnItem '
+' From #TheMNItemList '
+' Where ItemCode Not In (select ItemCode from #themnItem) ';
Executesql(AdoQry,sqltext,1);
sqltext:='Select Distinct WhPosition.WHCode,Warehouse.WHName '
+' From WhPosition '
+' Join Warehouse On WhPosition.WHCode=Warehouse.WHCode '
+' Where WhPosition.WHCode In (Select Distinct WHCode '
+' From CurrentInv '
+' Where ItemCode IN (select ItemCode from #tmPmnItem) '
+' And OnHandInv>0 ) '
+' And WhPosition.WHCode Not IN (Select Distinct WHCode '
+' From WhPosition '
+' Where BackFlushWHP=1 And WhPositionType=0 And DeptCode='+quotedstr(getDeptCode(mono))+') ';
//选出所有没设拉式货位的仓库
Executesql(AdoQry,sqltext,0);
if AdoQry.RecordCount>0 then
begin
strWHName:=AdoQry.fieldbyname('whName').asstring;
exit;
end;
Result:=True; }
finally
try
// if ishaveInv=0 then
Executesql(AdoQry,'drop table #themnItemList,#theCurrentInv,#tmpBatchCurrentInv,#themnItem',1);
except
end;
AdoQry.Free;
end;
end;
function TFrm_Mrp_Enter_NewPassMo.getDeptCode(mono: string): string;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:='';
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='select DeptCode from mo where mono='+quotedstr(mono);
try
Executesql(AdoQry,sqltext,0);
Result:=AdoQry.fieldbyname('DeptCode').asstring;
finally
AdoQry.Free;
end;
end;
function TFrm_Mrp_Enter_NewPassMo.CreatestallmoveBill(mono: string;
MoLineno: integer;BatchCtrl:integer): boolean;
var AdoQry:TAdoQuery;
sqltext:string;
Billno:string;
begin
Result:=False;
Billno:='';
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
try
try
{ sqltext:='Select mnItemList.ItemCode,BatchCtrl,Sum(MoCtrlQty) As MOCtrlQty '
+' into #tmPmnItemList '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -