Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
sales config first
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhsaikhan committed Oct 30, 2023
1 parent 41b5a5b commit a4f7efc
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 90 deletions.
72 changes: 37 additions & 35 deletions packages/plugin-syncerkhet-api/src/afterMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
productToErkhet,
productCategoryToErkhet
} from './utils/productToErkhet';
import { sendCardInfo } from './utils/utils';
import { customerToErkhet, companyToErkhet } from './utils/customerToErkhet';
import { generateModels } from './connectionResolver';
import { getSyncLogDoc } from './utils/utils';

const allowTypes = {
'cards:deal': ['update'],
Expand Down Expand Up @@ -49,6 +49,8 @@ export const afterMutationHandlers = async (subdomain, params) => {
{}
);

const mainConfigs = await models.Configs.getConfig('erkhetConfig', {});

// return
if (Object.keys(returnConfigs).includes(destinationStageId)) {
const returnConfig = {
Expand All @@ -70,7 +72,9 @@ export const afterMutationHandlers = async (subdomain, params) => {
apiSecret: returnConfig.apiSecret,
orderInfos: JSON.stringify(orderInfos)
};

const syncLog = await models.SyncLogs.syncLogsAdd(
getSyncLogDoc(params)
);
await sendRPCMessage(
models,
syncLog,
Expand All @@ -95,7 +99,9 @@ export const afterMutationHandlers = async (subdomain, params) => {
};

const postData = await getMoveData(subdomain, moveConfig, deal);

const syncLog = await models.SyncLogs.syncLogsAdd(
getSyncLogDoc(params)
);
const response = await sendRPCMessage(
models,
syncLog,
Expand All @@ -114,45 +120,41 @@ export const afterMutationHandlers = async (subdomain, params) => {
message: response.message,
error: response.error
});
if (moveConfig.responseField) {
await sendCardInfo(subdomain, deal, moveConfig, txt);
} else {
console.log(txt);
}
console.log(txt);
}

return;
}

// create sale
if (Object.keys(configs).includes(destinationStageId)) {
const config = {
...configs[destinationStageId],
...(await models.Configs.getConfig('ERKHET', {}))
};
const postData = await getPostData(subdomain, config, deal);

const response = await sendRPCMessage(
models,
syncLog,
'rpc_queue:erxes-automation-erkhet',
{
action: 'get-response-send-order-info',
isEbarimt: false,
payload: JSON.stringify(postData),
isJson: true,
thirdService: true
}
);

if (response && (response.message || response.error)) {
const txt = JSON.stringify({
message: response.message,
error: response.error
});
if (config.responseField) {
await sendCardInfo(subdomain, deal, config, txt);
} else {
const postDatas = (await getPostData(
subdomain,
configs[destinationStageId],
mainConfigs,
deal
)) as any;

for (const data of postDatas) {
const { syncLog, postData } = data;
const response = await sendRPCMessage(
models,
syncLog,
'rpc_queue:erxes-automation-erkhet',
{
action: 'get-response-send-order-info',
isEbarimt: false,
payload: JSON.stringify(postData),
isJson: true,
thirdService: true
}
);

if (response && (response.message || response.error)) {
const txt = JSON.stringify({
message: response.message,
error: response.error
});
console.log(txt);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ export const getPostData = async (subdomain, config, deal, dateType = '') => {
productCodeById[product._id] = product.code;
}

const details: any = [];

const branchIds = deal.productsData.map(pd => pd.branchId) || [];
const departmentIds = deal.productsData.map(pd => pd.departmentId) || [];

Expand Down Expand Up @@ -156,6 +154,8 @@ export const getPostData = async (subdomain, config, deal, dateType = '') => {
}
}

const details: any = [];

for (const productData of deal.productsData) {
// not tickUsed product not sent
if (!productData.tickUsed) {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-syncerkhet-api/src/utils/productToErkhet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const productCategoryToErkhet = async (
data: { _id: category.parentId },
isRPC: true
});
const noBrandConfig = configs['newBrandId'];
const noBrandConfig = configs['noBrand'];

const remBrands = oldCategory.scopeBrandIds.filter(
b => !category.scopeBrandIds.includes(b)
Expand Down Expand Up @@ -179,7 +179,7 @@ export const productToErkhet = async (subdomain, models, params, action) => {
ratioMeasureUnit = subUom.ratio;
}

const noBrandConfig = configs['newBrandId'];
const noBrandConfig = configs['noBrand'];

const remBrands = oldProduct.scopeBrandIds.filter(
b => !product.scopeBrandIds.includes(b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class PerSettings extends React.Component<Props, State> {
const { config } = this.state;
const key = config.stageId;

delete configsMap.returnEbarimtConfig[currentConfigKey];
configsMap.returnEbarimtConfig[key] = config;
delete configsMap.stageInReturnConfig[currentConfigKey];
configsMap.stageInReturnConfig[key] = config;
this.props.save(configsMap);
};

Expand Down Expand Up @@ -118,7 +118,11 @@ class PerSettings extends React.Component<Props, State> {
return (
<CollapseContent
title={__(config.title)}
open={this.props.currentConfigKey === 'newEbarimtConfig' ? true : false}
open={
this.props.currentConfigKey === 'newStageInReturnConfig'
? true
: false
}
>
<FormGroup>
<ControlLabel>{'Title'}</ControlLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class GeneralSettings extends React.Component<Props, State> {
e.preventDefault();
const { configsMap } = this.state;

if (!configsMap.returnEbarimtConfig) {
configsMap.returnEbarimtConfig = {};
if (!configsMap.stageInReturnConfig) {
configsMap.stageInReturnConfig = {};
}

// must save prev item saved then new item
configsMap.returnEbarimtConfig.newEbarimtConfig = {
configsMap.stageInReturnConfig.newStageInReturnConfig = {
title: 'New Erkhet Config',
boardId: '',
pipelineId: '',
Expand All @@ -53,8 +53,8 @@ class GeneralSettings extends React.Component<Props, State> {

delete = (currentConfigKey: string) => {
const { configsMap } = this.state;
delete configsMap.returnEbarimtConfig[currentConfigKey];
delete configsMap.returnEbarimtConfig['newEbarimtConfig'];
delete configsMap.stageInReturnConfig[currentConfigKey];
delete configsMap.stageInReturnConfig['newStageInReturnConfig'];

this.setState({ configsMap });

Expand All @@ -77,7 +77,7 @@ class GeneralSettings extends React.Component<Props, State> {

renderContent() {
const { configsMap } = this.state;
const configs = configsMap.returnEbarimtConfig || {};
const configs = configsMap.stageInReturnConfig || {};

return (
<ContentBox id={'GeneralSettingsMenu'}>
Expand Down
Loading

0 comments on commit a4f7efc

Please sign in to comment.