Andrew Wallo 5 个月前
父节点
当前提交
b02e29ee88
共有 3 个文件被更改,包括 30 次插入14 次删除
  1. 24
    8
      app/Models/Accounting/Account.php
  2. 3
    3
      app/Models/Accounting/Bill.php
  3. 3
    3
      app/Models/Accounting/Invoice.php

+ 24
- 8
app/Models/Accounting/Account.php 查看文件

147
         return $this->hasMany(JournalEntry::class, 'account_id');
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
     protected static function newFactory(): Factory
186
     protected static function newFactory(): Factory

+ 3
- 3
app/Models/Accounting/Bill.php 查看文件

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

+ 3
- 3
app/Models/Accounting/Invoice.php 查看文件

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

正在加载...
取消
保存