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

@model PantheonRA.WebApi.Contracts.PaWoExRegOper

@{
    ViewBag.Title = Loc.WOEditOperation;

    PaWoExItemResources WoExItemResurce = Model.WoExItem != null ? Model.WoExItem.WoExItemResources.FirstOrDefault(x => x.ResursID.Trim() == Model.ResursID.Trim()) : null;
    int resourceQID = WoExItemResurce.QId;
    double Tn = WoExItemResurce != null ? WoExItemResurce.Qty1 : 0;
    double Tpf = WoExItemResurce != null ? WoExItemResurce.Qty2 : 0;
    double PlanQty = (Model.WoExItem != null) && (WoExItemResurce != null) ? (double)Model.WoExItem.WoEx.PlanQty * WoExItemResurce.ExecutionPerc / 100 : 0;
    double PlanTime = (Model.WoExItem != null) && (WoExItemResurce != null) ? (double)Model.WoExItem.WoEx.PlanQty * WoExItemResurce.Qty1 * WoExItemResurce.ExecutionPerc / 100 : 0;
    double DoneQty = (Model.WoExItem != null) && (Model.WoExItem.WoExItemWork != null) ? (double)Model.WoExItem.WoExItemWork.Where(x => x.ResursID.Trim() == Model.ResursID.Trim()).Sum(p => p.Qty) : 0;
    double DoneTime = (Model.WoExItem != null) && (Model.WoExItem.WoExItemWork != null) ? (double)Model.WoExItem.WoExItemWork.Where(x => x.ResursID.Trim() == Model.ResursID.Trim()).Sum(p => p.Time) : 0;

    TimeSpan _planTime = TimeSpan.FromHours(PlanTime);
    var PlanTimeStr = Math.Floor(_planTime.TotalHours).ToString("00") + ":" + _planTime.Minutes.ToString("00");

    TimeSpan _doneTime = TimeSpan.FromHours(DoneTime);
    var DoneTimeStr = Math.Floor(_doneTime.TotalHours).ToString("00") + ":" + _doneTime.Minutes.ToString("00");

    string ProductUM = Model.WoExItem != null ? Model.WoExItem.WoEx.UM : String.Empty;
    string timeUM = Model.WoExItem != null ? Model.WoExItem.UM : String.Empty;

    Model.EventTypeCaption = String.Empty;

    if (Model.EventType == WorkRegEventType.OperationStart) { Model.EventTypeCaption = Loc.OperationStart; }
    if (Model.EventType == WorkRegEventType.OperationPause) { Model.EventTypeCaption = Loc.OperationPause; }
    if (Model.EventType == WorkRegEventType.OperationContinue) { Model.EventTypeCaption = Loc.OperationContinue; }
    if (Model.EventType == WorkRegEventType.OperationEnd) { Model.EventTypeCaption = Loc.OperationEnd; }

}


