dbmsv2/app/Cells/Customer/ServiceCell.php
2025-09-18 19:05:17 +09:00

54 lines
1.7 KiB
PHP

<?php
namespace App\Cells\Customer;
use App\Services\Payment\PaymentService;
use App\Services\Customer\ServiceService;
class ServiceCell extends CustomerCell
{
private ?PaymentService $_paymentService = null;
public function __construct()
{
parent::__construct(new ServiceService());
}
final public function getPaymentService(): PaymentService
{
if (!$this->_paymentService) {
$this->_paymentService = new PaymentService();
}
return $this->_paymentService;
}
public function detail(array $params): string
{
$this->getService()->setAction(__FUNCTION__);
$this->getService()->setFormFields();
$this->getService()->setFormFilters();
$this->getService()->setFormRules();
$this->getService()->setFormOptions();
$unPaids = [];
$entities = [];
foreach ($this->getService()->getEntities(['clientinfo_uid' => $params['clientinfo_uid']]) as $entity) {
if (!array_key_exists($entity->getPK(), $unPaids)) {
$unPaids[$entity->getPK()] = ['cnt' => 0, 'amount' => 0];
}
foreach ($this->getPaymentService()->getUnPaids('serviceinfo_uid', ['serviceinfo_uid' => $entity->getPK()]) as $unPaid) {
$unPaids[$entity->getPK()]['cnt'] += $unPaid->cnt;
$unPaids[$entity->getPK()]['amount'] += $unPaid->amount;
}
$entities[] = $entity;
}
$template = array_key_exists('template', $params) ? $params['template'] : __FUNCTION__;
return view('cells/service/' . $template, [
'serviceCellDatas' => [
'control' => $this->getService()->getControlDatas(),
'service' => $this->getService(),
'entities' => $entities,
'unPaids' => $unPaids
]
]);
}
}