1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Merge pull request #7141 from turbo124/v5-develop

Fixes for counter reset
This commit is contained in:
David Bomba 2022-01-20 09:30:06 +11:00 committed by GitHub
commit 96243e09a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 13 deletions

View File

@ -119,6 +119,9 @@ class PaymentController extends Controller
} else { } else {
$payment = PaymentFactory::create($payment_hash->fee_invoice->company_id, $payment_hash->fee_invoice->user_id); $payment = PaymentFactory::create($payment_hash->fee_invoice->company_id, $payment_hash->fee_invoice->user_id);
$payment->client_id = $payment_hash->fee_invoice->client_id; $payment->client_id = $payment_hash->fee_invoice->client_id;
$payment->saveQuietly();
$payment->currency_id = $payment->client->getSetting('currency_id');
$payment->saveQuietly(); $payment->saveQuietly();
$payment_hash->payment_id = $payment->id; $payment_hash->payment_id = $payment->id;

View File

@ -106,6 +106,7 @@ class PaymentRepository extends BaseRepository {
$payment->fill($data); $payment->fill($data);
$payment->is_manual = true; $payment->is_manual = true;
$payment->status_id = Payment::STATUS_COMPLETED; $payment->status_id = Payment::STATUS_COMPLETED;
$payment->save(); $payment->save();
/*Save documents*/ /*Save documents*/
@ -207,6 +208,7 @@ class PaymentRepository extends BaseRepository {
$payment->exchange_rate = $exchange_rate->exchangeRate($client_currency, $company_currency, Carbon::parse($payment->date)); $payment->exchange_rate = $exchange_rate->exchangeRate($client_currency, $company_currency, Carbon::parse($payment->date));
// $payment->exchange_currency_id = $client_currency; // $payment->exchange_currency_id = $client_currency;
$payment->exchange_currency_id = $company_currency; $payment->exchange_currency_id = $company_currency;
$payment->currency_id = $client_currency;
} }

View File

@ -12,6 +12,7 @@
namespace App\Services\Credit; namespace App\Services\Credit;
use App\Factory\PaymentFactory; use App\Factory\PaymentFactory;
use App\Jobs\Entity\CreateEntityPdf;
use App\Jobs\Util\UnlinkFile; use App\Jobs\Util\UnlinkFile;
use App\Models\Credit; use App\Models\Credit;
use App\Models\Payment; use App\Models\Payment;
@ -98,6 +99,8 @@ class CreditService
if($this->credit->balance > 0) if($this->credit->balance > 0)
return $this; return $this;
$this->markSent();
$payment_repo = new PaymentRepository(new CreditRepository()); $payment_repo = new PaymentRepository(new CreditRepository());
//set credit balance to zero //set credit balance to zero
@ -116,6 +119,7 @@ class CreditService
$payment->status_id = Payment::STATUS_COMPLETED; $payment->status_id = Payment::STATUS_COMPLETED;
$payment->type_id = PaymentType::CREDIT; $payment->type_id = PaymentType::CREDIT;
$payment->is_manual = true; $payment->is_manual = true;
$payment->currency_id = $this->credit->client->getSetting('currency_id');
$payment->date = now(); $payment->date = now();
$payment->saveQuietly(); $payment->saveQuietly();
@ -132,6 +136,7 @@ class CreditService
->client ->client
->service() ->service()
->updatePaidToDate($adjustment) ->updatePaidToDate($adjustment)
->setStatus(Credit::STATUS_APPLIED)
->save(); ->save();
event('eloquent.created: App\Models\Payment', $payment); event('eloquent.created: App\Models\Payment', $payment);
@ -176,6 +181,38 @@ class CreditService
return $this; return $this;
} }
/**
* Sometimes we need to refresh the
* PDF when it is updated etc.
* @return InvoiceService
*/
public function touchPdf($force = false)
{
try {
if($force){
$this->credit->invitations->each(function ($invitation) {
CreateEntityPdf::dispatchNow($invitation);
});
return $this;
}
$this->credit->invitations->each(function ($invitation) {
CreateEntityPdf::dispatch($invitation);
});
}
catch(\Exception $e){
nlog("failed creating invoices in Touch PDF");
}
return $this;
}
public function fillDefaults() public function fillDefaults()
{ {
$settings = $this->credit->client->getMergedSettings(); $settings = $this->credit->client->getMergedSettings();

View File

@ -42,7 +42,7 @@ class MarkSent
->setStatus(Credit::STATUS_SENT) ->setStatus(Credit::STATUS_SENT)
->applyNumber() ->applyNumber()
->adjustBalance($this->credit->amount) ->adjustBalance($this->credit->amount)
->deletePdf() ->touchPdf()
->save(); ->save();
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));

View File

@ -532,41 +532,41 @@ trait GeneratesCounter
switch ($reset_counter_frequency) { switch ($reset_counter_frequency) {
case RecurringInvoice::FREQUENCY_DAILY: case RecurringInvoice::FREQUENCY_DAILY:
$new_reset_date = now()->addDay(); $new_reset_date = $reset_date->addDay();
break; break;
case RecurringInvoice::FREQUENCY_WEEKLY: case RecurringInvoice::FREQUENCY_WEEKLY:
$new_reset_date = now()->addWeek(); $new_reset_date = $reset_date->addWeek();
break; break;
case RecurringInvoice::FREQUENCY_TWO_WEEKS: case RecurringInvoice::FREQUENCY_TWO_WEEKS:
$new_reset_date = now()->addWeeks(2); $new_reset_date = $reset_date->addWeeks(2);
break; break;
case RecurringInvoice::FREQUENCY_FOUR_WEEKS: case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
$new_reset_date = now()->addWeeks(4); $new_reset_date = $reset_date->addWeeks(4);
break; break;
case RecurringInvoice::FREQUENCY_MONTHLY: case RecurringInvoice::FREQUENCY_MONTHLY:
$new_reset_date = now()->addMonth(); $new_reset_date = $reset_date->addMonth();
break; break;
case RecurringInvoice::FREQUENCY_TWO_MONTHS: case RecurringInvoice::FREQUENCY_TWO_MONTHS:
$new_reset_date = now()->addMonths(2); $new_reset_date = $reset_date->addMonths(2);
break; break;
case RecurringInvoice::FREQUENCY_THREE_MONTHS: case RecurringInvoice::FREQUENCY_THREE_MONTHS:
$new_reset_date = now()->addMonths(3); $new_reset_date = $reset_date->addMonths(3);
break; break;
case RecurringInvoice::FREQUENCY_FOUR_MONTHS: case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
$new_reset_date = now()->addMonths(4); $new_reset_date = $reset_date->addMonths(4);
break; break;
case RecurringInvoice::FREQUENCY_SIX_MONTHS: case RecurringInvoice::FREQUENCY_SIX_MONTHS:
$new_reset_date = now()->addMonths(6); $new_reset_date = $reset_date->addMonths(6);
break; break;
case RecurringInvoice::FREQUENCY_ANNUALLY: case RecurringInvoice::FREQUENCY_ANNUALLY:
$new_reset_date = now()->addYear(); $new_reset_date = $reset_date->addYear();
break; break;
case RecurringInvoice::FREQUENCY_TWO_YEARS: case RecurringInvoice::FREQUENCY_TWO_YEARS:
$new_reset_date = now()->addYears(2); $new_reset_date = $reset_date->addYears(2);
break; break;
default: default:
$new_reset_date = now()->addYear(); $new_reset_date = $reset_date->addYear();
break; break;
} }