?? slsaleclothstatistic.pas
字號:
procedure TSLSaleClothStatisticForm.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 TSLSaleClothStatisticForm.adsMasterBeforeOpen(DataSet: TDataSet);
begin
inherited;
adsMaster.IndexFieldNames := '';
end;
procedure TSLSaleClothStatisticForm.DateTimePicker2Exit(Sender: TObject);
begin
if DateTimePicker1.Date>DateTimePicker2.Date then
DateTimePicker1.Date :=DateTimePicker2.Date;
end;
procedure TSLSaleClothStatisticForm.DateTimePicker1Exit(Sender: TObject);
begin
if DateTimePicker1.Date>DateTimePicker2.Date then
DateTimePicker2.Date :=DateTimePicker1.Date;
end;
procedure TSLSaleClothStatisticForm.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 TSLSaleClothStatisticForm.Button6Click(Sender: TObject);
begin
Panel2.Enabled :=True;
DBGrid.Enabled :=True;
VipsetPanel.Visible :=False;
end;
procedure TSLSaleClothStatisticForm.Button5Click(Sender: TObject);
begin
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('----')+' , '+Quotedstr('期初結轉')+' , '
+' [客戶名稱], 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 :=' Insert into #ExpenseList0 '
+' ( [客戶名稱],[日期],[編號],[業務類別] )'
+' select Distinct [客戶名稱], '
+ Quotedstr(Datetostr(DateTimePicker1.Date-1))
+' as [日期],'+Quotedstr('----')+' , '+Quotedstr('期初結轉')
+' from #ExpenseList '
+' where [客戶名稱] not in ( select distinct [客戶名稱] from #ExpenseList0 '
+' where [業務類別]='+ Quotedstr('期初結轉')+' ) ' ;
ADOQuery.ExecSQL ;
ADOQuery.Close;
ADOQuery.SQL.Text :=' Insert into #ExpenseList0 '
+' ([日期],[編號],[業務類別],[客戶名稱],[銷售金額] )'
+' select '+Quotedstr(Datetostr(DateTimePicker1.Date-1))
+' as [日期],'+Quotedstr('----')+' , '+Quotedstr('期初結轉')+' , '
+' [客戶名稱],sum(0.00) [銷售金額] '
+' from #ExpenseList '
+' where [客戶名稱] not in ( select [客戶名稱] from #ExpenseList0 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 TSLSaleClothStatisticForm.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;
procedure TSLSaleClothStatisticForm.ClientAccountLiastClick(Sender: TObject);
var BalanceF:real;
I:Integer;
begin
ADOQuery.Close;
ADOQuery.SQL.Text :=' select * from #ExpenseList where [業務類別]='+Quotedstr('期初結轉');
ADOQuery.Open;
if ADOQuery.IsEmpty then
begin
ShowMessage('請在“高級..”設置對帳日期,“確定”后,再執行此功能!');
// Button4.OnClick(sneder);
Exit;
end;
I :=0;
ADOQuery.Close;
ADOQuery.SQL.Text :=' select distinct [客戶名稱] from #ExpenseList ' + WhereStr;
ADOQuery.Open;
ADOQuery.First;
while not ADOQuery.Eof do
begin
ADOQuery2.Close;
ADOQuery2.SQL.Text :=' IF EXISTS( SELECT * FROM tempdb..sysobjects '
+' WHERE ID = OBJECT_ID('+Quotedstr('tempdb..#ClientAccountList')
+' )) DROP TABLE #ClientAccountList' ;
ADOQuery2.ExecSQL;
ADOQuery2.Close;
ADOQuery2.SQL.Text :=' CREATE TABLE #ClientAccountList ( '
+' [ID] [int] IDENTITY (1, 1) NOT NULL , '
+' [日期] [datetime] NULL , '
+' [編號] [varchar] (20) NULL , '
+' [業務類別] [varchar] (16) NULL , '
+' [銷售金額] [Float] NULL , '
+' [回款金額] [Float] NULL , '
+' [余額] [Float] NULL , '
+' [備注] [varchar] (30) NULL '
+' ) ';
ADOQuery2.ExecSQL;
// ADOQuery2.Close;
// ADOQuery2.SQL.Text :=' Truncate TABLE #ClientAccountList ';
// ADOQuery2.ExecSQL;
ADOQuery2.Close;
ADOQuery2.SQL.Text :=' Insert Into #ClientAccountList ( '
+' [日期],[編號],[業務類別],[銷售金額],[回款金額] )'
+' select [日期],[編號],[業務類別],'
+' sum(isnull([銷售金額],0)) as [銷售金額] , '
+' sum(isnull([結算金額],0)) as [回款金額] '
+' from #ExpenseList '
+' where [客戶名稱]='+Quotedstr(ADOQuery.FieldByName('客戶名稱').AsString)
+' Group by [日期],[編號],[業務類別] '
+' order by [日期]';
ADOQuery2.ExecSQL;
ADOQuery2.Close;
ADOQuery2.SQL.Text :=' Insert Into #ClientAccountList ( '
+' [日期],[編號],[業務類別],[回款金額] )'
+' select [日期],[編號],[業務類別],'
+' sum(isnull([折扣返利金額],0)) as [回款金額] '
+' from #ExpenseList '
+' where [客戶名稱]='+Quotedstr(ADOQuery.FieldByName('客戶名稱').AsString)
+' and isnull([折扣返利金額],0)<>0 '
+' Group by [日期],[編號],[業務類別] '
+' order by [日期]';
ADOQuery2.ExecSQL;
ADOQuery2.Close;
ADOQuery2.SQL.Text :=' select * from #ClientAccountList order by [日期],[ID]';
ADOQuery2.open;
ADOQuery2.First;
BalanceF := 0;
BalanceF := BalanceF+ ADOQuery2.FieldByName('銷售金額').AsFloat-
ADOQuery2.FieldByName('回款金額').AsFloat;
ADOQuery2.Edit;
ADOQuery2.FieldByName('銷售金額').AsFloat :=0;
ADOQuery2.FieldByName('回款金額').AsFloat :=0;
while not ADOQuery2.Eof do
begin
BalanceF := BalanceF+ ADOQuery2.FieldByName('銷售金額').AsFloat-
ADOQuery2.FieldByName('回款金額').AsFloat;
ADOQuery2.Edit;
ADOQuery2.FieldByName('余額').AsFloat :=BalanceF;
ADOQuery2.Next;
end;
AccountListQry.Close;
AccountListQry.SQL.Text :=' select [日期],[編號],[業務類別],[銷售金額], '
+' [回款金額],[余額],[備注] '
+' from #ClientAccountList order by [ID] ';
AccountListQry.open;
// tfloatfield.ADOQuery2.
DataSource1.DataSet := AccountListQry;
DBGrid1.DataSource := DataSource1;
// DBGrid1.Visible :=True;
// ShowMessage('請查看--'+ADOQuery.FieldByName('客戶名稱').AsString+' --對帳結果!');
//在此循環打印對帳單結果,完成后可以將 DBGrid1,DataSource1刪除
with TQLDBGridReportBuilder.Create(Self) do
try
DBGrid := DBGrid1;
AutoWidth := True;
Report := TSLCheckReckoningReport.Create(Self);
TSLCheckReckoningReport(Report).qrdbtClientName.DataSet := ADOQuery;
TSLCheckReckoningReport(Report).qrlCheckCourse.Caption :=
'對帳期間: ' + DateToStr(DateTimePicker1.Date) + ' ~ ' +
DateToStr(DateTimePicker2.Date);
SummaryFields.Add('銷售金額=SUM([銷售金額])');
SummaryFields.Add('回款金額=SUM([回款金額])');
SummaryFields.Add('余額='+floattostr(BalanceF));
AutoOrientation := False;
Active := True;
// InitReport(TQuickRep(Report));
if I<1 then
Report.PreviewModal
else Report.Print;
// if Preview then Report.PreviewModal
// else begin
// if ShowSetupDialog then Report.PrinterSetup;
// Report.Print;
// end;
finally
Free;
end;
ADOQuery.Next;
I :=I+1;
// DBGrid1.Visible :=False;
end;
end;
procedure TSLSaleClothStatisticForm.ListClientSaleActExecute(Sender: TObject);
var I:Integer;
Goods :string;
begin
for I:=0 to adsMaster.FieldCount-1 do
begin
if Pos('客戶名稱',adsMaster.Fields[I].FieldName)>0 then
begin
Goods := adsMaster.FieldByName('客戶名稱').AsString;
if Trim(Goods)='' then Exit;
adsMaster.Close;
adsMaster.CommandText :='select * from #ExpenseList where [客戶名稱]='+Quotedstr(Goods);
adsMaster.Open;
UpdateDBGrid;
Exit;
end;
end;
end;
procedure TSLSaleClothStatisticForm.ListGoodsSaleActExecute(Sender: TObject);
var I:Integer;
Goods :string;
begin
for I:=0 to adsMaster.FieldCount-1 do
begin
if Pos('商品名稱',adsMaster.Fields[I].FieldName)>0 then
begin
Goods := adsMaster.FieldByName('商品名稱').AsString;
if Trim(Goods)='' then Exit;
adsMaster.Close;
adsMaster.CommandText :='select * from #ExpenseList where [商品名稱]='+Quotedstr(Goods);
adsMaster.Open;
UpdateDBGrid;
Exit;
end;
end;
end;
procedure TSLSaleClothStatisticForm.ShowExpenseCkBxClick(Sender: TObject);
begin
if not ShowExpenseCkBx.Checked then EndStockCkBx.Checked :=False;
end;
procedure TSLSaleClothStatisticForm.adsMasterAfterOpen(DataSet: TDataSet);
begin
inherited;
RefreshAvailableFields;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -