mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
credit payment type
This commit is contained in:
parent
8b3fafa19c
commit
1b2922b57c
@ -60,15 +60,15 @@ class BaseController extends Controller
|
||||
|
||||
private $first_load = [
|
||||
'account',
|
||||
'user.company_user.token.company_user',
|
||||
//'token.company_user',
|
||||
'user.company_user',
|
||||
'token.company_user',
|
||||
'company.activities',
|
||||
'company.designs.company',
|
||||
'company.task_statuses',
|
||||
'company.expense_categories',
|
||||
'company.documents',
|
||||
'company.users.company_user',
|
||||
'company.clients.contacts',
|
||||
'company.clients.contacts.company',
|
||||
'company.clients.gateway_tokens',
|
||||
'company.clients.documents',
|
||||
'company.company_gateways.gateway',
|
||||
@ -93,11 +93,11 @@ class BaseController extends Controller
|
||||
'company.quotes.invitations.contact',
|
||||
'company.quotes.invitations.company',
|
||||
'company.quotes.documents',
|
||||
'company.tasks',
|
||||
'company.tasks.documents',
|
||||
'company.tax_rates',
|
||||
'company.tokens_hashed',
|
||||
'company.vendors.contacts',
|
||||
'company.vendors.contacts.company',
|
||||
'company.vendors.documents',
|
||||
'company.webhooks',
|
||||
];
|
||||
|
||||
@ -427,7 +427,8 @@ class BaseController extends Controller
|
||||
|
||||
public function flutterRoute()
|
||||
{
|
||||
if ((bool) $this->checkAppSetup() !== false && Schema::hasTable('accounts') && $account = Account::first()) {
|
||||
// if ((bool) $this->checkAppSetup() !== false && Schema::hasTable('accounts') && $account = Account::first()) {
|
||||
if ((bool) $this->checkAppSetup() !== false && $account = Account::first()) {
|
||||
if (config('ninja.require_https') && ! request()->isSecure()) {
|
||||
return redirect()->secure(request()->getRequestUri());
|
||||
}
|
||||
|
@ -42,12 +42,8 @@ class StoreProjectRequest extends Request
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
|
||||
if (array_key_exists('client_id', $input) && is_string($input['client_id'])) {
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
|
@ -36,12 +36,8 @@ class UpdateProjectRequest extends Request
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
|
||||
if (array_key_exists('client_id', $input) && is_string($input['client_id'])) {
|
||||
unset($input['client_id']);
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
}
|
||||
|
@ -37,49 +37,17 @@ class StoreTaskRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
$rules = [];
|
||||
/* Ensure we have a client name, and that all emails are unique*/
|
||||
//$rules['name'] = 'required|min:1';
|
||||
//$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
|
||||
|
||||
// $rules['number'] = new UniqueTaskNumberRule($this->all());
|
||||
|
||||
|
||||
return $rules;
|
||||
|
||||
return $this->globalRules($rules);
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
$input = $this->all();
|
||||
|
||||
if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
}
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
|
||||
if (array_key_exists('client_id', $input) && is_string($input['client_id'])) {
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) {
|
||||
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('project_id', $input) && is_string($input['project_id'])) {
|
||||
$input['project_id'] = $this->decodePrimaryKey($input['project_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('invoice_id', $input) && is_string($input['invoice_id'])) {
|
||||
$input['invoice_id'] = $this->decodePrimaryKey($input['invoice_id']);
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
// public function messages()
|
||||
// {
|
||||
// // return [
|
||||
// // 'unique' => ctrans('validation.unique', ['attribute' => 'email']),
|
||||
// // //'required' => trans('validation.required', ['attribute' => 'email']),
|
||||
// // 'contacts.*.email.required' => ctrans('validation.email', ['attribute' => 'email']),
|
||||
// // ];
|
||||
// }
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class UpdateTaskRequest extends Request
|
||||
$rules['number'] = 'unique:tasks,number,'.$this->id.',id,company_id,'.$this->taskss->company_id;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
return $this->globalRules($rules);
|
||||
}
|
||||
|
||||
// public function messages()
|
||||
@ -58,28 +58,9 @@ class UpdateTaskRequest extends Request
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
}
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
|
||||
if (array_key_exists('client_id', $input) && is_string($input['client_id'])) {
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) {
|
||||
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('project_id', $input) && is_string($input['project_id'])) {
|
||||
$input['project_id'] = $this->decodePrimaryKey($input['project_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('invoice_id', $input) && is_string($input['invoice_id'])) {
|
||||
$input['invoice_id'] = $this->decodePrimaryKey($input['invoice_id']);
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
$this->replace($input);
|
||||
}
|
||||
}
|
||||
|
140
app/Jobs/Entity/CreateEntityPdf.php
Normal file
140
app/Jobs/Entity/CreateEntityPdf.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Entity Ninja (https://entityninja.com).
|
||||
*
|
||||
* @link https://github.com/entityninja/entityninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Entity Ninja LLC (https://entityninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Jobs\Entity;
|
||||
|
||||
use App\Designs\Custom;
|
||||
use App\Designs\Designer;
|
||||
use App\Designs\Modern;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\Design;
|
||||
use App\Models\Entity;
|
||||
use App\Models\Quote;
|
||||
use App\Services\PdfMaker\Design as PdfDesignModel;
|
||||
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
||||
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Utils\Traits\MakesEntityHtml;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\NumberFormatter;
|
||||
use App\Utils\Traits\Pdf\PdfMaker;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Spatie\Browsershot\Browsershot;
|
||||
|
||||
class CreateEntityPdf implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesEntityHtml, PdfMaker, MakesHash;
|
||||
|
||||
public $entity;
|
||||
|
||||
public $company;
|
||||
|
||||
public $contact;
|
||||
|
||||
private $disk;
|
||||
|
||||
public $invitation;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($invitation)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
|
||||
if($invitation->invoice)
|
||||
$this->entity = $invitation->invoice;
|
||||
elseif($invitation->quote)
|
||||
$this->entity = $invitation->quote;
|
||||
elseif($invitation->credit))
|
||||
$this->entity = $invitation->credit;
|
||||
|
||||
$this->company = $invitation->company;
|
||||
|
||||
$this->contact = $invitation->contact;
|
||||
|
||||
$this->disk = $disk ?? config('filesystems.default');
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
if (config('ninja.phantomjs_key')) {
|
||||
return (new Phantom)->generate($this->invitation);
|
||||
}
|
||||
|
||||
App::setLocale($this->contact->preferredLocale());
|
||||
|
||||
if($this->entity instanceof Invoice)
|
||||
$path = $this->entity->client->invoice_filepath();
|
||||
elseif($this->entity instanceof Quote)
|
||||
$path = $this->entity->client->quote_filepath();
|
||||
elseif($this->entity instanceof Credit)
|
||||
$path = $this->entity->client->credit_filepath();
|
||||
|
||||
$file_path = $path.$this->entity->number.'.pdf';
|
||||
|
||||
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting('invoice_design_id'));
|
||||
|
||||
$design = Design::find($entity_design_id);
|
||||
$html = new HtmlEngine(null, $this->invitation, 'entity');
|
||||
|
||||
if ($design->is_custom) {
|
||||
$options = [
|
||||
'custom_partials' => json_decode(json_encode($design->design), true)
|
||||
];
|
||||
$template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options);
|
||||
} else {
|
||||
$template = new PdfMakerDesign(strtolower($design->name));
|
||||
}
|
||||
|
||||
$state = [
|
||||
'template' => $template->elements([
|
||||
'client' => $this->entity->client,
|
||||
'entity' => $this->entity,
|
||||
'pdf_variables' => (array) $this->entity->company->settings->pdf_variables,
|
||||
'products' => $design->design->product,
|
||||
]),
|
||||
'variables' => $html->generateLabelsAndValues(),
|
||||
'options' => [
|
||||
'all_pages_header' => $this->entity->client->getSetting('all_pages_header'),
|
||||
'all_pages_footer' => $this->entity->client->getSetting('all_pages_footer'),
|
||||
],
|
||||
];
|
||||
|
||||
$maker = new PdfMakerService($state);
|
||||
|
||||
$maker
|
||||
->design($template)
|
||||
->build();
|
||||
|
||||
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily
|
||||
Storage::makeDirectory($path, 0775);
|
||||
|
||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||
|
||||
$instance = Storage::disk($this->disk)->put($file_path, $pdf);
|
||||
|
||||
return $file_path;
|
||||
}
|
||||
}
|
@ -98,6 +98,8 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'gateway_tokens',
|
||||
'documents'
|
||||
//'currency',
|
||||
// 'primary_contact',
|
||||
// 'country',
|
||||
|
@ -31,6 +31,7 @@ class PaymentTypesSeeder extends Seeder
|
||||
const GATEWAY_TYPE_APPLE_PAY = 11;
|
||||
const GATEWAY_TYPE_CUSTOM2 = 12;
|
||||
const GATEWAY_TYPE_CUSTOM3 = 13;
|
||||
const GATEWAY_TYPE_CREDIT = 13;
|
||||
|
||||
public function run()
|
||||
{
|
||||
@ -69,6 +70,7 @@ class PaymentTypesSeeder extends Seeder
|
||||
['name' => 'SEPA', 'gateway_type_id' => self::GATEWAY_TYPE_SEPA],
|
||||
['name' => 'GoCardless', 'gateway_type_id' => self::GATEWAY_TYPE_GOCARDLESS],
|
||||
['name' => 'Crypto', 'gateway_type_id' => self::GATEWAY_TYPE_CRYPTO],
|
||||
['name' => 'Credit', 'gateway_type_id' => self::GATEWAY_TYPE_CREDIT],
|
||||
];
|
||||
|
||||
$x = 1;
|
||||
|
@ -3285,5 +3285,7 @@ return [
|
||||
|
||||
'credit_subject' => 'New credit :number from :account',
|
||||
'credit_message' => 'To view your credit for :amount, click the link below.',
|
||||
'payment_type_Crypto' => 'Cryptocurrency',
|
||||
'payment_type_Credit' => 'Credit',
|
||||
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user