Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            op           = RequestData.Get <string>("op");
            orderids     = RequestData.Get <string>("orderids");
            id           = RequestData.Get <string>("id");
            CustomerId   = RequestData.Get <string>("CustomerId");
            CustomerName = Server.HtmlDecode(RequestData.Get <string>("CustomerName"));
            entStrList   = RequestData.GetList <string>("data");
            if (!string.IsNullOrEmpty(id))
            {
                ent = OrderInvoice.Find(id);
            }
            switch (RequestActionString)
            {
            case "update":
                ent = GetMergedData <OrderInvoice>();
                ent.DoUpdate();
                ProcessDetail();
                break;

            case "JudgeRepeat":
                sql = "select count(1) from SHHG_AimExamine..OrderInvoice where Number like '%" + RequestData.Get <string>("InvoiceNo") + "%' ";
                if (DataHelper.QueryValue <int>(sql) > 0)
                {
                    PageState.Add("IsRepeat", "T");
                }
                else
                {
                    PageState.Add("IsRepeat", "F");
                }
                break;

            case "create":
                ent     = GetPostedData <OrderInvoice>();
                ent.OId = orderids;
                ent.DoCreate();
                ProcessDetail();
                break;

            default:
                DoSelect();
                break;
            }
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string       action = Request["action"];
            string       id     = Request["invoiceid"];
            OrderInvoice oiEnt  = null;

            switch (action)
            {
            case "loadform":
                if (!string.IsNullOrEmpty(id))
                {
                    oiEnt = OrderInvoice.Find(id);
                    Response.Write("{data:" + JsonHelper.GetJsonString(oiEnt) + "}");
                    Response.End();
                }
                break;

            case "loaddetail":
                string sql = @"select A.*,B.Number from SHHG_AimExamine..OrderInvoiceDetail A
                                 left join SHHG_AimExamine..SaleOrders B on A.SaleOrderId=B.Id
                                 where OrderInvoiceId='{0}' order by ProductCode asc";
                sql = string.Format(sql, id);
                DataTable dt = DataHelper.QueryDataTable(sql);
                Response.Write("{rows:" + JsonHelper.GetJsonStringFromDataTable(dt) + "}");
                Response.End();
                break;

            case "payoffinvoice":
                oiEnt          = OrderInvoice.Find(id);
                oiEnt.PayState = "已全部付款";
                oiEnt.Remark   = Request["remark"];
                oiEnt.DoUpdate();
                Response.Write("{success:'true'}");
                Response.End();
                break;
            }
        }
