1
Huangxiaoqiang-03
2024-11-06 f51582d5b4b498f28513f215f91828ef181df4a1
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 partial class StockQuantityChangeRecordService : ServiceBase<Dt_StockQuantityChangeRecord, IStockQuantityChangeRecordRepository>, IStockQuantityChangeRecordService
    {
        public void AddStockChangeRecord(Dt_StockInfo stockInfo, List<Dt_StockInfoDetail> stockInfoDetails, decimal beforeQuantity, decimal totalQuantity, StockChangeType changeType,int taskNum)
        {
            try
            {
                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;
                    x.TaskNum = taskNum;
                });
                BaseDal.AddData(stockQuantityChangeRecords);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}