Ejemplo n.º 1
0
        public void RecordBillTransaction(PlannedBill plannedBill, ActingBill actingBill, LocationLotDetail locationLotDetail, User user)
        {
            #region 记BillTransaction
            DateTime dateTimeNow = DateTime.Now;

            BillTransaction billTransaction = new BillTransaction();
            billTransaction.OrderNo = plannedBill.OrderNo;
            billTransaction.ExternalReceiptNo = plannedBill.ExternalReceiptNo;
            billTransaction.ReceiptNo = plannedBill.ReceiptNo;
            billTransaction.Item = plannedBill.Item.Code;
            billTransaction.ItemDescription = plannedBill.Item.Description;
            billTransaction.Uom = plannedBill.Uom.Code;
            billTransaction.BillAddress = plannedBill.BillAddress.Code;
            billTransaction.BillAddressDescription = plannedBill.BillAddress.Address;
            billTransaction.Party = plannedBill.BillAddress.Party.Code;
            billTransaction.PartyName = plannedBill.BillAddress.Party.Name;
            billTransaction.Qty = plannedBill.CurrentActingQty;
            billTransaction.EffectiveDate = DateTime.Parse(dateTimeNow.ToShortDateString());   //仅保留年月日;
            billTransaction.TransactionType = plannedBill.TransactionType;
            billTransaction.PlannedBill = plannedBill.Id;
            billTransaction.CreateUser = user.Code;
            billTransaction.CreateDate = dateTimeNow;
            billTransaction.ActingBill = actingBill.Id;
            billTransaction.LocationFrom = plannedBill.LocationFrom;
            billTransaction.PartyFrom = plannedBill.PartyFrom;
            billTransaction.IpNo = plannedBill.IpNo;
            billTransaction.ReferenceItemCode = plannedBill.ReferenceItemCode;
            if (locationLotDetail != null)
            {
                billTransaction.Location = locationLotDetail.Location.Code;
                billTransaction.LocationName = locationLotDetail.Location.Name;
                billTransaction.HuId = locationLotDetail.Hu != null ? locationLotDetail.Hu.HuId : string.Empty;
                billTransaction.LotNo = locationLotDetail.LotNo;
                billTransaction.BatchNo = locationLotDetail.Id;
            }

            this.CreateBillTransaction(billTransaction);
            #endregion
        }
Ejemplo n.º 2
0
        private LocationLotDetail CreateNewLocationLotDetail(Item item, Location location, string huId, string lotNo, decimal qty, bool isCS, PlannedBill plannedBill, IList<InventoryTransaction> inventoryTransactionList, User user, string refLoc)
        {
            #region �Ƿ���������
            if (!location.AllowNegativeInventory && qty < 0)
            {
                throw new BusinessErrorException("Location.Error.NotAllowNegativeInventory", location.Code);
            }
            #endregion

            #region �������&�ɹ����������������
            if (item.Type != BusinessConstants.CODE_MASTER_ITEM_TYPE_VALUE_P && item.Type != BusinessConstants.CODE_MASTER_ITEM_TYPE_VALUE_M)
            {
                throw new BusinessErrorException("Location.Error.ItemTypeNotValid", item.Type);
            }
            #endregion

            bool isBillSettled = false;
            #region �ջ�����/������
            if (isCS && (plannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_RECEIVING_SETTLEMENT
                        || (location.IsSettleConsignment
                            && (plannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING
                                || plannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING))))
            {
                plannedBill.CurrentActingQty = qty / plannedBill.UnitQty;
                this.billMgr.CreateActingBill(plannedBill, user);

                isCS = false;
                isBillSettled = true;
            }
            #endregion

            DateTime createDate = DateTime.Now;

            LocationLotDetail newLocationLotDetail = new LocationLotDetail();
            newLocationLotDetail.Item = item;
            newLocationLotDetail.Location = location;
            newLocationLotDetail.LotNo = lotNo;
            if (huId != null && huId != string.Empty)
            {
                huId = huId.ToUpper();
                newLocationLotDetail.Hu = this.huMgr.LoadHu(huId);

                //��������������ϵ������в��죬���������ϵ�����
                if (newLocationLotDetail.Hu.Qty * newLocationLotDetail.Hu.UnitQty != qty)
                {
                    newLocationLotDetail.Hu.Qty = qty / newLocationLotDetail.Hu.UnitQty;
                }
                newLocationLotDetail.Hu.Location = location.Code;
                newLocationLotDetail.Hu.Status = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_INVENTORY;

                this.huMgr.UpdateHu(newLocationLotDetail.Hu);
            }
            newLocationLotDetail.CreateDate = createDate;
            newLocationLotDetail.Qty = qty;
            newLocationLotDetail.IsConsignment = isCS;
            if (plannedBill != null)
            {
                newLocationLotDetail.PlannedBill = plannedBill.Id;
            }

            newLocationLotDetail.RefLocation = refLoc;

            this.locationLotDetailMgr.CreateLocationLotDetail(newLocationLotDetail);
            inventoryTransactionList.Add(InventoryTransactionHelper.CreateInventoryTransaction(newLocationLotDetail, qty, isBillSettled));

            return newLocationLotDetail;
        }