Ejemplo n.º 3
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.º 4
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();
            }
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            op   = RequestData.Get <string>("op");
            ids  = RequestData.Get <string>("ids");
            id   = RequestData.Get <string>("id");
            type = RequestData.Get <string>("type");

            OrderInvoice ent = null;

            switch (this.RequestAction)
            {
            case RequestActionEnum.Update:
                ent = this.GetMergedData <OrderInvoice>();
                ent.DoUpdate();
                this.SetMessage("修改成功!");
                break;

            case RequestActionEnum.Insert:
            case RequestActionEnum.Create:
                ent     = this.GetPostedData <OrderInvoice>();
                ent.OId = ids;
                ent.DoCreate();

                IList <string> strList = RequestData.GetList <string>("data");

                string[]    oids = ids.Split(',');
                SaleOrder[] ents = SaleOrder.FindAllByPrimaryKeys(oids);

                if (ents.Length > 0)
                {
                    foreach (SaleOrder soent in ents)
                    {
                        //更新订单开票状态及发票号码
                        soent.InvoiceState   = getInvoiceState(strList, soent.Id, soent.Number);
                        soent.InvoiceNumber += ent.Number + ",";

                        soent.DoSave();
                    }
                }

                this.SetMessage("新建成功!");
                break;

            case RequestActionEnum.Delete:
                ent = this.GetTargetData <OrderInvoice>();
                ent.DoDelete();
                this.SetMessage("删除成功!");
                return;

            default:
                if (RequestActionString == "")
                {
                }
                break;
            }

            //加载要开发票的数据
            if (op == "c" && !string.IsNullOrEmpty(ids))
            {
                string[] oids = ids.Split(',');

                SaleOrder[] ents = SaleOrder.FindAllByPrimaryKeys(oids);

                if (ents.Length > 0)
                {
                    DataTable dtall    = null;
                    DataTable dtMain   = null;
                    DataTable dtReturn = null;
                    DataTable dtChange = null;
                    string    columns  = "Id,OId,PId as ProductId,PCode as ProductCode,PName as ProductName,Isbn,[Count],Unit,SalePrice,Amount,Remark,BillingCount,'销售' as Type";
                    string    columns2 = "Id,OId,ProductId,ProductCode,ProductName,Isbn,[Count],Unit,ReturnPrice as SalePrice,Amount,Remark,BillingCount";
                    foreach (SaleOrder soent in ents)
                    {
                        //partList.AddRange(OrdersPart.FindAllByProperty("OId", soent.Id));

                        //查询数据
                        dtMain   = DataHelper.QueryDataTable("select " + columns + " from " + db + "..OrdersPart where OId='" + soent.Id + "'");
                        dtReturn = DataHelper.QueryDataTable("select " + columns2 + ",'退货' as Type from " + db + "..ReturnOrderPart where OId='" + soent.Id + "'");
                        dtChange = DataHelper.QueryDataTable("select " + columns2 + ",'换货' as Type from " + db + "..ChangeOrderPart where OId='" + soent.Id + "'");

                        //处理换货商品
                        DataTable dttemp = dtMain;
                        if (dtChange.Rows.Count > 0)
                        {
                            bool isfind = false;
                            foreach (DataRow charow in dtChange.Rows)
                            {
                                isfind = false;
                                foreach (DataRow mainrow in dtMain.Rows)
                                {
                                    if (charow["ProductId"] + "" == mainrow["ProductId"] + "")
                                    {
                                        isfind = true;
                                        //加上换货的商品数量
                                        //dttemp.Rows.Remove(mainrow);
                                        mainrow["Count"]  = Convert.ToInt32(mainrow["Count"]) + Convert.ToInt32(charow["Count"]);
                                        mainrow["Amount"] = Convert.ToInt32(mainrow["Amount"]) + Convert.ToInt32(charow["Amount"]);
                                        //dttemp.Rows.Add(mainrow);
                                        break;
                                    }
                                }
                                //不在原商品列表里,添加新的
                                if (!isfind)
                                {
                                    dttemp.Rows.Add(charow.ItemArray);
                                }
                            }
                            dtMain = dttemp;
                        }

                        //处理退货商品
                        if (dtReturn.Rows.Count > 0)
                        {
                            foreach (DataRow rtnrow in dtReturn.Rows)
                            {
                                foreach (DataRow mainrow in dtMain.Rows)
                                {
                                    if (rtnrow["ProductId"] + "" == mainrow["ProductId"] + "")
                                    {
                                        //完全退货移除
                                        if (rtnrow["Count"] + "" == mainrow["Count"] + "")
                                        {
                                            dttemp.Rows.Remove(mainrow);
                                        }
                                        else
                                        {
                                            //dttemp.Rows.Remove(mainrow);
                                            mainrow["Count"]  = Convert.ToInt32(mainrow["Count"]) - Convert.ToInt32(rtnrow["Count"]);
                                            mainrow["Amount"] = Convert.ToInt32(mainrow["Amount"]) - Convert.ToInt32(rtnrow["Amount"]);
                                            //dttemp.Rows.Add(mainrow);
                                        }
                                        break;
                                    }
                                }
                            }
                            dtMain = dttemp;
                        }

                        if (dtall == null)
                        {
                            dtall = dtMain;
                        }
                        else
                        {
                            dtall.Merge(dtMain);
                        }
                    }

                    #region old

                    //                    string sql = @"select OId,ProductId,ProductCode,ProductName,Isbn,sum([count]) as [Count],max(SalePrice) as SalePrice,sum(Amount) as Amount,Unit,sum(BillingCount) as BillingCount from(
                    //                                select Id,OId,PId as ProductId,PCode as ProductCode,PName as ProductName,Isbn,[Count],Unit,SalePrice,Amount,BillingCount from {0}..OrdersPart
                    //                                union all
                    //                                select Id,OId,ProductId,ProductCode,ProductName,Isbn,[Count],Unit,0,Amount,BillingCount from {1}..ChangeOrderPart
                    //                                union all
                    //                                select Id,OId,ProductId,ProductCode,ProductName,Isbn,([Count]*-1) as [Count],Unit,0,(Amount*-1) as Amount,BillingCount from {2}..ReturnOrderPart
                    //                                )t where OId in ('" + ids.Replace(",", "','") + "') group by ProductId,ProductCode,ProductName,Unit,Isbn,OId having sum([Count])>0";
                    //                    DataTable dt = DataHelper.QueryDataTable(string.Format(sql, db, db, db));

                    //                    PageState.Add("DetailList", DataHelper.DataTableToDictList(dt));

                    #endregion

                    PageState.Add("DetailList", DataHelper.DataTableToDictList(dtall));
                    ents[0].Child  = "";
                    ents[0].Number = "";
                    this.SetFormData(ents[0]);
                }
            }
            else if (op != "c" && op != "cs")
            {
                if (!String.IsNullOrEmpty(id))
                {
                    ent = OrderInvoice.Find(id);
                }

                this.SetFormData(ent);
            }
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Index = RequestData.Get <string>("Index");
            CC    = RequestData.Get <string>("CC");
            string ids = RequestData.Get <string>("ids");

            switch (RequestActionString)
            {
            case "delete":
                if (!string.IsNullOrEmpty(ids))
                {
                    string[] idArray = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < idArray.Length; i++)
                    {
                        oiEnt = OrderInvoice.Find(idArray[i]);
                        IList <OrderInvoiceDetail> oidEnts = OrderInvoiceDetail.FindAllByProperty("OrderInvoiceId", oiEnt.Id);
                        foreach (OrderInvoiceDetail oidEnt in oidEnts)
                        {
                            OrdersPart opEnt = OrdersPart.Find(oidEnt.OrderDetailId);
                            opEnt.BillingCount = opEnt.BillingCount - oidEnt.InvoiceCount;
                            opEnt.DoUpdate();
                            oidEnt.DoDelete();
                        }
                        //删除发票的时候 回滚销售订单的发票状态   soEnt.InvoiceState = "";
                        string[] oidArray = oiEnt.OId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string oid in oidArray)
                        {
                            SaleOrder soEnt = SaleOrder.Find(oid);
                            sql = "select count(Id) from SHHG_AimExamine..OrdersPart where BillingCount>0 and OId='" + oid + "'";
                            if (DataHelper.QueryValue <int>(sql) == 0)
                            {
                                soEnt.InvoiceState = "";
                            }
                            else
                            {
                                soEnt.InvoiceState = "已部分开发票";
                            }
                            soEnt.DoUpdate();
                        }
                        oiEnt.DoDelete();
                    }
                }
                break;

            case "RollBack":
                if (!string.IsNullOrEmpty(ids))
                {
                    string[] idArray = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < idArray.Length; i++)
                    {
                        oiEnt           = OrderInvoice.Find(idArray[i]);
                        oiEnt.PayState  = null;
                        oiEnt.PayAmount = null;
                        oiEnt.DoUpdate();
                    }
                }
                break;

            case "updateorderinvoicedetail":
                IList <OrderInvoice> oiEnts = OrderInvoice.FindAll();
                foreach (OrderInvoice oiEnt in oiEnts)
                {
                    IList <OrderInvoiceDetail> oidEnts = OrderInvoiceDetail.FindAllByProperty(OrderInvoiceDetail.Prop_OrderInvoiceId, oiEnt.Id);
                    if (oidEnts.Count == 0)
                    {
                        JArray ja = JsonHelper.GetObject <JArray>(oiEnt.Child);
                        foreach (JObject jo in ja)
                        {
                            OrderInvoiceDetail oidEnt = new OrderInvoiceDetail();
                            oidEnt.OrderDetailId  = jo.Value <string>("Id");
                            oidEnt.OrderInvoiceId = oiEnt.Id;
                            oidEnt.SaleOrderId    = jo.Value <string>("OId");
                            oidEnt.ProductId      = jo.Value <string>("ProductId");
                            oidEnt.ProductCode    = jo.Value <string>("ProductCode");
                            oidEnt.ProductName    = jo.Value <string>("ProductName");
                            oidEnt.SalePrice      = jo.Value <decimal>("SalePrice");
                            oidEnt.Unit           = jo.Value <string>("Unit");
                            oidEnt.Amount         = jo.Value <decimal>("Amount");
                            oidEnt.Count          = jo.Value <Int32>("Count");
                            oidEnt.InvoiceCount   = jo.Value <Int32>("Count");
                            oidEnt.DoCreate();
                        }
                    }
                }
                break;

            default:
                DoSelect();
                break;
            }
        }