inv_mnlistaudit_b.pas
来自「一个MRPII系统源代码版本」· PAS 代码 · 共 1,131 行 · 第 1/3 页
PAS
1,131 行
end
else
begin
clickpreview:=True;
inherited;
end;
end;
procedure TFrm_Inv_MnListAudit_B.Act_PrintExecute(Sender: TObject);
begin
if Trim(edt_No.text)<>'' then
begin
BillPrint(AdoQry_Tmp.Connection,getCode(cmbx_WhCode.text),edt_No.Text,Param2,ModuleCode,False,False,True,'');
end
else
begin
inherited;
end;
end;
procedure TFrm_Inv_MnListAudit_B.SaveData;
var
Bookm:tBookmArk;
M,N,tmp_Backflush,tmp_ItemListid,tmp_Parentid,tmp_alterNative:integer;
NeedChangePrice,BeforeSaveError:boolean;
tmp_WhCodeF,tmp_WhPositionCodeF:string;
tmp_actTime,tmp_actTimef,tmp_WhCode,tmp_WhPositionCode,tmp_fields,tmp_realoutqty,tmp_Batchno,text:string;
Billno,sqltext:string;
i:integer;
this_qty:real;
begin
inherited;
i:=0;
if AdoQry_Body.state<>dsBrowse then
AdoQry_Body.post;
// medt_Date.onexit(medt_Date);
//try
//全面有效检查
BeforeSaveError:=True;
NeedChangePrice:=NeedChangeAveragePrice(AdoQry_tmp,copy(MEdt_Date.text,1,7));
Bookm:=AdoQry_Body.GetBookmArk ;
AdoQry_Body.DisableControls ;
AdoQry_Body.First;
tmp_WhCode:=getCode(cmbx_WhCode.Text);
tmp_WhPositionCode:=getCode(cmbx_WhPosition.text);
tmp_actTimef:=DateTimeToStr(Now);
for M:=0 to AdoQry_Body.recordCount-1 do
begin
if AdoQry_Body.fieldbyname('tmprealoutqty').asfloat<>0 then
begin
tmp_ItemListid:=AdoQry_Body.fieldbyname('ItemListid').AsInteger;
tmp_Parentid:=AdoQry_Body.fieldbyname('Parentid').AsInteger;
tmp_alterNative:=AdoQry_Body.fieldbyname('alterNative').AsInteger;
i:=i+1;
//限额数量检查
AdoQry_tmp.Close;
AdoQry_tmp.sql.text:='select Count(*) aa from Item where ItemCode='+
QuotedStr(AdoQry_Body.fieldbyname('ItemCode').asstring)+
' and LimitOut=1';
AdoQry_tmp.open;
if AdoQry_tmp.fieldbyname('aa').AsInteger>0 then
begin
if AdoQry_Body.fieldbyname('moCtrlqty').asfloat<>0 then
begin
if AdoQry_Body.fieldbyname('tmprealoutqty').asfloat>0 then
begin
if AdoQry_Body.fieldbyname('moCtrlqty').asfloat<
AdoQry_Body.fieldbyname('MoRealqty').asfloat+
AdoQry_Body.fieldbyname('tmprealoutqty').asfloat then
begin
DispInfo('物料:'+AdoQry_Body.fieldbyname('ItemCode').asstring+' 超过了限额数量!',1);
abort;
end;
end;
end;
end;
//库存数量检查
if (tmp_alterNative=1) and ((tmp_Parentid=0) or (tmp_Parentid=tmp_ItemListid)) then
else
if not InvQtyCheck
(NeedChangePrice,
AdoQry_Body,
AdoQry_tmp,
tmp_WhCode,
tmp_WhPositionCode,
AdoQry_Body.fieldbyname('ItemCode').asstring,
'tmprealoutqty',
AdoQry_Body.fieldbyname('tmprealoutqty').asfloat,
False) then
abort;
if AdoQry_Body.fieldbyname('tmpBatchno').asstring<>'' then
begin
if not BatchInvCheck(AdoQry_tmp,
AdoQry_Body.fieldbyname('tmpBatchno').asstring,
'C',
tmp_WhCode,
tmp_WhPositionCode,
AdoQry_Body.fieldbyname('tmprealoutqty') .asfloat) then
abort;
end;
end;
AdoQry_Body.next;
end;
//ChangeInvstatus(AdoQry_tmp,tmp_WhCode,copy(medt_Date.text,1,7));
AdoQry_Body.GotoBookmArk(Bookm);
BeforeSaveError:=False;
{except
AdoQry_Body.EnableControls ;
DispInfo('没有保存成功,请检查后再保存!',3);
exit;
end;}
if i=0 then abort;
////插入单据表
DBGridEh.Enabled :=False;
AdoQry_Body.Connection.beginTrans;
try
ChangeInvstatus(AdoQry_tmp,tmp_WhCode,copy(medt_Date.text,1,7));
//产生单据号
Billno:=getno(AdoQry_Body.Connection,tmp_WhCode+
'C'+copy(medt_Date.text,3,2)+copy(medt_Date.text,6,2),'InvBill');
//增加InvOutBill
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
// AdoQry_tmp.sql.Add(
sqltext:='insert InvOutBill'+
'(InvBillno,'+
'whCode,'+
'InvBilldate,'+
'InvBillMonth,'+
'DeptCode,'+
'mono,'+
'MoLineno,'+
'BillTypeCode,'+
'EmployeeCode,'+
'wh_EmployeeCode,'+
'WhPositionCode,'+
'shiftType,'+
'InvBillwhchck,'+
'InvBillremArk)'+
'Values('''+Billno+''','+
''''+tmp_WhCode+''','+
''''+medt_Date.text+''','+
''''+copy(medt_Date.text,1,7)+''','+
''''+getCode(Frm_Inv_MnListAudit_H.tmp_DeptCode)+''','+
''''+AdoQry_Head.fieldbyname('mono').asstring+''','+
AdoQry_Head.fieldbyname('MoLineno').asstring+','+
''''+BillTypeCode+''','+
''''+userCode+''','+
''''+getCode(cmbx_Employee.Text)+''','+
''''+tmp_WhPositionCode+''','+
''''+cmbbx_Shift.text+''','+
'1'+','+
''''+''+''')';
AdoQry_tmp.sql.Add(sqltext);
AdoQry_tmp.execsql;
//取InvBillID
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(' select @@IDENTITY as Billid ');
AdoQry_tmp.open;
Billid:=AdoQry_tmp.fieldbyname('Billid').asstring;
Bookm:=AdoQry_Body.GetBookmArk ;
with AdoQry_Body do
begin
//处理替代件物料
First;
for M:=0 to recordCount-1 do
begin
tmp_ItemListid:=AdoQry_Body.fieldbyname('ItemListid').AsInteger;
tmp_Parentid:=AdoQry_Body.fieldbyname('Parentid').AsInteger;
tmp_alterNative:=AdoQry_Body.fieldbyname('alterNative').AsInteger;
if (tmp_alterNative=1) and (tmp_Parentid<>0) and (tmp_Parentid<>tmp_ItemListid) then
begin
this_qty:=round(fieldbyname('tmprealoutqty').asfloat/
(fieldbyname('Bomqty').asfloat*(1+fieldbyname('BomScrAp_Percent').asfloat/100)));
Bookm:=GetBookmArk;
Locate('ItemListid',tmp_Parentid,[]);
edit;
fieldbyname('tmprealoutqty').asfloat:=fieldbyname('tmprealoutqty').asfloat+this_qty;
post;
GotoBookmArk(Bookm);
end;
next;
end;
//全部处理
First;
N:=1;
for M:=0 to recordCount-1 do
begin
//增加表InvOutBillLINE 只增加不为零为的数量
if AdoQry_Body.fieldbyname('tmprealoutqty').asfloat<>0 then
begin
if AdoQry_Body.fieldbyname('realoutqty1').asfloat=0 then
begin
tmp_Batchno:='Batchno1';
tmp_realoutqty:='realoutqty1';
tmp_acttime:='Requesttime1';
tmp_WhCodef:='whCode1';
tmp_WhPositionCodef:='WhPositionCode1';
end
else if AdoQry_Body.fieldbyname('realoutqty2').asfloat=0 then
begin
tmp_Batchno:='Batchno2';
tmp_realoutqty:='realoutqty2';
tmp_acttime:='Requesttime2';
tmp_WhCodef:='whCode2';
tmp_WhPositionCodef:='WhPositionCode2';
end
else if AdoQry_Body.fieldbyname('realoutqty3').asfloat=0 then
begin
tmp_Batchno:='Batchno3';
tmp_realoutqty:='realoutqty3';
tmp_acttime:='Requesttime3';
tmp_WhCodef:='whCode3';
tmp_WhPositionCodef:='WhPositionCode3';
end
else if AdoQry_Body.fieldbyname('realoutqty4').asfloat=0 then
begin
tmp_Batchno:='Batchno4';
tmp_realoutqty:='realoutqty4';
tmp_acttime:='Requesttime4';
tmp_WhCodef:='whCode4';
tmp_WhPositionCodef:='WhPositionCode4';
end
else if AdoQry_Body.fieldbyname('realoutqty5').asfloat=0 then
begin
tmp_Batchno:='Batchno5';
tmp_realoutqty:='realoutqty5';
tmp_acttime:='Requesttime5';
tmp_WhCodef:='whCode5';
tmp_WhPositionCodef:='WhPositionCode5';
end
else if AdoQry_Body.fieldbyname('realoutqty6').asfloat=0 then
begin
tmp_Batchno:='Batchno6';
tmp_realoutqty:='realoutqty6';
tmp_acttime:='Requesttime6';
tmp_WhCodef:='whCode6';
tmp_WhPositionCodef:='WhPositionCode6';
end
else if AdoQry_Body.fieldbyname('realoutqty7').asfloat=0 then
begin
tmp_Batchno:='Batchno7';
tmp_realoutqty:='realoutqty7';
tmp_acttime:='Requesttime7';
tmp_WhCodef:='whCode7';
tmp_WhPositionCodef:='WhPositionCode7';
end
else if AdoQry_Body.fieldbyname('realoutqty8').asfloat=0 then
begin
tmp_Batchno:='Batchno8';
tmp_realoutqty:='realoutqty8';
tmp_acttime:='Requesttime8';
tmp_WhCodef:='whCode8';
tmp_WhPositionCodef:='WhPositionCode8';
end
else if AdoQry_Body.fieldbyname('realoutqty9').asfloat=0 then
begin
tmp_Batchno:='Batchno9';
tmp_realoutqty:='realoutqty9';
tmp_acttime:='Requesttime9';
tmp_WhCodef:='whCode9';
tmp_WhPositionCodef:='WhPositionCode9';
end
else if AdoQry_Body.fieldbyname('realoutqty10').asfloat=0 then
begin
tmp_Batchno:='Batchno10';
tmp_realoutqty:='realoutqty10';
tmp_acttime:='Requesttime10';
tmp_WhCodef:='whCode10';
tmp_WhPositionCodef:='WhPositionCode10';
end;
tmp_ItemListid:=AdoQry_Body.fieldbyname('ItemListid').AsInteger;
tmp_Parentid:=AdoQry_Body.fieldbyname('Parentid').AsInteger;
tmp_alterNative:=AdoQry_Body.fieldbyname('alterNative').AsInteger;
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
if (tmp_alterNative=1) and ((tmp_Parentid=0) or (tmp_Parentid=tmp_ItemListid)) then
else
begin
AdoQry_tmp.sql.Add(
'insert InvOutBillline'+
'(InvBillid,'+
'InvBilllineno,'+
'mono,'+
'MoLineno,'+
'ItemCode,'+
'ite_ItemCode,'+
'BilllineremArk,'+
'Batchno,'+
'ItemListid,'+
'InvBillqty)'+
'Values('+Billid+','+
''''+inttostr(N)+''','+
''''+AdoQry_Head.fieldbyname('mono').asstring+''','+
AdoQry_Head.fieldbyname('MoLineno').asstring+','+
''''+fieldbyname('ItemCode').asstring+''','+
''''+fieldbyname('ite_ItemCode').asstring+''','+
''''+fieldbyname('BilllineremArk').asstring+''','+
''''+fieldbyname('tmpBatchno').asstring+''','+
fieldbyname('ItemListid').asstring+','+
fieldbyname('tmprealoutqty').asstring+')');
if PriceType=0 then //更改移动平均价格
begin
AdoQry_tmp.sql.Add(
' if not exists (select ItemCode from AveragePrice '+
' where whCode='''+tmp_WhCode+''''+
' and ItemCode='''+fieldbyname('ItemCode').asstring+''')'+
' insert AveragePrice(whCode,ItemCode,Apqty) '+
' Values('''+tmp_WhCode+''','+
''''+fieldbyname('ItemCode').asstring+''','+
'-('+fieldbyname('tmprealoutqty').asstring+')) '+
' else '+
' update AveragePrice set '+
' Apqty=Apqty-('+fieldbyname('tmprealoutqty').asstring+'),'+
//旧单价*新数量
' ApAmount=case when Apqty=0 then AveragePrice*(Apqty-('+fieldbyname('tmprealoutqty').asstring+')) '+
' else (ApAmount/Apqty)*(Apqty-('+fieldbyname('tmprealoutqty').asstring+')) end '+
' where whCode='''+tmp_WhCode+''''+
' and ItemCode='''+fieldbyname('ItemCode').asstring+''''+
{' update InvOutBillline set InvBillnotaxPrice=AveragePrice,'+
' InvBillnotaxAmount=InvBillqty*AveragePrice from AveragePrice'+
' where InvBillid='+Billid+' and AveragePrice.whCode='+QuotedStr(tmp_WhCode)+
' and AveragePrice.ItemCode=InvOutBillline.ItemCode '+
' and InvOutBillline.ItemCode='+QuotedStr(fieldbyname('ItemCode').asstring));}
' update InvOutBillline set InvBillnotaxPrice=isnull(Sc_PriceMaster.Price,0),'+
' InvBillnotaxAmount=InvBillqty*isnull(Sc_PriceMaster.Price,0) '+
' from Sc_PriceMaster '+
' where InvBillid='+Billid+
' and Sc_PriceMaster.ItemCode=InvOutBillline.ItemCode '+
' and InvOutBillline.ItemCode='+QuotedStr(fieldbyname('ItemCode').asstring));
end;
//更改当前库存 更改Item表的库存数据
if updateInv(AdoQry_tmp2,tmp_WhCode,tmp_WhPositionCode,fieldbyname('ItemCode').asstring,'(-('+fieldbyname('tmprealoutqty').asstring+'))',needChangePrice,True)<>'' then
abort;
//更改批次库存数量
if fieldbyname('tmpBatchno').asstring<>'' then
ChangeBatchInv(AdoQry_tmp2,fieldbyname('tmpBatchno').asstring,'c',medt_Date.Text,tmp_WhCode,tmp_WhPositionCode,fieldbyname('tmprealoutqty').asfloat);
end;
//更新实领数量与累计实领数量
AdoQry_tmp2.Close;
AdoQry_tmp2.sql.Text:='select * from mnListRequest where ItemListid='''+fieldbyname('ItemListid').asstring+''' and shiftType='''+fieldbyname('shiftType').asstring+'''';
AdoQry_tmp2.open;
if AdoQry_tmp2.eof then
AdoQry_tmp.SQL.Add(' insert into mnListRequest (ItemListid,shiftType,'+
tmp_WhCodef+','+tmp_WhPositionCodef+','+
tmp_Batchno+','+tmp_acttime+','+
tmp_realoutqty+') Values ('+
fieldbyname('ItemListid').asstring+','+
''''+fieldbyname('shiftType').asstring+''','+
''''+tmp_WhCode+''','+
''''+tmp_WhPositionCode+''','+
''''+fieldbyname('tmpBatchno').asstring+''','+
''''+tmp_acttimef+''','+
fieldbyname('tmprealoutqty').asstring+')')
else
AdoQry_tmp.sql.Add(' update mnListRequest set '+
tmp_WhCodef+'='''+tmp_WhCode+''','+
tmp_acttime+'='''+tmp_acttimef+''','+
tmp_WhPositionCodef+'='''+tmp_WhPositionCode+''','+
tmp_Batchno+'='''+fieldbyname('tmpBatchno').asstring+''','+
tmp_realoutqty+'='+fieldbyname('tmprealoutqty').asstring+' '+
'where ItemListid='''+fieldbyname('ItemListid').asstring+''' and'+
' shiftType='''+fieldbyname('shiftType').asstring+'''');
AdoQry_tmp.SQL.Add(' update mnItemList set MoRealQty='+fieldbyname('MoRealQty').asstring+'+'+fieldbyname('tmprealoutqty').asstring+' '+
' where ItemListid='+fieldbyname('ItemListid').asstring+'');
text:=AdoQry_tmp.SQL.Text ;
AdoQry_tmp.ExecSQL;
N:=N+1;
next;
end
else
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?