📄 sledsalegoalunittopack.pas
字号:
code :=GetMaxCode('Code','SLGoodsOutMaster',number);
close;
sql.Text := 'insert into SLGoodsOutMaster ( CreateUserID,'
+' Date, Code, ClientID, EmployeeID, BillMode, '
+' ModeDC,ModeC, Brief, ClearDate, SundryFee, Apportion, '
+' Deliver, Memo, BillAffix ,OriginID, OriginTable ) '
+' select CreateUserID,Date, '+ QuotedStr(code)+ ' ,'
+' ClientID, EmployeeID,BillMode ,'
+' ModeDC,ModeC, '+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, 0.00, '
+' 0.00, 0.00, 0.00, 0.00, '
+' 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;//插入出库子表记录完毕
close;
Sql.Text :=' update SLGoodsOutDetail set '
+' SLGoodsOutDetail.PriceBase=#TpCostPrice.Costprice '
+' from SLGoodsOutDetail left outer join #TpCostPrice '
+' on #TpCostPrice.goodsid=SLGoodsOutDetail.goodsid '
+' where MasterID='+ Inttostr(MasterID);
Execsql;
close;
Sql.Text :=' update SLGoodsOutDetail set '
+' SLGoodsOutDetail.PriceBase=SLGoodsOutDetail.PriceBase* '
+' MsUnit.ExchangeRate '
+' from SLGoodsOutDetail left outer join MsUnit '
+' on MsUnit.ID=SLGoodsOutDetail.PackunitID'
+' where MasterID='+ Inttostr(MasterID);
Execsql;
close;
Sql.Text :=' update SLGoodsOutDetail set Amount=Quantity*PriceBase '
+' where MasterID= '+ Inttostr(MasterID);
ExecSQL;
//计算销售产品的临时成本单价完毕
end;
//--------------判断将要插入的记录是否已经正在于SLGoodsOutMaster,不存在就插入
{
//=======判断将要插入的记录是否已经正在于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);
if adsMaster.FieldByName('ModeC').AsInteger=-1 then BillMode :='销售结算[红字]'
else BillMode :='销售结算' ;
close;
sql.Text := 'insert into FNClearSLMaster ( CreateUserID,'
+' Date, Code, BillMode, ModeDC,ModeC, Brief, '
+' ClientID, EmployeeID, '
+' ClearDate, AccountsID, AmountD, AmountC,'
+' Memo, BillAffix, OriginID, OriginTable ) '
+' select a.CreateUserID , '
+' a.Date, '+QuotedStr(Code)+ ' , '
+ QuotedStr(BillMode) +' , a.ModeDC,a.ModeC, '
+ QuotedStr('销售开单自动提交结算') +' ,'
+' a.ClientID, a.EmployeeID, '
+' a.ClearDate, 0,0, 0, '
+' 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, '
+' OriginID, OriginTable ,Amount ) '
+' select '+ Inttostr(MasterID) + ' , 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;
//=======判断将要插入的记录是否已经正在于FNClearSLMaster,不存在就插入
}
end;
end;
procedure TSLEdSaleGoalUnitToPackForm.ClientQLDBLookupEnter(Sender: TObject);
begin
inherited;
GEdit1.Enabled :=true;
GEdit1.Text :='0';
GEdit1.Enabled :=false;
end;
procedure TSLEdSaleGoalUnitToPackForm.ClientQLDBLookupExit(Sender: TObject);
var adoTemp: TADOQuery;
FstDate:Tdatetime;
begin
inherited;
if (adsMaster.fieldbyname('ClientID').IsNull) or
(adsMaster.fieldbyname('ClientID').AsInteger=0) then exit;
adoTemp := TADOQuery.Create(nil);
adoTemp.Connection := CommonData.acnConnection;
with adoTemp do
begin
close;
sql.Text :=' select sum(isnull(AmountD,0)) as Balance from '
+' ( select (isnull(a.amount,0)-isnull(a.Discount,0)+isnull(a.TaxAmount,0) '
+' +isnull(a.SundryFee,0) )*Isnull(ModeDC,1)*Isnull(ModeC,1) as amountD '
+' from SLSaleDetail a '
+' left outer join SLSaleMaster b on b.ID=a.MasterID '
+' where b.RecordState<>'+Quotedstr('删除')+' and b.ClientID='
+ adsMaster.fieldbyname('ClientID').AsString
+' UNION ALL '
+' select (isnull(a.amount,0)-isnull(a.Discount,0)+isnull(a.TaxAmount,0) '
+' +isnull(a.SundryFee,0) )*Isnull(ModeDC,1)*Isnull(ModeC,1)*(-1) as amountD '
+' from PCPurchaseDetail a '
+' left outer join PCPurchaseMaster b on b.ID=a.MasterID '
+' where b.RecordState<>'+Quotedstr('删除')+' and b.ClientID='
+ adsMaster.fieldbyname('ClientID').AsString
+' UNION ALL '
+' select (Isnull(AmountD,0)+Isnull(AmountRed,0) )*Isnull(ModeDC,1)*Isnull(ModeC,1)*(-1) '
+' as AmountD '
+' from FNClearSLMaster '
+' where RecordState<>'+Quotedstr('删除')+' and ClientID='
+ adsMaster.fieldbyname('ClientID').AsString
+' UNION ALL '
+' select (Isnull(AmountC,0)+Isnull(AmountRed,0) )*Isnull(ModeDC,1)*Isnull(ModeC,1) '
+' as AmountD '
+' from FNClearPCMaster '
+' where RecordState<>'+Quotedstr('删除')+' and ClientID='
+ adsMaster.fieldbyname('ClientID').AsString +' ) as a ';
open;
GEdit1.Enabled :=true;
if adoTemp.IsEmpty then GEdit1.Text :='0'
else GEdit1.Text :=fieldbyname('Balance').asstring;
GEdit1.Enabled :=False;
close;
sql.Text :=' select QuotaAmountMin from SLCredit where '
+' RecordState<>'+ Quotedstr('删除')
+' and ClientID='+ adsMaster.fieldbyname('ClientID').AsString ;
open;
if (NewOrEditFlag='新增状态') and not (fieldbyname('QuotaAmountMin').IsNull) then
begin
adsMaster.Edit;
adsMaster.fieldbyname('ClearDate').AsDateTime :=
adsMaster.fieldbyname('Date').AsDateTime+ fieldbyname('QuotaAmountMin').AsInteger
end;
end;
end;
procedure TSLEdSaleGoalUnitToPackForm.FormActivate(Sender: TObject);
var adoTemp: TADOQuery;
begin
inherited;
adoTemp := TADOQuery.Create(nil);
adoTemp.Connection := CommonData.acnConnection;
adoTemp.Close;
adoTemp.SQL.Text :=' IF EXISTS( SELECT * FROM tempdb..sysobjects '
+' WHERE ID = OBJECT_ID('+Quotedstr('tempdb..#TpCostPrice')
+' )) DROP TABLE #TpCostPrice ' ;
adoTemp.ExecSQL;
adoTemp.Close;
adoTemp.SQL.Text :=' create table #TpCostPrice ('
+' ID [int] IDENTITY (1, 1) NOT NULL ,'
+' GoodsID [int] NULL , '
+' GoalQuantity [float] NULL , '
+' CostPrice [float] NULL , '
+' Amount [float] NULL) ' ;
adoTemp.ExecSQL;
with adoTemp do
begin
close; //计算销售产品的临时成本单价
Sql.Text :=' truncate Table #TpCostPrice' ;
ExecSQL;
close;
Sql.Text :=' insert into #TpCostPrice ('
+' GoodsID, GoalQuantity,Amount )'
+' select goodsid,sum(isnull(Quantity,0)),sum(isnull(Amount,0)) '
+' from ( '
+' select GoodsID,Quantity*Isnull(ModeDC,1)*Isnull(ModeC,1) as Quantity,Amount*Isnull(ModeDC,1)*Isnull(ModeC,1) '
+' as Amount,recordstate from PCgoodsIndetail a '
+' left outer join PCgoodsInMaster b on b.id=a.MasterID WHERE Amount<>0'
+' UNION ALL '
+' select GoodsID,Quantity*Isnull(ModeDC,1)*Isnull(ModeC,1) as Quantity,Amount*Isnull(ModeDC,1)*Isnull(ModeC,1)'
+' as Amount,recordstate from YDgoodsIndetail a '
+' left outer join YDgoodsInMaster b on b.id=a.MasterID Where Amount<>0'
+' UNION ALL '
+' select GoodsID,Quantity*Isnull(ModeDC,1)*Isnull(ModeC,1) as Quantity,Amount*Isnull(ModeDC,1)*Isnull(ModeC,1) '
+' as Amount,recordstate from YDgoodsIndetail a '
+' left outer join STgoodsCountOffMaster b on b.id=a.MasterID Where Amount<>0'
+' and BillMode like '+Quotedstr('%库存盘盈%' )+ ' ) as a '
+' where RecordState<>'+QuotedStr('删除')
+' group by GoodsID ' ;
ExecSQL;
close;
Sql.Text :=' Update #TpCostPrice set CostPrice=abs(Amount/ '
+' GoalQuantity) where GoalQuantity<>0';
ExecSQL;
close;
Sql.Text :=' insert into #TpCostPrice (GoodsID, CostPrice )'
+' select ID,abs(PricePurchase) from DAgoods where ID not in '
+' (select distinct GoodsID from #TpCostPrice)' ;
ExecSQL;
end;
ClientQLDBLookup.SetFocus;
end;
procedure TSLEdSaleGoalUnitToPackForm.FormDeactivate(Sender: TObject);
var adoTemp: TADOQuery;
begin
inherited;
adoTemp := TADOQuery.Create(nil);
adoTemp.Connection := CommonData.acnConnection;
adoTemp.Close;
adoTemp.SQL.Text :=' IF EXISTS( SELECT * FROM tempdb..sysobjects '
+' WHERE ID = OBJECT_ID('+Quotedstr('tempdb..#TpCostPrice')
+' )) DROP TABLE #TpCostPrice ' ;
adoTemp.ExecSQL;
end;
function TSLEdSaleGoalUnitToPackForm.CreateReport: TQuickRep;
begin
Result := TSLSaleVoucherReport.Create(Self);
TBaseVoucherReport(Result).SetMasterDataSet(MasterDataSet);
end;
procedure TSLEdSaleGoalUnitToPackForm.adsDetailGoalQuantityChange(
Sender: TField);
var ExChRate :real;
begin
inherited;
if PackUnit.fieldbyname('ExchangeRate').IsNull then ExChRate :=1
else ExChRate :=PackUnit.fieldbyname('ExchangeRate').AsFloat;
adsDetail.FieldByName('Quantity').ReadOnly :=False;
adsDetail.FieldByName('Quantity').AsFloat :=
adsDetail.fieldbyname('GoalQuantity').AsFloat/ExChRate;
adsDetail.FieldByName('Quantity').ReadOnly :=True;
adsDetail.FieldByName('Amount').ReadOnly :=False;
adsDetail.FieldByName('Amount').AsFloat :=
adsDetail.fieldbyname('GoalQuantity').asfloat
*adsDetail.fieldbyname('PriceBase').AsFloat;
adsDetail.FieldByName('Amount').ReadOnly :=True;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -