close #252 Fixed: Invoice partial payments are unpredictable
This commit is contained in:
parent
8573232586
commit
83ad45cdfa
@ -594,13 +594,22 @@ class Bills extends Controller
|
|||||||
} elseif ($bill->payments()->count() > 1) {
|
} elseif ($bill->payments()->count() > 1) {
|
||||||
$bill->bill_status_code = 'partial';
|
$bill->bill_status_code = 'partial';
|
||||||
} else {
|
} else {
|
||||||
$bill->bill_status_code = 'draft';
|
$bill->bill_status_code = 'received';
|
||||||
}
|
}
|
||||||
|
|
||||||
$bill->save();
|
$bill->save();
|
||||||
|
|
||||||
$payment->delete();
|
$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)]);
|
$message = trans('messages.success.deleted', ['type' => trans_choice('general.bills', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
|
@ -474,8 +474,20 @@ class Invoices extends Controller
|
|||||||
*/
|
*/
|
||||||
public function markSent(Invoice $invoice)
|
public function markSent(Invoice $invoice)
|
||||||
{
|
{
|
||||||
|
if ($invoice->invoice_status_code != 'partial') {
|
||||||
$invoice->invoice_status_code = 'sent';
|
$invoice->invoice_status_code = 'sent';
|
||||||
|
|
||||||
$invoice->save();
|
$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();
|
flash(trans('invoices.messages.marked_sent'))->success();
|
||||||
|
|
||||||
@ -522,8 +534,20 @@ class Invoices extends Controller
|
|||||||
unset($invoice->pdf_path);
|
unset($invoice->pdf_path);
|
||||||
|
|
||||||
// Mark invoice as sent
|
// Mark invoice as sent
|
||||||
|
if ($invoice->invoice_status_code != 'partial') {
|
||||||
$invoice->invoice_status_code = 'sent';
|
$invoice->invoice_status_code = 'sent';
|
||||||
|
|
||||||
$invoice->save();
|
$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();
|
flash(trans('invoices.messages.email_sent'))->success();
|
||||||
|
|
||||||
@ -705,13 +729,22 @@ class Invoices extends Controller
|
|||||||
} elseif ($invoice->payments()->count() > 1) {
|
} elseif ($invoice->payments()->count() > 1) {
|
||||||
$invoice->invoice_status_code = 'partial';
|
$invoice->invoice_status_code = 'partial';
|
||||||
} else {
|
} else {
|
||||||
$invoice->invoice_status_code = 'draft';
|
$invoice->invoice_status_code = 'sent';
|
||||||
}
|
}
|
||||||
|
|
||||||
$invoice->save();
|
$invoice->save();
|
||||||
|
|
||||||
$payment->delete();
|
$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)]);
|
$message = trans('messages.success.deleted', ['type' => trans_choice('general.invoices', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
|
51
app/Listeners/Updates/Version1115.php
Normal file
51
app/Listeners/Updates/Version1115.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,9 @@ class BillStatus extends Model
|
|||||||
case 'paid':
|
case 'paid':
|
||||||
$label = 'label-success';
|
$label = 'label-success';
|
||||||
break;
|
break;
|
||||||
|
case 'delete':
|
||||||
|
$label = 'label-danger';
|
||||||
|
break;
|
||||||
case 'partial':
|
case 'partial':
|
||||||
case 'received':
|
case 'received':
|
||||||
$label = 'label-warning';
|
$label = 'label-warning';
|
||||||
|
@ -34,6 +34,9 @@ class InvoiceStatus extends Model
|
|||||||
case 'paid':
|
case 'paid':
|
||||||
$label = 'label-success';
|
$label = 'label-success';
|
||||||
break;
|
break;
|
||||||
|
case 'delete':
|
||||||
|
$label = 'label-danger';
|
||||||
|
break;
|
||||||
case 'partial':
|
case 'partial':
|
||||||
case 'sent':
|
case 'sent':
|
||||||
$label = 'label-warning';
|
$label = 'label-warning';
|
||||||
|
@ -22,6 +22,7 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
'App\Listeners\Updates\Version112',
|
'App\Listeners\Updates\Version112',
|
||||||
'App\Listeners\Updates\Version113',
|
'App\Listeners\Updates\Version113',
|
||||||
'App\Listeners\Updates\Version119',
|
'App\Listeners\Updates\Version119',
|
||||||
|
'App\Listeners\Updates\Version1115',
|
||||||
],
|
],
|
||||||
'Illuminate\Auth\Events\Login' => [
|
'Illuminate\Auth\Events\Login' => [
|
||||||
'App\Listeners\Auth\Login',
|
'App\Listeners\Auth\Login',
|
||||||
|
@ -43,6 +43,11 @@ class BillStatuses extends Seeder
|
|||||||
'name' => trans('bills.status.partial'),
|
'name' => trans('bills.status.partial'),
|
||||||
'code' => 'partial',
|
'code' => 'partial',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'company_id' => $company_id,
|
||||||
|
'name' => trans('bills.status.delete'),
|
||||||
|
'code' => 'delete',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'company_id' => $company_id,
|
'company_id' => $company_id,
|
||||||
'name' => trans('bills.status.paid'),
|
'name' => trans('bills.status.paid'),
|
||||||
|
@ -53,6 +53,11 @@ class InvoiceStatuses extends Seeder
|
|||||||
'name' => trans('invoices.status.partial'),
|
'name' => trans('invoices.status.partial'),
|
||||||
'code' => 'partial',
|
'code' => 'partial',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'company_id' => $company_id,
|
||||||
|
'name' => trans('invoices.status.delete'),
|
||||||
|
'code' => 'delete',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'company_id' => $company_id,
|
'company_id' => $company_id,
|
||||||
'name' => trans('invoices.status.paid'),
|
'name' => trans('invoices.status.paid'),
|
||||||
|
@ -113,10 +113,23 @@
|
|||||||
<table class="table">
|
<table class="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach($bill->totals as $total)
|
@foreach($bill->totals as $total)
|
||||||
|
@if ($total->code != 'total')
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ trans($total['name']) }}:</th>
|
<th>{{ trans($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
|
||||||
|
@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
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -113,10 +113,23 @@
|
|||||||
<table class="table">
|
<table class="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach($invoice->totals as $total)
|
@foreach($invoice->totals as $total)
|
||||||
|
@if($total->code != 'total')
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ trans($total['name']) }}:</th>
|
<th>{{ trans($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
|
||||||
|
@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
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -165,7 +165,9 @@
|
|||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
@endif
|
@endif
|
||||||
@permission('update-incomes-invoices')
|
@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>
|
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/sent') }}">{{ trans('invoices.mark_sent') }}</a></li>
|
||||||
|
@endif
|
||||||
@endpermission
|
@endpermission
|
||||||
@if($invoice->customer_email)
|
@if($invoice->customer_email)
|
||||||
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/email') }}">{{ trans('invoices.send_mail') }}</a></li>
|
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/email') }}">{{ trans('invoices.send_mail') }}</a></li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user