Přídány datové třídy, DAO a servisní třída pro objednávky. Přidána

číselná řada pro objednávky.
refs #136
multitenant
Josef Rokos 10 years ago
parent e889e0f45a
commit 544d736719

@ -267,6 +267,17 @@ public class AppInitListener implements ServletContextListener {
ns.setNumber(1);
nsService.add(ns);
}
ns = nsService.getNumberSerie(Constants.MOD_ORDER);
if (ns == null)
{
ns = new NumberSeries();
ns.setModule(Constants.MOD_ORDER);
ns.setPrefix("");
ns.setNumber(1);
nsService.add(ns);
}
}
private void checkGlobalSettings() {

@ -8,6 +8,7 @@ import info.bukova.isspst.reporting.Report;
import info.bukova.isspst.reporting.ReportMapping;
import info.bukova.isspst.services.addressbook.AdbService;
import info.bukova.isspst.services.approved.ApprovedService;
import info.bukova.isspst.services.approved.OrderService;
import info.bukova.isspst.services.buildings.BuildingService;
import info.bukova.isspst.services.munits.MUnitService;
import info.bukova.isspst.services.reqsubjects.MaterialService;
@ -69,6 +70,7 @@ public class Constants {
public final static String MOD_WORKFLOW = "WORKFLOW";
public final static String MOD_TRIPBILL = "TRIPBILL";
public final static String MOD_APPROVED = "APPROVED";
public final static String MOD_ORDER = "ORDER";
public final static Module MODULES[] = {
new Module(MOD_USERS, "Uživatelé", UserService.class),
new Module(MOD_PERMISSIONS, "Práva", RoleService.class),
@ -82,7 +84,8 @@ public class Constants {
new Module(MOD_TRIPREQUIREMENTS, "Požadavky na služební cesty", TripRequirementService.class),
new Module(MOD_WORKFLOW, "Procesy schválení", RequirementTypeService.class),
new Module(MOD_TRIPBILL, "Cestovní příkazy", TripBillService.class),
new Module(MOD_APPROVED, "Schválené položky příkazů", ApprovedService.class) };
new Module(MOD_APPROVED, "Schválené položky požadavků", ApprovedService.class),
new Module(MOD_ORDER, "Objednávky", OrderService.class) };
public final static String PERM_APPROVE = "PERM_APPROVE";
public final static String PERM_SHOW_WORKGROUP_REQ = "PERM_SHOW_WORKGROUP_REQ";

@ -0,0 +1,7 @@
package info.bukova.isspst.dao;
import info.bukova.isspst.data.Order;
public interface OrderDao extends BaseDao<Order> {
}

@ -0,0 +1,9 @@
package info.bukova.isspst.dao.jpa;
import info.bukova.isspst.dao.OrderDao;
import info.bukova.isspst.data.Order;
public class OrderDaoJPA extends BaseDaoJPA<Order> implements OrderDao {
}

@ -0,0 +1,156 @@
package info.bukova.isspst.data;
import javax.persistence.Embeddable;
@Embeddable
public class AddressEmb {
private String company;
private String department;
private String contactName;
private String street;
private String houseNumber;
private String zipCode;
private String city;
private String state;
private long ic;
private String dic;
private String phone;
private String email;
private String web;
private String description;
public AddressEmb() {
super();
}
public AddressEmb(Address address) {
this.company = address.getCompany();
this.department = address.getDepartment();
this.contactName = address.getContactName();
this.street = address.getStreet();
this.houseNumber = address.getHouseNumber();
this.zipCode = address.getZipCode();
this.city = address.getCity();
this.state = address.getState();
this.ic = address.getIc();
this.dic = address.getDic();
this.phone = address.getPhone();
this.email = address.getEmail();
this.web = address.getWeb();
this.description = address.getDescription();
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getContactName() {
return contactName;
}
public void setContactName(String contactName) {
this.contactName = contactName;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getHouseNumber() {
return houseNumber;
}
public void setHouseNumber(String houseNumber) {
this.houseNumber = houseNumber;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public long getIc() {
return ic;
}
public void setIc(long ic) {
this.ic = ic;
}
public String getDic() {
return dic;
}
public void setDic(String dic) {
this.dic = dic;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getWeb() {
return web;
}
public void setWeb(String web) {
this.web = web;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

@ -0,0 +1,247 @@
package info.bukova.isspst.data;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
@Entity
@Table(name = "ORDERS")
public class Order extends BaseData {
@Column(name = "NUMSER")
private String numser;
@Column(name = "ORDER_DATE")
private Date orderDate;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "city", column = @Column(name = "SUPPLIER_CITY")),
@AttributeOverride(name = "company", column = @Column(name = "SUPPLIER_COMPANY")),
@AttributeOverride(name = "contactName", column = @Column(name = "SUPPLIER_CONTACT_NAME")),
@AttributeOverride(name = "department", column = @Column(name = "SUPPLIER_DEPARTMENT")),
@AttributeOverride(name = "description", column = @Column(name = "SUPPLIER_DESCRIPTION")),
@AttributeOverride(name = "dic", column = @Column(name = "SUPPLIER_DIC")),
@AttributeOverride(name = "email", column = @Column(name = "SUPPLIER_EMAIL")),
@AttributeOverride(name = "houseNumber", column = @Column(name = "SUPPLIER_HOUSENUMBER")),
@AttributeOverride(name = "ic", column = @Column(name = "SUPPLIER_IC")),
@AttributeOverride(name = "phone", column = @Column(name = "SUPPLIER_PHONE")),
@AttributeOverride(name = "state", column = @Column(name = "SUPPLIER_STATE")),
@AttributeOverride(name = "street", column = @Column(name = "SUPPLIER_STREET")),
@AttributeOverride(name = "web", column = @Column(name = "SUPPLIER_WEB")),
@AttributeOverride(name = "zipCode", column = @Column(name = "SUPPLIER_ZIP_CODE"))
})
private AddressEmb suplier;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "city", column = @Column(name = "INVOICE_CITY")),
@AttributeOverride(name = "company", column = @Column(name = "INVOICE_COMPANY")),
@AttributeOverride(name = "contactName", column = @Column(name = "INVOICE_CONTACT_NAME")),
@AttributeOverride(name = "department", column = @Column(name = "INVOICE_DEPARTMENT")),
@AttributeOverride(name = "description", column = @Column(name = "INVOICE_DESCRIPTION")),
@AttributeOverride(name = "dic", column = @Column(name = "INVOICE_DIC")),
@AttributeOverride(name = "email", column = @Column(name = "INVOICE_EMAIL")),
@AttributeOverride(name = "houseNumber", column = @Column(name = "INVOICE_HOUSENUMBER")),
@AttributeOverride(name = "ic", column = @Column(name = "INVOICE_IC")),
@AttributeOverride(name = "phone", column = @Column(name = "INVOICE_PHONE")),
@AttributeOverride(name = "state", column = @Column(name = "INVOICE_STATE")),
@AttributeOverride(name = "street", column = @Column(name = "INVOICE_STREET")),
@AttributeOverride(name = "web", column = @Column(name = "INVOICE_WEB")),
@AttributeOverride(name = "zipCode", column = @Column(name = "INVOICE_ZIP_CODE"))
})
private AddressEmb address;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "city", column = @Column(name = "DELIVERY_CITY")),
@AttributeOverride(name = "company", column = @Column(name = "DELIVERY_COMPANY")),
@AttributeOverride(name = "contactName", column = @Column(name = "DELIVERY_CONTACT_NAME")),
@AttributeOverride(name = "department", column = @Column(name = "DELIVERY_DEPARTMENT")),
@AttributeOverride(name = "description", column = @Column(name = "DELIVERY_DESCRIPTION")),
@AttributeOverride(name = "dic", column = @Column(name = "DELIVERY_DIC")),
@AttributeOverride(name = "email", column = @Column(name = "DELIVERY_EMAIL")),
@AttributeOverride(name = "houseNumber", column = @Column(name = "DELIVERY_HOUSENUMBER")),
@AttributeOverride(name = "ic", column = @Column(name = "DELIVERY_IC")),
@AttributeOverride(name = "phone", column = @Column(name = "DELIVERY_PHONE")),
@AttributeOverride(name = "state", column = @Column(name = "DELIVERY_STATE")),
@AttributeOverride(name = "street", column = @Column(name = "DELIVERY_STREET")),
@AttributeOverride(name = "web", column = @Column(name = "DELIVERY_WEB")),
@AttributeOverride(name = "zipCode", column = @Column(name = "DELIVERY_ZIP_CODE"))
})
private AddressEmb deliveryAddress;
@Column(name = "DELIVERY_DATE")
private Date deliveryDate;
@Column(name = "DELIVERED_DATE")
private Date deliveredDate;
@Column(name = "DELIVERY_TYPE")
private String deliveryType;
@Column(name = "DESCRIPTION")
private String description;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "order", orphanRemoval = true)
@LazyCollection(LazyCollectionOption.TRUE)
private List<OrderItem> items;
@Column(name = "TOTAL", precision=15, scale=4)
private BigDecimal total;
@Column(name = "ORDERED")
private boolean ordered;
@Column(name = "DELIVERED")
private boolean delivered;
@Column(name = "INVOICED")
private boolean invoiced;
@Column(name = "INVOICE_NUMBER")
private String invoiceNumber;
public Order() {
items = new ArrayList<OrderItem>();
}
public String getNumser() {
return numser;
}
public void setNumser(String numser) {
this.numser = numser;
}
public AddressEmb getSuplier() {
return suplier;
}
public void setSuplier(AddressEmb suplier) {
this.suplier = suplier;
}
public AddressEmb getAddress() {
return address;
}
public void setAddress(AddressEmb address) {
this.address = address;
}
public Date getDeliveryDate() {
return deliveryDate;
}
public void setDeliveryDate(Date deliveryDate) {
this.deliveryDate = deliveryDate;
}
public String getDeliveryType() {
return deliveryType;
}
public void setDeliveryType(String deliveryType) {
this.deliveryType = deliveryType;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public AddressEmb getDeliveryAddress() {
return deliveryAddress;
}
public void setDeliveryAddress(AddressEmb deliveryAddress) {
this.deliveryAddress = deliveryAddress;
}
public Date getDeliveredDate() {
return deliveredDate;
}
public void setDeliveredDate(Date deliveredDate) {
this.deliveredDate = deliveredDate;
}
public List<OrderItem> getItems() {
return items;
}
public void addItem(OrderItem item) {
item.setOrder(this);
items.add(item);
}
public void setItems(List<OrderItem> items) {
this.items = items;
}
public boolean isDelivered() {
return delivered;
}
public void setDelivered(boolean delivered) {
this.delivered = delivered;
}
public boolean isInvoiced() {
return invoiced;
}
public void setInvoiced(boolean invoiced) {
this.invoiced = invoiced;
}
public String getInvoiceNumber() {
return invoiceNumber;
}
public void setInvoiceNumber(String invoiceNumber) {
this.invoiceNumber = invoiceNumber;
}
public boolean isOrdered() {
return ordered;
}
public void setOrdered(boolean ordered) {
this.ordered = ordered;
}
public Date getOrderDate() {
return orderDate;
}
public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
public BigDecimal getTotal() {
return total;
}
public void setTotal(BigDecimal total) {
this.total = total;
}
}

