{% set absUrl = app.request.getSchemeAndHttpHost() ~ app.request.baseUrl|replace({'/app_dev.php': ''}) %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="{{ absUrl ~ asset('bundles/rxconnexion/admin/css/report/report_wkpdf.css') }}" />
</head>
<body>
<h3 class="report-header">{{ page_title }}</h3>
<table class="report-data" width="100%">
    <thead class="header">
    <tr>
        <th>Referral Date</th>
        <th>Receive Date</th>
        <th>Patient</th>
        <th>Patient Service</th>
        <th>Company</th>
        <th>Branch</th>
        <th>Referring Affiliate</th>
        <th>Referring Physician</th>
        <th>Latest Encounter</th>
        <th>Latest Encounter Status</th>
        <th>Letter Type</th>
        <th>Letter Status</th>
        <th>Agent</th>
        <th>Invoice No.</th>
        <th>Billing Date</th>
        <th>Rate</th>
    </tr>
    </thead>
    <tbody>
    {% set totalCount = 0 %}
    {% for record in records.marketing %}
        {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
        {% set totalCount = totalCount + 1 %}
        <tr class="{{ trC }}">
            <td>{{ record.referral_date }}</td>
            <td>{{ record.receive_date }}</td>
            <td>{{ record.patient }}</td>
            <td>
                {% set ps_split = record.patientServices|split(',') %}
                {% for ps in ps_split %}
                    {% set patientService = ps|split('|') %}
                    <div>{{ patientService[1]|default('') }}</div>

                {% endfor %}
            </td>
            <td>{{ record.companyDesc }}</td>
            <td>{{ record.branch }}</td>
            <td>{{ record.referring_affiliate }}</td>
            <td>{{ record.referring_physician }}</td>
            <td>{{ record.chartTypeDesc }}</td>
            <td>{{ record.chartStatusDesc }}</td>
            <td> {{ record.letterType }}</td>
            <td>{{ record.letterStatus }}</td>
            <td>{{ record.sales_agent }}</td>
            <td>{{ record.invoice_no }}</td>
            <td>{{ record.billingDate }}</td>
            <td style="text-align: right;">{{ record.rate }}</td>
        </tr>
    {% endfor %}
</table>
<div>Total Records: {{ totalCount }}</div>
<hr>
<h5 class="report-header">Summary</h5>
<table class="report-data" width="50%">
    <thead class="header">
    <tr>
        <th>Agent</th>
        <th>Total</th>
    </tr>
    </thead>
    <tbody>
    {% set totalCount = 0 %}
    {% for record in records.soldCount %}
        {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
        {% set totalCount = totalCount + 1 %}
        <tr class="{{ trC }}">
            <td>{{ record.sales_agent }}</td>
            <td>{{ record.rate }}</td>
        </tr>
    {% endfor %}
</table>
</body>
</html>