Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Comics

    Git – Bad Practices

    Node.js

    Dockerization of Node.JS Applications on Amazon Elastic Containers

    Node.js

    Why Fastify is a better Nodejs framework for your next project compared to Express

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Tuesday, September 9
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / POS Tutorial / Create simple POS with React.js, Node.js, and MongoDB #16: Order Screen
    JavaScript

    Create simple POS with React.js, Node.js, and MongoDB #16: Order Screen

    Krissanawat KaewsanmuangBy Krissanawat KaewsanmuangOctober 14, 2020No Comments16 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Create simple POS with React.js, Node.js, and MongoDB #16: Order Screen
    Create simple POS with React.js, Node.js, and MongoDB #16: Order Screen
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Create simple POS with React.js, Node.js, and MongoDB #16: Order Screen
    Create simple POS with React.js, Node.js, and MongoDB #16: Order Screen

    Defenition: POS – “Point of Sale”. At the point of sale, the merchant calculates the amount owed by the customer, indicates that amount, may prepare an invoice for the customer (which may be a cash register printout), and indicates the options for the customer to make payment.

    In the previous chapter, we worked on role-based access control feature for our react app. We had two roles: admin and employee. We used those user roles for conditional rendering with the react-rbac-guard package.

    In this chapter, we are going to create an order page. The order page displays the products and the calculator to help calculate the total price. Finally, we will save the transaction to the database.

    For the order page, the idea is to have to columns: lefts to display products and right to display total price and products in the cart.

    Displaying Products

    First, we are going to create a column that displays the number of products for sale. We are going to display them in a grid style by creating a new component called order.js. Now, we will create a file named create.js and work on it.

    In create.js, we need to import the required component, hooks, and product actions as displayed in the code snippet below:

    import React, { useEffect } from "react";
    import { useSelector, useDispatch } from "react-redux";
    import * as productActions from "../../actions/product.action";
    export default (props) => {}

    Then, we fetch the product data using useDispatch hook variable inside the useEffect hook as directed in the code snippet below:

    const dispatch = useDispatch();
    useEffect(() => {
        dispatch(productActions.Index());
      }, []);

    Next, we need to import a reducer named productReducer using useSelector hook in order to get the getting product data as displayed in the code snippet below:

    const productReducer = useSelector(({ productReducer }) => productReducer);

    Now, we need to create a function to fetch all products. First, we create a product catalog by wrapping it in the card element and using the classes to show four-card items in a row. Each card will have the data concerning a single product. There will also be a button to add the items to the cart. The overall coding implementation of the function is provided in the code snippet below:

    const renderProductRows = () => {
        if (productReducer.result) {
          const { result } = productReducer;
          return (
            <div className="row">
              {result &&
                result.map((item, index) => {
                  return (
                    <>
          {index % 3 === 0 && <div class="w-100 d-lg-none mt-4"></div>}
                      <div class="col-md-6 col-lg-4 col-xl-3 py-2">
                        <div className="card h-100">
                          <img
                            className="card-img-top img-fluid"
                            src={
                              process.env.REACT_APP_PRODUCT_IMAGE_PATH +
                              "/" +
                              item.image
                            }
                            alt="Card image cap"
                          />
                          <div className="card-block">
                            <h4 className="card-title">{item.name}</h4>
                            <p className="card-text">Price {item.price}</p>
                            <p className="card-text">
                              <small className="text-muted">
                                remain {item.stock}
                              </small>
                            </p>
                           <a href="#" class="btn btn-primary btn-block ">
                              Add to Card
                            </a>                      
    </div>
                        </div>
                      </div>
                    </>
                  );
                })}
            </div>
          );
        } else {
          return "loading...";
        }
      };

    Hence, we will get the result as displayed in the following screenshot:

    Product Catalog
    Product Catalog

    Our display Product section is complete. Now, we move to implement the right column which will have the total cost and items in the cart.

    Cart section

    Here, we are going to implement the right side of the column called the cart section. For that, we need to add another column just beside the Product Catalog section.

    In this section, we will show the total price and tax as well as a list of items in the cart. We will use number format to manage float number and create a new action named shop to handle all calculations.

    First, we need to create a new action and reducer in order to handle the cart operations.

    Hence, in the constant.js file, we need to create new constants as directed in the code snippet below:

    // Shop Page
    export const SHOP_FETCHING = "SHOP_FETCHING";
    export const SHOP_SUCCESS = "SHOP_SUCCESS";
    export const SHOP_FAILED = "SHOP_FAILED";
    export const SHOP_UPDATE_ORDER = "SHOP_UPDATE_ORDER";
    export const SHOP_UPDATE_PAYMENT = "SHOP_UPDATE_PAYMENT";

    Then, we need to create a new reducer named shop to handle updates in the cart as well as payment. The initial states are also to be defined. The overall coding implementation of the reducer is provided in the code snippet below:

    import { SHOP_UPDATE_ORDER, SHOP_UPDATE_PAYMENT } from "../constants";
    const initialState = {
      mOrderLines: [],
      mTotalPrice: 0,
      mTaxAmt: 0,
      mIsPaymentMade: false,
      mGiven: 0
    };
    export default (state = initialState, { type, payload }) => {
      switch (type) {
        case SHOP_UPDATE_ORDER:
          return {
            ...state,
            mOrderLines: payload.orderLines,
            mTotalPrice: payload.totalPrice,
            mTaxAmt: payload.taxAmt
          };
        case SHOP_UPDATE_PAYMENT:
          return {
            ...state,
            mIsPaymentMade: payload.isPaymentMade,
            mGiven: payload.given
          };
        default:
          return state;
      }
    };

    Next, we need to create an action that accesses the modification of reducer data. So, we need to create a new action named shop and add a function to handle orders. The coding implementation of action functions are provided in the code snippet below:

    import { httpClient } from "./../utils/HttpClient";
    import { SHOP_UPDATE_ORDER, SHOP_UPDATE_PAYMENT, server } from "../constants";
    const setStateShoptoUpdateOrder = (payload) => ({
      type: SHOP_UPDATE_ORDER,
      payload: payload,
    });
    const doUpdateOrder = (dispatch, orderLines) => {
      // debugger;
      let totalPrice = 0;
      let taxAmt = 0;
      for (let item of orderLines) {
        totalPrice += item.price * item.qty;
      }
      taxAmt = totalPrice * 0.07;
    dispatch(
        setStateShoptoUpdateOrder({
          orderLines,
          totalPrice,
          taxAmt,
        })
      );
    };
    export const addOrder = (item) => {
      return (dispatch, getState) => {
        let orderLines = getState().shopReducer.mOrderLines;
        let index = orderLines.indexOf(item);
        if (index === -1) {
          item.qty = 1;
          orderLines.unshift(item);
        } else {
          orderLines[index].qty++;
        }
    doUpdateOrder(dispatch, orderLines);
      };
    };
    export const removeOrder = (product) => {
      return (dispatch, getState) => {
        let orderLines = getState().shopReducer.mOrderLines;
        var foundIndex = orderLines.indexOf(product);
    orderLines.map((item) => {
          if (item.product_id === product.product_id) {
            item.qty = 1;
          }
        });
        orderLines.splice(foundIndex, 1);
    doUpdateOrder(dispatch, orderLines);
      };
    };

    Now, it is time to implement the UI. We will get the cart and price states from the reducer to be rendered into the UI. For now, we need to create a function named CartSection and use NumberFormat component to display price and table to display the cart items. The overall UI coding implementation is provided in the code snippet below:

    const CartSection = (index) => {
        return (
          <>
            <div className="row">
              <h4>Tax 7% </h4>
              <NumberFormat
                value={shopReducer.mTaxAmt}
                displayType={"text"}
                thousandSeparator={true}
                decimalScale={2}
                fixedDecimalScale={true}
                prefix={"฿"}
              />
            </div>
            <div className="row">
              <h4>Total</h4>
              <NumberFormat
                value={shopReducer.mTotalPrice}
                displayType={"text"}
                decimalScale={2}
                thousandSeparator={true}
                prefix={"฿"}
              />
              {shopReducer.mTotalPrice > 0 && !shopReducer.mIsPaymentMade && (
                <a
                  href="#"
                  class="btn btn-primary btn-block"
                  onClick={() => dispatch(shopActions.togglePaymentState())}
                >
                  Payment
                </a>
              )}
              {shopReducer.mOrderLines.length > 0 ? (
                <table class="table table-hover shopping-cart-wrap">
                  <thead class="text-muted">
                    <tr>
                      <th scope="col">Item</th>
                      <th scope="col" width="120">
                        Qty
                      </th>
                      <th scope="col" width="120">
                        Price
                      </th>
                      <th scope="col" class="text-right" width="200">
                        Delete
                      </th>
                    </tr>
                  </thead>
                  <tbody>{renderOrder()}</tbody>
                </table>
              ) : (
                <img src={cashier} style={{ width: 200 }} />
              )}
            </div>
          </>
        );
      };

    hence, we will get the result as displayed in the following screenshot:

    Read More:  Exploring the Power of JavaScript Proxies and Reflect API
    Cart Section
    Cart Section

    As we can notice, the state in the reducer is empty. Hence, we get the total price as 0 and no items in the cart section.

    In order to add the item to the cart and calculate the price, we dispatch the addOrder action from shopActions in the Add to Cart button as directed in the code snippet below:

           <Link
                type="button"
                class="btn btn-primary"
                onClick={() =>  dispatch(shopActions.addOrder(item))}
                 > <i class="fa fa-cart-plus"></i> Add to Cart
          </Link>

    Then, we add the updated data in the product when we add the products to the cart stock. Hence, the cart data will update as well. For that, we do the conditional rendering as directed in the code snippet below:

    <p className="card-text">
                              <small className="text-muted">
                                remain{" "}
                                {item.qty ? item.stock - item.qty : item.stock}{" "}
                                items
                              </small>
                              {isSelectedItem(item) && (
                                <div
                                  style={{
                                    display: "flex",
                                    flexDirection: "row",
                                  }}
                                >
                                  <small className="text-muted">
                                    X {item.qty} items
                                  </small>
                                </div>
                              )}
                            </p>

    The function to count the number of items in the cart is shown in the code snippet below:

    const isSelectedItem = (product) => {
        let index = shopReducer.mOrderLines.indexOf(product);
        return index !== -1;
      };

    Hence, we will get the result as displayed in the demo below:

    Add to Cart
    Add to Cart

    Now, we need to create a simple table element to display products in the cart. We will also add a remove feature to it in order to remove the product from the cart if needed. For that, we need to create a new function called renderOrder and use the code from the following code snippet:

    const renderOrder = () => {
        const { mOrderLines } = shopReducer;
         return mOrderLines.map((item) => {
          return (
            <tr>
              <td>{item.name}</td>
              <td>{item.qty}</td>
              <td>{item.price}</td>
              <td>
                <Link
                  type="button"
                  class="btn btn-danger"
                  onClick={() => dispatch(shopActions.removeOrder(item))}
                >
                  <i class="fa fa-trash"></i>
                </Link>
              </td>
            </tr>
          );
        });
      };

    Then, we need to add the function to the main table as displayed in the code snippet below:

    {shopReducer.mOrderLines.length > 0 ? (
                <table class="table table-hover shopping-cart-wrap">
                  <thead class="text-muted">
                    <tr>
                      <th scope="col">Item</th>
                      <th scope="col" width="120">
                        Qty
                      </th>
                      <th scope="col" width="120">
                        Price
                      </th>
                      <th scope="col" class="text-right" width="200">
                        Delete
                      </th>
                    </tr>
                  </thead>
                  <tbody>{renderOrder()}</tbody>
                </table>
              ) : (
                <img src={cashier} style={{ width: 200 }} />
              )}

    Hence, we will get the result as displayed in the demo below:

    List Order in Cart
    List Order in Cart

    Here, we can see that as we add an item to the card the item number decreases in the product section and the items added increases in the cart section along with updates to the price as well.

    Calculator

    Now, we are going to create a simple calculator that will allow employees to calculate the change easily. The calculator will be displayed once an employee clicks on the payment button.

    First, in the shop.action.js file, we add functions to send order data and toggle the calculator. The coding implementation of submitPayment and togglePaymentState functions are provided in the code snippet below:

    export const submitPayment = (data) => {
      return (dispatch, getState) => {
        httpClient.post(server.ORDER_URL, data).then(() => {
          swal({
            title: "Your are made sale success",
            icon: "success",
            buttons: true,
          });
          getState().shopReducer.mOrderLines = [];
          dispatch({
            type: SHOP_UPDATE_PAYMENT,
            payload: {
              isPaymentMade: false,
              given: 0,
            },
          });
        });
      };
    };
    export const togglePaymentState = () => {
      return (dispatch, getState) => {
        dispatch({
          type: SHOP_UPDATE_PAYMENT,
          payload: {
            isPaymentMade: !getState().shopReducer.mIsPaymentMade,
            given: !getState().shopReducer.mGiven,
          },
        });
      };
    };

    Now in the order component, we need to create a new component named Payment in order to contain the calculator components. Then, we need to import the Payment component to the Create component as directed in the code snippet below:

    import Payment from "./payment";

    Next, we need to create a function called renderPayment for conditional rendering and passing the order data in the cart to the calculator. The implementation of the function is provided in the code snippet below:

    const renderPayment = () => {
        return (
          <div className="col-md-8" style={{ maxHeight: 710 }}>
            <Payment order={JSON.stringify(shopReducer.mOrderLines)} />
          </div>
        );
      };

    Now, we can toggle between product catalog and calculator using the conditional rendering as shown in the code snippet below:

    <section className="content">
            <div className="container-fluid">
              <div className="row">
                <div
                  className="col-9"
                  data-spy="scroll"
                  data-target=".navbar"
                  data-offset="50"
                >
                  {shopReducer.mIsPaymentMade
                    ? renderPayment()
                    : renderProductRows()}
                </div>

    Now to implement the calculator screen, we import the necessary components in the payment.js file as shown in the code snippet below:

    import React, { useState, useEffect } from "react";
    import { useDispatch, useSelector } from "react-redux";
    import { TransactionRequest } from "./transaction";
    import * as shopActions from "../../actions/shop.action";
    import { Formik, Form, Field } from "formik";

    First, we are going to create a calculator UI. The idea is simple. Each button will represent a banknote and coin that a customer pays and subtracts from the order total. After subtraction, we can display the change to be returned to the customer. This will make it easier for employees to calculate money to be returned to the customers.

    Then, we will have two input fields: one to display the total money that customer pays and another to display change to be returned to the customer.

    Here, we will have three action button:

    • Exact for when there is no change to be returned.
    • Clear in order to reset the data.
    • Submit to save data of the successful sale to database

    The coding implementation for this is provided in the code snippet below:

    const showForm = ({ values, setFieldValue }) => {
        return (
          <div>
            <div className="row">
              <div className="col">
                {isMustChanged(values) && (
                  <div class="input-group mb-3">
                    <div class="input-group-prepend">
                      <span class="input-group-text" id="basic-addon1">
                        Change
                      </span>
                    </div>
                    <input
                      type="text"
                      readonly="readonly"
                      name="change"
                      value={values.change}
                      className="form-control"
                      placeholder="Change"
                    />
                  </div>
                )}
                <div class="input-group mb-3">
                  <div class="input-group-prepend">
                    <span class="input-group-text" id="basic-addon1">
                      Given
                    </span>
                  </div>
                  <input
                    type="text"
                    readonly="readonly"
                    name="given"
                    value={values.given}
                    className="form-control"
                    placeholder="Given"
                  />
                </div>
              </div>
            </div>
            <div className="row">
              <div className="col">
                <button
                  onClick={() => onClickGiven(1000, values.given, setFieldValue)}
                  className="btn btn-primary btn-lg btn-block"
                  type="button"
                >
                  1000
                </button>
              </div>
              <div className="col">
                <button
                  onClick={() => onClickGiven(500, values.given, setFieldValue)}
                  className="btn btn-primary btn-lg btn-block"
                  type="button"
                >
                  500
                </button>
              </div>
              <div className="col">
                <button
                  onClick={() => onClickGiven(100, values.given, setFieldValue)}
                  className="btn btn-primary btn-lg btn-block"
                  type="button"
                >
                  100
                </button>
              </div>
            </div>
            <div className="row">
              <div className="col">
                <button
                  onClick={() => onClickGiven(50, values.given, setFieldValue)}
                  className="btn btn-primary btn-lg btn-block"
                  type="button"
                >
                  50
                </button>
              </div>
              <div className="col">
                <button
                  onClick={() => onClickGiven(20, values.given, setFieldValue)}
                  className="btn btn-primary btn-lg btn-block"
                  type="button"
                >
                  20
                </button>
              </div>
              <div className="col">
                <button
                  onClick={() => onClickGiven(10, values.given, setFieldValue)}
                  className="btn btn-primary btn-lg btn-block"
                  type="button"
                >
                  10
                </button>
              </div>
            </div>
            <div className="row">
              <div className="col">
                <button className="btn btn-danger btn-lg btn-block" type="button">
                  Clear
                </button>
              </div>
              <div className="col">
                <button
                  onClick={() => onClickExact()}
                  className="btn btn-primary btn-lg btn-block"
                  type="button"
                >
                  Exact
                </button>
              </div>
              <div className="col">
                <button
                  onClick={() => onClickSubmit(values)}
                  className="btn btn-success btn-lg btn-block"
                  type="button"
                >
                  Submit
                </button>
              </div>
            </div>
          </div>
        );
      };
    return (
        <div>
          <Formik initialValues={{ given: 0 }}>{(props) => showForm(props)}</Formik>
        </div>
      );

    Hence, we will get the result as displayed in the demo below:

    Read More:  How to Run API Tests Automatically Every Time Your App Is Deployed using Loadmill
    Activate Calculator
    Activate Calculator

    Here, we can see that as soon as we press the Payment button, a calculator page pops up with three buttons that we mentioned before.

    Now for calculation, we need to create new functions as mentioned below:

    • isMustChanged function to display change input. If an employee doesn’t need to return the change then we simply hide this section.
    • updateChange to update the change value.
    • onClickGiven to sum up all money that the customer pays.
    • onClickExact trigger when no need for any change to be returned. The customer provides the exact fund equal to the money he/she has to pay.

    The coding implementations of these function are provided in the code snippet below:

    const isMustChanged = (values) => {
        try {
          return values.given > shopReducer.mTotalPrice;
        } catch (err) {
          return false;
        }
      };
    const updateChange = (given, setFieldValue) => {
        let change = given - shopReducer.mTotalPrice;
        if (change > 0) {
          setFieldValue("change", change);
        } else {
          setFieldValue("change", 0);
        }
      };
    const onClickGiven = (newValue, oldValue, setFieldValue) => {
        const newGiven = newValue + oldValue;
        console.log(newValue);
        setFieldValue("given", newGiven);
        updateChange(newGiven, setFieldValue);
      };
    const onClickExact = (setFieldValue) => {
        setFieldValue("given", shopReducer.mTotalPrice);
        updateChange(0, setFieldValue);
      };

    Hence, we will get the result as displayed in the demo screenshot below:

    Calculate Change Demo
    Calculate Change Demo

    Saving Order data

    Now, the last step is to save the order data to the database for each successful transaction. For this, we need to create a new endpoint in the backed to receive the order data.

    First, we need to create a schema for the new table named order. We are also going to add an auto-increment field in order to generate the data in sequential order. The schema implementation using mongoose library is provided in the code snippet below:

    const mongoose = require("mongoose");
    const AutoIncrement = require("mongoose-sequence")(mongoose);
    const OrderSchma = mongoose.Schema(
      {
        _id: { type: mongoose.Schema.Types.ObjectId, auto: true },
        total: Number,
        paid: Number,
        change: Number,
        order_list: String,
        payment_type: String,
        payment_detail: String,
        staff_id: { type: mongoose.Schema.Types.ObjectId, required: true },
        comment: String,
        timestamp: { type: Date, default: Date.now },
      },
      { _id: false }
    );
    OrderSchma.plugin(AutoIncrement, { inc_field: "order_id" });
    module.exports = mongoose.model("order", OrderSchma);

    Then, we need to create a new API endpoint named order. The API implementation code is simple. If you have been following this tutorial, you will find it pretty simple. The actual implementation of the endpoint is provided in the code snippet below:

    const express = require("express");
    const router = express.Router();
    const Order = require("./models/order_schema.js");
    router.post("/order", async (req, res) => {
      try {
        let newOrder = await Order.create(req.body);
    res.json({
          result: "success",
          message: "Create Brach data successfully",
        });
      } catch (err) {
        res.json({ result: "error", message: err });
      }
    });

    Hence, we have successfully created an endpoint to store the order data.

    Now, we need to go back to frontend and create a static file to contain default order data that will represent the blank data as directed in the code snippet below:

    export class TransactionRequest {
      subtotal = 0;
      discount = 0;
      shipping_cost = 0;
      tax_percent = 0;
      total = 0;
      paid = 0;
      change = 0;
      order_list = "x";
      payment_type = "x";
      payment_detail = "x";
      staff_id = "x";
      comment = "x";
    }

    In the payment component, we need to create a new function named onClickSubmit which takes order values as parameter. This function works to submit order data. The implementation is given in the code snippet below:

    const onClickSubmit = (values) => {
        let trans = new TransactionRequest();
        trans.total = shopReducer.mTotalPrice;
        trans.paid = values.given;
        trans.change = values.change;
        trans.payment_type = "cash";
        trans.payment_detail = "full";
        trans.staff_id = staff_id;
        trans.order_list = props.order;
        dispatch(shopActions.submitPayment(trans));
      };

    Now, we set up the data and pass it to action using submitPayment . We also add an alert to display the successful sale information as shown in the code snippet below:

    export const submitPayment = (data) => {
      return (dispatch, getState) => {
        httpClient.post(server.ORDER_URL, data).then(() => {
          swal({
            title: "Your are made sale success",
            icon: "success",
            buttons: true,
          });
          getState().shopReducer.mOrderLines = [];
          dispatch({
            type: SHOP_UPDATE_PAYMENT,
            payload: {
              isPaymentMade: false,
              given: 0,
            },
          });
        });
      };
    };

    Hence, we will get the result as displayed in the demo below:

    Submit Order
    Submit Order

    Finally, we have successfully completed the implementation of the order page in our POS system project.

    Your Next Challenge….
    In this tutorial, we completed the hard part to implement the overall UI and functionality of the Order page. Now, the challenge is the easy part that you have to implement. The challenge is to create a simple CRUD operation for Order in order to display the Order history.

    Conclusion

    At last, we have completed one of the difficult parts of this tutorial series. The tutorial was long but interesting with lots of new things to learn. We successfully coded the overall UI and functions of the Order screen. We learned how to display the product section as well as the cart section with the price section. We learned how to calculate the total items, total price as well as implement the calculator to simplify change calculation for employees. The implementation was simple but improvements can be made.

    The coding implementations used in this tutorial chapter are both Frontend and Backend available on Github.

    See you in the next chapter! Good day folks!

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Krissanawat Kaewsanmuang
    • Website
    • X (Twitter)

    Developer Relation @instamobile.io

    Related Posts

    Streamlining Resource Allocation for Enhanced Project Success

    December 18, 2024

    Conducting Effective Post-Project Evaluations: A Guide

    December 16, 2024

    Strategies for Keeping Projects on Track and Meeting Deadlines

    December 10, 2024
    Leave A Reply Cancel Reply

    You must be logged in to post a comment.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    JavaScript May 8, 2020

    Top Seven Remote Working Tools You Simply Need In 2020

    Many team managers even didn’t have the right tools and equipment to set up a professional working environment at home that enhances efficiency and boosts productivity. Using the best tools for remote working is a prerequisite for getting the job done in time, without compromising on the quality, as per the usual high expectations of clients.

    Understanding Python Decorators and How to Use Them Effectively

    May 13, 2023

    Introduction to Micro Frontends: The New Tech on the Block

    June 27, 2019

    Libero Enim Sedfaucibus Turpis Magna Fermentum Justoeget

    January 28, 2020

    Categories

    • AI & Automation
    • Angular
    • ASP.NET
    • AWS
    • B2B Leads
    • Beginners
    • Blogs
    • Business Growth
    • Case Studies
    • Comics
    • Consultation
    • Content & Leadership
    • CSS
    • Development
    • Django
    • E-commerce & Retail
    • Entrepreneurs
    • Entrepreneurship
    • Events
    • Express.js
    • Facebook Ads
    • Finance & Fintech
    • Flask
    • Flutter
    • Franchising
    • Funnel Strategy
    • Git
    • GraphQL
    • Home Services Marketing
    • Influencer & Community
    • Interview
    • Java
    • Java Spring
    • JavaScript
    • Job
    • Laravel
    • Lead Generation
    • Legal & Compliance
    • LinkedIn
    • Machine Learning
    • Marketing Trends
    • Medical Marketing
    • MSP Lead Generation
    • MSP Marketing
    • NestJS
    • Next.js
    • Node.js
    • Node.js Lessons
    • Paid Advertising
    • PHP
    • Podcasts
    • POS Tutorial
    • Programming
    • Programming
    • Python
    • React
    • React Lessons
    • React Native
    • React Native Lessons
    • Recruitment
    • Remote Job
    • SaaS & Tech
    • SEO & Analytics
    • Soshace
    • Startups
    • Swarm Intelligence
    • Tips
    • Trends
    • Vue
    • Wiki
    • WordPress
    Top Posts

    Happy Programmer’s Day!

    Programming September 12, 2016

    Exploring Modern JavaScript: A Comprehensive Guide to ES6 and Beyond

    JavaScript April 1, 2023

    Advanced Node.Js: A Hands on Guide to Event Loop, Child Process and Worker Threads in Node.Js

    JavaScript January 24, 2020

    Maximizing Impact: Strategies for SaaS & Technology Marketing

    SaaS & Tech August 27, 2025

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    About Us
    About Us

    Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

    7901 4th St N, Suite 28690
    Saint Petersburg, FL 33702-4305
    Phone: 1(877)SOSHACE

    Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
    Our Picks
    JavaScript

    Server-Side Rendering with Vue.js and Nuxt.js

    JavaScript

    Web Development Newsletters: JavaScript, React, Vue, Angular Email Newsletters

    JavaScript

    Top AngularJS interview questions

    Most Popular

    10 Practices You Should Avoid to Become a Good Java Developer

    Java

    Essential Recruitment Metrics: Measurement Strategies and Impact

    Recruitment

    Build Real-World React Native App #10 : Setup in-App Purchase in iOS

    React Native
    © 2025 Soshace Digital.
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.