Commit cc511818 authored by seykron's avatar seykron

Closes #24: displays the list of bills in the web balance

parent ebbc7caf
......@@ -5,9 +5,13 @@ import be.rlab.domino.application.model.BillDTO
import be.rlab.domino.application.model.BillingMode
import be.rlab.domino.application.model.MemorySlots.SERVICE_CONFIGURATIONS
import be.rlab.domino.application.model.ServiceConfig
import be.rlab.domino.domain.model.*
import be.rlab.domino.domain.model.Balance
import be.rlab.domino.domain.model.Bill
import be.rlab.domino.domain.model.TransactionType
import be.rlab.domino.domain.model.Value
import be.rlab.domino.domain.model.Value.Companion.ZERO
import be.rlab.tehanu.domain.Memory
import org.joda.time.DateTime
import java.util.*
class BalanceFactory(memory: Memory) {
......@@ -20,8 +24,11 @@ class BalanceFactory(memory: Memory) {
) {
val billingMode: BillingMode = serviceConfig.billingMode
val creditorId: UUID = bill.creditor().id
val creditorUserName: String = bill.creditor().userName
val pending: Boolean = bill.pending
val debt: Value = bill.credit.debt
val total: Value = bill.debt.value
val dueDate: DateTime? = bill.dueDate
}
fun create(
......@@ -36,10 +43,11 @@ class BalanceFactory(memory: Memory) {
return BalanceDTO(
previousBalance = -previousTotal,
bills = balance.bills.map { bill ->
bills = resolveSingleBills(balance.bills).map { bill ->
BillDTO.new(
serviceName = bill.creditor().userName,
debt = bill.debt.value,
serviceName = bill.creditorUserName,
debt = bill.debt,
total = bill.total,
dueDate = bill.dueDate,
pending = bill.pending
)
......@@ -63,11 +71,11 @@ class BalanceFactory(memory: Memory) {
}
private fun calculatePendingDebt(balance: Balance): Value {
val pendingBills: List<BillInfo> = pendingBills(createBillsInfos(balance.bills))
val bills: List<BillInfo> = resolveSingleBills(balance.bills)
return pendingBills.fold(ZERO) { pendingDebt, pendingBill ->
if (pendingBill.pending) {
pendingDebt + pendingBill.debt
return bills.fold(ZERO) { pendingDebt, billInfo ->
if (billInfo.pending) {
pendingDebt + billInfo.debt
} else {
pendingDebt
}
......@@ -90,11 +98,11 @@ class BalanceFactory(memory: Memory) {
}
}
private fun pendingBills(
bills: List<BillInfo>
private fun resolveSingleBills(
bills: List<Bill>
): List<BillInfo> {
return bills.fold(listOf()) { pendingBills, bill ->
if (bill.pending && !billExists(pendingBills, bill)) {
return createBillsInfos(bills).fold(listOf()) { pendingBills, bill ->
if (!billExists(pendingBills, bill)) {
pendingBills + bill
} else {
pendingBills
......
......@@ -6,6 +6,7 @@ import org.joda.time.DateTime
data class BillDTO(
val serviceName: String,
val debt: Value,
val total: Value,
val dueDate: DateTime?,
val pending: Boolean
) {
......@@ -13,11 +14,13 @@ data class BillDTO(
fun new(
serviceName: String,
debt: Value,
total: Value,
dueDate: DateTime?,
pending: Boolean
): BillDTO = BillDTO(
serviceName = serviceName,
debt = debt,
total = total,
dueDate = dueDate,
pending = pending
)
......
......@@ -65,4 +65,12 @@ body {
.content {
flex: 1 0 auto;
}
\ No newline at end of file
}
table.services {
margin-left: 5%;
}
table.services tr:last-child {
border-bottom: none;
}
......@@ -53,6 +53,20 @@
<td>Total de deudas</td>
<td>${balance.debtsTotal}</td>
</tr>
<tr>
<td>
<table class="services striped">
<tbody>
<#list balance.bills as bill>
<tr>
<td>${bill.serviceName}</td>
<td>${bill.total}</td>
</tr>
</#list>
</tbody>
</table>
</td>
</tr>
<tr>
<td>Deudas pendientes</td>
<td>${balance.debtsPending}</td>
......@@ -65,10 +79,6 @@
<td>Balance Anterior</td>
<td>${balance.previousBalance}</td>
</tr>
<tr>
<td>Balance del mes</td>
<td>${balance.income}</td>
</tr>
<tr class="blue-grey lighten-5">
<td>Balance total</td>
<td>${balance.totalBalance}</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment