mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for default mark down settings
This commit is contained in:
parent
6d9a42fef9
commit
9846a3e18f
@ -132,7 +132,8 @@ class DemoMode extends Command
|
||||
'enabled_modules' => 32767,
|
||||
'company_key' => 'KEY',
|
||||
'enable_shop_api' => true,
|
||||
'markdown_email_enabled' => false,
|
||||
'markdown_email_enabled' => true,
|
||||
'markdown_enabled' => false,
|
||||
]);
|
||||
|
||||
$settings = $company->settings;
|
||||
|
@ -46,7 +46,7 @@ class CompanyFactory
|
||||
|
||||
$company->enabled_modules = config('ninja.enabled_modules'); //32767;//8191; //4095
|
||||
$company->default_password_timeout = 1800000;
|
||||
$company->markdown_email_enabled = false;
|
||||
$company->markdown_email_enabled = true;
|
||||
$company->markdown_enabled = false;
|
||||
|
||||
return $company;
|
||||
|
@ -64,7 +64,8 @@ class CreateCompany
|
||||
$company->custom_fields = new \stdClass;
|
||||
$company->default_password_timeout = 1800000;
|
||||
$company->client_registration_fields = ClientRegistrationFields::generate();
|
||||
$company->markdown_email_enabled = false;
|
||||
$company->markdown_email_enabled = true;
|
||||
$company->markdown_enabled = false;
|
||||
|
||||
if (Ninja::isHosted()) {
|
||||
$company->subdomain = MultiDB::randomSubdomainGenerator();
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace App\Services\Client;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Services\Client\Merge;
|
||||
use App\Services\Client\PaymentMethod;
|
||||
use App\Utils\Number;
|
||||
@ -44,8 +45,9 @@ class ClientService
|
||||
public function updateBalanceAndPaidToDate(float $balance, float $paid_to_date)
|
||||
{
|
||||
// $this->client->balance += $amount;
|
||||
// $this->client->paid_to_date += $amount;
|
||||
|
||||
\DB::connection(config('database.default'))->transaction(function () use($amount) {
|
||||
\DB::connection(config('database.default'))->transaction(function () use($balance, $paid_to_date) {
|
||||
|
||||
$this->client = Client::where('id', $this->client->id)->lockForUpdate()->first();
|
||||
$this->client->balance += $balance;
|
||||
@ -81,7 +83,7 @@ class ClientService
|
||||
|
||||
public function getCreditBalance() :float
|
||||
{
|
||||
$credits = $this->client->credits()
|
||||
$credits = Credit::where('client_id', $this->client->id)
|
||||
->where('is_deleted', false)
|
||||
->where('balance', '>', 0)
|
||||
->where(function ($query) {
|
||||
@ -95,7 +97,7 @@ class ClientService
|
||||
|
||||
public function getCredits()
|
||||
{
|
||||
return $this->client->credits()
|
||||
return Credit::where('client_id', $this->client->id)
|
||||
->where('is_deleted', false)
|
||||
->where('balance', '>', 0)
|
||||
->where(function ($query) {
|
||||
|
@ -34,6 +34,8 @@ class MarkPaid extends AbstractService
|
||||
|
||||
private $invoice;
|
||||
|
||||
private $payable_balance;
|
||||
|
||||
public function __construct(Invoice $invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
@ -51,17 +53,17 @@ class MarkPaid extends AbstractService
|
||||
$this->invoice->service()->markSent()->save();
|
||||
}
|
||||
|
||||
$payable_balance = $this->invoice->balance;
|
||||
|
||||
\DB::connection(config('database.default'))->transaction(function () use($payable_balance) {
|
||||
\DB::connection(config('database.default'))->transaction(function () {
|
||||
|
||||
$this->invoice = Invoice::where('id', $this->invoice->id)->lockForUpdate()->first();
|
||||
|
||||
$this->payable_balance = $this->invoice->balance;
|
||||
|
||||
$this->invoice
|
||||
->service()
|
||||
->setExchangeRate()
|
||||
->updateBalance($payable_balance * -1)
|
||||
->updatePaidToDate($payable_balance)
|
||||
->updateBalance($this->payable_balance * -1)
|
||||
->updatePaidToDate($this->payable_balance)
|
||||
->setStatus(Invoice::STATUS_PAID)
|
||||
->save();
|
||||
|
||||
@ -70,8 +72,8 @@ class MarkPaid extends AbstractService
|
||||
/* Create Payment */
|
||||
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
||||
|
||||
$payment->amount = $payable_balance;
|
||||
$payment->applied = $payable_balance;
|
||||
$payment->amount = $this->payable_balance;
|
||||
$payment->applied = $this->payable_balance;
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
$payment->client_id = $this->invoice->client_id;
|
||||
$payment->transaction_reference = ctrans('texts.manual_entry');
|
||||
@ -99,21 +101,13 @@ class MarkPaid extends AbstractService
|
||||
|
||||
/* Create a payment relationship to the invoice entity */
|
||||
$payment->invoices()->attach($this->invoice->id, [
|
||||
'amount' => $payable_balance,
|
||||
'amount' => $this->payable_balance,
|
||||
]);
|
||||
|
||||
event('eloquent.created: App\Models\Payment', $payment);
|
||||
|
||||
$this->invoice->next_send_date = null;
|
||||
|
||||
// $this->invoice
|
||||
// ->service()
|
||||
// ->setExchangeRate()
|
||||
// ->updateBalance($payment->amount * -1)
|
||||
// ->updatePaidToDate($payment->amount)
|
||||
// ->setStatus(Invoice::STATUS_PAID)
|
||||
// ->save();
|
||||
|
||||
$this->invoice
|
||||
->service()
|
||||
->applyNumber()
|
||||
@ -121,16 +115,18 @@ class MarkPaid extends AbstractService
|
||||
->save();
|
||||
|
||||
$payment->ledger()
|
||||
->updatePaymentBalance($payable_balance * -1);
|
||||
->updatePaymentBalance($this->payable_balance * -1);
|
||||
|
||||
\DB::connection(config('database.default'))->transaction(function () use ($payment) {
|
||||
// \DB::connection(config('database.default'))->transaction(function () use ($payment) {
|
||||
|
||||
/* Get the last record for the client and set the current balance*/
|
||||
$client = Client::withTrashed()->where('id', $this->invoice->client_id)->lockForUpdate()->first();
|
||||
$client->paid_to_date += $payment->amount;
|
||||
$client->balance -= $payment->amount;
|
||||
$client->save();
|
||||
}, 1);
|
||||
// /* Get the last record for the client and set the current balance*/
|
||||
// $client = Client::withTrashed()->where('id', $this->invoice->client_id)->lockForUpdate()->first();
|
||||
// $client->paid_to_date += $payment->amount;
|
||||
// $client->balance -= $payment->amount;
|
||||
// $client->save();
|
||||
// }, 1);
|
||||
|
||||
$this->invoice->client->service()->updateBalanceAndPaidToDate($payment->amount, $payment->amount*-1)->save();
|
||||
|
||||
$this->invoice = $this->invoice
|
||||
->service()
|
||||
|
@ -63,14 +63,16 @@ class MarkSent extends AbstractService
|
||||
|
||||
/*Adjust client balance*/
|
||||
|
||||
\DB::connection(config('database.default'))->transaction(function () use ($adjustment) {
|
||||
// \DB::connection(config('database.default'))->transaction(function () use ($adjustment) {
|
||||
|
||||
/* Get the last record for the client and set the current balance*/
|
||||
$client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();
|
||||
$client->balance += $adjustment;
|
||||
$client->save();
|
||||
// /* Get the last record for the client and set the current balance*/
|
||||
// $client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();
|
||||
// $client->balance += $adjustment;
|
||||
// $client->save();
|
||||
|
||||
}, 1);
|
||||
// }, 1);
|
||||
|
||||
$this->invoice->client->service()->updateBalance($adjustment)->save();
|
||||
|
||||
$this->invoice->markInvitationsSent();
|
||||
|
||||
|
@ -90,9 +90,12 @@ class DeletePayment
|
||||
->updateInvoiceBalance($net_deletable, "Adjusting invoice {$paymentable_invoice->number} due to deletion of Payment {$this->payment->number}")
|
||||
->save();
|
||||
|
||||
$client = $client->service()
|
||||
->updateBalance($net_deletable)
|
||||
->save();
|
||||
$client = $this->payment
|
||||
->client
|
||||
->fresh()
|
||||
->service()
|
||||
->updateBalance($net_deletable)
|
||||
->save();
|
||||
|
||||
if ($paymentable_invoice->balance == $paymentable_invoice->amount) {
|
||||
$paymentable_invoice->service()->setStatus(Invoice::STATUS_SENT)->save();
|
||||
|
@ -57,6 +57,8 @@ class MarkInvoicePaidTest extends TestCase
|
||||
}
|
||||
|
||||
//events are not firing which makes this impossible to control.
|
||||
nlog($client_balance);
|
||||
nlog($invoice_balance);
|
||||
|
||||
$this->assertEquals(0.00, $invoice->balance);
|
||||
$this->assertEquals(($client_balance - $invoice_balance), $client->balance);
|
||||
|
Loading…
x
Reference in New Issue
Block a user