lazhen
2024-12-26 015a45fc5e4c88967179da0197cffad590ba20ab
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
Quintiq file version 2.0
#parent: #root
StaticMethod GenerateReport (
  MacroPlan macroPlan
)
{
  TextBody:
  [*
    macroPlan.TransferPlanRow( relflush );
    macroPlan.TransferPlanColumn( relflush );
    
    rowNr := 0;
    
    // 生成调拨计划
    traverse ( macroPlan, Unit, u, u.HasCapacityTypeTransportQuantity() ) {
      traverse ( u, Lane.LaneLeg.Trip, t ) {
        originFactory      := TransferPlanRow::IdentifyTheFactory( t.LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() );      // 起始工厂
        destinationFactory := TransferPlanRow::IdentifyTheFactory( t.LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() ); // 目标工厂
        traverse ( t, ProductInTrip, pit, pit.Quantity() > 0.0                                           and // 数量大于0
                   exists( pit.Product_MP(), AllParent.AsParent, tempP, tempP.ID() = "机加件" )          and // 只取机加件
                   originFactory                                                   <> destinationFactory     // 起始工厂不能和目标工厂一致
                  ) {
          // 找行
          tpr := TransferPlanRow::FindTransferPlanRowTypeIndex( TransferPlanRow::IdentifyTheFactory( t.LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ),
                                                                TransferPlanRow::IdentifyTheFactory( t.LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() ),
                                                                pit.Product_MP().ID() );
          if ( isnull( tpr ) ) {
            tpr := macroPlan.TransferPlanRow( relnew, 
                                              RowNr                   := rowNr,
                                              SourceStockpoingPointID := TransferPlanRow::IdentifyTheFactory( t.LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ),
                                              TargetStockpoingPointID := TransferPlanRow::IdentifyTheFactory( t.LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() ),
                                              ProductID               := pit.Product_MP().ID(),
                                              Category                := pit.Product_MP().ParentID() );     
          }
          
          // 找列
          tpc := TransferPlanColumn::FindTransferPlanColumnTypeIndex( t.Departure().Date() );
          if ( isnull( tpc ) ) {
            tpc := macroPlan.TransferPlanColumn( relnew,
                                                 ColumnDate := t.Departure().Date() );
          }
          
          // 赋值单元格
          cell := select( tpc, TransferPlanCell, tempTPC, tempTPC.TransferPlanRow() = tpr );
          if ( isnull( cell ) ) {
            cell := tpc.TransferPlanCell( relnew, Value := [String]pit.Quantity().Round( 0 ) );
            cell.TransferPlanRow( relset, tpr );
          } else {
            cell.Value( [String] ( [Number]cell.Value() + pit.Quantity().Round( 0 ) ) );
          }
        }
      }
    }
    
    // 补齐空列
    indexDate := minselect( macroPlan, TransferPlanColumn, tempTPC, true, tempTPC.ColumnDate() ).ColumnDate();
    endDate   := maxselect( macroPlan, TransferPlanColumn, tempTPC, true, tempTPC.ColumnDate() ).ColumnDate();
    while ( indexDate <= endDate ) {
      if ( isnull( TransferPlanColumn::FindTransferPlanColumnTypeIndex( indexDate ) ) ) {
        macroPlan.TransferPlanColumn( relnew,
                                      ColumnDate := indexDate );
      }
      indexDate := indexDate + 1;
    }
    
    // 补齐空格子
    traverse ( macroPlan, TransferPlanRow, tpr ) {
      traverse ( macroPlan, TransferPlanColumn, tpc, tpc.ColumnDate() >= minselect( macroPlan, TransferPlanColumn, tempTPC, true, tempTPC.ColumnDate() ).ColumnDate() ) {
        cell := select( tpr, TransferPlanCell, tempTPC, tempTPC.TransferPlanColumn() = tpc );
        if ( isnull( cell ) ) {
          cell := tpc.TransferPlanCell( relnew, Value := "" );
          cell.TransferPlanRow( relset, tpr );
        }
      }
    }
    
    // 生成产品列
    //minDateTPC := macroPlan.TransferPlanColumn( relnew,
    //                                            ColumnDate := Date::MinDate() );
    //traverse ( macroPlan, TransferPlanRow, tpr ) {
    //  productCell := minDateTPC.TransferPlanCell( relnew, Value := tpr.Category() + "_" + tpr.ProductID() );
    //  productCell.TransferPlanRow( relset, tpr );
    //}
    
    // 调拨数量调整
  *]
}