📄 sledsalebk.pas
字号:
begin
inherited;
if (adsMaster.fieldbyname('ID').AsInteger=0) or
(adsMaster.fieldbyname('ID').IsNull) then exit;
adoTemp := TADOQuery.Create(nil);
adoTemp.Connection := CommonData.acnConnection;
with adoTemp do
begin
//--------------判断将要插入的记录是否已经正在于SLGoodsOutMaster,不存在就插入
Close;
sql.Text :=' select b.ID from SLSaleDetail a '
+' left outer join SLSaleMaster b on a.MasterID=b.ID '
+' where isnull(a.goodsId,0)<>0 '
+' and isnull(a.GoalQuantity,0)<>0 '
+' and b.id=' + adsMaster.fieldbyname('ID').AsString
+' and b.RecordState<>' + QuotedStr('删除')
+' and b.ID not in '
+' (select top 1 OriginID from SLGoodsOutMaster where '
+' OriginTable='+ QuotedStr('SLSaleMaster')
+' and OriginID='+adsMaster.fieldbyname('ID').AsString+' )';
open;
if not adoTemp.IsEmpty then //判断完毕,开始插入
begin
code :=GetMaxCode('Code','SLGoodsOutMaster',number);
close;
sql.Text := 'insert into SLGoodsOutMaster ( CreateUserID,'
+' Date, Code, ClientID, EmployeeID, BillMode, '
+' BillModeDC, Brief, ClearDate, SundryFee, Apportion, '
+' Deliver, Memo, BillAffix ,OriginID, OriginTable ) '
+' select CreateUserID,Date, '+ QuotedStr(code)+ ' ,'
+' ClientID, EmployeeID, '+QuotedStr('销售出库') +' ,'
+' BillModeDC, '+QuotedStr('销售开单自动提交出库') +' ,'
+' ClearDate, SundryFee, Apportion, '
+' Deliver, Memo, BillAffix, ID, '+QuotedStr('SLSaleMaster')
+' from SLSaleMaster '
+' where id=' +adsMaster.fieldbyname('ID').AsString
+' and RecordState<>'+QuotedStr('删除')
+' and ID not in '
+' (select top 1 OriginID from SLGoodsOutMaster where '
+' OriginTable='+ QuotedStr('SLSaleMaster')
+' and OriginID='+adsMaster.fieldbyname('ID').AsString+' )';
ExecSQL; //插入主表记录完毕
close;
sql.Text := 'select top 1 ID from SLGoodsOutMaster where '
+' OriginTable='+ QuotedStr('SLSaleMaster')
+' and OriginID='+adsMaster.fieldbyname('ID').AsString;
open;
if adoTemp.IsEmpty then MasterID :=0
else MasterID :=adoTemp.FieldByName('ID').AsInteger;
sql.Text := 'insert into SLGoodsOutDetail ( '
+' MasterID, GoodsID, GoodsSpec, '
+' Quantity, QuantityPcs, PackUnitID, PriceBase, '
+' Amount, Discount, TaxAmount, SundryFee, '
+' GoalUnitID, GoalQuantity, Memo ) '
+' select '+ Inttostr(MasterID) + ' , a.GoodsID, a.GoodsSpec, '
+' a.Quantity, a.QuantityPcs, a.PackUnitID, a.PriceBase, '
+' a.Amount, a.Discount, a.TaxAmount, a.SundryFee, '
+' a.GoalUnitID, a.GoalQuantity, a.Memo '
+' from SLSaleDetail a '
+' left outer join SLSalemaster b on a.MasterID=b.ID'
+' where isnull(a.GoodsID,0)<>0 '
+' and isnull(a.GoalQuantity,0)<>0 '
+' and a.MasterID='+ adsMaster.fieldbyname('ID').AsString
+' and b.RecordState<>'+QuotedStr('删除');
ExecSQL;//插入子表记录
end;
//--------------
//=======判断将要插入的记录是否已经正在于FNClearSLMaster,不存在就插入
Close;
sql.Text :=' select b.ID from SLSaleDetail a '
+' Left Outer join SLSaleMaster b on a.MasterID=b.ID '
+' where ABS(isnull(a.amount,0))+ABS(isnull(a.Discount,0))'
+' +ABS(isnull(a.TaxAmount,0)) + ABS(isnull(a.SundryFee,0))<>0 '
+ ' and b.ID='+adsMaster.fieldbyname('ID').AsString
+' and b.RecordState<>' + QuotedStr('删除')+' and b.ID not in '
+' (select top 1 OriginID from FNClearSLMaster where '
+' OriginTable='+ QuotedStr('SLSaleMaster')
+' and OriginID='+adsMaster.fieldbyname('ID').AsString+' )';
open;
if not adoTemp.IsEmpty then //判断完毕,开始插入
begin
code :=GetMaxCode('Code','FNClearSLMaster',number);
close;
sql.Text := 'insert into FNClearSLMaster ( CreateUserID,'
+' Date, Code, BillMode, BillModeDC, Brief, '
+' ClientID, EmployeeID, '
+' ClearDate, AccountsID, AmountD, AmountC,'
+' Memo, BillAffix, OriginID, OriginTable ) '
+' select a.CreateUserID , '
+' a.Date, '+QuotedStr(Code)+ ' , '
+ QuotedStr('销售结算') +' , 1, '
+ QuotedStr('销售开单自动提交结算') +' ,'
+' a.ClientID, a.EmployeeID, '
+' a.ClearDate, 0,0,b.Amount*a.BillModeDC as Amount , '
+' a.Memo, a.BillAffix, a.ID,'+QuotedStr('SLSaleMaster')
+' from SLSaleMaster a left outer join '
+' (select MasterID,sum(isnull(amount,0))- '
+' -sum(isnull(Discount,0))+sum(isnull(TaxAmount,0)) '
+' +sum(isnull(SundryFee,0)) as amount '
+' from SLSaleDetail '
+' group by MasterId) as b on a.ID=b.MasterID '
+' where a.RecordState<>'+QuotedStr('删除')+ ' and '
+' a.id=' +adsMaster.fieldbyname('ID').AsString
+' and a.Id not in '
+' (select top 1 OriginID from FNClearSLMaster where '
+' OriginTable='+ QuotedStr('SLSaleMaster')
+' and OriginID='+adsMaster.fieldbyname('ID').AsString+' )';
ExecSQL; //FNClearSLMaster 插入记录完毕
close;
sql.Text := 'select top 1 ID from FNClearSLMaster where '
+' OriginTable='+ QuotedStr('SLSaleMaster')
+' and OriginID='+adsMaster.fieldbyname('ID').AsString;
open;
if adoTemp.IsEmpty then MasterID :=0
else MasterID :=adoTemp.FieldByName('ID').AsInteger;
sql.Text := 'insert into FNClearSLDetail ( MasterID, '
+' BillCode, OriginID, OriginTable ,Amount ) '
+' select '+ Inttostr(MasterID) + ' ,a.code , a.ID, '
+' a.OriginTable, b.Amount as Amount '
+' from SLSaleMaster a left outer join '
+' (select MasterID,sum(isnull(amount,0))- '
+' -sum(isnull(Discount,0))+sum(isnull(TaxAmount,0)) '
+' +sum(isnull(SundryFee,0)) as amount '
+' from SLSaleDetail '
+' group by MasterId) as b on a.ID=b.MasterID '
+' where a.RecordState<>'+QuotedStr('删除')
+' and a.ID='+ adsMaster.fieldbyname('ID').AsString;
ExecSQL;//插入子表记录
end;
//*********判断将要插入的记录是否已经正在于FNClearMaster,应收应付表中
Close;
sql.Text :=' select b.ID from SLSaleDetail a '
+' Left Outer join SLSaleMaster b on a.MasterID=b.ID '
+' where ABS(isnull(a.amount,0))+ABS(isnull(a.Discount,0))'
+' +ABS(isnull(a.TaxAmount,0)) + ABS(isnull(a.SundryFee,0))<>0 '
+ ' and b.ID='+adsMaster.fieldbyname('ID').AsString
+' and b.RecordState<>' + QuotedStr('删除')+' and b.ID not in '
+' (select top 1 OriginID from FNClearMaster where '
+' OriginTable='+ QuotedStr('SLSaleMaster')
+' and OriginID='+adsMaster.fieldbyname('ID').AsString+' )';
open;
if not adoTemp.IsEmpty then //判断完毕,开始插入
begin
code :=GetMaxCode('Code','FNClearMaster',number);
close;
sql.Text := 'insert into FNClearMaster ( CreateUserID,'
+' Date, Code, BillMode, BillModeDC, Brief, '
+' ClientID, EmployeeID, '
+' ClearDate, AccountsID, AmountD, AmountC,'
+' Memo, BillAffix, OriginID, OriginTable ) '
+' select a.CreateUserID , '
+' a.Date, '+QuotedStr(Code)+ ' , '
+ QuotedStr('销售开单') +' , BillModeDC, '
+ QuotedStr('销售记帐[贷]') +' ,'
+' a.ClientID, a.EmployeeID, '
+' a.ClearDate, 0,0,b.Amount*a.BillModeDC as Amount , '
+' a.Memo, a.BillAffix, a.ID,'+QuotedStr('SLSaleMaster')
+' from SLSaleMaster a left outer join '
+' (select MasterID,sum(isnull(amount,0))- '
+' -sum(isnull(Discount,0))+sum(isnull(TaxAmount,0)) '
+' +sum(isnull(SundryFee,0)) as amount '
+' from SLSaleDetail '
+' group by MasterId) as b on a.ID=b.MasterID '
+' where a.RecordState<>'+QuotedStr('删除')+ ' and '
+' a.id=' +adsMaster.fieldbyname('ID').AsString
+' and a.Id not in '
+' (select top 1 OriginID from FNClearMaster where '
+' OriginTable='+ QuotedStr('SLSaleMaster')
+' and OriginID='+adsMaster.fieldbyname('ID').AsString+' )';
ExecSQL; //FNClearMaster 插入记录完毕 ,不需要插入子表
end;
end;
end;
procedure TSLEdSaleBKForm.ImportActionExecute(Sender: TObject);
begin
inherited;
Application.CreateForm(TVoucherPickForm, VoucherPickForm);
VoucherPickForm.ShowModal;
VoucherPickForm.Free;
end;
procedure TSLEdSaleBKForm.DiscountModeExecute(Sender: TObject);
begin
inherited;
Application.CreateForm(TSLDiscountModeForm, SLDiscountModeForm);
SLDiscountModeForm.ShowModal;
SLDiscountModeForm.Free;
end;
procedure TSLEdSaleBKForm.ClientQLDBLookupEnter(Sender: TObject);
begin
inherited;
GEdit1.Enabled :=true;
GEdit1.Text :='0';
GEdit1.Enabled :=false;
end;
procedure TSLEdSaleBKForm.ClientQLDBLookupExit(Sender: TObject);
var adoTemp: TADOQuery;
begin
inherited;
adoTemp := TADOQuery.Create(nil);
adoTemp.Connection := CommonData.acnConnection;
with adoTemp do
begin
close;
sql.Text := 'select sum(isnull(AmountC,0))-sum(isnull(AmountD,0)) '
+' as Balance from '
+' FNClearmaster where RecordState<>' + QuotedStr('删除')
+' and ClientID='+ClientName.fieldbyname('ID').AsString;
open;
GEdit1.Enabled :=true;
if adoTemp.IsEmpty then GEdit1.Text :='0'
else GEdit1.Text :=fieldbyname('Balance').asstring;
GEdit1.Enabled :=False;
end;
end;
procedure TSLEdSaleBKForm.SLPubQuerry;
begin
{SLPubQuerryFrom:= TSLPubQuerryFrom.Create(self);
with SLPubQuerryFrom do
begin
adsPubQuerry.Close;
adsPubQuerry.CommandText :=SLPubQuerrySql;
adsPubQuerry.Open;
SLPubQuerryFrom.Caption :=SLPubQuerryCaption;
SLPubQuerryFrom.Show;
end; }
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -