materiels/src/www/admin/sorties/stock_disponible.php

68 lines
1.8 KiB
PHP

<?php
namespace Garradin;
use Garradin\Plugin\Materiels\Output;
use Garradin\Plugin\Materiels\Equipment;
use Garradin\Utils;
require_once __DIR__ . '/../_inc.php';
$output = new Output;
$eqmt = new Equipment;
$eqmts_by_cat = $eqmt->ListAllAvailableByCategory();
$selected_eqmt = "";
$kinds = $output->listKinds();
$selected_kind = $kinds[0];
$date = new \DateTime;
$date->setTimestamp(time());
$default_date = $date;
$default_comment = "";
$csrf_key = 'add_output';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
{
$eqmt_id = f('equipment_id');
$eqmt_number = (int) f('equipment_number');
$output_date_format = date_create_from_format(
"d/m/Y", f('output_date'))->format("Y-m-d");
if ($output->PossibilityOwnedEqmtOutput($eqmt_id, $eqmt_number, $output_date_format))
{
$output->add([
'kind' => f('kind'),
'equipment_number' => $eqmt_number,
'equipment_id' => $eqmt_id,
'output_date' => $output_date_format,
'additional_comment' => f('additional_comment'),
]);
Utils::redirect(PLUGIN_URL . 'sorties/index.php');
} else
{
$output_date = f('output_date');
$selected_eqmt = $eqmt_id;
$selected_kind = f('kind');
$default_date = $output_date;
$default_comment = f('additional_comment');
$equiment = $eqmt->get($eqmt_id);
$form->addError(
"Il est impossible de sortir " . (string) $eqmt_number . " " . $equiment->designation . " à la date du " . (string) $output_date . '.');
}
}
$cancel_link = PLUGIN_URL . 'sorties/index.php';
$legend_part = "en stock disponible";
$tpl_materiel_name = "stock_disponible";
$tpl->assign(compact(
'csrf_key', 'cancel_link', 'legend_part', 'tpl_materiel_name',
'kinds', 'selected_eqmt', 'selected_kind', 'default_date', 'default_comment',
'eqmts_by_cat'));
$tpl->display(PLUGIN_ROOT . '/templates/sorties/ajouter_sortie.tpl');