Billing System using Spring Boot - Purchase Order flow walkthrough in Billing Software

Billing System using Spring Boot - Purchase Order flow walkthrough in Billing Software
Billing Software using Spring Boot

Welcome back friends, In this story, we will going to explore the Purchase order flow part of the Billing System. Following is DB Model for Purchase Order flow.

Billing Software using Spring Boot

The Purchase Order table linked with three tables which are the “Vendor”,” Tax” and “Category” Table.
What is the Role of Purchase Order in Billing System?
If the seller wants to sell some product, the Seller must buy the Product from the Manufacturer or Wholesale Retailer. Whenever sellers buy the Product from the Manufacturer, the Purchase information we need to store in the Purchase Order table.

The Purchase order table mapped with Vendor Table. Using this relation we can find out who is the Manufacturer of a particular Product. Through the Tax table, we can map what is the GST % of a particular product in the Table. Through category, we can find out what category of the Product.

Billing software using Spring Boot
Billing software using Spring Boot

The above columns are important columns. The Unit Price holds the per price product, the Quantity Column holds the how many items purchased from Vendor, Tax column tells the Tax percentage of Product Item, Tax Amount gives the Total tax amount from Total Amount, Grand Total gives Tax Amount + Grand Total.

I have used the following class three class for implementing Purchase Order flow.
PurchaseOrderController
PurchaseOrderService
PurchaseOrderRepository

PurchaseOrderController

The following methods are defined in the PurchaseOrderController. This class uses the PurchaseOrderService class to perform CRUD Operation.

// This adds new Purchase Order 
@PostMapping("/purchase")
public ResponseEntity<ResponseMessage<?>> add(@RequestBody PurchaseOrderInfo purchaseOrderInfo) {
    ResponseMessage responseMessage  = purchaseOrderService.save(purchaseOrderInfo);
    return new ResponseEntity<ResponseMessage<?>>(responseMessage, HttpStatus.CREATED);
}
// Thisupdate the existing Purchase Order
@PutMapping("/purchase")
public ResponseEntity<ResponseMessage<?>> update(@RequestBody PurchaseOrderInfo purchaseOrderInfo) {
    ResponseMessage responseMessage  = purchaseOrderService.save(purchaseOrderInfo);
    return new ResponseEntity<ResponseMessage<?>>(responseMessage, HttpStatus.OK);
}
// This fetch all Purchase Order data
@GetMapping("/purchase")
public ResponseEntity<ResponseMessage<?>> getAll() throws Exception{
    ResponseMessage responseMessage  = purchaseOrderService.findAll();
    return new ResponseEntity<ResponseMessage<?>>(responseMessage, HttpStatus.OK);
}
// This fetch a Purchase order by Id
@GetMapping("/purchase/{id}")
public ResponseEntity<ResponseMessage<?>> get(@PathVariable String id) throws Exception{
    ResponseMessage responseMessage  = purchaseOrderService.findResourceById(id);
    return new ResponseEntity<ResponseMessage<?>>(responseMessage, HttpStatus.OK);
}

PurchaseOrderService

This class is having the following method implementation

