alert('$message'); window.location.href = '$redirectUrl'; "; exit(); } else { setcookie($_COOKIE["username"], '', time() - 3600, '/'); header("Location: https://blackhoundenterprises.com/invoices/index.php"); exit(); } } } else { setcookie($_COOKIE["username"], '', time() - 3600, '/'); header("Location: https://blackhoundenterprises.com/invoices/index.php"); exit(); } if(isset($_GET['logout']) && $_GET['logout'] == 1) { // Delete the cookie by setting its expiration time to a past value setcookie("username", $_COOKIE["username"], time() - 3600, '/'); // Redirect to the login page or any other page header("Location: https://blackhoundenterprises.com/invoices/index.php"); exit(); } // Check if the projects.db file exists, and if not, create it $dbFile2 = 'database/invoices.db'; if (!file_exists($dbFile2)) { $db = new SQLite3($dbFile2); if (!$db) { die("Failed to create the database file."); } // Create the 'projects' table $createQuery = "CREATE TABLE IF NOT EXISTS figures ( id INTEGER PRIMARY KEY AUTOINCREMENT, projectname TEXT, invoicefull TEXT, createdby TEXT, createdate TEXT, totalvalue TEXT, clientid INTEGER )"; $db->exec($createQuery); if (!$db->exec($createQuery)) { die("Failed to create the 'invoices' table."); } $db->close(); } else { $db = new SQLite3($dbFile2); if (!$db) { die("Database connection failed: " . $db->lastErrorMsg()); } } // Function to fetch and display data function displayDataForDue($db) { $totalDue = 0; $totalPaid = 0; $totalDuePrecentage = 0; $totalPaidPrecentage = 0; $totalPaidDay = 0; $totalPaidMonth = 0; $query = "SELECT id, projectname, invoicefull, createdby, createdate, totalvalue, status FROM figures"; $result = $db->query($query); $createYearString = []; //months data $createYearValue = []; //months data $createMonthString = []; //day data $createMonthValue = []; //day data $createJanTotal = 0; $createFebTotal = 0; $createMarTotal = 0; $createAprTotal = 0; $createMayTotal = 0; $createJunTotal = 0; $createJulTotal = 0; $createAugTotal = 0; $createSepTotal = 0; $createOctTotal = 0; $createNovTotal = 0; $createDecTotal = 0; $LastYearJanTotal = 0; $LastYearFebTotal = 0; $LastYearMarTotal = 0; $LastYearAprTotal = 0; $LastYearMayTotal = 0; $LastYearJunTotal = 0; $LastYearJulTotal = 0; $LastYearAugTotal = 0; $LastYearSepTotal = 0; $LastYearOctTotal = 0; $LastYearNovTotal = 0; $LastYearDecTotal = 0; $yearMinus2JanTotal = 0; $yearMinus2FebTotal = 0; $yearMinus2MarTotal = 0; $yearMinus2AprTotal = 0; $yearMinus2MayTotal = 0; $yearMinus2JunTotal = 0; $yearMinus2JulTotal = 0; $yearMinus2AugTotal = 0; $yearMinus2SepTotal = 0; $yearMinus2OctTotal = 0; $yearMinus2NovTotal = 0; $yearMinus2DecTotal = 0; $yearMinus3JanTotal = 0; $yearMinus3FebTotal = 0; $yearMinus3MarTotal = 0; $yearMinus3AprTotal = 0; $yearMinus3MayTotal = 0; $yearMinus3JunTotal = 0; $yearMinus3JulTotal = 0; $yearMinus3AugTotal = 0; $yearMinus3SepTotal = 0; $yearMinus3OctTotal = 0; $yearMinus3NovTotal = 0; $yearMinus3DecTotal = 0; $yearlyTotalValues = array(); $currentY = date('Y'); for ($i = 0; $i < 5; $i++) { $yearlyTotalValues[$currentY - $i] = 0; } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $currentYear = date('Y'); $currentMonth = date('m'); $currentDay = date('d'); $lastYear = date('Y', strtotime('-1 year')); $yearMinus2 = date('Y', strtotime('-2 year')); $yearMinus3 = date('Y', strtotime('-3 year')); $currentYearMonth = date('Y-m'); $dateString = $row['createdate']; list($year, $month, $day) = explode('-', $dateString); $dateYearMonth = $year . '-' . $month; $dateYear = $year; $dateMonth = $month; $dateDay = $day; if ($row['status'] == "unpaid") { // if ($dateYearMonth == $currentYearMonth) { $formattedTotalValue1 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $totalDue += $formattedTotalValue1; // } } else { if ($dateYearMonth == $currentYearMonth) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $totalPaid += $formattedTotalValue2; } } /// GET THE TOTAL VALUE OF EACH YEAR if ($row['status'] == "paid") { if ($year >= $currentYear - 4 && $year <= $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearlyTotalValues[$year] += $formattedTotalValue2; } } if ($row['status'] == "paid") { if ($dateYear == $currentYear) { $createYearString[] = $dateMonth; $formattedTotalValue1 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createYearValue[] = $formattedTotalValue1; // corrected assignment if ($dateMonth == $currentMonth) { $createMonthString[] = $dateDay; $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createMonthValue[] = $formattedTotalValue2; } } if ($dateMonth == "01") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createJanTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearJanTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2JanTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3JanTotal += $formattedTotalValue2; } } if ($dateMonth == "02") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createFebTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearFebTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2FebTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3FebTotal += $formattedTotalValue2; } } if ($dateMonth == "03") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createMarTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearMarTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2MarTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3MarTotal += $formattedTotalValue2; } } if ($dateMonth == "04") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createAprTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearAprTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2AprTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3AprTotal += $formattedTotalValue2; } } if ($dateMonth == "05") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createMayTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearMayTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2MayTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3MayTotal += $formattedTotalValue2; } } if ($dateMonth == "06") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createJunTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearJunTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2JunTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3JunTotal += $formattedTotalValue2; } } if ($dateMonth == "07") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createJulTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearJulTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2JulTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3JulTotal += $formattedTotalValue2; } } if ($dateMonth == "08") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createAugTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearAugTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2AugTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3AugTotal += $formattedTotalValue2; } } if ($dateMonth == "09") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createSepTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearSepTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2SepTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3SepTotal += $formattedTotalValue2; } } if ($dateMonth == "10") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createOctTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearOctTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2OctTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3OctTotal += $formattedTotalValue2; } } if ($dateMonth == "11") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createNovTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearNovTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2NovTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3NovTotal += $formattedTotalValue2; } } if ($dateMonth == "12") { if ($dateYear == $currentYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $createDecTotal += $formattedTotalValue2; } if ($dateYear == $lastYear) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $LastYearDecTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus2) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus2DecTotal += $formattedTotalValue2; } if ($dateYear == $yearMinus3) { $formattedTotalValue2 = preg_replace("/[^0-9.]+/", "", $row['totalvalue']); $yearMinus3DecTotal += $formattedTotalValue2; } } } } $total = $totalDue + $totalPaid; $totalDuePercentage = ($total != 0) ? ($totalDue / $total * 100) : 0; $totalPaidPercentage = ($total != 0) ? ($totalPaid / $total * 100) : 0; echo ""; echo ""; echo ""; } ?> Welcome
Home Clients Projects Invoices Statistics Leads Logout

Welcome, !