📄 ststockstatistic.pas
字号:
ADOQuery.SQL.Text :=' insert into #ExpenseList ( [日期], '
+' [编号], [业务类别],[摘要],[客户名称],[经手人], '
+' [备注],[结算金额],[折扣返利金额] ) '
+' select a.Date [日期],a.Code [编号], '
+' a.BillMode [业务类别],a.Brief [摘要], '
+' b.name [客户名称],c.name [经手人] , '
+' a.memo [备注],a.AmountD [结算金额], '
+' a.AmountRed [折扣返利金额] from FNClearSLMaster a '
+' left outer join DAClient b on b.ID=a.ClientID '
+' left outer join MSEmployee c on c.ID=a.EmployeeID '
+' where a.RecordState<>'+ Quotedstr('删除')
+' and a.ClientID is not null and a.ClientID<>0 ' ; //插入结算记录
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text :=' if exists (select * from dbo.sysobjects where '
+' id = object_id '
+' (' +Quotedstr('[dbo].[TempExpenseList]')+') and OBJECTPROPERTY(id,'
+Quotedstr('IsUserTable')+' ) = 1) drop table [dbo].[TempExpenseList] ';
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text :=' select top 1 * into TempExpenseList from #ExpenseList' ;
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text :=' select top 1 * from TempExpenseList' ;
ADOQuery.open;
ExpSttcCheckListBox.Columns :=4;
ExpSttcCheckListBox.Items.Clear;
ExpSttcCheckListBox.Hint :='';
WNADOCQuery1.Field.Clear;
for I := 0 to ADOQuery.Fields.Count - 1 do
begin
if not (ADOQuery.Fields[i] is TNumericField) then
ExpSttcCheckListBox.Items.Add(Trim(ADOQuery.Fields[i].FieldName))
else
ExpSttcCheckListBox.Hint :=ExpSttcCheckListBox.Hint
+', sum(isnull('+Trim(ADOQuery.Fields[i].FieldName)+',0)) as ['
+Trim(ADOQuery.Fields[i].FieldName)+'] ';
WNADOCQuery1.Field.Add(Trim(ADOQuery.Fields[i].FieldName));
end;
WhereStr :=' where 1=1 ';
Memo1.Text :='不限制条件!';
SelectStr :='';
end;
procedure TSTStockStatisticForm.Button1Click(Sender: TObject);
begin
Panel6.Visible :=True;
Panel6.Repaint;
Button1.Tag:=1 ;
adsMaster.Close;
adsMaster.CommandText:=' select * from #ExpenseList'+WhereStr
+' order by [日期], [编号]' ;
// showmessage(adsMaster.CommandText);
adsMaster.open;
Panel6.Visible :=False;
UpdateDBGrid;
DBGrid.hint :='';
end;
procedure TSTStockStatisticForm.FormActivate(Sender: TObject);
begin
inherited;
ADOQuery.Close;
ADOQuery.SQL.Text :='select max(日期) MDate from #ExpenseList ';
ADOQuery.Open;
if ADOQuery.FieldByName('MDate').IsNull then WhereStr :=Datetostr(date)
else WhereStr :=Trim(ADOQuery.fieldbyname('MDate').AsString);
Memo1.ReadOnly :=False;
Memo1.Clear;
Memo1.Text :=' 日期 等于'+ Quotedstr(WhereStr);
Memo1.ReadOnly :=True;
WhereStr :=' where [日期]='+Quotedstr(WhereStr);
Button1Click(sender);
end;
procedure TSTStockStatisticForm.Button2Click(Sender: TObject);
var I :integer;
SelectStr1:String;
begin
inherited;
Panel6.Visible :=True;
Panel6.Repaint;
Button1.Tag:=0;
if Trim(SelectStr) ='' then
begin
ExpSttcCheckListBox.Checked[1] :=true;
ExpSttcCheckListBox.ItemIndex := 1;
ExpSttcCheckListBox.OnClickCheck(ExpSttcCheckListBox);
end;
SelectStr1 :=Trim(SelectStr);
while Pos(',', SelectStr1)=1 do SelectStr1[Pos(',', SelectStr1)] :=' ';
ADOQuery.Close;
ADOQuery.SQL.Text :=' IF EXISTS( SELECT * FROM tempdb..sysobjects '
+' WHERE ID = OBJECT_ID('+Quotedstr('tempdb..#ExpenseListTtl')
+' )) DROP TABLE #ExpenseListTtl ' ;
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text:=' select ' + SelectStr1+ ExpSttcCheckListBox.hint
+' into #ExpenseListTtl from #ExpenseList '
+WhereStr +' group by '+SelectStr1;
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text:=' update #ExpenseListTtl set [标准单价]= '
+' [销售金额]/[标准数量] where [标准数量]<>0 ';
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text:=' update #ExpenseListTtl set [销售单价]= '
+' [销售金额]/[包装数量] where [包装数量]<>0 ';
ADOQuery.ExecSQL;
adsMaster.Close;
adsMaster.CommandText:=' select *,([销售金额]+[附加费用]-[结算金额]- '
+' [折扣返利金额]) as [应收帐款余额] from #ExpenseListTtl ';
adsMaster.open;
Panel6.Visible :=False;
UpdateDBGrid;
DBGrid.hint :='汇总项目:'+SelectStr1;
end;
procedure TSTStockStatisticForm.N1Click(Sender: TObject);
begin
ExpSttcCheckListBox.Sorted :=not ExpSttcCheckListBox.Sorted;
end;
procedure TSTStockStatisticForm.N2Click(Sender: TObject);
var I:integer;
begin
for I := 0 to ExpSttcCheckListBox.Items.Count - 1 do
begin
ExpSttcCheckListBox.Checked[I] :=not ExpSttcCheckListBox.Checked[I];
ExpSttcCheckListBox.ItemIndex := I;
ExpSttcCheckListBox.OnClickCheck(ExpSttcCheckListBox);
end;
end;
procedure TSTStockStatisticForm.N3Click(Sender: TObject);
var I:integer;
begin
for I := 0 to ExpSttcCheckListBox.Items.Count - 1 do
begin
ExpSttcCheckListBox.Checked[I] :=True;
ExpSttcCheckListBox.ItemIndex := I;
ExpSttcCheckListBox.OnClickCheck(ExpSttcCheckListBox);
end;
end;
procedure TSTStockStatisticForm.N4Click(Sender: TObject);
var I:integer;
begin
for I := 0 to ExpSttcCheckListBox.Items.Count - 1 do
begin
ExpSttcCheckListBox.Checked[I] :=False;
ExpSttcCheckListBox.ItemIndex := I;
ExpSttcCheckListBox.OnClickCheck(ExpSttcCheckListBox);
end;
end;
procedure TSTStockStatisticForm.adsMasterBeforeOpen(DataSet: TDataSet);
begin
inherited;
adsMaster.IndexFieldNames := '';
end;
procedure TSTStockStatisticForm.DateTimePicker2Exit(Sender: TObject);
begin
inherited;
if DateTimePicker1.Date>DateTimePicker2.Date then
DateTimePicker1.Date :=DateTimePicker2.Date;
end;
procedure TSTStockStatisticForm.DateTimePicker1Exit(Sender: TObject);
begin
inherited;
if DateTimePicker1.Date>DateTimePicker2.Date then
DateTimePicker2.Date :=DateTimePicker1.Date;
end;
procedure TSTStockStatisticForm.Button4Click(Sender: TObject);
var year,month,day:word;
begin
inherited;
Panel2.Enabled :=False;
DBGrid.Enabled :=False;
VipsetPanel.Visible :=True;
VipsetPanel.Repaint;
// DateTimePicker1.Date :=date;
// DateTimePicker2.Date :=EndoftheMonth(date);
DecodeDate(date,year,month,day) ;
DateTimePicker1.Date :=Encodedate(year,month,1);
DateTimePicker2.Date :=date;
end;
procedure TSTStockStatisticForm.Button6Click(Sender: TObject);
begin
inherited;
Panel2.Enabled :=True;
DBGrid.Enabled :=True;
VipsetPanel.Visible :=False;
end;
procedure TSTStockStatisticForm.Button5Click(Sender: TObject);
begin
inherited;
Panel2.Enabled :=True;
DBGrid.Enabled :=True;
VipsetPanel.Visible :=False;
ADOQuery.Close;
ADOQuery.SQL.Text :=' IF EXISTS( SELECT * FROM tempdb..sysobjects '
+' WHERE ID = OBJECT_ID('+Quotedstr('tempdb..#ExpenseList0')
+' )) DROP TABLE #ExpenseList0' ;
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text :=' select * into #ExpenseList0 from #ExpenseList'
+' where [日期] >='+Quotedstr(Datetostr(DateTimePicker1.Date))
+' and [日期] <='+Quotedstr(Datetostr(DateTimePicker2.Date));
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text :=' Insert into #ExpenseList0 '
+' ([日期],[业务类别],[客户名称],[销售金额],[结算金额],[折扣返利金额] )'
+' select '+Quotedstr(Datetostr(DateTimePicker1.Date-1))
+' as [日期],'+Quotedstr('期初结转')+' as [业务类别],'
+' [客户名称],sum(isnull([销售金额],0)), '
+' sum(isnull([结算金额],0)) ,sum(isnull([折扣返利金额],0)) '
+' from #ExpenseList '
+' where [日期] <'+Quotedstr(Datetostr(DateTimePicker1.Date))
+' Group by [日期],[业务类别],[客户名称]';
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text :=' IF EXISTS( SELECT * FROM tempdb..sysobjects '
+' WHERE ID = OBJECT_ID('+Quotedstr('tempdb..#ExpenseList')
+' )) DROP TABLE #ExpenseList' ;
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text :=' select * into #ExpenseList from #ExpenseList0'
+' where [日期] is not null '
+' order by [日期] ' ;
ADOQuery.ExecSQL;
if Button1.Tag=1 then Button1Click(sender)
else Button2Click(sender);
end;
procedure TSTStockStatisticForm.ExpSttcCheckListBoxClickCheck(
Sender: TObject);
var CheckStr :string;
begin
CheckStr :=','+Trim(ExpSttcCheckListBox.Items[ExpSttcCheckListBox.ItemIndex]);
if (ExpSttcCheckListBox.Checked[ExpSttcCheckListBox.ItemIndex]) and
(pos(CheckStr,SelectStr)<=0) then SelectStr :=Trim(SelectStr)+Trim(CheckStr);
if (not ExpSttcCheckListBox.Checked[ExpSttcCheckListBox.ItemIndex]) and
(pos(CheckStr,SelectStr)>0) then
SelectStr :=StringReplace(SelectStr,CheckStr,'',[rfReplaceAll, rfIgnoreCase]);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -