From c6fe61c5456d637849d40f175d3d47c106388323 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Mon, 5 Dec 2022 15:31:31 +0530 Subject: [PATCH 1/2] feat: add datetime component - refactor date component --- fyo/utils/format.ts | 10 +- models/baseModels/Invoice/Invoice.ts | 2 +- .../baseModels/JournalEntry/JournalEntry.ts | 2 +- models/baseModels/Payment/Payment.ts | 2 +- models/inventory/StockTransfer.ts | 2 +- src/components/Controls/Date.vue | 47 +- src/components/Controls/Datetime.vue | 99 ++++ src/components/Controls/DatetimePicker.vue | 538 ++++++++++++++++++ src/components/Controls/FormControl.vue | 3 +- src/components/DatePicker/DatePicker.vue | 281 --------- 10 files changed, 660 insertions(+), 326 deletions(-) create mode 100644 src/components/Controls/Datetime.vue create mode 100644 src/components/Controls/DatetimePicker.vue delete mode 100644 src/components/DatePicker/DatePicker.vue diff --git a/fyo/utils/format.ts b/fyo/utils/format.ts index 918d61a9..d5c80df1 100644 --- a/fyo/utils/format.ts +++ b/fyo/utils/format.ts @@ -9,7 +9,7 @@ import { DEFAULT_CURRENCY, DEFAULT_DATE_FORMAT, DEFAULT_DISPLAY_PRECISION, - DEFAULT_LOCALE + DEFAULT_LOCALE, } from './consts'; export function format( @@ -66,6 +66,10 @@ function toDatetime(value: DocValue) { } function formatDatetime(value: DocValue, fyo: Fyo): string { + if (value == null) { + return ''; + } + const dateFormat = (fyo.singles.SystemSettings?.dateFormat as string) ?? DEFAULT_DATE_FORMAT; const formattedDatetime = toDatetime(value).toFormat( @@ -80,6 +84,10 @@ function formatDatetime(value: DocValue, fyo: Fyo): string { } function formatDate(value: DocValue, fyo: Fyo): string { + if (value == null) { + return ''; + } + const dateFormat = (fyo.singles.SystemSettings?.dateFormat as string) ?? DEFAULT_DATE_FORMAT; diff --git a/models/baseModels/Invoice/Invoice.ts b/models/baseModels/Invoice/Invoice.ts index a749f848..252d1de5 100644 --- a/models/baseModels/Invoice/Invoice.ts +++ b/models/baseModels/Invoice/Invoice.ts @@ -436,7 +436,7 @@ export abstract class Invoice extends Transactional { return defaults?.purchaseInvoiceTerms ?? ''; }, - date: () => new Date().toISOString().slice(0, 10), + date: () => new Date(), }; static filters: FiltersMap = { diff --git a/models/baseModels/JournalEntry/JournalEntry.ts b/models/baseModels/JournalEntry/JournalEntry.ts index 156e1e00..2d357857 100644 --- a/models/baseModels/JournalEntry/JournalEntry.ts +++ b/models/baseModels/JournalEntry/JournalEntry.ts @@ -40,7 +40,7 @@ export class JournalEntry extends Transactional { static defaults: DefaultMap = { numberSeries: (doc) => getNumberSeries(doc.schemaName, doc.fyo), - date: () => DateTime.local().toISODate(), + date: () => new Date(), }; static filters: FiltersMap = { diff --git a/models/baseModels/Payment/Payment.ts b/models/baseModels/Payment/Payment.ts index 68a4aed8..0f928138 100644 --- a/models/baseModels/Payment/Payment.ts +++ b/models/baseModels/Payment/Payment.ts @@ -381,7 +381,7 @@ export class Payment extends Transactional { static defaults: DefaultMap = { numberSeries: (doc) => getNumberSeries(doc.schemaName, doc.fyo), - date: () => new Date().toISOString(), + date: () => new Date(), }; async _getAccountsMap(): Promise { diff --git a/models/inventory/StockTransfer.ts b/models/inventory/StockTransfer.ts index 76d2f296..5aae9c1f 100644 --- a/models/inventory/StockTransfer.ts +++ b/models/inventory/StockTransfer.ts @@ -43,7 +43,7 @@ export abstract class StockTransfer extends Transfer { return defaults?.purchaseReceiptTerms ?? ''; }, - date: () => new Date().toISOString().slice(0, 10), + date: () => new Date(), }; static filters: FiltersMap = { diff --git a/src/components/Controls/Date.vue b/src/components/Controls/Date.vue index e2dd39a3..415cc7d5 100644 --- a/src/components/Controls/Date.vue +++ b/src/components/Controls/Date.vue @@ -1,42 +1,11 @@ - -