Add capability to sync collected invoices to E-Conomic
Introduced a new endpoint for syncing collected order invoices with E-Conomic via a POST route. Added methods for creating, managing, and closing invoice drafts in E-Conomic. The implementation includes validations, external ID handling, and seamless integration of payment terms and layout configurations.
This commit is contained in:
@@ -119,5 +119,34 @@ class orderInvoicesRoute
|
||||
]
|
||||
);
|
||||
|
||||
/** Collected order invoices > E-Conomic > POST */
|
||||
$this->post('/collected-invoices/economic', function () {
|
||||
global $response;
|
||||
self::requirePermission('add_collected_invoice_economic');
|
||||
$user = (new authentication())->get_user();
|
||||
if ($user) {
|
||||
(new logs_o())->add('orderInvoices', 'global', 1, $user->id, 'ADD_COLLECTED_INVOICE_ECONOMIC', 'User added a collected order invoice to E-Conomic');
|
||||
// Require the ID, and validate its type and length
|
||||
self::requireParameters(['id']);
|
||||
self::requireType((int)self::getParameter('id'), self::type_int());
|
||||
self::requireMinLength('id', 1);
|
||||
self::requireMaxLength('id', 10);
|
||||
// Require the ID to be above 0
|
||||
self::requireMinValue((int)self::getParameter('id'), 1);
|
||||
// Validate the ID against the database
|
||||
$collected_order_invoices = (new collected_order_invoices_o())->select((int)self::getParameter('id'));
|
||||
$collected_order_invoices->requireSelected();
|
||||
// Add the collected order invoice to E-Conomic
|
||||
$collected_order_invoices->addToEconomic();
|
||||
$response->success($collected_order_invoices->asArray());
|
||||
} else {
|
||||
(new logs_o())->add('orderInvoices', 'global', 0, 0, 'ADD_COLLECTED_INVOICE_ECONOMIC', 'User tried to add a collected order invoice to E-Conomic without a valid session');
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
},
|
||||
[
|
||||
'add_collected_invoice_economic' => 'Add a collected order invoice to E-Conomic. This is a superuser-only route.'
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user