@using PantheonRA.BackOffice.Models
@using PAW.Contracts.Enums;
@{
    ViewBag.Title = Loc.ImportSubjects;
}

<div class="wrapper wrapper-content">
    <div class="tabs-container">
        @Html.Partial("~/Views/Products/_CodeListTabNavigation.cshtml")
        <div class="tab-content">
            <div class="row buttons-tabbed">
                @Html.Partial("_FormButtons", new FormButtonsViewModel
                {
                    BackUrl = Url.Action("Index", "Subjects"),
                    SaveButtonGroup = new FormButtonGroup
                    {
                        Buttons = new List<FormButton>
                        {
                            new FormButton { Text = Loc.Save, Icon = "far fa-print fa-lg", OnClick = "SaveProcessedSubjects()", Class = "disabled" },
                        }
                    },
                })

                <a href="@Url.Action("ImportSubjects", "Subjects")" title="@Loc.UploadAgain" id="uploadAgainBtn"
                   class="btn btn-primary btn-outline pull-right">
                    <i class="fas fa-cloud-upload-alt m-r-xs"></i>
                    <span class="visible-lg-inline visible-md-inline">@Loc.UploadAgain</span>
                </a>
            </div>

            <div id="uploadContainer" class="uploadContainer">
                <h4 class="m-t-sm">@Loc.ImportSubjectsFileUpload</h4>
                <div class="dropify-large">
                    <form id="importFileForm" class="" data-url="@Url.Action("UploadSubjectsImportFile", "Subjects")" method="post" enctype="multipart/form-data">
                        <input name="ImportFile" id="ImportFile" type="file" class="dropify" data-show-errors="false" data-allowed-file-extensions="xlsx xls" />
                    </form>
                </div>
            </div>

            <div id="subjectTableContainer" class="subjectTableContainer hidden">
                <div class="divided-content clearfix">
                    <div class="divided-content-main divided-content-full">
                        <div class="row document-head">
                            <div class="col-md-2">
                                <h4>@Loc.ShowOnlyErrors</h4>
                                <input id="showOnlyErrors" type="checkbox" class="form-control js-switch" />
                            </div>
                            <div class="col-md-2">
                                <h4>@Loc.NumberOfSubjectToBeUpdated</h4>
                                <span class="badge badge-primary" id="subjectToUpdateCount">0</span>
                            </div>
                            <div class="col-md-2">
                                <h4>@Loc.NumberOfSubjectToBeInserted</h4>
                                <span class="badge badge-primary" id="subjectToInsertCount">0</span>
                            </div>
                            <div class="col-md-6">
                                <h4>@Loc.NumberOfErrorsInColumns</h4>
                                <span class="badge badge-danger" id="errorsCount">0</span>
                            </div>
                        </div>

                        <div class="document-body">
                            <div class="import-table">
                                <table id="mainGrid" class="diplay nowrap dt-scroller" style="width:100%">
                                    <thead>
                                        <tr>
                                            <th data-column-id="Id" data-visible="false"></th>
                                            <th data-column-id="HasErrors">@Loc.Status</th>
                                            <th data-column-id="AcSubject">@Loc.Subject</th>
                                            <th data-column-id="AcName2">@Loc.Name 2</th>
                                            <th data-column-id="AcName3">@Loc.Name 3</th>
                                            <th data-column-id="AcAddress">@Loc.Address</th>
                                            <th data-column-id="AcCountry">@Loc.Country</th>
                                            <th data-column-id="AcPost">@Loc.Post</th>
                                            <th data-column-id="AcSKIS">@Loc.SKIS</th>
                                            <th data-column-id="AcActivityCode">@Loc.ActivityCode</th>
                                            <th data-column-id="AcVatCodePrefix">@(PantheonRA.BackOffice.CurrentUser.Localization != @Localization.Code.HR ? @Loc.VATNumberWithPrefix : @Loc.CompanyVAT)</th>
                                            <th data-column-id="AcCode">@Loc.GridVatNumber</th>
                                            <th data-column-id="AcRegNo">@Loc.RegistrationNumberShort</th>
                                            <th data-column-id="AcIbanprefix">@Loc.IbanPrefix</th>
                                            <th data-column-id="AcSwiftcode">@Loc.SwiftBicCode</th>
                                            <th data-column-id="AcBuyer">@Loc.Buyer</th>
                                            <th data-column-id="AcSupplier">@Loc.Supplier</th>
                                            <th data-column-id="AcBank">@Loc.Bank</th>
                                            <th data-column-id="AcMunicipality">@Loc.Municip</th>
                                            <th data-column-id="AcWarehouse">@Loc.Warehouse</th>
                                            <th data-column-id="AcDept">@Loc.Department</th>
                                            <th data-column-id="AcPhone">@Loc.Telefon</th>
                                            <th data-column-id="AcFax">@Loc.Fax</th>
                                            <th data-column-id="AcXmldocType">@Loc.BusinessType</th>
                                            <th data-column-id="AcWayOfSale">@Loc.WayOfSelling</th>
                                            <th data-column-id="AcSuppSaleMet">@Loc.MethodOfProcurement</th>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="countryOptions" hidden>
    <option></option>
    @foreach (var country in ViewBag.Countries)
    {
        <option value="@country.Country">
            @country.Country
        </option>
    }
