/// <summary> /// Handles the OnClick event of the lbtnSendInvoice control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void lbtnSendInvoice_OnClick(object sender, EventArgs e) { if (chxForBuyer.Checked && ucSendInvoiceBuyerContact.SelectedValue.HasValue) { InvoiceNotificationService.SendToContact(_invoiceId, ucSendInvoiceBuyerContact.SelectedValue.Value); } if (chxForExecutor.Checked && ucSendInvoiceExecutorContact.SelectedValue.HasValue) { InvoiceNotificationService.SendToContact(_invoiceId, ucSendInvoiceExecutorContact.SelectedValue.Value); } Response.Redirect(UrlsData.AP_InvoiceEdit(_invoiceId)); }
/// <summary> /// Updates the invoice. /// </summary> /// <param name="siteId">The site id.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <param name="xml">The XML.</param> /// <returns></returns> public string UpdateInvoice(Guid siteId, string username, string password, string xml) { var user = _authorization.Authorize(siteId, username, password); if (user == null || !Access.Check(user, "API").Write) { return(StatusHelper.FormatMessage(StatusCodes.AccessDenied, MethodBase.GetCurrentMethod().Name, _result).ToString(SaveOptions.DisableFormatting)); } XDocument inputXml; try { inputXml = XDocument.Parse(xml); } catch (Exception ex) { Log.Error(string.Format("LeadForce.API.UpdateInvoice error, SiteId: {0}, UserName: {1}, Xml: {2}", siteId, username, xml), ex); return(StatusHelper.FormatMessage(StatusCodes.InvalidParameters, MethodBase.GetCurrentMethod().Name, _result).ToString(SaveOptions.DisableFormatting)); } try { var result = Invoices.UpdateInvoice(siteId, user.ContactID, inputXml.Document); if (result.IsNew) { var dataManager = new DataManager(); var invoice = dataManager.Invoice.SelectById(siteId, result.InvoiceId); var invoiceType = dataManager.InvoiceType.SelectById(siteId, invoice.InvoiceTypeID); var documentNumerator = DocumentNumerator.GetNumber((Guid)invoiceType.NumeratorID, invoice.CreatedAt, invoiceType.tbl_Numerator.Mask, "tbl_Invoice"); invoice.Number = documentNumerator.Number; invoice.SerialNumber = documentNumerator.SerialNumber; dataManager.Invoice.Update(invoice); } if (result.IsPendingPayment && !result.IsNew) { InvoiceNotificationService.PendingPayment(result.InvoiceId); } _result = StatusHelper.FormatMessage(StatusCodes.Ok, MethodBase.GetCurrentMethod().Name, _result); } catch (Exception ex) { Log.Error(string.Format("LeadForce.API.UpdateInvoice error, SiteId: {0}, UserName: {1}, Xml: {2}", siteId, username, xml), ex); return(StatusHelper.FormatMessage(StatusCodes.InternalError, MethodBase.GetCurrentMethod().Name, _result).ToString(SaveOptions.DisableFormatting)); } return(_result.ToString(SaveOptions.DisableFormatting)); }
/// <summary> /// Adds the specified invoice. /// </summary> /// <param name="invoice">The invoice.</param> /// <returns></returns> public tbl_Invoice Add(tbl_Invoice invoice) { invoice.ID = Guid.NewGuid(); invoice.CreatedAt = DateTime.Now; _dataContext.tbl_Invoice.AddObject(invoice); _dataContext.SaveChanges(); AddHistory(new DataManager(), invoice); if (invoice.InvoiceStatusID == (int)InvoiceStatus.PendingPayment) { InvoiceNotificationService.PendingPayment(invoice.ID); } return(invoice); }
public void Run() { var dataManager = new DataManager(); var serviceLevelContacts = dataManager.ServiceLevelContact.SelectAll(); var today = DateTime.Now.Date; var firstDayOfWeek = today.AddDays(-(today.DayOfWeek - new CultureInfo("ru-RU").DateTimeFormat.FirstDayOfWeek)); if (firstDayOfWeek != today && today.Day != 1) { return; } foreach (var serviceLevelContact in serviceLevelContacts) { var invoices = dataManager.Invoice.SelectByBuyerCompanyId(serviceLevelContact.tbl_ServiceLevelClient.ClientID).Where(o => o.InvoiceStatusID == (int)InvoiceStatus.PartialPaid || o.InvoiceStatusID == (int)InvoiceStatus.PendingPayment); if (!invoices.Any()) { continue; } var informClient = false; switch ((InvoiceInformCatalog)serviceLevelContact.InvoiceInformCatalogID) { case InvoiceInformCatalog.Weekly: informClient = firstDayOfWeek == today; break; case InvoiceInformCatalog.Biweekly: informClient = WeekNumber(today) % 2 == 0; break; case InvoiceInformCatalog.Monthly: informClient = today.Day == 1; break; } if (informClient) { InvoiceNotificationService.Inform(serviceLevelContact.tbl_Contact.SiteID, serviceLevelContact.ContactID, serviceLevelContact.ID); } } }
/// <summary> /// Updates the specified invoice. /// </summary> /// <param name="invoice">The invoice.</param> public void Update(tbl_Invoice invoice) { var dataManager = new DataManager(); var invoiceInDataBase = dataManager.Invoice.SelectById(invoice.SiteID, invoice.ID); invoice.ModifiedAt = DateTime.Now; _dataContext.SaveChanges(); if (invoice.PaymentDatePlanned != invoiceInDataBase.PaymentDatePlanned || invoice.PaymentDateActual != invoiceInDataBase.PaymentDateActual || invoice.InvoiceAmount != invoiceInDataBase.InvoiceAmount || invoice.InvoiceStatusID != invoiceInDataBase.InvoiceStatusID || invoice.IsExistBuyerComplaint != invoiceInDataBase.IsExistBuyerComplaint || invoice.Note != invoiceInDataBase.Note) { AddHistory(dataManager, invoice); } if (invoice.InvoiceStatusID != invoiceInDataBase.InvoiceStatusID && invoice.InvoiceStatusID == (int)InvoiceStatus.PendingPayment) { InvoiceNotificationService.PendingPayment(invoice.ID); } }