diff --git a/materiels.tar.gz b/materiels.tar.gz index 92c9038..a0baec7 100644 Binary files a/materiels.tar.gz and b/materiels.tar.gz differ diff --git a/src/lib/Entry.php b/src/lib/Entry.php deleted file mode 100644 index 3881ff7..0000000 --- a/src/lib/Entry.php +++ /dev/null @@ -1,91 +0,0 @@ -insert('plugin_materiels_entry', $data); - } - - public function get($id) - { - return DB::getInstance()->first('SELECT * FROM plugin_materiels_entry WHERE id = ?;', $id); - } - - public function delete($id) - { - DB::getInstance()->delete('plugin_materiels_entry', 'id = ' . $id); - } - - public function listAll() - { - return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry ORDER BY entry_date DESC;'); - } - - public function listAllByEquipment($eqmt_id) - { - return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry WHERE equipment_id = ? ORDER BY entry_date DESC;', $eqmt_id); - } - - 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; - } - - public function PossibilityDeleteEntry($entry) - { - $output = new Output; - if ($entry->kind == 'Location / Prêt') - { - return $output->PossibilityNoOwnedEqmtOutput( - $entry->equipment_id, $entry->equipment_number, $entry->entry_date); - } else - { - return $output->PossibilityOwnedEqmtOutput( - $entry->equipment_id, $entry->equipment_number, $entry->entry_date); - } - } - - public function AllDatesByEquipment($eqmt_id) - { - $entry_dates = DB::getInstance()->get( - 'SELECT DISTINCT entry_date FROM plugin_materiels_entry WHERE equipment_id = ? ORDER BY entry_date DESC;', $eqmt_id); - $entry_dates_array = array(); - foreach ($entry_dates as $row) - { - array_push($entry_dates_array, $row->entry_date); - } - return $entry_dates_array; - } -} diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php index 8e98599..428b44f 100644 --- a/src/lib/Equipment.php +++ b/src/lib/Equipment.php @@ -223,14 +223,20 @@ class Equipment } public function ListAllBorrowedByCategory() + // return list of borrowed equipments ordered by category { + // get the list of all equipments ordered by category $eqmts_by_cat = $this->listAllByCategory(); + // construct list of equipments borrowed for all categories $eqmts_borrowed_by_cat = array(); foreach ($eqmts_by_cat as $cat => $eqmts) { + // construct list of equipments borrowed for one category $eqmts_borrowed = array(); foreach ($eqmts as $eqmt) { + // for each equipment calculte number of borrowed $borrowed = $this->CalculateNoOwned($eqmt->id); if ($borrowed) { + // add to the list if at least one is borrowed $eqmt->borrowed = $borrowed; array_push($eqmts_borrowed, $eqmt); } diff --git a/src/lib/Output.php b/src/lib/Output.php deleted file mode 100644 index a11fdb6..0000000 --- a/src/lib/Output.php +++ /dev/null @@ -1,106 +0,0 @@ -insert('plugin_materiels_output', $data); - } - - public function get($id) - { - return DB::getInstance()->first('SELECT * FROM plugin_materiels_output WHERE id = ?;', $id); - } - - public function delete($id) - { - DB::getInstance()->delete('plugin_materiels_output', 'id = ' . $id); - } - - public function listAll() - { - return DB::getInstance()->get('SELECT * FROM plugin_materiels_output ORDER BY output_date DESC;'); - } - - public function PossibilityOwnedEqmtOutput($id, $eqmt_number, $date) - { - $after_output_dates = DB::getInstance()->get( - "SELECT output_date FROM plugin_materiels_output WHERE kind IN ( - 'Vente', 'Don', 'Besoin', 'Autre (perte, vol, ...)', - '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) { - $available_eqmt = $eqmt->CalculateAvailableByDate($id, $output_date); - if ($available_eqmt - $eqmt_number < 0) - { - return false; - } - } - 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; - } - - public function PossibilityDeleteOutput($output) - { - $entry = new Entry; - if ($output->kind == 'Location / Prêt') - { - return $entry->PossibilityRentEqmtEntry( - $output->equipment_id, $output->equipment_number, $output->output_date); - } - return true; - } - - public function AllDatesByEquipment($eqmt_id) - { - $output_dates = DB::getInstance()->get( - 'SELECT DISTINCT output_date FROM plugin_materiels_output WHERE equipment_id = ? ORDER BY output_date DESC;', $eqmt_id); - $output_dates_array = array(); - foreach ($output_dates as $row) - { - array_push($output_dates_array, $row->output_date); - } - return $output_dates_array; - } -} diff --git a/src/templates/_nav.tpl b/src/templates/_nav.tpl index 48cb9ac..98bd414 100644 --- a/src/templates/_nav.tpl +++ b/src/templates/_nav.tpl @@ -1,11 +1,11 @@ + {include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id} +