File size: 1,893 Bytes
13240d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
using BakeryErp.Infrastructure.Database;

namespace BakeryErp.Infrastructure.Repositories;

public sealed class MasterDataLookupRepository
{
    private readonly DatabaseOptions _options;

    public MasterDataLookupRepository(DatabaseOptions options)
    {
        _options = options;
    }

    public IReadOnlyList<LookupOption> Suppliers()
    {
        return LocalDataStoreFile.Load(_options).Suppliers
            .Where(static supplier => supplier.IsActive)
            .OrderBy(static supplier => supplier.Code)
            .Select(static supplier => new LookupOption(supplier.Name, $"{supplier.Code} - {supplier.Name}"))
            .ToList();
    }

    public IReadOnlyList<ItemLookupOption> Items()
    {
        return LocalDataStoreFile.Load(_options).Items
            .Where(static item => item.IsActive)
            .OrderBy(static item => item.Sku)
            .Select(static item => new ItemLookupOption(item.Sku, item.Name, item.BaseUnit, $"{item.Sku} - {item.Name}"))
            .ToList();
    }

    public IReadOnlyList<LookupOption> Stores()
    {
        return LocalDataStoreFile.Load(_options).Stores
            .Where(static store => store.IsActive)
            .OrderBy(static store => store.Code)
            .Select(static store => new LookupOption(store.Name, $"{store.Code} - {store.Name}"))
            .ToList();
    }

    public IReadOnlyList<LookupOption> Warehouses()
    {
        return LocalDataStoreFile.Load(_options).Warehouses
            .Where(static warehouse => warehouse.IsActive)
            .OrderBy(static warehouse => warehouse.Code)
            .Select(static warehouse => new LookupOption(warehouse.Name, $"{warehouse.Code} - {warehouse.Name}"))
            .ToList();
    }
}

public sealed record LookupOption(string Value, string Label);

public sealed record ItemLookupOption(string Sku, string Name, string Unit, string Label);