Ejemplo n.º 1
0
        /// <summary>
        /// 获取发票实体列表
        /// </summary>
        /// <returns></returns>
        private List <InvoiceInfoReport> GetListInvoiceInfo()
        {
            List <InvoiceInfoReport> results = new List <InvoiceInfoReport>();

            //分页大小
            int nSplitPageSize = this.GetInvoiceInfoPageSizeByStockNo(soMaster.StockSysNo);

            //先构造未执行任何拆分的源发票实体
            InvoiceInfoReport sourceInvoiceEntity = this.CreateSourceInvoiceInfoEntity();

            //如果有发票拆分,执行发票拆分
            if (soMaster.IsMultiInvoice)
            {
                //第一次拆分:按照发票拆分规则
                List <InvoiceInfoReport> lstNewSub = this.SplitByInvoiceSub(sourceInvoiceEntity);

                //第二次拆分:按照分页大小
                lstNewSub.ForEach(x =>
                {
                    List <InvoiceInfoReport> lstNewPager = this.SplitByPageSize(x, nSplitPageSize);
                    results.AddRange(lstNewPager);
                });
            }
            else
            {
                //没有发票拆分,将延保产品的ItemNumber恢复为空值
                this.InvoiceItems_YBEmptyItemNumber();

                //执行分页拆分
                List <InvoiceInfoReport> lstNewPager = this.SplitByPageSize(sourceInvoiceEntity, nSplitPageSize);
                results.AddRange(lstNewPager);
            }
            return(results);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 计算发票明细的总金额
        /// </summary>
        /// <param name="invoiceInfo">发票</param>
        /// <returns></returns>
        private Decimal CalculateInvoiceItemSumAmt(InvoiceInfoReport invoiceInfo)
        {
            decimal resultSumAmt = 0;

            invoiceInfo.Items.ForEach(x =>
            {
                //判断不累加的Item(可得积分不累加)
                if (x.ProductType != 4)
                {
                    resultSumAmt += x.SumExtendPrice;
                }
            });

            //累加小于0,则等于0
            if (resultSumAmt < 0)
            {
                resultSumAmt = 0m;
            }

            return(resultSumAmt);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 按分页大小拆分发票实体
        /// </summary>
        /// <param name="unSplitInvoiceEntity">未拆分的发票实体</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns>已拆分的发票实体List</returns>
        private List <InvoiceInfoReport> SplitByPageSize(InvoiceInfoReport unSplitInvoiceEntity, int pageSize)
        {
            int sumSourceItemsNum = unSplitInvoiceEntity.Items.Count; //原始未拆分的Item总数
            int sumSplitPagerNum  = 1;                                //拆分的页总数

            decimal sumInvoiceSum = unSplitInvoiceEntity.InvoiceAmt;  // 源发票的总金额
            decimal subInvoiceSum = 0;                                // 累计已拆分的单张发票的总金额

            List <InvoiceInfoReport> results = new List <InvoiceInfoReport>();

            if (sumSourceItemsNum > pageSize)
            {
                //计算要拆分的总页数
                sumSplitPagerNum = (sumSourceItemsNum % pageSize == 0 ? sumSourceItemsNum / pageSize : sumSourceItemsNum / pageSize + 1);

                for (int i = 1; i <= sumSplitPagerNum; i++)
                {
                    //当前页码
                    int curPagerNum = i;

                    #region Head处理
                    //生成一个新的发票实体(只取Head部分);
                    InvoiceInfoReport newPageInvoiceInfo = new InvoiceInfoReport();

                    newPageInvoiceInfo.InvoiceCurPageNum = curPagerNum;      //修改当前页码
                    newPageInvoiceInfo.InvoiceSumPageNum = sumSplitPagerNum; //修改分页总数

                    newPageInvoiceInfo.InvoiceDate     = unSplitInvoiceEntity.InvoiceDate;
                    newPageInvoiceInfo.ServicePhone    = unSplitInvoiceEntity.ServicePhone;
                    newPageInvoiceInfo.ReceiveName     = unSplitInvoiceEntity.ReceiveName;
                    newPageInvoiceInfo.ReceivePhone    = unSplitInvoiceEntity.ReceivePhone;
                    newPageInvoiceInfo.ReceiveContact  = unSplitInvoiceEntity.ReceiveContact;
                    newPageInvoiceInfo.ReceiveAddress1 = unSplitInvoiceEntity.ReceiveAddress1;
                    newPageInvoiceInfo.ReceiveAddress2 = unSplitInvoiceEntity.ReceiveAddress2;
                    newPageInvoiceInfo.SOSysNo         = unSplitInvoiceEntity.SOSysNo;
                    newPageInvoiceInfo.CustomerSysNo   = unSplitInvoiceEntity.CustomerSysNo;
                    newPageInvoiceInfo.InvoiceNote     = unSplitInvoiceEntity.InvoiceNote;
                    newPageInvoiceInfo.PayTypeName     = unSplitInvoiceEntity.PayTypeName;
                    newPageInvoiceInfo.PayTypeSysNo    = unSplitInvoiceEntity.PayTypeSysNo;
                    newPageInvoiceInfo.InvoiceSeq      = unSplitInvoiceEntity.InvoiceSeq;
                    newPageInvoiceInfo.InvoiceSeqEx    = unSplitInvoiceEntity.InvoiceSeqEx;
                    newPageInvoiceInfo.ShipTypeName    = unSplitInvoiceEntity.ShipTypeName;
                    newPageInvoiceInfo.TotalWeight     = unSplitInvoiceEntity.TotalWeight;
                    newPageInvoiceInfo.Importance      = unSplitInvoiceEntity.Importance;
                    newPageInvoiceInfo.Items           = new List <InvoiceItem>();
                    #endregion

                    #region Item处理
                    //获取当前页面的Items
                    List <InvoiceItem> curPageItems = unSplitInvoiceEntity.Items.Skip((curPagerNum - 1) * pageSize).Take(pageSize).ToList();
                    //追加到Items
                    newPageInvoiceInfo.Items.AddRange(curPageItems);
                    #endregion

                    #region 金额处理
                    //当前拆分发票的总金额
                    decimal curInvoiceSumAmt = 0;
                    //如果是最后一张拆分票
                    if (curPagerNum == sumSplitPagerNum)
                    {
                        //当前票的金额 = 总发票金额 - 前面已经拆分的发票累计金额
                        curInvoiceSumAmt = sumInvoiceSum - subInvoiceSum;
                    }
                    else
                    {
                        //按照当前发票实体明细的计算总金额
                        curInvoiceSumAmt = this.CalculateInvoiceItemSumAmt(newPageInvoiceInfo);
                        //累计已拆分的总金额
                        subInvoiceSum += curInvoiceSumAmt;
                    }

                    //更新Head中金额相关字段
                    newPageInvoiceInfo.InvoiceAmt = curInvoiceSumAmt;
                    newPageInvoiceInfo.RMBConvert = this.GetRMBConvert(curInvoiceSumAmt);
                    #endregion

                    //ADD InvoiceInfo
                    results.Add(newPageInvoiceInfo);
                }
            }
            else
            {
                results.Add(unSplitInvoiceEntity);
            }
            return(results);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 按照发票拆分规则拆分发票实体
        /// 注意:拆分序号为1的拆分票需要增加其他费用Items,但最后输出
        /// </summary>
        /// <param name="unSplitInvoiceEntity">未拆分的发票实体</param>
        /// <returns>已拆分的发票实体List</returns>
        private List <InvoiceInfoReport> SplitByInvoiceSub(InvoiceInfoReport unSplitInvoiceEntity)
        {
            int     maxInvoiceSeq = 1;                               //最大的拆分序号,默认为1
            decimal sumInvoiceSum = unSplitInvoiceEntity.InvoiceAmt; // 源发票的总金额
            decimal subInvoiceSum = 0;                               // 累计已拆分的单张发票的总金额

            List <InvoiceInfoReport> results = new List <InvoiceInfoReport>();

            #region 获取发票拆分规则
            //获取发票拆分规则
            List <InvoiceSub> invoiceSubs = DA.GetInvoiceSub(soMaster.SOSysNo, soMaster.StockSysNo);
            //按照InvoiceSeq字段Group集合
            var groups = from u in invoiceSubs
                         group u by new { u.InvoiceSeq } into g
            select g;
            //计算最大的拆分序号
            Dictionary <int, List <InvoiceSub> > dicSeqSubs = new Dictionary <int, List <InvoiceSub> >();
            foreach (var data in groups)
            {
                dicSeqSubs.Add(data.Key.InvoiceSeq, data.ToList());
            }
            //最大拆分号 就是 dicSeqSubs.Count值
            maxInvoiceSeq = dicSeqSubs.Count;
            #endregion

            #region  InvoiceSeq分组生成拆分发票
            //拆分后新的序号,默认从1开始
            int curNewSeqNo = 1;
            //按InvoiceSeq分组生成拆分发票,为保证InvoiceSub表中序号为1的追加费用明细,倒序拆分
            for (int xhkey = dicSeqSubs.Count; xhkey > 0; xhkey--)
            {
                //当前拆分实体
                List <InvoiceSub> curSeqs = dicSeqSubs[xhkey];

                //当前拆分序号
                int curInvoiceSeq = xhkey;

                #region Head处理
                //生成一个新的发票实体(只取Head部分);
                InvoiceInfoReport newInvoiceInfo = new InvoiceInfoReport();

                newInvoiceInfo.InvoiceSeq   = curNewSeqNo;                                             //修改:InvoiceSeq
                newInvoiceInfo.InvoiceSeqEx = curNewSeqNo.ToString() + "-" + maxInvoiceSeq.ToString(); //修改:拆分序号-总拆分张数

                newInvoiceInfo.InvoiceDate       = unSplitInvoiceEntity.InvoiceDate;
                newInvoiceInfo.InvoiceSumPageNum = unSplitInvoiceEntity.InvoiceSumPageNum;
                newInvoiceInfo.InvoiceCurPageNum = unSplitInvoiceEntity.InvoiceCurPageNum;
                newInvoiceInfo.ServicePhone      = unSplitInvoiceEntity.ServicePhone;
                newInvoiceInfo.SOSysNo           = unSplitInvoiceEntity.SOSysNo;
                newInvoiceInfo.CustomerSysNo     = unSplitInvoiceEntity.CustomerSysNo;
                newInvoiceInfo.InvoiceNote       = unSplitInvoiceEntity.InvoiceNote;
                newInvoiceInfo.PayTypeName       = unSplitInvoiceEntity.PayTypeName;
                newInvoiceInfo.PayTypeSysNo      = unSplitInvoiceEntity.PayTypeSysNo;
                newInvoiceInfo.ReceiveAddress1   = unSplitInvoiceEntity.ReceiveAddress1;
                newInvoiceInfo.ReceiveAddress2   = unSplitInvoiceEntity.ReceiveAddress2;
                newInvoiceInfo.ReceiveContact    = unSplitInvoiceEntity.ReceiveContact;
                newInvoiceInfo.ReceiveName       = unSplitInvoiceEntity.ReceiveName;
                newInvoiceInfo.ReceivePhone      = unSplitInvoiceEntity.ReceivePhone;
                newInvoiceInfo.ShipTypeName      = unSplitInvoiceEntity.ShipTypeName;
                newInvoiceInfo.TotalWeight       = unSplitInvoiceEntity.TotalWeight;
                newInvoiceInfo.Importance        = unSplitInvoiceEntity.Importance;
                newInvoiceInfo.Items             = new List <InvoiceItem>();
                #endregion

                #region Items处理
                //Items处理
                //对当前Seq的拆分规则排序,以保证正常商品Item在前面,延保商品Item在后面
                var orderQuery = from o in curSeqs
                                 orderby o.IsExtendWarrantyItem
                                 select o;

                List <InvoiceItem> splitNewItems = newInvoiceInfo.Items;
                foreach (InvoiceSub splits in orderQuery.ToList <InvoiceSub>())
                {
                    //查找源明细中对应拆分项的Item
                    InvoiceItem sourceItem = null;
                    var         itemQuery  = from invoicetems in unSplitInvoiceEntity.Items
                                             where invoicetems.ItemNumberEx == splits.ProductID
                                             select invoicetems;

                    List <InvoiceItem> sourceItems = itemQuery.ToList();
                    if (sourceItems.Count > 0)
                    {
                        sourceItem = sourceItems[0];

                        //将拆分Item添加到List
                        InvoiceItem splitItem = new InvoiceItem();
                        splitItem.ItemNumber           = sourceItem.ItemNumber;
                        splitItem.Description          = sourceItem.Description;
                        splitItem.UnitPrice            = sourceItem.UnitPrice;
                        splitItem.Quantity             = splits.SplitQty;                        //取拆分数量
                        splitItem.SumExtendPrice       = sourceItem.UnitPrice * splits.SplitQty; //金额按拆分数量重新计算
                        splitItem.RepairWarrantyDays   = sourceItem.RepairWarrantyDays;
                        splitItem.ProductType          = sourceItem.ProductType;
                        splitItem.IsExtendWarrantyItem = splits.IsExtendWarrantyItem;
                        splitItem.ProductSysNo         = splits.ProductSysNo;
                        splitItem.MasterProductSysNo   = splits.MasterProductSysNo;

                        splitNewItems.Add(splitItem);
                    }
                }

                //拆分完毕后,将延保产品的ItemNumber恢复为空值
                this.InvoiceItems_YBEmptyItemNumber();
                #endregion

                #region 金额处理
                //当前拆分发票的总金额
                decimal curInvoiceSumAmt = 0;
                //如果是序号为1的拆分票,则增加运费等杂项
                if (curInvoiceSeq == 1)
                {
                    //增加费用明细项,MKT Place II需求要判断是否可添加其他费用明细项
                    if (this.IsAllowAddOtherFeesItems())
                    {
                        this.AddOtherFreesItems(ref newInvoiceInfo);
                    }

                    //当前票的金额 = 总发票金额 - 前面已经拆分的发票累计金额
                    curInvoiceSumAmt = sumInvoiceSum - subInvoiceSum;
                }
                else
                {
                    //按照当前发票实体明细计算总金额
                    curInvoiceSumAmt = this.CalculateInvoiceItemSumAmt(newInvoiceInfo);
                    //累计已拆分的总金额
                    subInvoiceSum += curInvoiceSumAmt;
                }

                //更新Head中金额相关字段
                newInvoiceInfo.InvoiceAmt = curInvoiceSumAmt;
                newInvoiceInfo.RMBConvert = this.GetRMBConvert(curInvoiceSumAmt);
                #endregion

                //ADD InvoiceInfo
                results.Add(newInvoiceInfo);

                curNewSeqNo++;
            }
            #endregion

            return(results);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 增加发票非商品款项的明细
 /// </summary>
 /// <param name="curInvoiceInfo">需要增加其他费用明细的拆分发票实体</param>
 /// <returns></returns>
 private void AddOtherFreesItems(ref InvoiceInfoReport curInvoiceInfo)
 {
     curInvoiceInfo.Items.AddRange(this.GetOtherFreesItems());
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 构造未拆分的源发票实体
        /// </summary>
        private InvoiceInfoReport CreateSourceInvoiceInfoEntity()
        {
            ECCentral.BizEntity.Invoice.InvoiceReport.InvoiceInfo invoiceInfo = DA.GetInvoicePrintHead(soMaster.SOSysNo, soMaster.StockSysNo);

            //发票总额处理(万里通/中智积分支付的特殊处理)
            if (this.soMaster.PayTypeSysNo == 47 || this.soMaster.PayTypeSysNo == 48)
            {
                //修改总发票金额为1分钱
                invoiceInfo.InvoiceAmt = 0.01m;
            }
            invoiceInfo.RMBConvert = this.GetRMBConvert(invoiceInfo.InvoiceAmt); //人民币大写金额

            //Head默认值处理
            invoiceInfo.InvoiceDate       = DateTime.Now.ToString("yyyy-MM-dd");
            invoiceInfo.InvoiceSeq        = 1; //拆分序号,先默认为1
            invoiceInfo.InvoiceSeqEx      = "";
            invoiceInfo.InvoiceSumPageNum = 1; //总页码,先默认为1
            invoiceInfo.InvoiceCurPageNum = 1; //当前页码,先默认为1

            //Head特殊处理
            //是否阿斯利康客户
            if (this.soMaster.SpecialSOType == 2)
            {
                invoiceInfo.ServicePhone   = "阿斯利康客服热线:400-600-5566";
                invoiceInfo.ReceiveContact = "阿斯利康(无锡)贸易有限公司";
            }
            //支付方式特殊处理
            if (this.soMaster.IsUseChequesPay)
            {
                invoiceInfo.PayTypeName += "(支票支付)";
            }
            if (this.soMaster.IsRequireShipInvoice)
            {
                invoiceInfo.PayTypeName += "(客户需要圆通发票)";
            }
            //收货地址分解
            if (invoiceInfo.ReceiveAddress.Length > 35)
            {
                invoiceInfo.ReceiveAddress1 = invoiceInfo.ReceiveAddress.Substring(0, 35);
                invoiceInfo.ReceiveAddress2 = invoiceInfo.ReceiveAddress.Substring(35);
            }
            else
            {
                invoiceInfo.ReceiveAddress1 = invoiceInfo.ReceiveAddress;
            }

            //特别说明
            if (this.soMaster.IsPayWhenRecv && this.soMaster.PrepayAmt > 0m)
            {
                if (this.soMaster.IsCombine)
                {
                    invoiceInfo.Importance = "本订单已收到余额支付" + this.soMaster.PrepayAmt.ToString("#########0.00") + "元";
                }
                else
                {
                    decimal cashPay = this.GetFinallReceivableAmt(invoiceInfo.InvoiceAmt, this.soMaster.PrepayAmt, this.soMaster.IsPayWhenRecv);
                    invoiceInfo.Importance = "预支付" + this.soMaster.PrepayAmt.ToString("#########0.00") + "元,现支付" + cashPay.ToString("#########0.00") + "元";
                }
            }

            //获取发票明细
            invoiceInfo.Items = GetInvoiceItems();

            return(invoiceInfo);
        }