📄 stclothstockrep.pas
字号:
+' WHERE ID = OBJECT_ID('+Quotedstr('tempdb..#StockListTtl')
+' )) DROP TABLE #StockListTtl ' ;
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text :=' select * into #StockListTtl from #ExpenseListTtl ';
ADOQuery.ExecSQL;
end;
procedure TSTClothStockRepForm.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;
if pos('商品名称',SelectStr1)>0 then
begin
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 *, '
+' (Isnull([入库标准数量],0)-Isnull([出库标准数量],0)) [结存数量],'
+' (Isnull([入库金额],0)-Isnull([出库金额],0)) [结存金额],'
+' [出库金额] [结存单价], '
+' [出库金额] [库存下限数量],[出库金额] [预警数量]'
+' into #ExpenseList0 from #ExpenseList ';
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text :=' Update #ExpenseList0 set [库存下限数量]=null,'
+' [预警数量]=null ,[结存单价]=null' ;
ADOQuery.ExecSQL;
//插入预警数量 ==========
ADOQuery.Close;
ADOQuery.SQL.Text :=' insert into #ExpenseList0 ( [业务类别],'
+' [商品类别], [商品名称],[标准单位],[库存下限数量] ) '
+' select '+Quotedstr('预警资料')+' [业务类别] ,'
+' h.name [商品类别], a.name [商品名称], s.name [标准单位], '
+' a.StockMin [库存下限数量] '
+' from DAGoods a '
+' left outer join DAGoodsClass h on h.ID=a.GoodsClassID '
+' left outer join MSUnit S on S.ID=a.UnitID '
+' where a.RecordState<>'+ Quotedstr('删除');
ADOQuery.ExecSQL;
//插入汇总记录 *****
ADOQuery.Close;
ADOQuery.SQL.Text:=' select ' + SelectStr1+ ExpSttcCheckListBox.hint
+' , Sum(Isnull([入库S],0)-Isnull([出库S],0)) [结存S],'
+' Sum(Isnull([入库M],0)-Isnull([出库M],0)) [结存M],'
+' Sum(Isnull([入库L],0)-Isnull([出库L],0)) [结存L],'
+' Sum(Isnull([入库XL],0)-Isnull([出库XL],0)) [结存XL],'
+' Sum(Isnull([入库XXL],0)-Isnull([出库XXL],0)) [结存XXL],'
+' Sum(Isnull([入库XXXL],0)-Isnull([出库XXXL],0)) [结存XXXL],'
+' Sum(Isnull([入库均码],0)-Isnull([出库均码],0)) [结存均码],'
+' Sum(Isnull([结存数量],0)) [结存数量],'
+' Sum(Isnull([结存单价],0)) [结存单价],'
+' Sum(Isnull([结存金额],0)) [结存金额],'
+' Sum(isnull([库存下限数量],0)) [库存下限数量] ,'
+' Sum(isnull([预警数量],0)) [预警数量]'
+' into #ExpenseListTtl from #ExpenseList0 '
+WhereStr +' group by '+SelectStr1 ;
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text:=' Update #ExpenseListTtl set [结存单价]= '
+' Isnull([结存金额],0)/[结存数量] where Isnull([结存数量],0)<>0 ' ;
ADOQuery.ExecSQL;
ADOQuery.Close;
ADOQuery.SQL.Text:=' Update #ExpenseListTtl set [预警数量]='
+' Isnull([结存数量],0)-Isnull([库存下限数量],0)' ;
ADOQuery.ExecSQL;
end else
begin
ADOQuery.Close;
ADOQuery.SQL.Text:=' select ' + SelectStr1+ ExpSttcCheckListBox.hint
+' into #ExpenseListTtl from #ExpenseList '
+WhereStr +' group by '+SelectStr1;
ADOQuery.ExecSQL;
end;
adsMaster.Close;
adsMaster.CommandText:=' select * from #ExpenseListTtl ';
adsMaster.open;
Panel6.Visible :=False;
UpdateDBGrid;
DBGrid.hint :='汇总项目:'+SelectStr1;
end;
procedure TSTClothStockRepForm.N1Click(Sender: TObject);
begin
ExpSttcCheckListBox.Sorted :=not ExpSttcCheckListBox.Sorted;
end;
procedure TSTClothStockRepForm.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 TSTClothStockRepForm.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 TSTClothStockRepForm.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 TSTClothStockRepForm.adsMasterBeforeOpen(DataSet: TDataSet);
begin
inherited;
adsMaster.IndexFieldNames := '';
end;
procedure TSTClothStockRepForm.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 TSTClothStockRepForm.ListGoodsDetailActExecute(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 TSTClothStockRepForm.GoodsFlowListActExecute(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 TSTClothStockRepForm.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 TSTClothStockRepForm.DateTimePicker1CloseUp(Sender: TObject);
begin
if DateTimePicker1.Date>DateTimePicker2.Date then
DateTimePicker2.Date :=DateTimePicker1.Date;
end;
procedure TSTClothStockRepForm.DateTimePicker2CloseUp(Sender: TObject);
begin
if DateTimePicker1.Date>DateTimePicker2.Date then
DateTimePicker1.Date :=DateTimePicker2.Date;
end;
procedure TSTClothStockRepForm.Button6Click(Sender: TObject);
begin
Panel2.Enabled :=True;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -