ok entry return for rent, next output for borrowed equipment
This commit is contained in:
parent
8fd778ebd3
commit
36784f51da
9 changed files with 96 additions and 31 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue