accounting workflows
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require_role($user_role, ['owner', 'admin', 'staff']);
|
||||
require '../../../assets/utils/classes/PaymentManager.php';
|
||||
|
||||
try {
|
||||
$mgr = new PaymentManager($pdo2, $company_id);
|
||||
$action = $data['action'] ?? ($_POST['action'] ?? '');
|
||||
|
||||
if ($action === 'open_documents') {
|
||||
$contact_id = (int)($data['contact_id'] ?? 0);
|
||||
$answer['output'] = $mgr->getOpenDocuments($contact_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'save_formula') {
|
||||
$id = (int)($data['id'] ?? 0);
|
||||
$formula_id = isset($data['formula_id']) && (int)$data['formula_id'] > 0 ? (int)$data['formula_id'] : null;
|
||||
$mgr->saveFormula($id, $formula_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'retrieve') {
|
||||
$payment_id = (int)($data['id'] ?? $data['payment_id'] ?? 0);
|
||||
$answer['output'] = $mgr->getPaymentById($payment_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'void') {
|
||||
$payment_id = (int)($data['id'] ?? $data['payment_id'] ?? 0);
|
||||
dbTransaction($pdo2, function($pdo) use ($payment_id, $company_id, $logging) {
|
||||
$mgr = new PaymentManager($pdo, $company_id);
|
||||
$mgr->voidPayment($payment_id, $logging);
|
||||
});
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = 'Payment voided.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'create') {
|
||||
$new_id = null;
|
||||
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging, &$new_id) {
|
||||
$mgr = new PaymentManager($pdo, $company_id);
|
||||
$new_id = $mgr->createPayment($data, $logging);
|
||||
});
|
||||
$answer['success'] = 1;
|
||||
$answer['new_id'] = $new_id;
|
||||
$answer['message'] = 'Payment posted.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$answer['output'] = $mgr->getPaymentList();
|
||||
$answer['success'] = 1;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$answer['message'] = 'Database error, please try again.';
|
||||
http_response_code(500);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
?>
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require_role($user_role, ['owner', 'admin', 'staff']);
|
||||
require '../../../assets/utils/classes/PaymentBillingManager.php';
|
||||
|
||||
try {
|
||||
$mgr = new PaymentBillingManager($pdo2, $company_id);
|
||||
$action = $data['action'] ?? ($_POST['action'] ?? '');
|
||||
|
||||
if ($action === 'billable_documents') {
|
||||
$contact_id = (int)($data['contact_id'] ?? 0);
|
||||
$answer['output'] = $mgr->getBillableDocuments($contact_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'open_billings') {
|
||||
$contact_id = (int)($data['contact_id'] ?? 0);
|
||||
$answer['output'] = $mgr->getOpenBillingList($contact_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'retrieve') {
|
||||
$billing_id = (int)($data['id'] ?? $data['billing_id'] ?? 0);
|
||||
$answer['output'] = $mgr->getBillingById($billing_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'void') {
|
||||
$billing_id = (int)($data['id'] ?? $data['billing_id'] ?? 0);
|
||||
dbTransaction($pdo2, function($pdo) use ($billing_id, $company_id, $logging) {
|
||||
$mgr = new PaymentBillingManager($pdo, $company_id);
|
||||
$mgr->voidBilling($billing_id, $logging);
|
||||
});
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = 'Payment billing voided.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'create') {
|
||||
$new_id = null;
|
||||
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging, &$new_id) {
|
||||
$mgr = new PaymentBillingManager($pdo, $company_id);
|
||||
$new_id = $mgr->createBilling($data, $logging);
|
||||
});
|
||||
$answer['success'] = 1;
|
||||
$answer['new_id'] = $new_id;
|
||||
$answer['message'] = 'Payment billing created.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$answer['output'] = $mgr->getBillingList();
|
||||
$answer['success'] = 1;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$answer['message'] = 'Database error, please try again.';
|
||||
http_response_code(500);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
?>
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require_role($user_role, ['owner', 'admin', 'staff']);
|
||||
require '../../../assets/utils/classes/ReceiptManager.php';
|
||||
|
||||
try {
|
||||
$mgr = new ReceiptManager($pdo2, $company_id);
|
||||
$action = $data['action'] ?? ($_POST['action'] ?? '');
|
||||
|
||||
if ($action === 'open_documents') {
|
||||
$contact_id = (int)($data['contact_id'] ?? 0);
|
||||
$answer['output'] = $mgr->getOpenDocuments($contact_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'save_formula') {
|
||||
$id = (int)($data['id'] ?? 0);
|
||||
$formula_id = isset($data['formula_id']) && (int)$data['formula_id'] > 0 ? (int)$data['formula_id'] : null;
|
||||
$mgr->saveFormula($id, $formula_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'retrieve') {
|
||||
$receipt_id = (int)($data['id'] ?? $data['receipt_id'] ?? 0);
|
||||
$answer['output'] = $mgr->getReceiptById($receipt_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'void') {
|
||||
$receipt_id = (int)($data['id'] ?? $data['receipt_id'] ?? 0);
|
||||
dbTransaction($pdo2, function($pdo) use ($receipt_id, $company_id, $logging) {
|
||||
$mgr = new ReceiptManager($pdo, $company_id);
|
||||
$mgr->voidReceipt($receipt_id, $logging);
|
||||
});
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = 'Receipt voided.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'create') {
|
||||
$new_id = null;
|
||||
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging, &$new_id) {
|
||||
$mgr = new ReceiptManager($pdo, $company_id);
|
||||
$new_id = $mgr->createReceipt($data, $logging);
|
||||
});
|
||||
$answer['success'] = 1;
|
||||
$answer['new_id'] = $new_id;
|
||||
$answer['message'] = 'Receipt posted.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$answer['output'] = $mgr->getReceiptList();
|
||||
$answer['success'] = 1;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$answer['message'] = 'Database error, please try again.';
|
||||
http_response_code(500);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
?>
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require_role($user_role, ['owner', 'admin', 'staff']);
|
||||
require '../../../assets/utils/classes/ReceiptBillingManager.php';
|
||||
|
||||
try {
|
||||
$mgr = new ReceiptBillingManager($pdo2, $company_id);
|
||||
$action = $data['action'] ?? ($_POST['action'] ?? '');
|
||||
|
||||
if ($action === 'billable_documents') {
|
||||
$contact_id = (int)($data['contact_id'] ?? 0);
|
||||
$answer['output'] = $mgr->getBillableDocuments($contact_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'open_billings') {
|
||||
$contact_id = (int)($data['contact_id'] ?? 0);
|
||||
$answer['output'] = $mgr->getOpenBillingList($contact_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'retrieve') {
|
||||
$billing_id = (int)($data['id'] ?? $data['billing_id'] ?? 0);
|
||||
$answer['output'] = $mgr->getBillingById($billing_id);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'void') {
|
||||
$billing_id = (int)($data['id'] ?? $data['billing_id'] ?? 0);
|
||||
dbTransaction($pdo2, function($pdo) use ($billing_id, $company_id, $logging) {
|
||||
$mgr = new ReceiptBillingManager($pdo, $company_id);
|
||||
$mgr->voidBilling($billing_id, $logging);
|
||||
});
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = 'Receipt billing voided.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'create') {
|
||||
$new_id = null;
|
||||
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging, &$new_id) {
|
||||
$mgr = new ReceiptBillingManager($pdo, $company_id);
|
||||
$new_id = $mgr->createBilling($data, $logging);
|
||||
});
|
||||
$answer['success'] = 1;
|
||||
$answer['new_id'] = $new_id;
|
||||
$answer['message'] = 'Receipt billing created.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$answer['output'] = $mgr->getBillingList();
|
||||
$answer['success'] = 1;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$answer['message'] = 'Database error, please try again.';
|
||||
http_response_code(500);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
?>
|
||||
Reference in New Issue
Block a user