@using PantheonRA.WebApi.Contracts.Enums
@using PantheonRA.BackOffice.Models
@using PantheonRA.BackOffice;

@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">
                @if (CurrentUser.CanAccess(Permissions.PRODUCTION))
                {
                    <div class="row buttons-tabbed">

                        @Html.Partial("_FormButtons", new FormButtonsViewModel
                        {
                            BackUrl = Url.Action("IssueMat", "Manufacturing", new { @key = Model.AcKey, type = ViewBag.ProdType }),
                            ConfirmButtonGroup = new FormButtonGroup
                            {
                                Buttons = new List<FormButton>
                                        {
                                            new FormButton {
                                                Text = Loc.Confirm,
                                                Icon = "fa fa-dolly",
                                                OnClick = "saveReceive();",
                                                CustomAttr = Model.Finished?"disabled":String.Empty
                                            }
                                        }
                            }

                        })

                    </div>}
                @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="row document-head">

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

                    <div class="col-lg-2 col-sm-3 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" id="IdentFilterSearch" value="@Model.Ident" />
                        </div>
                    </div>
                    <div class="col-lg-2 col-sm-3 col-xs-6">
                        <div class="form-group">
                            <label class="control-label m-t-xs">@Loc.Warehouse</label>
                            <select id="receivingWarehouse" name="Warehouse" class="form-control custom-select">
                                @foreach (var item in ViewBag.Warehouses)
                                {
                                    <option value="@item.Id" @(ViewBag.Receiver == item.Id ? "selected" : string.Empty)>
                                        @item.Name
                                    </option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="col-lg-2 col-sm-3 col-xs-6 dateFilter">
                        <div class="form-group">
                            <label class="control-label">@Loc.Date</label>
                            <div class="input-group">
                                <span class="input-group-addon"><i class="far fa-calendar alt"></i></span>
                                <input class="form-control datepicker" id="Date" name="Date" type="text" value="@DateTime.Now.Date.ToString(Loc.DateFormat)">
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-2 col-sm-3 col-xs-6">
                        <div class="form-group">
                            <label class="control-label">@Loc.Finished</label>
                            <div class="form-group input-group" style="margin:auto">
                                <input type="checkbox" class="js-switch timeRecordsSwitch" id="receiveFinished" readonly="@Model.Finished" checked="@Model.Finished" />
                            </div>
                        </div>
                    </div>
                </div>

                <div class="divided-content" style="overflow: auto">
                    <div class="divided-content-main divided-content-full">
                        <div class="form-horizontal">
                            <div class="card-receiving col-lg-12 col-sm-12 col-md-12 col-xs-12">
                                <div class="row text-center" style="margin:20px 0px">
                                    <div class="col-xs-12 col-md-12 col-lg-3">
                                        @Html.Image(ImageHelper.GetImageThumbnail(Model.Picture, 250), "alt", new { id = "image", height = "100" })
                                    </div>
                                    <div class="col-xs-12 col-md-3 col-lg-2 margin-top-10">
                                        <label class="input-group-lg">@Loc.Produced</label>
                                        <div class="row">
                                            <button type="button" id="b_dfinished" class="btn btn-link"><i class="fa fa-minus fa-lg" id="dfinished"></i></button>
                                            <input type="text" id="finished" name="ProducedQty" required class="text-center numberInput input-lg" autocomplete="off" style="width:8rem" value="0" />
                                            <button type="button" id="b_ifinished" class="btn btn-link"><i class="fa fa-plus fa-lg" id="ifinished"></i></button>
                                        </div>
                                        <div class="row margin-top-10">
                                            <a id="_finished" onclick="addRest(this)" href="#">@Loc.WOReceiving_AddRest (@Decimal.Round(Model.RestQty, Model.WoExDecPlacesProd)) </a>
                                        </div>
                                    </div>
                                    <div class="col-xs-12 col-md-3 col-lg-2 margin-top-10" style="@((ViewBag.ProdType == ProductionType.MF)?"display:block":"display:none")">
                                        <label class="input-group-lg">@Loc.WOScrap</label>
                                        <div class="row">
                                            <button type="button" id="b_dscrap" class="btn btn-link"><i class="fa fa-minus fa-lg" id="dscrap"></i></button>
                                            <input type="text" id="scrap" name="ScrapQty" required class="text-center numberInput input-lg" autocomplete="off" style="width:8rem" value="0" />
                                            <button type="button" id="b_iscrap" class="btn btn-link"><i class="fa fa-plus fa-lg" id="iscrap"></i></button>
                                        </div>
                                        <div class="row margin-top-10">
                                            <a id="_scrap" onclick="addRest(this)" href="#">@Loc.WOReceiving_AddRest (@Decimal.Round(Model.RestScrapQty, Model.WoExDecPlacesProd))</a>
                                        </div>
                                    </div>
                                    <div class="col-xs-12 col-md-3 col-lg-2 margin-top-10">
                                        <label class="input-group-lg">@((ViewBag.ProdType == ProductionType.MF)?Loc.WOWaste:Loc.Shrinkage)</label>
                                        <div class="row">
                                            <button type="button" id="b_dwaste" class="btn btn-link"><i class="fa fa-minus fa-lg" id="dwaste"></i></button>
                                            <input type="text" id="waste" name="WasteQty" required class="text-center numberInput input-lg" autocomplete="off" style="width:8rem" value="0" />
                                            <button type="button" id="b_iwaste" class="btn btn-link"><i class="fa fa-plus fa-lg" id="iwaste"></i></button>
                                        </div>
                                        <div class="row margin-top-10">
                                            <a id="_waste" onclick="addRest(this)" href="#">@Loc.WOReceiving_AddRest (@Decimal.Round(Model.RestWasteQty, Model.WoExDecPlacesProd))</a>
                                        </div>
                                    </div>
                                    <div class="col-xs-12 col-md-3 col-lg-2 margin-top-10" style="@((ViewBag.ProdType == ProductionType.MF)?"display:block":"display:none")">
                                        <label class="input-group-lg">@Loc.WORepair</label>
                                        <div class="row">
                                            <button type="button" id="b_drepair" class="btn btn-link"><i class="fa fa-minus fa-lg" id="drepair"></i></button>
                                            <input type="text" id="repair" name="RepairQty" required class="text-center numberInput input-lg" autocomplete="off" style="width:8rem" value="0" />
                                            <button type="button" id="b_irepair" class="btn btn-link"><i class="fa fa-plus fa-lg" id="irepair"></i></button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </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" />

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