Changeset 89865ae


Ignore:
Timestamp:
01/06/23 21:29:06 (23 months ago)
Author:
andrejtodorovski <82031894+andrejtodorovski@…>
Branches:
main
Children:
4d67d70
Parents:
cab5859
Message:

Added price and total price in currentOrder

Location:
src/main
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/autopartz/controller/HomeController.java

    rcab5859 r89865ae  
    22
    33import com.example.autopartz.model.*;
     4import com.example.autopartz.model.DTO.CurrentOrderDTO;
    45import com.example.autopartz.model.DTO.OrderInfo;
    56import com.example.autopartz.model.manytomany.OrderContainsPart;
     
    4041    private final PartManufacturersReportRepository partManufacturersReportRepository;
    4142    private final MostPurchasedPartRepository mostPurchasedPartRepository;
     43    private final PriceService priceService;
    4244    public HomeController(LoginService loginService, PartService partService, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, CarService carService, CategoryService categoryService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository, WarehouseRepository warehouseRepository,
    43                           OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveriesInProgressRepository deliveriesInProgressRepository, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, CarCategoryReportRepository carCategoryReportRepository, PartManufacturersReportRepository partManufacturersReportRepository, MostPurchasedPartRepository mostPurchasedPartRepository) {
     45                          OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveriesInProgressRepository deliveriesInProgressRepository, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, CarCategoryReportRepository carCategoryReportRepository, PartManufacturersReportRepository partManufacturersReportRepository, MostPurchasedPartRepository mostPurchasedPartRepository, PriceService priceService) {
    4446        this.loginService = loginService;
    4547        this.partService = partService;
     
    5860        this.partManufacturersReportRepository = partManufacturersReportRepository;
    5961        this.mostPurchasedPartRepository = mostPurchasedPartRepository;
     62        this.priceService = priceService;
    6063    }
    6164
     
    9093            model.addAttribute("hasError",false);
    9194            model.addAttribute("order",o);
    92             model.addAttribute("parts",orderService.findById(o.getOrderid()).getPartList());
     95            List<CurrentOrderDTO> list = new ArrayList<>();
     96            int total = 0;
     97            List<OrderContainsPart> qList = orderContainsPartRepository.findAllByOrderid(o.getOrderid());
     98            for (int i = 0; i < qList.size(); i++) {
     99                int pr = qList.get(i).getQuantity_order()*
     100                        priceService.findPriceForPart(partService.findById(qList.get(i).getPartid())).stream().findFirst().get().getAmount();
     101                CurrentOrderDTO temp = new CurrentOrderDTO(
     102                        partService.findById(qList.get(i).getPartid()).getName(),
     103                        partService.findById(qList.get(i).getPartid()).getManufacturer().getName(),
     104                        qList.get(i).getQuantity_order(),
     105                        pr);
     106                list.add(temp);
     107                total+=pr;
     108            }
     109            model.addAttribute("total",total);
     110            model.addAttribute("parts",list);
    93111        }
    94112        model.addAttribute("bodyContent","currentOrder");
  • src/main/resources/templates/currentOrder.html

    rcab5859 r89865ae  
    33    <div th:if="${!hasError}">
    44        <h3 class="mt-3 mb-3">
    5             Нарачка за корисник : <span th:text="${order.getUser().getUsername()}"></span>
     5            Тековна нарачка за корисник : <span th:text="${order.getUser().getUsername()}"></span>
    66        </h3>
    77        <table class="table table-bordered">
    88            <thead class="thead-dark">
    99            <tr>
    10                 <th>Name</th>
    11                 <th>Manufacturer</th>
     10                <th>Име</th>
     11                <th>Производител</th>
     12                <th>Количина</th>
     13                <th>Вкупна цена</th>
    1214            </tr>
    1315            </thead>
    1416            <tbody>
    1517            <tr th:each="part : ${parts}">
    16                 <td th:text="${part.getName()}"></td>
    17                 <td th:text="${part.getManufacturer().getName()}"></td>
     18                <td th:text="${part.getPartName()}"></td>
     19                <td th:text="${part.getManufacturerName()}"></td>
     20                <td th:text="${part.getQuantity()}"></td>
     21                <td th:text="${part.getPrice()}"></td>
     22
    1823            </tr>
    1924            </tbody>
    2025        </table>
     26        <h3>Вкупен износ : <span th:text="${total}"></span></h3>
    2127        <form th:action="@{'/part/delivery/'}">
    2228            <button class="btn btn-primary btn-block btn-lg" type="submit">Испрати нарачка</button>
Note: See TracChangeset for help on using the changeset viewer.