@ -0,0 +1,161 @@
package info.bukova.isspst.data;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "ORDER_ITEM")
public class OrderItem {
@Id
@Column(name="ID")
@GeneratedValue
private int id;
@Column(name = "CODE")
private String code;
@Column(name = "NAME")
private String name;
@Column(name = "TEXTITEM")
private String textItem;
@Column(name = "QUANTITY", precision=15, scale=4)
private BigDecimal quantity;
@Embedded
private MUnitEmb munit;
@Column(name = "UNITPRICE", precision=15, scale=4)
private BigDecimal unitPrice;
@Column(name = "TOTAL", precision=15, scale=4)
private BigDecimal total;
@Column(name = "DESCRIPTION")
private String description;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "REQUIREMENT_ITEM_ID")
private RequirementItem reqItem;
@ManyToOne
@JoinColumn(name = "ORDER_ID")
private Order order;
public OrderItem() {
super();
}
public OrderItem(RequirementItem reqItem) {
super();
this.reqItem = reqItem;
this.code = reqItem.getCode();
this.name = reqItem.getName();
this.textItem = reqItem.getTextItem();
this.quantity = reqItem.getQuantity();
this.unitPrice = reqItem.getUnitPrice();
this.munit = reqItem.getMunit();
this.total = reqItem.getTotal();
this.description = reqItem.getDescription();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTextItem() {
return textItem;
}
public void setTextItem(String textItem) {
this.textItem = textItem;
}
public BigDecimal getQuantity() {
return quantity;
}
public void setQuantity(BigDecimal quantity) {
this.quantity = quantity;
}
public MUnitEmb getMunit() {
return munit;
}
public void setMunit(MUnitEmb munit) {
this.munit = munit;
}
public BigDecimal getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
}
public BigDecimal getTotal() {
return total;
}
public void setTotal(BigDecimal total) {
this.total = total;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public RequirementItem getReqItem() {
return reqItem;
}
public void setReqItem(RequirementItem reqItem) {
this.reqItem = reqItem;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
}

@ -53,6 +53,9 @@ public class RequirementItem
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "DELIVERED")
private Boolean delivered;
public int getId()
{
return id;
@ -176,4 +179,12 @@ public class RequirementItem
{
this.requirement = requirement;
}
public Boolean getDelivered() {
return delivered;
}
public void setDelivered(Boolean delivered) {
this.delivered = delivered;
}
}

