Skip to content

Commit

Permalink
fix(cron): corrige aftercronjob
Browse files Browse the repository at this point in the history
altera a lógica da cron aftercronjob para processar toda NF que esteja 
na fila de emissão. Nesta nova lógica presume-se que qualquer NF na fila 
com status "waiting" está pronta e disponível para emissão.

refs: #103
  • Loading branch information
andrekutianski committed Dec 22, 2021
1 parent 5e06bf0 commit 6662fae
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions modules/addons/gofasnfeio/hooks/aftercronjob.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,29 @@
if (!defined('WHMCS')) {
exit();
}

use WHMCS\Database\Capsule;

$params = gnfe_config();
$dataAtual = date('Y-m-d H:i:s');

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

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

$data = getTodaysDate(false);
$dataAtual = toMySQLDate($data);
if ($hasNfWaiting) {
$queryNf = Capsule::table('gofasnfeio')->orderBy('id', 'desc')->where('status', '=', 'Waiting')->get(['id', 'invoice_id', 'services_amount']);
foreach ($queryNf as $waiting) {

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,'', '');
}
$getQuery = Capsule::table('tblinvoices')->where('id', '=', $waiting->invoice_id)->get(['id', 'userid', 'total']);
logModuleCall('nfeio', 'aftercronjob - getQuery 1', $waiting, $getQuery);

foreach ($getQuery as $invoices) {
emitNFE($invoices,$waiting);
emitNFE($invoices, $waiting);
}
}
}

0 comments on commit 6662fae

Please sign in to comment.