Fixes for vendor country

This commit is contained in:
David Bomba 2024-11-02 11:09:24 +11:00
parent 226909a9d7
commit ef3864b85b
2 changed files with 34 additions and 0 deletions

View File

@ -51,6 +51,9 @@ class VendorRepository extends BaseRepository
$vendor->fill($saveable_vendor);
if(!$vendor->country_id)
$vendor->country_id = auth()->user()->company()->country()->id ?? 840;
$vendor->saveQuietly();
$vendor->service()->applyNumber();

View File

@ -96,6 +96,37 @@ class ClientService
public function updateBalanceAndPaidToDate(float $balance, float $paid_to_date)
{
// refactor to calculated balances.
// $ib = Invoice::withTrashed()
// ->where('client_id', $this->client->id)
// ->whereIn('status_id', [2,3])
// ->where('is_deleted',0)
// ->where('is_proforma',0)
// ->sum('balance');
// $payments = Payment::withTrashed()
// ->where('client_id', $this->client->id)
// ->whereIn('status_id', [1,4,5,6])
// ->where('is_deleted',0)
// ->sum(\DB::raw('amount - refunded'));
// $credit_payments = Payment::where('client_id', $this->client->id)
// ->where('is_deleted', 0)
// ->join('paymentables', 'payments.id', '=', 'paymentables.payment_id')
// ->where('paymentables.paymentable_type', \App\Models\Credit::class)
// ->whereNull('paymentables.deleted_at')
// ->where('paymentables.amount', '>', 0)
// ->sum(DB::raw('paymentables.amount - paymentables.refunded'));
// $credits_from_reversal = \App\Models\Credit::withTrashed()
// ->where('client_id', $this->client->id)
// ->where('is_deleted', 0)
// ->whereNotNull('invoice_id')
// ->sum('amount');
// $paid_to_date = $payments+$credit_payments-$credits_from_reversal;
try {
DB::connection(config('database.default'))->transaction(function () use ($balance, $paid_to_date) {
$this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();