Fix bugs related to submitting a new application
This commit is contained in:
parent
be7c0d84bd
commit
ab34361c28
BIN
assets/pasted-20251204-044954-e49cb3ce.png
Normal file
BIN
assets/pasted-20251204-044954-e49cb3ce.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
@ -27,7 +27,7 @@ try {
|
||||
$application_id = 'APP-' . strtoupper(uniqid());
|
||||
$created_by = $_SESSION['user']['username'] ?? 'system';
|
||||
|
||||
$stmt = $db->prepare(
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO customer_applications (user_id, company_name, company_website, company_phone, sales_owner, payment_terms, tags, notes, declaration_text, signature_path, major_product, capital, capital_currency, main_shareholders, num_employees, payment_terms_ar, pl_year, net_sales, net_income_margin, net_income_margin_ratio, sales_target_this_year, sales_target_next_year, sales_target_after_next, credit_rank, credit_limit, credit_research_status, credit_research_reason, tax_rate_area, billing_type, del_to_code, delivery_abbreviation, del_to_customer_name, del_to_address_1, del_to_address_2, del_to_address_3, del_to_address_4, del_to_postcode, del_to_phone, del_to_area_code, del_to_transportation_code, del_to_stock_point_code, del_to_recipient_section, del_to_country_code, del_to_shipment_flag, del_to_transport_days, del_to_shipment_condition_category, del_to_transport_service_exist, del_to_shipment_condition_place, doc_req_do, doc_req_packing_list, doc_req_invoice, doc_req_export_permit, doc_req_po_do_inv, doc_req_do_inv, doc_req_others, pack_req_one_line_carton, pack_req_one_item_carton, pack_req_one_item_pocket, pack_req_thomson_label, pack_req_contents_label, pack_req_delivery_schedule, forwarder_name, forwarder_code, forwarder_address, forwarder_contact_person, forwarder_phone, forwarder_fax, forwarder_delivery_method, forwarder_delivery_timings, forwarder_delivery_requirements, special_instructions_shipping_mark, special_instructions_fax_documents, special_instructions_details, special_instructions_attention_to, special_instructions_fax_number, remarks) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
||||
);
|
||||
$stmt->execute([
|
||||
@ -199,6 +199,28 @@ try {
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
// Notify approvers
|
||||
require_once 'mail/MailService.php';
|
||||
$approver_emails = get_user_emails_by_role('Approver Level 1', $pdo);
|
||||
if (!empty($approver_emails)) {
|
||||
// Get Sales Rep name
|
||||
$stmt_sales_rep = $pdo->prepare('SELECT name FROM users WHERE id = ?');
|
||||
$stmt_sales_rep->execute([$_SESSION['user_id']]);
|
||||
$sales_rep_name = $stmt_sales_rep->fetchColumn();
|
||||
|
||||
$subject = 'New Credit Application Submitted - ' . $_POST['company_name'];
|
||||
$submission_date = date('Y-m-d');
|
||||
$body = "
|
||||
<p>A new credit application has been submitted and requires your approval.</p>
|
||||
<p><strong>Customer Name:</strong> {$_POST['company_name']}</p>
|
||||
<p><strong>Sales Rep:</strong> {$sales_rep_name}</p>
|
||||
<p><strong>Credit Amount:</strong> $" . number_format($_POST['credit_limit'], 2) . "</p>
|
||||
<p><strong>Submission Date:</strong> {$submission_date}</p>
|
||||
<p><a href='http://{$_SERVER['HTTP_HOST']}/view_application.php?id={$customer_application_id}' style='display: inline-block; padding: 10px 20px; background-color: #007bff; color: #fff; text-decoration: none;'>View Application</a></p>
|
||||
";
|
||||
MailService::sendMail($approver_emails, $subject, $body);
|
||||
}
|
||||
|
||||
// Redirect to dashboard with success message
|
||||
$_SESSION['flash_message'] = [
|
||||
'type' => 'success',
|
||||
@ -207,6 +229,12 @@ try {
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
|
||||
function get_user_emails_by_role($role_name, $pdo) {
|
||||
$stmt = $pdo->prepare('SELECT u.email FROM users u JOIN user_roles ur ON u.id = ur.user_id JOIN roles r ON ur.role_id = r.id WHERE r.name = ?');
|
||||
$stmt->execute([$role_name]);
|
||||
return $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$pdo->rollBack();
|
||||
error_log('Application submission failed: ' . $e->getMessage());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user