function process($parameters) { $payments = new Payments(); if (!$payments->checkLogin()) { $this->redirect('error'); } //if empty parameter, add there current user if (isset($parameters[0])) { $userId = $parameters[0]; } else { $userId = $_SESSION['id_user']; } if ($userId != $_SESSION['id_user'] && !$payments->checkIfIsAdminOfUser($_SESSION['id_user'], $userId)) { $this->redirect('error'); } $data = $payments->getUserData($userId); //actualize old payments $resultMessages = $payments->actualizePayments($data['payments']); //create new payments $payments->makeNewPayments($data['user'], $data['tariff'], $this->language); $this->messages = array_merge($this->messages, $resultMessages); //get new data for user view $data = $payments->getUserData($userId); $data['payments'] = $payments->enhanceUserPayments($data['payments'], $this->language); $extras = new Extras(); $this->data['blankExtras'] = $extras->getBlankExtras($userId); //display non-active user if (!$data['user']['active']) { $this->messages[] = ['s' => 'info', 'cs' => 'Neaktivní uživatel - nové faktury se negenerují', 'en' => 'Inactive user - new invoices are not generated']; } $this->data['admin'] = $payments->checkIfIsAdminOfUser($_SESSION['id_user'], $userId); $this->data['tariff'] = $data['tariff']; $this->data['user'] = $data['user']; $this->data['payments'] = $data['payments']; $this->header['title'] = ['cs' => 'Přehled plateb', 'en' => 'Payments overview']; //TODO add nice sliding JS invoice detail directly into view //TODO hide table in view when empty (no data) $this->view = 'payments'; }
private function createPayment($user, $tariff, $beginningDate, $lang) { $userId = $user['id_user']; $tariffId = $tariff['id_tariff']; $tariffName = $this->getTariffName($tariffId, 'cs'); //invoice is in czech only $priceCZK = $tariff['priceCZK']; $fakturoid = new FakturoidWrapper(); $fakturoidInvoice = $fakturoid->createInvoice($user, $tariff['priceCZK'], $tariffName, $beginningDate, $lang); if (!$fakturoidInvoice) { return ['s' => 'error', 'cs' => 'Nepovedlo se spojení s fakturoid.cz. Zkuste to prosím za pár minut', 'en' => 'We are unable to connect to fakturoid.cz. Try again in a few minutes']; } $fakturoidInvoiceId = $fakturoidInvoice->id; $fakturoidInvoiceNumber = $fakturoidInvoice->number; $now = date('Y-m-d H-i-s'); Db::queryModify(' INSERT INTO `payments` ( `id_payer`, `payment_first_date`, `status`, `time_generated`, `tariff_id`, `price_CZK`, `invoice_fakturoid_id`, `invoice_fakturoid_number` ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [$userId, date('Y-m-d', $beginningDate), 'unpaid', $now, $tariffId, $priceCZK, $fakturoidInvoiceId, $fakturoidInvoiceNumber]); //add blank extras $extras = new Extras(); $blankExtras = $extras->getBlankExtras($user['id_user']); if (!empty($blankExtras)) { foreach ($blankExtras as $extra) { $extraId = $extra['id_extra']; $price = $extra['priceCZK']; $description = $extra['description']; $fakturoidExtraId = $fakturoid->addExtra($fakturoidInvoiceId, $extra['priceCZK'], $extra['description']); $paymentId = $this->getPaymentIdFromFakturoidInvoiceId($fakturoidInvoiceId); $extras->assignBlankExtra($paymentId, $price, $description, $fakturoidExtraId, $extraId); } } //send email to user $subject = NAME . ' Paralelní Polis - nová faktura'; $link = ROOT . '/cs/payments'; $message = 'Ahoj,<br/> <br/> vystavili jsem ti fakturu za členství / pronájem v Paper Hub v Paralelní Polis.<br/> <a href="' . $link . '">' . $link . '</a><br/> Platbu uhradíš jednoduše na odkazu výše.<br/> <br/> Díky za rychlou platbu!<br/> Paper Hub'; $this->sendEmail(EMAIL, $user['email'], $subject, $message); //and send copy of email to hub manager //TODO refractor $this->sendEmail(EMAIL, EMAIL_HUB_MANAGER, NAME . ' - Poslána výzva o nové faktuře na email ' . $user['email'], $message); return ['s' => 'success']; }