mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 04:07:32 -05:00 
			
		
		
		
	Support passing reference with amount_paid and paid
This commit is contained in:
		
							parent
							
								
									1bae14c337
								
							
						
					
					
						commit
						a5f303f338
					
				@ -14,14 +14,10 @@ namespace App\Services\Invoice;
 | 
				
			|||||||
use App\Events\Invoice\InvoiceWasPaid;
 | 
					use App\Events\Invoice\InvoiceWasPaid;
 | 
				
			||||||
use App\Events\Payment\PaymentWasCreated;
 | 
					use App\Events\Payment\PaymentWasCreated;
 | 
				
			||||||
use App\Factory\PaymentFactory;
 | 
					use App\Factory\PaymentFactory;
 | 
				
			||||||
use App\Jobs\Invoice\InvoiceWorkflowSettings;
 | 
					 | 
				
			||||||
use App\Jobs\Payment\EmailPayment;
 | 
					 | 
				
			||||||
use App\Libraries\Currency\Conversion\CurrencyApi;
 | 
					use App\Libraries\Currency\Conversion\CurrencyApi;
 | 
				
			||||||
use App\Models\Client;
 | 
					 | 
				
			||||||
use App\Models\Invoice;
 | 
					use App\Models\Invoice;
 | 
				
			||||||
use App\Models\Payment;
 | 
					use App\Models\Payment;
 | 
				
			||||||
use App\Services\AbstractService;
 | 
					use App\Services\AbstractService;
 | 
				
			||||||
use App\Services\Client\ClientService;
 | 
					 | 
				
			||||||
use App\Utils\Ninja;
 | 
					use App\Utils\Ninja;
 | 
				
			||||||
use App\Utils\Traits\GeneratesCounter;
 | 
					use App\Utils\Traits\GeneratesCounter;
 | 
				
			||||||
use Illuminate\Support\Carbon;
 | 
					use Illuminate\Support\Carbon;
 | 
				
			||||||
@ -30,15 +26,7 @@ class ApplyPaymentAmount extends AbstractService
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    use GeneratesCounter;
 | 
					    use GeneratesCounter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private $invoice;
 | 
					    public function __construct(private Invoice $invoice, private float $amount, private ?string $reference){}
 | 
				
			||||||
 | 
					 | 
				
			||||||
    private $amount;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function __construct(Invoice $invoice, $amount)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $this->invoice = $invoice;
 | 
					 | 
				
			||||||
        $this->amount = $amount;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -63,7 +51,7 @@ class ApplyPaymentAmount extends AbstractService
 | 
				
			|||||||
        $payment->number = $this->getNextPaymentNumber($this->invoice->client, $payment);
 | 
					        $payment->number = $this->getNextPaymentNumber($this->invoice->client, $payment);
 | 
				
			||||||
        $payment->status_id = Payment::STATUS_COMPLETED;
 | 
					        $payment->status_id = Payment::STATUS_COMPLETED;
 | 
				
			||||||
        $payment->client_id = $this->invoice->client_id;
 | 
					        $payment->client_id = $this->invoice->client_id;
 | 
				
			||||||
        $payment->transaction_reference = ctrans('texts.manual_entry');
 | 
					        $payment->transaction_reference = $this->reference ?: ctrans('texts.manual_entry');
 | 
				
			||||||
        $payment->currency_id = $this->invoice->client->getSetting('currency_id');
 | 
					        $payment->currency_id = $this->invoice->client->getSetting('currency_id');
 | 
				
			||||||
        $payment->is_manual = true;
 | 
					        $payment->is_manual = true;
 | 
				
			||||||
        /* Create a payment relationship to the invoice entity */
 | 
					        /* Create a payment relationship to the invoice entity */
 | 
				
			||||||
 | 
				
			|||||||
@ -42,18 +42,18 @@ class InvoiceService
 | 
				
			|||||||
     * and executes child sub functions.
 | 
					     * and executes child sub functions.
 | 
				
			||||||
     * @return $this InvoiceService object
 | 
					     * @return $this InvoiceService object
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function markPaid()
 | 
					    public function markPaid(?string $reference = null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->removeUnpaidGatewayFees();
 | 
					        $this->removeUnpaidGatewayFees();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->invoice = (new MarkPaid($this->invoice))->run();
 | 
					        $this->invoice = (new MarkPaid($this->invoice, $reference))->run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function applyPaymentAmount($amount)
 | 
					    public function applyPaymentAmount($amount, ?string $reference = null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->invoice = (new ApplyPaymentAmount($this->invoice, $amount))->run();
 | 
					        $this->invoice = (new ApplyPaymentAmount($this->invoice, $amount, $reference))->run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -26,14 +26,9 @@ class MarkPaid extends AbstractService
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    use GeneratesCounter;
 | 
					    use GeneratesCounter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private $invoice;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private $payable_balance;
 | 
					    private $payable_balance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function __construct(Invoice $invoice)
 | 
					    public function __construct(private Invoice $invoice, private ?string $reference){}
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $this->invoice = $invoice;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -73,7 +68,7 @@ class MarkPaid extends AbstractService
 | 
				
			|||||||
        $payment->applied = $this->payable_balance;
 | 
					        $payment->applied = $this->payable_balance;
 | 
				
			||||||
        $payment->status_id = Payment::STATUS_COMPLETED;
 | 
					        $payment->status_id = Payment::STATUS_COMPLETED;
 | 
				
			||||||
        $payment->client_id = $this->invoice->client_id;
 | 
					        $payment->client_id = $this->invoice->client_id;
 | 
				
			||||||
        $payment->transaction_reference = ctrans('texts.manual_entry');
 | 
					        $payment->transaction_reference = $this->reference ?: ctrans('texts.manual_entry');
 | 
				
			||||||
        $payment->currency_id = $this->invoice->client->getSetting('currency_id');
 | 
					        $payment->currency_id = $this->invoice->client->getSetting('currency_id');
 | 
				
			||||||
        $payment->is_manual = true;
 | 
					        $payment->is_manual = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,7 +43,7 @@ class TriggeredActions extends AbstractService
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($this->request->has('paid') && $this->request->input('paid') == 'true') {
 | 
					        if ($this->request->has('paid') && $this->request->input('paid') == 'true') {
 | 
				
			||||||
            $this->invoice = $this->invoice->service()->markPaid()->save(); //update notification sends automatically for this.
 | 
					            $this->invoice = $this->invoice->service()->markPaid($this->request->input('reference'))->save(); //update notification sends automatically for this.
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($this->request->has('mark_sent') && $this->request->input('mark_sent') == 'true' && $this->invoice->status_id == Invoice::STATUS_DRAFT) {
 | 
					        if ($this->request->has('mark_sent') && $this->request->input('mark_sent') == 'true' && $this->invoice->status_id == Invoice::STATUS_DRAFT) {
 | 
				
			||||||
@ -52,7 +52,7 @@ class TriggeredActions extends AbstractService
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        if ($this->request->has('amount_paid') && is_numeric($this->request->input('amount_paid'))) {
 | 
					        if ($this->request->has('amount_paid') && is_numeric($this->request->input('amount_paid'))) {
 | 
				
			||||||
            $this->invoice = $this->invoice->service()->applyPaymentAmount($this->request->input('amount_paid'))->save();
 | 
					            $this->invoice = $this->invoice->service()->applyPaymentAmount($this->request->input('amount_paid'), $this->request->input('reference'))->save();
 | 
				
			||||||
            $this->updated = false;
 | 
					            $this->updated = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user