From 8b359b82b148fe547dcbbcc08a614490a5351fc7 Mon Sep 17 00:00:00 2001 From: munkhsaikhan Date: Tue, 31 Oct 2023 14:22:01 +0800 Subject: [PATCH] hasPayment --- .../src/utils/ebarimtData.ts | 50 ++++++++++--------- .../src/components/SalePerSettings.tsx | 2 + .../src/components/SaleStageSettings.tsx | 1 + 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts b/packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts index 7ccb541e13..defd0ca12a 100644 --- a/packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts +++ b/packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts @@ -234,7 +234,6 @@ export const getPostData = async (subdomain, configs, deal, dateType = '') => { } // debit payments coll - const payments = {}; const configure = { prepay: 'preAmount', cash: 'cashAmount', @@ -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; + } } } } diff --git a/packages/plugin-syncerkhet-ui/src/components/SalePerSettings.tsx b/packages/plugin-syncerkhet-ui/src/components/SalePerSettings.tsx index 7a79303176..464590c8b5 100644 --- a/packages/plugin-syncerkhet-ui/src/components/SalePerSettings.tsx +++ b/packages/plugin-syncerkhet-ui/src/components/SalePerSettings.tsx @@ -155,6 +155,7 @@ class PerSettings extends React.Component { newBrand: { brandId: '', userEmail: '', + hasPayment: true, hasVat: false, hasCitytax: false, defaultPay: 'debtAmount' @@ -305,6 +306,7 @@ class PerSettings extends React.Component { onChangeStage={this.onChangeStage} /> + {this.renderCheckbox('hasPayment', 'has Payment')} {__('Choose response field')}