📄 sledsale.pas
字号:
SetVarValue('S4', S4);
SetVarValue('S5', S5);
SetVarValue('S6', S6);
SetVarValue('S7', S7);
SetVarValue('QuantityTotal', CurrToStrF(DBGrid.AggregateList.Aggregates.FindAggregate(atSum, 'GoalQuantity').AggregateValue, ffFixed, 2));
SetVarValue('AmountTotal', CurrToStrF(DBGrid.AggregateList.Aggregates.FindAggregate(atSum, 'Amount').AggregateValue, ffCurrency, 2));
SetVarValue('AmountTotalHZ', CurrencyUpperCaseHitch(DBGrid.AggregateList.Aggregates.FindAggregate(atSum, 'Amount').AggregateValue));
PrintPreview(True);
end;
end;
procedure TSLEdSaleForm.LookupPackUintEnter(Sender: TObject);
var GoodsIDstr :string;
begin
GoodsIDstr :=adsDetail.fieldbyname('GoodsID').asstring;
if Trim(GoodsIDstr)='' then exit;
LookupPackUint.ListSource := PackUintFltDS;
PackUintFltAQ.Close;
PackUintFltAQ.CommandText :=' select ID, Name, ExchangeRate, GoalUnitID,'
+' IsGoalUnit from MSUnit where RecordState<>'+Quotedstr('删除')
+' and GoalUnitID in (select UnitID from DaGoods where ID='
+GoodsIDstr +' ) order by GoalUnitID,ExchangeRate' ;
PackUintFltAQ.Open;
end;
procedure TSLEdSaleForm.NoCreditSaleClick(Sender: TObject);
begin
if NoCreditSale.Checked then
begin
adsMaster.Edit;
if pos(Trim(NoCreditSale.Caption),Trim(adsMaster.FieldByName('Memo').AsString))<=0 then
adsMaster.FieldByName('Memo').AsString :=
Copy( Trim(NoCreditSale.Caption)+Trim(adsMaster.FieldByName('Memo').AsString),1,60);
adsMaster.FieldByName('BillMode').AsString :='现款销售';
RemarkDBEdit.ReadOnly :=True;
end else
begin
adsMaster.Edit;
if pos(Trim(NoCreditSale.Caption),Trim(adsMaster.FieldByName('Memo').AsString))>0 then
adsMaster.FieldByName('Memo').AsString :=
StringReplace( Trim(adsMaster.FieldByName('Memo').AsString) ,
Trim(NoCreditSale.Caption),'',[rfReplaceAll, rfIgnoreCase]);
adsMaster.FieldByName('BillMode').AsString :='销售开单';
RemarkDBEdit.ReadOnly :=False;
end;
DBEdit6.ReadOnly :=not NoCreditSale.Checked;
if DBEdit6.ReadOnly then
begin
adsMaster.Edit;
adsMaster.FieldByName('CashDiscount').Value :=null;
end;
end;
procedure TSLEdSaleForm.LookupPackUintExit(Sender: TObject);
begin
LookupPackUint.ListSource :=dsPackUnit;
end;
procedure TSLEdSaleForm.adsDetailPackUnitIDChange(Sender: TField);
var ExChRate :real;
begin
PackUnit.Locate('ID', adsDetail.fieldbyname('PackUnitID').AsString, []);
if PackUnit.fieldbyname('ExchangeRate').IsNull then ExChRate :=1
else ExChRate :=PackUnit.fieldbyname('ExchangeRate').AsFloat;
adsDetail.FieldByName('PriceBase').AsFloat := PriceBeforeDiscount*ExChRate;
adsDetail.FieldByName('PriceStandard').AsFloat := PriceBeforeDiscount*ExChRate;
if adsDetail.FieldByName('GoalQuantity').AsFloat<>0 then
begin
adsDetail.FieldByName('Memo').AsString :=
Trim(Floattostr(adsDetail.FieldByName('Quantity').AsFloat))
+'['+Trim(adsDetail.FieldByName('PackUnit').AsString)+']';
end;
end;
procedure TSLEdSaleForm.DBEdit6Enter(Sender: TObject);
begin
DBEdit6.ReadOnly :=not NoCreditSale.Checked;
if DBEdit6.ReadOnly then
begin
adsMaster.Edit;
adsMaster.FieldByName('CashDiscount').Value :=null;
end;
end;
procedure TSLEdSaleForm.InternalSave;
var adoTemp: TADOQuery;
code,AccountIDStr,MasterIDStr,IDStr:string;
MasterID:Integer;
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, '
+' 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, '+ QuotedStr('销售单号:')
+' +code, 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, '
+' GoalUnitID, GoalQuantity, Memo ) '
+' select '+ Inttostr(MasterID) + ' , a.GoodsID, a.GoodsSpec, '
+' a.Quantity, a.QuantityPcs, a.PackUnitID, '
+' 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.PriceGoal=#TpCostPrice.Costprice '
+' from SLGoodsOutDetail left outer join #TpCostPrice '
+' on #TpCostPrice.goodsid=SLGoodsOutDetail.goodsid '
+' where MasterID='+ Inttostr(MasterID);
Execsql;
close;
Sql.Text :=' update SLGoodsOutDetail set Amount=GoalQuantity*PriceGoal '
+' where MasterID= '+ Inttostr(MasterID);
ExecSQL;
close;
Sql.Text :=' update SLGoodsOutDetail set PriceBase=Amount/Quantity'
+' where GoalQuantity<>0 and MasterID= '+ Inttostr(MasterID);
ExecSQL;
//计算销售产品的临时成本单价完毕
end;
end;
//判断是否要插入销售结算表
if ( adsMaster.FieldByName('BillMode').AsString ='现款销售' ) then
begin
adoTemp.Close;
adoTemp.SQL.Text :='select OriginID from FNClearSLMaster'
+' where OriginTable='+Quotedstr('SLSaleMaster')
+' and RecordState<>'+Quotedstr('删除')+' and OriginID='
+ adsMaster.fieldbyname('ID').AsString ;
adoTemp.Open;
if adoTemp.IsEmpty then
begin
adoTemp.Close;
adoTemp.SQL.Text :=' select * from FNAccounts '
+' where AccountType like '+Quotedstr('%现金%')
+' and RecordState<>'+Quotedstr('删除') ;
adoTemp.open;
AccountIDStr :=adoTemp.fieldbyname('ID').AsString;
if Trim(AccountIDStr)='' then AccountIDStr :='1';
IDStr :=adsMaster.fieldbyname('ID').AsString;
if Trim(IDStr)='' then IDStr :='0';
adoTemp.Close;
adoTemp.SQL.Text :=' Insert into FNClearSLMaster ('
+' CreateUserID,Date,Code,BillMode,ModeDC,ModeC,'
+' Brief, ClientID, EmployeeID,AccountsID, AmountD, '
+' AmountC,AmountRed,Memo, OriginID, OriginTable) '
+' select CreateUserID, Date, '
+Quotedstr(GetMaxCode('Code','FNClearSLMaster',number))+' , '
+Quotedstr('现销结算')+' BillMode, ModeDC, ModeC, '
+Quotedstr('现款销售')+' as Brief, '
+' ClientID, EmployeeID, '+ AccountIDStr+' as AccountID , '
+' (isnull(b.Amount,0)+isnull(a.SundryFee,0)-isnull(CashDiscount,0) )'
+' as AmountD, '
+' 0.00,CashDiscount, '
+Quotedstr('现款销售')+' as Memo, a.ID, '
+Quotedstr('SLSaleMaster')
+' from SLSaleMaster a '
+' left outer join '
+' ( select MasterID,Sum(Isnull(Amount,0)) as Amount '
+' from SLSaleDetail '
+' Group by MasterID ) b on B.MasterID=a.ID '
+' where a.ID='+IDStr ;
adoTemp.ExecSQL;
AccountIDStr := adsMaster.fieldbyname('ID').AsString;
if Trim(AccountIDStr)='' then AccountIDStr :='0';
adoTemp.Close;
adoTemp.SQL.Text :='select ID from FNClearSLMaster '
+' where OriginID='+AccountIDStr+' and OriginTable='
+Quotedstr('SLSaleMaster') ;
adoTemp.Open; //选定新插入记录(FNClearSLMaster表)的ID号
MasterIDStr :=adoTemp.fieldbyname('ID').AsString;
if Trim(MasterIDStr)='' then MasterIDStr :='0';
adoTemp.Close;
adoTemp.SQL.Text :=' Insert into FNClearSLDetail ('
+' MasterID,OriginID,Amount)'
+' select '+MasterIDStr +'as MasterID,'
+' a.ID as OriginID, '
+' (isnull(b.Amount,0)+isnull(a.SundryFee,0) ) as Amount '
+' from SLSaleMaster a '
+' left outer join '
+' ( select MasterID,Sum(Isnull(Amount,0)) as Amount '
+' from SLSaleDetail '
+' Group by MasterID ) b on B.MasterID=a.ID '
+' where a.ID='+IDStr ;
adoTemp.ExecSQL;
end;
end;
end;
procedure TSLEdSaleForm.DiscountTempActClick(Sender: TObject);
var RateStr:string;
RateStrF :Double;
begin
inherited;
if InputQuery('临时折扣率', '请输入折扣率:', RateStr) then
while not TryStrToFloat(RateStr,RateStrF) do
if not InputQuery('临时折扣率', '请输入折扣率:', RateStr) then exit;
if RateStrF =0 then exit;
adsDetail.First;
while not adsDetail.Eof do
begin
adsDetail.Edit;
adsDetail.FieldByName('PriceBase').AsFloat :=
adsDetail.FieldByName('PriceBase').AsFloat*RateStrF/100;
adsDetail.FieldByName('PriceRate').AsFloat :=
adsDetail.FieldByName('PriceRate').AsFloat*RateStrF/100;
adsDetail.Next;
end;
end;
procedure TSLEdSaleForm.RepeatPrintActionExecute(Sender: TObject);
var RateStr:string;
RateStrF :Double;
begin
inherited;
if InputQuery('重打调整参数', '重打调整参数:', RateStr) then
while not TryStrToFloat(RateStr,RateStrF) do
if not InputQuery('重打调整参数', '重打调整参数:', RateStr) then exit;
if RateStrF =0 then exit;
{adsDetail.First;
while not adsDetail.Eof do
begin
adsDetail.Edit;
adsDetail.FieldByName('PriceBase').AsFloat :=
adsDetail.FieldByName('PriceBase').AsFloat*RateStrF/100;
adsDetail.FieldByName('PriceRate').AsFloat :=
adsDetail.FieldByName('PriceRate').AsFloat*RateStrF/100;
adsDetail.Next;
end;}
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -