136 lines
6.1 KiB
PHP
136 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers\Customer;
|
|
|
|
class ServiceHelper extends CustomerHelper
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
|
{
|
|
switch ($field) {
|
|
case 'site':
|
|
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
|
|
$extras['onChange'] = "$('select[name=\'clientinfo_uid\']').select2('open')";
|
|
$form = form_dropdown($field, $viewDatas['formOptions'][$field]['options'], $value, $extras);
|
|
break;
|
|
case 'serverinfo_uid':
|
|
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
|
|
$extras['onChange'] = "document.querySelector('input[name=\'amount\']').value = this.options[this.selectedIndex].getAttribute('data-price')";
|
|
if (array_key_exists('extras', $viewDatas['formOptions'][$field])) {
|
|
$extras = array_merge($extras, $viewDatas['formOptions'][$field]['extras']);
|
|
}
|
|
$form = $this->form_dropdown_custom($field, $viewDatas['formOptions'][$field]['options'], $value, $extras);
|
|
break;
|
|
case 'clientinfo_uid':
|
|
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
|
|
$form = form_dropdown($field, $viewDatas['formOptions'][$field]['options'], $value, $extras);
|
|
break;
|
|
case 'amount':
|
|
$form = form_input($field, 0, ["readonly" => "readonly", ...$extras]);
|
|
break;
|
|
default:
|
|
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $form;
|
|
}
|
|
public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
|
|
{
|
|
switch ($field) {
|
|
case 'serverinfo_uid':
|
|
$value = view_cell("\App\Cells\Equipment\ServerCell::detail", [
|
|
'serviceEntity' => $viewDatas['entity'],
|
|
'template' => 'servicelist',
|
|
]);
|
|
break;
|
|
case 'amount':
|
|
case 'sale':
|
|
$value = number_format($value) . "원";
|
|
break;
|
|
case 'billing_at':
|
|
if (array_key_exists('unPaids', $viewDatas)) {
|
|
if (array_key_exists($viewDatas['entity']->getPK(), $viewDatas['unPaids'])) {
|
|
$value .= sprintf(
|
|
"<div><a href=\"/admin/payment?serviceinfo_uid=%s\"><span style=\"color:red;\">%s개,총 %s원</span></a></div>",
|
|
$viewDatas['entity']->getPK(),
|
|
$viewDatas['unPaids'][$viewDatas['entity']->getPK()]['cnt'],
|
|
number_format($viewDatas['unPaids'][$viewDatas['entity']->getPK()]['amount'])
|
|
);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
$value = parent::getFieldView($field, $value, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $value;
|
|
}
|
|
public function getListLabel(string $field, string $label, array $viewDatas, array $extras = []): string
|
|
{
|
|
switch ($field) {
|
|
case 'serverinfo_uid':
|
|
$label = parent::getListLabel($field, $label, $viewDatas, $extras);
|
|
$label .= "<span class=\"float-start rounded border border-primary\" style=\"cursor:pointer;\" onclick=\"copyServerPartsToClipboard()\">ALL 📋</span>";
|
|
break;
|
|
default:
|
|
$label = parent::getListLabel($field, $label, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $label;
|
|
}
|
|
public function getListButton(string $action, string $label, array $viewDatas, array $extras = []): string
|
|
{
|
|
switch ($action) {
|
|
case 'modify':
|
|
$action = parent::getListButton($action, $label, $viewDatas, $extras);
|
|
break;
|
|
case 'addServer':
|
|
$action = form_label(
|
|
$label ? $label : ICONS['REBOOT'],
|
|
$action,
|
|
[
|
|
"data-src" => "/admin/customer/service/addServer/{$viewDatas['entity']->getPK()}",
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#modal_action_form",
|
|
"class" => "btn btn-sm form-label-sm",
|
|
...$extras
|
|
]
|
|
);
|
|
break;
|
|
case 'onetime':
|
|
$action = form_label(
|
|
$label ? $label : ICONS['ONETIME'],
|
|
$action,
|
|
[
|
|
"data-src" => "/admin/payment/create?serviceinfo_uid={$viewDatas['entity']->getPK()}",
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#modal_action_form",
|
|
"class" => "btn btn-sm form-label-sm",
|
|
...$extras
|
|
]
|
|
);
|
|
break;
|
|
case 'history':
|
|
$action = form_label(
|
|
$label ? $label : ICONS['HISTORY'],
|
|
$action,
|
|
[
|
|
"data-src" => "/admin/customer/service/history?serviceinfo_uid={$viewDatas['entity']->getPK()}&serviceinfo_uid={$viewDatas['entity']->getPK()}&ActionTemplate=popup",
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#modal_action_form",
|
|
"class" => "btn btn-sm btn-primary form-label-sm",
|
|
...$extras
|
|
]
|
|
);
|
|
break;
|
|
default:
|
|
$action = parent::getListButton($action, $label, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $action;
|
|
}
|
|
}
|