ok for validate form of borrowed equipement output, next modify entry
This commit is contained in:
parent
00b6aee6fd
commit
4aacfb204f
BIN
materiels.tar.gz
BIN
materiels.tar.gz
Binary file not shown.
@ -200,4 +200,13 @@ class Equipment
|
||||
}
|
||||
return $eqmts_borrowed_by_cat;
|
||||
}
|
||||
|
||||
public function CalculateNoOwnedByDate($id, $date)
|
||||
{
|
||||
$entries = DB::getInstance()->firstColumn(
|
||||
"SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind = 'Location / Prêt' AND equipment_id = '{$id}' AND entry_date <= '{$date}';");
|
||||
$outputs = DB::getInstance()->firstColumn(
|
||||
"SELECT sum(equipment_number) FROM plugin_materiels_output WHERE kind = 'Retour de location / prêt' AND equipment_id = '{$id}' AND output_date <= '{$date}';");
|
||||
return $entries - $outputs;
|
||||
}
|
||||
}
|
||||
|
@ -55,4 +55,24 @@ class Output
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function PossibilityNoOwnedEqmtOutput($id, $eqmt_number, $date)
|
||||
{
|
||||
$after_output_dates = DB::getInstance()->get(
|
||||
"SELECT output_date FROM plugin_materiels_output WHERE kind = 'Retour de location / prêt' AND equipment_id = '{$id}' AND output_date > '{$date}';");
|
||||
$output_dates = array($date);
|
||||
foreach ($after_output_dates as $row)
|
||||
{
|
||||
array_push($output_dates, $row->output_date);
|
||||
}
|
||||
$eqmt = new Equipment;
|
||||
foreach ($output_dates as $output_date) {
|
||||
$borrowed_eqmt = $eqmt->CalculateNoOwnedByDate($id, $output_date);
|
||||
if ($borrowed_eqmt - $eqmt_number < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
{if $eqmts}
|
||||
<optgroup label="-- {$cat} --">
|
||||
{foreach from=$eqmts item="eqmt"}
|
||||
<option value="{$eqmt.id}"{if ($selected_eqmt !== "") && ($selected_eqmt == $eqmt.id)} selected="selected"{/if}>{$eqmt.designation} - sortie: {$eqmt.borrowed}</option>
|
||||
<option value="{$eqmt.id}"{if ($selected_eqmt !== "") && ($selected_eqmt == $eqmt.id)} selected="selected"{/if}>{$eqmt.designation} - sortie: {$eqmt.released}</option>
|
||||
{/foreach}
|
||||
</optgroup>
|
||||
{/if}
|
||||
|
@ -23,6 +23,35 @@ $csrf_key = 'add_output';
|
||||
|
||||
$eqmts_by_cat = $eqmt->ListAllBorrowedByCategory();
|
||||
|
||||
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->PossibilityNoOwnedEqmtOutput($eqmt_id, $eqmt_number, $output_date_format))
|
||||
{
|
||||
$output->add([
|
||||
'kind' => 'Retour de location / prêt',
|
||||
'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;
|
||||
$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 = "emprunté";
|
||||
$tpl_materiel_name = "emprunte";
|
||||
|
Loading…
Reference in New Issue
Block a user