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

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.
@@ -154,172 +154,6 @@ 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
-
323
157
  export async function createFloors( req, res ) {
324
158
  try {
325
159
  if ( !req.files.file ) {
@@ -424,12 +258,12 @@ export async function createFloors( req, res ) {
424
258
  const maxYDistance = Math.max( floorYDistanceFeet, backYDistanceFeet );
425
259
  const maxYDetailedDistance = Math.max( floorYDetailedDistanceFeet, backYDetailedDistanceFeet );
426
260
 
427
- const finalXDistance = maxXDistance;
428
- const finalXDetailedDistance = maxXDetailedDistance;
429
261
 
262
+ const finalXDistance = maxXDistance < ( backXDistanceFeet + floorXDistanceFeet )? ( ( backXDistanceFeet + floorXDistanceFeet ) + ( ( 2 * constantFixtureLength )/mmToFeet ) ) : maxXDistance;
263
+ const finalXDetailedDistance = maxXDetailedDistance < ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet )? ( ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureLength )/mmToFeet ) ) : maxXDetailedDistance;
430
264
 
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;
265
+ const finalYDistance = maxYDistance < ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) ? ( ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) + ( ( 2 * constantFixtureWidth )/mmToFeet ) ) : ( maxYDistance + ( ( constantFixtureWidth )/mmToFeet ) );
266
+ const finalYDetailedDistance = maxYDetailedDistance < ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) ? ( ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureWidth )/mmToFeet ) ) : ( maxYDetailedDistance + ( ( constantDetailedFixtureWidth )/mmToFeet ) );
433
267
 
434
268
  const floorInsertData = {
435
269
  storeName: planoDoc.storeName,
@@ -513,466 +347,6 @@ export async function createFloors( req, res ) {
513
347
  }
514
348
  }
515
349
 
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
350
 
977
351
  export async function createFixturesShelves( req, res ) {
978
352
  try {
@@ -1082,11 +456,11 @@ export async function createFixturesShelves( req, res ) {
1082
456
  const maxYDistance = Math.max( floorYDistanceFeet, backYDistanceFeet );
1083
457
  const maxYDetailedDistance = Math.max( floorYDetailedDistanceFeet, backYDetailedDistanceFeet );
1084
458
 
1085
- const finalXDistance = maxXDistance;
1086
- const finalXDetailedDistance = maxXDetailedDistance;
459
+ const finalXDistance = maxXDistance < ( backXDistanceFeet + floorXDistanceFeet )? ( ( backXDistanceFeet + floorXDistanceFeet ) + ( ( 2 * constantFixtureLength )/mmToFeet ) ) : maxXDistance;
460
+ const finalXDetailedDistance = maxXDetailedDistance < ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet )? ( ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureLength )/mmToFeet ) ) : maxXDistance;
1087
461
 
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;
462
+ const finalYDistance = maxYDistance < ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) ? ( ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) + ( ( 2 * constantFixtureWidth )/mmToFeet ) ) : ( maxYDistance + ( ( constantFixtureWidth )/mmToFeet ) );
463
+ const finalYDetailedDistance = maxYDetailedDistance < ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) ? ( ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureWidth )/mmToFeet ) ) : ( maxYDetailedDistance + ( ( constantDetailedFixtureWidth )/mmToFeet ) );
1090
464
 
1091
465
 
1092
466
  let fixtureCounter = 1;
@@ -1434,8 +808,8 @@ export async function createFixturesShelves( req, res ) {
1434
808
 
1435
809
  const centerRow = Math.floor( totalRows / 2 );
1436
810
 
1437
- const startingX = ( finalXDistance / 2 ) - ( Math.floor( maxFixturesPerRow / 2 ) * ( constantFixtureLength / mmToFeet ) );
1438
- const detailedStartingX = ( finalXDetailedDistance / 2 ) - ( Math.floor( maxFixturesPerRow / 2 ) * ( constantDetailedFixtureLength / mmToFeet ) );
811
+ const startingX =roundToTwo( ( ( finalXDistance / 2 ) - ( ( maxFixturesPerRow / 2 ) * ( constantFixtureLength / mmToFeet ) ) ) );
812
+ const detailedStartingX = roundToTwo( ( ( finalXDetailedDistance / 2 ) - ( ( maxFixturesPerRow / 2 ) * ( constantDetailedFixtureLength / mmToFeet ) ) ) );
1439
813
 
1440
814
  const startingY = ( finalYDistance / 2 ) - ( centerRow * ( constantFixtureWidth / mmToFeet ) );
1441
815
  const detailedStartingY = ( finalYDetailedDistance / 2 ) - ( centerRow * ( constantDetailedFixtureWidth / mmToFeet ) );
@@ -1564,6 +938,597 @@ export async function createFixturesShelves( req, res ) {
1564
938
  }
1565
939
  }
