Subversion Repositories SmartDukaan

Rev

Rev 37312 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37312 Rev 37380
Line 271... Line 271...
271
            model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
271
            model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
272
        } else {
272
        } else {
273
            model.addAttribute("customerBillingAddress", "");
273
            model.addAttribute("customerBillingAddress", "");
274
 
274
 
275
        }
275
        }
276
        model.addAttribute("customerBillingAddressObj", customerAddress);
276
        model.addAttribute("customerBillingAddressObj",
-
 
277
                this.billingAddressOrCustomerFallback(customerAddress, fofoOrder.getCustomerId()));
277
        model.addAttribute("customerDetailsObj", customer);
278
        model.addAttribute("customerDetailsObj", customer);
278
        model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
279
        model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
279
        model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
280
        model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
280
        model.addAttribute("insurancePolicies", insurancePolicies);
281
        model.addAttribute("insurancePolicies", insurancePolicies);
281
        return "order-details";
282
        return "order-details";
Line 335... Line 336...
335
                .paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
336
                .paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
336
        List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
337
        List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
337
                .selectByRetailerIdInvoiceNumber(fofoOrder.getInvoiceNumber());
338
                .selectByRetailerIdInvoiceNumber(fofoOrder.getInvoiceNumber());
338
        this.addInsuranceProvider(insurancePolicies);
339
        this.addInsuranceProvider(insurancePolicies);
339
        Set<Integer> itemIds = fofoOrderItems.stream().map(FofoOrderItem::getItemId).collect(Collectors.toSet());
340
        Set<Integer> itemIds = fofoOrderItems.stream().map(FofoOrderItem::getItemId).collect(Collectors.toSet());
-
 
341
        // An insurance-only sale has no fofo_order_item row (a policy is not a catalog item), so
-
 
342
        // itemIds is empty and selectByIds would throw "List should not be empty" on the empty IN.
-
 
343
        Map<Integer, Item> itemsMap = itemIds.isEmpty()
-
 
344
                ? new HashMap<>()
340
        Map<Integer, Item> itemsMap = itemRepository.selectByIds(itemIds).stream()
345
                : itemRepository.selectByIds(itemIds).stream()
341
                .collect(Collectors.toMap(Item::getId, item -> item));
346
                        .collect(Collectors.toMap(Item::getId, item -> item));
342
        Map<Integer, Set<FofoLineItem>> fofoOrderItemIdLineItemMap = fofoOrderItems.stream()
347
        Map<Integer, Set<FofoLineItem>> fofoOrderItemIdLineItemMap = fofoOrderItems.stream()
343
                .collect(Collectors.toMap(FofoOrderItem::getId, FofoOrderItem::getFofoLineItems));
348
                .collect(Collectors.toMap(FofoOrderItem::getId, FofoOrderItem::getFofoLineItems));
344
 
349
 
345
        Map<Integer, List<CustomerReturnItem>> foiIdCustomerReturnInventoryItemsMap = new HashMap<>();
350
        Map<Integer, List<CustomerReturnItem>> foiIdCustomerReturnInventoryItemsMap = new HashMap<>();
346
        Map<Integer, Integer> inventoryItemBilledQtyMap = new HashMap<>();
351
        Map<Integer, Integer> inventoryItemBilledQtyMap = new HashMap<>();
Line 374... Line 379...
374
            model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
379
            model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
375
        } else {
380
        } else {
376
            model.addAttribute("customerBillingAddress", "");
381
            model.addAttribute("customerBillingAddress", "");
377
 
382
 
378
        }
383
        }
379
        model.addAttribute("customerBillingAddressObj", customerAddress);
384
        model.addAttribute("customerBillingAddressObj",
-
 
385
                this.billingAddressOrCustomerFallback(customerAddress, fofoOrder.getCustomerId()));
380
        model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
386
        model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
381
        model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
387
        model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
382
        model.addAttribute("insurancePolicies", insurancePolicies);
388
        model.addAttribute("insurancePolicies", insurancePolicies);
383
        model.addAttribute("markDefective", this.markDefective(fofoOrder));
389
        model.addAttribute("markDefective", this.markDefective(fofoOrder));
384
        return "sale-details";
390
        return "sale-details";
Line 2146... Line 2152...
2146
 
2152
 
2147
        return "response";
2153
        return "response";
2148
 
2154
 
2149
    }
2155
    }
2150
 
2156
 
-
 
2157
    /**
-
 
2158
     * The billing-address object the view calls {@code getName()} / {@code getPhoneNumber()} on.
-
 
2159
     *
-
 
2160
     * <p>A plain POS sale does not require an address (only insurance does), so ~140k orders carry
-
 
2161
     * {@code customerAddressId = 0} and the lookup returns null. Passing that null through means
-
 
2162
     * Velocity cannot resolve the reference and prints the literal
-
 
2163
     * {@code $customerBillingAddressObj.getName()} on the screen. Fall back to the customer's own
-
 
2164
     * name and mobile, which is what the invoice PDF already does via
-
 
2165
     * {@code OrderServiceImpl.createCustomAddressWithoutId} — so the screen and the invoice agree.
-
 
2166
     *
-
 
2167
     * <p>The fallback is transient and never persisted. A missing customer row is swallowed on
-
 
2168
     * purpose: this only feeds a display field, and throwing would turn blank text into a 500.
-
 
2169
     */
-
 
2170
    private CustomerAddress billingAddressOrCustomerFallback(CustomerAddress customerAddress, int customerId) {
-
 
2171
        if (customerAddress != null) {
-
 
2172
            return customerAddress;
-
 
2173
        }
-
 
2174
        CustomerAddress fallback = new CustomerAddress();
-
 
2175
        if (customerId != 0) {
-
 
2176
            try {
-
 
2177
                Customer customer = customerRepository.selectById(customerId);
-
 
2178
                fallback.setName(customer.getFirstName());
-
 
2179
                fallback.setLastName(customer.getLastName());
-
 
2180
                fallback.setPhoneNumber(customer.getMobileNumber());
-
 
2181
            } catch (ProfitMandiBusinessException e) {
-
 
2182
                LOGGER.warn("No customer {} for billing-address fallback", customerId, e);
-
 
2183
            }
-
 
2184
        }
-
 
2185
        return fallback;
-
 
2186
    }
-
 
2187
 
2151
}
2188
}
2152
 
2189