Ejemplo n.º 3
0
        private void BackFlushInventory(IList<LocationLotDetail> backFlushLocLotDetList, ref decimal qtyIn, IList<InventoryTransaction> inventoryTransactionList, PlannedBill plannedBill, User user, string transType)
        {
            if (backFlushLocLotDetList != null && backFlushLocLotDetList.Count > 0)
            {
                foreach (LocationLotDetail backFlushLocLotDet in backFlushLocLotDetList)
                {
                    PlannedBill backFlushPlannedBill = backFlushLocLotDet.IsConsignment ? this.plannedBillMgr.LoadPlannedBill(backFlushLocLotDet.PlannedBill.Value) : null;

                    #region ֻ�з����ڰ����뷢�����������ջ����������Ϊ��Щ���س�Ŀ���Ѿ�����һ�������������Ͳ������س��ˡ�
                    if (backFlushLocLotDet.Qty == 0)
                    {
                        continue;
                    }
                    #endregion

                    #region �ж��Ƿ�����س�����
                    if (qtyIn == 0)
                    {
                        return;
                    }

                    //������س�����Ķ��Ǽ��ۿ�沢����ͬһ����Ӧ�̣�һ��Ҫ�س�
                    if (backFlushLocLotDet.IsConsignment && plannedBill != null
                        && backFlushPlannedBill.BillAddress.Code == plannedBill.BillAddress.Code)
                    {

                    }
                    else
                    {
                        //���س�ļ��ۿ�棬�����ļ��ۿ�治��һ����Ӧ�̣����ܻس�
                        if (backFlushLocLotDet.IsConsignment && plannedBill != null
                            && backFlushPlannedBill.BillAddress.Code != plannedBill.BillAddress.Code)
                        {
                            return;
                        }

                        //���س�ļ��ۿ��Ľ��㷽ʽ�����߽��㣬�ж��Ƿ�ǰ���������Ƿ���ISS-*�������㲻�ܻس�
                        //if (backFlushLocLotDet.IsConsignment
                        //    && backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING)
                        //{
                        //    if (!transType.StartsWith("ISS-"))
                        //    {
                        //        return;
                        //    }
                        //}

                        //���س�ļ��ۿ��Ľ��㷽ʽ�����߽��㣬�ж��Ƿ�ǰ���������Ƿ���ISS-*���Ҳ�����ISS-TR�������㲻�ܻس�
                        //if (backFlushLocLotDet.IsConsignment
                        //   && backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING)
                        //{
                        //    if (!(transType.StartsWith("ISS-") && transType != BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR))
                        //    {
                        //        return;
                        //    }
                        //}
                    }
                    #endregion

                    #region �س���
                    decimal currentBFQty = 0; //���λس���
                    if (qtyIn > 0)
                    {
                        if (backFlushLocLotDet.Qty + qtyIn < 0)
                        {
                            //��������� < ���������ȫ���س壬�س��������ڱ��������
                            currentBFQty = qtyIn;
                        }
                        else
                        {
                            //��������� >= ��������������Ŀ�����س�
                            currentBFQty = 0 - backFlushLocLotDet.Qty;
                        }
                    }
                    else
                    {
                        if (backFlushLocLotDet.Qty + qtyIn > 0)
                        {
                            //���γ����� < ���������ȫ���س壬�س��������ڱ��γ�����
                            currentBFQty = qtyIn;
                        }
                        else
                        {
                            //���γ����� >= ��������������Ŀ�����س�
                            currentBFQty = 0 - backFlushLocLotDet.Qty;
                        }
                    }

                    //���¿������
                    backFlushLocLotDet.Qty += currentBFQty;
                    this.locationLotDetailMgr.UpdateLocationLotDetail(backFlushLocLotDet);

                    #endregion

                    #region ����
                    bool isBillSettled = false;
                    //ֻ�г���(qtyIn < 0 && plannedBill == null)�س���ۿ��(backFlushLocLotDet.IsConsignment == true)�Ű���SettleTerm����
                    //�������������������
                    if (qtyIn < 0 && plannedBill == null && backFlushLocLotDet.IsConsignment)
                    {
                        if (
                            //(backFlushPlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING   //���߽��������������ƿ��������Ž��㣬���Ա����ջ�����ʱ������λ�ͽ���
                            //&& (transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR
                            //        || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_MATERIAL_IN))
                            //||
                            (backFlushPlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING   //���߽�������
                                && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO)
                            //|| (backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION         //��������������Ӽ����λ���⣬���ҷ���ISS-INP����
                            //    && backFlushLocLotDet.Location.Code == BusinessConstants.SYSTEM_LOCATION_INSPECT
                            //        && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_INP)
                            //|| (backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION         //������㣬�Ӳ��ϸ�Ʒ��λ���⣬��������
                            //    && backFlushLocLotDet.Location.Code == BusinessConstants.SYSTEM_LOCATION_REJECT)
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_UNP                              //�������ISS_UNP����CYC_CNT����ǿ�н���
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_CYC_CNT
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_SO
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO
                            || transType.StartsWith(BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT))
                        {
                            //���ۿ����Ҫ���н��㣬�Ա��س�Ŀ����и�������
                            backFlushPlannedBill.CurrentActingQty = (0 - currentBFQty) / backFlushPlannedBill.UnitQty; //����������
                            this.billMgr.CreateActingBill(backFlushPlannedBill, backFlushLocLotDet, user);
                            isBillSettled = true;
                        }
                    }
                    else
                    {
                        if (backFlushLocLotDet.IsConsignment)
                        {
                            //���ۿ����Ҫ���н��㣬�Ա��س�Ŀ����и�������
                            backFlushPlannedBill.CurrentActingQty = (0 - currentBFQty) / backFlushPlannedBill.UnitQty; //����������
                            this.billMgr.CreateActingBill(backFlushPlannedBill, backFlushLocLotDet, user);
                            isBillSettled = true;
                        }

                        if (plannedBill != null)
                        {
                            //�����Ŀ����н���
                            plannedBill.CurrentActingQty = currentBFQty / plannedBill.UnitQty;  //����������
                            this.billMgr.CreateActingBill(plannedBill, user);
                        }
                    }
                    #endregion

                    //��¼���س�ļ�¼
                    inventoryTransactionList.Add(InventoryTransactionHelper.CreateInventoryTransaction(backFlushLocLotDet, currentBFQty, isBillSettled));

                    qtyIn -= currentBFQty;
                }
            }
        }
 public IList<LocationLotDetail> GetLocationLotDetail(PlannedBill plannedBill)
 {
     return GetLocationLotDetail(plannedBill.Id);
 }
Ejemplo n.º 5
0
 public ActingBill CreateActingBill(PlannedBill plannedBill, User user)
 {
     return CreateActingBill(plannedBill, null, user);
 }
 public virtual void DeletePlannedBill(PlannedBill entity)
 {
     Delete(entity);
 }
