public void IsContractAvailable()
        {
            var result = ContractData.IsContractAvailable();

            Assert.IsTrue(result);
        }
        public void EmptyContract()
        {
            var result = ContractData.EmptyContract();

            Assert.AreEqual(0, result.Count());
        }
        public void PaymentDailyReceipts2(DailyReceiptsReport item)
        {
            if (item.PriceReceipts <= 0)
            {
                throw new Exception("จำนวนเงินต้องมากว่า 0 บาท");
            }

            string           StrSql = string.Empty;
            ContractData     ct     = new ContractData();
            IList <Contract> list   = new List <Contract>();

            list = ct.GetContract(item.CustomerID, item.ContractID);
            Contract contract = new Contract();

            contract = list.FirstOrDefault();


            //get วันที่จ่ายล่าสุด
            ReportData data = new ReportData();
            IList <LastTransaction> listData1 = new List <LastTransaction>();

            listData1 = data.GetTransaction(item.StaffID.ToString(), item.CustomerID.ToString(), item.ContractID.ToString());
            listData1 = listData1.OrderByDescending(c => c.DateAsOf).ToArray();

            MySqlConnection ObjConn = DBHelper.ConnectDb(ref errMsg);

            try
            {
                DateTime LastDate = listData1.FirstOrDefault().DateAsOf; //วันที่จ่านล่าสุด
                decimal  LastPay  = listData1.FirstOrDefault().Amount;   //วันที่จ่านล่าสุด

                decimal totalsales = contract.ContractPayment;           // ยอดเงินทั้งหมด
                decimal rate       = contract.ContractInterest;          //ดอกเบี้ย
                decimal amount     = contract.ContractAmount;            //จำนวนที่จ่ายรายวัน
                decimal interest   = item.PriceReceipts * (rate / 100);  //ดอกเบี้ย
                decimal Priciple   = item.PriceReceipts - interest;      // เงินต้น


                if (item.PriceReceipts <= amount)   // จ่ายพอดี
                {
                    item.ID = Utility.GetMaxID("daily_receipts", "ID");
                    StrSql  = @" INSERT INTO daily_receipts(ID,CustomerID,ContractID,DateAsOf,
            TotalSales,PriceReceipts,Principle,Interest,StaffID,Latitude,Longitude,Activated,Deleted)
            VALUES("

                              + item.ID + ","
                              + item.CustomerID + ","
                              + item.ContractID + ","
                              + Utility.FormateDateTime(DateTime.Now) + ","
                              + totalsales + ","
                              + item.PriceReceipts + ","
                              + Priciple + ","
                              + interest + ","
                              + item.StaffID + ","
                              + item.Latitude + ","
                              + item.Longitude + ","
                              + 0 + ","
                              + 0 + ");";

                    DBHelper.Execute(StrSql, ObjConn);
                }
                else if (item.PriceReceipts > amount)   // จ่ายเกิน
                {
                    decimal price = item.PriceReceipts;
                    int     k     = 0;
                    while (price >= amount)
                    {
                        item.ID = Utility.GetMaxID("daily_receipts", "ID");
                        StrSql  = @" INSERT INTO daily_receipts(ID,CustomerID,ContractID,DateAsOf,
            TotalSales,PriceReceipts,Principle,Interest,StaffID,Latitude,Longitude,Activated,Deleted)
            VALUES("

                                  + item.ID + ","
                                  + item.CustomerID + ","
                                  + item.ContractID + ","
                                  + Utility.FormateDateTime(DateTime.Now.AddDays(k)) + ","
                                  + totalsales + ","
                                  + amount + ","
                                  + (amount - (amount * (rate / 100))) + ","
                                  + (amount * (rate / 100)) + ","
                                  + item.StaffID + ","
                                  + item.Latitude + ","
                                  + item.Longitude + ","
                                  + 0 + ","
                                  + 0 + ");";

                        DBHelper.Execute(StrSql, ObjConn);

                        price = price - amount;
                        k     = k + 1;


                        //เหลือเศษ
                        if (price < amount)
                        {
                            item.ID = Utility.GetMaxID("daily_receipts", "ID");
                            StrSql  = @" INSERT INTO daily_receipts(ID,CustomerID,ContractID,DateAsOf,
            TotalSales,PriceReceipts,Principle,Interest,StaffID,Latitude,Longitude,Activated,Deleted)
            VALUES("

                                      + item.ID + ","
                                      + item.CustomerID + ","
                                      + item.ContractID + ","
                                      + Utility.FormateDateTime(DateTime.Now.AddDays(k)) + "," // Get วัน อนาคต
                                      + totalsales + ","
                                      + price + ","
                                      + (price - (price * (rate / 100))) + ","
                                      + (price * (rate / 100)) + ","
                                      + item.StaffID + ","
                                      + item.Latitude + ","
                                      + item.Longitude + ","
                                      + 0 + ","
                                      + 0 + ");";
                            DBHelper.Execute(StrSql, ObjConn);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally {
                ObjConn.Close();
            }
        }
 void AddNewContractButton(RectTransform ParentPanel, ContractData _contract)
 {
     GameObject new_contract = (GameObject)Instantiate(contract_button_prefab);
     new_contract.transform.SetParent(ParentPanel, false);
     new_contract.transform.localScale = new Vector3(1, 1, 1);
     //new_contract.GetComponentInChildren<Text>().text = _contract.contractType.ToString();
     new_contract.GetComponent<ContractButton>().button_text.text = _contract.contractName;
     new_contract.GetComponent<ContractButton>().contract = _contract;
     contracts.Add(new_contract);
 }
Exemplo n.º 5
0
 public static void Register(Type type, ContractData contract)
 {
 }
        public void PaymentDailyReceipts(DailyReceiptsReport item)
        {
            if (item.PriceReceipts <= 0)
            {
                throw new Exception("จำนวนเงินต้องมากว่า 0 บาท");
            }


            string           StrSql = string.Empty;
            ContractData     ct     = new ContractData();
            IList <Contract> list   = new List <Contract>();

            list = ct.GetContract(item.CustomerID, item.ContractID);
            Contract contract = new Contract();

            contract = list.FirstOrDefault();

            decimal totalsales   = contract.ContractPayment;  // ยอดเงินทั้งหมด
            decimal rate         = contract.ContractInterest; //ดอกเบี้ย
            decimal amount       = contract.ContractAmount;   //จำนวนที่จ่ายรายวัน
            decimal priceReciept = item.PriceReceipts;

            decimal interest = item.PriceReceipts * (rate / 100); //ดอกเบี้ย
            decimal Priciple = item.PriceReceipts - interest;     // เงินต้น


            DataTable dt = new DataTable();

            MySqlConnection ObjConn = DBHelper.ConnectDb(ref errMsg);

            dt = DBHelper.List("select * FROM daily_receipts WHERE ContractID=" + item.ContractID +
                               "  and PriceReceipts!=Principle  order by PriceReceipts desc",
                               ObjConn);

            if (dt.Rows.Count > 0)
            {
                // ข้อมูลการจ่ายทั้งหมด
                int TotalReceiptID = Utility.GetMaxID("daily_totalreceipts", "TotalReceiptID");
                StrSql = @" INSERT INTO daily_totalreceipts(TotalReceiptID,CustomerID,ContractID,DateAsOf,
                TotalSales,PriceReceipts,Principle,Interest,StaffID,Activated,Deleted)
                VALUES("
                         + TotalReceiptID + ","
                         + item.CustomerID + ","
                         + item.ContractID + ","
                         + Utility.FormateDateTime(DateTime.Now) + ","
                         + totalsales + ","
                         + item.PriceReceipts + ","
                         + (item.PriceReceipts - (item.PriceReceipts * (rate / 100))) + ","
                         + (item.PriceReceipts * (rate / 100)) + ","
                         + item.StaffID + ","
                         + 1 + ","
                         + 0 +
                         ");";

                DBHelper.Execute(StrSql, ObjConn);

                decimal price = 0;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (priceReciept > 0)
                    {
                        //ครั้งก่อนยังจ่ายไม่เต็ม
                        if (Convert.ToDecimal(dt.Rows[i]["PriceReceipts"]) < amount)
                        {
                            //จำนวนเงินที่ขาด
                            price = (amount - Convert.ToDecimal(dt.Rows[i]["PriceReceipts"]));
                            if (priceReciept < price)
                            {
                                DBHelper.List("UPDATE daily_receipts SET " +
                                              "  PriceReceipts = PriceReceipts+" + priceReciept +
                                              "  ,StaffID =" + item.StaffID +
                                              "  ,Interest =" + interest +
                                              "   WHERE ContractID =" + item.ContractID + " and  DateAsOf='" + Convert.ToDateTime(dt.Rows[i]["DateAsOf"]).ToString(@"yyyy/MM/dd") + "'", ObjConn);
                                priceReciept = priceReciept - price;
                            }
                            else if (priceReciept >= price)
                            {
                                DBHelper.List("UPDATE daily_receipts SET " +
                                              "  PriceReceipts = PriceReceipts+" + price +
                                              "  ,StaffID =" + item.StaffID +
                                              "  ,Interest =" + interest +
                                              "   WHERE ContractID =" + item.ContractID + " and  DateAsOf='" + Convert.ToDateTime(dt.Rows[i]["DateAsOf"]).ToString(@"yyyy/MM/dd") + "'", ObjConn);
                                priceReciept = priceReciept - price;
                            }

                            //if (priceReciept >= amount)
                            //{
                            //    price = (amount - Convert.ToDecimal(dt.Rows[i]["PriceReceipts"]));
                            //    priceReciept = priceReciept - price;
                            //    DBHelper.List("UPDATE daily_receipts SET " +
                            //     "  PriceReceipts = PriceReceipts+" + price +
                            //     "  ,StaffID =" + item.StaffID +
                            //     "  ,Interest =" + interest +
                            //     "   WHERE ContractID =" + item.ContractID + " and  DateAsOf='" + Convert.ToDateTime(dt.Rows[i]["DateAsOf"]).ToString(@"yyyy/MM/dd") + "'", ObjConn);

                            //}
                            //else if (priceReciept< amount)   //เงินไม่พอ
                            //{
                            //    // เช็ค ตัวที่ยังไม่ครบ
                            //    if (Convert.ToDecimal(dt.Rows[i]["PriceReceipts"]) < amount){
                            //        if (priceReciept < amount) {
                            //            price = (amount - Convert.ToDecimal(dt.Rows[i]["PriceReceipts"]);

                            //        }
                            //        priceReciept = priceReciept - Convert.ToDecimal(dt.Rows[i]["PriceReceipts"]);

                            //        DBHelper.List("UPDATE daily_receipts SET " +
                            //         "  PriceReceipts = PriceReceipts + " + priceReciept +
                            //         "  ,StaffID =" + item.StaffID +
                            //         "  ,Interest =" + interest +
                            //         "   WHERE ContractID =" + item.ContractID + " and  DateAsOf='" + Convert.ToDateTime(dt.Rows[i]["DateAsOf"]).ToString(@"yyyy/MM/dd") + "'", ObjConn);

                            //    }

                            //    DBHelper.List("UPDATE daily_receipts SET " +
                            //     "  PriceReceipts = PriceReceipts + " + priceReciept +
                            //     "  ,StaffID =" + item.StaffID +
                            //     "  ,Interest =" + interest +
                            //     "   WHERE ContractID =" + item.ContractID + " and  DateAsOf='" + Convert.ToDateTime(dt.Rows[i]["DateAsOf"]).ToString(@"yyyy/MM/dd") + "'", ObjConn);
                            //    priceReciept = priceReciept - priceReciept;
                            //}
                        }//ปัจจุบัน
                    }
                    else
                    {
                        i = dt.Rows.Count;
                    }
                } // loop for
            }
        }
Exemplo n.º 7
0
 private void ClickCustomerBtn(ContractData contractData)
 {
     panelContractInformation.contractData = contractData;
     panelContractInformation.ReqOpenWnd();
 }
Exemplo n.º 8
0
 public MarketDataRecord(Instrument instrument, ContractData contract)
 {
     this.Instrument = instrument;
     this.Contract = contract;
     this.Tracker = new MDTracker (contract.PriceMultiplier);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Calculate the difficulty of a certain scene w.r.t a certain contract
 /// </summary>
 /// <param name="_scene"></param>
 /// <param name="_contract"></param>
 /// <returns></returns>
 public int SceneDifficulty(SceneData _scene, ContractData _contract)
 {
     int ret = _scene.baseDifficulty;
     GenreData highestGenre = _contract.genre[0];
     foreach (GenreData g in _contract.genre)
     {
         if (g.genreDifficulty > highestGenre.genreDifficulty)
         {
             highestGenre = g;
         }
     }
     ret += highestGenre.genreDifficulty;
     int sum = 0;
     foreach (GenreData g in _contract.genre)
     {
         if (g != highestGenre)
         {
             sum += g.genreDifficulty;
         }
     }
     ret += (int)(secondaryGenreWeight * sum);
     int diff = 0;
     foreach(SkillReq s in _contract.skill)
     {
         foreach(SkillData sk in currentSkills)
         {
             if(s.skillType == sk.skillType && sk.skillLevel > s.minReq)
             {
                 diff += sk.skillLevel - s.minReq;
             }
         }
     }
     ret -= (int)(skillBonusWeight * diff);
     ret += (int)(sequelDifficulty * _contract.prequel.Count);
     if(ret <= 1)
     {
         ret = 1;
     }
     else if(ret > 100)
     {
         ret = 100;
     }
     return ret;
 }
Exemplo n.º 10
0
        public async Task ExtractAsync(List <XmlElements.Contract> validContracts)
        {
            var contracts = new List <Contract>();

            foreach (var con in validContracts)
            {
                var originalAmount = con.ContractData.OriginalAmount != null?
                                     Money.New(con.ContractData.OriginalAmount.Value,
                                               con.ContractData.OriginalAmount.Currency)
                                         : new Money();

                var installmentAmount = con.ContractData.InstallmentAmount != null?
                                        Money.New(con.ContractData.InstallmentAmount.Value,
                                                  con.ContractData.InstallmentAmount.Currency)
                                            : new Money();

                var currentBalance = Money.New(con.ContractData.OriginalAmount.Value,
                                               con.ContractData.OriginalAmount.Currency);

                var overdueBalance = con.ContractData.OverdueBalance != null?
                                     Money.New(con.ContractData.OverdueBalance.Value, con.ContractData.OverdueBalance.Currency)
                                         : new Money();

                var contractData = ContractData.New(
                    originalAmount,
                    installmentAmount,
                    currentBalance,
                    overdueBalance,
                    con.ContractData.DateOfLastPayment,
                    con.ContractData.NextPaymentDate,
                    con.ContractData.DateAccountOpened,
                    con.ContractData.RealEndDate
                    );

                var individuals = new List <Individual>();
                foreach (var ind in con.Individual)
                {
                    var individual = Individual.New(
                        ind.CustomerCode,
                        ind.FirstName,
                        ind.LastName,
                        ind.Gender,
                        ind.DateOfBirth,
                        ind.IdentificationNumbers.NationalID.FirstOrDefault()
                        );
                    individuals.Add(individual);
                }

                var subjectRoles = new List <SubjectRole>();
                foreach (var role in con.SubjectRole)
                {
                    var guaranteeAmount = role.GuaranteeAmount is null ? new Money()
                    : Money.New(role.GuaranteeAmount.Value, role.GuaranteeAmount.Currency);

                    var subjectRole = SubjectRole.New(role.CustomerCode,
                                                      role.RoleOfCustomer.Value,
                                                      guaranteeAmount
                                                      );

                    subjectRoles.Add(subjectRole);
                }

                var contract = Contract.New(con.ContractCode,
                                            contractData,
                                            individuals,
                                            subjectRoles);

                if (contract.IsValid())
                {
                    contracts.Add(contract);
                }
            }

            await SaveData(contracts);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Evaluate the rating for the given contract
 /// </summary>
 /// <param name="_contract"></param>
 /// <returns> Rating </returns>
 public float EvaluateContract(ContractData _contract)
 {
     float rating = 0;
     rating += _contract.baseRating;
     int baseRating = 0;
     foreach (SkillReq s in _contract.skill)
     {
         foreach (SkillData sk in currentSkills)
         {
             if (s.skillType == sk.skillType && sk.skillLevel > s.minReq)
             {
                 baseRating += (int)((sk.skillLevel - s.minReq) * s.weight);
             }
         }
     }
     rating += skillRatingMultiplier * baseRating;
     rating += tempBonus;
     AddCash(_contract.baseCash, "Payment");
     float cashToAdd = ((Mathf.Max(0, rating - 5) / 2.5f)) * _contract.baseCash;
     AddCash(cashToAdd, "Rating Bonus");
     AddCash(fanToCash * cashToAdd, "Fan Bonus");
     AddXP(((Mathf.Max(0, rating - 5) / 2.5f) + 1) * _contract.baseXP);
     AddSP(((int)(Mathf.Max(0, rating - 5) / 1.6f) + 1) * _contract.baseSP);
     fans += ((int)(rating * rating) - 24) * fansMultiplier * ((int)Mathf.Sqrt(level));
     foreach(GenreData g in _contract.genre)
     {
         if(g.genreType == GameManager.Instance.currentTrend)
         {
             fans += fanTrendMultiplier;
         }
     }
     _contract.ratingAchieved = rating;
     _contract.completed = true;
     completedContracts.Add(_contract);
     GameManager.Instance.contractByYear[GameManager.Instance.currentYear - GameManager.Instance.GetFirstYear()].contractGrp.Remove(_contract);
     UIManager.Instance.PopulateContracts();
     tempBonus = 0;
     if (_contract.oscarWorthy && rating > 9)
     {
         oscarQueued = true;
         oscarMovie = _contract;
     }
     return rating;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Check if it is possible to take the contract
 /// </summary>
 /// <param name="_contract"></param>
 /// <returns></returns>
 public bool ContractPossibility(ContractData _contract)
 {
     int count = 0;
     foreach (SkillReq s in _contract.skill)
     {
         foreach (SkillData sk in currentSkills)
         {
             if (s.skillType == sk.skillType)
             {
                 if(sk.skillLevel < s.minReq)
                 {
                     return false;
                 }
                 else
                 {
                     count++;
                 }
             }
         }
     }
     if(count < _contract.skill.Count)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
Exemplo n.º 13
0
        public List <ServerInventoryItem> GiveRewards(string contractId, MmoActor player)
        {
            List <ServerInventoryItem> items = new List <ServerInventoryItem>();

            ContractData contractData = player.resource.contracts.GetContract(contractId);

            if (contractData != null)
            {
                foreach (var reward in contractData.rewards.rewards)
                {
                    switch (reward.type)
                    {
                    case Common.ContractRewardType.credits:
                        GiveCreditsReward(player, reward as ContractCreditsDataReward);
                        break;

                    case Common.ContractRewardType.exp:
                        GiveExpReward(player, reward as ContractExpDataReward);
                        break;

                    case Common.ContractRewardType.ore: {
                        var item = GiveOreReward(player, reward as ContractOreDataReward);
                        if (item != null)
                        {
                            items.Add(item);
                        }
                    }
                    break;

                    case Common.ContractRewardType.weapon: {
                        var item = GiveWeaponReward(player, reward as ContractWeaponDataReward);
                        if (item != null)
                        {
                            items.Add(item);
                        }
                    }
                    break;

                    case ContractRewardType.scheme: {
                        var item = GiveSchemeReward(player, reward as ContractSchemeDataReward);
                        if (item != null)
                        {
                            items.Add(item);
                        }
                    }
                    break;

                    case ContractRewardType.nebula_element: {
                        var item = GiveNebulaElement(player, reward as ContractNebulaElementDataReward);
                        if (item != null)
                        {
                            items.Add(item);
                        }
                    }
                    break;

                    case ContractRewardType.craft_resource: {
                        var item = GiveCraftResource(player, reward as ContractCraftResourceDataReward);
                        if (item != null)
                        {
                            items.Add(item);
                        }
                    }
                    break;

                    case ContractRewardType.turret: {
                        var item = GiveTurretReward(player, reward as ContractTurretDataReward);
                        if (item != null)
                        {
                            items.Add(item);
                        }
                    }
                    break;

                    case ContractRewardType.craft_resource_special: {
                        var item = GiveCraftResourceSpecial(player, reward as ContractCraftResourceSpecialReward);
                        if (item != null)
                        {
                            items.Add(item);
                        }
                    }
                    break;
                    }
                }
            }

            if (items.Count > 0)
            {
                foreach (var item in items)
                {
                    player.Station.StationInventory.Add(item.Object, item.Count);
                }
                player.EventOnStationHoldUpdated();
            }
            return(items);
        }
Exemplo n.º 14
0
        public JsonResult PostEdit_Contract(Contract item)
        {
            int Surety1 = 0;
            int Surety2 = 0;
            int parner  = 0;

            try
            {
                if (Session["iuser"] == null)
                {
                    throw new Exception(" Session หมดอายุ , กรุณาเข้าสู่ระบบใหม่อีกครั้ง !! ");
                }

                item.ContractInsertBy = (Int32)Session["iuser"];


                ContractData CD = new ContractData();
                CD.Edit_NewContract(item);

                if (item.CustomerPartnerData != null)
                {
                    //check insert Partner
                    if (item.CustomerPartner == 0)
                    {
                        parner = CD.Add_Partner(item.CustomerPartnerData);
                        item.CustomerPartner = parner;
                    }
                    else
                    {
                        parner = CD.Update_Partner(item.CustomerPartnerData);
                    }
                }


                //check insert Surety1
                if (item.CustomerSuretyData1 != null)
                {
                    if (item.CustomerSurety1 == 0 & item.CustomerSuretyData1 != null)
                    {
                        Surety1 = CD.Add_Surety(item.CustomerSuretyData1);
                        item.CustomerSurety1 = Surety1;
                    }
                    else
                    {
                        Surety1 = CD.Update_Surety(item.CustomerSuretyData1);
                    }
                }


                //check insert Surety1
                if (item.CustomerSuretyData2 != null)
                {
                    if (item.CustomerSurety2 == 0 & item.CustomerSuretyData2 != null)
                    {
                        Surety2 = CD.Add_Surety(item.CustomerSuretyData2);
                        item.CustomerSurety2 = Surety2;
                    }
                    else
                    {
                        Surety2 = CD.Update_Surety(item.CustomerSuretyData2);
                    }
                }

                //Update Product this Contract
                CD.Update_Product_customer(item);


                // getProduct By Contract
                ProductData           dataPro            = new ProductData();
                IList <ProductSelect> listProductsSelect = new List <ProductSelect>();
                listProductsSelect = dataPro.GetProductCustomer(item.ContractCustomerID, item.ContractID);



                double ContractPayment = 0;
                List <ProductSelect> listProductsSelect1 = new List <ProductSelect>();
                listProductsSelect1 = dataPro.ProductContractSummary(ref ContractPayment, listProductsSelect);

                item.ContractPayment = Convert.ToDecimal(Math.Round(ContractPayment, 2));

                // update จำนวนเงินสินค้าทั้งหมด
                CD.UpdateContractPayment(item.ContractID, item.ContractCustomerID, ContractPayment);

                // Update Contract Surety

                CD.UpdateSurety_In_Contract(item);

                // คำนวณ ค่างวด / วันสิ้นสุดสัญญา

                CD.UpdateContractAmount_ContractExpDate(item.ContractCustomerID, item.ContractID);
                return(Json(new
                {
                    data = "บันทึกการแก้ไขสัญญาสำเร็จ",
                    success = true
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    data = ex.Message,
                    success = false
                }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 15
0
        public JsonResult PostAdd_NewContract(Contract item)
        {
            ContractData CD         = new ContractData();
            int          Surety1    = 0;
            int          Surety2    = 0;
            int          ContractID = 0;
            int          parner     = 0;

            try
            {
                if (Session["iuser"] == null)
                {
                    throw new Exception(" Session หมดอายุ , กรุณาเข้าสู่ระบบใหม่อีกครั้ง !! ");
                }

                item.ContractInsertBy = (Int32)Session["iuser"];

                ContractID = CD.Add_NewContract(item);


                if (item.CustomerSuretyData1 != null)
                {
                    Surety1 = CD.Add_Surety(item.CustomerSuretyData1);
                }

                if (item.CustomerSuretyData2 != null)
                {
                    Surety2 = CD.Add_Surety(item.CustomerSuretyData2);
                }

                if (item.CustomerPartnerData != null)
                {
                    parner = CD.Add_Partner(item.CustomerPartnerData);
                }

                item.ContractID      = ContractID;
                item.CustomerSurety1 = Surety1;
                item.CustomerSurety2 = Surety2;
                item.CustomerPartner = parner;

                //Update Product this Contract
                CD.Update_Product_customer(item);
                // getProduct By Contract
                ProductData           dataPro            = new ProductData();
                IList <ProductSelect> listProductsSelect = new List <ProductSelect>();
                listProductsSelect   = dataPro.GetProductCustomer(item.ContractCustomerID, ContractID);
                item.ContractPayment = Convert.ToDecimal(listProductsSelect.Sum(c => c.ProductPrice));
                // Update Contract Surety
                CD.UpdateSurety_In_Contract(item);



                return(Json(new
                {
                    ContractID = ContractID,
                    data = "บันทึกการทำสัญญาสำเร็จ",
                    success = true
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    ContractID = 0,
                    data = ex.Message,
                    success = false
                }, JsonRequestBehavior.AllowGet));
            }
        }