Пример #1
0
        /// <summary>
        /// 审核生产计划
        /// </summary>
        /// <param name="scjh"></param>
        public static void ShScJh(YK_ZJJG_JH jh, List <YK_ZJJG_JHMX> lstjhmx, RelationalDatabase db, string ywlx, int jgbm)
        {
            //更新计划明细-更新原料消耗明细-更新计划表
            //办理加工入库
            try
            {
                List <YK_ZJJG_JH> lstjh_check = YK_ZJJG_JH.GetJhList(string.Format(" and a.id='{0}' ", jh.id), "", db);
                if (lstjh_check.Count <= 0)
                {
                    throw new Exception("审核失败!找不到该计划,请刷新数据后重试!");
                }
                else
                {
                    YK_ZJJG_JH jh_check = lstjh_check[0];
                    if (jh_check.bshbz == 1)
                    {
                        throw new Exception("审核失败!请刷新数据后重试!");
                    }
                    if (jh_check.bscbz == 1)
                    {
                        throw new Exception("审核失败!该计划已经被删除,请刷新数据!");
                    }
                }

                #region  插入加工入库单据头
                Guid    rk_djid;
                int     rk_err_code = 0;  //保存单据头存储过程错误代码
                string  rk_err_text = ""; //保存单据头存储过程错误文本
                long    rk_djh      = Yp.SeekNewDjh(ywlx, jh.deptid, db);
                long    rk_sdjh     = Yp.SeekNewDjh(ywlx, jh.deptid, db);
                decimal rk_sumjhje  = 0;
                decimal rk_sumpfje  = 0;
                decimal rk_sumlsje  = 0;
                int     deptid      = jh.deptid;
                int     uid         = jh.djy;
                string  sDate       = (db.GetDataResult(db.GetServerTimeString())).ToString();//当前服务器时间

                foreach (YK_ZJJG_JHMX jhmx in lstjhmx)
                {
                    rk_sumjhje += jhmx.jhj * jhmx.cpsl;
                    rk_sumpfje += jhmx.pfj * jhmx.cpsl;
                    rk_sumlsje += jhmx.lsj * jhmx.cpsl;
                }

                Yk_dj_djmx.SaveDJ(new Guid(Guid.Empty.ToString()),
                                  rk_djh, //单据号
                                  deptid, //仓库id
                                  ywlx,   //业务类型
                                  deptid, //往来单位
                                  0,      //经手人
                                  DateTime.Now.ToShortDateString(),
                                  uid,
                                  Convert.ToDateTime(sDate).ToShortDateString(),
                                  Convert.ToDateTime(sDate).ToLongTimeString(),
                                  "",
                                  "",
                                  "",
                                  "",
                                  0,
                                  0,
                                  rk_sumjhje,
                                  rk_sumpfje,
                                  rk_sumlsje,
                                  rk_sdjh.ToString(),
                                  out rk_djid, out rk_err_code, out rk_err_text, jgbm, db);
                #endregion

                #region 更新计划
                //if (jh.bshbz == 1) throw new Exception("该计划已经审核!");
                jh.bshbz  = 1;
                jh.rkdjid = rk_djid;
                jh.shrq   = Convert.ToDateTime(db.GetDataResult(db.GetServerTimeString()));
                YK_ZJJG_JH.SaveJh(db, jh, 1);
                #endregion

                #region 更新计划明细
                int pxxh = 0;
                foreach (YK_ZJJG_JHMX jhmx in lstjhmx)
                {
                    pxxh += 1;

                    //计算成本价
                    List <YK_ZJJG_YLMX> lstYlmx   = YK_ZJJG_YLMX.GetYlmxList(string.Format(" and b.id='{0}'", jhmx.id), "", db);
                    decimal             sumYlpfje = 0;
                    foreach (YK_ZJJG_YLMX ylmx in lstYlmx)
                    {
                        sumYlpfje += ylmx.pfj * ylmx.sl;
                    }
                    if (jhmx.cpsl == 0)
                    {
                        throw new Exception("成品数量不能为0");
                    }
                    jhmx.cbj = Convert.ToDecimal(sumYlpfje / jhmx.cpsl); //成本价

                    #region 插入加工入库单据明细
                    //int rk_djmx_err_code = 0;
                    //string rk_djmx_err_text = "";
                    Guid rk_djmxid = Guid.Empty;
                    Ypcj YPCJ      = new Ypcj(jhmx.cjid, db);
                    Ypgg YPGG      = new Ypgg(YPCJ.GGID, db);

                    //此方法不再使用 统一方法
                    //InsertDjmx(db, rk_djmxid, rk_djid, jhmx.cjid,
                    //    0, "", jhmx.yppm, jhmx.yppm, jhmx.ypgg,
                    //    jhmx.sccj, jhmx.ph,
                    //    jhmx.xq.ToShortDateString(), 0, 0, jhmx.cpsl, jhmx.ypdw, YPGG.YPDW, 1,
                    //    YPCJ.ZBJ, YPCJ.PFJ, YPCJ.LSJ, YPCJ.ZBJ * jhmx.cpsl,
                    //    YPCJ.PFJ * jhmx.cpsl, YPCJ.LSJ * jhmx.cpsl, rk_djh, deptid, ywlx, "", rk_sdjh.ToString(),
                    //    pxxh, 1);

                    int    err_code = 0;
                    string err_text = "";
                    //20140211 ncq 将成品入库批发价 设定为成本价 系统对账将会出现批发金额不对问题
                    Yk_dj_djmx.SaveDJMX_ID(Guid.Empty, rk_djid, jhmx.cjid, 0, "",
                                           jhmx.yppm, jhmx.yppm, jhmx.ypgg, jhmx.sccj, jhmx.ph,
                                           jhmx.xq.ToShortDateString(), 0, 0, jhmx.cpsl, jhmx.ypdw, YPGG.YPDW, 1,
                                           0,                                 //YPCJ.MRJJ, //ypcjd中默认进价
                                           YPCJ.PFJ,                          //批发价            //jhmx.cbj,  //成本价
                                           YPCJ.LSJ,                          //零售价
                                                                              //jhmx.cpsl*YPCJ.MRJJ,//ypcjd中默认进价*成品数量
                                           0,                                 //YPCJ.MRJJ * jhmx.cpsl/jhmx.ydwbl,//进货金额
                                           jhmx.cpsl * YPCJ.PFJ / jhmx.ydwbl, //批发金额      //jhmx.cbj * jhmx.cpsl/jhmx.ydwbl, //采用成本价计算批发金额
                                           YPCJ.LSJ * jhmx.cpsl / jhmx.ydwbl, //零售金额
                                           rk_djh, deptid, ywlx, "", rk_sdjh.ToString(),
                                           out err_code, out err_text, db, pxxh, out rk_djmxid, "", Guid.Empty);
                    if (err_code != 0)
                    {
                        throw new Exception(err_text);
                    }

                    #endregion

                    #region 更新计划明细
                    jhmx.cpl      = Convert.ToDecimal(jhmx.cpsl / jhmx.jhsl); //成本率
                    jhmx.rkdjmxid = rk_djmxid;                                //更新计划明细中 入库单据明细id
                    jhmx.djid     = jh.id;
                    jhmx.djh      = Convert.ToInt32(jh.djh);
                    YK_ZJJG_JHMX.SaveJhmx(jhmx, db, 1);
                    #endregion
                }
                #endregion

                #region 审核加工入库单据
                Yk_dj_djmx.Shdj(rk_djid, db.GetDataResult(db.GetServerTimeString()).ToString(), db);
                #endregion

                #region 更新库存
                int    upt_err_code = 0;
                string upt_err_text = "";
                //MessageBox.Show(rk_djid.ToString());
                Yk_dj_djmx.AddUpdateKcmx(rk_djid, out upt_err_code, out upt_err_text, Convert.ToInt64(jgbm), db);
                if (upt_err_code != 0)
                {
                    throw new Exception(upt_err_text.ToString());
                }
                //MessageBox.Show(upt_err_text);
                #endregion
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Пример #2
0
 /// <summary>
 /// 获取原料明细列表
 /// </summary>
 /// <param name="strWhere"></param>
 /// <param name="strOrder"></param>
 /// <param name="db"></param>
 /// <returns></returns>
 public List <YK_ZJJG_YLMX> GetYlmxList(string strWhere, string strOrder, RelationalDatabase db)
 {
     return(YK_ZJJG_YLMX.GetYlmxList(string.Format(" and a.djid='{0}'", id) + strWhere, strOrder, db));
 }