tango-app-api-store-builder 1.0.0-beta-42 → 1.0.0-beta-43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-store-builder",
3
- "version": "1.0.0-beta-42",
3
+ "version": "1.0.0-beta-43",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -57,12 +57,12 @@ export async function createFixtureConfig( req, res ) {
57
57
  const proportionRaw = item['Proportion'];
58
58
 
59
59
  const availableSections = typeof sectionDetailsRaw === 'string' ?
60
- sectionDetailsRaw.replace( /[{}]/g, '' ).split( ', ' ).map( ( s ) => s.trim() ) :
61
- [];
60
+ sectionDetailsRaw.replace( /[{}]/g, '' ).split( ', ' ).map( ( s ) => s.trim() ) :
61
+ [];
62
62
 
63
63
  const proportions = typeof proportionRaw === 'string' ?
64
- proportionRaw.replace( /[{}%]/g, '' ).split( ', ' ).map( ( num ) => parseInt( num.trim(), 10 ) ) :
65
- [];
64
+ proportionRaw.replace( /[{}%]/g, '' ).split( ', ' ).map( ( num ) => parseInt( num.trim(), 10 ) ) :
65
+ [];
66
66
 
67
67
  const sectionNames = [ 'Top', 'Mid', 'Bottom' ];
68
68
  const sectionKeys = [ 'Top_Section', 'Middle_Section', 'Bottom_Section' ];
@@ -154,6 +154,172 @@ export async function createPlano( req, res ) {
154
154
  }
155
155
  }
156
156
 
157
+ // export async function createFloors(req, res) {
158
+ // try {
159
+ // if (!req.files.file) {
160
+ // return res.sendError('Invalid or missing Excel file', 400);
161
+ // }
162
+
163
+ // const workbook = xlsx.read(req.files.file.data, { type: 'buffer' });
164
+ // const sheetName = 'Layout,Fixture&VM';
165
+ // if (!workbook.Sheets[sheetName]) {
166
+ // return res.sendError(`Sheet "${sheetName}" not found`, 400);
167
+ // }
168
+
169
+ // const rawData = xlsx.utils.sheet_to_json(workbook.Sheets[sheetName]);
170
+
171
+ // const groupedData = {};
172
+
173
+ // rawData.forEach((item) => {
174
+ // const fixtureId = item['Store Fixture ID'];
175
+
176
+ // if (!groupedData[fixtureId]) {
177
+ // groupedData[fixtureId] = {
178
+ // 'Store ID': item['Store ID'],
179
+ // 'Store Fixture ID': fixtureId,
180
+ // 'Fixture ID': item['Fixture ID ( For ref only)'],
181
+ // 'Fixture Category': item['Fixture Category'],
182
+ // 'Fixture Size (feet)': item['Fixture Size (feet)'],
183
+ // 'Fixture Count': item['Fixture Count'],
184
+ // 'Effective Fixture Count': item['Effective Fixture Count'],
185
+ // 'Capacity': item['Capacity'],
186
+ // 'Store Fixture Locator': item['Store Fixture Locator'],
187
+ // 'Wall': item['Wall'],
188
+ // 'Brand-Category': item['Brand-Category'],
189
+ // 'Brand - Sub Category': item['Brand - Sub Category'],
190
+ // 'VM Template ID': item['VM Template ID '],
191
+ // 'categories': [],
192
+ // };
193
+ // }
194
+
195
+ // const categories = groupedData[fixtureId]['categories'];
196
+ // const existingCategory = categories.find((cat) => cat['Zone'] === item['Section Allocation ']);
197
+
198
+ // if (!existingCategory) {
199
+ // categories.push({
200
+ // 'Allocation': item['Shelf Allocation'],
201
+ // 'Zone': item['Section Allocation '],
202
+ // });
203
+ // }
204
+ // });
205
+
206
+ // const raw = Object.values(groupedData);
207
+
208
+ // const constantFixtureLength = 1220;
209
+ // const constantDetailedFixtureLength = 1220;
210
+ // const constantFixtureWidth = 610;
211
+ // const constantDetailedFixtureWidth = 1524;
212
+ // const mmToFeet = 305;
213
+
214
+ // const storeList = await planoService.find({});
215
+
216
+ // await Promise.all(storeList.map(async (store) => {
217
+ // const planoDoc = store.toObject();
218
+ // const leftWalls = raw.filter((entry) => entry['Store ID'] === planoDoc.storeName && entry.Wall === 'Left');
219
+ // const leftWallCount = leftWalls.length;
220
+
221
+ // const totalLeftDistanceFeet = Math.round((leftWallCount * (constantFixtureLength / mmToFeet)));
222
+ // const totalLeftDetailedDistanceFeet = Math.round((leftWallCount * (constantDetailedFixtureLength / mmToFeet)));
223
+
224
+ // const rightWalls = raw.filter((entry) => entry['Store ID'] === planoDoc.storeName && entry.Wall === 'Right');
225
+ // const rightWallCount = rightWalls.length;
226
+
227
+ // const totalRightDistanceFeet = Math.round((rightWallCount * (constantFixtureLength / mmToFeet)));
228
+ // const totalRightDetailedDistanceFeet = Math.round((rightWallCount * (constantDetailedFixtureLength / mmToFeet)));
229
+
230
+ // const totalDistanceFeet = Math.max(totalLeftDistanceFeet, totalRightDistanceFeet);
231
+ // const totalDetailedDistanceFeet = Math.max(totalLeftDetailedDistanceFeet, totalRightDetailedDistanceFeet);
232
+
233
+ // const floorFixtures = raw.filter((entry) => entry['Store ID'] === planoDoc.storeName && entry.Wall === 'Centre');
234
+ // const floorFixtureLength = floorFixtures.length;
235
+ // const maxFixturesPerRow = floorFixtureLength > 4 ? 3 : 2;
236
+ // const totalRows = Math.ceil(floorFixtureLength / maxFixturesPerRow);
237
+
238
+ // const yDistance = Math.round(((totalRows + 6) * (constantFixtureWidth / mmToFeet)));
239
+ // const detailedyDistance = Math.round(((totalRows + 4) * (constantDetailedFixtureWidth / mmToFeet)));
240
+
241
+ // const floorInsertData = {
242
+ // storeName: planoDoc.storeName,
243
+ // storeId: planoDoc.storeId,
244
+ // layoutName: `${planoDoc.storeName} - Layout`,
245
+ // clientId: '11',
246
+ // floorNumber: 1,
247
+ // floorName: 'floor 1',
248
+ // layoutPolygon: [
249
+ // {
250
+ // elementType: 'wall',
251
+ // distance: totalDistanceFeet + 3,
252
+ // unit: 'ft',
253
+ // direction: 'right',
254
+ // angle: 90,
255
+ // elementNumber: 1,
256
+ // detailedDistance: totalDetailedDistanceFeet + 3,
257
+ // },
258
+ // {
259
+ // elementType: 'wall',
260
+ // distance: yDistance,
261
+ // unit: 'ft',
262
+ // direction: 'down',
263
+ // angle: 90,
264
+ // elementNumber: 2,
265
+ // detailedDistance: detailedyDistance,
266
+ // },
267
+ // {
268
+ // elementType: 'wall',
269
+ // distance: totalDistanceFeet + 3,
270
+ // unit: 'ft',
271
+ // direction: 'left',
272
+ // angle: 90,
273
+ // elementNumber: 3,
274
+ // detailedDistance: totalDetailedDistanceFeet + 3,
275
+ // },
276
+ // {
277
+ // elementType: 'wall',
278
+ // distance: Math.round((yDistance * 40) / 100),
279
+ // unit: 'ft',
280
+ // direction: 'up',
281
+ // angle: 90,
282
+ // elementNumber: 4,
283
+ // detailedDistance: Math.round((detailedyDistance * 35) / 100),
284
+ // },
285
+ // {
286
+ // elementType: 'entrance',
287
+ // distance: Math.round((yDistance * 20) / 100),
288
+ // unit: 'ft',
289
+ // direction: 'up',
290
+ // angle: 90,
291
+ // elementNumber: 1,
292
+ // detailedDistance: Math.round((detailedyDistance * 30) / 100),
293
+ // },
294
+ // {
295
+ // elementType: 'wall',
296
+ // distance: Math.round((yDistance * 40) / 100),
297
+ // unit: 'ft',
298
+ // direction: 'up',
299
+ // angle: 90,
300
+ // elementNumber: 5,
301
+ // detailedDistance: Math.round((detailedyDistance * 35) / 100),
302
+ // },
303
+ // ],
304
+ // createdBy: new mongoose.Types.ObjectId('66a78cd82734f4f857cd6db6'),
305
+ // createdByName: 'Bejan',
306
+ // createdByEmail: 'bejan@tangotech.co.in',
307
+ // status: 'completed',
308
+ // planoId: planoDoc._id,
309
+ // };
310
+
311
+ // await storeBuilderService.create(floorInsertData);
312
+
313
+ // console.log(floorInsertData);
314
+ // }));
315
+
316
+ // return res.sendSuccess({ message: 'Floor data inserted successfully' });
317
+ // } catch (e) {
318
+ // logger.error({ functionName: 'addFloorDataAPI', error: e });
319
+ // return res.sendError(e.message || 'Internal Server Error', 500);
320
+ // }
321
+ // }
322
+
157
323
  export async function createFloors( req, res ) {
158
324
  try {
159
325
  if ( !req.files.file ) {
@@ -207,36 +373,63 @@ export async function createFloors( req, res ) {
207
373
 
208
374
  const constantFixtureLength = 1220;
209
375
  const constantDetailedFixtureLength = 1220;
376
+
210
377
  const constantFixtureWidth = 610;
211
378
  const constantDetailedFixtureWidth = 1524;
379
+
212
380
  const mmToFeet = 305;
213
381
 
214
382
  const storeList = await planoService.find( {} );
215
383
 
384
+ function roundToTwo( num ) {
385
+ return Math.round( num * 100 ) / 100;
386
+ }
387
+
216
388
  await Promise.all( storeList.map( async ( store ) => {
217
389
  const planoDoc = store.toObject();
218
- const leftWalls = raw.filter( ( entry ) => entry['Store ID'] === planoDoc.storeName && entry.Wall === 'Left' );
219
- const leftWallCount = leftWalls.length;
390
+ const leftFixtures = raw.filter( ( entry ) => entry['Store ID'] === planoDoc.storeName && entry.Wall === 'Left' );
391
+ const rightFixtures = raw.filter( ( entry ) => entry['Store ID'] === planoDoc.storeName && entry.Wall === 'Right' );
392
+ const floorFixtures = raw.filter( ( entry ) => entry['Store ID'] === planoDoc.storeName && entry.Wall === 'Centre' );
393
+ const backFixtures = raw.filter( ( entry ) => entry['Store ID'] === planoDoc.storeName && entry.Wall === 'Back' );
220
394
 
221
- const totalLeftDistanceFeet = Math.round( ( leftWallCount * ( constantFixtureLength / mmToFeet ) ) );
222
- const totalLeftDetailedDistanceFeet = Math.round( ( leftWallCount * ( constantDetailedFixtureLength / mmToFeet ) ) );
395
+ const leftXDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
396
+ const leftXDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
223
397
 
224
- const rightWalls = raw.filter( ( entry ) => entry['Store ID'] === planoDoc.storeName && entry.Wall === 'Right' );
225
- const rightWallCount = rightWalls.length;
398
+ const leftYDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantFixtureWidth / mmToFeet ) ) ) : 0;
399
+ const leftYDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantDetailedFixtureWidth / mmToFeet ) ) ) : 0;
226
400
 
227
- const totalRightDistanceFeet = Math.round( ( rightWallCount * ( constantFixtureLength / mmToFeet ) ) );
228
- const totalRightDetailedDistanceFeet = Math.round( ( rightWallCount * ( constantDetailedFixtureLength / mmToFeet ) ) );
401
+ const rightXDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
402
+ const rightXDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
229
403
 
230
- const totalDistanceFeet = Math.max( totalLeftDistanceFeet, totalRightDistanceFeet );
231
- const totalDetailedDistanceFeet = Math.max( totalLeftDetailedDistanceFeet, totalRightDetailedDistanceFeet );
404
+ const rightYDistanceFeet = rightFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
405
+ const rightYDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( constantDetailedFixtureWidth / mmToFeet ) ): 0;
232
406
 
