public function setPaid($id, $paid) { try { $user = User::find(Session::uid()); // Check if we have a payer if (!$user->isPayer()) { throw new Exception('Nothing to see here. Move along!'); } // Get clean data $paid = $paid ? true : false; $notes = trim($_POST['notes']); if (!$notes) { throw new Exception('You must write a note!'); } $fund_id = Fee::getFundId($id); // Exit of this script if (!Fee::markPaidById($id, $user->getId(), $notes, $paid, false, $fund_id)) { throw new Exception('Payment Failed!'); } /* Only send the email when marking as paid. */ if ($paid) { $fee = Fee::getFee($fee_id); $workitem = new WorkItem($fee['worklist_id']); $summary = $workitem->getSummary(); $fee_user = User::find($fee['user_id']); $subject = "Worklist.net paid you " . $fee['amount'] . " for " . $summary; $body = "Your Fee was marked paid.<br/>" . "Job <a href='" . SERVER_URL . $fee['worklist_id'] . "'>#" . $fee['worklist_id'] . ': ' . $summary . '</a><br/>' . "Fee Description : " . nl2br($fee['desc']) . "<br/>" . "Paid Notes : " . nl2br($notes) . "<br/><br/>" . "Contact the job Designer with any questions<br/><br/>Worklist.net<br/>"; if (!Utils::send_email($fee_user->getUsername(), $subject, $body)) { error_log("FeeController::setPaid: Utils::send_email failed"); } } return $this->setOutput(array('success' => true, 'notes' => 'Payment has been saved!')); } catch (Exception $e) { return $this->setOutput(array('success' => false, 'notes' => $e->getMessage())); } }
public function reports() { if (empty($_SESSION['is_runner']) && empty($_SESSION['is_payer']) && isset($_POST['paid'])) { $this->view = null; Utils::redirect("jobs"); return; } $this->view = new ReportsView(); if (!empty($_REQUEST['payee'])) { $payee = new User(); $payee->findUserByNickname($_REQUEST['payee']); $_REQUEST['user'] = $payee->getId(); } $showTab = 0; if (!empty($_REQUEST['view'])) { if ($_REQUEST['view'] == 'chart') { $showTab = 1; } if ($_REQUEST['view'] == 'payee') { $showTab = 2; } } $this->write('showTab', $showTab); $w2_only = 0; if (!empty($_REQUEST['w2_only'])) { if ($_REQUEST['w2_only'] == 1) { $w2_only = 1; } } $this->write('w2_only', $w2_only); $_REQUEST['name'] = '.reports'; if (isset($_POST['paid']) && !empty($_POST['paidList']) && !empty($_SESSION['is_payer'])) { // we need to decide if we are dealing with a fee or bonus and call appropriate routine $fees_id = explode(',', trim($_POST['paidList'], ',')); foreach ($fees_id as $id) { $query = "SELECT `id`, `bonus` FROM `" . FEES . "` WHERE `id` = {$id} "; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if ($row['bonus']) { Bonus::markPaidById($id, $user_paid = 0, $paid = 1, true, $fund_id = false); } else { Fee::markPaidById($id, $user_paid = 0, $paid_notes = '', $paid = 1, true, $fund_id = false); } } } parent::run(); }