Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CC = RequestData.Get <string>("CC");
            string ids = RequestData.Get <string>("ids");

            string[] idArray = null;
            if (!string.IsNullOrEmpty(ids))
            {
                idArray = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            }
            switch (RequestActionString)
            {
            case "CancelCorrespond":
                foreach (string str in idArray)    //可以同时对多个付款进行撤销对应
                {
                    piEnt = PaymentInvoice.Find(str);
                    string[] invoiceArray = piEnt.CorrespondInvoice.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < invoiceArray.Length; i++)
                    {
                        int          index  = invoiceArray[i].IndexOf("_");
                        string       number = invoiceArray[i].Substring(0, index); //找到对应的发票号和销账金额 对发票进行回滚
                        decimal      amount = Convert.ToDecimal(invoiceArray[i].Substring(index + 1));
                        OrderInvoice oiEnt  = OrderInvoice.FindAllByProperty(OrderInvoice.Prop_Number, number).FirstOrDefault <OrderInvoice>();
                        oiEnt.PayAmount = oiEnt.PayAmount - amount;
                        oiEnt.PayState  = oiEnt.PayAmount > 0 ? "部分付款" : "";
                        oiEnt.DoUpdate();
                    }
                    piEnt.CorrespondAmount  = 0;
                    piEnt.CorrespondInvoice = "";
                    piEnt.CorrespondState   = "";
                    piEnt.Name = "暂不销账";
                    piEnt.DoUpdate();
                }
                break;

            case "AutoCorrespond":
                foreach (string id in idArray)
                {
                    piEnt = PaymentInvoice.Find(id);
                    sql   = @"select sum(Amount-isnull(PayAmount,0)) from SHHG_AimExamine..OrderInvoice where (PayState is null or PayState<>'已全部付款') and CId='" + piEnt.CId + "'";
                    decimal shouldpayAmount = DataHelper.QueryValue <decimal>(sql);   //合计应付金额
                    if (shouldpayAmount > 0)
                    {
                        decimal validAmount = piEnt.Money.Value - (piEnt.CorrespondAmount.HasValue ? piEnt.CorrespondAmount.Value : 0); //有效金额
                        if (shouldpayAmount >= validAmount)                                                                             //如果 付款金额小于等于应付款总额
                        {
                            sql = @"select * from SHHG_AimExamine..OrderInvoice where (PayState is null or PayState<>'已全部付款') and CId='" + piEnt.CId + "' order by InvoiceDate asc";
                            IList <EasyDictionary> dics = DataHelper.QueryDictList(sql);
                            //decimal payamount = piEnt.Money.Value;
                            foreach (EasyDictionary dic in dics)
                            {
                                if (validAmount > 0)
                                {
                                    OrderInvoice oiEnt = OrderInvoice.Find(dic.Get <string>("Id"));
                                    if (validAmount >= (oiEnt.Amount.Value - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0)))    //大于等于该发票的未付金额
                                    {
                                        validAmount              = validAmount - (oiEnt.Amount.Value - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0));
                                        oiEnt.PayState           = "已全部付款";
                                        piEnt.CorrespondInvoice += (string.IsNullOrEmpty(piEnt.CorrespondInvoice) ? "" : ",") + oiEnt.Number + "_" + (oiEnt.Amount - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0));
                                        oiEnt.PayAmount          = oiEnt.Amount;
                                    }
                                    else
                                    {
                                        oiEnt.PayAmount          = (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0) + validAmount;
                                        oiEnt.PayState           = "部分付款";
                                        piEnt.CorrespondInvoice += (string.IsNullOrEmpty(piEnt.CorrespondInvoice) ? "" : ",") + oiEnt.Number + "_" + validAmount;
                                        validAmount              = 0;
                                    }
                                    oiEnt.DoUpdate();
                                }
                            }
                            piEnt.CorrespondAmount = piEnt.Money;
                            piEnt.CorrespondState  = "已对应";
                            piEnt.Name             = "自动销账";
                            piEnt.DoUpdate();
                        }
                        else     //如果付款金额大于应付款总金额
                        {
                            sql = @"select * from SHHG_AimExamine..OrderInvoice where (PayState is null or PayState<>'已全部付款') and CId='" + piEnt.CId + "' order by InvoiceDate asc";
                            IList <EasyDictionary> dics = DataHelper.QueryDictList(sql);
                            foreach (EasyDictionary dic in dics)
                            {
                                OrderInvoice oiEnt = OrderInvoice.Find(dic.Get <string>("Id"));
                                piEnt.CorrespondInvoice += (string.IsNullOrEmpty(piEnt.CorrespondInvoice) ? "" : ",") + oiEnt.Number + "_" + (oiEnt.Amount - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0));
                                piEnt.CorrespondState    = "部分对应";
                                piEnt.CorrespondAmount   = (piEnt.CorrespondAmount.HasValue ? piEnt.CorrespondAmount.Value : 0) + shouldpayAmount;
                                piEnt.DoUpdate();
                                oiEnt.PayState  = "已全部付款";
                                oiEnt.PayAmount = oiEnt.Amount;
                                oiEnt.DoUpdate();
                            }
                        }
                    }
                }
                break;

            case "delete":
                foreach (string str in idArray)
                {
                    piEnt = PaymentInvoice.Find(str);
                    piEnt.DoDelete();
                }
                break;

            default:
                DoSelect();
                break;
            }
        }
