if((select count(*) from dbo.pal_TemplateType where templateType = 'PurchaseOrder') = 0)
begin
INSERT INTO [dbo].[pal_TemplateType]
           ([templateType]
           ,[isActive]
           ,[sequence])
     VALUES
           ('PurchaseOrder'
           ,1
           ,9);

INSERT INTO [dbo].[pal_Template]
           ([templateTypeId]
           ,[templateName]
           ,[templateContent])
     VALUES
           (9
           ,'PurchaseOrderHeader'
           ,'<style type="text/css">
    td {
    font-family: Calibri;
    color: #595959;
    }
    .heading {
    font-size: 22pt;
    font-family: Calibri;
    color: #595959;
    }
    .subheading{
    font-size: 14pt;
    color: #595959;
    font-family: Calibri;
    font-weight: bold;
    }
    .full {
    width: 95%;
    }
    .half {
    width: 50%;
    }
    .third {
    width: 33.3%;
    }
    .fourth {
    width: 25%;
    }
    .forty{
    width:40%;
    }
    .twenty{
    width:20%;
    }
    .right {
    text-align: right;
    }
    .spacer {
    height: 20px;
    }
    .shim {
    height: 10px;
    }
    div {
    position: relative;
    float: left;
    }
    .mainInfo{
    font-size: 10pt;
    color: #595959;
    font-family: Calibri;
    font-weight: bold;
    }
    .subInfo{
    font-size: 9pt;
    color: #595959;
    font-family: Calibri;
    }
    .contactInfo{
    font-size: 10pt;
    color: #595959;
    font-family: Calibri;
    }
</style>
<table class="full" cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
            <td class="heading">{logo}</td>
            <td class="forty"><span class="heading">{heading}</span>
            <br />
            <span class="contactInfo"><br />
            {contactDetails}</span></td>
        </tr>
    </tbody>
</table>
<table>
    <tbody>
        <tr>
            <td class="spacer"></td>
        </tr>
    </tbody>
</table>
<table class="full" cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
            <td class="forty">
            <table class="full" cellpadding="0" cellspacing="0" border="0">
                <tbody>
                    <tr>
                        <td class="subheading">{To}</td>
                    </tr>
                    <tr>
                        <td class="mainInfo">{oSales.name}</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{oSales.postalAddress}</td>
                    </tr>
                    <tr>
                        <td><br />
                        </td>
                    </tr>
                    <tr>
                        <td class="mainInfo">{ToTaxDisplayname}</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{ToTaxNumber}</td>
                    </tr>
                </tbody>
            </table>
            </td>
            <td class="forty">
            <table class="full" cellpadding="0" cellspacing="0" border="0">
                <tbody>
                    <tr>
                        <td class="subheading">{From}</td>
                    </tr>
                    <tr>
                        <td class="mainInfo">{FromName}</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{FromAddress}</td>
                    </tr>
                    <tr>
                        <td><br />
                        </td>
                    </tr>
                    <tr>
                        <td class="mainInfo">{FromTaxDisplayname}</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{FromTaxDisplayNumber}</td>
                    </tr>
                </tbody>
            </table>
            </td>
            <td class="twenty">
            <table class="full" cellpadding="0" cellspacing="0" border="0">
                <tbody>
                    <tr>
                        <td class="subInfo">{DocNum}</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{DocDate}</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{AccountNumber}</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{Reference}</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{Attention}</td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>');

INSERT INTO [dbo].[pal_Template]
           ([templateTypeId]
           ,[templateName]
           ,[templateContent])
     VALUES
           (9
           ,'PurchaseOrderBody'
           ,'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
    <head>
        <title>PurchaseOrder</title>
        <style type="text/css">
            td, a
            {
              font-family: Calibri;
              font-size: 11px;
              text-decoration: none;
              color: #595959;
            }
            .heading
            {
            font-size: 18px;
            font-weight: bold;
            }
            .title
            {
            font-size: 11px;
            }
            .titleAccount
            {
            font-size: 12px;
            }
            .titleDue
            {
            font-size: 16px;
            font-weight: bold;
            text-transform: uppercase;
            }
			.footer {
			  position: absolute;
			  bottom: 0;
			  width: 100%;
			  height: 50px;
			}
			.heading {
				font-size: 22pt;
				font-family: Calibri;
				color: #595959;
			}
			.mainInfo{
				font-size: 10pt;
				color: #595959;
				font-family: Calibri;
				font-weight: bold;
			}
			 .subInfo{
				font-size: 9pt;
				color: #595959;
				font-family: Calibri;
			}
			.purchaseOrderVerticalLine {
				display: block;
				border-left: 1px solid gray;
				height: 5%;
				position: absolute;
				top: 50%;
			}
      .subheading{
    font-size: 14pt;
    color: #595959;
    font-family: Calibri;
    font-weight: bold;
    }
    .full {
    width: 95%;
    }
    .forty{
    width:40%;
    }
     .thirty{
        width:30%;
    }
    .twenty{
    width:20%;
    }
      
</style>
    </head>
    <body class="RadEditorContentStyle">
        {AccountLines}<br />
        <table style="width: 100%;">
            <tbody>
                <tr>
                    <td style="width: 60%;">
                    <br/>
                    </td>
                    <td style="width: 40%;">
                    {Totals}
                    </td>
                </tr>
            </tbody>
        </table>
		<br/><br/><br/><hr>
<span class="subheading">DELIVERY DETAILS</span><br/><br/>
<table class="full" cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
            <td class="thirty">
            <table class="full" cellpadding="0" cellspacing="0" border="0">
                <tbody>
                     <tr>
                        <td class="mainInfo">DELIVERY ADDRESS:</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{DeliveryAddress}</td>
                    </tr>
                    <tr>
                        <td><br/>
                        </td>
                    </tr>
                    <tr>
                        <td><br/></td>
                    </tr>
                    <tr>
                        <td><br/></td>
                    </tr>
                </tbody>
            </table>
            </td>
            <td class="purchaseOrderVerticalLine"></td>
            <td class="twenty">
            <table class="full" cellpadding="0" cellspacing="0" border="0">
                <tbody>
                    <tr>
                        <td class="mainInfo">ATTENTION:</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{DeliveryAttention}</td>
                    </tr>
                    <tr>
                        <td><br/>
                        </td>
                    </tr>
                    <tr>
                        <td class="mainInfo">TELEPHONE:</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{DeliveryTelephone}</td>
                    </tr>
                </tbody>
            </table>
            </td>
            <td class="purchaseOrderVerticalLine"></td>
            <td class="forty">
            <table class="full" cellpadding="0" cellspacing="0" border="0">
                <tbody>
                    <tr>
                        <td class="mainInfo">DELIVERY INSTRUCTIONS:</td>
                    </tr>
                    <tr>
                        <td class="subInfo">{DeliveryInstructions}</td>
                    </tr>
                    <tr>
                        <td><br/></td>
                    </tr>
                    <tr>
                        <td><br/></td>
                    </tr>
                    <tr>
                        <td><br/></td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>
</body>
</html>');
end