Ejemplo n.º 7
0
        private void BackFlushInventory(IList<LocationLotDetail> backFlushLocLotDetList, ref decimal qtyIn, IList<InventoryTransaction> inventoryTransactionList, PlannedBill plannedBill, User user, string transType)
        {
            if (backFlushLocLotDetList != null && backFlushLocLotDetList.Count > 0)
            {
                foreach (LocationLotDetail backFlushLocLotDet in backFlushLocLotDetList)
                {
                    PlannedBill backFlushPlannedBill = backFlushLocLotDet.IsConsignment ? this.plannedBillMgrE.LoadPlannedBill(backFlushLocLotDet.PlannedBill.Value) : null;

                    #region 只有发生在按条码发货,按数量收货的情况,因为有些待回冲的库存已经被上一个条码冲掉,这里就不继续回冲了。
                    if (backFlushLocLotDet.Qty == 0)
                    {
                        continue;
                    }
                    #endregion

                    #region 判断是否满足回冲条件
                    if (qtyIn == 0)
                    {
                        return;
                    }

                    //如果被回冲和入库的都是寄售库存并且是同一个供应商,一定要回冲
                    if (backFlushLocLotDet.IsConsignment && plannedBill != null
                        && backFlushPlannedBill.BillAddress.Code == plannedBill.BillAddress.Code)
                    {

                    }
                    else
                    {
                        //被回冲的寄售库存,和入库的寄售库存不是一个供应商,不能回冲
                        if (backFlushLocLotDet.IsConsignment && plannedBill != null
                            && backFlushPlannedBill.BillAddress.Code != plannedBill.BillAddress.Code)
                        {
                            return;
                        }

                        //被回冲的寄售库存的结算方式是上线结算,判断是否当前事务类型是否是ISS-*,不满足不能回冲
                        //if (backFlushLocLotDet.IsConsignment
                        //    && backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING)
                        //{
                        //    if (!transType.StartsWith("ISS-"))
                        //    {
                        //        return;
                        //    }
                        //}

                        //被回冲的寄售库存的结算方式是下线结算,判断是否当前事务类型是否是ISS-*并且不等于ISS-TR,不满足不能回冲
                        //if (backFlushLocLotDet.IsConsignment
                        //   && backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING)
                        //{
                        //    if (!(transType.StartsWith("ISS-") && transType != BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR))
                        //    {
                        //        return;
                        //    }
                        //}
                    }
                    #endregion

                    #region 回冲库存
                    decimal currentBFQty = 0; //本次回冲数
                    if (qtyIn > 0)
                    {
                        if (backFlushLocLotDet.Qty + qtyIn < 0)
                        {
                            //本次入库数 < 库存数量,全部回冲,回冲数量等于本次入库数
                            currentBFQty = qtyIn;
                        }
                        else
                        {
                            //本次入库数 >= 库存数量,按负的库存数回冲
                            currentBFQty = 0 - backFlushLocLotDet.Qty;
                        }
                    }
                    else
                    {
                        if (backFlushLocLotDet.Qty + qtyIn > 0)
                        {
                            //本次出库数 < 库存数量,全部回冲,回冲数量等于本次出库数
                            currentBFQty = qtyIn;
                        }
                        else
                        {
                            //本次出库数 >= 库存数量,按正的库存数回冲
                            currentBFQty = 0 - backFlushLocLotDet.Qty;
                        }
                    }

                    //更新库存数量
                    backFlushLocLotDet.Qty += currentBFQty;
                    this.locationLotDetailMgrE.UpdateLocationLotDetail(backFlushLocLotDet);

                    #endregion

                    #region 结算
                    bool isBillSettled = false;
                    //只有出库(qtyIn < 0 && plannedBill == null)回冲寄售库存(backFlushLocLotDet.IsConsignment == true)才按照SettleTerm结算
                    //其它情况都是立即结算
                    if (qtyIn < 0 && plannedBill == null && backFlushLocLotDet.IsConsignment)
                    {
                        if (backFlushPlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING   //上线结算条件
                            || (backFlushPlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING   //下线结算条件
                                && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO)
                            //|| (backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION         //检验结算条件,从检验库位出库,并且发生ISS-INP事务
                            //    && backFlushLocLotDet.Location.Code == BusinessConstants.SYSTEM_LOCATION_INSPECT
                            //        && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_INP)
                            //|| (backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION         //检验结算,从不合格品库位出库,立即结算
                            //    && backFlushLocLotDet.Location.Code == BusinessConstants.SYSTEM_LOCATION_REJECT)
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_UNP                              //如果发生ISS_UNP或者CYC_CNT事务,强行结算
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_CYC_CNT
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_SO
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO
                            || transType.StartsWith(BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT))
                        {
                            //寄售库存需要进行结算,对被回冲的库存进行负数结算
                            backFlushPlannedBill.CurrentActingQty = (0 - currentBFQty) / backFlushPlannedBill.UnitQty; //按负数结算
                            this.billMgrE.CreateActingBill(backFlushPlannedBill, backFlushLocLotDet, user);
                            isBillSettled = true;
                        }
                    }
                    else
                    {
                        if (backFlushLocLotDet.IsConsignment)
                        {
                            //寄售库存需要进行结算,对被回冲的库存进行负数结算
                            backFlushPlannedBill.CurrentActingQty = (0 - currentBFQty) / backFlushPlannedBill.UnitQty; //按负数结算
                            this.billMgrE.CreateActingBill(backFlushPlannedBill, backFlushLocLotDet, user);
                            isBillSettled = true;
                        }

                        if (plannedBill != null)
                        {
                            //对入库的库存进行结算
                            plannedBill.CurrentActingQty = currentBFQty / plannedBill.UnitQty;  //按正数结算
                            this.billMgrE.CreateActingBill(plannedBill, user);
                        }
                    }
                    #endregion

                    //记录被回冲的记录
                    inventoryTransactionList.Add(InventoryTransactionHelper.CreateInventoryTransaction(backFlushLocLotDet, currentBFQty, isBillSettled));

                    qtyIn -= currentBFQty;
                }
            }
        }
