How to calculate and update rows based on the CUBA search result of a table from client side

Hi,

I have a client side table to show entity with many rows, users can search the table and display the results. my question is how can I calculate the amount based on the searched result and update those searched rows accordingly if any changes?

I have timesheet entity with date, user, status …

when I browse the entity, I can see all the rows for any date, any user and any status. when I want to see one user for one week, I can use the search button, then I can see one user for a two-week timesheet rows. I need to calculate the total amount for this searched result and if I change the status for those rows from ‘NEW’ to ‘PAID’, I need to update them accordingly.

in general, how to manipulate the data filtered by cuba search and update database.

thanks,

here is the timesheet and status entity:

package com.company.cvr.entity;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import com.haulmont.cuba.core.entity.StandardEntity;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.chile.core.annotations.NamePattern;

@NamePattern("%s|user")
@Table(name = "CVR_TIME_SHEET")
@Entity(name = "cvr$TimeSheet")
public class TimeSheet extends StandardEntity {
    private static final long serialVersionUID = -1159443290299199192L;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "USER_ID")
    protected User user;

    @Temporal(TemporalType.DATE)
    @NotNull
    @Column(name = "DATE_", nullable = false)
    protected Date date;

    @Temporal(TemporalType.TIME)
    @NotNull
    @Column(name = "STARTTIME", nullable = false)
    protected Date starttime;

    @Temporal(TemporalType.TIME)
    @NotNull
    @Column(name = "ENDTIME", nullable = false)
    protected Date endtime;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "ORDER_ID")
    protected Order order;

    @Column(name = "CHEQUERECEIVED")
    protected BigDecimal chequereceived=BigDecimal.ZERO;

    @Column(name = "DESCRIPTION", length = 1000)
    protected String description;

    @Column(name = "CASHRECEIVED")
    protected BigDecimal cashreceived=BigDecimal.ZERO;

    @Column(name = "ODOMETER")
    protected Integer odometer=0;

    @Column(name = "HOURRATE")
    protected BigDecimal hourrate=BigDecimal.ZERO;

    @Column(name = "HOURS")
    protected BigDecimal hours=BigDecimal.ZERO;

    @Column(name = "HOURAMOUNT")
    protected BigDecimal houramount=BigDecimal.ZERO;

    @Column(name = "ODORATE")
    protected BigDecimal odorate=BigDecimal.ZERO;

    @Column(name = "ODOAMOUNT")
    protected BigDecimal odoamount=BigDecimal.ZERO;

    @Column(name = "TOTAL")
    protected BigDecimal total=BigDecimal.ZERO;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "STATUS_ID")
    protected Status status;

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }


    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }


    public void setStatus(Status status) {
        this.status = status;
    }

    public Status getStatus() {
        return status;
    }




    public void setDate(Date date) {
        this.date = date;
    }

    public Date getDate() {
        return date;
    }

    public void setStarttime(Date starttime) {
        this.starttime = starttime;
    }

    public Date getStarttime() {
        return starttime;
    }

    public void setEndtime(Date endtime) {
        this.endtime = endtime;
    }

    public Date getEndtime() {
        return endtime;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    public Order getOrder() {
        return order;
    }

    public void setChequereceived(BigDecimal chequereceived) {
        this.chequereceived = chequereceived;
    }

    public BigDecimal getChequereceived() {
        return chequereceived;
    }

    public void setCashreceived(BigDecimal cashreceived) {
        this.cashreceived = cashreceived;
    }

    public BigDecimal getCashreceived() {
        return cashreceived;
    }

    public void setOdometer(Integer odometer) {
        this.odometer = odometer;
    }

    public Integer getOdometer() {
        return odometer;
    }

    public void setHourrate(BigDecimal hourrate) {
        this.hourrate = hourrate;
    }

    public BigDecimal getHourrate() {
        return hourrate;
    }

    public void setHours(BigDecimal hours) {
        this.hours = hours;
    }

    public BigDecimal getHours() {
        return hours;
    }

    public void setHouramount(BigDecimal houramount) {
        this.houramount = houramount;
    }

    public BigDecimal getHouramount() {
        return houramount;
    }

    public void setOdorate(BigDecimal odorate) {
        this.odorate = odorate;
    }

    public BigDecimal getOdorate() {
        return odorate;
    }

    public void setOdoamount(BigDecimal odoamount) {
        this.odoamount = odoamount;
    }

    public BigDecimal getOdoamount() {
        return odoamount;
    }

    public void setTotal(BigDecimal total) {
        this.total = total;
    }

    public BigDecimal getTotal() {
        return total;
    }


}



package com.company.cvr.entity;

import javax.persistence.Entity;
import javax.persistence.Table;
import com.haulmont.cuba.core.entity.StandardEntity;
import javax.persistence.Column;
import javax.validation.constraints.NotNull;
import com.haulmont.cuba.core.entity.annotation.CaseConversion;
import com.haulmont.chile.core.annotations.NamePattern;

@NamePattern("%s|status")
@Table(name = "CVR_STATUS")
@Entity(name = "cvr$Status")
public class Status extends StandardEntity {
    private static final long serialVersionUID = 4345940019731765775L;

    @CaseConversion
    @NotNull
    @Column(name = "STATUS", nullable = false, unique = true, length = 40)
    protected String status;


    public void setStatus(String status) {
        this.status = status;
    }

    public String getStatus() {
        return status;
    }


}


Hi,

I need to calculate the total amount for this searched result

The simplest way is to use Table aggregation.

how to manipulate the data filtered by cuba search and update database

Just use regular edit screens or editable columns. In the latter case, you will also need to commit data by clicking some “Save” button:

getDsContext().commit();

Is there any possibility to show selection row SUM? Should we use aggregation strategy ?
(Imagine that we want SUM rows amount between two dates.)
The problem with aggregation is that shows SUM per page (and we have to select Show rows number if we have more that 50 rows).

Regards,
-n