Files
opensourcepos/app/Config/OSPOS.php
T
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

80 lines
2.0 KiB
PHP

<?php
namespace Config;
use App\Models\Appconfig;
use CodeIgniter\Cache\CacheInterface;
use CodeIgniter\Config\BaseConfig;
use Config\Database;
/**
* This class holds the configuration options stored from the database so that on launch those settings can be cached
* once in memory. The settings are referenced frequently, so there is a significant performance hit to not storing
* them.
*/
class OSPOS extends BaseConfig
{
public array $settings = [];
public string $commit_sha1 = 'dev';
private CacheInterface $cache;
public function __construct()
{
parent::__construct();
$this->cache = Services::cache();
$this->set_settings();
}
/**
* @return void
*/
public function set_settings(): void
{
$cache = $this->cache->get('settings');
if ($cache) {
$this->settings = decode_array($cache);
return;
}
try {
$db = Database::connect();
$db->resetDataCache();
if (!$db->tableExists('app_config')) {
$this->settings = $this->getDefaultSettings();
return;
}
$appconfig = model(Appconfig::class);
foreach ($appconfig->get_all()->getResult() as $app_config) {
$this->settings[$app_config->key] = $app_config->value;
}
$this->cache->save('settings', encode_array($this->settings));
} catch (\Exception $e) {
$this->settings = $this->getDefaultSettings();
}
}
private function getDefaultSettings(): array
{
return [
'language' => 'english',
'language_code' => 'en',
'company' => 'Home',
'barcode_type' => 'Code39',
'invoice_enable' => '1',
'work_order_enable' => '0',
];
}
/**
* @return void
*/
public function update_settings(): void
{
$this->cache->delete('settings');
$this->set_settings();
}
}