Ejemplo n.º 8
0
 public virtual void DeletePlannedBill(PlannedBill entity)
 {
     entityDao.DeletePlannedBill(entity);
 }
        public PlannedBill CreatePlannedBill(ReceiptDetail receiptDetail, User user)
        {
            Receipt receipt = receiptDetail.Receipt;

            OrderLocationTransaction orderLocationTransaction = receiptDetail.OrderLocationTransaction;
            OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
            OrderHead orderHead = orderDetail.OrderHead;

            //DateTime dateTimeNow = DateTime.Now;
            //decimal plannedAmount = 0;

            PlannedBill plannedBill = new PlannedBill();
            plannedBill.OrderNo = orderHead.OrderNo;
            plannedBill.ExternalReceiptNo = receipt.ExternalReceiptNo;        //记录客户回单号
            plannedBill.ReceiptNo = receipt.ReceiptNo;
            plannedBill.Item = orderDetail.Item;
            plannedBill.SettleTerm = orderDetail.DefaultBillSettleTerm;
            plannedBill.PlannedQty =
                receiptDetail.ReceivedQty.HasValue ? receiptDetail.ReceivedQty.Value : 0;         //设置待结算数量默认值
            plannedBill.Uom = orderDetail.Uom;                                                  //单位为订单单位
            plannedBill.UnitCount = orderDetail.UnitCount;
            plannedBill.UnitQty = orderLocationTransaction.UnitQty;                                 //UnitQty沿用OrderLocationTransaction
            plannedBill.PlannedAmount = receiptDetail.PlannedAmount;
            plannedBill.CreateDate = receipt.CreateDate;
            plannedBill.CreateUser = user;
            plannedBill.LastModifyDate = receipt.CreateDate;
            plannedBill.LastModifyUser = user;
            plannedBill.IsAutoBill = orderHead.IsAutoBill;
            plannedBill.HuId = receiptDetail.HuId;
            plannedBill.LotNo = receiptDetail.LotNo;
            if (orderLocationTransaction.Location != null)
            {
                plannedBill.LocationFrom = orderLocationTransaction.Location.Code;
            }
            plannedBill.IpNo = receipt.ReferenceIpNo;
            plannedBill.ReferenceItemCode = orderDetail.ReferenceItemCode;

            //plannedBill.BillAddress = orderDetail.DefaultBillAddress;
            plannedBill.PriceList = orderDetail.DefaultPriceList;
            plannedBill.IsProvisionalEstimate =      //暂估价格处理,没有找到价格也认为是暂估价格
                     orderDetail.UnitPrice.HasValue ? orderDetail.IsProvisionalEstimate : true;
            plannedBill.ListPrice = orderDetail.UnitPrice.HasValue ? orderDetail.UnitPrice.Value : 0;
            plannedBill.UnitPrice = orderDetail.IncludeTaxPrice;
            plannedBill.PlannedAmount = orderDetail.IncludeTaxPrice * plannedBill.PlannedQty;
            plannedBill.Currency = orderDetail.OrderHead.Currency;
            plannedBill.IsIncludeTax = orderDetail.IsIncludeTax;
            plannedBill.TaxCode = orderDetail.TaxCode;
            if (orderDetail.OrderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT
                || orderDetail.OrderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_SUBCONCTRACTING)
            {
                plannedBill.TransactionType = BusinessConstants.BILL_TRANS_TYPE_PO;
                plannedBill.BillAddress = orderDetail.DefaultBillFrom;
            }
            else if (orderDetail.OrderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION)
            {
                plannedBill.TransactionType = BusinessConstants.BILL_TRANS_TYPE_SO;
                plannedBill.BillAddress = orderDetail.DefaultBillTo;
            }
            else
            {
                throw new TechnicalException("Only SO and PO/SubContract can create planned bill.");
            }
 

            //if (orderDetail.Uom.Code != plannedBill.Uom.Code)
            //{
            //    //订单单位和采购单位不一致,需要更改UnitQty和PlannedQty值
            //    plannedBill.UnitQty = this.uomConversionMgrE.ConvertUomQty(orderDetail.Item, orderDetail.Uom, plannedBill.UnitQty, plannedBill.Uom);
            //    plannedBill.PlannedQty = plannedBill.PlannedQty * plannedBill.UnitQty;
            //}

            
            this.CreatePlannedBill(plannedBill);

            return plannedBill;
        }
Ejemplo n.º 10
0
        private IList<InventoryTransaction> RecordInventory(Item item, Location location, string huId, string lotNo, decimal qty, bool isCS, PlannedBill plannedBill, string transType, string refOrderNo, User user, bool needInspection, bool flushbackIgnoreHu)
        {
            IList<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            if (huId != null && huId.Trim() != string.Empty)
            {
                #region 有Hu
                //寄售/非寄售处理逻辑相同
                //不支持对已有HU做计划外入库
                if (qty > 0)
                {
                    #region 入库数量 > 0
                    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetHuLocationLotDetail(location.Code, huId);
                    if (locationLotDetailList != null && locationLotDetailList.Count > 0)
                    {
                        //库存中已经存在相同的Hu
                        throw new BusinessErrorException("Hu.Error.HuIdAlreadyExist", huId, location.Code);
                    }
                    else
                    {
                        CreateNewLocationLotDetail(item, location, huId, lotNo, qty, isCS, plannedBill, inventoryTransactionList, user);
                    }
                    #endregion
                }
                else if (qty < 0)
                {
                    #region 入库数量 < 0 / 出库
                    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetHuLocationLotDetail(location.Code, huId);
                    if (locationLotDetailList != null && locationLotDetailList.Count > 0)
                    {
                        LocationLotDetail locationLotDetail = locationLotDetailList[0];  //如果查询到记录,只可能有一条

                        ////检查出库的Hu是否被拣货单占用
                        //if (this.IsHuOcuppyByPickList(huId))
                        //{
                        //    throw new BusinessErrorException("Order.Error.PickUp.HuOcuppied", huId);
                        //}

                        if (locationLotDetail.Qty + qty < 0)
                        {
                            //Hu中Item的数量小于出库数
                            throw new BusinessErrorException("Hu.Error.NoEnoughInventory", huId, location.Code, item.Code);
                        }

                        bool isBillSettled = false;
                        if (locationLotDetail.IsConsignment && locationLotDetail.PlannedBill.HasValue)
                        {
                            PlannedBill pb = this.plannedBillMgrE.LoadPlannedBill(locationLotDetail.PlannedBill.Value);
                            if (pb.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING   //上线结算条件
                            || (pb.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING   //下线结算条件
                                && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO)
                                //|| (locationLotDetail.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION         //检验结算条件,从检验库位出库并且ISS-INP事务
                                //    && locationLotDetail.Location.Code == BusinessConstants.SYSTEM_LOCATION_INSPECT
                                //    && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_INP)
                                //|| (locationLotDetail.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION         //检验结算,从不合格品库位出库
                                //    && locationLotDetail.Location.Code == BusinessConstants.SYSTEM_LOCATION_REJECT)
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_UNP                              //如果发生ISS_UNP或者CYC_CNT事务,强行结算
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_CYC_CNT
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_SO
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO
                            || transType.StartsWith(BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT))
                            {
                                //结算
                                //寄售库存需要进行结算,对被回冲的库存进行负数结算
                                pb.CurrentActingQty = (0 - qty) / pb.UnitQty; //按负数结算
                                this.billMgrE.CreateActingBill(pb, locationLotDetail, user);
                                isBillSettled = true;
                            }
                        }

                        //记录被回冲的记录
                        inventoryTransactionList.Add(InventoryTransactionHelper.CreateInventoryTransaction(locationLotDetail, qty, isBillSettled));

                        //更新库存数量
                        locationLotDetail.Qty += qty;
                        this.locationLotDetailMgrE.UpdateLocationLotDetail(locationLotDetail);
                    }
                    else
                    {
                        //没有找到指定的HU
                        throw new BusinessErrorException("Hu.Error.NoEnoughInventory", huId, location.Code, item.Code);
                    }
                    #endregion
                }
                #endregion
            }
            else
            {
                #region 没有Hu
                if (isCS)
                {
                    #region 寄售处理。
                    if (qty > 0)
                    {
                        #region 入库数量 > 0

                        //如果是收货后检验或者收货结算,不回冲库存。
                        if (!(needInspection
                            || plannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_RECEIVING_SETTLEMENT))
                        {
                            //#region 回冲指定收货单号的寄售库存
                            //if (refOrderNo != null && refOrderNo.Trim() != string.Empty)
                            //{
                            //    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.MINUS_INVENTORY, false, refOrderNo, flushbackIgnoreHu);
                            //    BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                            //}
                            //#endregion

                            #region 回冲寄售库存
                            if (qty > 0)
                            {
                                IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.MINUS_INVENTORY, false, flushbackIgnoreHu);
                                BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                            }
                            #endregion

                            #region 回冲非寄售库存
                            if (qty > 0)
                            {
                                IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, false, false, BusinessConstants.MINUS_INVENTORY, false, flushbackIgnoreHu);
                                BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                            }
                            #endregion
                        }

                        #region 记录库存
                        if (qty > 0)
                        {
                            CreateNewLocationLotDetail(item, location, huId, lotNo, qty, isCS, plannedBill, inventoryTransactionList, user);
                        }
                        #endregion
                        #endregion
                    }
                    else if (qty < 0)
                    {
                        #region 入库数量 < 0

                        //#region 回冲指定收货单号的寄售库存
                        //if (refOrderNo != null && refOrderNo.Trim() != string.Empty)
                        //{
                        //    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.PLUS_INVENTORY, false, refOrderNo, flushbackIgnoreHu);
                        //    BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                        //}
                        //#endregion

                        #region 回冲寄售库存
                        if (qty < 0)
                        {
                            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.PLUS_INVENTORY, false, flushbackIgnoreHu);
                            BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                        }
                        #endregion

                        #region 回冲非寄售库存
                        if (qty < 0)
                        {
                            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, false, false, BusinessConstants.PLUS_INVENTORY, false, flushbackIgnoreHu);
                            BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                        }
                        #endregion

                        #region 记录库存
                        if (qty < 0)
                        {
                            CreateNewLocationLotDetail(item, location, huId, lotNo, qty, isCS, plannedBill, inventoryTransactionList, user);
                        }
                        #endregion
                        #endregion
                    }
                    #endregion
                }
                else
                {
                    #region 非寄售处理
                    if (qty > 0)
                    {
                        #region 入库数量 > 0

                        //收货后检验的不能回冲库存
                        if (!needInspection)
                        {
                            #region 回冲非寄售库存
                            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, false, false, BusinessConstants.MINUS_INVENTORY, false, flushbackIgnoreHu);
                            BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, null, user, transType);
                            #endregion
                        }

                        #region 记录库存
                        if (qty > 0)
                        {
                            CreateNewLocationLotDetail(item, location, huId, lotNo, qty, isCS, null, inventoryTransactionList, user);
                        }
                        #endregion
                        #endregion
                    }
                    else if (qty < 0)
                    {
                        #region 入库数量 < 0
                        #region 回冲非寄售库存
                        if (qty < 0)
                        {
                            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, false, false, BusinessConstants.PLUS_INVENTORY, false, flushbackIgnoreHu);
                            BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, null, user, transType);
                        }
                        #endregion

                        #region 回冲寄售库存
                        if (qty < 0)
                        {
                            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.PLUS_INVENTORY, false, flushbackIgnoreHu);
                            BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, null, user, transType);
                        }
                        #endregion

                        #region 记录库存
                        if (qty < 0)
                        {
                            CreateNewLocationLotDetail(item, location, huId, lotNo, qty, isCS, null, inventoryTransactionList, user);
                        }
                        #endregion
                        #endregion
                    }
                    #endregion
                }
                #endregion
            }

            return inventoryTransactionList;
        }