233
- const floorFixtures = raw.filter( ( entry ) => entry['Store ID'] === planoDoc.storeName && entry.Wall === 'Centre' );
234
- const floorFixtureLength = floorFixtures.length;
235
- const maxFixturesPerRow = floorFixtureLength > 4 ? 3 : 2;
236
- const totalRows = Math.ceil( floorFixtureLength / maxFixturesPerRow );
407
+ const maxFixturesPerRow = floorFixtures.length > 4 ? 3 : 2;
408
+ const totalRows = Math.ceil( floorFixtures.length / maxFixturesPerRow );
409
+ const floorXDistanceFeet = floorFixtures.length ? roundToTwo( ( maxFixturesPerRow * ( constantFixtureLength / mmToFeet ) ) ) : 0;
410
+ const floorXDetailedDistanceFeet = floorFixtures.length ? roundToTwo( ( maxFixturesPerRow * ( constantDetailedFixtureLength / mmToFeet ) ) ): 0;
411
+
412
+ const floorYDistanceFeet = floorFixtures.length ? roundToTwo( ( totalRows * ( constantFixtureWidth/ mmToFeet ) ) ): 0;
413
+ const floorYDetailedDistanceFeet = floorFixtures.length ? roundToTwo( totalRows * ( constantDetailedFixtureWidth/mmToFeet ) ): 0;
414
+
415
+ const backXDistanceFeet = backFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
416
+ const backXDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( constantDetailedFixtureLength / mmToFeet ) ) : 0;
237
417
 
238
- const yDistance = Math.round( ( ( totalRows + 6 ) * ( constantFixtureWidth / mmToFeet ) ) );
239
- const detailedyDistance = Math.round( ( ( totalRows + 4 ) * ( constantDetailedFixtureWidth / mmToFeet ) ) );
418
+ const backYDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantFixtureLength / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantFixtureWidth )/mmToFeet ) ) ) : 0;
419
+ const backYDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantDetailedFixtureWidth / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth )/mmToFeet ) ) ): 0;
420
+
421
+ const maxXDistance = Math.max( leftXDistanceFeet, rightXDistanceFeet, floorXDistanceFeet );
422
+ const maxXDetailedDistance = Math.max( leftXDetailedDistanceFeet, rightXDetailedDistanceFeet, floorXDetailedDistanceFeet );
423
+
424
+ const maxYDistance = Math.max( floorYDistanceFeet, backYDistanceFeet );
425
+ const maxYDetailedDistance = Math.max( floorYDetailedDistanceFeet, backYDetailedDistanceFeet );
426
+
427
+ const finalXDistance = maxXDistance;
428
+ const finalXDetailedDistance = maxXDetailedDistance;
429
+
430
+
431
+ const finalYDistance = maxYDistance < ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) ? ( ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) + ( ( 2 * constantFixtureWidth )/mmToFeet ) ) : maxYDistance;
432
+ const finalYDetailedDistance = maxYDetailedDistance < ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) ? ( ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureWidth )/mmToFeet ) ) : maxYDetailedDistance;
240
433
 