<div class="tabs-container">
    @Html.Partial("~/Views/Shared/_TabNavigation.cshtml", new TabNavigationViewModel
        {
            Tabs = new List<NavigationtabViewModel> {
                new NavigationtabViewModel(Loc.WorkOrderList, Url.Action("Index", "Manufacturing", new { type = ViewBag.ProdType }),
                    Html.IsActive("Index", "Manufacturing"),
                    !PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.PRODUCTION)),

                new NavigationtabViewModel(Loc.WOProcessing_IssueMat, Url.Action("IssueMat", "Manufacturing", new { key = Model.AcKey, type = ViewBag.ProdType }),
                    Html.IsActive("IssueMat", "Manufacturing")||Html.IsActive("EditMat", "Manufacturing"),
                    !PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.PRODUCTION)),

                new NavigationtabViewModel(Loc.WOProcessing_CompletedWork, Url.Action("CompletWork", "Manufacturing", new { key = Model.AcKey, type = ViewBag.ProdType }),
                    Html.IsActive("CompletWork", "Manufacturing"),
                    !PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.PRODUCTION)),

                new NavigationtabViewModel(Loc.WorkRegistration, null, Html.IsActive("WorkReg", "Manufacturing"),
                    !PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.PRODUCTION))
            }
        })

    @Html.HiddenFor(model => model.AcKey)
    @Html.HiddenFor(model => model.AnNo)
    @Html.HiddenFor(model => model.Ident)
    @Html.HiddenFor(model => model.UM)
    @Html.HiddenFor(model => model.EventType)
    @Html.HiddenFor(model => model.EventTypeCaption)
    @Html.HiddenFor(model => model.EventTime)
    @Html.HiddenFor(model => model.Descr)
    @Html.HiddenFor(model => model.UM)
    @Html.HiddenFor(model => model.ResursID)
    @Html.HiddenFor(model => model.Worker)
    @Html.HiddenFor(model => model.ParentWorker)
    @Html.HiddenFor(model => model.Priority)
    @Html.HiddenFor(model => model.CalendarQId)
    @Html.HiddenFor(model => model.Shift)
    @Html.HiddenFor(model => model.QId)
    @Html.HiddenFor(model => model.WoExItem.QId)
    @Html.HiddenFor(model => model.WoExItem.WoEx.PlanQty)

    <div class="tab-content">
        <div class="row buttons-tabbed">

            @Html.Partial("_FormButtons", new FormButtonsViewModel
           {
               BackUrl = Url.Action("CompletWork", "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 = "confirmOperationWork();"
                                    }
                       }
               }
           })

        </div>


        <div class="row document-head" style="margin-bottom:-2px !important;">
            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-4 document-head-disabled-input">
                <div class="form-group">
                    @Html.LabelFor(model => model.ResursID, Loc.WOResource, new { @class = "control-label m-t-xs" })
                    @Html.TextBoxFor(model => model.ResursID, new { @id = "resursId", @class = "form-control", @readonly = "readonly", @placeholder = Loc.WOResource })
                </div>
            </div>
            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-4 document-head-disabled-input">
                <div class="form-group">
                    @Html.LabelFor(model => model.Ident, Loc.Operation, new { @class = "control-label m-t-xs" })
                    @Html.TextBoxFor(model => model.Ident, new { @id = "ident", @class = "form-control", @readonly = "readonly", @placeholder = Loc.Operation })
                </div>
            </div>
            <div class="col-md-2 col-sm-2 col-xs-4 document-head-disabled-input">
                <div class="form-group">
                    @Html.LabelFor(model => model.AnNo, Loc.Position, new { @class = "control-label m-t-xs" })
                    @Html.TextBoxFor(model => model.AnNo, new { @id = "no", @class = "form-control", @readonly = "readonly", @placeholder = Loc.Position })
                </div>
            </div>
            <div class="col-md-2 col-sm-2 col-xs-6 document-head-disabled-input">
                <div class="form-group">
                    @Html.LabelFor(model => model.AcKey, Loc.Number, new { @class = "control-label m-t-xs" })
                    <input class="form-control text-center" id="acKeyDisplay" disabled="disabled" type="text" value=" @Model.KeyView">
                </div>
            </div>
            <div class="col-md-2 col-sm-2 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>
                        @Html.TextBoxFor(model => model.Date, new { @id = "Date", @class = "form-control datepicker", @type = "text", @Value = @DateTime.Now.Date.ToString(Loc.DateFormat) })
                    </div>
                </div>
            </div>
        </div>

        @Html.Partial("_WorkRegistrationButtons", Model)


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

                        <div class="col-lg-10 col-md-12 col-xs-12">
                            <div class="form-horizontal form-md" style="margin: 0px 15px">
                                <div class="form-group">
                                    <div class="top-row-margin-bottom">
                                        <div class="col-xs-12 mb-8">
                                            <label class="input-group-lg">@Loc.OperationStart</label>
                                            <div id="beginTime">
                                                <input type="text"
                                                       id="BeginTime"
                                                       name="BeginTime"
                                                       required
                                                       style="width:215px;margin-left:10px"
                                                       class="custom-datetimepicker expense-dt-picker input-lg"
                                                       placeholder="@Loc.DateAndTime"
                                                       value="@ViewBag.BeginTime"
                                                       autocomplete="off" />

                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="border-bottom top-row-margin-bottom">
                                        <div class="col-xs-12  m-t mb-8">
                                            <label class="input-group-lg">@Loc.UsedTime</label>
                                            <div id="usedTime" class="row">
                                                <button id="b_dUsedTime" class="btn btn-link"><i class="fa fa-minus fa-lg"></i></button>
                                                <input type="text" id="UsedTime" required class="text-center numberInput input-lg" autocomplete="off" value="@Model.UsedTime.ToString("N")" placeholder="0" style="width:15rem" />
                                                <button id="b_iUsedTime" class="btn btn-link"><i class="fa fa-plus fa-lg"></i></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="border-bottom top-row-margin-bottom">
                                        <div class="col-xs-12 m-t mb-8">
                                            <label class="input-group-lg">@(ViewBag.ProdType == ProductionType.SE? Loc.UsedQty : Loc.WOOperationGoodPcs)</label>
                                            <div id="goodPcs" class="row">
                                                <button id="b_dGoodPcs" class="btn btn-link"><i class="fa fa-minus fa-lg"></i></button>
                                                <input type="text" id="GoodPcs" required class="text-center numberInput input-lg" autocomplete="off" value="0" placeholder="0" style="width:15rem" />
                                                <button id="b_iGoodPcs" class="btn btn-link"><i class="fa fa-plus fa-lg"></i></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group @(ViewBag.ProdType == ProductionType.SE?"hidden":String.Empty)">
                                    <div class="border-bottom top-row-margin-bottom">
                                        <div class="col-xs-12 m-t mb-8">
                                            <label class="input-group-lg">@Loc.WOOperationRepairPcs</label>
                                            <div id="repairPcs" class="row">
                                                <button id="b_dRepairQty" class="btn btn-link"><i class="fa fa-minus fa-lg"></i></button>
                                                <input type="text" id="RepairQty" required class="text-center numberInput input-lg" autocomplete="off" value="0" placeholder="0" style="width:15rem" />
                                                <button id="b_iRepairQty" class="btn btn-link"><i class="fa fa-plus fa-lg"></i></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group @(ViewBag.ProdType == ProductionType.SE?"hidden":String.Empty)">
                                    <div class="border-bottom top-row-margin-bottom">
                                        <div class="col-xs-12 m-t mb-8">
                                            <label class="input-group-lg">@Loc.WOOperationScrapPcs</label>
                                            <div id="scrapPcs" class="row">
                                                <button id="b_dScrapPcs" class="btn btn-link"><i class="fa fa-minus fa-lg"></i></button>
                                                <input type="text" id="ScrapPcs" required class="text-center numberInput input-lg" autocomplete="off" value="0" placeholder="0" style="width:15rem" />
                                                <button id="b_iScrapPcs" class="btn btn-link"><i class="fa fa-plus fa-lg"></i></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group @(ViewBag.ProdType == ProductionType.MF?"hidden":String.Empty)">
                                    <div class="border-bottom top-row-margin-bottom">
                                        <div class="col-xs-12 m-t mb-8">
                                            <label class="input-group-lg">@Loc.Shrinkage</label>
                                            <div id="wastePcs" class="row">
                                                <button id="b_dWastePcs" class="btn btn-link"><i class="fa fa-minus fa-lg"></i></button>
                                                <input type="text" id="WastePcs" required class="text-center numberInput input-lg" autocomplete="off" value="0" placeholder="0" style="width:15rem" />
                                                <button id="b_iWastePcs" class="btn btn-link"><i class="fa fa-plus fa-lg"></i></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="border-bottom top-row-margin-bottom">
                                        <div class="col-xs-12 m-t mb-8">
                                            <label class="input-group-lg">@Loc.Note</label>
                                            <div id="note" class="row">
                                                <button type="button" id="note-button" class="btn btn-link" onclick="openNoteModal1(this)"><i class="fas fa-comment"></i></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row hidden-xs">
                        <div class="col-lg-10 col-md-12 col-xs-12">
                            <div class="project-list">
                                <h4 class="panel-title text-primary m-b-sm">
                                    @Loc.WorkHistory
                                </h4>
                                <table id="woExRegOperExp" data-grid-id="WoExRegOperExp" data-url="@Url.Action("WoExItemWork", "Manufacturing")" class="table">
                                    <thead>
                                        <tr>
                                            <th style="width: 20%">@Loc.Worker</th>
                                            <th style="width: 10%">@Loc.StartDate</th>
                                            <th>@Loc.Note</th>
                                            <th class="dt-center" style="width: 10%">@Loc.Duration</th>
                                            <th class="dt-right" style="width: 10%">@Loc.WOOperationGoodPcs</th>
                                            <th class="dt-right" style="width: 10%">@Loc.WOOperationRepairPcs</th>
                                            <th class="dt-right" style="width: 10%">@Loc.WOOperationScrapPcs</th>
                                            <th class="dt-right" style="width: 10%">@Loc.WOOperationTsu</th>
                                            <th class="dt-right" style="width: 10%">@Loc.WOOperationTpr</th>
                                            <th class="dt-center" style="width: 10%">@Loc.Status</th>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                        </div>

                    </div>


                </div>


            </div>
        </div>

    </div>

    <div class="row document-footer">
        <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 document-head-disabled-input hidden-xs" title="@Loc.Total">
            <div class="form-group">
                <label>@Loc.IssuedQty / @Loc.Planned</label><br />
                <span class="timerecords-footer-left-span">@DoneQty.ToString("n0")/@PlanQty.ToString("n0") @ProductUM</span>
            </div>
        </div>
        <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 document-head-disabled-input hidden-xs">
            <div class="form-group">
                <label>@Loc.UsedTime / @Loc.Planned</label><br />
                <span class="timerecords-footer-left-span">@DoneTimeStr/@PlanTimeStr @timeUM</span>
            </div>
        </div>
        <div class="col-md-2 col-sm-3 col-xs-12 document-head-disabled-input" title="@Loc.Worker">
            <div class="form-group">
                <label>@Loc.Worker</label><br />
                <span class="timerecords-footer-left-span">@Model.Worker</span>
            </div>
        </div>
        <div class="col-md-2 col-sm-12 col-xs-6">
            <div class="form-group">
                <label class="control-label">@Loc.WOReceiving_ConfirmReceive</label>
                <div class="hw-switch-m-l m-t-3">
                    <input type="checkbox" class="js-switch timeRecordsSwitch" id="confirmReceive" onchange="setCreateReceivings();" />
                </div>
            </div>
        </div>
        <div class="col-md-2 col-sm-12 col-xs-6">
            <div class="form-group">
                <label class="control-label">@Loc.FinishTask</label>
                <div class="hw-switch-m-l m-t-3">
                    <input type="checkbox" class="js-switch timeRecordsSwitch" id="finishOperation" onchange="setFinishedOperation();" />
                </div>
            </div>
        </div>
    </div>

