Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using PX.Data;
using PX.Objects.AR;
using PX.SM;
using PX.Objects.EP;
namespace PX.Objects.SO
{
public class SOQuoteNotification : PXGraph<SOQuoteNotification, SOQuoteNotification.SOQuoteNotificationFilter>
{
public class SOQuoteNotificationFilter : IBqlTable
{
#region DueDate
public abstract class dueDate : PX.Data.IBqlField
{
}
[PXDate()]
[PXUIField(DisplayName = "Due Date")]
[PXDefault(typeof(AccessInfo.businessDate))]
public virtual DateTime? DueDate {get; set;}
#endregion
#region DueIn
public abstract class dueIn : PX.Data.IBqlField
{
}
[PXInt(MaxValue = 365, MinValue = 0)]
[PXDefault(0)]
[PXUIField(DisplayName = "Due In")]
public virtual Int32? DueIn {get; set;}
#endregion
}
public PXFilter<SOQuoteNotificationFilter> MasterView;
public PXFilteredProcessingJoin<SOOrder, SOQuoteNotificationFilter,
InnerJoin<SOBillingContact, On<SOBillingContact.contactID, Equal<SOOrder.billContactID>>>,
Where<SOOrder.status, Equal<SOOrderStatus.open>>> DetailsView;
public SOQuoteNotification()
{
DetailsView.SetSelected<SOOrder.selected>();
DetailsView.SetProcessDelegate(delegate(List<SOOrder> orders) { ProcessReminders(orders); });
}
public override bool IsDirty
{
get
{
return false;
}
}
public IEnumerable detailsView()
{
PXSelectBase<SOOrder> cmd = new PXSelectJoin<SOOrder,
InnerJoin<SOBillingContact, On<SOBillingContact.contactID, Equal<SOOrder.billContactID>>>,
Where<SOOrder.status, Equal<SOOrderStatus.open>,
And<SOOrder.dueDate, Equal<Required<SOOrder.dueDate>>>>>(this);
SOQuoteNotificationFilter filter = MasterView.Current;
DateTime date = filter.DueDate ?? DateTime.Now;
if(filter.DueIn != null) date.AddDays((double)filter.DueIn);
return cmd.Select(date);
}
public static void ProcessReminders(List<SOOrder> orders)
{
bool erroroccurred = false;
List<SOOrder> casesToProcess = new List<SOOrder>(orders);
SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();
//Get the Email Templates
SOSetupExt setup = graph.sosetup.Current.GetExtension<SOSetupExt>();
Notification notification = PXSelect<Notification,
Where<Notification.notificationID, Equal<Required<Notification.notificationID>>>>.Select(graph, setup.UsrQuoteNotificationMapID);
if (notification == null)
{
throw new PXException("Notification Template for Quote Reminder is not specified.");
}
foreach (SOOrder order in orders)
{
try
{
SOBillingContact contact = PXSelect<SOBillingContact, Where<SOBillingContact.contactID, Equal<Required<SOBillingContact.contactID>>>>.Select(graph, order.BillContactID);
AddEmailActivity(order, contact, notification);
PXProcessing<SOOrder>.SetInfo(orders.IndexOf(order), String.Format("Reminder has been sent for Order # {0}", order.OrderNbr));
}
catch (Exception e)
{
erroroccurred = true;
PXProcessing<SOOrder>.SetError(orders.IndexOf(order), e);
}
}
if (erroroccurred)
throw new PXException("At least one Case hasn't been processed.");
}
public static void AddEmailActivity(SOOrder order, SOBillingContact contact, Notification notification)
{
bool sent = false;
string sError = "Failed to send E-mail.";
try
{
TemplateNotificationGenerator sender = TemplateNotificationGenerator.Create(order, notification.NotificationID.Value);
sender.MailAccountId = (notification.NFrom.HasValue) ? notification.NFrom.Value : PX.Data.EP.MailAccountManager.DefaultMailAccountID;
sender.RefNoteID = order.NoteID;
sender.Owner = order.OwnerID;
sender.To = contact.Email;
sent |= sender.Send().Any();
}
catch (Exception Err)
{
sent = false;
sError = Err.Message;
}
if (!sent)
throw new PXException(sError);
}
}
}
<%@ Page Language="C#" MasterPageFile="~/MasterPages/FormDetail.master" AutoEventWireup="true" ValidateRequest="false" CodeFile="SO502080.aspx.cs" Inherits="Page_SO502080" Title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPages/FormDetail.master" %>
<asp:Content ID="cont1" ContentPlaceHolderID="phDS" Runat="Server">
<px:PXDataSource ID="ds" runat="server" Visible="True" Width="100%"
TypeName="PX.Objects.SO.SOQuoteNotification"
PrimaryView="MasterView"
>
<CallbackCommands>
</CallbackCommands>
</px:PXDataSource>
</asp:Content>
<asp:Content ID="cont2" ContentPlaceHolderID="phF" Runat="Server">
<px:PXFormView ID="form" runat="server" DataSourceID="ds" DataMember="MasterView" Width="100%" Height="40px" AllowAutoHide="false">
<Template>
<px:PXLayoutRule ID="PXLayoutRule1" runat="server" StartRow="True"></px:PXLayoutRule>
<px:PXDateTimeEdit CommitChanges="True" runat="server" ID="CstPXDateTimeEdit1" DataField="DueDate" ></px:PXDateTimeEdit>
<px:PXLayoutRule runat="server" ID="CstPXLayoutRule4" StartColumn="True" ></px:PXLayoutRule>
<px:PXNumberEdit CommitChanges="True" runat="server" ID="CstPXNumberEdit2" DataField="DueIn" ></px:PXNumberEdit></Template>
</px:PXFormView>
</asp:Content>
<asp:Content ID="cont3" ContentPlaceHolderID="phG" Runat="Server">
<px:PXGrid ID="grid" runat="server" DataSourceID="ds" Width="100%" Height="150px" SkinID="Details" AllowAutoHide="false">
<Levels>
<px:PXGridLevel DataMember="DetailsView">
<Columns>
<px:PXGridColumn TextAlign="Center" Type="CheckBox" DataField="Selected" Width="60" AllowCheckAll="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="OrderType" Width="90" ></px:PXGridColumn>
<px:PXGridColumn DataField="OrderNbr" Width="100" ></px:PXGridColumn>
<px:PXGridColumn DataField="CustomerID" Width="120" ></px:PXGridColumn>
<px:PXGridColumn DataField="OrderDesc" Width="200" ></px:PXGridColumn>
<px:PXGridColumn DataField="CuryID" Width="80" ></px:PXGridColumn>
<px:PXGridColumn DataField="OrderQty" Width="100" ></px:PXGridColumn>
<px:PXGridColumn DataField="CuryOrderTotal" Width="100" ></px:PXGridColumn>
<px:PXGridColumn DataField="OrderDate" Width="90" ></px:PXGridColumn>
<px:PXGridColumn DataField="DueDate" Width="90" ></px:PXGridColumn>
<px:PXGridColumn DataField="SOBillingContact__Email" Width="200" ></px:PXGridColumn>
<px:PXGridColumn DataField="OwnerID" Width="120" ></px:PXGridColumn></Columns>
</px:PXGridLevel>
</Levels>
<AutoSize Container="Window" Enabled="True" MinHeight="150" />
<ActionBar >
</ActionBar>
</px:PXGrid>
</asp:Content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.