241
434
  const floorInsertData = {
242
435
  storeName: planoDoc.storeName,
@@ -248,57 +441,57 @@ export async function createFloors( req, res ) {
248
441
  layoutPolygon: [
249
442
  {
250
443
  elementType: 'wall',
251
- distance: totalDistanceFeet + 3,
444
+ distance: finalXDistance,
252
445
  unit: 'ft',
253
446
  direction: 'right',
254
447
  angle: 90,
255
448
  elementNumber: 1,
256
- detailedDistance: totalDetailedDistanceFeet + 3,
449
+ detailedDistance: finalXDetailedDistance,
257
450
  },
258
451
  {
259
452
  elementType: 'wall',
260
- distance: yDistance,
453
+ distance: finalYDistance,
261
454
  unit: 'ft',
262
455
  direction: 'down',
263
456
  angle: 90,
264
457
  elementNumber: 2,
265
- detailedDistance: detailedyDistance,
458
+ detailedDistance: finalYDetailedDistance,
266
459
  },
267
460
  {
268
461
  elementType: 'wall',
269
- distance: totalDistanceFeet + 3,
462
+ distance: finalXDistance,
270
463
  unit: 'ft',
271
464
  direction: 'left',
272
465
  angle: 90,
273
466
  elementNumber: 3,
274
- detailedDistance: totalDetailedDistanceFeet + 3,
467
+ detailedDistance: finalXDetailedDistance,
275
468
  },
276
469
  {
277
470
  elementType: 'wall',
278
- distance: Math.round( ( yDistance * 40 ) / 100 ),
471
+ distance: roundToTwo( ( ( finalYDistance * 40 ) / 100 ) ),
279
472
  unit: 'ft',
280
473
  direction: 'up',
281
474
  angle: 90,
282
475
  elementNumber: 4,
283
- detailedDistance: Math.round( ( detailedyDistance * 35 ) / 100 ),
476
+ detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 35 ) / 100 ) ),
284
477
  },
285
478
  {
286
479
  elementType: 'entrance',
287
- distance: Math.round( ( yDistance * 20 ) / 100 ),
480
+ distance: roundToTwo( ( ( finalYDistance * 20 ) / 100 ) ),
288
481
  unit: 'ft',
289
482
  direction: 'up',
290
483
  angle: 90,
291
484
  elementNumber: 1,
292
- detailedDistance: Math.round( ( detailedyDistance * 30 ) / 100 ),
485
+ detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 30 ) / 100 ) ),
293
486
  },
294
487
  {
295
488
  elementType: 'wall',
296
- distance: Math.round( ( yDistance * 40 ) / 100 ),
489
+ distance: roundToTwo( ( ( finalYDistance * 40 ) / 100 ) ),
297
490
  unit: 'ft',
298
491
  direction: 'up',
299
492
  angle: 90,
300
493
  elementNumber: 5,
301
- detailedDistance: Math.round( ( detailedyDistance * 35 ) / 100 ),
494
+ detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 35 ) / 100 ) ),
302
495
  },
303
496
  ],
304
497
  createdBy: new mongoose.Types.ObjectId( '66a78cd82734f4f857cd6db6' ),
@@ -310,7 +503,7 @@ export async function createFloors( req, res ) {
310
503
 
311
504
  await storeBuilderService.create( floorInsertData );
312
505
 
313
- console.log( floorInsertData );
506
+ // console.log( floorInsertData );
314
507
  } ) );
315
508
 
316
509
  return res.sendSuccess( { message: 'Floor data inserted successfully' } );
@@ -320,6 +513,467 @@ export async function createFloors( req, res ) {
320
513
  }
321
514
  }
322
515
 