1566
940
 
941
+ export async function updateFixturesShelves( req, res ) {
942
+ try {
943
+ if ( !req.files.file ) {
944
+ return res.sendError( 'Invalid or missing Excel file', 400 );
945
+ }
946
+
947
+ const workbook = xlsx.read( req.files.file.data, { type: 'buffer' } );
948
+ const sheetName = 'Layout,Fixture&VM';
949
+ if ( !workbook.Sheets[sheetName] ) {
950
+ return res.sendError( `Sheet "${sheetName}" not found`, 400 );
951
+ }
952
+
953
+ const rawData = xlsx.utils.sheet_to_json( workbook.Sheets[sheetName] );
954
+
955
+ const groupedData = {};
956
+
957
+ rawData.forEach( ( item ) => {
958
+ const fixtureId = item['Store Fixture ID'];
959
+
960
+ if ( !groupedData[fixtureId] ) {
961
+ groupedData[fixtureId] = {
962
+ 'Store ID': item['Store ID'],
963
+ 'Store Fixture ID': fixtureId,
964
+ 'Fixture ID': item['Fixture ID ( For ref only)'],
965
+ 'Fixture Category': item['Fixture Category'],
966
+ 'Fixture Size (feet)': item['Fixture Size (feet)'],
967
+ 'Fixture Count': item['Fixture Count'],
968
+ 'Effective Fixture Count': item['Effective Fixture Count'],
969
+ 'Capacity': item['Capacity'],
970
+ 'Store Fixture Locator': item['Store Fixture Locator'],
971
+ 'Wall': item['Wall'],
972
+ 'Brand-Category': item['Brand-Category'],
973
+ 'Brand - Sub Category': item['Brand - Sub Category'],
974
+ 'VM Template ID': item['VM Template ID '],
975
+ 'categories': [],
976
+ 'fixtureNumber': item['fixtureNumber'],
977
+ };
978
+ }
979
+
980
+ const categories = groupedData[fixtureId]['categories'];
981
+ const existingCategory = categories.find( ( cat ) => cat['Zone'] === item['Section Allocation '] );
982
+
983
+ if ( !existingCategory ) {
984
+ categories.push( {
985
+ 'Allocation': item['Shelf Allocation'],
986
+ 'Zone': item['Section Allocation '],
987
+ } );
988
+ }
989
+ } );
990
+
991
+ const raw = Object.values( groupedData );
992
+
993
+ const constantFixtureLength = 1220;
994
+ const constantDetailedFixtureLength = 1220;
995
+
996
+
997
+ const constantFixtureWidth = 610;
998
+ const constantDetailedFixtureWidth = 1524;
999
+
1000
+
1001
+ const mmToFeet = 305;
1002
+ const layoutList = await storeBuilderService.find( {} );
1003
+
1004
+ function roundToTwo( num ) {
1005
+ return Math.round( num * 100 ) / 100;
1006
+ }
1007
+
1008
+ for ( let i = 0; i < layoutList.length; i++ ) {
1009
+ const layout = layoutList[i];
1010
+
1011
+ const layoutDoc = layout.toObject();
1012
+
1013
+ const leftFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Left' );
1014
+ const rightFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Right' );
1015
+ const floorFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Centre' );
1016
+ const backFixtures = raw.filter( ( entry ) => entry['Store ID'] === layoutDoc.storeName && entry.Wall === 'Back' );
1017
+
1018
+ const leftXDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
1019
+ const leftXDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
1020
+
1021
+ const leftYDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantFixtureWidth / mmToFeet ) ) ) : 0;
1022
+ const leftYDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantDetailedFixtureWidth / mmToFeet ) ) ) : 0;
1023
+
1024
+ const rightXDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
1025
+ const rightXDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
1026
+
1027
+ const rightYDistanceFeet = rightFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
1028
+ const rightYDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( constantDetailedFixtureWidth / mmToFeet ) ): 0;
1029
+
1030
+ const maxFixturesPerRow = floorFixtures.length > 4 ? 3 : 2;
1031
+ const totalRows = Math.ceil( floorFixtures.length / maxFixturesPerRow );
1032
+ const floorXDistanceFeet = floorFixtures.length ? roundToTwo( ( maxFixturesPerRow * ( constantFixtureLength / mmToFeet ) ) ) : 0;
1033
+ const floorXDetailedDistanceFeet = floorFixtures.length ? roundToTwo( ( maxFixturesPerRow * ( constantDetailedFixtureLength / mmToFeet ) ) ): 0;
1034
+
1035
+ const floorYDistanceFeet = floorFixtures.length ? roundToTwo( ( totalRows * ( constantFixtureWidth/ mmToFeet ) ) ): 0;
1036
+ const floorYDetailedDistanceFeet = floorFixtures.length ? roundToTwo( totalRows * ( constantDetailedFixtureWidth/mmToFeet ) ): 0;
1037
+
1038
+ const backXDistanceFeet = backFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
1039
+ const backXDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( constantDetailedFixtureLength / mmToFeet ) ) : 0;
1040
+
1041
+ const backYDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantFixtureLength / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantFixtureWidth )/mmToFeet ) ) ) : 0;
1042
+ const backYDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantDetailedFixtureWidth / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth )/mmToFeet ) ) ): 0;
1043
+
1044
+ const maxXDistance = Math.max( leftXDistanceFeet, rightXDistanceFeet, floorXDistanceFeet );
1045
+ const maxXDetailedDistance = Math.max( leftXDetailedDistanceFeet, rightXDetailedDistanceFeet, floorXDetailedDistanceFeet );
1046
+
1047
+ const maxYDistance = Math.max( floorYDistanceFeet, backYDistanceFeet );
1048
+ const maxYDetailedDistance = Math.max( floorYDetailedDistanceFeet, backYDetailedDistanceFeet );
1049
+
1050
+ const finalXDistance = maxXDistance < ( backXDistanceFeet + floorXDistanceFeet )? ( ( backXDistanceFeet + floorXDistanceFeet ) + ( ( 2 * constantFixtureLength )/mmToFeet ) ) : maxXDistance;
1051
+ const finalXDetailedDistance = maxXDetailedDistance < ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet )? ( ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureLength )/mmToFeet ) ) : maxXDistance;
1052
+
1053
+ const finalYDistance = maxYDistance < ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) ? ( ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) + ( ( 2 * constantFixtureWidth )/mmToFeet ) ) : ( maxYDistance + ( ( constantFixtureWidth )/mmToFeet ) );
1054
+ const finalYDetailedDistance = maxYDetailedDistance < ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) ? ( ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureWidth )/mmToFeet ) ) : ( maxYDetailedDistance + ( ( constantDetailedFixtureWidth )/mmToFeet ) );
1055
+
1056
+
1057
+ let fixtureCounter = 1;
1058
+
1059
+ for ( let index = 0; index < leftFixtures.length; index++ ) {
1060
+ const fixture = leftFixtures[index];
1061
+
1062
+ const fixtureData = {
1063
+ 'clientId': layoutDoc.clientId,
1064
+ 'storeName': layoutDoc.storeName,
1065
+ 'storeId': layoutDoc.storeId,
1066
+ 'planoId': layoutDoc.planoId,
1067
+ 'floorId': layoutDoc._id,
1068
+ 'fixtureName': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
1069
+ 'fixtureCategory': fixture?.['Fixture Category'] ? fixture?.['Fixture Category'] : 'nil',
1070
+ 'fixtureBrandCategory': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
1071
+ 'fixtureBrandSubCategory': fixture?.['Brand - Sub Category'] ? fixture?.['Brand - Sub Category'] : 'nil',
1072
+ 'fixtureCode': fixture?.['Fixture ID'],
1073
+ 'fixtureCapacity': fixture?.['Capacity'],
1074
+ 'fixtureType': 'wall',
1075
+ 'fixtureHeight': {
1076
+ 'value': 0,
1077
+ 'unit': 'mm',
1078
+ },
1079
+ 'fixtureLength': {
1080
+ 'value': constantFixtureLength,
1081
+ 'unit': 'mm',
1082
+ },
1083
+ 'fixtureWidth': {
1084
+ 'value': constantFixtureWidth,
1085
+ 'unit': 'mm',
1086
+ },
1087
+ 'associatedElementType': 'wall',
1088
+ 'associatedElementNumber': 1,
1089
+ 'relativePosition': {
1090
+ 'x': roundToTwo( ( index * ( constantFixtureLength / mmToFeet ) ) ),
1091
+ 'y': 0,
1092
+ 'unit': 'ft',
1093
+ },
1094
+ 'fixtureNumber': fixtureCounter++,
1095
+ 'detailedFixtureLength': {
1096
+ 'value': constantDetailedFixtureLength,
1097
+ 'unit': 'mm',
1098
+ },
1099
+ 'detailedFixtureWidth': {
1100
+ 'value': constantDetailedFixtureWidth,
1101
+ 'unit': 'mm',
1102
+ },
1103
+ 'relativeDetailedPosition': {
1104
+ 'x': roundToTwo( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
1105
+ 'y': 0,
1106
+ 'unit': 'ft',
1107
+ },
1108
+ 'productResolutionLevel': 'L2',
1109
+ };
1110
+
1111
+ const createdFixture = await storeFixtureService.findOneAndUpdate2( { storeName: layoutDoc.storeName, fixtureNumber: fixture?.['fixtureNumber'] }, { fixtureCode: fixture?.['Fixture ID'] } );
1112
+
1113
+ // console.log( 'Fixture Data', fixtureData );
1114
+
1115
+
1116
+ const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
1117
+
1118
+ for ( let i = 0; i < vms?.length; i++ ) {
1119
+ const vmTemplate = await planoProductService.findOne( { productId: vms[i] } );
1120
+
1121
+ if ( vmTemplate ) {
1122
+ const vmData = {
1123
+ 'clientId': layoutDoc.clientId,
1124
+ 'storeName': layoutDoc.storeName,
1125
+ 'storeId': layoutDoc.storeId,
1126
+ 'planoId': layoutDoc.planoId,
1127
+ 'floorId': layoutDoc._id,
1128
+ 'type': 'vm',
1129
+ 'fixtureId': createdFixture._id,
1130
+ 'productId': vmTemplate._id,
1131
+ };
1132
+
1133
+ await planoMappingService.create( vmData );
1134
+ }
1135
+ }
1136
+
1137
+
1138
+ const fixtureConfig = await fixtureConfigService.findOne( { fixtureCode: fixture?.['Fixture ID'] } );
1139
+
1140
+ if ( fixtureConfig ) {
1141
+ let shelfIndex = 0;
1142
+
1143
+ for ( const section of fixtureConfig.sections ) {
1144
+ const storeCategory = fixture.categories.find( ( cat ) => cat.Zone === section.sectionId );
1145
+
1146
+ for ( let j = 0; j < section.sectionShelves; j++ ) {
1147
+ if ( shelfIndex >= fixtureConfig.shelfCount ) break;
1148
+
1149
+
1150
+ const shelfData = {
1151
+ 'clientId': fixtureConfig.clientId,
1152
+ 'storeName': layoutDoc.storeName,
1153
+ 'storeId': layoutDoc.storeId,
1154
+ 'planoId': layoutDoc.planoId,
1155
+ 'floorId': layoutDoc._id,
1156
+ 'fixtureId': createdFixture._id,
1157
+ 'shelfNumber': shelfIndex + 1,
1158
+ 'shelfOrder': 'LTR',
1159
+ 'shelfCapacity': fixtureConfig.productPerShelf,
1160
+ 'sectionName': storeCategory ? storeCategory?.['Allocation'] : 'Unknown',
1161
+ 'sectionZone': section.sectionId,
1162
+ };
1163
+
1164
+
1165
+ await fixtureShelfService.create( shelfData );
1166
+
1167
+ // console.log( 'Shelf Data:', createdShelf );
1168
+
1169
+ shelfIndex++;
1170
+ }
1171
+ }
1172
+ }
1173
+ }
1174
+
1175
+ for ( let index = 0; index < backFixtures.length; index++ ) {
1176
+ const fixture = rightFixtures[index];
1177
+
1178
+ const fixtureData = {
1179
+ 'clientId': layoutDoc.clientId,
1180
+ 'storeName': layoutDoc.storeName,
1181
+ 'storeId': layoutDoc.storeId,
1182
+ 'planoId': layoutDoc.planoId,
1183
+ 'floorId': layoutDoc._id,
1184
+ 'fixtureName': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
1185
+ 'fixtureCategory': fixture?.['Fixture Category'] ? fixture?.['Fixture Category'] : 'nil',
1186
+ 'fixtureBrandCategory': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
1187
+ 'fixtureBrandSubCategory': fixture?.['Brand - Sub Category'] ? fixture?.['Brand - Sub Category'] : 'nil',
1188
+ 'fixtureCode': fixture?.['Fixture ID'],
1189
+ 'fixtureCapacity': fixture?.['Capacity'],
1190
+ 'fixtureType': 'wall',
1191
+ 'fixtureHeight': {
1192
+ 'value': 0,
1193
+ 'unit': 'mm',
1194
+ },
1195
+ 'fixtureLength': {
1196
+ 'value': constantFixtureWidth,
1197
+ 'unit': 'mm',
1198
+ },
1199
+ 'fixtureWidth': {
1200
+ 'value': constantFixtureLength,
1201
+ 'unit': 'mm',
1202
+ },
1203
+ 'associatedElementType': 'wall',
1204
+ 'associatedElementNumber': 2,
1205
+ 'relativePosition': {
1206
+ 'x': roundToTwo( ( finalXDistance - ( constantFixtureWidth/mmToFeet ) ) ),
1207
+ 'y': roundToTwo( ( ( index * ( ( constantFixtureLength/mmToFeet ) ) ) + ( ( leftFixtures.length ? 1 : 0 ) * constantFixtureWidth/mmToFeet ) ) ),
1208
+ 'unit': 'ft',
1209
+ },
1210
+ 'fixtureNumber': fixtureCounter++,
1211
+ 'detailedFixtureLength': {
1212
+ 'value': constantDetailedFixtureLength,
1213
+ 'unit': 'mm',
1214
+ },
1215
+ 'detailedFixtureWidth': {
1216
+ 'value': constantDetailedFixtureWidth,
1217
+ 'unit': 'mm',
1218
+ },
1219
+ 'relativeDetailedPosition': {
1220
+ 'x': roundToTwo( ( finalXDistance - ( constantDetailedFixtureLength/mmToFeet ) ) ),
1221
+ 'y': roundToTwo( ( ( index * ( ( constantDetailedFixtureWidth/mmToFeet ) ) ) + ( ( leftFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth/mmToFeet ) ) ),
1222
+ 'unit': 'ft',
1223
+ },
1224
+ 'productResolutionLevel': 'L2',
1225
+ };
1226
+
1227
+ const createdFixture = await storeFixtureService.findOneAndUpdate2( { storeName: layoutDoc.storeName, fixtureNumber: fixture?.['fixtureNumber'] }, { fixtureCode: fixture?.['Fixture ID'] } );
1228
+
1229
+ // console.log( 'Fixture Data', fixtureData );
1230
+
1231
+ const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
1232
+
1233
+ for ( let i = 0; i < vms?.length; i++ ) {
1234
+ const vmTemplate = await planoProductService.findOne( { productId: vms[i] } );
1235
+
1236
+ if ( vmTemplate ) {
1237
+ const vmData = {
1238
+ 'clientId': layoutDoc.clientId,
1239
+ 'storeName': layoutDoc.storeName,
1240
+ 'storeId': layoutDoc.storeId,
1241
+ 'planoId': layoutDoc.planoId,
1242
+ 'floorId': layoutDoc._id,
1243
+ 'type': 'vm',
1244
+ 'fixtureId': createdFixture._id,
1245
+ 'productId': vmTemplate._id,
1246
+ };
1247
+
1248
+ await planoMappingService.create( vmData );
1249
+ }
1250
+ }
1251
+
1252
+ const fixtureConfig = await fixtureConfigService.findOne( { fixtureCode: fixture?.['Fixture ID'] } );
1253
+
1254
+ if ( fixtureConfig ) {
1255
+ let shelfIndex = 0;
1256
+
1257
+ for ( const section of fixtureConfig.sections ) {
1258
+ const storeCategory = fixture.categories.find( ( cat ) => cat.Zone === section.sectionId );
1259
+ for ( let j = 0; j < section.sectionShelves; j++ ) {
1260
+ if ( shelfIndex >= fixtureConfig.shelfCount ) break;
1261
+
1262
+ const shelfData = {
1263
+ 'clientId': fixtureConfig.clientId,
1264
+ 'storeName': layoutDoc.storeName,
1265
+ 'storeId': layoutDoc.storeId,
1266
+ 'planoId': layoutDoc.planoId,
1267
+ 'floorId': layoutDoc._id,
1268
+ 'fixtureId': createdFixture._id,
1269
+ 'shelfNumber': shelfIndex + 1,
1270
+ 'shelfOrder': 'LTR',
1271
+ 'shelfCapacity': fixtureConfig.productPerShelf,
1272
+ 'sectionName': storeCategory ? storeCategory?.['Allocation'] : 'Unknown',
1273
+ 'sectionZone': section.sectionId,
1274
+ };
1275
+
1276
+ const createdShelf = await fixtureShelfService.create( shelfData );
1277
+
1278
+ // console.log( 'Shelf Data:', createdShelf );
1279
+
1280
+ shelfIndex++;
1281
+ }
1282
+ }
1283
+ }
1284
+ }
1285
+
1286
+ for ( let index = 0; index < rightFixtures.length; index++ ) {
1287
+ const fixture = rightFixtures[index];
1288
+
1289
+ const fixtureData = {
1290
+ 'clientId': layoutDoc.clientId,
1291
+ 'storeName': layoutDoc.storeName,
1292
+ 'storeId': layoutDoc.storeId,
1293
+ 'planoId': layoutDoc.planoId,
1294
+ 'floorId': layoutDoc._id,
1295
+ 'fixtureName': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
1296
+ 'fixtureCategory': fixture?.['Fixture Category'] ? fixture?.['Fixture Category'] : 'nil',
1297
+ 'fixtureBrandCategory': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
1298
+ 'fixtureBrandSubCategory': fixture?.['Brand - Sub Category'] ? fixture?.['Brand - Sub Category'] : 'nil',
1299
+ 'fixtureCode': fixture?.['Fixture ID'],
1300
+ 'fixtureCapacity': fixture?.['Capacity'],
1301
+ 'fixtureType': 'wall',
1302
+ 'fixtureHeight': {
1303
+ 'value': 0,
1304
+ 'unit': 'mm',
1305
+ },
1306
+ 'fixtureLength': {
1307
+ 'value': constantFixtureLength,
1308
+ 'unit': 'mm',
1309
+ },
1310
+ 'fixtureWidth': {
1311
+ 'value': constantFixtureWidth,
1312
+ 'unit': 'mm',
1313
+ },
1314
+ 'associatedElementType': 'wall',
1315
+ 'associatedElementNumber': 3,
1316
+ 'relativePosition': {
1317
+ 'x': roundToTwo( ( index * ( constantFixtureLength / mmToFeet ) ) ),
1318
+ 'y': roundToTwo( ( finalYDistance - ( constantFixtureWidth / mmToFeet ) ) ),
1319
+ 'unit': 'ft',
1320
+ },
1321
+ 'fixtureNumber': fixtureCounter++,
1322
+ 'detailedFixtureLength': {
1323
+ 'value': constantDetailedFixtureLength,
1324
+ 'unit': 'mm',
1325
+ },
1326
+ 'detailedFixtureWidth': {
1327
+ 'value': constantDetailedFixtureWidth,
1328
+ 'unit': 'mm',
1329
+ },
1330
+ 'relativeDetailedPosition': {
1331
+ 'x': roundToTwo( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
1332
+ 'y': roundToTwo( ( finalYDetailedDistance - ( constantDetailedFixtureWidth / mmToFeet ) ) ),
1333
+ 'unit': 'ft',
1334
+ },
1335
+ 'productResolutionLevel': 'L2',
1336
+ };
1337
+
1338
+ const createdFixture = await storeFixtureService.findOneAndUpdate2( { storeName: layoutDoc.storeName, fixtureNumber: fixture?.['fixtureNumber'] }, { fixtureCode: fixture?.['Fixture ID'] } );
1339
+
1340
+ // console.log( 'Fixture Data', fixtureData );
1341
+
1342
+ const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
1343
+
1344
+ for ( let i = 0; i < vms?.length; i++ ) {
1345
+ const vmTemplate = await planoProductService.findOne( { productId: vms[i] } );
1346
+
1347
+ if ( vmTemplate ) {
1348
+ const vmData = {
1349
+ 'clientId': layoutDoc.clientId,
1350
+ 'storeName': layoutDoc.storeName,
1351
+ 'storeId': layoutDoc.storeId,
1352
+ 'planoId': layoutDoc.planoId,
1353
+ 'floorId': layoutDoc._id,
1354
+ 'type': 'vm',
1355
+ 'fixtureId': createdFixture._id,
1356
+ 'productId': vmTemplate._id,
1357
+ };
1358
+
1359
+ await planoMappingService.create( vmData );
1360
+ }
1361
+ }
1362
+
1363
+ const fixtureConfig = await fixtureConfigService.findOne( { fixtureCode: fixture?.['Fixture ID'] } );
1364
+
1365
+ if ( fixtureConfig ) {
1366
+ let shelfIndex = 0;
1367
+
1368
+ for ( const section of fixtureConfig.sections ) {
1369
+ const storeCategory = fixture.categories.find( ( cat ) => cat.Zone === section.sectionId );
1370
+ for ( let j = 0; j < section.sectionShelves; j++ ) {
1371
+ if ( shelfIndex >= fixtureConfig.shelfCount ) break;
1372
+
1373
+ const shelfData = {
1374
+ 'clientId': fixtureConfig.clientId,
1375
+ 'storeName': layoutDoc.storeName,
1376
+ 'storeId': layoutDoc.storeId,
1377
+ 'planoId': layoutDoc.planoId,
1378
+ 'floorId': layoutDoc._id,
1379
+ 'fixtureId': createdFixture._id,
1380
+ 'shelfNumber': shelfIndex + 1,
1381
+ 'shelfOrder': 'LTR',
1382
+ 'shelfCapacity': fixtureConfig.productPerShelf,
1383
+ 'sectionName': storeCategory ? storeCategory?.['Allocation'] : 'Unknown',
1384
+ 'sectionZone': section.sectionId,
1385
+ };
1386
+
1387
+ await fixtureShelfService.create( shelfData );
1388
+
1389
+ // console.log( 'Shelf Data:', createdShelf );
1390
+
1391
+ shelfIndex++;
1392
+ }
1393
+ }
1394
+ }
1395
+ }
1396
+
1397
+ for ( let index = 0; index < floorFixtures.length; index++ ) {
1398
+ const fixture = floorFixtures[index];
1399
+
1400
+ const centerRow = Math.floor( totalRows / 2 );
1401
+
1402
+ const startingX =roundToTwo( ( ( finalXDistance / 2 ) - ( ( maxFixturesPerRow / 2 ) * ( constantFixtureLength / mmToFeet ) ) ) );
1403
+ const detailedStartingX = roundToTwo( ( ( finalXDetailedDistance / 2 ) - ( ( maxFixturesPerRow / 2 ) * ( constantDetailedFixtureLength / mmToFeet ) ) ) );
1404
+
1405
+ const startingY = ( finalYDistance / 2 ) - ( centerRow * ( constantFixtureWidth / mmToFeet ) );
1406
+ const detailedStartingY = ( finalYDetailedDistance / 2 ) - ( centerRow * ( constantDetailedFixtureWidth / mmToFeet ) );
1407
+
1408
+ const rowIndex = Math.floor( index / maxFixturesPerRow );
1409
+ const colIndex = index % maxFixturesPerRow;
1410
+
1411
+ const xPos = roundToTwo( ( startingX + colIndex * ( constantFixtureLength / mmToFeet ) ) );
1412
+ const yPos = roundToTwo( ( startingY + rowIndex * ( constantFixtureWidth / mmToFeet ) ) );
1413
+
1414
+ const detailedXPos = roundToTwo( ( detailedStartingX + colIndex * ( constantDetailedFixtureLength / mmToFeet ) ) );
1415
+ const detailedYPos = roundToTwo( ( detailedStartingY + rowIndex * ( constantDetailedFixtureWidth / mmToFeet ) ) );
1416
+
1417
+ const fixtureData = {
1418
+ 'clientId': layoutDoc.clientId,
1419
+ 'storeName': layoutDoc.storeName,
1420
+ 'storeId': layoutDoc.storeId,
1421
+ 'planoId': layoutDoc.planoId,
1422
+ 'floorId': layoutDoc._id,
1423
+ 'fixtureName': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
1424
+ 'fixtureCategory': fixture?.['Fixture Category'] ? fixture?.['Fixture Category'] : 'nil',
1425
+ 'fixtureBrandCategory': fixture?.['Brand-Category'] ? fixture?.['Brand-Category'] : 'nil',
1426
+ 'fixtureBrandSubCategory': fixture?.['Brand - Sub Category'] ? fixture?.['Brand - Sub Category'] : 'nil',
1427
+ 'fixtureCode': fixture?.['Fixture ID'],
1428
+ 'fixtureCapacity': fixture?.['Capacity'],
1429
+ 'fixtureType': 'floor',
1430
+ 'fixtureHeight': {
1431
+ 'value': 0,
1432
+ 'unit': 'mm',
1433
+ },
1434
+ 'fixtureLength': {
1435
+ 'value': constantFixtureLength,
1436
+ 'unit': 'mm',
1437
+ },
1438
+ 'fixtureWidth': {
1439
+ 'value': constantFixtureWidth,
1440
+ 'unit': 'mm',
1441
+ },
1442
+ 'relativePosition': {
1443
+ 'x': xPos,
1444
+ 'y': yPos,
1445
+ 'unit': 'ft',
1446
+ },
1447
+ 'fixtureNumber': fixtureCounter++,
1448
+ 'detailedFixtureLength': {
1449
+ 'value': constantDetailedFixtureLength,
1450
+ 'unit': 'mm',
1451
+ },
1452
+ 'detailedFixtureWidth': {
1453
+ 'value': constantDetailedFixtureWidth,
1454
+ 'unit': 'mm',
1455
+ },
1456
+ 'relativeDetailedPosition': {
1457
+ 'x': detailedXPos,
1458
+ 'y': detailedYPos,
1459
+ 'unit': 'ft',
1460
+ },
1461
+ 'productResolutionLevel': 'L2',
1462
+ };
1463
+
1464
+ const createdFixture = await storeFixtureService.findOneAndUpdate2( { storeName: layoutDoc.storeName, fixtureNumber: fixture?.['fixtureNumber'] }, { fixtureCode: fixture?.['Fixture ID'] } );
1465
+ // console.log( 'Fixture Data', fixtureData );
1466
+
1467
+ const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
1468
+
1469
+ for ( let i = 0; i < vms?.length; i++ ) {
1470
+ const vmTemplate = await planoProductService.findOne( { productId: vms[i] } );
1471
+
1472
+ if ( vmTemplate ) {
1473
+ const vmData = {
1474
+ 'clientId': layoutDoc.clientId,
1475
+ 'storeName': layoutDoc.storeName,
1476
+ 'storeId': layoutDoc.storeId,
1477
+ 'planoId': layoutDoc.planoId,
1478
+ 'floorId': layoutDoc._id,
1479
+ 'type': 'vm',
1480
+ 'fixtureId': createdFixture._id,
1481
+ 'productId': vmTemplate._id,
1482
+ };
1483
+
1484
+ await planoMappingService.create( vmData );
1485
+ }
1486
+ }
1487
+
1488
+
1489
+ const fixtureConfig = await fixtureConfigService.findOne( { fixtureCode: fixture?.['Fixture ID'] } );
1490
+
1491
+ if ( fixtureConfig ) {
1492
+ let shelfIndex = 0;
1493
+
1494
+ for ( const section of fixtureConfig.sections ) {
1495
+ const storeCategory = fixture.categories.find( ( cat ) => cat.Zone === section.sectionId );
1496
+ for ( let j = 0; j < section.sectionShelves; j++ ) {
1497
+ if ( shelfIndex >= fixtureConfig.shelfCount ) break;
1498
+
1499
+ const shelfData = {
1500
+ 'clientId': fixtureConfig.clientId,
1501
+ 'storeName': layoutDoc.storeName,
1502
+ 'storeId': layoutDoc.storeId,
1503
+ 'planoId': layoutDoc.planoId,
1504
+ 'floorId': layoutDoc._id,
1505
+ 'fixtureId': createdFixture._id,
1506
+ 'shelfNumber': shelfIndex + 1,
1507
+ 'shelfOrder': 'LTR',
1508
+ 'shelfCapacity': fixtureConfig.productPerShelf,
1509
+ 'sectionName': storeCategory ? storeCategory?.['Allocation'] : 'Unknown',
1510
+ 'sectionZone': section.sectionId,
1511
+ };
1512
+
1513
+ await fixtureShelfService.create( shelfData );
1514
+
1515
+ // console.log( 'Shelf Data:', createdShelf );
1516
+
1517
+ shelfIndex++;
1518
+ }
1519
+ }
1520
+ }
1521
+ }
1522
+ }
1523
+
1524
+
1525
+ return res.sendSuccess( 'Updated successfully' );
1526
+ } catch ( e ) {
1527
+ logger.error( { functionName: 'createFixturesShelves', error: e } );
1528
+ return res.sendError( e.message || 'Internal Server Error', 500 );
1529
+ }
1530
+ }
1531
+
1567
1532
  export async function createVmData( req, res ) {
1568
1533
  try {
1569
1534
  if ( !req.files.file ) {