@ -0,0 +1,13 @@
package info.bukova.isspst.services.approved;
import java.util.List;
import info.bukova.isspst.data.JoinedItem;
import info.bukova.isspst.data.Order;
import info.bukova.isspst.services.Service;
public interface OrderService extends Service<Order> {
public Order createOrder(List<JoinedItem> items);
}

@ -0,0 +1,53 @@
package info.bukova.isspst.services.approved;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import info.bukova.isspst.data.AddressEmb;
import info.bukova.isspst.data.JoinedItem;
import info.bukova.isspst.data.Order;
import info.bukova.isspst.data.OrderItem;
import info.bukova.isspst.services.AbstractOwnedService;
import info.bukova.isspst.services.settings.GlobalSettingsService;
public class OrderServiceImpl extends AbstractOwnedService<Order> implements
OrderService {
@Autowired
private GlobalSettingsService globalSettings;
@Override
@PreAuthorize("hasPermission(this, 'PERM_ADD')")
public Order createOrder(List<JoinedItem> items) {
Order order = new Order();
order.setAddress(new AddressEmb(globalSettings.getSettings().getMainAddress()));
order.setDeliveryAddress(new AddressEmb(globalSettings.getSettings().getMainAddress()));
order.setOrderDate(new Date());
BigDecimal total = BigDecimal.ZERO;
for (JoinedItem item : items) {
total = total.add(item.getTotal());
order.addItem(new OrderItem(item.getItem()));
}
order.setTotal(total);
return order;
}
@Override
@Transactional
@PreAuthorize("hasPermission(this, 'PERM_ADD')")
public void add(Order order) {
order.setNumser(getNumberSerie());
super.add(order);
}
}

@ -28,5 +28,7 @@
<mapping class="info.bukova.isspst.data.GlobalSettings"></mapping>
<mapping class="info.bukova.isspst.data.TripBill"></mapping>
<mapping class="info.bukova.isspst.data.TripBillItem"></mapping>
<mapping class="info.bukova.isspst.data.Order"></mapping>
<mapping class="info.bukova.isspst.data.OrderItem"></mapping>
</session-factory>
</hibernate-configuration>

@ -243,6 +243,10 @@
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="orderDao" class="info.bukova.isspst.dao.jpa.OrderDaoJPA">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Business logic -->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
@ -400,4 +404,10 @@
<property name="validator" ref="validator"/>
</bean>
<bean id="orderService" class="info.bukova.isspst.services.approved.OrderServiceImpl">
<property name="dao" ref="orderDao"/>
<property name="validator" ref="validator"/>
<property name="numberSeriesService" ref="numericSeriesService"/>
</bean>
</beans>

Loading…
Cancel
Save