Added Created Date, Created By & Prev Balance to Transaction

Date Created Custom Field with additional functionality to lock IssueDate and Reference.

image


<div id='DateCreated' style='display: none;'>
    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const FIELD_GUID = 'a1b2c3d4-e5f6-4abc-8def-abcdef000020';
            const LABEL_TEXT = 'Date Created';
            const dateInput = document.querySelector('.mx-input');
            if (dateInput) {
                dateInput.disabled = true;
                const calendarIcon = document.querySelector('.mx-icon-calendar');
                if (calendarIcon) {
                    calendarIcon.style.pointerEvents = 'none';
                    calendarIcon.style.opacity = '0.5';
                }
            }
            const checkbox = document.querySelector('.input-group-addon input[type="checkbox"]');
            const inputText = document.querySelector('.input-group input[type="text"]');
            if (checkbox && inputText) {
                app.AutomaticReference = false;
                checkbox.checked = false;
                checkbox.disabled = true;
                inputText.disabled = true;
            }
            const createButton = document.querySelector('button.btn.btn-primary[onclick="ajaxPost(true)"]');
            if (createButton && app?.CustomFields2?.Strings) {
                const now = new Date();
                const localDatetime = new Date(now.getTime() - (now.getTimezoneOffset() * 60000));
                const currentDateTime = localDatetime.toISOString().slice(0, 19).replace('T', ' ');
                app.CustomFields2.Strings[FIELD_GUID] = currentDateTime;
                app.IssueDate = currentDateTime.slice(0, 10);
                if (checkbox && inputText) {
                    app.AutomaticReference = true;
                    checkbox.checked = true;
                }
            }
            const vModelForm = document.getElementById('v-model-form');
            if (vModelForm) {
                const labels = vModelForm.querySelectorAll('label');
                labels.forEach(label => {
                    if (label.textContent.trim() === LABEL_TEXT) {
                        const formGroup = label.closest('.form-group');
                        if (formGroup) {
                            formGroup.style.display = 'none';
                        }
                    }
                });
            }
            const selfDeletingContainer = document.getElementById('DateCreated');
            if (selfDeletingContainer) {
                selfDeletingContainer.remove();
            }
        });
    </script>
</div>

Make sure to change this section according to the Customfield you created.

    const FIELD_GUID = 'a1b2c3d4-e5f6-4abc-8def-abcdef000020';
    const LABEL_TEXT = 'Date Created';

Date Picker will always be filled with the Date when Invoice was Created or Cloned, and Reference Number using Auto number mode

I plan to add this Custom Field to ZatcaEGS to get IssuedTime.

Update Script, to open the reference checkbox in edit mode, so that the reference number does not change to a new number when it saved.

1 Like