Ejemplo n.º 11
0
        public PlannedBill CreatePlannedBill(ReceiptDetail receiptDetail, User user)
        {
            Receipt receipt = receiptDetail.Receipt;

            OrderLocationTransaction orderLocationTransaction = receiptDetail.OrderLocationTransaction;
            OrderDetail orderDetail = orderLocationTransaction.OrderDetail;
            OrderHead orderHead = orderDetail.OrderHead;

            //DateTime dateTimeNow = DateTime.Now;
            //decimal plannedAmount = 0;

            PlannedBill plannedBill = new PlannedBill();
            plannedBill.OrderNo = orderHead.OrderNo;
            plannedBill.ExternalReceiptNo = receipt.ExternalReceiptNo;        //��¼�ͻ��ص���
            plannedBill.ReceiptNo = receipt.ReceiptNo;
            plannedBill.Item = orderDetail.Item;
            plannedBill.SettleTerm = orderDetail.DefaultBillSettleTerm;
            plannedBill.PlannedQty =
                receiptDetail.ReceivedQty.HasValue ? receiptDetail.ReceivedQty.Value : 0;         //���ô���������Ĭ��ֵ
            plannedBill.Uom = orderDetail.Uom;                                                  //��λΪ������λ
            plannedBill.UnitCount = orderDetail.UnitCount;
            plannedBill.UnitQty = orderLocationTransaction.UnitQty;                                 //UnitQty����OrderLocationTransaction
            plannedBill.CreateDate = receipt.CreateDate;
            plannedBill.CreateUser = user;
            plannedBill.LastModifyDate = receipt.CreateDate;
            plannedBill.LastModifyUser = user;
            plannedBill.EffectiveDate = receipt.CreateDate;
            plannedBill.PlannedAmount = receiptDetail.PlannedAmount;
            plannedBill.IsAutoBill = orderHead.IsAutoBill;
            plannedBill.HuId = receiptDetail.HuId;
            plannedBill.LotNo = receiptDetail.LotNo;
            if (orderLocationTransaction.Location != null)
            {
                plannedBill.LocationFrom = orderLocationTransaction.Location.Code;
                //Ϊ��֧�ֶ�site
                //����Dz��ϸ�Ʒ��λ����Ҫ�ڼ�¼PartyFrom���Ӷ�ͨ��PartyFrom��QAD���ҵ���Ӧ��QC��λ
                if (plannedBill.LocationFrom == BusinessConstants.SYSTEM_LOCATION_REJECT)
                {
                    plannedBill.PartyFrom = orderHead.PartyTo.Code;
                }
            }
            plannedBill.IpNo = receipt.ReferenceIpNo;
            plannedBill.ReferenceItemCode = orderDetail.ReferenceItemCode;

            if (orderDetail.OrderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT
                || orderDetail.OrderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_SUBCONCTRACTING)
            {
                plannedBill.TransactionType = BusinessConstants.BILL_TRANS_TYPE_PO;
                plannedBill.BillAddress = orderDetail.DefaultBillFrom;
                plannedBill.PriceList = orderDetail.DefaultPriceListFrom;
                plannedBill.IsProvisionalEstimate =      //�ݹ��۸����û���ҵ��۸�Ҳ��Ϊ���ݹ��۸�
                         orderDetail.PriceListDetailFrom != null ? orderDetail.PriceListDetailFrom.IsProvisionalEstimate : true;

                //plannedAmount = orderDetail.TotalAmountFrom.HasValue ? orderDetail.TotalAmountFrom.Value : 0;
                if (orderDetail.PriceListDetailFrom != null)
                {
                    //�ҵ��۸�
                    plannedBill.UnitPrice = orderDetail.PriceListDetailFrom.UnitPrice;
                    plannedBill.Currency = orderDetail.PriceListDetailFrom.Currency;
                    plannedBill.IsIncludeTax = orderDetail.PriceListDetailFrom.IsIncludeTax;
                    plannedBill.TaxCode = orderDetail.PriceListDetailFrom.TaxCode;
                }
                else
                {
                    //û���ҵ��۸�
                    plannedBill.UnitPrice = 0;
                    plannedBill.Currency = orderDetail.OrderHead.Currency;
                }
            }
            else if (orderDetail.OrderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION)
            {
                plannedBill.TransactionType = BusinessConstants.BILL_TRANS_TYPE_SO;
                plannedBill.BillAddress = orderDetail.DefaultBillTo;
                plannedBill.PriceList = orderDetail.DefaultPriceListTo;
                plannedBill.IsProvisionalEstimate =     //�ݹ��۸����û���ҵ��۸�Ҳ��Ϊ���ݹ��۸�
                orderDetail.PriceListDetailTo != null ? orderDetail.PriceListDetailTo.IsProvisionalEstimate : true;
                #region ��Ч����ȡasn����������
                if (receipt.InProcessLocations != null && receipt.InProcessLocations.Count > 0)
                {
                    plannedBill.EffectiveDate = DateTime.Parse(receipt.InProcessLocations[0].CreateDate.ToShortDateString());
                }

                #endregion

                //plannedAmount = orderDetail.TotalAmountTo.HasValue ? orderDetail.TotalAmountTo.Value : 0;
                if (orderDetail.PriceListDetailTo != null)
                {
                    //�ҵ��۸�
                    plannedBill.UnitPrice = orderDetail.PriceListDetailTo.UnitPrice;
                    plannedBill.Currency = orderDetail.PriceListDetailTo.Currency;
                    plannedBill.IsIncludeTax = orderDetail.PriceListDetailTo.IsIncludeTax;
                    plannedBill.TaxCode = orderDetail.PriceListDetailTo.TaxCode;
                }
                else
                {
                    //û���ҵ��۸�
                    plannedBill.UnitPrice = 0;
                    plannedBill.Currency = orderDetail.OrderHead.Currency;
                }
            }
            else
            {
                throw new TechnicalException("Only SO and PO/SubContract can create planned bill.");
            }

            //if (orderDetail.Uom.Code != plannedBill.Uom.Code)
            //{
            //    //������λ�Ͳɹ���λ��һ�£���Ҫ����UnitQty��PlannedQtyֵ
            //    plannedBill.UnitQty = this.uomConversionMgr.ConvertUomQty(orderDetail.Item, orderDetail.Uom, plannedBill.UnitQty, plannedBill.Uom);
            //    plannedBill.PlannedQty = plannedBill.PlannedQty * plannedBill.UnitQty;
            //}

            this.CreatePlannedBill(plannedBill);

            return plannedBill;
        }
