Fixes for default mark down settings

This commit is contained in:
David Bomba 2022-09-05 17:18:08 +10:00
parent 6d9a42fef9
commit 9846a3e18f
8 changed files with 46 additions and 39 deletions

View File

@ -132,7 +132,8 @@ class DemoMode extends Command
'enabled_modules' => 32767, 'enabled_modules' => 32767,
'company_key' => 'KEY', 'company_key' => 'KEY',
'enable_shop_api' => true, 'enable_shop_api' => true,
'markdown_email_enabled' => false, 'markdown_email_enabled' => true,
'markdown_enabled' => false,
]); ]);
$settings = $company->settings; $settings = $company->settings;

View File

@ -46,7 +46,7 @@ class CompanyFactory
$company->enabled_modules = config('ninja.enabled_modules'); //32767;//8191; //4095 $company->enabled_modules = config('ninja.enabled_modules'); //32767;//8191; //4095
$company->default_password_timeout = 1800000; $company->default_password_timeout = 1800000;
$company->markdown_email_enabled = false; $company->markdown_email_enabled = true;
$company->markdown_enabled = false; $company->markdown_enabled = false;
return $company; return $company;

View File

@ -64,7 +64,8 @@ class CreateCompany
$company->custom_fields = new \stdClass; $company->custom_fields = new \stdClass;
$company->default_password_timeout = 1800000; $company->default_password_timeout = 1800000;
$company->client_registration_fields = ClientRegistrationFields::generate(); $company->client_registration_fields = ClientRegistrationFields::generate();
$company->markdown_email_enabled = false; $company->markdown_email_enabled = true;
$company->markdown_enabled = false;
if (Ninja::isHosted()) { if (Ninja::isHosted()) {
$company->subdomain = MultiDB::randomSubdomainGenerator(); $company->subdomain = MultiDB::randomSubdomainGenerator();

View File

@ -12,6 +12,7 @@
namespace App\Services\Client; namespace App\Services\Client;
use App\Models\Client; use App\Models\Client;
use App\Models\Credit;
use App\Services\Client\Merge; use App\Services\Client\Merge;
use App\Services\Client\PaymentMethod; use App\Services\Client\PaymentMethod;
use App\Utils\Number; use App\Utils\Number;
@ -44,8 +45,9 @@ class ClientService
public function updateBalanceAndPaidToDate(float $balance, float $paid_to_date) public function updateBalanceAndPaidToDate(float $balance, float $paid_to_date)
{ {
// $this->client->balance += $amount; // $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 = Client::where('id', $this->client->id)->lockForUpdate()->first();
$this->client->balance += $balance; $this->client->balance += $balance;
@ -81,7 +83,7 @@ class ClientService
public function getCreditBalance() :float public function getCreditBalance() :float
{ {
$credits = $this->client->credits() $credits = Credit::where('client_id', $this->client->id)
->where('is_deleted', false) ->where('is_deleted', false)
->where('balance', '>', 0) ->where('balance', '>', 0)
->where(function ($query) { ->where(function ($query) {
@ -95,7 +97,7 @@ class ClientService
public function getCredits() public function getCredits()
{ {
return $this->client->credits() return Credit::where('client_id', $this->client->id)
->where('is_deleted', false) ->where('is_deleted', false)
->where('balance', '>', 0) ->where('balance', '>', 0)
->where(function ($query) { ->where(function ($query) {

View File

@ -34,6 +34,8 @@ class MarkPaid extends AbstractService
private $invoice; private $invoice;
private $payable_balance;
public function __construct(Invoice $invoice) public function __construct(Invoice $invoice)
{ {
$this->invoice = $invoice; $this->invoice = $invoice;
@ -51,17 +53,17 @@ class MarkPaid extends AbstractService
$this->invoice->service()->markSent()->save(); $this->invoice->service()->markSent()->save();
} }
$payable_balance = $this->invoice->balance; \DB::connection(config('database.default'))->transaction(function () {
\DB::connection(config('database.default'))->transaction(function () use($payable_balance) {
$this->invoice = Invoice::where('id', $this->invoice->id)->lockForUpdate()->first(); $this->invoice = Invoice::where('id', $this->invoice->id)->lockForUpdate()->first();
$this->payable_balance = $this->invoice->balance;
$this->invoice $this->invoice
->service() ->service()
->setExchangeRate() ->setExchangeRate()
->updateBalance($payable_balance * -1) ->updateBalance($this->payable_balance * -1)
->updatePaidToDate($payable_balance) ->updatePaidToDate($this->payable_balance)
->setStatus(Invoice::STATUS_PAID) ->setStatus(Invoice::STATUS_PAID)
->save(); ->save();
@ -70,8 +72,8 @@ class MarkPaid extends AbstractService
/* Create Payment */ /* Create Payment */
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id); $payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);
$payment->amount = $payable_balance; $payment->amount = $this->payable_balance;
$payment->applied = $payable_balance; $payment->applied = $this->payable_balance;
$payment->status_id = Payment::STATUS_COMPLETED; $payment->status_id = Payment::STATUS_COMPLETED;
$payment->client_id = $this->invoice->client_id; $payment->client_id = $this->invoice->client_id;
$payment->transaction_reference = ctrans('texts.manual_entry'); $payment->transaction_reference = ctrans('texts.manual_entry');
@ -99,21 +101,13 @@ class MarkPaid extends AbstractService
/* Create a payment relationship to the invoice entity */ /* Create a payment relationship to the invoice entity */
$payment->invoices()->attach($this->invoice->id, [ $payment->invoices()->attach($this->invoice->id, [
'amount' => $payable_balance, 'amount' => $this->payable_balance,
]); ]);
event('eloquent.created: App\Models\Payment', $payment); event('eloquent.created: App\Models\Payment', $payment);
$this->invoice->next_send_date = null; $this->invoice->next_send_date = null;
// $this->invoice
// ->service()
// ->setExchangeRate()
// ->updateBalance($payment->amount * -1)
// ->updatePaidToDate($payment->amount)
// ->setStatus(Invoice::STATUS_PAID)
// ->save();
$this->invoice $this->invoice
->service() ->service()
->applyNumber() ->applyNumber()
@ -121,16 +115,18 @@ class MarkPaid extends AbstractService
->save(); ->save();
$payment->ledger() $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*/ // /* Get the last record for the client and set the current balance*/
$client = Client::withTrashed()->where('id', $this->invoice->client_id)->lockForUpdate()->first(); // $client = Client::withTrashed()->where('id', $this->invoice->client_id)->lockForUpdate()->first();
$client->paid_to_date += $payment->amount; // $client->paid_to_date += $payment->amount;
$client->balance -= $payment->amount; // $client->balance -= $payment->amount;
$client->save(); // $client->save();
}, 1); // }, 1);
$this->invoice->client->service()->updateBalanceAndPaidToDate($payment->amount, $payment->amount*-1)->save();
$this->invoice = $this->invoice $this->invoice = $this->invoice
->service() ->service()

View File

@ -63,14 +63,16 @@ class MarkSent extends AbstractService
/*Adjust client balance*/ /*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*/ // /* Get the last record for the client and set the current balance*/
$client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); // $client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();
$client->balance += $adjustment; // $client->balance += $adjustment;
$client->save(); // $client->save();
}, 1); // }, 1);
$this->invoice->client->service()->updateBalance($adjustment)->save();
$this->invoice->markInvitationsSent(); $this->invoice->markInvitationsSent();

View File

@ -90,7 +90,10 @@ class DeletePayment
->updateInvoiceBalance($net_deletable, "Adjusting invoice {$paymentable_invoice->number} due to deletion of Payment {$this->payment->number}") ->updateInvoiceBalance($net_deletable, "Adjusting invoice {$paymentable_invoice->number} due to deletion of Payment {$this->payment->number}")
->save(); ->save();
$client = $client->service() $client = $this->payment
->client
->fresh()
->service()
->updateBalance($net_deletable) ->updateBalance($net_deletable)
->save(); ->save();

View File

@ -57,6 +57,8 @@ class MarkInvoicePaidTest extends TestCase
} }
//events are not firing which makes this impossible to control. //events are not firing which makes this impossible to control.
nlog($client_balance);
nlog($invoice_balance);
$this->assertEquals(0.00, $invoice->balance); $this->assertEquals(0.00, $invoice->balance);
$this->assertEquals(($client_balance - $invoice_balance), $client->balance); $this->assertEquals(($client_balance - $invoice_balance), $client->balance);