Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.4 kB
2
Indexable
Never
void removeStyleFromOrder(String productNo, BigDecimal itemPrice, def items, boolean skuLevelPricing = false) {
        int qty = 0
        orderItems.values().each { deliveries ->
            if (deliveries) {
                Map<String, Date> startAndCancelDates=  this.extractDates(deliveries)
                String startDateKey = DateUtils.simpleFormatDate(startAndCancelDates.get("startDate"))
                String canelDateKey = DateUtils.simpleFormatDate(startAndCancelDates.get("cancelDate"))
                String deliveryDateKey = DateUtils.getDeliveryKey(startAndCancelDates.get("startDate"),startAndCancelDates.get("cancelDate"))

                BigDecimal currentLogoCharges =BigDecimal.ZERO
                BigDecimal updatedLogoCharges =BigDecimal.ZERO
                currentLogoCharges =  this.getStyleLogoCharges( productNo,startDateKey, deliveryDateKey,  null)
                deliveries.values().findAll { it.containsKey(productNo) }.each { eachDelivery ->
                    if (eachDelivery[productNo][OrderDTO.SIZE_QTY_MAP]?.values())
                        qty += eachDelivery[productNo][OrderDTO.SIZE_QTY_MAP].values().sum()
                    eachDelivery.remove(productNo)
                }
                updatedLogoCharges = this.getStyleLogoCharges( productNo,  startDateKey,deliveryDateKey,  null)
                if (skuLevelPricing && items && items.size()) {
                    items.each { item ->
                        int orderedQty = (item.qty && item.qty.isNumber()) ? item.qty as int : 0
                        BigDecimal price = (item.price && item.price.toString().isNumber()) ? (item.price as BigDecimal) : 0
                        this.updateTotal(-orderedQty, price)
                    }
                }
                else {
                    this.updateTotal(-qty, itemPrice)
                }
            }
        }
    }


    Map<String, Date> extractDates(def deliveries) {
        Map<String, LocalDate> dateMap = new HashMap<>();

        deliveries.each { dateString, deliveryDetails ->
            String[] parts = dateString.split("_");
            Date startDate = DateUtils.parseDateFromString(parts[0])
            Date cancelDate = DateUtils.parseDateFromString(parts[1])

            dateMap.put("startDate", startDate);
            dateMap.put("cancelDate", cancelDate);
        }

        return dateMap;
    }
Leave a Comment