516
+ // export async function createFixturesShelves( req, res ) {
517
+ // try {
518
+ // if ( !req.files.file ) {
519
+ // return res.sendError( 'Invalid or missing Excel file', 400 );
520
+ // }
521
+
522
+ // const workbook = xlsx.read( req.files.file.data, { type: 'buffer' } );
523
+ // const sheetName = 'Layout,Fixture&VM';
524
+ // if ( !workbook.Sheets[sheetName] ) {
525
+ // return res.sendError( `Sheet "${sheetName}" not found`, 400 );
526
+ // }
527
+
528
+ // const rawData = xlsx.utils.sheet_to_json( workbook.Sheets[sheetName] );
529
+
530
+ // const groupedData = {};
531
+
532
+ // rawData.forEach( ( item ) => {
533
+ // const fixtureId = item['Store Fixture ID'];
534
+
535
+ // if ( !groupedData[fixtureId] ) {
536
+ // groupedData[fixtureId] = {
537
+ // 'Store ID': item['Store ID'],
538
+ // 'Store Fixture ID': fixtureId,
539
+ // 'Fixture ID': item['Fixture ID ( For ref only)'],
540
+ // 'Fixture Category': item['Fixture Category'],
541
+ // 'Fixture Size (feet)': item['Fixture Size (feet)'],
542
+ // 'Fixture Count': item['Fixture Count'],
543
+ // 'Effective Fixture Count': item['Effective Fixture Count'],
544
+ // 'Capacity': item['Capacity'],
545
+ // 'Store Fixture Locator': item['Store Fixture Locator'],
546
+ // 'Wall': item['Wall'],
547
+ // 'Brand-Category': item['Brand-Category'],
548
+ // 'Brand - Sub Category': item['Brand - Sub Category'],
549
+ // 'VM Template ID': item['VM Template ID '],
550
+ // 'categories': [],
551
+ // };
552
+ // }
553
+
554
+ // const categories = groupedData[fixtureId]['categories'];
555
+ // const existingCategory = categories.find( ( cat ) => cat['Zone'] === item['Section Allocation '] );
556
+
557
+ // if ( !existingCategory ) {
558
+ // categories.push( {
559
+ // 'Allocation': item['Shelf Allocation'],
560
+ // 'Zone': item['Section Allocation '],
561
+ // } );
562
+ // }
563
+ // } );
564
+
565
+ // const raw = Object.values( groupedData );
566
+
567
+ // const constantFixtureLength = 1220;
568
+ // const constantDetailedFixtureLength = 1220;
569
+ // const constantDetailedFloorFixtureLength = 1524;
570
+
571
+
572
+ // const constantFixtureWidth = 610;
573
+ // const constantDetailedFixtureWidth = 1524;
574
+ // const constantDetailedFloorFixtureWidth = 1220;
575
+
576
+
577
+ // const mmToFeet = 305;
578
+ // const layoutList = await storeBuilderService.find( {} );
579
+
580
+ // for ( let i = 0; i < layoutList.length; i++ ) {
581
+ // const layout = layoutList[i];
582
+
583
+ // const layoutDoc = layout.toObject();
584
+
585
+ // const leftFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Left' );
586
+ // const leftWallCount = leftFixtures.length;
587
+
588
+ // const rightFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Right' );
589
+ // const rightWallCount = rightFixtures.length;
590
+
591
+
592
+ // const floorFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Centre' );
593
+ // const floorFixtureCount = floorFixtures.length;
594
+
595
+ // const maxFixturesPerRow = floorFixtureCount > 4 ? 3 : 2;
596
+
597
+ // const totalRows = Math.ceil( floorFixtureCount / maxFixturesPerRow );
598
+ // const centerRow = Math.floor( totalRows / 2 );
599
+
600
+ // const totalLeftDistanceFeet = Math.round( ( leftWallCount * ( constantFixtureLength / mmToFeet ) ) );
601
+ // const totalLeftDetailedDistanceFeet = Math.round( ( leftWallCount * ( constantDetailedFixtureLength / mmToFeet ) ) );
602
+
603
+ // const totalRightDistanceFeet = Math.round( ( rightWallCount * ( constantFixtureLength / mmToFeet ) ) );
604
+ // const totalRightDetailedDistanceFeet = Math.round( ( rightWallCount * ( constantDetailedFixtureLength / mmToFeet ) ) );
605
+
606
+ // const totalCentreDistanceFeet = Math.round( ( ( totalRows + 6 ) * ( constantFixtureWidth / mmToFeet ) ) );
607
+ // const totalCentreDetailedDistanceFeet = Math.round( ( ( totalRows + 4 ) * ( constantDetailedFixtureWidth / mmToFeet ) ) );
608
+
609
+ // const totalDistanceFeetX = Math.max( totalLeftDistanceFeet, totalRightDistanceFeet );
610
+ // const totalDetailedDistanceFeetX = Math.max( totalLeftDetailedDistanceFeet, totalRightDetailedDistanceFeet );
611
+
612
+ // const totalDistanceFeetY = totalCentreDistanceFeet;
613
+ // const totalDetailedDistanceFeetY = totalCentreDetailedDistanceFeet;
614
+
615
+ // const startingX = ( totalDistanceFeetX / 2 ) - ( Math.floor( maxFixturesPerRow / 2 ) * ( constantFixtureLength / mmToFeet ) );
616
+ // const startingY = ( totalDistanceFeetY / 2 ) - ( centerRow * ( constantFixtureWidth / mmToFeet ) );
617
+
618
+ // const detailedStartingX = ( totalDetailedDistanceFeetX / 2 ) - ( Math.floor( maxFixturesPerRow / 2 ) * ( constantDetailedFloorFixtureLength / mmToFeet ) );
619
+ // const detailedStartingY = ( totalDetailedDistanceFeetY / 2 ) - ( centerRow * ( constantDetailedFloorFixtureWidth / mmToFeet ) );
620
+
621
+ // let fixtureCounter = 1;
622
+
623
+ // for ( let index = 0; index < leftFixtures.length; index++ ) {
624
+ // const fixture = leftFixtures[index];
625
+
626
+ // const fixtureData = {
627
+ // 'clientId': layoutDoc.clientId,
628
+ // 'storeName': layoutDoc.storeName,
629
+ // 'storeId': layoutDoc.storeId,
630
+ // 'planoId': layoutDoc.planoId,
631
+ // 'floorId': layoutDoc._id,
632
+ // 'fixtureName': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
633
+ // 'fixtureCategory': fixture?.['Fixture Category'] ? fixture?.['Fixture Category'] : 'nil',
634
+ // 'fixtureBrandCategory': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
635
+ // 'fixtureBrandSubCategory': fixture?.['Brand - Sub Category'] ? fixture?.['Brand - Sub Category'] : 'nil',
636
+ // 'fixtureCode': fixture?.['Fixture ID'],
637
+ // 'fixtureCapacity': fixture?.['Capacity'],
638
+ // 'fixtureType': 'wall',
639
+ // 'fixtureHeight': {
640
+ // 'value': 0,
641
+ // 'unit': 'mm',
642
+ // },
643
+ // 'fixtureLength': {
644
+ // 'value': constantFixtureLength,
645
+ // 'unit': 'mm',
646
+ // },
647
+ // 'fixtureWidth': {
648
+ // 'value': constantFixtureWidth,
649
+ // 'unit': 'mm',
650
+ // },
651
+ // 'associatedElementType': 'wall',
652
+ // 'associatedElementNumber': 1,
653
+ // 'relativePosition': {
654
+ // 'x': Math.round( ( index * ( constantFixtureLength / mmToFeet ) ) ),
655
+ // 'y': 0,
656
+ // 'unit': 'ft',
657
+ // },
658
+ // 'fixtureNumber': fixtureCounter++,
659
+ // 'detailedFixtureLength': {
660
+ // 'value': constantDetailedFixtureLength,
661
+ // 'unit': 'mm',
662
+ // },
663
+ // 'detailedFixtureWidth': {
664
+ // 'value': constantDetailedFixtureWidth,
665
+ // 'unit': 'mm',
666
+ // },
667
+ // 'relativeDetailedPosition': {
668
+ // 'x': Math.round( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
669
+ // 'y': 0,
670
+ // 'unit': 'ft',
671
+ // },
672
+ // 'productResolutionLevel': 'L2',
673
+ // };
674
+
675
+ // const createdFixture = await storeFixtureService.create( fixtureData );
676
+
677
+ // // console.log( 'Fixture Data', fixtureData );
678
+
679
+
680
+ // const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
681
+
682
+ // for ( let i = 0; i < vms?.length; i++ ) {
683
+ // const vmTemplate = await planoProductService.findOne( { productId: vms[i] } );
684
+
685
+ // if ( vmTemplate ) {
686
+ // const vmData = {
687
+ // 'clientId': layoutDoc.clientId,
688
+ // 'storeName': layoutDoc.storeName,
689
+ // 'storeId': layoutDoc.storeId,
690
+ // 'planoId': layoutDoc.planoId,
691
+ // 'floorId': layoutDoc._id,
692
+ // 'type': 'vm',
693
+ // 'fixtureId': createdFixture._id,
694
+ // 'productId': vmTemplate._id,
695
+ // };
696
+
697
+ // await planoMappingService.create( vmData );
698
+ // }
699
+ // }
700
+
701
+
702
+ // const fixtureConfig = await fixtureConfigService.findOne( { fixtureCode: fixture?.['Fixture ID'] } );
703
+
704
+ // if ( fixtureConfig ) {
705
+ // let shelfIndex = 0;
706
+
707
+ // for ( const section of fixtureConfig.sections ) {
708
+ // const storeCategory = fixture.categories.find( ( cat ) => cat.Zone === section.sectionId );
709
+
710
+ // for ( let j = 0; j < section.sectionShelves; j++ ) {
711
+ // if ( shelfIndex >= fixtureConfig.shelfCount ) break;
712
+
713
+
714
+ // const shelfData = {
715
+ // 'clientId': fixtureConfig.clientId,
716
+ // 'storeName': layoutDoc.storeName,
717
+ // 'storeId': layoutDoc.storeId,
718
+ // 'planoId': layoutDoc.planoId,
719
+ // 'floorId': layoutDoc._id,
720
+ // 'fixtureId': createdFixture._id,
721
+ // 'shelfNumber': shelfIndex + 1,
722
+ // 'shelfOrder': 'LTR',
723
+ // 'shelfCapacity': fixtureConfig.productPerShelf,
724
+ // 'sectionName': storeCategory ? storeCategory?.['Allocation'] : 'Unknown',
725
+ // 'sectionZone': section.sectionId,
726
+ // };
727
+
728
+
729
+ // const createdShelf = await fixtureShelfService.create( shelfData );
730
+
731
+ // // console.log( 'Shelf Data:', createdShelf );
732
+
733
+ // shelfIndex++;
734
+ // }
735
+ // }
736
+ // }
737
+ // }
738
+
739
+ // for ( let index = 0; index < rightFixtures.length; index++ ) {
740
+ // const fixture = rightFixtures[index];
741
+
742
+ // const fixtureData = {
743
+ // 'clientId': layoutDoc.clientId,
744
+ // 'storeName': layoutDoc.storeName,
745
+ // 'storeId': layoutDoc.storeId,
746
+ // 'planoId': layoutDoc.planoId,
747
+ // 'floorId': layoutDoc._id,
748
+ // 'fixtureName': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
749
+ // 'fixtureCategory': fixture?.['Fixture Category'] ? fixture?.['Fixture Category'] : 'nil',
750
+ // 'fixtureBrandCategory': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
751
+ // 'fixtureBrandSubCategory': fixture?.['Brand - Sub Category'] ? fixture?.['Brand - Sub Category'] : 'nil',
752
+ // 'fixtureCode': fixture?.['Fixture ID'],
753
+ // 'fixtureCapacity': fixture?.['Capacity'],
754
+ // 'fixtureType': 'wall',
755
+ // 'fixtureHeight': {
756
+ // 'value': 0,
757
+ // 'unit': 'mm',
758
+ // },
759
+ // 'fixtureLength': {
760
+ // 'value': constantFixtureLength,
761
+ // 'unit': 'mm',
762
+ // },
763
+ // 'fixtureWidth': {
764
+ // 'value': constantFixtureWidth,
765
+ // 'unit': 'mm',
766
+ // },
767
+ // 'associatedElementType': 'wall',
768
+ // 'associatedElementNumber': 3,
769
+ // 'relativePosition': {
770
+ // 'x': Math.round( ( index * ( constantFixtureLength / mmToFeet ) ) ),
771
+ // 'y': Math.round( ( ( ( totalRows + 6 ) * ( constantFixtureWidth / mmToFeet ) ) - ( constantFixtureWidth / mmToFeet ) ) ),
772
+ // 'unit': 'ft',
773
+ // },
774
+ // 'fixtureNumber': fixtureCounter++,
775
+ // 'detailedFixtureLength': {
776
+ // 'value': constantDetailedFixtureLength,
777
+ // 'unit': 'mm',
778
+ // },
779
+ // 'detailedFixtureWidth': {
780
+ // 'value': constantDetailedFixtureWidth,
781
+ // 'unit': 'mm',
782
+ // },
783
+ // 'relativeDetailedPosition': {
784
+ // 'x': Math.round( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
785
+ // 'y': Math.round( ( ( ( totalRows + 4 ) * ( constantDetailedFixtureWidth / mmToFeet ) ) - ( constantDetailedFixtureWidth / mmToFeet ) ) ),
786
+ // 'unit': 'ft',
787
+ // },
788
+ // 'productResolutionLevel': 'L2',
789
+ // };
790
+
791
+ // const createdFixture = await storeFixtureService.create( fixtureData );
792
+
793
+ // // console.log( 'Fixture Data', fixtureData );
794
+
795
+ // const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
796
+
797
+ // for ( let i = 0; i < vms?.length; i++ ) {
798
+ // const vmTemplate = await planoProductService.findOne( { productId: vms[i] } );
799
+
800
+ // if ( vmTemplate ) {
801
+ // const vmData = {
802
+ // 'clientId': layoutDoc.clientId,
803
+ // 'storeName': layoutDoc.storeName,
804
+ // 'storeId': layoutDoc.storeId,
805
+ // 'planoId': layoutDoc.planoId,
806
+ // 'floorId': layoutDoc._id,
807
+ // 'type': 'vm',
808
+ // 'fixtureId': createdFixture._id,
809
+ // 'productId': vmTemplate._id,
810
+ // };
811
+
812
+ // await planoMappingService.create( vmData );
813
+ // }
814
+ // }
815
+
816
+ // const fixtureConfig = await fixtureConfigService.findOne( { fixtureCode: fixture?.['Fixture ID'] } );
817
+
818
+ // if ( fixtureConfig ) {
819
+ // let shelfIndex = 0;
820
+
821
+ // for ( const section of fixtureConfig.sections ) {
822
+ // const storeCategory = fixture.categories.find( ( cat ) => cat.Zone === section.sectionId );
823
+ // for ( let j = 0; j < section.sectionShelves; j++ ) {
824
+ // if ( shelfIndex >= fixtureConfig.shelfCount ) break;
825
+
826
+ // const shelfData = {
827
+ // 'clientId': fixtureConfig.clientId,
828
+ // 'storeName': layoutDoc.storeName,
829
+ // 'storeId': layoutDoc.storeId,
830
+ // 'planoId': layoutDoc.planoId,
831
+ // 'floorId': layoutDoc._id,
832
+ // 'fixtureId': createdFixture._id,
833
+ // 'shelfNumber': shelfIndex + 1,
834
+ // 'shelfOrder': 'LTR',
835
+ // 'shelfCapacity': fixtureConfig.productPerShelf,
836
+ // 'sectionName': storeCategory ? storeCategory?.['Allocation'] : 'Unknown',
837
+ // 'sectionZone': section.sectionId,
838
+ // };
839
+
840
+ // const createdShelf = await fixtureShelfService.create( shelfData );
841
+
842
+ // // console.log( 'Shelf Data:', createdShelf );
843
+
844
+ // shelfIndex++;
845
+ // }
846
+ // }
847
+ // }
848
+ // }
849
+
850
+ // for ( let index = 0; index < floorFixtures.length; index++ ) {
851
+ // const fixture = floorFixtures[index];
852
+
853
+ // const rowIndex = Math.floor( index / maxFixturesPerRow );
854
+ // const colIndex = index % maxFixturesPerRow;
855
+
856
+ // const xPos = Math.round( startingX + colIndex * ( constantFixtureLength / mmToFeet ) );
857
+ // const yPos = Math.round( startingY + rowIndex * ( constantFixtureWidth / mmToFeet ) );
858
+
859
+ // const detailedXPos = Math.round( detailedStartingX + colIndex * ( constantDetailedFloorFixtureLength / mmToFeet ) );
860
+ // const detailedYPos = Math.round( detailedStartingY + rowIndex * ( constantDetailedFloorFixtureWidth / mmToFeet ) );
861
+
862
+ // const fixtureData = {
863
+ // 'clientId': layoutDoc.clientId,
864
+ // 'storeName': layoutDoc.storeName,
865
+ // 'storeId': layoutDoc.storeId,
866
+ // 'planoId': layoutDoc.planoId,
867
+ // 'floorId': layoutDoc._id,
868
+ // 'fixtureName': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
869
+ // 'fixtureCategory': fixture?.['Fixture Category'] ? fixture?.['Fixture Category'] : 'nil',
870
+ // 'fixtureBrandCategory': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
871
+ // 'fixtureBrandSubCategory': fixture?.['Brand - Sub Category'] ? fixture?.['Brand - Sub Category'] : 'nil',
872
+ // 'fixtureCode': fixture?.['Fixture ID'],
873
+ // 'fixtureCapacity': fixture?.['Capacity'],
874
+ // 'fixtureType': 'floor',
875
+ // 'fixtureHeight': {
876
+ // 'value': 0,
877
+ // 'unit': 'mm',
878
+ // },
879
+ // 'fixtureLength': {
880
+ // 'value': constantFixtureLength,
881
+ // 'unit': 'mm',
882
+ // },
883
+ // 'fixtureWidth': {
884
+ // 'value': constantFixtureWidth,
885
+ // 'unit': 'mm',
886
+ // },
887
+ // 'relativePosition': {
888
+ // 'x': xPos,
889
+ // 'y': yPos,
890
+ // 'unit': 'ft',
891
+ // },
892
+ // 'fixtureNumber': fixtureCounter++,
893
+ // 'detailedFixtureLength': {
894
+ // 'value': constantDetailedFloorFixtureLength,
895
+ // 'unit': 'mm',
896
+ // },
897
+ // 'detailedFixtureWidth': {
898
+ // 'value': constantDetailedFloorFixtureWidth,
899
+ // 'unit': 'mm',
900
+ // },
901
+ // 'relativeDetailedPosition': {
902
+ // 'x': detailedXPos,
903
+ // 'y': detailedYPos,
904
+ // 'unit': 'ft',
905
+ // },
906
+ // 'productResolutionLevel': 'L2',
907
+ // };
908
+
909
+ // const createdFixture = await storeFixtureService.create( fixtureData );
910
+ // // console.log( 'Fixture Data', fixtureData );
911
+
912
+ // const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
913
+
914
+ // for ( let i = 0; i < vms?.length; i++ ) {
915
+ // const vmTemplate = await planoProductService.findOne( { productId: vms[i] } );
916
+
917
+ // if ( vmTemplate ) {
918
+ // const vmData = {
919
+ // 'clientId': layoutDoc.clientId,
920
+ // 'storeName': layoutDoc.storeName,
921
+ // 'storeId': layoutDoc.storeId,
922
+ // 'planoId': layoutDoc.planoId,
923
+ // 'floorId': layoutDoc._id,
924
+ // 'type': 'vm',
925
+ // 'fixtureId': createdFixture._id,
926
+ // 'productId': vmTemplate._id,
927
+ // };
928
+
929
+ // await planoMappingService.create( vmData );
930
+ // }
931
+ // }
932
+
933
+
934
+ // const fixtureConfig = await fixtureConfigService.findOne( { fixtureCode: fixture?.['Fixture ID'] } );
935
+
936
+ // if ( fixtureConfig ) {
937
+ // let shelfIndex = 0;
938
+
939
+ // for ( const section of fixtureConfig.sections ) {
940
+ // const storeCategory = fixture.categories.find( ( cat ) => cat.Zone === section.sectionId );
941
+ // for ( let j = 0; j < section.sectionShelves; j++ ) {
942
+ // if ( shelfIndex >= fixtureConfig.shelfCount ) break;
943
+
944
+ // const shelfData = {
945
+ // 'clientId': fixtureConfig.clientId,
946
+ // 'storeName': layoutDoc.storeName,
947
+ // 'storeId': layoutDoc.storeId,
948
+ // 'planoId': layoutDoc.planoId,
949
+ // 'floorId': layoutDoc._id,
950
+ // 'fixtureId': createdFixture._id,
951
+ // 'shelfNumber': shelfIndex + 1,
952
+ // 'shelfOrder': 'LTR',
953
+ // 'shelfCapacity': fixtureConfig.productPerShelf,
954
+ // 'sectionName': storeCategory ? storeCategory?.['Allocation'] : 'Unknown',
955
+ // 'sectionZone': section.sectionId,
956
+ // };
957
+
958
+ // const createdShelf = await fixtureShelfService.create( shelfData );
959
+
960
+ // // console.log( 'Shelf Data:', createdShelf );
961
+
962
+ // shelfIndex++;
963
+ // }
964
+ // }
965
+ // }
966
+ // }
967
+ // }
968
+
969
+
970
+ // return res.sendSuccess( 'Updated successfully' );
971
+ // } catch ( e ) {
972
+ // logger.error( { functionName: 'createFixturesShelves', error: e } );
973
+ // return res.sendError( e.message || 'Internal Server Error', 500 );
974
+ // }
975
+ // }
976
+
323
977
  export async function createFixturesShelves( req, res ) {
324
978
  try {
325
979
  if ( !req.files.file ) {
@@ -373,57 +1027,67 @@ export async function createFixturesShelves( req, res ) {
373
1027
 
374
1028
  const constantFixtureLength = 1220;
375
1029
  const constantDetailedFixtureLength = 1220;
376
- const constantDetailedFloorFixtureLength = 1524;
377
1030
 
378
1031
 
379
1032
  const constantFixtureWidth = 610;
380
1033
  const constantDetailedFixtureWidth = 1524;
381
- const constantDetailedFloorFixtureWidth = 1220;
382
1034
 
383
1035
 
384
1036
  const mmToFeet = 305;
385
1037
  const layoutList = await storeBuilderService.find( {} );
386
1038
 
1039
+ function roundToTwo( num ) {
1040
+ return Math.round( num * 100 ) / 100;
1041
+ }
1042
+
387
1043
  for ( let i = 0; i < layoutList.length; i++ ) {
388
1044
  const layout = layoutList[i];
389
1045
 
390
1046
  const layoutDoc = layout.toObject();
391
1047
 
392
1048
  const leftFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Left' );
393
- const leftWallCount = leftFixtures.length;
394
-
395
1049
  const rightFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Right' );
396
- const rightWallCount = rightFixtures.length;
1050
+ const floorFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Centre' );
1051
+ const backFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Back' );
397
1052
 
1053
+ const leftXDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
1054
+ const leftXDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
398
1055
 
399
- const floorFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Centre' );
400
- const floorFixtureCount = floorFixtures.length;
1056
+ const leftYDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantFixtureWidth / mmToFeet ) ) ) : 0;
1057
+ const leftYDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantDetailedFixtureWidth / mmToFeet ) ) ) : 0;
1058
+
1059
+ const rightXDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
1060
+ const rightXDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
401
1061
 
