mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-12 22:22:32 +01:00
commit
71faa3d18d
@ -20,10 +20,10 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
class DocumentFilters extends QueryFilters
|
||||
{
|
||||
|
||||
public function client_id(int $client_id) :Builder
|
||||
{
|
||||
return $this->builder->where('client_id', $client_id);
|
||||
}
|
||||
// public function client_id(int $client_id) :Builder
|
||||
// {
|
||||
// return $this->builder->where('client_id', $client_id);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Filter based on search text.
|
||||
|
@ -57,7 +57,12 @@ class DocumentController extends Controller
|
||||
{
|
||||
$document = Document::where('hash', $document_hash)->firstOrFail();
|
||||
|
||||
return Storage::disk($document->disk)->download($document->url, $document->name);
|
||||
$headers = [];
|
||||
|
||||
if(request()->input('inline') == 'true')
|
||||
$headers = array_merge($headers, ['Content-Disposition' => 'inline']);
|
||||
|
||||
return Storage::disk($document->disk)->download($document->url, $document->name, $headers);
|
||||
}
|
||||
|
||||
public function downloadMultiple(DownloadMultipleDocumentsRequest $request)
|
||||
|
@ -16,6 +16,7 @@ use App\Events\Invoice\InvoiceWasViewed;
|
||||
use App\Events\Misc\InvitationWasViewed;
|
||||
use App\Events\Quote\QuoteWasViewed;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\Entity\CreateRawPdf;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Payment;
|
||||
@ -106,15 +107,12 @@ class InvitationController extends Controller
|
||||
{
|
||||
switch ($entity_string) {
|
||||
case 'invoice':
|
||||
$invitation->invoice->service()->markSent()->save();
|
||||
event(new InvoiceWasViewed($invitation, $invitation->company, Ninja::eventVars()));
|
||||
break;
|
||||
case 'quote':
|
||||
$invitation->quote->service()->markSent()->save();
|
||||
event(new QuoteWasViewed($invitation, $invitation->company, Ninja::eventVars()));
|
||||
break;
|
||||
case 'credit':
|
||||
$invitation->credit->service()->markSent()->save();
|
||||
event(new CreditWasViewed($invitation, $invitation->company, Ninja::eventVars()));
|
||||
break;
|
||||
default:
|
||||
@ -125,9 +123,43 @@ class InvitationController extends Controller
|
||||
|
||||
public function routerForDownload(string $entity, string $invitation_key)
|
||||
{
|
||||
|
||||
if(Ninja::isHosted())
|
||||
return $this->returnRawPdf($entity, $invitation_key);
|
||||
|
||||
return redirect('client/'.$entity.'/'.$invitation_key.'/download_pdf');
|
||||
}
|
||||
|
||||
private function returnRawPdf(string $entity, string $invitation_key)
|
||||
{
|
||||
|
||||
$key = $entity.'_id';
|
||||
|
||||
$entity_obj = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation';
|
||||
|
||||
$invitation = $entity_obj::whereRaw('BINARY `key`= ?', [$invitation_key])
|
||||
->with('contact.client')
|
||||
->firstOrFail();
|
||||
|
||||
if(!$invitation)
|
||||
return response()->json(["message" => "no record found"], 400);
|
||||
|
||||
$file_name = $invitation->{$entity}->numberFormatter().'.pdf';
|
||||
nlog($file_name);
|
||||
|
||||
$file = CreateRawPdf::dispatchNow($invitation, $invitation->company->db);
|
||||
|
||||
$headers = ['Content-Type' => 'application/pdf'];
|
||||
|
||||
if(request()->input('inline') == 'true')
|
||||
$headers = array_merge($headers, ['Content-Disposition' => 'inline']);
|
||||
|
||||
return response()->streamDownload(function () use($file) {
|
||||
echo $file;
|
||||
}, $file_name, $headers);
|
||||
|
||||
}
|
||||
|
||||
public function routerForIframe(string $entity, string $client_hash, string $invitation_key)
|
||||
{
|
||||
}
|
||||
|
@ -397,7 +397,7 @@ class InvoiceController extends BaseController
|
||||
|
||||
$invoice = $this->invoice_repo->save($request->all(), $invoice);
|
||||
|
||||
$invoice->service()->deletePdf();
|
||||
$invoice->service()->triggeredActions($request)->deletePdf();
|
||||
|
||||
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
|
@ -391,7 +391,9 @@ class QuoteController extends BaseController
|
||||
|
||||
$quote = $this->quote_repo->save($request->all(), $quote);
|
||||
|
||||
$quote->service()->deletePdf();
|
||||
$quote->service()
|
||||
->triggeredActions($request)
|
||||
->deletePdf();
|
||||
|
||||
event(new QuoteWasUpdated($quote, $quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
|
@ -104,9 +104,6 @@ class CreateEntityPdf implements ShouldQueue
|
||||
/* Set customized translations _NOW_ */
|
||||
$t->replace(Ninja::transformTranslations($this->entity->client->getMergedSettings()));
|
||||
|
||||
/*This line of code hurts... it deletes ALL $entity PDFs... this causes a race condition when trying to send an email*/
|
||||
// $this->entity->service()->deletePdf();
|
||||
|
||||
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
|
||||
return (new Phantom)->generate($this->invitation);
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ class CreditViewedActivity implements ShouldQueue
|
||||
{
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
$event->invitation->credit->service()->markSent()->save();
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->invitation->user_id;
|
||||
|
@ -45,6 +45,8 @@ class InvoiceViewedActivity implements ShouldQueue
|
||||
|
||||
$user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->invitation->invoice->user_id;
|
||||
|
||||
$event->invitation->invoice->service()->markSent()->save();
|
||||
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->invitation->company_id;
|
||||
$fields->activity_type_id = Activity::VIEW_INVOICE;
|
||||
|
@ -41,6 +41,8 @@ class QuoteViewedActivity implements ShouldQueue
|
||||
{
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
$event->invitation->quote->service()->markSent()->save();
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$fields->user_id = $event->invitation->quote->user_id;
|
||||
|
@ -43,37 +43,26 @@ class GatewayType extends StaticModel
|
||||
switch ($type) {
|
||||
case self::CREDIT_CARD:
|
||||
return ctrans('texts.credit_card');
|
||||
break;
|
||||
case self::BANK_TRANSFER:
|
||||
return ctrans('texts.bank_transfer');
|
||||
break;
|
||||
case self::PAYPAL:
|
||||
return ctrans('texts.paypal');
|
||||
break;
|
||||
case self::CRYPTO:
|
||||
return ctrans('texts.crypto');
|
||||
break;
|
||||
case self::CUSTOM:
|
||||
return ctrans('texts.custom');
|
||||
break;
|
||||
case self::ALIPAY:
|
||||
return ctrans('texts.alipay');
|
||||
break;
|
||||
case self::SOFORT:
|
||||
return ctrans('texts.sofort');
|
||||
break;
|
||||
case self::APPLE_PAY:
|
||||
return ctrans('texts.apple_pay');
|
||||
break;
|
||||
case self::SEPA:
|
||||
return ctrans('texts.sepa');
|
||||
break;
|
||||
case self::KBC:
|
||||
return ctrans('texts.kbc_cbc');
|
||||
break;
|
||||
case self::BANCONTACT:
|
||||
return ctrans('texts.bancontact');
|
||||
break;
|
||||
|
||||
default:
|
||||
return 'Undefined.';
|
||||
|
@ -164,4 +164,77 @@ class RecurringExpense extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
public function recurringDates()
|
||||
{
|
||||
|
||||
/* Return early if nothing to send back! */
|
||||
if ($this->status_id == RecurringInvoice::STATUS_COMPLETED ||
|
||||
$this->remaining_cycles == 0 ||
|
||||
!$this->next_send_date) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/* Endless - lets send 10 back*/
|
||||
$iterations = $this->remaining_cycles;
|
||||
|
||||
if ($this->remaining_cycles == -1) {
|
||||
$iterations = 10;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
if (!Carbon::parse($this->next_send_date)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$next_send_date = Carbon::parse($this->next_send_date)->copy();
|
||||
|
||||
for ($x=0; $x<$iterations; $x++) {
|
||||
// we don't add the days... we calc the day of the month!!
|
||||
$this->nextDateByFrequency($next_send_date);
|
||||
|
||||
$data[] = [
|
||||
'send_date' => $next_send_date->format('Y-m-d'),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function nextDateByFrequency($date)
|
||||
{
|
||||
$offset = $this->client->timezone_offset();
|
||||
|
||||
switch ($this->frequency_id) {
|
||||
case RecurringInvoice::FREQUENCY_DAILY:
|
||||
return $date->startOfDay()->addDay()->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_WEEKLY:
|
||||
return $date->startOfDay()->addWeek()->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_TWO_WEEKS:
|
||||
return $date->startOfDay()->addWeeks(2)->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
|
||||
return $date->startOfDay()->addWeeks(4)->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_MONTHLY:
|
||||
return $date->startOfDay()->addMonthNoOverflow()->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_TWO_MONTHS:
|
||||
return $date->startOfDay()->addMonthsNoOverflow(2)->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_THREE_MONTHS:
|
||||
return $date->startOfDay()->addMonthsNoOverflow(3)->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
|
||||
return $date->startOfDay()->addMonthsNoOverflow(4)->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_SIX_MONTHS:
|
||||
return $date->addMonthsNoOverflow(6)->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_ANNUALLY:
|
||||
return $date->startOfDay()->addYear()->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_TWO_YEARS:
|
||||
return $date->startOfDay()->addYears(2)->addSeconds($offset);
|
||||
case RecurringInvoice::FREQUENCY_THREE_YEARS:
|
||||
return $date->startOfDay()->addYears(3)->addSeconds($offset);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class RecurringExpenseTransformer extends EntityTransformer
|
||||
*/
|
||||
public function transform(RecurringExpense $recurring_expense)
|
||||
{
|
||||
return [
|
||||
$data = [
|
||||
'id' => $this->encodePrimaryKey($recurring_expense->id),
|
||||
'user_id' => $this->encodePrimaryKey($recurring_expense->user_id),
|
||||
'assigned_user_id' => $this->encodePrimaryKey($recurring_expense->assigned_user_id),
|
||||
@ -102,5 +102,10 @@ class RecurringExpenseTransformer extends EntityTransformer
|
||||
'last_sent_date' => $recurring_expense->last_sent_date ?: '',
|
||||
'next_send_date' => $recurring_expense->next_send_date ?: '',
|
||||
];
|
||||
|
||||
if(request()->has('show_dates') && request()->query('show_dates') == 'true')
|
||||
$data['recurring_dates'] = (array) $recurring_expense->recurringDates();
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ class AddBancontactToPaymentTypes extends Migration
|
||||
{
|
||||
$type = new PaymentType();
|
||||
|
||||
$type->id = 35;
|
||||
$type->id = 36;
|
||||
$type->name = 'Bancontact';
|
||||
$type->gateway_type_id = GatewayType::BANCONTACT;
|
||||
|
||||
|
0
storage/app/public/.gitignore
vendored
Normal file → Executable file
0
storage/app/public/.gitignore
vendored
Normal file → Executable file
Loading…
Reference in New Issue
Block a user