예제 #1
0
        /// <summary>
        /// 取消配送
        /// </summary>
        /// <param name="costPdtIds">成本产品id</param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public string PurchaseUnShip(string costPdtIds, long userId)
        {
            ctt_contract_cost_product_dal cstPdtDal = new ctt_contract_cost_product_dal();
            var pdtList = cstPdtDal.FindListBySql <ctt_contract_cost_product>($"select * from ctt_contract_cost_product where id in({costPdtIds})");

            if (pdtList == null || pdtList.Count == 0)
            {
                return("");
            }

            ctt_contract_cost_dal        costDal     = new ctt_contract_cost_dal();
            ivt_transfer_dal             tsfDal      = new ivt_transfer_dal();
            ctt_contract_dal             cttDal      = new ctt_contract_dal();
            pro_project_dal              proDal      = new pro_project_dal();
            sdk_task_dal                 tskDal      = new sdk_task_dal();
            ivt_warehouse_product_sn_dal lctPdtSnDal = new ivt_warehouse_product_sn_dal();
            ivt_transfer_sn_dal          tsfSnDal    = new ivt_transfer_sn_dal();

            foreach (var pdt in pdtList)
            {
                // 修改成本产品状态
                var pdtOld = cstPdtDal.FindById(pdt.id);
                pdt.status_id      = (int)DicEnum.CONTRACT_COST_PRODUCT_STATUS.PENDING_DISTRIBUTION;
                pdt.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                pdt.shipping_time  = null;
                pdt.update_user_id = userId;
                cstPdtDal.Update(pdt);
                OperLogBLL.OperLogUpdate(OperLogBLL.CompareValue <ctt_contract_cost_product>(pdtOld, pdt), pdt.id, userId, DicEnum.OPER_LOG_OBJ_CATE.CTT_CONTRACT_COST_PRODUCT, "成本产品配送");

                // 修改成本状态
                var cost = costDal.FindById(pdt.contract_cost_id);
                if (cost.status_id == (int)DicEnum.COST_STATUS.ALREADY_DELIVERED)
                {
                    var costOld = costDal.FindById(pdt.contract_cost_id);
                    cost.status_id      = (int)DicEnum.COST_STATUS.PENDING_DELIVERY;
                    cost.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                    cost.update_user_id = userId;
                    costDal.Update(cost);
                    OperLogBLL.OperLogUpdate(OperLogBLL.CompareValue <ctt_contract_cost>(costOld, cost), cost.id, userId, DicEnum.OPER_LOG_OBJ_CATE.CONTRACT_COST, "取消配送修改成本状态");
                }

                // 新建库存转移信息
                ivt_transfer tsf = new ivt_transfer();
                tsf.id             = tsfDal.GetNextIdCom();
                tsf.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                tsf.update_user_id = userId;
                tsf.create_time    = tsf.update_time;
                tsf.create_user_id = userId;
                tsf.type_id        = (int)DicEnum.INVENTORY_TRANSFER_TYPE.PROJECT;
                tsf.product_id     = (long)cost.product_id;
                tsf.quantity       = 0 - pdt.quantity;
                if (cost.contract_id != null)
                {
                    tsf.to_account_id = cttDal.FindById((long)cost.contract_id).account_id;
                }
                else if (cost.project_id != null)
                {
                    tsf.to_account_id = proDal.FindById((long)cost.project_id).account_id;
                }
                else if (cost.task_id != null)
                {
                    tsf.to_account_id = tskDal.FindById((long)cost.task_id).account_id;
                }
                tsf.to_contract_id    = cost.contract_id;
                tsf.to_project_id     = cost.project_id;
                tsf.to_task_id        = cost.task_id;
                tsf.from_warehouse_id = (long)pdt.warehouse_id;
                tsfDal.Insert(tsf);
                OperLogBLL.OperLogAdd <ivt_transfer>(tsf, tsf.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM_TRANSFER, "取消配送新建库存转移");


                // 保存库存数修改
                var lctPdt = dal.FindSignleBySql <ivt_warehouse_product>($"select * from ivt_warehouse_product where product_id={cost.product_id} and warehouse_id={(long)pdt.warehouse_id} and delete_time=0");
                if (lctPdt != null)
                {
                    var lctPdtOld = dal.FindById(lctPdt.id);
                    lctPdt.quantity       = lctPdt.quantity + pdt.quantity;
                    lctPdt.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                    lctPdt.update_user_id = userId;
                    dal.Update(lctPdt);
                    OperLogBLL.OperLogUpdate(OperLogBLL.CompareValue <ivt_warehouse_product>(lctPdtOld, lctPdt), lctPdt.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM, "修改库存产品库存数");

                    var sns = costDal.FindListBySql <string>($"select sn from ctt_contract_cost_product_sn where contract_cost_product_id={pdt.id} and delete_time=0");
                    if (sns == null || sns.Count == 0)
                    {
                        continue;
                    }

                    foreach (var sn in sns)
                    {
                        ivt_warehouse_product_sn lctPdtSn = new ivt_warehouse_product_sn();
                        lctPdtSn.id                   = lctPdtSnDal.GetNextIdCom();
                        lctPdtSn.create_time          = Tools.Date.DateHelper.ToUniversalTimeStamp();
                        lctPdtSn.create_user_id       = userId;
                        lctPdtSn.update_time          = lctPdtSn.create_time;
                        lctPdtSn.update_user_id       = userId;
                        lctPdtSn.warehouse_product_id = lctPdt.id;
                        lctPdtSn.sn                   = sn;
                        lctPdtSnDal.Insert(lctPdtSn);
                        OperLogBLL.OperLogAdd <ivt_warehouse_product_sn>(lctPdtSn, lctPdtSn.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM_SN, "取消配送产品新增库存产品串号");

                        ivt_transfer_sn tsfSn = new ivt_transfer_sn();
                        tsfSn.id             = tsfSnDal.GetNextIdCom();
                        tsfSn.sn             = sn;
                        tsfSn.transfer_id    = tsf.id;
                        tsfSn.create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                        tsfSn.create_user_id = userId;
                        tsfSn.update_time    = tsfSn.create_time;
                        tsfSn.update_user_id = userId;
                        tsfSnDal.Insert(tsfSn);
                        OperLogBLL.OperLogAdd <ivt_transfer_sn>(tsfSn, tsfSn.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM_TRANSFER_SN, "取消配送产品新增转移产品串号");
                    }
                }
            }

            return("");
        }
