store existing article in warehouse
This commit is contained in:
parent
f448ca64ad
commit
2f7116aa09
@ -1,31 +1,99 @@
|
||||
package org.hso.ecommerce.action.warehouse;
|
||||
|
||||
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.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 {
|
||||
|
||||
//TODO add delivery date and warehouse booking
|
||||
|
||||
private WarehouseBookingPositionSlotEntryRepository warehouseBookingPositionSlotEntryRepository;
|
||||
private SupplierOrder order;
|
||||
|
||||
|
||||
public StoreSupplierOrderAction(SupplierOrder order) {
|
||||
public StoreSupplierOrderAction(SupplierOrder order,
|
||||
WarehouseBookingPositionSlotEntryRepository warehouseBookingPositionSlotEntryRepository) {
|
||||
this.order = order;
|
||||
this.warehouseBookingPositionSlotEntryRepository = warehouseBookingPositionSlotEntryRepository;
|
||||
}
|
||||
|
||||
public WarehouseBooking storeOrder() {
|
||||
|
||||
// order.delivered = new Timestamp(System.currentTimeMillis()); //TODO
|
||||
|
||||
public void storeOrder() {
|
||||
WarehouseBooking booking = new WarehouseBooking();
|
||||
booking.created = new Timestamp(new Date().getTime());
|
||||
booking.reason = new BookingReason(order);
|
||||
|
||||
order.delivered = new Timestamp(System.currentTimeMillis());
|
||||
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.entities.supplier.SupplierOrder;
|
||||
import org.hso.ecommerce.entities.warehouse.WarehouseBooking;
|
||||
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.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@ -25,6 +28,12 @@ public class SupplierOrderController {
|
||||
@Autowired
|
||||
private final SupplierOrderRepository supplierOrderRepository = null;
|
||||
|
||||
@Autowired
|
||||
private final WarehouseBookingPositionSlotEntryRepository warehouseBookingPositionSlotEntryRepository = null;
|
||||
|
||||
@Autowired
|
||||
private final WarehouseBookingRepository warehouseBookingRepository = null;
|
||||
|
||||
@GetMapping("supplierOrders")
|
||||
public String listSuppliers(Model model) {
|
||||
|
||||
@ -41,25 +50,18 @@ public class SupplierOrderController {
|
||||
|
||||
@PostMapping("/supplierOrders/store/{id}")
|
||||
public RedirectView storeOrder(@PathVariable(required = true) String id) {
|
||||
|
||||
long supplierOrderID = Long.parseLong(id);
|
||||
|
||||
Optional<SupplierOrder> order = supplierOrderRepository.findById(supplierOrderID);
|
||||
|
||||
long supplierOrderID = Long.parseLong(id); //get supplier order id
|
||||
Optional<SupplierOrder> order = supplierOrderRepository.findById(supplierOrderID); //get supplier order
|
||||
if (order.isPresent()) {
|
||||
// TODO call action
|
||||
StoreSupplierOrderAction orderAction = new StoreSupplierOrderAction(order.get(), warehouseBookingPositionSlotEntryRepository); //create new action
|
||||
WarehouseBooking booking = orderAction.storeOrder(); //store order in warehouse
|
||||
supplierOrderRepository.save(order.get()); //save updated supplier order
|
||||
|
||||
System.out.println("Order is present\n");
|
||||
warehouseBookingRepository.save(booking);
|
||||
|
||||
|
||||
StoreSupplierOrderAction orderAction = new StoreSupplierOrderAction(order.get());
|
||||
|
||||
orderAction.storeOrder();
|
||||
|
||||
supplierOrderRepository.save(order.get());
|
||||
//TODO save warehouse booking
|
||||
|
||||
}
|
||||
|
||||
return new RedirectView("../../supplierOrders/");
|
||||
}
|
||||
|
||||
|
@ -20,5 +20,8 @@ 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)
|
||||
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