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

Commit

Permalink
merge with dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Anu-Ujin committed Oct 17, 2023
2 parents f79798d + ad3c058 commit 41ce6f7
Show file tree
Hide file tree
Showing 24 changed files with 4,951 additions and 250 deletions.
28 changes: 19 additions & 9 deletions packages/core/src/data/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,24 @@ export const createTransporter = async ({ ses }, models?: IModels) => {

export const uploadsFolderPath = path.join(__dirname, '../private/uploads');

export const initFirebase = async (models: IModels): Promise<void> => {
const config = await models.Configs.findOne({
code: 'GOOGLE_APPLICATION_CREDENTIALS_JSON'
});
export const initFirebase = async (
models: IModels,
customConfig?: string
): Promise<void> => {
let codeString = 'value';

if (!config) {
return;
}
if (customConfig) {
codeString = customConfig;
} else {
const config = await models.Configs.findOne({
code: 'GOOGLE_APPLICATION_CREDENTIALS_JSON'
});

const codeString = config.value || 'value';
if (!config) {
return;
}
codeString = config.value;
}

if (codeString[0] === '{' && codeString[codeString.length - 1] === '}') {
const serviceAccount = JSON.parse(codeString);
Expand Down Expand Up @@ -1287,12 +1295,14 @@ export const configReplacer = config => {
export const sendMobileNotification = async (
models: IModels,
{
customConfig,
receivers,
title,
body,
deviceTokens,
data
}: {
customConfig: string;
receivers: string[];
title: string;
body: string;
Expand All @@ -1301,7 +1311,7 @@ export const sendMobileNotification = async (
}
): Promise<void> => {
if (!admin.apps.length) {
await initFirebase(models);
await initFirebase(models, customConfig);
}

const transporter = admin.messaging();
Expand Down
129 changes: 32 additions & 97 deletions packages/plugin-cards-ui/src/deals/components/CalendarColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import styled from 'styled-components';
import options from '@erxes/ui-cards/src/deals/options';
import { IDeal, IDealTotalAmount } from '@erxes/ui-cards/src/deals/types';
import Deal from '@erxes/ui-cards/src/deals/components/DealItem';
import styledTS from 'styled-components-ts';
import ItemProductProbabilities from '@erxes/ui-cards/src/deals/components/ItemProductProbabilities';

type Props = {
deals: IDeal[];
Expand All @@ -23,23 +23,12 @@ type Props = {
onLoadMore: (skip: number) => void;
};

const Amount = styledTS<{ showAll: boolean }>(styled.ul)`
const Amount = styled.ul`
list-style: none;
overflow: hidden;
margin: 0 0 5px;
padding: 0 16px;
${props =>
props.showAll === false
? `
height: 20px;
overflow: hidden;
transition: all 300ms ease-out;
`
: `
height: unset;
`}
li {
padding-right: 5px;
font-size: 12px;
Expand Down Expand Up @@ -113,101 +102,47 @@ class DealColumn extends React.Component<Props, {}> {

renderTotalAmount() {
const { dealTotalAmounts, deals } = this.props;
const totalForType = dealTotalAmounts || [];

const forecastArray = [];
const totalAmountArray = [];
const totalForType = dealTotalAmounts || ([] as IDealTotalAmount[]);

dealTotalAmounts.map(total =>
total.currencies.map(currency => totalAmountArray.push(currency))
);

this.props.deals.map(deal => {
const probability =
deal.stage.probability === 'Won'
? '100%'
: deal.stage.probability === 'Lost'
? '0%'
: deal.stage.probability;

Object.keys(deal.amount).map(key =>
forecastArray.push({
name: key,
amount: deal.amount[key] as number,
probability: parseInt(probability, 10)
})
);
});

const detail = () => {
const renderDetail = () => {
if (!deals || deals.length === 0) {
return null;
}

if (
localStorage.getItem('showSalesDetail') === 'false' ||
!localStorage.getItem('showSalesDetail')
) {
return null;
}

return (
<>
<li>
<span>Total ({deals.length}): </span>
{this.renderPercentedAmount(totalAmountArray)}
</li>
<li>
<span>Forecasted: </span>
{this.renderPercentedAmount(forecastArray)}
</li>
<ItemProductProbabilities
dealTotalAmounts={totalForType}
deals={deals}
/>
{totalForType.map(type => {
if (type.name === 'In progress') {
return null;
}

const percent = type.name === 'Won' ? '100%' : '0%';

return (
<li key={type._id}>
<span>
{type.name} ({percent}){' '}
</span>
{this.renderAmount(type.currencies)}
</li>
);
})}
</>
);
};

return (
<Amount
showAll={
localStorage.getItem('showSalesDetail') === 'true' ? true : false
}
>
{detail()}
{totalForType.map(type => {
if (type.name === 'In progress') {
return null;
}

const percent = type.name === 'Won' ? '100%' : '0%';

return (
<li key={type._id}>
<span>
{type.name} ({percent}):{' '}
</span>
{this.renderAmount(type.currencies)}
</li>
);
})}
</Amount>
);
}

renderPercentedAmount(currencies) {
const sumByName = {};

currencies.forEach(item => {
const { name, amount, probability = 100 } = item;
if (sumByName[name] === undefined) {
sumByName[name] = (amount * probability) / 100;
} else {
sumByName[name] += (amount * probability) / 100;
}
});

return Object.keys(sumByName).map((key, index) => (
<div key={index}>
{sumByName[key].toLocaleString(undefined, {
maximumFractionDigits: 0
})}{' '}
<span>
{key}
{index < Object.keys(sumByName).length - 1 && ','}&nbsp;
</span>
</div>
));
return <Amount>{renderDetail()}</Amount>;
}

renderFooter() {
Expand Down
Loading

0 comments on commit 41ce6f7

Please sign in to comment.