store existing article in warehouse
This commit is contained in:
parent
f448ca64ad
commit
2f7116aa09
@ -1,31 +1,99 @@
|
|||||||
package org.hso.ecommerce.action.warehouse;
|
package org.hso.ecommerce.action.warehouse;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.hso.ecommerce.entities.booking.BookingReason;
|
||||||
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
||||||
|
import org.hso.ecommerce.entities.warehouse.WarehouseBooking;
|
||||||
|
import org.hso.ecommerce.entities.warehouse.WarehouseBookingPosition;
|
||||||
|
import org.hso.ecommerce.entities.warehouse.WarehouseBookingPositionSlotEntry;
|
||||||
|
import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository;
|
||||||
|
|
||||||
public class StoreSupplierOrderAction {
|
public class StoreSupplierOrderAction {
|
||||||
|
|
||||||
//TODO add delivery date and warehouse booking
|
private WarehouseBookingPositionSlotEntryRepository warehouseBookingPositionSlotEntryRepository;
|
||||||
|
|
||||||
private SupplierOrder order;
|
private SupplierOrder order;
|
||||||
|
|
||||||
|
public StoreSupplierOrderAction(SupplierOrder order,
|
||||||
public StoreSupplierOrderAction(SupplierOrder order) {
|
WarehouseBookingPositionSlotEntryRepository warehouseBookingPositionSlotEntryRepository) {
|
||||||
this.order = order;
|
this.order = order;
|
||||||
|
this.warehouseBookingPositionSlotEntryRepository = warehouseBookingPositionSlotEntryRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WarehouseBooking storeOrder() {
|
||||||
|
|
||||||
public void storeOrder() {
|
// order.delivered = new Timestamp(System.currentTimeMillis()); //TODO
|
||||||
|
|
||||||
order.delivered = new Timestamp(System.currentTimeMillis());
|
WarehouseBooking booking = new WarehouseBooking();
|
||||||
|
booking.created = new Timestamp(new Date().getTime());
|
||||||
|
booking.reason = new BookingReason(order);
|
||||||
|
|
||||||
|
System.out.println(warehouseBookingPositionSlotEntryRepository);
|
||||||
|
|
||||||
|
// loop bis alles verteilt
|
||||||
|
|
||||||
|
// new BookingPosition
|
||||||
|
|
||||||
|
// slot entry,
|
||||||
|
|
||||||
|
int amount = order.numberOfUnits;
|
||||||
|
|
||||||
|
for (WarehouseBookingPositionSlotEntry slot : warehouseBookingPositionSlotEntryRepository.findAll()) {
|
||||||
|
|
||||||
|
System.out.println(slot.article.title);
|
||||||
|
|
||||||
|
if (slot.article.related == order.ordered) {
|
||||||
|
|
||||||
|
// ordered article is already in warehouse
|
||||||
|
|
||||||
|
System.out.println("ordered article is allready in warehouse");
|
||||||
|
|
||||||
|
if (slot.newSumSlot < slot.article.warehouseUnitsPerSlot) {
|
||||||
|
|
||||||
|
int freeSpace = (slot.article.warehouseUnitsPerSlot - slot.newSumSlot);
|
||||||
|
|
||||||
|
System.out.println("Slot noch frei");
|
||||||
|
|
||||||
|
WarehouseBookingPosition bookingPosition = new WarehouseBookingPosition();
|
||||||
|
|
||||||
|
bookingPosition.article = slot.article;
|
||||||
|
bookingPosition.amount = Math.min(amount, freeSpace);
|
||||||
|
bookingPosition.slotEntry = slot.copyAddAmount(Math.min(amount, freeSpace));
|
||||||
|
bookingPosition.booking = booking;
|
||||||
|
|
||||||
|
amount = amount - freeSpace;
|
||||||
|
|
||||||
|
booking.positions.add(bookingPosition);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
System.out.println("Slot voll");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} //end loop article in already
|
||||||
|
|
||||||
|
|
||||||
|
if (amount > 0) {
|
||||||
|
|
||||||
|
//loop to add new slots
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return booking;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,10 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import org.hso.ecommerce.action.warehouse.StoreSupplierOrderAction;
|
import org.hso.ecommerce.action.warehouse.StoreSupplierOrderAction;
|
||||||
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
||||||
|
import org.hso.ecommerce.entities.warehouse.WarehouseBooking;
|
||||||
import org.hso.ecommerce.repos.supplier.SupplierOrderRepository;
|
import org.hso.ecommerce.repos.supplier.SupplierOrderRepository;
|
||||||
|
import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository;
|
||||||
|
import org.hso.ecommerce.repos.warehouse.WarehouseBookingRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
@ -25,6 +28,12 @@ public class SupplierOrderController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private final SupplierOrderRepository supplierOrderRepository = null;
|
private final SupplierOrderRepository supplierOrderRepository = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final WarehouseBookingPositionSlotEntryRepository warehouseBookingPositionSlotEntryRepository = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final WarehouseBookingRepository warehouseBookingRepository = null;
|
||||||
|
|
||||||
@GetMapping("supplierOrders")
|
@GetMapping("supplierOrders")
|
||||||
public String listSuppliers(Model model) {
|
public String listSuppliers(Model model) {
|
||||||
|
|
||||||
@ -41,25 +50,18 @@ public class SupplierOrderController {
|
|||||||
|
|
||||||
@PostMapping("/supplierOrders/store/{id}")
|
@PostMapping("/supplierOrders/store/{id}")
|
||||||
public RedirectView storeOrder(@PathVariable(required = true) String id) {
|
public RedirectView storeOrder(@PathVariable(required = true) String id) {
|
||||||
|
long supplierOrderID = Long.parseLong(id); //get supplier order id
|
||||||
long supplierOrderID = Long.parseLong(id);
|
Optional<SupplierOrder> order = supplierOrderRepository.findById(supplierOrderID); //get supplier order
|
||||||
|
|
||||||
Optional<SupplierOrder> order = supplierOrderRepository.findById(supplierOrderID);
|
|
||||||
|
|
||||||
if (order.isPresent()) {
|
if (order.isPresent()) {
|
||||||
// TODO call action
|
StoreSupplierOrderAction orderAction = new StoreSupplierOrderAction(order.get(), warehouseBookingPositionSlotEntryRepository); //create new action
|
||||||
|
WarehouseBooking booking = orderAction.storeOrder(); //store order in warehouse
|
||||||
System.out.println("Order is present\n");
|
supplierOrderRepository.save(order.get()); //save updated supplier order
|
||||||
|
|
||||||
|
warehouseBookingRepository.save(booking);
|
||||||
|
|
||||||
StoreSupplierOrderAction orderAction = new StoreSupplierOrderAction(order.get());
|
//TODO save warehouse booking
|
||||||
|
|
||||||
orderAction.storeOrder();
|
|
||||||
|
|
||||||
supplierOrderRepository.save(order.get());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RedirectView("../../supplierOrders/");
|
return new RedirectView("../../supplierOrders/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,9 @@ public interface WarehouseBookingPositionSlotEntryRepository extends JpaReposito
|
|||||||
|
|
||||||
@Query(value = "Select e.id, e.article_id, e.new_sum_slot, e.slot_id from warehouse_booking_position_entries as e, warehouse_slots as s where e.slot_id = s.id AND s.slot_num = :slotnum GROUP BY s.slot_num HAVING max(e.id)", nativeQuery = true)
|
@Query(value = "Select e.id, e.article_id, e.new_sum_slot, e.slot_id from warehouse_booking_position_entries as e, warehouse_slots as s where e.slot_id = s.id AND s.slot_num = :slotnum GROUP BY s.slot_num HAVING max(e.id)", nativeQuery = true)
|
||||||
Optional<WarehouseBookingPositionSlotEntry> getBySlotNum(long slotnum);
|
Optional<WarehouseBookingPositionSlotEntry> getBySlotNum(long slotnum);
|
||||||
|
|
||||||
|
@Query(value = "Select e.id, e.article_id, e.new_sum_slot, e.slot_id from warehouse_booking_position_entries as e, warehouse_slots as s where e.slot_id = s.id", nativeQuery = true)
|
||||||
|
List<WarehouseBookingPositionSlotEntry> getAll();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user