Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SendEmailFollowUps | |
0.00% |
0 / 44 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| handle | |
0.00% |
0 / 43 |
|
0.00% |
0 / 1 |
56 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Console\Commands; |
| 4 | |
| 5 | use App\Http\Controllers\Quotations; |
| 6 | use App\Http\Controllers\Users; |
| 7 | use App\Http\Controllers\Companies; |
| 8 | use App\Models\TblEmailConfiguration; |
| 9 | use Illuminate\Console\Command; |
| 10 | use Illuminate\Support\Facades\Log; |
| 11 | use Illuminate\Http\Request; |
| 12 | |
| 13 | class SendEmailFollowUps extends Command |
| 14 | { |
| 15 | /** |
| 16 | * The name and signature of the console command. |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | protected $signature = 'send:follow-ups'; |
| 21 | |
| 22 | /** |
| 23 | * The console command description. |
| 24 | * |
| 25 | * @var string |
| 26 | */ |
| 27 | protected $description = 'Send email follow-ups'; |
| 28 | |
| 29 | /** |
| 30 | * Create a new command instance. |
| 31 | * |
| 32 | * @return void |
| 33 | */ |
| 34 | public function __construct() |
| 35 | { |
| 36 | parent::__construct(); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Execute the console command. |
| 41 | * |
| 42 | * @return int |
| 43 | */ |
| 44 | public function handle() |
| 45 | { |
| 46 | try { |
| 47 | |
| 48 | $order = new Quotations(); |
| 49 | $user = new Users(); |
| 50 | $company = new Companies(); |
| 51 | |
| 52 | $listCompanies = $company->list_companies(); |
| 53 | |
| 54 | foreach ($listCompanies->original['data'] as $item) { |
| 55 | $getAllUsers = $user->get_commercial_with_pendings($item->company_id); |
| 56 | if (!empty($getAllUsers->original['commercialWithPendings'])) { |
| 57 | $commercialWithPendings = $getAllUsers->original['commercialWithPendings']; |
| 58 | for ($i = 0; $i < count($commercialWithPendings); $i++) { |
| 59 | $total = $commercialWithPendings[$i]['totalPendingFollowUps']; |
| 60 | $userId = $commercialWithPendings[$i]['userId']; |
| 61 | $commercial = $commercialWithPendings[$i]['commercial']; |
| 62 | |
| 63 | $getEmailTemplate = TblEmailConfiguration::where('company_id', $item->company_id) |
| 64 | ->where('type', 'followUps') |
| 65 | ->where('cron_default', 1) |
| 66 | ->first(); |
| 67 | |
| 68 | if ($getEmailTemplate) { |
| 69 | if ($total > 0) { |
| 70 | |
| 71 | $filterModel = array( |
| 72 | "status" => array( |
| 73 | "values" => array("Enviado"), |
| 74 | "filterType" => "set" |
| 75 | ), |
| 76 | "commercial" => array( |
| 77 | "values" => array($commercial), |
| 78 | "filterType" => "set" |
| 79 | ) |
| 80 | ); |
| 81 | |
| 82 | $r = new Request([ |
| 83 | 'company_id' => $item->company_id, |
| 84 | 'user_id' => $userId, |
| 85 | 'sortModel' => [], |
| 86 | 'filterModel' => $filterModel, |
| 87 | 'searchText' => "", |
| 88 | 'ids' => [], |
| 89 | 'ids_not_in' => [], |
| 90 | 'email_template_id' => $getEmailTemplate->id |
| 91 | ]); |
| 92 | |
| 93 | $followUps = $order->send_email_follow_ups($r, 999999999); |
| 94 | |
| 95 | Log::channel('cron_send_email_follow_ups')->info($followUps->original); |
| 96 | } |
| 97 | } else { |
| 98 | Log::channel('cron_send_email_follow_ups')->error("No default email template (companyId: {$item->company_id})"); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } catch (\Exception $e) { |
| 104 | Log::channel('cron_send_email_follow_ups')->error($e->getMessage()); |
| 105 | } |
| 106 | } |
| 107 | } |