Added shipping information. Pulls list of all documentIDs per Order. Looks up individual DocumentID information. Added Address Block and Item Detail Block to Invoice HTML. Added BCC and CC testing addresses.

This commit is contained in:
Dan Dembinski
2021-03-20 00:25:58 -04:00
parent 5720ac4dbb
commit 56722752ac
2 changed files with 103 additions and 9 deletions

View File

@@ -98,4 +98,31 @@ def record_lookup(record):
result.append(lookup.ChargeCode)
result.append(lookup.InvoiceNumber)
result.append(lookup.InvoiceEmailAddress)
result.append(lookup.ShippingCompany)
result.append(lookup.ShippingFirstName)
result.append(lookup.ShippingLastName)
result.append(lookup.ShippingAddress1)
result.append(lookup.ShippingAddress2)
result.append(lookup.ShippingCity)
result.append(lookup.ShippingState)
result.append(lookup.ShippingPostalCode)
result.append(lookup.ShippingCharges)
result.append(lookup.DuePayment)
return result
def all_items(orderId):
all = []
for items in session.query(ItemDetail).filter(ItemDetail.OrderID == orderId):
all.append(items.DocumentID)
return all
def item_lookup(item):
result = []
for lookup in session.query(ItemDetail).filter(ItemDetail.DocumentID == item):
result.append(lookup.Quantity)
result.append(lookup.DocumentID)
result.append(lookup.ProductName)
result.append(lookup.ItemPrice)
return result

View File

@@ -14,7 +14,7 @@ def send_email(test, record):
orders = InvoiceDatabase.just_work()
for each in orders:
info = InvoiceDatabase.record_lookup(each)
print(info)
OrderNumber = info[0]
OrderDate = info[1]
UserLogon = info[2]
@@ -22,8 +22,70 @@ def send_email(test, record):
ChargeCode = info[5]
InvoiceNumber = info[6]
InvoiceEmailAddress = info[7]
ShippingCharges = info[16]
BalanceDue = info[17]
InvoiceDate = datetime.today().strftime('%m/%d/%Y')
#shipping information
ShippingCompany = info[8]
ShippingFirstName = info[9]
ShippingLastName = info[10]
ShippingAddress1 = info[11]
ShippingAddress2 = info[12]
ShippingCity = info[13]
ShippingState = info[14]
ShippingPostalCode = info[15]
# if ShippingCompany != 'None' and ShippingAddress2 == 'None':
block = '''
<br>{name}
<br>{ShippingAddress1}
<br>{ShippingCity}, {ShippingState} {ShippingZip}
<br>
</p>
</td>
'''
addressBlock = block.format(name=Name, ShippingAddress1=ShippingAddress1, ShippingCity=ShippingCity,
ShippingState=ShippingState, ShippingZip=ShippingPostalCode)
itemDetailBlock = '''
<TABLE style=""BORDER-TOP: #838282 1px solid; BORDER-RIGHT: #838282 1px solid; WIDTH: 600px;
BORDER-COLLAPSE: collapse; BORDER-BOTTOM: #838282 1px solid; COLOR: black;
BORDER-LEFT: #838282 1px solid; MARGIN-TOP: 10px"" borderColor=#838282 cellSpacing=0 cellPadding=5
rules=all border=1><TBODY>
<TR><TD style=""FONT-WEIGHT: 800""><B>Quantity</B></TD><TD style=""FONT-WEIGHT: 800""><B>Document ID</B></TD>
<TD style=""FONT-WEIGHT: 800""><B>Product Name</B</TD><TD style=""FONT-WEIGHT: 800""><B>Sales</B></TD></TR>
'''
items = InvoiceDatabase.all_items(OrderNumber)
for eachItem in items:
info = InvoiceDatabase.item_lookup(eachItem)
Quantity = info[0]
DocumentID = info[1]
ProductName = info[2]
ItemPrice = info[3]
addItem = '''
<tr>
<td> {Quantity} </td>
<td>{DocumentID}</td>
<td>{ProductName}</td>
<td align=" & Chr(34) & "right" & Chr(34)>
${ItemPrice:,.2f}</td>
</tr>
'''
itemDetailBlock = itemDetailBlock + addItem.format(Quantity=Quantity, DocumentID=DocumentID,
ProductName=ProductName, ItemPrice=ItemPrice)
addItem = '''
<TR><TD colSpan=9 align=right>Shipping:&nbsp; <SPAN contentEditable=false style=""BACKGROUND-COLOR: transparent"">
${ShippingCharges:,.2f} </SPAN></TD></TR><TR><TD colSpan=9 align=right>Invoice Total
<SPAN contentEditable=false style=""BACKGROUND-COLOR: transparent""> ${BalanceDue:,.2f}
</SPAN></TD></TR></TBODY></TABLE>
'''
itemDetailBlock = itemDetailBlock + addItem.format(ShippingCharges=ShippingCharges, BalanceDue=BalanceDue)
body = '''
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
@@ -61,11 +123,14 @@ def send_email(test, record):
</TR>
<TR vAlign="top">
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300">
<SPAN contentEditable=false style="" PFVar="AddressBlock">Address Block</SPAN></TD>
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300"><BR><P><B>Shipment Address</B><BR>
{addressBlock}
</TD>
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300">&nbsp;<BR><P><B>Make Checks Payable To:</B> <BR>Great Lakes Integrated <BR>4246 Hudson Dr.<BR>Stow, Ohio 44224<BR>&nbsp;</P></TD>
</TR>
<TR>
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300"><BR></TD>
</TR>
<TR vAlign="top">
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300">
<P>
@@ -90,6 +155,7 @@ def send_email(test, record):
<TR>
<TD width="600" colSpan="2"><P style="MARGIN-TOP: 20px"><B>The order consists of the following items:</B> </P>
<SPAN contentEditable=false style="" PFVar="OrderDetail"></SPAN>
{itemDetailBlock}
</TD>
</TR>
</TBODY>
@@ -97,8 +163,8 @@ def send_email(test, record):
</BODY>
</HTML>
'''
HTMLpart = body.format(OrderNumber=OrderNumber, OrderDate=OrderDate, UserLogon=UserLogon, Name=Name,
ChargeCode=ChargeCode, InvoiceDate=InvoiceDate, InvoiceNumber=InvoiceNumber)
HTMLpart = body.format(addressBlock=addressBlock, OrderNumber=OrderNumber, OrderDate=OrderDate, UserLogon=UserLogon, Name=Name,
ChargeCode=ChargeCode, InvoiceDate=InvoiceDate, InvoiceNumber=InvoiceNumber, itemDetailBlock=itemDetailBlock)
bodyHTML = MIMEText(HTMLpart, "html")
@@ -111,9 +177,10 @@ def send_email(test, record):
msg['Subject'] = 'INVOICE ' + InvoiceNumber
if test is True:
msg['To'] = 'ddembinski@gll.com'
msg['Cc'] = 'ddembinski@gll.com'
msg['Bcc'] = 'ddembinski@gll.com'
else:
# msg['To'] = InvoiceEmailAddress
msg['To'] = 'ddembinski@gll.com'
msg['To'] = InvoiceEmailAddress
msg['From'] = 'ddembinski@gll.com'
msg.add_header('Content-Type', 'text/html')
msg.attach(bodyHTML)