mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
commit
f0b51b7949
@ -50,7 +50,7 @@ class PostUpdate extends Command
|
||||
info("I wasn't able to migrate the data.");
|
||||
}
|
||||
|
||||
nlog("finished migrating");
|
||||
info("finished migrating");
|
||||
|
||||
$output = [];
|
||||
|
||||
|
@ -63,7 +63,7 @@ class Kernel extends ConsoleKernel
|
||||
|
||||
$schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping();
|
||||
|
||||
$schedule->job(new RecurringExpensesCron)->dailyAt('23:45')->withoutOverlapping();
|
||||
$schedule->job(new RecurringExpensesCron)->dailyAt('00:10')->withoutOverlapping();
|
||||
|
||||
$schedule->job(new AutoBillCron)->dailyAt('00:30')->withoutOverlapping();
|
||||
|
||||
|
@ -15,6 +15,7 @@ namespace App\Http\Controllers\ClientPortal;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ClientPortal\Uploads\StoreUploadRequest;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Account;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Utils\Ninja;
|
||||
@ -26,14 +27,21 @@ use Illuminate\Support\Facades\Auth;
|
||||
class NinjaPlanController extends Controller
|
||||
{
|
||||
|
||||
public function index(string $contact_key, string $company_key)
|
||||
public function index(string $contact_key, string $account_or_company_key)
|
||||
{
|
||||
MultiDB::findAndSetDbByCompanyKey($company_key);
|
||||
$company = Company::where('company_key', $company_key)->first();
|
||||
MultiDB::findAndSetDbByCompanyKey($account_or_company_key);
|
||||
$company = Company::where('company_key', $account_or_company_key)->first();
|
||||
|
||||
if(!$company){
|
||||
MultiDB::findAndSetDbByAccountKey($account_or_company_key);
|
||||
$account = Account::where('key', $account_or_company_key)->first();
|
||||
}
|
||||
else
|
||||
$account = $company->account;
|
||||
|
||||
|
||||
nlog("Ninja Plan Controller Company key found {$company->company_key}");
|
||||
|
||||
$account = $company->account;
|
||||
|
||||
if (MultiDB::findAndSetDbByContactKey($contact_key) && $client_contact = ClientContact::where('contact_key', $contact_key)->first())
|
||||
{
|
||||
|
@ -52,6 +52,9 @@ class AutoBillCron
|
||||
->where('auto_bill_enabled', true)
|
||||
->where('balance', '>', 0)
|
||||
->where('is_deleted', false)
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled',0);
|
||||
})
|
||||
->with('company');
|
||||
|
||||
nlog($auto_bill_partial_invoices->count(). " partial invoices to auto bill");
|
||||
@ -65,6 +68,9 @@ class AutoBillCron
|
||||
->where('auto_bill_enabled', true)
|
||||
->where('balance', '>', 0)
|
||||
->where('is_deleted', false)
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled',0);
|
||||
})
|
||||
->with('company');
|
||||
|
||||
nlog($auto_bill_invoices->count(). " full invoices to auto bill");
|
||||
@ -85,6 +91,9 @@ class AutoBillCron
|
||||
->where('auto_bill_enabled', true)
|
||||
->where('balance', '>', 0)
|
||||
->where('is_deleted', false)
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled',0);
|
||||
})
|
||||
->with('company');
|
||||
|
||||
nlog($auto_bill_partial_invoices->count(). " partial invoices to auto bill db = {$db}");
|
||||
@ -98,6 +107,9 @@ class AutoBillCron
|
||||
->where('auto_bill_enabled', true)
|
||||
->where('balance', '>', 0)
|
||||
->where('is_deleted', false)
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled',0);
|
||||
})
|
||||
->with('company');
|
||||
|
||||
nlog($auto_bill_invoices->count(). " full invoices to auto bill db = {$db}");
|
||||
|
@ -66,6 +66,9 @@ class RecurringExpensesCron
|
||||
->whereNull('deleted_at')
|
||||
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||
->where('remaining_cycles', '!=', '0')
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled',0);
|
||||
})
|
||||
->with('company')
|
||||
->cursor();
|
||||
|
||||
|
@ -53,15 +53,19 @@ class RecurringInvoicesCron
|
||||
$query->where('is_deleted',0)
|
||||
->where('deleted_at', NULL);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled',0);
|
||||
})
|
||||
->with('company')
|
||||
->cursor();
|
||||
|
||||
nlog(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count());
|
||||
|
||||
$recurring_invoices->each(function ($recurring_invoice, $key) {
|
||||
|
||||
nlog("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date);
|
||||
|
||||
if (!$recurring_invoice->company->is_disabled) {
|
||||
nlog("Trying to send {$recurring_invoice->number}");
|
||||
|
||||
try{
|
||||
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
|
||||
@ -69,7 +73,7 @@ class RecurringInvoicesCron
|
||||
catch(\Exception $e){
|
||||
nlog("Unable to sending recurring invoice {$recurring_invoice->id}");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
//multiDB environment, need to
|
||||
@ -86,6 +90,9 @@ class RecurringInvoicesCron
|
||||
$query->where('is_deleted',0)
|
||||
->where('deleted_at', NULL);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled',0);
|
||||
})
|
||||
->with('company')
|
||||
->cursor();
|
||||
|
||||
@ -94,7 +101,7 @@ class RecurringInvoicesCron
|
||||
$recurring_invoices->each(function ($recurring_invoice, $key) {
|
||||
nlog("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date ." Recurring #id = ". $recurring_invoice->id);
|
||||
|
||||
if (!$recurring_invoice->company->is_disabled) {
|
||||
nlog("Trying to send {$recurring_invoice->number}");
|
||||
|
||||
try{
|
||||
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
|
||||
@ -102,7 +109,7 @@ class RecurringInvoicesCron
|
||||
catch(\Exception $e){
|
||||
nlog("Unable to sending recurring invoice {$recurring_invoice->id}");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,11 @@ class SendRecurring implements ShouldQueue
|
||||
// Generate Standard Invoice
|
||||
$invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client);
|
||||
|
||||
if($this->recurring_invoice->auto_bill == "always")
|
||||
$invoice->auto_bill_enabled = true;
|
||||
elseif($this->recurring_invoice->auto_bill == "off")
|
||||
$invoice->auto_bill_enabled = false;
|
||||
|
||||
$invoice->date = now()->format('Y-m-d');
|
||||
$invoice->due_date = $this->recurring_invoice->calculateDueDate(now()->format('Y-m-d'));
|
||||
$invoice->recurring_id = $this->recurring_invoice->id;
|
||||
|
@ -70,6 +70,9 @@ class ReminderJob implements ShouldQueue
|
||||
$query->where('is_deleted',0)
|
||||
->where('deleted_at', NULL);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled',0);
|
||||
})
|
||||
->with('invitations')->cursor()->each(function ($invoice) {
|
||||
|
||||
if ($invoice->isPayable()) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Libraries;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
@ -178,7 +179,7 @@ class MultiDB
|
||||
$current_db = config('database.default');
|
||||
|
||||
foreach (self::$dbs as $db) {
|
||||
if ($ct = ClientContact::on($db)->whereRaw('BINARY `token`= ?', [$token])->first()) {
|
||||
if (ClientContact::on($db)->whereRaw('BINARY `token`= ?', [$token])->exists()) {
|
||||
self::setDb($db);
|
||||
return true;
|
||||
}
|
||||
@ -230,8 +231,8 @@ class MultiDB
|
||||
$current_db = config('database.default');
|
||||
|
||||
foreach (self::$dbs as $db) {
|
||||
if ($ct = CompanyToken::on($db)->whereRaw('BINARY `token`= ?', [$token])->first()) {
|
||||
self::setDb($ct->company->db);
|
||||
if (CompanyToken::on($db)->whereRaw('BINARY `token`= ?', [$token])->exists()) {
|
||||
self::setDb($db);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -246,8 +247,24 @@ class MultiDB
|
||||
$current_db = config('database.default');
|
||||
|
||||
foreach (self::$dbs as $db) {
|
||||
if ($company = Company::on($db)->where('company_key', $company_key)->first()) {
|
||||
self::setDb($company->db);
|
||||
if (Company::on($db)->where('company_key', $company_key)->exists()) {
|
||||
self::setDb($db);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
self::setDB($current_db);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function findAndSetDbByAccountKey($account_key) :bool
|
||||
{
|
||||
$current_db = config('database.default');
|
||||
|
||||
foreach (self::$dbs as $db) {
|
||||
if (Account::on($db)->where('key', $account_key)->exists()) {
|
||||
self::setDb($db);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -262,8 +279,8 @@ class MultiDB
|
||||
$current_db = config('database.default');
|
||||
|
||||
foreach (self::$dbs as $db) {
|
||||
if ($client_contact = ClientContact::on($db)->where('contact_key', $contact_key)->first()) {
|
||||
self::setDb($client_contact->company->db);
|
||||
if (ClientContact::on($db)->where('contact_key', $contact_key)->exists()) {
|
||||
self::setDb($db);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -278,8 +295,8 @@ class MultiDB
|
||||
$current_db = config('database.default');
|
||||
|
||||
foreach (self::$dbs as $db) {
|
||||
if ($client = Client::on($db)->where('client_hash', $client_hash)->first()) {
|
||||
self::setDb($client->company->db);
|
||||
if (Client::on($db)->where('client_hash', $client_hash)->exists()) {
|
||||
self::setDb($db);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -299,7 +316,7 @@ class MultiDB
|
||||
|
||||
foreach (self::$dbs as $db) {
|
||||
if ($company = Company::on($db)->where($query_array)->first()) {
|
||||
self::setDb($company->db);
|
||||
self::setDb($db);
|
||||
return $company;
|
||||
}
|
||||
}
|
||||
@ -315,7 +332,7 @@ class MultiDB
|
||||
$current_db = config('database.default');
|
||||
|
||||
foreach (self::$dbs as $db) {
|
||||
if ($invite = $class::on($db)->whereRaw('BINARY `key`= ?', [$invitation_key])->first()) {
|
||||
if ($invite = $class::on($db)->whereRaw('BINARY `key`= ?', [$invitation_key])->exists()) {
|
||||
self::setDb($db);
|
||||
return true;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ class SupportMessageSent extends Mailable
|
||||
$db = str_replace("db-ninja-", "", $company->db);
|
||||
$is_large = $company->is_large ? "L" : "S";
|
||||
$platform = array_key_exists('platform', $this->data) ? $this->data['platform'] : "U";
|
||||
$migrated = strlen($company->company_key) == 32 ? "M" : "";
|
||||
$migrated = strlen($company->company_key) == 32 ? "M" : "T";
|
||||
|
||||
if(Ninja::isHosted())
|
||||
$subject = "{$priority}Hosted-{$db}-{$is_large}{$platform}{$migrated} :: {$plan} :: ".date('M jS, g:ia');
|
||||
|
@ -34,6 +34,8 @@ class InvoiceObserver
|
||||
->where('event_id', Webhook::EVENT_CREATE_INVOICE)
|
||||
->exists();
|
||||
|
||||
$invoice->load('client');
|
||||
|
||||
if ($subscriptions) {
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company);
|
||||
}
|
||||
@ -51,6 +53,9 @@ class InvoiceObserver
|
||||
->where('event_id', Webhook::EVENT_UPDATE_INVOICE)
|
||||
->exists();
|
||||
|
||||
$invoice->load('client');
|
||||
|
||||
|
||||
if ($subscriptions) {
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company);
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ class QuoteObserver
|
||||
->where('event_id', Webhook::EVENT_CREATE_QUOTE)
|
||||
->exists();
|
||||
|
||||
$quote->load('client');
|
||||
|
||||
if ($subscriptions) {
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote, $quote->company);
|
||||
}
|
||||
@ -47,6 +49,9 @@ class QuoteObserver
|
||||
->where('event_id', Webhook::EVENT_UPDATE_QUOTE)
|
||||
->exists();
|
||||
|
||||
$quote->load('client');
|
||||
|
||||
|
||||
if ($subscriptions) {
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company);
|
||||
}
|
||||
|
@ -270,6 +270,10 @@ class CreditCard
|
||||
if ($api_response->isSuccess()) {
|
||||
$customers = $api_response->getBody();
|
||||
$customers = json_decode($customers);
|
||||
|
||||
if(count(array($api_response->getBody(),1)) == 0)
|
||||
$customers = false;
|
||||
|
||||
} else {
|
||||
$errors = $api_response->getErrors();
|
||||
}
|
||||
|
@ -60,12 +60,16 @@ class ACH
|
||||
'method' => '1',
|
||||
*/
|
||||
|
||||
try{
|
||||
$response = $this->wepay_payment_driver->wepay->request('payment_bank/persist', [
|
||||
'client_id' => config('ninja.wepay.client_id'),
|
||||
'client_secret' => config('ninja.wepay.client_secret'),
|
||||
'payment_bank_id' => (int)$data['bank_account_id'],
|
||||
]);
|
||||
|
||||
}
|
||||
catch(\Exception $e){
|
||||
throw new PaymentFailed($e->getMessage(), 400);
|
||||
}
|
||||
// display the response
|
||||
// nlog($response);
|
||||
|
||||
@ -202,6 +206,7 @@ class ACH
|
||||
|
||||
$app_fee = (config('ninja.wepay.fee_ach_multiplier') * $this->wepay_payment_driver->payment_hash->data->amount_with_fee) + config('ninja.wepay.fee_fixed');
|
||||
|
||||
try{
|
||||
$response = $this->wepay_payment_driver->wepay->request('checkout/create', array(
|
||||
// 'callback_uri' => route('payment_webhook', ['company_key' => $this->wepay_payment_driver->company_gateway->company->company_key, 'company_gateway_id' => $this->wepay_payment_driver->company_gateway->hashed_id]),
|
||||
'unique_id' => Str::random(40),
|
||||
@ -221,6 +226,10 @@ class ACH
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
catch(\Exception $e){
|
||||
throw new PaymentFailed($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
/* Merge all data and store in the payment hash*/
|
||||
$state = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user