</div>

<div id="prefixOptions" hidden>
    <option></option>
    @foreach (var country in ViewBag.Countries)
    {
        <option value="@country.VATCodePrefix">
            @country.VATCodePrefix
        </option>
    }
</div>


<div id="subjectCisOptions" hidden>
    <option></option>
    @foreach (var skis in ViewBag.SubjectSkis)
    {
        <option value="@skis.Id">
            @skis.Id
        </option>
    }
</div>


<div id="subjectACOptions" hidden>
    <option></option>
    @foreach (var ac in ViewBag.SubjectActivityCodes)
    {
        <option value="@ac.Id">
            @ac.Id
        </option>
    }
</div>

<div id="postOptions" hidden>
    <option></option>
    @foreach (var ac in ViewBag.Posts)
    {
        <option value="@ac.Id">
            @ac.Id
        </option>
    }
</div>

<div class="modal inmodal fade" id="errorModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <span id="errorModalMessage"></span>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="">@Loc.OK</button>
            </div>
        </div>
    </div>
</div>

<input type="hidden" id="CurrentLoc" value="@PantheonRA.BackOffice.CurrentUser.DatabaseLocalization" />
<input type="hidden" id="paperLoc" value="@Loc.Paper" />
<input type="hidden" id="paperAndElectronicLoc" value="@Loc.PaperAndElectronic" />
<input type="hidden" id="emailEStyleSimpleInvoiceLoc" value="@Loc.EmailEStyleSimpleInvoice" />
<input type="hidden" id="wayOfSaleFinalBuyer" value="@Loc.FinalBuyer" />
<input type="hidden" id="wayOfSaleIsTaxCommited" value="@Loc.IsTaxCommited" />
<input type="hidden" id="wayOfSaleFlatrate" value="@Loc.Flatrate" />
<input type="hidden" id="wayOfSaleDomesticTaxpayers" value="@Loc.DomesticTaxpayers" />
<input type="hidden" id="wayOfSaleExportSale" value="@Loc.ExportSale" />
<input type="hidden" id="wayOfSaleExportSaleEU" value="@Loc.ImportEU" />
<input type="hidden" id="wayOfSaleBiH" value="@Loc.BrckoDistrictBiH" />
<input type="hidden" id="wayOfSaleImport" value="@Loc.Import" />
<input type="hidden" id="wayOfSaleNonresident" value="@Loc.Nonresident" />
<input type="hidden" id="wayOfSaleFederationBiH" value="@Loc.FederationBiH" />
<input type="hidden" id="wayOfSaleOtherNotTaxCommited" value="@Loc.OtherPersonsNotTaxpayers" />
<input type="hidden" id="wayOfSaleR1" value="R1" />
<input type="hidden" id="wayOfSaleR2" value="R2" />
<input type="hidden" id="wayOfSaleRS" value="@Loc.SerbianRepublic" />
<input type="hidden" id="postTypeaheadUrl" value="@Url.Action("SearchPostsForDatatable", "Post")" />
<input type="hidden" id="subjectCisGetUrl" value="@Url.Action("Get", "SubjectCis")" />
<input type="hidden" id="subjectNaceGetUrl" value="@Url.Action("Get", "SubjectNace")" />
<input type="hidden" id="countriesGetUrl" value="@Url.Action("Get", "Country")" />
<input id="getProcessedSubjectsPartialUrl" type="hidden" value="@Url.Action("ProcessedSubjectsPartial", "Subjects")" />
<input id="uploadSubjectsImportFile" type="hidden" value="@Url.Action("UploadSubjectsImportFile", "Subjects")" />
<input id="subjectsIndex" type="hidden" value="@Url.Action("Index", "Subjects")" />
<input id="processSubjectsInsertUrl" type="hidden" value="@Url.Action("ProcessSubjects", "Subjects", new { insertAndUpdate = false })" />
<input id="processSubjectsInsertAndUpdateUrl" type="hidden" value="@Url.Action("ProcessSubjects", "Subjects")" />
<input type="hidden" id="DragAndDropOrClick" value="@Loc.UploadExcelMessage" />
<input type="hidden" id="Remove" value="@Loc.Remove" />
<input type="hidden" id="GeneralErrorMessage" value="@Loc.GeneralError" />
<input type="hidden" id="WrongFormat" value="@Loc.WrongFormat" />
<input type="hidden" id="ValidateSubjectUrl" value="@Url.Action("SubjetValidation", "Subjects")" />
<input type="hidden" id="selectLoc" value="@Loc.Select" />

@section pageScripts{
    @Scripts.Render("~/bundles/product")
    <script>
        $(document).ready(function () {
            initializeSubjectsImportSubjects();
        });
    </script>
}