yangle
2023-05-24 b129762a4bb5ec2cde5edf16bc9cbda57c73587d
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace BLL
{
    public class ClsKf_MateOutBackBill
    {
        /// <summary>
        /// 根据过滤条件,返回源单信息-生产领料单-蓝字(红字领料源单)
        /// </summary>
        /// <param name="sWhere">过滤条件</param>
        /// <returns></returns>
        public DataSet GetKf_MateOutBillList(string sWhere, ref string sErr)
        {
            try
            {
                DAL.Cls_S_IF_MateOutBill_Lite dal = new DAL.Cls_S_IF_MateOutBill_Lite();
                return dal.DisSourceBillList(sWhere);
            }
            catch (Exception e)
            {
                sErr = sErr + "," + e.Message;
                return null;
            }
        }
 
        /// <summary>
        /// 根据过滤条件,返回源单信息-生产任务单(投料单)-退料列表(红字领料源单)
        /// </summary>
        /// <param name="sWhere">过滤条件</param>
        /// <param name="sErr"></param>
        /// <returns></returns>
        public DataSet GetSc_PPBomBackBillList(string sWhere, ref string sErr)
        {
            try
            {
                DAL.Cls_S_IF_PPBomBackList_Lite dal = new DAL.Cls_S_IF_PPBomBackList_Lite();
                return dal.DisSourceBillList(sWhere);
            }
            catch (Exception e)
            {
                sErr = sErr + "," + e.Message;
                return null;
            }
        }
 
 
 
 
        //生成生产退料单 
        public bool set_SaveMateOutBackBill_New(Model.ClsKf_ICStockBillMain oMain, string sHSourceType, ref string sErrMsg)
        {
            //获取系统参数
            Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
            if (oSystemParameter.ShowBill(ref sErrMsg) == false)
            {
                sErrMsg = "获取系统参数失败! " + sErrMsg;
                return false;
            }
            //
            if (oSystemParameter.omodel.Kf_MateOutBackBill_ERPMode.ToUpper() == "WISE") //判断同步模式是金蝶WISE
            {
                if (SaveMateOutBackBill_K3(oMain, sHSourceType, oSystemParameter.omodel, ref sErrMsg))
                {
                    //"保存成功!";
                    sErrMsg = "保存成功!" + oMain.HBillNo;
                    return true;
                }
                else
                {
                    //"保存失败!";
                    sErrMsg = sErrMsg;
                    return false;
                }
            }
            if (oSystemParameter.omodel.Kf_MateOutBackBill_ERPMode.ToUpper() == "CLOUD")  //判断同步模式是金蝶CLOUD
            {
 
            }
 
            sErrMsg = "保存生产退料单失败!" + sErrMsg;
            return false;
        }
 
         
 
        /// <summary>
        /// 生成生产退料单K3
        /// </summary>
        /// <param name="oMain"></param>
        /// <param name="sErrMsg"></param>
        /// <returns></returns>
        public bool SaveMateOutBackBill_K3(Model.ClsKf_ICStockBillMain oMain, string sHSourceType, Pub_Class.ClsXt_SystemParameterMain oSystemParameterMain, ref string sErrMsg)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            DAL.ClsKf_MateOutBackBill dal = new DAL.ClsKf_MateOutBackBill();
            dal.omodel = oMain;
            //上传前必填项判断
            if (oMain.HDeptID == 0)
            {
                sErrMsg = "部门没有选择!";
                return false;
            }
            if (oMain.HSecManagerID == 0)
            {
                sErrMsg = "收料没有选择!";
                return false;
            }
            if (oMain.HKeeperID == 0)
            {
                sErrMsg = "保管没有选择!";
                return false;
            }
 
            try
            {
                //判断会计期是否合理
                string s = "";
                int sYear = 0;
                int sPeriod = 0;
                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(oMain.HDate, ref sYear, ref sPeriod, ref s) == false)
                {
                    sErrMsg = s;
                    return false;
                }
                oMain.HYear = sYear;
                oMain.HPeriod = sPeriod;
 
                DataSet Ds;
                oCn.BeginTran();
                //生成出入库单据
                //插入子表
                oCn.RunProc("EXEC h_p_Kf_MateOutBackBillSub_Insert_New " + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "','" + sHSourceType + "'");
                //插入主表
                oCn.RunProc("Insert Into Kf_ICStockBillMain   " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMainSourceBillType" +
                ",HYear,HPeriod,HRemark,HMaker,HMakeDate" +
                ",HSupID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID" +
                ",HKeeperID,HDeptID,HExplanation,HInnerBillNo,HRedBlueFlag" +
                ") " +
                " values('1244','1244'," + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "',convert(varchar(10),getdate(),120),'" + oMain.HMainSourceBillType + "'" +
                ", " + oMain.HYear.ToString() + "," + oMain.HPeriod.ToString() + ",'" + oMain.HRemark + "','" + oMain.HMaker + "',convert(varchar(10),getdate(),120)" +
                ", " + oMain.HSupID.ToString() + "," + oMain.HWHID.ToString() + "," + oMain.HSCWHID.ToString() + "," + oMain.HEmpID.ToString() + "," + oMain.HManagerID.ToString() + "," + oMain.HSecManagerID.ToString() +
                ", " + oMain.HKeeperID.ToString() + "," + oMain.HDeptID.ToString() + ",'" + oMain.HExplanation + "','" + oMain.HInnerBillNo + "'," + DBUtility.ClsPub.BoolToString(oMain.HRedBlueFlag) +
                ") ");
 
                //新增K3子表、主表
                oCn.RunProc("exec h_p_IFK3_ToERP_MateOutBackBill_Insert_New " + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "'," + oMain.HBillerID.ToString() + ",'" + sHSourceType + "'");
 
                //更新关联数量
                if (sHSourceType == "3720")         //生产任务单-投料
                {
                    oCn.RunProc("exec h_p_Sc_UpDateRelation_PPBomToMateOutBack_Add " + oMain.HInterID.ToString());
                    //回填K3关联数量
                    oCn.RunProc("exec h_p_IFK3_ToERP_MateOutBackBill_UpdateBillRelateData_PPBom " + oMain.HInterID.ToString());
                }
                else if (sHSourceType == "1204")    //生产领料单-蓝字
                {
                    oCn.RunProc("exec h_p_Kf_UpDateRelation_MateOutToMateOutBack_Add " + oMain.HInterID.ToString());
                    //回填K3关联数量
                    oCn.RunProc("exec h_p_IFK3_ToERP_MateOutBackBill_UpdateBillRelateData_Blue " + oMain.HInterID.ToString());
                }
                else    //无源单
                {
                    //回填K3关联数量
                    oCn.RunProc("exec h_p_IFK3_ToERP_MateOutBackBill_UpdateBillRelateData " + oMain.HInterID.ToString());
                }
 
                //审核单据
                if (oSystemParameterMain.Kf_MateOutBackBill_AutoCheck == "Y") //系统参数  自动审核 
                {
                    //审核单据
                    oCn.RunProc("Update Kf_ICStockBillMain Set HChecker='" + oMain.HMaker + "',HCheckDate=convert(varchar(10),getdate(),120) where HInterID= " + oMain.HInterID.ToString());
 
                    //审核K3单据
                    oCn.RunProc("exec h_p_IFK3_ToERP_MateOutBackBill_Check " + oMain.HInterID.ToString() + "," + oMain.HBillerID.ToString());
                    //更新K3库存
                    oCn.RunProc("exec h_p_IFK3_ToERP_MateOutBackBill_UpdateStock " + oMain.HInterID.ToString());
                    oCn.RunProc("exec h_p_IFK3_ToERP_MateOutBackBill_UpdateOrderStock " + oMain.HInterID.ToString());
                }
 
                sErrMsg = "新增单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sErrMsg = "生成生产退料单失败!" + e.Message;
                oCn.RollBack();
                return false;
            }
        }
 
 
 
 
 
    }
}