daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 70 in 149 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Segue codigo:
  2.  
  3. <?php
  4.  
  5. require __DIR__ . "/../vendor/autoload.php";
  6.  
  7. /**
  8. * SEND INVOICES
  9. */
  10.  
  11. $invoices = new \Source\Models\CafeApp\AppInvoice();
  12. $email = new \Source\Support\Email();
  13. $view = new \Source\Core\View( __DIR__ . "/../shared/views/email");
  14.  
  15. /**
  16. *SEND INVOICES: ENVIA FATURAS DE HOJE POR EMAIL
  17. */
  18.  
  19. /*
  20. * Identifica todos os clientes que tem invoices com data de hoje.
  21. */
  22. $user_ids = $invoices->find("due_at = DATE(NOW()) AND status IN ('paid', 'unpaid') AND type IN ('income','expense')", "", "user_id")
  23. ->group("user_id")
  24. ->order("user_id")
  25. ->fetch(true);
  26.  
  27. if ($user_ids) {
  28.  
  29. foreach ($user_ids as $user_item) {
  30. $id_usuario = $user_item->user_id;
  31.  
  32. /*
  33. * Identifica todas as invoices do cliente
  34. */
  35.  
  36. $invocesNow = $invoices->find("user_id = :id AND due_at = DATE(NOW()) AND (status = 'paid' OR status = 'unpaid') AND (type = 'income' OR type = 'expense')",
  37. "id={$id_usuario}")->fetch(true);
  38.  
  39. if ($invocesNow) {
  40.  
  41. $corpo = "<table border='0' cellpadding='0' cellspacing='0'>";
  42. $corpo .= "<tr><td style='width: 300px;'>Descrição</td><td style='width: 200px; text-align: right;'>Receber</td><td style='width: 200px; text-align: right;'>Pagar</td></tr>";
  43.  
  44. foreach ($invocesNow as $invoiceSend) {
  45. $user_id = $invoiceSend->user_id;
  46.  
  47. if ($invoiceSend->type == "income") {
  48. $credito = str_price($invoiceSend->value);
  49. $debito = str_price(0);
  50. } elseif ($invoiceSend->type == "expense") {
  51. $debito = str_price($invoiceSend->value);
  52. $credito = str_price(0);
  53. }
  54.  
  55. $corpo .= "<tr><td>{$invoiceSend->description}</td><td style='text-align: right;'>{$credito}</td><td style='text-align: right;'>{$debito}</td></tr>";
  56. }
  57.  
  58. $corpo .= "</table>";
  59. $user = (new \Source\Models\User())->findById($user_id);
  60.  
  61. $subject = "[FATURAS EM ABERTO] no CafeApp {$user->fist_name}";
  62. $body = $view->render("mail", [
  63. "subject" => $subject,
  64. "message" => "<h3>Você tem faturas em aberto {$user->first_name}!</h3>" . $corpo
  65. ]);
  66.  
  67.  
  68. $email->bootstrap(
  69. $subject,
  70. $body,
  71. $user->email,
  72. "{$user->first_name} {$user->last_name}"
  73. )->send();
  74.  
  75. }
  76.  
  77. }
  78.  
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top