402
- const maxFixturesPerRow = floorFixtureCount > 4 ? 3 : 2;
1062
+ const rightYDistanceFeet = rightFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
1063
+ const rightYDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( constantDetailedFixtureWidth / mmToFeet ) ): 0;
403
1064
 
404
- const totalRows = Math.ceil( floorFixtureCount / maxFixturesPerRow );
405
- const centerRow = Math.floor( totalRows / 2 );
1065
+ const maxFixturesPerRow = floorFixtures.length > 4 ? 3 : 2;
1066
+ const totalRows = Math.ceil( floorFixtures.length / maxFixturesPerRow );
1067
+ const floorXDistanceFeet = floorFixtures.length ? roundToTwo( ( maxFixturesPerRow * ( constantFixtureLength / mmToFeet ) ) ) : 0;
1068
+ const floorXDetailedDistanceFeet = floorFixtures.length ? roundToTwo( ( maxFixturesPerRow * ( constantDetailedFixtureLength / mmToFeet ) ) ): 0;
406
1069
 
407
- const totalLeftDistanceFeet = Math.round( ( leftWallCount * ( constantFixtureLength/mmToFeet ) ) );
408
- const totalLeftDetailedDistanceFeet = Math.round( ( leftWallCount * ( constantDetailedFixtureLength/mmToFeet ) ) );
1070
+ const floorYDistanceFeet = floorFixtures.length ? roundToTwo( ( totalRows * ( constantFixtureWidth/ mmToFeet ) ) ): 0;
1071
+ const floorYDetailedDistanceFeet = floorFixtures.length ? roundToTwo( totalRows * ( constantDetailedFixtureWidth/mmToFeet ) ): 0;
409
1072
 
