1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use App\Invoice; |
7
|
|
|
use DB; |
8
|
|
|
use App\Sms_trigger; |
9
|
|
|
use Carbon\Carbon; |
10
|
|
|
|
11
|
|
|
class PendingInvoice extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The name and signature of the console command. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $signature = 'pending:invoice'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The console command description. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $description = 'Triggers sms alerts for pending invoices'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create a new command instance. |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
public function __construct() |
33
|
|
|
{ |
34
|
|
|
parent::__construct(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Execute the console command. |
39
|
|
|
* |
40
|
|
|
* @return mixed |
41
|
|
|
*/ |
42
|
|
|
public function handle() |
43
|
|
|
{ |
44
|
|
|
$invoices = Invoice::select(DB::raw('*, DATE_ADD(created_at , INTERVAL 4 DAY) AS sms_start, DATE_ADD(created_at , INTERVAL 6 DAY) AS sms_end')) |
45
|
|
|
->havingRaw('CURDATE() >= sms_start AND CURDATE() <= sms_end') |
46
|
|
|
->whereIn('status',[0,2]) |
47
|
|
|
->get(); |
48
|
|
|
|
49
|
|
|
$sms_trigger = Sms_trigger::where('alias','=','pending_invoice')->first(); |
50
|
|
|
$message = $sms_trigger->message; |
51
|
|
|
$sms_status = $sms_trigger->status; |
52
|
|
|
$sender_id = \Utilities::getSetting('sms_sender_id'); |
53
|
|
|
|
54
|
|
|
foreach ($invoices as $invoice) |
55
|
|
|
{ |
56
|
|
|
if($invoice->Payment_details->contains('mode',1)) |
57
|
|
|
{ |
58
|
|
|
$sms_text = sprintf($message,$invoice->member->name,$invoice->pending_amount,$invoice->invoice_number); |
59
|
|
|
\Utilities::Sms($sender_id,$invoice->member->contact,$sms_text,$sms_status); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|