මචංලා POS ප්‍රශ්නයක්

Lokka Bro

Well-known member
  • Aug 18, 2020
    1,412
    2,514
    113
    Loading...
    elakiri.com
    මට බිස්නස් එකට POS සිස්ටම් එකක් ඔනා කරලා තියනවා.මම හිතුවෙ php ස්ක්‍රිප්ට් එකක් අරන් localhost එකේ දාගන්න.GPL සයිට් තියනවද POS එකක් ගන්න.මට GPL සයිට් ටිකක් දෙන්න දන්න කොල්ලො ටික.
    ලොකු උදව්වක් මිත්‍රවරුනී
     
    • Like
    Reactions: Nidarshana_k

    cocacola

    Well-known member
  • Jan 20, 2010
    1,584
    1,123
    113
    Android
    ubata coding gana hoda idea ekak thiyenawa nam uba nam business eke bill karanne, ecchara sale ekak nathi business ekak nam no issue..

    - uba yatathey wena staff ekak wada karanawa nam,
    - uba vena job ekak karanawa nam,
    - uba serious business ekak nam karanne ( retail shop etc.. )

    salli balanne nathuwa mey welawey market eke run wena pos ekak daa ganna,,,
    nikang mokatada salli denne kiyala hithei...
    habai ehema nevei...anthimata ubata business eka karanna wenne na..POS eka hada hada inna wei :)
     

    Lokka Bro

    Well-known member
  • Aug 18, 2020
    1,412
    2,514
    113
    Loading...
    elakiri.com
    ubata coding gana hoda idea ekak thiyenawa nam uba nam business eke bill karanne, ecchara sale ekak nathi business ekak nam no issue..

    - uba yatathey wena staff ekak wada karanawa nam,
    - uba vena job ekak karanawa nam,
    - uba serious business ekak nam karanne ( retail shop etc.. )

    salli balanne nathuwa mey welawey market eke run wena pos ekak daa ganna,,,
    nikang mokatada salli denne kiyala hithei...
    habai ehema nevei...anthimata ubata business eka karanna wenne na..POS eka hada hada inna wei :)
    තවම පටන් ගැන්ම මචන්.ලොකු මුදලක් pos එකට යට කරන්නෙ නැතුව ඉන්න බැලුවෙ මේ වෙලාවේ.දැනට php එකකින් රන් කරලා පස්සෙ pos එකකට යනවා
     

    Martian Professor

    Well-known member
  • Dec 4, 2024
    2,477
    3,137
    113
    තවම පටන් ගැන්ම මචන්.ලොකු මුදලක් pos එකට යට කරන්නෙ නැතුව ඉන්න බැලුවෙ මේ වෙලාවේ.දැනට php එකකින් රන් කරලා පස්සෙ pos එකකට යනවා
    Mail eka daanna..mama php Script ekk dennam
     

    VimangaLK

    Well-known member
  • Sep 26, 2024
    3,130
    2,140
    113
    PHP:
    <?php
    // Configuration and Database Connection
    require_once 'config/database.php';
    require_once 'config/session.php';
    
    // Autoload Classes
    spl_autoload_register(function($class) {
        $directories = [
            'models/',
            'controllers/',
            'services/'
        ];
        
        foreach ($directories as $directory) {
            $filename = $directory . $class . '.php';
            if (file_exists($filename)) {
                require_once $filename;
                return;
            }
        }
    });
    
    // Main Application Class
    class POSApplication {
        private $database;
        private $userService;
        private $productService;
        private $saleService;
    
        public function __construct() {
            // Initialize database connection
            $this->database = new Database();
            
            // Initialize services
            $this->userService = new UserService($this->database);
            $this->productService = new ProductService($this->database);
            $this->saleService = new SaleService($this->database);
        }
    
        // User Authentication
        public function authenticate($username, $password) {
            return $this->userService->login($username, $password);
        }
    
        // Product Management
        public function addProduct($data) {
            return $this->productService->create($data);
        }
    
        public function updateProduct($id, $data) {
            return $this->productService->update($id, $data);
        }
    
        public function deleteProduct($id) {
            return $this->productService->delete($id);
        }
    
        // Sale Processing
        public function processSale($saleData) {
            return $this->saleService->create($saleData);
        }
    
        // Reporting
        public function generateSalesReport($startDate, $endDate) {
            return $this->saleService->generateReport($startDate, $endDate);
        }
    }
    
    // Database Connection Class
    class Database {
        private $host = 'localhost';
        private $username = 'root';
        private $password = '';
        private $database = 'advanced_pos';
        public $connection;
    
        public function __construct() {
            $this->connection = new mysqli($this->host, $this->username, $this->password, $this->database);
            
            if ($this->connection->connect_error) {
                throw new Exception("Database Connection Failed: " . $this->connection->connect_error);
            }
        }
    
        public function prepare($sql) {
            return $this->connection->prepare($sql);
        }
    
        public function beginTransaction() {
            $this->connection->begin_transaction();
        }
    
        public function commit() {
            $this->connection->commit();
        }
    
        public function rollback() {
            $this->connection->rollback();
        }
    }
    
    // User Service
    class UserService {
        private $db;
    
        public function __construct(Database $database) {
            $this->db = $database;
        }
    
        public function login($username, $password) {
            $stmt = $this->db->prepare("SELECT id, username, password_hash, role FROM users WHERE username = ?");
            $stmt->bind_param("s", $username);
            $stmt->execute();
            $result = $stmt->get_result();
            
            if ($user = $result->fetch_assoc()) {
                if (password_verify($password, $user['password_hash'])) {
                    // Start session and store user info
                    $_SESSION['user_id'] = $user['id'];
                    $_SESSION['username'] = $user['username'];
                    $_SESSION['role'] = $user['role'];
                    return true;
                }
            }
            return false;
        }
    
        public function createUser($username, $password, $role) {
            $password_hash = password_hash($password, PASSWORD_BCRYPT);
            $stmt = $this->db->prepare("INSERT INTO users (username, password_hash, role) VALUES (?, ?, ?)");
            $stmt->bind_param("sss", $username, $password_hash, $role);
            return $stmt->execute();
        }
    }
    
    // Product Service
    class ProductService {
        private $db;
    
        public function __construct(Database $database) {
            $this->db = $database;
        }
    
        public function create($productData) {
            $stmt = $this->db->prepare("
                INSERT INTO products
                (name, description, price, cost_price, category_id, stock_quantity, barcode)
                VALUES (?, ?, ?, ?, ?, ?, ?)
            ");
            $stmt->bind_param(
                "ssddiss",
                $productData['name'],
                $productData['description'],
                $productData['price'],
                $productData['cost_price'],
                $productData['category_id'],
                $productData['stock_quantity'],
                $productData['barcode']
            );
            return $stmt->execute();
        }
    
        public function update($productId, $productData) {
            $stmt = $this->db->prepare("
                UPDATE products
                SET name = ?, description = ?, price = ?, cost_price = ?,
                    category_id = ?, stock_quantity = ?, barcode = ?
                WHERE id = ?
            ");
            $stmt->bind_param(
                "ssddissi",
                $productData['name'],
                $productData['description'],
                $productData['price'],
                $productData['cost_price'],
                $productData['category_id'],
                $productData['stock_quantity'],
                $productData['barcode'],
                $productId
            );
            return $stmt->execute();
        }
    
        public function delete($productId) {
            $stmt = $this->db->prepare("DELETE FROM products WHERE id = ?");
            $stmt->bind_param("i", $productId);
            return $stmt->execute();
        }
    
        public function getProductByBarcode($barcode) {
            $stmt = $this->db->prepare("SELECT * FROM products WHERE barcode = ?");
            $stmt->bind_param("s", $barcode);
            $stmt->execute();
            return $stmt->get_result()->fetch_assoc();
        }
    }
    
    // Sale Service
    class SaleService {
        private $db;
    
        public function __construct(Database $database) {
            $this->db = $database;
        }
    
        public function create($saleData) {
            try {
                // Start transaction
                $this->db->beginTransaction();
    
                // Insert sale master record
                $stmt = $this->db->prepare("
                    INSERT INTO sales
                    (user_id, total_amount, payment_method, sale_date)
                    VALUES (?, ?, ?, NOW())
                ");
                $stmt->bind_param(
                    "ids",
                    $saleData['user_id'],
                    $saleData['total_amount'],
                    $saleData['payment_method']
                );
                $stmt->execute();
                $sale_id = $stmt->insert_id;
    
                // Insert sale items
                $itemStmt = $this->db->prepare("
                    INSERT INTO sale_items
                    (sale_id, product_id, quantity, unit_price)
                    VALUES (?, ?, ?, ?)
                ");
    
                foreach ($saleData['items'] as $item) {
                    $itemStmt->bind_param(
                        "iid",
                        $sale_id,
                        $item['product_id'],
                        $item['quantity'],
                        $item['unit_price']
                    );
                    $itemStmt->execute();
    
                    // Update product stock
                    $updateStockStmt = $this->db->prepare("
                        UPDATE products
                        SET stock_quantity = stock_quantity - ?
                        WHERE id = ?
                    ");
                    $updateStockStmt->bind_param("ii", $item['quantity'], $item['product_id']);
                    $updateStockStmt->execute();
                }
    
                // Commit transaction
                $this->db->commit();
                return $sale_id;
            } catch (Exception $e) {
                // Rollback in case of error
                $this->db->rollback();
                throw $e;
            }
        }
    
        public function generateReport($startDate, $endDate) {
            $stmt = $this->db->prepare("
                SELECT
                    p.name AS product_name,
                    SUM(si.quantity) AS total_quantity,
                    SUM(si.quantity * si.unit_price) AS total_revenue
                FROM sales s
                JOIN sale_items si ON s.id = si.sale_id
                JOIN products p ON si.product_id = p.id
                WHERE s.sale_date BETWEEN ? AND ?
                GROUP BY p.id
            ");
            $stmt->bind_param("ss", $startDate, $endDate);
            $stmt->execute();
            return $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
        }
    }
    
    // Usage Example
    try {
        $pos = new POSApplication();
    
        // Example: User Authentication
        if ($pos->authenticate('admin', 'password123')) {
            // Example: Add a Product
            $productData = [
                'name' => 'Smart Phone',
                'description' => 'Latest model smartphone',
                'price' => 50000,
                'cost_price' => 40000,
                'category_id' => 1,
                'stock_quantity' => 50,
                'barcode' => '123456789'
            ];
            $pos->addProduct($productData);
    
            // Example: Process a Sale
            $saleData = [
                'user_id' => 1,
                'total_amount' => 100000,
                'payment_method' => 'cash',
                'items' => [
                    [
                        'product_id' => 1,
                        'quantity' => 2,
                        'unit_price' => 50000
                    ]
                ]
            ];
            $saleId = $pos->processSale($saleData);
    
            // Example: Generate Sales Report
            $report = $pos->generateSalesReport('2024-01-01', '2024-12-31');
        }
    } catch (Exception $e) {
        // Error Handling
        error_log($e->getMessage());
    }
    ?>
     

    XibitZ

    Well-known member
  • Oct 10, 2008
    13,243
    1
    4,032
    113
    Moratuwa
    මම දැක්ක විදියට ගොඩක් ඒවල තියෙන්නේ SDB බැන්ක් එකේ ඒවා
     

    XibitZ

    Well-known member
  • Oct 10, 2008
    13,243
    1
    4,032
    113
    Moratuwa
    නිකමට ලින්ක් එකට ගියා.සයිට් එක වත් වැඩ නෑ කියහන්කො :lol:

    මුංගේ මොකක් හරි වාසියක් ඇති. මම කාඩ් පේමන්ට් කරපු ගොඩක් තැන්වල උන්ගේ ඒවා තමයි තිබ්බේ
     

    madboyxxx

    Well-known member
  • Feb 22, 2010
    483
    416
    63
    Kandy
    ලංකාවේ මගුල් නම් ගන්න එපා.. CodeCanyon එකෙන් rating තියන script එකක් අරන් දාගන්න.
    මන් use කරේ මේක - iRestora PLUS
     

    mdrc111

    Well-known member
  • Oct 13, 2009
    5,537
    1,503
    113
    දක්ශින දේශය
    මම github ඒකේ ඒ්වා දාන්න හැදුව හරි ගියේ නැහැ
    උදව් කරන්න පුලුවන් දාගන්න
    දැනට මම aronium පාවිච්චි කරන්නෙ