lazhen
2024-10-31 0382a81753b0b1ee1dfbc9cab7f529703fa643cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Quintiq file version 2.0
#parent: #root
Method Generate0 (
  EnginePipelineSearch search,
  Product_MPs products
)
{
  TextBody:
  [*
    // 甄兰鸽 Jun-25-2024 (created)
    table                   := selectobject( this, Source.Report, report, not report.IsShow() );
    //清空之前存储的显示数据
    this.Clear( search.TimeUnit(), search.StartDate(), search.EndDate() );
    Transaction::Transaction().Propagate( attribute( EnginePipelineColumn, Index ) );
    Transaction::Transaction().Propagate( attribute( EnginePipelineCell, ProductionQuantity ) );
    Transaction::Transaction().Propagate( attribute( EnginePipelineCell, DemandQuantity ) );
    //过滤后的产品id
    productids              := selectuniquevalues( products, Elements, product, true, product.ID() );
    rows                    := selectsortedset( table, Row, row, row.RowNr() );
    models                  := selectuniquevalues( table, Column.Cell.Demand, demand, demand.Model() );
    cellnr                  := 5 + models.Size();
    //合计行
    sumname                 := 'SUM';
    sumstr                  := sumname.Format( 'S(Len(10))' );
    sumrowproduction        := EnginePipelineRow::CraeteCellValueForRow( this, sumstr.Concat( '总产量' ), sumname, '', rows.Size() * cellnr );
    sumrowdlproduction      := EnginePipelineRow::CraeteCellValueForRow( this, sumstr.Concat( '大连产量' ), sumname, '', sumrowproduction.RowNr() + 1 );
    sumrowccproduction      := EnginePipelineRow::CraeteCellValueForRow( this, sumstr.Concat( '长春产量' ), sumname, '', sumrowdlproduction.RowNr() + 1  );
    sumrowdemand            := EnginePipelineRow::CraeteCellValueForRow( this, sumstr.Concat( '总需求' ), sumname, '', sumrowccproduction.RowNr() + 1 );
    sumdemandrows           := construct( EnginePipelineRows );
    rowno                   := sumrowdemand.RowNr() + 1;
    traverse( models, Elements, model ){
      sumdemandrows.Add( EnginePipelineRow::CraeteCellValueForRow( this, sumstr.Concat( model.Concat( '需求' ) ), sumname, model, rowno ) ); 
      rowno                 := rowno + 1;
    }
    sumrowinventory         := EnginePipelineRow::CraeteCellValueForRow( this, sumstr.Concat( '库存' ), sumname, '', rowno );
    
    //行计数
    rownr                   := 0;
    traverse( rows, Elements, row, productids.Find( row.Name() ) >= 0 ){
      rowname               := row.Name().Format( 'S(Len(10))' );
      showrowproduction     := EnginePipelineRow::CraeteCellValueForRow( this, rowname.Concat( '总产量' ), row.Name(), '', rownr );
      showrowdlproduction   := EnginePipelineRow::CraeteCellValueForRow( this, rowname.Concat( '大连产量' ), row.Name(), '', showrowproduction.RowNr() + 1 );
      showrowccproduction   := EnginePipelineRow::CraeteCellValueForRow( this, rowname.Concat( '长春产量' ), row.Name(), '', showrowdlproduction.RowNr() + 1 );
      showrowdemand         := EnginePipelineRow::CraeteCellValueForRow( this, rowname.Concat( '总需求' ), row.Name(), '', showrowccproduction.RowNr() + 1 );
      rownr                 := showrowdemand.RowNr() + 1;
      modelsnr              := showrowdemand.RowNr() + 3;
      uniquemodels          := selectuniquevalues( row, Cell.Demand, demand, true, demand.Model() );
      demandrows            := construct( EnginePipelineRows );
      traverse( uniquemodels, Elements, e ){
    
        if( rownr < modelsnr ){
          demandrows.Add( EnginePipelineRow::CraeteCellValueForRow( this, rowname.Concat( e.Concat( '需求' ) ), row.Name(), e, rownr ) ); 
          rownr             := rownr + 1;
        }
      }
    
      for( rownr := rownr; rownr < modelsnr; rownr ++ ){
    
        demandrows.Add( EnginePipelineRow::CraeteCellValueForRow( this, rowname.Concat( '' ), row.Name(), '', rownr ) ); 
      }
      showrowinventory      :=  EnginePipelineRow::CraeteCellValueForRow( this, rowname.Concat( '库存' ), row.Name(), '', rownr );
    
      traverse( this, Column, column ){
        daycells            := selectset( row, Cell, cell, cell.Column().TimeUnit() = Translations::MP_GlobalParameters_Day() and
                                            cell.Column().StartDate() >= column.StartDate() and 
                                            cell.Column().StartDate() <= column.EndDate() );
        
        //生产
        productionqty       := sum( daycells, Elements, cell, cell.ProductionQuantity() );
        production          := column.CellValue( relnew, Value := [String]productionqty );
        showrowproduction.CellValue( relinsert, production );
        sumproduction       := selectobject( column, CellValue, c, c.Row() = sumrowproduction );
        if( isnull( sumproduction ) ){
          sumproduction     := column.CellValue( relnew, Value := [String]0 );
          sumrowproduction.CellValue( relinsert, sumproduction );
        }
        sumproduction.Value( [String]( [Real]sumproduction.Value() + productionqty ) );
        //大连产量
        dlproductionqty     := sum( daycells, Elements, cell, cell.Production().DLProduction() );
        dlproduction        := column.CellValue( relnew, Value := [String]dlproductionqty );
        showrowdlproduction.CellValue( relinsert, dlproduction );
        sumdlproduction     := selectobject( column, CellValue, c, c.Row() = sumrowdlproduction );
        if( isnull( sumdlproduction ) ){
          sumdlproduction   := column.CellValue( relnew, Value := [String]0 );
          sumrowdlproduction.CellValue( relinsert, sumdlproduction );
        }
        sumdlproduction.Value( [String]( [Real]sumdlproduction.Value() + dlproductionqty ) );
        //长春产量
        ccproductionqty     := sum( daycells, Elements, cell, cell.Production().CCProduction() );
        ccproduction        := column.CellValue( relnew, Value := [String]ccproductionqty );
        showrowccproduction.CellValue( relinsert, ccproduction );
        sumccproduction     := selectobject( column, CellValue, c, c.Row() = sumrowccproduction );
        if( isnull( sumccproduction ) ){
          sumccproduction   := column.CellValue( relnew, Value := [String]0 );
          sumrowccproduction.CellValue( relinsert, sumccproduction );
        }
        sumccproduction.Value( [String]( [Real]sumccproduction.Value() + ccproductionqty ) );
        //需求
        totaldemandqty      := sum( daycells, Elements, cell, cell.DemandQuantity() );
        totaldemand         := column.CellValue( relnew, Value := [String]totaldemandqty );
        showrowdemand.CellValue( relinsert, totaldemand );
        sumdemand           := selectobject( column, CellValue, c, c.Row() = sumrowdemand );
        if( isnull( sumdemand ) ){
          sumdemand         := column.CellValue( relnew, Value := [String]0 );
          sumrowdemand.CellValue( relinsert, sumdemand );
        }
        sumdemand.Value( [String]( [Real]sumdemand.Value() + totaldemandqty ) );
        //具体需求
        traverse( demandrows, Elements, demandrow ){
          demandqty         :=  sum( daycells, Elements.Demand, celldemand, celldemand.Model() = demandrow.Demand(), celldemand.Quantity() );
          demandcell        := column.CellValue( relnew, Value := [String]demandqty );
          demandrow.CellValue( relinsert, demandcell );
          sumdemandrow      := selectobject( sumdemandrows, Elements, r, r.Demand() = demandrow.Demand() );
          if( not isnull( sumdemandrow ) ){
            sumdemandcell   := selectobject( column, CellValue, c, c.Row() = sumdemandrow );
            if( isnull( sumdemandcell ) ){
              sumdemandcell := column.CellValue( relnew, Value := [String]0 );
              sumdemandrow.CellValue( relinsert, sumdemandcell );
            }
            sumdemandcell.Value( [String]( [Real]sumdemandcell.Value() + demandqty ) );
          }
        }
        //库存
        inventroyqty             := maxobject( daycells, Elements, e, e.Column().StartDate() ).InventoryQuantity();
        inventory                := column.CellValue( relnew, Value := [String]inventroyqty );
        showrowinventory.CellValue( relinsert, inventory );
        suminventory             := selectobject( column, CellValue, c, c.Row() = sumrowinventory );
        if( isnull( suminventory ) ){
          suminventory           := column.CellValue( relnew, Value := [String]0 );
          sumrowinventory.CellValue( relinsert, suminventory );
        }
        suminventory.Value( [String]( [Real]suminventory.Value() + inventroyqty ) );
      }
    }
    traverse( this, Column, column ){
      for( demandr := sumrowdemand.RowNr() + 1; demandr < sumrowinventory.RowNr(); demandr := demandr + 1 ){
        demandrow              := selectobject( this, Row, r, r.RowNr() = demandr and r.Name() = sumname );
    //    info( '------------------14----------------' );
        if( not isnull( demandrow ) and not exists( demandrow, CellValue, cv, cv.Column() = column ) ){
          demandcell           := column.CellValue( relnew, Value := '' );
          demandrow.CellValue( relinsert, demandcell );
        }
      }
    }
    
    rows := selectsortedset( this, Row, row, row.Name(), row.RowNr() );
    i    := 0;
    traverse( rows, Elements, e ){
      e.RowNr( i );
      i := i + 1;
    }
  *]
}