Skip to content

Commit

Permalink
hook InvoiceCancelled #9
Browse files Browse the repository at this point in the history
  • Loading branch information
andrekutianski committed Oct 18, 2021
1 parent b5ba58c commit ca5e09e
Show file tree
Hide file tree
Showing 3 changed files with 24 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 @@ -3,7 +3,7 @@ Checklist dos hooks a serem migrados
* [x] InvoiceCreation
* [x] InvoicePaid
* [ ] AdminInvoicesControlsOutput
* [ ] InvoiceCancelled
* [x] InvoiceCancelled
* [ ] DailyCronJob
* [ ] AfterCronJob
* [ ] ProductDelete
Expand Down
5 changes: 5 additions & 0 deletions modules/addons/NFEioServiceInvoices/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@
$legacyHooks = new \NFEioServiceInvoices\Legacy\Hooks();
$legacyHooks->invoicepaid($vars);
});

add_hook('InvoiceCancelled', 1, function ($vars) {
$legacyHooks = new \NFEioServiceInvoices\Legacy\Hooks();
$legacyHooks->invoicecancelled($vars);
});
18 changes: 18 additions & 0 deletions modules/addons/NFEioServiceInvoices/lib/Legacy/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,22 @@ function invoicepaid($vars)
}
}
}

function invoicecancelled($vars)
{
$params = $this->functions->gnfe_config();
if ($params['cancel_invoice_cancel_nfe']) {
$nfe_for_invoice = $this->functions->gnfe_get_local_nfe($vars['invoiceid'], ['nfe_id', 'status', 'services_amount', 'environment']);
if ($nfe_for_invoice['status'] === (string) 'Issued') {
$invoice = localAPI('GetInvoice', ['invoiceid' => $vars['invoiceid']], false);
$delete_nfe = $this->functions->gnfe_delete_nfe($nfe_for_invoice['nfe_id']);
if (!$delete_nfe->message) {
logModuleCall('gofas_nfeio', 'invoicecancelled', $nfe_for_invoice['nfe_id'], $delete_nfe, 'OK', '');
$gnfe_update_nfe = $this->functions->gnfe_update_nfe((object) ['id' => $nfe_for_invoice['nfe_id'], 'status' => 'Cancelled', 'servicesAmount' => $nfe_for_invoice['services_amount'], 'environment' => $nfe_for_invoice['environment'], 'flow_status' => $nfe_for_invoice['flow_status']], $invoice['userid'], $vars['invoiceid'], 'n/a', $nfe_for_invoice['created_at'], date('Y-m-d H:i:s'));
} else {
logModuleCall('gofas_nfeio', 'invoicecancelled', $nfe_for_invoice['nfe_id'], $delete_nfe, 'ERROR', '');
}
}
}
}
}

0 comments on commit ca5e09e

Please sign in to comment.