410
- const totalRightDistanceFeet = Math.round( ( rightWallCount * ( constantFixtureLength/mmToFeet ) ) );
411
- const totalRightDetailedDistanceFeet = Math.round( ( rightWallCount * ( constantDetailedFixtureLength/mmToFeet ) ) );
1073
+ const backXDistanceFeet = backFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
1074
+ const backXDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( constantDetailedFixtureLength / mmToFeet ) ) : 0;
412
1075
 
413
- const totalCentreDistanceFeet = Math.round( ( ( totalRows + 6 ) * ( constantFixtureWidth/mmToFeet ) ) );
414
- const totalCentreDetailedDistanceFeet = Math.round( ( ( totalRows + 4 ) * ( constantDetailedFixtureWidth/mmToFeet ) ) );
1076
+ const backYDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantFixtureLength / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantFixtureWidth )/mmToFeet ) ) ) : 0;
1077
+ const backYDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantDetailedFixtureWidth / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth )/mmToFeet ) ) ): 0;
415
1078
 
416
- const totalDistanceFeetX = Math.max( totalLeftDistanceFeet, totalRightDistanceFeet );
417
- const totalDetailedDistanceFeetX = Math.max( totalLeftDetailedDistanceFeet, totalRightDetailedDistanceFeet );
1079
+ const maxXDistance = Math.max( leftXDistanceFeet, rightXDistanceFeet, floorXDistanceFeet );
1080
+ const maxXDetailedDistance = Math.max( leftXDetailedDistanceFeet, rightXDetailedDistanceFeet, floorXDetailedDistanceFeet );
418
1081
 
