function __construct($_session, $_member_id = '') { parent::__construct(); $this->employee = new Employee($_session['id'], $_session['sid']); $this->referrals = new Referral(); $now = now(); $this->period = array(0 => sql_date_add($now, -4, 'year'), 1 => $now); }
public function extend() { $query = "INSERT INTO job_extensions \n SELECT 0, id, created_on, expire_on, for_replacement, invoiced \n FROM jobs \n WHERE id = " . $this->id; if ($this->mysqli->execute($query) === false) { return false; } $query = "SELECT expire_on FROM jobs \n WHERE id = " . $this->id . " LIMIT 1"; $result = $this->mysqli->query($query); $is_expired = sql_date_diff($result[0]['expire_on'], now()) <= 0 ? true : false; $expire_on = $result[0]['expire_on']; if ($is_expired) { $expire_on = now(); } $data = array(); $data['created_on'] = $expire_on; $data['expire_on'] = sql_date_add($data['created_on'], 30, 'day'); $data['closed'] = 'N'; if ($this->update($data) == false) { return false; } return true; }
} $query = "INSERT INTO job_extensions \n SELECT 0, id, created_on, expire_on, for_replacement, invoiced FROM jobs WHERE id = " . $_POST['job']; if (!$mysqli->execute($query)) { echo "ko"; exit; } $query = "SELECT expire_on \n FROM jobs \n WHERE id = " . $_POST['job'] . " LIMIT 1"; $result = $mysqli->query($query); $is_expired = sql_date_diff($result[0]['expire_on'], now()) <= 0 ? true : false; $expire_on = $result[0]['expire_on']; if ($is_expired) { $expire_on = now(); } $data = array(); $data['created_on'] = $expire_on; $data['expire_on'] = sql_date_add($data['created_on'], 30, 'day'); $data['closed'] = 'N'; $job = new Job($_POST['job']); if ($job->update($data) == false) { echo "ko"; exit; } echo "ok"; exit; } if ($_POST['action'] == 'get_contact_person') { $query = "SELECT contact_person, email_addr FROM employers WHERE id = '" . $_POST['id'] . "' LIMIT 1"; $mysqli = Database::connect(); $result = $mysqli->query($query); $response = array('contact' => $result[0]); header('Content-type: text/xml');
</p><p style="font-weight: bold;">Add an item... </p><p><?php if (Invoice::add_item($id, 270.98, 23, 'some references')) { print_array(Invoice::get_items_of($id)); } else { echo "failed"; exit; } ?> </p><p style="font-weight: bold;">Add another item... </p><p><?php if (Invoice::add_item($id, 0.05, 93, 'some other charges')) { print_array(Invoice::get_items_of($id)); } else { echo "failed"; exit; } ?> </p><p style="font-weight: bold;">Pay an invoice... </p><p><?php $data = array(); $data['id'] = $id; $data['paid_on'] = sql_date_add(today(), 30, 'day'); $data['paid_through'] = 'CHQ'; $data['paid_id'] = 'a_cheque_number'; if (Invoice::update($data)) { print_array(Invoice::get($id)); } else { echo "failed"; exit; } ?> </p>
exit; } if ($_POST['action'] == 'authorize_replacement') { $today = now(); $data = array(); $data['id'] = $_POST['id']; $data['replacement_authorized_on'] = $today; if (!Referral::update($data)) { echo 'ko'; exit; } $query = "SELECT job FROM referrals WHERE id = " . $_POST['id'] . " LIMIT 1"; $mysqli = Database::connect(); $result = $mysqli->query($query); $data = array(); $data['expire_on'] = sql_date_add($today, 30, 'day'); $data['closed'] = 'N'; $data['for_replacement'] = 'Y'; $job = new Job($result[0]['job']); if (!$job->update($data)) { echo 'ko'; exit; } $query = "SELECT employers.name AS employer, industries.industry, jobs.title, \n referrals.member AS member_email_addr, referrals.referee AS referee_email_addr, \n CONCAT(members.lastname, ', ', members.firstname) AS member, \n CONCAT(referees.lastname, ', ', referees.firstname) AS referee, \n DATE_FORMAT(referrals.referred_on, '%e %b, %Y') AS formatted_referred_on, \n DATE_FORMAT(referrals.employed_on, '%e %b, %Y') AS formatted_employed_on, \n DATE_FORMAT(referrals.replacement_authorized_on, '%e %b, %Y') AS formatted_replacement_authorized_on \n FROM referrals \n LEFT JOIN jobs ON jobs.id = referrals.job \n LEFT JOIN employers ON employers.id = jobs.employer \n LEFT JOIN industries ON industries.id = jobs.industry \n LEFT JOIN members ON members.email_addr = referrals.member \n LEFT JOIN members AS referees ON referees.email_addr = referrals.referee \n WHERE referrals.id = " . $_POST['id'] . " LIMIT 1"; $result = $mysqli->query($query); $lines = file(dirname(__FILE__) . '/../private/mail/member_replacement.txt'); $message = ''; foreach ($lines as $line) { $message .= $line; } $message = str_replace('%member%', htmlspecialchars_decode($result[0]['member']), $message);
$data['title'] = "Some lame job"; $data['description'] = "blah blah... some job descriptions goes here"; $first_job_id = 0; if ($job->create($data)) { $first_job_id = $job->getId(); echo "This job gets the ID of <b>" . $job->getId() . "</b><br><br>"; print_array($job->get()); } else { echo "failed"; exit; } ?> </p><p style="font-weight: bold;">Add another new job... </p><p><?php $job = new Job(); $date = date('Y-m-d H:i:s'); $expiry_date = sql_date_add($date, 30, 'day'); $data = array(); $data['employer'] = 'acme123'; $data['industry'] = '2'; $data['country'] = 'SG'; $data['currency'] = 'MYR'; $data['salary'] = '3200'; $data['salary_negotiable'] = 'N'; $data['created_on'] = $date; $data['expire_on'] = $expiry_date; $data['title'] = "Some lame job"; $data['description'] = "blahlelelll blah... some job descriptions goes here"; if ($job->create($data)) { echo "This job gets the ID of <b>" . $job->getId() . "</b><br><br>"; print_array($job->get()); } else {
function send_invoice(&$_employer, $_paid_postings, $_subscription_period) { if (!is_a($_employer, 'Employer')) { return false; } $today = date('Y-m-d'); $branch = $_employer->getAssociatedBranch(); $sales = 'sales.' . strtolower($branch[0]['country']) . '@yellowelevator.com'; $branch[0]['address'] = str_replace(array("\r\n", "\r"), "\n", $branch[0]['address']); $branch['address_lines'] = explode("\n", $branch[0]['address']); $currency = Currency::getSymbolFromCountryCode($branch[0]['country']); if ($_paid_postings > 0) { // 0. get the job postings pricing and currency $posting_rates = $GLOBALS['postings_rates']; $price = $posting_rates[$currency]; // 1. generate invoice in the system $data = array(); $data['issued_on'] = $today; $data['type'] = 'P'; $data['employer'] = $_POST['id']; $data['payable_by'] = sql_date_add($today, $_employer->getPaymentTermsInDays(), 'day'); $invoice = Invoice::create($data); if ($invoice === false) { echo 'ko'; exit; } $amount = $price * $_paid_postings; $desc = $_paid_postings . ' Job Posting(s) @ ' . $currency . ' $' . $price; $item_added = Invoice::addItem($invoice, $amount, '1', $desc); $items = array(); $items[0]['itemdesc'] = $desc; $items[0]['amount'] = number_format($amount, '2', '.', ', '); // 2. generate the invoice as PDF file $pdf = new PaidPostingsInvoice(); $pdf->AliasNbPages(); $pdf->SetAuthor('Yellow Elevator. This invoice was automatically generated. Signature is not required.'); $pdf->SetTitle($GLOBALS['COMPANYNAME'] . ' - Invoice ' . pad($invoice, 11, '0')); $pdf->SetCurrency($currency); $pdf->SetBranch($branch); $pdf->AddPage(); $pdf->SetFont('Arial', '', 10); $pdf->SetTextColor(255, 255, 255); $pdf->SetFillColor(54, 54, 54); $pdf->Cell(60, 5, "Invoice Number", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(33, 5, "Issuance Date", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(33, 5, "Payable By", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(0, 5, "Amount Payable (" . $currency . ")", 1, 0, 'C', 1); $pdf->Ln(6); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(60, 5, pad($invoice, 11, '0'), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(33, 5, sql_date_format($data['issued_on']), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(33, 5, sql_date_format($data['payable_by']), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(0, 5, number_format($amount, '2', '.', ', '), 1, 0, 'C'); $pdf->Ln(6); $pdf->SetTextColor(255, 255, 255); $pdf->Cell(60, 5, "User ID", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(0, 5, "Employer Name", 1, 0, 'C', 1); $pdf->Ln(6); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(60, 5, $_employer->getId(), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(0, 5, $_employer->getName(), 1, 0, 'C'); $pdf->Ln(10); $table_header = array("No.", "Item", "Amount (" . $currency . ")"); $pdf->FancyTable($table_header, $items, number_format($amount, '2', '.', ', ')); $pdf->Ln(13); $pdf->SetFont('', 'I'); $pdf->Cell(0, 0, "This invoice was automatically generated. Signature is not required.", 0, 0, 'C'); $pdf->Ln(6); $pdf->Cell(0, 5, "Payment Notice", 'LTR', 0, 'C'); $pdf->Ln(); $pdf->Cell(0, 5, "- Payment shall be made payable to " . $branch[0]['branch'] . ".", 'LR', 0, 'C'); $pdf->Ln(); $pdf->Cell(0, 5, "- To facilitate the processing of the payment, please write down the invoice number(s) on your cheque(s)/payment slip(s)", 'LBR', 0, 'C'); $pdf->Ln(10); $pdf->Cell(0, 0, "E. & O. E.", 0, 0, 'C'); $pdf->Close(); $pdf->Output($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf', 'F'); // 3. sends it as an email $attachment = chunk_split(base64_encode(file_get_contents($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf'))); $subject = "Subscription Invoice " . pad($invoice, 11, '0'); $headers = 'From: YellowElevator.com <*****@*****.**>' . "\n"; $headers .= 'Bcc: ' . $sales . "\n"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-Type: multipart/mixed; boundary="yel_mail_sep_' . $invoice . '";' . "\n\n"; $body = '--yel_mail_sep_' . $invoice . "\n"; $body .= 'Content-Type: multipart/alternative; boundary="yel_mail_sep_alt_' . $invoice . '"' . "\n"; $body .= '--yel_mail_sep_alt_' . $invoice . "\n"; $body .= 'Content-Type: text/plain; charset="iso-8859-1"' . "\n"; $body .= 'Content-Transfer-Encoding: 7bit"' . "\n"; $mail_lines = file('../private/mail/employer_posting_invoice.txt'); $message = ''; foreach ($mail_lines as $line) { $message .= $line; } $message = str_replace('%employer%', $_employer->getName(), $message); $message = str_replace('%postings%', $_POST['paid_postings'], $message); $message = str_replace('%price%', $price, $message); $message = str_replace('%currency%', $currency, $message); $message = str_replace('%amount%', number_format($amount, 2, '.', ', '), $message); $issued_date = explode('-', $data['issued_on']); $issued_timestamp = $issued_date[0] . $issued_date[1] . $issued_date[2]; $message = str_replace('%purchased_on%', date('j M', $issued_timestamp) . ', ' . $issued_date[0], $message); $body .= $message . "\n"; $body .= '--yel_mail_sep_alt_' . $invoice . "--\n\n"; $body .= '--yel_mail_sep_' . $invoice . "\n"; $body .= 'Content-Type: application/pdf; name="yel_invoice_' . pad($invoice, 11, '0') . '.pdf"' . "\n"; $body .= 'Content-Transfer-Encoding: base64' . "\n"; $body .= 'Content-Disposition: attachment' . "\n"; $body .= $attachment . "\n"; $body .= '--yel_mail_sep_' . $invoice . "--\n\n"; mail($_employer->getEmailAddress(), $subject, $body, $headers); // $handle = fopen('/tmp/email_to_'. $_employer->getEmailAddress(). '.txt', 'w'); // fwrite($handle, 'Subject: '. $subject. "\n\n"); // fwrite($handle, $body); // fclose($handle); unlink($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf'); } if ($_subscription_period > 0) { $single_subscription_prices = array('MYR' => 1000, 'SGD' => 1000); // 0. get the job postings pricing and currency $subscriptions_rates = $GLOBALS['subscriptions_rates']; $amount = $subscriptions_rates[$currency][$_subscription_period]; if ($_subscription_period == 1) { $amount = $single_subscription_prices[$currency]; } $admin_fee = 0.05 * $amount; $total = $admin_fee + $amount; // 1. generate invoice in the system $data = array(); $data['issued_on'] = $today; $data['type'] = 'J'; $data['employer'] = $_employer->getId(); $data['payable_by'] = sql_date_add($today, $_employer->getPaymentTermsInDays(), 'day'); $invoice = Invoice::create($data); if ($invoice === false) { echo 'ko'; exit; } $desc = $_subscription_period . ' month(s) of subscription'; $item_added = Invoice::addItem($invoice, $total, '1', $desc); $items = array(); $items[0]['itemdesc'] = $desc; $items[0]['amount'] = number_format($amount, '2', '.', ', '); $items[1]['itemdesc'] = 'Administration Fee'; $items[1]['amount'] = number_format($admin_fee, '2', '.', ', '); // 2. generate the PDF version to be attached to sales.xx and the employer $pdf = new SubscriptionInvoice(); $pdf->AliasNbPages(); $pdf->SetAuthor('Yellow Elevator. This invoice was automatically generated. Signature is not required.'); $pdf->SetTitle($GLOBALS['COMPANYNAME'] . ' - Invoice ' . pad($invoice, 11, '0')); $pdf->SetCurrency($currency); $pdf->SetBranch($branch); $pdf->AddPage(); $pdf->SetFont('Arial', '', 10); $pdf->SetTextColor(255, 255, 255); $pdf->SetFillColor(54, 54, 54); $pdf->Cell(60, 5, "Invoice Number", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(33, 5, "Issuance Date", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(33, 5, "Payable By", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(0, 5, "Amount Payable (" . $currency . ")", 1, 0, 'C', 1); $pdf->Ln(6); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(60, 5, pad($invoice, 11, '0'), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(33, 5, sql_date_format($data['issued_on']), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(33, 5, sql_date_format($data['payable_by']), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(0, 5, number_format($total, '2', '.', ', '), 1, 0, 'C'); $pdf->Ln(6); $pdf->SetTextColor(255, 255, 255); $pdf->Cell(60, 5, "User ID", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(0, 5, "Employer Name", 1, 0, 'C', 1); $pdf->Ln(6); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(60, 5, $_employer->getId(), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(0, 5, $_employer->getName(), 1, 0, 'C'); $pdf->Ln(10); $table_header = array("No.", "Item", "Amount (" . $currency . ")"); $pdf->FancyTable($table_header, $items, number_format($total, '2', '.', ', ')); $pdf->Ln(13); $pdf->SetFont('', 'I'); $pdf->Cell(0, 0, "This invoice was automatically generated. Signature is not required.", 0, 0, 'C'); $pdf->Ln(6); $pdf->Cell(0, 5, "Payment Notice", 'LTR', 0, 'C'); $pdf->Ln(); $pdf->Cell(0, 5, "- Payment shall be made payable to " . $branch[0]['branch'] . ".", 'LR', 0, 'C'); $pdf->Ln(); $pdf->Cell(0, 5, "- To facilitate the processing of the payment, please write down the invoice number(s) on your cheque(s)/payment slip(s)", 'LBR', 0, 'C'); $pdf->Ln(10); $pdf->Cell(0, 0, "E. & O. E.", 0, 0, 'C'); $pdf->Close(); $pdf->Output($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf', 'F'); // 3. attach it to email $attachment = chunk_split(base64_encode(file_get_contents($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf'))); $subject = "Subscription Invoice " . pad($invoice, 11, '0'); $headers = 'From: YellowElevator.com <*****@*****.**>' . "\n"; $headers .= 'Bcc: ' . $sales . "\n"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-Type: multipart/mixed; boundary="yel_mail_sep_' . $invoice . '";' . "\n\n"; $body = '--yel_mail_sep_' . $invoice . "\n"; $body .= 'Content-Type: multipart/alternative; boundary="yel_mail_sep_alt_' . $invoice . '"' . "\n"; $body .= '--yel_mail_sep_alt_' . $invoice . "\n"; $body .= 'Content-Type: text/plain; charset="iso-8859-1"' . "\n"; $body .= 'Content-Transfer-Encoding: 7bit"' . "\n"; $mail_lines = file('../private/mail/employer_subscription_invoice.txt'); $message = ''; foreach ($mail_lines as $line) { $message .= $line; } $message = str_replace('%employer%', $_employer->getName(), $message); $message = str_replace('%period%', $_subscription_period, $message); $message = str_replace('%currency%', $currency, $message); $message = str_replace('%amount%', number_format($total, 2, '.', ', '), $message); $issued_date = explode('-', $data['issued_on']); $issued_timestamp = $issued_date[0] . $issued_date[1] . $issued_date[2]; $message = str_replace('%purchased_on%', date('j M', $issued_timestamp) . ', ' . $issued_date[0], $message); $body .= $message . "\n"; $body .= '--yel_mail_sep_alt_' . $invoice . "--\n\n"; $body .= '--yel_mail_sep_' . $invoice . "\n"; $body .= 'Content-Type: application/pdf; name="yel_invoice_' . pad($invoice, 11, '0') . '.pdf"' . "\n"; $body .= 'Content-Transfer-Encoding: base64' . "\n"; $body .= 'Content-Disposition: attachment' . "\n"; $body .= $attachment . "\n"; $body .= '--yel_mail_sep_' . $invoice . "--\n\n"; mail($_employer->getEmailAddress(), $subject, $body, $headers); /*$handle = fopen('/tmp/email_to_'. $_employer->getEmailAddress(). '.txt', 'w'); fwrite($handle, 'Subject: '. $subject. "\n\n"); fwrite($handle, $body); fclose($handle);*/ unlink($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf'); } return true; }
$item_added = Invoice::add_item($invoice, $discount, $_POST['id'], 'Discount'); if (!$item_added) { echo "ko"; exit; } $item_added = Invoice::add_item($invoice, $extra_charges, $_POST['id'], 'Extra charges'); if (!$item_added) { echo "ko"; exit; } } else { if ($credit_amount > 0) { $credit_note_desc = 'Refund of balance for Invoice: ' . pad($previous_invoice, 11, '0'); $filename = generate_random_string_of(8) . '.' . generate_random_string_of(8); $issued_on = today(); $expire_on = sql_date_add($issued_on, 30, 'day'); Invoice::accompany_credit_note_with($previous_invoice, $invoice, $issued_on, $credit_amount); $branch = $employer->get_branch(); $sales = 'sales.' . strtolower($branch[0]['country']) . '@yellowelevator.com'; $branch[0]['address'] = str_replace(array("\r\n", "\r"), "\n", $branch[0]['address']); $branch['address_lines'] = explode("\n", $branch[0]['address']); $currency = Currency::getSymbolFromCountryCode($branch[0]['country']); $pdf = new CreditNote(); $pdf->AliasNbPages(); $pdf->SetAuthor('Yellow Elevator. This credit note was automatically generated. Signature is not required.'); $pdf->SetTitle($GLOBALS['COMPANYNAME'] . ' - Credit Note ' . pad($invoice, 11, '0')); $pdf->SetRefundAmount($credit_amount); $pdf->SetDescription($credit_note_desc); $pdf->SetCurrency($currency); $pdf->SetBranch($branch); $pdf->AddPage();
$result[0]['has_free_postings'] = $employer->has_free_job_postings() === false ? '0' : $employer->has_free_job_postings(); $result[0]['has_paid_postings'] = $employer->has_paid_job_postings() === false ? '0' : $employer->has_paid_job_postings(); $response = array('subscription' => $result[0]); header('Content-type: text/xml'); echo $xml_dom->get_xml_from_array($response); exit; } if ($_POST['action'] == 'buy_subscriptions') { $mysqli = Database::connect(); $employer = new Employer($_POST['id']); // 1. generate invoice in the system $data = array(); $data['issued_on'] = today(); $data['type'] = 'J'; $data['employer'] = $_POST['id']; $data['payable_by'] = sql_date_add($data['issued_on'], $employer->get_payment_terms_days(), 'day'); $invoice = Invoice::create($data); if ($invoice === false) { echo 'ko'; exit; } $desc = $_POST['period'] . ' month(s) of subscription'; $item_added = Invoice::add_item($invoice, $_POST['amount'], '1', $desc); $items = array(); $items[0]['itemdesc'] = $desc; $items[0]['amount'] = number_format($_POST['price'], '2', '.', ', '); $items[1]['itemdesc'] = 'Administration Fee'; $items[1]['amount'] = number_format($_POST['admin_fee'], '2', '.', ', '); // 2. generate the PDF version to be attached to sales.xx and the employer $branch_raw = $employer->get_branch(); $sales = 'sales.' . strtolower($branch_raw[0]['country']) . '@yellowelevator.com';