<div class="row">
    <div class="container {if $lang_code == 'en'} gt4-ltr{/if}">
        <ol class="breadcrumb">
            <li><a href="#">{$smarty.const.EXPENSES_REVENUE}</a></li>
            <li><a href="#">{$smarty.const.EXPENSES}</a></li>
            <li class="active">{$smarty.const.EXPENSES_SHOW}</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
         <!--    <div class="panel-heading" style="padding:5px 15px 5px">
                <h3 class="panel-title" style="display: inline-block;"> </h3>
                <h3 class="panel-title" id="gexpensestypename" style="display: none;"></h3>
                <a href="{$youtubes[99]->url}" target="_blank" class="hidden-print"><img src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube" style="width: 2%;"></a>
                <a href="expensesController.php" class="hidden-print"><input type="button" style="margin-left: 12px" id="submit"  class="btn btn-primary pull-left " value=""/></a>
            </div> -->

              <div class="panel-heading" style="padding:5px 15px 15px">
                <h3 class="panel-title" style="display: inline-block;"> {$smarty.const.EXPENSES_SHOW}   </h3>
                <a href="{$youtubes[198]->url}" target="_blank" class="hidden-print"><img src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube" style="width: 2%;"></a>
                <a href="expensesController.php" class="hidden-print"><input type="button"  id="submit" style="margin-left: 12px" class="btn btn-primary pull-left " value="إضافة جديد"/></a>
            </div>

            <div class="panel-body">

                <!---------- start outputString alert ----------->
                <div id="outputString" class="alert alert-block alert-success fade in" style="display:none">
                    <button type="button" class="close pull-left" data-dismiss="alert" aria-hidden="true">&times;</button>
                    <p id="outputStringValue">{$outputString}</p>
                    <div class="clearfix"></div>
                </div>
                <!---------  end outputString alert ------------>

                <form class="form-inline hidden-print" method="post" action="expensesController.php?do=show">
                    <div class="form-group">
                        <label class="sr-only">{$smarty.const.EXPENSES_TYPE_NAME}</label>
                        <select data-placeholder="{$smarty.const.EXPENSES_CHOOSE_TYPE}"  class="select2 wdt100"  name="expensestypeid" id="expensestypeid" >
                            <option value="-1">{$smarty.const.EXPENSES_CHOOSE_TYPE}</option>


                            {foreach $alldata as $type}

                            <option value="{$type->expensestypeid}">{$type->expensestypename}</option>

                            {/foreach}

                        </select>
                    </div>
                    <div class="form-group"  {if $Programsettingdata->costcenter neq 0 && $Programsettingdata->realestatedev neq 0} style="display:none" {/if}>
                        <label class="sr-only">{$smarty.const.EXPENSES_COST_CENTER}</label>
                        <select class="select2 wdt100" name="Costcenterid" id="Costcenterid" >
                            <option value="-1" >{$smarty.const.EXPENSES_CHOOSE_COST_CENTER}</option>
                            {foreach $allCostcenter as $myallCostcenter}
                            <option value="{$myallCostcenter->id}" {if $myallCostcenter->id eq $projectid}selected=""{/if}>{$myallCostcenter->name}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group"   {if $Programsettingdata->expensesproduct eq 0} {else} style="display:none" {/if}>
                        <label class="sr-only">{$smarty.const.EXPENSES_PRODUCTS}</label>
                        <input type="hidden" name="searchvalue" id="searchvalue" value="{$Programsettingdata->searchvalue}"/>
                        <input type="text" name="productid" id="productid"    class="select2product wdt100 clas_offerproduct" data-itr='1'  data-placeholder="{$smarty.const.EXPENSES_CHOOSE_PRODUCT}" tabindex="301"/>
                    </div>

                    <br />
                    <div class="form-group">
                        <label class="sr-only">{$smarty.const.EXPENSES_FROM_DATE}</label>
                        <input type="text" class="form-control awdatepicker" autocomplete="off"   data-date-format="yyyy-mm-dd" name="from" >
                    </div>
                    <div class="form-group">
                        <label class="sr-only">{$smarty.const.EXPENSES_TO_DATE}</label>
                        <input type="text" class="form-control awdatepicker" autocomplete="off"   data-date-format="yyyy-mm-dd" name="to" >
                    </div>
                    <button type="submit" class="btn btn-primary hidden-print">{$smarty.const.EXPENSES_SEARCH}</button>
                </form>
                <div class="panel panel-default">
                    <!-- Default panel contents -->
                    <div class="panel-heading">{$message}</div>
                    <div class="panel-body">
                        <!--div class="col-lg-offset-8 col-lg-4 ">
                            <div class="well well-sm">
                                <h4 class="text-center">إجمالي المصروفات:  {$sum}</h4>
                            </div>
                        </div-->
                        {literal}

                        <form id="form1" name="form1" method="post" action="expensesController.php?do=executeOperation" onsubmit="if (Spry.Widget.Form.validate(this)) {
                                    return countChoosenProducts('expensesController');
                                } else {
                                    return false;
                                }
                              " enctype="multipart/form-data">
                            {/literal}
                            <!-- Table -->
                            <table class="table table-black">
                                <thead>
                                    <tr>
                                        <th class="hidden-print">
                                            <label>
                                                <input type="checkbox" name="checkAll" id="checkAll"/>
                                            </label>
                                        </th>
                                        <th>{$smarty.const.EXPENSES_DATE}</th>
                                        <th>{$smarty.const.EXPENSES_SAVEN}</th>
                                        <th>{$smarty.const.EXPENSES_NAME}</th>
                                        <th class="expensestypename " >{$smarty.const.EXPENSES_TYPE}</th>
                                        {if $Programsettingdata->expensesupplier eq 1}
                                        <th>المورد</th>
                                        <th>المتبقى على المورد</th>
                                        {/if}

                                        {if $Programsettingdata->clientsell eq 1}
                                        <th>العميل</th>
                                        {/if}


                                        {if $Programsettingdata->realestateunits eq 1}
                                        <th>العقار</th>
                                        <th>الوحده</th>
                                        {/if}


                                        {if $Programsettingdata->expensesproduct eq 0}
                                        <th>{$smarty.const.EXPENSES_PRODUCTS}</th>
                                        {/if}
                                        {if $Programsettingdata->costcenter eq 0}
                                        <th>{$smarty.const.EXPENSES_COST_CENTER}</th>
                                        {/if}

                                        <th>{$smarty.const.EXPENSES_AMOUNT}</th>
                                        <th>القيمة المضافة</th>
                                        {if $Programsettingdata->specialexpenses eq 0}
                                        <th>{$smarty.const.EXPENSES_NUMBER}</th>
                                        <th>{$smarty.const.EXPENSES_PRICE}</th>
                                        <th>{$smarty.const.EXPENSES_TOTALN}</th>
                                        <th>{$smarty.const.EXPENSES_SHORTFALLS}</th>
                                        {/if}
                                        <th>{$smarty.const.EXPENSES_COMMENT}</th>
                                        <th class="hidden-print">{$smarty.const.EXPENSES_TEMPORARY_DELETE}/{$smarty.const.EXPENSES_UNDELETE}</th>
                                        <th class="hidden-print">{$smarty.const.EDIT}</th>
                                        <th class="hidden-print">{$smarty.const.EXPENSES_DELETE}</th>
                                        <th class="hidden-print">قيد اليومية</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {assign var=sumUser value=0}
                                    {foreach $expenseData as $data}
                                    {if !$usergroupid|in_array:$data->addOnlyGroupIds}
                                    {if {$data->conditions} eq 1}
                                    <tr class="danger"> {elseif {$data->conditions} eq 0}

                                    <tr> {/if}
                                        <td class="hidden-print">
                                            <label>
                                                <input type="checkbox" name="choosedItem[]" id="checked{$i}" class="choosenItem" value="{$data->expensesid}" />
                                                <input type="hidden" value="{$data->expensesid}" name="expensestype"/>
                                            </label>
                                        </td>

                                        <td>{$data->expensesdate}</td>
                                        <td>{$data->savename}</td>
                                        <td>{$data->expensesname} </td>

                                        <td class="expensestypename ">{$data->expensestypename}</td>

                                        {if $Programsettingdata->expensesupplier eq 1}
                                        <td>{$data->supplier}</td>
                                        <td>{$data->suppRemainingVal}</td>
                                        {/if}

                                        {if $Programsettingdata->clientsell eq 1}
                                        <td>{$data->clientid}</td>
                                        {/if}
                                        {if $Programsettingdata->realestateunits eq 1}
                                        <td>{$data->realestatename}</td>
                                        <td>{$data->unitdata}</td>
                                        {/if}


                                        {if $Programsettingdata->expensesproduct eq 0}
                                        <td>{$data->productName}</td>
                                        {/if}
                                        {if $Programsettingdata->costcenter eq 0}
                                        <td>{$data->name}</td>
                                        {/if}

                                        <td>{$data->expensesValue}{assign var=sumUser value=$sumUser+$data->expensesValue}</td>
                                        <td>{$data->taxVal}</td>

                                        {if $Programsettingdata->specialexpenses eq 0}
                                        <td>{$data->expensenumbrt} </td>
                                        <td>{$data->expenseprice} </td>
                                        <td>{$data->expensetotaln} </td>
                                        <td>{$data->expenseshortfalls} </td>
                                        {/if}
                                        <td>{if {$data->expensesdetails} <> ""}
                                            {$data->expensesdetails}
                                            {else } {$smarty.const.EXPENSES_NO_COMMENT}
                                            {/if} </td>
                                        <td  class="hidden-print"> {if {$data->conditions} eq 0} <a href="expensesController.php?do=tempdelete&id={$data->expensesid}" type="button" class="btn btn-default btn-lg removeicon"> </a> {elseif {$data->conditions} eq 1 } <a  href="expensesController.php?do=returndelete&id={$data->expensesid}" type="button" class="btn btn-default btn-lg correcticon"> </a> </td>
                                        {/if}
                                        <td  class="hidden-print"> <a href="expensesController.php?do=edit&id={$data->expensesid}"  type="button" class="btn btn-default btn-lg editicon"></a></td>
                                        <td class="hidden-print" ><!--<a onclick="getValue({$data->expensesid})" name="dd" > حذف </a>-->
                                            <a href="#"  name="dd" id="delbtn" data-id="{$data->expensesid}" data-entryId="{$data->dailyentryid}"  type="button" class="btn btn-default btn-lg deleteicon"> </a> </td>
                                        <td class="hidden-print"><a href="dailyentry.php?id={$data->dailyentryid}" target="_blank" type="button" class="btn btn-default btn-lg editicon"> </a></td>
                                    </tr>
                                    {/if}
                                    {/foreach}

                                </tbody>

                            </table>
                            <div class="clearfix hidden-print"></div>
                            <hr />
                            <div  class="">
                                <div class="col-lg-12 hidden-print">
                                    <div class="well well-sm">
                                        <div class="form-group " >
                                            <div class="col-lg-4 hidden-print">
                                                <label for="operation"></label>
                                                <span id="spryselect1">
                                                    <select name="operation" id="operation"  data-placeholder="{$smarty.const.EXPENSES_CHOOSE_PROCESS}"  class="select2 wdt100">
                                                        <option value="-1"></option>
                                                        <option value="1">{$smarty.const.EXPENSES_TEMPORARY_DELETE}</option>
                                                        <option value="2">{$smarty.const.EXPENSES_UNDELETE}</option>
                                                        <option value="3">{$smarty.const.EXPENSES_PERMANENT_DELETE}</option>
                                                    </select>
                                                    <span class="selectInvalidMsg">{$smarty.const.EXPENSES_CHOOSE_PROCESS}</span></span></div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-4">
                                                <input name=""  class="hidden-print btn btn-primary" type="submit" value="{$smarty.const.EXPENSES_EXECUTION}"/>
                                            </div>
                                        </div>

                                        <!-----------  start noElementsError alert ------------->
                                        <div class="clearfix"></div>
                                        <div id="noElementsError" class="alert alert-danger fade in" style="display:none;">
                                            <button type="button" class="close pull-left" data-dismiss="alert" aria-hidden="true">×</button>
                                            <p>{$smarty.const.EXPENSES_SELECTED_FIRST}</p>
                                            <div class="clearfix"></div>
                                        </div>
                                        <!----------  end noElementsError alert -------------->

                                        <div class="clearfix"></div>
                                    </div>
                                </div>
                                <!--div class="col-lg-offset-8 col-lg-4 ">
                                    <div class="well well-sm">
                                        <h4 class="text-center">إجمالي المصروفات:  {$sum}</h4>
                                    </div>
                                </div-->
                                <div class="col-lg-offset-8 col-lg-4 ">
                                    <div class="well well-sm">
                                        <h4 class="text-center">{$smarty.const.EXPENSES_TOTAL}:  {$sumUser}</h4>
                                    </div>
                                </div>

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


                        <!-- Modal -->
                        <div class="modal fade hidden-print" id="myModal155" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close pull-left savemodel2" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    </div>
                                    <div class="modal-body">
                                        <h4 class="modal-title">{$smarty.const.EXPENSES_WANT_DELETE}</h4>

                                        <form id="expDel" action="expensesController.php?do=delete&id={$data->expensesid}&dailyentryid={$data->dailyentryid}" method="post" class="form-horizontal">
                                        </form>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" id="ddbtn" class="btn btn-default" > {$smarty.const.EXPENSES_DELETE}</button>

                                        <button type="button" class="btn btn-default" data-dismiss="modal">{$smarty.const.EXPENSES_CLOSE} </button>
                                    </div>
                                </div>
                                <!-- /.modal-content -->
                            </div>
                            <!-- /.modal-dialog -->
                        </div>

                        <div class="clearfix"></div>
                        <hr />
                        <div  class="hidden-print">
                            <div class="col-lg-12">
                                <div class="form-group">
                                    <div class="col-lg-4">
                                        <button type="button" onclick="print_Custom('mycustomheader');" class="btn btn-success pull-right">{$smarty.const.EXPENSES_PRINT}</button>
                                    </div>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {literal}
        <script type="text/javascript">
            var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {invalidValue: "-1", isRequired: false});
        </script>
        <script type="text/javascript">

            $(document).ready(function () {

                $("#expensestypeid").live('change', function () {
                    var expensestypeid = $(this).val();
                    if (expensestypeid > 0) {
                        var expensestypename = $('#expensestypeid').find('option:selected').text();
                        $("#gexpensestypename").show();
                        $("#gexpensestypename").text(expensestypename);
                        $(".expensestypename").addClass('hidden-print');
                    } else {
                        $("#gexpensestypename").show();
                        $("#gexpensestypename").text('');
                        $(".expensestypename").removeClass('hidden-print');
                    }
                });

                $(".positiveNo").forcepositiveNum();
                var formatResult;
                formatResult = function (data) {

                    return  data.text;
                }
                $("#productid").select2({
                    placeholder: "إسم المنتج",
                    width: '100%',
                    minimumInputLength: document.getElementById("searchvalue").value,
                    multiple: false,
                    quietMillis: 100,
                    ajax: {
                        url: "sellbillAjaxController.php?do=getProductsexpenses",
                        dataType: 'json',
                        data: function (term, page) {
                            return {
                                term: term, //search term
                                page_limit: 10,

                            };
                        },
                        results: function (data) {
                            return {results: data};
                        }
                    },
                    formatResult: formatResult,
                    initSelection: function (element, callback) {
                        var item = element.val().split(':');
                        var data = {id: item[0], text: item[1]};
                        callback(data);
                    }
                });

            });
        </script>
        {/literal}