Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add hints to import fields #401

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/server/src/models/Bill.Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default {
relationModel: 'Item',
relationImportMatch: ['name', 'code'],
required: true,
importHint: "Matches the item name or code."
},
rate: {
name: 'Rate',
Expand Down
3 changes: 3 additions & 0 deletions packages/server/src/models/BillPayment.Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ export default {
name: 'bill_payment.field.payment_number',
fieldType: 'text',
unique: true,
importHint: "The payment number should be unique."
},
paymentAccountId: {
name: 'bill_payment.field.payment_account',
fieldType: 'relation',
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
required: true,
importHint: "Matches the account name or code."
},
exchangeRate: {
name: 'bill_payment.field.exchange_rate',
Expand Down Expand Up @@ -118,6 +120,7 @@ export default {
relationModel: 'Bill',
relationImportMatch: 'billNumber',
required: true,
importHint: "Matches the bill number."
},
paymentAmount: {
name: 'bill_payment.field.entries.payment_amount',
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/models/CreditNote.Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export default {
relationModel: 'Item',
relationImportMatch: ['name', 'code'],
required: true,
importHint: 'Matches the item name or code.',
},
rate: {
name: 'Rate',
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/models/Expense.Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default {
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
required: true,
importHint: "Matches the account name or code."
},
referenceNo: {
name: 'expense.field.reference_no',
Expand Down Expand Up @@ -101,6 +102,7 @@ export default {
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
required: true,
importHint: "Matches the account name or code."
},
amount: {
name: 'expense.field.amount',
Expand Down
91 changes: 28 additions & 63 deletions packages/server/src/models/Item.Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,117 +124,82 @@ export default {
fields2: {
type: {
name: 'item.field.type',
column: 'type',
fieldType: 'enumeration',
options: [
{ key: 'inventory', label: 'item.field.type.inventory' },
{ key: 'service', label: 'item.field.type.service' },
{ key: 'non-inventory', label: 'item.field.type.non-inventory' },
],
required: true,
},
name: {
name: 'item.field.name',
column: 'name',
fieldType: 'text',
required: true,
},
code: {
name: 'item.field.code',
column: 'code',
fieldType: 'text',
},
sellable: {
name: 'item.field.sellable',
column: 'sellable',
fieldType: 'boolean',
},
purchasable: {
name: 'item.field.purchasable',
column: 'purchasable',
fieldType: 'boolean',
},
sell_price: {
name: 'item.field.cost_price',
column: 'sell_price',
sellPrice: {
name: 'item.field.sell_price',
fieldType: 'number',
},
cost_price: {
name: 'item.field.cost_account',
column: 'cost_price',
name: 'item.field.cost_price',
fieldType: 'number',
},
cost_account: {
name: 'item.field.sell_account',
column: 'cost_account_id',
costAccount: {
name: 'item.field.cost_account',
fieldType: 'relation',

relationType: 'enumeration',
relationKey: 'costAccount',

relationEntityLabel: 'name',
relationEntityKey: 'slug',
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
importHint: 'Matches the account name or code.',
},
sell_account: {
name: 'item.field.sell_description',
column: 'sell_account_id',
sellAccount: {
name: 'item.field.sell_account',
fieldType: 'relation',

relationType: 'enumeration',
relationKey: 'sellAccount',

relationEntityLabel: 'name',
relationEntityKey: 'slug',
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
importHint: 'Matches the account name or code.',
},
inventory_account: {
inventoryAccount: {
name: 'item.field.inventory_account',
column: 'inventory_account_id',

relationType: 'enumeration',
relationKey: 'inventoryAccount',

relationEntityLabel: 'name',
relationEntityKey: 'slug',
fieldType: 'relation',
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
importHint: 'Matches the account name or code.',
},
sell_description: {
name: 'Sell description',
column: 'sell_description',
sellDescription: {
name: 'Sell Description',
fieldType: 'text',
},
purchase_description: {
name: 'Purchase description',
column: 'purchase_description',
purchaseDescription: {
name: 'Purchase Description',
fieldType: 'text',
},
quantity_on_hand: {
name: 'item.field.quantity_on_hand',
column: 'quantity_on_hand',
fieldType: 'number',
},
note: {
name: 'item.field.note',
column: 'note',
fieldType: 'text',
},
category: {
name: 'item.field.category',
column: 'category_id',

relationType: 'enumeration',
relationKey: 'category',

relationEntityLabel: 'name',
relationEntityKey: 'id',
fieldType: 'relation',
relationModel: 'ItemCategory',
relationImportMatch: ['name'],
importHint: "Matches the category name."
},
active: {
name: 'item.field.active',
column: 'active',
fieldType: 'boolean',
filterable: false,
},
created_at: {
name: 'item.field.created_at',
column: 'created_at',
columnType: 'date',
fieldType: 'date',
},
},
};
3 changes: 3 additions & 0 deletions packages/server/src/models/PaymentReceive.Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ export default {
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
required: true,
importHint: "Matches the account name or code."
},
paymentReceiveNo: {
name: 'payment_receive.field.payment_receive_no',
fieldType: 'text',
importHint: "The payment number should be unique."
},
statement: {
name: 'payment_receive.field.statement',
Expand All @@ -106,6 +108,7 @@ export default {
relationModel: 'SaleInvoice',
relationImportMatch: 'invoiceNo',
required: true,
importHint: "Matches the invoice number."
},
paymentAmount: {
name: 'payment_receive.field.entries.payment_amount',
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/models/SaleEstimate.Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default {
relationModel: 'Item',
relationImportMatch: ['name', 'code'],
required: true,
importHint: "Matches the item name or code."
},
rate: {
name: 'invoice.field.rate',
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/models/SaleInvoice.Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export default {
relationModel: 'Item',
relationImportMatch: ['name', 'code'],
required: true,
importHint: "Matches the item name or code."
},
rate: {
name: 'invoice.field.rate',
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/models/SaleReceipt.Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default {
relationModel: 'Item',
relationImportMatch: ['name', 'code'],
required: true,
importHint: "Matches the item name or code."
},
rate: {
name: 'invoice.field.rate',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,19 @@ export default {
},
payee: {
name: 'Payee',
column: 'payee',
fieldType: 'text',
},
description: {
name: 'Description',
column: 'description',
fieldType: 'text',
},
referenceNo: {
name: 'Reference No.',
column: 'reference_no',
fieldType: 'text',
},
amount: {
name: 'Amount',
column: 'Amount',
fieldType: 'numeric',
fieldType: 'number',
required: true,
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/models/VendorCredit.Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default {
relationModel: 'Item',
relationImportMatch: ['name', 'code'],
required: true,
importHint: "Matches the item name or code."
},
rate: {
name: 'Rate',
Expand Down
44 changes: 21 additions & 23 deletions packages/server/src/services/Cashflow/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,25 @@ export interface ICashflowTransactionTypeMeta {
}

export const BankTransactionsSampleData = [
[
{
Amount: '6,410.19',
Date: '2024-03-26',
Payee: 'MacGyver and Sons',
'Reference No.': 'REF-1',
Description: 'Commodi quo labore.',
},
{
Amount: '8,914.17',
Date: '2024-01-05',
Payee: 'Eichmann - Bergnaum',
'Reference No.': 'REF-1',
Description: 'Quia enim et.',
},
{
Amount: '6,200.88',
Date: '2024-02-17',
Payee: 'Luettgen, Mraz and Legros',
'Reference No.': 'REF-1',
Description: 'Occaecati consequuntur cum impedit illo.',
},
],
{
Amount: '6,410.19',
Date: '2024-03-26',
Payee: 'MacGyver and Sons',
'Reference No.': 'REF-1',
Description: 'Commodi quo labore.',
},
{
Amount: '8,914.17',
Date: '2024-01-05',
Payee: 'Eichmann - Bergnaum',
'Reference No.': 'REF-1',
Description: 'Quia enim et.',
},
{
Amount: '6,200.88',
Date: '2024-02-17',
Payee: 'Luettgen, Mraz and Legros',
'Reference No.': 'REF-1',
Description: 'Occaecati consequuntur cum impedit illo.',
},
];
15 changes: 10 additions & 5 deletions packages/server/src/services/Import/ImportFileProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { Inject, Service } from 'typedi';
import { chain } from 'lodash';
import { Knex } from 'knex';
import { ServiceError } from '@/exceptions';
import { ERRORS, getSheetColumns, getUnmappedSheetColumns, readImportFile } from './_utils';
import {
ERRORS,
getSheetColumns,
getUnmappedSheetColumns,
readImportFile,
} from './_utils';
import { ImportFileCommon } from './ImportFileCommon';
import { ImportFileDataTransformer } from './ImportFileDataTransformer';
import ResourceService from '../Resource/ResourceService';
Expand Down Expand Up @@ -49,10 +54,9 @@ export class ImportFileProcess {
const sheetData = this.importCommon.parseXlsxSheet(buffer);
const header = getSheetColumns(sheetData);

const resourceFields = this.resource.getResourceFields2(
tenantId,
importFile.resource
);
const resource = importFile.resource;
const resourceFields = this.resource.getResourceFields2(tenantId, resource);

// Runs the importing operation with ability to return errors that will happen.
const [successedImport, failedImport, allData] =
await this.uow.withTransaction(
Expand Down Expand Up @@ -91,6 +95,7 @@ export class ImportFileProcess {
const skippedCount = errorsCount;

return {
resource,
createdCount,
skippedCount,
totalCount,
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/services/Import/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface ImportFileMapPOJO {
}

export interface ImportFilePreviewPOJO {
resource: string;
createdCount: number;
skippedCount: number;
totalCount: number;
Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/services/Items/ItemsImportable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Knex } from 'knex';
import { Importable } from '@/services/Import/Importable';
import { IItemCreateDTO } from '@/interfaces';
import { CreateItem } from './CreateItem';
import { ItemsSampleData } from './constants';

@Service()
export class ItemsImportable extends Importable {
Expand All @@ -28,6 +29,6 @@ export class ItemsImportable extends Importable {
* Retrieves the sample data of customers used to download sample sheet.
*/
public sampleData(): any[] {
return [];
return ItemsSampleData;
}
}
Loading
Loading