diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php index 56cb647..225dcb3 100644 --- a/src/lib/Equipment.php +++ b/src/lib/Equipment.php @@ -181,14 +181,20 @@ class Equipment } public function listAllReleasedRentByCategory() + // return list of equipments for possible return (loan or rent) ordered by category { + // get the list of all equipments ordered by category $eqmts_by_cat = $this->listAllByCategory(); + // construct list of equipments for possible return for all categories $eqmts_released_by_cat = array(); foreach ($eqmts_by_cat as $cat => $eqmts) { + // construct list of equipments for possible return for one category $eqmts_released = array(); foreach ($eqmts as $eqmt) { + // for each equipment calculte number of possible return $released = $this->CalculateOwnedOut($eqmt->id); if ($released) { + // add to the list if at least one is possible for return $eqmt->released = $released; array_push($eqmts_released, $eqmt); } @@ -201,11 +207,12 @@ class Equipment } public function CalculateOutOfStockByDate($id, $date) + // return number of a specific equipment is out at a specific 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}';"); + "SELECT sum(equipment_number) FROM plugin_materiels_movement WHERE side = '0' AND kind = 'Retour de location / prêt' AND equipment_id = '{$id}' AND mvt_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}';"); + "SELECT sum(equipment_number) FROM plugin_materiels_movement WHERE side = '1' AND kind = 'Location / Prêt' AND equipment_id = '{$id}' AND mvt_date <= '{$date}';"); return $outputs - $entries; } diff --git a/src/lib/Movement.php b/src/lib/Movement.php index cffa604..7bb9ffe 100644 --- a/src/lib/Movement.php +++ b/src/lib/Movement.php @@ -36,4 +36,31 @@ class Movement } return $mvts; } + + public function PossibilityRentEqmtEntry($id, $eqmt_number, $date) + // check if it's possible to add a return entry + // at specific date for a specific number + // return true if it's ok else return false + { + // get all entry dates after the specific date and make a list with its + $after_entry_dates = DB::getInstance()->get( + "SELECT mvt_date FROM plugin_materiels_movement WHERE side = '0' AND kind = 'Retour de location / prêt' AND equipment_id = '{$id}' AND mvt_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) { + // for each date check if it's possible to add this number of return entries + $out_of_stock_eqmt = $eqmt->CalculateOutOfStockByDate($id, $entry_date); + if ($out_of_stock_eqmt - $eqmt_number < 0) + { + // not possible + return false; + } + } + // possible for all dates + return true; + } } diff --git a/src/templates/mouvements/entrees/retour.tpl b/src/templates/mouvements/entrees/retour.tpl new file mode 100644 index 0000000..8991cd8 --- /dev/null +++ b/src/templates/mouvements/entrees/retour.tpl @@ -0,0 +1,20 @@ + +
diff --git a/src/templates/mouvements/formulaire_mouvement.tpl b/src/templates/mouvements/formulaire_mouvement.tpl index d9c5ec1..9e76444 100644 --- a/src/templates/mouvements/formulaire_mouvement.tpl +++ b/src/templates/mouvements/formulaire_mouvement.tpl @@ -8,7 +8,7 @@ {form_errors}