inv_mnoutaudit_b.pas
来自「一个MRPII系统源代码版本」· PAS 代码 · 共 1,334 行 · 第 1/4 页
PAS
1,334 行
begin
if BatchCtrl(AdoQry_tmp,fieldbyname('ItemCode').asstring) then
begin
//如果是批处理控制,则根据处入来的数量OUTQTY与批处理库存中最佳数量比效,
//取最佳批次号
outqty:=onhandInv;
Batchno:=GiveBatchNo(AdoQry_tmp,
getCode(lbl_WhCode.text),
getCode(lbl_WhPosition.text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
medt_Date.text,
outqty,
AdoQry_Body.fieldbyname('ItemCode').asstring);
if Batchno='' then
begin
// edit;
// fieldbyname('moRequestqty').asfloat:=0;
end
else
begin
edit;
fieldbyname('InvBillqty').asfloat:=outqty;
fieldbyname('Batchno').asstring:=Batchno;
end;
end
else
begin
edit;
fieldbyname('InvBillqty').asfloat:=onhandInv;
end;
end
else
begin
if (moCtrlqty-MoRealqty)>0 then
begin
if BatchCtrl(AdoQry_tmp,fieldbyname('ItemCode').asstring) then
begin
//如果是批处理控制,则根据处入来的数量OUTQTY与批处理库存中最佳数量比效,
//取最佳批次号
outqty:=(moCtrlqty-MoRealqty);
Batchno:=GiveBatchNo(AdoQry_tmp,
getCode(lbl_WhCode.text),
getCode(lbl_WhPosition.text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
medt_Date.text,
outqty,
AdoQry_Body.fieldbyname('Batchno').asstring);
if Batchno='' then
begin
// edit;
// fieldbyname('moRequestqty').asfloat:=0;
end
else
begin
edit;
fieldbyname('InvBillqty').asfloat:=outqty;
fieldbyname('Batchno').asstring:=Batchno;
end;
end
else
begin
edit;
fieldbyname('InvBillqty').asfloat:=(moCtrlqty-MoRealqty);
end;
end;
end;
end;
end
else
begin
//如果是替代件的最佳获取 不是超领,实领数量=MIN(请领数量,库存数量,限额数量-累计实领数量)
AdoQuery1.First;
AdoQuery1.Locate ('ItemListid',AdoQry_Body.fieldbyname('Parentid').asstring,[]);
tmp_SwApmoCtrlqty:=AdoQuery1.fieldbyname('moCtrlqty').asfloat;
tmp_SwApMoRealqty:=AdoQuery1.fieldbyname('MoRealqty').asfloat;
//折合替换实项的:限额数量-累计实领数量
tmp_reMain:=(tmp_SwApmoCtrlqty-tmp_SwApMoRealqty)*tmp_Bomqty*(1+tmp_BomScrAp_Percent/100);
if InvBillSfcqty<onhandInv then
begin
if InvBillSfcqty<tmp_reMain then
begin
if BatchCtrl(AdoQry_tmp,fieldbyname('ItemCode').asstring) then
begin
//如果是批处理控制,则根据处入来的数量OUTQTY与批处理库存中最佳数量比效,
//取最佳批次号
outqty:=InvBillSfcqty;
Batchno:=GiveBatchNo(AdoQry_tmp,
getCode(lbl_WhCode.text),
getCode(lbl_WhPosition.text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
medt_Date.text,
outqty,
AdoQry_Body.fieldbyname('Batchno').asstring);
if Batchno='' then
begin
// edit;
// fieldbyname('moRequestqty').asfloat:=0;
end
else
begin
edit;
fieldbyname('InvBillqty').asfloat:=outqty;
fieldbyname('Batchno').asstring:=Batchno;
end;
end
else
begin
edit;
fieldbyname('InvBillqty').asfloat:=InvBillSfcqty;
end;
end
else
begin
if tmp_reMain>0 then
begin
edit;
fieldbyname('InvBillqty').asfloat:=tmp_reMain;
end;
end;
end
else
begin
if onhandInv<tmp_reMain then
begin
if BatchCtrl(AdoQry_tmp,fieldbyname('ItemCode').asstring) then
begin
//如果是批处理控制,则根据处入来的数量OUTQTY与批处理库存中最佳数量比效,
//取最佳批次号
outqty:=onhandInv;
Batchno:=GiveBatchNo(AdoQry_tmp,
getCode(lbl_WhCode.text),
getCode(lbl_WhPosition.text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
medt_Date.text,
outqty,
AdoQry_Body.fieldbyname('Batchno').asstring);
if Batchno='' then
begin
// edit;
// fieldbyname('moRequestqty').asfloat:=0;
end
else
begin
edit;
fieldbyname('InvBillqty').asfloat:=outqty;
fieldbyname('Batchno').asstring:=Batchno;
end;
end
else
begin
edit;
fieldbyname('InvBillqty').asfloat:=onhandInv;
end;
end
else
begin
if tmp_reMain>0 then
begin
if BatchCtrl(AdoQry_tmp,fieldbyname('ItemCode').asstring) then
begin
//如果是批处理控制,则根据处入来的数量OUTQTY与批处理库存中最佳数量比效,
//取最佳批次号
outqty:=tmp_reMain;
Batchno:=GiveBatchNo(AdoQry_tmp,
getCode(lbl_WhCode.text),
getCode(lbl_WhPosition.text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
medt_Date.text,
outqty,
AdoQry_Body.fieldbyname('Batchno').asstring);
if Batchno='' then
begin
// edit;
// fieldbyname('moRequestqty').asfloat:=0;
end
else
begin
edit;
fieldbyname('InvBillqty').asfloat:=outqty;
fieldbyname('Batchno').asstring:=Batchno;
end;
end
else
begin
edit;
fieldbyname('InvBillqty').asfloat:=tmp_reMain;
end;
end;
end;
end;
end;
end;
end;
next;
end;
First;
enablecontrols;
end;
end;
procedure TFrm_Inv_MnOutAudit_B.Act_CheckExecute(Sender: TObject);
var
M,tmp_Backflush:integer;
NeedChangePrice,BeforeSaveError:boolean;
tmp_WhCode,tmp_WhPositionCode,tmp_fields:string;
begin
inherited;
DBGridEhColExit(DBGridEh);
if AdoQry_Body.state<>dsBrowse then
AdoQry_Body.post;
medt_Date.onexit(medt_Date);
tmp_WhCode:=getCode(lbl_WhCode.text);
tmp_WhPositionCode:=getCode(lbl_WhPosition.text);
//全面有效检查
BeforeSaveError:=True;
//检查日期、库存
//medt_Date.onexit(medt_Date);
//增加一个变量,用于判断是否为拉式生产订单补退料
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select BackFlush from MoLine '+
' where mono='''+lbl_Mono.text+''''+
' and MoLineno='+lbl_MoLineno.text);
open;
tmp_Backflush:=fieldbyname('Backflush').asinteger;
end;
NeedChangePrice:=NeedChangeAveragePrice(AdoQry_tmp,copy(MEdt_Date.text,1,7));
AdoQry_Body.First;
for M:=0 to AdoQry_Body.recordCount-1 do
begin
if AdoQry_Body.fieldbyname('InvBillqty').asstring<>'0' then
begin
if not InvQtyCheck
(NeedChangePrice,
AdoQry_Body,
AdoQry_tmp,
getCode(lbl_WhCode.text),
getCode(lbl_WhPosition.text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
'InvBillqty',
AdoQry_Body.fieldbyname('InvBillqty').asfloat,
False) then
abort;
if AdoQry_Body.fieldbyname('Batchno').asstring<>'' then
begin
if not BatchInvCheck(AdoQry_tmp,
AdoQry_Body.fieldbyname('Batchno').asstring,
'C',
tmp_WhCode,
tmp_WhPositionCode,
AdoQry_Body.fieldbyname('InvBillqty').asfloat) then
abort;
end;
end;
AdoQry_Body.next;
end;
//真正开始存盘
BeforeSaveError:=False;
DBGridEh.Enabled :=False;
AdoQry_Body.DisableControls ;
AdoQry_Head.Connection.beginTrans;
try
//记录本仓库数据发生改变
ChangeInvStatus(AdoQry_tmp,getCode(lbl_WhCode.text),copy(medt_Date.text,1,7));
//更改InvInBill
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(
'update InvOutBill set'+
' InvBilldate='''+medt_Date.text+''','+
' InvBillMonth='''+copy(medt_Date.text,1,7)+''','+
' InvBillwhchck=1,'+
' wh_EmployeeCode='''+userCode+''','+
' InvBillremArk='''+Extedt_memo.text+''''+
' where InvBillid='+InvBillid);
AdoQry_tmp.execsql;
with AdoQry_Body do
begin
First;
for M:=0 to recordCount-1 do
begin
//对实领数量不为零的数据进行处理
if fieldbyname('InvBillqty').asfloat<>0.0 then
begin
//如果是加权平均,则按加权平均计算
if True then
begin
if PriceType=0 then
begin
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(
' if not exists (select ItemCode from AveragePrice '+
' where whCode='''+getCode(lbl_WhCode.text)+''''+
' and ItemCode='''+fieldbyname('ItemCode').asstring+''')'+
' insert AveragePrice(whCode,ItemCode,Apqty) '+
' Values('''+getCode(lbl_WhCode.text)+''','+
''''+fieldbyname('ItemCode').asstring+''','+
'-('+fieldbyname('InvBillqty').asstring+')) '+
' else '+
' update AveragePrice set '+
' Apqty=Apqty-('+fieldbyname('InvBillqty').asstring+'),'+
//旧单价*新数量
' ApAmount=case when Apqty=0 then AveragePrice*(Apqty-('+fieldbyname('InvBillqty').asstring+')) '+
' else (ApAmount/Apqty)*(Apqty-('+fieldbyname('InvBillqty').asstring+')) end '+
' where whCode='''+getCode(lbl_WhCode.text)+''''+
' and ItemCode='''+fieldbyname('ItemCode').asstring+'''');
AdoQry_tmp.execsql;
end;
end;
//更改InvOutBillline
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(
'update InvOutBillline set '+
' BilllineremArk='''+fieldbyname('BilllineremArk').asstring+''','+
' Batchno='''+fieldbyname('Batchno').asstring+''','+
' InvBillqty='+fieldbyname('InvBillqty').asstring+','+
' InvBillnotaxPrice=isnull((select isnull(Price,0) '+
' from Sc_PriceMaster '+
' where ItemCode='''+fieldbyname('ItemCode').asstring+'''),0),'+
' InvBillnotaxAmount=isnull((select isnull(Price,0) '+
' from Sc_PriceMaster '+
' where ItemCode='''+fieldbyname('ItemCode').asstring+'''),0)*'+fieldbyname('InvBillqty').asstring+
' where InvBillid='+fieldbyname('InvBillid').asstring+
' and InvBilllineno='''+fieldbyname('InvBilllineno').asstring+''''+
' and ItemCode='''+fieldbyname('ItemCode').asstring+'''');
AdoQry_tmp.execsql;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?