75 lines
2.8 KiB
Java
75 lines
2.8 KiB
Java
package com.utopiaindustries.querybuilder.ctp;
|
|
|
|
import com.utopiaindustries.querybuilder.QueryBuilder;
|
|
import com.utopiaindustries.util.CTPDateTimeFormat;
|
|
import com.utopiaindustries.util.StringUtils;
|
|
|
|
import java.time.LocalDate;
|
|
import java.util.List;
|
|
|
|
public class InventoryAccountQueryBuilder {
|
|
|
|
public static String buildQuery(String id,
|
|
String title,
|
|
String active,
|
|
String createdBy,
|
|
String startDate,
|
|
String endDate,
|
|
String siteId,
|
|
Long count,
|
|
List<Long> accountIds,
|
|
String parentEntityType,
|
|
String parentEntityId,
|
|
Boolean isPackaging) {
|
|
|
|
// format date
|
|
String formattedDate;
|
|
String formattedEndDate;
|
|
String startDate1 = "";
|
|
String endDate1 = "";
|
|
if (!StringUtils.isNullOrEmpty(startDate)) {
|
|
formattedDate = CTPDateTimeFormat.getMySQLFormattedDateString(startDate, CTPDateTimeFormat.HTML5_DATE_INPUT_FORMAT);
|
|
formattedEndDate = CTPDateTimeFormat.getMySQLFormattedDateString(endDate, CTPDateTimeFormat.HTML5_DATE_INPUT_FORMAT);
|
|
startDate1 = String.format("'%s 00:00:01'", formattedDate);
|
|
if (!StringUtils.isNullOrEmpty(endDate)) {
|
|
endDate1 = String.format("'%s 23:59:59'", formattedEndDate);
|
|
} else {
|
|
endDate1 = String.format("'%s 23:59:59'", LocalDate.now());
|
|
}
|
|
}
|
|
|
|
QueryBuilder qb = (new QueryBuilder())
|
|
.setTable("cut_to_pack.inventory_account")
|
|
.setColumns("*")
|
|
.where()
|
|
.columnLikeTitle("title", title)
|
|
.or()
|
|
.columnEquals("id", id)
|
|
.and()
|
|
.columnEquals("active", active)
|
|
.and()
|
|
.columnLike("created_by", createdBy)
|
|
.and()
|
|
.columnEqualToOrGreaterThan("created_at", startDate1)
|
|
.and()
|
|
.columnEqualToOrLessThan("created_at", endDate1)
|
|
.and()
|
|
.columnEquals("location_site_id", siteId)
|
|
.and()
|
|
.columnEquals("parent_entity_type", parentEntityType )
|
|
.and()
|
|
.columnEquals("parent_entity_id", parentEntityId )
|
|
.and()
|
|
.columnEquals("is_packaging", isPackaging );
|
|
|
|
if (!accountIds.isEmpty()) {
|
|
qb.and()
|
|
.columnIn("id", accountIds.toArray( new Long[0] ));
|
|
}
|
|
|
|
qb.limit(count.intValue());
|
|
return qb.build();
|
|
|
|
}
|
|
}
|