mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 20:07:31 -05:00 
			
		
		
		
	Merge pull request #5005 from turbo124/v5-develop
Fixes for Quotes not attaching to emails
This commit is contained in:
		
						commit
						2f4544e3bd
					
				@ -1 +1 @@
 | 
				
			|||||||
5.1.10
 | 
					5.1.11
 | 
				
			||||||
@ -26,7 +26,7 @@ class UserVerified
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function __construct(?User $user)
 | 
					    public function __construct(?User $user)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->user = $user ?: auth()->user();
 | 
					        $this->user = property_exists($user, 'id') ? $user : auth()->user();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -44,6 +44,10 @@ class UserVerified
 | 
				
			|||||||
            'errors' => new \stdClass,
 | 
					            'errors' => new \stdClass,
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // nlog(auth()->user()->toArray());
 | 
				
			||||||
 | 
					        // nlog($this->user->toArray());
 | 
				
			||||||
 | 
					        // nlog((bool)$this->user->isVerified());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($this->user && !$this->user->isVerified()) 
 | 
					        if ($this->user && !$this->user->isVerified()) 
 | 
				
			||||||
            return response()->json($error, 403);
 | 
					            return response()->json($error, 403);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
				
			|||||||
@ -89,7 +89,9 @@ class CreditEmailEngine extends BaseEmailEngine
 | 
				
			|||||||
            ->setInvitation($this->invitation);
 | 
					            ->setInvitation($this->invitation);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($this->client->getSetting('pdf_email_attachment') !== false) {
 | 
					        if ($this->client->getSetting('pdf_email_attachment') !== false) {
 | 
				
			||||||
            $this->setAttachments(['path' => $this->credit->pdf_file_path(), 'name' => basename($this->credit->pdf_file_path())]);
 | 
					            $this->setAttachments([$this->credit->pdf_file_path()]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // $this->setAttachments(['path' => $this->credit->pdf_file_path(), 'name' => basename($this->credit->pdf_file_path())]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //attach third party documents
 | 
					        //attach third party documents
 | 
				
			||||||
 | 
				
			|||||||
@ -90,8 +90,8 @@ class QuoteEmailEngine extends BaseEmailEngine
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($this->client->getSetting('pdf_email_attachment') !== false) {
 | 
					        if ($this->client->getSetting('pdf_email_attachment') !== false) {
 | 
				
			||||||
            // $this->setAttachments([$this->quote->pdf_file_path()]);
 | 
					            $this->setAttachments([$this->quote->pdf_file_path()]);
 | 
				
			||||||
            $this->setAttachments(['path' => $this->quote->pdf_file_path(), 'name' => basename($this->quote->pdf_file_path())]);
 | 
					            //$this->setAttachments(['path' => $this->quote->pdf_file_path(), 'name' => basename($this->quote->pdf_file_path())]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -85,6 +85,7 @@ class Company extends BaseModel
 | 
				
			|||||||
        'expense_inclusive_taxes',
 | 
					        'expense_inclusive_taxes',
 | 
				
			||||||
        'session_timeout',
 | 
					        'session_timeout',
 | 
				
			||||||
        'oauth_password_required',
 | 
					        'oauth_password_required',
 | 
				
			||||||
 | 
					        'invoice_task_datelog',
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected $hidden = [
 | 
					    protected $hidden = [
 | 
				
			||||||
 | 
				
			|||||||
@ -91,13 +91,13 @@ class CompanyPresenter extends EntityPresenter
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getSpcQrCode($client_currency, $invoice_number, $balance)
 | 
					    public function getSpcQrCode($client_currency, $invoice_number, $balance_due_raw)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $settings = $this->entity->settings;
 | 
					        $settings = $this->entity->settings;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return 
 | 
					        return 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        "SPC\n0200\n1\nCH860021421411198240K\nK\n{$this->name}\n{$settings->address1}\n{$settings->postal_code} {$settings->city}\n\n\nCH\n\n\n\n\n\n\n\n{$balance}\n{$client_currency}\n\n\n\n\n\n\n\nNON\n\n{$invoice_number}\nEPD\n";
 | 
					        "SPC\n0200\n1\nCH860021421411198240K\nK\n{$this->name}\n{$settings->address1}\n{$settings->postal_code} {$settings->city}\n\n\nCH\n\n\n\n\n\n\n\n{$balance_due_raw}\n{$client_currency}\n\n\n\n\n\n\n\nNON\n\n{$invoice_number}\nEPD\n";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -200,25 +200,27 @@ class Quote extends BaseModel
 | 
				
			|||||||
        return new QuoteService($this);
 | 
					        return new QuoteService($this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function pdf_file_path($invitation = null, string $type = 'url')
 | 
					    public function pdf_file_path($invitation = null, string $type = 'url')
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (! $invitation) {
 | 
					        if (! $invitation) {
 | 
				
			||||||
            $invitation = $this->invitations->where('client_contact_id', $this->client->primary_contact()->first()->id)->first();
 | 
					            $invitation = $this->invitations->first();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $storage_path = Storage::$type($this->client->quote_filepath().$this->number.'.pdf');
 | 
					        $storage_path = Storage::$type($this->client->quote_filepath().$this->number.'.pdf');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (Storage::exists($this->client->quote_filepath().$this->number.'.pdf')) {
 | 
					        nlog($storage_path);
 | 
				
			||||||
            return $storage_path;
 | 
					
 | 
				
			||||||
 | 
					        if (! Storage::exists($this->client->quote_filepath().$this->number.'.pdf')) {
 | 
				
			||||||
 | 
					            event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars()));
 | 
				
			||||||
 | 
					            CreateEntityPdf::dispatchNow($invitation);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars()));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        CreateEntityPdf::dispatchNow($invitation);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return $storage_path;
 | 
					        return $storage_path;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @param int $status
 | 
					     * @param int $status
 | 
				
			||||||
     * @return string
 | 
					     * @return string
 | 
				
			||||||
 | 
				
			|||||||
@ -37,7 +37,7 @@ class CreditObserver
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function updated(Credit $credit)
 | 
					    public function updated(Credit $credit)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        UnlinkFile::dispatchNow(config('filesystems.default'), $credit->client->credit_filepath() . $credit->number.'.pdf');
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -51,8 +51,6 @@ class QuoteObserver
 | 
				
			|||||||
            WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company);
 | 
					            WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        UnlinkFile::dispatchNow(config('filesystems.default'), $quote->client->quote_filepath() . $quote->number.'.pdf');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ return [
 | 
				
			|||||||
    'require_https' => env('REQUIRE_HTTPS', true),
 | 
					    'require_https' => env('REQUIRE_HTTPS', true),
 | 
				
			||||||
    'app_url' => rtrim(env('APP_URL', ''), '/'),
 | 
					    'app_url' => rtrim(env('APP_URL', ''), '/'),
 | 
				
			||||||
    'app_domain' => env('APP_DOMAIN', ''),
 | 
					    'app_domain' => env('APP_DOMAIN', ''),
 | 
				
			||||||
    'app_version' => '5.1.10',
 | 
					    'app_version' => '5.1.11',
 | 
				
			||||||
    'minimum_client_version' => '5.0.16',
 | 
					    'minimum_client_version' => '5.0.16',
 | 
				
			||||||
    'terms_version' => '1.0.1',
 | 
					    'terms_version' => '1.0.1',
 | 
				
			||||||
    'api_secret' => env('API_SECRET', false),
 | 
					    'api_secret' => env('API_SECRET', false),
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Illuminate\Database\Migrations\Migration;
 | 
				
			||||||
 | 
					use Illuminate\Database\Schema\Blueprint;
 | 
				
			||||||
 | 
					use Illuminate\Support\Facades\Schema;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class AddInvoiceTaskDatelogProperty extends Migration
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Run the migrations.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return void
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function up()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        Schema::table('companies', function(Blueprint $table){
 | 
				
			||||||
 | 
					            $table->boolean('invoice_task_datelog')->default(0);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Reverse the migrations.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return void
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function down()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        //
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										55
									
								
								tests/Unit/RangeDetectionTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								tests/Unit/RangeDetectionTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,55 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Invoice Ninja (https://invoiceninja.com).
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @link https://github.com/invoiceninja/invoiceninja source repository
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @license https://opensource.org/licenses/AAL
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					namespace Tests\Unit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Illuminate\Foundation\Testing\DatabaseTransactions;
 | 
				
			||||||
 | 
					use Tests\TestCase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @test
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class RangeDetectionTest extends TestCase
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function setUp() :void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        parent::setUp();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function test_range_detection()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $ranges = [];
 | 
				
			||||||
 | 
					        $ranges[] = [100, 105];
 | 
				
			||||||
 | 
					        $ranges[] = [106, 110];
 | 
				
			||||||
 | 
					        $ranges[] = [110, 115];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $expanded_ranges = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        foreach($ranges as $range)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            $expanded_ranges[] = $this->makeRanges($range);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        foreach($ranges as $range)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private function makeRanges(array $range)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return range($range[0], $range[1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user