/// <summary> /// Create meta data object. /// </summary> /// <returns>Returns the ModificationMetaData object.</returns> internal static ModificationMetaData CreateMetaDataObject() { ModificationMetaData mmd = new ModificationMetaData(); mmd.CreatedByRef = CreateReferenceType(); mmd.CreateTime = DateTime.Now; mmd.CreateTimeSpecified = true; mmd.LastModifiedByRef = CreateReferenceType(); mmd.LastUpdatedTime = DateTime.Now; mmd.LastUpdatedTimeSpecified = true; return(mmd); }
public JsonResult MakePaymentData(PaymentModel objPaymentModel, PaymentModel ObjData) { eTracLoginModel ObjLoginModel = null; long Vendor = 0; var result = ""; var resultPayment = new BillPayment(); if (Session["eTrac"] != null) { ObjLoginModel = (eTracLoginModel)(Session["eTrac"]); } try { if (objPaymentModel != null && ObjData != null) { objPaymentModel.UserId = ObjLoginModel.UserId; string realmId = CallbackController.RealMId.ToString(); // Session["realmId"].ToString(); try { if (realmId != null) { string AccessToken = CallbackController.AccessToken.ToString(); //Session["access_token"].ToString(); var principal = User as ClaimsPrincipal; OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(AccessToken); // Create a ServiceContext with Auth tokens and realmId ServiceContext serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, oauthValidator); serviceContext.IppConfiguration.MinorVersion.Qbo = "23"; DataService commonServiceQBO = new DataService(serviceContext); // Create a QuickBooks QueryService using ServiceContext QueryService <Vendor> querySvc = new QueryService <Vendor>(serviceContext); List <Vendor> vendorList = querySvc.ExecuteIdsQuery("SELECT * FROM Vendor MaxResults 1000").ToList(); QueryService <Account> querySvcAccount = new QueryService <Account>(serviceContext); List <Account> accountData = querySvcAccount.ExecuteIdsQuery("SELECT * FROM Account MaxResults 1000").ToList(); var VendorDetails = _IVendorManagement.GetCompanyQuickBookId(Convert.ToInt64(ObjData.VendorId)); //var getAccountDetails = _IVendorManagement.GetAccountDetailsByVendorId(Convert.ToInt64(objPaymentModel.OpeartorCAD_Id)); // (Convert.ToInt64(ObjData.VendorId)); var getAccountDetails = _IVendorManagement.GetAccountDetailsByVendorId(Convert.ToInt64(objPaymentModel.CompanyAccountId)); // (Convert.ToInt64(ObjData.VendorId)); var getBill = _IBillDataManager.GetBillQBKId(Convert.ToInt64(ObjData.BillNo)); QueryService <Bill> querySvcBill = new QueryService <Bill>(serviceContext); List <Bill> billData = querySvcBill.ExecuteIdsQuery("SELECT * FROM Bill MaxResults 1000").ToList(); var bill = billData.Where(x => x.Id == getBill.ToString()).FirstOrDefault(); // var vendorData = vendorList.Where(x => x.Id == "64").FirstOrDefault(); var payment = new BillPayment(); //Vendor Reference var reference = new ReferenceType(); var accountRef = new AccountBasedExpenseLineDetail(); var billPaymentCheck = new BillPaymentCheck(); var billPaymentCredit = new BillPaymentCreditCard(); var line = new Line(); var lineList = new List <Line>(); if (VendorDetails > 0) { var vendorData = vendorList.Where(x => x.Id == VendorDetails.ToString()).FirstOrDefault(); //Vendor Reference payment.VendorRef = new ReferenceType() { name = vendorData.DisplayName, Value = vendorData.Id }; } line.LineNum = "1"; var any = new IntuitAnyType(); if (getAccountDetails != null) { var ayintuit = new IntuitAnyType(); var accountsDetails = accountData.Where(x => x.Id == getAccountDetails.QuickbookAcountId.ToString()).FirstOrDefault();//getAccountDetails.QuickbookAcountId.ToString() if (ObjData.PaymentMode == "Wired") { payment.PayType = BillPaymentTypeEnum.CreditCard; var CCD = new CreditCardPayment(); billPaymentCredit.CCAccountRef = new ReferenceType() { name = accountsDetails.Name, Value = accountsDetails.Id, }; payment.AnyIntuitObject = billPaymentCredit; } else if (ObjData.PaymentMode == "Card") { payment.PayType = BillPaymentTypeEnum.CreditCard; var CCD = new CreditCardPayment(); billPaymentCredit.CCAccountRef = new ReferenceType() { name = accountsDetails.Name, Value = accountsDetails.Id, }; payment.AnyIntuitObject = billPaymentCredit; } else if (ObjData.PaymentMode == "Check") { var checking = new CheckPayment(); payment.PayType = BillPaymentTypeEnum.Check; billPaymentCheck.BankAccountRef = new ReferenceType() { name = accountsDetails.Name, Value = accountsDetails.Id }; billPaymentCheck.PrintStatus = PrintStatusEnum.NeedToPrint; payment.AnyIntuitObject = billPaymentCheck; } } payment.APAccountRef = new ReferenceType() { name = "Accounts Payable (A/P)", Value = "33" }; QueryService <Department> querySvcDept = new QueryService <Department>(serviceContext); var LocationName = _IBillDataManager.GetLocationDataByLocId(Convert.ToInt64(ObjData.LocationId)); payment.DepartmentRef = new ReferenceType() { name = LocationName.LocationName, Value = LocationName.QBK_Id.ToString() }; line.Amount = Convert.ToDecimal(ObjData.BillAmount); line.AmountSpecified = true; var linkedlist = new List <LinkedTxn>(); var linked = new LinkedTxn(); linked.TxnId = bill.Id; linked.TxnType = "Bill"; linkedlist.Add(linked); line.LinkedTxn = linkedlist.ToArray(); line.DetailType = LineDetailTypeEnum.PaymentLineDetail; lineList.Add(line); payment.Line = lineList.ToArray(); //payment.PayType = BillPaymentTypeEnum.CreditCard; payment.PayTypeSpecified = true; payment.TotalAmt = Convert.ToDecimal(ObjData.BillAmount); payment.TotalAmtSpecified = true; var metaData = new ModificationMetaData(); metaData.CreateTime = Convert.ToDateTime(ObjData.BillDate); payment.MetaData = metaData; payment.PayTypeSpecified = true; resultPayment = commonServiceQBO.Add(payment) as BillPayment; //To close PO after Payment. Update Payment in Quickbook. QueryService <PurchaseOrder> querySvcPO = new QueryService <PurchaseOrder>(serviceContext); List <PurchaseOrder> POList = querySvcPO.ExecuteIdsQuery("SELECT * FROM PurchaseOrder MaxResults 1000").ToList(); if (ObjData.BillType == "PO") { var getPOQData = _IPaymentManager.GetPODetails(objPaymentModel, ObjData); if (getPOQData.QuickBookPOId > 0) { var data = POList.Where(x => x.Id == getPOQData.QuickBookPOId.ToString()).FirstOrDefault(); data.POStatus = PurchaseOrderStatusEnum.Closed; var update = commonServiceQBO.Update(data) as PurchaseOrder; } } } else { ViewBag.Message = CommonMessage.FailureMessage(); result = CommonMessage.FailureMessage(); ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger; return(Json(result, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { ViewBag.Message = ex.Message; ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger; } result = _IPaymentManager.MakePayment(objPaymentModel, ObjData); if (result != null) { return(Json(result, JsonRequestBehavior.AllowGet)); } else { ViewBag.Message = CommonMessage.FailureMessage(); ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger; return(Json(result, JsonRequestBehavior.AllowGet)); } } else { ViewBag.Message = CommonMessage.FailureMessage(); ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger; } } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } //return null; return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult ApproveBillData(BillListApproveModel Obj, long LocationId, List <BillFacilityModel> FacilityData) { eTracLoginModel ObjLoginModel = null; string result = ""; string UserName = ""; string data = ""; long UserId = 0; var resultBill = new Bill(); if (Session["eTrac"] != null) { ObjLoginModel = (eTracLoginModel)(Session["eTrac"]); } try { if (Obj != null && Obj.BillId > 0) { UserName = ObjLoginModel.UserName; UserId = ObjLoginModel.UserId; //if (Session["realmId"] != null) //{ string realmId = CallbackController.RealMId.ToString();// Session["realmId"].ToString(); try { string AccessToken = CallbackController.AccessToken.ToString(); //Session["access_token"].ToString(); if (AccessToken == null) { AccessToken = Session["refresh_token"].ToString(); AccessToken = CallbackController.AccessToken.ToString(); } var principal = User as ClaimsPrincipal; OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(AccessToken); // Create a ServiceContext with Auth tokens and realmId ServiceContext serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, oauthValidator); serviceContext.IppConfiguration.MinorVersion.Qbo = "23"; DataService commonServiceQBO = new DataService(serviceContext); // Create a QuickBooks QueryService using ServiceContext QueryService <Vendor> querySvc = new QueryService <Vendor>(serviceContext); List <Vendor> vendorList = querySvc.ExecuteIdsQuery("SELECT * FROM Vendor MaxResults 1000").ToList(); QueryService <Account> querySvcBill = new QueryService <Account>(serviceContext); List <Account> BillList = querySvcBill.ExecuteIdsQuery("SELECT * FROM Account MaxResults 1000").ToList(); var VendorDetails = _IVendorManagement.GetCompanyQuickBookId(Convert.ToInt64(Obj.VendorId)); //var vendorData = vendorList.Where(x => x.Id == "64").FirstOrDefault(); //var dataget = BillList.Where(x => x.Name == "Sample1").FirstOrDefault(); var bill = new Bill(); //Vendor Reference var reference = new ReferenceType(); var accountRef = new AccountBasedExpenseLineDetail(); if (VendorDetails > 0) { var vendorData = vendorList.Where(x => x.Id == VendorDetails.ToString()).FirstOrDefault(); //Vendor Reference bill.VendorRef = new ReferenceType() { name = vendorData.DisplayName, Value = vendorData.Id }; } //End Vendor Reference bill.TotalAmt = Convert.ToDecimal(Obj.BillAmount); var metaData = new ModificationMetaData(); metaData.CreateTime = Convert.ToDateTime(Obj.InvoiceDate); bill.MetaData = metaData; //End Time var LocationName = _IBillDataManager.GetLocationDataByLocId(LocationId); bill.DepartmentRef = new ReferenceType() { name = LocationName.LocationName, Value = LocationName.QBK_Id.ToString() }; Line line = new Line(); List <Line> lineList = new List <Line>(); bill.APAccountRef = new ReferenceType() { name = "Accounts Payable (A/P)", Value = "33" }; int i = 1; var costArray = new List <long>(); var costCodeArray = new List <CostCodeListData>(); var costDataModel = new CostCodeListData(); decimal amt = 0; decimal?Total = 0; if (FacilityData != null && FacilityData.Count() > 0) { foreach (var item in FacilityData) { long CostCodeId = Convert.ToInt64(item.CostCodeId); var costCodeName = _IBillDataManager.GetCostCodeData(CostCodeId); var dataget = BillList.Where(x => x.Name == costCodeName.Description).FirstOrDefault(); accountRef.AccountRef = new ReferenceType() { name = dataget.Name, Value = dataget.Id }; if (costCodeArray.Count() > 0) { foreach (var tt in costCodeArray) { if (tt.CostCodeId == item.CostCodeId) { amt = Convert.ToDecimal(item.Amount); Total = amt + tt.Amount; line.Amount = Convert.ToDecimal(Total); } else { line.Amount = Convert.ToDecimal(item.Amount); } } line.AnyIntuitObject = accountRef; line.DetailType = LineDetailTypeEnum.AccountBasedExpenseLineDetail; line.DetailTypeSpecified = true; //line.Amount = Convert.ToDecimal(item.Amount); // line.Amount = Convert.ToDecimal(objBillDataServiceModel.InvoiceAmount); line.AmountSpecified = true; line.LineNum = Convert.ToString(i); line.Description = "Manual Bill"; lineList.Add(line); } else { line.Amount = Convert.ToDecimal(item.Amount); if (FacilityData.Count() == 1) { line.AnyIntuitObject = accountRef; line.DetailType = LineDetailTypeEnum.AccountBasedExpenseLineDetail; line.DetailTypeSpecified = true; //line.Amount = Convert.ToDecimal(item.Amount); // line.Amount = Convert.ToDecimal(objBillDataServiceModel.InvoiceAmount); line.AmountSpecified = true; line.LineNum = Convert.ToString(i); line.Description = "Manual Bill"; lineList.Add(line); } } costDataModel.CostCodeId = Convert.ToInt64(item.CostCodeId); costDataModel.Amount = Convert.ToDecimal(item.Amount); costCodeArray.Add(costDataModel); i++; } } else { line.Amount = Convert.ToDecimal(Obj.BillAmount); var dataget = BillList.Where(x => x.Name == "Other Expenses").FirstOrDefault(); accountRef.AccountRef = new ReferenceType() { name = dataget.Name, Value = dataget.Id }; line.AnyIntuitObject = accountRef; line.DetailType = LineDetailTypeEnum.AccountBasedExpenseLineDetail; line.DetailTypeSpecified = true; //line.Amount = Convert.ToDecimal(item.Amount); // line.Amount = Convert.ToDecimal(objBillDataServiceModel.InvoiceAmount); line.AmountSpecified = true; line.LineNum = Convert.ToString(i); line.Description = "Manual Bill"; lineList.Add(line); } bill.Line = lineList.ToArray(); // bill.ref resultBill = commonServiceQBO.Add(bill) as Bill; } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } //} Obj.QuickBookBillId = Convert.ToInt64(resultBill.Id); result = _IBillDataManager.ApproveBill(Obj, UserName, UserId, LocationId); } else { result = "No data to Approve please check bill data in grid."; } } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } return(Json(result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Created By: Ashwajit Bansod /// Created Date : 18-OCT-2018 /// Created For : To Approve Miscellaneous. /// </summary> /// <param name="Obj"></param> /// <returns></returns> public JsonResult ApproveData(List <MiscellaneousListModel> Obj, long LocationId) { eTracLoginModel ObjLoginModel = null; bool result; string UserName = ""; string data = ""; long UserId = 0; var resultBill = new Bill(); long VendorDetailsId = 0; if (Session["eTrac"] != null) { ObjLoginModel = (eTracLoginModel)(Session["eTrac"]); } try { if (Obj.Count > 0) { //long VendorId = 0; UserName = ObjLoginModel.UserName; UserId = ObjLoginModel.UserId; //foreach (var item in Obj) //{ // VendorId = item.Vendor; //} //if (Session["realmId"] != null) //{ string realmId = CallbackController.RealMId.ToString();// Session["realmId"].ToString(); try { string AccessToken = CallbackController.AccessToken.ToString(); // Session["access_token"].ToString(); var principal = User as ClaimsPrincipal; OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(AccessToken); // Create a ServiceContext with Auth tokens and realmId ServiceContext serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, oauthValidator); serviceContext.IppConfiguration.MinorVersion.Qbo = "23"; DataService commonServiceQBO = new DataService(serviceContext); // Create a QuickBooks QueryService using ServiceContext QueryService <Vendor> querySvc = new QueryService <Vendor>(serviceContext); List <Vendor> vendorList = querySvc.ExecuteIdsQuery("SELECT * FROM Vendor MaxResults 1000").ToList(); QueryService <Account> querySvcAccount = new QueryService <Account>(serviceContext); List <Account> accountData = querySvcAccount.ExecuteIdsQuery("SELECT * FROM Account MaxResults 1000").ToList(); /// default elite parking service vendor Id passed hardcoded it will will change in future VendorDetailsId = _IVendorManagement.GetCompanyQuickBookId(Convert.ToInt64(10019)); // var vendorData = vendorList.Where(x => x.Id == "64").FirstOrDefault(); var bill = new Bill(); //Vendor Reference var reference = new ReferenceType(); var accountRef = new AccountBasedExpenseLineDetail(); if (VendorDetailsId > 0) { var vendorData = vendorList.Where(x => x.Id == VendorDetailsId.ToString()).FirstOrDefault(); //Vendor Reference //Set it Hardcoded because need to add vendor , it is mendatory field so as per manager //operating company will pay miscellaneous expense bill.VendorRef = new ReferenceType() { name = vendorData.CompanyName, Value = vendorData.Id }; } bill.APAccountRef = new ReferenceType() { name = "Accounts Payable (A/P)", Value = "33" }; QueryService <Department> querySvcDept = new QueryService <Department>(serviceContext); var LocationName = _IBillDataManager.GetLocationDataByLocId(LocationId); bill.DepartmentRef = new ReferenceType() { name = LocationName.LocationName, Value = LocationName.QBK_Id.ToString() }; Line line = new Line(); List <Line> lineList = new List <Line>(); Line[] line1 = { }; int i = 1; var costArray = new List <long>(); var costCodeArray = new List <CostCodeListData>(); var costDataModel = new CostCodeListData(); decimal amt = 0; decimal?Total = 0; long CostCodeIdData = 0; var date = new DateTime(); long MISNumber = 0; foreach (var item in Obj) { string id = item.MISId.Split('S')[1]; MISNumber = Convert.ToInt64(id); var costCodeId = _IMiscellaneousManager.MiscellaneoousDataById(MISNumber); var CostCodeData = _IBillDataManager.GetCostCodeData(Convert.ToInt64(costCodeId.CostCode)); var dataget = accountData.Where(x => x.Name == CostCodeData.Description).FirstOrDefault(); MISNumber = Convert.ToInt64(item.MISNumber); accountRef.AccountRef = new ReferenceType() { name = dataget.Name, Value = dataget.Id }; //if (costCodeArray.Count() > 0) //{ // foreach (var tt in costCodeArray) // { // if (tt.CostCodeId == costCodeId.CostCode) // { // amt = Convert.ToDecimal(item.InvoiceAmount); // Total = amt + tt.Amount; // line.Amount = Convert.ToDecimal(Total); // } // else // { // line.Amount = Convert.ToDecimal(item.InvoiceAmount); // } // } // date = Convert.ToDateTime(item.MISDate); // line.LineNum = Convert.ToString(i); // line.AnyIntuitObject = accountRef; // line.DetailType = LineDetailTypeEnum.AccountBasedExpenseLineDetail; // line.DetailTypeSpecified = true; // line.AmountSpecified = true; // bill.Balance = Convert.ToDecimal(item.InvoiceAmount); // line.Amount = Convert.ToDecimal(item.InvoiceAmount); // line.Description = "Miscellaneous"; // //line1(line ); // lineList.Add(line); //} //else //{ // line.Amount = Convert.ToDecimal(item.InvoiceAmount); // if (Obj.Count() == 1) // { // date = Convert.ToDateTime(item.MISDate); // line.LineNum = Convert.ToString(i); // line.DetailType = LineDetailTypeEnum.AccountBasedExpenseLineDetail; // line.DetailTypeSpecified = true; // line.AnyIntuitObject = accountRef; // line.AmountSpecified = true; // bill.Balance = Convert.ToDecimal(item.InvoiceAmount); // line.Amount = Convert.ToDecimal(item.InvoiceAmount); // line.Description = "Miscellaneous"; // lineList.Add(line); // //line. // } //} //costDataModel.CostCodeId = Convert.ToInt64(costCodeId.CostCode); //costDataModel.Amount = Convert.ToDecimal(item.InvoiceAmount); //costCodeArray.Add(costDataModel); date = Convert.ToDateTime(item.MISDate); line.LineNum = Convert.ToString(i); line.DetailType = LineDetailTypeEnum.AccountBasedExpenseLineDetail; line.DetailTypeSpecified = true; line.AnyIntuitObject = accountRef; line.AmountSpecified = true; line.Amount = Convert.ToDecimal(item.InvoiceAmount); line.Description = "Miscellaneous"; //line lineList.Add(line); i++; } var metaData = new ModificationMetaData(); metaData.CreateTime = Convert.ToDateTime(date); bill.MetaData = metaData; bill.Line = lineList.ToArray(); resultBill = commonServiceQBO.Add(bill) as Bill; } catch (Exception ex) { ViewBag.Message = ex.Message; ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger; } //} long MiscQbkId = Convert.ToInt64(resultBill.Id); result = _IMiscellaneousManager.ApproveMiscellaneous(Obj, UserName, UserId, LocationId, MiscQbkId, VendorDetailsId); if (result == true) { data = CommonMessage.ApproveMiscellaneous(); } else { data = CommonMessage.ErrorMiscellaneous(); } } else { data = "No data to Approve please check miscellaneous data in grid."; } } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } return(Json(data, JsonRequestBehavior.AllowGet)); }