예제 #2
0
        /// <summary>
        /// 配送
        /// </summary>
        /// <param name="costPdtIds">成本产品id</param>
        /// <param name="isEditSaleOrder">是否修改销售订单状态</param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public string PurchaseShip(string costPdtIds, bool isEditSaleOrder, long userId)
        {
            ctt_contract_cost_product_dal cstPdtDal = new ctt_contract_cost_product_dal();
            var pdtList = cstPdtDal.FindListBySql <ctt_contract_cost_product>($"select * from ctt_contract_cost_product where id in({costPdtIds})");

            if (pdtList == null || pdtList.Count == 0)
            {
                return("");
            }

            foreach (var pdt in pdtList)
            {
                if (pdt.status_id != (int)DicEnum.CONTRACT_COST_PRODUCT_STATUS.PENDING_DISTRIBUTION)
                {
                    return("状态为“待配送”的成本产品才能配送");
                }
            }

            ctt_contract_cost_dal        costDal     = new ctt_contract_cost_dal();
            ivt_transfer_dal             tsfDal      = new ivt_transfer_dal();
            ctt_contract_dal             cttDal      = new ctt_contract_dal();
            pro_project_dal              proDal      = new pro_project_dal();
            sdk_task_dal                 tskDal      = new sdk_task_dal();
            ivt_warehouse_product_sn_dal lctPdtSnDal = new ivt_warehouse_product_sn_dal();
            ivt_transfer_sn_dal          tsfSnDal    = new ivt_transfer_sn_dal();

            foreach (var pdt in pdtList)
            {
                var pdtOld = cstPdtDal.FindById(pdt.id);
                pdt.status_id      = (int)DicEnum.CONTRACT_COST_PRODUCT_STATUS.DISTRIBUTION;
                pdt.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                pdt.shipping_time  = pdt.update_time;
                pdt.update_user_id = userId;
                cstPdtDal.Update(pdt);
                OperLogBLL.OperLogUpdate(OperLogBLL.CompareValue <ctt_contract_cost_product>(pdtOld, pdt), pdt.id, userId, DicEnum.OPER_LOG_OBJ_CATE.CTT_CONTRACT_COST_PRODUCT, "成本产品配送");

                var cost = costDal.FindById(pdt.contract_cost_id);
                var cnt  = dal.FindSignleBySql <int>($"select count(0) from ctt_contract_cost_product where contract_cost_id={pdt.contract_cost_id} and status_id<>{(int)DicEnum.CONTRACT_COST_PRODUCT_STATUS.DISTRIBUTION} and delete_time=0");
                if (cnt == 0)   // 产品全部已配送,修改成本状态
                {
                    var costOld = costDal.FindById(pdt.contract_cost_id);
                    cost.status_id      = (int)DicEnum.COST_STATUS.ALREADY_DELIVERED;
                    cost.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                    cost.update_user_id = userId;
                    costDal.Update(cost);
                    OperLogBLL.OperLogUpdate(OperLogBLL.CompareValue <ctt_contract_cost>(costOld, cost), cost.id, userId, DicEnum.OPER_LOG_OBJ_CATE.CONTRACT_COST, "修改成本状态已配送");
                }

                ivt_transfer transfer = new ivt_transfer();
                transfer.id                = tsfDal.GetNextIdCom();
                transfer.create_time       = Tools.Date.DateHelper.ToUniversalTimeStamp();
                transfer.create_user_id    = userId;
                transfer.update_time       = transfer.create_time;
                transfer.update_user_id    = userId;
                transfer.product_id        = (long)cost.product_id;
                transfer.type_id           = (int)DicEnum.INVENTORY_TRANSFER_TYPE.PROJECT;
                transfer.from_warehouse_id = (long)pdt.warehouse_id;
                transfer.quantity          = pdt.quantity;
                if (cost.contract_id != null)
                {
                    transfer.to_account_id = cttDal.FindById((long)cost.contract_id).account_id;
                }
                else if (cost.project_id != null)
                {
                    transfer.to_account_id = proDal.FindById((long)cost.project_id).account_id;
                }
                else if (cost.task_id != null)
                {
                    transfer.to_account_id = tskDal.FindById((long)cost.task_id).account_id;
                }
                transfer.to_contract_id = cost.contract_id;
                transfer.to_project_id  = cost.project_id;
                transfer.to_task_id     = cost.task_id;
                tsfDal.Insert(transfer);
                OperLogBLL.OperLogAdd <ivt_transfer>(transfer, transfer.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM_TRANSFER, "产品配送转移库存");

                // 保存库存数修改
                var lctPdt = dal.FindSignleBySql <ivt_warehouse_product>($"select * from ivt_warehouse_product where product_id={cost.product_id} and warehouse_id={(long)pdt.warehouse_id} and delete_time=0");
                if (lctPdt != null)
                {
                    var lctPdtOld = dal.FindById(lctPdt.id);
                    lctPdt.quantity       = lctPdt.quantity - pdt.quantity;
                    lctPdt.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                    lctPdt.update_user_id = userId;
                    dal.Update(lctPdt);
                    OperLogBLL.OperLogUpdate(OperLogBLL.CompareValue <ivt_warehouse_product>(lctPdtOld, lctPdt), lctPdt.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM, "修改库存产品库存数");

                    var sns = costDal.FindListBySql <string>($"select sn from ctt_contract_cost_product_sn where contract_cost_product_id={pdt.id} and delete_time=0");
                    if (sns == null || sns.Count == 0)
                    {
                        continue;
                    }

                    foreach (var sn in sns)
                    {
                        var lctPdtSn = lctPdtSnDal.FindSignleBySql <ivt_warehouse_product_sn>($"select * from ivt_warehouse_product_sn where sn='{sn}' and warehouse_product_id={lctPdt.id}");
                        lctPdtSn.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                        lctPdtSn.delete_user_id = userId;
                        lctPdtSnDal.Update(lctPdtSn);
                        OperLogBLL.OperLogDelete <ivt_warehouse_product_sn>(lctPdtSn, lctPdtSn.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM_SN, "配送产品删除库存产品串号");

                        ivt_transfer_sn tsfSn = new ivt_transfer_sn();
                        tsfSn.id             = tsfSnDal.GetNextIdCom();
                        tsfSn.sn             = sn;
                        tsfSn.transfer_id    = transfer.id;
                        tsfSn.create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
                        tsfSn.create_user_id = userId;
                        tsfSn.update_time    = tsfSn.create_time;
                        tsfSn.update_user_id = userId;
                        tsfSnDal.Insert(tsfSn);
                        OperLogBLL.OperLogAdd <ivt_transfer_sn>(tsfSn, tsfSn.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM_TRANSFER_SN, "配送产品新增转移产品串号");
                    }
                }
            }

            return("");
        }