mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 22:17:35 -05:00 
			
		
		
		
	INA-6 | WIP
This commit is contained in:
		
							parent
							
								
									f4035b7e3b
								
							
						
					
					
						commit
						d1f9235cec
					
				@ -22,6 +22,7 @@ use App\Models\ClientContact;
 | 
			
		||||
use App\Models\CreditInvitation;
 | 
			
		||||
use App\Models\InvoiceInvitation;
 | 
			
		||||
use App\Models\Payment;
 | 
			
		||||
use App\Models\PurchaseOrderInvitation;
 | 
			
		||||
use App\Models\QuoteInvitation;
 | 
			
		||||
use App\Services\ClientPortal\InstantPayment;
 | 
			
		||||
use App\Utils\CurlUtils;
 | 
			
		||||
@ -41,7 +42,7 @@ class InvitationController extends Controller
 | 
			
		||||
    use MakesDates;
 | 
			
		||||
 | 
			
		||||
    public function router(string $entity, string $invitation_key)
 | 
			
		||||
    {   
 | 
			
		||||
    {
 | 
			
		||||
        Auth::logout();
 | 
			
		||||
 | 
			
		||||
        return $this->genericRouter($entity, $invitation_key);
 | 
			
		||||
@ -166,7 +167,7 @@ class InvitationController extends Controller
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        set_time_limit(45);
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        if(Ninja::isHosted())
 | 
			
		||||
            return $this->returnRawPdf($entity, $invitation_key);
 | 
			
		||||
 | 
			
		||||
@ -202,7 +203,7 @@ class InvitationController extends Controller
 | 
			
		||||
        return response()->streamDownload(function () use($file) {
 | 
			
		||||
                echo $file;
 | 
			
		||||
        },  $file_name, $headers);
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function routerForIframe(string $entity, string $client_hash, string $invitation_key)
 | 
			
		||||
@ -228,14 +229,14 @@ class InvitationController extends Controller
 | 
			
		||||
        $invitation = InvoiceInvitation::where('key', $invitation_key)
 | 
			
		||||
                                    ->with('contact.client')
 | 
			
		||||
                                    ->firstOrFail();
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        auth()->guard('contact')->loginUsingId($invitation->contact->id, true);
 | 
			
		||||
 | 
			
		||||
        $invoice = $invitation->invoice;
 | 
			
		||||
 | 
			
		||||
        if($invoice->partial > 0)
 | 
			
		||||
            $amount = round($invoice->partial, (int)$invoice->client->currency()->precision);
 | 
			
		||||
        else 
 | 
			
		||||
        else
 | 
			
		||||
            $amount = round($invoice->balance, (int)$invoice->client->currency()->precision);
 | 
			
		||||
 | 
			
		||||
        $gateways = $invitation->contact->client->service()->getPaymentMethods($amount);
 | 
			
		||||
@ -279,6 +280,10 @@ class InvitationController extends Controller
 | 
			
		||||
            $invite = CreditInvitation::withTrashed()->where('key', $invitation_key)->first();
 | 
			
		||||
            $invite->contact->send_email = false;
 | 
			
		||||
            $invite->contact->save();
 | 
			
		||||
        }elseif($entity == 'purchase_order'){
 | 
			
		||||
            $invite = PurchaseOrderInvitation::withTrashed()->where('key', $invitation_key)->first();
 | 
			
		||||
            $invite->contact->send_email = false;
 | 
			
		||||
            $invite->contact->save();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return abort(404);
 | 
			
		||||
 | 
			
		||||
@ -12,8 +12,12 @@
 | 
			
		||||
namespace App\Models;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
use App\Jobs\Entity\CreateEntityPdf;
 | 
			
		||||
use App\Services\PurchaseOrder\PurchaseOrderService;
 | 
			
		||||
use App\Utils\Ninja;
 | 
			
		||||
use Illuminate\Database\Eloquent\SoftDeletes;
 | 
			
		||||
use Illuminate\Support\Carbon;
 | 
			
		||||
use Illuminate\Support\Facades\Storage;
 | 
			
		||||
 | 
			
		||||
class PurchaseOrder extends BaseModel
 | 
			
		||||
{
 | 
			
		||||
@ -129,11 +133,52 @@ class PurchaseOrder extends BaseModel
 | 
			
		||||
    {
 | 
			
		||||
        return $this->belongsTo(Client::class)->withTrashed();
 | 
			
		||||
    }
 | 
			
		||||
    public function markInvitationsSent()
 | 
			
		||||
    {
 | 
			
		||||
        $this->invitations->each(function ($invitation) {
 | 
			
		||||
            if (! isset($invitation->sent_date)) {
 | 
			
		||||
                $invitation->sent_date = Carbon::now();
 | 
			
		||||
                $invitation->save();
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function pdf_file_path($invitation = null, string $type = 'path', bool $portal = false)
 | 
			
		||||
    {
 | 
			
		||||
        if (! $invitation) {
 | 
			
		||||
 | 
			
		||||
            if($this->invitations()->exists())
 | 
			
		||||
                $invitation = $this->invitations()->first();
 | 
			
		||||
            else{
 | 
			
		||||
                $this->service()->createInvitations();
 | 
			
		||||
                $invitation = $this->invitations()->first();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(!$invitation)
 | 
			
		||||
            throw new \Exception('Hard fail, could not create an invitation - is there a valid contact?');
 | 
			
		||||
 | 
			
		||||
        $file_path = $this->client->credit_filepath($invitation).$this->numberFormatter().'.pdf';
 | 
			
		||||
 | 
			
		||||
        if(Ninja::isHosted() && $portal && Storage::disk(config('filesystems.default'))->exists($file_path)){
 | 
			
		||||
            return Storage::disk(config('filesystems.default'))->{$type}($file_path);
 | 
			
		||||
        }
 | 
			
		||||
        elseif(Ninja::isHosted() && $portal){
 | 
			
		||||
            $file_path = CreateEntityPdf::dispatchNow($invitation,config('filesystems.default'));
 | 
			
		||||
            return Storage::disk(config('filesystems.default'))->{$type}($file_path);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(Storage::disk('public')->exists($file_path))
 | 
			
		||||
            return Storage::disk('public')->{$type}($file_path);
 | 
			
		||||
 | 
			
		||||
        $file_path = CreateEntityPdf::dispatchNow($invitation);
 | 
			
		||||
        return Storage::disk('public')->{$type}($file_path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function invitations()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->hasMany(CreditInvitation::class);
 | 
			
		||||
        return $this->hasMany(PurchaseOrderInvitation::class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function project()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user