Selaa lähdekoodia

Merge pull request #156 from andrewdwallo/development-3.x

Development 3.x
3.x
Andrew Wallo 5 kuukautta sitten
vanhempi
commit
8c4d2d8bb1
No account linked to committer's email address

+ 24
- 8
app/Models/Accounting/Account.php Näytä tiedosto

@@ -147,24 +147,40 @@ class Account extends Model
147 147
         return $this->hasMany(JournalEntry::class, 'account_id');
148 148
     }
149 149
 
150
-    public static function getAccountsReceivableAccount(): self
150
+    public static function getAccountsReceivableAccount(?int $companyId = null): self
151 151
     {
152
-        return self::where('name', 'Accounts Receivable')->firstOrFail();
152
+        return self::where('name', 'Accounts Receivable')
153
+            ->when($companyId, function (Builder $query) use ($companyId) {
154
+                $query->where('company_id', $companyId);
155
+            })
156
+            ->firstOrFail();
153 157
     }
154 158
 
155
-    public static function getAccountsPayableAccount(): self
159
+    public static function getAccountsPayableAccount(?int $companyId = null): self
156 160
     {
157
-        return self::where('name', 'Accounts Payable')->firstOrFail();
161
+        return self::where('name', 'Accounts Payable')
162
+            ->when($companyId, function (Builder $query) use ($companyId) {
163
+                $query->where('company_id', $companyId);
164
+            })
165
+            ->firstOrFail();
158 166
     }
159 167
 
160
-    public static function getSalesDiscountAccount(): self
168
+    public static function getSalesDiscountAccount(?int $companyId = null): self
161 169
     {
162
-        return self::where('name', 'Sales Discount')->firstOrFail();
170
+        return self::where('name', 'Sales Discount')
171
+            ->when($companyId, function (Builder $query) use ($companyId) {
172
+                $query->where('company_id', $companyId);
173
+            })
174
+            ->firstOrFail();
163 175
     }
164 176
 
165
-    public static function getPurchaseDiscountAccount(): self
177
+    public static function getPurchaseDiscountAccount(?int $companyId = null): self
166 178
     {
167
-        return self::where('name', 'Purchase Discount')->firstOrFail();
179
+        return self::where('name', 'Purchase Discount')
180
+            ->when($companyId, function (Builder $query) use ($companyId) {
181
+                $query->where('company_id', $companyId);
182
+            })
183
+            ->firstOrFail();
168 184
     }
169 185
 
170 186
     protected static function newFactory(): Factory

+ 3
- 3
app/Models/Accounting/Bill.php Näytä tiedosto

@@ -253,7 +253,7 @@ class Bill extends Document
253 253
             'amount' => $formattedAmountForBankCurrency,
254 254
             'payment_method' => $data['payment_method'],
255 255
             'bank_account_id' => $data['bank_account_id'],
256
-            'account_id' => Account::getAccountsPayableAccount()->id,
256
+            'account_id' => Account::getAccountsPayableAccount($this->company_id)->id,
257 257
             'description' => $transactionDescription,
258 258
             'notes' => $data['notes'] ?? null,
259 259
             'meta' => [
@@ -282,7 +282,7 @@ class Bill extends Document
282 282
         $transaction->journalEntries()->create([
283 283
             'company_id' => $this->company_id,
284 284
             'type' => JournalEntryType::Credit,
285
-            'account_id' => Account::getAccountsPayableAccount()->id,
285
+            'account_id' => Account::getAccountsPayableAccount($this->company_id)->id,
286 286
             'amount' => $total,
287 287
             'description' => $baseDescription,
288 288
         ]);
@@ -342,7 +342,7 @@ class Bill extends Document
342 342
                     $transaction->journalEntries()->create([
343 343
                         'company_id' => $this->company_id,
344 344
                         'type' => JournalEntryType::Credit,
345
-                        'account_id' => Account::getPurchaseDiscountAccount()->id,
345
+                        'account_id' => Account::getPurchaseDiscountAccount($this->company_id)->id,
346 346
                         'amount' => CurrencyConverter::convertCentsToFormatSimple($lineItemDiscount),
347 347
                         'description' => "{$lineItemDescription} (Proportional Discount)",
348 348
                     ]);

+ 3
- 3
app/Models/Accounting/Invoice.php Näytä tiedosto

@@ -337,7 +337,7 @@ class Invoice extends Document
337 337
             'amount' => $formattedAmountForBankCurrency,
338 338
             'payment_method' => $data['payment_method'],
339 339
             'bank_account_id' => $data['bank_account_id'],
340
-            'account_id' => Account::getAccountsReceivableAccount()->id,
340
+            'account_id' => Account::getAccountsReceivableAccount($this->company_id)->id,
341 341
             'description' => $transactionDescription,
342 342
             'notes' => $data['notes'] ?? null,
343 343
             'meta' => [
@@ -380,7 +380,7 @@ class Invoice extends Document
380 380
         $transaction->journalEntries()->create([
381 381
             'company_id' => $this->company_id,
382 382
             'type' => JournalEntryType::Debit,
383
-            'account_id' => Account::getAccountsReceivableAccount()->id,
383
+            'account_id' => Account::getAccountsReceivableAccount($this->company_id)->id,
384 384
             'amount' => $total,
385 385
             'description' => $baseDescription,
386 386
         ]);
@@ -430,7 +430,7 @@ class Invoice extends Document
430 430
                     $transaction->journalEntries()->create([
431 431
                         'company_id' => $this->company_id,
432 432
                         'type' => JournalEntryType::Debit,
433
-                        'account_id' => Account::getSalesDiscountAccount()->id,
433
+                        'account_id' => Account::getSalesDiscountAccount($this->company_id)->id,
434 434
                         'amount' => CurrencyConverter::convertCentsToFormatSimple($lineItemDiscount),
435 435
                         'description' => "{$lineItemDescription} (Proportional Discount)",
436 436
                     ]);

Loading…
Peruuta
Tallenna