Normal Topic Email Invoices - PrintAFormToHTML ? (Read 757 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Email Invoices - PrintAFormToHTML ?
Feb 2nd, 2012 at 3:55am
Print Post Print Post  
Am experimenting with generating, for some of my clients, invoices that are automatically saved as files and then emailed automatically instead of hard copy printed and snail mailed.    Here's my rough code to do so (not polished, not caveats inserted yet to look for same name file, etc):



FormViewType("SOLines", 1)
                                                     
vPrt = @PrintAFormToHTML(vSONum + ".html")
                                                           
If vPrt = 0
{
  Writeln("error: Failed to create " + vSONum + ".html")
}

   else if vPrt = 1
           {
               vInvoice = vSONum + ".html"
               vEmail = @sendmail("smtp2go.com","MyCompanyInvoice","MyServer@gmail.com","Customer@gmail.
com","","","Here is MyCompany invoice " + vSONum,"","",vInvoice)
            }


It works great!  But (isn't there always?), even though the programming turns the SOLines subform into tableview just prior to printing, when printed to the html file, it prints the 'form view' of the SOLines subform (which is unacceptable).

Is the inability to print a normally formview subform in tableview a limitation of @PrintAFormToHTML?   
  

Larry
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Email Invoices - PrintAFormToHTML ?
Reply #1 - Feb 5th, 2012 at 1:38am
Print Post Print Post  
Do you really want to send your customers an HTML invoice? Wouldn't it be better to create a PDF, and attach that to the email?
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Email Invoices - PrintAFormToHTML ?
Reply #2 - Feb 5th, 2012 at 1:57am
Print Post Print Post  
Hi Carl,

Yes, you're right, of course - a pdf attached to an email would be preferable.  Actually, we do it that way for 8 or 10 clients now.  But our current procedure is cumbersome: we 'print the invoice' to a pdf print driver that pops up a user interaction screen that requires us to manually give the pdf a filename.  So it's certainly not an ideal solution. 
   I'm wanting to come up with a completely automated programmed solution, in anticipation of converting maybe half of my 700 invoices/month to email.

I'm looking to have the Sesame programming automatically 1)  print the invoice to a file (programmatically assigning a file name)  - and then
2) emailing the digital invoice to the client's email address.

I'm certainly open to advice on how to do that.

ps - out of curiosity, though, what is the drawback to attaching the html file to an email?  Anti-Virus filters on customers' email settings?
« Last Edit: Feb 5th, 2012 at 8:50pm by lksseven »  

Larry
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Email Invoices - PrintAFormToHTML ?
Reply #3 - Feb 6th, 2012 at 2:54pm
Print Post Print Post  
fyi,

The command 'PrintAForm' WILL print wysiwyg when changing a 'formview' subform to a 'tableview' subform just before printing.  But PrintAFormToHTML will not - at least not in the version 2.50 that I am currently running. 

It would be delightful if it did, or if there is a workaround I can use to accomplish the same thing.
  

Larry
Back to top
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Email Invoices - PrintAFormToHTML ?
Reply #4 - Feb 6th, 2012 at 5:51pm
Print Post Print Post  
This isn't a perfect solution, but it works for me. I use the following subroutine to use the command line to call Thunderbird (open source email client) to file attach an HTML report. I use this on my 'Estimates' form, so that my sales reps don't have to manually 'find' the file that they want to attach.

Code
Select All
// The Thunderbird() subroutine take four arguments (all as STR) in the order of SendAddress, Subject, Body and the Attachments.
// The subroutine allows for multiple address and attachments, so long as the inputs are string arrays.
// Also, this subroutine assumes that the default Thunderbird install directory is the same on all computers.
SUBROUTINE Thunderbird(vToAddress as String, vSubject as String, vBody as String, vAttachment as String)
var vCommand as String
var vLoop as Int

If vToAddress <> "" // Not a blank vToAddress value.
{
	If @CountStringArray(vToAddress) = 1
	{
		vCommand = "to=" + vToAddress
	}
	Else // More than one address to be sent.
	{
		vCommand = "to='"
		For vLoop = 1 to @CountStringArray(vToAddress)
			vCommand = vCommand + @AccessStringArray(vToAddress, vLoop) + ","
		Next
		// Now remove the trailing ","
		vCommand = @TrimStringRight(vCommand, ",")
		// Now add the last "'".
		vCommand = vCommand + "'"
	}
}

If vSubject <> "" // Not a blank vSubject value.
{
	vCommand = vCommand + "," + "subject=" + vSubject
}

If vBody <> ""
{
	vCommand = vCommand + "," + "body=" + vBody
}

If vAttachment <> ""
{
	If @CountStringArray(vAttachment) = 1
	{
		vCommand = vCommand + "," + "attachment=file:///" + vAttachment
	}
	Else
	{
		vCommand = vCommand + "," + "attachment='"
		For vLoop = 1 to @CountStringArray(vAttachment)
			vCommand = vCommand + "file:///" + @AccessStringArray(vAttachment, vLoop) + ","
		Next
		// Now remove the trailing ","
		vCommand = @TrimStringRight(vCommand, ",")
		// Now add the last "'"
		vCommand = vCommand + "'"
	}
}
// Add final quote marks to vCommand string.
vCommand = @Chr(34) + vCommand + @Chr(34)
CreateAProcess("C:\Program Files\Mozilla Thunderbird\thunderbird.exe -compose" + " " + vCommand)
END SUBROUTINE
 



Here's an example of how the subroutine is called on my 'Estimates' form, from a Print/Preview command button:
Code
Select All
var vPDFLocation as String
var vPDFChoices as String
var vRS as int
var vReportFileName as string
var vChoice as String
var vPDFChoice as String
var vChoices as String
var vAttachment as String

vChoices = "Preview/Print;Email"

//vPDFLocation = "C:\Sesame2\Data\PDFs" // This specifies that the local directory be used.
vPDFLocation = "P:\Sesame2\Data\PDFs"
vPDFChoices = @LocalListDirectory(vPDFLocation)

PopupSelectPosition(4, @XPos(ThisElement) + 80, @YPos(ThisElement))

If NOT @IsNew // This record has been saved!
{
	vChoice = @PopupChoiceList(vChoices, "Select A Print Option")

	If vChoice = "Preview/Print"
	{
		vRS = @XResultSetSearch(@FN, "CLIENTS!ESTIMATES", 0, 2, "!ESTIMATENUMBER=" + ESTIMATENUMBER)
		If vRS > -1
		{
			If @XResultSetTotal(vRS) = 1
			{
				vReportFileName = @XResultSetPrintReport("Print Estimate Form", vRS, 1)
			}
			Else
			{
				@MsgBox("Two records were found with the Estimate Number: " + ESTIMATENUMBER, "The estimate cannot be printed.","Please contact CJ.")
			}
			XResultSetClose(vRS)
		}
		Else
		{
			@MsgBox("A valid result set could not be created.", "This is a serious error.", "Contact CJ.")
		}
	}

	If vChoice = "Email"
	{
		If @IsBlank(EMAIL) <> 1
		{
			vPDFChoice = @PopupChoiceList(vPDFChoices, "Include a PDF?")
			If vPDFChoice <> ""
			{
				vAttachment = vPDFLocation + "\" + vPDFChoice
			}

			vRS = @XResultSetSearch(@FN, "CLIENTS!ESTIMATES", 0, 2, "!ESTIMATENUMBER=" + ESTIMATENUMBER)
			If vRS > -1
			{
				If @XResultSetTotal(vRS) = 1
				{
					vReportFileName = @XResultSetPrintReport("Print Estimate Form", vRS, 1)
					If @CountStringArray(vAttachment) = 1
					{
						vAttachment = @AppendStringArray(vReportFileName, vAttachment)
					}
					Else
					{
						vAttachment = vReportFileName
					}
				}
				Else
				{
					@MsgBox("Two records were found with the Estimate Number: " + ESTIMATENUMBER, "The estimate cannot be printed.", "Please contact CJ.")
				}
				XResultSetClose(vRS)
				ThunderBird(EMAIL, "Ace Banner Estimate #" + ESTIMATENUMBER, "", vAttachment)
			}
			Else
			{
				@MsgBox("A valid result set could not be created.", "This is a serious error.", "Contact CJ.")
			}
		}
		Else
		{
			@MsgBox("This estimate cannot be emailed because the contact","does not have an email address listed.","")
		}
	}
}
Else
{
	@MsgBox("Please SAVE this record before you print it.", "Hit the SAVE button and then try again.", "")
}
 



When the command button programming is called, the user gets a choice of simply viewing the estimate (as its an HTML, whatever internet browser is available is used), or emailing it. In either case, the HTML report is shown. If emailing was selected then the user is asked if they would like to add any additional files to the email. My company does graphic work, so we usually add a PDF for artwork submission guidelines, etc. After that, the Thunderbird email composing window pops up with the major fields filled out -- the client's email, the subject line, and the estimate report is attached. The user can then fill out the body with whatever they need, and hit send.

The major drawbacks are that the file is not a PDF, and it gets the Sesame default name. Not a perfect solution, but maybe a starting point. I would much prefer to send a PDF file, but I never managed to figure out how to print one automatically to a file.

Hope this helps.
  
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Email Invoices - PrintAFormToHTML ?
Reply #5 - Feb 6th, 2012 at 7:28pm
Print Post Print Post  
Hi Acebanner,

Thanks for your answer - I'll pour over it and see where it will help me.

Below are a pdf example of my invoice, and the invoice programming.  The invoice program starts with the SalesOrder and then automatically manipulates a bunch of stuff in it to be able to present a printed invoice to the client, and an internal invoice for our records (which has some different and some additional information on it).  After all the manipulation and printing, it then changes everything back to the SalesOrder form, and loops on to the next Sales Order to invoice.  Having our invoicing process be automated is critical to us (we issue about 700 invoices a month), and the ability to move many of our clients from printed to emailed invoices would be a big benefit in time (no folding, enveloping time required) and money savings (no envelope expense, no stamp expense).

http://www.wordcom.com/28441.jpg
The above link is an example of the invoice output from the programming below.

// prompt user for a list of order #s to invoice.  Once the list is enters (separated by ";")
// then that variable will be inserted into SONum field, the result set found, then the
// screen will be setup by making some fields visible and others invisible, then the
// result set will be looped through, printed, notated, then saved, then F10'd via code
// to the next record in the result set. The last record will be saved via FormCommit, and a
// summary report will be printed for the SONum, cust #, shipto ID, Orderer, PO#, Total cost, SOTotal, tax, pay this amount
// Then a writeln window will display, telling user that the job is finished and how many records were printed


var vAnswer as string
var vQuestion as string
var vLoop as int
var vCount as int
var vIDate as string
var vRS as int
var n as int
var vPrt as int
var vInv as string
var vQues2 as string
var vSeparatePage as string
var vMailDiff as string
var vClientMailToAddress as string
var vRSm as int
var vClientID as string
var vCountMail as int
var vOrderShipToA as string
var vOrderShipToB as string
var vClientName as string
var vClientAddress1 as string
var vClientAddress2 as string
var vClientCity as string
var vClientState as string
var vClientZip as string
var vClientID4 as string
var vRS4Tot as int
var vRS4 as int
var vClientBillingName as string
var vSHOPC as double
var vFlag2 as string
var vSONum as string
var vClientNameOri as string
var vShipToOri as string

var vQtyNotPrinted as int
var vQtyPrinted as int
var vSONumsPrinted as string
var vSONumsNotPrinted as string

var vSOCostTotal as double
var vSOTotalShadow as double
var vSOTaxTotal as double
var vSOTaxTotalShadow as double
var vSOTotalPlusTax as double

var vBatchCost as double
var vBatchSales as double
var vBatchSHOPC as double
var vBatchTax as double
var vBatchOverall as double

var vRSbo as int
var vCountMailbo as int
var vLoopbo as int
var vSONumA as string
var vSONumB as string
var vSONumC as string
var vSONumD as string
var vSONumE as string
var vSONumBO as string

var vSOLNum as string

var vRSSOLInv as int
var vCountSOLInv as int
var vLoopSOLInv as int
var vSOLbo as string
var vSOLInvDate as date

var vS as string

var vSavings as string
var vSavingsInfo as string

var vInvoiceEmailAddress as string
var vInvoice as string
var vEmail as int



vQtyNotPrinted = 0
vSONumsNotPrinted = ""

vQtyPrinted = 0
vSONumsPrinted = ""

vBatchCost = 0
vBatchSales = 0
vBatchSHOPC = 0
vBatchTax = 0
vBatchOverall = 0



If @Group <> "clients"
{

If @Mode() = 2
  {
    vIDate = @Calendar("", "Invoice Date (Esc to cancel)")
    vIDate = @ToDate(vIDate)

    If vIDate < @ToDate("04/01/2010")   // = ""
      {
        @MsgBox("You must choose an invoice date to print invoices.","Please try again.","")
      }
       else if vIDate <> ""
              {
                   vQuestion = @PromptforUserInput("Enter the order #s to be invoiced, separated by a semi-colon ';'","")
               vAnswer = vQuestion

               If vAnswer = ""
                    {
                   @MsgBox("You must enter at least one valid Order # to invoice.", "Please", "try it again")
                    }

                      else
                        {
                       FormFieldValue("", "SONum", 0, vAnswer)
                       n = @SelectTreeItem("Search Menu!Search Commands!Retrieve New Results (F10)")
                       vCount = @FormResultSetTotal("Orders")

                       
                             If vCount = 0
                               {
                                   @MsgBox("No matching records.", "Review the Order #'s you inserted and try again", "")
                               }

                                             Else If vCount > 0
                                           {

                                            SubFormVisibility("LE0", 1)
                                            FormThrowfocus("SOLines", "Launchpad")
                                            VQues2 = @PromptForUserInput("Enter 'X' and press 'ok'","")
                                            FormFieldValue("SOLines", "Launchpad", 0, vQues2)
                                            
                                            NotifyForm(-1)
                                            FormCommit("SOLines")
                                            FormCommit("")

                                            Attribute(WhosePage, ATTR_ID_FONT_SIZE, "28")
                                               
                                                   CreateAProcess("RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n wcInvoic")
                                              Loiter(1500)
     
                                            For vLoop = 1 To vCount
                                              vInv = ""
                                              vSONum = @FormFieldValue("Orders", "SONum", vLoop)
                                              vInv = @FormFieldValue("Orders", "Invoiced", vLoop)
                                              If vInv <> ""
                                               {
                                                     vSONumsNotPrinted = vSONumsNotPrinted + vSONum + ";"
                                               vQtyNotPrinted = vQtyNotPrinted + 1
     
                                               }

                                               else if vInv = ""
                                                      {
                                                                                                        
                                                     NotifyForm(-6)
                                                     NotifyForm(-1)
                                                     ResultSetCurrentPosition(vLoop)

                                                     vClientID = @FormFieldValue("", "ClientID", vLoop)
                                                     vClientNameOri = @FormFieldValue("", "ClientName", vLoop)
                                                     vShipToOri = @FormFieldValue("", "ShipTo", vLoop)
                                                     
                                                     SubFormVisibility("LE0", 1)
                                                     Visibility(Savings, 0)
                                                                                   
                                                     FormResultSetCurrentPosition("SOLines", @FormResultSetTotal("SOLines"))
                                                                             
                                                     
                                                     
                                                     
                                                     vMailDiff = ""
                                                     vClientMailToAddress = ""

                                                                                                                                                                 
                                                     Visibility(ClientID2, 0)
                                                     Visibility(LE9, 0)
                                                     Visibility(InternalFlag1, 0)
                                                     Visibility(SOCostTotal, 0)
                                                     Visibility(SOProfitTotal, 0)
                                                     Visibility(LE2, 0)
                                                     Visibility(LE3, 0)
                                                     Visibility(LE4, 0)
                                                     Visibility(LE20, 0)
                                                     Visibility(SOTime, 0)
                                                     Visibility(ClientEmail, 0)
                                                     Visibility(SOTotal, 0)
                                                     Visibility(SOTaxTotal, 0)
                                                     Visibility(LE8, 0)
                                                     Visibility(UserID, 0)
                                                     Visibility(DateRange, 0)
                                                     Visibility(DiscountPerc, 0)

                                                     Visibility(WhosePage, 1)
                                                     Visibility(InvoiceDate, 1)

                                                     Visibility(SOTotalShadow, 1)
                                                     Visibility(SOTaxTotalShadow, 1)
                                                     Visibility(SOTotalPlusTax, 1)
                                                     Visibility(SHOPC, 1)
                                                     If DiscountPerc <> ""
                                                       {
                                                         Visibility(DiscountPerc, 1)
                                                       }
                                                     Visibility(LE12, 1)
                                                     Visibility(Flag2, 0)

                                                     FormFieldValue("", "InvoiceDate", vLoop, vIDate)
                                                     vSOCostTotal = SOCostTotal
                                                     vSOTotalShadow = SOTotalShadow
                                                     vSHOPC = SHOPC
                                                     vSOTaxTotalShadow = SOTaxTotalShadow
                                                     vSOTotalPlusTax = SOTotalPlusTax

                                                     If (SOTotalPlusTax > 0) or (SOTotalPlusTax = 0)
                                                       {
                                                           Attribute(LE1, ATTR_ID_LABEL, "MyCompany, Inc. - INVOICE")
                                                           Attribute(LE6, ATTR_ID_LABEL, "P.O. Box 5555, Tulsa, OK  74159")
                                                           Attribute(SONum, ATTR_ID_LABEL, "InvoiceNum")
                                                           FormFieldValue("", "WhosePage", vLoop, "Client INVOICE")
                                                           
                                                           Visibility(Flag3, 1)
                                                           FormFieldValue("", "Flag3", vLoop, "Please reference invoice # on payment document")
                                                           
                                                           vSavings = 0
                                                           vSavings = @TN(Savings)
                                                           vSavingsInfo = 0
                                                           Visibility(Flag4, 0)
                                                           If SOTotal > 0
                                                             {
                                                                 If (((@TN(vSavings) > 8) and (@TN(SOTotal) < 400)) or ((SOTotal > 400) and (@TN(vSavings))/(@TN(SOTotal)) > .03))
                                                                    {
                                                                          vSavingsInfo = "You just saved over $" + vSavings + " by using MyCompany instead of a big box chain store!!"
                                                                          FormFieldValue("", "Flag4", vLoop, vSavingsInfo) 
                                                                          Visibility(Flag4, 1)
                                                                    }
                                                             }
                                                           
                                                           RGBColor(SONum, 0, 0, 255, 255, 165, 96)
                                                           RGBColor(SOTotalPlusTax, -1, -1, -1, 255, 165, 96)
                                                           RGBColor(WhosePage, -1, -1, -1, 255, 165, 96)

                                                           vBatchCost = vBatchCost + vSOCostTotal
                                                           vBatchSales = vBatchSales + vSOTotalShadow
                                                           vBatchSHOPC = vBatchSHOPC + vSHOPC
                                                           vBatchTax = vBatchTax + vSOTaxTotalShadow
                                                           vBatchOverall = vBatchOverall + vSOTotalPlusTax
                                                       }
                                                        else If SOTotalPlusTax < 0
                                                             {
                                                                 Attribute(LE1, ATTR_ID_LABEL, "MyCompany, Inc. - CREDIT")
                                                                 Attribute(LE6, ATTR_ID_LABEL, "P.O. Box 5555, Tulsa, OK  74159")
                                                                 Attribute(SONum, ATTR_ID_LABEL, "CreditNum")
                                                                 Attribute(InvoiceDate, ATTR_ID_LABEL, "CreditDate")
                                                                 Attribute(SOTotalPlusTax, ATTR_ID_LABEL, "Credit Amount")
                                                                 Attribute(SOTotalPlusTax, ATTR_ID_LABEL_RGB_COLOR, "255 0 0")
                                                                 FormFieldValue("", "WhosePage", vLoop, "Client CREDIT")
                                                                 
                                                                 Visibility(Flag3, 1)
                                                                 //FormFieldValue("", "Flag3", vLoop, "Please reference invoice # on payment document")
                                                                 
                                                                 RGBColor(SOTotalPlusTax, 255, 0, 0, 255, 255, 255)
                                                                 RGBColor(WhosePage, 255, 0, 0, 255, 255, 255)

                                                                 vBatchCost = vBatchCost - vSOCostTotal
                                                                 vBatchSales = vBatchSales - vSOTotalShadow
                                                                 vBatchSHOPC = vBatchSHOPC - vSHOPC
                                                                 vBatchTax = vBatchTax - vSOTaxTotalShadow
                                                                 vBatchOverall = vBatchOverall - vSOTotalPlusTax
                                                                 
                                                             }
                                                     
                                                     
                                                     RGBColor(ClientName, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientAddress1, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientAddress2, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientCity, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientState, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientZip, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientPO, 255, 0, 0, 255, 255, 255)
                                                     
                                                     RGBColor(InvoiceDate, 0, 0, 255, 255, 255, 255)
                                                     

                                                     vRSm = @XResultSetSearch(@FN, "Client", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!ClientID=" + vClientID)
                                                     If vRSm > -1
                                                       {
                                                         vCountMail = @XResultSetTotal(vRSm)
                                                         If vCountMail = 1

                                                           {
                                                           vMailDiff = @XResultSetValue(vRSm, "ClientMailToDifferent")
                                                           If vMailDiff = "Y"
                                                             {
                                                               vClientMailToAddress = @XResultSetValue(vRSm, "ClientMailToAddress")

                                                               If vClientMailToAddress <> ""
                                                                 {
                                                                 If ShipToID = ""
                                                                   {
                                                                       vOrderShipToA = ""
                                                                       vOrderShipToB = ""

                                                                       VClientName = ClientName
                                                                       vClientAddress1 = ClientAddress1
                                                                       vClientAddress2 = ClientAddress2
                                                                       vClientCity = ClientCity
                                                                       vClientState = ClientState
                                                                       vClientZip = ClientZip
                                                                       vOrderShipToA = ShipTo

                                                                       vOrderShipToB = vOrderShipToA + @NewLine() + vClientAddress1 + @NewLine() + vClientAddress2 + @NewLine() + vClientCity + ", " + vClientState + "  " + vClientZip

                                                                       ShipToName = vClientName
                                                                       ShipTo = vOrderShipToB
                             
                                                                       vClientID4 = @Left(ClientID, 4)
                 
                                                                       vRS4 = @XResultSetSearch(@FN, "Client", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!ClientID=" + vClientID4)
                                                                       If vRS4 > -1
                                                                          {
                                                                                vRS4Tot = @XResultSetTotal(vRS4)
                                                                                If vRS4Tot = 1

                                                                                     {
                                                                                   vInvoiceEmailAddress = ""                                                                        
                                                                                   vClientBillingName = @XResultSetValue(vRS4, "ClientName")
                                                                                   vInvoiceEmailAddress = @XResultSetValue(vRS4, "InvoiceEmailAddress")
                                                                                   FormFieldValue("", "ClientName", vLoop, vClientBillingName)
                                                                               }
                                                                       
                                                                          }
                                                                       XResultSetClose(vRS4)
                                                                   }
                                                                                                                                                

                                                                    Visibility(ClientAddress1, 0)
                                                                    Visibility(ClientAddress2, 0)
                                                                 Visibility(ClientCity, 0)
                                                                 Visibility(ClientState, 0)
                                                                 Visibility(ClientZip, 0)
                                                                 Visibility(MailToAddress, 1)
                                                                 FormFieldValue("", "MailToAddress", vLoop, vClientMailToAddress)
                                                                 }
                                                             }
                                                           }
                                                       }
                                                     XResultSetClose(vRSm)                                                      

                                                     FormViewType("SOLines", 1)
                                                     
                                                     Loiter(500)
                                                     ForceRedraw()
                                                     vS = @Right(SONum, 1)
                                                     If vS <> "S"
                                                       {
                                                         If (vMailDiff = "") or ((vMailDiff <> "") and (vInvoiceEmailAddress = ""))
                                                           {
                                                           vPrt = @PrintAForm(0, 1, 1, 0, 28, -1, -1, -1, -1, 1, 1)
                                                           }
                                                           else if (vMailDiff <> "") and (vInvoiceEmailAddress <> "")
                                                                 {
                                                                   vPrt = @PrintAFormToHTML("./Invoices/" + vSONum + ".html")
                                                                   Loiter(500)
                                                                   If vPrt = 1
                                                                     {
                                                                       vInvoice = "./Invoices/" + vSONum + ".html"
                                                                       vEmail = @sendmail("smtp2go.com","MyCompany Invoice","MyServer@gmail.com",vInvoiceEmailAddress,"","","Here is MyCompany invoice " + vSONum,"","",vInvoice)
                       
                                                                      }
                                                                       else if vPrt = 0
                                                                            {
                                                                             Writeln("error: Failed to create " + vSONum + ".html")
                                                                                }

                                                                       
                                                                 }

                                                           

                                                       }
                                                                                                     
                                                     Attribute(LE1, ATTR_ID_LABEL, "MyCompany, Inc. Sales Order")
                                                     Attribute(LE6, ATTR_ID_LABEL, "123 Main St., Tulsa, OK 74104")
                                                     Attribute(SONum, ATTR_ID_LABEL, "SONum")
                                                     Attribute(SOTotalPlusTax, ATTR_ID_LABEL, "Pay This Amount")
                                                     Attribute(SOTotalPlusTax, ATTR_ID_LABEL_RGB_COLOR, "0 127 0")
                                                     
                                                     Attribute(InvoiceDate, ATTR_ID_LABEL, "InvoiceDate")

                                                     //Attribute(Flag3, ATTR_ID_LABEL, "Flag3")

                                                     Visibility(SOTotal, 1)
                                                     Clear(Flag3)
                                                     Visibility(Flag3, 0)
                                                     Clear(Flag4)
                                                     Visibility(Flag4, 0)
                                                     RGBColor(ClientName, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientAddress1, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientAddress2, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientCity, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientState, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientZip, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientPO, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(SONum, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(WhosePage, 0, 0, 255, 229, 229, 229)
                                                     RGBColor(SOTotalPlusTax, 0, 127, 0, 255, 255, 255)
                                                     
                                                                                                           
                                                     FormViewType("SOLines", 0)
                                                     Loiter(100)
                                                     

                                                     FormFieldValue("", "WhosePage", vLoop, "")
                                                     
           
                                                     vQtyPrinted = vQtyPrinted + 1
                                                     vSONumsPrinted = vSONumsPrinted + vSONum + ";"

                                                     If @Visibility(MailToAddress) = 1
                                                       {
                                                           ClientName = vClientNameOri

                                                           Visibility(MailToAddress, 0)
                                                           Visibility(ClientAddress1, 1)
                                                           Visibility(ClientAddress2, 1)
                                                           Visibility(ClientCity, 1)
                                                           Visibility(ClientState, 1)
                                                           Visibility(ClientZip, 1)
                                                           ShipTo = vShipToOri
                                         
                                                           
                                                       }
                                                     
                                                     Visibility(Savings, 0)
                                                     Visibility(Flag4, 0)
                                                                                                           
                                                     
                                                     NotifyForm(-1)

                                                     FormCommit("")
                                                      }
                                                     
                       
                                            Next
                                                       Attribute(WhosePage, ATTR_ID_FONT_SIZE, "18")

                 // this small section prints the Separator page btwn Client Invoices and WC Internal invoice copy

                                                     vSeparatePage = vCount + " invoices were attempted - " + vAnswer + "." + @NewLine() + "Actual qty printed was " + vQtyPrinted + ", and SONums printed were " + vSONumsPrinted + "." + @NewLine() + "Qty Not Printed were " + vQtyNotPrinted + ".  SONums not printed were " + vSONumsNotPrinted
                                                                                                           
                                                     NewPage(840, 1100)
                                                     PrintString("Separator Page and Summary", 18, 18, 0, " ARIAL", 14, 0)
                                                         PrintString(vSeparatePage, 21, @PageExtentY(), 400, " ARIAL", 14, 0)

                                                     PrintString("Total Sales = " + vBatchSales, 40, @PageExtentY(), 400, " ARIAL", 14, 0)
                                                     PrintString("Total Freight = " + vBatchSHOPC, 40, @PageExtentY(), 400, " ARIAL", 14, 0)
                                                     PrintString("Total Tax = " + vBatchTax, 40, @PageExtentY(), 400, " ARIAL", 14, 0)
                                                     PrintString("Total Overall = " + vBatchoverall, 50, @PageExtentY(), 400, " ARIAL", 14, 0)

                                                     PrintString("Total Cost = " + vBatchCost, 60, @PageExtentY(), 400, " ARIAL", 14, 0)

                                                     FinishPage()

                                                     
     
                 // this following code is the Internal Invoice copy

                                            For vLoop = 1 To vCount
                                              vInv = ""

                                              vSONum = @FormFieldValue("Orders", "SONum", vLoop)
                                              vInv = @FormFieldValue("Orders", "Invoiced", vLoop)

                                              If vInv <> ""
                                               {
                                                 writeln(vSONum + " not printed - previously invoiced")
                                               }
                                                                 else If vInv = ""
                                                      {

                                                     NotifyForm(-1)
                                                     NotifyForm(-6)
                                                     ResultSetCurrentPosition(vLoop)

                                                     vClientID = @FormFieldValue("", "ClientID", vLoop)
                                                     vClientNameOri = @FormFieldValue("", "ClientName", vLoop)
                                                     vShipToOri = @FormFieldValue("", "ShipTo", vLoop)
                                                     

                                                     SubFormVisibility("LE0", 1)
                                                                                   
                                                     FormResultSetCurrentPosition("SOLines", @FormResultSetTotal("SOLines"))
                                                                             
                                                     vMailDiff = ""
                                                     vClientMailToAddress = ""
                                                     
                                                     Visibility(ClientID2, 0)
                                                     Visibility(LE9, 0)
                                                     Visibility(InternalFlag1, 0)
                                                     Visibility(Flag2, 0)
                                                     Visibility(Flag3, 0)
                                                     Visibility(Flag4, 0)
                                                     Visibility(Savings, 0)
                                                     Visibility(SOCostTotal, 0)
                                                     Visibility(SOProfitTotal, 0)
                                                     Visibility(LE2, 0)
                                                     Visibility(LE3, 0)
                                                     Visibility(LE4, 0)
                                                     Visibility(LE20, 0)
                                                     Visibility(SOTime, 0)
                                                     Visibility(ClientEmail, 0)
                                                     Visibility(SOTotal, 0)
                                                     Visibility(SOTaxTotal, 0)
                                                     Visibility(LE8, 0)
                                                     Visibility(UserID, 0)
                                                     Visibility(DateRange, 0)
                                                     
                                                     
                                                     Visibility(WhosePage, 1)
                                                     Visibility(InvoiceDate, 1)

                                                     Visibility(SOCostTotal, 1)
                                                     Visibility(SOTotalShadow, 1)
                                                     Visibility(SOTaxTotalShadow, 1)
                                                     Visibility(SOTotalPlusTax, 1)
                                                     Visibility(DiscountPerc, 1)
                                                     Visibility(LE12, 1)

// this next little section finds backorders and assigns them an invoice and logout date so they show completed in searches

writeln(vSONum)
                                                     vSONumA = vSONum + "A"
                                                     vSONumB = vSONum + "B"
                                                     vSONumC = vSONum + "C"
                                                     vSONumD = vSONum + "D"
                                                     vSONumE = vSONum + "E"

                                                     //vCountMailbo = 0                                                      
                                                     vRSbo = @XResultSetSearch(@FN, "Orders", SEARCH_MODE_OR, SEARCH_SYNTAX_QA, "!SONum=" + vSONumA, "!SONum=" + vSONumB, "!SONum=" + vSONumC, "!SONum=" + vSONumD, "!SONum=" + vSONumE)

                                                     If vRSbo > -1
                                                       {
                                                         vCountMailbo = @XResultSetTotal(vRSbo)


                                                         If vCountMailbo > 0
                                                           {
                                                           For vLoopbo = 1 to vCountMailbo

                                                                 XResultSetCurrentPosition(vRSbo, vLoopbo)
                                                                 vSONumBO = @XResultSetValue(vRSbo, "SONum")
                                                                 XResultSetValue(vRSbo, "InvoiceDate", vIDate)
                                                                   XResultSetValue(vRSbo, "LogoutDate", @Date)
                                                                   XResultSetValue(vRSbo, "Invoiced", "B")
                                                             Next
                                                                              }
                                                                          }
                                                     XResultSetClose(vRSbo)
                 
                                                     vRSSOLInv = @XResultSetSearch(@FN, "Orders!SOLines", SEARCH_MODE_OR, SEARCH_SYNTAX_QA, "!SONum=" + vSONum, "!SONum=" + vSONumA, "!SONum=" + vSONumB, "!SONum=" + vSONumC, "!SONum=" + vSONumD, "!SONum=" + vSONumE)
                                                     
                                                     If vRSSOLInv > -1
                                                       {
                                                         vCountSOLInv = @XResultSetTotal(vRSSOLInv)

                                                         If vCountSOLInv > 0
                                                           {
                                                           For vLoopSOLInv = 1 to vCountSOLInv
                                                                 
                                                                 XResultSetCurrentPosition(vRSSOLInv, vLoopSOLInv)
                                                                 vSOLNum = @XResultSetValue(vRSSOLInv, "SONum")
                                                                 
                                                                 vSOLbo = @ContainsStringArray(vSOLNum, "A;B;C;D;E;X", 0)
                                                                 If vSOLbo <> ""
                                                                    {
                                                                                    XResultSetValue(vRSSOLInv, "Invd", "B")
                                                                       XResultSetValue(vRSSOLInv, "InvoiceDate", vIDate)
                                                                   }
                                                                    Else If vSOLbo = ""
                                                                         {
                                                                             XResultSetValue(vRSSOLInv, "Invd", "Y")
                                                                             XResultSetValue(vRSSOLInv, "InvoiceDate", vIDate)
                                                                         }

                                                           Next
                                                            }
                                                        }
                                                      XResultSetClose(vRSSOLInv)


// this ends the BO ticket updates section

                                                     FormFieldValue("", "InvoiceDate", vLoop, vIDate)
                                                     FormFieldValue("", "LogoutDate", vLoop, @Date)

                                                     If (SOTotalPlusTax > 0) or (SOTotalPlusTax = 0)
                                                       {
                                                           Attribute(LE1, ATTR_ID_LABEL, "MyCompany, Inc. - invoice")
                                                           Attribute(SONum, ATTR_ID_LABEL, "InvoiceNum")
                                                           FormFieldValue("", "WhosePage", vLoop, "WC Internal Invoice")
                                                           
                                                           RGBColor(SONum, 0, 0, 255, 255, 165, 96)
                                                           
                                                       }
                                                        else If SOTotalPlusTax < 0
                                                             {
                                                                 Attribute(LE1, ATTR_ID_LABEL, "MyCompany, Inc. - CREDIT")
                                                                 
                                                                 Attribute(SONum, ATTR_ID_LABEL, "CreditNum")
                                                                 Attribute(InvoiceDate, ATTR_ID_LABEL, "CreditDate")
                                                                 Attribute(SOTotalPlusTax, ATTR_ID_LABEL, "Credit Amount")
                                                                 Attribute(SOTotalPlusTax, ATTR_ID_LABEL_RGB_COLOR, "255 0 0")
                                                                 FormFieldValue("", "WhosePage", vLoop, "WC Internal Credit")
                                                                 
                                                                                                                                   
                                                                 RGBColor(SOTotalPlusTax, 255, 0, 0, 255, 255, 255)
                                                                                                                                   
                                                             }

                                                           
                                                     
                                                     
                                                     RGBColor(WhosePage, 255, 0, 0, 255, 255, 0)
                                                     
                                                     If (SHOPC <> "") and (SHOPC <> 0)
                                                       {
                                                           //vSHOPC = @FormFieldValue("Orders", "SHOPC", vLoop)
                                                           //vSHOPC = @ToMoney(vSHOPC)
                                                           //FormFieldValue("", "Flag2", vLoop, "Be Sure to Add SHOPC to AV32 invoice")                                                      
                                                           Visibility(Flag2, 1)
                                                           //vFlag2 = "x"   // "Add SHOPC  " + vSHOPC + "  to AV32 invoice"
                                         
                                                           //Loiter(25)
                                                           //FormFieldValue("", "Flag2", vLoop, "Be Sure to Add SHOPC to AV32 invoice")
                                                                                                                       
                                                       }
                                                     

                                                     RGBColor(ClientName, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientAddress1, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientAddress2, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientCity, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientState, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientZip, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientPO, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(SONum, 0, 0, 255, 255, 255, 255)
                                                     RGBColor(InvoiceDate, 0, 0, 255, 255, 255, 255)
                                                     RGBColor(SOCostTotal, 0, 0, 0, 252, 252, 168)
                                                     RGBColor(SOTotalShadow, 0, 0, 0, 252, 252, 168)
                                                     RGBColor(SHOPC, 0, 0, 0, 223, 229, 146)

                                                     vRSm = 0
                                                     vRSm = @XResultSetSearch(@FN, "Client", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!ClientID=" + vClientID)
                                                     If vRSm > -1
                                                       {
                                                         vCountMail = @XResultSetTotal(vRSm)
                                                         If vCountMail = 1
                                                        
                                                           {
                                                           vMailDiff = @XResultSetValue(vRSm, "ClientMailToDifferent")
                                                           If vMailDiff = "Y"
                                                             {
                                                               vClientMailToAddress = @XResultSetValue(vRSm, "ClientMailToAddress")
                                                               If vClientMailToAddress <> ""
                                                                 {
                                                                 If ShipToID = ""
                                                                   {

                                                                       vOrderShipToA = ""
                                                                       vOrderShipToB = ""                                                                        

                                                                       VClientName = ClientName
                                                                       vClientAddress1 = ClientAddress1
                                                                       vClientAddress2 = ClientAddress2
                                                                       vClientCity = ClientCity
                                                                       vClientState = ClientState
                                                                       vClientZip = ClientZip
                                                                       vOrderShipToA = ShipTo

                                                                       vOrderShipToB = vOrderShipToA + @NewLine() + vClientAddress1 + @NewLine() + vClientAddress2 + @NewLine() + vClientCity + ", " + vClientState + "  " + vClientZip

                                                                       ShipToName = vClientName
                                                                       ShipTo = vOrderShipToB

                                                                       vClientID4 = @Left(ClientID, 4)
                 
                                                                       vRS4 = @XResultSetSearch(@FN, "Client", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!ClientID=" + vClientID4)
                                                                       If vRS4 > -1
                                                                          {
                                                                                vRS4Tot = @XResultSetTotal(vRS4)
                                                                                If vRS4Tot = 1

                                                                                     {                                                                        
                                                                                   vClientBillingName = @XResultSetValue(vRS4, "ClientName")
                                                                                   FormFieldValue("", "ClientName", vLoop, vClientBillingName)
                                                                               }
                                                                       
                                                                          }
                                                                       XResultSetClose(vRS4)
                                                                   }

                                                                    Visibility(ClientAddress1, 0)
                                                                    Visibility(ClientAddress2, 0)
                                                                 Visibility(ClientCity, 0)
                                                                 Visibility(ClientState, 0)
                                                                 Visibility(ClientZip, 0)
                                                                 Visibility(MailToAddress, 1)
                                                                 FormFieldValue("", "MailToAddress", vLoop, vClientMailToAddress)
                                                                 }
                                                             }
                                                           }
                                                       }
                                                     XResultSetClose(vRSm)

                                                     FormFieldValue("Orders", "Invoiced", vLoop, "Y")
                                                     
                                                     FormViewType("SOLines", 1)
                                                     
                                                     
                                                     Loiter(500)
                                                     If @Visibility(Flag2) = 1
                                                       {
                                                           Flag2 = "Be sure to add SHOPC to AV32 invoice"
                                                       }
                                                     Loiter(200)

                                                     vS = @Right(SONum, 1)
                                                     If vS <> "S"
                                                       {
                                                           vPrt = @PrintAForm(0, 1, 1, 0, 28, -1, -1, -1, -1, 1, 1)
                                                       }
                                                                                                     
                                                     Attribute(LE1, ATTR_ID_LABEL, "MyCompany Inc Sales Order")
                                                     Attribute(SONum, ATTR_ID_LABEL, "SONum")
                                                     Attribute(SOTotalPlusTax, ATTR_ID_LABEL_RGB_COLOR, "0 127 0")

                                                     Visibility(SOTotal, 1)
                                                     Visibility(SOTaxTotal, 1)
                                                     RGBColor(ClientName, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientAddress1, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientAddress2, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientCity, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientState, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientZip, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(ClientPO, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(SONum, 255, 0, 0, 255, 255, 255)
                                                     RGBColor(SOCostTotal, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(SOTotalShadow, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(SHOPC, 0, 0, 0, 255, 255, 255)
                                                     RGBColor(SOTotalPlusTax, 0, 127, 0, 255, 255, 255)

                                                                                                           
                                                     FormViewType("SOLines", 0)
                                                     Loiter(100)
                                                     
                                                     RGBColor(WhosePage, 0, 0, 255, 255, 255, 255)
                                                     FormFieldValue("", "WhosePage", vLoop, "")
                                                     

                                                     If @Visibility(MailToAddress) = 1
                                                       {
                                                           ClientName = vClientNameOri

                                                           Visibility(MailToAddress, 0)
                                                           Visibility(ClientAddress1, 1)
                                                           Visibility(ClientAddress2, 1)
                                                           Visibility(ClientCity, 1)
                                                           Visibility(ClientState, 1)
                                                           Visibility(ClientZip, 1)
                                                           ShipTo = vShipToOri
                                                       }
                                                     
                                                     Clear(Flag2)
                                                     Visibility(Flag2, 0)
                                                     Visibility(DateRange, 1)

                                                     NotifyForm(-1)
                                                     FormCommit("")
                                                                       }
                                            Next

                                                         //Writeln((vCount) + " records were invoiced. The Order/Invoice #s were " + vAnswer)
                                               CreateAProcess("RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n wcLaser1")

                                               
                                               }

               
                          
                      }


           }
}

}


  

Larry
Back to top
IP Logged