mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 02:37:34 -05:00 
			
		
		
		
	Merge pull request #7141 from turbo124/v5-develop
Fixes for counter reset
This commit is contained in:
		
						commit
						96243e09a2
					
				@ -119,6 +119,9 @@ class PaymentController extends Controller
 | 
			
		||||
        } else {
 | 
			
		||||
            $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->saveQuietly();
 | 
			
		||||
            $payment->currency_id = $payment->client->getSetting('currency_id');
 | 
			
		||||
            $payment->saveQuietly();
 | 
			
		||||
 | 
			
		||||
            $payment_hash->payment_id = $payment->id;
 | 
			
		||||
 | 
			
		||||
@ -106,6 +106,7 @@ class PaymentRepository extends BaseRepository {
 | 
			
		||||
        $payment->fill($data);
 | 
			
		||||
        $payment->is_manual = true;
 | 
			
		||||
        $payment->status_id = Payment::STATUS_COMPLETED;
 | 
			
		||||
 | 
			
		||||
        $payment->save();
 | 
			
		||||
 | 
			
		||||
        /*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_currency_id = $client_currency;
 | 
			
		||||
            $payment->exchange_currency_id = $company_currency;
 | 
			
		||||
            $payment->currency_id = $client_currency;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -12,6 +12,7 @@
 | 
			
		||||
namespace App\Services\Credit;
 | 
			
		||||
 | 
			
		||||
use App\Factory\PaymentFactory;
 | 
			
		||||
use App\Jobs\Entity\CreateEntityPdf;
 | 
			
		||||
use App\Jobs\Util\UnlinkFile;
 | 
			
		||||
use App\Models\Credit;
 | 
			
		||||
use App\Models\Payment;
 | 
			
		||||
@ -98,6 +99,8 @@ class CreditService
 | 
			
		||||
        if($this->credit->balance > 0)
 | 
			
		||||
            return $this;
 | 
			
		||||
 | 
			
		||||
        $this->markSent();
 | 
			
		||||
 | 
			
		||||
        $payment_repo = new PaymentRepository(new CreditRepository());
 | 
			
		||||
 | 
			
		||||
        //set credit balance to zero
 | 
			
		||||
@ -116,6 +119,7 @@ class CreditService
 | 
			
		||||
        $payment->status_id = Payment::STATUS_COMPLETED;
 | 
			
		||||
        $payment->type_id = PaymentType::CREDIT;
 | 
			
		||||
        $payment->is_manual = true;
 | 
			
		||||
        $payment->currency_id = $this->credit->client->getSetting('currency_id');
 | 
			
		||||
        $payment->date = now();
 | 
			
		||||
 | 
			
		||||
        $payment->saveQuietly();
 | 
			
		||||
@ -132,6 +136,7 @@ class CreditService
 | 
			
		||||
             ->client
 | 
			
		||||
             ->service()
 | 
			
		||||
             ->updatePaidToDate($adjustment)
 | 
			
		||||
             ->setStatus(Credit::STATUS_APPLIED)
 | 
			
		||||
             ->save();
 | 
			
		||||
 | 
			
		||||
        event('eloquent.created: App\Models\Payment', $payment);
 | 
			
		||||
@ -176,6 +181,38 @@ class CreditService
 | 
			
		||||
        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()
 | 
			
		||||
    {
 | 
			
		||||
        $settings = $this->credit->client->getMergedSettings();
 | 
			
		||||
 | 
			
		||||
@ -42,7 +42,7 @@ class MarkSent
 | 
			
		||||
             ->setStatus(Credit::STATUS_SENT)
 | 
			
		||||
             ->applyNumber()
 | 
			
		||||
             ->adjustBalance($this->credit->amount)
 | 
			
		||||
             ->deletePdf()
 | 
			
		||||
             ->touchPdf()
 | 
			
		||||
             ->save();
 | 
			
		||||
 | 
			
		||||
        event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
 | 
			
		||||
 | 
			
		||||
@ -532,41 +532,41 @@ trait GeneratesCounter
 | 
			
		||||
 | 
			
		||||
        switch ($reset_counter_frequency) {
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_DAILY:
 | 
			
		||||
                $new_reset_date = now()->addDay();
 | 
			
		||||
                $new_reset_date = $reset_date->addDay();
 | 
			
		||||
                break;
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_WEEKLY:
 | 
			
		||||
                $new_reset_date = now()->addWeek();
 | 
			
		||||
                $new_reset_date = $reset_date->addWeek();
 | 
			
		||||
                break;
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_TWO_WEEKS:
 | 
			
		||||
                $new_reset_date = now()->addWeeks(2);
 | 
			
		||||
                $new_reset_date = $reset_date->addWeeks(2);
 | 
			
		||||
                break;
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
 | 
			
		||||
                $new_reset_date = now()->addWeeks(4);
 | 
			
		||||
                $new_reset_date = $reset_date->addWeeks(4);
 | 
			
		||||
                break;
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_MONTHLY:
 | 
			
		||||
                $new_reset_date = now()->addMonth();
 | 
			
		||||
                $new_reset_date = $reset_date->addMonth();
 | 
			
		||||
                break;
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_TWO_MONTHS:
 | 
			
		||||
                $new_reset_date = now()->addMonths(2);
 | 
			
		||||
                $new_reset_date = $reset_date->addMonths(2);
 | 
			
		||||
                break;
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_THREE_MONTHS:
 | 
			
		||||
                $new_reset_date = now()->addMonths(3);
 | 
			
		||||
                $new_reset_date = $reset_date->addMonths(3);
 | 
			
		||||
                break;
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
 | 
			
		||||
                $new_reset_date = now()->addMonths(4);
 | 
			
		||||
                $new_reset_date = $reset_date->addMonths(4);
 | 
			
		||||
                break;
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_SIX_MONTHS:
 | 
			
		||||
                $new_reset_date = now()->addMonths(6);
 | 
			
		||||
                $new_reset_date = $reset_date->addMonths(6);
 | 
			
		||||
                break;
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_ANNUALLY:
 | 
			
		||||
                $new_reset_date = now()->addYear();
 | 
			
		||||
                $new_reset_date = $reset_date->addYear();
 | 
			
		||||
                break;
 | 
			
		||||
            case RecurringInvoice::FREQUENCY_TWO_YEARS:
 | 
			
		||||
                $new_reset_date = now()->addYears(2);
 | 
			
		||||
                $new_reset_date = $reset_date->addYears(2);
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
                default:
 | 
			
		||||
                $new_reset_date = now()->addYear();
 | 
			
		||||
                $new_reset_date = $reset_date->addYear();
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user