@model PantheonRA.WebApi.Contracts.PaWoEx

@{
    Model.ProdType = ViewBag.ProdType;
}

@Html.HiddenFor(model => model.PlanScrapQty)
@Html.HiddenFor(model => model.PlanWasteQty)
@Html.HiddenFor(model => model.RestQty)
@Html.HiddenFor(model => model.RestScrapQty)
@Html.HiddenFor(model => model.RestWasteQty)
@Html.HiddenFor(model => model.WoExDecPlacesProd)
@Html.HiddenFor(model => model.Finished)

@using (Html.BeginForm(null, null, FormMethod.Post, new { @id = "workOrderReceiving", enctype = "multipart/form-data" }))
{

    <div class="wrapper wrapper-content">
        <div class="tabs-container">
            @Html.Partial("_ReceivingTabNavigation")
            <div class="tab-content">

                @Html.HiddenFor(model => model.AcKey)
                @Html.HiddenFor(model => model.AnNo)
                @Html.HiddenFor(model => model.Ident)
                @Html.HiddenFor(model => model.UM)
                @Html.HiddenFor(model => model.DocType)
                @Html.HiddenFor(model => model.Receiver)
                @Html.HiddenFor(model => model.Dept)
                @Html.HiddenFor(model => model.CostDrv)
                @Html.HiddenFor(model => model.PlanQty)
                @Html.HiddenFor(model => model.QId)
                @Html.HiddenFor(model => model.ProdType)


                <div class="divided-content">
                    <div class="divided-content-main divided-content-full">

                        <div class="row document-head d-head-m-b-10">

                            <div class="col-xs-6 document-head-disabled-input">
                                <div class="form-group">
                                    <label class="control-label m-t-xs">@Loc.Number</label>
                                    <input class="form-control" id="acKeyDisplay" disabled="disabled" type="text" value=" @Model.KeyView">
                                </div>
                            </div>

                            <div class="col-xs-6 document-head-disabled-input">
                                <div class="form-group">
                                    <label class="control-label m-t-xs">@Loc.Product</label>
                                    <input type="text" disabled="disabled" class="form-control" style="overflow:hidden;text-overflow:ellipsis" value="@Model.Ident  - @Model.Name" />
                                </div>
                            </div>
                        </div>

                        <div class="project-list">
                            <div class="row">

                                <div class="form-horizontal form-md">
                                    <div class="col-xs-12 card-work-reg-card">
                                        <div class="card card-work-reg">
                                            <div class="card-header">
                                                <h3 class="card-title"><i class="fas fa-thumbs-up fa-lg text-primary m-r-sm"></i>  @Loc.Produced</h3>
                                            </div>

                                            <div class="card-body">

                                                <div class="input-group input-group-lg">
                                                    <span class="input-group-btn">
                                                        <button type="button" id="b_dfinished" class="btn btn-plus-minus"><i class="fa fa-minus fa-lg text-primary" id="dfinished"></i></button>
                                                    </span>
                                                    <input type="number" id="finished" name="ProducedQty" required class="form-control col-md-8 text-center input-lg" autocomplete="off" min="0" />
                                                    <span class="input-group-btn">
                                                        <button type="button" id="b_ifinished" class="btn btn-plus-minus"><i class="fa fa-plus fa-lg text-primary" id="ifinished"></i></button>
                                                    </span>

                                                </div>
                                                <div class="row text-center margin-top-10">
                                                    <a id="_finished" onclick="addRestMobile(this)" href="#">@Loc.WOReceiving_AddRest (@Decimal.Round(Model.RestQty, Model.WoExDecPlacesProd)) </a>
                                                </div>

                                            </div>

                                        </div>

                                    </div>

                                    <div class="col-xs-12 card-work-reg-card">
                                        <div class="card card-work-reg">
                                            <div class="card-header">

                                                <h3 class="card-title"><i class="fas fa-trash fa-lg text-primary m-r-sm"></i>  @Loc.WOScrap</h3>
                                            </div>

                                            <div class="card-body">

                                                <div class="input-group input-group-lg">
                                                    <span class="input-group-btn">
                                                        <button type="button" id="b_dscrap" class="btn btn-plus-minus"><i class="fa fa-minus fa-lg text-primary" id="dscrap"></i></button>
                                                    </span>
                                                    <input type="number" id="scrap" name="ScrapQty" required class="col-md-8 form-control text-center input-lg" autocomplete="off" min="0" />
                                                    <span class="input-group-btn">
                                                        <button type="button" id="b_iscrap" class="btn btn-plus-minus"><i class="fa fa-plus fa-lg text-primary" id="iscrap"></i></button>
                                                    </span>
                                                </div>
                                                <div class="row text-center margin-top-10">
                                                    <a id="_scrap" onclick="addRestMobile(this)" href="#">@Loc.WOReceiving_AddRest (@Decimal.Round(Model.RestScrapQty, Model.WoExDecPlacesProd))</a>
                                                </div>

                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-12 card-work-reg-card">
                                        <div class="card card-work-reg">
                                            <div class="card-header">

                                                <h3 class="card-title"><i class="fas fa-fire fa-lg text-primary m-r-sm"></i>@Loc.WOWaste</h3>
                                            </div>

                                            <div class="card-body">

                                                <div class="input-group input-group-lg">

                                                    <span class="input-group-btn">
                                                        <button type="button" id="b_dwaste" class="btn btn-plus-minus"><i class="fa fa-minus fa-lg text-primary" id="dwaste"></i></button>
                                                    </span>
                                                    <input type="number" id="waste" name="WasteQty" required class="col-md-8 form-control text-center input-lg" autocomplete="off" min="0" />
                                                    <span class="input-group-btn">
                                                        <button type="button" id="b_iwaste" class="btn btn-plus-minus"><i class="fa fa-plus fa-lg text-primary" id="iwaste"></i></button>
                                                    </span>
                                                </div>
                                                <div class="row text-center margin-top-10">
                                                    <a id="_waste" onclick="addRestMobile(this)" href="#">@Loc.WOReceiving_AddRest (@Decimal.Round(Model.RestWasteQty, Model.WoExDecPlacesProd))</a>

                                                </div>

                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-12 card-work-reg-card">
                                        <div class="card card-work-reg">
                                            <div class="card-header">

                                                <h3 class="card-title"><i class="fas fa-wrench fa-lg text-primary m-r-sm"></i>  @Loc.WORepair</h3>
                                            </div>

                                            <div class="card-body">

                                                <div class="input-group input-group-lg">
                                                    <span class="input-group-btn">
                                                        <button type="button" id="b_drepair" class="btn btn-plus-minus"><i class="fa fa-minus fa-lg text-primary" id="drepair"></i></button>
                                                    </span>
                                                    <input type="number" id="repair" name="RepairQty" required class="col-md-8 form-control text-center input-lg" autocomplete="off" min="0" />
                                                    <span class="input-group-btn">
                                                        <button type="button" id="b_irepair" class="btn btn-plus-minus"><i class="fa fa-plus fa-lg text-primary" id="irepair"></i></button>
                                                    </span>
                                                </div>

                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-12 card-work-reg-card">
                                        <div class="card card-work-reg ">
                                            <div class="card-header">

                                                <h3 class="card-title"><i class="far fa-calendar-alt fa-lg  text-primary m-r-sm"></i>  @Loc.Date</h3>
                                            </div>

                                            <div class="card-body">
                                                <input id="date" type="date" value="@DateTime.Now.Date.ToString("yyyy-MM-dd")" name="Date" class="input-lg text-center col-xs-12">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-12 card-work-reg-card">
                                        <div class="card card-work-reg ">
                                            <div class="card-body text-center">

                                                @Html.Image(ImageHelper.GetImageThumbnail(Model.Picture, 200), "", new { id = "image" })
                                                <i id="noImage" class='fal fa-image fa-3x text-muted hidden' style='opacity:0.5'></i>

                                            </div>
                                        </div>

                                    </div>
                                </div>

                            </div>

                        </div>

                    </div>

                    <div class="divided-content-side">
                        <div class="tabs-container">
                            <ul class="nav nav-tabs horizontal-menu" id="tabNav">
                                <li class="active divided-tab-2" id="homeTab"><a id="tabCaption" data-toggle="tab" href="#additional-settings" class="local-tab">@Loc.AdditionalSettings</a></li>
                                <li class="divided-tab-2" id="homeTab2"><a id="tabCaption" data-toggle="tab" href="#warehouse-list" class="local-tab">@Loc.ReceivingWarehouse</a></li>
                            </ul>
                        </div>
                        <div class="tab-content" id="sideNavBar">
                            <div id="additional-settings" class="tab-pane" data-tab-caption="Dodatne nastavitve">
                                <div class="form-horizontal additonal-options">

                                    <div class="row border-bottom p-l-10" id="finish-task">
                                        <a data-toggle="tab">
                                            <h3 class="text-default" data-toggle="tab">
                                                <i class="fa fa-dolly text-primary p-r-sm"></i>@Loc.FinishReceiving
                                                <span class="hw-switch-m-l pull-right">
                                                    <input type="checkbox" class="js-switch timeRecordsSwitch" id="receiveFinished" disabled="@Model.Finished" checked="@Model.Finished" />
                                                </span>
                                            </h3>
                                        </a>
                                    </div>
                                </div>

                            </div>

                            <div id="warehouse-list" class="tab-pane" data-tab-caption="@Loc.ReceivingWarehouse">
                                <div class="form-horizontal additonal-options">

                                    @foreach (var item in ViewBag.Warehouses)
                                    {
                                        <div class="row border-bottom p-l-10 warehouse-list-item @(ViewBag.Receiver == item.Id ? "active" : string.Empty)" data-value="@item.Id">
                                            <a data-toggle="tab">
                                                <h3 class="text-default" data-toggle="tab">
                                                    @item.Name
                                                    <i class="fa text-primary p-r-sm pull-right @(ViewBag.Receiver == item.Id ? "fa-check" : string.Empty)"></i>
                                                </h3>
                                            </a>
                                        </div>
                                    }

                                </div>
                            </div>

                            <button id="back" type="button" class="btn btn-rounded btn-back">
                                <i class="fas fa-chevron-left"></i>
                            </button>
                        </div>
                    </div>

                </div>

            </div>

            <a href="@Url.Action("IssueMat", "Manufacturing", new { key = Model.AcKey, type = ViewBag.ProdType })" class="btn btn-light btn-rounded text-primary btn-back">
                <i class="fas fa-chevron-left"></i>
            </a>
            <div class="cont-right m-r-n-sm">
                <button id="confirmButton" type="button" class="btn btn-success pull-right btn-rounded m-l-sm"  @(Model.Finished?"disabled":String.Empty) onclick="saveReceive(true)">
                    <i class="fas fa-check"></i> <span>@Loc.WOReceiving_ConfirmReceive</span>
                </button>

                <button id="options" type="button" class="btn pull-right btn-rounded">
                    <i class="fas fa-ellipsis-h"></i>
                </button>

            </div>
        </div>
    </div>

    <input type="hidden" id="receivingWarehouse" name="Warehouse" value="@ViewBag.Receiver" />

};

<div class="modal inmodal fade" id="imageModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body text-center">
                @Html.Image(ImageHelper.GetImageThumbnail(Model.Picture, 400), "", new { id = "image" })
                <i id="noImage" class='fal fa-image fa-3x text-muted hidden' style='opacity:0.5'></i>
            </div>
            <div class="modal-footer" style="text-align:center !important;">
                <button type="button" class="btn btn-primary  btn-rounded" data-dismiss="modal">@Loc.Close</button>
            </div>
        </div>
    </div>
</div>

<input type="hidden" id="receiveURL" value="@Url.Action("ConfirmReceive", "Manufacturing")" />
<input type="hidden" id="buttonText" value="@Loc.OK" />
<input type="hidden" id="succesText" value="@Loc.SuccessReceiveMsg" />
<input type="hidden" id="requiedQty" value="@Loc.RequiredInput @Loc.Produced" />
<input type="hidden" id="siteLocale" value="@Loc.CurrentLocalization.ToString()" />

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