Ejemplo n.º 12
0
        private ActingBill RetriveActingBill(PlannedBill plannedBill, DateTime dateTimeNow, User user)
        {

            DateTime effectiveDate = DateTime.Parse(dateTimeNow.ToShortDateString());   //仅保留年月日

            DetachedCriteria criteria = DetachedCriteria.For<ActingBill>();

            criteria.Add(Expression.Eq("OrderHead.OrderNo", plannedBill.OrderNo));
            if (plannedBill.ExternalReceiptNo != null)
            {
                criteria.Add(Expression.Eq("ExternalReceiptNo", plannedBill.ExternalReceiptNo));
            }
            else
            {
                criteria.Add(Expression.IsNull("ExternalReceiptNo"));
            }
            criteria.Add(Expression.Eq("ReceiptNo", plannedBill.ReceiptNo));
            criteria.Add(Expression.Eq("TransactionType", plannedBill.TransactionType));
            criteria.Add(Expression.Eq("Item", plannedBill.Item));
            criteria.Add(Expression.Eq("BillAddress", plannedBill.BillAddress));
            criteria.Add(Expression.Eq("Uom", plannedBill.Uom));
            criteria.Add(Expression.Eq("UnitCount", plannedBill.UnitCount));
            criteria.Add(Expression.Eq("PriceList", plannedBill.PriceList));
            criteria.Add(Expression.Eq("UnitPrice", plannedBill.UnitPrice));
            criteria.Add(Expression.Eq("Currency", plannedBill.Currency));
            criteria.Add(Expression.Eq("IsIncludeTax", plannedBill.IsIncludeTax));
            if (plannedBill.TaxCode != null)
            {
                criteria.Add(Expression.Eq("TaxCode", plannedBill.TaxCode));
            }
            else
            {
                criteria.Add(Expression.IsNull("TaxCode"));
            }

            if (plannedBill.LocationFrom != null)
            {
                criteria.Add(Expression.Eq("LocationFrom", plannedBill.LocationFrom));
            }
            else
            {
                criteria.Add(Expression.IsNull("LocationFrom"));
            }

            criteria.Add(Expression.Eq("IsProvisionalEstimate", plannedBill.IsProvisionalEstimate));
            criteria.Add(Expression.Eq("EffectiveDate", effectiveDate));

            IList<ActingBill> actingBillList = this.criteriaMgrE.FindAll<ActingBill>(criteria);

            ActingBill actingBill = null;
            if (actingBillList.Count == 0)
            {
                actingBill = new ActingBill();
                CloneHelper.CopyProperty(plannedBill, actingBill, PlannedBill2ActingBillCloneField);
                OrderHead orderHead = new OrderHead();
                orderHead.OrderNo = plannedBill.OrderNo;
                actingBill.OrderHead = orderHead;
                actingBill.EffectiveDate = effectiveDate;
                actingBill.CreateUser = user;
                actingBill.CreateDate = dateTimeNow;
            }
            else if (actingBillList.Count == 1)
            {
                actingBill = actingBillList[0];
            }
            else
            {
                throw new TechnicalException("Acting bill record consolidate error, find target acting bill number great than 1.");
            }


            actingBill.BillQty += plannedBill.CurrentActingQty;
            if (actingBill.BillQty != actingBill.BilledQty)
            {
                actingBill.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE;
            }
            else
            {
                actingBill.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE;
            }
            actingBill.LastModifyUser = user;
            actingBill.LastModifyDate = dateTimeNow;
            return actingBill;
        }
