All files / src/domains/inventory/services inventory.service.ts

0% Statements 0/40
0% Branches 0/56
0% Functions 0/2
0% Lines 0/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                                                                                                                                                                               
import { Injectable } from '@nestjs/common';
import { ConfigurationService } from '../configuration/services/configuration.service';
import { ItemService } from '../items/services/item.service';
import { WarehouseService } from '../warehouses/services/warehouse.service';
import { LedgerService } from '../stock-ledger/services/ledger.service';
import { BatchSerialService } from '../batches/services/batch-serial.service';
import { ReservationService } from '../reservations/services/reservation.service';
import { MovementService } from '../transfers/services/movement.service';
import { AdjustmentService } from '../adjustments/services/adjustment.service';
import { CountService } from '../counts/services/count.service';
import { ReplenishmentService } from '../replenishment/services/replenishment.service';
import { ValuationService } from '../valuation/services/valuation.service';
import { TraceabilityService } from '../traceability/services/traceability.service';
import { ReceiptIntegrationService } from '../receipts/services/receipt-integration.service';
 
@Injectable()
export class InventoryService {
  constructor(
    public readonly configService: ConfigurationService,
    public readonly itemService: ItemService,
    public readonly warehouseService: WarehouseService,
    public readonly ledgerService: LedgerService,
    public readonly batchSerialService: BatchSerialService,
    public readonly reservationService: ReservationService,
    public readonly movementService: MovementService,
    public readonly adjustmentService: AdjustmentService,
    public readonly countService: CountService,
    public readonly replenishmentService: ReplenishmentService,
    public readonly valuationService: ValuationService,
    public readonly traceabilityService: TraceabilityService,
    public readonly receiptIntegrationService: ReceiptIntegrationService
  ) {}
 
  async seed(tenantId: string): Promise<any> {
    // Seed initial configuration parameters
    await this.configService.getConfiguration(tenantId);
 
    // Seed default item product catalogs
    const count = await this.itemService.getItems(tenantId);
    if (count.length === 0) {
      await this.itemService.createItem(tenantId, {
        itemCode: 'ITEM-CONCRETE-01',
        itemName: 'Standard Portland Concrete Grade-A',
        itemType: 'Stock Item',
        trackingType: 'Batch',
        baseUom: 'BAG',
        reorderPoint: 50,
        safetyStock: 10,
        minStock: 20,
        maxStock: 500,
      });
 
      await this.itemService.createItem(tenantId, {
        itemCode: 'ITEM-ROD-02',
        itemName: 'Rebar Steel Reinforcing Rod 12mm',
        itemType: 'Stock Item',
        trackingType: 'Serial',
        baseUom: 'PCS',
        reorderPoint: 100,
        safetyStock: 20,
        minStock: 30,
        maxStock: 1000,
      });
    }
 
    // Seed default warehouses
    const whCount = await this.warehouseService.getWarehouses(tenantId);
    if (whCount.length === 0) {
      const wh = await this.warehouseService.createWarehouse(tenantId, {
        warehouseCode: 'WH-MAIN-01',
        name: 'Be-Vision Central Warehouse TX',
        warehouseType: 'Main',
      });
 
      await this.warehouseService.createLocation(tenantId, {
        warehouseId: (wh as any)._id.toString(),
        zoneCode: 'ZONE-A',
        aisle: '01',
        rack: '02',
        shelf: '03',
        bin: '04',
      });
    }
 
    return { seeded: true };
  }
}