</div>

<div class="modal inmodal fade" id="note-modal" tabindex="-1" role="dialog" aria-hidden="true" data-new-row="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="pn-modal-title">@Loc.Note</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <textarea class="form-control" id="Note" name="Note" rows="3" maxlength="500"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" id="modalSave" class="btn btn-primary" data-dismiss="modal">@Loc.Save</button>
                <button type="button" id="modalClose" class="btn btn-primary" data-dismiss="modal">@Loc.Close</button>
            </div>
        </div>
    </div>
</div>


<input type="hidden" id="confirmOperWork" value="@Url.Action("ConfirmOperWork", "Manufacturing")" />
<input type="hidden" id="confirmOperation" value="@Url.Action("ConfirmOper", "Manufacturing")" />
<input type="hidden" id="backURL" value="" />
<input type="hidden" id="resourceQId" value="@resourceQID" />
<input type="hidden" id="activeEventType" value="@Model.EventType" />
<input type="hidden" id="buttonText" value="@Loc.OK" />
<input type="hidden" id="succesText" value="@Loc.SuccessWorkMsg" />
<input type="hidden" id="requiedQty" value="@Loc.RequiredInput @Loc.UsedTime" />
<input type="hidden" id="requiedWorker" value="@Loc.RequiredInput @Loc.Worker" />
<input type="hidden" id="WoExDecPlacesOper" value="@ViewBag.WoExDecPlacesOper" />
<input type="hidden" id="confirmed" value="@Loc.StatusConfirmed" />
<input type="hidden" id="unconfirmed" value="@Loc.StatusUnconfirmed" />
<input type="hidden" id="buttonYes" value="@Loc.Yes" />
<input type="hidden" id="buttonNo" value="@Loc.No" />
<input type="hidden" id="prodType" value="@ViewBag.ProdType" />
<input type="hidden" id="questionText" value="@Loc.FinishOperationTracking"/>
<input type="hidden" id="notEmployeeText" value="@Loc.EmployeeWorkTracking" />

@section pageScripts{

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

}
