Exemplo n.º 1
0
        public ActionResult AddInvoice2(int custId, int custShipId, string orderIds, string orderServiceIds, int billingTemplateId, int billingTypeId, int timeTypeId,
            string jobNo, string billing_code, string remark, double discount, double amount, string month, string date, int customer_ship_length,
            int customer_ship_teus, string isShowShipLengthRule, string isShowShipTEUSRule,
            float? ratio1, float? ratio2, float? ratio3, float? ratio4, float? ratio5, float? ratio6, float? ratio7, float? minTime,
            string jsonArrayItems, string jsonArraySummaryItems)
        {
            this.Internationalization();

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

                    List<string> strOrderIDs = orderIds.Split(',').ToList();
                    List<int> iOrderIDs = new List<int>();
                    if (strOrderIDs != null)
                    {
                        foreach (var item in strOrderIDs)
                        {
                            iOrderIDs.Add(TugBusinessLogic.Module.Util.toint(item));
                        }
                    }

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

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

                        aScheduler.CustomerID = custId;
                        aScheduler.JobNo = jobNo;
                        aScheduler.IsShowShipLengthRule = isShowShipLengthRule;
                        aScheduler.IsShowShipTEUSRule = isShowShipTEUSRule;
                        aScheduler.InvoiceType = "普通账单";

                        aScheduler.BillingTemplateID = billingTemplateId;
                        aScheduler.BillingTypeID = billingTypeId;
                        //aScheduler.BillingCode = TugBusinessLogic.Utils.AutoGenerateBillCode();
                        aScheduler.BillingCode = billing_code.Trim() ;
                        aScheduler.BillingName = "";
                        aScheduler.TimeTypeID = timeTypeId;
                        aScheduler.Discount = discount;
                        aScheduler.TotalRebate = 0;
                        aScheduler.Amount = amount;
                        aScheduler.Remark = remark;
                        aScheduler.Month = month;
                        aScheduler.UserDefinedCol10 = date;

                        if (ratio1 != null)
                            aScheduler.Ratio1 = (int?)Math.Round((float)ratio1, 2);
                        if (ratio2 != null)
                            aScheduler.Ratio2 = (int?)Math.Round((float)ratio2, 2);
                        if (ratio3 != null)
                            aScheduler.Ratio3 = (int?)Math.Round((float)ratio3, 2);
                        if (ratio4 != null)
                            aScheduler.Ratio4 = (int?)Math.Round((float)ratio4, 2);
                        if (ratio5 != null)
                            aScheduler.Ratio5 = (int?)Math.Round((float)ratio5, 2);
                        if (ratio6 != null)
                            aScheduler.Ratio6 = (int?)Math.Round((float)ratio6, 2);
                        if (ratio7 != null)
                            aScheduler.Ratio7 = (int?)Math.Round((float)ratio7, 2);
                        if (minTime != null)
                            aScheduler.MinTime = (int?)Math.Round((float)minTime, 2);

                        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();

                        //2.插入账单、多个订单
                        List<BillingOrder> listBillingOrder = new List<BillingOrder>();
                        foreach (int orderId in iOrderIDs)
                        {
                            BillingOrder bo = new BillingOrder();
                            bo.BillingID = aScheduler.IDX;
                            bo.OrderID = orderId;
                            listBillingOrder.Add(bo);
                        }
                        db.BillingOrder.AddRange(listBillingOrder);
                        db.SaveChanges();

                        //3.插入账单的收费项目
                        List<InVoiceItem> listInVoiceItems = new List<InVoiceItem>();
                        listInVoiceItems = TugBusinessLogic.Utils.JSONStringToList<InVoiceItem>(jsonArrayItems);
                        if (listInVoiceItems != null)
                        {
                            foreach (InVoiceItem item in listInVoiceItems)
                            {
                                BillingItem bi = new BillingItem();
                                bi.BillingID = aScheduler.IDX;
                                bi.SchedulerID = item.SchedulerID;
                                bi.ItemID = item.ItemID;
                                bi.UnitPrice = item.UnitPrice;
                                bi.Currency = item.Currency;
                                bi.OwnerID = -1;
                                bi.UserID = Session.GetDataFromSession<int>("userid");
                                bi.CreateDate = bi.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                bi.UserDefinedCol1 = "";
                                bi.UserDefinedCol2 = "";
                                bi.UserDefinedCol3 = "";
                                bi.UserDefinedCol4 = "";

                                bi.UserDefinedCol9 = "";
                                bi.UserDefinedCol10 = "";

                                bi = db.BillingItem.Add(bi);
                                db.SaveChanges();
                            }
                        }

                        //4.插入账单的汇总项目
                        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.FuelAmount = item.FuelPrice;
                                amtSum.Currency = item.Currency;
                                amtSum.Hours = item.Hours;
                                amtSum.Year = aScheduler.Month.Split('-')[0];//DateTime.Now.Year.ToString();
                                amtSum.Month = aScheduler.Month.Split('-')[1];// 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();
                                }
                            }
                        }

                        //6.更新订单服务表里的字段 HasBilling、HasBillingInFlow 是否已有帳單
                        {

                            List<string> strOrderServiceIDs = orderServiceIds.Split(',').ToList();
                            List<int> iOrderServiceIDs = new List<int>();
                            if (strOrderServiceIDs != null)
                            {
                                foreach (var item in strOrderServiceIDs)
                                {
                                    iOrderServiceIDs.Add(TugBusinessLogic.Module.Util.toint(item));
                                }
                            }

                            List<OrderService> ordSrvList = db.OrderService.Where(u => iOrderServiceIDs.Contains((int)u.IDX)).ToList();
                            //throw new Exception();
                            if (ordSrvList != null)
                            {
                                foreach (OrderService ods in ordSrvList)
                                {
                                    ods.HasBilling = "是";
                                    ods.HasBillingInFlow = "否";
                                    ods.BillingType = 0;
                                    db.Entry(ods).State = System.Data.Entity.EntityState.Modified;
                                    db.SaveChanges();
                                }
                            }
                        }

                        //7.更新客户船的船长、箱量
                        {
                            CustomerShip cs = db.CustomerShip.FirstOrDefault(u => u.IDX == custShipId);
                            if (cs != null)
                            {
                                cs.Length = customer_ship_length;
                                cs.TEUS = customer_ship_teus;
                                db.Entry(cs).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);
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult EditInvoice2(int billingId, int billingTemplateId, int billingTypeId, int timeTypeId,
            string jobNo, string remark, string billing_code, double discount, double amount, string month, string date, int customer_ship_length,
            int customer_ship_teus, string jsonArrayItems, string isShowShipLengthRule,
            float? ratio1, float? ratio2, float? ratio3, float? ratio4, float? ratio5, float? ratio6, float? ratio7, float? minTime,
            string isShowShipTEUSRule, string jsonArraySummaryItems)
        {
            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() == billing_code.Trim());
                    if (tmp != null)
                    {
                        if (tmp.IDX != oldBilling.IDX)
                        {
                            return Json(new { code = Resources.Common.FAIL_CODE, message = Resources.Common.FAIL_MESSAGE }, JsonRequestBehavior.AllowGet);
                        }
                    }

                    if (oldBilling != null)
                    {
                        oldBilling.BillingTemplateID = billingTemplateId;
                        oldBilling.BillingTypeID = billingTypeId;
                        oldBilling.TimeTypeID = timeTypeId;
                        oldBilling.Discount = discount;
                        oldBilling.Amount = amount;
                        oldBilling.BillingCode = billing_code.Trim();
                        oldBilling.JobNo = jobNo;
                        if (ratio1 != null)
                        oldBilling.Ratio1 = (double?)Math.Round((double)ratio1, 2);
                        if (ratio2 != null)
                        oldBilling.Ratio2 = (double?)Math.Round((double)ratio2, 2);
                        if (ratio3 != null)
                        oldBilling.Ratio3 = (double?)Math.Round((double)ratio3, 2);
                        if (ratio4 != null)
                        oldBilling.Ratio4 = (double?)Math.Round((double)ratio4, 2);
                        if (ratio5 != null)
                        oldBilling.Ratio5 = (double?)Math.Round((double)ratio5, 2);
                        if (ratio6 != null)
                        oldBilling.Ratio6 = (double?)Math.Round((double)ratio6, 2);
                        if (ratio7 != null)
                        oldBilling.Ratio7 = (double?)Math.Round((double)ratio7, 2);
                        if (minTime != null)
                        oldBilling.MinTime = (double?)Math.Round((double)minTime, 2);

                        oldBilling.Remark = remark;
                        oldBilling.Month = month;
                        oldBilling.UserDefinedCol10 = date;
                        oldBilling.IsShowShipLengthRule = isShowShipLengthRule;
                        oldBilling.IsShowShipTEUSRule = isShowShipTEUSRule;
                        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 更新客户船长、箱量
                            V_Billing2 vb2 = db.V_Billing2.FirstOrDefault(u => u.IDX == billingId);
                            if (vb2 != null)
                            {
                                //vb2.ShipID;
                                CustomerShip cs = db.CustomerShip.FirstOrDefault(u => u.IDX == vb2.ShipID);
                                if (cs != null)
                                {
                                    cs.Length = customer_ship_length;
                                    cs.TEUS = customer_ship_teus;
                                    db.Entry(cs).State = System.Data.Entity.EntityState.Modified;
                                    db.SaveChanges();
                                }
                            }

                            #endregion

                            #region 订单收费项
                            //1.订单收费项
                            List<BillingItem> invoiceItems = db.BillingItem.Where(u => u.BillingID == billingId).ToList();
                            if (invoiceItems != null)
                            {
                                db.BillingItem.RemoveRange(invoiceItems);
                                ret = db.SaveChanges();
                                if (ret > 0)
                                {
                                    List<InVoiceItem> listInVoiceItems = new List<InVoiceItem>();
                                    listInVoiceItems = TugBusinessLogic.Utils.JSONStringToList<InVoiceItem>(jsonArrayItems);
                                    if (listInVoiceItems != null)
                                    {
                                        foreach (InVoiceItem item in listInVoiceItems)
                                        {
                                            BillingItem bi = new BillingItem();
                                            bi.BillingID = billingId;
                                            bi.SchedulerID = item.SchedulerID;
                                            bi.ItemID = item.ItemID;
                                            bi.UnitPrice = item.UnitPrice;
                                            bi.Currency = item.Currency;
                                            bi.OwnerID = -1;
                                            bi.UserID = Session.GetDataFromSession<int>("userid"); ;
                                            bi.CreateDate = bi.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                            bi.UserDefinedCol1 = "";
                                            bi.UserDefinedCol2 = "";
                                            bi.UserDefinedCol3 = "";
                                            bi.UserDefinedCol4 = "";

                                            bi.UserDefinedCol9 = "";
                                            bi.UserDefinedCol10 = "";

                                            bi = db.BillingItem.Add(bi);
                                            ret = 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<InVoiceItem> listInVoiceItems = new List<InVoiceItem>();
                                listInVoiceItems = TugBusinessLogic.Utils.JSONStringToList<InVoiceItem>(jsonArrayItems);
                                if (listInVoiceItems != null)
                                {
                                    foreach (InVoiceItem item in listInVoiceItems)
                                    {
                                        BillingItem bi = new BillingItem();
                                        bi.BillingID = billingId;
                                        bi.SchedulerID = item.SchedulerID;
                                        bi.ItemID = item.ItemID;
                                        bi.UnitPrice = item.UnitPrice;
                                        bi.Currency = item.Currency;
                                        bi.OwnerID = -1;
                                        bi.UserID = Session.GetDataFromSession<int>("userid"); ;
                                        bi.CreateDate = bi.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                        bi.UserDefinedCol1 = "";
                                        bi.UserDefinedCol2 = "";
                                        bi.UserDefinedCol3 = "";
                                        bi.UserDefinedCol4 = "";

                                        bi.UserDefinedCol9 = "";
                                        bi.UserDefinedCol10 = "";

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

                            #region 账单的汇总项目
                            //2.插入账单的汇总项目

                            List<AmountSum> oldAmountSumList = db.AmountSum.Where(u => u.BillingID == oldBilling.IDX).ToList();
                            db.AmountSum.RemoveRange(oldAmountSumList);
                            db.SaveChanges();

                            List<InVoiceSummaryItem> listInVoiceSummaryItems = new List<InVoiceSummaryItem>();
                            listInVoiceSummaryItems = TugBusinessLogic.Utils.JSONStringToList<InVoiceSummaryItem>(jsonArraySummaryItems);
                            if (listInVoiceSummaryItems != null)
                            {
                                V_Invoice2 vi2 = db.V_Invoice2.FirstOrDefault(u => u.BillingID == oldBilling.IDX);

                                foreach (InVoiceSummaryItem item in listInVoiceSummaryItems)
                                {
                                    AmountSum amtSum = new AmountSum();
                                    amtSum.CustomerID = vi2.CustomerID;
                                    amtSum.CustomerShipID = vi2.ShipID;
                                    amtSum.BillingID = oldBilling.IDX;
                                    amtSum.BillingDateTime = TugBusinessLogic.Utils.CNDateTimeToDateTime(oldBilling.CreateDate);
                                    amtSum.SchedulerID = item.SchedulerID;
                                    amtSum.Amount = item.Amount;
                                    amtSum.FuelAmount = item.FuelPrice;
                                    amtSum.Currency = item.Currency;
                                    amtSum.Hours = item.Hours;
                                    amtSum.Year = oldBilling.Month.Split('-')[0];//DateTime.Now.Year.ToString();
                                    amtSum.Month = oldBilling.Month.Split('-')[1];//oldBilling.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();
                                }
                            }
                            #endregion

                            #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" + billing_code.Substring(1, billing_code.Length - 1);
                                    db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                                    db.SaveChanges();
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_CODE }, 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);
        }
Exemplo n.º 3
0
        public ActionResult AddInvoice(int orderId, int billingTemplateId, int billingTypeId, int timeTypeId,
            string jobNo, string remark, double discount, double amount, string month, string jsonArrayItems)
        {
            this.Internationalization();

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

                    TugDataEntities db = new TugDataEntities();
                    {
                        TugDataModel.Billing aScheduler = new Billing();

                        aScheduler.BillingTemplateID = billingTemplateId;
                        //aScheduler.BillingCode = TugBusinessLogic.Utils.AutoGenerateBillCode();
                        aScheduler.BillingName = "";

                        aScheduler.BillingTypeID = billingTypeId;
                        aScheduler.CreateDate = aScheduler.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        aScheduler.Month = DateTime.Now.Month.ToString();
                        aScheduler.OrderID = orderId;
                        aScheduler.OwnerID = -1;

                        aScheduler.Phase = 0;
                        aScheduler.Remark = "";
                        aScheduler.Status = "创建";
                        aScheduler.TimesNo = 0;
                        aScheduler.TimeTypeID = timeTypeId;
                        aScheduler.UserID = Session.GetDataFromSession<int>("userid");
                        aScheduler.Discount = discount;
                        aScheduler.JobNo = jobNo;
                        aScheduler.Remark = remark;
                        aScheduler.Amount = amount;
                        aScheduler.Month = month;

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

                        //if (Request.Form["UserDefinedCol5"].Trim() != "")
                        //    aScheduler.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"].Trim());

                        //if (Request.Form["UserDefinedCol6"].Trim() != "")
                        //    aScheduler.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"].Trim());

                        //if (Request.Form["UserDefinedCol7"].Trim() != "")
                        //    aScheduler.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"].Trim());

                        //if (Request.Form["UserDefinedCol8"].Trim() != "")
                        //    aScheduler.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"].Trim());

                        aScheduler.UserDefinedCol9 = "";
                        aScheduler.UserDefinedCol10 = "";

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

                        List<InVoiceItem> listInVoiceItems = new List<InVoiceItem>();
                        listInVoiceItems = TugBusinessLogic.Utils.JSONStringToList<InVoiceItem>(jsonArrayItems);
                        if (listInVoiceItems != null)
                        {
                            foreach (InVoiceItem item in listInVoiceItems)
                            {
                                BillingItem bi = new BillingItem();
                                bi.BillingID = aScheduler.IDX;
                                bi.SchedulerID = item.SchedulerID;
                                bi.ItemID = item.ItemID;
                                bi.UnitPrice = item.UnitPrice;
                                bi.Currency = item.Currency;
                                bi.OwnerID = -1;
                                bi.UserID = Session.GetDataFromSession<int>("userid");
                                bi.CreateDate = bi.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                bi.UserDefinedCol1 = "";
                                bi.UserDefinedCol2 = "";
                                bi.UserDefinedCol3 = "";
                                bi.UserDefinedCol4 = "";

                                //if (Request.Form["UserDefinedCol5"].Trim() != "")
                                //    aScheduler.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"].Trim());

                                //if (Request.Form["UserDefinedCol6"].Trim() != "")
                                //    aScheduler.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"].Trim());

                                //if (Request.Form["UserDefinedCol7"].Trim() != "")
                                //    aScheduler.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"].Trim());

                                //if (Request.Form["UserDefinedCol8"].Trim() != "")
                                //    aScheduler.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"].Trim());

                                bi.UserDefinedCol9 = "";
                                bi.UserDefinedCol10 = "";

                                bi = db.BillingItem.Add(bi);
                                db.SaveChanges();
                            }
                        }

                        //更新订单的字段 V_OrderInfor_HasInvoice	是否已有帳單
                        {
                            OrderInfor od = db.OrderInfor.FirstOrDefault(u => u.IDX == orderId);
                            //throw new Exception();
                            if (od != null)
                            {
                                od.HasInvoice = "是";
                                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 };
                        //Response.Write(@Resources.Common.SUCCESS_MESSAGE);
                        return Json(ret, JsonRequestBehavior.AllowGet);
                    }

                }
                catch (Exception)
                {
                    trans.Dispose();
                    var ret = new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE };
                    //Response.Write(@Resources.Common.EXCEPTION_MESSAGE);
                    return Json(ret, JsonRequestBehavior.AllowGet);
                }
            }
        }
Exemplo n.º 4
0
        public ActionResult EditInvoice(int orderId, int billingId, int billingTemplateId, int billingTypeId, int timeTypeId, 
            string jobNo, string remark, double discount, double amount, string month, string jsonArrayItems)
        {
            this.Internationalization();

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

                    if (oldBilling != null)
                    {
                        oldBilling.BillingTemplateID = billingTemplateId;
                        oldBilling.BillingTypeID = billingTypeId;
                        oldBilling.TimeTypeID = timeTypeId;
                        oldBilling.Discount = discount;
                        oldBilling.Amount = amount;
                        oldBilling.JobNo = jobNo;
                        oldBilling.Remark = remark;
                        oldBilling.Month = month;
                        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)
                        {
                            List<BillingItem> invoiceItems = db.BillingItem.Where(u => u.BillingID == billingId).ToList();
                            if (invoiceItems != null)
                            {
                                db.BillingItem.RemoveRange(invoiceItems);
                                ret = db.SaveChanges();
                                if (ret > 0)
                                {
                                    List<InVoiceItem> listInVoiceItems = new List<InVoiceItem>();
                                    listInVoiceItems = TugBusinessLogic.Utils.JSONStringToList<InVoiceItem>(jsonArrayItems);
                                    if (listInVoiceItems != null)
                                    {
                                        foreach (InVoiceItem item in listInVoiceItems)
                                        {
                                            BillingItem bi = new BillingItem();
                                            bi.BillingID = billingId;
                                            bi.SchedulerID = item.SchedulerID;
                                            bi.ItemID = item.ItemID;
                                            bi.UnitPrice = item.UnitPrice;
                                            bi.Currency = item.Currency;
                                            bi.OwnerID = -1;
                                            bi.UserID = Session.GetDataFromSession<int>("userid"); ;
                                            bi.CreateDate = bi.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                            bi.UserDefinedCol1 = "";
                                            bi.UserDefinedCol2 = "";
                                            bi.UserDefinedCol3 = "";
                                            bi.UserDefinedCol4 = "";

                                            //if (Request.Form["UserDefinedCol5"].Trim() != "")
                                            //    aScheduler.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"].Trim());

                                            //if (Request.Form["UserDefinedCol6"].Trim() != "")
                                            //    aScheduler.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"].Trim());

                                            //if (Request.Form["UserDefinedCol7"].Trim() != "")
                                            //    aScheduler.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"].Trim());

                                            //if (Request.Form["UserDefinedCol8"].Trim() != "")
                                            //    aScheduler.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"].Trim());

                                            bi.UserDefinedCol9 = "";
                                            bi.UserDefinedCol10 = "";

                                            bi = db.BillingItem.Add(bi);
                                            ret = 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<InVoiceItem> listInVoiceItems = new List<InVoiceItem>();
                                listInVoiceItems = TugBusinessLogic.Utils.JSONStringToList<InVoiceItem>(jsonArrayItems);
                                if (listInVoiceItems != null)
                                {
                                    foreach (InVoiceItem item in listInVoiceItems)
                                    {
                                        BillingItem bi = new BillingItem();
                                        bi.BillingID = billingId;
                                        bi.SchedulerID = item.SchedulerID;
                                        bi.ItemID = item.ItemID;
                                        bi.UnitPrice = item.UnitPrice;
                                        bi.Currency = item.Currency;
                                        bi.OwnerID = -1;
                                        bi.UserID = Session.GetDataFromSession<int>("userid"); ;
                                        bi.CreateDate = bi.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                        bi.UserDefinedCol1 = "";
                                        bi.UserDefinedCol2 = "";
                                        bi.UserDefinedCol3 = "";
                                        bi.UserDefinedCol4 = "";

                                        //if (Request.Form["UserDefinedCol5"].Trim() != "")
                                        //    aScheduler.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"].Trim());

                                        //if (Request.Form["UserDefinedCol6"].Trim() != "")
                                        //    aScheduler.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"].Trim());

                                        //if (Request.Form["UserDefinedCol7"].Trim() != "")
                                        //    aScheduler.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"].Trim());

                                        //if (Request.Form["UserDefinedCol8"].Trim() != "")
                                        //    aScheduler.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"].Trim());

                                        bi.UserDefinedCol9 = "";
                                        bi.UserDefinedCol10 = "";

                                        bi = db.BillingItem.Add(bi);
                                        ret = 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
                    {
                        return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }, JsonRequestBehavior.AllowGet);
                    }
                }
            }
            catch (Exception)
            {
                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 });
        }