Skip to content

Commit

Permalink
Working With Sell
Browse files Browse the repository at this point in the history
  • Loading branch information
rupomsoft committed Oct 26, 2022
1 parent b004b38 commit 5bac41e
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const PurchaseProductsModel = require("../../models/Purchases/PurchaseProductsMo
const ReturnProductsModel = require("../../models/Returns/ReturnProductsModel");
const DeleteService = require("../../services/common/DeleteService");
const DetailsByIDService = require("../../services/common/DetailsByIDService");
const DropDownService = require("../../services/common/DropDownService");


exports.CreateProducts=async (req, res) => {
Expand Down Expand Up @@ -62,3 +63,7 @@ exports.DeleteProduct=async (req, res) => {



exports.ProductsDropDown=async (req, res) => {
let Result= await DropDownService(req,DataModel,{_id:1,Name:1})
res.status(200).json(Result)
}
1 change: 1 addition & 0 deletions Inventory/inventory-mern-backend/src/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ router.post("/UpdateProducts/:id",AuthVerifyMiddleware,ProductsController.Update
router.get("/ProductsList/:pageNo/:perPage/:searchKeyword",AuthVerifyMiddleware,ProductsController.ProductsList);
router.get("/DeleteProduct/:id",AuthVerifyMiddleware,ProductsController.DeleteProduct);
router.get("/ProductsDetailsByID/:id",AuthVerifyMiddleware,ProductsController.ProductsDetailsByID);
router.get("/ProductsDropDown",AuthVerifyMiddleware,ProductsController.ProductsDropDown);


//Purchases
Expand Down
8 changes: 7 additions & 1 deletion Inventory/inventory-mern-frontend/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import {HideLoader, ShowLoader} from "../redux/state-slice/settings-slice";
import axios from "axios";
import {ErrorToast} from "../helper/FormHelper";
import {getToken} from "../helper/SessionHelper";
import {SetCustomerDropDown, SetSaleList, SetSaleListTotal} from "../redux/state-slice/sale-slice";
import {SetCustomerDropDown, SetProductDropDown, SetSaleList, SetSaleListTotal} from "../redux/state-slice/sale-slice";
import {BaseURL} from "../helper/config";
import {SetProductBrandDropDown} from "../redux/state-slice/product-slice";
const AxiosHeader={headers:{"token":getToken()}}

export async function SaleListRequest(pageNo, perPage, searchKeyword) {
Expand Down Expand Up @@ -59,15 +58,15 @@ export async function CustomerDropDownRequest() {
export async function ProductDropDownRequest() {
try {
store.dispatch(ShowLoader());
let URL = BaseURL+"/CustomersDropDown";
let URL = BaseURL+"/ProductsDropDown";
const result = await axios.get(URL,AxiosHeader)
store.dispatch(HideLoader())
if (result.status === 200 && result.data['status'] === "success") {
if (result.data['data'].length > 0) {
store.dispatch(SetCustomerDropDown(result.data['data']))
store.dispatch(SetProductDropDown(result.data['data']))
} else {
store.dispatch(SetCustomerDropDown([]));
ErrorToast("No Customer Found");
store.dispatch(SetProductDropDown([]));
ErrorToast("No Product Found");
}
} else {
ErrorToast("Something Went Wrong")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,77 @@
import React, {Fragment, useEffect} from 'react';
import {CustomerDropDownRequest} from "../../APIRequest/SaleAPIRequest";
import React, {Fragment, useEffect, useRef} from 'react';
import {CustomerDropDownRequest, ProductDropDownRequest} from "../../APIRequest/SaleAPIRequest";
import {useSelector} from "react-redux";
import {BsCartCheck, BsTrash} from "react-icons/all";
import {ErrorToast, IsEmpty} from "../../helper/FormHelper";
import store from "../../redux/store/store";
import {OnChangeProductInput} from "../../redux/state-slice/product-slice";

import {RemoveSaleItem, SetSaleItemList} from "../../redux/state-slice/sale-slice";


const SalesCreateUpdate = () => {

let productRef,qtyRef,unitPriceRef,noteRef,grandTotalRef, shippingCostRef, otherCostRef, discountRef, vatRef, customerRef=useRef();

useEffect(()=>{
(async () => {
await CustomerDropDownRequest();
await ProductDropDownRequest();
})();
},[])

let CustomerDropDown=useSelector((state)=>(state.sale.CustomerDropDown));

let CustomerDropDown=useSelector((state)=>(state.sale.CustomerDropDown));
let ProductDropDown=useSelector((state)=>(state.sale.ProductDropDown));
let SaleItemList=useSelector((state)=>(state.sale.SaleItemList));


const OnAddCart = () => {
let productValue=productRef.value;
let productName=productRef.selectedOptions[0].text;
let qtyValue=qtyRef.value;
let unitPriceValue=unitPriceRef.value;

if(IsEmpty(productValue)){
ErrorToast("Select Product")
}
else if(IsEmpty(qtyValue)){
ErrorToast("Qty Required")
}
else if(IsEmpty(unitPriceValue)){
ErrorToast("Unit Price Required")
}
else {
let item= {
"ProductID":productValue,
"ProductName":productName,
"Qty":qtyValue,
"UnitCost":unitPriceValue,
"Total":(parseInt(qtyValue))*(parseInt(unitPriceValue))
}
store.dispatch(SetSaleItemList(item))
}

}


const removeCart = (i) => {
store.dispatch(RemoveSaleItem(i))
}


return (
<Fragment>
<div className="container-fluid">
<div className="row">

<div className="col-12 col-md-4 col-lg-4 mb-3">
<div className="card">
<div className="card h-100">
<div className="card-body">
<div className="row">
<h5 >Create Sales</h5>
<hr className="bg-light"/>
<div className="col-12 p-1">
<label className="form-label">Customer</label>
<select className="form-select form-select-sm">
<option value="">Select Type</option>
<select ref={(input)=>customerRef=input} className="form-select form-select-sm">
<option value="">Select Customer</option>
{
CustomerDropDown.map((item,i)=>{
return( <option key={i.toLocaleString()} value={item._id}>{item.CustomerName}</option>)
Expand All @@ -43,33 +82,33 @@ const SalesCreateUpdate = () => {

<div className="col-12 p-1">
<label className="form-label">Vat/Tax</label>
<input className="form-control form-control-sm" type="number"/>
<input ref={(input)=>vatRef=input} className="form-control form-control-sm" type="number"/>
</div>

<div className="col-12 p-1">
<label className="form-label">Discount</label>
<input className="form-control form-control-sm" type="number"/>
<input ref={(input)=>discountRef=input} className="form-control form-control-sm" type="number"/>
</div>

<div className="col-12 p-1">
<label className="form-label">Other Cost</label>
<input className="form-control form-control-sm" type="number"/>
<input ref={(input)=>otherCostRef=input} className="form-control form-control-sm" type="number"/>
</div>

<div className="col-12 p-1">
<label className="form-label">Shipping Cost</label>
<input className="form-control form-control-sm" type="number"/>
<input ref={(input)=>shippingCostRef=input} className="form-control form-control-sm" type="number"/>
</div>

<div className="col-12 p-1">
<label className="form-label">Grand Total</label>
<input className="form-control form-control-sm" type="number"/>
<input ref={(input)=>grandTotalRef=input} className="form-control form-control-sm" type="number"/>
</div>


<div className="col-12 p-1">
<label className="form-label">Note</label>
<input className="form-control form-control-sm" type="number"/>
<input ref={(input)=>noteRef=input} className="form-control form-control-sm" type="number"/>
</div>


Expand All @@ -82,8 +121,73 @@ const SalesCreateUpdate = () => {
</div>
</div>
</div>
<div className="col-12 col-md-8 col-lg-8 mb-3">
<div className="card h-100">
<div className="card-body">

<div className="row">
<div className="col-6 p-1">
<label className="form-label">Select Product</label>
<select ref={(input)=>productRef=input} className="form-select form-select-sm">
<option value="">Select Product</option>
{
ProductDropDown.map((item,i)=>{
return( <option key={i.toLocaleString()} value={item._id}>{item.Name}</option>)
})
}
</select>
</div>
<div className="col-2 p-1">
<label className="form-label">Qty</label>
<input ref={(input)=>qtyRef=input} className="form-control form-control-sm" />
</div>
<div className="col-2 p-1">
<label className="form-label">Unit Price</label>
<input ref={(input)=>unitPriceRef=input} className="form-control form-control-sm" />
</div>
<div className="col-2 p-1">
<label className="form-label">Add to cart</label>
<button onClick={OnAddCart} className="btn w-100 btn-success btn-sm"><BsCartCheck/></button>
</div>
</div>

<div className="row">
<div className="col-12">
<div className="table-responsive table-section">
<table className="table-sm text-center table">
<thead className="sticky-top bg-white">
<tr>
<th>Name</th>
<th>Qty</th>
<th>Unit Price</th>
<th>Total</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
{
SaleItemList.map((item,i)=>{
return(
<tr>
<td>{item.ProductName}</td>
<td>{item.Qty}</td>
<td>{item.UnitCost}</td>
<td>{item.Total}</td>
<td><button onClick={removeCart.bind(this,i)} className="btn btn-outline-light text-danger p-2 mb-0 btn-sm ms-2"><BsTrash/></button></td>
</tr>
)
})
}
</tbody>
</table>
</div>
</div>
</div>


</div>
</div>
</div>
</div>
</div>
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const saleSlice=createSlice({
List:[],
ListTotal:0,
CustomerDropDown:[],
ProductDropDown:[],
SaleFormValue:{
CustomerID:"",
VatTax:"",
Expand All @@ -26,11 +27,20 @@ export const saleSlice=createSlice({
SetCustomerDropDown:(state,action)=>{
state.CustomerDropDown=action.payload
},
SetProductDropDown:(state,action)=>{
state.ProductDropDown=action.payload
},
OnChangeSaleInput:(state,action)=>{
state.SaleFormValue[`${action.payload.Name}`]=action.payload.Value;
},
SetSaleItemList:(state,action)=>{
state.SaleItemList.push(action.payload)
},
RemoveSaleItem:(state,action)=>{
state.SaleItemList.splice(action.payload,1)
},
}
})

export const {SetSaleList,SetSaleListTotal,SetCustomerDropDown}=saleSlice.actions;
export const {RemoveSaleItem,SetSaleList,SetProductDropDown,SetSaleItemList,SetSaleListTotal,SetCustomerDropDown}=saleSlice.actions;
export default saleSlice.reducer;

0 comments on commit 5bac41e

Please sign in to comment.