lazhen
2024-10-31 1416622ccad797dc3602b6672ca59137bab49c7e
_Main/BL/Type_MachiningPipelineReport/Method_Generate.qbl
@@ -8,31 +8,60 @@
  TextBody:
  [*
    // 甄兰鸽 Jun-25-2024 (created)
    table      := selectobject( this, Source.Report, report, not report.IsShow() );
    startyearmonth          := search.MacroPlan().StartOfPlanning().StartOfMonth().Date();
    table                   := selectobject( this, Source.Report, report, not report.IsShow() );
    //清空之前存储的显示数据
    this.Clear( search.TimeUnit(), search.StartDate(), search.EndDate() );
    //过滤后的产品id
    productids := selectuniquevalues( products, Elements, product, true, product.ID() );
    sumrow     := this.Row( relnew, Name := 'SUM', RowNr := table.Row( relsize ) );
    productids              := selectuniquevalues( products, Elements, product, true, product.ID() );
    sumrow                  := this.Row( relnew, Name := 'SUM', RowNr := table.Row( relsize ) );
    traverse( table, Row, row, productids.Find( row.Name() ) >= 0 ){
      showrow := this.Row( relnew, Name := row.Name(), RowNr := row.RowNr() );
      traverse( row, Cell, cell, cell.Column().TimeUnit() = search.TimeUnit() ){
        column   := selectobject( this, Column, column, column.StartDate() = cell.Column().StartDate() and column.TimeUnit() = search.TimeUnit() );
        if( not isnull( column ) ){
          sumcell  := selectobject( column, Cell, c, c.Row() = sumrow );
          if( isnull( sumcell ) ){
            sumcell := MachiningPipelineCell::Initialize( column );
            sumrow.Cell( relinsert, sumcell );
          }
          showcell := cell.Copy( column );
          showrow.Cell( relinsert, showcell );
          sumcell.Add( cell );
      showrow               := this.Row( relnew, Name := row.Name(), RowNr := row.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() );
        maxinventory        := maxobject( daycells, Elements, e, e.Column().StartDate() );
        ccassemblyplanqty   := sum( daycells, Elements, cell, cell.CCAssemblyPlanQty() );
        ccproductionqty     := sum( daycells, Elements, cell, cell.CCProductionQty() );
        cctransferqty       := sum( daycells, Elements, cell, cell.CCTransferQty() );
        ccinventoryqty      := 0.0;
        dlassemblyplanqty   := sum( daycells, Elements, cell, cell.DLAssemblyPlanQty() );
        dlproductionqty     := sum( daycells, Elements, cell, cell.DLProductionQty() );
        dltransferqty       := sum( daycells, Elements, cell, cell.DLTransferQty() );
        dlinventoryqty      := 0.0;
        if( column.StartDate() = startyearmonth ){//当日期是计划开始第一个月时,计算库存是实际库存
          ccinventoryqty    := row.CCInventoryQty() + maxinventory.CCProductionQty() - maxinventory.CCToDLDepartureQty() + maxinventory.DLToCCArrivalQty() - maxinventory.CCAssemblyPlanQty();
          dlinventoryqty    := row.DLInventoryQty() + maxinventory.DLProductionQty() - maxinventory.DLToCCDepartureQty() + maxinventory.CCToDLArrivalQty() - maxinventory.DLAssemblyPlanQty();
        }else{
          beforecolumn      := column.PreviousColumn();
          beforeinventory   := selectobject( showrow, Cell, c, c.Column() = beforecolumn );
          ccinventoryqty    := beforeinventory.CCInventoryQty() + maxinventory.CCProductionQty() - maxinventory.CCToDLDepartureQty() + maxinventory.DLToCCArrivalQty() - maxinventory.CCAssemblyPlanQty();
          ccinventoryqty    := beforeinventory.DLInventoryQty() + maxinventory.DLProductionQty() - maxinventory.DLToCCDepartureQty() + maxinventory.DLToCCDepartureQty() - maxinventory.DLAssemblyPlanQty();
        }
        sumcell  := selectobject( column, Cell, c, c.Row() = sumrow );
        if( isnull( sumcell ) ){
          sumcell           := column.Cell( relnew, CCAssemblyPlanQty  := 0,
                                             CCProductionQty           := 0,
                                             CCTransferQty             := 0,
                                             CCInventoryQty            := 0,
                                             DLAssemblyPlanQty         := 0,
                                             DLProductionQty           := 0,
                                             DLTransferQty             := 0,
                                             DLInventoryQty            := 0 );
          sumrow.Cell( relinsert, sumcell );
        }
        showcell            := column.Cell( relnew, CCAssemblyPlanQty  := ccassemblyplanqty,
                                             CCProductionQty           := ccproductionqty,
                                             CCTransferQty             := cctransferqty,
                                             CCInventoryQty            := ccinventoryqty,
                                             DLAssemblyPlanQty         := dlassemblyplanqty,
                                             DLProductionQty           := dlproductionqty,
                                             DLTransferQty             := dltransferqty,
                                             DLInventoryQty            := dlinventoryqty );
        showrow.Cell( relinsert, showcell );
        sumcell.Add( showcell );
      }
    }
  *]