1
hutongqing
2024-09-13 ea9bdf217e8202a5fa475262dba1792decb05bcb
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
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_IRecordRepository;
using WIDESEA_IRecordService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_RecordService
{
    public class StockQuantityChangeRecordService : ServiceBase<Dt_StockQuantityChangeRecord, IStockQuantityChangeRecordRepository>, IStockQuantityChangeRecordService
    {
        private readonly IMapper _mapper;
        public StockQuantityChangeRecordService(IStockQuantityChangeRecordRepository BaseDal, IMapper mapper) : base(BaseDal)
        {
            _mapper = mapper;
        }
 
        public IStockQuantityChangeRecordRepository Repository => BaseDal;
 
        public void AddStockChangeRecord(Dt_StockInfo stockInfo, List<Dt_StockInfoDetail> stockInfoDetails, decimal beforeQuantity, decimal totalQuantity, StockChangeType changeType)
        {
            List<Dt_StockQuantityChangeRecord> stockQuantityChangeRecords = new List<Dt_StockQuantityChangeRecord>();
            stockQuantityChangeRecords = _mapper.Map<List<Dt_StockQuantityChangeRecord>>(stockInfoDetails);
            int index = 0;
            decimal currentQuantity = 0;
            stockQuantityChangeRecords.ForEach(x =>
            {
                x.PalleCode = stockInfo.PalletCode;
                x.BeforeQuantity = beforeQuantity;
                if (totalQuantity > beforeQuantity)
                {
                    x.ChangeQuantity = stockInfoDetails[index].StockQuantity;
                    currentQuantity += stockInfoDetails[index].StockQuantity;
                    x.AfterQuantity = stockInfoDetails[index].StockQuantity + beforeQuantity;
                }
                else
                {
                    x.ChangeQuantity = -stockInfoDetails[index].StockQuantity;
                    currentQuantity -= stockInfoDetails[index].StockQuantity;
                    x.AfterQuantity = beforeQuantity - stockInfoDetails[index].StockQuantity;
                }
 
                x.ChangeType = changeType.ObjToInt();
                beforeQuantity += x.ChangeQuantity;
            });
            BaseDal.AddData(stockQuantityChangeRecords);
        }
    }
}