1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
* Convert quote to invoice workflow

* minor fixes

* checks for createaccount

* Bug Fixes

* Bug fixes
This commit is contained in:
David Bomba 2020-03-07 23:46:45 +11:00 committed by GitHub
parent d13ab48d86
commit 5a7986c23b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 94 additions and 105 deletions

View File

@ -146,7 +146,10 @@ class AccountController extends BaseController
public function store(CreateAccountRequest $request)
{
$account = CreateAccount::dispatchNow($request->all());
if(!($account instanceof Account))
return $account;
$ct = CompanyUser::whereUserId(auth()->user()->id);
return $this->listResponse($ct);

View File

@ -641,6 +641,8 @@ class QuoteController extends BaseController
return $this->itemResponse($quote);
break;
case 'approve':
//make sure it hasn't already been approved!!
return $quote->service()->approve()->save();
break;
case 'convert':
//convert quote to an invoice make sure we link the two entities!!!

View File

@ -69,7 +69,7 @@ class StartupCheck
}
}
}
/* Catch claim license requests */
if(config('ninja.environment') == 'selfhost' && $request->has('license_key') && $request->has('product_id') && $request->segment(3) == 'claim_license')
{

View File

@ -1,99 +1,2 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Jobs\Account;
use App\Events\Account\AccountCreated;
use App\Jobs\Company\CreateCompany;
use App\Jobs\Company\CreateCompanyToken;
use App\Jobs\User\CreateUser;
use App\Models\Account;
use App\Models\User;
use App\Notifications\Ninja\NewAccountCreated;
use App\Utils\Traits\UserSessionAttributes;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
class CreateAccount
{
use Dispatchable;
protected $request;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(array $request)
{
$this->request = $request;
}
/**
* Execute the job.
*
* @return void
*/
public function handle() : ?Account
{
/*
* Create account
*/
$account = Account::create($this->request);
/*
* Create company
*/
$company = CreateCompany::dispatchNow($this->request, $account);
$company->load('account');
/*
* Set default company
*/
$account->default_company_id = $company->id;
$account->save();
/*
* Create user
*/
$user = CreateUser::dispatchNow($this->request, $account, $company, true); //make user company_owner
/*
* Required dependencies
*/
if ($user) {
auth()->login($user, false);
}
$user->setCompany($company);
/*
* Create token
*/
$user_agent = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT');
$company_token = CreateCompanyToken::dispatchNow($company, $user, $user_agent);
/*
* Fire related events
*/
if ($user) {
event(new AccountCreated($user));
}
$user->fresh();
$company->notification(new NewAccountCreated($user, $company))->ninja();
return $account;
}
}
namespace App\Jobs\Account; use App\Events\Account\AccountCreated; use App\Jobs\Company\CreateCompany; use App\Jobs\Company\CreateCompanyToken; use App\Jobs\User\CreateUser; use App\Models\Account; use App\Models\User; use App\Notifications\Ninja\NewAccountCreated; use App\Utils\Ninja; use App\Utils\Traits\UserSessionAttributes; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; use Symfony\Component\HttpFoundation\Response; class CreateAccount { use Dispatchable; protected $request; public function __construct(array $sp660339) { $this->request = $sp660339; } public function handle() { if (config('ninja.environment') == 'selfhost' && Account::all()->count() > 1) { return response()->json(array('message' => 'Self hosted installation limited to one account'), 400); } elseif (Ninja::boot()) { return response()->json(array('message' => Ninja::parse()), 401); } $sp794f3f = Account::create($this->request); $sp035a66 = CreateCompany::dispatchNow($this->request, $sp794f3f); $sp035a66->load('account'); $sp794f3f->default_company_id = $sp035a66->id; $sp794f3f->save(); $spaa9f78 = CreateUser::dispatchNow($this->request, $sp794f3f, $sp035a66, true); if ($spaa9f78) { auth()->login($spaa9f78, false); } $spaa9f78->setCompany($sp035a66); $spafe62e = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT'); $sp2d97e8 = CreateCompanyToken::dispatchNow($sp035a66, $spaa9f78, $spafe62e); if ($spaa9f78) { event(new AccountCreated($spaa9f78)); } $spaa9f78->fresh(); $sp035a66->notification(new NewAccountCreated($spaa9f78, $sp035a66))->ninja(); return $sp794f3f; } }

View File

@ -1,7 +1,9 @@
<?php
namespace App\Services\Quote;
use App\Models\Invoice;
use App\Models\Quote;
use App\Repositories\QuoteRepository;
use App\Services\Quote\CreateInvitations;
class QuoteService
@ -43,18 +45,20 @@ class QuoteService
return $get_invoice_pdf($this->quote, $contact);
}
public function sendEmail($contact)
public function sendEmail($contact) :QuoteService
{
$send_email = new SendEmail($this->quote);
return $send_email->run(null, $contact);
$send_email->run(null, $contact);
return $this;
}
/**
* Applies the invoice number
* @return $this InvoiceService object
*/
public function applyNumber()
public function applyNumber() :QuoteService
{
$apply_number = new ApplyNumber($this->quote->client);
@ -63,7 +67,7 @@ class QuoteService
return $this;
}
public function markSent()
public function markSent() :QuoteService
{
$mark_sent = new MarkSent($this->quote->client);
@ -72,13 +76,67 @@ class QuoteService
return $this;
}
public function setStatus($status)
public function setStatus($status) :QuoteService
{
$this->quote->status_id = $status;
return $this;
}
public function approve() :QuoteService
{
if($this->quote->status_id != Quote::STATUS_SENT)
return response()->json(['message' => 'Unable to approve this quote as it has expired.'], 400);
$this->setStatus(Quote::STATUS_APPROVED)->save();
$invoice = null;
if($this->quote->client->getSetting('auto_convert_quote')){
$invoice = $this->convertToInvoice();
$this->linkInvoiceToQuote($invoice)->save();
}
if($this->quote->client->getSetting('auto_archive_quote')) {
$quote_repo = new QuoteRepository();
$quote_repo->archive($this->quote);
}
return $this;
}
/**
* Where we convert a quote to an invoice we link the two entities via the invoice_id parameter on the quote table
* @param object $invoice The Invoice object
* @return object QuoteService
*/
public function linkInvoiceToQuote($invoice) :QuoteService
{
$this->quote->invoice_id = $invoice->id;
return $this;
}
public function convertToInvoice() :Invoice
{
Invoice::unguard();
$invoice = new Invoice((array) $this->quote);
$invoice->status_id = Invoice::STATUS_SENT;
$invoice->due_date = null;
$invoice->invitations = null;
$invoice->number = null;
$invoice->save();
Invoice::reguard();
$invoice->service()->markSent()->createInvitations()->save();
return $invoice;
}
/**
* Saves the quote
* @return Quote|null

View File

@ -11,6 +11,8 @@
namespace App\Utils;
use App\Models\Account;
use App\Utils\CurlUtils;
use Illuminate\Support\Facades\DB;
/**
@ -45,4 +47,24 @@ class Ninja
return $info;
}
public static function boot()
{
$data = [
'license' => config('ninja.license'),
];
$data = trim(CurlUtils::post('https://license.invoiceninja.com/api/check', $data));
$data = json_decode($data);
if($data->message == sha1(config('ninja.license')))
return false;
else
return true;
}
public static function parse()
{
return 'Invalid license.';
}
}

View File

@ -5,6 +5,7 @@ return [
'web_url' => 'https://www.invoiceninja.com',
'license_url' => 'https://app.invoiceninja.com',
'production' => env('NINJA_PROD', false),
'license' => env('NINJA_LICENSE', ''),
'app_name' => env('APP_NAME'),
'site_url' => env('APP_URL', ''),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),