Files
opensourcepos/tests/Support/ExpenseFixtureTrait.php
objecttothis f5233b20e6 refactor(cashups): extract value object and focused methods in Cashups controller (#4786)
Introduce a CashupAmounts transfer object and break down large Cashups
controller methods into focused private helpers. Includes a breaking
change to constructor parameter order.

- Add CashupAmounts (TransferObjects/Cashups) to bundle open/transfer/
  closed cash, due, card, and check amounts; reorder constructor params
  to cash-before-due sequence
- Replace positional _calculate_total() with calculateTotal(CashupAmounts),
  eliminating argument-order errors
- Decompose getView() into buildEmployeeLookup(), normalizeCashupInfo(),
  initializeNewCashup(), isPendingClose(), closeCashup(),
  buildReportDateRangeInputs(), applyPaymentTotals(), subtractCashExpenses()
- Decompose postSave() with parseCashupDate() and getCashupAmountsFromPost()
  helpers; update both CashupAmounts call sites to new param order
- Rename snake_case vars/params to camelCase throughout Cashups controller
- Drop stale TODO comments in OSPOS.php and Cashups::getIndex filter block
- Scope escape => false to cashup_headers() note column rather than a
  broad regex exclusion in transform_headers()
- Add CashupFixtureTrait and ExpenseFixtureTrait under tests/Support;
  tighten cashup view test to assertSeeInField on specific form fields

BREAKING CHANGE: CashupAmounts constructor positional argument order
changed — closedAmountCash now precedes closedAmountDue; any callers
passing positional args must swap those two arguments.

Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
2026-11-02 03:59:07 +04:00

40 lines
1.1 KiB
PHP

<?php
namespace Tests\Support;
use App\Models\Expense;
use App\Models\Expense_category;
trait ExpenseFixtureTrait
{
protected function createExpenseCategory(array $overrides = []): int
{
$categoryData = array_merge([
'category_name' => 'Test Category ' . uniqid(),
'category_description' => '',
'deleted' => 0,
], $overrides);
model(Expense_category::class)->save_value($categoryData);
return (int) $categoryData['expense_category_id'];
}
protected function createExpense(int $employeeId, int $categoryId, array $overrides = []): int
{
$expenseData = array_merge([
'date' => date('Y-m-d H:i:s'),
'amount' => 0,
'payment_type' => 'Cash',
'expense_category_id' => $categoryId,
'description' => 'Test expense',
'employee_id' => $employeeId,
'deleted' => 0,
], $overrides);
model(Expense::class)->save_value($expenseData);
return (int) $expenseData['expense_id'];
}
}