Beispiel #1
0
        public ActionResult AddSpecialInvoice(int custId, double amount, string month, string date, string billingCode, string jsonArrayItems)
        {
            this.Internationalization();

            using (TransactionScope trans = new TransactionScope())
            {
                try
                {

                    TugDataEntities db = new TugDataEntities();
                    {
                        //0.验证账单编号是否已存在
                        var tmp = db.Billing.FirstOrDefault(u => u.BillingCode.Trim() == billingCode.Trim());
                        if (tmp != null)
                        {
                            var ret2 = new { code = Resources.Common.FAIL_CODE, message = "帳單編號已存在!" };
                            //Response.Write(@Resources.Common.SUCCESS_MESSAGE);
                            return Json(ret2, JsonRequestBehavior.AllowGet);
                        }

                        //1.插入账单
                        TugDataModel.Billing aScheduler = new Billing();

                        aScheduler.CustomerID = custId;
                        aScheduler.Amount = amount;
                        aScheduler.Month = month;
                        aScheduler.UserDefinedCol10 = date;
                        aScheduler.InvoiceType = "特殊账单";
                        aScheduler.BillingCode = billingCode.Trim();

                        aScheduler.TimesNo = 0;
                        aScheduler.Status = "创建";
                        aScheduler.Phase = 0;

                        aScheduler.OwnerID = -1;
                        aScheduler.CreateDate = aScheduler.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        aScheduler.UserID = Session.GetDataFromSession<int>("userid");

                        aScheduler.UserDefinedCol1 = "";
                        aScheduler.UserDefinedCol2 = "";
                        aScheduler.UserDefinedCol3 = "";
                        aScheduler.UserDefinedCol4 = "";

                        aScheduler.UserDefinedCol9 = "";

                        aScheduler = db.Billing.Add(aScheduler);
                        db.SaveChanges();

                        //3.插入账单的收费项目
                        List<MySpecialBillingItem> listInVoiceItems = new List<MySpecialBillingItem>();
                        listInVoiceItems = TugBusinessLogic.Utils.JSONStringToList<MySpecialBillingItem>(jsonArrayItems);
                        if (listInVoiceItems != null)
                        {
                            foreach (MySpecialBillingItem item in listInVoiceItems)
                            {
                                SpecialBillingItem bi = new SpecialBillingItem();
                                bi.SpecialBillingID = aScheduler.IDX;
                                bi.OrderServiceID = item.OrderServiceID;
                                bi.CustomerShipName = item.CustomerShipName;
                                bi.FeulUnitPrice = item.FeulUnitPrice;
                                bi.ServiceDate = item.ServiceDate;
                                bi.ServiceNatureID = item.ServiceNatureID;
                                bi.ServiceNatureValue = item.ServiceNatureValue;
                                bi.ServiceNature = item.ServiceNature;
                                bi.ServiceUnitPrice = item.ServiceUnitPrice;
                                bi.TugNumber = item.TugNumber;

                                bi = db.SpecialBillingItem.Add(bi);
                                db.SaveChanges();

                                //更新订单服务的账单标记
                                {
                                    OrderService os = db.OrderService.First(u => u.IDX == item.OrderServiceID);
                                    os.HasBilling = "是";
                                    os.HasBillingInFlow = "否";
                                    os.BillingType = 1;
                                    db.Entry(os).State = System.Data.Entity.EntityState.Modified;
                                    db.SaveChanges();

                                    //更新服务对应的订单的账单标记;因为现在一个订单对应一个服务
                                    OrderInfor ordInfor = db.OrderInfor.FirstOrDefault(u => u.IDX == os.OrderID);
                                    if (ordInfor != null)
                                    {
                                        ordInfor.HasInvoice = "是";
                                        db.Entry(ordInfor).State = System.Data.Entity.EntityState.Modified;
                                        db.SaveChanges();
                                    }
                                }

                            }
                        }

                        //4.插入账单的汇总项目
                        TugBusinessLogic.Module.FinanceLogic.UpdateSpecialBillingSummarizeItems(aScheduler.IDX, (int)aScheduler.UserID);
                        //List<InVoiceSummaryItem> listInVoiceSummaryItems = new List<InVoiceSummaryItem>();
                        //listInVoiceSummaryItems = TugBusinessLogic.Utils.JSONStringToList<InVoiceSummaryItem>(jsonArraySummaryItems);
                        //if (listInVoiceSummaryItems != null)
                        //{
                        //    foreach (InVoiceSummaryItem item in listInVoiceSummaryItems)
                        //    {
                        //        AmountSum amtSum = new AmountSum();
                        //        amtSum.CustomerID = custId;
                        //        amtSum.CustomerShipID = custShipId;
                        //        amtSum.BillingID = aScheduler.IDX;
                        //        amtSum.BillingDateTime = TugBusinessLogic.Utils.CNDateTimeToDateTime(aScheduler.CreateDate);
                        //        amtSum.SchedulerID = item.SchedulerID;
                        //        amtSum.Amount = item.Amount;
                        //        amtSum.Currency = item.Currency;
                        //        amtSum.Hours = item.Hours;
                        //        amtSum.Year = DateTime.Now.Year.ToString();
                        //        amtSum.Month = aScheduler.Month;
                        //        amtSum.OwnerID = -1;
                        //        amtSum.CreateDate = amtSum.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        //        amtSum.UserID = Session.GetDataFromSession<int>("userid");

                        //        amtSum = db.AmountSum.Add(amtSum);
                        //        db.SaveChanges();
                        //    }
                        //}

                        //5.更新订单的字段 V_OrderInfor_HasInvoice	是否已有帳單
                        //{
                        //    List<OrderInfor> odList = db.OrderInfor.Where(u => iOrderIDs.Contains(u.IDX)).ToList();
                        //    //throw new Exception();
                        //    if (odList != null)
                        //    {
                        //        foreach (OrderInfor od in odList)
                        //        {
                        //            od.HasInvoice = "是";
                        //            od.HasInFlow = "否";
                        //            db.Entry(od).State = System.Data.Entity.EntityState.Modified;
                        //            db.SaveChanges();
                        //        }
                        //    }
                        //}

                        trans.Complete();

                        var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE, billing_id = aScheduler.IDX };
                        //Response.Write(@Resources.Common.SUCCESS_MESSAGE);
                        return Json(ret, JsonRequestBehavior.AllowGet);
                    }

                }
                catch (Exception ex)
                {
                    trans.Dispose();
                    var ret = new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE, billing_id = -1 };
                    //Response.Write(@Resources.Common.EXCEPTION_MESSAGE);
                    return Json(ret, JsonRequestBehavior.AllowGet);
                }
            }
        }