419
- const totalDistanceFeetY = totalCentreDistanceFeet;
420
- const totalDetailedDistanceFeetY = totalCentreDetailedDistanceFeet;
1082
+ const maxYDistance = Math.max( floorYDistanceFeet, backYDistanceFeet );
1083
+ const maxYDetailedDistance = Math.max( floorYDetailedDistanceFeet, backYDetailedDistanceFeet );
421
1084
 
422
- const startingX = ( totalDistanceFeetX / 2 ) - ( Math.floor( maxFixturesPerRow / 2 ) * ( constantFixtureLength / mmToFeet ) );
423
- const startingY = ( totalDistanceFeetY / 2 ) - ( centerRow * ( constantFixtureWidth / mmToFeet ) );
1085
+ const finalXDistance = maxXDistance;
1086
+ const finalXDetailedDistance = maxXDetailedDistance;
1087
+
1088
+ const finalYDistance = maxYDistance < ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) ? ( ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) + ( ( 2 * constantFixtureWidth )/mmToFeet ) ) : maxYDistance;
1089
+ const finalYDetailedDistance = maxYDetailedDistance < ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) ? ( ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureWidth )/mmToFeet ) ) : maxYDetailedDistance;
424
1090
 
425
- const detailedStartingX = ( totalDetailedDistanceFeetX / 2 ) - ( Math.floor( maxFixturesPerRow / 2 ) * ( constantDetailedFloorFixtureLength / mmToFeet ) );
426
- const detailedStartingY = ( totalDetailedDistanceFeetY / 2 ) - ( centerRow * ( constantDetailedFloorFixtureWidth / mmToFeet ) );
427
1091
 
428
1092
  let fixtureCounter = 1;
429
1093
 