// This save method to save or update the Purchase order data. It
// accepts the PurchaseOrderInfo as parameter. This object converted
// as Purchase Order Entity Object using MapStruct Framework.
public ResponseMessage<PurchaseOrderInfo> save(PurchaseOrderInfo purchaseOrderInfo) {

    PurchaseOrder purchaseOrder = PurchaseOrderMapper.INSTANCE
            .purchaseOrderInfoToPurchaseOrder(purchaseOrderInfo);
// The following code fetch Category, Vendor, and Tax data and set
// into PurchaseOrder entity Obbject
Category category = categoryRepository.findById(purchaseOrderInfo.getCategory().getId()).orElse(null);
    purchaseOrder.setCategory(category);
    Vendor vendor = vendorRepository.getOne(purchaseOrder.getVendor().getId()) ;
    purchaseOrder.setVendor(vendor);
    Tax tax = taxRepository.getOne(purchaseOrder.getTax().getId());
    purchaseOrder.setTax(tax);
// This getId is null, creating new Purchase Order and populating
// Purchase Order data. Then, calculating Tax details for a given // 
// Unit Price, Tax Percentage, and Quantity. I have created a 
// generic class called "TaxCalculation" which calculates the Tax.
// The TaxCalculation accepts TaxCalculationInput as parameter. 
// Using this parameter, it calculates the Tax and returns back to 
// TaxCalculationResponse. Using this response class I am populating // tax calculation in the PurchaseOrder entity table. Then, save to // DB.
    if(purchaseOrderInfo.getId() == null) {
        String purchaseOrderCode = codeGenerator.newCode(CodeType.PURCHASE_ORDER_CODE);
        purchaseOrder.setPurchaseOrderCode(purchaseOrderCode);
        TaxCalculationInput taxCalculationInput =
                new TaxCalculationInput(                    purchaseOrder.getUnitPrice(),purchaseOrder.getTax().getTaxPercentage(),purchaseOrder.getQuantity());
        TaxCalculationResponse taxCalculationResponse
                = taxCalculation.calculateTax(taxCalculationInput);
        purchaseOrder.setTotalAmount(taxCalculationResponse.getTotalAmount());
        purchaseOrder.setGrandTotal(taxCalculationResponse.getGrandTotal());
        purchaseOrder.setTaxAmount(taxCalculationResponse.getTaxAmount());
    }
    PurchaseOrder newPurchaseOrder = purchaseOrderRepository.save(purchaseOrder);
    PurchaseOrderInfo newPurchaseOrderInfo = PurchaseOrderMapper
            .INSTANCE.purchaseOrderToPurchaseOrderInfo(newPurchaseOrder);
    ResponseMessage<PurchaseOrderInfo> responseMessage = ResponseMessage.withResponseData(newPurchaseOrderInfo,"","");
    return responseMessage;
}
// The following method for fetching PurchaseOrder data by Id
@Override
public ResponseMessage findResourceById(String id) throws Exception {
    PurchaseOrder purchaseOrder = purchaseOrderRepository.findById(Long.parseLong(id)).orElse(null);
    PurchaseOrderInfo purchaseOrderInfo = PurchaseOrderMapper.INSTANCE.purchaseOrderToPurchaseOrderInfo(purchaseOrder);
    ResponseMessage responseMessage = ResponseMessage.withResponseData(purchaseOrderInfo,"","");
    return responseMessage;
}
// The following method for fetching All PurchaseOrder
@Override
public ResponseMessage findAll() throws Exception {
    List<PurchaseOrderInfo> purchaseOrderInfos = new ArrayList<>();
    List<PurchaseOrder> purchaseOrders = purchaseOrderRepository.findAll();
    for (PurchaseOrder purchaseOrder: purchaseOrders) {
        PurchaseOrderInfo purchaseOrderInfo = PurchaseOrderMapper.INSTANCE.purchaseOrderToPurchaseOrderInfo(purchaseOrder);
        purchaseOrderInfos.add(purchaseOrderInfo);
    }
    ResponseMessage responseMessage = ResponseMessage.withResponseData(purchaseOrderInfos,"","");
    return responseMessage;
}

PurchaseOrderRepository

This repository class for performing CRUD Operation. This Repository class used in PurchaseOrderService class to perform the CRUD Operation.

 


Please follow our ITGARDEN YouTube channel for Billing System Project development work using Spring Boot. The Project source code absolutely free. This project is very good for those who are looking for real-time project experience in Spring Boot. To understand the Billing System Project code, watch all Billing System-related YouTube videos from this link. Click Here
Our YouTube Channel
https://www.youtube.com/channel/UChj5CeuWaHIFr4RkXoG3iJA?view_as=subscriber
Please follow me on Medium.com for all billing system related stories and Java-based technical Articles
https://suresh-stalin.medium.com/

Close Menu
×
×

Cart