Ejemplo n.º 1
0
 @Override
 public void getEffects(ITransactionEffects e) {
   for (TransactionItem item : getTransactionItems()) {
     double amount = -item.getLineTotal();
     e.add(item.getAccount(), amount);
   }
   // if (getInvolvedPayee() != null) {
   // // This is Payee Opening Balance related Journal Entry
   // e.add(involvedPayee, involvedPayee.getOpeningBalance());
   // }
 }
Ejemplo n.º 2
0
  @Override
  public void selfValidate() throws AccounterException {
    super.selfValidate();
    // Checking transaction items empty
    if (getTransactionItems() == null || getTransactionItems().isEmpty()) {
      throw new AccounterException(
          AccounterException.ERROR_NO_RECORDS_TO_SAVE, Global.get().messages().journalEntry());
    }
    // checking for Amounts zero or negative
    List<TransactionItem> entrylist = this.getTransactionItems();
    for (TransactionItem entry : entrylist) {
      if (entry.getLineTotal() == null || entry.getLineTotal() == 0) {
        throw new AccounterException(
            AccounterException.ERROR_AMOUNT_ZERO, Global.get().messages().amount());
      }
    }

    // Checking Accounts same

    for (TransactionItem entry : entrylist) {
      long accountId = entry.getAccount().getID();
      for (TransactionItem entry2 : entrylist) {
        long accountId2 = entry2.getAccount().getID();
        if (!entry.equals(entry2) && accountId == accountId2) {
          throw new AccounterException(
              AccounterException.ERROR_SHOULD_NOT_SELECT_SAME_ACCOUNT_MULTIPLE_TIMES);
        }
      }
    }
    checkCreditsAndDebits();
  }
Ejemplo n.º 3
0
 /*
  * For Max DecimalPoints
  */
 private int getMaxDecimals(CustomerCreditMemo memo) {
   String qty;
   String max;
   int temp = 0;
   for (TransactionItem item : memo.getTransactionItems()) {
     qty = String.valueOf(item.getQuantity());
     max = qty.substring(qty.indexOf(".") + 1);
     if (!max.equals("0")) {
       if (temp < max.length()) {
         temp = max.length();
       }
     }
   }
   return temp;
 }
Ejemplo n.º 4
0
 private void checkCreditsAndDebits() throws AccounterException {
   double creditTotal = 0, debitTotal = 0;
   for (TransactionItem rec : getTransactionItems()) {
     if (rec.getLineTotal() != null) {
       if (DecimalUtil.isGreaterThan(rec.getLineTotal(), 0)) {
         debitTotal += rec.getLineTotal();
       } else {
         creditTotal += (-1 * rec.getLineTotal());
       }
     }
   }
   if (!DecimalUtil.isEquals(creditTotal, debitTotal)) {
     throw new AccounterException(AccounterException.ERROR_CREDIT_DEBIT_TOTALS_NOT_EQUAL);
   } else {
     setCreditTotal(creditTotal);
     setDebitTotal(debitTotal);
   }
 }
Ejemplo n.º 5
0
  /**
   * This removes a item from the current transaction.
   *
   * @param barcode the item's barcode number.
   * @throws IllegalStateException if there are no items on the invoice to remove.
   */
  public void removeItem(String barcode) throws IllegalStateException {
    int itemCount = myTransaction.getNumberOfItems();
    if (itemCount == 0) {
      throw new IllegalStateException("There are no items on the Invoice.");
    }

    // compare each item that is currently on the invoice with the barcode given
    boolean found = false;
    int line = 1; // the line in the invoice where this item is, start looking on line 1.
    for (line = 1; line <= itemCount; line++) {
      TransactionItem itemOnInvoice = myTransaction.getItem(line);
      if (itemOnInvoice.getBarcode() == barcode) {
        found = true;
        break;
      }
    }
    if (!found) throw new IllegalStateException("Item not in list");
    else myTransaction.removeTransactionItem(line);
  }
Ejemplo n.º 6
0
 /**
  * This adds/saves the current transaction to the database.
  *
  * @throws IllegalStateException if the transaction has not been paid for.
  *     <dt><b>Precondition:</b>
  *     <dd>
  *         <ul>
  *           <li>Payment for the transaction has been made.
  *         </ul>
  */
 public void process()
     throws IllegalStateException, SQLException, ClassNotFoundException, MovieNotFoundException,
         Exception {
   if (myTransaction.isPaid() == false) {
     throw new IllegalStateException("The invoice has not been paid, not saving info.");
   }
   // mySQLhelper.insertInvoiceTable(myTransaction);
   RentalMovieManagement rentalManager = new RentalMovieManagement();
   SaleMovieManagement saleManager = new SaleMovieManagement();
   for (int i = 1; i <= myTransaction.getNumberOfItems(); i++) {
     TransactionItem item = myTransaction.getItem(i);
     if (item.getType().equals("for sale")) {
       saleManager.sell(item.getBarcode());
     } else if (item.getType().trim().toLowerCase().equals("new release")
         || item.getType().trim().toLowerCase().equals("7 day")) {
       rentalManager.checkOut(
           myTransaction.getCustomerID(), item.getBarcode(), new JDBCConnection());
     }
   }
 }
