📄 ap_enter_noinvoiceinvinorder1.pas
字号:
KillNoInvoiceNo:string;//抵冲历史未开票金额未开票入库单单号;
beforeTotal:double ; //未开票金额未开票入库单金额 ;
curTotal:double; //当前入库单金额 ;
tmpAdoQry:TAdoQuery;
//单据总金额;
SumInvBillNoTaxAmount,SumInvBillAmount,SumInvBillAmountC,SumInvBillNoTaxAmountC:double;
begin
//取单据号
inherited;
//取服务器的日期;
Executesql(AdoQry_tmp,'select convert (varchAr(10),getdate(),102) as a ',0);
curdate:=AdoQry_tmp.fieldbyname('a').asstring;
if not Edt_InvBillDate.Enabled then
Edt_InvBillDate.Enabled:=True;
if AdoQry_Body.state<>dsBrowse then
AdoQry_Body.post;
if Trim(Edt_InvBillDate.text)>curdate then
begin
DispInfo('单据日期和单据月份必须小于等于当前日期或月份',3);
Edt_InvBillDate.setfocus;
abort;
end;
if copy(Trim(Edt_InvBillDate.text),1,7)>SelectStArtMonthAp then
begin
DispInfo(' 单据日期和单据月份必须小于等于模块启用月份',3);
Edt_InvBillDate.setfocus;
abort;
end;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select ApParamValueC '+
' from ApParam '+
' where ApParamCode=''KillNoInvoiceNo''');
open;
KillNoInvoiceNo:=fieldbyname('ApParamValueC').asstring;
end;
if KillNoInvoiceNo='' then
begin
DispInfo('应付帐款参数设置未能抵冲'+#10+#13+'历史未开票金额未开票入库单单号!'+#10+#13+'请设置',3);
abort;
end;
if Trim(Edt_InvBillNo.text)='' then
begin
DispInfo('入库单单号不能为空',3);
Edt_InvBillNo.SetFocus ;
abort;
end;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.text:=' select InvBillid from InvInBill where InvBillno='''+Trim(Edt_InvBillNo.text)+'''';
open;
if recordCount<>0 then
begin
DispInfo('此入库单单号已存在!请重新输入!',3);
Edt_InvBillNo.SetFocus ;
abort;
end;
end;
beforeTotal:=0;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.text:=' select sum(InvInBillline.InvBillNoTaxAmount) as Total '
+' from InvInBillline,InvInBill'
+' where InvInBillline.InvBillid=InvInBill.InvBillid '
+' and InvInBill.InvBillNo='''+KillNoInvoiceNo+'''';
open;
beforeTotal:=fieldbyname('Total').asfloat;
end;
curTotal:=0;
with AdoQry_Body do
begin
First;
while not eof do
begin
curTotal:=curTotal+fieldbyname('InvBillNoTaxAmount').asfloat;
next;
end;
end;
if curTotal> beforeTotal then
begin
DispInfo('当前入库单金额不能大于未开票金额未开票入库单金额',3);
abort;
end;
SumInvBillNoTaxAmount:=0;
SumInvBillAmount:=0;
SumInvBillAmountC:=0;
SumInvBillNoTaxAmountC:=0;
try
with AdoQry_Body do
begin
First;
while not eof do
begin
if IsMasterCurrency(Trim(Edt_CurrencyCode.text)) then
begin
SumInvBillNoTaxAmount:=SumInvBillNoTaxAmount+fieldbyname('InvBillNoTaxAmount').asfloat;
SumInvBillAmount:=SumInvBillAmount+fieldbyname('InvBillAmount').asfloat;
SumInvBillAmountC:=SumInvBillAmountC+fieldbyname('InvBillAmount').asfloat;
SumInvBillNoTaxAmountC:=SumInvBillNoTaxAmountC+fieldbyname('InvBillNoTaxAmount').asfloat;
end
else
begin
SumInvBillNoTaxAmount:=SumInvBillNoTaxAmount+fieldbyname('InvBillNoTaxAmount').asfloat;
SumInvBillAmount:=SumInvBillAmount+fieldbyname('InvBillAmount').asfloat;
SumInvBillAmountC:=SumInvBillAmountC+fieldbyname('InvBillAmount').asfloat*strtofloat(ExchRate);
SumInvBillNoTaxAmountC:=SumInvBillNoTaxAmountC+fieldbyname('InvBillNoTaxAmount').asfloat*strtofloat(ExchRate);
end;
next;
end;
end;
finally
AdoQry_Body.EnableControls ;
end;
dbconnect.beginTrans;
try
if Status='Add' then
begin
//增加InvInBill
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('insert InvInBill'+
'(InvBillno,'+
'VendorCode ,'+
'whCode,'+
'InvBilldate,'+
'InvBillMonth,'+
'BillTypeCode,'+
'EmployeeCode,'+
'WH_EmployeeCode,'+
'WhPositionCode,'+
'InvBillwhchck,'+
'ISHistoryBill,'+
'InvBillFinChck,'+
'currencyCode,'+
'ExchRate,'+
'InvBilltaxrate,'+
'InvBillCreateTime,'+
'VendorBillNo,'+
'InvBillValuation,'+
'InvBillremArk)'+
'Values('''+Trim(Edt_InvBillNo.text)+''','+
''''+LkEdt_VendorCode.text+''','+
''''+getCode(CmBx_WhCode.text)+''','+
''''+Edt_InvBillDate.text+''','+
''''+copy(Edt_InvBillDate.text,1,7)+''','+
''''+getCode(CmBx_BillTypeCode.text)+''','+
''''+userCode+''','+
''''+userCode+''','+
''''+getCode(Edt_WhPositionCode.text)+''','+
'1,'+
'1,'+
'0,'+
''''+Trim(Edt_CurrencyCode.text)+''','+
Trim(Edt_ExchRate.text)+','+
Vendortaxrate_Percent+','+
''''+curdate+''','+
''''+Edt_VendorBillNo.text+''','+
'0,'+
'''历史未匹配入库单//抵冲参数设置中历史未匹配入库单金额的未匹配入库单:'+KillNoInvoiceNo+Edt_InvBillRemArk.text+''''+')');
AdoQry_tmp.execsql;
//取InvBillID
Billid:='';
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(' select @@IDENTITY as Billid ');
AdoQry_tmp.open;
Billid:=AdoQry_tmp.fieldbyname('Billid').asstring;
Amount:=0;
AdoQry_Body.DisableControls ;
with AdoQry_Body do
begin
First;
for M:=0 to recordCount-1 do
begin
//由于显示在DBGRID中的价格不管外币还是人民币,都是用同一个字段,因
//此在存盘时把字段分开,如下:
if IsMasterCurrency(Trim(Edt_CurrencyCode.text)) then
begin
tmp_InvBillAmount:=fieldbyname('InvBillAmount').asstring;
tmp_InvBillnotaxAmount:=fieldbyname('InvBillnotaxAmount').asstring;
tmp_InvBillAmountc:=fieldbyname('InvBillAmount').asstring;
tmp_InvBillnotaxAmountc:=fieldbyname('InvBillnotaxAmount').asstring;
tmp_InvBillPriceC:=fieldbyname('InvBillPrice').asstring;
tmp_InvBillNoTaxPriceC:= fieldbyname('InvBillNoTaxPrice').asstring;
end
else
begin
tmp_InvBillAmount:=fieldbyname('InvBillAmount').asstring;
tmp_InvBillnotaxAmount:=fieldbyname('InvBillnotaxAmount').asstring;
tmp_InvBillAmountc:=floattostr(fieldbyname('InvBillAmount').asfloat*strtofloat(ExchRate));
tmp_InvBillnotaxAmountc:=floattostr(fieldbyname('InvBillnotaxAmount').asfloat*strtofloat(ExchRate));
tmp_InvBillPriceC:=floattostr(fieldbyname('InvBillPrice').asfloat*strtofloat(ExchRate));
tmp_InvBillNoTaxPriceC:=floattostr( fieldbyname('InvBillNoTaxPrice').asfloat*strtofloat(ExchRate));
end;
//只用人民币结算
Amount:=Amount+strtofloat(tmp_InvBillAmount);
//增加InvBillLINE
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('insert InvInBillline'+
'(InvBillid,'+
'InvBilllineno,'+
'ItemCode,'+
'BilllineremArk,'+
'InvBillQty,'+
'InvBillPrice,'+
'InvBillNoTaxPrice,'+
'InvBillPriceC,'+
'InvBillNoTaxPriceC,'+
'bl.InvBillAmount,'+
'bl.InvBillnotaxAmount,'+
'bl.InvBillAmountc,'+
'bl.InvBillnotaxAmountc )'+
'Values('+Billid+','+
inttostr(m+1)+','+
''''+fieldbyname('ItemCode').asstring+''','+
''''+fieldbyname('BilllineremArk').asstring+''','+
fieldbyname('InvBillQty').asstring+','+
fieldbyname('InvBillPrice').asstring+','+
fieldbyname('InvBillNoTaxPrice').asstring+','+
tmp_InvBillPriceC+','+
tmp_InvBillNoTaxPriceC+',' +
tmp_InvBillAmount+','+
tmp_InvBillnotaxAmount+','+
tmp_InvBillAmountc+','+
tmp_InvBillnotaxAmountc+')' );
AdoQry_tmp.ExecSQL;
next;
end;
end;
end;
//if KillNoInvoiceNo=Trim(Edt_InvBillNo.text) then
//抵冲历史未开票金额未开票入库单单号
try
tmpAdoQry:=TAdoQuery.Create(nil);
with tmpAdoQry do
begin
tmpAdoQry.Connection :=AdoQry_tmp.Connection ;
Close;
sql.clear;
sql.Add(' select InvInBillline.* from InvInBillline,InvInBill'
+' where InvInBillline.InvBillid=InvInBill.InvBillid '
+' and InvInBill.InvBillNo='''+KillNoInvoiceNo+'''');
open;
First ;
while not eof do
begin
if tmpAdoQry.fieldbyname('InvBillNoTaxAmount').asfloat>=SumInvBillNoTaxAmount then
begin
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add(' update InvInBillline set'
+' InvBillNoTaxAmount=InvBillNoTaxAmount-('+floattostr(sumInvBillNoTaxAmount)+')'
+' ,InvBillAmount=InvBillAmount-('+floattostr(sumInvBillAmount)+')'
+' ,InvBillAmountC=InvBillAmountC-('+floattostr(sumInvBillAmountC)+')'
+' ,InvBillNoTaxAmountC=InvBillNoTaxAmountC-('+floattostr(sumInvBillNoTaxAmountC)+')'
+' where InvBillid='+tmpAdoQry.fieldbyname('InvBillid').asstring
+' and InvBillLineNo='+tmpAdoQry.fieldbyname('InvBillLineNo').asstring
+' and ItemCode='''+tmpAdoQry.fieldbyname('ItemCode').asstring+'''');
execsql;
end;
break;
end
else
begin
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add(' update InvInBillline set'
+' InvBillNoTaxAmount=0'
+' ,InvBillAmount=0'
+' ,InvBillAmountC=0'
+' ,InvBillNoTaxAmountC=0'
+' where InvBillid='+tmpAdoQry.fieldbyname('InvBillid').asstring
+' and InvBillLineNo='+tmpAdoQry.fieldbyname('InvBillLineNo').asstring
+' and ItemCode='''+tmpAdoQry.fieldbyname('ItemCode').asstring+'''');
execsql;
SumInvBillNoTaxAmount:=SumInvBillNoTaxAmount-tmpAdoQry.fieldbyname('InvBillNoTaxAmount').asfloat;
SumInvBillAmount:=SumInvBillAmount-tmpAdoQry.fieldbyname('InvBillAmount').asfloat;
SumInvBillAmountC:=SumInvBillAmountC-tmpAdoQry.fieldbyname('InvBillAmountC').asfloat;
SumInvBillNoTaxAmountC:=SumInvBillNoTaxAmountC-tmpAdoQry.fieldbyname('InvBillNoTaxAmountC').asfloat;
end;
end;
next;
end;
end;
finally
tmpAdoQry.free;
AdoQry_Body.EnableControls ;
end;
dbconnect.CommitTrans ;
Edt_InvBillDate.Enabled:=False;
except
dbconnect.RollBackTrans;
DispInfo('保存失败',1);
abort;
end;
Billmemo:=Edt_InvBillRemArk.text;
BillwhCode:=getCode(cmbx_WhCode.text);
BillWhPositionCode:=getCode(Edt_WhPositionCode.text);
//llBillType2Code:=getCode(cmbbx_BillType2Code.text);
//lloutType:=getCode(Cmbbx_OutType.text);
//Edt_InvBillNo.text:=Billno;
BilloutCode:=LkEdt_VendorCode.text;
BilloutName:=Edt_VendorName.text;
BillLoginDate:=Edt_InvBillDate.text;
Frm_Ap_Enter_NoInvoiceInvInOrderH1.InvBillid:=Billid;
act_insertline.Enabled :=False;
act_Deleteline.Enabled :=False;
act_Save.Enabled :=False;
act_Modify.Enabled :=False;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -