<style>
    @media (min-width: 768px){
        .form-horizontal .form-group {
            margin-right: -10px;
            margin-left:-10px;
        }

        .m10{
            margin: 10px
        }
        h4{
            font-size: 17px;
            font-weight: bold;
            color: #000000;
            margin: 10px 0 15px;
            font-family: sans-serif;
        }
        hr {
            margin: 20px ;
            border: 0;
            border-top: 2px solid #d7d7d7;

        }
        .card{
            box-shadow: 0 4px 16px rgba(0,0,0,.12);
            padding: 10px;
            margin: 40px 0;
            border-radius: 5px
        }

    }
    .wdt230{
        width:230px
    }
    .billtable thead>tr>th {
        color: #eeecda;
        background-color: #0081a8;
    }
    .add i{
        font-size: 20px;
        color: #607D8B;
    }
    .wdt50{
        width:50px
    }
    .mt-10{
        margin-top: 10px
    }
    .data-search{
        margin: 10px 15px 0;
    }
    .btn-dark {
        color: #fff;
        background-color: #636262;
        border-color: #646464;
    }
    .data-search .form-control{
        border-radius:3px
    }

</style>




<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">تصنيع </a></li>
            <li><a href="#">أمر إنتاج</a></li>
            <li class="active">تعديل</li>
        </ol>

        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">تعديل أمر إنتاج</h3>
            </div>

            <div class="panel-body">

                <input type="hidden" name="lowOutPriceAlert" id="lowOutPriceAlert" value="{$ManufacuresettingData->lowOutPriceAlert}"/>
                <form action="productionExecutionController.php?do=update" method="post" id="form1">
                    <input type="hidden" name="searchvalue" id="searchvalue" value="{$Programsettingdata->searchvalue}"/>
                    <input type="hidden" name="executionId" id="executionId" value="{$productionExecutionData->id}" />

                    <div class="data-search">
                        <div class="row">
                            <div class="col-lg-4">
                                <div class="form-group">
                                    <label>عنوان</label>
                                    <input name="title" id="title" value="{$productionExecutionData->title}" type="text" class="form-control" required/>
                                </div>
                            </div>
                            <div class="col-lg-2">
                                <div class="form-group">
                                    <label>رقم أمر انتاج</label>
                                    <input type="text" name="proOrderId" id="proOrderId" required value="{$productionExecutionData->orderId}" data-val="{$productionExecutionData->id}" data-editId="{$productionExecutionData->id}" class="form-control" placeholder="">
                                </div>
                            </div>
                            <div class="col-lg-3">
                                <div class="form-group">
                                    <label class="">تاريخ </label>
                                    <input type="text" class="form-control awdatepicker" autocomplete="off" id="orderdate" value="{$productionExecutionData->orderdate}" data-date-format="yyyy-mm-dd" name="orderdate" required>
                                </div>
                            </div>
                            <div class="col-lg-2">
                                <div class="form-group">
                                    <label>{if $ManufacuresettingData->taskOrderName == 1}طلبية{else}أمر شغل{/if}</label>
                                    <select class=" select2" id="orderId" name="orderId">
                                        <option value="-1">اختر {if $ManufacuresettingData->taskOrderName == 1}طلبية{else}أمر شغل{/if}</option>
                                        {foreach $allTaskOrders as $order}
                                        {if $order->conditions neq 1}
                                        <option value="{$order->id}" data-proId="{$order->productId}" data-proName="{$order->productName}/{$order->proCatName}" data-num="{$order->num}" {if $order->id eq $productionExecutionData->taskid}selected{/if}>{$order->title}</option>
                                        {/if}
                                        {/foreach}
                                    </select>
                                </div>
                            </div>

                            <div class="col-lg-4">
                                <div class="form-group">
                                    <label> المنتج النهائى</label>
                                    <input type="hidden" class="getFinalProductsWithOutProductionEquation wdt300" name="finalProductId" id="finalProductId" data-placeholder=" اختر منتج"  />
                                    <input id="oldfinalproduct" name="oldfinalproduct" type="hidden" value="{$oldfinalproduct}" />
                                    <input id="oldfinalproductname" class="form-control" name="oldfinalproductname" type="hidden" disabled value="{$oldfinalproductname}" />
                                </div>
                            </div>

                            <div class="col-lg-1">
                                <div class="form-group">
                                    <label>العدد</label>
                                    <input type="text" name="proNum" value="{$productionExecutionData->num}" class="form-control positivefloat" id="proNum" placeholder="">
                                </div>
                            </div>

                            <div class="col-lg-2" style="margin-right: 96px;">
                                <div class="form-group">
                                    <label>التعليق</label>
                                    <textarea type="text" name="comment" class="form-control" placeholder="Enter text here...">{$productionExecutionData->comment}</textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="SCProEqDiv">

                    </div>
                    <!-- المكونات -->
                    <div class="card">
                        <div class="col-lg-6">
                            <h4>المكونات</h4>
                        </div>

                        <div class="table-responsive">
                            <table class="table billtable table-bordered table-black " id="table">
                                <thead>
                                    <tr>
                                        <th class="wdt400">المنتجات الخام</th>
                                        <th class="wdt120 ">وحدة القياس</th>
                                        <th class="wdt120"> الكمية المتوقعة</th>
                                        <th  class="wdt120">الكمية الفعلية</th>
                                        <th  class="wdt120" > التكلفة المتوقعة</th>
                                        <th class="wdt120">التكلفة الفعلية</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {assign var="totalQuantity" value="0"}
                                    {assign var="totalCost" value="0"}
                                    {assign var="actualtotalQuantity" value="0"}
                                    {assign var="actualtotalCost" value="0"}

                                    {foreach $productionExecutionProductsData as $pro}



                                    {if $allowedit == 0}
                                    <tr>
                                        <td>
                                            <input type="hidden" readonly name="pro{$pro@iteration}" value="{$pro->productid}"/>
                                            {$pro->productName}
                                        </td>
                                        <td>
                                            <input type="hidden" readonly name="unit{$pro@iteration}" value="{$pro->unitid}"/>
                                            {$pro->unitName}
                                        </td>
                                        <td>
                                            <span id="quantity{$pro@iteration}">{$pro->quantity}</span>
                                            <input type="hidden" class="quantity" name="quantity{$pro@iteration}" id="quantityVal{$pro@iteration}" data-val="{$pro->quantity/$productionExecutionData->num}" value="{$pro->quantity}"/>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control actual positivefloat" id="actual{$pro@iteration}" name="actual{$pro@iteration}" data-val="{$pro->quantity}" value="{$pro->actualquantity}"/>
                                        </td>
                                        <td>
                                            <span id="costSpan{$pro@iteration}">{$pro->cost}</span>
                                            <input type="hidden" class="cost" id="cost{$pro@iteration}" name="cost{$pro@iteration}" data-val="{$pro->productBuyPrice}" value="{$pro->cost}"/>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control actualCost positivefloat" id="actualCost{$pro@iteration}" name="actualCost{$pro@iteration}" value="{$pro->actualcost}"/>
                                        </td>
                                    </tr>

                                    {elseif $allowedit == 1}

                                    <tr>
                                        <td>
                                            <input type="hidden" name="pro{$pro@iteration}" id="pro{$pro@iteration}"/>
                                            <input type="hidden" id="oldproId{$pro@iteration}" value="{$pro->productid}"/>
                                            <input type="hidden" id="oldproName{$pro@iteration}" value="{$pro->productName}"/>
                                        </td>
                                        <td>
                                            <div id="unitDiv{$pro@iteration}">
                                                <input type="hidden" readonly name="unit{$pro@iteration}" id="unit{$pro@iteration}"/>
                                            </div>

                                            <input type="hidden" id="oldunitId{$pro@iteration}" value="{$pro->unitid}"/>
                                            <input type="hidden" id="oldunitName{$pro@iteration}" value="{$pro->unitName}"/>
                                        </td>
                                        <td>
                                            <input type="number" step="any" class="quantity" name="quantity{$pro@iteration}" id="quantityVal{$pro@iteration}" data-val="{$pro->quantity/$productionExecutionData->num}" value="{$pro->quantity}"/>
                                        </td>
                                        <td>
                                            <input type="number" step="any" class="form-control actual" id="actual{$pro@iteration}" name="actual{$pro@iteration}" data-val="{$pro->quantity}" value="{$pro->actualquantity}"/>
                                        </td>
                                        <td>
                                            <input type="number" step="any" class="cost" id="cost{$pro@iteration}" name="cost{$pro@iteration}" data-val="{$pro->productBuyPrice}" value="{$pro->cost}"/>
                                        </td>
                                        <td>
                                            <input type="number" step="any" class="form-control actualCost" id="actualCost{$pro@iteration}" name="actualCost{$pro@iteration}" value="{$pro->actualcost}"/>
                                        </td>
                                    </tr>


                                    {/if}




                                    {assign var="totalQuantity" value=$totalQuantity+$pro->quantity}
                                    {assign var="totalCost" value=$totalCost+($pro->cost)}
                                    {assign var="actualtotalQuantity" value=$actualtotalQuantity+$pro->actualquantity}
                                    {assign var="actualtotalCost" value=$actualtotalCost+($pro->actualcost)}
                                    {/foreach}
                                    <tr>
                                        <th colspan="2" style="color: #eeecda; background-color: #0081a8;"><span style="font: bold;">الإجمالي</span></th>
                                        <th><span id="totalQuantitySpan">{$totalQuantity}</span></th>
                                        <th><span id="totalActualQuantity">{$actualtotalQuantity}</span></th>
                                        <th id="totCost">{$totalCost}</th>
                                        <th>
                                            <span id="actualTotalCost">{$actualtotalCost}</span>
                                            <input type="hidden" id="actlTotalCost" name="actlTotalCost" value="{$actualtotalCost}"/>
                                        </th>
                                    </tr>
                                <input type="hidden" name="rowitr" id="rowitr" value="{count($productionExecutionProductsData)}"/>
                                </tbody>
                            </table>
                        </div>

                    </div>
                    <!-- end of title row-->
                    <div class="row">
                        <div class="col-lg-4">
                            <div class="form-group">
                                <label class="col-lg-5">تكلفة أجور للقطعة</label>
                                <div class="col-lg-7">
                                    <input type="text" min="0" name="rentCost" id="rentCost" class="form-control countCost positivefloat" value="{$productionExecutionData->rentcost}" placeholder="">
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4">
                            <div class="form-group">
                                <label class="col-lg-5 pull">تكاليف أخرى للقطعة</label>
                                <div class="col-lg-7">
                                    <input type="text" name="otherCost" id="otherCost" value="{$productionExecutionData->othercost}" class="form-control countCost positivefloat" placeholder="">
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- المخرجات -->
                    <div class="card">
                        <div class="col-lg-6">
                            <h4>المخرجات</h4>
                        </div>
                        <div class="col-lg-3 ">
                            <div class="form-group mt-10">
                                <label class="col-lg-3"> المخزن</label>
                                <div class="col-lg-9">
                                    <select class=" select2" id="storeMain" name="storeMain">
                                        <option value="-1">اختر المخزن</option>
                                        {foreach $allStore as $store}
                                        <option value="{$store->storeId}" {if $store->storeId eq $productionExecutionData->outstoreid}selected{/if}>{$store->storeName}</option>
                                        {/foreach}
                                    </select>
                                </div>

                            </div>
                        </div>
                        <!--                        <div class="col-lg-3">
                                                    <button type="button" name="addOutPro" id="addOutPro" class="btn btn-primary pull-left ft-nor mt-10 addOutPro"> <i class="glyphicon glyphicon-plus"></i>
                                                        اضافة جديد</button>
                                                </div>-->
                        <input type="hidden" name="outItr" id="outItr" value="{if count($productionExecutionOutputData)>1}{count($productionExecutionOutputData)}{else}1{/if}"/>
                        <input type="hidden" id="countItr" name="countItr" value="{count($productionExecutionOutputData)}"/>
                        <div class="table-responsive">
                            <table class="table billtable table-bordered table-black " id="outTable">
                                <thead>
                                    <tr>
                                        <th class="wdt400">المنتجات </th>
                                        <th class="wdt230 ">
                                            اسعار البيع
                                            <br/>
                                            الجملة -  نصف الجملة - تجزئة
                                        </th>
                                        <th class="wdt120">  العدد</th>
                                        <th class="wdt200"> تكلفةالمواد الخام للوحدة</th>
                                        <th class="wdt200"> التكلفة الكلية للوحدة</th>
                                        <th  class="wdt300" >  المخزن</th>
                                        <th class="wdt50"></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {if empty($productionExecutionOutputData)}
                                    <tr>
                                        <td >
                                            <input type="hidden" id="product1" name="product1"  class="select2product wdt100"  data-placeholder="اختر منتج"  tabindex="7" />
                                        </td>
                                        <td >
                                            <input type="text" style="width:60px;margin:3px;float:right" name="allPrice1" id="allPrice1"  class="form-control checkPrice" value="" />
                                            <input type="text" style="width:60px;margin:3px;float:right" name="halfPrice1" id="halfPrice1"  class="form-control checkPrice" value="" />
                                            <input type="text" style="width:60px;margin:3px;float:right" name="unitPrice1" id="unitPrice1"  class="form-control checkPrice" value="" />
                                        </td>
                                        <td >
                                            <input type="text" name="amount1" id="amount1" min="0" class="form-control outAmount positivefloat" value="" />
                                        </td>

                                        <td><span id="outCost1"></span></td>
                                        <td><span id="outTotalCost1"></span></td>
                                        <td >
                                            <select class="select2 outStore" id="outStore1" name="outStore1">
                                                <option value="-1">اختر المخزن</option>
                                                {foreach $allStore as $store}
                                                <option value="{$store->storeId}">{$store->storeName}</option>
                                                {/foreach}
                                            </select>
                                        </td>
                                        <td class="noprint"><a href="javascript:;" type="button" class="btn add addOutPro" id="addOutPro1"><i class="glyphicon glyphicon-plus-sign"></i></a></td>
                                    </tr>
                                    {else}
                                    {foreach $productionExecutionOutputData as $output}
                                    <tr>
                                        <td >
                                            <input type="hidden" id="product{$output@iteration}" name="product{$output@iteration}"  class="select2product wdt100 outputSelect"  data-placeholder="اختر منتج"  tabindex="7" />
                                            <input id="productOut{$output@iteration}" name="oldfinalproduct" type="hidden" value="{$output->productid}" />
                                            <input id="productnameOut{$output@iteration}" class="form-control" name="oldfinalproductname" type="hidden" disabled value="{$output->productName}" />
                                        </td>
                                        <td >
                                            <input type="text" style="width:60px;margin:3px;float:right" name="allPrice{$output@iteration}" id="allPrice{$output@iteration}"  class="form-control checkPrice" value="{$output->allprice}" />
                                            <input type="text" style="width:60px;margin:3px;float:right" name="halfPrice{$output@iteration}" id="halfPrice{$output@iteration}"  class="form-control checkPrice" value="{$output->halfprice}" />
                                            <input type="text" style="width:60px;margin:3px;float:right" name="unitPrice{$output@iteration}" id="unitPrice{$output@iteration}"  class="form-control checkPrice" value="{$output->unitprice}" />
                                        </td>
                                        <td >
                                            <input type="text" name="amount{$output@iteration}" id="amount{$output@iteration}" min="0" class="form-control outAmount positivefloat" value="{$output->num}" />
                                        </td>

                                        <td><span id="outCost{$output@iteration}">{$output->cost|round:"2"}</span></td>
                                        <td><span id="outTotalCost{$output@iteration}">{($output->cost + $productionExecutionData->rentcost + $productionExecutionData->othercost)|round:"2"}</span></td>
                                        <td >
                                            <select class="select2 outStore" id="outStore{$output@iteration}" name="outStore{$output@iteration}">
                                                <option value="-1">اختر المخزن</option>
                                                {foreach $allStore as $store}
                                                <option value="{$store->storeId}" {if $store->storeId eq $output->storeid}selected{/if}>{$store->storeName}</option>
                                                {/foreach}
                                            </select>
                                        </td>
                                        <td class="noprint">
                                            {if $output@iteration eq count($productionExecutionOutputData)}
                                            <a href="javascript:;" type="button" class="btn add addOutPro" id="addOutPro{$output@iteration}"><i class="glyphicon glyphicon-plus-sign"></i></a>
                                            {else}
                                            <button id="remove{$output@iteration}" type="button" data-del="out" class="close flt-none removeicon removeproduct" aria-hidden="true">&times;</button>
                                            {/if}
                                        </td>
                                    </tr>
                                    {/foreach}
                                    {/if}
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- end of title row-->


                    <!-- الهادر -->
                    <div class="card">
                        <div class="col-lg-6">
                            <h4>الهادر</h4>
                        </div>
                        <div class="col-lg-3 ">
                            <div class="form-group mt-10">
                                <label class="col-lg-3"> المخزن</label>
                                <div class="col-lg-9">
                                    <select class=" select2" id="storeWasteMain" name="storeWasteMain">
                                        <option value="-1">اختر المخزن</option>
                                        {foreach $allStore as $store}
                                        <option value="{$store->storeId}" {if $store->storeId eq $productionExecutionData->wastestoreid}selected{/if}>{$store->storeName}</option>
                                        {/foreach}
                                    </select>
                                </div>

                            </div>
                        </div>
                        <!--                        <div class="col-lg-3">
                                                    <button type="button" name="addWastePro" id="addWastePro" class="btn btn-primary pull-left ft-nor mt-10 addWastePro"> <i class="glyphicon glyphicon-plus"></i>
                                                        اضافة جديد</button>
                                                </div>-->
                        <input type="hidden" name="wasteItr" id="wasteItr" value="{if count($productionExecutionWasteData) >1}{count($productionExecutionWasteData)}{else}1{/if}"/>

                        <div class="table-responsive">
                            <table class="table billtable table-bordered table-black " id="wasteTable">
                                <thead>
                                    <tr>
                                        <th class="wdt400">المنتجات </th>
                                        <th class="wdt230 ">
                                            اسعار البيع
                                            <br/>
                                            الجملة -  نصف الجملة - تجزئة
                                        </th>
                                        <th class="wdt120">  العدد</th>
                                        <th  class="wdt400" >  المخزن</th>
                                        <th class="wdt50"></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {if empty($productionExecutionWasteData)}
                                    <tr>
                                        <td >
                                            <input type="hidden" id="wasteproduct1" name="wasteproduct1"  class="select2product wdt100 wasteproduct"  data-placeholder="اختر منتج"  tabindex="7" />
                                        </td>
                                        <td >
                                            <input type="text" style="width:60px;margin:3px;float:right" name="wasteAllPrice1" id="wasteAllPrice1"  class="form-control " value="" />
                                            <input type="text" style="width:60px;margin:3px;float:right" name="wasteHalfPrice1" id="wasteHalfPrice1"  class="form-control " value="" />
                                            <input type="text" style="width:60px;margin:3px;float:right" name="wasteUnitPrice1" id="wasteUnitPrice1"  class="form-control " value="" />

                                        </td>

                                        <td>
                                            <input type="text" name="wasteAmount1" id="wasteAmount1" min="0" class="form-control positivefloat" value="" />
                                        </td>
                                        <td >
                                            <select class="wasteStore select2" id="wasteStore1" name="wasteStore1">
                                                <option value="-1">اختر المخزن</option>
                                                {foreach $allStore as $store}
                                                <option value="{$store->storeId}">{$store->storeName}</option>
                                                {/foreach}
                                            </select>
                                        </td>
                                        <td class="noprint"><a href="javascript:;" type="button" class="btn add addWastePro" id="addWastePro1"><i class="glyphicon glyphicon-plus-sign"></i></a></td>
                                    </tr>
                                    {else}
                                    {foreach $productionExecutionWasteData as $waste}
                                    <tr>
                                        <td >
                                            <input type="hidden" id="wasteproduct{$waste@iteration}" name="wasteproduct{$waste@iteration}"  class="select2product wdt100 wasteproduct"  data-placeholder="اختر منتج"  tabindex="7" />
                                            <input id="productWaste{$waste@iteration}" name="oldfinalproductwaste{$waste@iteration}" type="hidden" value="{$waste->productid}" />
                                            <input id="productnametWaste{$waste@iteration}" class="form-control" name="oldfinalproductnamewaste{$waste@iteration}" type="hidden" disabled value="{$waste->productName}" />
                                        </td>
                                        <td >
                                            <input type="text" style="width:60px;margin:3px;float:right" name="wasteAllPrice{$waste@iteration}" id="wasteAllPrice{$waste@iteration}"  class="form-control " value="{$waste->allprice}" />
                                            <input type="text" style="width:60px;margin:3px;float:right" name="wasteHalfPrice{$waste@iteration}" id="wasteHalfPrice{$waste@iteration}"  class="form-control " value="{$waste->halfprice}" />
                                            <input type="text" style="width:60px;margin:3px;float:right" name="wasteUnitPrice{$waste@iteration}" id="wasteUnitPrice{$waste@iteration}"  class="form-control " value="{$waste->unitprice}" />

                                        </td>

                                        <td>
                                            <input type="text" name="wasteAmount{$waste@iteration}" id="wasteAmount{$waste@iteration}" min="0" class="form-control positivefloat" value="{$waste->num}" />
                                        </td>
                                        <td >
                                            <select class="wasteStore select2" id="wasteStore{$waste@iteration}" name="wasteStore{$waste@iteration}">
                                                <option value="-1">اختر المخزن</option>
                                                {foreach $allStore as $store}
                                                <option value="{$store->storeId}" {if $store->storeId eq $waste->storeid}selected{/if}>{$store->storeName}</option>
                                                {/foreach}
                                            </select>
                                        </td>
                                        <td class="noprint">
                                            {if $waste@iteration eq count($productionExecutionWasteData)}
                                            <a href="javascript:;" type="button" class="btn add addWastePro" id="addWastePro{$waste@iteration}"><i class="glyphicon glyphicon-plus-sign"></i></a>
                                            {else}
                                            <button id="remove{$waste@iteration}" type="button" class="close flt-none removeicon removeproduct" aria-hidden="true">&times;</button>
                                            {/if}
                                        </td>
                                    </tr>
                                    {/foreach}
                                    {/if}
                                </tbody>
                            </table>
                        </div>

                    </div>
                    <!-- end of title row-->

                    <div class="row">

                        <div class="col-lg-12">
                            <button type="button" class="btn btn-dark pull-left ft-nor">
                                تكلفة أمر الانتاج <span class="badge wht-clo">
                                    <div id='allCost'>{$productionExecutionData->executioncost}</div>
                                </span>
                            </button>
                        </div>
                    </div>



                    <div class="clearfix"></div>
                    <hr/>

                    <div class="row" align="center">
                        {if $productionExecutionData->executed neq 1}  <button type="submit"  id="editBtn" class="btn btn-primary"><i class="glyphicon glyphicon-ok "></i>  حفظ</button>
                        {if $ManufacuresettingData->reducestoreamount && $ManufacuresettingData->reducestoreamount eq 1} <button type="submit"  id="executeEdit" class="btn btn-success"><i class="glyphicon glyphicon-send "></i>  حفظ وتنفيذ </button>{/if}
                        {else} <button type="submit"  id="executeEdit" class="btn btn-success"><i class="glyphicon glyphicon-send "></i>  تعديل</button> {/if}

                    </div>
                </form>


            </div> <!-- end of panel-body-->

        </div>  <!-- end of panel panel-default-->

    </div> <!-- end of container-->

</div>  <!-- end of row-->