feat: fix journal.

This commit is contained in:
elforjani13
2022-03-17 17:31:40 +02:00
parent b0407168a0
commit 888c3a11e0
8 changed files with 48 additions and 18 deletions

View File

@@ -21,7 +21,7 @@ export default function BranchSuggestField({
...suggestProps
}) {
const initialBranch = React.useMemo(
() => branches.some((b) => b.id === initialBranchId),
() => branches.find((b) => b.id === initialBranchId),
[initialBranchId, branches],
);
@@ -29,6 +29,15 @@ export default function BranchSuggestField({
initialBranch || null,
);
React.useEffect(() => {
if (typeof selectedBranchId !== 'undefined') {
const branch = selectedBranchId
? branches.find((a) => a.id === selectedBranchId)
: null;
setSelectedBranch(branch);
}
}, [selectedBranchId, branches, setSelectedBranch]);
/**
*
* @param {*} branch

View File

@@ -14,7 +14,7 @@ export default function BranchesListFieldCell({
}) {
const handleBranchSelected = React.useCallback(
(branch) => {
updateData(index, 'brnach_id', branch.id);
updateData(index, 'branch_id', branch.id);
},
[updateData, index],
);
@@ -33,7 +33,7 @@ export default function BranchesListFieldCell({
<BranchSuggestField
branches={branches}
onBranchSelected={handleBranchSelected}
selectedBranchId={original?.contact_id}
selectedBranchId={original?.branch_id}
/>
</FormGroup>
);

View File

@@ -59,6 +59,7 @@ function MakeJournalEntriesForm({
journalNumberPrefix,
journalNextNumber,
);
// Form initial values.
const initialValues = useMemo(
() => ({
@@ -69,7 +70,7 @@ function MakeJournalEntriesForm({
: {
...defaultManualJournal,
...(journalAutoIncrement && {
journal_number: defaultTo(journalNumber, ''),
journal_number: journalNumber,
}),
currency_code: base_currency,
}),
@@ -187,7 +188,7 @@ function MakeJournalEntriesForm({
export default compose(
withMediaActions,
withSettings(({ manualJournalsSettings }) => ({
journalNextNumber: parseInt(manualJournalsSettings?.nextNumber, 10),
journalNextNumber: manualJournalsSettings?.nextNumber,
journalNumberPrefix: manualJournalsSettings?.numberPrefix,
journalAutoIncrement: manualJournalsSettings?.autoIncrement,
})),

View File

@@ -62,14 +62,14 @@ function MakeJournalEntriesHeader({
// Handle journal number change.
const handleJournalNumberChange = () => {
openDialog('journal-number-form', {});
openDialog('journal-number-form');
};
// Handle journal number blur.
const handleJournalNoBlur = (form, field) => (event) => {
const newValue = event.target.value;
if (field.value !== newValue) {
if (field.value !== newValue && journalAutoIncrement) {
openDialog('journal-number-form', {
initialFormValues: {
manualTransactionNo: newValue,

View File

@@ -40,6 +40,7 @@ export const defaultEntry = {
export const defaultManualJournal = {
journal_number: '',
journal_number_manually: false,
journal_type: 'Journal',
date: moment(new Date()).format('YYYY-MM-DD'),
description: '',

View File

@@ -1,4 +1,5 @@
import React, { useCallback } from 'react';
import intl from 'react-intl-universal';
import { DialogContent } from 'components';
import { useSaveSettings, useSettingsManualJournals } from 'hooks/query';
@@ -12,7 +13,7 @@ import {
transformSettingsToForm,
} from 'containers/JournalNumber/utils';
import 'style/pages/ManualJournal/JournalNumberDialog.scss'
import 'style/pages/ManualJournal/JournalNumberDialog.scss';
/**
* Journal number dialog's content.
@@ -28,16 +29,14 @@ function JournalNumberDialogContent({
// #ownProps
onConfirm,
initialValues
initialValues,
}) {
const { isLoading: isSettingsLoading } = useSettingsManualJournals();
const { mutateAsync: saveSettingsMutate } = useSaveSettings();
const [referenceFormValues, setReferenceFormValues] = React.useState(null);
// Handle the form submit.
// Handle the form submit.
const handleSubmitForm = (values, { setSubmitting }) => {
// Transformes the form values to settings to save it.
const options = transformFormToSettings(values, 'manual_journals');
// Handle success.
const handleSuccess = () => {
setSubmitting(false);
@@ -52,6 +51,9 @@ function JournalNumberDialogContent({
handleSuccess();
return;
}
// Transformes the form values to settings to save it.
const options = transformFormToSettings(values, 'manual_journals');
saveSettingsMutate({ options }).then(handleSuccess).catch(handleErrors);
};
@@ -59,6 +61,17 @@ function JournalNumberDialogContent({
closeDialog('journal-number-form');
}, [closeDialog]);
// Handle form change.
const handleChange = (values) => {
setReferenceFormValues(values);
};
// Description.
const description =
referenceFormValues?.incrementMode === 'auto'
? intl.get('manual_journals.auto_increment.auto')
: intl.get('manual_journals.auto_increment.manually');
return (
<DialogContent isLoading={isSettingsLoading}>
<ReferenceNumberForm
@@ -71,7 +84,9 @@ function JournalNumberDialogContent({
...initialValues,
}}
onSubmit={handleSubmitForm}
description={description}
onClose={handleClose}
onChange={handleChange}
/>
</DialogContent>
);
@@ -84,4 +99,4 @@ export default compose(
numberPrefix: manualJournalsSettings?.numberPrefix,
autoIncrement: manualJournalsSettings?.autoIncrement,
})),
)(JournalNumberDialogContent);
)(JournalNumberDialogContent);

View File

@@ -1361,6 +1361,8 @@
"item_entries.landed.hint": "يتيح لك هذه الخيار إمكانية إضافة تكلفة اضافية علي فاتورة الشراء متال علي ذلك تكاليف الشحن ، ثم تحديد هذه التكلفة لتحميلها علي فاتورة الشراء.",
"invoice.auto_increment.auto": "يتم تعيين أرقام الفواتير على وضع الزيادة التلقائي. هل أنت متأكد من تغيير هذا الإعداد؟",
"invoice.auto_increment.manually": "يتم تعيين أرقام فواتيرك يدوياً. هل أنت متأكد من تغيير هذه الإعدادات؟",
"manual_journals.auto_increment.auto": "يتم تعيين أرقام القيود على وضع الزيادة التلقائي. هل أنت متأكد من تغيير هذا الإعداد؟",
"manual_journals.auto_increment.manually": "يتم تعيين أرقام القيود يدوياً. هل أنت متأكد من تغيير هذه الإعدادات؟",
"estimate.auto_increment.auto": "يتم تعيين أرقام العروض على وضع الزيادة التلقائي. هل أنت متأكد من تغيير هذا الإعداد؟",
"estimate.auto_increment.manually": "يتم تعيين أرقام عروض الاسعار يدوياً. هل أنت متأكد من تغيير هذه الإعدادات؟",
"receipt.auto_increment.auto": "يتم تعيين أرقام إيصالات على وضع الزيادة التلقائي. هل أنت متأكد من تغيير هذا الإعداد؟",

View File

@@ -1339,13 +1339,15 @@
"item_entries.products_services.hint": "Enter products or services you sell or buy to keep tracking what your sold or purchased.",
"item_entries.landed.hint": "This options allows you to be able to add additional cost eg. freight then allocate cost to the items in your bills.",
"invoice.auto_increment.auto": "Your invoice numbers are set on auto-increment mode. Are you sure changing this setting?",
"invoice.auto_increment.manually": "Yor invoice numbers are set on manual mode. Are you sure chaning this settings?",
"invoice.auto_increment.manually": "Your invoice numbers are set on manual mode. Are you sure chaning this settings?",
"manual_journals.auto_increment.auto": "Your Jouranl numbers are set on auto-increment mode. Are you sure changing this setting?",
"manual_journals.auto_increment.manually": "Your Journal numbers are set on manual mode. Are you sure chaning this settings?",
"estimate.auto_increment.auto": "Your estimate numbers are set on auto-increment mode. Are you sure changing this setting?",
"estimate.auto_increment.manually": "Yor estimate numbers are set on manual mode. Are you sure chaning this settings?",
"estimate.auto_increment.manually": "Your estimate numbers are set on manual mode. Are you sure chaning this settings?",
"receipt.auto_increment.auto": "Your receipt numbers are set on auto-increment mode. Are you sure changing this setting?",
"receipt.auto_increment.manually": "Yor receipt numbers are set on manual mode. Are you sure chaning this settings?",
"receipt.auto_increment.manually": "Your receipt numbers are set on manual mode. Are you sure chaning this settings?",
"payment_receive.auto_increment.auto": "Your payment numbers are set on auto-increment mode. Are you sure changing this setting?",
"payment_receive.auto_increment.manually": "Yor payment numbers are set on manual mode. Are you sure chaning this settings?",
"payment_receive.auto_increment.manually": "Your payment numbers are set on manual mode. Are you sure chaning this settings?",
"auto_increment.field.manually": "I will enter them manually each time",
"auto_increment.field.manual_this_transaction": "Manual entering for this transaction.",
"auto_increment.field.auto": "Auto-incrementing number.",