ok entry return for rent, next output for borrowed equipment
This commit is contained in:
parent
8fd778ebd3
commit
36784f51da
BIN
materiels.tar.gz
BIN
materiels.tar.gz
Binary file not shown.
|
@ -3,6 +3,7 @@
|
|||
namespace Garradin\Plugin\Materiels;
|
||||
|
||||
use Garradin\DB;
|
||||
use Garradin\Plugin\Materiels\Equipment;
|
||||
|
||||
class Entry
|
||||
{
|
||||
|
@ -31,4 +32,24 @@ class Entry
|
|||
{
|
||||
return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry ORDER BY entry_date DESC;');
|
||||
}
|
||||
|
||||
public function PossibilityRentEqmtEntry($id, $eqmt_number, $date)
|
||||
{
|
||||
$after_entry_dates = DB::getInstance()->get(
|
||||
"SELECT entry_date FROM plugin_materiels_entry WHERE kind = 'Retour de location / prêt' AND equipment_id = '{$id}' AND entry_date > '{$date}';");
|
||||
$entry_dates = array($date);
|
||||
foreach ($after_entry_dates as $row)
|
||||
{
|
||||
array_push($entry_dates, $row->entry_date);
|
||||
}
|
||||
$eqmt = new Equipment;
|
||||
foreach ($entry_dates as $entry_date) {
|
||||
$out_of_stock_eqmt = $eqmt->CalculateOutOfStockByDate($id, $entry_date);
|
||||
if ($out_of_stock_eqmt - $eqmt_number < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ class Equipment
|
|||
return $entries - $outputs;
|
||||
}
|
||||
|
||||
public function GetAllListByCategory()
|
||||
public function AllListsAllByCategory()
|
||||
{
|
||||
$eqmts_by_cat = $this->listAllByCategory();
|
||||
$eqmts_owned_by_cat = array();
|
||||
|
@ -119,7 +119,7 @@ class Equipment
|
|||
return $entries - $outputs;
|
||||
}
|
||||
|
||||
public function GetAvailableListByCategory()
|
||||
public function ListAllAvailableByCategory()
|
||||
{
|
||||
$eqmts_by_cat = $this->listAllByCategory();
|
||||
$eqmts_available_by_cat = array();
|
||||
|
@ -151,4 +151,33 @@ class Equipment
|
|||
'Location / Prêt') AND equipment_id = '{$id}' AND output_date <= '{$date}';");
|
||||
return $entries - $outputs;
|
||||
}
|
||||
|
||||
public function listAllReleasedRentByCategory()
|
||||
{
|
||||
$eqmts_by_cat = $this->listAllByCategory();
|
||||
$eqmts_borrowed_by_cat = array();
|
||||
foreach ($eqmts_by_cat as $cat => $eqmts) {
|
||||
$eqmts_borrowed = array();
|
||||
foreach ($eqmts as $eqmt) {
|
||||
$borrowed = $this->CalculateOutOfStock($eqmt->id);
|
||||
if ($borrowed) {
|
||||
$eqmt->borrowed = $borrowed;
|
||||
array_push($eqmts_borrowed, $eqmt);
|
||||
}
|
||||
}
|
||||
if ($eqmts_borrowed) {
|
||||
$eqmts_borrowed_by_cat[$cat] = $eqmts_borrowed;
|
||||
}
|
||||
}
|
||||
return $eqmts_borrowed_by_cat;
|
||||
}
|
||||
|
||||
public function CalculateOutOfStockByDate($id, $date)
|
||||
{
|
||||
$entries = DB::getInstance()->firstColumn(
|
||||
"SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind = 'Retour de 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 = 'Location / Prêt' AND equipment_id = '{$id}' AND output_date <= '{$date}';");
|
||||
return $outputs - $entries;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
{if $eqmts}
|
||||
<optgroup label="-- {$cat} --">
|
||||
{foreach from=$eqmts item="eqmt"}
|
||||
<option value="{$eqmt.id}">{$eqmt.designation}</option>
|
||||
<option value="{$eqmt.id}"{if ($selected_eqmt !== "") && ($selected_eqmt == $eqmt.id)} selected="selected"{/if}>{$eqmt.designation} - sortie: {$eqmt.borrowed}</option>
|
||||
{/foreach}
|
||||
</optgroup>
|
||||
{/if}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
{/if}
|
||||
{/foreach}
|
||||
|
||||
<h2>Matériel dont l'association n'est pas propriétaire (loué ou prêté)</h2>
|
||||
<h2>Matériel dont l'association n'est pas propriétaire (emprunté)</h2>
|
||||
{foreach from=$eqmts_no_owned_by_cat key='cat' item="eqmts"}
|
||||
{if $eqmts}
|
||||
<h3>{$cat}</h3>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
{foreach from=$eqmts_by_cat key='cat' item="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} - (dispo: {$eqmt.available})</option>
|
||||
<option value="{$eqmt.id}"{if ($selected_eqmt !== "") && ($selected_eqmt == $eqmt.id)} selected="selected"{/if}>{$eqmt.designation} - dispo: {$eqmt.available}</option>
|
||||
{/foreach}
|
||||
</optgroup>
|
||||
{/foreach}
|
||||
|
|
|
@ -8,36 +8,51 @@ use Garradin\Utils;
|
|||
|
||||
require_once __DIR__ . '/../_inc.php';
|
||||
|
||||
$csrf_key = 'add_entry';
|
||||
|
||||
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||||
{
|
||||
if ($form->check($csrf_key) && !$form->hasErrors())
|
||||
{
|
||||
$entry = new Entry;
|
||||
$entry_date_format = date_create_from_format(
|
||||
"d/m/Y", f('entry_date'))->format("Y-m-d");
|
||||
$entry->add([
|
||||
'kind' => 'Retour de location / prêt',
|
||||
'equipment_number' => (int) f('equipment_number'),
|
||||
'equipment_id' => f('equipment_id'),
|
||||
'entry_date' => $entry_date_format,
|
||||
'additional_comment' => f('additional_comment'),
|
||||
]);
|
||||
Utils::redirect(PLUGIN_URL . 'entrees/index.php');
|
||||
}
|
||||
}
|
||||
|
||||
$entry = new Entry;
|
||||
$eqmt = new Equipment;
|
||||
$eqmts_by_cat = $eqmt->listAllByCategory();
|
||||
|
||||
$eqmts_by_cat = $eqmt->listAllReleasedRentByCategory();
|
||||
$selected_eqmt = "";
|
||||
|
||||
$date = new \DateTime;
|
||||
$date->setTimestamp(time());
|
||||
$default_date = $date;
|
||||
|
||||
$default_number = "1";
|
||||
$default_comment = "";
|
||||
|
||||
$csrf_key = 'add_entry';
|
||||
|
||||
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||||
{
|
||||
$eqmt_id = f('equipment_id');
|
||||
$eqmt_number = (int) f('equipment_number');
|
||||
$entry_date_format = date_create_from_format(
|
||||
"d/m/Y", f('entry_date'))->format("Y-m-d");
|
||||
if ($entry->PossibilityRentEqmtEntry($eqmt_id, $eqmt_number, $entry_date_format))
|
||||
{
|
||||
$entry->add([
|
||||
'kind' => 'Retour de location / prêt',
|
||||
'equipment_number' => $eqmt_number,
|
||||
'equipment_id' => $eqmt_id,
|
||||
'entry_date' => $entry_date_format,
|
||||
'additional_comment' => f('additional_comment'),
|
||||
]);
|
||||
Utils::redirect(PLUGIN_URL . 'entrees/index.php');
|
||||
} else
|
||||
{
|
||||
$entry_date = f('entry_date');
|
||||
$selected_eqmt = $eqmt_id;
|
||||
$default_date = $entry_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) $entry_date . '.');
|
||||
}
|
||||
}
|
||||
|
||||
$default_number = "1";
|
||||
|
||||
$cancel_link = PLUGIN_URL . 'entrees/index.php';
|
||||
$legend_part = "en retour de location / prêt";
|
||||
$tpl_materiel_name = "retour";
|
||||
|
@ -45,7 +60,7 @@ $tpl_materiel_name = "retour";
|
|||
$tpl->assign(compact(
|
||||
'eqmts_by_cat', 'default_date', 'default_number',
|
||||
'default_comment', 'cancel_link', 'legend_part',
|
||||
'tpl_materiel_name', 'csrf_key'
|
||||
'tpl_materiel_name', 'csrf_key', 'selected_eqmt',
|
||||
));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/entrees/ajouter_entree.tpl');
|
||||
|
|
|
@ -15,7 +15,7 @@ $eqmt = new Equipment;
|
|||
|
||||
list(
|
||||
$eqmts_owned_by_cat, $eqmts_no_owned_by_cat,
|
||||
$eqmts_just_listed_by_cat) = $eqmt->GetAllListByCategory();
|
||||
$eqmts_just_listed_by_cat) = $eqmt->AllListsAllByCategory();
|
||||
|
||||
$tpl->assign(compact(
|
||||
'eqmts_owned_by_cat', 'eqmts_no_owned_by_cat',
|
||||
|
|
|
@ -11,7 +11,7 @@ require_once __DIR__ . '/../_inc.php';
|
|||
$output = new Output;
|
||||
$eqmt = new Equipment;
|
||||
|
||||
$eqmts_by_cat = $eqmt->GetAvailableListByCategory();
|
||||
$eqmts_by_cat = $eqmt->ListAllAvailableByCategory();
|
||||
$selected_eqmt = "";
|
||||
|
||||
$kinds = $output->listKinds();
|
||||
|
@ -49,7 +49,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
|||
$default_date = $output_date;
|
||||
$default_comment = f('additional_comment');
|
||||
|
||||
$equiment = $eqmt->get(f('equipment_id'));
|
||||
$equiment = $eqmt->get($eqmt_id);
|
||||
$form->addError(
|
||||
"Il est impossible de sortir " . (string) $eqmt_number . " " . $equiment->designation . " à la date du " . (string) $output_date . '.');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue