📄 mrp_enter_freepassmo.pas
字号:
except
Result:=False;
end;
finally
AdoQry.free;
end;
end;
function TFrm_Mrp_Enter_FreePassMo.beendilivered(mono: string;
MoLineno: integer): boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='select * from mnItemList '
+' where MoRealqty>0 '
+' and mono='+quotedstr(mono)
+' and MoLineno='+inttostr(MoLineno);
try
Executesql(AdoQry,sqltext,0);
if AdoQry.RecordCount>0 then
Result:=True;
finally
AdoQry.Free;
end;
end;
function TFrm_Mrp_Enter_FreePassMo.beenProducted(mono: string;
MoLineno: integer): boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='select * from MoLine '
+' where moqty=MoNoFinishqty '
+' and mono='+quotedstr(mono)
+' and MoLineno='+inttostr(MoLineno);
try
Executesql(AdoQry,sqltext,0);
if AdoQry.RecordCount=0 then
Result:=True;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_FreePassMo.Act_ModifyExecute(Sender: TObject);
var sqltext:string;
tmpQry:TAdoQuery;
tmPmoqty:string;
begin
inherited;
if AdoQry_Head.RecordCount=0 then exit;
{if getstatus(AdoQry_Head.fieldbyname('mono').asstring,AdoQry_Head.fieldbyname('MoLineno').asinteger)<>5 then
begin
DispInfo('该生产订单行不是准备状态,不可修改!',5);
abort;
end;}
tmpQry:=TAdoQuery.Create(nil);
tmpQry.EnableBCD:=False;
tmpQry.Connection:=AdoQry_Head.Connection;
sqltext:='select sum(MoRealqty) as MoRealqty from mnItemList'
+' where mono='+quotedstr(AdoQry_Head.fieldbyname('mono').asstring)
+' and MoLineno='+AdoQry_Head.fieldbyname('MoLineno').asstring;
Executesql(tmpQry,sqltext,0) ;
Frm_Mrp_Enter_PassMo_D := TFrm_Mrp_Enter_PassMo_D.Create(self);
try
with Frm_Mrp_Enter_PassMo_D do
begin
AdoQry_tmp.Connection:=dbconnect;
edtmono.Text:=AdoQry_Head.fieldbyname('mono').asstring;
edtMoLineno.Text:=AdoQry_Head.fieldbyname('MoLineno').asstring;
Extedt_ItemCode.Text:=AdoQry_Head.fieldbyname('ItemCode').asstring;
lbl_ItemName.Caption:=AdoQry_Head.fieldbyname('ItemName').asstring;
Extedt_ItemName.Text:=AdoQry_Head.fieldbyname('ItemName').asstring;
medt_Modate.Text:=AdoQry_Head.fieldbyname('MoLinedate').asstring;
medt_MostArtworkdate.Text:=AdoQry_Head.fieldbyname('mostArtworkdate').asstring;
edt_qty.Text:=AdoQry_Head.fieldbyname('moqty').asstring;
tmPmoqty:=edt_qty.Text;
if AdoQry_Head.fieldbyname('MoLinestatus').asinteger=5 then
edt_qty.Enabled:=True;
if (AdoQry_Head.fieldbyname('MoLinestatus').asinteger=6) and
(AdoQry_Head.fieldbyname('MoRealinqty') .asfloat<=0) and
(AdoQry_Head.fieldbyname('MoInqty').asfloat<=0) and
(tmpQry.fieldbyname('MoRealqty').asfloat<=0) then
edt_qty.Enabled:=True;
edtMoNoFinishqty.Text:=AdoQry_Head.fieldbyname('MoNoFinishqty').asstring;
btn_ok.Enabled:=False;
showmodal;
// medt_Modate.SetFocus;
if modalResult=mrok then
begin
AdoQry_Head.Edit;
AdoQry_Head.fieldbyname('MoLinedate').asstring:=medt_Modate.Text;
AdoQry_Head.fieldbyname('mostArtworkdate').asstring:=medt_MostArtworkdate.Text;
if tmPmoqty<>edt_qty.Text then
begin
AdoQry_Head.fieldbyname('moqty').asstring:=edt_qty.Text;
AdoQry_Head.fieldbyname('MoNoFinishqty').asstring:=edt_qty.Text;
if AdoQry_Head.fieldbyname('MoLinestatus').asinteger=6 then
AdoQry_Head.fieldbyname('MoLinestatus').asinteger:=5;
end;
AdoQry_Head.Post;
saveMoLineHistory(dbconnect,AdoQry_Head.fieldbyname('mono').asstring,AdoQry_Head.fieldbyname('MoLineno').asinteger,userCode,1);
updateMoLine(AdoQry_Head.fieldbyname('mono').asstring,AdoQry_Head.fieldbyname('MoLineno').asinteger,tmPmoqty<>edt_qty.text);
end;
end;
finally
Frm_Mrp_Enter_PassMo_D.Free;
end;
end;
procedure TFrm_Mrp_Enter_FreePassMo.updateMoLine(mono: string;
MoLineno: integer;isupdate:boolean);
var AdoQry:TAdoQuery;
sqltext:string;
begin
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='update MoLine '
+' set MoLinedate= '+quotedstr(AdoQry_Head.fieldbyname('MoLinedate').asstring)+','
+' MoLinestatus='+AdoQry_Head.fieldbyname('MoLinestatus').asstring+','
+iifstring(isupdate,'moqty='+AdoQry_Head.fieldbyname('moqty').asstring+',MoNoFinishqty='+AdoQry_Head.fieldbyname('MoNoFinishqty').asstring+',',' ')
+' mostArtworkdate='+quotedstr(AdoQry_Head.fieldbyname('mostArtworkdate').asstring)
+' where mono='+quotedstr(mono)
+' and MoLineno='+inttostr(MoLineno);
try
Executesql(AdoQry,sqltext,1);
finally
AdoQry.Free;
end;
end;
function TFrm_Mrp_Enter_FreePassMo.beenbuildBill(mono: string;
MoLineno: integer): boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='select * from InvOutBill '
+' where mono='+quotedstr(mono)
+' and MoLineno='+inttostr(MoLineno)
+' and InvBillwhchck=0 ';
try
Executesql(AdoQry,sqltext,0);
if AdoQry.RecordCount>0 then
Result:=True;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_FreePassMo.deletemnList(mono:string;MoLineno:integer);
var AdoQry:TAdoQuery;
sqltext:string;
begin
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='delete from mnItemList '
+' where mono='+quotedstr(mono)
+' and MoLineno='+inttostr(MoLineno);
try
Executesql(AdoQry,sqltext,1);
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_FreePassMo.Button1Click(Sender: TObject);
var BookmArk:string;
tMpsqltext:string;
Ordernoandlineno:string;
AdoQry:TAdoQuery;
tmpItemCode:string;
tmprequireqty:double;
tmpPlanqty:double;
mindate:string;
txt:string;
tmpponoFinishqty:double;
tmPMoNoFinishqty:double;
begin
inherited;
try
if AdoQry_Head.RecordCount=0 then exit;
if AdoQry_Head.State in [dsedit] then AdoQry_Head.Post;
if SelectedCount=0 then
begin
DispInfo('请选择记录!',3);
exit;
end;
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
tmpPlanqty:=0;
mindate:='1900.01.01';
BookmArk:=AdoQry_Head.BookmArk;
Ordernoandlineno:=quotedstr('yy');
try
Executesql(AdoQry_tmp,'drop table #tmpBom',1);
except
end;
tMpsqltext:='Select top 0 Bom.ItemCode,mono=''fgfdggfgfdfgfgfggf'',MoLineno=0,Bom.BomItemType,Item.PmCode, '+#13+
' dateAdd(dd,(Item.MnLdTime)*(-1),'''+requiredate+''''+') As RequireDate, '+#13+
floattostr(requireqty)+'*Bom.BomQty*(1+ BomScrAp_Percent/100) as requireqty,'
+' Item.ItemName,Item.CurrentonhandInv,Item.CurrentonCheckInv, '+#13+
' Itemflag=Bom.ItemCode+'' ''+Item.ItemName'+#13+
' into #tmpBom '+#13+
' From Bom '+#13+
' Join Item On Bom.ItemCode=Item.ItemCode '+#13+
' where Bom.ite_ItemCode='''+ItemCode+'''';
Executesql(AdoQry_tmp,tMpsqltext,1);
AdoQry_Head.First;
while not AdoQry_Head.Eof do
begin
if AdoQry_Head.fieldbyname('MoLineCheck').asinteger=1 then
begin
Ordernoandlineno:=Ordernoandlineno+','+quotedstr(AdoQry_Head.fieldbyname('mono').asstring+inttostr(AdoQry_Head.fieldbyname('MoLineno').asinteger));
ItemCode:=AdoQry_Head.fieldbyname('ItemCode').asstring;
requiredate:=AdoQry_Head.fieldbyname('MoLinedate').asstring;
requireqty:=AdoQry_Head.fieldbyname('moqty').asfloat;
openBom(ItemCode,requireqty,requiredate);
end;
AdoQry_Head.Next;
end;
//-------------------------------------------------------------
tMpsqltext:=' select #tmpBom.ItemCode,#tmpBom.mono,#tmpBom.MoLineno,convert(float,0) as wipqty,sum(isnull(mnItemList.MoRealqty,0)) as Assignqty '
+' into #tmpBom1 '
+' from #tmpBom '
+' left outer join mnItemList on #tmpBom.ItemCode=mnItemList.ItemCode '
+' and #tmpBom.mono=mnItemList.mono'
+' and #tmpBom.MoLineno=mnItemList.MoLineno '
+' group by #tmpBom.ItemCode,#tmpBom.mono,#tmpBom.MoLineno ';
Executesql(AdoQry_tmp,tMpsqltext,1);
tMpsqltext:=' select #tmpBom.*,lessqty=convert(decimal(14,2),#tmpBom.requireqty-#tmpBom.CurrentonhandInv-isnull(#tmpBom1.Assignqty,0)),netqty=case when requireqty-#tmpBom1.Assignqty>0 then requireqty-#tmpBom1.Assignqty else 0 end,'
+' Planqty=convert(float,0),wipqty=isnull(#tmpBom1.wipqty,0),Assignqty=isnull(#tmpBom1.Assignqty,0),minflag=0 '
+' into #tmpBomResult'+
' from #tmpBom'+#13+
' left join #tmpBom1 on #tmpBom.ItemCode=#tmpBom1.ItemCode'+
' and #tmpBom.mono=#tmpBom1.mono '
+' and #tmpBom.MoLineno=#tmpBom1.MoLineno '
+' Order by #tmpBom.ItemCode,#tmpBom.requiredate';
Executesql(AdoQry_tmp,tMpsqltext,1);
Executesql(AdoQry,'select * from #tmpBomResult Order by ItemCode,requiredate',0);
AdoQry.First;
tmpItemCode:=AdoQry.fieldbyname('ItemCode').asstring;
while not AdoQry.Eof do
begin
if AdoQry.fieldbyname('ItemCode').asstring<>tmpItemCode then
begin
mindate:='1900.01.01';
end;
txt:='select sum(isnull(case when ponoFinishqty<0 then 0 else ponoFinishqty end,0)) as ponoFinishqty from poline'
+' where poline.polinestatus=6 '
+' and poline.ItemCode='+quotedstr(AdoQry.fieldbyname('ItemCode').asstring)
+' and poline.polinedate > '+quotedstr(mindate)
+' and poline.polinedate<='+quotedstr(AdoQry.fieldbyname('requiredate').asstring);
Executesql(AdoQry_tmp,txt,0) ;
tmpponoFinishqty:=AdoQry_tmp.fieldbyname('ponoFinishqty').asfloat;
txt:='select sum(isnull(case when MoNoFinishqty<0 then 0 else MoNoFinishqty end,0)) as MoNoFinishqty from MoLine'
+' where MoLine.MoLinestatus=6 '
+' and MoLine.ItemCode='+quotedstr(AdoQry.fieldbyname('ItemCode').asstring)
+' and MoLine.MoLinedate > '+quotedstr(mindate)
+' and MoLine.MoLinedate<='+quotedstr(AdoQry.fieldbyname('requiredate').asstring);
Executesql(AdoQry_tmp,txt,0) ;
tmPMoNoFinishqty:=AdoQry_tmp.fieldbyname('MoNoFinishqty').asfloat;
txt:='update #tmpBomResult'
+' set wipqty= '+floattostr(tmpponoFinishqty+tmPMoNoFinishqty)
+' from #tmpBomResult '
+' where #tmpBomResult.ItemCode='+quotedstr(AdoQry.fieldbyname('ItemCode').asstring)
+' and #tmpBomResult.mono='+quotedstr(AdoQry.fieldbyname('mono').asstring)
+' and #tmpBomResult.MoLineno='+inttostr(AdoQry.fieldbyname('MoLineno').asinteger);
Executesql(AdoQry_tmp,txt,1);
if (AdoQry.RecNo=1) or (AdoQry.fieldbyname('ItemCode').asstring<>tmpItemCode) then
begin
txt:='update #tmpBomResult'
+' set Planqty=CurrentonhandInv+CurrentonCheckInv,'
+' minflag=1 '
+' where #tmpBomResult.ItemCode='+quotedstr(AdoQry.fieldbyname('ItemCode').asstring)
+' and #tmpBomResult.mono='+quotedstr(AdoQry.fieldbyname('mono').asstring)
+' and #tmpBomResult.MoLineno='+inttostr(AdoQry.fieldbyname('MoLineno').asinteger);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -