dbms_primeidc_init...1

This commit is contained in:
최준흠 2025-04-08 19:33:34 +09:00
parent bbd1a8d8ac
commit f66b21f534
9 changed files with 709 additions and 195 deletions

View File

@ -4,6 +4,7 @@ namespace lib\Configs;
use \lib\Core\App as Core;
use Dotenv\Dotenv;
use lib\Database\DB;
class App extends Core
{
@ -12,6 +13,7 @@ class App extends Core
// .env 파일 로드
$dotenv = Dotenv::createImmutable(ROOT_PATH);
$dotenv->load();
DB::init(); // ✅ 여기서 초기화
parent::__construct();
}
}

View File

@ -49,6 +49,19 @@ $router->group('dbms/client/onetime', function (Router $router) {
// // Response::view($result);
// });
});
$router->group('dbms/client/payment', function (Router $router) {
$router->add('GET', 'billpaper', function ($params) {
$controller = new OnetimeController();
return $controller->billpaper($params);
// Response::view($result);
});
$router->add('GET', 'nonpayment', function ($params) {
$controller = new OnetimeController();
return $controller->nonpayment($params);
// Response::view($result);
});
});
// 예제 라우트 그룹: dbms/dashboard/index 이후에 key/value 파라미터 허용
$router->group('dbms/dashboard', function (Router $router) {

View File

@ -2,7 +2,7 @@
namespace lib\Controllers\DBMS\Client;
use lib\Services\ClientService;
use lib\Utils\Pagination;
class PaymentController extends ClientController
{
@ -11,4 +11,75 @@ class PaymentController extends ClientController
parent::__construct();
$this->getView()->setPath('payment');
} //
//청구서, depositbillpaper.php
//CLI 접속방법 : php index.php site/client/payment/billpaper
//WEB 접속방법 : http://localhostsite/client/payment/billpaper
public function billpaper(array $params): string
{
//사이트 정보 가져오기
if (!array_key_exists('sitekey', $params)) {
throw new \Exception("sitekey 값이 정의되지 않았습니다.");
}
$sitekey = $params['sitekey'];
$this->siteInfo = DBMS_SITEINFOS[$sitekey];
if (!array_key_exists($sitekey, DBMS_SITEINFOS)) {
throw new \Exception("[{$sitekey}]에 해당하는 사이트정보가 없습니다.");
}
//사용자정보가져오기
$client_code = $params['client_code'];
if (!array_key_exists('client_code', $params)) {
throw new \Exception("client_code 값이 정의되지 않았습니다.");
}
$client = $this->getClientService()->getEntityByCode($client_code);
if (!$client) {
throw new \Exception("[{$client_code}]에 해당하는 사이트정보가 없습니다.");
}
$this->client = $client;
return $this->render(__FUNCTION__);
}
//청구서, NonPaymentList.php
//CLI 접속방법 : php index.php site/client/payment/unpaid
//WEB 접속방법 : http://localhostsite/client/payment/unpaid
public function nonpayment(array $params): string
{
//사이트 정보 가져오기
if (!array_key_exists('sitekey', $params)) {
throw new \Exception("sitekey 값이 정의되지 않았습니다.");
}
$sitekey = $params['sitekey'];
$this->siteInfo = DBMS_SITEINFOS[$sitekey];
if (!array_key_exists($sitekey, DBMS_SITEINFOS)) {
throw new \Exception("[{$sitekey}]에 해당하는 사이트정보가 없습니다.");
}
//사용자정보가져오기
$client_code = $params['client_code'];
if (!array_key_exists('client_code', $params)) {
throw new \Exception("client_code 값이 정의되지 않았습니다.");
}
$client = $this->getClientService()->getEntityByCode($client_code);
if (!$client) {
throw new \Exception("[{$client_code}]에 해당하는 사이트정보가 없습니다.");
}
$this->client = $client;
//mode 당일,1일전,2일전,3일전,custom
$nonpaymentDay = 'all';
switch ($params['mode']) {
case '1day':
break;
case '2day':
break;
case '3day':
break;
case 'custom':
break;
default:
}
$total = count($temps);
$page = $parmas['page'] ?? 1;
$perPage = $parmas['perPage'] ?? 10;
$this->pagination = new Pagination($total, (int)$page, (int)$perPage);
return $this->render(path: __FUNCTION__);
}
} //Class

View File

@ -2,229 +2,70 @@
namespace lib\Core;
use \PDO;
use PDOException;
use PDOStatement;
use lib\Database\DB;
use lib\Database\QueryBuilder;
abstract class Model
{
private $_db = null;
private $_debug = false;
private $_reset = true;
private $_querys = ['SELECT' => 'SELECT *', 'JOIN' => [], 'ORDERBY' => [], 'LIMIT' => ''];
private $_wheres = [];
private $_lastQuery = "";
protected function __construct()
{
$this->init();
} //
private bool $_debug = false;
protected static QueryBuilder $queryBuilder;
public function __construct() {} //
abstract public function getTable(): string;
abstract public function getPKField(): string;
abstract public function getTitleField(): string;
final public function getConnect(): PDO
{
if ($this->_db === null) {
$driver = $_ENV['DATABASE_DRIVER'] ?? $_SERVER['DATABASE_DRIVER'] ?? 'mysql';
$host = $_ENV['DATABASE_HOST'] ?? $_SERVER['DATABASE_HOST'] ?? 'localhost';
$dbname = $_ENV['DATABASE_DB'] ?? $_SERVER['DATABASE_DB'] ?? 'test';
$charset = $_ENV['DATABASE_CHARSET'] ?? $_SERVER['DATABASE_CHARSET'] ?? 'utf8';
$user = $_ENV['DATABASE_ID'] ?? $_SERVER['DATABASE_ID'] ?? 'root';
$pass = $_ENV['DATABASE_PASSWORD'] ?? $_SERVER['DATABASE_PASSWORD'] ?? '';
$dsn = sprintf("%s:host=%s;dbname=%s;charset=%s", $driver, $host, $dbname, $charset);
try {
$this->_db = new PDO($dsn, $user, $pass);
$this->_db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$this->_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
throw new \Exception("❌ DB 연결 실패: " . $e->getMessage());
}
}
$this->init();
return $this->_db;
}
final public function setDebug($debug)
final public function setDebug(bool $debug): void
{
$this->_debug = $debug;
}
final public function getDebug()
final public function getDebug(): bool
{
return $this->_debug;
}
private function init(): void
public static function query(): QueryBuilder
{
$debug = $_ENV['DATABASE_QUERY_DEBUG'] ?? $_SERVER['DATABASE_QUERY_DEBUG'] ?? 'false';
if ($debug === "true") {
$this->_debug = true;
if (!isset(self::$queryBuilder)) {
self::$queryBuilder = new QueryBuilder(pdo: DB::getPDO()); // Assuming DB::getPDO() gives PDO instance
}
$this->_reset = true;
$this->_querys = ['SELECT' => 'SELECT *', 'JOIN' => [], 'ORDERBY' => [], 'LIMIT' => ''];
$this->_wheres = [];
$this->_lastQuery = "";
}
final public function getLastQuery(): string
{
return $this->_lastQuery;
return self::$queryBuilder->table((new static())->getTable());
}
//Where절관련
private function getColumnValue(mixed $datas, $delimeter = ","): string
public static function all(): array
{
$value = "";
if ($datas === null) {
return "";
}
if (is_array($datas)) {
$temps = [];
foreach ($datas as $data) {
$data = trim($data);
$temps[] = is_string($data) ? "'{$data}'" : $data;
}
$value = implode($delimeter, $temps);
} else {
$value = is_string($datas) ? "='{$datas}'" : $datas;
}
return $value;
return self::query()->get();
}
private function getColumnData(mixed $columns, mixed $datas = null, string $delimeter): string
public static function find($id): ?array
{
$temps = [];
if (is_array($columns)) {
//복합배열형태로 들어온 경우
foreach ($columns as $column => $data) {
$value = $this->getColumnValue($data);
$temps[] = " {$column}{$value} ";
}
} else {
$value = $this->getColumnValue($datas);
$temps[] = " {$columns}{$value} ";
}
// throw new \Exception("DATA:" . $columns . $value === null ? "NULL" : $value);
return implode($delimeter, $temps);
return self::query()->where((new static())->getPKField(), '=', $id)->first();
}
final public function getWhere(): string
public static function where(string $column, string $operator = "", mixed $value = ""): QueryBuilder
{
return count($this->_wheres) ? "WHERE " . implode(" ", $this->_wheres) : "";
return self::query()->where($column, $operator, $value);
}
final public function where(mixed $columns, mixed $values = null, string $delimeter = "AND"): void
public static function whereNotIn(string $column, array $values): QueryBuilder
{
$query = $this->getColumnData($columns, $values, $delimeter);
$this->_wheres[] = count($this->_wheres) ? "{$delimeter} {$query}" : $query;
return self::query()->whereNotIn($column, $values);
}
final public function orWhere(mixed $columns, mixed $values = null, string $delimeter = "OR"): void
public static function orWhereIn(string $column, array $values): QueryBuilder
{
$this->where($columns, $values, $delimeter);
return self::query()->orWhereIn($column, $values);
}
final public function whereLike(string $column, string $value, string $option = "both", string $delimeter = "AND"): void
public static function count(): int
{
switch ($option) {
case 'before':
$value = "%{$value}";
break;
case 'after':
$value = "{$value}%";
break;
default:
$value = "%{$value}%";
break;
}
$this->where("{$column} LIKE '{$value}'", null, $delimeter);
return self::query()->count();
}
final public function orWhereLike(string $column, string $value, string $option = "both", string $delimeter = "OR"): void
public static function insert(array $data): bool
{
$this->whereLike($column, $value, $option, $delimeter);
return self::query()->insert($data);
}
final public function whereIn(string $column, array $values, string $delimeter = "AND", $range = "IN")
public static function updateById($id, array $data): bool
{
$query = " {$column} {$range} (" . $this->getColumnValue($values) . ")";
$this->_wheres[] = count($this->_wheres) ? $delimeter . " " . $query : $query;
return self::query()->where((new static())->getPKField(), '=', $id)->update($data);
}
final public function whereNotIn(string $column, array $values, string $delimeter = "AND", $range = "NOT IN")
public static function deleteById($id): bool
{
$this->whereIn($column, $values, $delimeter, $range);
return self::query()->where((new static())->getPKField(), '=', $id)->delete();
}
final public function execute(string $query): bool|PDOStatement
{
if ($this->_debug) {
echo "\n<BR>Query:" . $query . "\n<BR>";
}
$this->_lastQuery = $query;
$stmt = $this->getConnect()->prepare($query);
$stmt->execute();
if ($this->_reset) {
$this->init();
}
return $stmt;
}
//CURD문
final protected function create_process(mixed $columns, mixed $values = null): bool|PDOStatement
{
$this->where($columns, $values);
$query = sprintf("INSERT INTO %s VALUES(%s) %s", $this->getTable(), $this->getColumnData($columns, $values, ","), $this->getWhere());
return $this->execute($query);
} //
final protected function modify_process(mixed $columns, mixed $values = null): bool|PDOStatement
{
$query = sprintf("UPDATE %s SET %s %s", $this->getTable(), $this->getColumnData($columns, $values, ","), $this->getWhere());
return $this->execute($query);
} //
final protected function delete_process(): bool|PDOStatement
{
$query = sprintf("DELETE FROM %s %s", $this->getTable(), $this->getWhere());
return $this->execute($query);
} //
public function select(mixed $columns = "*"): void
{
$columns = is_array($columns) ? implode(",", $columns) : $columns;
$this->_querys["SELECT"] = "SELECT {$columns}";
}
//join_type : LEFT, RIGHT, INNER, OUTER
final public function join(string $table, mixed $match = null, $join_type = ""): void
{
$this->_querys['JOIN'][] = " {$join_type} JOIN {$table} ON {$match}";
}
final public function orderBy(mixed $columns, string $default_direction = ""): void
{
if (is_array($columns)) {
foreach ($columns as $column => $direction) {
$this->orderBy($column, $direction ?? $default_direction);
}
} else {
$this->_querys['ORDERBY'][] = "{$columns} {$default_direction}";
}
}
final public function limit(int $start, int $offset = 0): void
{
$offset = $offset > 0 ? ",{$offset}" : "";
$this->_querys["LIMIT"] = " LIMIT {$start} {$offset}";
}
//Result
private function getResultQuery(string $head, string $tail = ""): string
{
$join = count($this->_querys['JOIN']) ? implode(",", $this->_querys['JOIN']) : "";
$where = $this->getWhere();
$orderby = count($this->_querys['ORDERBY']) ? "ORDER BY " . implode(",", $this->_querys['ORDERBY']) : "";
return "{$head} FROM {$this->getTable()} {$join} {$where} {$tail} {$orderby} {$this->_querys['LIMIT']}";
}
public function getResult($mode = PDO::FETCH_ASSOC): mixed
{
$stmt = $this->execute($this->getResultQuery($this->_querys['SELECT']));
return $stmt->fetch($mode);
}
public function getResults($mode = PDO::FETCH_ASSOC): mixed
{
$stmt = $this->execute($this->getResultQuery($this->_querys['SELECT']));
return $stmt->fetchAll($mode);
}
final public function countAllResults(string $column = "*", $reset = true): int
{
$this->_reset = $reset;
$stmt = $this->execute($this->getResultQuery("SELECT COUNT({$column})"));
$count = $stmt->fetchColumn(0);
$this->_reset = true;
return $count;
}
} //Class
}

View File

@ -0,0 +1,32 @@
<?php
namespace lib\Database;
use lib\Database\QueryBuilder;
use PDO;
class DB
{
private static PDO $pdo;
public static function init(): void
{
$driver = $_ENV['DATABASE_DRIVER'] ?? $_SERVER['DATABASE_DRIVER'] ?? 'mysql';
$host = $_ENV['DATABASE_HOST'] ?? $_SERVER['DATABASE_HOST'] ?? 'localhost';
$dbname = $_ENV['DATABASE_DB'] ?? $_SERVER['DATABASE_DB'] ?? 'test';
$charset = $_ENV['DATABASE_CHARSET'] ?? $_SERVER['DATABASE_CHARSET'] ?? 'utf8';
$user = $_ENV['DATABASE_ID'] ?? $_SERVER['DATABASE_ID'] ?? 'root';
$pass = $_ENV['DATABASE_PASSWORD'] ?? $_SERVER['DATABASE_PASSWORD'] ?? '';
$dsn = sprintf("%s:host=%s;dbname=%s;charset=%s", $driver, $host, $dbname, $charset);
self::$pdo = new \PDO($dsn, $user, $pass);
self::$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}
public static function getPDO(): PDO
{
if (!isset(self::$pdo)) {
throw new \Exception("PDO not initialized. Call DB::init() first.");
}
return self::$pdo;
}
}

View File

@ -0,0 +1,265 @@
<?php
namespace lib\Database;
use PDO;
class QueryBuilder
{
private PDO $pdo;
private string $table = '';
private array $select = ['*'];
private array $where = [];
private array $bindings = [];
private array $order = [];
private ?int $limit = null;
private ?int $offset = null;
private array $joins = [];
public function __construct(PDO $pdo)
{
$this->pdo = $pdo;
}
public function table(string $table): static
{
$this->table = $table;
return $this;
}
public function select(array|string $columns): static
{
$this->select = is_array($columns) ? $columns : explode(',', $columns);
return $this;
}
public function where(string $column, string $operator = "", mixed $value = ""): static
{
$placeholder = ':w_' . count($this->bindings);
$this->where[] = "$column $operator $placeholder";
$this->bindings[$placeholder] = $value;
return $this;
}
public function orderBy(string $column, string $direction = 'ASC'): static
{
$this->order[] = "$column $direction";
return $this;
}
public function limit(int $limit): static
{
$this->limit = $limit;
return $this;
}
public function offset(int $offset): static
{
$this->offset = $offset;
return $this;
}
public function when(bool $condition, callable $callback): static
{
if ($condition) {
$callback($this);
}
return $this;
}
public function rawWhere(string $expression, array $bindings = []): static
{
$this->where[] = "($expression)";
foreach ($bindings as $key => $value) {
$this->bindings[":raw_" . $key] = $value;
}
return $this;
}
public function get(): array
{
$sql = "SELECT " . implode(', ', $this->select) . " FROM {$this->table}";
if (!empty($this->where)) {
$sql .= " WHERE " . implode(' AND ', $this->where);
}
if (!empty($this->order)) {
$sql .= " ORDER BY " . implode(', ', $this->order);
}
if (!is_null($this->limit)) {
$sql .= " LIMIT :__limit";
$this->bindings[':__limit'] = $this->limit;
}
if (!is_null($this->offset)) {
$sql .= " OFFSET :__offset";
$this->bindings[':__offset'] = $this->offset;
}
$stmt = $this->pdo->prepare($sql);
foreach ($this->bindings as $placeholder => $value) {
$stmt->bindValue($placeholder, $value);
}
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function first(): ?array
{
$this->limit(1);
$rows = $this->get();
return $rows[0] ?? null;
}
public function count(): int
{
$this->select = ['COUNT(*) AS cnt'];
$results = $this->get();
return (int)($results[0]['cnt'] ?? 0);
}
public function exists(): bool
{
return $this->count() > 0;
}
public function insert(array $data): bool
{
$columns = array_keys($data);
$placeholders = array_map(fn($col) => ':' . $col, $columns);
$sql = "INSERT INTO {$this->table} (" . implode(', ', $columns) . ") VALUES (" . implode(', ', $placeholders) . ")";
$stmt = $this->pdo->prepare($sql);
foreach ($data as $col => $value) {
$stmt->bindValue(':' . $col, $value);
}
return $stmt->execute();
}
public function update(array $data): bool
{
if (empty($this->where)) {
throw new \Exception("Update without WHERE is not allowed.");
}
$setClauses = [];
foreach ($data as $col => $val) {
$placeholder = ':u_' . $col;
$setClauses[] = "$col = $placeholder";
$this->bindings[$placeholder] = $val;
}
$sql = "UPDATE {$this->table} SET " . implode(', ', $setClauses);
if (!empty($this->where)) {
$sql .= " WHERE " . implode(' AND ', $this->where);
}
$stmt = $this->pdo->prepare($sql);
foreach ($this->bindings as $placeholder => $value) {
$stmt->bindValue($placeholder, $value);
}
return $stmt->execute();
}
public function delete(): bool
{
if (empty($this->where)) {
throw new \Exception("Delete without WHERE is not allowed.");
}
$sql = "DELETE FROM {$this->table} WHERE " . implode(' AND ', $this->where);
$stmt = $this->pdo->prepare($sql);
foreach ($this->bindings as $placeholder => $value) {
$stmt->bindValue($placeholder, $value);
}
return $stmt->execute();
}
public function whereIn(string $column, array $values, string $boolean = 'AND'): static
{
if (empty($values)) {
throw new \InvalidArgumentException("whereIn: values 배열이 비어있을 수 없습니다.");
}
$placeholders = implode(', ', array_fill(0, count($values), '?'));
$this->where[] = "$column IN ($placeholders)";
$this->bindings = array_merge($this->bindings, $values);
return $this;
}
public function whereNotIn(string $column, array $values, string $boolean = 'AND'): static
{
if (empty($values)) {
throw new \InvalidArgumentException("whereNotIn: values 배열이 비어있을 수 없습니다.");
}
$placeholders = implode(', ', array_fill(0, count($values), '?'));
$this->where[] = "$column NOT IN ($placeholders)";
$this->bindings = array_merge($this->bindings, $values);
return $this;
}
public function orWhereIn(string $column, array $values): static
{
return $this->whereIn($column, $values, 'OR');
}
public function orWhere(string $column, string $operator, mixed $value): static
{
$placeholder = ':w_' . count($this->bindings);
$condition = "$column $operator $placeholder";
if (empty($this->where)) {
$this->where[] = $condition;
} else {
$last = array_pop($this->where);
$this->where[] = "($last OR $condition)";
}
$this->bindings[$placeholder] = $value;
return $this;
}
public function join(string $table, string $on, string $type = 'INNER'): static
{
$this->joins[] = strtoupper($type) . " JOIN $table ON $on";
return $this;
}
public function raw(string $sql, array $bindings = []): array
{
$stmt = $this->pdo->prepare($sql);
foreach ($bindings as $key => $value) {
$stmt->bindValue(is_int($key) ? $key + 1 : $key, $value);
}
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function beginTransaction(): void
{
$this->pdo->beginTransaction();
}
public function commit(): void
{
$this->pdo->commit();
}
public function rollBack(): void
{
if ($this->pdo->inTransaction()) {
$this->pdo->rollBack();
}
}
}

View File

@ -39,7 +39,7 @@ class ServiceService extends CommonService
$this->getModel()->where("service_open_date > DATE_ADD(now(), INTERVAL -{$day} DAY)");
$this->getModel()->where("service_status", 'o');
$this->getModel()->whereNotIn("service_line", $excepts);
$count = $this->getModel()->countAllResults();
$count = $this->getModel()->count();
// echo __FUNCTION__ . ":" . $this->getModel()->getLastQuery();
return $count;
}
@ -49,7 +49,7 @@ class ServiceService extends CommonService
$this->getModel()->where("service_payment_date > now()");
$this->getModel()->where("service_status", 'o');
$this->getModel()->whereNotIn("service_line", $excepts);
$count = $this->getModel()->countAllResults();
$count = $this->getModel()->count();
// echo __FUNCTION__ . ":" . $this->getModel()->getLastQuery();
return $count;
}

View File

@ -0,0 +1,112 @@
<?php
namespace lib\Utils;
class Pagination
{
public int $currentPage;
public int $perPage;
public int $totalItems;
public int $totalPages;
public int $start;
public int $end;
public function __construct(int $totalItems, int $currentPage = 1, int $perPage = 10)
{
$this->totalItems = $totalItems;
$this->perPage = $perPage;
$this->currentPage = max(1, $currentPage);
$this->totalPages = (int)ceil($totalItems / $perPage);
$this->start = ($this->currentPage - 1) * $perPage;
$this->end = min($this->start + $perPage, $totalItems);
}
public function hasPrevious(): bool
{
return $this->currentPage > 1;
}
public function hasNext(): bool
{
return $this->currentPage < $this->totalPages;
}
public function previousPage(): int
{
return max(1, $this->currentPage - 1);
}
public function nextPage(): int
{
return min($this->totalPages, $this->currentPage + 1);
}
public function getOffset(): int
{
return $this->start;
}
public function getLimit(): int
{
return $this->perPage;
}
public function toArray(): array
{
return [
'current_page' => $this->currentPage,
'per_page' => $this->perPage,
'total_items' => $this->totalItems,
'total_pages' => $this->totalPages,
'has_previous' => $this->hasPrevious(),
'has_next' => $this->hasNext(),
'previous_page' => $this->previousPage(),
'next_page' => $this->nextPage(),
'offset' => $this->getOffset(),
'limit' => $this->getLimit(),
];
}
public function render(string $baseUrl = '', array $query = []): string
{
if ($this->totalPages <= 1) {
return ''; // 페이지가 1개 이하면 렌더링 생략
}
$html = '<nav><ul class="pagination">';
// 이전 버튼
if ($this->hasPrevious()) {
$html .= $this->pageLink($this->previousPage(), '&laquo;', $baseUrl, $query);
} else {
$html .= '<li class="page-item disabled"><span class="page-link">&laquo;</span></li>';
}
// 페이지 번호 링크 (간단히 1 ~ totalPages 모두 표시, 필요시 range 조절 가능)
for ($i = 1; $i <= $this->totalPages; $i++) {
if ($i === $this->currentPage) {
$html .= '<li class="page-item active"><span class="page-link">' . $i . '</span></li>';
} else {
$html .= $this->pageLink($i, (string)$i, $baseUrl, $query);
}
}
// 다음 버튼
if ($this->hasNext()) {
$html .= $this->pageLink($this->nextPage(), '&raquo;', $baseUrl, $query);
} else {
$html .= '<li class="page-item disabled"><span class="page-link">&raquo;</span></li>';
}
$html .= '</ul></nav>';
return $html;
}
private function pageLink(int $page, string $label, string $baseUrl, array $query): string
{
$query['page'] = $page;
$url = $baseUrl . '?' . http_build_query($query);
return '<li class="page-item"><a class="page-link" href="' . htmlspecialchars($url) . '">' . $label . '</a></li>';
}
}

View File

@ -0,0 +1,178 @@
<?
// 기본 설정 로딩
require_once 'config.php';
require_once 'function.php';
require_once 'lib.php';
//HTML 시작
switch ($_GET[mode]) {
case "today":
//당일
$count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = CURDATE() ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC";
$msg = "당일 미납리스트";
$checkall2 = "checked";
break;
case "1day":
//1일전
$count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 1 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC ";
$date = str_replace('-', '/', $date);
$date = date('Y-m-d', strtotime($date . "+1 days"));
$msg = "1일전 미납리스트($date)";
$checkall3 = "checked";
break;
case "2day":
//2일전
$count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 2 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC ";
$date = str_replace('-', '/', $date);
$date = date('Y-m-d', strtotime($date . "+2 days"));
$msg = "2일전 미납리스트($date)";
$checkall4 = "checked";
break;
case "3day":
//3일전
$count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 3 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC ";
$date = str_replace('-', '/', $date);
$date = date('Y-m-d', strtotime($date . "+3 days"));
$msg = "3일전 미납리스트($date)";
$checkall5 = "checked";
break;
case "custom":
//커스텀
//$count = "SELECT count(servicedb.server_code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = CURDATE() Group By server_code ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC";
$count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 1 DAY) Group By server_code ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC";
$msg = "커스텀 미납리스트($date)+1일";
$checkall6 = "checked";
break;
default:
//전체
$count = "SELECT count(clientdb.Client_Code) FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC ";
$msg = "전체 미납리스트";
$checkall1 = "checked";
break;
}
?>
<form method="get" action="#">
<input type="radio" name="mode" value="all" <?= $checkall1 ?>>전체
<input type="radio" name="mode" value="today" <?= $checkall2 ?>>당일
<input type="radio" name="mode" value="1day" <?= $checkall3 ?>>1일전
<input type="radio" name="mode" value="2day" <?= $checkall4 ?>>2일전
<input type="radio" name="mode" value="3day" <?= $checkall5 ?>>3일전
<!-- <input type="radio" name="mode" value="custom" <?= $checkall6 ?>>커스텀(수정중)<br>-->
<input type="hidden" name="ea" value="<?= $_GET[ea] ?>">
<input type="submit" value="확인">
</form>
<?
$list_no = (!$_GET[ea]) ? '50' : $_GET[ea];
$total_num = mysql_fetch_array(mysql_query($count, $db_connect));
$total = $total_num[0];
if ($list_no > $total) {
$list_no = $total;
}
$total_page = ($total != '0') ? ceil($total / $list_no) : '0';
$page = $_GET[curPage];
if (!$page) {
$page = 1;
} elseif ($page >= $total_page) {
$page = $total_page;
} else {
$page = $page;
}
$next_page = ($page - '1') * $list_no;
$next_no = $next_page + $list_no;
switch ($_GET[mode]) {
case "today":
//당일
$query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = CURDATE() ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC limit " . $next_page . "," . $next_no;
break;
case "1day":
//1일전
$query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 1 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC limit " . $next_page . "," . $next_no;
break;
case "2day":
//2일전
$query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 2 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC limit " . $next_page . "," . $next_no;
break;
case "3day":
//3일전
$query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 3 DAY) ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC limit " . $next_page . "," . $next_no;
break;
case "custom":
//커스텀
//$query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = CURDATE() Group By server_code ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC limit ".$next_page.",".$next_no;
$query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') AND service_payment_date = Date_Add(curdate(),INTERVAL 1 DAY) Group By server_code ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC limit " . $next_page . "," . $next_no;
break;
default:
//전체
$query = "SELECT clientdb.Client_Code,Client_Name,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,adddb_case,adddb.client_code,adddb.service_code,adddb_nonpayment,adddb_payment,adddb_accountStatus,addDB_ip,addDB_payment_date FROM clientdb INNER JOIN servicedb ON clientdb.client_code = servicedb.client_code INNER JOIN adddb ON servicedb.service_code = adddb.service_code WHERE servicedb.service_code = adddb.service_code AND adddb.client_code not in ('C116','C219') AND adddb.adddb_accountStatus not in ('complete') ORDER BY service_payment_date,Client_Name,adddb_accountStatus ASC limit " . $next_page . "," . $next_no;
break;
}
$result = @mysql_query($query, $db_connect) or die($db_q_error);
?>
<!--미납 서버 대수 : <?= $total ?>-->
<?= $msg ?> <a class="btn btn-outline btn-default" href="IdcDepositNonPaymentListExcel.dep">엑셀</a>
<div class="table-responsive" id="table">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th style="text-align:center;width:100px;">고객명</th>
<th style="text-align:center;width:60px;">종류</th>
<th style="text-align:center;width:130px;">장비명</th>
<th style="text-align:center;width:120px;">IP</th>
<th style="text-align:center;width:100px;">결제일</th>
<th style="text-align:center;width:100px;">서비스 가격</th>
<th style="text-align:center;width:100px;">과금상태</th>
<th style="text-align:center;width:100px;">미납과금</th>
<!--<th>청구서 발행 대상</th>-->
<th style="text-align:center;">비고</th>
</tr>
</thead>
<tbody>
<?
for ($i = $next_page; $i < $next_no; $i++) {
$data = mysql_fetch_assoc($result);
$num = ($total) - $i;
$reg_date = date("Y/m/d H:i", $data['reg_date']);
?>
<tr>
<!-- <td><input type="radio"></td>
<td><?= $data[Client_Code] ?></td>
-->
<td style="text-align:center;"><a href="/IdcDepositNonPaymentList.dep?searchContent=<?= $data[Client_Name] ?>"><?= $data[Client_Name] ?></a></td>
<td style="text-align:center;"><?= $data[adddb_case] ?></td>
<td style="text-align:center;"><?= $data[server_code] ?></td>
<td style="text-align:center;"><?= $data[service_ip] ?></td>
<!--<td><?= $data[service_code] ?></td>-->
<td style="text-align:center;"><?= $data[service_payment_date] ?></td>
<td style="text-align:center;"><?= $data[service_amount] ?></td>
<!--<td><?= $data[adddb_payment] ?></td>-->
<td style="text-align:center;"><?= $data[adddb_accountStatus] ?></td>
<td style="text-align:center;"><?= $data[adddb_nonpayment] ?></td>
<!--<td><?= $data[adddb_accountStatus] ?></td>-->
<!--<td></td>-->
<td><?= $data[service_note] ?></td>
</td>
</tr>
<? } ?>
</tbody>
<tfoot></tfoot>
</table>
<div align='center'>
<?= $this->pagination->render("http://{$_SERVER['HTTP_HOST']}:6752/IdcDepositNonPaymentListMK.dep?mode=", ['mode' => "{$this->mode}", 'ea' => "{$this->ea}"]) ?>
</div>