Skip to content

Commit

Permalink
hook AfterCronJob #9
Browse files Browse the repository at this point in the history
  • Loading branch information
andrekutianski committed Oct 19, 2021
1 parent 12ea2c5 commit 53c1fdd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion checklist_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Checklist dos hooks a serem migrados
* [ ] AdminInvoicesControlsOutput
* [x] InvoiceCancelled
* [x] DailyCronJob
* [ ] AfterCronJob
* [x] AfterCronJob
* [ ] ProductDelete
* [ ] AdminClientProfileTabFields
* [ ] AdminClientProfileTabFieldsSave
5 changes: 5 additions & 0 deletions modules/addons/NFEioServiceInvoices/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@
add_hook('DailyCronJob', 1, function ($vars) {
$legacyHooks = new \NFEioServiceInvoices\Legacy\Hooks();
$legacyHooks->dailycronjob();
});

add_hook('AfterCronJob', 1, function ($vars) {
$legacyHooks = new \NFEioServiceInvoices\Legacy\Hooks();
$legacyHooks->aftercronjob();
});
37 changes: 37 additions & 0 deletions modules/addons/NFEioServiceInvoices/lib/Legacy/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ class Hooks
{
private $config;
private $functions;
private $serviceInvoicesRepo;

public function __construct()
{
$this->config = new \NFEioServiceInvoices\Configuration();
$this->functions = new \NFEioServiceInvoices\Legacy\Functions();
$this->serviceInvoicesRepo = new \NFEioServiceInvoices\Models\ServiceInvoices\Repository();
}

function dailycronjob()
Expand Down Expand Up @@ -183,4 +185,39 @@ function invoicecancelled($vars)
}
}
}

function aftercronjob()
{
$storageKey = $this->config->getStorageKey();
$serviceInvoicesTable = $this->serviceInvoicesRepo->tableName();
$params = $this->functions->gnfe_config();
$dataAtual = date('Y-m-d H:i:s');

if (Capsule::table('tbladdonmodules')->where('setting','=','last_cron')->count() == 0) {
Capsule::table('tbladdonmodules')->insert(['module' => $storageKey, 'setting' => 'last_cron', 'value' => $dataAtual]);
} else {
Capsule::table('tbladdonmodules')->where('setting','=','last_cron')->update(['value' => $dataAtual]);
}

if (!isset($params['issue_note_after']) || $params['issue_note_after'] <= 0) {
foreach (Capsule::table($serviceInvoicesTable)->orderBy('id', 'desc')->where('status', '=', 'Waiting')->get(['id', 'invoice_id', 'services_amount']) as $waiting) {
logModuleCall('gofas_nfeio', 'aftercronjob - checktablegofasnfeio', '', $waiting,'', '');

$data = getTodaysDate(false);
$dataAtual = toMySQLDate($data);

if ($params['issue_note_default_cond'] !== 'Manualmente') {
$getQuery = Capsule::table('tblinvoices')->whereBetween('date', [$params['initial_date'], $dataAtual])->where('id', '=', $waiting->invoice_id)->get(['id', 'userid', 'total']);
logModuleCall('gofas_nfeio', 'aftercronjob - getQuery', ['date' => [$params['initial_date'], $dataAtual], 'where' => 'id=' . $waiting->invoice_id], $getQuery,'', '');
} else {
$getQuery = Capsule::table('tblinvoices')->where('id', '=', $waiting->invoice_id)->get(['id', 'userid', 'total']);
logModuleCall('gofas_nfeio', 'aftercronjob - getQuery', 'id=' . $waiting->invoice_id, $getQuery,'', '');
}

foreach ($getQuery as $invoices) {
$this->functions->emitNFE($invoices,$waiting);
}
}
}
}
}

0 comments on commit 53c1fdd

Please sign in to comment.