@extends('layouts.front')
@section('title', $supplier->name)
@section('content')

    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                تفاصيل - {{ $supplier->name }}
            </h1>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">

                <div class="col-xs-12">
                    <div class="box">
                        {{-- <div class="box-header">
                     <h3 class="box-title">Data Table With Full Features</h3>
                 </div> --}}
                        <!-- /.box-header -->
                        <div class="box-body">
                            <div class="row">
                                <div class="col-md-12">
                                    <table class="table table-bordered table-striped">
                                        <tr>
                                            <td>الأسم: {{ $supplier->name }}</td>
                                            <td>الجوال: {{ $supplier->mobile }}</td>
                                        </tr>
                                        <tr>
                                            <td>الهوية: {{ $supplier->id_number }}</td>
                                            <td>الرقم الضريبي: {{ $supplier->tax_number }}</td>
                                        </tr>

                                        <tr>
                                            <td>إجمالى الفواتير</td>
                                            <td>{{ number_format($supplier->total_orders) . ' ' . $settings['currency'] }}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>إجمالى المدفوع</td>
                                            <td>{{ number_format($supplier->total_collection) . ' ' . $settings['currency'] }}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>الحساب</td>
                                            <td>{{ number_format($supplier->total_remaining) . ' ' . $settings['currency'] }}
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                        <div class="text-center">

                        </div>
                    </div>
                    <!-- /.box -->
                </div>

                <div class="col-xs-12">
                    <div class="box box-primary">
                        <div class="box-header">
                            <h3 class="box-title">الفواتير</h3>
                        </div>
                        <div class="box-body">
                            <div class="row">
                                <div class="col-md-12">
                                    <table class="table table-bordered table-hover dataTableTT">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>التاريخ</th>
                                                <th>المستخدم</th>
                                                <th>طريقة الدفع</th>
                                                <th>الإجمالى</th>
                                                <th>المدفوع</th>
                                                <th>المتبقى</th>
                                                <th></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach ($supplier->invoices as $item)
                                                <tr>
                                                    <td>{{ $loop->iteration }}</td>
                                                    <td>{{ $item->post_date }}</td>
                                                    <td>{{ optional($item->creator)->name }}</td>
                                                    <td>{{ $item->payment }}</td>
                                                    <td>{{ number_format($item->total) }}</td>
                                                    <td>{{ number_format($item->total_paid) }}</td>
                                                    <td>{{ number_format($item->total_due) }}</td>
                                                    <td>
                                                        @if ($currentUser->can('Edit Purchases'))
                                                            <a title="تعديل" href="{{ route('purchases.edit', $item) }}"
                                                                class="btn btn-primary btn-xs">
                                                                <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>
                                                            </a>
                                                        @endif
                                                        @if ($item->total_due)
                                                            @if ($currentUser->can('addPayment Purchases'))
                                                                <a title="سند قبض" data-toggle="modal"
                                                                    data-target="#myModal"
                                                                    href="{{ route('purchases.addPayment', $item->id) }}"
                                                                    class="btn btn-success btn-xs">
                                                                    <i class="fa fa-money fa-fw" aria-hidden="true"></i>
                                                                </a>
                                                            @endif
                                                        @endif
                                                        @if ($currentUser->can('Delete Purchases'))
                                                            <a title="حذف" class="btn btn-xs btn-danger remove-record"
                                                                data-url="{{ route('purchases.destroy', $item) }}"
                                                                data-id="{{ $item->id }}">
                                                                <i class="fa fa-trash"></i>
                                                            </a>
                                                        @endif
                                                        @if ($currentUser->can('Show Purchases'))
                                                            <a title="التفاصيل" href="{{ route('purchases.show', $item) }}"
                                                                class="btn btn-warning btn-xs">
                                                                <i class="fa fa-pencil fa-eye" aria-hidden="true"></i>
                                                            </a>
                                                        @endif
                                                    </td>
                                                </tr>
                                            @endforeach
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-xs-12">
                    <div class="box box-warning">
                        <div class="box-header">
                            <h3 class="box-title">المدفوعات</h3>
                        </div>
                        <div class="box-body">
                            <div class="row">
                                <div class="col-md-12">
                                    <table class="table table-bordered">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>التاريخ</th>
                                                <th>البيان</th>
                                                <th>المبلغ</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach ($supplier->transactions as $trans)
                                                <tr>
                                                    <td>{{ $loop->iteration }}</td>
                                                    <td>{{ $trans->trans_date }}</td>
                                                    <td>{{ $trans->note }}</td>
                                                    <td>{{ number_format(abs($trans->value)) }}</td>
                                                </tr>
                                            @endforeach
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
    </div>
@endsection

@include('_partial.datatable')
