349 lines
11 KiB
JavaScript
349 lines
11 KiB
JavaScript
import { createAsyncThunk } from '@reduxjs/toolkit';
|
|
import { axiosRetailInstanceData, axiosEmail_SMSData } from '../AuthenicationToken/AuthenticationToken';
|
|
|
|
export const getPurchaseSupplierData = createAsyncThunk(
|
|
'PurchaseOrder/getPurchaseSupplierData',
|
|
async (ProdData) => {
|
|
if (
|
|
ProdData?.CompId !== null &&
|
|
ProdData?.CompId !== undefined &&
|
|
ProdData?.BranchId !== null &&
|
|
ProdData?.BranchId !== undefined &&
|
|
ProdData?.AppId !== null &&
|
|
ProdData?.AppId !== undefined &&
|
|
ProdData?.ActiveStatus !== null &&
|
|
ProdData?.ActiveStatus !== undefined
|
|
) {
|
|
return await axiosRetailInstanceData.get(
|
|
`/supplier?CompId=${ProdData?.CompId}&BranchId=${ProdData?.BranchId}&AppId=${ProdData?.AppId}&ActiveStatus=${ProdData?.ActiveStatus}`
|
|
);
|
|
}
|
|
}
|
|
);
|
|
export const getstockAdjustment = createAsyncThunk(
|
|
'PurchaseOrder/getstockAdjustment',
|
|
async (ProdData) => {
|
|
if (
|
|
ProdData?.CompId !== null &&
|
|
ProdData?.CompId !== undefined &&
|
|
ProdData?.BranchId !== null &&
|
|
ProdData?.BranchId !== undefined &&
|
|
ProdData?.AppId !== null &&
|
|
ProdData?.AppId !== undefined
|
|
|
|
) {
|
|
|
|
let endPoint = `/GetBeforeStockAdjustment?CompId=${ProdData?.CompId}&BranchId=${ProdData?.BranchId}&AppId=${ProdData?.AppId}&fromDate=${ProdData?.fromDate}&toDate=${ProdData?.toDate}`;
|
|
if (ProdData?.prodId) {
|
|
endPoint += `&prodId=${ProdData?.prodId}`
|
|
}
|
|
return await axiosRetailInstanceData.get(endPoint);
|
|
}
|
|
}
|
|
);
|
|
export const getstockAdjustmentDetails = createAsyncThunk(
|
|
'PurchaseOrder/getstockAdjustmentDetails',
|
|
async (ProdData) => {
|
|
if (
|
|
ProdData?.CompId !== null &&
|
|
ProdData?.CompId !== undefined &&
|
|
ProdData?.BranchId !== null &&
|
|
ProdData?.BranchId !== undefined &&
|
|
ProdData?.AppId !== null &&
|
|
ProdData?.AppId !== undefined
|
|
|
|
) {
|
|
return await axiosRetailInstanceData.get(
|
|
`/StockAdjustment?CompId=${ProdData?.CompId}&BranchId=${ProdData?.BranchId}&AppId=${ProdData?.AppId}`
|
|
);
|
|
}
|
|
}
|
|
);
|
|
export const postStockAdjustment = createAsyncThunk(
|
|
'PurchaseOrder/postStockAdjustment',
|
|
async (postData) => {
|
|
return await axiosRetailInstanceData.post(`/StockAdjustment`, postData);
|
|
}
|
|
);
|
|
|
|
|
|
export const getPurchaseSupplierAndWareHouseData = createAsyncThunk(
|
|
'PurchaseOrder/getPurchaseSupplierAndWareHouseData',
|
|
async (ProdData, { rejectWithValue }) => {
|
|
const { AppId, CompId, BranchId } = ProdData;
|
|
|
|
if (AppId && CompId && BranchId) {
|
|
try {
|
|
const response = await axiosRetailInstanceData.get(
|
|
`/Supplier/AllSupplierBranchDropdown?appId=${AppId}&compId=${CompId}&branchId=${BranchId}`
|
|
);
|
|
return response.data;
|
|
} catch (error) {
|
|
return rejectWithValue(error.response?.data || error.message);
|
|
}
|
|
} else {
|
|
return rejectWithValue("Missing required parameters.");
|
|
}
|
|
}
|
|
);
|
|
|
|
export const getPurProdvaraiantdata = createAsyncThunk(
|
|
'PurchaseOrder/getPurProdvaraiantdata',
|
|
async (data) => {
|
|
if (
|
|
data?.CompId !== null &&
|
|
data?.CompId !== undefined &&
|
|
data?.BranchId !== null &&
|
|
data?.BranchId !== undefined &&
|
|
data?.AppId !== null &&
|
|
data?.AppId !== undefined &&
|
|
data?.prodName !== null &&
|
|
data?.prodName !== undefined
|
|
) {
|
|
return await axiosRetailInstanceData.get(
|
|
`/ProductCardList?CompId=${data?.CompId}&BranchId=${data?.BranchId}&AppId=${data?.AppId}&prodName=${encodeURIComponent(data?.prodName)}&type=S`
|
|
);
|
|
}
|
|
}
|
|
);
|
|
export const getPurOrderListdata = createAsyncThunk(
|
|
'PurchaseOrder/getPurProdvaraiantdata',
|
|
async (data) => {
|
|
if (
|
|
data?.CompId !== null &&
|
|
data?.CompId !== undefined &&
|
|
data?.BranchId !== null &&
|
|
data?.BranchId !== undefined &&
|
|
data?.AppId !== null &&
|
|
data?.AppId !== undefined
|
|
) {
|
|
return await axiosRetailInstanceData.get(
|
|
`/PurchaseOrder?CompId=${data?.CompId}&BranchId=${data?.BranchId}&AppId=${data?.AppId}`
|
|
);
|
|
}
|
|
}
|
|
);
|
|
export const getPurchaseOrderList = createAsyncThunk(
|
|
'PurchaseOrder/getPurchaseOrderList',
|
|
async (data) => {
|
|
if (
|
|
data?.CompId !== null &&
|
|
data?.CompId !== undefined &&
|
|
data?.BranchId !== null &&
|
|
data?.BranchId !== undefined &&
|
|
data?.AppId !== null &&
|
|
data?.AppId !== undefined &&
|
|
data?.Type !== null &&
|
|
data?.Type !== undefined
|
|
) {
|
|
return await axiosRetailInstanceData.get(
|
|
`/PurchaseOrder?CompId=${data?.CompId}&BranchId=${data?.BranchId}&AppId=${data?.AppId}&Type=${data?.Type}`
|
|
);
|
|
}
|
|
}
|
|
);
|
|
export const getPurcTaxTypeData = createAsyncThunk(
|
|
'PurchaseOrder/getPurcTaxTypeData',
|
|
async () => {
|
|
return await axiosRetailInstanceData.get(
|
|
`/configMaster?TypeName=Purchase Tax Type`
|
|
);
|
|
}
|
|
);
|
|
export const getPurcProdTaxData = createAsyncThunk(
|
|
'PurchaseOrder/getPurcProdTaxData',
|
|
async ({ AppId }) => {
|
|
if (AppId) {
|
|
return await axiosRetailInstanceData.get(
|
|
`/configMaster?TypeName=Product Tax&AppId=${AppId}`
|
|
);
|
|
} else {
|
|
return await axiosRetailInstanceData.get(
|
|
`/configMaster?TypeName=Product Tax`
|
|
);
|
|
}
|
|
}
|
|
);
|
|
export const postPurcOrderData = createAsyncThunk(
|
|
'PurchaseOrder/postPurcOrderData',
|
|
async (postData) => {
|
|
return await axiosRetailInstanceData.post(`/PurchaseOrder`, postData);
|
|
}
|
|
);
|
|
|
|
export const getPurProductData = createAsyncThunk(
|
|
'PurchaseOrder/getPurProductData',
|
|
async (ProdData) => {
|
|
if (ProdData?.SuppId !== null && ProdData?.SuppId !== undefined) {
|
|
return await axiosRetailInstanceData.get(
|
|
`/product?SuppId=${ProdData?.SuppId}`
|
|
);
|
|
}
|
|
}
|
|
);
|
|
export const getProductData = createAsyncThunk(
|
|
'Stock/getProductData',
|
|
async (ProdData) => {
|
|
if (
|
|
ProdData?.CompId != null &&
|
|
ProdData?.CompId != undefined &&
|
|
ProdData?.BranchId != null &&
|
|
ProdData?.BranchId != undefined &&
|
|
ProdData?.AppId != null &&
|
|
ProdData?.AppId != undefined
|
|
) {
|
|
// based on Active Product get issue by sridhar
|
|
return await axiosRetailInstanceData.get(
|
|
`/product?CompId=${ProdData?.CompId}&BranchId=${ProdData?.BranchId}&AppId=${ProdData?.AppId}&ActiveStatus=A`
|
|
);
|
|
}
|
|
}
|
|
);
|
|
|
|
export const getSupplierData = createAsyncThunk(
|
|
'product/getSupplierData',
|
|
async ({ CompId, AppId, BranchId }) => {
|
|
if (
|
|
CompId != null &&
|
|
CompId != undefined &&
|
|
AppId != null &&
|
|
AppId != undefined &&
|
|
BranchId
|
|
) {
|
|
return await axiosRetailInstanceData.get(
|
|
`/supplierlist?AppId=${AppId}&CompId=${CompId}&BranchId=${BranchId}`
|
|
);
|
|
}
|
|
}
|
|
);
|
|
|
|
export const getProductStockDetails = createAsyncThunk(
|
|
'Product/ProductStockDetails',
|
|
async ({ CompId, AppId, BranchId, qty, type }) => {
|
|
if (
|
|
CompId != null &&
|
|
CompId != undefined &&
|
|
AppId != null &&
|
|
AppId != undefined &&
|
|
BranchId &&
|
|
qty != null
|
|
) {
|
|
return await axiosRetailInstanceData.get(
|
|
`/Product/ProductStockDetails?AppId=${AppId}&CompId=${CompId}&BranchId=${BranchId}&qty=${qty}`
|
|
);
|
|
}
|
|
else if (
|
|
CompId != null &&
|
|
CompId != undefined &&
|
|
AppId != null &&
|
|
AppId != undefined &&
|
|
BranchId &&
|
|
type != null
|
|
) {
|
|
return await axiosRetailInstanceData.get(
|
|
`/Product/ProductStockDetails?AppId=${AppId}&CompId=${CompId}&BranchId=${BranchId}&Type=${type}`
|
|
);
|
|
}
|
|
else {
|
|
return await axiosRetailInstanceData.get(
|
|
`/Product/ProductStockDetails?AppId=${AppId}&CompId=${CompId}&BranchId=${BranchId}`
|
|
);
|
|
|
|
}
|
|
}
|
|
);
|
|
|
|
// Product/ProductStockDetails?request.compId=3&request.branchId=3&request.appId=3
|
|
|
|
|
|
export const PurchaseOrderBulkpost = createAsyncThunk(
|
|
'Stock/Bulkstockpost',
|
|
async (postData) => {
|
|
return await axiosRetailInstanceData.post(`/OrderBulkUpload`, postData);
|
|
}
|
|
);
|
|
|
|
export const PurchaseOrderMailPost = createAsyncThunk(
|
|
'Stock/PurchaseOrderMailPost',
|
|
async (postData) => {
|
|
return await axiosRetailInstanceData.post(`/PurOrderMail`, postData);
|
|
}
|
|
);
|
|
export const postOpeningStock = createAsyncThunk(
|
|
'Stock/postOpeningStock',
|
|
async (postData) => {
|
|
return await axiosRetailInstanceData.post(`/OpeningStock`, postData);
|
|
}
|
|
);
|
|
export const putOpeningStock = createAsyncThunk(
|
|
'Stock/putOpeningStock',
|
|
async (putData) => {
|
|
return await axiosRetailInstanceData.put(`/updateStock`, putData);
|
|
}
|
|
);
|
|
|
|
export const getOpeningStock = createAsyncThunk(
|
|
'Stock/getOpeningStock',
|
|
async (
|
|
{ CompId, AppId, BranchId }
|
|
) => {
|
|
return await axiosRetailInstanceData.get(`/OBStock?AppId=${AppId}&CompId=${CompId}&BranchId=${BranchId}`);
|
|
}
|
|
);
|
|
|
|
|
|
export const Emailsend = createAsyncThunk(
|
|
'/sendEmail',
|
|
async (EmailData) => {
|
|
const { fileBlob, toEmail, type, messageTemplatesList } = EmailData;
|
|
|
|
// Convert Blob to File
|
|
const file = new File([fileBlob], `${type}.pdf`, {
|
|
type: 'application/pdf',
|
|
});
|
|
|
|
// Build FormData
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
formData.append('toEmail', toEmail);
|
|
formData.append('Type', type);
|
|
// formData.append('messageTemplatesList', JSON.stringify(messageTemplatesList || []));
|
|
|
|
// Send to API
|
|
return await axiosEmail_SMSData.post('/SendPdfEmail', formData);
|
|
}
|
|
);
|
|
|
|
export const getProductsForAutoReorder = createAsyncThunk('/AutoReorder', async (data) => {
|
|
const { CompId, BranchId, AppId } = data;
|
|
return await axiosRetailInstanceData.get(`/AutoReorder?CompId=${CompId}&BranchId=${BranchId}&AppId=${AppId}`);
|
|
})
|
|
|
|
export const getSuppliersOfProducts = createAsyncThunk('/AutoReorderSuppliers', async (data) => {
|
|
const { CompId, BranchId, AppId, ProdId } = data;
|
|
if (CompId !== undefined && CompId !== null && BranchId !== undefined && BranchId !== null && AppId !== undefined && AppId !== null && ProdId !== undefined && ProdId !== null) {
|
|
return await axiosRetailInstanceData.get(`/AutoReorderSuppliers?CompId=${CompId}&BranchId=${BranchId}&AppId=${AppId}&ProdId=${ProdId}`);
|
|
}
|
|
})
|
|
|
|
export const postAutomatedReorder = createAsyncThunk('postAutomatedReorder/AutoReorder', async (data) => {
|
|
return await axiosRetailInstanceData.post(`/AutoReorder`, data);
|
|
})
|
|
|
|
export const putAutomatedReorder = createAsyncThunk('postAutomatedReorder/AutoReorder', async (data) => {
|
|
return await axiosRetailInstanceData.put(`/AutoReorder`, data);
|
|
})
|
|
export const deleteAutomatedReorder = createAsyncThunk('postAutomatedReorder/AutoReorder', async (data) => {
|
|
const { UniqueId, ActiveStatus, UpdatedBy } = data;
|
|
return await axiosRetailInstanceData.delete(`/AutoReorder?UpdateBy=${UpdatedBy}&UniqueId=${UniqueId}&ActiveStatus=${ActiveStatus}`);
|
|
})
|
|
|
|
export const getAutomatedReorderList = createAsyncThunk('getAutomatedReorderList/AutomatedReorders', async (data) => {
|
|
const { CompId, BranchId, AppId } = data;
|
|
if (CompId !== undefined && CompId !== null && BranchId !== undefined && BranchId !== null && AppId !== undefined && AppId !== null) {
|
|
return await axiosRetailInstanceData.get(`/AutomatedReorders?CompId=${CompId}&BranchId=${BranchId}&AppId=${AppId}`);
|
|
}
|
|
})
|
|
|
|
|