@using PantheonRA.BackOffice.Enums
@model PantheonRA.BackOffice.Models.InvoiceReportViewModel
@{
    ViewBag.Title = Loc.Invoicing;
    Html.RenderPartial("_Breadcrumb", new PantheonRA.BackOffice.Models.BreadcrumbViewModel
    {
        Links = new List<Tuple<string, string>> {
            new Tuple<string, string>(Loc.InvoiceList, Url.Action("Index", "Wholesale")),
            new Tuple<string, string>(Loc.PreviewAndPrint, string.Empty)
        }
    });
}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row m-b-sm">
        <div class="col-xs-12 m-b-sm">
            <a onclick="redirectBack()" class="btn btn-success pull-right m-l-xs">@Loc.Back</a>

            <button type="button" onclick="printInvoice()" class="btn btn-primary pull-right printDropdown" id="print-invoice">
                <i class="far fa-print print-loader-icon m-r-sm"></i><span class="visible-lg-inline visible-md-inline">
                    @Loc.Print
                </span>
            </button>
        </div>
        @Html.HiddenFor(model => model.AcKey)
        @Html.HiddenFor(model => model.FiscalDate)
        <div class="col-xs-12">
            <div class="ibox-content">
                <div class="row">
                    <div id="invoicePreview"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="PrintPreview" data-url="@Url.Action("WholesalePdf", "Wholesale")" style="display:none"></div>

@section pageScripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#invoicePreview").mediaViewer({ dataUrl: $('#PrintPreview').data('url') + "?id=" + $("#AcKey").val()+ "&paperSize=" + "@PaperSizeType.A4" + "&preview=" + true, dataType: "pdf" });
        });

        function printInvoice() {
            let printWindow = window.open('');
            var fiscalize = false;
            if ($("#FiscalDate").val()) {
                fiscalize = true;
            }

            printWindow.location = $('#PrintPreview').data('url') + "?id=" + $("#AcKey").val() + "&fiscalize=" + fiscalize;
            printWindow.focus();
        }

        function redirectBack() {
            if (document.referrer == "") {
                window.location.href = '@Url.Action("Index", "Wholesale")';
            } else {
                window.history.back()
            }
        }
    </script>
}