@GET @Path("debt") @Produces("application/xml") @Transactional public String debt( @QueryParam("offer_id") Long offerId, @QueryParam("aff_id") Long affId, @QueryParam("date_kind") @DefaultValue("CREATION") Debts.DateKind dateKind, @QueryParam("from") @DefaultValue("0") Long from, @QueryParam("to") Long to, @QueryParam("ordering") @DefaultValue("DEBT") Debts.Ordering ord, @QueryParam("direction") @DefaultValue("DESC") OrderingDirection dir, @QueryParam("offset") int offset, @QueryParam("limit") @DefaultValue("20") int limit) { DateTime dateFrom = new DateTime(from); DateTime dateTo = new DateTime(to); DataFilter<Debts.Ordering> filter = DataFilter.newInstance(); filter .setTo(dateTo) .setFrom(dateFrom) .setOrdering(ord) .setDirection(dir) .setOffset(offset) .setLimit(limit); Pair<QueryResult, Long> result = debts.debtInfo(offerId, affId, dateKind, filter); return new XmlQueryResult(result.fst) .setElement("debt") .setRoot("debts") .addRootAttribute("count", result.snd) .toString(); }
@PUT @Transactional public Response makeWithdraw( @FormParam("offer_id") Long offerId, @FormParam("user_id") List<Long> userIdList, @FormParam("basis") List<Withdrawal.Basis> basisList, @FormParam("amount") List<BigDecimal> amountList, @FormParam("date_kind") Debts.DateKind dateKind, @FormParam("from") @DefaultValue("0") Long from, @FormParam("to") Long to) { checkCondition(userIdList.size() == amountList.size()); checkNotNull(offerId); Offer offer = existingOffer(offerId); for (int i = 0; i < userIdList.size(); i++) { checkNotNull(userIdList.get(i), amountList.get(i)); try { debts.payOffToAffiliate( offer, userIdList.get(i), basisList.get(i), amountList.get(i), dateKind, new DateTime(from), new DateTime(to)); } catch (IllegalArgumentException e) { return Response.status(409).build(); } } return Response.ok().build(); }
@GET @Path("sum") @Produces("application/xml") @Transactional public String sumOrdered(@QueryParam("aff_id") Long affId) { return toXmlSum(debts.sumOrderedByUser(affId)); }
@PUT @Transactional @Path("order") public Response orderWithdrawal(@FormParam("aff_id") Long affId) { checkNotNull(affId); debts.orderWithdrawal(affId); return Response.ok().build(); }
@GET @Path("debt/sum") @Transactional @Produces("application/xml") public String sumDebt( @QueryParam("aff_id") Long affId, @QueryParam("offer_id") Long offerId, @QueryParam("date_kind") @DefaultValue("CREATION") Debts.DateKind dateKind, @QueryParam("from") @DefaultValue("0") Long from, @QueryParam("to") Long to) { return toXmlSum(debts.sumDebt(affId, offerId, dateKind, new DateTime(from), new DateTime(to))); }
@GET @Path("masspayment") @Transactional @Produces("application/xml") public String massPayment( @QueryParam("from") @DefaultValue("0") Long from, @QueryParam("to") Long to) { DataFilter<Debts.PaymentOrdering> filter = DataFilter.newInstance(); filter .setFrom(from) .setTo(to) .setOrdering(Debts.PaymentOrdering.AMOUNT) .setDirection(OrderingDirection.DESC); return massPaymentXml(debts.payments(Debts.PayMethod.AUTO, filter)); }
@GET @Produces("application/xml") @Transactional public String listOrdered( @QueryParam("aff_id") Long affId, @QueryParam("offset") int offset, @QueryParam("limit") @DefaultValue("20") int limit) { DataFilter<Debts.Ordering> filter = DataFilter.newInstance(); filter.setOffset(offset).setLimit(limit); Pair<QueryResult, Long> result = debts.orderedByUser(affId, filter); return new XmlQueryResult(result.fst) .setRoot("debts") .setElement("debt") .addRootAttribute("count", result.snd) .toString(); }
@GET @Produces("application/xml") @Path("by_offer") @Transactional public String listOrdered( @QueryParam("from") @DefaultValue("0") Long from, @QueryParam("to") Long to, @QueryParam("offset") int offset, @QueryParam("limit") @DefaultValue("20") int limit) { DataFilter<Debts.Ordering> filter = DataFilter.newInstance(); filter.setOffset(offset).setLimit(limit).setFrom(from).setTo(to); Pair<QueryResult, Long> result = debts.orderedByOffer(filter); return new XmlQueryResult(result.fst) .setRoot("debts") .setElement("debt") .addRootAttribute("count", result.snd) .toString(); }
@GET @Path("payments") @Transactional @Produces("application/xml") public String payments( @QueryParam("pay_method") Debts.PayMethod payMethod, @QueryParam("from") @DefaultValue("0") Long from, @QueryParam("to") Long to, @QueryParam("offset") int offset, @QueryParam("limit") @DefaultValue("20") int limit, @QueryParam("ordering") @DefaultValue("AMOUNT") Debts.PaymentOrdering ordering, @QueryParam("direction") @DefaultValue("DESC") OrderingDirection direction) { DataFilter<Debts.PaymentOrdering> filter = DataFilter.newInstance(); filter .setFrom(from) .setTo(to) .setOffset(offset) .setLimit(limit) .setOrdering(ordering) .setDirection(direction); return paymentsXml(debts.payments(payMethod, filter)); }