⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slsaleclothstatistic.pas

📁 详细的ERP设计资料
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    ADOQuery.Close;
    ADOQuery.SQL.Text :=' delete from #ExpenseList '
        +' where [经手人] not in ( select b.name  '
        +' from MSRolePermissions a '
        +' left outer join MSPermission b on b.ID=a.PermissionID '
        +' where b.PermissionClass='+Quotedstr('Y-查看业务')
        +' and a.RoleID= '+ inttostr(Guarder.UserID)+' ) ';
    ADOQuery.ExecSQL;
  end;

  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 TSLSaleClothStatisticForm.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 TSLSaleClothStatisticForm.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 TSLSaleClothStatisticForm.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) or (pos('经手人',SelectStr1)>0) or (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;
    if ShowExpenseCkBx.Checked then
        ADOQuery.SQL.Text :=' select *,  '
        +' [结算金额] [销售毛利] ,'
        +' [商品名称] [费用名称] ,'
        +' [结算金额] [费用金额], '
        +' [结算金额] [客户信用金额], '
        +' [结算金额] [信用预警金额] '
        +' into #ExpenseList0  from #ExpenseList  '
      else
        ADOQuery.SQL.Text :=' select *,  '
        +' [结算金额] [销售毛利] ,'
        +' [结算金额] [客户信用金额], '
        +' [结算金额] [信用预警金额] '
        +' into #ExpenseList0  from #ExpenseList ' ;
    ADOQuery.ExecSQL;

    ADOQuery.Close;
    if ShowExpenseCkBx.Checked then
      ADOQuery.SQL.Text :=' Update #ExpenseList0 set [客户信用金额]=0,'
      +' [信用预警金额]=0 ,[费用名称]=null ,[费用金额]=0 ,'
      +' [销售毛利]=Isnull([成本单价],0)*Isnull([标准数量],0) '      
    else
      ADOQuery.SQL.Text :=' Update #ExpenseList0 set [客户信用金额]=0,'
      +' [信用预警金额]=0 ,[销售毛利]=Isnull([成本单价],0)*Isnull([标准数量],0) ';
    ADOQuery.ExecSQL;

    //插入预警数量 ==========
    ADOQuery.Close;
    ADOQuery.SQL.Text :=' insert into  #ExpenseList0 ( '
      +' [客户名称],[客户信用金额] ) '
      +' select b.name [客户名称], a.QuotaAmount [客户信用金额] '
      +' from PCCredit a                  '
      +' left outer join DAClient b on b.ID=a.ClientID '
      +' where a.RecordState<>'+ Quotedstr('删除')
      +' and Isnull(a.QuotaAmount,0)<>0 ';
    ADOQuery.ExecSQL;

    if ShowExpenseCkBx.Checked then
    begin
      ADOQuery.Close;

      if EndStockCkBx.Checked then
        ADOQuery.SQL.Text :=' insert into  #ExpenseList0 ( '
          +' [日期],[编号],[业务类别],[客户名称],[经手人], '
          +' [部门名称], [费用名称],[费用金额] ) '
          +' select b.date [日期],b.Code [编号],b.BillMode [业务类别],'
          +' c.name [客户名称],d.name [经手人], e.name  [部门名称] ,'
          +' f.name [费用名称],Isnull(Amount,0)  [费用金额]  '
          +' from FNExpenseDetail  a                  '
          +' left outer join FNExpenseMaster b on b.ID=a.MasterID '
          +' left outer join DAClient        c on c.ID=a.ClientID '
          +' left outer join MSEmployee      d on d.ID=b.EmployeeID  '
          +' left outer join MSDepartment    e on e.ID=d.DepartmentID  '
          +' left outer join DAExpenseClass    f on f.ID=a.ExpenseID  '
          +' where b.RecordState<>'+ Quotedstr('删除')
          +' and Isnull(a.Amount,0)<>0  and Isnull(a.ClientID,0)<>0  '
      else
        ADOQuery.SQL.Text :=' insert into  #ExpenseList0 ( '
          +' [日期],[编号],[业务类别],[客户名称],[经手人], '
          +' [部门名称], [费用名称],[费用金额] ) '
          +' select b.date [日期],b.Code [编号],b.BillMode [业务类别],'
          +' c.name [客户名称],d.name [经手人], e.name  [部门名称] ,'
          +' f.name [费用名称],Isnull(Amount,0)  [费用金额]  '
          +' from FNExpenseDetail  a                  '
          +' left outer join FNExpenseMaster b on b.ID=a.MasterID '
          +' left outer join DAClient        c on c.ID=a.ClientID '
          +' left outer join MSEmployee      d on d.ID=b.EmployeeID  '
          +' left outer join MSDepartment    e on e.ID=d.DepartmentID  '
          +' left outer join DAExpenseClass    f on f.ID=a.ExpenseID  '
          +' where b.RecordState<>'+ Quotedstr('删除')
          +' and Isnull(a.Amount,0)<>0 ';
      ADOQuery.ExecSQL;
    end;

    ADOQuery.Close;
    if ShowExpenseCkBx.Checked then
      begin
        if EndStockCkBx.Checked  then
          ADOQuery.SQL.Text:=' select ' + SelectStr1+ ExpSttcCheckListBox.hint
          +' , Sum(Isnull([销售毛利],0)) [销售毛利]  '
          +' , Sum(Isnull([费用金额],0)) [客户成本]  '
          +' , Sum(Isnull([客户信用金额],0)) [应收帐款余额]  '
          +' , Sum(Isnull([客户信用金额],0)) [客户信用金额]  '
          +' , Sum(Isnull([客户信用金额],0)) [信用预警金额]  '
          +' into #ExpenseListTtl from #ExpenseList0  '
          +WhereStr +' group by '+SelectStr1
        else
          ADOQuery.SQL.Text:=' select ' + SelectStr1+ ExpSttcCheckListBox.hint
  //        +' , [费用名称]  '
          +' , Sum(Isnull([销售毛利],0)) [销售毛利]  '
          +' , Sum(Isnull([费用金额],0)) [费用金额]  '
          +' , Sum(Isnull([客户信用金额],0)) [应收帐款余额]  '
          +' , Sum(Isnull([客户信用金额],0)) [客户信用金额]  '
          +' , Sum(Isnull([客户信用金额],0)) [信用预警金额]  '
          +' into #ExpenseListTtl from #ExpenseList0  '
  //        +WhereStr +' group by '+SelectStr1+',[费用名称] '
          +WhereStr +' group by '+SelectStr1 ;
      end
    else
        ADOQuery.SQL.Text:=' select ' + SelectStr1+ ExpSttcCheckListBox.hint
        +' , 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 [标准单价]=null, '
       +'  [成本单价]=null ';
    ADOQuery.ExecSQL;


    ADOQuery.Close;
    ADOQuery.SQL.Text:=' update #ExpenseListTtl set [标准单价]= '
       +' [销售金额]/[标准数量] where Isnull([标准数量],0)<>0 ';
    ADOQuery.ExecSQL;

    ADOQuery.Close;
    ADOQuery.SQL.Text:=' update #ExpenseListTtl set [成本单价]= '
       +' [销售毛利]/[标准数量] where Isnull([标准数量],0) <>0 ';
    ADOQuery.ExecSQL;

    ADOQuery.Close;
    ADOQuery.SQL.Text:=' update #ExpenseListTtl set [销售毛利]= '
       +' [销售金额]-[销售毛利]';
    ADOQuery.ExecSQL;

//    ADOQuery.Close;
//    ADOQuery.SQL.Text:=' update #ExpenseListTtl set [销售单价]= '
//       +' [销售金额]/[包装数量] where isnull([包装数量],0) <>0 ';
//    ADOQuery.ExecSQL;


    ADOQuery.Close;
    ADOQuery.SQL.Text:=' update #ExpenseListTtl set [应收帐款余额]= '
      +' ( Isnull([销售金额],0)+Isnull([附加费用],0) -Isnull([结算金额],0) - '
      +' Isnull([折扣返利金额],0) ) ,'
      +' [信用预警金额]= (-Isnull([客户信用金额],0) ) +'
      +' ( Isnull([销售金额],0)+Isnull([附加费用],0) -Isnull([结算金额],0) - '
      +' Isnull([折扣返利金额],0) ) ';
    ADOQuery.ExecSQL;


    adsMaster.Close;
    adsMaster.CommandText:=' select * from #ExpenseListTtl ';
    adsMaster.open;
  end else
  begin
    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 [标准单价]=null ';
    ADOQuery.ExecSQL;

    ADOQuery.Close;
    ADOQuery.SQL.Text:=' update #ExpenseListTtl set [标准单价]= '
       +' [销售金额]/[标准数量] where [标准数量]<>0 ';
    ADOQuery.ExecSQL;
    adsMaster.Close;
    adsMaster.CommandText:=' select *,(Isnull([销售金额],0)+Isnull([附加费用],0) '
      +' -Isnull([结算金额],0) - '
      +' Isnull([折扣返利金额],0) ) as [应收帐款余额] from #ExpenseListTtl ';
    adsMaster.open;
  end;


  Panel6.Visible :=False;
  UpdateDBGrid;
  DBGrid.hint :='汇总项目:'+SelectStr1;
end;

procedure TSLSaleClothStatisticForm.N1Click(Sender: TObject);
begin
  ExpSttcCheckListBox.Sorted :=not ExpSttcCheckListBox.Sorted;
end;

procedure TSLSaleClothStatisticForm.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 TSLSaleClothStatisticForm.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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -