rislai
2024-08-16 bcd7eb876bff759f6aef96f1014b0bca7a3322ff
_Main/BL/Type_MachiningPipelineSource0/StaticMethod_Initialize.qbl
@@ -8,6 +8,7 @@
  [*
    // 甄兰鸽 Jun-24-2024 (created)
    owner.FinancialProductionSource( relflush );
    productparent             := MachiningPipelineReport::GetDefaultProductParent();
    ccunit                    := MachiningPipelineReport::GetDefaultCCUnit();
    dlunit                    := MachiningPipelineReport::GetDefaultDLUnit();
    //allunit                   := EnginePipelineReport::GetDefaultAllUnit();
@@ -39,39 +40,48 @@
      //是否属于大连机加产线
      isdlproduction          := unit.ID() = MachiningPipelineReport::GetDefaultDLProductionUnit() or exists( parentunits, Elements, punit, punit.ID() = MachiningPipelineReport::GetDefaultDLProductionUnit() );
      if( iscc or isdl ){
        traverse( stockingpoint, ProductInStockingPoint_MP, pisp,  pisp.Product_MP().IsLeaf() and not pisp.IsSystem() ){
          row := table.GetRow( pisp.ProductID() );
          weekstart             := owner.StartOfPlanning().Date();
          pispips               := selectsortedset( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical()
                                                  and pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day(), pispip.Start() );
        traverse( stockingpoint, ProductInStockingPoint_MP, pisp,  pisp.Product_MP().IsLeaf() and not pisp.IsSystem()
    //              and exists( pisp.Product_MP().GetAllParent(), Elements, e, e.ID() = productparent )
                  and exists( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day() and ( pispip.NewSupplyQuantity() <> 0 or pispip.PlannedInventoryLevelEnd() <> 0 ) ) ){
          pispips             := selectsortedset( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical()
                                                  and pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day() and ( pispip.NewSupplyQuantity() <> 0 or pispip.PlannedInventoryLevelEnd() <> 0 ), pispip.Start() );
          traverse( pispips, Elements, pispip ){
            supplyquantity    := [Number]pispip.NewSupplyQuantity();//四舍五入
            //天
            daycolumn           := table.GetColumnByUnit( Translations::MP_GlobalParameters_Day(), pispip.Start().Date() );
            daycolumn         := table.GetColumnByUnit( Translations::MP_GlobalParameters_Day(), pispip.Start().Date() );
            //周
            weekcolumn          := table.GetColumnByUnit( Translations::MP_GlobalParameters_Week(), weekstart );
            supplyquantity      := [Real]ceil( pispip.NewSupplyQuantity() );//向上取整
            inventoryquantity   := [Real]ceil( pispip.PlannedInventoryLevelEnd() );//向上取整
            weekcolumn        := table.GetColumnByUnit( Translations::MP_GlobalParameters_Week(), pispip.Start().Date() );
            
            //装配线
            if( isccassemnly or isdlassemnly ){
              row.SetCellAssemblyValue( daycolumn, isccassemnly, supplyquantity );
              row.SetCellAssemblyValue( weekcolumn, isccassemnly, supplyquantity );
              if( isccassemnly ){
                daycolumn.CCAssemblyPlanQty( daycolumn.CCAssemblyPlanQty() + supplyquantity );
                weekcolumn.CCAssemblyPlanQty( weekcolumn.CCAssemblyPlanQty() + supplyquantity );
              } else {
                daycolumn.DLAssemblyPlanQty( daycolumn.DLAssemblyPlanQty() + supplyquantity );
                weekcolumn.DLAssemblyPlanQty( weekcolumn.DLAssemblyPlanQty() + supplyquantity );
              }
            }
            
            //机加线
            if( isccproduction or isdlproduction ){
              row.SetCellProductionValue( daycolumn, isccproduction, supplyquantity );
              row.SetCellProductionValue( weekcolumn, isccproduction, supplyquantity );
            }
            //库存
            if( iscc or isdl ){
              row.SetCellInventoryValue( daycolumn, iscc, inventoryquantity );
              if( pispip.Start() = weekstart + Duration::Days( 6 ) or pispip.Period_MP() = endperiod ){
                weekstart         := ( weekstart + Duration::Days( 7 ) ).Date();
                row.SetCellInventoryValue( weekcolumn, iscc, inventoryquantity );
            product           := pisp.Product_MP();
            productparents    := product.GetAllParent();
            if( exists( productparents, Elements, e, e.ID() = productparent ) ){//查询产品类型是发动机
              row             := table.GetRow( pisp.ProductID() );
              products.Add( pisp.Product_MP() );
              inventoryquantity:= [Number]pispip.PlannedInventoryLevelEnd();//四舍五入
              //机加线
              if( isccproduction or isdlproduction ){
                row.SetCellProductionValue( daycolumn, isccproduction, [Real]supplyquantity );
                row.SetCellProductionValue( weekcolumn, isccproduction, [Real]supplyquantity );
              }
              //库存
              if( iscc or isdl ){
                row.SetCellInventoryValue( daycolumn, iscc, [Real]inventoryquantity );
                if( weekcolumn.EndDate() = pispip.Start().Date() or pispip.Period_MP() = endperiod ){
                  row.SetCellInventoryValue( weekcolumn, iscc, [Real]inventoryquantity );
                }
              }
            }
          }
@@ -80,25 +90,33 @@
    }
    
    //生成调拨数据
    traverse( owner, TransferPlanRow, tprow, ( tprow.SourceStockpoingPointID() = 'CC' and tprow.TargetStockpoingPointID() = 'DL' ) or ( tprow.SourceStockpoingPointID() = 'DL' and tprow.TargetStockpoingPointID() = 'CC' ) ){
      row := selectobject( table, Row, row, row.Name() = tprow.Name() );
      traverse( table, Column, column ){
        cell := selectobject( row, Cell, cell, cell.Column() = column );
        if( column.TimeUnit() = Translations::MP_GlobalParameters_Day() ){
          tpcell := selectobject( tprow, TransferPlanCell, tpcell, tpcell.TransferPlanColumn().ColumnDate() = column.Period() );
          if( tprow.SourceStockpoingPointID() = 'CC' and tprow.TargetStockpoingPointID() = 'DL' ){
            cell.CCTransferQty( [Real]tpcell.Value() );
          }else if( tprow.SourceStockpoingPointID() = 'DL' and tprow.TargetStockpoingPointID() = 'CC' ){
            cell.DLTransferQty( [Real]tpcell.Value() );
          }
        }else if( column.TimeUnit() = Translations::MP_GlobalParameters_Week() ){
          period := column.Period() + Duration::Days( 6 );
          tpcell := selectobject( tprow, TransferPlanCell, tpcell, tpcell.TransferPlanColumn().ColumnDate() = period.Date() );
          if( tprow.SourceStockpoingPointID() = 'CC' and tprow.TargetStockpoingPointID() = 'DL' ){
            cell.CCTransferQty( [Real]tpcell.Value() );
          }else if( tprow.SourceStockpoingPointID() = 'DL' and tprow.TargetStockpoingPointID() = 'CC' ){
            cell.DLTransferQty( [Real]tpcell.Value() );
    traverse( owner, TransferPlanRow, tprow ){
      product               := selectobject( owner, Product_MP, product, product.ID() = tprow.ProductID() );
      productparents        := product.GetAllParent();
      if( exists( productparents, Elements, e, e.ID() = productparent ) ){//查询产品类型是发动机
        //起始库存点是否是大连or长春
        originsp              := selectobject( owner, StockingPoint_MP, sp, sp.ID() = tprow.SourceStockpoingPointID() );
        originunit            := originsp.Unit();
        originparentunits     := originunit.GetAllParent();
        originiscc            := originsp.ID() = ccunit or originunit.ID() = ccunit or exists( originparentunits, Elements, punit, punit.ID() = ccunit );
        originisdl            := originsp.ID() = dlunit or originunit.ID() = dlunit or exists( originparentunits, Elements, punit, punit.ID() = dlunit );
        //目的地是否是长春外租库
        destisp               := selectobject( owner, StockingPoint_MP, sp, sp.ID() = tprow.TargetStockpoingPointID() );
        destiunit             := destisp.Unit();
        destiparentunits      := destiunit.GetAllParent();
        destiiscc             := destisp.ID() = ccunit or destiunit.ID() = ccunit or exists( destiparentunits, Elements, punit, punit.ID() = ccunit );
        destiisdl             := destisp.ID() = dlunit or destiunit.ID() = dlunit or exists( destiparentunits, Elements, punit, punit.ID() = dlunit );
        if( ( originiscc and destiisdl ) or ( originisdl and destiiscc ) ){
          row := table.GetRow( tprow.ProductID() );
          traverse( tprow, TransferPlanCell, tpcell, tpcell.TransferPlanColumn().ColumnDate() <> Date::MinDate() ){
            //天
            daycolumn        := table.GetColumnByUnit( Translations::MP_GlobalParameters_Day(), tpcell.TransferPlanColumn().ColumnDate() );
            //周
            weekcolumn       := table.GetColumnByUnit( Translations::MP_GlobalParameters_Week(), tpcell.TransferPlanColumn().ColumnDate() );
            quantity         := [Real]tpcell.Value();//四舍五入
            row.SetCellTransferValue( daycolumn, ( originiscc and destiisdl ), quantity );
            row.SetCellTransferValue( weekcolumn, ( originiscc and destiisdl ), quantity );
          }
        }
      }
@@ -108,6 +126,10 @@
    i    := 0;
    traverse( rows, Elements, e ){
      e.RowNr( i );
      traverse( e, Cell, cell ){
        cell.CCAssemblyPlanQty( cell.Column().CCAssemblyPlanQty() );
        cell.DLAssemblyPlanQty( cell.Column().DLAssemblyPlanQty() );
      }
      i := i + 1;
    }
    showtable.Generate( search, products );