<style type="text/css">
    th{
        text-align: center;
    }
    td{
        text-align: center;
        
    }
</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">
            <!-- Default panel contents -->
            <div class="panel-heading">تقرير مراكز التكلفه</div>
            <div class="panel-body">

                <!---------- start outputString alert ----------->
                <div id="outputString" class="alert alert-block alert-success fade in hidden-print" 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 method="post" class="form-inline" action="costcenterReportController.php?do=search" enctype="multipart/form-data">
                    <div class="form-group">

                        <label class="sr-only">مركز التكلفة</label>
                        <select class="select2 wdt300"   name="costCenterId"  data-placeholder="اختر مركز التكلفة " required>
                            <!-- <option value="-1">اختر مركز التكلفة</option> -->

                            <option value=""></option>
                            {foreach $allCostCenter as $costcenter}


                            <option value="{$costcenter->id}">{$costcenter->name}</option>


                            {/foreach}


                        </select>

                    </div>
                    <div id="dateOnlyDiv">
                        <div class="form-group">
                            <label class="sr-only">من التاريخ</label>
                            <input type="text" class="form-control awdatepicker" autocomplete="off" data-date-format="yyyy-mm-dd" name="start_date">
                        </div>
                        <div class="form-group">
                            <label class="sr-only">إلى التاريخ</label>
                            <input type="text" class="form-control awdatepicker" autocomplete="off" data-date-format="yyyy-mm-dd" name="end_date">
                        </div>
                        <div class="input-group">
                            <label> <input name="detail" type="checkbox" value="1">
                                مفصل</label>
                            
                        </div>
                    </div>
                    <button type="submit" class="btn btn-primary">بحث</button>
                </form>
                {if !empty($allDetails) && $details != 1}
                <table class="table table-black">
                    <thead>
                        <tr>
                            <th>العملية</th>
                            <th>نوع العملية</th>
                            <th>القيمة</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach $allDetails as $detail}
                        <tr>
                            <td>
                                {if $detail->type eq 0}
                                <a class="color-white" href="{$hosturl}/erp2016/controllers/{$detail->tablename}?do=showDetail&sellbillid={$detail->modelid}" target="_new">
                                    {$detail->processname}
                                </a>
                                {elseif $detail->type eq 1}
                                <a class="color-white" href="{$hosturl}/erp2016/controllers/{$detail->tablename}?do=showDetail&returnsellbillid={$detail->modelid}" target="_new">
                                    {$detail->processname}
                                </a>
                                {elseif $detail->type eq 2}
                                <a class="color-white" href="{$hosturl}/erp2016/controllers/{$detail->tablename}?do={if $detail->type eq 0}showDetail&sellbillid={$detail->modelid}{elseif $detail->type eq 1}showDetail&returnsellbillid={$detail->modelid}{elseif $detail->type eq 2}showDetail&sellbillid={$detail->modelid}{elseif $detail->type eq 3}details&id={$detail->modelid}{elseif $detail->type eq 4}details&id={$detail->modelid}{elseif $detail->type eq 5}details&id={$detail->modelid}{elseif $detail->type eq 6}edit&id={$detail->modelid}{elseif $detail->type eq 7}edit&id={$detail->modelid}{elseif $detail->type eq 8}#{elseif $detail->type eq 9}#{elseif $detail->type eq 10}#{elseif $detail->type eq 11}#{/if}" target="_new">
                                    {$detail->processname}
                                </a>

                                <a class="color-white" href="{$hosturl}/erp2016/controllers/{$detail->tablename}?do=showDetail&sellbillid={$detail->modelid}" target="_new">
                                    {$detail->processname}
                                </a>
                                {elseif $detail->type eq 3}
                                <a class="color-white" href="{$hosturl}/erp2016/controllers/{$detail->tablename}?do=details&id={$detail->modelid}" target="_new">
                                    {$detail->processname}
                                </a>
                                {elseif $detail->type eq 4}
                                <a class="color-white" href="{$hosturl}/erp2016/controllers/{$detail->tablename}?do=details&id={$detail->modelid}" target="_new">
                                    {$detail->processname}
                                </a>
                                {elseif $detail->type eq 5}
                                <a class="color-white" href="{$hosturl}/erp2016/controllers/{$detail->tablename}?do=details&id={$detail->modelid}" target="_new">
                                    {$detail->processname}
                                </a>
                                {elseif $detail->type eq 6}
                                <a class="color-white" href="{$hosturl}/erp2016/controllers/{$detail->tablename}?do=edit&id={$detail->modelid}" target="_new">
                                    {$detail->processname}
                                </a>
                                {elseif $detail->type eq 7}
                                <a class="color-white" href="{$hosturl}/erp2016/controllers/{$detail->tablename}?do=edit&id={$detail->modelid}" target="_new">
                                    {$detail->processname}
                                </a>
                                {else}
                                {$detail->processname}
                                {/if}
                            </td>
                            <td>
                                {if $detail->type eq 0}
                                فاتورة مبيعات
                                {elseif $detail->type eq 1}
                                فاتورة مردود مبيعات
                                {elseif $detail->type eq 2}
                                فاتورة مبيعات و مردودها
                                {elseif $detail->type eq 3}
                                فاتورة مشتريات
                                {elseif $detail->type eq 4}
                                فاتورة مردود مشتريات
                                {elseif $detail->type eq 5}
                                فاتورة مشتريات و مردودها
                                {elseif $detail->type eq 6}
                                مصروفات
                                {elseif $detail->type eq 7}
                                إيرادات
                                {elseif $detail->type eq 8}
                                مرتبات
                                {elseif $detail->type eq 9}
                                سحب لموظف
                                {elseif $detail->type eq 10}
                                سلفة موظف
                                {elseif $detail->type eq 11}
                                سداد سلفة مباشرة
                                {/if}
                            </td>
                            <td>{$detail->costamount}</td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
                {/if}




                {if !empty($allDetails) && $details == 1}
                <table class="table table-black">
                    <thead>
                        <tr >
                            <th>   إيرادات</th>
                            <th>مصروفات</th>                            
                        </tr>
                    </thead>
                    <tbody>
                         {assign var = Revenues  value = 0}
                          {assign var = Expenses  value = 0}
                        {foreach $allDetails as $detail}
                        <tr>
                            <td> 
                                {if $detail->type eq 0}
                                فاتورة مبيعات    : {$detail->costamount} 
                                 {assign  var = Revenues value = $Revenues + $detail->costamount }
                                {elseif $detail->type eq 4}
                                فاتورة مردود مشتريات      : {$detail->costamount} 
                                {assign  var = Revenues value = $Revenues + $detail->costamount }
                                 {elseif $detail->type eq 7}
                             إيرادات    : {$detail->costamount} 
                                {assign  var = Revenues value = $Revenues + $detail->costamount }
                                 {elseif $detail->type eq 2 && $detail->costamount >= 0 }
                                ف   فاتورة مبيعات و مردودها  : {$detail->costamount} 
                                {assign  var = Revenues value = $Revenues + $detail->costamount }
                                {elseif $detail->type eq 11}
                            سداد سلفة مباشرة : {$detail->costamount} 
                                {assign  var = Revenues value = $Revenues + $detail->costamount }
                                 {elseif $detail->type eq 5 && $detail->costamount > 0}
                                  فاتورة مشتريات و مردودها   : {$detail->costamount} 
                                {assign  var = Revenues value = $Revenues + $detail->costamount }
                                {else}
                                ***********************
                                {/if}
                            </td>
                            
                            <td>
                               {if $detail->type eq 1}
                                فاتورة مردود مبيعات    : {$detail->costamount} 
                             {assign  var = Expenses value = $Expenses + $detail->costamount }
                                {elseif $detail->type eq 3}
                                فاتورة مشتريات      : {$detail->costamount} 
                                {assign  var = Expenses value = $Expenses + $detail->costamount }
                                 {elseif $detail->type eq 6}
                                فمصروفات   : {$detail->costamount} 
                                {assign  var = Expenses value = $Expenses + $detail->costamount }
                                 {elseif $detail->type eq 5 && $detail->costamount < 0}
                                  فاتورة مشتريات و مردودها   : {$detail->costamount} 
                                {assign  var = Expenses value = $Expenses + $detail->costamount }

                                 {elseif $detail->type eq 8}
                                 مرتبات    : {$detail->costamount} 
                                {assign  var = Expenses value = $Expenses + $detail->costamount }
                                  {elseif $detail->type eq 9}
                                سحب لموظف    : {$detail->costamount} 
                                {assign  var = Expenses value = $Expenses + $detail->costamount }
                                {elseif $detail->type eq 10}
                               سلفة موظف   : {$detail->costamount} 
                                {assign  var = Expenses value = $Expenses + $detail->costamount }
                                {elseif $detail->type eq 2 && $detail->costamount >= 0 }
                                ف   فاتورة مبيعات و مردودها  : {$detail->costamount} 
                                {assign  var = Expenses value = $Expenses + $detail->costamount }


                                {else}
                                ***********************
                                {/if}
                            </td>
                        </tr>

                        {/foreach}
                        <tr >
                            <td style="font-size: 25px"> 
                              اجمالى الايرادات  :    {$Revenues}
                            </td>
                            
                            <td style="font-size: 25px">
                                اجمالى المصروفات:    {$Expenses}
                            </td>
                        </tr>
                        <tr style="text-align: center;">
                              <td style="font-size: 25px" colspan="2">     الصافى  : {$Revenues - $Expenses}  </td>
                        </tr>

                    </tbody>
                </table>
                {/if}


                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>
{literal}
<script type="text/javascript">
    var spryselect2 = new Spry.Widget.allCostCenter("spryselect2", {invalidValue: "-1", isRequired: false});
</script>
{/literal}