MnftCompared.java :  » ERP-CRM-Financial » Evaristo-4.0 » com » m16e » mpbiz » mnft » Java Open Source

Java Open Source » ERP CRM Financial » Evaristo 4.0 
Evaristo 4.0 » com » m16e » mpbiz » mnft » MnftCompared.java
/**
 *
 * MnftCompared.java
 *
 * @author carlos@m16e.com
 */

package com.m16e.mpbiz.mnft;

////////////////////////////////////////////////////////////

import com.m16e.mpbiz.docs.MpBizDoc;
import com.m16e.mpbiz.tables.DbBillOfMaterials;
import com.m16e.tools.db.DatabaseException;
import java.sql.SQLException;
import java.util.ArrayList;

public class MnftCompared 
{
//  static enum BomDiffType
//  {
//    EQUAL, ONLY_IN_MNFT, ONLY_IN_ESTIMATE, DIFF
//  };

  MpBizDoc bizMnft =null;
  MpBizDoc bizEstimate =null;
  java.util.List<BomDiff> bomDiffs = new ArrayList<BomDiff>();

  ////////////////////////////////////////////////////////////
  public MnftCompared( MpBizDoc bizMnft, MpBizDoc bizEstimate )
  {
    this.bizMnft = bizMnft;
    this.bizEstimate = bizEstimate;
  }

  ////////////////////////////////////////////////////////////
  private void computeBomDiffs()
  throws SQLException, DatabaseException
  {
    bomDiffs.clear();
    java.util.List<DbBillOfMaterials> bomMnftList =
      DbBillOfMaterials.getList(
        false,
        DbBillOfMaterials.FN_TIPO_ENT_ID + " = ? and " +
        DbBillOfMaterials.FN_TIPO_DOC_ID + " = ? and " +
        DbBillOfMaterials.FN_DOC_ID + " = ?",
        DbBillOfMaterials.FN_SRC_PROD_ID,
        bizMnft.getTipoEntId(),
        bizMnft.getTipoDocId(),
        bizMnft.getDocId() );
    for( DbBillOfMaterials bm : bomMnftList )
    {
      DbBillOfMaterials be =
        DbBillOfMaterials.getSingleRecord(
          DbBillOfMaterials.FN_TIPO_ENT_ID + " = ? and " +
          DbBillOfMaterials.FN_TIPO_DOC_ID + " = ? and " +
          DbBillOfMaterials.FN_DOC_ID + " = ?",
          DbBillOfMaterials.FN_SRC_PROD_ID,
          bizEstimate.getTipoEntId(),
          bizEstimate.getTipoDocId(),
          bizEstimate.getDocId() );
      if( be == null )
      {
        bomDiffs.add( new BomDiff( BomDiff.BomDiffType.ONLY_IN_MNFT, bm, null ) );
      }
      else if( tuplesAreDifferent( bm, be ) )
      {
        bomDiffs.add( new BomDiff( BomDiff.BomDiffType.DIFF, bm, be ) );
      }
    }
    java.util.List<DbBillOfMaterials> bomEstimateList =
      DbBillOfMaterials.getList(
        false,
        DbBillOfMaterials.FN_TIPO_ENT_ID + " = ? and " +
        DbBillOfMaterials.FN_TIPO_DOC_ID + " = ? and " +
        DbBillOfMaterials.FN_DOC_ID + " = ?",
        DbBillOfMaterials.FN_SRC_PROD_ID,
        bizEstimate.getTipoEntId(),
        bizEstimate.getTipoDocId(),
        bizEstimate.getDocId() );
    for( DbBillOfMaterials be : bomEstimateList )
    {
      DbBillOfMaterials bm =
        DbBillOfMaterials.getSingleRecord(
          DbBillOfMaterials.FN_TIPO_ENT_ID + " = ? and " +
          DbBillOfMaterials.FN_TIPO_DOC_ID + " = ? and " +
          DbBillOfMaterials.FN_DOC_ID + " = ?",
          DbBillOfMaterials.FN_SRC_PROD_ID,
          bizMnft.getTipoEntId(),
          bizMnft.getTipoDocId(),
          bizMnft.getDocId() );
      if( bm == null )
      {
        bomDiffs.add(  new BomDiff( BomDiff.BomDiffType.ONLY_IN_ESTIMATE, null, be ) );
      }
    }
  }

  ////////////////////////////////////////////////////////////
  private boolean tuplesAreDifferent(
    DbBillOfMaterials bomMnft, DbBillOfMaterials bomEstimate )
  {
    int[] fields =
    {
      DbBillOfMaterials.SRC_PROD_ID,
      DbBillOfMaterials.UNITS,
      DbBillOfMaterials.ESTIMATED_COST,
      DbBillOfMaterials.ESTIMATED_SELL_PRICE
    };
    for( int f = 0; f < fields.length; f++ )
    {
      if( !bomMnft.getTupleValue( f ).equals( bomEstimate.getTupleValue( f ) ) )
        return true;
    }

    return false;
  }

//  ////////////////////////////////////////////////////////////
//  class BomDiff
//  {
//    BomDiffType diffType = null;
//    DbBillOfMaterials bomMnft = null;
//    DbBillOfMaterials bomEstimate = null;
//
//    ////////////////////////////////////////////////////////////
//    BomDiff( BomDiffType type, DbBillOfMaterials bomMnft, DbBillOfMaterials bomEstimate )
//    {
//      this.diffType = type;
//      this.bomMnft = bomMnft;
//      this.bomEstimate = bomEstimate;
//    }
//
//    ////////////////////////////////////////////////////////////
//    public DbBillOfMaterials getBomEstimate() { return bomEstimate; }
//    public DbBillOfMaterials getBomMnft() { return bomMnft; }
//    public BomDiffType getDiffType() { return diffType; }
//
//  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.