mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 18:59:09 -04:00
118 lines
3.3 KiB
PHP
118 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Item;
|
|
|
|
class Schedule extends Model
|
|
{
|
|
protected $casts = [
|
|
'data' => 'array',
|
|
];
|
|
|
|
public function getInventory($periode)
|
|
{
|
|
$dispo_id = [];
|
|
$dispo_qt = [];
|
|
$used_id = [];
|
|
$used_qt = [];
|
|
$dispo_item = collect();
|
|
|
|
$string_periode = 'p'.$periode;
|
|
|
|
$inventory = Item::all();
|
|
|
|
foreach ($inventory as $item) {
|
|
array_push($dispo_id, $item->id);
|
|
array_push($dispo_qt, $item->quantity);
|
|
}
|
|
|
|
$n1 = 'n1_'.$string_periode.'_item';
|
|
$items_array = explode("-",$this->$n1);
|
|
if ($items_array[0] == "") {
|
|
unset($items_array[0]);
|
|
}
|
|
$items_array = array_values($items_array);
|
|
if ($items_array != "") {
|
|
foreach ($items_array as $item_array) {
|
|
$items_for = explode(":",$item_array);
|
|
array_push($used_id,$items_for[0]);
|
|
array_push($used_qt,$items_for[1]);
|
|
}
|
|
}
|
|
|
|
$n2 = 'n2_'.$string_periode.'_item';
|
|
$items_array = explode("-",$this->$n2);
|
|
if ($items_array[0] == "") {
|
|
unset($items_array[0]);
|
|
}
|
|
$items_array = array_values($items_array);
|
|
|
|
if ($items_array != "") {
|
|
foreach ($items_array as $item_array) {
|
|
$items_for = explode(":",$item_array);
|
|
array_push($used_id,$items_for[0]);
|
|
array_push($used_qt,$items_for[1]);
|
|
}
|
|
}
|
|
|
|
$n3 = 'n3_'.$string_periode.'_item';
|
|
$items_array = explode("-",$this->$n3);
|
|
if ($items_array[0] == "") {
|
|
unset($items_array[0]);
|
|
}
|
|
$items_array = array_values($items_array);
|
|
if ($items_array != "") {
|
|
foreach ($items_array as $item_array) {
|
|
$items_for = explode(":",$item_array);
|
|
array_push($used_id,$items_for[0]);
|
|
array_push($used_qt,$items_for[1]);
|
|
}
|
|
}
|
|
|
|
for ($i=0; $i < count($used_id); $i++) {
|
|
for ($e=0; $e < count($dispo_id); $e++) {
|
|
if (isset($dispo_id[0])) {
|
|
if ($used_id[$i] == $dispo_id[$e]) {
|
|
$dispo_qt[$e] = $dispo_qt[$e] - $used_qt[$i];
|
|
if ($dispo_qt[$e] < 1) {
|
|
unset($dispo_id[$e]);
|
|
unset($dispo_qt[$e]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$dispo_id = array_values($dispo_id);
|
|
$dispo_qt = array_values($dispo_qt);
|
|
for ($i=0; $i < count($dispo_id); $i++) {
|
|
$this_item = Item::find($dispo_id[$i]);
|
|
$this_item->quantity = $dispo_qt[$i];
|
|
$dispo_item->push($this_item);
|
|
}
|
|
|
|
return $dispo_item;
|
|
}
|
|
|
|
public function getUserToNotify($priority = 0)
|
|
{
|
|
$users = \App\User::all();
|
|
|
|
if($priority == 0)
|
|
{
|
|
$userToNotify = collect();
|
|
foreach ($users as $user) {
|
|
if ($user->getPerm('schedule_notify')) {
|
|
$userToNotify->push($user);
|
|
}
|
|
}
|
|
|
|
return $userToNotify;
|
|
} else if ($priority == 1)
|
|
{
|
|
return $users;
|
|
}
|
|
}
|
|
}
|