Creating Bills and Cancel Sale Operations
Start course
2h 34m

In this course, we will learn the concepts of microservice and spring framework with a focus on Spring Boot.

Learning Objectives

  • Understanding Spring Boot

Intended Audience

  • Beginner Java developers
  • Java developers interested in learning how to Build and Deploy RESTful Web Services
  • Java Developers who want to develop web applications using the Spring framework
  • Java Developers who want to develop web applications with microservices
  • Java Developers who wish to develop Spring Boot Microservices with Spring Cloud


  • Basic Java knowledge

Hello, dear friends. In this video, we will continue creating bills and cancel the sale operation, so let's begin. In the previous video, we created our createBill page. Let's now save bill action in the EmployeeController. First our method must be PostMapping, The path is saveBill. We will get model from the form, so we need ModelAttributes. The model will be Bill. Also, we need HttpsServeletResponse. First, we need all bills. Now, in this list, we have to find the unconfirmed bill. Create an instance from the bill. Now, find the unconfirmed bill. Set the unconfirmed bill to the new bill and we will break the loop. We made this to get bill ID and bill date only because we have already created a bill when we sold the product. In this section, we will update our bill only. Now, set values one by one.

Admin controller must be false because we will make this in the AdminController. Employee confirmed true. bill date, name and surname, total price, Now, save. After saving, we have to clear the basket. Get all products. Make all products In_basket attribute false. Save soldProduct. This will be enough for now. Let's redirect the page to the EmployeeProduct list page.

Okay, that looks good. After confirming the bill on the employee page, we need to confirm this bill on the admin page as well. So, we need an unconfirmed bill list page for admin. We will make this in the following videos, but first let's try. Run the project. Go to the basket now save bill. Go to the basket page again. And as you can see, our basket is empty now. Let's perform a new sale operation because we also need to cancel these sales. As you can see, we have three products in our basket. Now, we can cancel the sale. First, we have to set an action to the 'Cancel' button. Action will be cancelTheSale.

Now, open EmployeeController, We need a new method with GetMapping. Path will be cancelTheSale. Method name, cancel sale and the method must take HttpServeletResponse as parameter. First, we need all soldProducts. Now, we need an empty SoldProduct list to hold selected soldProducts. billId is zero. Let's set all SoldProduct list to the for. If sp.isIn_basket, we will add the sold product to the selected product list. Now, we will delete the soldProduct and we will get billId from soldProduct. Now, we have to delete this bill also. Okay, done. The last process is adding stocks to the total stock.

For SoldProduct in selected soldProducts get ProductById. Now, add selected soldProducts piece to the total product stock. Now, save. Okay, that's enough for now. Let's redirect the page to the EmployeeProduct list page. Okay, done. Now, let's try the cancel operation. Run the project and log in as employee. Open the EmployeeProduct list page. Look at Lenovo product amount.

Go to the basket. Cancel. Now, let's look at Lenovo's stock amount again. Okay, done. Now, we have completed the canceling process. In the next video, we will confirm bills with the AdminController. So, I will see you there.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.