Beispiel #2
0
        public ActionResult EditSpecialInvoice(int billingId, double amount, string month, string date, string billingCode, string jsonArrayItems)
        {
            this.Internationalization();

                try
                {
                    TugDataEntities db = new TugDataEntities();
                    {
                        Billing oldBilling = db.Billing.FirstOrDefault(u => u.IDX == billingId);

                        Billing tmp = db.Billing.FirstOrDefault(u => u.BillingCode.Trim() == billingCode.Trim());
                        if (tmp != null)
                        {
                            if (tmp.IDX != oldBilling.IDX)
                            {
                                return Json(new { code = Resources.Common.FAIL_CODE, message = "帳單編號已存在!" }, JsonRequestBehavior.AllowGet);
                            }
                        }

                        if (oldBilling != null)
                        {
                            oldBilling.BillingCode = billingCode.Trim();
                            oldBilling.Amount = amount;
                            oldBilling.Month = month;
                            oldBilling.UserDefinedCol10 = date;
                            oldBilling.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                            db.Entry(oldBilling).State = System.Data.Entity.EntityState.Modified;
                            int ret = db.SaveChanges();

                            if (ret > 0)
                            {
                                #region 订单收费项
                                //1.订单收费项
                                List<SpecialBillingItem> invoiceItems = db.SpecialBillingItem.Where(u => u.SpecialBillingID == billingId).ToList();
                                if (invoiceItems != null)
                                {
                                    db.SpecialBillingItem.RemoveRange(invoiceItems);
                                    ret = db.SaveChanges();
                                    if (ret > 0)
                                    {
                                        List<MySpecialBillingItem> listInVoiceItems = new List<MySpecialBillingItem>();
                                        listInVoiceItems = TugBusinessLogic.Utils.JSONStringToList<MySpecialBillingItem>(jsonArrayItems);
                                        if (listInVoiceItems != null)
                                        {
                                            foreach (MySpecialBillingItem item in listInVoiceItems)
                                            {
                                                SpecialBillingItem bi = new SpecialBillingItem();
                                                bi.SpecialBillingID = billingId;
                                                bi.OrderServiceID = item.OrderServiceID;
                                                bi.ServiceNatureID = item.ServiceNatureID;
                                                bi.ServiceNatureValue = item.ServiceNatureValue;
                                                bi.CustomerShipName = item.CustomerShipName;
                                                bi.FeulUnitPrice = item.FeulUnitPrice;
                                                bi.ServiceDate = item.ServiceDate;
                                                bi.ServiceNature = item.ServiceNature;
                                                bi.ServiceUnitPrice = item.ServiceUnitPrice;
                                                bi.TugNumber = item.TugNumber;

                                                bi = db.SpecialBillingItem.Add(bi);
                                                db.SaveChanges();
                                            }
                                        }
                                        else
                                        {
                                            return Json(new { code = Resources.Common.FAIL_CODE, message = Resources.Common.FAIL_MESSAGE }, JsonRequestBehavior.AllowGet);
                                        }
                                    }
                                    else
                                    {
                                        return Json(new { code = Resources.Common.FAIL_CODE, message = Resources.Common.FAIL_MESSAGE }, JsonRequestBehavior.AllowGet);
                                    }

                                }
                                else
                                {
                                    List<MySpecialBillingItem> listInVoiceItems = new List<MySpecialBillingItem>();
                                    listInVoiceItems = TugBusinessLogic.Utils.JSONStringToList<MySpecialBillingItem>(jsonArrayItems);
                                    if (listInVoiceItems != null)
                                    {
                                        foreach (MySpecialBillingItem item in listInVoiceItems)
                                        {
                                            SpecialBillingItem bi = new SpecialBillingItem();

                                            bi.SpecialBillingID = billingId;
                                            bi.OrderServiceID = item.OrderServiceID;
                                            bi.ServiceNatureID = item.ServiceNatureID;
                                            bi.ServiceNatureValue = item.ServiceNatureValue;
                                            bi.CustomerShipName = item.CustomerShipName;
                                            bi.FeulUnitPrice = item.FeulUnitPrice;
                                            bi.ServiceDate = item.ServiceDate;
                                            bi.ServiceNature = item.ServiceNature;
                                            bi.ServiceUnitPrice = item.ServiceUnitPrice;
                                            bi.TugNumber = item.TugNumber;

                                            bi = db.SpecialBillingItem.Add(bi);
                                            db.SaveChanges();
                                        }
                                    }
                                    else
                                    {
                                        return Json(new { code = Resources.Common.FAIL_CODE, message = Resources.Common.FAIL_MESSAGE }, JsonRequestBehavior.AllowGet);
                                    }
                                }
                                #endregion

                                //2.插入账单的汇总项目
                                TugBusinessLogic.Module.FinanceLogic.UpdateSpecialBillingSummarizeItems(billingId, Session.GetDataFromSession<int>("userid"));

                                #region 更新回扣单编号
                                System.Linq.Expressions.Expression<Func<Credit, bool>> expCredit = u => u.BillingID == billingId;
                                List<Credit> tmpCredit = db.Credit.Where(expCredit).Select(u => u).ToList<Credit>();
                                //Credit tmpCredit = db.Credit.Where(expCredit).FirstOrDefault();
                                if (tmpCredit.Count != 0)
                                {
                                    foreach (var item in tmpCredit)
                                    {
                                        item.CreditCode = "C" + billingCode.Substring(1, billingCode.Length - 1);
                                        db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                                        db.SaveChanges();
                                    }
                                }
                                #endregion
                            }
                            else
                            {

                                return Json(new { code = Resources.Common.FAIL_CODE, message = Resources.Common.FAIL_MESSAGE }, JsonRequestBehavior.AllowGet);
                            }
                        }
                        else
                        {

                            return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }, JsonRequestBehavior.AllowGet);
                        }
                    }
                }
                catch (Exception ex)
                {
                    return Json(new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }, JsonRequestBehavior.AllowGet);
                }

                return Json(new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }, JsonRequestBehavior.AllowGet);
        }