Skip to content

Commit

Permalink
update faster inventory from dynamics gp
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Feb 19, 2025
1 parent 03a0635 commit 002303a
Show file tree
Hide file tree
Showing 16 changed files with 482 additions and 44 deletions.
3 changes: 3 additions & 0 deletions data/config.defaultValues.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ export declare const configDefaultValues: {
'modules.integrityChecker.worktechEquipment.isEnabled': boolean;
'modules.integrityChecker.worktechEquipment.mappingFunctions': import("../modules/integrityChecker/config/types.js").ConfigModuleIntegrityCheckerMappingFunctions;
'modules.integrityChecker.fasterInventory.isEnabled': boolean;
'modules.integrityChecker.fasterInventory.storerooms': string[];
'modules.integrityChecker.fasterInventory.validation.source': string;
'modules.integrityChecker.fasterInventory.validation.gpLocationCodesToFasterStorerooms': Record<string, string>;
'modules.integrityChecker.fasterInventory.validation.gpItemFilter': ((item: import("@cityssm/dynamics-gp").GPItemWithQuantity) => boolean) | undefined;
'modules.integrityChecker.fasterInventory.validation.updateFaster': boolean;
'modules.integrityChecker.fasterInventory.validation.createInvoiceDefaults': import("../modules/integrityChecker/config/types.js").ConfigIntegrityCheckerItemValidationDynamicsGPCreateInvoiceDefaults | undefined;
'modules.inventoryScanner.isEnabled': boolean;
'modules.inventoryScanner.scannerIpAddressRegex': RegExp;
'modules.inventoryScanner.fasterSync.integrationId': number | undefined;
Expand Down
5 changes: 4 additions & 1 deletion modules/integrityChecker/config/defaultValues.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GPItemWithQuantity } from '@cityssm/dynamics-gp';
import type { ConfigModuleIntegrityCheckerMappingFunctions } from './types.js';
import type { ConfigIntegrityCheckerItemValidationDynamicsGPCreateInvoiceDefaults, ConfigModuleIntegrityCheckerMappingFunctions } from './types.js';
type GpItemFilterFunction = (item: GPItemWithQuantity) => boolean;
declare const _default: {
'modules.integrityChecker.isEnabled': boolean;
Expand All @@ -8,8 +8,11 @@ declare const _default: {
'modules.integrityChecker.worktechEquipment.isEnabled': boolean;
'modules.integrityChecker.worktechEquipment.mappingFunctions': ConfigModuleIntegrityCheckerMappingFunctions;
'modules.integrityChecker.fasterInventory.isEnabled': boolean;
'modules.integrityChecker.fasterInventory.storerooms': string[];
'modules.integrityChecker.fasterInventory.validation.source': string;
'modules.integrityChecker.fasterInventory.validation.gpLocationCodesToFasterStorerooms': Record<string, string>;
'modules.integrityChecker.fasterInventory.validation.gpItemFilter': GpItemFilterFunction | undefined;
'modules.integrityChecker.fasterInventory.validation.updateFaster': boolean;
'modules.integrityChecker.fasterInventory.validation.createInvoiceDefaults': ConfigIntegrityCheckerItemValidationDynamicsGPCreateInvoiceDefaults | undefined;
};
export default _default;
5 changes: 4 additions & 1 deletion modules/integrityChecker/config/defaultValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export default {
'modules.integrityChecker.worktechEquipment.isEnabled': false,
'modules.integrityChecker.worktechEquipment.mappingFunctions': {},
'modules.integrityChecker.fasterInventory.isEnabled': true,
'modules.integrityChecker.fasterInventory.storerooms': [],
'modules.integrityChecker.fasterInventory.validation.source': '',
'modules.integrityChecker.fasterInventory.validation.gpLocationCodesToFasterStorerooms': {},
'modules.integrityChecker.fasterInventory.validation.gpItemFilter': undefined
'modules.integrityChecker.fasterInventory.validation.gpItemFilter': undefined,
'modules.integrityChecker.fasterInventory.validation.updateFaster': false,
'modules.integrityChecker.fasterInventory.validation.createInvoiceDefaults': undefined
};
16 changes: 14 additions & 2 deletions modules/integrityChecker/config/defaultValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

import type { GPItemWithQuantity } from '@cityssm/dynamics-gp'

import type { ConfigModuleIntegrityCheckerMappingFunctions } from './types.js'
import type {
ConfigIntegrityCheckerItemValidationDynamicsGPCreateInvoiceDefaults,
ConfigModuleIntegrityCheckerMappingFunctions
} from './types.js'

type GpItemFilterFunction = (item: GPItemWithQuantity) => boolean

Expand All @@ -21,11 +24,20 @@ export default {

'modules.integrityChecker.fasterInventory.isEnabled': true,

'modules.integrityChecker.fasterInventory.storerooms': [] as string[],

'modules.integrityChecker.fasterInventory.validation.source': '',

'modules.integrityChecker.fasterInventory.validation.gpLocationCodesToFasterStorerooms':
{} as unknown as Record<string, string>,

'modules.integrityChecker.fasterInventory.validation.gpItemFilter':
undefined as unknown as GpItemFilterFunction | undefined
undefined as unknown as GpItemFilterFunction | undefined,

'modules.integrityChecker.fasterInventory.validation.updateFaster': false,

'modules.integrityChecker.fasterInventory.validation.createInvoiceDefaults':
undefined as unknown as
| ConfigIntegrityCheckerItemValidationDynamicsGPCreateInvoiceDefaults
| undefined
} satisfies Record<`modules.integrityChecker.${string}`, unknown>
19 changes: 16 additions & 3 deletions modules/integrityChecker/config/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ import type { AssetResult } from '@cityssm/faster-api';
export type FasterAssetMappingFunction = (fasterAsset: AssetResult) => string | undefined;
type FasterAssetMappingFunctionName = 'fasterAssetToEquipmentId' | 'fasterAssetToEquipmentClass' | 'fasterAssetToEquipmentDescription' | 'fasterAssetToDepartment';
export type ConfigModuleIntegrityCheckerMappingFunctions = Partial<Record<FasterAssetMappingFunctionName, FasterAssetMappingFunction>>;
export interface ConfigItemValidationDynamicsGP {
source: 'dynamicsGP';
export interface ConfigIntegrityCheckerItemValidationDynamicsGPCreateInvoiceDefaults {
vendorId: string;
shipToLocationId: string;
partTypeId: string;
paymentTypeId: string;
purchaseOrderId: string;
purchaseOrderAccountId: string;
taxCodeId: string;
partCategory: string;
}
export interface ConfigIntegrityCheckerItemValidationDynamicsGP {
source: 'dynamicsGp';
gpLocationCodesToFasterStorerooms: Record<string, string>;
gpItemFilter?: (item: GPItemWithQuantity) => boolean;
updateFaster?: boolean;
createInvoiceDefaults?: ConfigIntegrityCheckerItemValidationDynamicsGPCreateInvoiceDefaults;
}
export interface ConfigModuleIntegrityChecker {
fasterAssets?: {
Expand All @@ -21,7 +33,8 @@ export interface ConfigModuleIntegrityChecker {
};
fasterInventory?: {
isEnabled?: boolean;
validation?: ConfigItemValidationDynamicsGP;
storerooms?: string[];
validation?: ConfigIntegrityCheckerItemValidationDynamicsGP;
};
}
export {};
22 changes: 17 additions & 5 deletions modules/integrityChecker/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@ export type ConfigModuleIntegrityCheckerMappingFunctions = Partial<
Record<FasterAssetMappingFunctionName, FasterAssetMappingFunction>
>

export interface ConfigItemValidationDynamicsGP {
source: 'dynamicsGP'
export interface ConfigIntegrityCheckerItemValidationDynamicsGPCreateInvoiceDefaults {
vendorId: string
shipToLocationId: string
partTypeId: string
paymentTypeId: string
purchaseOrderId: string
purchaseOrderAccountId: string
taxCodeId: string
partCategory: string
}

export interface ConfigIntegrityCheckerItemValidationDynamicsGP {
source: 'dynamicsGp'
gpLocationCodesToFasterStorerooms: Record<string, string>
gpItemFilter?: (item: GPItemWithQuantity) => boolean
updateFaster?: boolean
createInvoiceDefaults?: ConfigIntegrityCheckerItemValidationDynamicsGPCreateInvoiceDefaults
}


export interface ConfigModuleIntegrityChecker {
fasterAssets?: {
isEnabled?: boolean
Expand All @@ -37,7 +49,7 @@ export interface ConfigModuleIntegrityChecker {

fasterInventory?: {
isEnabled?: boolean
validation?: ConfigItemValidationDynamicsGP
storerooms?: string[]
validation?: ConfigIntegrityCheckerItemValidationDynamicsGP
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface DynamicsGpInventoryItemToUpdate {
itemNumber: string;
storeroom: string;
fasterItemName: string | null;
fasterBinLocation: string | null;
fasterQuantityInStock: number | null;
gpItemName: string | null;
gpBinLocation: string | null;
gpAlternateLocation: string | null;
gpCurrentCost: number | null;
gpQuantityInStock: number | null;
}
export default function getDynamicsGpInventoryItemsToUpdateInFaster(): DynamicsGpInventoryItemToUpdate[];
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import fasterInventoryItemConstants from '@cityssm/faster-constants/inventory/items';
import sqlite from 'better-sqlite3';
import { databasePath } from './helpers.database.js';
export default function getDynamicsGpInventoryItemsToUpdateInFaster() {
const database = sqlite(databasePath, {
readonly: true
});
const result = database
.prepare(`select
ifnull(f.itemNumber, gp.itemNumber) as itemNumber,
ifnull(f.storeroom, gp.fasterStoreroom) as storeroom,
f.itemName as fasterItemName,
case when f.binLocation = 'Undefined' then '' else f.binLocation end as fasterBinLocation,
f.quantityInStock as fasterQuantityInStock,
gp.itemDescription as gpItemName,
gp.binNumber as gpBinLocation,
gp.itemShortName as gpAlternateLocation,
gp.currentCost as gpCurrentCost,
gp.quantityOnHand as gpQuantityInStock
from FasterInventoryItems f
full join DynamicsGpInventoryItems gp
on f.itemNumber = gp.itemNumber and f.storeroom = gp.fasterStoreroom
where (f.itemNumber is null and gp.quantityOnHand > 0)
or gp.itemNumber is null
or f.itemName <> substring(gp.itemDescription, 1, ${fasterInventoryItemConstants.itemName.maxLength})
or case when f.binLocation = 'Undefined' then '' else f.binLocation end <> substr(gp.binNumber, 1, ${fasterInventoryItemConstants.binLocation.maxLength})
order by gpItemName desc`)
.all();
database.close();
return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import fasterInventoryItemConstants from '@cityssm/faster-constants/inventory/items'
import sqlite from 'better-sqlite3'

import { databasePath } from './helpers.database.js'

interface DynamicsGpInventoryItemToUpdate {
itemNumber: string
storeroom: string

fasterItemName: string | null
fasterBinLocation: string | null
fasterQuantityInStock: number | null

gpItemName: string | null
gpBinLocation: string | null
gpAlternateLocation: string | null
gpCurrentCost: number | null
gpQuantityInStock: number | null
}

export default function getDynamicsGpInventoryItemsToUpdateInFaster(): DynamicsGpInventoryItemToUpdate[] {
const database = sqlite(databasePath, {
readonly: true
})

const result = database
.prepare(
`select
ifnull(f.itemNumber, gp.itemNumber) as itemNumber,
ifnull(f.storeroom, gp.fasterStoreroom) as storeroom,
f.itemName as fasterItemName,
case when f.binLocation = 'Undefined' then '' else f.binLocation end as fasterBinLocation,
f.quantityInStock as fasterQuantityInStock,
gp.itemDescription as gpItemName,
gp.binNumber as gpBinLocation,
gp.itemShortName as gpAlternateLocation,
gp.currentCost as gpCurrentCost,
gp.quantityOnHand as gpQuantityInStock
from FasterInventoryItems f
full join DynamicsGpInventoryItems gp
on f.itemNumber = gp.itemNumber and f.storeroom = gp.fasterStoreroom
where (f.itemNumber is null and gp.quantityOnHand > 0)
or gp.itemNumber is null
or f.itemName <> substring(gp.itemDescription, 1, ${fasterInventoryItemConstants.itemName.maxLength})
or case when f.binLocation = 'Undefined' then '' else f.binLocation end <> substr(gp.binNumber, 1, ${fasterInventoryItemConstants.binLocation.maxLength})
order by gpItemName desc`
)
.all() as DynamicsGpInventoryItemToUpdate[]

database.close()

return result
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import type sqlite from 'better-sqlite3';
export declare function refreshDynamicsGpInventory(database: sqlite.Database): Promise<void>;
export declare function refreshDynamicsGpInventory(): Promise<boolean>;
export declare function updateInventoryInFaster(): Promise<void>;
Loading

0 comments on commit 002303a

Please # to comment.