@@ -458,7 +1122,7 @@ export async function createFixturesShelves( req, res ) {
458
1122
  'associatedElementType': 'wall',
459
1123
  'associatedElementNumber': 1,
460
1124
  'relativePosition': {
461
- 'x': Math.round( ( index * ( constantFixtureLength/mmToFeet ) ) ),
1125
+ 'x': roundToTwo( ( index * ( constantFixtureLength / mmToFeet ) ) ),
462
1126
  'y': 0,
463
1127
  'unit': 'ft',
464
1128
  },
@@ -472,7 +1136,7 @@ export async function createFixturesShelves( req, res ) {
472
1136
  'unit': 'mm',
473
1137
  },
474
1138
  'relativeDetailedPosition': {
475
- 'x': Math.round( ( index * ( constantDetailedFixtureLength/mmToFeet ) ) ),
1139
+ 'x': roundToTwo( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
476
1140
  'y': 0,
477
1141
  'unit': 'ft',
478
1142
  },
@@ -543,6 +1207,117 @@ export async function createFixturesShelves( req, res ) {
543
1207
  }
544
1208
  }
545
1209
 
1210
+ for ( let index = 0; index < backFixtures.length; index++ ) {
1211
+ const fixture = rightFixtures[index];
1212
+
1213
+ const fixtureData = {
1214
+ 'clientId': layoutDoc.clientId,
1215
+ 'storeName': layoutDoc.storeName,
1216
+ 'storeId': layoutDoc.storeId,
1217
+ 'planoId': layoutDoc.planoId,
1218
+ 'floorId': layoutDoc._id,
1219
+ 'fixtureName': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
1220
+ 'fixtureCategory': fixture?.['Fixture Category'] ? fixture?.['Fixture Category'] : 'nil',
1221
+ 'fixtureBrandCategory': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
1222
+ 'fixtureBrandSubCategory': fixture?.['Brand - Sub Category'] ? fixture?.['Brand - Sub Category'] : 'nil',
1223
+ 'fixtureCode': fixture?.['Fixture ID'],
1224
+ 'fixtureCapacity': fixture?.['Capacity'],
1225
+ 'fixtureType': 'wall',
1226
+ 'fixtureHeight': {
1227
+ 'value': 0,
1228
+ 'unit': 'mm',
1229
+ },
1230
+ 'fixtureLength': {
1231
+ 'value': constantFixtureWidth,
1232
+ 'unit': 'mm',
1233
+ },
1234
+ 'fixtureWidth': {
1235
+ 'value': constantFixtureLength,
1236
+ 'unit': 'mm',
1237
+ },
1238
+ 'associatedElementType': 'wall',
1239
+ 'associatedElementNumber': 2,
1240
+ 'relativePosition': {
1241
+ 'x': roundToTwo( ( finalXDistance - ( constantFixtureWidth/mmToFeet ) ) ),
1242
+ 'y': roundToTwo( ( ( index * ( ( constantFixtureLength/mmToFeet ) ) ) + ( ( leftFixtures.length ? 1 : 0 ) * constantFixtureWidth/mmToFeet ) ) ),
1243
+ 'unit': 'ft',
1244
+ },
1245
+ 'fixtureNumber': fixtureCounter++,
1246
+ 'detailedFixtureLength': {
1247
+ 'value': constantDetailedFixtureLength,
1248
+ 'unit': 'mm',
1249
+ },
1250
+ 'detailedFixtureWidth': {
1251
+ 'value': constantDetailedFixtureWidth,
1252
+ 'unit': 'mm',
1253
+ },
1254
+ 'relativeDetailedPosition': {
1255
+ 'x': roundToTwo( ( finalXDistance - ( constantDetailedFixtureLength/mmToFeet ) ) ),
1256
+ 'y': roundToTwo( ( ( index * ( ( constantDetailedFixtureWidth/mmToFeet ) ) ) + ( ( leftFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth/mmToFeet ) ) ),
1257
+ 'unit': 'ft',
1258
+ },
1259
+ 'productResolutionLevel': 'L2',
1260
+ };
1261
+
1262
+ const createdFixture = await storeFixtureService.create( fixtureData );
1263
+
1264
+ // console.log( 'Fixture Data', fixtureData );
1265
+
1266
+ const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
1267
+
1268
+ for ( let i = 0; i < vms?.length; i++ ) {
1269
+ const vmTemplate = await planoProductService.findOne( { productId: vms[i] } );
1270
+
1271
+ if ( vmTemplate ) {
1272
+ const vmData = {
1273
+ 'clientId': layoutDoc.clientId,
1274
+ 'storeName': layoutDoc.storeName,
1275
+ 'storeId': layoutDoc.storeId,
1276
+ 'planoId': layoutDoc.planoId,
1277
+ 'floorId': layoutDoc._id,
1278
+ 'type': 'vm',
1279
+ 'fixtureId': createdFixture._id,
1280
+ 'productId': vmTemplate._id,
1281
+ };
1282
+
1283
+ await planoMappingService.create( vmData );
1284
+ }
1285
+ }
1286
+
1287
+ const fixtureConfig = await fixtureConfigService.findOne( { fixtureCode: fixture?.['Fixture ID'] } );
1288
+
1289
+ if ( fixtureConfig ) {
1290
+ let shelfIndex = 0;
1291
+
1292
+ for ( const section of fixtureConfig.sections ) {
1293
+ const storeCategory = fixture.categories.find( ( cat ) => cat.Zone === section.sectionId );
1294
+ for ( let j = 0; j < section.sectionShelves; j++ ) {
1295
+ if ( shelfIndex >= fixtureConfig.shelfCount ) break;
1296
+
1297
+ const shelfData = {
1298
+ 'clientId': fixtureConfig.clientId,
1299
+ 'storeName': layoutDoc.storeName,
1300
+ 'storeId': layoutDoc.storeId,
1301
+ 'planoId': layoutDoc.planoId,
1302
+ 'floorId': layoutDoc._id,
1303
+ 'fixtureId': createdFixture._id,
1304
+ 'shelfNumber': shelfIndex + 1,
1305
+ 'shelfOrder': 'LTR',
1306
+ 'shelfCapacity': fixtureConfig.productPerShelf,
1307
+ 'sectionName': storeCategory ? storeCategory?.['Allocation'] : 'Unknown',
1308
+ 'sectionZone': section.sectionId,
1309
+ };
1310
+
1311
+ const createdShelf = await fixtureShelfService.create( shelfData );
1312
+
1313
+ // console.log( 'Shelf Data:', createdShelf );
1314
+
1315
+ shelfIndex++;
1316
+ }
1317
+ }
1318
+ }
1319
+ }
1320
+
546
1321
  for ( let index = 0; index < rightFixtures.length; index++ ) {
547
1322
  const fixture = rightFixtures[index];
548
1323
 
@@ -574,8 +1349,8 @@ export async function createFixturesShelves( req, res ) {
574
1349
  'associatedElementType': 'wall',
575
1350
  'associatedElementNumber': 3,
576
1351
  'relativePosition': {
577
- 'x': Math.round( ( index * ( constantFixtureLength/mmToFeet ) ) ),
578
- 'y': Math.round( ( ( ( totalRows + 6 ) * ( constantFixtureWidth/mmToFeet ) ) - ( constantFixtureWidth/mmToFeet ) ) ),
1352
+ 'x': roundToTwo( ( index * ( constantFixtureLength / mmToFeet ) ) ),
1353
+ 'y': roundToTwo( ( finalYDistance - ( constantFixtureWidth / mmToFeet ) ) ),
579
1354
  'unit': 'ft',
580
1355
  },
581
1356
  'fixtureNumber': fixtureCounter++,
@@ -588,8 +1363,8 @@ export async function createFixturesShelves( req, res ) {
588
1363
  'unit': 'mm',
589
1364
  },
590
1365
  'relativeDetailedPosition': {
591
- 'x': Math.round( ( index * ( constantDetailedFixtureLength/mmToFeet ) ) ),
592
- 'y': Math.round( ( ( ( totalRows + 4 ) * ( constantDetailedFixtureWidth/mmToFeet ) ) - ( constantDetailedFixtureWidth/mmToFeet ) ) ),
1366
+ 'x': roundToTwo( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
1367
+ 'y': roundToTwo( ( finalYDetailedDistance - ( constantDetailedFixtureWidth / mmToFeet ) ) ),
593
1368
  'unit': 'ft',
594
1369
  },
595
1370
  'productResolutionLevel': 'L2',
@@ -657,14 +1432,22 @@ export async function createFixturesShelves( req, res ) {
657
1432
  for ( let index = 0; index < floorFixtures.length; index++ ) {
658
1433
  const fixture = floorFixtures[index];
659
1434
 
1435
+ const centerRow = Math.floor( totalRows / 2 );
1436
+
1437
+ const startingX = ( finalXDistance / 2 ) - ( Math.floor( maxFixturesPerRow / 2 ) * ( constantFixtureLength / mmToFeet ) );
1438
+ const detailedStartingX = ( finalXDetailedDistance / 2 ) - ( Math.floor( maxFixturesPerRow / 2 ) * ( constantDetailedFixtureLength / mmToFeet ) );
1439
+
1440
+ const startingY = ( finalYDistance / 2 ) - ( centerRow * ( constantFixtureWidth / mmToFeet ) );
1441
+ const detailedStartingY = ( finalYDetailedDistance / 2 ) - ( centerRow * ( constantDetailedFixtureWidth / mmToFeet ) );
1442
+
660
1443
  const rowIndex = Math.floor( index / maxFixturesPerRow );
661
1444
  const colIndex = index % maxFixturesPerRow;
662
1445
 
663
- const xPos = Math.round( startingX + colIndex * ( constantFixtureLength / mmToFeet ) );
664
- const yPos = Math.round( startingY + rowIndex * ( constantFixtureWidth / mmToFeet ) );
1446
+ const xPos = roundToTwo( ( startingX + colIndex * ( constantFixtureLength / mmToFeet ) ) );
1447
+ const yPos = roundToTwo( ( startingY + rowIndex * ( constantFixtureWidth / mmToFeet ) ) );
665
1448
 
666
- const detailedXPos = Math.round( detailedStartingX + colIndex * ( constantDetailedFloorFixtureLength / mmToFeet ) );
667
- const detailedYPos = Math.round( detailedStartingY + rowIndex * ( constantDetailedFloorFixtureWidth / mmToFeet ) );
1449
+ const detailedXPos = roundToTwo( ( detailedStartingX + colIndex * ( constantDetailedFixtureLength / mmToFeet ) ) );
1450
+ const detailedYPos = roundToTwo( ( detailedStartingY + rowIndex * ( constantDetailedFixtureWidth / mmToFeet ) ) );
668
1451
 
669
1452
  const fixtureData = {
670
1453
  'clientId': layoutDoc.clientId,
@@ -698,11 +1481,11 @@ export async function createFixturesShelves( req, res ) {
698
1481
  },
699
1482
  'fixtureNumber': fixtureCounter++,
700
1483
  'detailedFixtureLength': {
701
- 'value': constantDetailedFloorFixtureLength,
1484
+ 'value': constantDetailedFixtureLength,
702
1485
  'unit': 'mm',
703
1486
  },
704
1487
  'detailedFixtureWidth': {
705
- 'value': constantDetailedFloorFixtureWidth,
1488
+ 'value': constantDetailedFixtureWidth,
706
1489
  'unit': 'mm',
707
1490
  },
708
1491
  'relativeDetailedPosition': {