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

Commit

Permalink
hasPayment
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhsaikhan committed Oct 31, 2023
1 parent db683da commit 8b359b8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
50 changes: 26 additions & 24 deletions packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ export const getPostData = async (subdomain, configs, deal, dateType = '') => {
}

// debit payments coll
const payments = {};
const configure = {
prepay: 'preAmount',
cash: 'cashAmount',
Expand All @@ -254,31 +253,34 @@ export const getPostData = async (subdomain, configs, deal, dateType = '') => {
}

const config = configs[brandId];
const payments = {};

if (config.hasPayment) {
let sumSaleAmount = details.reduce((predet, detail) => {
return { amount: predet.amount + detail.amount };
}).amount;

for (const paymentKind of Object.keys(deal.paymentsData || [])) {
const payment = deal.paymentsData[paymentKind];
payments[configure[paymentKind]] =
(payments[configure[paymentKind]] || 0) + payment.amount;
sumSaleAmount = sumSaleAmount - payment.amount;
}

let sumSaleAmount = details.reduce((predet, detail) => {
return { amount: predet.amount + detail.amount };
}).amount;

for (const paymentKind of Object.keys(deal.paymentsData || [])) {
const payment = deal.paymentsData[paymentKind];
payments[configure[paymentKind]] =
(payments[configure[paymentKind]] || 0) + payment.amount;
sumSaleAmount = sumSaleAmount - payment.amount;
}

// if payments is less sum sale amount then create debt
if (sumSaleAmount > 0.005) {
payments[config.defaultPay] =
(payments[config.defaultPay] || 0) + sumSaleAmount;
} else if (sumSaleAmount < -0.005) {
if ((payments[config.defaultPay] || 0) > 0.005) {
// if payments is less sum sale amount then create debt
if (sumSaleAmount > 0.005) {
payments[config.defaultPay] =
payments[config.defaultPay] + sumSaleAmount;
} else {
for (const key of Object.keys(payments)) {
if (payments[key] > 0.005) {
payments[key] = payments[key] + sumSaleAmount;
continue;
(payments[config.defaultPay] || 0) + sumSaleAmount;
} else if (sumSaleAmount < -0.005) {
if ((payments[config.defaultPay] || 0) > 0.005) {
payments[config.defaultPay] =
payments[config.defaultPay] + sumSaleAmount;
} else {
for (const key of Object.keys(payments)) {
if (payments[key] > 0.005) {
payments[key] = payments[key] + sumSaleAmount;
continue;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class PerSettings extends React.Component<Props, State> {
newBrand: {
brandId: '',
userEmail: '',
hasPayment: true,
hasVat: false,
hasCitytax: false,
defaultPay: 'debtAmount'
Expand Down Expand Up @@ -305,6 +306,7 @@ class PerSettings extends React.Component<Props, State> {
onChangeStage={this.onChangeStage}
/>
</FormGroup>
{this.renderCheckbox('hasPayment', 'has Payment')}
<FormGroup>
<ControlLabel>{__('Choose response field')}</ControlLabel>
<Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class GeneralSettings extends React.Component<Props, State> {
userEmail: '',
hasVat: false,
hasCitytax: false,
hasPayment: true,
defaultPay: 'debtAmount'
}
}
Expand Down

0 comments on commit 8b359b8

Please sign in to comment.