Ejemplo n.º 2
0
        private void UpdateOrderInvoice()//销售付款创建完毕后  如果该客户有应付款记录   开始执行对应操作
        {
            if (ent.Name == "自动销账")
            {
                PaymentInvoice piEnt = ent;
                piEnt.CorrespondInvoice = "";
                sql = @"select sum(Amount-isnull(PayAmount,0)) from SHHG_AimExamine..OrderInvoice where (PayState is null or PayState<>'已全部付款') and CId='" + piEnt.CId + "'";
                decimal shouldpayAmount = DataHelper.QueryValue <decimal>(sql);//合计应付金额

                if (shouldpayAmount > 0)
                {
                    decimal validAmount = piEnt.Money.Value - (piEnt.CorrespondAmount.HasValue ? piEnt.CorrespondAmount.Value : 0); //有效金额
                    if (shouldpayAmount >= validAmount)                                                                             //如果有效金额小于等于应付款总额
                    {
                        sql = @"select * from SHHG_AimExamine..OrderInvoice where (PayState is null or PayState<>'已全部付款') and CId='" + piEnt.CId + "' order by InvoiceDate asc";
                        IList <EasyDictionary> dics = DataHelper.QueryDictList(sql);
                        foreach (EasyDictionary dic in dics)
                        {
                            if (validAmount > 0)
                            {
                                OrderInvoice oiEnt = OrderInvoice.Find(dic.Get <string>("Id"));
                                if (validAmount >= (oiEnt.Amount.Value - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0)))//大于等于该发票的未付金额
                                {
                                    validAmount              = validAmount - (oiEnt.Amount.Value - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0));
                                    oiEnt.PayState           = "已全部付款";
                                    piEnt.CorrespondInvoice += (string.IsNullOrEmpty(piEnt.CorrespondInvoice) ? "" : ",") + oiEnt.Number + "_" + (oiEnt.Amount - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0));
                                    oiEnt.PayAmount          = oiEnt.Amount;
                                }
                                else
                                {
                                    oiEnt.PayAmount          = (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0) + validAmount;
                                    oiEnt.PayState           = "部分付款";
                                    piEnt.CorrespondInvoice += (string.IsNullOrEmpty(piEnt.CorrespondInvoice) ? "" : ",") + oiEnt.Number + "_" + validAmount;
                                    validAmount              = 0;
                                }
                                oiEnt.DoUpdate();
                            }
                        }
                        piEnt.CorrespondAmount = piEnt.Money;
                        piEnt.CorrespondState  = "已对应";
                        piEnt.Name             = "自动销账";
                        piEnt.DoUpdate();
                    }
                    else //如果付款金额大于应付款总金额
                    {
                        sql = @"select * from SHHG_AimExamine..OrderInvoice where (PayState is null or PayState<>'已全部付款') and CId='" + piEnt.CId + "' order by InvoiceDate asc";
                        IList <EasyDictionary> dics = DataHelper.QueryDictList(sql);
                        foreach (EasyDictionary dic in dics)
                        {
                            OrderInvoice oiEnt = OrderInvoice.Find(dic.Get <string>("Id"));
                            piEnt.CorrespondInvoice += (string.IsNullOrEmpty(piEnt.CorrespondInvoice) ? "" : ",") + oiEnt.Number + "_" + (oiEnt.Amount - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0));
                            piEnt.CorrespondState    = "部分对应";
                            piEnt.CorrespondAmount   = (piEnt.CorrespondAmount.HasValue ? piEnt.CorrespondAmount.Value : 0) + shouldpayAmount;
                            piEnt.DoUpdate();
                            oiEnt.PayState  = "已全部付款";
                            oiEnt.PayAmount = oiEnt.Amount;
                            oiEnt.DoUpdate();
                        }
                    }
                }
            }
            if (ent.Name == "手动销账")
            {
                string[] orderinvoiceArray = ent.CorrespondInvoice.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                ent.CorrespondInvoice = "";
                foreach (string str in orderinvoiceArray)
                {
                    OrderInvoice oiEnt = OrderInvoice.FindAllByProperty(OrderInvoice.Prop_Number, str).FirstOrDefault <OrderInvoice>();
                    ent.CorrespondInvoice += oiEnt.Number + "_" + (oiEnt.Amount - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0)) + ",";
                    oiEnt.PayAmount        = oiEnt.Amount;
                    oiEnt.PayState         = "已全部付款";
                    oiEnt.DoUpdate();
                }
                ent.CorrespondState = "已对应";
                ent.DoUpdate();
            }
            if (ent.Name == "暂不销账")
            {
                ent.CorrespondInvoice = "";
                ent.DoUpdate();
            }
        }