示例#1
0
 /**
  * Get Name
  *
  * @return get the name of the line (from Product)
  */
 public String getName() {
   getProduct();
   if (m_product != null) return m_product.getName();
   if (getC_Charge_ID() != 0) {
     MCharge charge = MCharge.get(getCtx(), getC_Charge_ID());
     return charge.getName();
   }
   return "";
 } // getName
  /**
   * Create Facts (the accounting logic) for PJI
   *
   * <pre>
   *  Issue
   *      ProjectWIP      DR
   *      Inventory               CR
   *  </pre>
   *
   * Project Account is either Asset or WIP depending on Project Type
   *
   * @param as accounting schema
   * @return Fact
   */
  public ArrayList<Fact> createFacts(MAcctSchema as) {
    //  create Fact Header
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    setC_Currency_ID(as.getC_Currency_ID());

    MProject project = new MProject(getCtx(), m_issue.getC_Project_ID(), getTrxName());
    String ProjectCategory = project.getProjectCategory();
    MProduct product = MProduct.get(getCtx(), m_issue.getM_Product_ID());

    //  Line pointers
    FactLine dr = null;
    FactLine cr = null;

    //  Issue Cost
    BigDecimal costs = null;
    BigDecimal total = Env.ZERO;
    if (m_issue.getM_InOutLine_ID() != 0) costs = getPOCost(as);
    else if (m_issue.getS_TimeExpenseLine_ID() != 0) costs = getLaborCost(as);
    if (costs == null) // 	standard Product Costs
    {
      for (MCostDetail cost : m_line.getCostDetail(as)) {
        if (!MCostDetail.existsCost(cost)) continue;

        costs = MCostDetail.getTotalCost(cost, as);
        total = total.add(costs);
      }
    }

    if (total == null || total.signum() == 0) {
      p_Error = "Resubmit - No Costs for " + product.getName();
      log.log(Level.WARNING, p_Error);
      return null;
    }

    //  Project         DR
    int acctType = ACCTTYPE_ProjectWIP;
    if (MProject.PROJECTCATEGORY_AssetProject.equals(ProjectCategory))
      acctType = ACCTTYPE_ProjectAsset;
    dr = fact.createLine(m_line, getAccount(acctType, as), as.getC_Currency_ID(), costs, null);
    dr.setQty(m_line.getQty().negate());

    //  Inventory               CR
    acctType = ProductCost.ACCTTYPE_P_Asset;
    if (product.isService()) acctType = ProductCost.ACCTTYPE_P_Expense;
    cr =
        fact.createLine(
            m_line, m_line.getAccount(acctType, as), as.getC_Currency_ID(), null, costs);
    cr.setM_Locator_ID(m_line.getM_Locator_ID());
    cr.setLocationFromLocator(m_line.getM_Locator_ID(), true); // from Loc
    //
    ArrayList<Fact> facts = new ArrayList<Fact>();
    facts.add(fact);
    return facts;
  } //  createFact
  private int selectASIID(BOMLineWrapper line) {

    if (line.getM_Product_ID() <= 0) return -1;

    MProduct p = new MProduct(Env.getCtx(), line.getM_Product_ID(), null);
    PAttributeInstance pai =
        new PAttributeInstance(
            (JFrame) null,
            p.getName(),
            getParameterValueAsInt("M_Warehouse_ID"),
            0,
            line.getM_Product_ID(),
            0);

    return pai.getM_AttributeSetInstance_ID();
  }
示例#4
0
  /**
   * Add Product
   *
   * @param element panel
   * @param product product
   */
  private void addProduct(CPanel element, MProduct product) {
    Insets ii = new Insets(2, 4, 2, 4);
    int M_Product_ID = product.getM_Product_ID();
    CPanel pe = new CPanel();
    pe.setBorder(BorderFactory.createLineBorder(Color.BLUE, 1));
    pe.setLayout(new GridBagLayout());

    //	Product Value - Price
    pe.add(
        new JLabel(product.getValue()),
        new GridBagConstraints(
            0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, ii, 0, 0));
    String formatted = "";
    if (m_M_PriceList_Version_ID != 0) {
      MProductPrice pp =
          MProductPrice.get(Env.getCtx(), m_M_PriceList_Version_ID, M_Product_ID, null);
      if (pp != null) {
        BigDecimal price = pp.getPriceStd();
        formatted = m_price.format(price);
      } else formatted = "-";
    }
    pe.add(
        new JLabel(formatted, JLabel.RIGHT),
        new GridBagConstraints(
            1, 0, 1, 1, .5, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, ii, 0, 0));

    //	Product Name - Qty
    pe.add(
        new JLabel(product.getName()),
        new GridBagConstraints(
            0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, ii, 0, 0));
    formatted = "";
    if (m_M_Warehouse_ID != 0) {
      BigDecimal qty = MStorage.getQtyAvailable(m_M_Warehouse_ID, M_Product_ID, 0, null);
      if (qty == null) formatted = "-";
      else formatted = m_qty.format(qty);
    }
    pe.add(
        new JLabel(formatted, JLabel.RIGHT),
        new GridBagConstraints(
            1, 1, 1, 1, .5, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, ii, 0, 0));
    //
    element.add(pe);
  } //	addProduct