Merge pull request #4309 from turbo124/v5-develop

Ninja namespace in resources
This commit is contained in:
David Bomba 2020-11-16 12:20:52 +11:00 committed by GitHub
commit 49e4e77290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 78 additions and 22 deletions

View File

@ -321,9 +321,9 @@ class CheckData extends Command
Client::withTrashed()->cursor()->each(function ($client) use ($wrong_paid_to_dates, $credit_total_applied) {
$total_invoice_payments = 0;
foreach ($client->invoices as $invoice) {
$total_amount = $invoice->payments->sum('pivot.amount');
$total_refund = $invoice->payments->sum('pivot.refunded');
foreach ($client->invoices->where('is_deleted', false) as $invoice) {
$total_amount = $invoice->payments->whereNull('deleted_at')->sum('pivot.amount');
$total_refund = $invoice->payments->whereNull('deleted_at')->sum('pivot.refunded');
$total_invoice_payments += ($total_amount - $total_refund);
}
@ -356,7 +356,7 @@ class CheckData extends Command
$wrong_paid_to_dates = 0;
Client::cursor()->each(function ($client) use ($wrong_balances) {
$client->invoices->where('is_deleted', false)->each(function ($invoice) use ($wrong_balances, $client) {
$client->invoices->where('is_deleted', false)->whereIn('status_id', '!=', Invoice::STATUS_DRAFT)->each(function ($invoice) use ($wrong_balances, $client) {
$total_amount = $invoice->payments->sum('pivot.amount');
$total_refund = $invoice->payments->sum('pivot.refunded');
$total_credit = $invoice->credits->sum('amount');

View File

@ -207,14 +207,17 @@ class InvoiceSum
private function setCalculatedAttributes()
{
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
if ($this->invoice->amount != $this->invoice->balance) {
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision) - $paid_to_date;
} else {
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
if($this->invoice->status_id != Invoice::STATUS_DRAFT)
{
if ($this->invoice->amount != $this->invoice->balance) {
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision) - $paid_to_date;
} else {
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
}
}
/* Set new calculated total */
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);

View File

@ -438,11 +438,13 @@ class PaymentController extends BaseController
*/
public function destroy(DestroyPaymentRequest $request, Payment $payment)
{
$payment->service()->reversePayment();
// $payment->service()->deletePayment();
$payment->is_deleted = true;
$payment->save();
$payment->delete();
// $payment->is_deleted = true;
// $payment->save();
// $payment->delete();
$this->payment_repo->delete($payment);
return $this->itemResponse($payment);
}

View File

@ -69,7 +69,9 @@ class StoreInvoiceRequest extends Request
$input = $this->decodePrimaryKeys($input);
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
$input['amount'] = 0;
$input['balance'] = 0;
$this->replace($input);
}
}

View File

@ -12,9 +12,12 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\SoftDeletes;
class Paymentable extends Pivot
{
use SoftDeletes;
protected $table = 'paymentables';
//protected $dateFormat = 'Y-m-d H:i:s.u';

View File

@ -158,6 +158,7 @@ class BaseRepository
*/
protected function alternativeSave($data, $model)
{
$class = new ReflectionClass($model);
if (array_key_exists('client_id', $data)) {

View File

@ -46,6 +46,7 @@ class MarkSent extends AbstractService
->setStatus(Invoice::STATUS_SENT)
->applyNumber()
->setDueDate()
->updateBalance($this->invoice->amount)
->save();
$this->client->service()->updateBalance($this->invoice->balance)->save();

View File

@ -40,6 +40,7 @@ class DeletePayment
->updateCreditables() //return the credits first
->adjustInvoices()
->updateClient()
->deletePaymentables()
->save();
}
@ -51,6 +52,13 @@ class DeletePayment
//set applied amount to 0
private function deletePaymentables()
{
$this->payment->paymentables()->update(['deleted_at' => now()]);
return $this;
}
private function updateClient()
{
$this->payment->client->service()->updatePaidToDate(-1 * $this->payment->amount)->save();
@ -66,7 +74,7 @@ class DeletePayment
$paymentable_invoice->ledger()->updateInvoiceBalance($paymentable_invoice->pivot->amount)->save();
$paymentable_invoice->client->service()->updateBalance($paymentable_invoice->pivot->amount)->save();
if (floatval($paymentable_invoice->balance) == 0) {
if ($paymentable_invoice->balance == $paymentable_invoice->amount) {
$paymentable_invoice->service()->setStatus(Invoice::STATUS_SENT)->save();
} else {
$paymentable_invoice->service()->setStatus(Invoice::STATUS_PARTIAL)->save();

View File

@ -46,6 +46,7 @@ class PaymentableTransformer extends EntityTransformer
'refunded' => (float) $paymentable->refunded,
'created_at' => (int) $paymentable->created_at,
'updated_at' => (int) $paymentable->updated_at,
'archived_at' => (int) $paymentable->deleted_at,
];
}
}

View File

@ -304,6 +304,8 @@ class HtmlEngine
$data['$product.tax_name2'] = ['value' => '', 'label' => ctrans('texts.tax')];
$data['$product.tax_name3'] = ['value' => '', 'label' => ctrans('texts.tax')];
$data['$product.line_total'] = ['value' => '', 'label' => ctrans('texts.line_total')];
$data['$product.description'] = ['value' => '', 'label' => ctrans('texts.description')];
$data['$product.unit_cost'] = ['value' => '', 'label' => ctrans('texts.unit_cost')];
$data['$task.date'] = ['value' => '', 'label' => ctrans('texts.date')];
$data['$task.discount'] = ['value' => '', 'label' => ctrans('texts.discount')];

View File

@ -617,6 +617,7 @@ trait MakesInvoiceValues
}
$data[$key][$table_type.'.product_key'] = $item->product_key;
$data[$key][$table_type.'.notes'] = $item->notes;
$data[$key][$table_type.'.description'] = $item->notes;
$data[$key][$table_type.'.custom_value1'] = $item->custom_value1;
$data[$key][$table_type.'.custom_value2'] = $item->custom_value2;
@ -625,6 +626,8 @@ trait MakesInvoiceValues
$data[$key][$table_type.'.quantity'] = $item->quantity;
$data[$key][$table_type.'.unit_cost'] = Number::formatMoney($item->cost, $this->client);
$data[$key][$table_type.'.cost'] = Number::formatMoney($item->cost, $this->client);
$data[$key][$table_type.'.line_total'] = Number::formatMoney($item->line_total, $this->client);
if (isset($item->discount) && $item->discount > 0) {

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class SoftDeletePaymentables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('paymentables', function(Blueprint $table){
$table->softDeletes('deleted_at', 6);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -1,7 +1,7 @@
@component('email.template.master', ['design' => 'dark', 'settings' => $settings, 'whitelabel' => $whitelabel])
@slot('header')
@component('email.components.header', ['p' => $body, 'logo' => 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png'])
@component('email.components.header', ['p' => $body, 'logo' => $settings->company_logo ?: 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png'])
@if(isset($title))
{{$title}}

View File

@ -1,7 +1,7 @@
@component('email.template.master', ['design' => 'light', 'settings' => $settings, 'whitelabel' => $whitelabel])
@slot('header')
@component('email.components.header', ['p' => $body, 'logo' => 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png'])
@component('email.components.header', ['p' => $body, 'logo' => $settings->company_logo ?: 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png'])
@if(isset($title))
{{$title}}

View File

@ -56,7 +56,7 @@
<link rel="canonical" href="{{ config('ninja.site_url') }}/{{ request()->path() }}"/>
@if((bool) Ninja::isSelfHost())
@if((bool) \App\Utils\Ninja::isSelfHost())
<style>
{!! $client->getSetting('portal_custom_css') !!}
</style>
@ -67,7 +67,7 @@
{{-- Feel free to push anything to header using @push('header') --}}
@stack('head')
@if((bool) Ninja::isSelfHost())
@if((bool) \App\Utils\Ninja::isSelfHost())
{!! $client->getSetting('portal_custom_head') !!}
@endif
</head>
@ -92,12 +92,12 @@
@yield('footer')
@stack('footer')
@if((bool) Ninja::isSelfHost())
@if((bool) \App\Utils\Ninja::isSelfHost())
{!! $client->getSetting('portal_custom_footer') !!}
@endif
</footer>
@if((bool) Ninja::isSelfHost())
@if((bool) \App\Utils\Ninja::isSelfHost())
<script>
{!! $client->getSetting('portal_custom_js') !!}
</script>