Ejemplo n.º 13
0
        public ActingBill CreateActingBill(PlannedBill plannedBill, LocationLotDetail locationLotDetail, User user)
        {

            PlannedBill oldPlannedBill = plannedBillMgrE.LoadPlannedBill(plannedBill.Id);
            oldPlannedBill.CurrentActingQty = plannedBill.CurrentActingQty;

            //检验,已结算数+本次结算数不能大于总结算数量,可能有负数结算,所以要用绝对值比较
            if (!oldPlannedBill.ActingQty.HasValue)
            {
                oldPlannedBill.ActingQty = 0;
            }
            if (Math.Abs(oldPlannedBill.ActingQty.Value + oldPlannedBill.CurrentActingQty) > Math.Abs(oldPlannedBill.PlannedQty))
            {
                throw new BusinessErrorException("PlannedBill.Error.ActingQtyExceed");
            }

            DateTime dateTimeNow = DateTime.Now;

            ActingBill actingBill = this.RetriveActingBill(oldPlannedBill, dateTimeNow, user);

            #region 计算结算金额
            decimal currentBillAmount = 0;
            if (Math.Abs(oldPlannedBill.ActingQty.Value + oldPlannedBill.CurrentActingQty) < Math.Abs(oldPlannedBill.PlannedQty))
            {
                //总结算数小于计划数,用实际单价计算待开票金额

                #region 计算实际单价
                EntityPreference entityPreference = entityPreferenceMgrE.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_AMOUNT_DECIMAL_LENGTH);
                int decimalLength = int.Parse(entityPreference.Value);
                decimal actualUnitPrice = Math.Round((oldPlannedBill.PlannedAmount / oldPlannedBill.PlannedQty), decimalLength, MidpointRounding.AwayFromZero);
                #endregion

                currentBillAmount = actualUnitPrice * oldPlannedBill.CurrentActingQty;
            }
            else
            {
                //总结算数等于计划数,先用剩余金额作为待开票金额
                if (!oldPlannedBill.ActingAmount.HasValue)
                {
                    oldPlannedBill.ActingAmount = 0;
                }
                currentBillAmount = oldPlannedBill.PlannedAmount - oldPlannedBill.ActingAmount.Value;
            }
            actingBill.BillAmount += currentBillAmount;
            #endregion

            #region 更新Planed Bill的已结算数量和金额
            if (!oldPlannedBill.ActingQty.HasValue)
            {
                oldPlannedBill.ActingQty = 0;
            }
            oldPlannedBill.ActingQty += oldPlannedBill.CurrentActingQty;

            if (!oldPlannedBill.ActingAmount.HasValue)
            {
                oldPlannedBill.ActingAmount = 0;
            }
            oldPlannedBill.ActingAmount += currentBillAmount;
            oldPlannedBill.LastModifyDate = dateTimeNow;
            oldPlannedBill.LastModifyUser = user;

            this.plannedBillMgrE.UpdatePlannedBill(oldPlannedBill);
            #endregion

            if (actingBill.Id == 0)
            {
                actingBillMgrE.CreateActingBill(actingBill);
            }
            else
            {
                actingBillMgrE.UpdateActingBill(actingBill);
            }

            #region 记BillTransaction
            billTransactionMgrE.RecordBillTransaction(plannedBill, actingBill, locationLotDetail, user);
            #endregion

            return actingBill;
        }
