close #252 Fixed: Invoice partial payments are unpredictable

This commit is contained in:
cuneytsenturk 2018-03-13 15:06:28 +03:00
parent 8573232586
commit 83ad45cdfa
11 changed files with 152 additions and 14 deletions

View File

@ -594,13 +594,22 @@ class Bills extends Controller
} elseif ($bill->payments()->count() > 1) {
$bill->bill_status_code = 'partial';
} else {
$bill->bill_status_code = 'draft';
$bill->bill_status_code = 'received';
}
$bill->save();
$payment->delete();
// Add invoice history
BillHistory::create([
'company_id' => $bill->company_id,
'invoice_id' => $bill->id,
'status_code' => 'delete',
'notify' => 0,
'description' => trans('general.delete') . ' ' . $payment->description,
]);
$message = trans('messages.success.deleted', ['type' => trans_choice('general.bills', 1)]);
flash($message)->success();

View File

@ -474,8 +474,20 @@ class Invoices extends Controller
*/
public function markSent(Invoice $invoice)
{
$invoice->invoice_status_code = 'sent';
$invoice->save();
if ($invoice->invoice_status_code != 'partial') {
$invoice->invoice_status_code = 'sent';
$invoice->save();
}
// Add invoice history
InvoiceHistory::create([
'company_id' => $invoice->company_id,
'invoice_id' => $invoice->id,
'status_code' => 'sent',
'notify' => 0,
'description' => trans('invoices.mark_sent'),
]);
flash(trans('invoices.messages.marked_sent'))->success();
@ -522,8 +534,20 @@ class Invoices extends Controller
unset($invoice->pdf_path);
// Mark invoice as sent
$invoice->invoice_status_code = 'sent';
$invoice->save();
if ($invoice->invoice_status_code != 'partial') {
$invoice->invoice_status_code = 'sent';
$invoice->save();
}
// Add invoice history
InvoiceHistory::create([
'company_id' => $invoice->company_id,
'invoice_id' => $invoice->id,
'status_code' => 'sent',
'notify' => 1,
'description' => trans('invoices.send_mail'),
]);
flash(trans('invoices.messages.email_sent'))->success();
@ -705,13 +729,22 @@ class Invoices extends Controller
} elseif ($invoice->payments()->count() > 1) {
$invoice->invoice_status_code = 'partial';
} else {
$invoice->invoice_status_code = 'draft';
$invoice->invoice_status_code = 'sent';
}
$invoice->save();
$payment->delete();
// Add invoice history
InvoiceHistory::create([
'company_id' => $invoice->company_id,
'invoice_id' => $invoice->id,
'status_code' => 'delete',
'notify' => 0,
'description' => trans('general.delete') . ' ' . $payment->description,
]);
$message = trans('messages.success.deleted', ['type' => trans_choice('general.invoices', 1)]);
flash($message)->success();

View File

@ -0,0 +1,51 @@
<?php
namespace App\Listeners\Updates;
use App\Events\UpdateFinished;
use App\Models\Company\Company;
use App\Models\Income\InvoiceStatus;
use App\Models\Expense\BillStatus;
use Artisan;
class Version1115 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.1.15';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(UpdateFinished $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Create new bill statuses
$companies = Company::all();
foreach ($companies as $company) {
$invoice = [
'company_id' => $company->id,
'name' => trans('invoices.status.delete'),
'code' => 'delete',
];
InvoiceStatus::create($invoice);
$bill = [
'company_id' => $company->id,
'name' => trans('bills.status.delete'),
'code' => 'delete',
];
BillStatus::create($bill);
}
}
}

View File

@ -34,6 +34,9 @@ class BillStatus extends Model
case 'paid':
$label = 'label-success';
break;
case 'delete':
$label = 'label-danger';
break;
case 'partial':
case 'received':
$label = 'label-warning';

View File

@ -34,6 +34,9 @@ class InvoiceStatus extends Model
case 'paid':
$label = 'label-success';
break;
case 'delete':
$label = 'label-danger';
break;
case 'partial':
case 'sent':
$label = 'label-warning';

View File

@ -22,6 +22,7 @@ class EventServiceProvider extends ServiceProvider
'App\Listeners\Updates\Version112',
'App\Listeners\Updates\Version113',
'App\Listeners\Updates\Version119',
'App\Listeners\Updates\Version1115',
],
'Illuminate\Auth\Events\Login' => [
'App\Listeners\Auth\Login',

View File

@ -43,6 +43,11 @@ class BillStatuses extends Seeder
'name' => trans('bills.status.partial'),
'code' => 'partial',
],
[
'company_id' => $company_id,
'name' => trans('bills.status.delete'),
'code' => 'delete',
],
[
'company_id' => $company_id,
'name' => trans('bills.status.paid'),

View File

@ -53,6 +53,11 @@ class InvoiceStatuses extends Seeder
'name' => trans('invoices.status.partial'),
'code' => 'partial',
],
[
'company_id' => $company_id,
'name' => trans('invoices.status.delete'),
'code' => 'delete',
],
[
'company_id' => $company_id,
'name' => trans('invoices.status.paid'),

View File

@ -113,10 +113,23 @@
<table class="table">
<tbody>
@foreach($bill->totals as $total)
<tr>
<th>{{ trans($total['name']) }}:</th>
<td class="text-right">@money($total->amount, $bill->currency_code, true)</td>
</tr>
@if ($total->code != 'total')
<tr>
<th>{{ trans($total['name']) }}:</th>
<td class="text-right">@money($total->amount, $bill->currency_code, true)</td>
</tr>
@else
@if ($bill->paid)
<tr class="text-success">
<th>{{ trans('invoices.paid') }}:</th>
<td class="text-right">- @money($bill->paid, $bill->currency_code, true)</td>
</tr>
@endif
<tr>
<th>{{ trans($total['name']) }}:</th>
<td class="text-right">@money($total->amount - $bill->paid, $bill->currency_code, true)</td>
</tr>
@endif
@endforeach
</tbody>
</table>

View File

@ -113,10 +113,23 @@
<table class="table">
<tbody>
@foreach($invoice->totals as $total)
<tr>
<th>{{ trans($total['name']) }}:</th>
<td class="text-right">@money($total->amount, $invoice->currency_code, true)</td>
</tr>
@if($total->code != 'total')
<tr>
<th>{{ trans($total['name']) }}:</th>
<td class="text-right">@money($total->amount, $invoice->currency_code, true)</td>
</tr>
@else
@if ($invoice->paid)
<tr class="text-success">
<th>{{ trans('invoices.paid') }}:</th>
<td class="text-right">- @money($invoice->paid, $invoice->currency_code, true)</td>
</tr>
@endif
<tr>
<th>{{ trans($total['name']) }}:</th>
<td class="text-right">@money($total->amount - $invoice->paid, $invoice->currency_code, true)</td>
</tr>
@endif
@endforeach
</tbody>
</table>

View File

@ -165,7 +165,9 @@
<li class="divider"></li>
@endif
@permission('update-incomes-invoices')
@if($invoice->invoice_status_code != 'partial')
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/sent') }}">{{ trans('invoices.mark_sent') }}</a></li>
@endif
@endpermission
@if($invoice->customer_email)
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/email') }}">{{ trans('invoices.send_mail') }}</a></li>