এই লেসনে Purchase Invoice add করা এবং Purchase Invoice এর জন্য Payment add করা দেখানো হয়েছে। এবং User এর Balance and Due দেখানো হয়েছে।
Routes:
// Routes for purchase
Route::get('users/{id}/purchases', 'UserPurchasesController@index')->name('user.purchases');
Route::post('users/{id}/purchases', 'UserPurchasesController@createInvoice')->name('user.purchases.store');
Route::get('users/{id}/purchases/{invoice_id}', 'UserPurchasesController@invoice')->name('user.purchases.invoice_details');
Route::delete('users/{id}/purchases/{invoice_id}', 'UserPurchasesController@destroy')->name('user.purchases.destroy');
Route::post('users/{id}/purchases/{invoice_id}', 'UserPurchasesController@addItem')->name('user.purchases.add_item');
Route::delete('users/{id}/purchases/{invoice_id}/{item_id}', 'UserPurchasesController@destroyItem')->name('user.purchases.delete_item');
Route::post('users/{id}/payments/{invoice_id?}', 'UserPaymentsController@store')->name('user.payments.store');
UserPurchasesController.php
namespace App\Http\Controllers;
use App\Http\Requests\InvoiceProductRequest;
use App\Http\Requests\InvoiceRequest;
use App\Product;
use App\PurchaseInvoice;
use App\PurchaseItem;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
class UserPurchasesController extends Controller
{
public function __construct()
{
$this->data['tab_menu'] = 'purchases';
}
/**
* Purchase list of a user
* @param User $id
*/
public function index( $id )
{
$this->data['user'] = User::findOrFail($id);
return view('users.purchases.purchases', $this->data);
}
/**
* Create new invoice for purchase
* @param InvoiceRequest $request
* @param User $user_id
*/
public function createInvoice(InvoiceRequest $request, $user_id)
{
$formData = $request->all();
$formData['user_id'] = $user_id;
$formData['admin_id'] = Auth::id();
$invoice = PurchaseInvoice::create($formData);
return redirect()->route( 'user.purchases.invoice_details', ['id' => $user_id, 'invoice_id' => $invoice->id] );
}
/**
* A single invoice
* @param User $user_id
* @param PurchaseInvoice $invoice_id
*/
public function invoice($user_id, $invoice_id)
{
$this->data['user'] = User::findOrFail($user_id);
$this->data['invoice'] = PurchaseInvoice::findOrFail($invoice_id);
$this->data['totalPayable'] = $this->data['invoice']->items()->sum('total');
$this->data['totalPaid'] = $this->data['invoice']->payments()->sum('amount');
$this->data['products'] = Product::arrayForSelect();
return view('users.purchases.invoice', $this->data);
}
/**
* Add item to purchase invoice
* @param InvoiceProductRequest $request
* @param User $user_id
* @param PurchaseInvoice $invoice_id
*/
public function addItem(InvoiceProductRequest $request, $user_id, $invoice_id)
{
$formData = $request->all();
$formData['purchase_invoice_id'] = $invoice_id;
if( PurchaseItem::create($formData) ) {
Session::flash('message', 'Item Added Successfully');
}
return redirect()->route( 'user.purchases.invoice_details', ['id' => $user_id, 'invoice_id' => $invoice_id] );
}
/**
* Delete a item form purchase invoice
* @param User $user_id
* @param PurchaseInvoice $invoice_id
* @param PurchaseItem $item_id
*/
public function destroyItem($user_id, $invoice_id, $item_id)
{
if( PurchaseItem::destroy( $item_id ) ) {
Session::flash('message', 'Item Deleted Successfully');
}
return redirect()->route( 'user.purchases.invoice_details', ['id' => $user_id, 'invoice_id' => $invoice_id] );
}
/**
* Delete a purchase invoice
* @param User $user_id
* @param PurchaseInvoice $invoice_id
*/
public function destroy($user_id, $invoice_id)
{
if( PurchaseInvoice::destroy($invoice_id) ) {
Session::flash('message', 'Invoice Deleted Successfully');
}
return redirect()->route( 'user.purchases', ['id' => $user_id] );
}
}
UserPaymentsController.php
namespace App\Http\Controllers;
use App\Http\Requests\PaymentRequest;
use App\Payment;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
class UserPaymentsController extends Controller
{
public function __construct()
{
$this->data['tab_menu'] = 'payments';
}
/**
* Show all payments of a users
* @param User $id
*/
public function index( $id )
{
$this->data['user'] = User::findOrFail($id);
return view('users.payments.payments', $this->data);
}
/**
* Add new Payment
* @param PaymentRequest $request
* @param int $user_id
*/
public function store(PaymentRequest $request, $user_id, $invoice_id = null)
{
$formData = $request->all();
$formData['user_id'] = $user_id;
$formData['admin_id'] = Auth::id();
if ($invoice_id) {
$formData['purchase_invoice_id'] = $invoice_id;
}
if( Payment::create($formData) ) {
Session::flash('message', 'Payment Added Successfully');
}
if ($invoice_id) {
return redirect()->route( 'user.purchases.invoice_details', ['id' => $user_id, 'invoice_id' => $invoice_id] );
} else {
return redirect()->route('users.show', ['user' => $user_id]);
}
}
/**
* Delete a payment
* @param int $user_id
* @param int $payment_id
*/
public function destroy($user_id, $payment_id)
{
if( Payment::destroy($payment_id) ) {
Session::flash('message', 'Payment Deleted Successfully');
}
return redirect()->route('user.payments', ['id' => $user_id]);
}
}
InvoiceRequest.php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class InvoiceRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'date' => 'required',
'challan_no' => 'nullable',
'note' => 'nullable'
];
}
}
app/Payment.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Payment extends Model
{
protected $fillable = ['date', 'amount', 'note', 'user_id', 'admin_id', 'purchase_invoice_id'];
public function admin()
{
return $this->belongsTo(Admin::class);
}
}
app/PurchaseInvoice.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class PurchaseInvoice extends Model
{
protected $fillable = ['date', 'challan_no', 'note', 'user_id', 'admin_id'];
public function user()
{
return $this->belongsTo(User::class);
}
public function admin()
{
return $this->belongsTo(Admin::class);
}
public function items()
{
return $this->hasMany(PurchaseItem::class);
}
public function payments()
{
return $this->hasMany(Payment::class);
}
}
app/PurchaseItem.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class PurchaseItem extends Model
{
protected $fillable = [ 'product_id', 'purchase_invoice_id', 'price', 'quantity', 'total' ];
public function invoice()
{
return $this->belongsTo(PurchaseInvoice::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
}
users/user_layout.blade.php
@extends('layout.main')
@section('main_content')
@yield('user_card')
<div class="row clearfix page_header">
<div class="col-md-4">
<a class="btn btn-info" href="{{ route('users.index') }}"> <i class="fa fa-arrow-left" aria-hidden="true"></i> Back </a>
</div>
<div class="col-md-8 text-right">
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#newSale">
<i class="fa fa-plus"></i> New Sale
</button>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#newPayment">
<i class="fa fa-plus"></i> New Payment
</button>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#newPurchase">
<i class="fa fa-plus"></i> New Purchase
</button>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#newReceipt">
<i class="fa fa-plus"></i> New Receipt
</button>
</div>
</div>
@include('users.user_layout_content')
{{-- Modal For add new payment --}}
<div class="modal fade" id="newPayment" tabindex="-1" role="dialog" aria-labelledby="newPaymentModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
{!! Form::open([ 'route' => ['user.payments.store', $user->id], 'method' => 'post' ]) !!}
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="newPaymentModalLabel"> New Payments </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group row">
<label for="date" class="col-sm-3 col-form-label"> Date <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::date('date', NULL, [ 'class'=>'form-control', 'id' => 'date', 'placeholder' => 'Date', 'required' ]) }}
</div>
</div>
<div class="form-group row">
<label for="amount" class="col-sm-3 col-form-label">Amount <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::text('amount', NULL, [ 'class'=>'form-control', 'id' => 'amount', 'placeholder' => 'Amount', 'required' ]) }}
</div>
</div>
<div class="form-group row">
<label for="note" class="col-sm-3 col-form-label">Note </label>
<div class="col-sm-9">
{{ Form::textarea('note', NULL, [ 'class'=>'form-control', 'id' => 'note', 'rows' => '3', 'placeholder' => 'Note' ]) }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
{{-- Modal For Receipt --}}
<div class="modal fade" id="newReceipt" tabindex="-1" role="dialog" aria-labelledby="newReceiptModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
{!! Form::open([ 'route' => ['user.receipts.store', $user->id], 'method' => 'post' ]) !!}
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="newReceiptModalLabel"> New Receipts </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group row">
<label for="date" class="col-sm-3 col-form-label"> Date <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::date('date', NULL, [ 'class'=>'form-control', 'id' => 'date', 'placeholder' => 'Date', 'required' ]) }}
</div>
</div>
<div class="form-group row">
<label for="amount" class="col-sm-3 col-form-label">Amount <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::text('amount', NULL, [ 'class'=>'form-control', 'id' => 'amount', 'placeholder' => 'Amount', 'required' ]) }}
</div>
</div>
<div class="form-group row">
<label for="note" class="col-sm-3 col-form-label">Note </label>
<div class="col-sm-9">
{{ Form::textarea('note', NULL, [ 'class'=>'form-control', 'id' => 'note', 'rows' => '3', 'placeholder' => 'Note' ]) }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
{{-- Modal For Sales --}}
<div class="modal fade" id="newSale" tabindex="-1" role="dialog" aria-labelledby="newSaleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
{!! Form::open([ 'route' => ['user.sales.store', $user->id], 'method' => 'post' ]) !!}
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="newSaleModalLabel"> New Sale Invoice </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group row">
<label for="date" class="col-sm-3 col-form-label"> Date <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::date('date', NULL, [ 'class'=>'form-control', 'id' => 'date', 'placeholder' => 'Date', 'required' ]) }}
</div>
</div>
<div class="form-group row">
<label for="challan_no" class="col-sm-3 col-form-label">Challan Number </label>
<div class="col-sm-9">
{{ Form::text('challan_no', NULL, [ 'class'=>'form-control', 'id' => 'challan_no', 'placeholder' => 'Challan Number' ]) }}
</div>
</div>
<div class="form-group row">
<label for="note" class="col-sm-3 col-form-label">Note </label>
<div class="col-sm-9">
{{ Form::textarea('note', NULL, [ 'class'=>'form-control', 'id' => 'note', 'rows' => '3', 'placeholder' => 'Note' ]) }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
{{-- Modal For Sales --}}
<div class="modal fade" id="newPurchase" tabindex="-1" role="dialog" aria-labelledby="newPurchaseModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
{!! Form::open([ 'route' => ['user.purchases.store', $user->id], 'method' => 'post' ]) !!}
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="newPurchaseModalLabel"> New Purchase Invoice </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group row">
<label for="date" class="col-sm-3 col-form-label"> Date <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::date('date', NULL, [ 'class'=>'form-control', 'id' => 'date', 'placeholder' => 'Date', 'required' ]) }}
</div>
</div>
<div class="form-group row">
<label for="challan_no" class="col-sm-3 col-form-label">Challan Number </label>
<div class="col-sm-9">
{{ Form::text('challan_no', NULL, [ 'class'=>'form-control', 'id' => 'challan_no', 'placeholder' => 'Challan Number' ]) }}
</div>
</div>
<div class="form-group row">
<label for="note" class="col-sm-3 col-form-label">Note </label>
<div class="col-sm-9">
{{ Form::textarea('note', NULL, [ 'class'=>'form-control', 'id' => 'note', 'rows' => '3', 'placeholder' => 'Note' ]) }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
@stop
users/purchases/purchases.blade.php
@extends('users.user_layout')
@section('user_content')
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary"> Purchases of <strong>{{ $user->name }} </strong></h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Challen No</th>
<th>Customer</th>
<th>Date</th>
<th>Items</th>
<th>Total</th>
<th class="text-right">Actions</th>
</tr>
</thead>
<tbody>
<?php
$totalItem = 0;
$grandTotal = 0;
?>
@foreach ($user->purchases as $purchase)
<tr>
<td> {{ $purchase->challan_no }} </td>
<td> {{ $user->name }} </td>
<td> {{ $purchase->date }} </td>
<td>
<?php
$itemQty = $purchase->items()->sum('quantity');
$totalItem += $itemQty;
echo $itemQty;
?>
</td>
<td>
<?php
$total = $purchase->items()->sum('total');
$grandTotal += $total;
echo $total;
?>
</td>
<td class="text-right">
<form method="POST" action=" {{ route('user.purchases.destroy', ['id' => $user->id, 'invoice_id' => $purchase->id ]) }} ">
<a class="btn btn-primary btn-sm" href="{{ route('user.purchases.invoice_details', ['id' => $user->id, 'invoice_id' => $purchase->id]) }}">
<i class="fa fa-eye"></i>
</a>
@if($itemQty == 0)
@csrf
@method('DELETE')
<button onclick="return confirm('Are you sure?')" type="submit" class="btn btn-danger btn-sm">
<i class="fa fa-trash"></i>
</button>
@endif
</form>
</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th>Challen No</th>
<th>Customer</th>
<th>Date</th>
<th> {{ $totalItem }} </th>
<th> {{ $grandTotal }} </th>
<th class="text-right">Actions</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
@stop
users/purchases/invoice.blade.php
@extends('users.invoice_layout')
@section('user_content')
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary"> Purchase Invoice Details </h6>
</div>
<div class="card-body">
<div class="row clearfix justify-content-md-center">
<div class="col-md-6">
<div class="no_padding no_margin"> <strong>Supplier:</strong> {{ $user->name }}</div>
<div class="no_padding no_margin"><strong>Email:</strong> {{ $user->email }}</div>
<div class="no_padding no_margin"><strong>Phone:</strong> {{ $user->phone }}</div>
</div>
<div class="col-md-3"></div>
<div class="col-md-3">
<div class="no_padding no_margin"><strong>Date:</strong> {{ $invoice->date }} </div>
<div class="no_padding no_margin"><strong>Challen No:</strong> {{ $invoice->challan_no }} </div>
</div>
</div>
<div class="invoice_items">
<table class="table table-borderless ">
<thead>
<th>SL</th>
<th>Product</th>
<th>Price</th>
<th>Qty</th>
<th class="text-right">Total</th>
<th class="text-right">-</th>
</thead>
<tbody>
@foreach ($invoice->items as $key => $item)
<tr>
<td> {{ $key+1 }} </td>
<td> {{ $item->product->title }} </td>
<td> {{ $item->price }} </td>
<td> {{ $item->quantity }} </td>
<td class="text-right"> {{ $item->total }} </td>
<td class="text-right">
<form
method="POST"
action=" {{ route('user.purchases.delete_item', ['id' => $user->id, 'invoice_id' => $invoice->id, 'item_id'=> $item->id]) }}
">
@csrf
@method('DELETE')
<button onclick="return confirm('Are you sure?')" type="submit" class="btn btn-danger btn-sm">
<i class="fa fa-trash"></i>
</button>
</form>
</td>
</tr>
@endforeach
</tbody>
<tr>
<th></th>
<th>
<button class="btn btn-info btn-sm" data-toggle="modal" data-target="#newProduct">
<i class="fa fa-plus "></i> Add Product
</button>
</th>
<th colspan="2" class="text-right"> Total: </th>
<th class="text-right"> {{ $totalPayable }} </th>
<th></th>
</tr>
<tr>
<th></th>
<th>
<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#newPaymentForInvoice">
<i class="fa fa-plus "></i> Add Payment
</button>
</th>
<th colspan="2" class="text-right"> Paid: </th>
<th class="text-right"> {{ $totalPaid }} </th>
<th></th>
</tr>
<tr>
<th colspan="4" class="text-right"> Due: </th>
<th class="text-right"> {{ $totalPayable - $totalPaid }} </th>
<th></th>
</tr>
</table>
</div>
</div>
</div>
{{-- Modal For Add new Product --}}
<div class="modal fade" id="newProduct" tabindex="-1" role="dialog" aria-labelledby="newProductModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
{!! Form::open([ 'route' => ['user.purchases.add_item', ['id' => $user->id, 'invoice_id' => $invoice->id] ], 'method' => 'post' ]) !!}
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="newProductModalLabel"> Add New Product </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group row">
<label for="product" class="col-sm-3 col-form-label text-right">Product <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::select('product_id', $products, NULL, [ 'class'=>'form-control', 'id' => 'product', 'required', 'placeholder' => 'Select Product' ]) }}
</div>
</div>
<div class="form-group row">
<label for="price" class="col-sm-3 col-form-label text-right">Unite Price <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::text('price', NULL, [ 'class'=>'form-control', 'id' => 'price', 'placeholder' => 'Unite Price', 'required' ]) }}
</div>
</div>
<div class="form-group row">
<label for="quantity" class="col-sm-3 col-form-label text-right">Quantity <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::text('quantity', NULL, [ 'class'=>'form-control', 'id' => 'quantity', 'placeholder' => 'Quantity', 'required' ]) }}
</div>
</div>
<div class="form-group row">
<label for="total" class="col-sm-3 col-form-label text-right">Total <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::text('total', NULL, [ 'class'=>'form-control', 'id' => 'total', 'placeholder' => 'Total', 'required' ]) }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
{{-- New Receipt For Invoice --}}
<div class="modal fade" id="newPaymentForInvoice" tabindex="-1" role="dialog" aria-labelledby="newPaymentForInvoiceModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
{!! Form::open([ 'route' => [ 'user.payments.store', [$user->id, $invoice->id] ], 'method' => 'post' ]) !!}
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="newPaymentForInvoiceModalLabel"> New Payment For This Invoice </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group row">
<label for="date" class="col-sm-3 col-form-label"> Date <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::date('date', NULL, [ 'class'=>'form-control', 'id' => 'date', 'placeholder' => 'Date', 'required' ]) }}
</div>
</div>
<div class="form-group row">
<label for="amount" class="col-sm-3 col-form-label">Amount <span class="text-danger">*</span> </label>
<div class="col-sm-9">
{{ Form::text('amount', NULL, [ 'class'=>'form-control', 'id' => 'amount', 'placeholder' => 'Amount', 'required' ]) }}
</div>
</div>
<div class="form-group row">
<label for="note" class="col-sm-3 col-form-label">Note </label>
<div class="col-sm-9">
{{ Form::textarea('note', NULL, [ 'class'=>'form-control', 'id' => 'note', 'rows' => '3', 'placeholder' => 'Note' ]) }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
@stop
users/show.blade.php
@extends('users.user_layout')
@section('user_card')
<div class="row">
<!-- Earnings (Monthly) Card Example -->
<div class="col-xl-2 col-md-3 mb-4">
<div class="card border-left-primary shadow h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Sales</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">
<?php
$totalSales = 0;
foreach ($user->sales as $sale) {
$totalSales += $sale->items()->sum('total');
}
echo $totalSales;
?>
</div>
</div>
<div class="col-auto">
<i class="fas fa-calendar fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
</div>
<!-- Earnings (Monthly) Card Example -->
<div class="col-xl-2 col-md-3 mb-4">
<div class="card border-left-primary shadow h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Purchases</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">
<?php
$totalPurchase = 0;
foreach ($user->purchases as $purchase) {
$totalPurchase += $purchase->items()->sum('total');
}
echo $totalPurchase;
?>
</div>
</div>
<div class="col-auto">
<i class="fas fa-calendar fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
</div>
<!-- Earnings (Monthly) Card Example -->
<div class="col-xl-2 col-md-3 mb-4">
<div class="card border-left-primary shadow h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Receipts</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ $totalRecept = $user->receipts()->sum('amount') }}</div>
</div>
<div class="col-auto">
<i class="fas fa-calendar fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
</div>
<!-- Earnings (Monthly) Card Example -->
<div class="col-xl-2 col-md-3 mb-4">
<div class="card border-left-primary shadow h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Payments</div>
<div class="h5 mb-0 font-weight-bold text-gray-800"> {{ $totalPayment = $user->payments()->sum('amount') }} </div>
</div>
<div class="col-auto">
<i class="fas fa-calendar fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
</div>
<?php
$totalBalance = ($totalPurchase + $totalRecept) - ($totalSales + $totalPayment);
?>
<!-- Earnings (Monthly) Card Example -->
<div class="col-xl-2 col-md-3 mb-4">
<div class="card border-left-primary shadow h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1"> Balance </div>
<div class="h5 mb-0 font-weight-bold text-gray-800">
@if ($totalBalance >= 0)
{{ $totalBalance }}
@else
0
@endif
</div>
</div>
<div class="col-auto">
<i class="fas fa-calendar fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
</div>
<!-- Earnings (Monthly) Card Example -->
<div class="col-xl-2 col-md-3 mb-4">
<div class="card border-left-primary shadow h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1"> Due </div>
<div class="h5 mb-0 font-weight-bold text-gray-800">
@if ($totalBalance < 0)
{{ $totalBalance }}
@else
0
@endif
</div>
</div>
<div class="col-auto">
<i class="fas fa-calendar fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
</div>
</div>
@stop
@section('user_content')
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary"> {{ $user->name }} </h6>
</div>
<div class="card-body">
<div class="row clearfix justify-content-md-center">
<div class="col-md-8">
<table class="table table-borderless table-striped">
<tr>
<th class="text-right">Group :</th>
<td> {{ $user->group->title }} </td>
</tr>
<tr>
<th class="text-right">Name : </th>
<td> {{ $user->name }} </td>
</tr>
<tr>
<th class="text-right">Eamil : </th>
<td> {{ $user->email }} </td>
</tr>
<tr>
<th class="text-right">Phone : </th>
<td> {{ $user->phone }} </td>
</tr>
<tr>
<th class="text-right">Address : </th>
<td> {{ $user->address }} </td>
</tr>
</table>
</div>
</div>
</div>
</div>
@stop