/// <summary> /// This function is responsible for populating the /// parameters required for generating a invoice. /// </summary> /// <param name="invoicedto"></param> /// <param name="timeActivity"></param> /// <returns></returns> private Invoice PopulateInvoiceParam(Invoicedto invoicedto, TimeActivity timeActivity) { Invoice invoice = new Invoice(); invoice.TxnDate = timeActivity.TxnDate; invoice.Line = new Line[] { new Line{AmountSpecified=true,Description=timeActivity.Description,Amount=25,DetailType=LineDetailTypeEnum.SalesItemLineDetail,DetailTypeSpecified=true,AnyIntuitObject = new SalesItemLineDetail{Qty=Convert.ToDecimal(3.5),TaxCodeRef=new ReferenceType{Value="NON"},ItemRef=new ReferenceType{Value=timeActivity.ItemRef.Value}}}, new Line{Amount=25,AmountSpecified=true,DetailType=LineDetailTypeEnum.SubTotalLineDetail,DetailTypeSpecified=true,AnyIntuitObject = new SubTotalLineDetail{}} }; invoice.TxnTaxDetail = new TxnTaxDetail { TotalTax = 0 }; invoice.CustomerRef = new ReferenceType { Value = timeActivity.CustomerRef.Value }; invoice.DueDate = DateTime.Now; invoice.TotalAmt = 25; invoice.ApplyTaxAfterDiscount = false; invoice.PrintStatus = PrintStatusEnum.NeedToPrint; invoice.PrintStatusSpecified = true; invoice.EmailStatus = EmailStatusEnum.NotSet; invoice.EmailStatusSpecified = true; invoice.Balance = 25; invoice.BalanceSpecified = true; invoice.Deposit = 0; invoice.DepositSpecified = true; invoice.AllowIPNPayment = false; invoice.AllowIPNPaymentSpecified = true; invoice.AllowOnlinePayment = false; invoice.AllowOnlinePaymentSpecified = true; invoice.AllowOnlineCreditCardPayment = false; invoice.AllowOnlineCreditCardPaymentSpecified = true; invoice.AllowOnlineACHPayment = false; invoice.AllowOnlineACHPaymentSpecified = true; return invoice; }
/// <summary> /// Save the object to dictionary /// </summary> /// <param name="controller"></param> /// <param name="invoicedto"></param> /// <returns></returns> internal Invoicedto Save(object controller, Invoicedto invoicedto) { invoiceController = controller as Controller; Random random = new Random(); invoicedto.Id = random.Next(1, 100); invoiceRepository.Add(invoicedto.Id, invoicedto); invoiceController.TempData["Invoice"] = invoiceRepository; invoiceController.TempData.Keep(); return invoicedto; }
public JsonResult Save(Int64 id, Int64 qboId) { Invoicedto invoicedto = id > 0 ? new InvoiceRepository().Get(this, id) : new Invoicedto(); invoicedto.timeQboId = qboId; invoiceService = new InvoiceService(invoicedto); invoicedto = invoiceService.GenerateInvoice(invoicedto); invoicedto = invoiceService.UpdateDatabase(invoicedto); //invoicedto = invoiceService.FillCreatedInvoice(invoicedto); invoiceRepository = new InvoiceRepository(); invoicedto = invoiceRepository.Save(this, invoicedto); object data = new { Id = invoicedto.Id }; return Json(data, JsonRequestBehavior.AllowGet); }
/// <summary> /// this function generate invoice by receiving customer id /// create instance of invoice object /// push to QBO /// </summary> /// <param name="invoicedto"></param> /// <returns></returns> internal Invoicedto GenerateInvoice(Invoicedto invoicedto) { try { TimeActivity timeActivity = GetCustomerId(invoicedto); Invoice invoice = PopulateInvoiceParam(invoicedto, timeActivity); invoice = dataService.Add<Invoice>(invoice); invoicedto.Invoice = invoice; invoicedto.InvoiceQboId = Convert.ToInt64(invoice.Id); invoicedto.AlertMessage = string.Format("Invoice successfully created and pushed to QBO (QBO ID = {0})", invoice.Id); return invoicedto; } catch (Intuit.Ipp.Exception.FaultException ex) { throw ex; } }
public ActionResult Load(Int64 id) { TimeActivitydto timeActivitydto = id > 0 ? new TimeActivityRepository().Get(this, id) : new TimeActivitydto(); invoicedto.oAuthTokens = timeActivitydto.oAuthTokens; invoicedto.CustomerList = timeActivitydto.CustomerList; invoicedto.CompanyId = invoicedto.oAuthTokens.Realmid; invoicedto.ConnectionString = timeActivitydto.Syncdto.ConnectionString; invoicedto.TimeActivityDto = timeActivitydto; invoiceService = new InvoiceService(invoicedto); invoicedto = invoiceService.LoadPending(invoicedto); invoicedto = invoiceService.LoadInvoiced(invoicedto); invoiceRepository = new InvoiceRepository(); invoicedto = invoiceRepository.Save(this, invoicedto); multiplemodels = new Multiplemodels(); multiplemodels.TimeActivityModel = timeActivitydto; multiplemodels.InvoiceModel = invoicedto; multiplemodels.SyncObjectsModel = invoicedto.TimeActivityDto.Syncdto; multiplemodels.IsConnected = timeActivitydto.oAuthTokens.IsConnected; multiplemodels.IsReadyTimeentry = true; multiplemodels.IsReadytoInvoice = true; multiplemodels.IsReadySync = false; return View("Invoices", multiplemodels); }
public InvoiceService(Invoicedto invoicedto) { dataserviceFactory = new DataserviceFactory(invoicedto.oAuthTokens); dataService = dataserviceFactory.getDataService(); invoiceRepository = new InvoiceRepository(); }
/// <summary> /// Pull all the invoiced records from DB. /// </summary> /// <param name="invoicedto"></param> /// <returns></returns> internal Invoicedto LoadInvoiced(Invoicedto invoicedto) { List<InvoiceCreated> invoiceCreatedList = new List<InvoiceCreated>(); using (SqlConnection sqlConnection = new SqlConnection(invoicedto.ConnectionString)) { string oString = string.Format("select * from TimeActivity where RealmId='{0}' and Invoice_QboId is not null", invoicedto.CompanyId); SqlCommand oCmd = new SqlCommand(oString, sqlConnection); sqlConnection.Open(); using (SqlDataReader oReader = oCmd.ExecuteReader()) { while (oReader.Read()) { InvoiceCreated nvoiceCreated = new InvoiceCreated(); nvoiceCreated.Employee = oReader["Employee"].ToString(); nvoiceCreated.Customer = oReader["Customer"].ToString(); nvoiceCreated.Item = oReader["Item"].ToString(); nvoiceCreated.Date = Convert.ToDateTime(oReader["Date"].ToString()).ToShortDateString(); nvoiceCreated.Hours = oReader["Hours"].ToString(); nvoiceCreated.QboId = oReader["Invoice_QboId"].ToString(); invoiceCreatedList.Add(nvoiceCreated); } sqlConnection.Close(); } } if (invoicedto.InvoiceCreated == null) { invoicedto.InvoiceCreated = new List<InvoiceCreated>(); } invoicedto.InvoiceStatus = "Invoiced"; invoicedto.InvoiceListLength = invoiceCreatedList.Count; invoicedto.InvoiceCreated = invoiceCreatedList; return invoicedto; }
/// <summary> /// Update the invoice to sql /// </summary> /// <param name="invoicedto"></param> /// <returns></returns> internal Invoicedto UpdateDatabase(Invoicedto invoicedto) { var qboId = invoicedto.timeQboId; var invoiceQboId = invoicedto.InvoiceQboId; string query = "UPDATE TimeActivity SET Invoice_QboId=@Invoice_QboId WHERE QboId=@QboId"; using (SqlCommand myCommand = new SqlCommand(query, new SqlConnection(invoicedto.ConnectionString))) { myCommand.Connection.Open(); myCommand.Parameters.AddWithValue("@Invoice_QboId", invoiceQboId); myCommand.Parameters.AddWithValue("@QboId", qboId); myCommand.ExecuteNonQuery(); myCommand.Connection.Close(); } invoicedto.UpdatePending = true; return invoicedto; }
/// <summary> /// Populate the invoice left for pending. /// </summary> /// <param name="invoicedto"></param> /// <returns></returns> internal Invoicedto LoadPending(Invoicedto invoicedto) { List<TimeActivityFill> timeActivityFillList = new List<TimeActivityFill>(); using (SqlConnection sqlConnection = new SqlConnection(invoicedto.ConnectionString)) { string oString = string.Format("select * from TimeActivity where RealmId='{0}' and Invoice_QboId is null", invoicedto.CompanyId); SqlCommand oCmd = new SqlCommand(oString, sqlConnection); sqlConnection.Open(); using (SqlDataReader oReader = oCmd.ExecuteReader()) { while (oReader.Read()) { TimeActivityFill timeActivityFill = new TimeActivityFill(); timeActivityFill.Employee = oReader["Employee"].ToString(); timeActivityFill.Customer = oReader["Customer"].ToString(); timeActivityFill.Item = oReader["Item"].ToString(); timeActivityFill.Date = Convert.ToDateTime(oReader["Date"].ToString()).ToShortDateString(); timeActivityFill.Hours = oReader["Hours"].ToString(); timeActivityFill.QboId = oReader["QboId"].ToString(); timeActivityFillList.Add(timeActivityFill); } sqlConnection.Close(); } } if (invoicedto.InvoiceCreated==null) { invoicedto.InvoiceCreated = new List<InvoiceCreated>(); } invoicedto.InvoicePending = "Pending"; invoicedto.InvoicePendingLength = timeActivityFillList.Count; invoicedto.InvoicePendingList = timeActivityFillList; return invoicedto; }
/// <summary> /// Return the customer id from timeactivity. /// </summary> /// <param name="invoicedto"></param> /// <returns></returns> private TimeActivity GetCustomerId(Invoicedto invoicedto) { string EXISTING_TimeActive_QUERY = string.Format("select * from timeactivity where Id = '{0}'", invoicedto.timeQboId); QueryService<TimeActivity> queryService = new QueryService<TimeActivity>(dataserviceFactory.getServiceContext); TimeActivity resultFound = queryService.ExecuteIdsQuery(EXISTING_TimeActive_QUERY).FirstOrDefault<TimeActivity>(); return resultFound; }
/// <summary> /// View is resposible for rendering the final view /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult View(Int64 id) { Invoicedto invoicedto = id > 0 ? new InvoiceRepository().Get(this, id) : new Invoicedto(); invoiceService = new InvoiceService(invoicedto); invoicedto = invoiceService.LoadPending(invoicedto); invoicedto = invoiceService.LoadInvoiced(invoicedto); multiplemodels = new Multiplemodels(); multiplemodels.TimeActivityModel = invoicedto.TimeActivityDto; multiplemodels.InvoiceModel = invoicedto; multiplemodels.SyncObjectsModel = invoicedto.TimeActivityDto.Syncdto; multiplemodels.IsReadySync = multiplemodels.SyncObjectsModel.IsEmployeeSync | multiplemodels.SyncObjectsModel.IsCustomerSync | multiplemodels.SyncObjectsModel.IsServiceItemSync; multiplemodels.IsReadyTimeentry = true; multiplemodels.IsReadytoInvoice = false; return View("Invoices", multiplemodels); }