# CCTV Service & Account Management Software

A robust, enterprise-grade **Service Ticket, Inventory, and Accounting Management System** designed specifically for CCTV security system providers and repair agencies. Built using pure PHP (OOP via PDO), MySQL, Tailwind CSS, and vanilla JavaScript.

---

## 🚀 Key Modules & Features

### 🛠️ 1. Service Desk & Ticket Management (Complaints)
- **Ticket Lifecycle**: Log complaints, record client issues, assign jobs to specific field technicians, set status updates (Pending, In Progress, Solved), and capture client feedback.
- **Client Search**: Auto-complete searchable customer dropdowns on complaints registration.
- **Service Billing**: Seamless transition from resolved service ticket to invoice generation, incorporating repair services charges and parts consumed details.

### 📦 2. Stock & Inventory Management
- **Product Tracking**: Categorize products, track stock levels (Opening Stock and Current Stock), and manage serial numbers.
- **FIFO Batch Tracking**: Purchase entries generate unique product stock batches with distinct costs. Sales automatically deduct from active batches on a First-In-First-Out basis.
- **Technician Inventory**: Tracks stock issued to technicians for site visits and service jobs.

### 💼 3. Accounting & Ledgers
- **Sales & Purchases**: Log itemized sales and vendor purchases with flexible GST calculations (Inclusive / Exclusive slabs: 0%, 5%, 12%, 18%, 28%).
- **Financial Ledgers**:
  - **Cash & Bank Ledgers**: Displays cash-in-hand and bank statement lines.
  - **Customer & Supplier Ledgers**: Complete credit tracking, payment logging, and balance dues summaries.
- **Voucher Vouching**: Log receipt and payment vouchers for direct tracking of miscellaneous business income/expenses.

### 🖨️ 4. Tally-Style Print Layouts
- **Custom Print Layouts**: Invoice outputs (`invoice_gen.php` and `purchase_bill_gen.php`) are styled using A4-portrait print guidelines matching standard corporate layouts:
  - **Main Goods Table**: Itemized columns with Sl No, Description of Goods, HSN/SAC, GST%, Quantity, Unit Rate, per, Discount, and Net Amount.
  - **Boxed Taxable Slab Breakdown**: Inner cell partition lines detailing GST rates, taxable value, and SGST/CGST/IGST breakdown.
  - **Calculations Summary**: Visual display of Gross Value, Discount (%), Total GST, Adjustment Amount (Round Off to integer), Extra Charges, and Net Amount.
  - **Declaration & Transporter Signature Line**: Clean compliance block.
  - **PDF Export**: Full PDF downloads via client-side print emulations (`html2pdf.js`).

---

## 📂 Project Directory Structure

```lispt
cctv/
├── index.php                 # Core Dashboard Router & Login
├── check.php                 # Auth checking helper
├── dev_login.php             # Developer auto-authentication access
├── forgot_password.php       # Password recovery handler
├── register_company.php      # Company onboarding portal
├── database.sql / db.sql     # Database schema structure dump
│
├── includes/                 # Global layout inclusions
│   ├── auth.php              # Session checks and role-based access control
│   ├── db_connect.php        # PDO database connection configuration
│   ├── header.php            # HTML top, stylesheet bindings, global helper functions
│   └── footer.php            # HTML bottom, script imports
│
├── uploads/                  # Uploaded logos, sign images, attachments
│
├── admin/                    # Admin Control Panel
│   ├── index.php             # Admin Dashboard metrics, ticket charts, recent sales
│   ├── company_profile.php   # Manage logo, company bank settings, address, terms
│   ├── complaints.php        # Manage service tickets & status updates
│   ├── customers.php         # Manage customer directories
│   ├── technicians.php       # Technician list & credential assignments
│   ├── amc_tracking.php      # Annual Maintenance Contracts tracker
│   ├── reports.php           # Business metrics & performance reports
│   │
│   ├── accounts/             # Ledger & Financial accounting scripts
│   │   ├── sales.php         # Create new sales invoices (with searchable dropdowns)
│   │   ├── edit_sale.php     # Modify existing sales invoice data
│   │   ├── purchases.php     # Enter vendor purchases
│   │   ├── edit_purchase.php # Edit purchases
│   │   ├── cash_ledger.php   # Cash Transactions Ledger
│   │   ├── bank_ledger.php   # Bank Ledger
│   │   ├── customer_payments.php
│   │   ├── supplier_payments.php
│   │   ├── dues.php          # Dues list
│   │   ├── daily_reports.php # Combined daybook reports
│   │   ├── invoice_gen.php   # Print/PDF generator for sales invoices
│   │   └── purchase_bill_gen.php # Print/PDF generator for purchases
│   │
│   └── stock/                # Product inventory managers
│       ├── products.php      # Base product catalog & opening stock manager
│       ├── child_products.php# Partner/Child brand product catalogues
│       └── serials.php       # Track item serial numbers (Available, Sold)
│
├── tech/                     # Technician Portal (Mobile-friendly layout)
│   ├── index.php             # Technician jobs dashboard list
│   ├── service-update.php    # Update complaint progress, log materials/serials used
│   ├── inventory.php         # View currently issued field inventory stock list
│   └── invoice_gen.php       # Technician customer-facing receipt printer
│
└── api/                      # Backend AJAX / API endpoints
```

---

## 🛠️ Setup & Installation

### 1. Requirements
- Local Web Server (XAMPP / WAMP / Laragon) with **PHP 7.4+**
- **MySQL / MariaDB**

### 2. Database Migration
1. Open phpMyAdmin or your MySQL CLI client.
2. Create a new database:
   ```sql
   CREATE DATABASE cctv_db;
   ```
3. Import the database schema from the `database.sql` (or `db.sql`) file located at the project root:
   ```bash
   mysql -u root -p cctv_db < database.sql
   ```

### 3. Connection Configuration
Open `includes/db_connect.php` and verify the settings align with your MySQL server:
```php
$host = 'localhost';
$db   = 'cctv_db';
$user = 'root';
$pass = ''; // Set your password
```

### 4. Admin Access
- Navigate to `http://localhost/cctv/` in your browser.
- Set up a new company using `register_company.php` or sign in using your admin credentials.

---

## 🔒 Security & Access Levels

The software implements a strict Role-Based Access Control (RBAC) mechanism verified by `includes/auth.php`:
1. **Admin Role**: Full access to dashboard metrics, user management, profile settings, stock catalogs, sales/purchases billing, cash flow ledgers, and voucher vouching.
2. **Technician Role**: Restricted mobile-friendly portal access (`/tech/`). Allowed to update allocated service tickets, request/search parts inventory, view ticket history, and print customer repair receipts. Cannot access billing databases or financial ledgers.
