1
huanghongfeng
2024-10-31 47f3edac31e999a919f34968d56271c8f425cddc
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
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 partial class StockQuantityChangeRecordService : ServiceBase<Dt_StockQuantityChangeRecord, IStockQuantityChangeRecordRepository>, IStockQuantityChangeRecordService
    {
        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);
        }
    }
}