function calc_total($tourID, $userID, $total = NULL) { if ($total === NULL) { $tw_tour = record_by_id($tourID, 'tw_tours'); $total = $tw_tour->tourPrice1; } $ps = new tw_payments(); $ps->find_records(array('tourID' => $tourID, 'userID' => $userID)); foreach ($ps as $p) { if ($p->Type == 'оплата' || $p->Type == 'скидка') { $total -= $p->Amount; } else { if ($p->Type != 'инфо') { $total += $p->Amount; } } } $ps->after($ps->first(), 'after_update'); return sprintf('%.02f', $total); }