# BAA Aequitas Association Tally System – Complete Package v3

## Directory Structure
```
/home/belugadev/
├─ belugacore/dbConnect/mysql.php
└─ public_html/BAA-AMS/
   ├─ Beluga_Currency_Tally.html
   ├─ inventory_tally.php
   ├─ admin_report.php
   ├─ ReadMe.md
   └─ sql/
       └─ tally.sql
```

## Setup Steps

1. Upload **all files** under `/home/belugadev/public_html/BAA-AMS/`.

2. **Database**
   - Open phpMyAdmin → select `belugadev_beluga_association`.
   - Go to **SQL** tab → paste contents of `sql/tally.sql` → click **Go**.

3. **Bitrix24 Custom Fields**
   - In CRM → Settings → CRM Fields → Contacts:
     - Create **Tally Submitted** (Yes/No → Checkbox).
     - Create **Tally Date Submitted** (Date/Time).
   - If UI doesn’t show “Field Code,” in browser visit:
     ```
     https://yourcompany.bitrix24.com/rest/1/WEBHOOK_ID/userfield.userfield.get?ENTITY_ID=CRM_CONTACT
     ```
     and copy `FIELD_NAME` for each field (e.g. `UF_CRM_TALLY_SUBMITTED`, `UF_CRM_TALLY_DATE`).

4. **Webhook**
   - In Bitrix24 (CRM module) → Settings → Integrations → Webhooks → Add Inbound Webhook.
   - Grant **crm.contact.update**.
   - Copy the generated URL:
     ```
     https://yourcompany.bitrix24.com/rest/1/ABC123XYZ/crm.contact.update

https://b24-vs4xys.bitrix24.eu/rest/353/muwv8afa56aup4v9/
https://b24-vs4xys.bitrix24.eu/rest/353/muwv8afa56aup4v9/crm.contact.update.json
     ```

5. **Configure PHP**
   - Open `inventory_tally.php`.
   - Update DB creds if needed.
   - Replace `$webhookUrl` with your actual webhook URL.
   - Save changes.

6. **Permissions**
   ```
   chmod 644 ~/public_html/BAA-AMS/*.php
   chmod 644 ~/public_html/BAA-AMS/*.html
   chmod 755 ~/public_html/BAA-AMS/sql
   chmod 644 ~/public_html/BAA-AMS/sql/tally.sql
   ```

7. **Test Workflow**
   - Visit:
     ```
     https://beluga-online.ch/BAA-AMS/Beluga_Currency_Tally.html
     ```
   - Enter Member ID, accept terms, fill quantities.
   - Test Print, Save PDF, Return to Top.
   - Click Submit → 3 confirmations → locks & posts.
   - Check phpMyAdmin → `tally_submissions`.
   - Check Bitrix24 contact → Tally Submitted & Tally Date.
   - Check email at `assets@beluga-association.ch`.

8. **Admin Report**
   ```
   https://beluga-online.ch/BAA-AMS/admin_report.php?start=2025-01-01&end=2025-12-31
   ```
   → downloads CSV.

---


In phpMyAdmin you will find:
Database: whatever DB_NAME is set to in beluga_connect.php

Table: pre_registrations

Columns:

firstname ← your $first_name

middlename ← your $middle_name

lastname ← your $last_name

email ← your $email

phone ← your $phone
