tango-app-api-store-builder 1.0.9 → 1.0.11-dont-user
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Hip Hop Placement_25_Septmeber_2025.xlsx +0 -0
- package/Phonic_Tango_254.xlsb +0 -0
- package/data/Meller Planned stores.xlsx +0 -0
- package/data/Stranger Things - Tango.xlsx +0 -0
- package/package.json +1 -1
- package/src/controllers/fixtureTemplate.controller.js +5 -2
- package/src/controllers/managePlano.controller.js +12 -0
- package/src/controllers/script.controller.js +1718 -258
- package/src/routes/script.routes.js +2 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable quotes */
|
|
2
2
|
// import { writeFileSync } from 'fs';
|
|
3
3
|
import xlsx from 'xlsx';
|
|
4
|
-
import { logger, fileUpload } from 'tango-app-api-middleware';
|
|
4
|
+
import { logger, fileUpload, download } from 'tango-app-api-middleware';
|
|
5
5
|
import * as storeBuilderService from '../service/storeBuilder.service.js';
|
|
6
6
|
import * as storeService from '../service/store.service.js';
|
|
7
7
|
import * as planoService from '../service/planogram.service.js';
|
|
@@ -11311,6 +11311,8 @@ export async function migrateOvmToIvm( req, res ) {
|
|
|
11311
11311
|
if ( fixtureTarget ) {
|
|
11312
11312
|
if ( req.body.type === 'ivm' ) {
|
|
11313
11313
|
fixtureTarget.header.label = rule.Header;
|
|
11314
|
+
fixtureTarget.templateGroupNumber = k+1;
|
|
11315
|
+
fixtureTarget.templateGroupMax = groupRule.fixtureCount;
|
|
11314
11316
|
}
|
|
11315
11317
|
}
|
|
11316
11318
|
|
|
@@ -11358,6 +11360,8 @@ export async function migrateOvmToIvm( req, res ) {
|
|
|
11358
11360
|
if ( fixtureTarget ) {
|
|
11359
11361
|
if ( req.body.type === 'ivm' ) {
|
|
11360
11362
|
fixtureTarget.header.label = rule.Header;
|
|
11363
|
+
fixtureTarget.templateGroupNumber = k+1;
|
|
11364
|
+
fixtureTarget.templateGroupMax = groupRule.fixtureCount;
|
|
11361
11365
|
}
|
|
11362
11366
|
}
|
|
11363
11367
|
|
|
@@ -11419,6 +11423,8 @@ export async function migrateOvmToIvm( req, res ) {
|
|
|
11419
11423
|
if ( fixtureTarget ) {
|
|
11420
11424
|
if ( req.body.type === 'ivm' ) {
|
|
11421
11425
|
fixtureTarget.header.label = rule.Header_1;
|
|
11426
|
+
fixtureTarget.templateGroupNumber = k+1;
|
|
11427
|
+
fixtureTarget.templateGroupMax = groupRule.fixtureCount;
|
|
11422
11428
|
}
|
|
11423
11429
|
}
|
|
11424
11430
|
|
|
@@ -12004,193 +12010,226 @@ export async function migrateOvmToIvm( req, res ) {
|
|
|
12004
12010
|
export async function updateFixtureDetails() {
|
|
12005
12011
|
const mbqWorkbook = xlsx.readFile( './data/Fixture capacity.xlsx' );
|
|
12006
12012
|
|
|
12007
|
-
const
|
|
12008
|
-
const
|
|
12009
|
-
|
|
12010
|
-
const mbqJsonData = xlsx.utils.sheet_to_json( mbqSheet );
|
|
12011
|
-
|
|
12012
|
-
const mbqData = JSON.parse( JSON.stringify( mbqJsonData, null, 2 ) );
|
|
12013
|
-
|
|
12014
|
-
async function updateFixtures( fixtures = [] ) {
|
|
12015
|
-
for ( let i = 0; i < fixtures.length; i++ ) {
|
|
12016
|
-
const fixture = fixtures[i];
|
|
12017
|
-
const fixtureId = fixture._id;
|
|
12018
|
-
delete fixture._id;
|
|
12019
|
-
|
|
12020
|
-
|
|
12021
|
-
await storeFixtureService.updateOne( { _id: fixtureId }, fixture );
|
|
12022
|
-
}
|
|
12023
|
-
}
|
|
12024
|
-
|
|
12025
|
-
const storeList = await planoService.aggregate( [
|
|
12026
|
-
{
|
|
12027
|
-
$group: {
|
|
12028
|
-
_id: null,
|
|
12029
|
-
stores: {
|
|
12030
|
-
$addToSet: "$storeName",
|
|
12031
|
-
},
|
|
12013
|
+
const combinationFixturesSheetName = 'Combined fixture logic';
|
|
12014
|
+
const combinationFixtureSheet = strategyWorkbook.Sheets[combinationFixturesSheetName];
|
|
12032
12015
|
|
|
12033
|
-
|
|
12034
|
-
},
|
|
12035
|
-
{
|
|
12036
|
-
$project: {
|
|
12037
|
-
stores: 1,
|
|
12038
|
-
},
|
|
12039
|
-
},
|
|
12040
|
-
] );
|
|
12016
|
+
const combinationFixtureJsonData = xlsx.utils.sheet_to_json( combinationFixtureSheet );
|
|
12041
12017
|
|
|
12042
|
-
const
|
|
12018
|
+
const combinationFixtureData = JSON.parse( JSON.stringify( combinationFixtureJsonData, null, 2 ) );
|
|
12019
|
+
const checkHeaderExistInFixtures = ( fixtures, headerName ) => {
|
|
12020
|
+
if ( !headerName || !Array.isArray( fixtures ) ) return false;
|
|
12043
12021
|
|
|
12044
|
-
|
|
12045
|
-
"VC Eye / LK Air": "VC Eye / LK Air",
|
|
12046
|
-
"JJ Eye": "JJ Eye + OD",
|
|
12047
|
-
"OD Eye": "JJ Eye + OD",
|
|
12048
|
-
"VC Sun": "VC Sun",
|
|
12049
|
-
"JJ Sun": "JJ Sun",
|
|
12050
|
-
"Hooper": "Hooper",
|
|
12051
|
-
"Hooper Eye": "Hooper",
|
|
12052
|
-
"LPL Eye": "LPL",
|
|
12053
|
-
"Fossil Eye": "Fossil",
|
|
12022
|
+
const normalizedHeader = headerName.replace( /\s+/g, '' ).toLowerCase();
|
|
12054
12023
|
|
|
12055
|
-
|
|
12056
|
-
|
|
12057
|
-
|
|
12058
|
-
|
|
12059
|
-
|
|
12060
|
-
"JJ Sun Metal": "JJ Sun",
|
|
12061
|
-
"LK Air": "VC Eye / LK Air",
|
|
12062
|
-
"JJ Sun Non Metal": "JJ Sun",
|
|
12063
|
-
"Hustlr": "Hustlr",
|
|
12064
|
-
"Tentpole": "Tentpole",
|
|
12065
|
-
"VC Sun Non Metal": "VC Sun",
|
|
12066
|
-
"Owndays Eye": "OD Eye",
|
|
12067
|
-
"VC Eye Metal": "VC Eye / LK Air",
|
|
12068
|
-
"VC Eye Non-Metal": "VC Eye / LK Air",
|
|
12069
|
-
"Work Essentials": "VC Eye / LK Air",
|
|
12070
|
-
"Work Essentials 1": "VC Eye / LK Air",
|
|
12071
|
-
"Work Essentials 2": "VC Eye / LK Air",
|
|
12072
|
-
"Work Essentials 3": "VC Eye / LK Air",
|
|
12073
|
-
"Work Essentials 4": "VC Eye / LK Air",
|
|
12074
|
-
"Trending": "VC Eye / LK Air",
|
|
12075
|
-
"Trending 1": "VC Eye / LK Air",
|
|
12076
|
-
"Trending 2": "VC Eye / LK Air",
|
|
12077
|
-
"Trending 3": "VC Eye / LK Air",
|
|
12078
|
-
"Trending 4": "VC Eye / LK Air",
|
|
12079
|
-
"Innovation": "VC Eye / LK Air",
|
|
12080
|
-
"Premium Work": "JJ Eye + OD",
|
|
12081
|
-
"Premium Work 1": "JJ Eye + OD",
|
|
12082
|
-
"Premium Work 2": "JJ Eye + OD",
|
|
12083
|
-
"Premium Work 3": "JJ Eye + OD",
|
|
12084
|
-
"Premium Work 4": "JJ Eye + OD",
|
|
12085
|
-
"Shades": "VC Sun",
|
|
12086
|
-
"Shades 1": "VC Sun",
|
|
12087
|
-
"Shades 2": "VC Sun",
|
|
12088
|
-
"Shades 3": "VC Sun",
|
|
12089
|
-
"Shades 4": "VC Sun",
|
|
12090
|
-
"Premium Shades": "JJ Sun",
|
|
12091
|
-
"Premium Shades 1": "JJ Sun",
|
|
12092
|
-
"Premium Shades 2": "JJ Sun",
|
|
12093
|
-
"Premium Shades 3": "JJ Sun",
|
|
12094
|
-
"Kids": "Hooper",
|
|
12095
|
-
"Premium Trending": "JJ Eye + OD",
|
|
12096
|
-
"Premium Trending 1": "JJ Eye + OD",
|
|
12097
|
-
"Premium Trending 2": "JJ Eye + OD",
|
|
12098
|
-
"Premium Trending 3": "JJ Eye + OD",
|
|
12099
|
-
"Premium Trending 4": "JJ Eye + OD",
|
|
12100
|
-
"JJ Eye + OD": "JJ Eye + OD",
|
|
12101
|
-
"Vc Eye /LK Air": "VC Eye / LK Air",
|
|
12102
|
-
"JJ eye": "JJ Eye",
|
|
12024
|
+
return fixtures.some( ( fixture ) => {
|
|
12025
|
+
if ( !fixture.header?.label ) return false;
|
|
12026
|
+
const normalizedFixtureHeader = fixture.header.label.replace( /\s+/g, '' ).toLowerCase();
|
|
12027
|
+
return normalizedFixtureHeader === normalizedHeader;
|
|
12028
|
+
} );
|
|
12103
12029
|
};
|
|
12104
12030
|
|
|
12105
|
-
|
|
12106
|
-
const
|
|
12107
|
-
|
|
12108
|
-
|
|
12109
|
-
|
|
12110
|
-
|
|
12111
|
-
|
|
12112
|
-
|
|
12031
|
+
async function processFixtures( allFixtures ) {
|
|
12032
|
+
const templateGroupMapping = {
|
|
12033
|
+
"VC Eye / LK Air": "VC Eye / LK Air",
|
|
12034
|
+
"JJ Eye": "JJ Eye + OD",
|
|
12035
|
+
"OD Eye": "JJ Eye + OD",
|
|
12036
|
+
"VC Sun": "VC Sun",
|
|
12037
|
+
"JJ Sun": "JJ Sun",
|
|
12038
|
+
"Hooper": "Hooper",
|
|
12039
|
+
"Hooper Eye": "Hooper",
|
|
12040
|
+
"LPL Eye": "LPL",
|
|
12041
|
+
"Fossil Eye": "Fossil",
|
|
12042
|
+
|
|
12043
|
+
"Almost Gone 1": "VC Eye / LK Air",
|
|
12044
|
+
"Almost Gone": "VC Eye / LK Air",
|
|
12045
|
+
"VC Sun Metal": "VC Sun",
|
|
12046
|
+
"LPL Eye": "LPL",
|
|
12047
|
+
"JJ Eye Metal": "JJ Eye + OD",
|
|
12048
|
+
"JJ Sun Metal": "JJ Sun",
|
|
12049
|
+
"LK Air": "VC Eye / LK Air",
|
|
12050
|
+
"JJ Sun Non Metal": "JJ Sun",
|
|
12051
|
+
"Hustlr": "Hustlr",
|
|
12052
|
+
"Tentpole": "Tentpole",
|
|
12053
|
+
"VC Sun Non Metal": "VC Sun",
|
|
12054
|
+
"Owndays Eye": "OD Eye",
|
|
12055
|
+
"Owndays": "JJ Eye + OD",
|
|
12056
|
+
"VC Eye Metal": "VC Eye / LK Air",
|
|
12057
|
+
"VC Eye Non-Metal": "VC Eye / LK Air",
|
|
12058
|
+
"Work Essentials": "VC Eye / LK Air",
|
|
12059
|
+
"Work essentials": "VC Eye / LK Air",
|
|
12060
|
+
"Work Essentials 1": "VC Eye / LK Air",
|
|
12061
|
+
"Work Essentials 2": "VC Eye / LK Air",
|
|
12062
|
+
"Work Essentials 3": "VC Eye / LK Air",
|
|
12063
|
+
"Work Essentials 4": "VC Eye / LK Air",
|
|
12064
|
+
"Trending": "VC Eye / LK Air",
|
|
12065
|
+
"Trending 1": "VC Eye / LK Air",
|
|
12066
|
+
"Trending 2": "VC Eye / LK Air",
|
|
12067
|
+
"Trending 3": "VC Eye / LK Air",
|
|
12068
|
+
"Trending 4": "VC Eye / LK Air",
|
|
12069
|
+
"Innovation": "VC Eye / LK Air",
|
|
12070
|
+
"Premium Work": "JJ Eye + OD",
|
|
12071
|
+
"Premium work": "JJ Eye + OD",
|
|
12072
|
+
"Premium Work 1": "JJ Eye + OD",
|
|
12073
|
+
"Premium Work 2": "JJ Eye + OD",
|
|
12074
|
+
"Premium Work 3": "JJ Eye + OD",
|
|
12075
|
+
"Premium Work 4": "JJ Eye + OD",
|
|
12076
|
+
"Shades": "VC Sun",
|
|
12077
|
+
"Shades 1": "VC Sun",
|
|
12078
|
+
"Shades 2": "VC Sun",
|
|
12079
|
+
"Shades 3": "VC Sun",
|
|
12080
|
+
"Shades 4": "VC Sun",
|
|
12081
|
+
"Premium Shades": "JJ Sun",
|
|
12082
|
+
"Premium Shades 1": "JJ Sun",
|
|
12083
|
+
"Premium Shades 2": "JJ Sun",
|
|
12084
|
+
"Premium Shades 3": "JJ Sun",
|
|
12085
|
+
"Kids": "Hooper",
|
|
12086
|
+
"Premium Trending": "JJ Eye + OD",
|
|
12087
|
+
"Premium trending": "JJ Eye + OD",
|
|
12088
|
+
"Premium Trending 1": "JJ Eye + OD",
|
|
12089
|
+
"Premium Trending 2": "JJ Eye + OD",
|
|
12090
|
+
"Premium Trending 3": "JJ Eye + OD",
|
|
12091
|
+
"Premium Trending 4": "JJ Eye + OD",
|
|
12092
|
+
"JJ Eye + OD": "JJ Eye + OD",
|
|
12093
|
+
"Vc Eye /LK Air": "VC Eye / LK Air",
|
|
12094
|
+
"JJ eye": "JJ Eye + OD",
|
|
12095
|
+
"JJ Eye tentpole": "JJ Eye + OD",
|
|
12096
|
+
"CL": "CL",
|
|
12097
|
+
"JJ sun": "JJ Sun",
|
|
12098
|
+
"John Jacobs": "JJ Eye",
|
|
12099
|
+
"John Jacobs ": "JJ Eye",
|
|
12100
|
+
"Hooper Sun": "Hooper",
|
|
12101
|
+
"Polaroid Eye": "Polaroid Eye",
|
|
12102
|
+
"Polaroid": "Polaroid Eye",
|
|
12103
|
+
"Le Petit Lunetier": "LPL",
|
|
12104
|
+
"Vincent Chase": "VC Eye / LK Air",
|
|
12105
|
+
"VC sun": "VC Sun",
|
|
12106
|
+
"Fossil": "Fossil",
|
|
12107
|
+
"Accessories": "Accessories",
|
|
12108
|
+
"Cl": "CL",
|
|
12109
|
+
"VC Eye Half Rim & Rimless": "VC Eye / LK Air",
|
|
12110
|
+
"Innovation 1": "VC Eye / LK Air",
|
|
12111
|
+
"VC LK Air": "VC Eye / LK Air",
|
|
12112
|
+
"VC LK AIr": "VC Eye / LK Air",
|
|
12113
|
+
"Vincent Chase Lenskart air": "VC Eye / LK Air",
|
|
12114
|
+
"JJ Eye Half Rim & Rimless": "JJ Eye + OD",
|
|
12115
|
+
"All JJ Eye": "JJ Eye + OD",
|
|
12116
|
+
"BZ": "BZ",
|
|
12117
|
+
};
|
|
12118
|
+
let vcLkCount = 1;
|
|
12113
12119
|
|
|
12114
|
-
for ( let j = 0; j <
|
|
12115
|
-
const fixture =
|
|
12120
|
+
for ( let j = 0; j < allFixtures.length; j++ ) {
|
|
12121
|
+
const fixture = allFixtures[j];
|
|
12116
12122
|
|
|
12117
12123
|
const fixtureShelves = await fixtureShelfService.find( { fixtureId: fixture._id } );
|
|
12118
12124
|
|
|
12119
12125
|
const brandNames = new Set();
|
|
12120
|
-
|
|
12121
|
-
const zoneMap = {
|
|
12122
|
-
"Top": [],
|
|
12123
|
-
"Mid": [],
|
|
12124
|
-
"Bottom": [],
|
|
12125
|
-
};
|
|
12126
|
+
const zoneMap = { Top: [], Mid: [], Bottom: [] };
|
|
12126
12127
|
|
|
12127
12128
|
fixtureShelves.forEach( ( shelf ) => {
|
|
12128
|
-
|
|
12129
|
-
|
|
12129
|
+
const shelfObj = shelf.toObject();
|
|
12130
|
+
|
|
12131
|
+
if ( shelf.zone === "Top" ) {
|
|
12132
|
+
zoneMap.Top = shelfObj.productBrandName;
|
|
12130
12133
|
}
|
|
12131
|
-
if ( shelf.zone ===
|
|
12132
|
-
zoneMap.Mid =
|
|
12134
|
+
if ( shelf.zone === "Mid" ) {
|
|
12135
|
+
zoneMap.Mid = shelfObj.productBrandName;
|
|
12133
12136
|
}
|
|
12134
|
-
if ( shelf.zone ===
|
|
12135
|
-
zoneMap.Bottom =
|
|
12137
|
+
if ( shelf.zone === "Bottom" ) {
|
|
12138
|
+
zoneMap.Bottom = shelfObj.productBrandName;
|
|
12136
12139
|
}
|
|
12137
|
-
|
|
12140
|
+
|
|
12141
|
+
shelfObj.productBrandName.forEach( ( brand ) => {
|
|
12138
12142
|
brandNames.add( brand );
|
|
12139
12143
|
} );
|
|
12140
12144
|
} );
|
|
12141
12145
|
|
|
12142
12146
|
fixture.productBrandName = [ ...brandNames ];
|
|
12143
12147
|
|
|
12144
|
-
if ( !fixture
|
|
12145
|
-
|
|
12148
|
+
if ( !fixture?.header?.label ) {
|
|
12149
|
+
// console.log( fixture.description, 'test' );
|
|
12150
|
+
// fixture.header.label = fixture?.description?.replace( /[\r\n]+/g, " " ).trim();
|
|
12151
|
+
// console.log( fixture.header.label, 'tesfdg' );
|
|
12146
12152
|
}
|
|
12147
12153
|
|
|
12148
|
-
|
|
12149
12154
|
if ( templateGroupMapping?.[fixture.header.label] ) {
|
|
12150
|
-
if ( templateGroupMapping?.[fixture.header.label] ===
|
|
12151
|
-
if (
|
|
12152
|
-
|
|
12153
|
-
|
|
12154
|
-
|
|
12155
|
+
if ( templateGroupMapping?.[fixture.header.label] === "Premium Trending" || templateGroupMapping?.[fixture.header.label] === "Premium trending" ) {
|
|
12156
|
+
if (
|
|
12157
|
+
brandNames.has( "LPL Eye" ) ||
|
|
12158
|
+
brandNames.has( "LPL" ) ||
|
|
12159
|
+
brandNames.has( "LPL PIDs" )
|
|
12160
|
+
) {
|
|
12161
|
+
fixture.templateGroupName = "LPL";
|
|
12162
|
+
} else if ( brandNames.has( "Fossil Eye" ) || brandNames.has( "Fossil PIDs" ) ) {
|
|
12163
|
+
fixture.templateGroupName = "Fossil";
|
|
12155
12164
|
} else {
|
|
12156
|
-
fixture.templateGroupName =
|
|
12165
|
+
fixture.templateGroupName = "JJ Eye + OD";
|
|
12157
12166
|
}
|
|
12158
12167
|
} else {
|
|
12159
12168
|
fixture.templateGroupName = templateGroupMapping[fixture.header.label];
|
|
12160
12169
|
}
|
|
12161
12170
|
} else {
|
|
12162
|
-
|
|
12171
|
+
if ( fixture.header?.label?.includes( '+' ) ) {
|
|
12172
|
+
const combinationFixture = combinationFixtureData.find( ( fix ) => fix.Header === fixture.header.label );
|
|
12173
|
+
if ( combinationFixture ) {
|
|
12174
|
+
if ( combinationFixture.Mapping === 'JJ eye + OD eye' ) {
|
|
12175
|
+
fixture.templateGroupName = 'JJ Eye + OD';
|
|
12176
|
+
} else {
|
|
12177
|
+
fixture.templateGroupName = combinationFixture.Mapping;
|
|
12178
|
+
}
|
|
12179
|
+
}
|
|
12180
|
+
} else {
|
|
12181
|
+
console.log( fixture.storeName );
|
|
12182
|
+
console.log( fixture.header.label );
|
|
12183
|
+
if ( fixture.header.label ) {
|
|
12184
|
+
console.log( unknown );
|
|
12185
|
+
}
|
|
12186
|
+
// fixture.templateGroupName = fixture.header.label;
|
|
12187
|
+
}
|
|
12163
12188
|
}
|
|
12164
12189
|
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
|
|
12168
|
-
|
|
12169
|
-
|
|
12170
|
-
|
|
12171
|
-
|
|
12172
|
-
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
|
|
12176
|
-
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12190
|
+
if (
|
|
12191
|
+
( !fixture.associatedElementType && !fixture.associatedElementNumber ) &&
|
|
12192
|
+
fixture.templateGroupName === "VC Eye / LK Air"
|
|
12193
|
+
) {
|
|
12194
|
+
if ( vcLkCount === 1 || vcLkCount === 2 ) {
|
|
12195
|
+
const fixtureTarget = allFixtures.find( ( fix ) => fix._id === fixture._id );
|
|
12196
|
+
if ( fixtureTarget ) {
|
|
12197
|
+
if (
|
|
12198
|
+
!checkHeaderExistInFixtures( allFixtures, "Tentpole" ) &&
|
|
12199
|
+
!checkHeaderExistInFixtures( allFixtures, "Hustlr" )
|
|
12200
|
+
) {
|
|
12201
|
+
if ( vcLkCount === 1 ) {
|
|
12202
|
+
fixtureTarget.header.label = "Tentpole";
|
|
12203
|
+
fixture.templateGroupName = "Tentpole";
|
|
12204
|
+
} else if ( vcLkCount === 2 ) {
|
|
12205
|
+
fixtureTarget.header.label = "Hustlr";
|
|
12206
|
+
fixture.templateGroupName = "Hustlr";
|
|
12207
|
+
}
|
|
12208
|
+
} else if ( !checkHeaderExistInFixtures( allFixtures, "Tentpole" ) ) {
|
|
12209
|
+
fixtureTarget.header.label = "Tentpole";
|
|
12210
|
+
fixture.templateGroupName = "Tentpole";
|
|
12211
|
+
} else if ( !checkHeaderExistInFixtures( allFixtures, "Hustlr" ) ) {
|
|
12212
|
+
fixtureTarget.header.label = "Hustlr";
|
|
12213
|
+
fixture.templateGroupName = "Hustlr";
|
|
12214
|
+
}
|
|
12215
|
+
}
|
|
12216
|
+
}
|
|
12217
|
+
vcLkCount += 1;
|
|
12183
12218
|
}
|
|
12184
12219
|
|
|
12185
|
-
|
|
12220
|
+
let response = await storeFixtureService.updateOne( { _id: fixture._id }, { templateGroupName: fixture.templateGroupName } );
|
|
12221
|
+
console.log( response );
|
|
12186
12222
|
}
|
|
12187
12223
|
|
|
12188
|
-
|
|
12189
|
-
|
|
12190
|
-
console.log( store, 'updated' );
|
|
12224
|
+
console.log( "updated" );
|
|
12191
12225
|
}
|
|
12226
|
+
|
|
12227
|
+
let fixtureDetails = await storeFixtureService.find( {} );
|
|
12228
|
+
processFixtures( fixtureDetails );
|
|
12192
12229
|
}
|
|
12193
12230
|
|
|
12231
|
+
// updateFixtureDetails();
|
|
12232
|
+
|
|
12194
12233
|
|
|
12195
12234
|
export async function readExcel( req, res ) {
|
|
12196
12235
|
try {
|
|
@@ -12245,7 +12284,6 @@ export async function readExcel( req, res ) {
|
|
|
12245
12284
|
return res.sendError( e, 500 );
|
|
12246
12285
|
}
|
|
12247
12286
|
}
|
|
12248
|
-
// updateFixtureDetails();
|
|
12249
12287
|
|
|
12250
12288
|
async function deriveSubTemplatesFromStoreFixtures() {
|
|
12251
12289
|
async function getFixtures( query ) {
|
|
@@ -12300,7 +12338,9 @@ async function deriveSubTemplatesFromStoreFixtures() {
|
|
|
12300
12338
|
for ( let index = 0; index < storeFixtures.length; index++ ) {
|
|
12301
12339
|
const fixture = storeFixtures[index];
|
|
12302
12340
|
|
|
12303
|
-
let mapKey = `${fixture.
|
|
12341
|
+
let mapKey = `${fixture.templateGroupName}${fixture.templateGroupMax}${fixture.templateGroupNumber}`;
|
|
12342
|
+
|
|
12343
|
+
// let mapKey = `${fixture.fixtureCategory}${fixture.fixtureWidth.value}${fixture.fixtureWidth.unit}${fixture.header.label}`;
|
|
12304
12344
|
|
|
12305
12345
|
// const shelfIdentifier = `${fixture.shelfConfig.length}${JSON.stringify(
|
|
12306
12346
|
// fixture.productBrandName,
|
|
@@ -12356,7 +12396,9 @@ async function deriveSubTemplatesFromStoreFixtures() {
|
|
|
12356
12396
|
templateIndex = maxIndex + 1;
|
|
12357
12397
|
}
|
|
12358
12398
|
|
|
12359
|
-
|
|
12399
|
+
fixture.templateGroupMax = fixture?.templateGroupMax ?? 1;
|
|
12400
|
+
fixture.templateGroupNumber = fixture?.templateGroupNumber ?? 1;
|
|
12401
|
+
const templateName = `${fixture.templateGroupName}-rule-${fixture.templateGroupMax}-fixture-${fixture.templateGroupNumber}-varient-${templateIndex}`;
|
|
12360
12402
|
|
|
12361
12403
|
const fixtureTemplateData = {
|
|
12362
12404
|
...fixture,
|
|
@@ -12367,6 +12409,19 @@ async function deriveSubTemplatesFromStoreFixtures() {
|
|
|
12367
12409
|
};
|
|
12368
12410
|
|
|
12369
12411
|
delete fixtureTemplateData._id;
|
|
12412
|
+
delete fixtureTemplateData.masterTemplateId;
|
|
12413
|
+
|
|
12414
|
+
// const templateName = `${fixture.header.label}-${fixture.fixtureCategory}-${fixture.fixtureWidth.value}-${fixture.fixtureWidth.unit}-varient-${templateIndex}`;
|
|
12415
|
+
|
|
12416
|
+
// const fixtureTemplateData = {
|
|
12417
|
+
// ...fixture,
|
|
12418
|
+
// fixtureName: templateName,
|
|
12419
|
+
// crestMapKey: mapKey,
|
|
12420
|
+
// templateType: 'sub',
|
|
12421
|
+
// templateIndex,
|
|
12422
|
+
// };
|
|
12423
|
+
|
|
12424
|
+
// delete fixtureTemplateData._id;
|
|
12370
12425
|
|
|
12371
12426
|
const fixtureTemplate = await fixtureConfigService.upsertOne(
|
|
12372
12427
|
{ crestMapKey: mapKey, templateType: 'sub' },
|
|
@@ -12490,7 +12545,7 @@ async function deriveLibrariesFromMasterTemplate() {
|
|
|
12490
12545
|
console.log( 'updated' );
|
|
12491
12546
|
}
|
|
12492
12547
|
|
|
12493
|
-
// deriveLibrariesFromMasterTemplate()
|
|
12548
|
+
// deriveLibrariesFromMasterTemplate();
|
|
12494
12549
|
|
|
12495
12550
|
async function deriveMasterTemplatesFromStoreFixtures() {
|
|
12496
12551
|
async function getFixtures( query ) {
|
|
@@ -12612,11 +12667,11 @@ export async function groupFixture( req, res ) {
|
|
|
12612
12667
|
}, {} );
|
|
12613
12668
|
let fixtureData = [];
|
|
12614
12669
|
let descOrder = [ "5", "3" ];
|
|
12615
|
-
Object.keys( groupWallFloor ).
|
|
12670
|
+
await Promise.all( Object.keys( groupWallFloor ).map( async ( fixt ) => {
|
|
12616
12671
|
let wDetails = groupWallFloor[fixt];
|
|
12617
12672
|
wDetails.sort( ( a, b ) => a.associatedElementFixtureNumber - b.associatedElementFixtureNumber );
|
|
12618
|
-
let relativePositionDetails = new Map( wDetails.map( ( ele, index ) => [ index, ele.relativePosition ] ) );
|
|
12619
|
-
|
|
12673
|
+
// let relativePositionDetails = new Map( wDetails.map( ( ele, index ) => [ index, ele.relativePosition ] ) );
|
|
12674
|
+
let rearrangeOrder = JSON.parse( JSON.stringify( wDetails ) );
|
|
12620
12675
|
function findIndex( header ) {
|
|
12621
12676
|
const key = header.toLowerCase().trim();
|
|
12622
12677
|
|
|
@@ -12632,7 +12687,7 @@ export async function groupFixture( req, res ) {
|
|
|
12632
12687
|
|
|
12633
12688
|
return Infinity;
|
|
12634
12689
|
}
|
|
12635
|
-
|
|
12690
|
+
rearrangeOrder.sort( ( a, b ) => {
|
|
12636
12691
|
let num = fixt.split( ' ' )[1];
|
|
12637
12692
|
if ( descOrder.includes( ( num ) ) ) {
|
|
12638
12693
|
return findIndex( b.header.label ) - findIndex( a.header.label );
|
|
@@ -12640,15 +12695,41 @@ export async function groupFixture( req, res ) {
|
|
|
12640
12695
|
return findIndex( a.header.label ) - findIndex( b.header.label );
|
|
12641
12696
|
}
|
|
12642
12697
|
} );
|
|
12643
|
-
wDetails.
|
|
12698
|
+
await Promise.all( wDetails.map( async ( ele, index ) => {
|
|
12699
|
+
console.log( index );
|
|
12644
12700
|
let data = {
|
|
12645
|
-
|
|
12646
|
-
|
|
12701
|
+
"header.label": rearrangeOrder[index].header.label,
|
|
12702
|
+
"templateGroupName": rearrangeOrder[index].templateGroupName,
|
|
12647
12703
|
};
|
|
12704
|
+
// ele.header.label = rearrangeOrder[index].header.label;
|
|
12705
|
+
// ele.templateGroupName = rearrangeOrder[index].templateGroupName;
|
|
12706
|
+
let query = [
|
|
12707
|
+
{
|
|
12708
|
+
$match: {
|
|
12709
|
+
fixtureId: new mongoose.Types.ObjectId( rearrangeOrder[index]._id ),
|
|
12710
|
+
},
|
|
12711
|
+
},
|
|
12712
|
+
{
|
|
12713
|
+
$unwind: "$productBrandName", // flatten array elements
|
|
12714
|
+
},
|
|
12715
|
+
{
|
|
12716
|
+
$group: {
|
|
12717
|
+
_id: '$zone',
|
|
12718
|
+
product: {
|
|
12719
|
+
$addToSet: '$productBrandName',
|
|
12720
|
+
},
|
|
12721
|
+
},
|
|
12722
|
+
},
|
|
12723
|
+
];
|
|
12724
|
+
let getShelfDetails = await fixtureShelfService.aggregate( query );
|
|
12725
|
+
await Promise.all( getShelfDetails.map( async ( shelf ) => {
|
|
12726
|
+
await fixtureShelfService.updateMany( { zone: shelf._id, fixtureId: ele._id }, { productBrandName: shelf.product } );
|
|
12727
|
+
} ) );
|
|
12648
12728
|
await storeFixtureService.updateOne( { _id: ele._id }, data );
|
|
12649
|
-
} );
|
|
12729
|
+
} ) );
|
|
12730
|
+
|
|
12650
12731
|
fixtureData.push( ...wDetails );
|
|
12651
|
-
} );
|
|
12732
|
+
} ) );
|
|
12652
12733
|
return res.sendSuccess( fixtureData );
|
|
12653
12734
|
} catch ( e ) {
|
|
12654
12735
|
console.log( e );
|
|
@@ -13044,81 +13125,176 @@ async function updateBlitzCollection() {
|
|
|
13044
13125
|
shelf.productBrandName = [ 'Bits' ];
|
|
13045
13126
|
} );
|
|
13046
13127
|
|
|
13047
|
-
|
|
13128
|
+
return tentpoleFixture;
|
|
13048
13129
|
|
|
13049
|
-
await updateFixtures( [ tentpoleFixture ] );
|
|
13130
|
+
// await updateFixtures( [ tentpoleFixture ] );
|
|
13131
|
+
// }
|
|
13050
13132
|
}
|
|
13051
|
-
}
|
|
13052
13133
|
|
|
13053
|
-
|
|
13054
|
-
|
|
13055
|
-
|
|
13134
|
+
async function checkTentpoleCondition( fixtures ) {
|
|
13135
|
+
return checkVmExistInFixtures( fixtures, 'harry potter' ) && checkVmExistInFixtures( fixtures, 'superman' );
|
|
13136
|
+
}
|
|
13056
13137
|
|
|
13057
|
-
|
|
13138
|
+
const exportData = [];
|
|
13058
13139
|
|
|
13059
13140
|
|
|
13060
|
-
|
|
13061
|
-
|
|
13062
|
-
|
|
13063
|
-
|
|
13141
|
+
for ( let i = 0; i < blitzData.length; i++ ) {
|
|
13142
|
+
const store = blitzData[i];
|
|
13143
|
+
// if ( store?.['Store Code'] === 'LKST2101' ) {
|
|
13144
|
+
const planogram = await planoService.findOne( { storeName: store?.['Store Code'] } );
|
|
13064
13145
|
|
|
13065
|
-
|
|
13146
|
+
if ( !planogram ) continue;
|
|
13066
13147
|
|
|
13067
|
-
|
|
13148
|
+
let storeFixtures = await getFixtures( { planoId: planogram._id } );
|
|
13068
13149
|
|
|
13069
|
-
|
|
13150
|
+
storeFixtures = sortFunc( storeFixtures );
|
|
13070
13151
|
|
|
13071
|
-
|
|
13072
|
-
|
|
13073
|
-
|
|
13152
|
+
const floorFixtures = storeFixtures.filter(
|
|
13153
|
+
( f ) => f.associatedElementType === undefined && f.associatedElementNumber === undefined,
|
|
13154
|
+
);
|
|
13074
13155
|
|
|
13075
13156
|
|
|
13076
|
-
|
|
13077
|
-
|
|
13157
|
+
if ( store?.["Plano placement"] === 'Tentpole eurocentre' ) {
|
|
13158
|
+
await handleTentpoleUpdate( floorFixtures );
|
|
13078
13159
|
|
|
13079
|
-
|
|
13160
|
+
// const isExist = await checkTentpoleCondition( floorFixtures );
|
|
13080
13161
|
|
|
13081
|
-
|
|
13162
|
+
// const replacedCollection = await handleTentpoleUpdate( floorFixtures );
|
|
13082
13163
|
|
|
13083
|
-
|
|
13084
|
-
|
|
13085
|
-
|
|
13086
|
-
|
|
13087
|
-
|
|
13164
|
+
// console.log( replacedCollection?.vmConfig );
|
|
13165
|
+
// const data = {
|
|
13166
|
+
// "Store Code": store?.['Store Code'],
|
|
13167
|
+
// "Was the store having both Harry Potter & Superman on Euro Centers": isExist? true : false,
|
|
13168
|
+
// "What was replaced (Earlier what was it there)": replacedCollection?.vmConfig?.[0]?.vmName,
|
|
13088
13169
|
|
|
13089
|
-
|
|
13170
|
+
// };
|
|
13090
13171
|
|
|
13091
13172
|
// exportData.push( data );
|
|
13092
|
-
|
|
13093
|
-
|
|
13094
|
-
|
|
13095
|
-
|
|
13173
|
+
} else if ( store?.["Plano placement"] === 'First fixture of trending and it should be placed at mid. If store have a sale fixture then 2nd trending fixture should be used and same mid placement should be used' ) {
|
|
13174
|
+
await handleTrendingUpdate( storeFixtures );
|
|
13175
|
+
} else if ( store?.["Plano placement"] === 'First LK air fixture and the placement should be mid' ) {
|
|
13176
|
+
await handleLlAirUpdate( storeFixtures );
|
|
13177
|
+
}
|
|
13178
|
+
console.log( store?.['Store Code'] );
|
|
13096
13179
|
}
|
|
13097
|
-
|
|
13098
|
-
}
|
|
13099
|
-
// }
|
|
13180
|
+
// }
|
|
13100
13181
|
|
|
13101
|
-
|
|
13102
|
-
|
|
13103
|
-
|
|
13104
|
-
|
|
13182
|
+
if ( exportData.length > 0 ) {
|
|
13183
|
+
const worksheet = xlsx.utils.json_to_sheet( exportData );
|
|
13184
|
+
const workbook = xlsx.utils.book_new();
|
|
13185
|
+
xlsx.utils.book_append_sheet( workbook, worksheet, "Euro" );
|
|
13105
13186
|
|
|
13106
|
-
|
|
13107
|
-
|
|
13187
|
+
const buffer = xlsx.write( workbook, { type: "buffer", bookType: "xlsx" } );
|
|
13188
|
+
fs.writeFileSync( "./data/Euro.xlsx", buffer );
|
|
13108
13189
|
|
|
13109
|
-
|
|
13110
|
-
|
|
13111
|
-
|
|
13190
|
+
console.log( `Excel file written with ${exportData.length} rows.` );
|
|
13191
|
+
} else {
|
|
13192
|
+
console.log( "No trending fixtures found." );
|
|
13193
|
+
}
|
|
13112
13194
|
}
|
|
13113
13195
|
}
|
|
13114
13196
|
|
|
13115
13197
|
// updateBlitzCollection();
|
|
13116
13198
|
|
|
13117
13199
|
|
|
13200
|
+
export async function getmisMatchedGroup( req, res ) {
|
|
13201
|
+
try {
|
|
13202
|
+
if ( !req?.files?.file ) {
|
|
13203
|
+
return res.sendError( 'No data found', 204 );
|
|
13204
|
+
}
|
|
13205
|
+
|
|
13206
|
+
let workbook = xlsx.read( req?.files?.file.data, { type: 'buffer' } );
|
|
13207
|
+
let sheetData = xlsx.utils.sheet_to_json( workbook.Sheets['Fixture details'] );
|
|
13208
|
+
sheetData = sheetData.filter( ( ele ) => Number.isInteger( ele['Fixture Count'] ) );
|
|
13209
|
+
let mappedData = sheetData.reduce( ( acc, ele ) => {
|
|
13210
|
+
if ( [ 'Hooper Sun', 'Hooper Eye', 'Hooper Eye / Hooper Sun' ].includes( ele['Brand-Category'] ) ) {
|
|
13211
|
+
ele['Brand-Category'] = 'Hooper';
|
|
13212
|
+
}
|
|
13213
|
+
if ( [ 'JJ Eye', 'OD Eye' ].includes( ele['Brand-Category'] ) ) {
|
|
13214
|
+
ele['Brand-Category'] = 'JJ Eye + OD';
|
|
13215
|
+
}
|
|
13216
|
+
if ( ele['Brand-Category'] == 'Hustlr Eye' ) {
|
|
13217
|
+
ele['Brand-Category'] = 'Hustlr';
|
|
13218
|
+
}
|
|
13219
|
+
let brand = ele['Brand-Category'];
|
|
13220
|
+
let name = `${ele['Store Code']} - ${brand} - ${ele['Fixture Type']} - ${ele['Fixture Size (feet)']}`;
|
|
13221
|
+
if ( acc[name] ) {
|
|
13222
|
+
acc[name]['Fixture Count'] += ele['Fixture Count'];
|
|
13223
|
+
} else {
|
|
13224
|
+
acc[name] = ele;
|
|
13225
|
+
}
|
|
13226
|
+
return acc;
|
|
13227
|
+
}, {} );
|
|
13228
|
+
let groupStore = Object.values( mappedData );
|
|
13229
|
+
groupStore = groupStore.reduce( ( acc, ele ) => {
|
|
13230
|
+
const storeCode = ele['Store Code'];
|
|
13231
|
+
|
|
13232
|
+
if ( acc[storeCode] ) {
|
|
13233
|
+
acc[storeCode].push( ele );
|
|
13234
|
+
} else {
|
|
13235
|
+
acc[storeCode] = [ ele ];
|
|
13236
|
+
}
|
|
13237
|
+
|
|
13238
|
+
return acc;
|
|
13239
|
+
}, {} );
|
|
13240
|
+
console.log( groupStore, 'groupStore' );
|
|
13241
|
+
// groupStore = { "LKST01": groupStore['LKST01'] };
|
|
13242
|
+
// console.log( mappedData, 'mappedData' );
|
|
13243
|
+
let resultData = [];
|
|
13244
|
+
for ( let [ key, value ] of Object.entries( groupStore ) ) {
|
|
13245
|
+
// console.log( key );
|
|
13246
|
+
let misMatchedData = await Promise.all( value.map( async ( ele ) => {
|
|
13247
|
+
let brandCondition = [ { "templateGroupName": ele['Brand-Category'] } ];
|
|
13248
|
+
// if ( [ 'Hooper Sun', 'Hooper Eye', 'Hooper Eye / Hooper Sun' ].includes( ele['Brand-Category'] ) ) {
|
|
13249
|
+
// brandCondition.push( { "templateGroupName": 'Hooper' } );
|
|
13250
|
+
// }
|
|
13251
|
+
// if ( [ 'JJ Eye', 'OD Eye' ].includes( ele['Brand-Category'] ) ) {
|
|
13252
|
+
// brandCondition.push( { "templateGroupName": 'JJ Eye + OD' } );
|
|
13253
|
+
// }
|
|
13254
|
+
// if ( ele['Brand-Category'] == 'Hustlr Eye' ) {
|
|
13255
|
+
// brandCondition.push( { "templateGroupName": 'Hustlr' } );
|
|
13256
|
+
// }
|
|
13257
|
+
if ( ele['Brand-Category'] == 'VC Eye / LK Air' ) {
|
|
13258
|
+
brandCondition.push( { "templateGroupName": 'Tentpole' } );
|
|
13259
|
+
}
|
|
13260
|
+
|
|
13261
|
+
let query = [
|
|
13262
|
+
{
|
|
13263
|
+
$addFields: {
|
|
13264
|
+
store: { $toLower: '$storeName' },
|
|
13265
|
+
},
|
|
13266
|
+
},
|
|
13267
|
+
{
|
|
13268
|
+
$match: {
|
|
13269
|
+
"store": ele['Store Code'].toLowerCase(),
|
|
13270
|
+
"fixtureCategory": ele['Fixture Type'],
|
|
13271
|
+
'fixtureWidth.value': ele['Fixture Size (feet)'],
|
|
13272
|
+
"$or": brandCondition,
|
|
13273
|
+
},
|
|
13274
|
+
},
|
|
13275
|
+
|
|
13276
|
+
];
|
|
13277
|
+
let fixtureDetails = await storeFixtureService.aggregate( query );
|
|
13278
|
+
console.log( fixtureDetails.length );
|
|
13279
|
+
if ( !fixtureDetails.length || fixtureDetails.length != ele['Fixture Count'] ) {
|
|
13280
|
+
console.log( fixtureDetails );
|
|
13281
|
+
return ele;
|
|
13282
|
+
}
|
|
13283
|
+
return null;
|
|
13284
|
+
} ) );
|
|
13285
|
+
resultData.push( ...misMatchedData.filter( Boolean ) );
|
|
13286
|
+
}
|
|
13287
|
+
return res.sendSuccess( resultData );
|
|
13288
|
+
} catch ( e ) {
|
|
13289
|
+
logger.error( { functionName: 'getmisMatchedGroup', error: e } );
|
|
13290
|
+
return res.sendError( e, 500 );
|
|
13291
|
+
}
|
|
13292
|
+
}
|
|
13293
|
+
|
|
13118
13294
|
async function updateFixtureGroupNumber( ) {
|
|
13119
13295
|
const ivmLogicJson = fs.readFileSync( './data/ivmLogic.json', 'utf8' );
|
|
13120
13296
|
const ivmLogic = JSON.parse( ivmLogicJson );
|
|
13121
|
-
const strategyWorkbook = xlsx.readFile( './Updated IVM New Fixture Flow-
|
|
13297
|
+
const strategyWorkbook = xlsx.readFile( './Updated IVM New Fixture Flow-v8.xlsx' );
|
|
13122
13298
|
|
|
13123
13299
|
const combinationFixturesSheetName = 'Combined fixture logic';
|
|
13124
13300
|
const combinationFixtureSheet = strategyWorkbook.Sheets[combinationFixturesSheetName];
|
|
@@ -13571,9 +13747,10 @@ async function updateJJCollection() {
|
|
|
13571
13747
|
const fixturesWithShelvesAndVms = await Promise.all(
|
|
13572
13748
|
fixtures.map( async ( fixture ) => {
|
|
13573
13749
|
const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { }, { shelfNumber: 1 } );
|
|
13574
|
-
|
|
13750
|
+
let product = new Set();
|
|
13575
13751
|
const shelfDetails = await Promise.all(
|
|
13576
13752
|
shelves.map( async ( shelf ) => {
|
|
13753
|
+
shelf.productBrandName.forEach( ( brand ) => product.add( brand ) );
|
|
13577
13754
|
return shelf.toObject();
|
|
13578
13755
|
} ),
|
|
13579
13756
|
);
|
|
@@ -13589,6 +13766,7 @@ async function updateJJCollection() {
|
|
|
13589
13766
|
|
|
13590
13767
|
return {
|
|
13591
13768
|
...fixture,
|
|
13769
|
+
fixtureProduct: [ ...product ],
|
|
13592
13770
|
shelfConfig: shelfDetails,
|
|
13593
13771
|
vmConfig: vmDetails,
|
|
13594
13772
|
};
|
|
@@ -13727,6 +13905,43 @@ async function updateJJCollection() {
|
|
|
13727
13905
|
console.log( matchedFixture );
|
|
13728
13906
|
};
|
|
13729
13907
|
|
|
13908
|
+
const getJJProductFixtures = ( fixtures ) => {
|
|
13909
|
+
const matchedFixture = fixtures.filter( ( fxt ) => {
|
|
13910
|
+
if ( !fxt.fixtureProduct.some( ( el ) => /(fossil|lpl|od)/i.test( el ) ) ) {
|
|
13911
|
+
return fxt;
|
|
13912
|
+
}
|
|
13913
|
+
} );
|
|
13914
|
+
return matchedFixture;
|
|
13915
|
+
};
|
|
13916
|
+
|
|
13917
|
+
const getODProductFixtures = ( fixtures ) => {
|
|
13918
|
+
const matchedFixture = fixtures.filter( ( fxt ) => {
|
|
13919
|
+
if ( fxt.fixtureProduct.some( ( el ) => /(owndays|od)/i.test( el ) ) ) {
|
|
13920
|
+
return fxt;
|
|
13921
|
+
}
|
|
13922
|
+
} );
|
|
13923
|
+
return matchedFixture;
|
|
13924
|
+
};
|
|
13925
|
+
|
|
13926
|
+
const writeLog = ( logData ) => {
|
|
13927
|
+
const path = "./vmlogs.json";
|
|
13928
|
+
let logs = [];
|
|
13929
|
+
|
|
13930
|
+
try {
|
|
13931
|
+
const fileContent = fs.readFileSync( path, "utf8" );
|
|
13932
|
+
logs = JSON.parse( fileContent );
|
|
13933
|
+
|
|
13934
|
+
if ( !Array.isArray( logs ) ) {
|
|
13935
|
+
logs = [];
|
|
13936
|
+
}
|
|
13937
|
+
} catch ( err ) {
|
|
13938
|
+
logs = [];
|
|
13939
|
+
}
|
|
13940
|
+
|
|
13941
|
+
logs.push( logData );
|
|
13942
|
+
|
|
13943
|
+
fs.writeFileSync( path, JSON.stringify( logs, null, 2 ) );
|
|
13944
|
+
};
|
|
13730
13945
|
|
|
13731
13946
|
for ( let i = 0; i < zodiacData.length; i++ ) {
|
|
13732
13947
|
const store = zodiacData[i];
|
|
@@ -13741,19 +13956,574 @@ async function updateJJCollection() {
|
|
|
13741
13956
|
const floorFixtures = storeFixtures.filter(
|
|
13742
13957
|
( f ) => f.associatedElementType === undefined && f.associatedElementNumber === undefined,
|
|
13743
13958
|
);
|
|
13744
|
-
}
|
|
13745
|
-
}
|
|
13746
13959
|
|
|
13960
|
+
const wallFixtures = storeFixtures.filter(
|
|
13961
|
+
( f ) => f.associatedElementType !== undefined && f.associatedElementNumber !== undefined,
|
|
13962
|
+
);
|
|
13747
13963
|
|
|
13748
|
-
|
|
13964
|
+
if ( store?.['VM Type'] == 'Flattop' ) {
|
|
13965
|
+
let jjFixtures;
|
|
13966
|
+
// if ( store['Store Type'] != 'IVM' ) {
|
|
13967
|
+
jjFixtures = floorFixtures.find( ( ele ) => /(JJ Eye)/i.test( ele.header.label ) );
|
|
13968
|
+
if ( jjFixtures ) {
|
|
13969
|
+
let planovmDetails = await planoVmService.find( { vmName: { $regex: 'Zodiac ', $options: 'i' } } );
|
|
13970
|
+
let vmConfig = [];
|
|
13971
|
+
jjFixtures.shelfConfig.sort( ( a, b ) => a.shelfNumber - b.shelfNumber );
|
|
13972
|
+
console.log( jjFixtures.shelfConfig.length );
|
|
13973
|
+
planovmDetails.forEach( ( ele, index ) => {
|
|
13974
|
+
vmConfig.push( {
|
|
13975
|
+
vmId: ele._id,
|
|
13976
|
+
startYPosition: index == 0 ? 1 : jjFixtures.shelfConfig.length == 6 ? 5 : 4,
|
|
13977
|
+
endYPosition: index == 0 ? jjFixtures.shelfConfig.length == 6 ? 4 : 3 : jjFixtures.shelfConfig.length,
|
|
13978
|
+
xZone: index == 0 ? "left" : 'stretch',
|
|
13979
|
+
yZone: "stretch",
|
|
13980
|
+
} );
|
|
13981
|
+
} );
|
|
13982
|
+
let logData = {
|
|
13983
|
+
storeName: store?.['Store Code'],
|
|
13984
|
+
status: 'success',
|
|
13985
|
+
oldVmConfig: jjFixtures.vmConfig,
|
|
13986
|
+
newVmConfig: vmConfig,
|
|
13987
|
+
};
|
|
13988
|
+
writeLog( logData );
|
|
13989
|
+
// console.log( jjFixtures );
|
|
13990
|
+
await storeFixtureService.updateOne( { _id: jjFixtures._id }, { vmConfig: vmConfig } );
|
|
13991
|
+
await fixtureShelfService.updateMany( { fixtureId: jjFixtures._id }, { productBrandName: [ `JJ Eye - Zodiac` ] } );
|
|
13992
|
+
}
|
|
13993
|
+
// }
|
|
13994
|
+
} else {
|
|
13995
|
+
let jjFixtures;
|
|
13996
|
+
if ( store['Store Type'] != 'IVM' ) {
|
|
13997
|
+
let jjFixtureList = wallFixtures.filter( ( ele ) => /(JJ Eye)/i.test( ele.header.label ) );
|
|
13998
|
+
let fixtureNum = store['Fixture Remarks'][0];
|
|
13999
|
+
jjFixtures = jjFixtureList[parseInt( fixtureNum ) - 1];
|
|
14000
|
+
console.log( checkVmExistInFixtures( [ jjFixtures ], 'Retro Rhapsody' ) );
|
|
14001
|
+
if ( checkVmExistInFixtures( [ jjFixtures ], 'Retro Rhapsody' ) ) {
|
|
14002
|
+
jjFixtures = jjFixtureList.filter( ( ele ) => ele._id.toString() != jjFixtures._id.toString() );
|
|
14003
|
+
jjFixtures = jjFixtures[0];
|
|
14004
|
+
}
|
|
14005
|
+
} else {
|
|
14006
|
+
jjFixtures = wallFixtures.filter( ( ele ) => /(Premium Trending)/i.test( ele.header.label ) );
|
|
14007
|
+
if ( !jjFixtures.length ) {
|
|
14008
|
+
jjFixtures = wallFixtures.filter( ( ele ) => /(JJ Eye)/i.test( ele.header.label ) );
|
|
14009
|
+
}
|
|
14010
|
+
let getJJFixtures = getJJProductFixtures( jjFixtures );
|
|
14011
|
+
let fixtureNum = store['Fixture Remarks'][0];
|
|
14012
|
+
jjFixtures = getJJFixtures[parseInt( fixtureNum ) - 1];
|
|
14013
|
+
if ( checkVmExistInFixtures( [ jjFixtures ], 'Retro Rhapsody' ) ) {
|
|
14014
|
+
jjFixtures = getJJFixtures.filter( ( ele ) => ele._id.toString() != jjFixtures._id.toString() );
|
|
14015
|
+
jjFixtures = jjFixtures[0];
|
|
14016
|
+
}
|
|
14017
|
+
}
|
|
14018
|
+
// if ( store['VM Type'] != 'NO VM' ) {
|
|
14019
|
+
if ( !jjFixtures ) {
|
|
14020
|
+
let logData = {
|
|
14021
|
+
storeName: store?.['Store Code'],
|
|
14022
|
+
status: 'Permium trending is missing',
|
|
14023
|
+
};
|
|
14024
|
+
writeLog( logData );
|
|
14025
|
+
continue;
|
|
14026
|
+
}
|
|
14027
|
+
let planovmDetails = await planoVmService.findOne( { vmName: 'Zodiac' } );
|
|
14028
|
+
let position = store['VM Type'] == 'Bottom Slanter' ? 'Bottom' : 'Mid';
|
|
14029
|
+
let shelves = jjFixtures.shelfConfig.filter( ( ele ) => ele.zone == position );
|
|
14030
|
+
shelves.sort( ( a, b ) => a.shelfNumber - b.shelfNumber );
|
|
14031
|
+
let mid1;
|
|
14032
|
+
let mid2;
|
|
14033
|
+
if ( position == 'Mid' ) {
|
|
14034
|
+
if ( shelves.length % 2 !== 0 ) {
|
|
14035
|
+
mid1 = shelves[Math.floor( shelves.length / 2 )].shelfNumber;
|
|
14036
|
+
mid2 = mid1;
|
|
14037
|
+
} else {
|
|
14038
|
+
mid1 = shelves[shelves.length / 2 - 1].shelfNumber;
|
|
14039
|
+
mid2 = shelves[shelves.length / 2].shelfNumber;
|
|
14040
|
+
}
|
|
14041
|
+
} else {
|
|
14042
|
+
mid1 = shelves[shelves.length-1].shelfNumber;
|
|
14043
|
+
mid2 = mid1;
|
|
14044
|
+
let trayShelf = shelves.filter( ( ele ) => ele.shelfType == 'tray' );
|
|
14045
|
+
if ( trayShelf.length ) {
|
|
14046
|
+
mid1 = shelves[shelves.length-1].shelfNumber;
|
|
14047
|
+
mid2 = mid1;
|
|
14048
|
+
}
|
|
14049
|
+
}
|
|
14050
|
+
let vmConfig = {
|
|
14051
|
+
vmId: planovmDetails._id,
|
|
14052
|
+
startYPosition: mid1,
|
|
14053
|
+
endYPosition: mid2,
|
|
14054
|
+
xZone: position == 'Bottom' ? 'stretch' :'left',
|
|
14055
|
+
yZone: "stretch",
|
|
14056
|
+
};
|
|
14057
|
+
let logData = {
|
|
14058
|
+
storeName: store?.['Store Code'],
|
|
14059
|
+
status: 'success',
|
|
14060
|
+
oldVmConfig: jjFixtures.vmConfig,
|
|
14061
|
+
newvmConfig: "",
|
|
14062
|
+
storeName: store?.['Store Code'],
|
|
14063
|
+
fixtureId: jjFixtures._id,
|
|
14064
|
+
};
|
|
14065
|
+
let findVm = jjFixtures.vmConfig.findIndex( ( ele ) => ele.startYPosition == vmConfig.startYPosition && ele.endYPosition == vmConfig.endYPosition );
|
|
14066
|
+
if ( findVm != -1 ) {
|
|
14067
|
+
jjFixtures.vmConfig[findVm] = vmConfig;
|
|
14068
|
+
} else {
|
|
14069
|
+
jjFixtures.vmConfig.push( vmConfig );
|
|
14070
|
+
}
|
|
14071
|
+
logData.newvmConfig = jjFixtures.vmConfig;
|
|
14072
|
+
writeLog( logData );
|
|
14073
|
+
if ( store['VM Type'] != 'NO VM' ) {
|
|
14074
|
+
await storeFixtureService.updateOne( { _id: jjFixtures._id }, { vmConfig: jjFixtures.vmConfig } );
|
|
14075
|
+
}
|
|
14076
|
+
await fixtureShelfService.updateMany( { fixtureId: jjFixtures._id, zone: position }, { productBrandName: [ `JJ Eye - Zodiac` ] } );
|
|
14077
|
+
// }
|
|
14078
|
+
}
|
|
14079
|
+
}
|
|
13749
14080
|
|
|
13750
|
-
|
|
13751
|
-
|
|
14081
|
+
for ( let i = 0; i < postcardData.length; i++ ) {
|
|
14082
|
+
const store = postcardData[i];
|
|
14083
|
+
const planogram = await planoService.findOne( { storeName: store?.['Store Code'] } );
|
|
13752
14084
|
|
|
13753
|
-
|
|
13754
|
-
const sheet = workbook.Sheets[sheetName];
|
|
14085
|
+
if ( !planogram ) continue;
|
|
13755
14086
|
|
|
13756
|
-
|
|
14087
|
+
let storeFixtures = await getFixtures( { planoId: planogram._id } );
|
|
14088
|
+
|
|
14089
|
+
storeFixtures = sortFunc( storeFixtures );
|
|
14090
|
+
|
|
14091
|
+
// const floorFixtures = storeFixtures.filter(
|
|
14092
|
+
// ( f ) => f.associatedElementType === undefined && f.associatedElementNumber === undefined,
|
|
14093
|
+
// );
|
|
14094
|
+
|
|
14095
|
+
const wallFixtures = storeFixtures.filter(
|
|
14096
|
+
( f ) => f.associatedElementType !== undefined && f.associatedElementNumber !== undefined,
|
|
14097
|
+
);
|
|
14098
|
+
|
|
14099
|
+
let jjFixtures;
|
|
14100
|
+
let type = store['Fixture Remarks'].split( " of " );
|
|
14101
|
+
let data = type[1];
|
|
14102
|
+
if ( store['Store Type'] != 'IVM' ) {
|
|
14103
|
+
let regex = new RegExp( type[1], 'i' );
|
|
14104
|
+
jjFixtures = wallFixtures.filter( ( ele ) => regex.test( ele.header.label ) );
|
|
14105
|
+
if ( !jjFixtures.length && data == 'OD Eye' ) {
|
|
14106
|
+
data = 'JJ Eye';
|
|
14107
|
+
jjFixtures = wallFixtures.filter( ( ele ) => /(JJ Eye)/i.test( ele.header.label ) );
|
|
14108
|
+
}
|
|
14109
|
+
let fixtureNum = store['Fixture Remarks'][0];
|
|
14110
|
+
jjFixtures = jjFixtures[parseInt( fixtureNum ) - 1];
|
|
14111
|
+
} else {
|
|
14112
|
+
data = 'OD Eye';
|
|
14113
|
+
jjFixtures = wallFixtures.filter( ( ele ) => /(Premium Work)/i.test( ele.header.label ) );
|
|
14114
|
+
let getJJFixtures;
|
|
14115
|
+
|
|
14116
|
+
if ( !jjFixtures.length ) {
|
|
14117
|
+
getJJFixtures = wallFixtures.filter( ( ele ) => /(OD Eye|JJ Eye)/i.test( ele.header.label ) );
|
|
14118
|
+
let getodFixture = getODProductFixtures( getJJFixtures );
|
|
14119
|
+
if ( !getodFixture.length ) {
|
|
14120
|
+
data = 'JJ Eye';
|
|
14121
|
+
getJJFixtures = getJJProductFixtures( getJJFixtures );
|
|
14122
|
+
}
|
|
14123
|
+
} else {
|
|
14124
|
+
getJJFixtures = getODProductFixtures( jjFixtures );
|
|
14125
|
+
if ( !getJJFixtures.length ) {
|
|
14126
|
+
data = 'JJ Eye';
|
|
14127
|
+
getJJFixtures = getJJProductFixtures( jjFixtures );
|
|
14128
|
+
}
|
|
14129
|
+
}
|
|
14130
|
+
let fixtureNum = store['Fixture Remarks'][0];
|
|
14131
|
+
jjFixtures = getJJFixtures[parseInt( fixtureNum ) - 1];
|
|
14132
|
+
}
|
|
14133
|
+
// if ( store['VM Type'] != 'No VM' ) {
|
|
14134
|
+
if ( !jjFixtures ) {
|
|
14135
|
+
let logData = {
|
|
14136
|
+
storeName: store?.['Store Code'],
|
|
14137
|
+
status: 'Permium trending is missing',
|
|
14138
|
+
};
|
|
14139
|
+
writeLog( logData );
|
|
14140
|
+
continue;
|
|
14141
|
+
}
|
|
14142
|
+
let planovmDetails = await planoVmService.findOne( { vmName: 'Postcard' } );
|
|
14143
|
+
let position = store['VM Type'] == 'Bottom Slanter' ? 'Bottom' : store['Placement'].split( ' ' )[0];
|
|
14144
|
+
if ( checkVmExistInFixtures( jjFixtures, 'Retro Rhapsody' ) ) {
|
|
14145
|
+
position = 'Top';
|
|
14146
|
+
}
|
|
14147
|
+
let getZone = [ 'Top', 'Mid', 'Bottom' ];
|
|
14148
|
+
let shelves = jjFixtures.shelfConfig.filter( ( ele ) => ele.zone == position );
|
|
14149
|
+
shelves.sort( ( a, b ) => a.shelfNumber - b.shelfNumber );
|
|
14150
|
+
let shlefList = shelves.map( ( el ) => el.shelfNumber );
|
|
14151
|
+
let mid1;
|
|
14152
|
+
let mid2;
|
|
14153
|
+
if ( position == 'Mid' ) {
|
|
14154
|
+
if ( shelves.length % 2 !== 0 ) {
|
|
14155
|
+
mid1 = shelves[Math.floor( shelves.length / 2 )].shelfNumber;
|
|
14156
|
+
mid2 = mid1;
|
|
14157
|
+
} else {
|
|
14158
|
+
mid1 = shelves[shelves.length / 2 - 1].shelfNumber;
|
|
14159
|
+
mid2 = shelves[shelves.length / 2].shelfNumber;
|
|
14160
|
+
let trayShelf = shelves.filter( ( ele ) => ele.shelfType == 'tray' );
|
|
14161
|
+
if ( trayShelf.length ) {
|
|
14162
|
+
mid1 = shelves[shelves.length-1].shelfNumber;
|
|
14163
|
+
mid2 = mid1;
|
|
14164
|
+
}
|
|
14165
|
+
}
|
|
14166
|
+
} else {
|
|
14167
|
+
mid1 = shelves[shelves.length-1].shelfNumber;
|
|
14168
|
+
mid2 = mid1;
|
|
14169
|
+
}
|
|
14170
|
+
let vmConfig = {
|
|
14171
|
+
vmId: planovmDetails._id,
|
|
14172
|
+
startYPosition: mid1,
|
|
14173
|
+
endYPosition: mid2,
|
|
14174
|
+
xZone: store['VM Type'] == 'Bottom Slanter' ? 'stretch' :'left',
|
|
14175
|
+
yZone: "stretch",
|
|
14176
|
+
};
|
|
14177
|
+
let nextZone = getZone.findIndex( ( prod ) => prod == position );
|
|
14178
|
+
if ( nextZone != -1 ) {
|
|
14179
|
+
nextZone = getZone[nextZone + 1];
|
|
14180
|
+
let getnextZoneProduct = jjFixtures.shelfConfig.filter( ( shel ) => shel.zone == nextZone );
|
|
14181
|
+
let checkzoneProduct = jjFixtures.vmConfig.find( ( vm ) => getnextZoneProduct.map( ( shelf ) => shelf.shelfNumber ).includes( vm.startYPosition ) );
|
|
14182
|
+
if ( checkzoneProduct && vmConfig.xZone != 'stretch' ) {
|
|
14183
|
+
vmConfig.xZone = 'right';
|
|
14184
|
+
}
|
|
14185
|
+
}
|
|
14186
|
+
let logData = {
|
|
14187
|
+
storeName: store?.['Store Code'],
|
|
14188
|
+
status: 'success',
|
|
14189
|
+
oldVmConfig: jjFixtures.vmConfig,
|
|
14190
|
+
newvmConfig: "",
|
|
14191
|
+
storeName: store?.['Store Code'],
|
|
14192
|
+
fixtureId: jjFixtures._id,
|
|
14193
|
+
};
|
|
14194
|
+
let findVm = jjFixtures.vmConfig.findIndex( ( ele ) => shlefList.includes( ele.startYPosition ) );
|
|
14195
|
+
if ( findVm != -1 ) {
|
|
14196
|
+
jjFixtures.vmConfig[findVm] = vmConfig;
|
|
14197
|
+
} else {
|
|
14198
|
+
jjFixtures.vmConfig.push( vmConfig );
|
|
14199
|
+
}
|
|
14200
|
+
logData.newvmConfig = jjFixtures.vmConfig;
|
|
14201
|
+
writeLog( logData );
|
|
14202
|
+
if ( store['VM Type'] != 'No VM' ) {
|
|
14203
|
+
await storeFixtureService.updateOne( { _id: jjFixtures._id }, { vmConfig: jjFixtures.vmConfig } );
|
|
14204
|
+
}
|
|
14205
|
+
await fixtureShelfService.updateMany( { fixtureId: jjFixtures._id, zone: position }, { productBrandName: [ `${data} - Postcard` ] } );
|
|
14206
|
+
// }
|
|
14207
|
+
}
|
|
14208
|
+
|
|
14209
|
+
// for ( let i = 0; i < hiphopData.length; i++ ) {
|
|
14210
|
+
// const store = hiphopData[i];
|
|
14211
|
+
// const planogram = await planoService.findOne( { storeName: store?.['Store Code'] } );
|
|
14212
|
+
|
|
14213
|
+
// if ( !planogram ) continue;
|
|
14214
|
+
|
|
14215
|
+
// let storeFixtures = await getFixtures( { planoId: planogram._id } );
|
|
14216
|
+
|
|
14217
|
+
// storeFixtures = sortFunc( storeFixtures );
|
|
14218
|
+
|
|
14219
|
+
// const floorFixtures = storeFixtures.filter(
|
|
14220
|
+
// ( f ) => f.associatedElementType === undefined && f.associatedElementNumber === undefined && f.header?.label !== undefined && f.header?.label != null,
|
|
14221
|
+
// );
|
|
14222
|
+
|
|
14223
|
+
// const wallFixtures = storeFixtures.filter(
|
|
14224
|
+
// ( f ) => f.associatedElementType !== undefined && f.associatedElementNumber !== undefined && f.header?.label !== undefined && f.header?.label != null,
|
|
14225
|
+
// );
|
|
14226
|
+
|
|
14227
|
+
// let jjFixtures;
|
|
14228
|
+
// let jjFixturesList;
|
|
14229
|
+
// let type = store['hiphop_Placement'].split( " " );
|
|
14230
|
+
// let data = store['hiphop_Placement'].includes( "-" ) ? 'VC Eye / LK Air' : type[1];
|
|
14231
|
+
// let regex = new RegExp( data, 'i' );
|
|
14232
|
+
// if ( store['hiphop_Placement'].includes( 'Euro Center' ) ) {
|
|
14233
|
+
// jjFixturesList = floorFixtures.filter( ( ele ) => regex.test( ele.header.label ) );
|
|
14234
|
+
// // console.log( store?.['Store Code'] );
|
|
14235
|
+
// if ( !jjFixturesList.length ) {
|
|
14236
|
+
// type[0] = 'First';
|
|
14237
|
+
// jjFixturesList = floorFixtures.filter( ( ele ) => ele?.header?.label?.startsWith( 'Trending' ) || /\(VC Eye \/ LK Air\)/i.test( ele?.header?.label ) );
|
|
14238
|
+
// // if ( store?.['Store Code'] == 'LKST2610' ) {
|
|
14239
|
+
// // console.log( jjFixturesList, 'jjFixturesList', store?.['Store Code'] );
|
|
14240
|
+
// // }
|
|
14241
|
+
// if ( !jjFixturesList.length ) {
|
|
14242
|
+
// type[0] = 'First';
|
|
14243
|
+
// jjFixturesList = floorFixtures.filter( ( ele ) => ele?.header?.label?.startsWith( 'VC Eye' ) );
|
|
14244
|
+
// console.log( jjFixturesList?.[0]?.header?.label, 'jjFixturesList', store?.['Store Code'] );
|
|
14245
|
+
// }
|
|
14246
|
+
// }
|
|
14247
|
+
// } else {
|
|
14248
|
+
// if ( store['hiphop_Placement'].includes( "Trending" ) ) {
|
|
14249
|
+
// jjFixturesList = wallFixtures.filter( ( ele ) => ele?.header?.label?.startsWith( 'Trending' ) );
|
|
14250
|
+
// if ( !jjFixturesList.length ) {
|
|
14251
|
+
// jjFixturesList = wallFixtures.filter( ( ele ) => /\(VC Eye \/ LK Air\)/i.test( ele?.header?.label ) );
|
|
14252
|
+
// }
|
|
14253
|
+
// } else {
|
|
14254
|
+
// jjFixturesList = wallFixtures.filter( ( ele ) => regex.test( ele?.header?.label ) );
|
|
14255
|
+
// }
|
|
14256
|
+
// }
|
|
14257
|
+
// let fixtureNum = type[0] == 'First' ? 0 : 1;
|
|
14258
|
+
// jjFixtures = jjFixturesList[fixtureNum];
|
|
14259
|
+
// // if ( store['VM Type'] != 'No VM' ) {
|
|
14260
|
+
// if ( !jjFixtures ) {
|
|
14261
|
+
// if ( store['hiphop_Placement'].includes( 'Euro Center' ) ) {
|
|
14262
|
+
// type[0] = 'First';
|
|
14263
|
+
// jjFixturesList = floorFixtures.filter( ( ele ) => ele?.header?.label.startsWith( 'Trending' ) || /\(VC Eye \/ LK Air\)/i.test( ele.header.label ) );
|
|
14264
|
+
// if ( !jjFixturesList.length ) {
|
|
14265
|
+
// type[0] = 'First';
|
|
14266
|
+
// jjFixturesList = floorFixtures.filter( ( ele ) => ele?.header?.label.startsWith( 'VC Eye' ) );
|
|
14267
|
+
// }
|
|
14268
|
+
// if ( jjFixturesList.length ) {
|
|
14269
|
+
// fixtureNum = 0;
|
|
14270
|
+
// jjFixtures = jjFixturesList[fixtureNum];
|
|
14271
|
+
// }
|
|
14272
|
+
// } if ( !jjFixtures ) {
|
|
14273
|
+
// let logData = {
|
|
14274
|
+
// storeName: store?.['Store Code'],
|
|
14275
|
+
// status: 'Permium trending is missing',
|
|
14276
|
+
// };
|
|
14277
|
+
// writeLog( logData );
|
|
14278
|
+
// continue;
|
|
14279
|
+
// }
|
|
14280
|
+
// }
|
|
14281
|
+
// if ( store['hiphop_Placement'].includes( 'Euro Center' ) ) {
|
|
14282
|
+
// let planovmDetails = await planoVmService.find( { vmName: { $regex: 'hiphop ', $options: 'i' } } );
|
|
14283
|
+
// let vmConfig = [];
|
|
14284
|
+
// planovmDetails.forEach( ( ele, index ) => {
|
|
14285
|
+
// vmConfig.push( {
|
|
14286
|
+
// vmId: ele._id,
|
|
14287
|
+
// startYPosition: index == 0 ? 1 : 4,
|
|
14288
|
+
// endYPosition: index == 0 ? 3 : 4,
|
|
14289
|
+
// xZone: index == 0 ? "left" : 'stretch',
|
|
14290
|
+
// yZone: "stretch",
|
|
14291
|
+
// } );
|
|
14292
|
+
// } );
|
|
14293
|
+
// let logData = {
|
|
14294
|
+
// storeName: store?.['Store Code'],
|
|
14295
|
+
// status: 'success',
|
|
14296
|
+
// oldVmConfig: jjFixtures.vmConfig,
|
|
14297
|
+
// newVmConfig: vmConfig,
|
|
14298
|
+
// storeName: store?.['Store Code'],
|
|
14299
|
+
// fixtureId: jjFixtures._id,
|
|
14300
|
+
// };
|
|
14301
|
+
// writeLog( logData );
|
|
14302
|
+
// if ( store['Exceptions'].includes( 'Bitz' ) && checkVmExistInFixtures( [ jjFixtures ], 'Bitz' ) ) {
|
|
14303
|
+
// if ( jjFixturesList.length > 1 ) {
|
|
14304
|
+
// jjFixtures = jjFixturesList[fixtureNum + 1];
|
|
14305
|
+
// }
|
|
14306
|
+
// }
|
|
14307
|
+
// // console.log( jjFixtures );
|
|
14308
|
+
// if ( jjFixtures ) {
|
|
14309
|
+
// await storeFixtureService.updateOne( { _id: jjFixtures._id }, { vmConfig: vmConfig } );
|
|
14310
|
+
// }
|
|
14311
|
+
// } else {
|
|
14312
|
+
// let position = 'Top';
|
|
14313
|
+
// if ( store['hiphop_Placement'].includes( '-' ) ) {
|
|
14314
|
+
// position = 'Mid';
|
|
14315
|
+
// }
|
|
14316
|
+
// let planovmDetails = await planoVmService.findOne( { vmName: 'Hiphop' } );
|
|
14317
|
+
// let shelves = jjFixtures.shelfConfig.filter( ( ele ) => ele.zone == position );
|
|
14318
|
+
// shelves.sort( ( a, b ) => a.shelfNumber - b.shelfNumber );
|
|
14319
|
+
// let shlefList = shelves.map( ( el ) => el.shelfNumber );
|
|
14320
|
+
// let mid1 = 1;
|
|
14321
|
+
// let mid2 = 1;
|
|
14322
|
+
// if ( position == 'Mid' ) {
|
|
14323
|
+
// if ( shelves.length % 2 !== 0 ) {
|
|
14324
|
+
// mid1 = shelves[Math.floor( shelves.length / 2 )].shelfNumber;
|
|
14325
|
+
// mid2 = mid1;
|
|
14326
|
+
// } else {
|
|
14327
|
+
// mid1 = shelves[shelves.length / 2 - 1].shelfNumber;
|
|
14328
|
+
// mid2 = shelves[shelves.length / 2].shelfNumber;
|
|
14329
|
+
// let trayShelf = shelves.filter( ( ele ) => ele.shelfType == 'tray' );
|
|
14330
|
+
// if ( trayShelf.length ) {
|
|
14331
|
+
// mid1 = shelves[shelves.length-1].shelfNumber;
|
|
14332
|
+
// mid2 = mid1;
|
|
14333
|
+
// }
|
|
14334
|
+
// }
|
|
14335
|
+
// }
|
|
14336
|
+
// let vmConfig = {
|
|
14337
|
+
// vmId: planovmDetails._id,
|
|
14338
|
+
// startYPosition: mid1,
|
|
14339
|
+
// endYPosition: mid2,
|
|
14340
|
+
// xZone: position == 'Top' ? 'stretch' : 'left',
|
|
14341
|
+
// yZone: "stretch",
|
|
14342
|
+
// };
|
|
14343
|
+
// let logData = {
|
|
14344
|
+
// storeName: store?.['Store Code'],
|
|
14345
|
+
// status: 'success',
|
|
14346
|
+
// oldVmConfig: JSON.parse( JSON.stringify( jjFixtures.vmConfig ) ),
|
|
14347
|
+
// newvmConfig: "",
|
|
14348
|
+
// };
|
|
14349
|
+
// let findVm = jjFixtures.vmConfig.findIndex( ( ele ) => shlefList.includes( ele.startYPosition ) );
|
|
14350
|
+
// if ( findVm != -1 ) {
|
|
14351
|
+
// jjFixtures.vmConfig[findVm] = vmConfig;
|
|
14352
|
+
// } else {
|
|
14353
|
+
// jjFixtures.vmConfig.push( vmConfig );
|
|
14354
|
+
// }
|
|
14355
|
+
// logData.newvmConfig = jjFixtures.vmConfig;
|
|
14356
|
+
// // if ( store?.['Store Code'] == 'LKST599' ) {
|
|
14357
|
+
// // console.log( jjFixtures.fixtureProduct );
|
|
14358
|
+
// // console.log( jjFixtures.fixtureProduct.some( ( str ) => str.toLowerCase().includes( 'discounted' ) ) );
|
|
14359
|
+
// // console.log( jjFixturesList );
|
|
14360
|
+
// // }
|
|
14361
|
+
// if ( /(almost gone)/i.test( jjFixtures.header.label ) || checkVmExistInFixtures( [ jjFixtures ], 'All Styles at Rs 800' ) || jjFixtures.fixtureProduct.some( ( str ) => str.toLowerCase().includes( 'discounted' ) ) ) {
|
|
14362
|
+
// if ( jjFixturesList.length > 1 ) {
|
|
14363
|
+
// // console.log( 'planioio' );
|
|
14364
|
+
// jjFixturesList = jjFixturesList.filter( ( ele ) => !ele.fixtureProduct.some( ( str ) => str.toLowerCase().includes( 'discounted' ) ) && !/(almost gone)/i.test( ele.header.label ) && !checkVmExistInFixtures( [ ele ], 'All Styles at Rs 800' ) && !checkVmExistInFixtures( [ ele ], 'Bitz' ) );
|
|
14365
|
+
// if ( store['hiphop_Placement'].includes( '-' ) ) {
|
|
14366
|
+
// jjFixturesList = jjFixturesList.filter( ( ele ) => {
|
|
14367
|
+
// if ( ele.vmConfig.some( ( vm ) => !/(Hustlr|Phonic|bitz)/i.test( vm.vmName ) ) ) {
|
|
14368
|
+
// return ele;
|
|
14369
|
+
// }
|
|
14370
|
+
// } );
|
|
14371
|
+
// }
|
|
14372
|
+
// // console.log( jjFixturesList );
|
|
14373
|
+
// if ( jjFixturesList.length ) {
|
|
14374
|
+
// // console.log( 'jjFixturesList.length', jjFixturesList.length, store?.['Store Code'] );
|
|
14375
|
+
// // if ( store?.['Store Code'] == 'LKST599' ) {
|
|
14376
|
+
// // console.log( jjFixturesList, 'jjFixturesList', 'LKST599' );
|
|
14377
|
+
// // }
|
|
14378
|
+
// jjFixtures = jjFixturesList[0];
|
|
14379
|
+
// let findVm = jjFixtures.vmConfig.findIndex( ( ele ) => shlefList.includes( ele.startYPosition ) );
|
|
14380
|
+
// if ( findVm != -1 ) {
|
|
14381
|
+
// logData.oldVmConfig= JSON.parse( JSON.stringify( jjFixtures.vmConfig ) );
|
|
14382
|
+
// jjFixtures.vmConfig.endYPosition = jjFixtures.vmConfig[findVm].endYPosition;
|
|
14383
|
+
// jjFixtures.vmConfig[findVm] = vmConfig;
|
|
14384
|
+
// } else {
|
|
14385
|
+
// jjFixtures.vmConfig.push( vmConfig );
|
|
14386
|
+
// }
|
|
14387
|
+
// await storeFixtureService.updateOne( { _id: jjFixtures._id }, { vmConfig: jjFixtures.vmConfig } );
|
|
14388
|
+
// }
|
|
14389
|
+
// }
|
|
14390
|
+
// } else {
|
|
14391
|
+
// if ( store['hiphop_Placement'].includes( '-' ) ) {
|
|
14392
|
+
// jjFixturesList = jjFixturesList.filter( ( ele ) => {
|
|
14393
|
+
// if ( ele.vmConfig.some( ( vm ) => !/(Hustlr|Phonic|bitz)/i.test( vm.vmName ) ) ) {
|
|
14394
|
+
// return ele;
|
|
14395
|
+
// }
|
|
14396
|
+
// } );
|
|
14397
|
+
// // let findShelfVm = jjFixtures.vmConfig.find( ( ele ) => /(Hustlr|Phonic|bitz)/i.test( ele.vmName ) );
|
|
14398
|
+
// // if ( findShelfVm ) {
|
|
14399
|
+
// if ( jjFixturesList.length > 1 ) {
|
|
14400
|
+
// jjFixtures = jjFixturesList[0];
|
|
14401
|
+
|
|
14402
|
+
// // jjFixturesList = jjFixturesList.filter( ( ele ) => {
|
|
14403
|
+
// // if ( ele.vmConfig.some( ( vm ) => !/(Hustlr|Phonic|bitz)/i.test( vm.vmName ) ) ) {
|
|
14404
|
+
// // return ele;
|
|
14405
|
+
// // }
|
|
14406
|
+
// // } );
|
|
14407
|
+
// // jjFixtures = jjFixturesList[0];
|
|
14408
|
+
// jjFixtures = jjFixturesList[fixtureNum + 1];
|
|
14409
|
+
// let findVm = jjFixtures.vmConfig.findIndex( ( ele ) => shlefList.includes( ele.startYPosition ) );
|
|
14410
|
+
// if ( findVm != -1 ) {
|
|
14411
|
+
// logData.oldVmConfig= JSON.parse( JSON.stringify( jjFixtures.vmConfig ) );
|
|
14412
|
+
// jjFixtures.vmConfig.endYPosition = jjFixtures.vmConfig[findVm].endYPosition;
|
|
14413
|
+
// jjFixtures.vmConfig[findVm] = vmConfig;
|
|
14414
|
+
// } else {
|
|
14415
|
+
// jjFixtures.vmConfig.push( vmConfig );
|
|
14416
|
+
// }
|
|
14417
|
+
// await storeFixtureService.updateOne( { _id: jjFixtures._id }, { vmConfig: jjFixtures.vmConfig } );
|
|
14418
|
+
// }
|
|
14419
|
+
// // }
|
|
14420
|
+
// // else {
|
|
14421
|
+
// // await storeFixtureService.updateOne( { _id: jjFixtures._id }, { vmConfig: jjFixtures.vmConfig } );
|
|
14422
|
+
// // }
|
|
14423
|
+
// } else {
|
|
14424
|
+
// await storeFixtureService.updateOne( { _id: jjFixtures._id }, { vmConfig: jjFixtures.vmConfig } );
|
|
14425
|
+
// }
|
|
14426
|
+
// }
|
|
14427
|
+
// logData.storeName = store?.['Store Code'];
|
|
14428
|
+
// logData.fixtureId = jjFixtures._id;
|
|
14429
|
+
// writeLog( logData );
|
|
14430
|
+
// }
|
|
14431
|
+
// }
|
|
14432
|
+
|
|
14433
|
+
console.log( 'updated' );
|
|
14434
|
+
}
|
|
14435
|
+
|
|
14436
|
+
|
|
14437
|
+
// updateJJCollection();
|
|
14438
|
+
|
|
14439
|
+
|
|
14440
|
+
export async function getstoreFixtureExcel( req, res ) {
|
|
14441
|
+
try {
|
|
14442
|
+
if ( !req.body?.storeName ) {
|
|
14443
|
+
return res.sendError( 'storeName is required', 400 );
|
|
14444
|
+
}
|
|
14445
|
+
let getStoreDetails = await storeService.find( { storeName: { $in: req.body.storeName }, status: 'active', clientId: '11' }, { storeProfile: 1, storeName: 1 } );
|
|
14446
|
+
if ( !getStoreDetails.length ) {
|
|
14447
|
+
return res.sendError( 'No data found', 204 );
|
|
14448
|
+
}
|
|
14449
|
+
let data = [];
|
|
14450
|
+
let sortOrder = [ 5, 1, 2, 3, 4 ];
|
|
14451
|
+
for ( let store of getStoreDetails ) {
|
|
14452
|
+
let uniqueFixtureNumber = 1;
|
|
14453
|
+
let storeFixturesList = await storeFixtureService.findAndSort( { storeName: store.storeName }, {}, { fixtureNumber: 1, associatedElementNumber: 1, associatedElementFixtureNumber: 1 } );
|
|
14454
|
+
storeFixturesList.sort( ( a, b ) => {
|
|
14455
|
+
const floorDiff = b.floorId.toString().localeCompare( a.floorId.toString() );
|
|
14456
|
+
if ( floorDiff !== 0 ) return floorDiff;
|
|
14457
|
+
|
|
14458
|
+
if ( a.fixtureType !== b.fixtureType ) {
|
|
14459
|
+
return a.fixtureType === "wall" ? -1 : 1;
|
|
14460
|
+
}
|
|
14461
|
+
|
|
14462
|
+
if ( a.fixtureType === "wall" ) {
|
|
14463
|
+
const orderDiff =
|
|
14464
|
+
sortOrder.indexOf( a.associatedElementNumber ) -
|
|
14465
|
+
sortOrder.indexOf( b.associatedElementNumber );
|
|
14466
|
+
|
|
14467
|
+
if ( orderDiff !== 0 ) return orderDiff;
|
|
14468
|
+
|
|
14469
|
+
return (
|
|
14470
|
+
( a.associatedElementFixtureNumber || 0 ) -
|
|
14471
|
+
( b.associatedElementFixtureNumber || 0 )
|
|
14472
|
+
);
|
|
14473
|
+
}
|
|
14474
|
+
|
|
14475
|
+
return 0;
|
|
14476
|
+
} );
|
|
14477
|
+
|
|
14478
|
+
|
|
14479
|
+
let storeFixtureDetails = [];
|
|
14480
|
+
for ( let ele of storeFixturesList ) {
|
|
14481
|
+
let shelfDetails = await fixtureShelfService.findAndSort( { fixtureId: ele._id }, {}, { shelfNumber: 1 } );
|
|
14482
|
+
ele.shelfConfig = shelfDetails;
|
|
14483
|
+
let fixtureVm = await Promise.all( ele.vmConfig.map( async ( vmConfig ) => {
|
|
14484
|
+
let vmDetails = await planoVmService.findOne( { _id: vmConfig.vmId } );
|
|
14485
|
+
return { ...vmConfig.toObject(), ...vmDetails.toObject() };
|
|
14486
|
+
} ) );
|
|
14487
|
+
|
|
14488
|
+
let topShelfNumber = ele.shelfConfig.filter( ( ele ) => ele.zone == 'Top' ).map( ( ele ) => ele.shelfNumber );
|
|
14489
|
+
let midShelfNumber = ele.shelfConfig.filter( ( ele ) => ele.zone == 'Mid' ).map( ( ele ) => ele.shelfNumber );
|
|
14490
|
+
let bottomShelfNumber = ele.shelfConfig.filter( ( ele ) => ele.zone == 'Bottom' ).map( ( ele ) => ele.shelfNumber );
|
|
14491
|
+
|
|
14492
|
+
storeFixtureDetails.push( {
|
|
14493
|
+
"City": getStoreDetails.find( ( store ) => store.storeName == ele.storeName )?.storeProfile?.city,
|
|
14494
|
+
"Store Name": ele.storeName,
|
|
14495
|
+
"Wall Number": ele?.associatedElementNumber ?? 'floor',
|
|
14496
|
+
"Fixture Number": ele.associatedElementFixtureNumber,
|
|
14497
|
+
"Unique Fixture Number": 'FX - ' + ele.fixtureNumber,
|
|
14498
|
+
"Fixture Type": ele.fixtureType == 'wall' ? ele.fixtureCategory : '',
|
|
14499
|
+
"Fixture Width": ele.fixtureWidth.value +' '+ ele.fixtureWidth.unit,
|
|
14500
|
+
"Header": ele.header?.label,
|
|
14501
|
+
"Top Masking": ele.fixtureType != 'floor' ? fixtureVm.find( ( vm ) => vm.startYPosition == 1 && vm.yZone == 'stretch' && vm.xZone == 'stretch' )?.vmName : '',
|
|
14502
|
+
"Middle Masking": ele.fixtureType != 'floor' ? fixtureVm.find( ( vm ) => midShelfNumber.includes( vm.startYPosition ) && vm.startYPosition != midShelfNumber[midShelfNumber.length - 1] && !vm.vmName.includes( 'Leatherite' ) )?.vmName : '',
|
|
14503
|
+
"Leatherite": ele.fixtureType != 'floor' ? fixtureVm.find( ( vm ) => vm.vmName.includes( 'Leatherite' ) )?.vmName : '',
|
|
14504
|
+
"Lower Middle Masking": ele.fixtureType != 'floor' ? fixtureVm.find( ( vm ) => vm.startYPosition == midShelfNumber[midShelfNumber.length - 1] )?.vmName : '',
|
|
14505
|
+
"Bottom Slander": ele.fixtureType != 'floor' ? fixtureVm.find( ( vm ) => vm.startYPosition == ele.shelfConfig.length && vm.yZone == 'stretch' && vm.xZone == 'stretch' )?.vmName : '',
|
|
14506
|
+
"Bottom Mid": ele.fixtureType != 'floor' ? fixtureVm.find( ( vm ) => vm.startYPosition == ele.shelfConfig.length && vm.yZone == 'stretch' && vm.xZone != 'stretch' )?.vmName : '',
|
|
14507
|
+
"Euro Center Type": ele.fixtureType == 'floor' ? ele.fixtureCategory +'-'+ ele.fixtureWidth.value +' '+ ele.fixtureWidth.unit : '',
|
|
14508
|
+
"Euro Center VM": ele.fixtureType == 'floor' ? fixtureVm.map( ( ele ) => ele.vmName )?.toString() : '',
|
|
14509
|
+
},
|
|
14510
|
+
);
|
|
14511
|
+
}
|
|
14512
|
+
data.push( ...storeFixtureDetails );
|
|
14513
|
+
}
|
|
14514
|
+
await download( data, res );
|
|
14515
|
+
} catch ( e ) {
|
|
14516
|
+
console.log( e );
|
|
14517
|
+
return res.sendError( e, 500 );
|
|
14518
|
+
}
|
|
14519
|
+
}
|
|
14520
|
+
async function updateCoastlineCollection() {
|
|
14521
|
+
const workbook = xlsx.readFile( './data/Coastline 3.0 Tango.xlsx' );
|
|
14522
|
+
|
|
14523
|
+
const sheetName = 'Sheet1';
|
|
14524
|
+
const sheet = workbook.Sheets[sheetName];
|
|
14525
|
+
|
|
14526
|
+
const JsonData = xlsx.utils.sheet_to_json( sheet, { range: 6 } );
|
|
13757
14527
|
|
|
13758
14528
|
const data = JSON.parse( JSON.stringify( JsonData, null, 2 ) );
|
|
13759
14529
|
|
|
@@ -14060,12 +14830,13 @@ async function updateCoastlineCollection() {
|
|
|
14060
14830
|
async function updatePhonicCollection() {
|
|
14061
14831
|
const workbook = xlsx.readFile( './data/Coastline 3.0 Tango.xlsx' );
|
|
14062
14832
|
|
|
14063
|
-
const sheetName = '
|
|
14833
|
+
const sheetName = 'List';
|
|
14064
14834
|
const sheet = workbook.Sheets[sheetName];
|
|
14065
14835
|
|
|
14066
|
-
const JsonData = xlsx.utils.sheet_to_json( sheet, { range:
|
|
14836
|
+
const JsonData = xlsx.utils.sheet_to_json( sheet, { range: 5 } );
|
|
14067
14837
|
|
|
14068
14838
|
const data = JSON.parse( JSON.stringify( JsonData, null, 2 ) );
|
|
14839
|
+
console.log( data );
|
|
14069
14840
|
|
|
14070
14841
|
const sortFunc = ( groupFixtures ) => {
|
|
14071
14842
|
const sortRules = {
|
|
@@ -14224,56 +14995,57 @@ async function updatePhonicCollection() {
|
|
|
14224
14995
|
return;
|
|
14225
14996
|
}
|
|
14226
14997
|
|
|
14227
|
-
const
|
|
14998
|
+
const topShelves = fixture?.shelfConfig?.filter( ( shelf ) => shelf.zone === 'Top' ).sort( ( shelf ) => shelf.shelfNumber - shelf.shelfNumber );
|
|
14228
14999
|
|
|
14229
|
-
if (
|
|
15000
|
+
if ( topShelves.length === 0 ) {
|
|
14230
15001
|
return;
|
|
14231
15002
|
}
|
|
14232
15003
|
|
|
14233
|
-
const midShelfNumbers = new Set( midShelves.map( ( shelf ) => shelf.shelfNumber ) );
|
|
14234
|
-
|
|
14235
|
-
const existingVms = fixture?.vmConfig?.filter(
|
|
14236
|
-
( vm ) => !midShelfNumbers.has( vm.startYPosition ),
|
|
14237
|
-
);
|
|
14238
15004
|
|
|
14239
15005
|
const vmData = {
|
|
14240
|
-
vmName: '
|
|
14241
|
-
startYPosition:
|
|
14242
|
-
endYPosition:
|
|
14243
|
-
xZone: '
|
|
15006
|
+
vmName: 'Phonic',
|
|
15007
|
+
startYPosition: topShelves[topShelves.length - 1].shelfNumber,
|
|
15008
|
+
endYPosition: topShelves[topShelves.length - 1].shelfNumber,
|
|
15009
|
+
xZone: 'right',
|
|
14244
15010
|
yZone: 'stretch',
|
|
14245
15011
|
};
|
|
14246
15012
|
|
|
14247
|
-
existingVms.push( vmData );
|
|
14248
15013
|
|
|
14249
|
-
|
|
15014
|
+
const existingVms = fixture?.vmConfig?.findIndex(
|
|
15015
|
+
( vm ) => vm.startYPosition == vmData.startYPosition && vm.endYPosition == vmData.endYPosition && vm.xZone == vmData.xZone && vm.yZone == vmData.yZone,
|
|
15016
|
+
);
|
|
15017
|
+
|
|
15018
|
+
if ( existingVms != -1 ) {
|
|
15019
|
+
fixture.vmConfig[existingVms] = vmData;
|
|
15020
|
+
} else {
|
|
15021
|
+
fixture.vmConfig.push( vmData );
|
|
15022
|
+
}
|
|
15023
|
+
|
|
14250
15024
|
|
|
14251
15025
|
return fixture;
|
|
14252
15026
|
};
|
|
14253
15027
|
|
|
14254
|
-
async function handleCond1( fixtures ) {
|
|
14255
|
-
let
|
|
14256
|
-
if ( !
|
|
15028
|
+
async function handleCond1( fixtures, index ) {
|
|
15029
|
+
let fixtureList = fixtures.filter( ( fixture ) => ( fixture.header?.label === 'JJ Eye' || fixture.header?.label === 'John Jacobs' || fixture.header?.label?.toLowerCase().startsWith( 'premium trending' ) || fixture.header?.label?.toLowerCase().startsWith( 'premium work' ) ) );
|
|
15030
|
+
if ( !fixtureList.length ) {
|
|
14257
15031
|
return;
|
|
14258
15032
|
}
|
|
14259
|
-
|
|
15033
|
+
fixtureList = updateVm( fixtureList[index] );
|
|
14260
15034
|
|
|
14261
|
-
await updateFixtures( [
|
|
15035
|
+
await updateFixtures( [ fixtureList ] );
|
|
14262
15036
|
};
|
|
14263
15037
|
|
|
14264
|
-
async function handleCond2( fixtures ) {
|
|
14265
|
-
let
|
|
14266
|
-
fixture.header?.label
|
|
14267
|
-
fixture.header?.label === 'Premium trending' ||
|
|
14268
|
-
fixture.header?.label === 'Premium Trending 1' ||
|
|
14269
|
-
fixture.header?.label === 'Premium Trending 2'||
|
|
14270
|
-
fixture.header?.label ==='Premium Trending 3' ||
|
|
14271
|
-
fixture.header?.label === 'Premium Trending 4' );
|
|
15038
|
+
async function handleCond2( fixtures, index ) {
|
|
15039
|
+
let updateFixtureList = fixtures.filter( ( fixture ) =>
|
|
15040
|
+
fixture.header?.label?.toLowerCase().startsWith( 'trending' ) || fixture.header?.label?.toLowerCase().startsWith( 'work essentials' ) || fixture.header?.label?.toLowerCase().startsWith( 'innovation' ) || fixture.header?.label?.toLowerCase().startsWith( 'vc eye' ) );
|
|
14272
15041
|
|
|
14273
|
-
if ( !
|
|
15042
|
+
if ( !updateFixtureList.length ) {
|
|
14274
15043
|
return;
|
|
14275
15044
|
}
|
|
14276
|
-
|
|
15045
|
+
let updateFixture = updateFixtureList[index];
|
|
15046
|
+
if ( index == 2 && ( ( checkVmExistInFixtures( 'Bitz' ) && checkVmExistInFixtures( 'Hustlr' ) ) || ( !updateFixture.header?.label?.toLowerCase().startsWith( 'innovation' ) && !updateFixture.header?.label?.toLowerCase().startsWith( 'vc eye' ) ) ) ) {
|
|
15047
|
+
updateFixture = updateFixtureList[index + 1];
|
|
15048
|
+
}
|
|
14277
15049
|
updateFixture = updateVm( updateFixture );
|
|
14278
15050
|
|
|
14279
15051
|
await updateFixtures( [ updateFixture ] );
|
|
@@ -14334,7 +15106,6 @@ async function updatePhonicCollection() {
|
|
|
14334
15106
|
|
|
14335
15107
|
await updateFixtures( [ updateFixture ] );
|
|
14336
15108
|
};
|
|
14337
|
-
|
|
14338
15109
|
for ( let i = 0; i < data.length; i++ ) {
|
|
14339
15110
|
const store = data[i];
|
|
14340
15111
|
const storePlano = await planoService.findOne( { storeName: store?.['Store Code'] } );
|
|
@@ -14348,21 +15119,22 @@ async function updatePhonicCollection() {
|
|
|
14348
15119
|
);
|
|
14349
15120
|
|
|
14350
15121
|
|
|
14351
|
-
|
|
14352
|
-
|
|
14353
|
-
|
|
14354
|
-
|
|
14355
|
-
|
|
14356
|
-
|
|
14357
|
-
|
|
14358
|
-
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
|
|
14362
|
-
|
|
15122
|
+
if ( store?.['Store Code'] === 'LKST1228' ) {
|
|
15123
|
+
logger.error( { function: wallFixtures } );
|
|
15124
|
+
if ( store['Fixture Remarks'] === '1st Wall Fixture of JJ Eye' ) {
|
|
15125
|
+
await handleCond1( wallFixtures, 0 );
|
|
15126
|
+
} else if ( store['Fixture Remarks'] === '2nd Wall Fixture of JJ Eye' ) {
|
|
15127
|
+
await handleCond1( wallFixtures, 1 );
|
|
15128
|
+
} else if ( store['Fixture Remarks'] === '3rd Wall Fixture of VC Eye_LK Air' ) {
|
|
15129
|
+
console.log( store?.['Store Code'] );
|
|
15130
|
+
await handleCond2( wallFixtures, 2 );
|
|
15131
|
+
} else if ( store['Fixture Remarks'] === '4th Wall Fixture of VC Eye_LK Air' ) {
|
|
15132
|
+
await handleCond2( wallFixtures, 3 );
|
|
15133
|
+
}
|
|
14363
15134
|
}
|
|
14364
|
-
// }
|
|
14365
15135
|
}
|
|
15136
|
+
|
|
15137
|
+
console.log( 'updated' );
|
|
14366
15138
|
}
|
|
14367
15139
|
|
|
14368
15140
|
// updatePhonicCollection();
|
|
@@ -17077,3 +17849,691 @@ async function standardizeTemplateGroup() {
|
|
|
17077
17849
|
}
|
|
17078
17850
|
|
|
17079
17851
|
// standardizeTemplateGroup()
|
|
17852
|
+
|
|
17853
|
+
async function updateStrangerCollection() {
|
|
17854
|
+
const workbook = xlsx.readFile( './data/Stranger Things - Tango.xlsx' );
|
|
17855
|
+
|
|
17856
|
+
const sheetName = 'Sheet2';
|
|
17857
|
+
const sheet = workbook.Sheets[sheetName];
|
|
17858
|
+
|
|
17859
|
+
const JsonData = xlsx.utils.sheet_to_json( sheet, { range: 5 } );
|
|
17860
|
+
|
|
17861
|
+
console.log( JsonData, 'JsonData' );
|
|
17862
|
+
|
|
17863
|
+
const data = JSON.parse( JSON.stringify( JsonData, null, 2 ) );
|
|
17864
|
+
console.log( data );
|
|
17865
|
+
|
|
17866
|
+
const sortFunc = ( groupFixtures ) => {
|
|
17867
|
+
const sortRules = {
|
|
17868
|
+
5: 'desc',
|
|
17869
|
+
1: 'asc',
|
|
17870
|
+
2: 'asc',
|
|
17871
|
+
3: 'asc',
|
|
17872
|
+
4: 'desc',
|
|
17873
|
+
floor: 'asc',
|
|
17874
|
+
};
|
|
17875
|
+
|
|
17876
|
+
const staticOrder = [ '5', '1', '2', '4', '3', 'floor' ];
|
|
17877
|
+
|
|
17878
|
+
return groupFixtures.sort( ( a, b ) => {
|
|
17879
|
+
const wallA = a.associatedElementNumber !== undefined ? String( a.associatedElementNumber ) : 'floor';
|
|
17880
|
+
const wallB = b.associatedElementNumber !== undefined ? String( b.associatedElementNumber ) : 'floor';
|
|
17881
|
+
|
|
17882
|
+
// Step 1: enforce static wall order
|
|
17883
|
+
if ( wallA !== wallB ) {
|
|
17884
|
+
return staticOrder.indexOf( wallA ) - staticOrder.indexOf( wallB );
|
|
17885
|
+
}
|
|
17886
|
+
|
|
17887
|
+
// Step 2: same wall/floor → apply rule
|
|
17888
|
+
const rule = sortRules[wallA];
|
|
17889
|
+
const fixtureA = a.associatedElementFixtureNumber;
|
|
17890
|
+
const fixtureB = b.associatedElementFixtureNumber;
|
|
17891
|
+
|
|
17892
|
+
return rule === 'asc' ?
|
|
17893
|
+
fixtureA - fixtureB :
|
|
17894
|
+
fixtureB - fixtureA;
|
|
17895
|
+
} );
|
|
17896
|
+
};
|
|
17897
|
+
|
|
17898
|
+
async function getFixtures( query ) {
|
|
17899
|
+
let fixtures = await storeFixtureService.find( query );
|
|
17900
|
+
|
|
17901
|
+
fixtures = fixtures.map( ( fixture ) => fixture.toObject() );
|
|
17902
|
+
|
|
17903
|
+
const fixturesWithShelvesAndVms = await Promise.all(
|
|
17904
|
+
fixtures.map( async ( fixture ) => {
|
|
17905
|
+
const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { }, { shelfNumber: 1 } );
|
|
17906
|
+
|
|
17907
|
+
const shelfDetails = await Promise.all(
|
|
17908
|
+
shelves.map( async ( shelf ) => {
|
|
17909
|
+
return shelf.toObject();
|
|
17910
|
+
} ),
|
|
17911
|
+
);
|
|
17912
|
+
|
|
17913
|
+
|
|
17914
|
+
const vmDetails = await Promise.all( fixture?.vmConfig?.map( async ( vm ) => {
|
|
17915
|
+
const vmInfo = await planoVmService.findOne( { _id: vm.vmId } );
|
|
17916
|
+
return {
|
|
17917
|
+
...vm,
|
|
17918
|
+
...vmInfo?.toObject(),
|
|
17919
|
+
};
|
|
17920
|
+
} ) );
|
|
17921
|
+
|
|
17922
|
+
return {
|
|
17923
|
+
...fixture,
|
|
17924
|
+
shelfConfig: shelfDetails,
|
|
17925
|
+
vmConfig: vmDetails,
|
|
17926
|
+
};
|
|
17927
|
+
} ),
|
|
17928
|
+
);
|
|
17929
|
+
|
|
17930
|
+
return fixturesWithShelvesAndVms;
|
|
17931
|
+
};
|
|
17932
|
+
|
|
17933
|
+
async function updateFixtures( fixtures = [] ) {
|
|
17934
|
+
for ( let i = 0; i < fixtures.length; i++ ) {
|
|
17935
|
+
const fixture = fixtures[i];
|
|
17936
|
+
if ( !fixture ) {
|
|
17937
|
+
continue;
|
|
17938
|
+
}
|
|
17939
|
+
|
|
17940
|
+
const fixtureId = fixture._id;
|
|
17941
|
+
delete fixture._id;
|
|
17942
|
+
|
|
17943
|
+
const fixtureBrands = new Set();
|
|
17944
|
+
|
|
17945
|
+
await Promise.all( fixture.shelfConfig.map( async ( shelf ) => {
|
|
17946
|
+
const shelfId = shelf._id;
|
|
17947
|
+
delete shelf._id;
|
|
17948
|
+
shelf.productBrandName.forEach( ( brand ) => fixtureBrands.add( brand ) );
|
|
17949
|
+
return await fixtureShelfService.updateOne( { _id: shelfId }, shelf );
|
|
17950
|
+
} ) );
|
|
17951
|
+
|
|
17952
|
+
fixture.productBrandName = [ ...fixtureBrands ];
|
|
17953
|
+
|
|
17954
|
+
const vmConfig = await Promise.all( fixture.vmConfig.map( async ( vm ) => {
|
|
17955
|
+
let isVmExist = await planoVmService.findOne( { vmName: vm.vmName } );
|
|
17956
|
+
|
|
17957
|
+
if ( !isVmExist ) {
|
|
17958
|
+
const updateData = {
|
|
17959
|
+
'vmName': vm.vmName,
|
|
17960
|
+
'clientId': '11',
|
|
17961
|
+
'status': 'complete',
|
|
17962
|
+
'vmHeight': {
|
|
17963
|
+
'value': 100,
|
|
17964
|
+
'unit': 'mm',
|
|
17965
|
+
},
|
|
17966
|
+
'vmType': 'LKVM',
|
|
17967
|
+
'vmWidth': {
|
|
17968
|
+
'value': 230,
|
|
17969
|
+
'unit': 'mm',
|
|
17970
|
+
},
|
|
17971
|
+
};
|
|
17972
|
+
|
|
17973
|
+
isVmExist = await planoVmService.create( updateData );
|
|
17974
|
+
}
|
|
17975
|
+
|
|
17976
|
+
return { vmId: isVmExist._id, ...vm };
|
|
17977
|
+
} ) );
|
|
17978
|
+
|
|
17979
|
+
fixture.vmConfig = vmConfig;
|
|
17980
|
+
delete fixture.shelfConfig;
|
|
17981
|
+
|
|
17982
|
+
await storeFixtureService.updateOne( { _id: fixtureId }, fixture );
|
|
17983
|
+
}
|
|
17984
|
+
}
|
|
17985
|
+
|
|
17986
|
+
const checkVmExistInFixtures = ( fixtures, vmName ) => {
|
|
17987
|
+
if ( !vmName || !Array.isArray( fixtures ) ) return false;
|
|
17988
|
+
|
|
17989
|
+
const normalizedName = vmName.replace( /\s+/g, '' ).toLowerCase();
|
|
17990
|
+
|
|
17991
|
+
return fixtures.some( ( fixture ) =>
|
|
17992
|
+
Array.isArray( fixture?.vmConfig ) &&
|
|
17993
|
+
fixture.vmConfig.some( ( vm ) => {
|
|
17994
|
+
if ( !vm.vmName ) return false;
|
|
17995
|
+
const normalizedFixtureVm = vm.vmName.replace( /\s+/g, '' ).toLowerCase();
|
|
17996
|
+
return normalizedFixtureVm.includes( normalizedName );
|
|
17997
|
+
} ),
|
|
17998
|
+
);
|
|
17999
|
+
};
|
|
18000
|
+
|
|
18001
|
+
|
|
18002
|
+
const checkBrandExistInShelves = ( fixtures, brandName ) => {
|
|
18003
|
+
if ( !brandName || !Array.isArray( fixtures ) ) return false;
|
|
18004
|
+
|
|
18005
|
+
const normalizedBrand = brandName.replace( /\s+/g, '' ).toLowerCase();
|
|
18006
|
+
|
|
18007
|
+
return fixtures.some( ( fixture ) =>
|
|
18008
|
+
Array.isArray( fixture.shelfConfig ) &&
|
|
18009
|
+
fixture.shelfConfig.some( ( shelf ) =>
|
|
18010
|
+
Array.isArray( shelf.productBrandName ) &&
|
|
18011
|
+
shelf.productBrandName.some( ( name ) =>
|
|
18012
|
+
name.replace( /\s+/g, '' ).toLowerCase().includes( normalizedBrand ),
|
|
18013
|
+
),
|
|
18014
|
+
),
|
|
18015
|
+
);
|
|
18016
|
+
};
|
|
18017
|
+
|
|
18018
|
+
const updateVm = ( fixture ) => {
|
|
18019
|
+
if ( !fixture?.shelfConfig ) {
|
|
18020
|
+
return;
|
|
18021
|
+
}
|
|
18022
|
+
|
|
18023
|
+
const midShelves = fixture?.shelfConfig?.filter( ( shelf ) => shelf.zone === 'Mid' ).sort( ( shelf ) => shelf.shelfNumber - shelf.shelfNumber );
|
|
18024
|
+
|
|
18025
|
+
if ( midShelves.length === 0 ) {
|
|
18026
|
+
return;
|
|
18027
|
+
}
|
|
18028
|
+
let mid1; let mid2;
|
|
18029
|
+
if ( midShelves.length % 2 !== 0 ) {
|
|
18030
|
+
mid1 = midShelves[Math.floor( midShelves.length / 2 )].shelfNumber;
|
|
18031
|
+
mid2 = mid1;
|
|
18032
|
+
} else {
|
|
18033
|
+
mid1 = midShelves[midShelves.length / 2 - 1].shelfNumber;
|
|
18034
|
+
mid2 = midShelves[midShelves.length / 2].shelfNumber;
|
|
18035
|
+
}
|
|
18036
|
+
|
|
18037
|
+
if ( midShelves?.[0]?.shelfType == 'tray' ) {
|
|
18038
|
+
mid1=mid2;
|
|
18039
|
+
}
|
|
18040
|
+
|
|
18041
|
+
|
|
18042
|
+
const vmData = {
|
|
18043
|
+
vmName: 'Stranger Things',
|
|
18044
|
+
startYPosition: mid1,
|
|
18045
|
+
endYPosition: mid2,
|
|
18046
|
+
xZone: 'left',
|
|
18047
|
+
yZone: 'stretch',
|
|
18048
|
+
};
|
|
18049
|
+
|
|
18050
|
+
|
|
18051
|
+
// const existingVms = fixture?.vmConfig?.findIndex(
|
|
18052
|
+
// ( vm ) => vm.startYPosition == vmData.startYPosition && vm.endYPosition == vmData.endYPosition && vm.xZone == vmData.xZone && vm.yZone == vmData.yZone,
|
|
18053
|
+
// );
|
|
18054
|
+
|
|
18055
|
+
// if ( existingVms != -1 ) {
|
|
18056
|
+
fixture.vmConfig = [ vmData ];
|
|
18057
|
+
// } else {
|
|
18058
|
+
// fixture.vmConfig.push( vmData );
|
|
18059
|
+
// }
|
|
18060
|
+
|
|
18061
|
+
|
|
18062
|
+
return fixture;
|
|
18063
|
+
};
|
|
18064
|
+
|
|
18065
|
+
async function handleCond1( fixtures, index, exception ) {
|
|
18066
|
+
let fixtureList = fixtures.filter( ( fixture ) => ( fixture.header?.label === 'JJ Eye' || fixture.header?.label === 'John Jacobs' || fixture.header?.label?.toLowerCase().startsWith( 'premium trending' ) || fixture.header?.label?.toLowerCase().startsWith( 'premium work' ) ) && !checkVmExistInFixtures( [ fixture ], 'Fossil' ) && !checkVmExistInFixtures( [ fixture ], 'LPL' ) && fixture.shelfConfig.some( ( shelf ) => shelf.productBrandName.some( ( product ) => !product.toLowerCase().includes( 'fossil' ) && !product.toLowerCase().includes( 'lpl' ) ) ) );
|
|
18067
|
+
if ( !fixtureList.length ) {
|
|
18068
|
+
return;
|
|
18069
|
+
}
|
|
18070
|
+
let updateFixture;
|
|
18071
|
+
let urbanList = fixtureList.filter( ( ele ) => ele.vmConfig.some( ( vm ) => vm.vmId.toString() == '686cf5812e0f3d99b9d1e8b7' ) );
|
|
18072
|
+
if ( urbanList.length ) {
|
|
18073
|
+
updateFixture = urbanList[0];
|
|
18074
|
+
urbanList.splice( 0, 1 );
|
|
18075
|
+
urbanList.forEach( async ( ele ) => {
|
|
18076
|
+
let vmIndex = ele.vmConfig.findIndex( ( vm ) => vm.vmId.toString() == '686cf5812e0f3d99b9d1e8b7' );
|
|
18077
|
+
if ( vmIndex != -1 ) {
|
|
18078
|
+
ele.vmConfig.splice( vmIndex, 1 );
|
|
18079
|
+
}
|
|
18080
|
+
await storeFixtureService.updateOne( { _id: ele._id }, { vmConfig: ele.vmConfig } );
|
|
18081
|
+
} );
|
|
18082
|
+
}
|
|
18083
|
+
if ( !updateFixture ) {
|
|
18084
|
+
let acetateList = fixtureList.filter( ( ele ) => ele.shelfConfig.some( ( shelf ) => shelf.productBrandName.some( ( product ) => product.toLowerCase().includes( 'acetate' ) ) ) );
|
|
18085
|
+
updateFixture = acetateList[index];
|
|
18086
|
+
if ( exception == 'if conflicting with Coastline 3.0 or Zodiac, shift to the next fixture of JJ Eye/Premium Trending' && ( checkVmExistInFixtures( [ updateFixture ], 'Coastline 3.0' ) || checkVmExistInFixtures( [ updateFixture ], 'Zodiac' ) ) ) {
|
|
18087
|
+
let list = acetateList.filter( ( ele, i ) => i > index && !checkVmExistInFixtures( [ ele ], 'Coastline 3.0' ) &&!checkVmExistInFixtures( [ ele ], 'Zodiac' ) );
|
|
18088
|
+
updateFixture = list[0];
|
|
18089
|
+
}
|
|
18090
|
+
if ( !updateFixture ) {
|
|
18091
|
+
fixtureList = fixtureList.filter( ( ele ) => ele.shelfConfig.every( ( shelf ) => shelf.productBrandName.every( ( product ) => !product.toLowerCase().includes( 'acetate' ) ) ) && !checkVmExistInFixtures( [ ele ], 'Coastline 3.0' ) &&!checkVmExistInFixtures( [ ele ], 'Zodiac' ) );
|
|
18092
|
+
if ( acetateList.length ) {
|
|
18093
|
+
updateFixture = fixtureList[0];
|
|
18094
|
+
} else {
|
|
18095
|
+
updateFixture = fixtureList[index];
|
|
18096
|
+
}
|
|
18097
|
+
}
|
|
18098
|
+
}
|
|
18099
|
+
|
|
18100
|
+
fixtureList = updateVm( updateFixture );
|
|
18101
|
+
|
|
18102
|
+
await updateFixtures( [ fixtureList ] );
|
|
18103
|
+
};
|
|
18104
|
+
|
|
18105
|
+
async function handleCond2( fixtures, index ) {
|
|
18106
|
+
let updateFixtureList = fixtures.filter( ( fixture ) =>
|
|
18107
|
+
fixture.header?.label?.toLowerCase().startsWith( 'trending' ) || fixture.header?.label?.toLowerCase().startsWith( 'work essentials' ) || fixture.header?.label?.toLowerCase().startsWith( 'innovation' ) || fixture.header?.label?.toLowerCase().startsWith( 'vc eye' ) );
|
|
18108
|
+
|
|
18109
|
+
if ( !updateFixtureList.length ) {
|
|
18110
|
+
return;
|
|
18111
|
+
}
|
|
18112
|
+
let updateFixture = updateFixtureList[index];
|
|
18113
|
+
if ( index == 2 && ( ( checkVmExistInFixtures( 'Bitz' ) && checkVmExistInFixtures( 'Hustlr' ) ) || ( !updateFixture.header?.label?.toLowerCase().startsWith( 'innovation' ) && !updateFixture.header?.label?.toLowerCase().startsWith( 'vc eye' ) ) ) ) {
|
|
18114
|
+
updateFixture = updateFixtureList[index + 1];
|
|
18115
|
+
}
|
|
18116
|
+
updateFixture = updateVm( updateFixture );
|
|
18117
|
+
|
|
18118
|
+
await updateFixtures( [ updateFixture ] );
|
|
18119
|
+
};
|
|
18120
|
+
|
|
18121
|
+
async function handleCond3( fixtures ) {
|
|
18122
|
+
const caseFixtures = fixtures.filter( ( fixture ) => ( fixture.header.label === 'JJ Eye' || fixture.header.label === 'John Jacobs' ) ).slice( 1 );
|
|
18123
|
+
|
|
18124
|
+
let updateFixture = caseFixtures.find( ( fixture ) => !checkVmExistInFixtures( [ fixture ], 'Zodiac' ) );
|
|
18125
|
+
|
|
18126
|
+
if ( !updateFixture ) {
|
|
18127
|
+
return;
|
|
18128
|
+
}
|
|
18129
|
+
|
|
18130
|
+
updateFixture = updateVm( updateFixture );
|
|
18131
|
+
|
|
18132
|
+
await updateFixtures( [ updateFixture ] );
|
|
18133
|
+
};
|
|
18134
|
+
|
|
18135
|
+
async function handleCond4( fixtures ) {
|
|
18136
|
+
const caseFixtures = fixtures.filter( ( fixture ) =>
|
|
18137
|
+
fixture.header?.label === 'Premium Trending' ||
|
|
18138
|
+
fixture.header?.label === 'Premium trending' ||
|
|
18139
|
+
fixture.header?.label === 'Premium Trending 1' ||
|
|
18140
|
+
fixture.header?.label === 'Premium Trending 2'||
|
|
18141
|
+
fixture.header?.label ==='Premium Trending 3' ||
|
|
18142
|
+
fixture.header?.label === 'Premium Trending 4' ).slice( 1 );
|
|
18143
|
+
|
|
18144
|
+
if ( caseFixtures.length === 0 ) {
|
|
18145
|
+
return;
|
|
18146
|
+
}
|
|
18147
|
+
|
|
18148
|
+
let updateFixture = caseFixtures[0];
|
|
18149
|
+
|
|
18150
|
+
if ( !updateFixture ) {
|
|
18151
|
+
return;
|
|
18152
|
+
}
|
|
18153
|
+
|
|
18154
|
+
updateFixture = updateVm( updateFixture );
|
|
18155
|
+
|
|
18156
|
+
await updateFixtures( [ updateFixture ] );
|
|
18157
|
+
};
|
|
18158
|
+
|
|
18159
|
+
async function handleCond5( fixtures ) {
|
|
18160
|
+
let updateFixture = fixtures.find( ( fixture ) => checkBrandExistInShelves( [ fixture ], 'JJ Acetate' ) && !checkVmExistInFixtures( [ fixture ], 'Zodiac' ) );
|
|
18161
|
+
|
|
18162
|
+
if ( !updateFixture ) {
|
|
18163
|
+
updateFixture = fixtures.find( ( fixture ) => !checkVmExistInFixtures( [ fixture ], 'Zodiac' ) && ( fixture.header.label === 'JJ Eye' || fixture.header.label === 'John Jacobs' ) );
|
|
18164
|
+
}
|
|
18165
|
+
|
|
18166
|
+
|
|
18167
|
+
if ( !updateFixture ) {
|
|
18168
|
+
return;
|
|
18169
|
+
}
|
|
18170
|
+
|
|
18171
|
+
updateFixture = updateVm( updateFixture );
|
|
18172
|
+
|
|
18173
|
+
|
|
18174
|
+
await updateFixtures( [ updateFixture ] );
|
|
18175
|
+
};
|
|
18176
|
+
let storeList = [
|
|
18177
|
+
"LKST1166",
|
|
18178
|
+
"LKST129",
|
|
18179
|
+
"LKST160",
|
|
18180
|
+
"LKST1726",
|
|
18181
|
+
"LKST196",
|
|
18182
|
+
"LKST209",
|
|
18183
|
+
"LKST2136",
|
|
18184
|
+
"LKST2155",
|
|
18185
|
+
"LKST2226",
|
|
18186
|
+
"LKST2228",
|
|
18187
|
+
"LKST225",
|
|
18188
|
+
"LKST2396",
|
|
18189
|
+
"LKST2446",
|
|
18190
|
+
"LKST2450",
|
|
18191
|
+
"LKST2458",
|
|
18192
|
+
"LKST253",
|
|
18193
|
+
"LKST255",
|
|
18194
|
+
"LKST2566",
|
|
18195
|
+
"LKST2570",
|
|
18196
|
+
"LKST268",
|
|
18197
|
+
"LKST2715",
|
|
18198
|
+
"LKST272",
|
|
18199
|
+
"LKST273",
|
|
18200
|
+
"LKST282",
|
|
18201
|
+
"LKST3006",
|
|
18202
|
+
"LKST303",
|
|
18203
|
+
"LKST3032",
|
|
18204
|
+
"LKST351",
|
|
18205
|
+
"LKST356",
|
|
18206
|
+
"LKST387",
|
|
18207
|
+
"LKST453",
|
|
18208
|
+
"LKST464",
|
|
18209
|
+
"LKST496",
|
|
18210
|
+
"LKST527",
|
|
18211
|
+
"LKST53",
|
|
18212
|
+
"LKST566",
|
|
18213
|
+
"LKST62",
|
|
18214
|
+
"LKST694",
|
|
18215
|
+
"LKST86",
|
|
18216
|
+
"LKST907",
|
|
18217
|
+
"LKST96",
|
|
18218
|
+
"ST151",
|
|
18219
|
+
"ST196",
|
|
18220
|
+
];
|
|
18221
|
+
|
|
18222
|
+
for ( let i = 0; i < data.length; i++ ) {
|
|
18223
|
+
const store = data[i];
|
|
18224
|
+
if ( !storeList.includes( store?.['Store Code'] ) ) {
|
|
18225
|
+
continue;
|
|
18226
|
+
}
|
|
18227
|
+
const storePlano = await planoService.findOne( { storeName: store?.['Store Code'] } );
|
|
18228
|
+
if ( !storePlano ) continue;
|
|
18229
|
+
|
|
18230
|
+
let storeFixtures = await getFixtures( { planoId: storePlano._id } );
|
|
18231
|
+
storeFixtures = sortFunc( storeFixtures );
|
|
18232
|
+
|
|
18233
|
+
const wallFixtures = storeFixtures.filter(
|
|
18234
|
+
( f ) => f.associatedElementType !== undefined && f.associatedElementNumber !== undefined,
|
|
18235
|
+
);
|
|
18236
|
+
|
|
18237
|
+
|
|
18238
|
+
// if ( store?.['Store Code'] === 'LKST1072' ) {
|
|
18239
|
+
logger.error( { function: wallFixtures } );
|
|
18240
|
+
console.log( store['Fixture Remarks'] );
|
|
18241
|
+
if ( store['Fixture Remarks'] === '1st Fixture of JJ Acetate' || store['Fixture Remarks'] === '1st Euro of JJ Eye/Premium Trending' ) {
|
|
18242
|
+
await handleCond1( wallFixtures, 0, store['Remarks'] );
|
|
18243
|
+
} else if ( store['Fixture Remarks'] === '2nd Fixture marked as JJ Acetate' ) {
|
|
18244
|
+
await handleCond1( wallFixtures, 1, store['Remarks'] );
|
|
18245
|
+
}
|
|
18246
|
+
// else if ( store['Fixture Remarks'] === '1st Euro of JJ Eye/Premium Trending' ) {
|
|
18247
|
+
// console.log( store?.['Store Code'] );
|
|
18248
|
+
// await handleCond1( wallFixtures, 0, store['Remarks'] );
|
|
18249
|
+
// } else if ( store['Fixture Remarks'] === '4th Wall Fixture of VC Eye_LK Air' ) {
|
|
18250
|
+
// await handleCond2( wallFixtures, 3 );
|
|
18251
|
+
// }
|
|
18252
|
+
// }
|
|
18253
|
+
}
|
|
18254
|
+
|
|
18255
|
+
console.log( 'updated' );
|
|
18256
|
+
}
|
|
18257
|
+
|
|
18258
|
+
|
|
18259
|
+
// updateStrangerCollection();
|
|
18260
|
+
|
|
18261
|
+
async function updateMellerCollection() {
|
|
18262
|
+
const workbook = xlsx.readFile( './data/Meller Planned stores.xlsx' );
|
|
18263
|
+
|
|
18264
|
+
const sheetName = 'Store Level';
|
|
18265
|
+
const sheet = workbook.Sheets[sheetName];
|
|
18266
|
+
|
|
18267
|
+
const JsonData = xlsx.utils.sheet_to_json( sheet, { range: 0 } );
|
|
18268
|
+
|
|
18269
|
+
|
|
18270
|
+
const data = JSON.parse( JSON.stringify( JsonData, null, 2 ) );
|
|
18271
|
+
|
|
18272
|
+
|
|
18273
|
+
const sortFunc = ( groupFixtures ) => {
|
|
18274
|
+
const sortRules = {
|
|
18275
|
+
5: 'desc',
|
|
18276
|
+
1: 'asc',
|
|
18277
|
+
2: 'asc',
|
|
18278
|
+
3: 'asc',
|
|
18279
|
+
4: 'desc',
|
|
18280
|
+
floor: 'asc',
|
|
18281
|
+
};
|
|
18282
|
+
|
|
18283
|
+
const staticOrder = [ '5', '1', '2', '4', '3', 'floor' ];
|
|
18284
|
+
|
|
18285
|
+
return groupFixtures.sort( ( a, b ) => {
|
|
18286
|
+
const wallA = a.associatedElementNumber !== undefined ? String( a.associatedElementNumber ) : 'floor';
|
|
18287
|
+
const wallB = b.associatedElementNumber !== undefined ? String( b.associatedElementNumber ) : 'floor';
|
|
18288
|
+
|
|
18289
|
+
// Step 1: enforce static wall order
|
|
18290
|
+
if ( wallA !== wallB ) {
|
|
18291
|
+
return staticOrder.indexOf( wallA ) - staticOrder.indexOf( wallB );
|
|
18292
|
+
}
|
|
18293
|
+
|
|
18294
|
+
// Step 2: same wall/floor → apply rule
|
|
18295
|
+
const rule = sortRules[wallA];
|
|
18296
|
+
const fixtureA = a.associatedElementFixtureNumber;
|
|
18297
|
+
const fixtureB = b.associatedElementFixtureNumber;
|
|
18298
|
+
|
|
18299
|
+
return rule === 'asc' ?
|
|
18300
|
+
fixtureA - fixtureB :
|
|
18301
|
+
fixtureB - fixtureA;
|
|
18302
|
+
} );
|
|
18303
|
+
};
|
|
18304
|
+
|
|
18305
|
+
async function getFixtures( query ) {
|
|
18306
|
+
let fixtures = await storeFixtureService.find( query );
|
|
18307
|
+
|
|
18308
|
+
fixtures = fixtures.map( ( fixture ) => fixture.toObject() );
|
|
18309
|
+
|
|
18310
|
+
const fixturesWithShelvesAndVms = await Promise.all(
|
|
18311
|
+
fixtures.map( async ( fixture ) => {
|
|
18312
|
+
const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { }, { shelfNumber: 1 } );
|
|
18313
|
+
|
|
18314
|
+
const shelfDetails = await Promise.all(
|
|
18315
|
+
shelves.map( async ( shelf ) => {
|
|
18316
|
+
return shelf.toObject();
|
|
18317
|
+
} ),
|
|
18318
|
+
);
|
|
18319
|
+
|
|
18320
|
+
|
|
18321
|
+
const vmDetails = await Promise.all( fixture?.vmConfig?.map( async ( vm ) => {
|
|
18322
|
+
const vmInfo = await planoVmService.findOne( { _id: vm.vmId } );
|
|
18323
|
+
return {
|
|
18324
|
+
...vm,
|
|
18325
|
+
...vmInfo?.toObject(),
|
|
18326
|
+
};
|
|
18327
|
+
} ) );
|
|
18328
|
+
|
|
18329
|
+
return {
|
|
18330
|
+
...fixture,
|
|
18331
|
+
shelfConfig: shelfDetails,
|
|
18332
|
+
vmConfig: vmDetails,
|
|
18333
|
+
};
|
|
18334
|
+
} ),
|
|
18335
|
+
);
|
|
18336
|
+
|
|
18337
|
+
return fixturesWithShelvesAndVms;
|
|
18338
|
+
};
|
|
18339
|
+
|
|
18340
|
+
async function updateFixtures( fixtures = [] ) {
|
|
18341
|
+
for ( let i = 0; i < fixtures.length; i++ ) {
|
|
18342
|
+
const fixture = fixtures[i];
|
|
18343
|
+
if ( !fixture ) {
|
|
18344
|
+
continue;
|
|
18345
|
+
}
|
|
18346
|
+
|
|
18347
|
+
const fixtureId = fixture._id;
|
|
18348
|
+
delete fixture._id;
|
|
18349
|
+
|
|
18350
|
+
const fixtureBrands = new Set();
|
|
18351
|
+
|
|
18352
|
+
await Promise.all( fixture.shelfConfig.map( async ( shelf ) => {
|
|
18353
|
+
const shelfId = shelf._id;
|
|
18354
|
+
delete shelf._id;
|
|
18355
|
+
shelf.productBrandName.forEach( ( brand ) => fixtureBrands.add( brand ) );
|
|
18356
|
+
return await fixtureShelfService.updateOne( { _id: shelfId }, shelf );
|
|
18357
|
+
} ) );
|
|
18358
|
+
|
|
18359
|
+
fixture.productBrandName = [ ...fixtureBrands ];
|
|
18360
|
+
|
|
18361
|
+
const vmConfig = await Promise.all( fixture.vmConfig.map( async ( vm ) => {
|
|
18362
|
+
let isVmExist = await planoVmService.findOne( { vmName: vm.vmName } );
|
|
18363
|
+
|
|
18364
|
+
if ( !isVmExist ) {
|
|
18365
|
+
const updateData = {
|
|
18366
|
+
'vmName': vm.vmName,
|
|
18367
|
+
'clientId': '11',
|
|
18368
|
+
'status': 'complete',
|
|
18369
|
+
'vmHeight': {
|
|
18370
|
+
'value': 100,
|
|
18371
|
+
'unit': 'mm',
|
|
18372
|
+
},
|
|
18373
|
+
'vmType': 'LKVM',
|
|
18374
|
+
'vmWidth': {
|
|
18375
|
+
'value': 230,
|
|
18376
|
+
'unit': 'mm',
|
|
18377
|
+
},
|
|
18378
|
+
};
|
|
18379
|
+
|
|
18380
|
+
isVmExist = await planoVmService.create( updateData );
|
|
18381
|
+
}
|
|
18382
|
+
|
|
18383
|
+
return { vmId: isVmExist._id, ...vm };
|
|
18384
|
+
} ) );
|
|
18385
|
+
|
|
18386
|
+
fixture.vmConfig = vmConfig;
|
|
18387
|
+
delete fixture.shelfConfig;
|
|
18388
|
+
|
|
18389
|
+
await storeFixtureService.updateOne( { _id: fixtureId }, fixture );
|
|
18390
|
+
}
|
|
18391
|
+
}
|
|
18392
|
+
|
|
18393
|
+
const checkVmExistInFixtures = ( fixtures, vmName ) => {
|
|
18394
|
+
if ( !vmName || !Array.isArray( fixtures ) ) return false;
|
|
18395
|
+
|
|
18396
|
+
const normalizedName = vmName.replace( /\s+/g, '' ).toLowerCase();
|
|
18397
|
+
|
|
18398
|
+
return fixtures.some( ( fixture ) =>
|
|
18399
|
+
Array.isArray( fixture?.vmConfig ) &&
|
|
18400
|
+
fixture.vmConfig.some( ( vm ) => {
|
|
18401
|
+
if ( !vm.vmName ) return false;
|
|
18402
|
+
const normalizedFixtureVm = vm.vmName.replace( /\s+/g, '' ).toLowerCase();
|
|
18403
|
+
return normalizedFixtureVm.includes( normalizedName );
|
|
18404
|
+
} ),
|
|
18405
|
+
);
|
|
18406
|
+
};
|
|
18407
|
+
|
|
18408
|
+
|
|
18409
|
+
const checkBrandExistInShelves = ( fixtures, brandName ) => {
|
|
18410
|
+
if ( !brandName || !Array.isArray( fixtures ) ) return false;
|
|
18411
|
+
|
|
18412
|
+
const normalizedBrand = brandName.replace( /\s+/g, '' ).toLowerCase();
|
|
18413
|
+
|
|
18414
|
+
return fixtures.some( ( fixture ) =>
|
|
18415
|
+
Array.isArray( fixture.shelfConfig ) &&
|
|
18416
|
+
fixture.shelfConfig.some( ( shelf ) =>
|
|
18417
|
+
Array.isArray( shelf.productBrandName ) &&
|
|
18418
|
+
shelf.productBrandName.some( ( name ) =>
|
|
18419
|
+
name.replace( /\s+/g, '' ).toLowerCase().includes( normalizedBrand ),
|
|
18420
|
+
),
|
|
18421
|
+
),
|
|
18422
|
+
);
|
|
18423
|
+
};
|
|
18424
|
+
|
|
18425
|
+
const updateVm = ( fixture ) => {
|
|
18426
|
+
if ( !fixture?.shelfConfig ) {
|
|
18427
|
+
return;
|
|
18428
|
+
}
|
|
18429
|
+
|
|
18430
|
+
if ( fixture.fixtureType == 'wall' ) {
|
|
18431
|
+
const midShelves = fixture?.shelfConfig?.filter( ( shelf ) => shelf.zone === 'Mid' ).sort( ( shelf ) => shelf.shelfNumber - shelf.shelfNumber );
|
|
18432
|
+
|
|
18433
|
+
if ( midShelves.length === 0 ) {
|
|
18434
|
+
return;
|
|
18435
|
+
}
|
|
18436
|
+
let mid1; let mid2;
|
|
18437
|
+
if ( midShelves.length % 2 !== 0 ) {
|
|
18438
|
+
mid1 = midShelves[Math.floor( midShelves.length / 2 )].shelfNumber;
|
|
18439
|
+
mid2 = mid1;
|
|
18440
|
+
} else {
|
|
18441
|
+
mid1 = midShelves[midShelves.length / 2 - 1].shelfNumber;
|
|
18442
|
+
mid2 = midShelves[midShelves.length / 2].shelfNumber;
|
|
18443
|
+
}
|
|
18444
|
+
if ( midShelves?.[0]?.shelfType == 'tray' ) {
|
|
18445
|
+
mid1 = mid2;
|
|
18446
|
+
}
|
|
18447
|
+
|
|
18448
|
+
const vmData = {
|
|
18449
|
+
vmName: 'Meller',
|
|
18450
|
+
startYPosition: mid1,
|
|
18451
|
+
endYPosition: mid2,
|
|
18452
|
+
xZone: 'left',
|
|
18453
|
+
yZone: 'stretch',
|
|
18454
|
+
};
|
|
18455
|
+
|
|
18456
|
+
console.log( vmData );
|
|
18457
|
+
const existingVms = fixture?.vmConfig?.findIndex(
|
|
18458
|
+
( vm ) => vm.startYPosition == vmData.startYPosition && vm.endYPosition == vmData.endYPosition && vm.xZone == vmData.xZone && vm.yZone == vmData.yZone,
|
|
18459
|
+
);
|
|
18460
|
+
|
|
18461
|
+
if ( existingVms != -1 ) {
|
|
18462
|
+
fixture.vmConfig[existingVms] = vmData;
|
|
18463
|
+
} else {
|
|
18464
|
+
fixture.vmConfig.push( vmData );
|
|
18465
|
+
}
|
|
18466
|
+
}
|
|
18467
|
+
|
|
18468
|
+
if ( fixture.fixtureType === 'floor' ) {
|
|
18469
|
+
const shelves = fixture?.shelfConfig?.sort( ( shelf ) => shelf.shelfNumber - shelf.shelfNumber );
|
|
18470
|
+
const vms = [];
|
|
18471
|
+
vms.push( {
|
|
18472
|
+
vmName: 'meller - 1',
|
|
18473
|
+
startYPosition: shelves[0].shelfNumber,
|
|
18474
|
+
endYPosition: shelves[shelves.length - 2].shelfNumber,
|
|
18475
|
+
xZone: 'left',
|
|
18476
|
+
yZone: 'stretch',
|
|
18477
|
+
} );
|
|
18478
|
+
|
|
18479
|
+
vms.push( {
|
|
18480
|
+
vmName: 'meller - 2',
|
|
18481
|
+
startYPosition: shelves[shelves.length - 1].shelfNumber,
|
|
18482
|
+
endYPosition: shelves[shelves.length - 1].shelfNumber,
|
|
18483
|
+
xZone: 'stretch',
|
|
18484
|
+
yZone: 'stretch',
|
|
18485
|
+
} );
|
|
18486
|
+
|
|
18487
|
+
fixture.vmConfig = vms;
|
|
18488
|
+
|
|
18489
|
+
fixture.shelfConfig.forEach( ( shelf ) => {
|
|
18490
|
+
shelf.productBrandName = [ 'meller' ];
|
|
18491
|
+
} );
|
|
18492
|
+
}
|
|
18493
|
+
|
|
18494
|
+
|
|
18495
|
+
return fixture;
|
|
18496
|
+
};
|
|
18497
|
+
|
|
18498
|
+
async function handleCond1( fixtures, store ) {
|
|
18499
|
+
let getJJSUN = fixtures.filter( ( fixture ) => ( fixture.header?.label === 'JJ Sun' || fixture.header?.label?.toLowerCase().startsWith( 'premium shades' ) ) );
|
|
18500
|
+
let updateFixture;
|
|
18501
|
+
if ( getJJSUN.length ) {
|
|
18502
|
+
updateFixture = getJJSUN.find( ( ele ) => ele.fixtureCategory.toLowerCase() == store['Fixture Type'].toLowerCase() );
|
|
18503
|
+
if ( !updateFixture ) {
|
|
18504
|
+
updateFixture = getJJSUN[0];
|
|
18505
|
+
}
|
|
18506
|
+
}
|
|
18507
|
+
|
|
18508
|
+
updateFixture?.shelfConfig?.forEach( ( fixt ) => {
|
|
18509
|
+
if ( [ 'Top', 'Mid' ].includes( fixt.zone ) ) {
|
|
18510
|
+
fixt.productBrandName = [ 'JJ Sun - Meller' ];
|
|
18511
|
+
}
|
|
18512
|
+
} );
|
|
18513
|
+
let fixtureList = updateVm( updateFixture );
|
|
18514
|
+
|
|
18515
|
+
await updateFixtures( [ fixtureList ] );
|
|
18516
|
+
};
|
|
18517
|
+
|
|
18518
|
+
for ( let i = 0; i < data.length; i++ ) {
|
|
18519
|
+
const store = data[i];
|
|
18520
|
+
const storePlano = await planoService.findOne( { storeName: store?.['Store Code'] } );
|
|
18521
|
+
if ( !storePlano ) continue;
|
|
18522
|
+
|
|
18523
|
+
let storeFixtures = await getFixtures( { planoId: storePlano._id } );
|
|
18524
|
+
storeFixtures = sortFunc( storeFixtures );
|
|
18525
|
+
|
|
18526
|
+
// const wallFixtures = storeFixtures.filter(
|
|
18527
|
+
// ( f ) => f.associatedElementType !== undefined && f.associatedElementNumber !== undefined,
|
|
18528
|
+
// );
|
|
18529
|
+
|
|
18530
|
+
// if ( store['Store Code'] == 'LKST2495' ) {
|
|
18531
|
+
await handleCond1( storeFixtures, store );
|
|
18532
|
+
// }
|
|
18533
|
+
}
|
|
18534
|
+
|
|
18535
|
+
console.log( 'updated' );
|
|
18536
|
+
}
|
|
18537
|
+
|
|
18538
|
+
// updateMellerCollection();
|
|
18539
|
+
|