discount
This commit is contained in:
parent
cfda5585a4
commit
18a3a3f6cb
@ -84,9 +84,7 @@ class Bills extends Controller
|
|||||||
|
|
||||||
$payment_methods = Modules::getPaymentMethods();
|
$payment_methods = Modules::getPaymentMethods();
|
||||||
|
|
||||||
$taxes = Tax::enabled()->get()->pluck('title', 'name');
|
return view('expenses.bills.show', compact('bill', 'accounts', 'currencies', 'account_currency_code', 'vendors', 'categories', 'payment_methods'));
|
||||||
|
|
||||||
return view('expenses.bills.show', compact('bill', 'accounts', 'currencies', 'account_currency_code', 'vendors', 'categories', 'payment_methods', 'taxes'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,6 +146,8 @@ class Bills extends Controller
|
|||||||
|
|
||||||
$tax_total = 0;
|
$tax_total = 0;
|
||||||
$sub_total = 0;
|
$sub_total = 0;
|
||||||
|
$discount_total = 0;
|
||||||
|
$discount = $request['discount'];
|
||||||
|
|
||||||
$bill_item = [];
|
$bill_item = [];
|
||||||
$bill_item['company_id'] = $request['company_id'];
|
$bill_item['company_id'] = $request['company_id'];
|
||||||
@ -177,6 +177,11 @@ class Bills extends Controller
|
|||||||
$tax_id = $item['tax_id'];
|
$tax_id = $item['tax_id'];
|
||||||
|
|
||||||
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
||||||
|
|
||||||
|
// Apply discount to tax
|
||||||
|
if ($discount) {
|
||||||
|
$tax = $tax - ($tax * ($discount / 100));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$bill_item['item_id'] = $item['item_id'];
|
$bill_item['item_id'] = $item['item_id'];
|
||||||
@ -210,12 +215,21 @@ class Bills extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$request['amount'] += $sub_total + $tax_total;
|
$s_total = $sub_total;
|
||||||
|
|
||||||
|
// Apply discount to total
|
||||||
|
if ($discount) {
|
||||||
|
$s_discount = $s_total * ($discount / 100);
|
||||||
|
$discount_total += $s_discount;
|
||||||
|
$s_total = $s_total - $s_discount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request['amount'] = $s_total + $tax_total;
|
||||||
|
|
||||||
$bill->update($request->input());
|
$bill->update($request->input());
|
||||||
|
|
||||||
// Add bill totals
|
// Add bill totals
|
||||||
$this->addTotals($bill, $request, $taxes, $sub_total, $tax_total);
|
$this->addTotals($bill, $request, $taxes, $sub_total, $discount_total, $tax_total);
|
||||||
|
|
||||||
// Add bill history
|
// Add bill history
|
||||||
BillHistory::create([
|
BillHistory::create([
|
||||||
@ -336,6 +350,8 @@ class Bills extends Controller
|
|||||||
$taxes = [];
|
$taxes = [];
|
||||||
$tax_total = 0;
|
$tax_total = 0;
|
||||||
$sub_total = 0;
|
$sub_total = 0;
|
||||||
|
$discount_total = 0;
|
||||||
|
$discount = $request['discount'];
|
||||||
|
|
||||||
$bill_item = [];
|
$bill_item = [];
|
||||||
$bill_item['company_id'] = $request['company_id'];
|
$bill_item['company_id'] = $request['company_id'];
|
||||||
@ -363,6 +379,11 @@ class Bills extends Controller
|
|||||||
$tax_id = $item['tax_id'];
|
$tax_id = $item['tax_id'];
|
||||||
|
|
||||||
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
||||||
|
|
||||||
|
// Apply discount to tax
|
||||||
|
if ($discount) {
|
||||||
|
$tax = $tax - ($tax * ($discount / 100));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$bill_item['item_id'] = $item['item_id'];
|
$bill_item['item_id'] = $item['item_id'];
|
||||||
@ -392,7 +413,16 @@ class Bills extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$request['amount'] = $sub_total + $tax_total;
|
$s_total = $sub_total;
|
||||||
|
|
||||||
|
// Apply discount to total
|
||||||
|
if ($discount) {
|
||||||
|
$s_discount = $s_total * ($discount / 100);
|
||||||
|
$discount_total += $s_discount;
|
||||||
|
$s_total = $s_total - $s_discount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request['amount'] = $s_total + $tax_total;
|
||||||
|
|
||||||
$bill->update($request->input());
|
$bill->update($request->input());
|
||||||
|
|
||||||
@ -407,7 +437,8 @@ class Bills extends Controller
|
|||||||
BillTotal::where('bill_id', $bill->id)->delete();
|
BillTotal::where('bill_id', $bill->id)->delete();
|
||||||
|
|
||||||
// Add bill totals
|
// Add bill totals
|
||||||
$this->addTotals($bill, $request, $taxes, $sub_total, $tax_total);
|
$bill->totals()->delete();
|
||||||
|
$this->addTotals($bill, $request, $taxes, $sub_total, $discount_total, $tax_total);
|
||||||
|
|
||||||
// Fire the event to make it extendible
|
// Fire the event to make it extendible
|
||||||
event(new BillUpdated($bill));
|
event(new BillUpdated($bill));
|
||||||
@ -478,9 +509,7 @@ class Bills extends Controller
|
|||||||
|
|
||||||
$logo = $this->getLogo($bill);
|
$logo = $this->getLogo($bill);
|
||||||
|
|
||||||
$taxes = Tax::enabled()->get()->pluck('title', 'name');
|
return view($bill->template_path, compact('bill', 'logo'));
|
||||||
|
|
||||||
return view($bill->template_path, compact('bill', 'logo', 'taxes'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -496,9 +525,7 @@ class Bills extends Controller
|
|||||||
|
|
||||||
$logo = $this->getLogo($bill);
|
$logo = $this->getLogo($bill);
|
||||||
|
|
||||||
$taxes = Tax::enabled()->get()->pluck('title', 'name');
|
$html = view($bill->template_path, compact('bill', 'logo'))->render();
|
||||||
|
|
||||||
$html = view($bill->template_path, compact('bill', 'logo', 'taxes'))->render();
|
|
||||||
|
|
||||||
$pdf = \App::make('dompdf.wrapper');
|
$pdf = \App::make('dompdf.wrapper');
|
||||||
$pdf->loadHTML($html);
|
$pdf->loadHTML($html);
|
||||||
@ -646,11 +673,11 @@ class Bills extends Controller
|
|||||||
return $bill;
|
return $bill;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addTotals($bill, $request, $taxes, $sub_total, $tax_total)
|
protected function addTotals($bill, $request, $taxes, $sub_total, $discount_total, $tax_total)
|
||||||
{
|
{
|
||||||
$sort_order = 1;
|
$sort_order = 1;
|
||||||
|
|
||||||
// Added bill total sub total
|
// Added bill sub total
|
||||||
BillTotal::create([
|
BillTotal::create([
|
||||||
'company_id' => $request['company_id'],
|
'company_id' => $request['company_id'],
|
||||||
'bill_id' => $bill->id,
|
'bill_id' => $bill->id,
|
||||||
@ -662,7 +689,24 @@ class Bills extends Controller
|
|||||||
|
|
||||||
$sort_order++;
|
$sort_order++;
|
||||||
|
|
||||||
// Added bill total taxes
|
// Added bill discount
|
||||||
|
if ($discount_total) {
|
||||||
|
BillTotal::create([
|
||||||
|
'company_id' => $request['company_id'],
|
||||||
|
'bill_id' => $bill->id,
|
||||||
|
'code' => 'discount',
|
||||||
|
'name' => 'bills.discount',
|
||||||
|
'amount' => $discount_total,
|
||||||
|
'sort_order' => $sort_order,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// This is for total
|
||||||
|
$sub_total = $sub_total - $discount_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sort_order++;
|
||||||
|
|
||||||
|
// Added bill taxes
|
||||||
if ($taxes) {
|
if ($taxes) {
|
||||||
foreach ($taxes as $tax) {
|
foreach ($taxes as $tax) {
|
||||||
BillTotal::create([
|
BillTotal::create([
|
||||||
@ -678,7 +722,7 @@ class Bills extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Added bill total total
|
// Added bill total
|
||||||
BillTotal::create([
|
BillTotal::create([
|
||||||
'company_id' => $request['company_id'],
|
'company_id' => $request['company_id'],
|
||||||
'bill_id' => $bill->id,
|
'bill_id' => $bill->id,
|
||||||
|
@ -87,9 +87,7 @@ class Invoices extends Controller
|
|||||||
|
|
||||||
$payment_methods = Modules::getPaymentMethods();
|
$payment_methods = Modules::getPaymentMethods();
|
||||||
|
|
||||||
$taxes = Tax::enabled()->get()->pluck('title', 'name');
|
return view('incomes.invoices.show', compact('invoice', 'accounts', 'currencies', 'account_currency_code', 'customers', 'categories', 'payment_methods'));
|
||||||
|
|
||||||
return view('incomes.invoices.show', compact('invoice', 'accounts', 'currencies', 'account_currency_code', 'customers', 'categories', 'payment_methods', 'taxes'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,6 +151,8 @@ class Invoices extends Controller
|
|||||||
|
|
||||||
$tax_total = 0;
|
$tax_total = 0;
|
||||||
$sub_total = 0;
|
$sub_total = 0;
|
||||||
|
$discount_total = 0;
|
||||||
|
$discount = $request['discount'];
|
||||||
|
|
||||||
$invoice_item = [];
|
$invoice_item = [];
|
||||||
$invoice_item['company_id'] = $request['company_id'];
|
$invoice_item['company_id'] = $request['company_id'];
|
||||||
@ -192,6 +192,11 @@ class Invoices extends Controller
|
|||||||
$tax_id = $item['tax_id'];
|
$tax_id = $item['tax_id'];
|
||||||
|
|
||||||
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
||||||
|
|
||||||
|
// Apply discount to tax
|
||||||
|
if ($discount) {
|
||||||
|
$tax = $tax - ($tax * ($discount / 100));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$invoice_item['item_id'] = $item['item_id'];
|
$invoice_item['item_id'] = $item['item_id'];
|
||||||
@ -225,12 +230,21 @@ class Invoices extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$request['amount'] = $sub_total + $tax_total;
|
$s_total = $sub_total;
|
||||||
|
|
||||||
|
// Apply discount to total
|
||||||
|
if ($discount) {
|
||||||
|
$s_discount = $s_total * ($discount / 100);
|
||||||
|
$discount_total += $s_discount;
|
||||||
|
$s_total = $s_total - $s_discount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request['amount'] = $s_total + $tax_total;
|
||||||
|
|
||||||
$invoice->update($request->input());
|
$invoice->update($request->input());
|
||||||
|
|
||||||
// Add invoice totals
|
// Add invoice totals
|
||||||
$this->addTotals($invoice, $request, $taxes, $sub_total, $tax_total);
|
$this->addTotals($invoice, $request, $taxes, $sub_total, $discount_total, $tax_total);
|
||||||
|
|
||||||
// Add invoice history
|
// Add invoice history
|
||||||
InvoiceHistory::create([
|
InvoiceHistory::create([
|
||||||
@ -357,6 +371,8 @@ class Invoices extends Controller
|
|||||||
$taxes = [];
|
$taxes = [];
|
||||||
$tax_total = 0;
|
$tax_total = 0;
|
||||||
$sub_total = 0;
|
$sub_total = 0;
|
||||||
|
$discount_total = 0;
|
||||||
|
$discount = $request['discount'];
|
||||||
|
|
||||||
$invoice_item = [];
|
$invoice_item = [];
|
||||||
$invoice_item['company_id'] = $request['company_id'];
|
$invoice_item['company_id'] = $request['company_id'];
|
||||||
@ -384,6 +400,11 @@ class Invoices extends Controller
|
|||||||
$tax_id = $item['tax_id'];
|
$tax_id = $item['tax_id'];
|
||||||
|
|
||||||
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
||||||
|
|
||||||
|
// Apply discount to tax
|
||||||
|
if ($discount) {
|
||||||
|
$tax = $tax - ($tax * ($discount / 100));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$invoice_item['item_id'] = $item['item_id'];
|
$invoice_item['item_id'] = $item['item_id'];
|
||||||
@ -413,7 +434,16 @@ class Invoices extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$request['amount'] = $sub_total + $tax_total;
|
$s_total = $sub_total;
|
||||||
|
|
||||||
|
// Apply discount to total
|
||||||
|
if ($discount) {
|
||||||
|
$s_discount = $s_total * ($discount / 100);
|
||||||
|
$discount_total += $s_discount;
|
||||||
|
$s_total = $s_total - $s_discount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request['amount'] = $s_total + $tax_total;
|
||||||
|
|
||||||
$invoice->update($request->input());
|
$invoice->update($request->input());
|
||||||
|
|
||||||
@ -428,7 +458,8 @@ class Invoices extends Controller
|
|||||||
InvoiceTotal::where('invoice_id', $invoice->id)->delete();
|
InvoiceTotal::where('invoice_id', $invoice->id)->delete();
|
||||||
|
|
||||||
// Add invoice totals
|
// Add invoice totals
|
||||||
$this->addTotals($invoice, $request, $taxes, $sub_total, $tax_total);
|
$invoice->totals()->delete();
|
||||||
|
$this->addTotals($invoice, $request, $taxes, $sub_total, $discount_total, $tax_total);
|
||||||
|
|
||||||
// Fire the event to make it extendible
|
// Fire the event to make it extendible
|
||||||
event(new InvoiceUpdated($invoice));
|
event(new InvoiceUpdated($invoice));
|
||||||
@ -513,11 +544,7 @@ class Invoices extends Controller
|
|||||||
|
|
||||||
$logo = $this->getLogo();
|
$logo = $this->getLogo();
|
||||||
|
|
||||||
$taxes = collect(Tax::enabled()->get())->each(function ($item) {
|
$html = view($invoice->template_path, compact('invoice', 'logo'))->render();
|
||||||
$item->title = $item->name . ' (' . $item->rate . '%)';
|
|
||||||
})->pluck('title', 'name');
|
|
||||||
|
|
||||||
$html = view($invoice->template_path, compact('invoice', 'logo', 'taxes'))->render();
|
|
||||||
|
|
||||||
$pdf = \App::make('dompdf.wrapper');
|
$pdf = \App::make('dompdf.wrapper');
|
||||||
$pdf->loadHTML($html);
|
$pdf->loadHTML($html);
|
||||||
@ -573,9 +600,7 @@ class Invoices extends Controller
|
|||||||
|
|
||||||
$logo = $this->getLogo();
|
$logo = $this->getLogo();
|
||||||
|
|
||||||
$taxes = Tax::enabled()->get()->pluck('title', 'name');
|
return view($invoice->template_path, compact('invoice', 'logo'));
|
||||||
|
|
||||||
return view($invoice->template_path, compact('invoice', 'logo', 'taxes'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -591,9 +616,7 @@ class Invoices extends Controller
|
|||||||
|
|
||||||
$logo = $this->getLogo();
|
$logo = $this->getLogo();
|
||||||
|
|
||||||
$taxes = Tax::enabled()->get()->pluck('title', 'name');
|
$html = view($invoice->template_path, compact('invoice', 'logo'))->render();
|
||||||
|
|
||||||
$html = view($invoice->template_path, compact('invoice', 'logo', 'taxes'))->render();
|
|
||||||
|
|
||||||
$pdf = \App::make('dompdf.wrapper');
|
$pdf = \App::make('dompdf.wrapper');
|
||||||
$pdf->loadHTML($html);
|
$pdf->loadHTML($html);
|
||||||
@ -783,11 +806,11 @@ class Invoices extends Controller
|
|||||||
return $invoice;
|
return $invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addTotals($invoice, $request, $taxes, $sub_total, $tax_total)
|
protected function addTotals($invoice, $request, $taxes, $sub_total, $discount_total, $tax_total)
|
||||||
{
|
{
|
||||||
$sort_order = 1;
|
$sort_order = 1;
|
||||||
|
|
||||||
// Added invoice total sub total
|
// Added invoice sub total
|
||||||
InvoiceTotal::create([
|
InvoiceTotal::create([
|
||||||
'company_id' => $request['company_id'],
|
'company_id' => $request['company_id'],
|
||||||
'invoice_id' => $invoice->id,
|
'invoice_id' => $invoice->id,
|
||||||
@ -799,7 +822,24 @@ class Invoices extends Controller
|
|||||||
|
|
||||||
$sort_order++;
|
$sort_order++;
|
||||||
|
|
||||||
// Added invoice total taxes
|
// Added invoice discount
|
||||||
|
if ($discount_total) {
|
||||||
|
InvoiceTotal::create([
|
||||||
|
'company_id' => $request['company_id'],
|
||||||
|
'invoice_id' => $invoice->id,
|
||||||
|
'code' => 'discount',
|
||||||
|
'name' => 'invoices.discount',
|
||||||
|
'amount' => $discount_total,
|
||||||
|
'sort_order' => $sort_order,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// This is for total
|
||||||
|
$sub_total = $sub_total - $discount_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sort_order++;
|
||||||
|
|
||||||
|
// Added invoice taxes
|
||||||
if ($taxes) {
|
if ($taxes) {
|
||||||
foreach ($taxes as $tax) {
|
foreach ($taxes as $tax) {
|
||||||
InvoiceTotal::create([
|
InvoiceTotal::create([
|
||||||
@ -815,7 +855,7 @@ class Invoices extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Added invoice total total
|
// Added invoice total
|
||||||
InvoiceTotal::create([
|
InvoiceTotal::create([
|
||||||
'company_id' => $request['company_id'],
|
'company_id' => $request['company_id'],
|
||||||
'invoice_id' => $invoice->id,
|
'invoice_id' => $invoice->id,
|
||||||
|
@ -246,6 +246,7 @@ class Items extends Controller
|
|||||||
{
|
{
|
||||||
$input_items = request('item');
|
$input_items = request('item');
|
||||||
$currency_code = request('currency_code');
|
$currency_code = request('currency_code');
|
||||||
|
$discount = request('discount');
|
||||||
|
|
||||||
if (empty($currency_code)) {
|
if (empty($currency_code)) {
|
||||||
$currency_code = setting('general.default_currency');
|
$currency_code = setting('general.default_currency');
|
||||||
@ -273,6 +274,12 @@ class Items extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sub_total += $item_sub_total;
|
$sub_total += $item_sub_total;
|
||||||
|
|
||||||
|
// Apply discount to tax
|
||||||
|
if ($discount) {
|
||||||
|
$item_tax_total = $item_tax_total - ($item_tax_total * ($discount / 100));
|
||||||
|
}
|
||||||
|
|
||||||
$tax_total += $item_tax_total;
|
$tax_total += $item_tax_total;
|
||||||
|
|
||||||
$total = $item_sub_total + $item_tax_total;
|
$total = $item_sub_total + $item_tax_total;
|
||||||
@ -287,6 +294,11 @@ class Items extends Controller
|
|||||||
|
|
||||||
$json->tax_total = money($tax_total, $currency_code, true)->format();
|
$json->tax_total = money($tax_total, $currency_code, true)->format();
|
||||||
|
|
||||||
|
// Apply discount to total
|
||||||
|
if ($discount) {
|
||||||
|
$sub_total = $sub_total - ($sub_total * ($discount / 100));
|
||||||
|
}
|
||||||
|
|
||||||
$grand_total = $sub_total + $tax_total;
|
$grand_total = $sub_total + $tax_total;
|
||||||
|
|
||||||
$json->grand_total = money($grand_total, $currency_code, true)->format();
|
$json->grand_total = money($grand_total, $currency_code, true)->format();
|
||||||
|
@ -15,6 +15,13 @@ class Bill extends Model
|
|||||||
|
|
||||||
protected $table = 'bills';
|
protected $table = 'bills';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The accessors to append to the model's array form.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $appends = ['attachment', 'discount'];
|
||||||
|
|
||||||
protected $dates = ['deleted_at', 'billed_at', 'due_at'];
|
protected $dates = ['deleted_at', 'billed_at', 'due_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,4 +162,26 @@ class Bill extends Model
|
|||||||
|
|
||||||
return $this->getMedia('attachment')->last();
|
return $this->getMedia('attachment')->last();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the discount percentage.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDiscountAttribute()
|
||||||
|
{
|
||||||
|
$discount = 0;
|
||||||
|
|
||||||
|
foreach ($this->totals as $total) {
|
||||||
|
if ($total->code != 'discount') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$discount = number_format((($total->amount * 100) / $this->amount), 0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $discount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models\Expense;
|
namespace App\Models\Expense;
|
||||||
|
|
||||||
use App\Models\Model;
|
use App\Models\Model;
|
||||||
|
use App\Models\Setting\Tax;
|
||||||
use App\Traits\DateTime;
|
use App\Traits\DateTime;
|
||||||
|
|
||||||
class BillTotal extends Model
|
class BillTotal extends Model
|
||||||
@ -33,4 +34,45 @@ class BillTotal extends Model
|
|||||||
{
|
{
|
||||||
$this->attributes['amount'] = (double) $value;
|
$this->attributes['amount'] = (double) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the formatted name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getNameAttribute($value)
|
||||||
|
{
|
||||||
|
$name = $value;
|
||||||
|
|
||||||
|
$percent = 0;
|
||||||
|
|
||||||
|
// Discount
|
||||||
|
if ($this->code == 'discount') {
|
||||||
|
$name = trans($name);
|
||||||
|
$percent = $this->bill->discount;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tax
|
||||||
|
if ($this->code == 'tax') {
|
||||||
|
$rate = Tax::where('name', $name)->value('rate');
|
||||||
|
|
||||||
|
if (!empty($rate)) {
|
||||||
|
$percent = $rate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($percent)) {
|
||||||
|
$name .= ' (';
|
||||||
|
|
||||||
|
if (setting('general.percent_position', 'after') == 'after') {
|
||||||
|
$name .= $percent . '%';
|
||||||
|
} else {
|
||||||
|
$name .= '%' . $percent;
|
||||||
|
}
|
||||||
|
|
||||||
|
$name .= ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class Invoice extends Model
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $appends = ['attachment'];
|
protected $appends = ['attachment', 'discount'];
|
||||||
|
|
||||||
protected $dates = ['deleted_at', 'invoiced_at', 'due_at'];
|
protected $dates = ['deleted_at', 'invoiced_at', 'due_at'];
|
||||||
|
|
||||||
@ -164,4 +164,26 @@ class Invoice extends Model
|
|||||||
|
|
||||||
return $this->getMedia('attachment')->last();
|
return $this->getMedia('attachment')->last();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the discount percentage.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDiscountAttribute()
|
||||||
|
{
|
||||||
|
$discount = 0;
|
||||||
|
|
||||||
|
foreach ($this->totals as $total) {
|
||||||
|
if ($total->code != 'discount') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$discount = number_format((($total->amount * 100) / $this->amount), 0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $discount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models\Income;
|
namespace App\Models\Income;
|
||||||
|
|
||||||
use App\Models\Model;
|
use App\Models\Model;
|
||||||
|
use App\Models\Setting\Tax;
|
||||||
use App\Traits\DateTime;
|
use App\Traits\DateTime;
|
||||||
|
|
||||||
class InvoiceTotal extends Model
|
class InvoiceTotal extends Model
|
||||||
@ -33,4 +34,45 @@ class InvoiceTotal extends Model
|
|||||||
{
|
{
|
||||||
$this->attributes['amount'] = (double) $value;
|
$this->attributes['amount'] = (double) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the formatted name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getNameAttribute($value)
|
||||||
|
{
|
||||||
|
$name = $value;
|
||||||
|
|
||||||
|
$percent = 0;
|
||||||
|
|
||||||
|
// Discount
|
||||||
|
if ($this->code == 'discount') {
|
||||||
|
$name = trans($name);
|
||||||
|
$percent = $this->invoice->discount;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tax
|
||||||
|
if ($this->code == 'tax') {
|
||||||
|
$rate = Tax::where('name', $name)->value('rate');
|
||||||
|
|
||||||
|
if (!empty($rate)) {
|
||||||
|
$percent = $rate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($percent)) {
|
||||||
|
$name .= ' (';
|
||||||
|
|
||||||
|
if (setting('general.percent_position', 'after') == 'after') {
|
||||||
|
$name .= $percent . '%';
|
||||||
|
} else {
|
||||||
|
$name .= '%' . $percent;
|
||||||
|
}
|
||||||
|
|
||||||
|
$name .= ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
7
public/css/app.css
vendored
7
public/css/app.css
vendored
@ -562,4 +562,11 @@ span.picture, span.attachment {
|
|||||||
|
|
||||||
.form-group.col-md-6 input.fake-input.form-control{
|
.form-group.col-md-6 input.fake-input.form-control{
|
||||||
min-width: 150px;
|
min-width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input::-webkit-outer-spin-button,
|
||||||
|
input::-webkit-inner-spin-button {
|
||||||
|
/* display: none; <- Crashes Chrome on hover */
|
||||||
|
-webkit-appearance: none;
|
||||||
|
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
|
||||||
}
|
}
|
@ -12,6 +12,7 @@ return [
|
|||||||
'quantity' => 'Quantity',
|
'quantity' => 'Quantity',
|
||||||
'price' => 'Price',
|
'price' => 'Price',
|
||||||
'sub_total' => 'Subtotal',
|
'sub_total' => 'Subtotal',
|
||||||
|
'discount' => 'Discount',
|
||||||
'tax_total' => 'Tax Total',
|
'tax_total' => 'Tax Total',
|
||||||
'total' => 'Total',
|
'total' => 'Total',
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ return [
|
|||||||
'quantity' => 'Quantity',
|
'quantity' => 'Quantity',
|
||||||
'price' => 'Price',
|
'price' => 'Price',
|
||||||
'sub_total' => 'Subtotal',
|
'sub_total' => 'Subtotal',
|
||||||
|
'discount' => 'Discount',
|
||||||
'tax_total' => 'Tax Total',
|
'tax_total' => 'Tax Total',
|
||||||
'total' => 'Total',
|
'total' => 'Total',
|
||||||
|
|
||||||
|
@ -114,17 +114,10 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
@foreach($bill->totals as $total)
|
@foreach($bill->totals as $total)
|
||||||
@if ($total->code != 'total')
|
@if ($total->code != 'total')
|
||||||
@if (($total->code == 'tax') && isset($taxes[$total->name]))
|
<tr>
|
||||||
<tr>
|
<th>{{ trans($total->name) }}:</th>
|
||||||
<th>{{ $taxes[$total->name] }}:</th>
|
<td class="text-right">@money($total->amount, $bill->currency_code, true)</td>
|
||||||
<td class="text-right">@money($total->amount, $bill->currency_code, true)</td>
|
</tr>
|
||||||
</tr>
|
|
||||||
@else
|
|
||||||
<tr>
|
|
||||||
<th>{{ trans($total->name) }}:</th>
|
|
||||||
<td class="text-right">@money($total->amount, $bill->currency_code, true)</td>
|
|
||||||
</tr>
|
|
||||||
@endif
|
|
||||||
@else
|
@else
|
||||||
@if ($bill->paid)
|
@if ($bill->paid)
|
||||||
<tr class="text-success">
|
<tr class="text-success">
|
||||||
|
@ -76,6 +76,15 @@
|
|||||||
<td class="text-right" colspan="5"><strong>{{ trans('bills.sub_total') }}</strong></td>
|
<td class="text-right" colspan="5"><strong>{{ trans('bills.sub_total') }}</strong></td>
|
||||||
<td class="text-right"><span id="sub-total">0</span></td>
|
<td class="text-right"><span id="sub-total">0</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="text-right" style="vertical-align: middle;" colspan="5"><strong>{{ trans('bills.discount') }}</strong></td>
|
||||||
|
<td class="text-right">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon"><i class="fa fa-percent"></i></div>
|
||||||
|
{!! Form::number('discount', null, ['class' => 'form-control text-right']) !!}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td>
|
<td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td>
|
||||||
<td class="text-right"><span id="tax-total">0</span></td>
|
<td class="text-right"><span id="tax-total">0</span></td>
|
||||||
@ -255,7 +264,7 @@
|
|||||||
url: '{{ url("items/items/totalItem") }}',
|
url: '{{ url("items/items/totalItem") }}',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
dataType: 'JSON',
|
dataType: 'JSON',
|
||||||
data: $('#currency_code, #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select'),
|
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select'),
|
||||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
@ -92,6 +92,15 @@
|
|||||||
<td class="text-right" colspan="5"><strong>{{ trans('bills.sub_total') }}</strong></td>
|
<td class="text-right" colspan="5"><strong>{{ trans('bills.sub_total') }}</strong></td>
|
||||||
<td class="text-right"><span id="sub-total">0</span></td>
|
<td class="text-right"><span id="sub-total">0</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="text-right" style="vertical-align: middle;" colspan="5"><strong>{{ trans('bills.discount') }}</strong></td>
|
||||||
|
<td class="text-right">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon"><i class="fa fa-percent"></i></div>
|
||||||
|
{!! Form::number('discount', $bill->discount, ['class' => 'form-control text-right']) !!}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td>
|
<td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td>
|
||||||
<td class="text-right"><span id="tax-total">0</span></td>
|
<td class="text-right"><span id="tax-total">0</span></td>
|
||||||
@ -300,7 +309,7 @@
|
|||||||
url: '{{ url("items/items/totalItem") }}',
|
url: '{{ url("items/items/totalItem") }}',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
dataType: 'JSON',
|
dataType: 'JSON',
|
||||||
data: $('#currency_code, #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select'),
|
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select'),
|
||||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
@ -119,17 +119,10 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($bill->totals as $total)
|
@foreach ($bill->totals as $total)
|
||||||
@if ($total->code != 'total')
|
@if ($total->code != 'total')
|
||||||
@if (($total->code == 'tax') && isset($taxes[$total->name]))
|
<tr>
|
||||||
<tr>
|
<th>{{ trans($total->name) }}:</th>
|
||||||
<th>{{ $taxes[$total->name] }}:</th>
|
<td class="text-right">@money($total->amount, $bill->currency_code, true)</td>
|
||||||
<td class="text-right">@money($total->amount, $bill->currency_code, true)</td>
|
</tr>
|
||||||
</tr>
|
|
||||||
@else
|
|
||||||
<tr>
|
|
||||||
<th>{{ trans($total->name) }}:</th>
|
|
||||||
<td class="text-right">@money($total->amount, $bill->currency_code, true)</td>
|
|
||||||
</tr>
|
|
||||||
@endif
|
|
||||||
@else
|
@else
|
||||||
@if ($bill->paid)
|
@if ($bill->paid)
|
||||||
<tr class="text-success">
|
<tr class="text-success">
|
||||||
|
@ -76,6 +76,15 @@
|
|||||||
<td class="text-right" colspan="5"><strong>{{ trans('invoices.sub_total') }}</strong></td>
|
<td class="text-right" colspan="5"><strong>{{ trans('invoices.sub_total') }}</strong></td>
|
||||||
<td class="text-right"><span id="sub-total">0</span></td>
|
<td class="text-right"><span id="sub-total">0</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="text-right" style="vertical-align: middle;" colspan="5"><strong>{{ trans('invoices.discount') }}</strong></td>
|
||||||
|
<td class="text-right">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon"><i class="fa fa-percent"></i></div>
|
||||||
|
{!! Form::number('discount', null, ['class' => 'form-control text-right']) !!}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td>
|
<td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td>
|
||||||
<td class="text-right"><span id="tax-total">0</span></td>
|
<td class="text-right"><span id="tax-total">0</span></td>
|
||||||
@ -256,7 +265,7 @@
|
|||||||
url: '{{ url("items/items/totalItem") }}',
|
url: '{{ url("items/items/totalItem") }}',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
dataType: 'JSON',
|
dataType: 'JSON',
|
||||||
data: $('#currency_code, #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select'),
|
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select'),
|
||||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
@ -91,6 +91,15 @@
|
|||||||
<td class="text-right" colspan="5"><strong>{{ trans('invoices.sub_total') }}</strong></td>
|
<td class="text-right" colspan="5"><strong>{{ trans('invoices.sub_total') }}</strong></td>
|
||||||
<td class="text-right"><span id="sub-total">0</span></td>
|
<td class="text-right"><span id="sub-total">0</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="text-right" style="vertical-align: middle;" colspan="5"><strong>{{ trans('invoices.discount') }}</strong></td>
|
||||||
|
<td class="text-right">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon"><i class="fa fa-percent"></i></div>
|
||||||
|
{!! Form::number('discount', $invoice->discount, ['class' => 'form-control text-right']) !!}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td>
|
<td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td>
|
||||||
<td class="text-right"><span id="tax-total">0</span></td>
|
<td class="text-right"><span id="tax-total">0</span></td>
|
||||||
@ -299,7 +308,7 @@
|
|||||||
url: '{{ url("items/items/totalItem") }}',
|
url: '{{ url("items/items/totalItem") }}',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
dataType: 'JSON',
|
dataType: 'JSON',
|
||||||
data: $('#currency_code, #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select'),
|
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select'),
|
||||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
@ -114,17 +114,10 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($invoice->totals as $total)
|
@foreach ($invoice->totals as $total)
|
||||||
@if ($total->code != 'total')
|
@if ($total->code != 'total')
|
||||||
@if (($total->code == 'tax') && isset($taxes[$total->name]))
|
<tr>
|
||||||
<tr>
|
<th>{{ trans($total->name) }}:</th>
|
||||||
<th>{{ $taxes[$total->name] }}:</th>
|
<td class="text-right">@money($total->amount, $invoice->currency_code, true)</td>
|
||||||
<td class="text-right">@money($total->amount, $invoice->currency_code, true)</td>
|
</tr>
|
||||||
</tr>
|
|
||||||
@else
|
|
||||||
<tr>
|
|
||||||
<th>{{ trans($total->name) }}:</th>
|
|
||||||
<td class="text-right">@money($total->amount, $invoice->currency_code, true)</td>
|
|
||||||
</tr>
|
|
||||||
@endif
|
|
||||||
@else
|
@else
|
||||||
@if ($invoice->paid)
|
@if ($invoice->paid)
|
||||||
<tr class="text-success">
|
<tr class="text-success">
|
||||||
|
@ -121,17 +121,10 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($invoice->totals as $total)
|
@foreach ($invoice->totals as $total)
|
||||||
@if ($total->code != 'total')
|
@if ($total->code != 'total')
|
||||||
@if (($total->code == 'tax') && isset($taxes[$total->name]))
|
<tr>
|
||||||
<tr>
|
<th>{{ trans($total->name) }}:</th>
|
||||||
<th>{{ $taxes[$total->name] }}:</th>
|
<td class="text-right">@money($total->amount, $invoice->currency_code, true)</td>
|
||||||
<td class="text-right">@money($total->amount, $invoice->currency_code, true)</td>
|
</tr>
|
||||||
</tr>
|
|
||||||
@else
|
|
||||||
<tr>
|
|
||||||
<th>{{ trans($total->name) }}:</th>
|
|
||||||
<td class="text-right">@money($total->amount, $invoice->currency_code, true)</td>
|
|
||||||
</tr>
|
|
||||||
@endif
|
|
||||||
@else
|
@else
|
||||||
@if ($invoice->paid)
|
@if ($invoice->paid)
|
||||||
<tr class="text-success">
|
<tr class="text-success">
|
||||||
|
8
resources/views/partials/form/number_group.blade.php
Normal file
8
resources/views/partials/form/number_group.blade.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<div class="form-group {{ $col }} {{ isset($attributes['required']) ? 'required' : '' }} {{ $errors->has($name) ? 'has-error' : '' }}">
|
||||||
|
{!! Form::label($name, $text, ['class' => 'control-label']) !!}
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon"><i class="fa fa-{{ $icon }}"></i></div>
|
||||||
|
{!! Form::number($name, $value, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.enter', ['field' => $text])], $attributes)) !!}
|
||||||
|
</div>
|
||||||
|
{!! $errors->first($name, '<p class="help-block">:message</p>') !!}
|
||||||
|
</div>
|
Loading…
x
Reference in New Issue
Block a user