duyongjia
2025-02-28 cb385f0b515c738b503c5c75c9d7efcec323716d
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
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.StockEnum;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IRecordRepository;
using WIDESEAWCS_IRecordService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_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);
        }
    }
}