listAllReleasedRentByCategory(); $selected_eqmt = ""; // make default date (now) and default comment (empty) $date = new \DateTime; $date->setTimestamp(time()); $default_date = $date; $default_comment = ""; // check if add form is submitted $csrf_key = 'add_entry'; if (f('save') && $form->check($csrf_key) && !$form->hasErrors()) { $eqmt_id = f('equipment_id'); $eqmt_number = (int) f('equipment_number'); $mvt_date_format = date_create_from_format( "d/m/Y", f('mvt_date'))->format("Y-m-d"); // check if it's possible to add this return entry if ($mvt->PossibilityRentEqmtEntry($eqmt_id, $eqmt_number, $mvt_date_format)) { // it's possible, add new entry $mvt->add([ 'side' => 0, 'kind' => 'Retour de location / prêt', 'equipment_number' => $eqmt_number, 'equipment_id' => $eqmt_id, 'mvt_date' => $mvt_date_format, 'additional_comment' => f('additional_comment'), ]); Utils::redirect(PLUGIN_URL . 'mouvements/entrees/index.php'); } else { // not possible, keep the datas submitted as defaults and add error to form $mvt_date = f('mvt_date'); $selected_eqmt = $eqmt_id; $default_date = $mvt_date; $default_comment = f('additional_comment'); $equiment = $eqmt->get($eqmt_id); $form->addError( "Il est impossible de rentrer " . (string) $eqmt_number . " " . $equiment->designation . " à la date du " . (string) $mvt_date . '.'); } } // make default date (now), default number (1) $default_number = "1"; // make cancel link, legend for the title of the form // and the template name for equipment to use in form $cancel_link = PLUGIN_URL . 'mouvements/entrees/index.php'; $legend_part = "en retour de location / prêt"; $tpl_materiel_name = "retour"; // no kinds needed $kinds = false; $selected_kind = false; // send all to template $tpl->assign(compact( 'eqmts_by_cat', 'default_date', 'default_number', 'default_comment', 'cancel_link', 'legend_part', 'tpl_materiel_name', 'csrf_key', 'selected_eqmt', 'kinds', 'selected_kind', )); $tpl->display(PLUGIN_ROOT . '/templates/mouvements/entrees/ajouter_entree.tpl');