Ejemplo n.º 1
0
  public ArrayList<Account> getAccountList() {
    Connection connect = null;

    try {
      ArrayList<Account> accounts = new ArrayList<>();
      connect = DBConnection.getConnection();

      String sql = "SELECT * FROM account" + "ORDER BY name desc";

      ResultSet result = Utility.queryOperation(connect, sql);
      Account temp = new Account();
      while (result.next()) {
        temp.setName(result.getString("name"));
        temp.setEmail(result.getString("email"));
        temp.setSecondaryEmail(result.getString("secondaryEmail"));
        temp.setTypeAccount(result.getString("typeAccount"));
        temp.setPassword(result.getString("password"));
        temp.setAdmin(result.getBoolean("isAdministrator"));
        accounts.add(temp);
      }
      return accounts;

    } catch (SQLException ex) {
      Logger.getLogger(AccountManager.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      DBConnection.releaseConnection(connect);
    }
    return null;
  }
Ejemplo n.º 2
0
  public ArrayList<Account> searchUser(String search, String type) throws SQLException {
    Connection connect = null;
    ArrayList<Account> accounts;

    String sql =
        "SELECT * from account WHERE "
            + "name LIKE '%"
            + search
            + "%'"
            + "AND typeAccount = '"
            + type
            + "'";
    String sql2 = "SELECT * from account WHERE " + "typeAccount ='" + type + "'";
    try {
      connect = DBConnection.getConnection();
      accounts = new ArrayList<>();
      if (search.isEmpty()) {
        ResultSet result = Utility.queryOperation(connect, sql2);
        Account temp = new Account();
        while (result.next()) {
          temp.setName(result.getString("name"));
          temp.setEmail(result.getString("email"));
          temp.setSecondaryEmail(result.getString("secondaryEmail"));
          temp.setTypeAccount(result.getString("typeAccount"));
          temp.setPassword(result.getString("password"));
          temp.setAdmin(result.getBoolean("isAdministrator"));
          accounts.add(temp);
        }
      } else {
        ResultSet result = Utility.queryOperation(connect, sql);
        Account temp = new Account();
        while (result.next()) {
          temp.setName(result.getString("name"));
          temp.setEmail(result.getString("email"));
          temp.setSecondaryEmail(result.getString("secondaryEmail"));
          temp.setTypeAccount(result.getString("typeAccount"));
          temp.setPassword(result.getString("password"));
          temp.setAdmin(result.getBoolean("isAdministrator"));
          accounts.add(temp);
        }
      }

    } finally {
      DBConnection.releaseConnection(connect);
    }
    return accounts;
  }
Ejemplo n.º 3
0
  private void createAccounts(final Context context) {
    persistence.runInTransaction(
        em -> {
          Account account;

          account = metadata.create(Account.class);
          account.setName("Credit card");
          account.setCurrency(context.rubCurrency);
          em.persist(account);
          context.accounts.add(account);

          account = metadata.create(Account.class);
          account.setName("Cash");
          account.setCurrency(context.rubCurrency);
          em.persist(account);
          context.accounts.add(account);

          account = metadata.create(Account.class);
          account.setName("Deposit");
          account.setCurrency(context.rubCurrency);
          em.persist(account);
          context.accounts.add(account);

          account = metadata.create(Account.class);
          account.setName("Deposit USD");
          account.setCurrency(context.usdCurrency);
          em.persist(account);
          context.accounts.add(account);

          account = metadata.create(Account.class);
          account.setName("Deposit EUR");
          account.setCurrency(context.eurCurrency);
          em.persist(account);
          context.accounts.add(account);
        });
  }
  /** Test for fetching zobjects when there is an object that matches the query */
  @Test
  public void getInvoice() throws Exception {

    // Setup Product details
    String productId = getTestProduct();
    String productRatePlanId = getTestProductRatePlan(productId);
    String productRateplanChargeId = getTestProductRatePlanCharge(productRatePlanId);

    assertNotNull(productId);
    assertNotNull(productRatePlanId);
    assertNotNull(productRateplanChargeId);

    SubscribeRequest subscribeReq = new SubscribeRequest();

    // subscribeReq.setAccount(testAccount());
    String uniqueString = UUID.randomUUID().toString();

    Contact contact = new Contact();
    contact.setFirstName(uniqueString);
    contact.setLastName(uniqueString);

    Account account = new Account();
    account.setName(uniqueString);
    account.setBillCycleDay(1);
    account.setCurrency("USD");
    account.setAllowInvoiceEdit(false);
    account.setAutoPay(false);
    account.setStatus("Draft");
    account.setPaymentTerm("Due Upon Receipt");
    account.setBatch("Batch1");

    PaymentMethod paymentMethod = new PaymentMethod();
    paymentMethod.setType("CreditCard");
    paymentMethod.setCreditCardNumber("5105105105105100");
    paymentMethod.setCreditCardType("Visa");
    paymentMethod.setCreditCardExpirationYear(2026);
    paymentMethod.setCreditCardExpirationMonth(5);
    paymentMethod.setCreditCardHolderName("Unit Test");

    // Generate Start and stop days for subscription
    XMLGregorianCalendar effectiveStartDate = null;
    XMLGregorianCalendar effectiveEndDate = null;
    try {
      GregorianCalendar calStart = new GregorianCalendar();
      // calStart.setTime(now);
      calStart.add(Calendar.DATE, -1);

      GregorianCalendar calEnd = new GregorianCalendar();
      // calEnd.setTime(now);
      calEnd.add(Calendar.DATE, 1);

      effectiveStartDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calStart);
      effectiveEndDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calStart);

    } catch (DatatypeConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    Subscription subscription = new Subscription();
    subscription.setContractAcceptanceDate(effectiveStartDate);
    subscription.setContractEffectiveDate(effectiveStartDate);
    subscription.setInitialTerm(12);
    subscription.setRenewalTerm(12);

    RatePlan ratePlan = new RatePlan();
    ratePlan.setProductRatePlanId(productRatePlanId);
    RatePlanData ratePlanData = new RatePlanData();
    ratePlanData.setRatePlan(ratePlan);

    SubscriptionData subscriptionData = new SubscriptionData();
    subscriptionData.setSubscription(subscription);
    subscriptionData.getRatePlanData().add(ratePlanData);

    subscribeReq.setAccount(account);
    subscribeReq.setBillToContact(contact);
    subscribeReq.setSoldToContact(contact);
    subscribeReq.setPaymentMethod(paymentMethod);
    subscribeReq.setSubscriptionData(subscriptionData);

    SubscribeResult subscribeResult =
        module.subscribe(Collections.singletonList(subscribeReq)).get(0);
    assertTrue(subscribeResult.isSuccess());
    assertEquals(0, subscribeResult.getErrors().size());

    Map<String, Object> result = module.getInvoice(subscribeResult.getInvoiceId());

    System.out.println("Result = " + result);

    assertEquals("Posted", result.get("status"));
    // assertEquals("amount",result.get("amount"));
    assertNotSame(0, ((ArrayList) result.get("invoiceitems")).size());

    assertNotNull(result.get("billTo"));
    assertNotNull(result.get("soldTo"));

    DeleteResult deleteResultAccount = null;
    DeleteResult deleteResultProduct = null;
    try {
      deleteResultAccount =
          module
              .delete(
                  ZObjectType.Account, Collections.singletonList(subscribeResult.getAccountId()))
              .get(0);
      deleteResultProduct =
          module.delete(ZObjectType.Product, Collections.singletonList(productId)).get(0);
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    assertTrue(deleteResultAccount.isSuccess());
    assertTrue(deleteResultProduct.isSuccess());
  }
  /** Stores to persistence layer initial data. */
  @PostConstruct
  public void init() {
    if (roleRepository.findByName("ROLE_ADMIN") == null) {
      Role roleUser = new Role();
      roleUser.setName("ROLE_USER");
      roleRepository.save(roleUser);

      Role roleAdmin = new Role();
      roleAdmin.setName("ROLE_ADMIN");
      roleRepository.save(roleAdmin);

      User user = new User();
      user.setEnabled(true);
      user.setEmail("admin@admin");

      BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
      user.setPassword(encoder.encode("admin"));
      List<Role> roles = new ArrayList<>();
      roles.add(roleAdmin);
      roles.add(roleUser);
      user.setRoles(roles);
      userRepository.save(user);

      // Create account for wallet
      Account walletAccount = new Account();
      walletAccount.setName(context.getMessage("Name.default.account", null, Locale.ENGLISH));
      walletAccount.setUser(user);
      walletAccount.setAmount(new BigDecimal(0));
      walletAccount.setCurrency(Currency.getInstance("UAH"));
      accountRepository.save(walletAccount);

      Account bankAccount = new Account();
      bankAccount.setName("Bank");
      bankAccount.setUser(user);
      bankAccount.setAmount(new BigDecimal(500));
      bankAccount.setCurrency(Currency.getInstance("UAH"));
      accountRepository.save(bankAccount);

      // Create categories for expenses
      for (int i = 1; i < 6; i++) {
        Category category = new Category();
        category.setName(
            context.getMessage("Name" + i + ".default.category", null, Locale.ENGLISH));
        category.setType(Operation.EXPENSE);
        category.setUser(user);
        categoryRepository.save(category);
      }

      // Create categories for incomes
      for (int i = 6; i < 8; i++) {
        Category category = new Category();
        category.setName(
            context.getMessage("Name" + i + ".default.category", null, Locale.ENGLISH));
        category.setType(Operation.INCOME);
        category.setUser(user);
        categoryRepository.save(category);
      }

      Transaction transaction1 = new Transaction();
      transaction1.setDate(new Date());
      transaction1.setAccount(walletAccount);
      transaction1.setAmount(new BigDecimal(50));
      transaction1.setCurrency(Currency.getInstance("UAH"));
      transaction1.setCategory(categoryRepository.findOne(3));
      transaction1.setType(Operation.EXPENSE);
      transaction1.setComment("McDonalds");
      transaction1.setUser(user);
      transactionRepository.save(transaction1);

      Transaction transaction2 = new Transaction();
      Calendar calendar = new GregorianCalendar();
      calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
      transaction2.setDate(calendar.getTime());
      transaction2.setAccount(bankAccount);
      transaction2.setAmount(new BigDecimal(45));
      transaction2.setCurrency(Currency.getInstance("UAH"));
      transaction2.setCategory(categoryRepository.findOne(7));
      transaction2.setType(Operation.INCOME);
      transaction2.setComment("Festo");
      transaction2.setUser(user);
      transactionRepository.save(transaction2);

      List<Transaction> transactions = new ArrayList<>();
      transactions.add(transaction1);
      user.setTransactions(transactions);
    }
  }