Declare @SalesCount int

SET @SalesCount = (SELECT COUNT(*) FROM pal_Template WHERE templateName = 'Statement Sales Body')

if @SalesCount = 0

BEGIN

INSERT [dbo].[pal_Template] ([templateTypeId], [templateName], [templateContent]) VALUES (7, N'Statement Sales Body', N'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
    <head>
        <title>Statement</title>
        <style type="text/css">
            td, a
            {
            font-family: Calibri;
            font-size: 11px;
            text-decoration: none;
            color: #000000;
            }
            .heading
            {
            font-size: 18px;
            font-weight: bold;
            }
            .title
            {
            font-size: 11px;
            }
            .titleAccount
            {
            font-size: 12px;
            }
            .titleDue
            {
            font-size: 16px;
            font-weight: bold;
            }
            .footer
            {
            text-align: center;
            font-size: 10px;
            }
        </style>
    </head>
    <body>
        {AccountLines}
        <table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
            <tbody>
                <tr>
                    <td style="text-align: right; width: 100%;">
                    <span class="titleDue">Total Due: {Balance}</span>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; width: 100%;">
                    Please make sure your account is settled within 30 days.
                    </td>
                </tr>
            </tbody>
        </table>
    </body>
</html>')

INSERT [dbo].[pal_Template] ([templateTypeId], [templateName], [templateContent]) VALUES (7, N'Statement Sales Header', N'<table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
    <tbody>
        <tr>
            <td style="font-family: Calibri; text-align: center; font-size: 14px; font-weight: bold;">{Heading}
            </td>
        </tr>
        <tr>
            <td style="width: 100%;">
            <table cellpadding="0" cellspacing="0" border="0" style="width: 100%; height: 33px;">
                <tbody>
                    <tr>
                        <td style="font-family: Calibri; font-size: 12px; width: 60%; text-align: left;" valign="top"><br />
                        </td>
                        <td style="font-family: Calibri; font-size: 16px; width: 40%;"><br />
                        </td>
                    </tr>
                    <tr>
                        <td style="font-family: Calibri; font-size: 12px;"><br />
                        </td>
                        <td style="font-family: Calibri; font-size: 12px;">&nbsp;</td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr>
            <td style="font-family: Calibri; font-size: 11px; width: 100%; text-align: center;">
            <p><img alt="" src="/upload/image/Logo.jpg" /><br />
            <strong>{oSetup.customer}</strong></p>
            <p>&nbsp;</p>
            </td>
        </tr>
        <tr>
            <td style="font-family: Calibri; font-size: 11px; text-align: center;"><br />
            </td>
        </tr>
        <tr>
            <td style="width: 100%;">
            <table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
                <tbody>
                    <tr>
                        <td style="height: 40px;"></td>
                    </tr>
                    <tr>
                        <td style="width: 50%; text-align: left;" valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" align="left" style="width: 100%;">
                            <tbody>
                                <tr>
                                    <td style="width: 25px;"></td>
                                    <td style="font-family: Calibri; font-size: 14px;">{oSales.title} {oSales.name} {oSales.surname}<br />
                                    {oSales.postalAddress}
                                    </td>
                                    <td style="width: 5px;"></td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                        <td style="width: 25%;" valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
                            <tbody>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: left;">
                                    <strong>Bank Details</strong>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: left;"><br />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: left;"><br />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: left;"><br />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: left;"><br />
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                        <td style="width: 25%;" valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
                            <tbody>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: right;"><strong>Date:</strong> {Date}
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: right;">
                                    <strong>Tel:</strong> {oSetup.tel}<br />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: right;">
                                    <strong>Email:</strong> {oSetup.email}
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>')


INSERT [dbo].[pal_Template] ([templateTypeId], [templateName], [templateContent]) VALUES (7, N'Invoice Sales Body', N'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
    <head>
        <title>Statement</title>
        <style type="text/css">
            td, a
            {
            font-family: Calibri;
            font-size: 11px;
            text-decoration: none;
            color: #000000;
            }
            .heading
            {
            font-size: 18px;
            font-weight: bold;
            }
            .title
            {
            font-size: 11px;
            }
            .titleAccount
            {
            font-size: 12px;
            }
            .titleDue
            {
            font-size: 16px;
            font-weight: bold;
            }
            .footer
            {
            text-align: center;
            font-size: 10px;
            }
        </style>
    </head>
    <body>
        {AccountLines}
        <table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
            <tbody>
                <tr>
                    <td style="text-align: right; width: 100%;">
                    <span class="titleDue">Total Due: {Balance}</span>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; width: 100%;">
                    Please make sure your account is settled within 30 days.
                    </td>
                </tr>
            </tbody>
        </table>
    </body>
</html>')

INSERT [dbo].[pal_Template] ([templateTypeId], [templateName], [templateContent]) VALUES (7, N'Invoice Sales Header', N'<table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
    <tbody>
        <tr>
            <td style="font-family: Calibri; text-align: center; font-size: 14px; font-weight: bold;">{Heading}
            </td>
        </tr>
        <tr>
            <td style="width: 100%;">
            <table cellpadding="0" cellspacing="0" border="0" style="width: 100%; height: 33px;">
                <tbody>
                    <tr>
                        <td style="font-family: Calibri; font-size: 12px; width: 60%; text-align: left;" valign="top"><br />
                        </td>
                        <td style="font-family: Calibri; font-size: 16px; width: 40%;"><br />
                        </td>
                    </tr>
                    <tr>
                        <td style="font-family: Calibri; font-size: 12px;"><br />
                        </td>
                        <td style="font-family: Calibri; font-size: 12px;">&nbsp;</td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr>
            <td style="font-family: Calibri; font-size: 11px; width: 100%; text-align: center;">
            <p><img alt="" src="/upload/image/Logo.jpg" /><br />
            <strong>{oSetup.customer}</strong></p>
            <p>&nbsp;</p>
            </td>
        </tr>
        <tr>
            <td style="font-family: Calibri; font-size: 11px; text-align: center;"><br />
            </td>
        </tr>
        <tr>
            <td style="width: 100%;">
            <table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
                <tbody>
                    <tr>
                        <td style="height: 40px;"></td>
                    </tr>
                    <tr>
                        <td style="width: 50%; text-align: left;" valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" align="left" style="width: 100%;">
                            <tbody>
                                <tr>
                                    <td style="width: 25px;"></td>
                                    <td style="font-family: Calibri; font-size: 14px;">{oSales.title} {oSales.name} {oSales.surname}<br />
                                    {oSales.postalAddress}
                                    </td>
                                    <td style="width: 5px;"></td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                        <td style="width: 25%;" valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
                            <tbody>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: left;">
                                    <strong>Bank Details</strong>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: left;"><br />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: left;"><br />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: left;"><br />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: left;"><br />
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                        <td style="width: 25%;" valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
                            <tbody>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: right;"><strong>Date:</strong> {Date}
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: right;">
                                    <strong>Tel:</strong> {oSetup.tel}<br />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="font-family: Calibri; font-size: 11px; text-align: right;">
                                    <strong>Email:</strong> {oSetup.email}
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>')

END


Declare @ProdCount int 
SET @ProdCount = (Select Count(*) FROM pal_Product)
IF @ProdCount > 0
BEGIN
UPDATE pal_Module SET isActive = 1 WHERE recID= 4
END
