ok entry return for rent, next output for borrowed equipment

This commit is contained in:
JBthePenguin 2021-06-11 10:57:16 +02:00
parent 8fd778ebd3
commit 36784f51da
9 changed files with 96 additions and 31 deletions

View file

@ -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;
}
}