Ejemplo n.º 14
0
        private IList<InventoryTransaction> RecordInventory(Item item, Location location, string huId, string lotNo, decimal qty, bool isCS, PlannedBill plannedBill, string transType, string refOrderNo, User user, bool needInspection, bool flushbackIgnoreHu, string refLoc)
        {
            IList<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();

            if (huId != null && huId.Trim() != string.Empty)
            {
                #region ��Hu
                //����/�Ǽ��۴����߼���ͬ
                //��֧�ֶ�����HU���ƻ������
                if (qty > 0)
                {
                    #region ������� > 0
                    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetHuLocationLotDetail(location.Code, huId);
                    if (locationLotDetailList != null && locationLotDetailList.Count > 0)
                    {
                        //������Ѿ�������ͬ��Hu
                        throw new BusinessErrorException("Hu.Error.HuIdAlreadyExist", huId, location.Code);
                    }
                    else
                    {
                        CreateNewLocationLotDetail(item, location, huId, lotNo, qty, isCS, plannedBill, inventoryTransactionList, user, refLoc);
                    }
                    #endregion
                }
                else if (qty < 0)
                {
                    #region ������� < 0 / ����
                    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetHuLocationLotDetail(location.Code, huId);
                    if (locationLotDetailList != null && locationLotDetailList.Count > 0)
                    {
                        LocationLotDetail locationLotDetail = locationLotDetailList[0];  //�����ѯ����¼��ֻ������һ��

                        ////�������Hu�Ƿ񱻼����ռ��
                        //if (this.IsHuOcuppyByPickList(huId))
                        //{
                        //    throw new BusinessErrorException("Order.Error.PickUp.HuOcuppied", huId);
                        //}

                        if (locationLotDetail.Qty + qty < 0)
                        {
                            //Hu��Item������С�ڳ�����
                            throw new BusinessErrorException("Hu.Error.NoEnoughInventory", huId, location.Code, item.Code);
                        }

                        bool isBillSettled = false;
                        if (locationLotDetail.IsConsignment && locationLotDetail.PlannedBill.HasValue)
                        {
                            PlannedBill pb = this.plannedBillMgr.LoadPlannedBill(locationLotDetail.PlannedBill.Value);
                            if (
                                //(pb.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING   //���߽��������������ƿ��������Ž��㣬���Ա����ջ�����ʱ������λ�ͽ���
                                //&& (transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR
                                //    || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_MATERIAL_IN))
                            //||
                            (pb.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING   //���߽�������
                                && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO)
                                //|| (locationLotDetail.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION         //��������������Ӽ����λ���Ⲣ��ISS-INP����
                                //    && locationLotDetail.Location.Code == BusinessConstants.SYSTEM_LOCATION_INSPECT
                                //    && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_INP)
                                //|| (locationLotDetail.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION         //������㣬�Ӳ��ϸ�Ʒ��λ����
                                //    && locationLotDetail.Location.Code == BusinessConstants.SYSTEM_LOCATION_REJECT)
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_UNP                                   //����ISS_UNP����CYC_CNT����ǿ�н���
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_CYC_CNT
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_SO
                            || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO
                            || transType.StartsWith(BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT))
                            {
                                //����
                                //���ۿ����Ҫ���н��㣬�Ա��س�Ŀ����и�������
                                pb.CurrentActingQty = (0 - qty) / pb.UnitQty; //����������
                                this.billMgr.CreateActingBill(pb, locationLotDetail, user);
                                isBillSettled = true;
                            }
                        }

                        //��¼���س�ļ�¼
                        inventoryTransactionList.Add(InventoryTransactionHelper.CreateInventoryTransaction(locationLotDetail, qty, isBillSettled));

                        //���¿������
                        locationLotDetail.Qty += qty;
                        this.locationLotDetailMgr.UpdateLocationLotDetail(locationLotDetail);
                    }
                    else
                    {
                        //û���ҵ�ָ����HU
                        throw new BusinessErrorException("Hu.Error.NoEnoughInventory", huId, location.Code, item.Code);
                    }
                    #endregion
                }
                #endregion
            }
            else
            {
                #region û��Hu
                if (isCS)
                {
                    #region ���۴����
                    if (qty > 0)
                    {
                        #region ������� > 0

                        //������ջ����������ջ����㣬���س��档
                        if (!(needInspection
                            || plannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_RECEIVING_SETTLEMENT))
                        {
                            //#region �س�ָ���ջ����ŵļ��ۿ��
                            //if (refOrderNo != null && refOrderNo.Trim() != string.Empty)
                            //{
                            //    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.MINUS_INVENTORY, false, refOrderNo, flushbackIgnoreHu);
                            //    BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                            //}
                            //#endregion

                            #region �س���ۿ��
                            if (qty > 0)
                            {
                                IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.MINUS_INVENTORY, false, flushbackIgnoreHu);
                                BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                            }
                            #endregion

                            #region �س�Ǽ��ۿ��
                            if (qty > 0)
                            {
                                IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetLocationLotDetail(location.Code, item.Code, false, false, BusinessConstants.MINUS_INVENTORY, false, flushbackIgnoreHu);
                                BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                            }
                            #endregion
                        }

                        #region ��¼���
                        if (qty > 0)
                        {
                            CreateNewLocationLotDetail(item, location, huId, lotNo, qty, isCS, plannedBill, inventoryTransactionList, user, refLoc);
                        }
                        #endregion
                        #endregion
                    }
                    else if (qty < 0)
                    {
                        #region ������� < 0

                        //#region �س�ָ���ջ����ŵļ��ۿ��
                        //if (refOrderNo != null && refOrderNo.Trim() != string.Empty)
                        //{
                        //    IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.PLUS_INVENTORY, false, refOrderNo, flushbackIgnoreHu);
                        //    BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                        //}
                        //#endregion

                        #region �س���ۿ��
                        if (qty < 0)
                        {
                            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.PLUS_INVENTORY, false, flushbackIgnoreHu);
                            BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                        }
                        #endregion

                        #region �س�Ǽ��ۿ��
                        if (qty < 0)
                        {
                            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetLocationLotDetail(location.Code, item.Code, false, false, BusinessConstants.PLUS_INVENTORY, false, flushbackIgnoreHu);
                            BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, plannedBill, user, transType);
                        }
                        #endregion

                        #region ��¼���
                        if (qty < 0)
                        {
                            CreateNewLocationLotDetail(item, location, huId, lotNo, qty, isCS, plannedBill, inventoryTransactionList, user, refLoc);
                        }
                        #endregion
                        #endregion
                    }
                    #endregion
                }
                else
                {
                    #region �Ǽ��۴���
                    if (qty > 0)
                    {
                        #region ������� > 0

                        //�ջ������IJ��ܻس���
                        if (!needInspection)
                        {
                            #region �س�Ǽ��ۿ��
                            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetLocationLotDetail(location.Code, item.Code, false, false, BusinessConstants.MINUS_INVENTORY, false, flushbackIgnoreHu);
                            BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, null, user, transType);
                            #endregion
                        }

                        #region ��¼���
                        if (qty > 0)
                        {
                            CreateNewLocationLotDetail(item, location, huId, lotNo, qty, isCS, null, inventoryTransactionList, user,refLoc);
                        }
                        #endregion
                        #endregion
                    }
                    else if (qty < 0)
                    {
                        #region ������� < 0
                        #region �س�Ǽ��ۿ��
                        if (qty < 0)
                        {
                            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetLocationLotDetail(location.Code, item.Code, false, false, BusinessConstants.PLUS_INVENTORY, false, flushbackIgnoreHu);
                            BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, null, user, transType);
                        }
                        #endregion

                        #region �س���ۿ��
                        if (qty < 0)
                        {
                            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgr.GetLocationLotDetail(location.Code, item.Code, true, false, BusinessConstants.PLUS_INVENTORY, false, flushbackIgnoreHu);
                            BackFlushInventory(locationLotDetailList, ref qty, inventoryTransactionList, null, user, transType);
                        }
                        #endregion

                        #region ��¼���
                        if (qty < 0)
                        {
                            CreateNewLocationLotDetail(item, location, huId, lotNo, qty, isCS, null, inventoryTransactionList, user,refLoc);
                        }
                        #endregion
                        #endregion
                    }
                    #endregion
                }
                #endregion
            }

            return inventoryTransactionList;
        }
 public virtual void CreatePlannedBill(PlannedBill entity)
 {
     Create(entity);
 }
Ejemplo n.º 16
0
 public virtual void CreatePlannedBill(PlannedBill entity)
 {
     entityDao.CreatePlannedBill(entity);
 }
 public virtual void UpdatePlannedBill(PlannedBill entity)
 {
     Update(entity);
 }
Ejemplo n.º 18
0
 public virtual void UpdatePlannedBill(PlannedBill entity)
 {
     entityDao.UpdatePlannedBill(entity);
 }
Ejemplo n.º 19
0
        public ActingBill ManualCreateActingBill(PlannedBill plannedBill, LocationLotDetail locationLotDetail, User user)
        {
            IList<LocationLotDetail> locationLotDetailList = this.locationLotDetailMgrE.GetLocationLotDetail(plannedBill);

            if (locationLotDetailList != null && locationLotDetailList.Count > 0)
            {
                decimal actingQty = plannedBill.CurrentActingQty;

                foreach (LocationLotDetail currentLocationLotDetail in locationLotDetailList)
                {
                    if (actingQty > 0)
                    {
                        #region 更新库存寄售标记
                        if (actingQty - currentLocationLotDetail.Qty >= 0)
                        {
                            actingQty -= currentLocationLotDetail.Qty;
                            currentLocationLotDetail.IsConsignment = false;
                            currentLocationLotDetail.PlannedBill = null;
                        }
                        else
                        {
                            //不支持同一库存记录进行部分结算
                            throw new BusinessErrorException("Location.Error.PlannedBill.CantSplitInventory");
                        }

                        this.locationLotDetailMgrE.UpdateLocationLotDetail(currentLocationLotDetail);
                        #endregion
                    }
                    else
                    {
                        break;
                    }
                }
            }

            #region 创建ActBill
            ActingBill actingBill = this.CreateActingBill(plannedBill, locationLotDetail, user);
            #endregion

            return actingBill;
        }