Ejemplo n.º 7
0
  /** BODY */
  @Override
  public void initBody() {
    String addressHtml;
    String itemsHtml;

    String billAdrs =
        "<div align=\"left\">&nbsp;"
            + forUnusedAddress(memo.getCustomer().getName(), false)
            + "</div>";
    Address bill = memo.getBillingAddress();
    if (bill != null) {
      billAdrs =
          "<div align=\"left\">&nbsp;"
              + forUnusedAddress(memo.getCustomer().getName(), false)
              + forUnusedAddress(bill.getAddress1(), false)
              + forUnusedAddress(bill.getStreet(), false)
              + forUnusedAddress(bill.getCity(), false)
              + forUnusedAddress(bill.getStateOrProvinence(), false)
              + forUnusedAddress(bill.getZipOrPostalCode(), false)
              + bill.getCountryOrRegion()
              + "</div>";
    }

    addressHtml =
        "<table style=\"width: 100%; height: 100%;\" ><tr><td style=\"vertical-align: top;\" align=\"left\"><table style=\"width: 280px; height: 100%;\" class=\"gridHeader\"><colgroup><col></colgroup><tr><td class=\"gridHeaderBackGround\"><center>Credit To</center></td></tr><tr><td align=\"left\" style=\"vertical-align: top;padding: 6px;height:105px;\">"
            + billAdrs
            + "</td></tr></table>";

    String recordsHtml =
        "<tr class=\"item-row\"><td class=\"description\"><div></div></td><td class=\"qty\"><div></div></td><td><div class=\"cost\"></div></td><td><div class=\"price\"></div></td><td class=\"vatRate\"><span ></span></td><td class=\"vatAmount\"><div></div></td></tr>";
    if (!memo.getTransactionItems().isEmpty()) {
      recordsHtml = "";
      for (TransactionItem item : memo.getTransactionItems()) {
        recordsHtml =
            recordsHtml
                + "<tr class=\"item-row\"><td style=\"padding: 6px;\" class=\"description\"><div>"
                + forNullValue(item.getDescription())
                + "</div></td><td style=\"padding: 6px;\" align=\"right\" class=\"qty\"><div>"
                + (forZeroAmounts(
                    getDecimalsUsingMaxDecimals(
                        item.getQuantity().getValue(), null, maxDecimalPoints)))
                + "</div></td><td style=\"padding: 6px;\" align=\"right\"><div class=\"cost\">"
                + (forZeroAmounts(largeAmountConversation(item.getUnitPrice())))
                + "</div></td><td style=\"padding: 6px;\" align=\"right\"><div class=\"price\">"
                + largeAmountConversation(item.getLineTotal())
                + (company.getPreferences().isTrackTax()
                    ? "</div></td><td style=\"padding: 6px;\" align=\"right\" class=\"vatRate\"><span >"
                                + Utility.getVATItemRate(item.getTaxCode(), true)
                                + "%</span></td><td style=\"padding: 6px;\" align=\"right\" class=\"vatAmount\"><div>"
                                + item.getVATfraction()
                            == null
                        ? " "
                        : getDecimalsUsingMaxDecimals(item.getVATfraction(), null, 2)
                    : "")
                + "</div></td></tr>";
      }
    }
    itemsHtml =
        ("<table id=\"items\"><tr><th>Description</th><th>Qty</th><th>Unit Price</th><th>Total Price</th><th>VAT Rate</th><th>VAT Amount</th></tr>"
            + recordsHtml
            + "</table><table id=\"totals\"><tr><td class=\"blank\" style=\"padding: 5px;\">"
            + forNullValue(memo.getMemo())
            + "</td><td class=\"total-line\" >&nbsp;&nbsp;Sub Total</td><td class=\"total-value\"><div id=\"subtotal\">"
            + largeAmountConversation(memo.getNetAmount())
            + "&nbsp;&nbsp;</div></td></tr><tr><td class=\"blank\" ></td> <td class=\"total-line\" >&nbsp;&nbsp;VAT Total</td><td class=\"total-value\"><div id=\"total\">"
            + largeAmountConversation(memo.getTotal() - memo.getNetAmount())
            + "&nbsp;&nbsp;</div></td></tr><tr><td class=\"blank\" > </td><td class=\"total-line balance\">&nbsp;&nbsp;TOTAL</td><td class=\"total-value balance\"><div id=\"due\">"
            + largeAmountConversation(memo.getTotal())
            + "&nbsp;&nbsp;</div></td></tr></table>");

    bodyHtml = addressHtml + itemsHtml;
  }