inv_priceaudit_b.pas
来自「一个MRPII系统源代码版本」· PAS 代码 · 共 1,055 行 · 第 1/3 页
PAS
1,055 行
tmp_AdoQry.First;
for M:=0 to tmp_AdoQry.RecordCount-1 do
begin
if (AdoQry_Body.fieldbyname('InvBillPrice').asstring<>tmp_AdoQry.fieldbyname('InvBillPrice').asstring) or
(AdoQry_Body.fieldbyname('InvBillnotaxPrice').asstring<>tmp_AdoQry.fieldbyname('InvBillnotaxPrice').asstring) or
(AdoQry_Body.fieldbyname('InvBillAmount').asstring<>tmp_AdoQry.fieldbyname('InvBillAmount').asstring) or
(AdoQry_Body.fieldbyname('InvBillnotaxAmount').asstring<>tmp_AdoQry.fieldbyname('InvBillnotaxAmount').asstring) then
begin
mArk:=0;
end;
oldAmount:=oldAmount+tmp_AdoQry.fieldbyname('InvBillAmount').asfloat;
Amount:=Amount+AdoQry_Body.fieldbyname('InvBillAmount').asfloat;
AdoQry_Body.Next;
tmp_AdoQry.Next;
end;
// 1、暂估价处理Body,增加CheckBox,“真实价格”,当选中,保存时InvInBill.InvBillValuation=0、InvInBillLine.Valuation=0,否则=1
// 注意分两种情况:价格没有改变、价格有改变,产生红蓝单,后者只标识蓝单的Valuation字段,原单、红单都按原来的处理
//2、订单结算核价,按原来的处理,即只要是通过订单结算核价的单据,如果原来是暂估价,经过核价处理后,都不是暂估价了
if (modal='暂估价') then
begin
//如果是暂估价,不管单据有没有改变,只要选了真实价后,则单据变成不是暂估价单据,即InvBillValuation=0
if (mArk=1) and (chck_realPrice.checked=True) then
begin
InvBillValuation:='InvBillValuation=0';
Valuation:='Valuation=0';
blue_InvBillValuation:='0';
blue_Valuation:='0';
end;
if (mArk=1) and (chck_realPrice.checked=False) then
begin
InvBillValuation:='InvBillValuation=1';
Valuation:='Valuation=1';
blue_InvBillValuation:='0';
blue_Valuation:='0';
end;
if (mArk=0) and (chck_realPrice.checked=True) then
begin
InvBillValuation:='InvBillValuation=0';
Valuation:='Valuation=0';
blue_InvBillValuation:='0';
blue_Valuation:='0';
end;
if (mArk=0) and (chck_realPrice.checked=False) then
begin
InvBillValuation:='InvBillValuation=0';
Valuation:='Valuation=0';
blue_InvBillValuation:='1';
blue_Valuation:='1';
end;
end
else
begin
blue_InvBillValuation:='0';
blue_Valuation:='0';
end;
SaveHeadData;
AdoQry_Body.Connection.beginTrans;
try
//更改旧单据的核价的状态或暂估价的状态
//如果是暂估价,把整张单据的物料的暂估价状态设为0
if (modal='暂估价') then
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('update InvInBill '+
' set RealBillFlag='+inttostr(mArk)+','+
InvBillValuation+','+
' InvBillStkchck=1,'+
' PriceAuditTimes='+inttostr(PriceAuditTimes)+','+
' Stk_EmployeeCode='''+userCode+''' '+
' where InvBillid='+AdoQry_Head.fieldbyname('InvBillid').asstring+
' update InvInBillline '+
' set '+
Valuation+
' where InvBillid='+AdoQry_Head.fieldbyname('InvBillid').asstring );
execsql;
end
else
with AdoQry_tmp do
begin
//更改旧单据的一些标志
Close;
sql.clear;
sql.Add(' update InvInBill '+
' set InvBillStkchck=1,'+
' RealBillFlag='+inttostr(mArk)+','+
' PriceAuditTimes='+inttostr(PriceAuditTimes)+','+
' Stk_EmployeeCode='''+userCode+''''+
' where InvBillid='+AdoQry_Head.fieldbyname('InvBillid').asstring);
execsql;
end;
//更改当前供应商应收应付
if AdoQry_Head.fieldbyname('PriceAudittimes').asinteger=0 then
oldAmount:=0;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add(' if not exists (select VendorCode from CurrentAp '+
' where VendorCode='''+getCode(lbl_Vendor.Caption)+''' and '+
' currencyCode='''+currency+''') '+
' insert CurrentAp(VendorCode,currencyCode,ApNoInvoice) '+
' Values('''+getCode(lbl_Vendor.Caption)+''','+
''''+currency+''','+
floattostr(round(Amount*100)/100)+') '+
' else '+
' update CurrentAp '+
' set ApNoInvoice=ApNoInvoice+('+floattostr(round((Amount-oldAmount)*100)/100)+')'+
' where VendorCode='''+getCode(lbl_Vendor.Caption)+''' and '+
' currencyCode='''+currency+'''');
execsql;
end;
if mArk=1 then
begin
tmp_memo:=copy(Trim((oldmemo+'/'+Trim(Extedt_memo.text))),1,250);
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add(' update InvInBill '+
' set InvBillremArk='''+tmp_memo+''''+
' where InvBillid='+AdoQry_Head.fieldbyname('InvBillid').asstring);
execsql;
end;
end;
//如果新旧数据有改变,就产生红,蓝单,并重新计算当前加权平均价
if mArk=0 then
begin
ChangeInvStatus(AdoQry_tmp,getCode(lbl_WhCode.Caption),copy(lbl_Month.Caption,1,7));
//取旧的单据体记录,用于回冲加权平均价及产生一张回冲的单据(负向,红色)
//不管核价还是暂估价,都回冲一加权平均价,因为在采购入库时改经更改了加权平均价
with tmp_AdoQry do
begin
First;
for M:=0 to recordCount-1 do
begin
if True then
// if NeedChangeAveragePrice(AdoQry_tmp,copy(lbl_Month.Caption,1,7)) then
begin
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
//更改加权平均价 回冲当前加权平均价
AdoQry_tmp.sql.Add(' update AveragePrice '+
' set Apqty=Apqty-('+fieldbyname('InvBillqty').asstring+'),'+
' ApAmount=ApAmount-('+fieldbyname('InvBillnotaxAmount').asstring+'*'+fExchRate+')'+
' where whCode='''+getCode(lbl_WhCode.Caption)+''' and '+
' ItemCode='''+fieldbyname('ItemCode').asstring+''''+
' update AveragePrice '+
' set AveragePrice=case when Apqty=0 then AveragePrice else ApAmount/Apqty end '+
' where whCode='''+getCode(lbl_WhCode.Caption)+''' and '+
' ItemCode='''+fieldbyname('ItemCode').asstring+'''');
AdoQry_tmp.execsql;
end;
next;
end;
end;
tmp_memo:=copy(Trim((oldmemo+'/'+Trim(Extedt_memo.text))),1,250);
if (modal='暂估价') then
tmp_memo:=tmp_memo+' 暂估价处理'+AdoQry_Head.fieldbyname('InvBillno').asstring
else
tmp_memo:=tmp_memo+' 核价处理'+AdoQry_Head.fieldbyname('InvBillno').asstring;
//取SourceNO的值
if Trim(AdoQry_Head.fieldbyname('Sourceno').asstring)='' then
Sourceno:=AdoQry_Head.fieldbyname('InvBillno').asstring
else
Sourceno:=AdoQry_Head.fieldbyname('Sourceno').asstring;
Billno:='';
//产生新单据号记录更改后的单据记录 (蓝单)
Billno:=getno(AdoQry_Body.Connection,getCode(lbl_WhCode.Caption)+'R'+copy(tmp_Date,3,2)+copy(tmp_Date,6,2),'InvBill');
blueBillno:=Billno; //lan dan hao
Extedt_Billno.text:=Billno;
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('insert InvInBill'+
'(InvBillno,'+
'whCode,'+
'InvBilldate,'+
'InvBillMonth,'+
'BillTypeCode,'+
'BillType2Code,'+
'VendorCode,'+
'EmployeeCode,'+
'Stk_EmployeeCode,'+
//币种要控制
'currencyCode,'+
'VendorBillno,'+
'pono,'+
'InvBilltaxrate,'+
'WhPositionCode,'+
'InvBillStkchck,'+
'InvBillwhchck,'+
'ParentBillno,'+
'RealBillFlag,'+
'PriceAuditTimes,'+
'InvBillValuation,'+
'InvBillBomChck,'+
'opBill,'+
'bluered,'+
'Sourceno,'+
'InvBillremArk)'+
'Values('''+Billno+''','+
''''+getCode(lbl_WhCode.Caption)+''','+
''''+tmp_Date+''','+
''''+copy(tmp_Date,1,7)+''','+
''''+BillTypeCode+''','+
quotedstr(AdoQry_Head.fieldbyname('BillType2Code').asstring)+','+
''''+getCode(lbl_Vendor.Caption)+''','+
''''+userCode+''','+
''''+userCode+''','+
''''+currency+''','+
quotedstr(AdoQry_Head.fieldbyname('VendorBillno').asstring)+','+
''''+lbl_Pono.Caption+''','+
''''+Extedt_InvBilltaxrate.text+''','+
''''+getCode(lbl_WhPositionCode.Caption)+''','+
'1,'+
'1,'+
''''+AdoQry_Head.fieldbyname('InvBillno').asstring+''','+
'1,'+
inttostr(PriceAuditTimes)+','+
blue_InvBillValuation+','+
'1,'+
AdoQry_Head.fieldbyname('opBill').asstring+','+
quotedstr('B')+','+
quotedstr(Sourceno)+','+
''''+tmp_memo+''')');
AdoQry_tmp.execsql;
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(' select @@IDENTITY as Billid ');
AdoQry_tmp.open;
Billid:=AdoQry_tmp.fieldbyname('Billid').asstring;
with AdoQry_Body do
begin
First;
for M:=0 to recordCount-1 do
begin
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(
'insert InvInBillline(InvBillid,'+
'InvBilllineno,'+
'ItemCode,'+
'pono,'+
'polineno,'+
'BilllineremArk,'+
'InvBillqty,'+
'InvBillPrice,'+
'InvBillAmount,'+
'InvBillnotaxPrice,'+
'InvBillnotaxAmount,'+
'InvBillPricec,'+
'InvBillAmountc,'+
'InvBillnotaxPricec,'+
'InvBillnotaxAmountc,'+
'Valuation) '+
' Values('+Billid+','+
''''+fieldbyname('InvBilllineno').asstring+''','+
''''+fieldbyname('ItemCode').asstring+''','+
''''+lbl_Pono.Caption+''','+
''''+fieldbyname('polineno').asstring+''','+
''''+fieldbyname('BilllineremArk').asstring+''','+
fieldbyname('InvBillqty').asstring+','+
fieldbyname('InvBillPrice').asstring+'*'+fExchRate+','+
'round('+fieldbyname('InvBillAmount').asstring+'*'+fExchRate+',2),'+
fieldbyname('InvBillnotaxPrice').asstring+'*'+fExchRate+','+
'round('+fieldbyname('InvBillnotaxAmount').asstring+'*'+fExchRate+',2),'+
fieldbyname('InvBillPrice').asstring+','+
fieldbyname('InvBillAmount').asstring+','+
fieldbyname('InvBillnotaxPrice').asstring+','+
fieldbyname('InvBillnotaxAmount').asstring+','+
blue_Valuation+')');
AdoQry_tmp.execsql;
//重新更新加权平均价
if True then
// if NeedChangeAveragePrice(AdoQry_tmp,copy(tmp_Date,1,7)) then
begin
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(' update AveragePrice '+
' set Apqty=Apqty+('+fieldbyname('InvBillqty').asstring+'),'+
' ApAmount=ApAmount+('+fieldbyname('InvBillnotaxAmount').asstring+'*'+fExchRate+')'+
' where whCode='''+getCode(lbl_WhCode.Caption)+''' and '+
' ItemCode='''+fieldbyname('ItemCode').asstring+''''+
' update AveragePrice '+
' set AveragePrice=case when Apqty=0 then AveragePrice else ApAmount/Apqty end '+
' where whCode='''+getCode(lbl_WhCode.Caption)+''' and '+
' ItemCode='''+fieldbyname('ItemCode').asstring+'''');
AdoQry_tmp.ExecSQL;
end;
next;
end;
end;
//产生新单据号(负向 红色)
Billno:=getno(AdoQry_Body.Connection,getCode(lbl_WhCode.Caption)+'R'+copy(lbl_Month.Caption,3,2)+copy(lbl_Month.Caption,6,2),'InvBill');
redBillno:=Billno;
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('insert InvInBill'+
'(InvBillno,'+
'whCode,'+
'InvBilldate,'+
'InvBillMonth,'+
'BillTypeCode,'+
'BillType2Code,'+
'VendorCode,'+
'EmployeeCode,'+
//币种要控制
'currencyCode,'+
'VendorBillno,'+
'pono,'+
'InvBilltaxrate,'+
'WhPositionCode,'+
'InvBillStkchck,'+
'InvBillWhChck,'+
'InvBillFinChck,'+
'Stk_EmployeeCode,'+
'ParentBillno,'+
'RealBillFlag,'+
'InvBillBomChck,'+
'bluered,'+
'Sourceno,'+
'InvBillremArk)'+
'Values('''+Billno+''','+
''''+getCode(lbl_WhCode.Caption)+''','+
''''+tmp_Date+''','+
''''+copy(tmp_Date,1,7)+''','+
''''+BillTypeCode+''','+
quotedstr(AdoQry_Head.fieldbyname('BillType2Code').asstring)+','+
''''+getCode(lbl_Vendor.Caption)+''','+
''''+userCode+''','+
''''+currency+''','+
quotedstr(AdoQry_Head.fieldbyname('VendorBillno').asstring)+','+
''''+lbl_Pono.Caption+''','+
Extedt_InvBilltaxrate.text+','+
''''+getCode(lbl_WhPositionCode.Caption)+''','+
'1,'+
'1,'+
'0,'+
''''+userCode+''','+
''''+AdoQry_Head.fieldbyname('InvBillno').asstring+''','+
'0,'+
'1,'+
quotedstr('R')+','+
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?