1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 12:42:36 +01:00

Proposals

This commit is contained in:
Hillel Coren 2018-02-11 13:09:29 +02:00
parent 09c6debbc9
commit db6cc52faa
9 changed files with 81 additions and 5 deletions

View File

@ -360,6 +360,7 @@ class InitLookup extends Command
DB::statement('truncate lookup_users');
DB::statement('truncate lookup_contacts');
DB::statement('truncate lookup_invitations');
DB::statement('truncate lookup_proposal_invitations');
DB::statement('truncate lookup_account_tokens');
DB::statement('SET FOREIGN_KEY_CHECKS = 1');
}

View File

@ -134,4 +134,11 @@ class ProposalController extends BaseController
return redirect()->to('/proposals');
}
public function download(ProposalRequest $request)
{
$proposal = $request->entity();
}
}

View File

@ -7,6 +7,7 @@ use Closure;
use App\Models\LookupAccount;
use App\Models\LookupContact;
use App\Models\LookupInvitation;
use App\Models\LookupProposalInvitation;
use App\Models\LookupAccountToken;
use App\Models\LookupUser;
use Auth;
@ -43,6 +44,8 @@ class DatabaseLookup
} elseif ($guard == 'contact') {
if ($key = request()->invitation_key) {
LookupInvitation::setServerByField('invitation_key', $key);
} elseif ($key = request()->proposal_invitation_key) {
LookupProposalInvitation::setServerByField('invitation_key', $key);
} elseif ($key = request()->contact_key ?: session('contact_key')) {
LookupContact::setServerByField('contact_key', $key);
} elseif ($key = request()->account_key) {

View File

@ -76,6 +76,7 @@ class PurgeAccountData extends Job
$lookupAccount = LookupAccount::whereAccountKey($account->account_key)->firstOrFail();
DB::table('lookup_contacts')->where('lookup_account_id', '=', $lookupAccount->id)->delete();
DB::table('lookup_invitations')->where('lookup_account_id', '=', $lookupAccount->id)->delete();
DB::table('lookup_proposal_invitations')->where('lookup_account_id', '=', $lookupAccount->id)->delete();
config(['database.default' => $current]);
}

View File

@ -0,0 +1,47 @@
<?php
namespace App\Models;
use Eloquent;
/**
* Class ExpenseCategory.
*/
class LookupProposalInvitation extends LookupModel
{
/**
* @var array
*/
protected $fillable = [
'lookup_account_id',
'invitation_key',
'message_id',
];
public static function updateInvitation($accountKey, $invitation)
{
if (! env('MULTI_DB_ENABLED')) {
return;
}
if (! $invitation->message_id) {
return;
}
$current = config('database.default');
config(['database.default' => DB_NINJA_LOOKUP]);
$lookupAccount = LookupAccount::whereAccountKey($accountKey)
->firstOrFail();
$lookupInvitation = LookupProposalInvitation::whereLookupAccountId($lookupAccount->id)
->whereInvitationKey($invitation->invitation_key)
->firstOrFail();
$lookupInvitation->message_id = $invitation->message_id;
$lookupInvitation->save();
config(['database.default' => $current]);
}
}

View File

@ -3,7 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
//use App\Models\LookupProposalInvitation;
use App\Models\LookupProposalInvitation;
use App\Models\Traits\Inviteable;
/**
@ -60,7 +60,6 @@ class ProposalInvitation extends EntityModel
}
}
/*
ProposalInvitation::creating(function ($invitation)
{
LookupProposalInvitation::createNew($invitation->account->account_key, [
@ -68,7 +67,8 @@ ProposalInvitation::creating(function ($invitation)
]);
});
ProposalInvitation::updating(function ($invitation) {
ProposalInvitation::updating(function ($invitation)
{
$dirty = $invitation->getDirty();
if (array_key_exists('message_id', $dirty)) {
LookupProposalInvitation::updateInvitation($invitation->account->account_key, $invitation);
@ -83,4 +83,3 @@ ProposalInvitation::deleted(function ($invitation)
]);
}
});
*/

View File

@ -128,6 +128,14 @@ class AddSubscriptionFormat extends Migration
$table->unique(['account_id', 'public_id']);
});
Schema::create('lookup_proposal_invitations', function ($table) {
$table->increments('id');
$table->unsignedInteger('lookup_account_id')->index();
$table->string('invitation_key')->unique();
$table->string('message_id')->nullable()->unique();
$table->foreign('lookup_account_id')->references('id')->on('lookup_accounts')->onDelete('cascade');
});
}
/**
@ -150,5 +158,6 @@ class AddSubscriptionFormat extends Migration
Schema::dropIfExists('proposal_snippets');
Schema::dropIfExists('proposal_categories');
Schema::dropIfExists('proposal_invitations');
Schema::dropIfExists('lookup_proposal_invitations');
}
}

View File

@ -57,6 +57,10 @@
->appendIcon(Icon::create('remove-circle'))
->asLinkTo(HTMLUtils::previousUrl('/proposals')) !!}
{!! Button::primary(trans('texts.download_pdf'))
->withAttributes(['onclick' => 'onDownloadClick()'])
->appendIcon(Icon::create('download-alt')) !!}
{!! Button::success(trans("texts.save"))
->submit()
->appendIcon(Icon::create('floppy-disk')) !!}
@ -86,6 +90,10 @@
return true;
}
function onDownloadClick() {
location.href = "{{ url("/proposals/{$proposal->public_id}/download") }}";
}
function loadTemplate() {
var templateId = $('select#proposal_template_id').val();
var template = templateMap[templateId];

View File

@ -227,6 +227,7 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () {
Route::post('proposals/bulk', 'ProposalController@bulk');
Route::get('proposals/{proposals}/edit', 'ProposalController@edit');
Route::get('proposals/{proposals}/download', 'ProposalController@download');
Route::get('proposals/create/{invoice_id?}/{proposal_template_id?}', 'ProposalController@create');
Route::resource('proposals', 'ProposalController');
Route::get('api/proposals', 'ProposalController@getDatatable');