Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
146 righe
5.7 KiB
146 righe
5.7 KiB
<? |
|
Class asta { |
|
protected $parent; |
|
public $info; |
|
|
|
public function __construct($parent,$asta) { |
|
$this->parent = $parent; |
|
$this->info = $asta; |
|
} |
|
|
|
public function aggiornaGraduatoria() { |
|
$this->parent->importScore("asta"); |
|
$this->parent->aggiudica(); |
|
} |
|
|
|
public function getRilanci() { |
|
$return = []; |
|
$db = $this->parent->db; |
|
$rilanci = $db->go("SELECT b_offerte_gare.codice,b_offerte_gare.codice_partecipante,b_offerte_gare.timestamp,r_partecipanti_gare.ragione_sociale, b_offerte_gare.verificata |
|
FROM b_offerte_gare JOIN r_partecipanti_gare ON b_offerte_gare.codice_partecipante = r_partecipanti_gare.codice |
|
WHERE b_offerte_gare.tipo = 'asta' |
|
AND r_partecipanti_gare.codice_round = :round AND r_partecipanti_gare.codice_lotto = :lotto AND r_partecipanti_gare.conferma = 'S' AND r_partecipanti_gare.escluso = 'N' |
|
ORDER BY b_offerte_gare.timestamp DESC", |
|
[":lotto"=>$this->info["codice_lotto"],":round"=>$this->info["codice_round"]] |
|
); |
|
$dettagli = $db->prepare("SELECT * FROM b_dettaglio_offerte_gare WHERE codice_offerta = :codice AND offerta IS NOT NULL"); |
|
if (!empty($rilanci->rowCount())) { |
|
$rilanci = $rilanci->fetchAll(PDO::FETCH_ASSOC); |
|
$voci = []; |
|
$criteri = []; |
|
foreach($rilanci as $rilancio) { |
|
$dettagli->bindValue(":codice",$rilancio["codice"]); |
|
$dettagli->execute(); |
|
if ($dettagli->rowCount() > 0) { |
|
$rilancio["dettagli"] = []; |
|
while($dettaglio = $dettagli->fetch(PDO::FETCH_ASSOC)) { |
|
$codice_criterio = explode(".",$dettaglio["codice_dettaglio"]); |
|
$codice_voce = null; |
|
if (!empty($codice_criterio[1])) { |
|
$codice_voce = $codice_criterio[1]; |
|
} |
|
$codice_criterio = $codice_criterio[0]; |
|
if (!isset($criteri[$codice_criterio])) { |
|
$criteri[$codice_criterio] = $this->parent->getCriteri($codice_criterio)[0] ?? null; |
|
} |
|
$criterio = $criteri[$codice_criterio]; |
|
if (!empty($criterio)) { |
|
if ($criterio["tipologia"] == "E" && empty($voci[$criterio["codice"]])) { |
|
$elencoPrezzi = $this->parent->getElencoPrezzi($criterio["codice"]); |
|
$voci[$criterio["codice"]] = []; |
|
foreach($elencoPrezzi AS $voce) { |
|
$voci[$criterio["codice"]][$voce["codice"]] = $voce; |
|
} |
|
} |
|
$quantita = 1; |
|
if (isset($codice_voce)) { |
|
$quantita = $voci[$codice_criterio][$codice_voce]["quantita"]; |
|
} |
|
$offer = $dettaglio["offerta"] * $quantita; |
|
if (!isset($rilancio["dettagli"][$codice_criterio][$dettaglio["codice_partecipante"]])) { |
|
$rilancio["dettagli"][$codice_criterio][$dettaglio["codice_partecipante"]] = 0; |
|
} |
|
$rilancio["dettagli"][$codice_criterio][$dettaglio["codice_partecipante"]] += $offer; |
|
} |
|
} |
|
$return[] = $rilancio; |
|
} |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public function getBestOffer($criterio,$compare = null) { |
|
$criterio = $this->parent->getCriteri($criterio)[0] ?? null; |
|
if (!empty($criterio) && $criterio["economico"] == "S") { |
|
$offerte = $this->parent->getOfferte($criterio["codice"],true,true,true,true); |
|
if (!empty($offerte)) { |
|
if (tuttogareMath::getFormule()[$criterio["auto"]]["diretta"]) { |
|
$maggiorazione = true; |
|
arsort($offerte); |
|
} else { |
|
$maggiorazione = false; |
|
asort($offerte); |
|
} |
|
$return = reset($offerte); |
|
if (!isset($compare)) { |
|
return $return; |
|
} else { |
|
$rilancioMinimo = $this->info["rilancio_minimo"]; |
|
if(!empty($rilancioMinimo)) { |
|
if ($criterio["tipologia"] == "E" && tuttogareMath::getFormule()[$criterio["auto"]]["diretta"]) { |
|
$compare = tuttogareMath::convertInversaForScore($offerte,$this->parent->lotto["importoBase"]); |
|
arsort($compare); |
|
$compare = reset($compare); |
|
} |
|
if ($maggiorazione) { |
|
if (($compare - $return) >= $rilancioMinimo) { |
|
return true; |
|
} |
|
} else { |
|
if (($return - $compare) >= $rilancioMinimo) { |
|
return true; |
|
} |
|
} |
|
} else { |
|
return true; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
public function getScadenza($boolean = false) { |
|
if (!empty($this->info["tempo_base"])) { |
|
$offerte = $this->getRilanci(); |
|
if (!empty($offerte)) { |
|
$offerte = array_column($offerte,"timestamp"); |
|
$lastOfferta = $offerte[0]; |
|
$scadenza = (strtotime($lastOfferta)) + ($this->info["tempo_base"] * 60); |
|
} |
|
} |
|
if (empty($scadenza)) { |
|
$scadenza = strtotime($this->info["fine"]); |
|
} |
|
if ($boolean === true) { |
|
return ($scadenza < time()); |
|
} else if ($boolean === "deadline") { |
|
return $scadenza; |
|
} else { |
|
return $scadenza - time(); |
|
} |
|
} |
|
|
|
public function confirmDeadline($boolean = false) { |
|
$scadenza = $this->getScadenza("deadline") + (60*60); |
|
if ($boolean === true) { |
|
return ($scadenza < time()); |
|
} else if ($boolean === "deadline") { |
|
return $scadenza; |
|
} else { |
|
return $scadenza - time(); |
|
} |
|
} |
|
|
|
} |
|
?>
|