diff --git a/app/Livewire/BoardDispatcher.php b/app/Livewire/BoardDispatcher.php index f5ae18f5..eaeb97f3 100644 --- a/app/Livewire/BoardDispatcher.php +++ b/app/Livewire/BoardDispatcher.php @@ -8,9 +8,14 @@ use Livewire\Component; class BoardDispatcher extends Component { public array $lists = []; + public array $results = []; public array $destLabels = ['DR', 'MR', 'RW', 'DC', 'DM', 'MC', 'AM', 'SW', 'DC', 'DM', 'MC', 'AM', 'SM', 'ST', 'DC', 'DM', 'MC', 'AM', 'DL', 'ML', 'LM']; - public string $boardVersion = ''; + public bool $calculationDisabled = true; + public bool $copyDisabled = true; + public string $calculationColor = 'gray'; + public string $copyColor = 'gray'; + public function mount(array $filters) { @@ -28,6 +33,65 @@ class BoardDispatcher extends Component } } + public function setCalculationButton() + { + $count = 1; + for ($i = 1; $i <= 35; $i++) { + $bayKey = "dest-{$i}"; + + if (isset($this->lists[$bayKey]) && ! empty($this->lists[$bayKey])) { + $count++; + } + } + if ($count > 2) { + $this->calculationDisabled = false; + $this->calculationColor = 'info'; + } else { + $this->calculationDisabled = true; + $this->calculationColor = 'gray'; + } + } + + public function setCopyButton() + { + if (\count($this->results) > 0) { + $this->copyDisabled = false; + $this->copyColor = 'info'; + } else { + $this->copyDisabled = true; + $this->copyColor = 'gray'; + } + } + + public function calculate() + { + $this->results = []; + for ($i = 1; $i <= 35; $i++) { + $bayKey = "dest-{$i}"; + + if (isset($this->lists[$bayKey]) && ! empty($this->lists[$bayKey])) { + $this->results[] = $this->lists[$bayKey][0]; + } + } + + $this->setCopyButton(); + } + + public function copy() + { + $str = '
| ' . $result['name'] . ' | '; + $str .= '' . $result['position'] . ' | '; + $str .= '' . number_format(mt_rand(1, 100) / 100, 2) . ' | '; + $str .= '