Untitled

mail@pastecode.io avatar
unknown
php
a year ago
286 kB
2
Indexable
Never
<?php
date_default_timezone_set("Asia/Jakarta");

require "konek.php";

function konek()
{
  return mysqli_connect("localhost", "root", "", "nsw");
}

function query($id)
{
  $konek = konek();
  return mysqli_query($konek, $id);
}

function query_banyak($id)
{
  return mysqli_fetch_assoc($id);
}

function query_satu($id)
{
  $konek = konek();
  return mysqli_fetch_assoc(
    mysqli_query($konek, $id)
  );
}

function jumlah($id)
{
  $konek = konek();
  return mysqli_num_rows(
    mysqli_query($konek, $id)
  );
}

function enc($id)
{
  return base64_encode($id);
}

function dec($id)
{
  return base64_decode($id);
}

function riwayat()
{
  return date("Y-m-d H:i:s");
}

function riwayat_all($kode, $id_riwayat_header)
{
  return query("SELECT * FROM riwayat
  WHERE
  kode = '$kode' AND
  id_riwayat_header = '$id_riwayat_header'
  ORDER BY tgl ASC");
}

function p($id)
{
  return @$_POST[$id];
}

function g($id)
{
  return $_GET[$id];
}

function f($id)
{
  return $_FILES[$id];
}

function code($id)
{
  return eval(base64_decode($id));
}

function get_random_string($valid_chars, $length)
{
  // start with an empty random string
  $random_string = "";

  // count the number of chars in the valid chars string so we know how many choices we have
  $num_valid_chars = strlen($valid_chars);

  // repeat the steps until we've created a string of the right length
  for ($i = 0; $i < $length; $i++) {
    // pick a random number from 1 up to the number of valid chars
    $random_pick = mt_Rand(1, $num_valid_chars);

    // take the random character out of the string of valid chars
    // subtract 1 from $random_pick because strings are indexed starting at 0, and we started picking at 1
    $random_char = $valid_chars[$random_pick - 1];

    // add the randomly-chosen char onto the end of our string so far
    $random_string .= $random_char;
  }

  // return our finished random string
  return $random_string;
}

function user($id)
{
  $q = query_satu("SELECT * FROM user WHERE id_user = '$_SESSION[id_user]'");
  return $q[$id];
}

function account_disabled()
{
  if ($_SESSION) {
    $q = @query_satu("SELECT * FROM user WHERE id_user = '$_SESSION[id_user]'");
    if ($q && $q["id_status_user"] != 1) {
      return true;
    } else {
      return false;
    }
  } else {
    return false;
  }
}

function user_image()
{
  $q = query_satu("SELECT * FROM user_gambar WHERE id_user = '$_SESSION[id_user]'");

  $img_name = $q["nama_gambar_user"];

  if ($img_name == "" or $img_name == null or $img_name == "unknown") {
    return "nophoto.png";
  } else {
    return $img_name;
  }
}

function user_image_jumlah($id)
{
  return jumlah("SELECT * FROM user_gambar WHERE id_user = '$id'");
}

function user_image_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM user_gambar WHERE id_user = '$id'");
  return $a[$ok];
}

function title($alt)
{
  if (@$_GET['halaman'] == 'produk') {
    $hal = 'Halaman Produk';
  } elseif (@$_GET['halaman'] == 'kategori') {
    $hal = 'Halaman Kategori';
  } elseif (@$_GET['halaman'] == 'customer') {
    $hal = 'Halaman Customer';
  } elseif (@$_GET['halaman'] == 'wilayah') {
    $hal = 'Halaman Wilayah';
  } elseif (@$_GET['halaman'] == 'satuan') {
    $hal = 'Halaman Satuan';
  } else {
    if ($alt != "") {
      $hal = $alt;
    } else {
      $hal = "Admin NSW";
    }
  }
  return $hal;
}

function rupiah($angka)
{

  $hasil_rupiah = "Rp. " . number_format($angka, 2, ",", ".");
  return $hasil_rupiah;
}

function rp($angka)
{

  $hasil_rupiah = "Rp " . number_format($angka, 0, ",", ".");
  return $hasil_rupiah;
}

function numb($id)
{
  return number_format($id, 2, ",", ".");
}

function numb_nol($id)
{
  return number_format($id, 0, ",", ".");
}

function get_sidebar_user($level)
{
  if ($level == 1) {
    return '
    <li class="nav-item">
                    <a href="../../" class="nav-link active">
                        <i class="nav-icon fas fa-tachometer-alt"></i>
                        <p>
                            Dashboard
                        </p>
                    </a>
                </li>
                <li
                    class="nav-item">
                    <a href="#"
                        class="nav-link">
                        <i class="nav-icon fas fa-chart-line"></i>
                        <p>
                            Other Dashboard
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-sales" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Sales and Profitability</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-finance" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Finance</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-inventory" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Inventory</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-cfo" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>CFO</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-ceo" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>CEO</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-cashflow" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Cash Flow</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-budget-actual"
                                class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Budget vs Acutal</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-accounts-payable"
                                class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Accounts Payable </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-accounts-receivable"
                                class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Accounts Receivable </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-profit-margin"
                                class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Profit Margin </p>
                            </a>
                        </li>
                        <!-- <li class="nav-item">
              <a href="pages/nsw/?halaman=yearly-comparison-report" class="nav-link">
                <i class="fas fa-chart-line nav-icon"></i>
                <p>Yearly Comparison </p>
              </a>
            </li> -->
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>
                                    Yearly Comparison
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=yearly-comparison-report-jenis"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Jenis Produk</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=yearly-comparison-report-produk"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Produk</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>
                                    KPI
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-kpi-monthly"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Monthly</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-kpi-ytd" class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>YTD</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li
                            class="nav-item">
                            <a href="#"
                                class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>
                                    Annual Report
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-AR-quater"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Quater</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-AR-month"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Month</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-AR-report"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Report</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-AR-income"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Income Statement</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-salesman" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Salesman </p>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="nav-icon fas fa-shopping-bag"></i>
                        <p>
                            Onlineshop
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dasbor-OS" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Dasbor Penjualan</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=product-OS" class="nav-link">
                                <i class="fas fa-box-open nav-icon"></i>
                                <p>Product</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=order-OS" class="nav-link">
                                <i class="fas fa-clipboard-list nav-icon"></i>
                                <p>Pesanan</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=payment-OS" class="nav-link">
                                <i class="fas fa-money-bill-wave-alt nav-icon"></i>
                                <p>Pembayaran</p>
                            </a>
                        </li>
                    </ul>
                </li>

                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-building"></i>
                        <p>
                            Dashboard Office
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Pengumuman Marketing</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="" class="nav-link">
                                <i class="fas fa-box-open nav-icon"></i>
                                <p>Pengumuman Surkom</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="" class="nav-link">
                                <i class="fas fa-clipboard-list nav-icon"></i>
                                <p>Planing Jadwal</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="" class="nav-link">
                                <i class="fas fa-money-bill-wave-alt nav-icon"></i>
                                <p>Kalender</p>
                            </a>
                        </li>
                    </ul>
                </li>

                <li class="nav-item">
                    <a href="#"
                        class="nav-link">
                        <i class="nav-icon fas fa-folder"></i>
                        <p>
                            Master Database
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Produk
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=produk" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Produk</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=kategori" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Kategori</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=customer" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Customer</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=wilayah" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Wilayah</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=satuan" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Satuan</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=expedisi" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Expedisi</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=sales" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Sales</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=bank" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Bank</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=promo" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Promo
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Supplier
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=supplier" class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Supplier</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=data-supplier" class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Data Supplier</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li class="nav-header">DATA PUSAT</li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=coa" class="nav-link">
                        <i class="fas fa-book nav-icon"></i>
                        <p>
                            Master Perkiraan
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=jurnal" class="nav-link">
                        <i class="fas fa-cash-register nav-icon"></i>
                        <p>
                            Jurnal
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=bank-new" class="nav-link">
                        <i class="fas fa-university nav-icon"></i>
                        <p>
                            Bank
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=asset" class="nav-link">
                        <i class="fas fa-coins nav-icon"></i>
                        <p>
                            Asset
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-book-open nav-icon"></i>
                        <p>
                            Buku Kas
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=kas" class="nav-link">
                                <i class="far fa-circle nav-icon" style="font-size:15px"></i>
                                <p>Daftar Kas</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=kas-bank" class="nav-link">
                                <i class="far fa-circle nav-icon" style="font-size:15px"></i>
                                <p>Daftar Kas Bank</p>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-header">DATA CABANG</li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=cabang" class="nav-link">
                        <i class="fas fa-clinic-medical nav-icon"></i>
                        <p>
                            Cabang
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=coa-cabang" class="nav-link">
                        <i class="fas fa-book nav-icon"></i>
                        <p>
                            Master Perkiraan
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=jurnal-cabang" class="nav-link">
                        <i class="fas fa-cash-register nav-icon"></i>
                        <p>
                            Jurnal
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=bank-cabang" class="nav-link">
                        <i class="fas fa-university nav-icon"></i>
                        <p>
                            Bank
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=asset-cabang" class="nav-link">
                        <i class="fas fa-coins nav-icon"></i>
                        <p>
                            Asset
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-book-open nav-icon"></i>
                        <p>
                            Buku Kas
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=kas-cabang" class="nav-link">
                                <i class="far fa-circle nav-icon" style="font-size:15px"></i>
                                <p>Daftar Kas</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=kas-bank-cabang" class="nav-link">
                                <i class="far fa-circle nav-icon" style="font-size:15px"></i>
                                <p>Daftar Kas Bank</p>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-header">PPIC</li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=ppic" class="nav-link">
                        <i class="fab fa-envira nav-icon"></i>
                        <p>
                            PPIC
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=recycle-bin" class="nav-link">
                        <i class="fas fa-recycle nav-icon"></i>
                        <p>
                            Recycle Bin
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=bom" class="nav-link">
                        <i class="fab fa-envira nav-icon"></i>
                        <p>
                            BOM
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=quantation" class="nav-link">
                        <i class="fas fa-envelope-open nav-icon"></i>
                        <p>
                            Surat Penawaran
                        </p>
                    </a>
                </li>
                <li
                    class="nav-item">
                    <a href="#"
                        class="nav-link">
                        <i class="nav-icon far fa-handshake"></i>
                        <p>
                            Transaksi
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-SO" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Sales Order (SO)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-FP" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Faktur Penjualan (FP)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-SPB" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>SPB</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-RJ" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Retur Jual (RJ)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-WO" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Working Order (WO)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>PBBP</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-LHP" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Laporan Hasil Produksi</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-BPBP" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Bukti Penerimaan Barang Pembelian (BPBP)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-PR" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Purchase Request (PR)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-PO" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Purchase Order (PO)</p>
                            </a>
                        </li>
                    </ul>
                </li>
    ';
  } elseif ($level == 2) {
    return '
    <li class="nav-item">
                    <a href="../../" class="nav-link active">
                        <i class="nav-icon fas fa-tachometer-alt"></i>
                        <p>
                            Dashboard
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="nav-icon fas fa-shopping-bag"></i>
                        <p>
                            Onlineshop
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dasbor-OS" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Dasbor Penjualan</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=product-OS" class="nav-link">
                                <i class="fas fa-box-open nav-icon"></i>
                                <p>Product</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=order-OS" class="nav-link">
                                <i class="fas fa-clipboard-list nav-icon"></i>
                                <p>Pesanan</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=payment-OS" class="nav-link">
                                <i class="fas fa-money-bill-wave-alt nav-icon"></i>
                                <p>Pembayaran</p>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-building"></i>
                        <p>
                            Dashboard Office
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Pengumuman Marketing</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="" class="nav-link">
                                <i class="fas fa-box-open nav-icon"></i>
                                <p>Pengumuman Surkom</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="" class="nav-link">
                                <i class="fas fa-clipboard-list nav-icon"></i>
                                <p>Planing Jadwal</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="" class="nav-link">
                                <i class="fas fa-money-bill-wave-alt nav-icon"></i>
                                <p>Kalender</p>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="#"
                        class="nav-link">
                        <i class="nav-icon fas fa-chart-line"></i>
                        <p>
                            Dashboard Report
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-sales" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Sales and Profitability</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-finance" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Finance</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-inventory" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Inventory</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-cfo" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>CFO</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-ceo" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>CEO</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-cashflow" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Cash Flow</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-budget-actual"
                                class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Budget vs Acutal</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-accounts-payable"
                                class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Accounts Payable </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-accounts-receivable"
                                class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Accounts Receivable </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-profit-margin"
                                class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Profit Margin </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>
                                    Yearly Comparison
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=yearly-comparison-report-jenis"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Jenis Produk</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=yearly-comparison-report-produk"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Produk</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>
                                    KPI
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-kpi-monthly"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Monthly</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-kpi-ytd" class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>YTD</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li
                            class="nav-item">
                            <a href="#"
                                class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>
                                    Annual Report
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-AR-quater"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Quater</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-AR-month"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Month</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-AR-report"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Report</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=dashboard-AR-income"
                                        class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Income Statement</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=dashboard-salesman" class="nav-link">
                                <i class="fas fa-chart-line nav-icon"></i>
                                <p>Salesman</p>
                            </a>
                        </li>
                    </ul>
                </li>

                <li class="nav-item">
                    <a href="#"
                        class="nav-link">
                        <i class="fas fa-server"></i>
                        <p>
                            Master Database
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Produk
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=produk" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Produk</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=stock" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Stock</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=kategori" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Kategori</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=satuan" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Satuan</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=sales" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Sales
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Customer
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=customer" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Customer</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=data-customer" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Data Customer</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=wilayah" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Wilayah</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Markerting
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=promo" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>
                                            Promo
                                        </p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=promo" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>
                                            Pameran & EVENT
                                        </p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Supplier, Cargo & Transport
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=supplier" class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Supplier</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=data-supplier" class="nav-link">
                                        <i class="far fa-dot-circle nav-icon"></i>
                                        <p>Data Supplier</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=expedisi" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Expedisi</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-database"></i>
                        <p>
                            MASTER PUSAT
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Bank
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=bank" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Bank Umum</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Rekening Perushaan
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=bank-new" class="nav-link">
                                        <i class="fas fa-university nav-icon"></i>
                                        <p>
                                            My Rekening
                                        </p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>
                                    Master Perkiraan
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=coa" class="nav-link">
                                        <i class="fas fa-book nav-icon"></i>
                                        <p>
                                            Master COA
                                        </p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=coa" class="nav-link">
                                        <i class="fas fa-book nav-icon"></i>
                                        <p>
                                            Input Perkiraan
                                        </p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=jurnal" class="nav-link">
                                <i class="fas fa-cash-register nav-icon"></i>
                                <p>
                                    Jurnal
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=asset" class="nav-link">
                                <i class="fas fa-coins nav-icon"></i>
                                <p>
                                    Asset
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="fas fa-book-open nav-icon"></i>
                                <p>
                                    Buku Kas
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=kas" class="nav-link">
                                        <i class="far fa-circle nav-icon" style="font-size:15px"></i>
                                        <p>Daftar Kas</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=kas-bank" class="nav-link">
                                        <i class="far fa-circle nav-icon" style="font-size:15px"></i>
                                        <p>Daftar Kas Bank</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-code-branch"></i>
                        <p>
                            MASTER CABANG
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=cabang" class="nav-link">
                                <i class="fas fa-clinic-medical nav-icon"></i>
                                <p>
                                    Cabang
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=coa-cabang" class="nav-link">
                                <i class="fas fa-book nav-icon"></i>
                                <p>
                                    Master Perkiraan
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=jurnal-cabang" class="nav-link">
                                <i class="fas fa-cash-register nav-icon"></i>
                                <p>
                                    Jurnal
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=bank-cabang" class="nav-link">
                                <i class="fas fa-university nav-icon"></i>
                                <p>
                                    Bank
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=asset-cabang" class="nav-link">
                                <i class="fas fa-coins nav-icon"></i>
                                <p>
                                    Asset
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="fas fa-book-open nav-icon"></i>
                                <p>
                                    Buku Kas
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=kas-cabang" class="nav-link">
                                        <i class="far fa-circle nav-icon" style="font-size:15px"></i>
                                        <p>Daftar Kas</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pages/nsw/?halaman=kas-bank-cabang" class="nav-link">
                                        <i class="far fa-circle nav-icon" style="font-size:15px"></i>
                                        <p>Daftar Kas Bank</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-money-check-alt nav-icon"></i>
                        <p>
                            PROSES GIRO
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=giro-masuk" class="nav-link">
                              <i class="far fa-circle nav-icon" style="font-size:15px"></i>
                              <p>Giro Masuk</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=giro-keluar" class="nav-link">
                              <i class="far fa-circle nav-icon" style="font-size:15px"></i>
                              <p>Giro Keluar</p>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="#"
                        class="nav-link">
                        <i class="nav-icon far fa-handshake"></i>
                        <p>
                            Transaksi Pembelian
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                    <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-PR" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Purchase Request (PR)</p>
                            </a>
                        </li>    
                    <li class="nav-item">
                        <a href="pages/nsw/?halaman=pemesanan-barang" class="nav-link">
                            <i class="fas fa-minus nav-icon"></i>
                            <p>SPBD</p>
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="" class="nav-link">
                            <i class="fas fa-minus nav-icon"></i>
                            <p>PBBP</p>
                        </a>
                    </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-PO" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Purchase Order (PO)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-BPBP" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Bukti Penerimaan Barang Pembelian (BPBP)</p>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="#"
                        class="nav-link">
                        <i class="fas fa-cash-register"></i>
                        <p>
                            Transaksi Penjualan
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-RJ" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Retur Jual (RJ)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=quantation" class="nav-link">
                                <i class="fas fa-envelope-open nav-icon"></i>
                                <p>
                                    Surat Penawaran
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-SO" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Sales Order (SO)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-FP" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Faktur Penjualan (FP)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-SPB" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>SPB</p>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="#"
                        class="nav-link">
                        <i class="fas fa-truck-loading"></i>
                        <p>
                            Transaksi Produksi
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=ppic" class="nav-link">
                                <i class="fab fa-envira nav-icon"></i>
                                <p>
                                    PPIC
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=bom" class="nav-link">
                                <i class="fab fa-envira nav-icon"></i>
                                <p>
                                    BOM
                                </p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-WO" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Working Order (WO)</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=transaksi-LHP" class="nav-link">
                                <i class="fas fa-minus nav-icon"></i>
                                <p>Laporan Hasil Produksi</p>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="#"
                        class="nav-link">
                        <i class="fas fa-hand-holding-usd"></i>
                        <p>
                            Payroll
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="pages/nsw/?halaman=karyawan" class="nav-link">
                                <i class="fas fa-users"></i>
                                <p>
                                    Data Karyawan
                                </p>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="pages/nsw/?halaman=recycle-bin" class="nav-link">
                        <i class="fas fa-recycle nav-icon"></i>
                        <p>
                            Recycle Bin
                        </p>
                    </a>
                </li>
    ';
  } elseif ($level == 3) {
    return '
    <li class="nav-item">
    <a href="#" class="nav-link">
      <i class="nav-icon fas fa-tachometer-alt"></i>
      <p>
        Dashboard
      </p>
    </a>
  </li>
  <li class="nav-item">
    <a href="#" class="nav-link">
      <i class="nav-icon fas fa-chart-line"></i>
      <p>
        Other Dashboard
        <i class="right fas fa-angle-left"></i>
      </p>
    </a>
    <ul class="nav nav-treeview">
      <li class="nav-item">
        <a href="pages/nsw/?halaman=dashboard-salesman" class="nav-link">
          <i class="fas fa-chart-line nav-icon"></i>
          <p>Salesman </p>
        </a>
      </li>
    </ul>
  </li>
  <li class="nav-item">
    <a href="#" class="nav-link">
      <i class="nav-icon far fa-handshake"></i>
      <p>
        Transaksi
        <i class="right fas fa-angle-left"></i>
      </p>
    </a>
    <ul class="nav nav-treeview">
      <li class="nav-item">
        <a href="pages/nsw/?halaman=transaksi-SO" class="nav-link">
          <i class="fas fa-minus nav-icon"></i>
          <p>Sales Order (SO)</p>
        </a>
      </li>
    </ul>
  </li>
    ';
  }
}

function content_header()
{
  if (@$_GET['halaman'] == "kategori") {
    return "<h1>Halaman Master Kategori<h1>";
  } elseif (@$_GET['halaman'] == "setting_account") {
    return "<h1>Settings<h1>";
  } elseif (@$_GET['halaman'] == "customer") {
    return "<h1>Halaman Master Customer<h1>";
  } elseif (@$_GET['halaman'] == 'wilayah') {
    return "<h1>Halaman Master Wilayah<h1>";
  } elseif (@$_GET['halaman'] == 'satuan') {
    return "<h1>Halaman Master Satuan<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-sales") {
    return "<h1>Dashboard Sales and Profitability<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-finance") {
    return "<h1>Dashboard Finance<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-inventory") {
    return "<h1>Dashboard Inventory<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-cfo") {
    return "<h1>Dashboard CFO<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-ceo") {
    return "<h1>Dashboard CEO<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-cashflow") {
    return "<h1>Dashboard Cash Flow<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-budget-actual") {
    return "<h1>Dashboard Budget vs Acutal<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-accounts-payable") {
    return "<h1>Dashboard Accounts Payable<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-accounts-receivable") {
    return "<h1>Dashboard Accounts Receivable<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-profit-margin") {
    return "<h1>Dashboard Profit Margin<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-kpi-monthly") {
    return "<h1>Dashboard KPI Monthly<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-kpi-ytd") {
    return "<h1>Dashboard KPI YTD<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-AR-quater") {
    return "<h1>Dashboard Annual Report Quater<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-AR-month") {
    return "<h1>Dashboard Annual Report Month<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-AR-report") {
    return "<h1>Dashboard Annual Report<h1>";
  } elseif (@$_GET["halaman"] == "dashboard-AR-income") {
    return "<h1>Dashboard Annual Report Income<h1>";
  } elseif (@$_GET['halaman'] == 'dasbor-OS') {
    return "<h1>Halaman Dasbor Penjualan<h1>";
  } elseif (@$_GET['halaman'] == 'product-OS') {
    return "<h1>Halaman Product Onlineshop<h1>";
  } elseif (@$_GET['detail-productOS']) {
    return "<h1>Halaman Detail Produk Onlineshop<h1>";
  } elseif (@$_GET['halaman'] == 'order-OS') {
    return "<h1>Halaman Order Onlineshop<h1>";
  } elseif (@$_GET['detail-orderOS']) {
    return "<h1>Halaman Detail Pesanan Onlineshop<h1>";
  } elseif (@$_GET['invoice-orderOS']) {
    return "<h1>Halaman Invoice Pesanan Onlineshop<h1>";
  } elseif (@$_GET['halaman'] == 'payment-OS') {
    return "<h1>Halaman Payment Onlineshop<h1>";
  } elseif (@$_GET['edit-wilayah']) {
    return "<h1>Halaman Edit Kode Wilayah<h1>";
  } elseif (@$_GET['halaman'] == 'produk' || @$_GET['produk-kategori']) {
    return "<h1>Halaman Produk<h1>";
  } elseif (@$_GET['detail-produk']) {
    return "<h1>Halaman Detail Produk<h1>";
  } elseif (@$_GET['detail-customer']) {
    return "<h1>Halaman Detail Customer<h1>";
  } elseif (@$_GET["halaman"] == "bom") {
    return "<h1>Halaman BOM (Bill of Material)<h1>";
  } elseif (@$_GET["bom-detail"]) {
    return "<h1>Halaman Detail BOM (Bill of Material)<h1>";
  } elseif (@$_GET["halaman"] == "transaksi-LHP") {
    return "<h1>Laporan Hasil Produksi<h1>";
  } elseif (@$_GET["invoice-LHP"]) {
    return "<h1>Data Laporan Hasil Produksi<h1>";
  } elseif (@$_GET["halaman"] == "transaksi-FP") {
    return "<h1>Faktur Penjualan<h1>";
  } elseif (@$_GET["invoice-FP"]) {
    return "<h1>Data Faktur Penjualan<h1>";
  } elseif (@$_GET["halaman"] == "transaksi-BPBP") {
    return "<h1>Bukti Penerimaan Barang Pembelian (BPBP)<h1>";
  } elseif (@$_GET["halaman"] == "transaksi-RJ" || @$_GET["invoice-RJ"]) {
    return "<h1>Retur Jual (RJ)<h1>";
  } elseif (@$_GET["halaman"] == "transaksi-WO" || @$_GET["invoice-WO"]) {
    return "<h1>Working Order (WO)<h1>";
  } elseif (@$_GET["halaman"] == "transaksi-PR" || @$_GET["invoice-PR"]) {
    return "<h1>Purchase Request (PR)<h1>";
  } elseif (@$_GET["halaman"] == "transaksi-PO" || @$_GET["invoice-PO"]) {
    return "<h1>Purchase Order (PO)<h1>";
  } elseif (@$_GET["invoice-BPBP"]) {
    return "<h1>Data Bukti Penerimaan Barang Pembelian<h1>";
  } elseif (@$_GET["halaman"] == "expedisi") {
    return "<h1>Halaman Expedisi<h1>";
  } elseif (@$_GET["expedisi-detail"]) {
    return "<h1>Halaman Detail Expedisi<h1>";
  } elseif (@$_GET["halaman"] == "status-customer") {
    return "<h1>Halaman Status Customer<h1>";
  } elseif (@$_GET["halaman"] == "type-customer") {
    return "<h1>Halaman Tipe Customer<h1>";
  } elseif (@$_GET["halaman"] == "sales" || @$_GET["sales-detail"]) {
    return "<h1>Halaman Sales<h1>";
  } elseif (@$_GET["halaman"] == "promo") {
    return "<h1>Halaman Promo<h1>";
  } else {
    return "Halaman kosong";
  }
}

function diskon_jenis()
{
  $isi = [];
  $a = query("SELECT * FROM diskon_jenis WHERE id_diskon_jenis <> 0");
  while ($b = query_banyak($a)) {
    $isi[] = $b;
  }
  return $isi;
}

function diskon_detail($id, $kode)
{
  $a = query_satu("SELECT * FROM diskon,
  diskon_jenis,
  diskon_tipe
  WHERE
  diskon.id_diskon = '$id' AND
  diskon_jenis.id_diskon_jenis = diskon.id_diskon_jenis AND
  diskon_tipe.id_diskon_tipe = diskon.id_diskon_tipe");
  return $a[$kode];
}

function produk()
{
  $i = [];
  $a = query("SELECT * FROM produk,
  kategori,
  kategori_jenis,
  kategori_header
  WHERE
  kategori.id_kategori = produk.id_kategori AND
  kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis AND
  kategori_header.id_kategori_header = kategori.id_kategori_header
  ORDER BY produk.sku DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_urutan()
{
  return query("SELECT * FROM produk LIMIT 1");
}

function produk_stok()
{
  $i = [];
  $a = query("SELECT * FROM produk,
  kategori,
  kategori_jenis,
  kategori_header
  WHERE
  kategori.id_kategori = produk.id_kategori AND
  kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis AND
  kategori_header.id_kategori_header = kategori.id_kategori_header AND
  produk.stok_produk <> 0
  ORDER BY produk.sku DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_all()
{
  return query("SELECT * FROM satuan");
}

function produk_isi_satuan_jum($id)
{
  return jumlah("SELECT * FROM produk_isi_satuan WHERE id_produk = '$id'");
}

function produk_isi_satuan_akhir($id, $y)
{
  $a = query_satu("SELECT * FROM produk_isi_satuan WHERE id_produk = '$id' ORDER BY id DESC LIMIT 1");
  return @$a[$y];
}

function produk_isi_satuan_awal($id, $y)
{
  $a = query_satu("SELECT * FROM produk_isi_satuan WHERE id_produk = '$id' ORDER BY id ASC LIMIT 1");
  return $a[$y];
}

function produk_isi_satuan($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_isi_satuan WHERE id_produk = '$id' ORDER BY id ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_isi_satuan_kebalik($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_isi_satuan WHERE id_produk = '$id' ORDER BY id DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_isi_satuan_all($id, $o)
{
  return query("SELECT * FROM produk_isi_satuan LIMIT $id, $o");
}

function produk_isi_satuan_alla()
{
  return query("SELECT * FROM produk_isi_satuan");
}

function produk_isi_satuan_kecuali($id, $y)
{
  return query("SELECT * FROM produk_isi_satuan WHERE
  id_produk = '$id' AND
  id_satuan <> '$y'
  ORDER BY id ASC");
}

function produk_isi_satuan_kecuali_kebalik($id, $y)
{
  return query("SELECT * FROM produk_isi_satuan WHERE
  id_produk = '$id' AND
  id_satuan <> '$y'
  ORDER BY id DESC");
}

function produk_isi_satuan_jum_jq($id, $y)
{
  return jumlah("SELECT * FROM produk_isi_satuan,
  satuan,
  jenis_qty
  WHERE
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = '$y' AND
  produk_isi_satuan.id_produk = '$id'");
}

function produk_isi_satuan_kedua($id)
{
  $a = [];
  foreach (produk_isi_satuan($id) as $pis) :
    $a[] = $pis["id_satuan"];
  endforeach;
  return $a[1];
}

function produk_sisa_produksi_satu($id, $o, $n)
{
  $a = query_satu("SELECT * FROM produk_sisa_produksi WHERE
  id_produk = '$id' AND
  id_satuan = '$o'");
  return @$a[$n];
}

function produk_sisa_produksi_jum($id, $o)
{
  return jumlah("SELECT * FROM produk_sisa_produksi WHERE
  id_produk = '$id' AND
  id_satuan = '$o' AND
  jumlah != 0");
}

function produk_sisa_produksi_jumlah($id, $o)
{
  return jumlah("SELECT * FROM produk_sisa_produksi WHERE
  id_produk = '$id' AND
  id_satuan = '$o'");
}

function produk_sisa_produksi_riwayat_id($id, $o, $y)
{
  $a = query_satu("SELECT id FROM produk_sisa_produksi_riwayat
  WHERE
  id_produk = '$id' AND
  tgl = '$o' AND
  id_user = '$y'");
  return $a["id"];
}

function produk_sisa_produksi_riwayat_satu($id, $o)
{
  $a = query_satu("SELECT * FROM produk_sisa_produksi_riwayat
  WHERE
  id = '$id'");
  return $a[$o];
}

function produk_link_bsj_jum($id)
{
  return jumlah("SELECT * FROM produk_link_bsj WHERE
  id_produk_utama = '$id'");
}

function produk_link_bsj_satu($id, $o)
{
  $a = query_satu("SELECT * FROM produk_link_bsj WHERE id_produk_utama = '$id'");
  return @$a[$o];
}

function produk_nama_jum($id)
{
  return jumlah("SELECT * FROM produk WHERE nama_produk = '$id'");
}

function kategori()
{
  $i = [];
  $a = query("SELECT * FROM kategori,
  kategori_header,
  kategori_jenis
  WHERE
  kategori_header.id_kategori_header = kategori.id_kategori_header AND
  kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function kategori_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM kategori,
  kategori_header,
  kategori_jenis
  WHERE
  kategori_header.id_kategori_header = kategori.id_kategori_header AND
  kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis AND
  kategori.id_kategori <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function kategori_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM kategori WHERE id_kategori = '$id'");
  return $a[$ok];
}

function kategori_header_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM kategori_header WHERE id_kategori_header = '$id'");
  return $a[$ok];
}

function kategori_header()
{
  return query("SELECT * FROM kategori_header");
}

function diskon_produk_gratis($id)
{
  $i = [];
  $a = query("SELECT * FROM diskon_produk_gratis,
  produk_satuan,
  satuan,
  produk
  WHERE
  diskon_produk_gratis.id_diskon = '$id' AND
  produk_satuan.id_produk_satuan = diskon_produk_gratis.id_produk_satuan AND
  satuan.id_satuan = produk_satuan.id_satuan AND
  produk.id_produk = diskon_produk_gratis.id_produk");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon()
{
  $i = [];
  $a = query("SELECT * FROM diskon,
  diskon_jenis,
  diskon_tipe
  WHERE
  diskon_jenis.id_diskon_jenis = diskon.id_diskon_jenis AND
  diskon_tipe.id_diskon_tipe = diskon.id_diskon_tipe");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon_target($id, $oke)
{
  $a = query_satu("SELECT * FROM diskon_target,
  diskon_target_jenis 
  WHERE 
  diskon_target.id_diskon = '$id' AND
  diskon_target_jenis.id_diskon_target_jenis = diskon_target.id_diskon_target_jenis");
  return $a[$oke];
}

function diskon_target_jenis()
{
  $i = [];
  $a = query("SELECT * FROM diskon_target_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon_target_jenis_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM diskon_target_jenis WHERE id_diskon_target_jenis <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon_produk_jenis()
{
  $i = [];
  $a = query("SELECT * FROM diskon_produk_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon_produk($id)
{
  $i = [];
  $a = query("SELECT * FROM diskon_produk,
  diskon_produk_jenis
  WHERE 
  diskon_produk.id_diskon = '$id' AND
  diskon_produk_jenis.id_diskon_produk_jenis = diskon_produk.id_diskon_produk_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function hari()
{
  $i = [];
  $a = query("SELECT * FROM hari ORDER BY id_hari ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function seller()
{
  $i = [];
  $a = query("SELECT * FROM seller");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function seller_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM seller WHERE id_seller = '$id'");
  return @$a[$ok];
}

function seller_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM seller WHERE id_seller <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function merk()
{
  $i = [];
  $a = query("SELECT * FROM merk WHERE id_merk <> 0");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function merk_satu($id, $y)
{
  $a = query_satu("SELECT * FROM merk WHERE id_merk = '$id'");
  return $a[$y];
}

function merk_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM merk WHERE id_merk <> 0 AND
  id_merk <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function pabrik_produk()
{
  $i = [];
  $a = query("SELECT * FROM pabrik WHERE id_pabrik <> 0");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function pabrik_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM pabrik WHERE id_pabrik <> 0 AND
  id_pabrik <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function pabrik_satu($id, $y)
{
  $a = query_satu("SELECT * FROM pabrik WHERE id_pabrik = '$id'");
  return $a[$y];
}

function kategori_jenis()
{
  $i = [];
  $a = query("SELECT * FROM kategori_jenis WHERE id_kategori_jenis <> 0");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon_cust($id)
{
  $i = [];
  $a = query("SELECT * FROM diskon_cust,
  diskon_cust_jenis 
  WHERE 
  diskon_cust.id_diskon = '$id' AND
  diskon_cust_jenis.id_diskon_cust_jenis = diskon_cust.id_diskon_cust_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon_cust_jenis()
{
  $i = [];
  $a = query("SELECT * FROM diskon_cust_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function customer()
{
  $i = [];
  $a = query("SELECT * FROM customer");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function customer_satu($id, $o)
{
  $a = query_satu("SELECT * FROM customer WHERE id_customer = '$id'");
  return @$a[$o];
}

function customer_kil_pilih()
{
  return query("SELECT * FROM customer WHERE
  id_customer NOT IN(SELECT id_customer FROM kil_customer)");
}

function customer_lihat($id, $oke)
{
  $a = query_satu("SELECT * FROM customer,
  customer_alamat 
  WHERE 
  customer.id_customer = '$id' AND
  customer_alamat.id_customer = customer.id_customer AND
  customer_alamat.utama = 1");
  return @$a[$oke];
}

function customer_tipe()
{
  $i = [];
  $a = query("SELECT * FROM customer_tipe");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function customer_status()
{
  $i = [];
  $a = query("SELECT * FROM customer_status,
  seller
  WHERE
  seller.id_seller = customer_status.id_seller");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function customer_status_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM customer_status WHERE
  kode_customer_status = '$id'");
  return @$a[$ok];
}

function customer_search($id)
{
  return query("SELECT * FROM customer,
  customer_tipe,
  customer_status
  WHERE
  customer_tipe.kode_customer_tipe = customer.kode_customer_tipe AND
  customer_status.kode_customer_status = customer.kode_customer_status AND
  customer.kode_customer LIKE '%$id%'
  OR
  customer_tipe.kode_customer_tipe = customer.kode_customer_tipe AND
  customer_status.kode_customer_status = customer.kode_customer_status AND
  customer.nama_customer LIKE '%$id%'
  OR
  customer_tipe.kode_customer_tipe = customer.kode_customer_tipe AND
  customer_status.kode_customer_status = customer.kode_customer_status AND
  customer_tipe.nama_customer_tipe LIKE '%$id%'
  OR
  customer_tipe.kode_customer_tipe = customer.kode_customer_tipe AND
  customer_status.kode_customer_status = customer.kode_customer_status AND
  customer_status.nama_customer_status LIKE '%$id%'");
}

function customer_telp($id)
{
  return query("SELECT * FROM customer_telp WHERE
  id_customer = '$id'");
}

function customer_kecuali($id)
{
  return query("SELECT * FROM customer WHERE id_customer != '$id'");
}

function diskon_jumlah($id, $kode)
{
  $a = query_satu("SELECT * FROM diskon_jumlah WHERE id_diskon = '$id'");
  return $a[$kode];
}

function prov_lihat($id, $oke)
{
  $a = query_satu("SELECT * FROM provinces WHERE id = '$id'");
  return @$a[$oke];
}

function kab_lihat($id, $oke)
{
  $a = query_satu("SELECT * FROM regencies WHERE id = '$id'");
  return @$a[$oke];
}

function kec_lihat($id, $oke)
{
  $a = query_satu("SELECT * FROM districts WHERE id = '$id'");
  return @$a[$oke];
}

function kel_lihat($id, $oke)
{
  $a = query_satu("SELECT * FROM villages WHERE id = '$id'");
  return @$a[$oke];
}

function expedisi_contact($id)
{
  $i = [];
  $a = query("SELECT * FROM expedisi_contact,
  expedisi_posisi
  WHERE
  expedisi_contact.id_expedisi_alamat = '$id' AND
  expedisi_posisi.id_expedisi_posisi = expedisi_contact.id_expedisi_posisi");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function expired($id, $kode)
{
  if ($id == 1) {
    $jj = date("Y-m-d");
    if ($jj > $kode) {
      return '
      <span class="badge bg-danger">Expired</span>
      ';
    } else {
      $tgl1 = strtotime(date("Y-m-d"));
      $tgl2 = strtotime($kode);
      $jarak = $tgl2 - $tgl1;
      $hari = $jarak / 60 / 60 / 24;
      if ($hari > 30 and $hari < 360) {
        $thari = round($hari / 30, 1) . ' bulan';
      } elseif ($hari > 360) {
        $thari = round($hari / 30 / 12, 1) . ' tahun';
      } else {
        $thari = $hari . ' hari';
      }
      return '
  <span class="badge bg-success">' . $thari . '</span>
  ';
    }
  } else {
    return '<span class="badge bg-info">Nothing</span>';
  }
}

function expired2($id, $kode)
{
  if ($id == 1) {
    $jj = date("Y-m-d");
    if ($jj > $kode) {
      return false;
    } else {
      $tgl1 = strtotime(date("Y-m-d"));
      $tgl2 = strtotime($kode);
      $jarak = $tgl2 - $tgl1;
      $hari = $jarak / 60 / 60 / 24;
      if ($hari > 30 and $hari < 360) {
        $thari = round($hari / 30, 1) . ' bulan';
      } elseif ($hari > 360) {
        $thari = round($hari / 30 / 12, 1) . ' tahun';
      } else {
        $thari = $hari . ' hari';
      }
      return true;
    }
  } else {
    return true;
  }
}

function expedisi_alamat()
{
  $i = [];
  $a = query("SELECT * FROM expedisi_alamat,
  expedisi,
  provinces,
  expedisi_tipe
  WHERE
  expedisi.id_expedisi = expedisi_alamat.id_expedisi AND
  provinces.id = expedisi_alamat.id_provinsi AND
  expedisi_tipe.id_expedisi_tipe = expedisi.id_expedisi_tipe
  ORDER BY expedisi.id_expedisi ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function expedisi_alamat_kab_jum($id, $ok)
{
  return jumlah("SELECT * FROM expedisi_alamat WHERE
  id_expedisi = '$id' AND
  id_kabupaten = '$ok'");
}

function expedisi_alamat_kab($id, $ok, $yes)
{
  $a = query_satu("SELECT * FROM expedisi_alamat WHERE
  id_expedisi = '$id' AND
  id_kabupaten = '$ok'");
  return $a[$yes];
}

function expedisi_alamat_kec_jum($id, $ok)
{
  return jumlah("SELECT * FROM expedisi_alamat WHERE
  id_expedisi = '$id' AND
  id_kecamatan = '$ok'");
}

function expedisi_alamat_kec($id, $ok, $yes)
{
  $a = query_satu("SELECT * FROM expedisi_alamat WHERE
  id_expedisi = '$id' AND
  id_kecamatan = '$ok'");
  return $a[$yes];
}

function expedisi_ongkir($id, $id2, $id3)
{
  $i = [];
  $a = query("SELECT * FROM expedisi_alamat,
  expedisi
  WHERE
  expedisi.id_expedisi = expedisi_alamat.id_expedisi AND
  expedisi_alamat.id_expedisi_alamat
  NOT IN(SELECT id_expedisi_alamat FROM
  expedisi_ongkir
  WHERE
  id_kecamatan = '$id' AND
  id_kabupaten = '$id2' AND
  id_provinsi = '$id3')");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function ongkir_satu($id, $o)
{
  $a = query_satu("SELECT * FROM ongkir WHERE
  id_ongkir = '$id'");
  return @$a[$o];
}

function sales_grup()
{
  $i = [];
  $a = query("SELECT * FROM sales_grup,
  sales,
  sales_jab,
  sales_alamat
  WHERE
  sales.id_sales = sales_grup.id_sales AND
  sales_grup.status_sales_grup = 1 AND
  sales_jab.id_sales_jab = sales_grup.id_sales_jab AND
  sales_alamat.id_sales = sales.id_sales AND
  sales_alamat.alamat_utama = 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function sales_satu($id, $oke)
{
  $a = query_satu("SELECT * FROM sales WHERE id_sales = '$id'");
  return $a[$oke];
}


function sales_hp_satu($id, $oke)
{
  $a = query_satu("SELECT * FROM sales_hp
  WHERE
  id_sales = '$id'");
  return $a[$oke];
}

function sales_hp($id)
{
  $i = [];
  $a = query("SELECT * FROM sales_hp
  WHERE
  id_sales = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function sales_photo_jumlah($id)
{
  $a = jumlah("SELECT * FROM sales_photo WHERE id_sales = '$id'");
  return $a;
}

function sales_photo_satu($id, $kode)
{
  $a = query_satu("SELECT * FROM sales_photo WHERE id_sales = '$id' AND
  utama = 1");
  return $a[$kode];
}

function sales_kecuali($id)
{
 return query("SELECT * FROM sales WHERE id_sales != '$id'");
}

function grup()
{
  $i = [];
  // $a = query("SELECT * FROM grup,
  // market,
  // sales_grup,
  // sales,
  // sales_jab
  // WHERE
  // market.id_market = grup.id_market AND
  // sales_grup.id_grup = grup.id_grup AND
  // sales_grup.status_sales_grup = 1 AND
  // sales_grup.pimpinan = 1 AND
  // sales.id_sales = sales_grup.id_sales AND
  // sales_jab.id_sales_jab = sales_grup.id_sales_jab
  // ORDER BY grup.id_market DESC");
  $a = query("SELECT * FROM grup,
  market
  WHERE
  market.id_market = grup.id_market");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function grup_pimpinan($id, $oke)
{
  $a = query_satu("SELECT * FROM sales_grup
  WHERE
  id_grup = '$id' AND
  status_sales_grup = '1'");
  return $a[$oke];
}

function grup_pimpinan_jumlah($id)
{
  return jumlah("SELECT * FROM sales_grup WHERE
  id_grup = '$id' AND
  pimpinan = 1 AND
  status_sales_grup = 1");
}

function grup_pimpinan_all($id)
{
  $cek_pim_isi = [];
  $cek_pim = query("SELECT * FROM sales_grup,
                sales,
                sales_jab
                 WHERE
                 sales_grup.id_grup = '$id' AND
                 sales_grup.status_sales_grup = 1 AND
                 sales_grup.kepala = 1 AND
                 sales.id_sales = sales_grup.id_sales AND
                 sales_jab.id_sales_jab = sales_grup.id_sales_jab");
  while ($l_cek_pim = query_banyak($cek_pim)) {
    $cek_pim_isi[] = $l_cek_pim;
  }
  return $cek_pim_isi;
}

function grup_anggota($id)
{
  $i = [];
  $a = query("SELECT * FROM sales_grup,
  sales
  WHERE
  sales_grup.id_grup = '$id' AND
  sales_grup.kepala = 0 AND
  sales_grup.status_sales_grup = 1 AND
  sales.id_sales = sales_grup.id_sales LIMIT 5");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function sales()
{
  $i = [];
  $a = query("SELECT * FROM sales
  WHERE
  id_sales
  NOT IN(SELECT id_sales FROM sales_grup)");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function sales_all()
{
  $i = [];
  $a = query("SELECT * FROM sales,
  sales_jenis
  WHERE
  sales_jenis.id_sales_jenis = sales.id_sales_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function sales_alamat($id, $oke)
{
  $a = query_satu("SELECT * FROM sales_alamat,
  villages 
  WHERE 
  sales_alamat.id_sales = '$id' 
  AND 
  sales_alamat.alamat_utama = 1 AND
  villages.id = sales_alamat.id_kelurahan");
  return $a[$oke];
}

function sales_jab()
{
  $i = [];
  $a = query("SELECT * FROM sales_jab ORDER BY nama_sales_jab ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function sales_jab_isi($id, $oke)
{
  $a = query_satu("SELECT * FROM sales_jab WHERE id_sales_jab = '$id'");
  return $a[$oke];
}

function grup_detail($id, $oke)
{
  $a = query_satu("SELECT * FROM grup,
  sales_grup,
  sales,
  sales_jab
  WHERE
  grup.id_grup = '$id' AND
  sales_grup.id_grup = grup.id_grup AND
  sales.id_sales = sales_grup.id_sales AND
  sales_jab.id_sales_jab = sales_jab.id_sales_jab AND
  sales_grup.pimpinan = 1 AND
  sales_grup.status_sales_grup = 1");
  return $a[$oke];
}

function grup_isi($id, $oke)
{
  $a = query_satu("SELECT * FROM grup WHERE id_grup = '$id'");
  return $a[$oke];
}

function grup_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM grup
  WHERE
  id_grup <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function grup_wilayah($id)
{
  $i = [];
  $a = query("SELECT * FROM grup_wilayah
  WHERE
  id_grup = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function grup_wilayah_jumlah_all($id)
{
  return jumlah("SELECT * FROM grup_wilayah WHERE id_grup = '$id'");
}

function sales_wilayah($id)
{
  $i = [];
  $a = query("SELECT * FROM sales_wilayah
  WHERE 
  id_sales_grup = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function sales_wilayah_header($id)
{
  $i = [];
  $a = query("SELECT * FROM sales_wilayah_header,
  sales_grup,
  sales
  WHERE
  sales_wilayah_header.id_sales_wilayah = '$id' AND
  sales_grup.id_sales_grup = sales_wilayah_header.id_sales_grup AND
  sales.id_sales = sales_grup.id_sales AND
  sales_grup.status_sales_grup = 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function sales_wilayah_header_all()
{
  $i = [];
  $a = query("SELECT * FROM sales_wilayah_header,
  sales_grup,
  sales,
  grup
  WHERE
  sales_grup.id_sales_grup = sales_wilayah_header.id_sales_grup AND
  sales.id_sales = sales_grup.id_sales AND
  grup.id_grup = sales_grup.id_grup");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function sales_wilayah_detail($id)
{
  $i = [];
  $a = query("SELECT * FROM sales_wilayah_detail,
  villages
  WHERE
  sales_wilayah_detail.id_sales_wilayah_header = '$id' AND
  villages.id = sales_wilayah_detail.id_kelurahan");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function sales_cust($id)
{
  $i = [];
  $a = query("SELECT * FROM sales_cust,
    customer,
    customer_alamat
    WHERE
    sales_cust.id_grup_wilayah_sales = '$id' AND
    customer.id_customer = sales_cust.id_customer AND
    customer_alamat.id_customer = customer.id_customer AND
    utama = 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function sales_cust_jumlah($id)
{
  return jumlah("SELECT * FROM sales_cust WHERE id_grup_wilayah_sales = '$id'");
}

function sales_cust_jumlah_all($id)
{
  $a = jumlah("SELECT * FROM sales_cust,
  grup_wilayah_sales
  WHERE
  grup_wilayah_sales.id_grup_wilayah_sales = sales_cust.id_grup_wilayah_sales AND
  grup_wilayah_sales.id_grup_wilayah = '$id' AND
  grup_wilayah_sales.status = 1");
  echo $a;
}

function jumlah_diskon_sales($id)
{
  return jumlah("SELECT * FROM diskon_sales WHERE id_diskon = '$id'");
}

function jumlah_diskon_wilayah($id)
{
  return jumlah("SELECT * FROM diskon_wilayah WHERE id_diskon = '$id'");
}

function diskon_sales_aktif()
{
  $i = [];
  $a = query("SELECT * FROM sales_grup,
  sales,
  sales_jab,
  grup
  WHERE
  sales_grup.status_sales_grup = 1 AND
  sales.id_sales = sales_grup.id_sales AND
  sales_jab.id_sales_jab = sales_grup.id_sales_jab AND
  grup.id_grup = sales_grup.id_grup AND
  sales_grup.id_sales
  ORDER BY
  grup.nama_grup");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon_sales($id)
{
  $i = [];
  $a = query("SELECT * FROM diskon_sales,
  diskon_sales_jenis
  WHERE
  diskon_sales.id_diskon = '$id' AND
  diskon_sales_jenis.id_diskon_sales_jenis = diskon_sales.id_diskon_sales_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon_wilayah()
{
  $i = [];
  $a = query("SELECT * FROM kode_customer
  ORDER BY kode_cust");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon_wilayah_detail($id)
{
  $i = [];
  $a = query("SELECT * FROM diskon_wilayah,
  kode_customer
  WHERE
  diskon_wilayah.id_diskon = '$id' AND
  kode_customer.id_kode_customer = diskon_wilayah.id_kode_customer");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function diskon_sales_jenis()
{
  $i = [];
  $a = query("SELECT * FROM diskon_sales_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function bank()
{
  $i = [];
  $a = query("SELECT * FROM bank
  WHERE
  id_bank NOT IN(SELECT kode FROM recycle WHERE id_recycle_jenis = 8)
  ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function bank_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM bank WHERE id_bank <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function bank_coa_aktiva($id, $ok)
{
  $a = query_satu("SELECT * FROM bank_coa,
  coa 
  WHERE 
  bank_coa.id_rekening = '$id' AND
  bank_coa.id_bank_coa_jenis = 1 AND
  coa.id_coa = bank_coa.id_coa");
  return $a[$ok];
}

function bank_coa_passiva($id, $ok)
{
  $a = query_satu("SELECT * FROM bank_coa,
  coa 
  WHERE 
  bank_coa.id_rekening = '$id' AND
  bank_coa.id_bank_coa_jenis = 2 AND
  coa.id_coa = bank_coa.id_coa");
  return $a[$ok];
}

function bank_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM bank
  WHERE 
  id_bank = '$id'");
  return $a[$ok];
}

function jumlah_sales_anggota($id)
{
  return jumlah("SELECT * FROM sales_wilayah_header WHERE
  id_sales_grup = '$id'");
}

function jumlah_sales_wilayah($id)
{
  return jumlah("SELECT * FROM sales_wilayah WHERE id_sales_grup = '$id'");
}

function jumlah_sales_grup($id)
{
  return jumlah("SELECT * FROM sales_grup,
  grup_wilayah_sales
   WHERE
  status_sales_grup = 1 AND
  grup_wilayah_sales.id_sales_grup = sales_grup.id_sales_grup AND
  grup_wilayah_sales.id_grup_wilayah = '$id'");
}

function sales_grup_detail($id, $oke)
{
  $a = query_satu("SELECT * FROM sales_grup,
  grup,
  sales,
  sales_jab
  WHERE
  sales_grup.id_sales_grup = '$id' AND
  grup.id_grup = sales_grup.id_grup AND
  sales.id_sales = sales_grup.id_sales AND
  sales_jab.id_sales_jab = sales_grup.id_sales_jab");
  return $a[$oke];
}

function sales_grup_jumlah_isi($id)
{
  return jumlah("SELECT * FROM sales_grup WHERE id_sales = '$id' AND
  pimpinan = 1 AND
  status_sales_grup = 1");
}

function suplier()
{
  $i = [];
  $a = query("SELECT * FROM suplier,
  suplier_jenis
  WHERE
  suplier_jenis.id_suplier_jenis = suplier.id_suplier_jenis
  ORDER BY suplier.nama_suplier ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function suplier_pilih($id)
{
  $i = [];
  $a = query("SELECT * FROM suplier,
  suplier_jenis 
  WHERE 
  suplier.id_suplier_jenis = '$id' AND
  suplier_jenis.id_suplier_jenis = suplier.id_suplier_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function suplier_email($id)
{
  $i = [];
  $a = query("SELECT * FROM suplier_email WHERE id_suplier = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function suplier_contact($id)
{
  $i = [];
  $a = query("SELECT * FROM suplier_contact WHERE id_suplier = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function suplier_detail($id, $oke)
{
  $a = query_satu("SELECT * FROM suplier,
  suplier_jenis
  WHERE 
  suplier.id_suplier = '$id' AND
  suplier_jenis.id_suplier_jenis = suplier.id_suplier_jenis");
  return $a[$oke];
}

function suplier_alamat($id, $oke)
{
  $a = query_satu("SELECT * FROM suplier_alamat WHERE id_suplier = '$id'");
  return @$a[$oke];
}

function suplier_rekening($id)
{
  $i = [];
  $a = query("SELECT * FROM suplier_rek,
  bank
  WHERE
  suplier_rek.id_suplier = '$id' AND
  bank.id_bank = suplier_rek.id_bank");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function suplier_produk($id)
{
  $i = [];
  $a = query("SELECT * FROM suplier_produk,
  produk_satuan,
  produk,
  satuan,
  kategori,
  kategori_header,
  kategori_jenis
  WHERE
  suplier_produk.id_suplier = '$id' AND
  produk_satuan.id_produk_satuan = suplier_produk.id_produk_satuan AND
  produk.id_produk = produk_satuan.id_produk AND
  satuan.id_satuan = produk_satuan.id_satuan AND
  kategori.id_kategori = produk.id_kategori AND
  kategori_header.id_kategori_header = kategori.id_kategori_header AND
  kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function suplier_produk_isi($id)
{
  $i = [];
  $a = query("SELECT * FROM suplier_produk_isi,
  produk,
  satuan
  WHERE
  suplier_produk_isi.id_suplier = '$id' AND
  produk.id_produk = suplier_produk_isi.id_produk AND
  satuan.id_satuan = suplier_produk_isi.id_satuan
  ORDER BY suplier_produk_isi.edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }

  return $i;
}

function suplier_produk_isi_jum_suplier($id, $ok)
{
  return jumlah("SELECT * FROM suplier_produk_isi
  WHERE
  id_produk = '$id' AND
  id_suplier = '$ok'");
}

function suplier_produk_isi_satu_suplier($id)
{
  return query("SELECT DISTINCT id_suplier FROM suplier_produk_isi
  WHERE
  id_produk = '$id'");
}

function suplier_produk_isi_jum($id, $y, $a)
{
  return jumlah("SELECT * FROM suplier_produk_isi
  WHERE
  id_suplier = '$id' AND
  id_produk = '$y' AND
  id_satuan = '$a'");
}

function suplier_produk_isi_satu($id, $y, $a, $b)
{
  $c = query_satu("SELECT * FROM suplier_produk_isi
  WHERE
  id_suplier = '$id' AND
  id_produk = '$y' AND
  id_satuan = '$a'");
  return @$c[$b];
}

function suplier_produk_per_produk($id)
{
  $i = [];
  $a = query("SELECT * FROM suplier_produk,
  produk_satuan,
  produk
  WHERE
  produk_satuan.id_produk_satuan = suplier_produk.id_produk_satuan AND
  suplier_produk.id_suplier_produk = '$id' AND
  produk.id_produk = produk_satuan.id_produk");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function suplier_produk_per_produk_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM suplier_produk,
  produk_satuan,
  produk,
  satuan
  WHERE
  suplier_produk.id_suplier_produk = '$id' AND
  produk_satuan.id_produk_satuan = suplier_produk.id_produk_satuan AND
  produk.id_produk = produk_satuan.id_produk AND
  satuan.id_satuan = produk_satuan.id_satuan");
  return $a[$ok];
}

function suplier_ex_bpom($id, $oke)
{
  $a = query_satu("SELECT * FROM suplier_produk_expired WHERE id_suplier_produk = '$id' AND
  id_expired = 2");
  return $a[$oke];
}

function suplier_ex_bpom_produk($id, $ok, $yes)
{
  $a = query_satu("SELECT * FROM suplier_produk_expired,
  suplier_produk,
  produk_satuan
  WHERE
  suplier_produk_expired.id_expired = 2 AND
  suplier_produk.id_suplier_produk = suplier_produk_expired.id_suplier_produk AND
  suplier_produk.id_suplier = '$id' AND
  produk_satuan.id_produk_satuan = suplier_produk.id_produk_satuan AND
  produk_satuan.id_produk = '$ok'
  ");
  return $a[$yes];
}

function suplier_ex_mui_produk($id, $ok, $yes)
{
  $a = query_satu("SELECT * FROM suplier_produk_expired,
  suplier_produk,
  produk_satuan
  WHERE
  suplier_produk_expired.id_expired = 1 AND
  suplier_produk.id_suplier_produk = suplier_produk_expired.id_suplier_produk AND
  suplier_produk.id_suplier = '$id' AND
  produk_satuan.id_produk_satuan = suplier_produk.id_produk_satuan AND
  produk_satuan.id_produk = '$ok'
  ");
  return $a[$yes];
}

function suplier_produk_ex($ha, $id, $ok, $yes)
{
  $a = query_satu("SELECT * FROM suplier_produk_expired,
  suplier_produk,
  produk_satuan
  WHERE
  suplier_produk_expired.id_expired = '$ha' AND
  suplier_produk.id_suplier_produk = suplier_produk_expired.id_suplier_produk AND
  suplier_produk.id_suplier = '$id' AND
  produk_satuan.id_produk_satuan = suplier_produk.id_produk_satuan AND
  produk_satuan.id_produk = '$ok'
  ");
  return $a[$yes];
}

function suplier_ex_mui($id, $oke)
{
  $a = query_satu("SELECT * FROM suplier_produk_expired WHERE id_suplier_produk = '$id' AND
  id_expired = 1
  ORDER BY tgl_expired ASC");
  return $a[$oke];
}

function suplier_produk_saja()
{
  $i = [];
  $a = query("SELECT * FROM suplier_produk,
    suplier,
    produk_satuan,
    satuan
    WHERE
    suplier.id_suplier = suplier_produk.id_suplier AND
    produk_satuan.id_produk_satuan = suplier_produk.id_produk_satuan AND
    satuan.id_satuan = produk_satuan.id_satuan");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function suplier_produk_nama($id, $oke)
{
  $a = query_satu("SELECT * FROM produk_satuan,
  produk,
  kategori
  WHERE
  produk_satuan.id_produk_satuan = '$id' AND
  produk.id_produk = produk_satuan.id_produk AND
  kategori.id_kategori = produk.id_kategori");
  return $a[$oke];
}



function produk_suplier($id)
{
  $i = [];
  $a = query("SELECT * FROM suplier_produk,
  suplier,
  produk_satuan,
  satuan
  WHERE
  suplier_produk.id_produk_satuan = '$id' AND
  suplier.id_suplier = suplier_produk.id_suplier AND
  produk_satuan.id_produk_satuan = suplier_produk.id_produk_satuan AND
  satuan.id_satuan = produk_satuan.id_satuan");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function suplier_jenis()
{
  $i = [];
  $a = query("SELECT * FROM suplier_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function suplier_jenis_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM suplier_jenis WHERE id_suplier_jenis <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function suplier_jenis_satu($id, $oke)
{
  $a = query_satu("SELECT * FROM suplier_jenis WHERE id_suplier_jenis = '$id'");
  return $a[$oke];
}

function suplier_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM suplier
  WHERE
  id_suplier = '$id'");
  return $a[$ok];
}

function kategori_jenis_satu($id, $oke)
{
  $a = query_satu("SELECT * FROM kategori_jenis WHERE id_kategori_jenis = '$id'");
  return $a[$oke];
}

function kategori_jenis_all()
{
  $a = query("SELECT * FROM kategori_jenis");
  return $a;
}

function diskon_bonus_produk()
{
  $i = [];
  $a = query("SELECT * FROM diskon_bonus_produk ORDER BY nama_diskon_bonus_produk ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function diskon_bonus($id)
{
  $i = [];
  $a = query("SELECT * FROM diskon_bonus,
  diskon_bonus_jenis 
  WHERE 
  diskon_bonus.id_diskon = '$id' AND
  diskon_bonus_jenis.id_diskon_bonus_jenis = diskon_bonus.id_diskon_bonus_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function diskon_bonus_produk_header($id)
{
  $i = [];
  $a = query("SELECT * FROM diskon_bonus_produk_header,
  diskon_bonus_produk
  WHERE 
  diskon_bonus_produk_header.id_diskon_bonus = '$id' AND
  diskon_bonus_produk.id_diskon_bonus_produk = diskon_bonus_produk_header.id_diskon_bonus_produk");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function market()
{
  $i = [];
  $a = query("SELECT * FROM market ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function market_grup_jumlah($id)
{
  return jumlah("SELECT * FROM grup WHERE id_market = '$id'");
}

function market_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM market WHERE id_market <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function kode($id, $kode)
{
  $a = query_satu("SELECT * FROM kode WHERE id = '$id'");
  return $a[$kode];
}

function jumlah_pimpinan_grup($id)
{
  $a = jumlah("SELECT * FROM sales_grup WHERE
  id_grup = '$id' AND
  pimpinan = 1 AND
  status_sales_grup = 1");
  return $a;
}

function grup_wilayah_sales($id)
{
  $i = [];
  $a = query("SELECT * FROM grup_wilayah_sales,
  sales
  WHERE
  grup_wilayah_sales.id_grup_wilayah = '$id' AND
  sales.id_sales = grup_wilayah_sales.id_sales AND
  status = 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function grup_wilayah_sales_detail($id, $oke)
{
  $a = query_satu("SELECT * FROM grup_wilayah_sales,
  sales,
  grup_wilayah
  WHERE
  grup_wilayah_sales.id_grup_wilayah_sales = '$id' AND
  sales.id_sales = grup_wilayah_sales.id_sales AND
  grup_wilayah.id_grup_wilayah = grup_wilayah_sales.id_grup_wilayah");
  return $a[$oke];
}

function grup_wilayah_sales_jumlah_all($id)
{
  return jumlah("SELECT * FROM grup_wilayah_sales WHERE id_grup_wilayah = '$id' AND
  status = 1");
}

function villages($id)
{
  $i = [];
  $a = query("SELECT * FROM villages WHERE district_id = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function villages_kecuali($id, $o)
{
  $i = [];
  $a = query("SELECT * FROM villages WHERE district_id = '$id' AND
  id != '$o'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function tipe_master_perkiraan()
{
  $i = [];
  $a = query("SELECT * FROM coa_tipe_perkiraan");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_kecuali($kode_master_perkiraan, $id_coa)
{
  return query("SELECT * FROM coa WHERE
  kode_master_perkiraan = '$kode_master_perkiraan' AND
  id_coa != '$id_coa'");
}

function coa_master_perkiraan()
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan ORDER BY kode_master_perkiraan ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_master_perkiraan_kecuali($kode_master_perkiraan)
{
  return query("SELECT * FROM coa_master_perkiraan WHERE
  kode_master_perkiraan != '$kode_master_perkiraan'");
}

function coa_master_perkiraan_satu_kode($kode_master_perkiraan, $isi)
{
  $a = query_satu("SELECT * FROM coa_master_perkiraan WHERE
  kode_master_perkiraan = '$kode_master_perkiraan'");
  return $a[$isi];
}

function coa_master_perkiraan_bukan_biaya()
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan,
  coa_tipe_perkiraan,
  coa_kelompok_perkiraan
  WHERE
  coa_master_perkiraan.id_coa_tipe_perkiraan <> 5 AND
  coa_tipe_perkiraan.id_coa_tipe_perkiraan = coa_master_perkiraan.id_coa_tipe_perkiraan AND
  coa_kelompok_perkiraan.id_coa_kelompok_perkiraan = coa_master_perkiraan.id_coa_kelompok_perkiraan
  ORDER BY
  coa_master_perkiraan.kode_master_perkiraan ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_master_perkiraan_yang_biaya()
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan,
  coa_tipe_perkiraan,
  coa_kelompok_perkiraan
  WHERE
  coa_master_perkiraan.id_coa_tipe_perkiraan = 5 AND
  coa_tipe_perkiraan.id_coa_tipe_perkiraan = coa_master_perkiraan.id_coa_tipe_perkiraan AND
  coa_kelompok_perkiraan.id_coa_kelompok_perkiraan = coa_master_perkiraan.id_coa_kelompok_perkiraan
  ORDER BY coa_master_perkiraan.kode_master_perkiraan ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}


function coa_master_perkiraan_detail()
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan_detail,
  coa_master_perkiraan,
  coa_kelompok_perkiraan
  WHERE
  coa_master_perkiraan.id_coa_master_perkiraan = coa_master_perkiraan_detail.id_coa_master_perkiraan AND
  coa_kelompok_perkiraan.id_coa_kelompok_perkiraan = coa_master_perkiraan.id_coa_kelompok_perkiraan
  ORDER BY coa_master_perkiraan_detail.edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_master_perkiraan_detail_berdasarkan($id)
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan_detail,
  coa_master_perkiraan
  WHERE
  coa_master_perkiraan_detail.id_coa_master_perkiraan = '$id' AND
  coa_master_perkiraan.id_coa_master_perkiraan = coa_master_perkiraan_detail.id_coa_master_perkiraan");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_neraca_lajur()
{
  $i = [];
  $a = query("SELECT * FROM coa_neraca_lajur ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_jenis_perkiraan()
{
  $i = [];
  $a = query("SELECT * FROM coa_jenis_perkiraan ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_kategori_perkiraan()
{
  $i = [];
  $a = query("SELECT * FROM coa_kategori_perkiraan ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_jenis_biaya_perkiraan()
{
  $i = [];
  $a = query("SELECT * FROM coa_jenis_biaya_perkiraan ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_lihat($id)
{
  $i = [];
  $a = query("SELECT * FROM coa,
  coa_master_perkiraan,
  coa_jenis_perkiraan,
  coa_detail,
  coa_kategori_perkiraan,
  coa_kelompok_perkiraan
  WHERE
  coa_master_perkiraan.kode_master_perkiraan = coa.kode_master_perkiraan AND
  coa.kode_master_perkiraan = '$id' AND
  coa_jenis_perkiraan.id_coa_jenis_perkiraan = coa.id_coa_jenis_perkiraan AND
  coa_detail.id_coa = coa.id_coa AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan AND
  coa_kelompok_perkiraan.id_coa_kelompok_perkiraan = coa_master_perkiraan.id_coa_kelompok_perkiraan");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_lihat_passiva($id)
{
  $i = [];
  $a = query("SELECT * FROM coa,
  coa_master_perkiraan,
  coa_jenis_perkiraan,
  coa_detail,
  coa_kategori_perkiraan,
  coa_kelompok_perkiraan
  WHERE
  coa_master_perkiraan.kode_master_perkiraan = coa.kode_master_perkiraan AND
  coa.kode_master_perkiraan = '$id' AND
  coa_jenis_perkiraan.id_coa_jenis_perkiraan = coa.id_coa_jenis_perkiraan AND
  coa_detail.id_coa = coa.id_coa AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan AND
  coa_kelompok_perkiraan.id_coa_kelompok_perkiraan = coa_master_perkiraan.id_coa_kelompok_perkiraan AND
  coa.id_coa_jenis_perkiraan = 2");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_lihat_aktiva($id)
{
  $i = [];
  $a = query("SELECT * FROM coa,
  coa_master_perkiraan,
  coa_jenis_perkiraan,
  coa_detail,
  coa_kategori_perkiraan,
  coa_kelompok_perkiraan
  WHERE
  coa_master_perkiraan.kode_master_perkiraan = coa.kode_master_perkiraan AND
  coa.kode_master_perkiraan = '$id' AND
  coa_jenis_perkiraan.id_coa_jenis_perkiraan = coa.id_coa_jenis_perkiraan AND
  coa_detail.id_coa = coa.id_coa AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan AND
  coa_kelompok_perkiraan.id_coa_kelompok_perkiraan = coa_master_perkiraan.id_coa_kelompok_perkiraan AND
  coa.id_coa_jenis_perkiraan = 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_lihat_modal($id)
{
  $i = [];
  $a = query("SELECT * FROM coa,
  coa_master_perkiraan,
  coa_jenis_perkiraan,
  coa_detail,
  coa_kategori_perkiraan,
  coa_kelompok_perkiraan
  WHERE
  coa_master_perkiraan.kode_master_perkiraan = coa.kode_master_perkiraan AND
  coa.kode_master_perkiraan = '$id' AND
  coa_jenis_perkiraan.id_coa_jenis_perkiraan = coa.id_coa_jenis_perkiraan AND
  coa_detail.id_coa = coa.id_coa AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan AND
  coa_kelompok_perkiraan.id_coa_kelompok_perkiraan = coa_master_perkiraan.id_coa_kelompok_perkiraan AND
  coa.id_coa_jenis_perkiraan = 3");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_lihat_laba_rugi($id)
{
  $i = [];
  $a = query("SELECT * FROM coa,
  coa_master_perkiraan,
  coa_jenis_perkiraan,
  coa_detail,
  coa_kategori_perkiraan,
  coa_kelompok_perkiraan
  WHERE
  coa_master_perkiraan.kode_master_perkiraan = coa.kode_master_perkiraan AND
  coa.kode_master_perkiraan = '$id' AND
  coa_jenis_perkiraan.id_coa_jenis_perkiraan = coa.id_coa_jenis_perkiraan AND
  coa_detail.id_coa = coa.id_coa AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan AND
  coa_kelompok_perkiraan.id_coa_kelompok_perkiraan = coa_master_perkiraan.id_coa_kelompok_perkiraan AND
  coa.id_coa_jenis_perkiraan = 17");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_lihat_biaya($id)
{
  $i = [];
  $a = query("SELECT * FROM coa,
  coa_master_perkiraan,
  coa_jenis_perkiraan,
  coa_detail,
  coa_kategori_perkiraan,
  coa_kelompok_perkiraan
  WHERE
  coa_master_perkiraan.kode_master_perkiraan = coa.kode_master_perkiraan AND
  coa.kode_master_perkiraan = '$id' AND
  coa_jenis_perkiraan.id_coa_jenis_perkiraan = coa.id_coa_jenis_perkiraan AND
  coa_detail.id_coa = coa.id_coa AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan AND
  coa_kelompok_perkiraan.id_coa_kelompok_perkiraan = coa_master_perkiraan.id_coa_kelompok_perkiraan AND
  coa.id_coa_jenis_perkiraan = 4");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function jumlah_coa_biaya($id)
{
  return jumlah("SELECT * FROM coa_biaya WHERE id_coa = '$id'");
}

function coa_biaya_lihat($id, $ok)
{
  $a = query_satu("SELECT * FROM coa_biaya,
  coa_jenis_biaya_perkiraan 
  WHERE 
  coa_biaya.id_coa = '$id' AND
  coa_jenis_biaya_perkiraan.id_coa_jenis_biaya_perkiraan = coa_biaya.id_jenis_biaya_perkiraan");
  return $a[$ok];
}

function coa_aja($id, $ok)
{
  $a = query_satu("SELECT * FROM coa,
  coa_master_perkiraan,
  coa_jenis_perkiraan,
  coa_kategori_perkiraan,
  coa_detail,
  coa_jenis,
  coa_neraca_lajur
  WHERE
  coa.id_coa = '$id' AND
  coa_master_perkiraan.kode_master_perkiraan = coa.kode_master_perkiraan AND
  coa_jenis_perkiraan.id_coa_jenis_perkiraan = coa.id_coa_jenis_perkiraan AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan AND
  coa_detail.id_coa = coa.id_coa AND
  coa_jenis.id_coa_jenis = coa_detail.id_coa_jenis AND
  coa_neraca_lajur.id_coa_neraca_lajur = coa.id_coa_neraca_lajur");
  return $a[$ok];
}

function coa_jenis_perkiraan_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM coa_jenis_perkiraan
  WHERE
  id_coa_jenis_perkiraan <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_kategori_perkiraan_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM coa_kategori_perkiraan
  WHERE
  id_coa_kategori_perkiraan <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_biaya_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM coa_biaya,
  coa_jenis_biaya_perkiraan 
  WHERE 
  coa_biaya.id_coa = '$id' AND
  coa_jenis_biaya_perkiraan.id_coa_jenis_biaya_perkiraan = coa_biaya.id_jenis_biaya_perkiraan");
  return $a[$ok];
}

function coa_biaya_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM coa_jenis_biaya_perkiraan
  WHERE
  id_coa_jenis_biaya_perkiraan <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_neraca_lajur_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM coa_neraca_lajur
  WHERE
  id_coa_neraca_lajur <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_master_perkiraan_ada_dicoa()
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan
      WHERE
      kode_master_perkiraan IN(SELECT kode_master_perkiraan
      FROM coa)");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_master_perkiraan_aktiva()
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan
      WHERE
      kode_master_perkiraan IN(SELECT kode_master_perkiraan
      FROM coa
      WHERE
      id_coa_jenis_perkiraan = 1)");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_master_perkiraan_passiva()
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan
      WHERE
      kode_master_perkiraan IN(SELECT kode_master_perkiraan
      FROM coa
      WHERE
      id_coa_jenis_perkiraan = 2)");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_master_perkiraan_modal()
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan
      WHERE
      kode_master_perkiraan IN(SELECT kode_master_perkiraan
      FROM coa
      WHERE
      id_coa_jenis_perkiraan = 3)");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_master_perkiraan_laba_rugi()
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan
      WHERE
      kode_master_perkiraan IN(SELECT kode_master_perkiraan
      FROM coa
      WHERE
      id_coa_jenis_perkiraan = 17)");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_master_perkiraan_biaya()
{
  $i = [];
  $a = query("SELECT * FROM coa_master_perkiraan
      WHERE
      kode_master_perkiraan IN(SELECT kode_master_perkiraan
      FROM coa
      WHERE
      id_coa_jenis_perkiraan = 4)");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_detail($id, $oke)
{
  $a = query_satu("SELECT * FROM coa,
  coa_jenis_perkiraan,
  coa_kategori_perkiraan,
  coa_master_perkiraan,
  coa_kelompok_perkiraan,
  coa_neraca_lajur
  WHERE
  coa.id_coa = '$id' AND
  coa_jenis_perkiraan.id_coa_jenis_perkiraan = coa.id_coa_jenis_perkiraan AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan AND
  coa_master_perkiraan.kode_master_perkiraan = coa.kode_master_perkiraan AND
  coa_kelompok_perkiraan.id_coa_kelompok_perkiraan = coa_master_perkiraan.id_coa_kelompok_perkiraan AND
  coa_neraca_lajur.id_coa_neraca_lajur = coa.id_coa_neraca_lajur");
  return $a[$oke];
}

function coa_detail_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM coa_detail WHERE id_coa = '$id'");
  return $a[$ok];
}

function coa_aktiva()
{
  $i = [];
  $a = query("SELECT * FROM coa WHERE id_coa_jenis_perkiraan = 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_aktiva_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM coa WHERE id_coa_jenis_perkiraan = 1 AND
  id_coa <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_passiva()
{
  $i = [];
  $a = query("SELECT * FROM coa WHERE id_coa_jenis_perkiraan = 2");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_passiva_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM coa WHERE id_coa_jenis_perkiraan = 2 AND
  id_coa <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_img($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_img WHERE id_produk = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa()
{
  $i = [];
  $a = query("SELECT * FROM coa,
  coa_jenis_perkiraan,
  coa_detail,
  coa_kategori_perkiraan
  WHERE
  coa_jenis_perkiraan.id_coa_jenis_perkiraan = coa.id_coa_jenis_perkiraan AND
  coa_detail.id_coa = coa.id_coa AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan
  ORDER BY
  coa.kode_coa ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_favorite()
{
  $i = [];
  $a = query("SELECT * FROM coa_favorit,
  coa,
  coa_jenis_perkiraan
  WHERE
  coa.kode_coa = coa_favorit.kode_coa AND
  coa_jenis_perkiraan.id_coa_jenis_perkiraan = coa.id_coa_jenis_perkiraan
  ORDER BY coa_favorit.kode_coa ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_jenis_perkiraan_biaya()
{
  $i = [];
  $a = query("SELECT * FROM coa
  WHERE
  id_coa_jenis_perkiraan = 4
  ORDER BY kode_coa ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function jurnal_kelompok()
{
  $i = [];
  $a = query("SELECT * FROM jurnal_kelompok
  ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function jurnal_kelompok_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM jurnal_kelompok WHERE id_jurnal_kelompok = '$id'");
  return $a[$ok];
}

function coa_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM coa,
  coa_kategori_perkiraan 
  WHERE
  coa.id_coa = '$id' AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan");
  return $a[$ok];
}

function jurnal_kode_jumlah($id, $ok)
{
  return jumlah("SELECT * FROM jurnal_kode WHERE
  bulan = '$id' AND
  tahun = '$ok'");
}

function jurnal_kode_satu($id, $ok, $ya)
{
  $a = query_satu("SELECT * FROM jurnal_kode WHERE
  bulan = '$id' AND
  tahun = '$ok'");
  return $a[$ya];
}

function jurnal_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM jurnal,
  jurnal_kelompok,
  jurnal_jenis
  WHERE
  jurnal.id_jurnal = '$id' AND
  jurnal_kelompok.id_jurnal_kelompok = jurnal.id_jurnal_kelompok AND
  jurnal_jenis.id_jurnal_jenis = jurnal.id_jurnal_jenis");
  return $a[$ok];
}

function jurnal()
{
  $i = [];
  $a = query("SELECT * FROM jurnal
    WHERE
    id_jurnal NOT IN(SELECT kode FROM recycle WHERE id_recycle_jenis = 1)
  ORDER BY kode_jurnal ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function jurnal_kelompok_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM jurnal_kelompok WHERE id_jurnal_kelompok <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function jurnal_detail($id)
{
  $i = [];
  $a = query("SELECT * FROM jurnal_detail,
  coa,
  coa_kategori_perkiraan
  WHERE
  jurnal_detail.id_jurnal = '$id' AND
  coa.kode_coa = jurnal_detail.kode_coa AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function jurnal_detail_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM
  jurnal_detail,
  coa,
  coa_kategori_perkiraan,
  akuntan_jenis
  WHERE
  jurnal_detail.id_jurnal_detail = '$id' AND
  coa.kode_coa = jurnal_detail.kode_coa AND
  coa_kategori_perkiraan.id_coa_kategori_perkiraan = coa.id_kategori_perkiraan AND
  akuntan_jenis.id_akuntan_jenis = jurnal_detail.id_akuntan_jenis");
  return $a[$ok];
}

function akuntan_jenis()
{
  return query("SELECT * FROM akuntan_jenis");
}

function akuntan_jenis_kecuali($id)
{
  return query("SELECT * FROM akuntan_jenis WHERE id_akuntan_jenis != '$id'");
}

function akuntan_jenis_satu($id, $a)
{
  $b = query_satu("SELECT * FROM akuntan_jenis WHERE
  id_akuntan_jenis = '$id'");
  return $b[$a];
}

function jurnal_detail_jumlah($id)
{
  return jumlah("SELECT * FROM jurnal_detail WHERE id_jurnal = '$id'");
}

function cabang()
{
  $i = [];
  $a = query("SELECT * FROM cabang
  WHERE 
  id_cabang NOT IN(SELECT kode FROM recycle WHERE id_recycle_jenis = 2)
  ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function recycle()
{
  $i = [];
  $a = query("SELECT * FROM recycle,
  recycle_jenis,
  user
  WHERE
  recycle_jenis.id_recycle_jenis = recycle.id_recycle_jenis AND
  user.id_user = recycle.id_user
  ORDER BY 
  recycle.tgl_masuk DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function recycle_jumlah()
{
  return jumlah("SELECT * FROM recycle");
}

function cabang_cp($id)
{
  $i = [];
  $a = query("SELECT * FROM cabang_cp
  WHERE
  id_cabang = '$id' AND
  id_cabang_cp NOT IN(SELECT kode FROM recycle WHERE
  id_recycle_jenis = 3)
  ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function cabang_cp_satu($id, $i)
{
  $a = query_satu("SELECT * FROM cabang_cp
  WHERE
  id_cabang_cp = '$id'");
  return $a[$i];
}

function recycle_proses()
{
  $hari = date("Y-m-d");
  $cek = jumlah("SELECT * FROM recycle WHERE '$hari' > tgl_berakhir");
  if ($cek > 0) {
    $lihat = query("SELECT * FROM recycle WHERE '$hari' > tgl_berakhir");
    while ($l_lihat = query_banyak($lihat)) {
      $recycle_jenis = $l_lihat["id_recycle_jenis"];
      $kode = $l_lihat["kode"];
      $id = $l_lihat["id"];
      if ($recycle_jenis == 1) {
        $h = query("DELETE FROM jurnal_detail WHERE id_jurnal = '$kode'");
        if ($h) {
          query("DELETE FROM jurnal WHERE id_jurnal = '$kode'");
          query("DELETE FROM recycle WHERE id = '$id'");
        } else {
          query("DELETE FROM recycle WHERE id = '$id'");
        }
      } elseif ($recycle_jenis == 2) {
        $h = query("DELETE FROM cabang WHERE id_cabang = '$kode'");
        if ($h) {
          query("DELETE FROM cabang_cp WHERE id_cabang = '$kode'");
          query("DELETE FROM recycle WHERE id = '$id'");
        } else {
          query("DELETE FROM recycle WHERE id = '$id'");
        }
      } elseif ($recycle_jenis == 3) {
        $h = query("DELETE FROM cabang_cp WHERE id_cabang_cp = '$kode'");
        if ($h) {
          query("DELETE FROM recycle WHERE id = '$id'");
        } else {
          query("DELETE FROM recycle WHERE id = '$id'");
        }
      } elseif ($recycle_jenis == 4) {
        $h = query("DELETE FROM asset_bulan_susut WHERE id_asset_bulan_susut = '$kode'");
        if ($h) {
          query("DELETE FROM recycle WHERE id = '$id'");
        } else {
          query("DELETE FROM recycle WHERE id = '$id'");
        }
      } elseif ($recycle_jenis == 5) {
        $h = query("DELETE FROM asset_coa WHERE id_asset = '$kode'");
        if ($h) {
          query("DELETE FROM asset_suplier WHERE id_asset = '$kode'");
          query("DELETE FROM asset WHERE id_asset = '$kode'");
          query("DELETE FROM recycle WHERE id = '$id'");
        } else {
          query("DELETE FROM recycle WHERE id = '$id'");
        }
      } elseif ($recycle_jenis == 6) {
        $h = query("DELETE FROM rekening WHERE id_rekening = '$kode'");
        if ($h) {
          query("DELETE FROM rekening_alamat WHERE id_rekening = '$kode'");
          query("DELETE FROM bank_coa WHERE id_rekening = '$kode'");
          query("DELETE FROM recycle WHERE id = '$id'");
        } else {
          query("DELETE FROM recycle WHERE id = '$id'");
        }
      } elseif ($recycle_jenis == 7) {
        $h = query("DELETE FROM bank_biaya_jenis WHERE id_bank_biaya_jenis = '$kode'");
        if ($h) {
          query("DELETE FROM recycle WHERE id = '$id'");
        } else {
          query("DELETE FROM recycle WHERE id = '$id'");
        }
      } elseif ($recycle_jenis == 8) {
        $cek_bank = query_satu("SELECT * FROM bank WHERE id_bank = '$kode'");
        $gambar_bank = $cek_bank["gambar_bank"];
        $tmp = "../../admin/pages/img/bank/" . $gambar_bank;
        $h = query("DELETE FROM bank WHERE id_bank = '$kode'");
        if ($h) {
          if ($gambar_bank != "nophoto.jpg") {
            unlink($tmp);
          }
          query("DELETE FROM recycle WHERE id = '$id'");
        } else {
          query("DELETE FROM recycle WHERE id = '$id'");
        }
      } elseif ($recycle_jenis == 9) {
        $h = query("DELETE FROM bank_biaya WHERE id_bank_biaya = '$kode'");
        if ($h) {
          query("DELETE FROM recycle WHERE id = '$id'");
        } else {
          query("DELETE FROM recycle WHERE id = '$id'");
        }
      }
    }
  }
}

function recycle_jenis_satu($id, $o)
{
  $a = query_satu("SELECT * FROM recycle_jenis WHERE id_recycle_jenis = '$id'");
  return $a[$o];
}

function asset_bulan_susut()
{
  $i = [];
  $a = query("SELECT * FROM asset_bulan_susut
  WHERE
  id_asset_bulan_susut NOT IN(SELECT kode FROM recycle WHERE
  id_recycle_jenis = 4)
  ORDER BY bulan_susut ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function asset_bulan_susut_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM asset_bulan_susut
  WHERE
  id_asset_bulan_susut NOT IN(SELECT kode FROM recycle WHERE
  id_recycle_jenis = 4) AND
  bulan_susut <> '$id'
  ORDER BY bulan_susut ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_inventaris()
{
  $i = [];
  $a = query("SELECT * FROM coa WHERE kode_master_perkiraan = 108");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_inventaris_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM coa WHERE kode_master_perkiraan = 108 AND
  kode_coa <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_biaya_penyusutan()
{
  $i = [];
  $a = query("SELECT * FROM coa WHERE kode_master_perkiraan = 604");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_biaya_penyusutan_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM coa WHERE kode_master_perkiraan = 604 AND
  kode_coa <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_akumulasi_penyusutan()
{
  $i = [];
  $a = query("SELECT * FROM coa WHERE kode_master_perkiraan = 109");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_akumulasi_penyusutan_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM coa WHERE kode_master_perkiraan = 109 AND
  kode_coa <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function asset_pusat()
{
  $i = [];
  $a = query("SELECT * FROM asset
  WHERE
  pusat = 1 AND
  id_asset NOT IN(SELECT kode FROM recycle WHERE id_recycle_jenis = 5)
  ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function asset_coa($id)
{
  $i = [];
  $a = query("SELECT * FROM asset_coa,
  coa,
  asset_coa_jenis
  WHERE
  asset_coa.id_asset = '$id' AND
  coa.kode_coa = asset_coa.kode_coa AND
  asset_coa_jenis.id_asset_coa_jenis = asset_coa.id_asset_coa_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function asset_coa_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM asset_coa,
  coa,
  asset_coa_jenis
  WHERE
  asset_coa.id_asset_coa = '$id' AND
  coa.kode_coa = asset_coa.kode_coa AND
  asset_coa_jenis.id_asset_coa_jenis = asset_coa.id_asset_coa_jenis");
  return $a[$ok];
}

function asset_suplier($id, $ok)
{
  $a = query_satu("SELECT * FROM asset_suplier,
  suplier 
  WHERE 
  asset_suplier.id_asset = '$id' AND
  suplier.id_suplier = asset_suplier.id_suplier");
  return $a[$ok];
}

function asset_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM asset WHERE id_asset = '$id'");
  return $a[$ok];
}

function asset_inventaris_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM asset_coa,
  coa
  WHERE
  asset_coa.id_asset = '$id' AND
  coa.kode_coa = asset_coa.kode_coa AND
  coa.kode_master_perkiraan = 108");
  return $a[$ok];
}

function asset_biaya_penyusutan($id, $ok)
{
  $a = query_satu("SELECT * FROM asset_coa,
  coa
  WHERE
  asset_coa.id_asset = '$id' AND
  coa.kode_coa = asset_coa.kode_coa AND
  coa.kode_master_perkiraan = 604");
  return $a[$ok];
}

function rekening()
{
  $i = [];
  $a = query("SELECT * FROM rekening,
  bank
  WHERE
  rekening.id_rekening NOT IN(SELECT kode FROM recycle WHERE id_recycle_jenis = 6) AND
  bank.id_bank = rekening.id_bank
  ORDER BY rekening.edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function rekening_alamat($id, $ok)
{
  $a = query_satu("SELECT * FROM rekening_alamat WHERE id_rekening = '$id'");
  return $a[$ok];
}

function rekening_sendiri()
{
  $i = [];
  $a = query("SELECT * FROM rekening,
  bank,
  bank_valuta
  WHERE
  rekening.id_rekening NOT IN(SELECT kode FROM recycle WHERE id_recycle_jenis = 6) AND
  bank.id_bank = rekening.id_bank AND
  sendiri = 1 AND
  bank_valuta.id_bank_valuta = rekening.id_bank_valuta
  ORDER BY rekening.edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function rekening_lainnya()
{
  $i = [];
  $a = query("SELECT * FROM rekening,
  bank
  WHERE
  rekening.id_rekening NOT IN(SELECT kode FROM recycle WHERE id_recycle_jenis = 6) AND
  bank.id_bank = rekening.id_bank AND
  sendiri = 0
  ORDER BY rekening.edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function rekening_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM rekening,
  bank,
  bank_valuta
  WHERE
  rekening.id_rekening = '$id' AND
  bank.id_bank = rekening.id_bank AND
  bank_valuta.id_bank_valuta = rekening.id_bank_valuta");
  return $a[$ok];
}

function rekening_kecuali($id_rekening)
{
  return query("SELECT * FROM rekening WHERE
  id_rekening != '$id_rekening'");
}

function bank_biaya_jenis()
{
  $i = [];
  $a = query("SELECT * FROM bank_biaya_jenis
  WHERE
  id_bank_biaya_jenis NOT IN(SELECT kode FROM recycle WHERE id_recycle_jenis = 7)
  ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function bank_biaya_jenis_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM bank_biaya_jenis WHERE id_bank_biaya_jenis = '$id'");
  return $a[$ok];
}

function bank_valuta()
{
  $i = [];
  $a = query("SELECT * FROM bank_valuta ORDER BY id_bank_valuta ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function bank_valuta_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM bank_valuta WHERE id_bank_valuta <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function bank_coa($id)
{
  $i = [];
  $a = query("SELECT * FROM bank_coa,
  coa,
  bank_coa_jenis
  WHERE
  bank_coa.id_rekening = '$id' AND
  coa.id_coa = bank_coa.id_coa AND
  bank_coa_jenis.id_bank_coa_jenis = bank_coa.id_bank_coa_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function bank_coa_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM bank_coa,
  bank_coa_jenis,
  coa
  WHERE 
  bank_coa.id_bank_coa = '$id' AND
  bank_coa_jenis.id_bank_coa_jenis = bank_coa.id_bank_coa_jenis AND
  coa.id_coa = bank_coa.id_coa");
  return $a[$ok];
}

function bank_biaya()
{
  $i = [];
  $a = query("SELECT * FROM bank_biaya,
  bank,
  coa,
  bank_biaya_jenis
  WHERE
  bank.id_bank = bank_biaya.id_bank AND
  coa.id_coa = bank_biaya.id_coa AND
  bank_biaya_jenis.id_bank_biaya_jenis = bank_biaya.id_bank_biaya_jenis AND
  bank_biaya.id_bank_biaya NOT IN(SELECT kode FROM recycle WHERE id_recycle_jenis = 9)
  ORDER BY bank_biaya.id_bank ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_online_kondisi()
{
  $i = [];
  $a = query("SELECT * FROM produk_online_kondisi");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_online_kondisi_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_online_kondisi WHERE id_produk_online_kondisi <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_online_kondisi_satu($id, $o)
{
  $a = query_satu("SELECT * FROM produk_online_kondisi WHERE
  id_produk_online_kondisi = '$id'");
  return $a[$o];
}

function produk_online()
{
  return query("SELECT * FROM produk_online");
}

function check_product_online($id)
{
  $a = query_satu("SELECT * FROM produk_online WHERE id_produk_online = '$id'");
  if ($a) {
    return true;
  } else {
    return false;
  }
}

function get_product_data($id)
{
  $a = query_satu("SELECT * FROM produk_online,
  produk,
  kategori
  WHERE
  produk.id_produk = produk_online.id_produk AND
  kategori.id_kategori = produk.id_kategori AND
  produk_online.id_produk_online = '$id'");
  return $a;
}

function produk_online_satuan_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM produk_online_satuan
  WHERE
  id_produk = '$id'
  ORDER BY buat ASC");
  return $a[$ok];
}

function get_product_online_satuan($id_satuan)
{
  if ($id_satuan == "") {
    return "-";
  } else {
    $a = query_satu("SELECT * FROM satuan WHERE id_satuan = '$id_satuan'");
    if ($a) {
      return $a['nama_satuan'];
    } else {
      return "-";
    }
  }
}

function produk_online_file_gambar_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM produk_online_file WHERE id_produk = '$id'");
  if ($a) {
    return $a[$ok];
  } else {
    return "";
  }
}

function produk_online_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM produk_online
  WHERE 
  id_produk = '$id'");
  return $a[$ok];
}

function produk_online_satuan($id)
{
  return query("SELECT * FROM produk_online_satuan
  WHERE
  id_produk = '$id'");
}

function produk_online_harga($id, $satuan)
{
  $satuan_terbesar = produk_isi_satuan_awal($id, "id_satuan");
  $harga_jual = @harga_produk_terbesar_satu(4, $id, "harga") + (@harga_produk_terbesar_satu(4, $id, "harga") * @produk_harga_jual(@harga_produk_terbesar_satu(4, $id, "id_harga_produk_terbesar"), "persen") / 100);
  $nilai = @produk_satuan_nilai($id, $satuan_terbesar, $satuan, "nilai");
  if ($satuan == $satuan_terbesar) {
    $hasil = @$harga_jual;
  } else {
    $hasil = @$harga_jual / @$nilai;
  }
  return $hasil;
}

function produk_stok_all($id, $satuan)
{
  $satuan_terkecil = produk_isi_satuan_akhir($id, "id_satuan");
  if ($satuan_terkecil == $satuan) {
    echo @produk_satu($id, "stok_produk");
  } else {
    if (@produk_satu($id, "stok_produk") / @produk_satuan_nilai($id, $satuan, $satuan_terkecil, "nilai") > 0) {
      $hasil = @produk_satu($id, "stok_produk") / @produk_satuan_nilai($id, $satuan, $satuan_terkecil, "nilai");
    } else {
      $hasil = 0;
    }
  }
  return @$hasil;
}

function produk_berat($id, $satuan)
{
  $satuan_terbesar = produk_isi_satuan_awal($id, "id_satuan");
  if ($satuan_terbesar == $satuan) {
    $hasil = @produk_satu($id, "gram_satuan_terbesar");
  } else {
    $hasil = @produk_satu($id, "gram_satuan_terbesar") / produk_satuan_nilai($id, $satuan_terbesar, $satuan, "nilai");
  }
  return $hasil;
}

function produk_online_file_gambar($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_online_file
  WHERE
  id_produk_online_tipe = 1 AND
  id_produk = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_online_file_gambar_kecuali($id, $nama)
{
  return query("SELECT * FROM produk_online_file
  WHERE
  id_produk_online_tipe = 1 AND
  id_produk = '$id' AND
  nama_file <> '$nama'");
}

function fsize($file)
{
  $a = array("B", "KB", "MB", "GB", "TB", "PB");
  $pos = 0;
  $size = filesize($file);
  while ($size >= 1024) {
    $size /= 1024;
    $pos++;
  }
  return round($size, 2) . " " . $a[$pos];
}

function produk_kategori_kecuali($id, $ok)
{
  $i = [];
  $a = query("SELECT * FROM produk
  WHERE
  id_kategori = '$id' AND
  id_produk <> '$ok'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_kategori($id)
{
  $i = [];
  $a = query("SELECT * FROM produk
  WHERE
  id_kategori = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_kategori_jum($id)
{
  return jumlah("SELECT * FROM produk WHERE id_kategori = '$id'");
}

function produk_kecuali($id)
{
  return query("SELECT * FROM produk WHERE id_produk != '$id'");
}

function coa_setting_autobalance($id)
{
  $a = query_satu("SELECT * FROM coa_setting,
    coa 
    WHERE 
    coa_setting.id_coa_setting = 1 AND
    coa.kode_coa = coa_setting.kode_coa");
  return $a[$id];
}

function produk_harga_standard()
{
  $i = [];
  $a = query("SELECT * FROM produk_harga,
    produk,
    harga_produk_header,
    produk_satuan,
    satuan,
    kategori,
    kategori_jenis,
    kategori_header
    WHERE
    produk_harga.id_produk_harga_header = 1 AND
    produk.id_produk = produk_harga.id_produk AND
    harga_produk_header.id_harga_produk_header = produk_harga.id_harga_produk_header AND
    produk_satuan.id_produk_satuan = harga_produk_header.id_produk_satuan AND
    satuan.id_satuan = produk_satuan.id_satuan AND
    kategori.id_kategori = produk.id_kategori AND
    kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis AND
    kategori_header.id_kategori_header = kategori.id_kategori_header");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_harga_standard_satu($id)
{
  return harga_produk_terbesar_satu(4, $id, "harga") + (harga_produk_terbesar_satu(4, $id, "harga") * produk_harga_jual(harga_produk_terbesar_satu(4, $id, "id_harga_produk_terbesar"), "persen") / 100);
}

function harga_produk_header($id, $ok, $cie, $yes)
{
  $a = query_satu("SELECT * FROM harga_produk_header
    WHERE
    id_produk = '$id' AND
    id_produk_satuan = '$ok' AND
    id_seller = '$cie'");
  return $a[$yes];
}

function produk_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM produk,
  kategori,
  merk,
  mata_uang,
  buatan,
  pabrik,
  warna,
  kategori_header
   WHERE
   produk.id_produk = '$id' AND
   kategori.id_kategori = produk.id_kategori AND
   merk.id_merk = produk.id_merk AND
   mata_uang.id_mata_uang = produk.id_mata_uang AND
   buatan.id_buatan = produk.id_buatan AND
   pabrik.id_pabrik = produk.id_pabrik AND
   warna.id_warna = produk.id_warna AND
   kategori_header.id_kategori_header = kategori.id_kategori_header");
  return @$a[$ok];
}

function produk_satu_nama($id, $i)
{
  $a = query_satu("SELECT * FROM produk WHERE
  nama_produk = '$id'");
  return $a[$i];
}

function cek_kategri_produk($id)
{
  return @produk_satu($id, "nama_kategori");
}

function get_id_jenis_kat($id)
{
  return @produk_satu($id, "id_kategori_jenis");
}

function cek_jenis_kat($id)
{
  return @query_satu("SELECT * FROM kategori_jenis WHERE id_kategori_jenis = '$id'")["nama_kategori_jenis"];
}

function produk_search_simple($isi)
{
  return query("SELECT * FROM produk WHERE
  sku LIKE '%$isi%' OR
  nama_produk LIKE '%$isi%'");
}

function produk_search($id)
{
  return query("SELECT * FROM produk,
  kategori,
  kategori_jenis,
  kategori_header
  WHERE
  kategori.id_kategori = produk.id_kategori AND
  kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis AND
  kategori_header.id_kategori_header = kategori.id_kategori_header AND
  kategori.nama_kategori LIKE '%$id%' 
  OR
  kategori.id_kategori = produk.id_kategori AND
  kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis AND
  kategori_header.id_kategori_header = kategori.id_kategori_header AND
  produk.nama_produk LIKE '%$id%'
  OR
  kategori.id_kategori = produk.id_kategori AND
  kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis AND
  kategori_header.id_kategori_header = kategori.id_kategori_header AND
  produk.sku LIKE '%$id%'
  OR
  kategori.id_kategori = produk.id_kategori AND
  kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis AND
  kategori_header.id_kategori_header = kategori.id_kategori_header AND
  kategori_jenis.nama_kategori_jenis LIKE '%$id%'
  OR
  kategori.id_kategori = produk.id_kategori AND
  kategori_jenis.id_kategori_jenis = kategori.id_kategori_jenis AND
  kategori_header.id_kategori_header = kategori.id_kategori_header AND
  kategori_header.nama_kategori_header LIKE '%$id%'");
}

function jurnal_setting()
{
  $i = [];
  $a = query("SELECT * FROM jurnal_setting");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_setting()
{
  $i = [];
  $a = query("SELECT * FROM coa_setting,
    coa
    WHERE
    coa.kode_coa = coa_setting.kode_coa");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function coa_setting_cari($id, $ok)
{
  $a = query_satu("SELECT * FROM coa_setting,
    coa
    WHERE
    coa_setting.id_coa_setting = '$id' AND
    coa.kode_coa = coa_setting.kode_coa");
  return $a[$ok];
}

function lembaga_penerbit_halal()
{
  $i = [];
  $a = query("SELECT * FROM lembaga_penerbit_halal,
    user
    WHERE
    user.id_user = lembaga_penerbit_halal.id_user
    ORDER BY lembaga_penerbit_halal.edit_lembaga DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function lembaga_penerbit_halal_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM lembaga_penerbit_halal
    WHERE
    id_lembaga_penerbit_halal = '$id'");
  return $a[$ok];
}

function satuan()
{
  $i = [];
  $a = query("SELECT * FROM satuan ORDER BY id_jenis_qty ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function jenis_qty($id, $ok)
{
  $a = query_satu("SELECT * FROM jenis_qty WHERE id_jenis_qty = '$id'");
  return $a[$ok];
}

function satuan_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM satuan
    WHERE
    id_satuan != '$id' ORDER BY id_jenis_qty ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_jenis_qty_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM satuan,
    jenis_qty
    WHERE
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty != '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_value()
{
  $i = [];
  $a = query("SELECT * FROM satuan_value
    ORDER BY satuan1 ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_value_kg($id, $ok)
{
  $a = query_satu("SELECT * FROM satuan_value WHERE satuan1 = '$id' AND
    satuan2 = 12");
  return $a[$ok];
}

function satuan_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM satuan,
  jenis_qty 
  WHERE 
  satuan.id_satuan = '$id' AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty");
  return @$a[$ok];
}

function satuan_besar()
{
  $i = [];
  $a = query("SELECT * FROM satuan
    WHERE
    id_jenis_qty = 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_besar_kecuali()
{
  $i = [];
  $a = query("SELECT * FROM satuan
    WHERE
    id_jenis_qty <> 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_sedang()
{
  $i = [];
  $a = query("SELECT * FROM satuan,
  jenis_qty
    WHERE
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 2");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_sedangkecil()
{
  $i = [];
  $a = query("SELECT * FROM satuan,
  jenis_qty
    WHERE
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 2 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 3 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 4 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 5
    ORDER BY satuan.id_jenis_qty ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_kecil()
{
  $i = [];
  $a = query("SELECT * FROM satuan,
  jenis_qty
    WHERE
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 3");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_kecil_hujan_lagi()
{
  $i = [];
  $a = query("SELECT * FROM satuan,
  jenis_qty
    WHERE
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 6");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_kecilpalingkecil()
{
  $i = [];
  $a = query("SELECT * FROM satuan,
  jenis_qty
    WHERE
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 3 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 4 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 5 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 6
    ORDER BY satuan.id_jenis_qty ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_palingkecil()
{
  $i = [];
  $a = query("SELECT * FROM satuan,
  jenis_qty
    WHERE
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 4 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 5 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 6 
    ORDER BY satuan.id_jenis_qty ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_palingkecilkecil()
{
  $i = [];
  $a = query("SELECT * FROM satuan,
  jenis_qty
    WHERE
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 5 or 
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 6
    ORDER BY satuan.id_jenis_qty ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function satuan_besarsedang()
{
  $i = [];
  $a = query("SELECT * FROM satuan,
  jenis_qty
    WHERE
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 1 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 2 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 3 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 4 or
    jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
    satuan.id_jenis_qty = 5
    ORDER BY satuan.id_jenis_qty ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function country()
{
  $i = [];
  $a = query("SELECT * FROM country");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function country_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM country WHERE id = '$id'");
  return $a[$ok];
}

function country_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM country WHERE id <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function pajak_satu($id, $i)
{
  $a = query_satu("SELECT * FROM pajak WHERE
  id_pajak = '$id'");
  return $a[$i];
}

function pajak_persen_satu($id, $i)
{
  $a = query_satu("SELECT * FROM pajak_persen WHERE
  id_pajak_persen = '$id'");
  return $a[$i];
}

function pajak_persen()
{
  $i = [];
  $a = query("SELECT * FROM pajak_persen,
    pajak
    WHERE
    pajak.id_pajak = pajak_persen.id_pajak");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function expedisi_ongkir_jenis($id)
{
  $i = [];
  $a = query("SELECT * FROM expedisi_ongkir_jenis
    WHERE
    id_expedisi = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function expedisi_ongkir_jenis_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM expedisi_ongkir_jenis WHERE id_expedisi_ongkir_jenis = '$id'");
  return @$a[$ok];
}

function expedisi_satu($id, $o)
{
  $a = query_satu("SELECT * FROM expedisi WHERE id_expedisi = '$id'");
  return @$a[$o];
}

function province()
{
  $i = [];
  $a = query("SELECT * FROM provinces");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function province_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM provinces WHERE id != '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function regencies()
{
  $i = [];
  $a = query("SELECT * FROM regencies");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function regencies_pilih($id)
{
  $i = [];
  $a = query("SELECT * FROM regencies WHERE province_id = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function regencies_kecuali($id, $o)
{
  $i = [];
  $a = query("SELECT * FROM regencies WHERE province_id = '$id' AND
  id != '$o'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function districts()
{
  $i = [];
  $a = query("SELECT * FROM districts");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function districts_pilih($id)
{
  $i = [];
  $a = query("SELECT * FROM districts WHERE regency_id = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function districts_kecuali($id, $o)
{
  $i = [];
  $a = query("SELECT * FROM districts WHERE regency_id = '$id' AND
  id != '$o'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function expedisi_hp($id)
{
  return query("SELECT * FROM expedisi_hp WHERE
  id_expedisi_hp= '$id'");
}

function expedisi_hp_satu($id, $o)
{
  $a = query_satu("SELECT * FROM expedisi_hp WHERE
  id_expedisi_contact = '$id'");
  return $a[$o];
}

function expedisi_alamat_prov($id, $ok)
{
  $i = [];
  $a = query("SELECT * FROM expedisi_alamat,
    expedisi_header
    WHERE 
    expedisi_alamat.id_provinsi = '$id' AND
    expedisi_alamat.id_expedisi = '$ok' AND
    expedisi_header.id_expedisi_header = expedisi_alamat.id_expedisi_header");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function expedisi_alamat_prov_jumlah($id, $ok)
{
  return jumlah("SELECT * FROM expedisi_alamat WHERE
    id_provinsi = '$id' AND
    id_expedisi = '$ok'");
}

function suplier_sertifikasi_halal($id)
{
  $i = [];
  $a = query("SELECT * FROM suplier_sertifikasi_halal,
    lembaga_penerbit_halal
    WHERE
    suplier_sertifikasi_halal.id_suplier = '$id' AND
    lembaga_penerbit_halal.id_lembaga_penerbit_halal = suplier_sertifikasi_halal.id_lembaga_penerbit_halal");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function suplier_sertifikasi_halal_jumlah($id)
{
  return jumlah("SELECT * FROM suplier_sertifikasi_halal WHERE id_suplier = '$id'");
}

function suplier_sertifikasi_halal_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM suplier_sertifikasi_halal,
    lembaga_penerbit_halal
    WHERE
    suplier_sertifikasi_halal.id_suplier = '$id' AND
    lembaga_penerbit_halal.id_lembaga_penerbit_halal = suplier_sertifikasi_halal.id_lembaga_penerbit_halal");
  return $a[$ok];
}

function surat_pemesanan($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_pemesanan,
    suplier,
    status
    WHERE
    surat_pemesanan.id_surat_pemesanan = '$id' AND
    suplier.id_suplier = surat_pemesanan.id_suplier AND
    status.id_status = surat_pemesanan.id_status OR
    surat_pemesanan.no_po = '$id' AND
    suplier.id_suplier = surat_pemesanan.id_suplier AND
    status.id_status = surat_pemesanan.id_status");
  return @$a[$ok];
}

function surat_pemesanan_status()
{
  foreach(surat_pemesanan_save() as $sps) :
  $a = jumlah("SELECT * FROM surat_pemesanan_detail
  WHERE
  id_surat_pemesanan = '$sps[id_surat_pemesanan]' AND
  sisa != 0");
  if ($a == 0) {
    return query("UPDATE surat_pemesanan SET
    id_status = 1
    WHERE
    id_surat_pemesanan = '$sps[id_surat_pemesanan]'");
  }
endforeach;
}

function surat_pemesanan_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_pemesanan,
  suplier,
  status
  WHERE
  surat_pemesanan.id_surat_pemesanan = '$id' AND
  suplier.id_suplier = surat_pemesanan.id_suplier AND
  status.id_status = surat_pemesanan.id_status");
  return $a[$ok];
}

function surat_pemesanan_po($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_pemesanan,
    suplier,
    status
    WHERE
    surat_pemesanan.no_po = '$id' AND
    suplier.id_suplier = surat_pemesanan.id_suplier AND
    status.id_status = surat_pemesanan.id_status");
  return @$a[$ok];
}

function surat_pemesanan_si($id, $ok)
{
  $a = query_satu("SELECT * FROM si_stok_detail, si_stok,
    customer, si,
    status
    WHERE
    si_stok_detail.id_si = '$id' AND si.id_si = '$id' AND
    customer.id_customer = si_stok.id_customer AND
    status.id_status = si.id_status");
  return @$a[$ok];
}

function surat_pemesanan_save()
{
  $i = [];
  $a = query("SELECT * FROM surat_pemesanan,
    suplier,
    status
    WHERE
    surat_pemesanan.id_status <> 0 AND
    suplier.id_suplier = surat_pemesanan.id_suplier AND
    status.id_status = surat_pemesanan.id_status
    ORDER BY surat_pemesanan.tgl_po DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function surat_pemesanan_today()
{
  $date = date("Y-m-d");
  return query("SELECT * FROM surat_pemesanan WHERE
  tgl_po = '$date' AND
  id_status != 0");
}

function surat_pemesanan_kredit($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_pemesanan_kredit
    WHERE
    id_surat_pemesanan = '$id'");
  return $a[$ok];
}

function surat_pemesanan_pajak($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_pemesanan_pajak
    WHERE
    id_surat_pemesanan = '$id'");
  return $a[$ok];
}

function surat_pemesanan_pajak_jumlah($id)
{
  return jumlah("SELECT * FROM surat_pemesanan_pajak WHERE id_surat_pemesanan = '$id'");
}

function surat_pemesanan_diskon($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_pemesanan_diskon
    WHERE
    id_surat_pemesanan = '$id'");
  return $a[$ok];
}

function surat_pemesanan_detail($id)
{
  $i = [];
  $a = query("SELECT * FROM surat_pemesanan_detail,
    produk,
    satuan
    WHERE
    surat_pemesanan_detail.id_surat_pemesanan = '$id' AND
    produk.id_produk = surat_pemesanan_detail.id_produk AND
    satuan.id_satuan = surat_pemesanan_detail.id_satuan");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function surat_pemesanan_detail_si($id)
{
  $i = [];
  $a = query("SELECT * FROM si_stok_detail,
    produk,
    satuan
    WHERE
    si_stok_detail.id_si = '$id' AND
    produk.id_produk = si_stok_detail.id_produk AND
    satuan.id_satuan = si_stok_detail.id_satuan");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function surat_pemesanan_detail_sisa()
{
  $i = [];
  $a = query("SELECT distinct id_surat_pemesanan FROM surat_pemesanan_detail
    WHERE
    sisa <> 0
  ");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function surat_pemesanan_detail_harga_satuan($id, $o, $y, $h)
{
  $a = query_satu("SELECT * FROM surat_pemesanan_detail
  WHERE
  id_surat_pemesanan = '$id' AND
  id_produk = '$o' AND
  id_satuan = '$y'");
  return $a[$h];
}

function surat_pemesanan_detail_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_pemesanan_detail
    WHERE
    id_surat_pemesanan_detail = '$id'");
  return $a[$ok];
}

function surat_pemesanan_detail_satu_dua($id_surat_pemesanan,$id_produk, $isi)
{
  $a = query_satu("SELECT * FROM surat_pemesanan_detail
    WHERE
    id_surat_pemesanan = '$id_surat_pemesanan' AND
    id_produk = '$id_produk'");
  return $a[$isi];
}

function surat_pemesanan_detail_jum($id)
{
  return jumlah("SELECT * FROM surat_pemesanan_detail WHERE id_surat_pemesanan = '$id'");
}

function surat_pemesanan_detail_jum_produk($id, $y)
{
  return jumlah("SELECT * FROM surat_pemesanan_detail WHERE id_surat_pemesanan = '$id' AND
  id_produk = '$y'");
}

function surat_pemesanan_detail_diskon($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_pemesanan_detail_diskon WHERE id_surat_pemesanan_detail = '$id'");
  return $a[$ok];
}

function cek_ongkir($id, $ok)
{
  $i = [];
  $a = query("SELECT * FROM ongkir,
    expedisi_ongkir_jenis,
    expedisi
    WHERE
    ongkir.kabupaten_pengirim = '$id' AND
    ongkir.kecamatan_tujuan = '$ok' AND
    expedisi_ongkir_jenis.id_expedisi_ongkir_jenis = ongkir.id_expedisi_ongkir_jenis AND
    expedisi.id_expedisi = expedisi_ongkir_jenis.id_expedisi");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function cek_ongkir_jumlah($id, $ok)
{
  return jumlah("SELECT * FROM ongkir
    WHERE
    kabupaten_pengirim = '$id' AND
    kecamatan_tujuan = '$ok'");
}

function company_nsw($a)
{
  $b = query_satu("SELECT * FROM company WHERE id_company = 1");
  return $b[$a];
}

function surat_pemesanan_expedisi($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_pemesanan_expedisi,
    ongkir,
    expedisi_ongkir_jenis,
    expedisi
    WHERE
    surat_pemesanan_expedisi.id_surat_pemesanan = '$id' AND
    ongkir.id_ongkir = surat_pemesanan_expedisi.id_ongkir AND
    expedisi_ongkir_jenis.id_expedisi_ongkir_jenis = ongkir.id_expedisi_ongkir_jenis AND
    expedisi.id_expedisi = expedisi_ongkir_jenis.id_expedisi");
  return @$a[$ok];
}

function surat_pemesanan_expedisi_jum($id)
{
  return jumlah("SELECT * FROM surat_pemesanan_expedisi WHERE id_surat_pemesanan = '$id'");
}

function status_riwayat_terakhir($id, $ok, $yes)
{
  $a = query_satu("SELECT * FROM status_riwayat WHERE
    kode = '$id' AND
    id_report = '$ok'
    ORDER BY tgl DESC");
  return @$a[$yes];
}

function status_riwayat_lalu($id, $ok, $ho)
{

  $i = [];
  $a = query("SELECT * FROM status_riwayat WHERE
    kode = '$id' AND
    id_report = '$ok' AND
    tgl <> '$ho'
    ORDER BY tgl ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function status_riwayat_jum($id, $ok)
{
  return jumlah("SELECT * FROM status_riwayat WHERE kode = '$id' AND id_report = '$ok'");
}

function surat_pemesanan_brutto($id)
{
  foreach (surat_pemesanan_detail($id) as $spd) :
    if ($spd["diskon"] == 1) {
      if (surat_pemesanan_detail_diskon($spd["id_surat_pemesanan_detail"], "tipe_diskon") == 1) {
        $diskon_produk = surat_pemesanan_detail_diskon($spd["id_surat_pemesanan_detail"], "value");
      } elseif (surat_pemesanan_detail_diskon($spd["id_surat_pemesanan_detail"], "tipe_diskon") == 2) {
        $diskon_produk = ($spd["qty"] * $spd["harga_satuan"]) * surat_pemesanan_detail_diskon($spd["id_surat_pemesanan_detail"], "value") / 100;
      }
    } else {
      $diskon_produk = 0;
    }

    // $kg = $spd["weight_kg"]*$spd["qty"];

    @$brutto = @$brutto + (($spd["harga_satuan"] * $spd["qty"]));
  // @$brutto = @$brutto + (($spd["harga_satuan"] * $spd["qty"]) - $diskon_produk);
  //@$total_kg = @$total_kg + $kg;

  //   if ($spd["id_satuan"] == 12) {
  //     $weight = $spd["qty"];
  //   }else {
  //     $weight = satuan_value_kg($spd["id_satuan"],"value")*$spd["qty"];
  //   }

  //   $brutto = $weight*$spd["harga_satuan"]-@$diskon_produk;
  //   @$tot_brutto = @$tot_brutto + $brutto;
  endforeach;
  return $brutto;
}

function surat_pemesanan_diskon_nilai($id)
{
  if (surat_pemesanan($id, "diskon") == 1) {
    if (surat_pemesanan_diskon($id, "tipe_diskon") == 1) {
      $diskon = surat_pemesanan_diskon($id, "value_diskon");
    } elseif (surat_pemesanan_diskon($id, "tipe_diskon") == 2) {
      $diskon = surat_pemesanan_brutto($id) * (surat_pemesanan_diskon($id, "value_diskon") / 100);
    }
  } else {
    $diskon = 0;
  }


  return $diskon;
}

function surat_pemesanan_dpp($id)
{
  //error_reporting(0);
  // foreach (surat_pemesanan_detail($id) as $spd) :
  //   if ($spd["diskon"] == 1) {
  //     if (surat_pemesanan_detail_diskon($spd["id_surat_pemesanan_detail"], "tipe_diskon") == 1) {
  //       $diskon_produk = surat_pemesanan_detail_diskon($spd["id_surat_pemesanan_detail"], "value");
  //     } elseif (surat_pemesanan_detail_diskon($spd["id_surat_pemesanan_detail"], "tipe_diskon") == 2) {
  //       $diskon_produk = ($spd["qty"] * $spd["harga_satuan"]) * surat_pemesanan_detail_diskon($spd["id_surat_pemesanan_detail"], "value") / 100;
  //     }
  //   }else{
  //     $diskon_produk = 0;
  //   }
  //   $brutto = ($spd["qty"] * $spd["harga_satuan"]) - $diskon_produk;
  //   $total_brutto = $brutto;
  //   $total_brutto += $total_brutto;
  // endforeach;

  // if (surat_pemesanan($id, "diskon") == 1) {
  //   if (surat_pemesanan_diskon($id, "tipe_diskon") == 1) {
  //     $diskon = surat_pemesanan_diskon($id, "value_diskon");
  //   } elseif (surat_pemesanan_diskon($id, "tipe_diskon") == 2) {
  //     $diskon = surat_pemesanan_brutto($id) * surat_pemesanan_diskon($id, "value_diskon") / 100;
  //   }
  // } else {
  //   $diskon = 0;
  // }

  $dpp = surat_pemesanan_brutto($id) - surat_pemesanan_diskon_nilai($id);

  return $dpp;
}

function surat_pemesanan_tax($id)
{
  $dpp = surat_pemesanan_dpp($id);
  if (surat_pemesanan($id, "pajak") == 1) {
    $pajak = $dpp * surat_pemesanan_pajak($id, "persen") / 100;
  } elseif (surat_pemesanan($id, "pajak") == 0) {
    $pajak = 0;
  }
  return $pajak;
}

function surat_pemesanan_ongkir($id)
{
  error_reporting(0);
  //   foreach (surat_pemesanan_detail($id) as $spd) :
  //     $kg = $spd["weight_kg"] * $spd["qty"];
  //     $berat += $kg;
  //     //$berat += $berat;
  //   endforeach;
  // //  $ongkir = surat_pemesanan_expedisi($id, "kg") * $berat;
  //   return $ongkir;

  foreach (surat_pemesanan_detail($id) as $ss) :
    @$tt += $ss["weight_kg"] * $ss["qty"];
  endforeach;
  $tt = surat_pemesanan_expedisi($id, "kg") * $tt;
  return $tt;
}

function surat_pemesanan_weight_kg($id)
{
  foreach (surat_pemesanan_detail($id) as $spd) :
    @$tt += $spd["weight_kg"] * $spd["qty"];
  endforeach;
  return $tt;
}

function surat_pemesanan_tgl_berakhir_po($id)
{
  $b = mktime(0, 0, 0, date("n", strtotime(surat_pemesanan($id, "tgl_po"))), date("j", strtotime(surat_pemesanan($id, "tgl_po"))) + surat_pemesanan($id, "masa_berlaku"), date("Y", strtotime(surat_pemesanan($id, "tgl_po"))));
  $masa_berakhir_po = date("Y-m-d", $b);
  return query("UPDATE surat_pemesanan SET
  tgl_berakhir_po = '$masa_berakhir_po'
  WHERE
  id_surat_pemesanan = '$id'");
}

// function surat_pemesanan_ongkir_master($id)
// {
//    error_reporting(0);
//   foreach (surat_pemesanan_detail($id) as $spd) :
//     $kg = $spd["weight_kg"] * $spd["qty"];
//     $berat += $kg;
//     //$berat += $berat;
//   endforeach;
// //  $ongkir = surat_pemesanan_expedisi($id, "kg") * $berat;
//   return $ongkir;

// // foreach(surat_pemesanan_detail($id) as $ss) :
// //   @$tt += $ss["weight_kg"]*$ss["qty"];
// // endforeach;
// //   $tt = surat_pemesanan_expedisi($id,"kg")*$tt;
// //   return $tt;

// }

function surat_pemesanan_ongkir_diskon($id)
{
  if (surat_pemesanan_diskon_ongkir_jum($id) > 0) {
    $x = surat_pemesanan_diskon_ongkir_satu($id, "nilai_diskon_ongkir");
  } else {
    $x = 0;
  }
  return $x;
}

function surat_pemesanan_ongkir_bersih($id)
{
  $tot = surat_pemesanan_ongkir($id) - surat_pemesanan_ongkir_diskon($id);
  return $tot;
}

function surat_pemesanan_netto($id)
{
  error_reporting(0);
  $dpp = surat_pemesanan_dpp($id);
  $pajak = surat_pemesanan_tax($id);
  $ongkos_angkut = surat_pemesanan($id, "ongkos_angkut");

  // foreach (surat_pemesanan_detail($id) as $spd) :
  //   if ($spd["id_satuan"] == 12) {
  //     $kg = $spd["qty"];
  //   } else {
  //     $kg = satuan_value_kg($spd["id_satuan"], "value") * $spd["qty"];
  //   }
  //   $berat += $kg;
  //   //$berat += $berat;
  // endforeach;
  // $ongkir = surat_pemesanan_expedisi($id, "kg") * $berat;

  $ongkir = surat_pemesanan_ongkir_bersih($id);

  $netto = $dpp + $pajak;
  // $netto = $dpp + $pajak + $ongkos_angkut + $ongkir;
  return $netto;
}

function total_faktur_ql($id)
{
  error_reporting(0);
  $dpp = surat_pemesanan_dpp($id);
  $pajak = surat_pemesanan_tax($id);
  $ongkos_angkut = surat_pemesanan($id, "ongkos_angkut");

  $total_faktur = $dpp + $pajak + $ongkos_angkut;

  return $total_faktur;
}

function surat_pemesanan_gr()
{
  $i = [];
  $a = query("SELECT * FROM surat_pemesanan,
  suplier
  WHERE
  surat_pemesanan.id_status = 3 AND
  suplier.id_suplier = surat_pemesanan.id_suplier");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function status_riwayat($id, $ok)
{
  $i = [];
  $a = query("SELECT * FROM status_riwayat 
    WHERE
    kode = '$id' AND
    id_report = '$ok' ORDER BY tgl DESC LIMIT 3");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function status_riwayatmodal($id, $ok)
{
  $i = [];
  $a = query("SELECT * FROM status_riwayat 
    WHERE
    kode = '$id' AND
    id_report = '$ok'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}



function status_riwayat_all($id, $ok)
{
  return query("SELECT * FROM status_riwayat WHERE
  kode = '$id' AND
  id_report = '$ok'");
}

function menu()
{
  $i = [];
  $a = query("SELECT * FROM menu");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function menu_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM menu WHERE id_menu = '$id'");
  return $a[$ok];
}

function menu_halaman($id)
{
  $i = [];
  $a = query("SELECT * FROM menu_halaman WHERE id_menu = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function menu_option()
{
  $i = [];
  $a = query("SELECT * FROM menu_option ORDER BY id_menu_option ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function level_user()
{
  $i = [];
  $a = query("SELECT * FROM level_user,
    user_jenis
    WHERE
    user_jenis.id_user_jenis = level_user.id_user_jenis
    ORDER BY level_user.edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function level_user_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM level_user,
    user_jenis
    WHERE
    user_jenis.id_user_jenis = level_user.id_user_jenis AND
    level_user.id_level_user <> '$id'
    ORDER BY level_user.edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function level_user_jum()
{
  return jumlah("SELECT * FROM level_user");
}


function level_user_per_user($id)
{
  return jumlah("SELECT * FROM user WHERE id_level_user = '$id'");
}

function level_user_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM level_user,
    user_jenis 
    WHERE 
    level_user.id_level_user = '$id' AND
    user_jenis.id_user_jenis = level_user.id_user_jenis");
  return $a[$ok];
}

function user_jenis()
{
  $i = [];
  $a = query("SELECT * FROM user_jenis,
    user
    WHERE
    user.id_user = user_jenis.id_user 
    ORDER BY user_jenis.edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function user_jenis_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM user_jenis,
    user
    WHERE
    user.id_user = user_jenis.id_user AND
    user_jenis.id_user_jenis <> '$id'
    ORDER BY user_jenis.edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function menu_halaman_option_jumsatu($id, $ok, $tes)
{
  return jumlah("SELECT * FROM menu_halaman_option WHERE
    id_menu_halaman = '$id' AND
    id_menu_option = '$ok' AND
    id_level_user = '$tes'");
}

function menu_halaman_option_level_user($id, $ok)
{
  return jumlah("SELECT * FROM menu_halaman_option,
    menu_halaman,
    menu
    WHERE
    menu_halaman_option.id_level_user = '$id' AND
    menu_halaman.id_menu_halaman = menu_halaman_option.id_menu_halaman AND
    menu.id_menu = menu_halaman.id_menu AND
    menu.id_menu = '$ok'");
}

function user_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM user,
  status_user 
  WHERE 
  user.id_user = '$id' AND
  status_user.id_status_user = user.id_status_user");
  return @$a[$ok];
}

function report()
{
  $i = [];
  $a = query("SELECT * FROM report,
  report_setting_jenis
  WHERE
  report_setting_jenis.id_report_setting_jenis = report.id_report_setting_jenis");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function report_setting($id)
{
  $i = [];
  $a = query("SELECT * FROM report_setting,
  report_setting_ttd_jenis,
  level_user
  WHERE
  id_report = '$id' AND
  report_setting_ttd_jenis.id_report_setting_ttd_jenis = report_setting.id_report_setting_ttd_jenis AND
  level_user.id_level_user = report_setting.id_level_user
  ORDER BY report_setting.urutan ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function report_setting_urutan_satu($id, $o, $y)
{
  $a = query_satu("SELECT * FROM report_setting WHERE
  id_report = '$id' AND
  urutan = '$o'");
  return $a[$y];
}

function report_setting_status_satu($id, $o, $y)
{
  $a = query_satu("SELECT * FROM report_setting WHERE
  id_report = '$id' AND
  id_status = '$o'
  ORDER BY urutan ASC");
  return $a[$y];
}

function report_setting_kecuali_satu($id, $o, $x, $y)
{
  $a = query_satu("SELECT * FROM report_setting WHERE
  id_report = '$id' AND
  id_status != '$o' AND
  urutan > '$x'
  ORDER BY urutan ASC");
  return $a[$y];
}

function report_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM report,
  report_setting_jenis 
  WHERE 
  report.id_report = '$id' AND
  report_setting_jenis.id_report_setting_jenis = report.id_report_setting_jenis");
  return $a[$ok];
}

function report_setting_ttd_jenis()
{
  $i = [];
  $a = query("SELECT * FROM report_setting_ttd_jenis ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function report_setting_jum($id)
{
  return jumlah("SELECT * FROM report_setting WHERE id_report = '$id'");
}

function report_gudang($id)
{
  $a = query_satu("SELECT id_gudang FROM report_gudang WHERE id_report = '$id'");
  return $a["id_gudang"];
}

function report_gudang_satu($id, $o)
{
  $a = query_satu("SELECT * FROM report_gudang WHERE id_report = '$id'");
  return $a[$o];
}

function report_gudang_rh_satu($id, $y, $o)
{
  $a = query_satu("SELECT * FROM report_gudang WHERE id_report = '$id' AND
  id_riwayat_header = '$y'");
  return $a[$o];
}

function report_gudang_jum($id)
{
  return jumlah("SELECT id_gudang FROM report_gudang WHERE id_report = '$id'");
}

function report_rek_jum($id_report)
{
  return jumlah("SELECT * FROM report_rek WHERE id_report = '$id_report'");
}

function report_rek_satu($id_report,$o)
{
  $a = query_satu("SELECT * FROM report_rek WHERE id_report = '$id_report'");
  return $a[$o];
}

function user_akses_jumlah($id, $ok, $yes)
{
  return jumlah("SELECT * FROM user_akses WHERE
  id_user = '$id' AND
  id_menu_halaman = '$ok' AND
  id_menu_option = '$yes'");
}

function user_akses_satu($id, $ok, $haha, $yes)
{
  $a = query_satu("SELECT * FROM user_akses WHERE
  id_user = '$id' AND
  id_menu_halaman = '$ok' AND
  id_menu_option = '$haha' AND
  id_user <> 1");
  return $a[$yes];
}

function user_akses_cek($id, $ok)
{
  return jumlah("SELECT * FROM user_akses,
  menu_halaman,
  menu
  WHERE
  user_akses.id_user = '$id' AND
  menu_halaman.id_menu_halaman = user_akses.id_menu_halaman AND
  menu.id_menu = menu_halaman.id_menu AND
  menu.id_menu = '$ok'");
}

function user_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM user,
  status_user
  WHERE
  user.id_user <> '$id' AND
  status_user.id_status_user = user.id_status_user AND
  user.id_user <> 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function status_user_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM status_user WHERE id_status_user <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function user_jum()
{
  return jumlah("SELECT * FROM user WHERE id_user <> 1");
}

function surat_pemesanan_diskon_ongkir_jum($id)
{
  return jumlah("SELECT * FROM surat_pemesanan_diskon_ongkir WHERE id_surat_pemesanan = '$id'");
}

function surat_pemesanan_diskon_ongkir_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_pemesanan_diskon_ongkir WHERE id_surat_pemesanan = '$id'");
  return $a[$ok];
}

function user_ttd_jum($id)
{
  return jumlah("SELECT * FROM user_ttd WHERE id_user = '$id'");
}

function user_ttd_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM user_ttd WHERE id_user = '$id'");
  return $a[$ok];
}

function gr_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM gr,
  suplier 
  WHERE 
  gr.id_gr = '$id' AND
  suplier.id_suplier = gr.id_suplier or
  gr.no_gr = '$id' AND
  suplier.id_suplier = gr.id_suplier");
  return $a[$ok];
}

function gr_no($no_gr,$isi)
{
  $a = query_satu("SELECT * FROM gr WHERE
  no_gr = '$no_gr'");
  return $a[$isi];
}

function gr_alone($id, $ok)
{
  $a = query_satu("SELECT * FROM gr WHERE id_gr = '$id'");
  return $a[$ok];
}

function gr_pesanan($id)
{
  $i = [];
  $a = query("SELECT * FROM gr_pesanan,
  produk,
  gr,
  satuan
  WHERE
  gr_pesanan.id_gr = '$id' AND
  produk.id_produk = gr_pesanan.id_produk AND
  gr.id_gr = gr_pesanan.id_gr AND
  gr_pesanan.id_satuan = satuan.id_satuan");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function gr_pesanan_satu($id, $ok, $ye, $ya)
{
  $a = query_satu("SELECT * FROM gr_pesanan WHERE
  id_gr = '$id' AND
  id_produk = '$ok' AND
  id_satuan = '$ye'");
  return $a[$ya];
}

function gr_pesanan_jumlah($id, $ok, $ye)
{
  return jumlah("SELECT * FROM gr_pesanan WHERE
  id_gr = '$id' AND
  id_produk = '$ok' AND
  id_satuan = '$ye'");
}

function gr_pesanan_qty_diterima($id)
{
  foreach (gr_pesanan($id) as $gp) {
    $qty = $gp["qty_diterima"];
    @$tot += $qty;
  }
  return $tot;
}

function gr_pesanan_qty_rusak($id)
{
  foreach (gr_pesanan($id) as $gp) {
    $qty = $gp["qty_kondisi_rusak"];
    @$tot += $qty;
  }
  return $tot;
}

function gr_pesanan_qty_baik($id)
{
  foreach (gr_pesanan($id) as $gp) {
    $qty = $gp["qty_kondisi_baik"];
    @$tot += $qty;
  }
  return $tot;
}

function gr_pesanan_qty_awal($id)
{
  foreach (gr_pesanan($id) as $gp) {
    $qty = $gp["qty_awal"];
    @$tot += $qty;
  }
  return $tot;
}

function gr_pesanan_total($id, $ok)
{
  error_reporting(0);
  foreach (gr_pesanan($id) as $gp) {
    $id_produk = $gp["id_produk"];
    $id_satuan = $gp["id_satuan"];
    $qty_diterima = $gp["qty_diterima"];
    $a = query("SELECT * FROM surat_pemesanan_detail
    WHERE
    id_surat_pemesanan = '$ok' AND
    id_produk = '$id_produk' AND
    id_satuan = '$id_satuan'");
    while ($l_a = query_banyak($a)) {
      $harga_satuan = $l_a["harga_satuan"];
      $total = $harga_satuan * $qty_diterima;
      @$tot += @$tot + $total;
    }
  }
  return @$tot;
}

function gr()
{
  $i = [];
  $a = query("SELECT * FROM gr,
  suplier,
  status
  WHERE
  suplier.id_suplier = gr.id_suplier AND
  status.id_status = gr.id_status AND
  gr.no_gr <> ''");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function gr_header_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM gr_header WHERE id_gr = '$id' AND
  id_status = 0");
  return $a[$ok];
}

function gr_pesanan_ex($id, $yes, $j)
{
  $a = query_satu("SELECT * FROM gr_pesanan_ex,
  expired
  WHERE
  expired.id_expired = gr_pesanan_ex.id_expired AND
  gr_pesanan_ex.id_gr_pesanan = '$id' AND
  gr_pesanan_ex.id_expired = '$yes'");
  return @$a[$j];
}

function gr_pesanan_ex_jum($id, $yes)
{
  return jumlah("SELECT * FROM gr_pesanan_ex,
  expired
  WHERE
  expired.id_expired = gr_pesanan_ex.id_expired AND
  gr_pesanan_ex.id_gr_pesanan = '$id' AND
  gr_pesanan_ex.id_expired = '$yes'");
}

function gr_pesanan_total_qty_minus($id)
{
  foreach (gr_pesanan($id) as $gp) {
    $qty_minus = $gp["qty_minus"];
    @$tot += $qty_minus;
  }
  return @$tot;
}

function gr_produk_sisa($id, $ok, $ye)
{
  $a = query_satu("SELECT * FROM gr_produk_sisa WHERE
  id_gr = '$id' AND
  id_produk = '$ok'");
  return $a[$ye];
}

function status_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM status WHERE id_status = '$id'");
  return $a[$ok];
}

function status()
{
  return query("SELECT * FROM status");
}

function status_kecuali($id)
{
  return query("SELECT * FROM status WHERE id_status != '$id'");
}

function report_coa($id, $ok)
{
  $a = query_satu("SELECT * FROM report_coa,
  coa,
  suplier_jenis
  WHERE
  coa.id_coa = report_coa.id_coa AND
  report_coa.id_report = '$id' AND
  suplier_jenis.id_suplier_jenis = report_coa.id_suplier_jenis");
  return $a[$ok];
}

function report_coa_all($id_report)
{
  return query("SELECT * FROM report_coa WHERE
  id_report = '$id_report'");
}

function report_coa_dua($id, $ok, $y)
{
  $a = query_satu("SELECT * FROM report_coa,
  coa,
  suplier_jenis
  WHERE
  coa.id_coa = report_coa.id_coa AND
  report_coa.id_report = '$id' AND
  suplier_jenis.id_suplier_jenis = report_coa.id_suplier_jenis AND
  report_coa.id_suplier_jenis = '$ok'");
  return $a[$y];
}

function report_coa_satu($id, $ok, $y)
{
  $a = query_satu("SELECT * FROM report_coa,
  coa 
  WHERE
  report_coa.id_report = '$id' AND
  report_coa.id_suplier_jenis = '$ok' AND
  coa.id_coa = report_coa.id_coa");
  return $a[$y];
}

function report_coa_lihat($id)
{
  $i = [];
  $a = query("SELECT * FROM report_coa,
  suplier_jenis,
  coa
  WHERE
  report_coa.id_report = '$id' AND
  suplier_jenis.id_suplier_jenis = report_coa.id_suplier_jenis AND
  coa.id_coa = report_coa.id_coa");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function report_coa_lihat_satu($id_report, $id_akuntan_jenis, $id_suplier_jenis, $isi)
{
  $a = query_satu("SELECT * FROM report_coa WHERE
  id_report = '$id_report' AND
  id_akuntan_jenis = '$id_akuntan_jenis' AND
  id_suplier_jenis = '$id_suplier_jenis'");
  return $a[$isi];
}

function kode_bulan($id, $yes, $ya, $yo)
{
  $a = query_satu("SELECT * FROM kode_bulan
  WHERE
  bulan = '$id' AND
  tahun = '$yes' AND
  id_report = '$ya'");
  return $a[$yo];
}

function kode_bulan_jum($id, $ya, $yo)
{
  return jumlah("SELECT * FROM kode_bulan
  WHERE
  bulan = '$id' AND
  tahun = '$ya' AND
  id_report = '$yo'");
}

function get_total_accounts()
{
  return jumlah("SELECT * FROM user");
}

function get_total_products()
{
  return jumlah("SELECT * FROM produk");
}

function get_total_customers()
{
  return jumlah("SELECT * FROM customer");
}

function get_total_branch()
{
  return jumlah("SELECT * FROM cabang");
}

function get_total_sales()
{
  return jumlah("SELECT * FROM sales");
}

function get_total_category()
{
  return jumlah("SELECT * FROM kategori");
}

function get_total_promo_active()
{
  $total = 0;
  foreach (diskon() as $d) {
    if ($d["status_diskon"] == 1) {
      if (expired2($d["kadaluarsa"], $d["tgl_kadaluarsa"]) == true) {
        $total++;
      }
    }
  }
  return $total;
}

function get_total_active_purchase_order()
{
  $total = 0;
  foreach (surat_pemesanan_save() as $d) {
    $encrypted = enc($d["id_surat_pemesanan"]);
    if ($encrypted) {
      $id = mysqli_real_escape_string(konek(), dec($encrypted));
      if ($id) {
        if (surat_pemesanan($id, "masa_berlaku") > 0) {
          $total++;
        }
      }
    }
  }
  return $total;
}

function invoice_pi()
{
  $i = [];
  $a = query("SELECT * FROM invoice WHERE id_report = 10");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function invoice_pi_brutto($id_gr, $id_surat_pemesanan)
{
  foreach (gr_pesanan($id_gr) as $ip) {
    $har_sat = surat_pemesanan_detail_harga_satuan($id_surat_pemesanan, $ip["id_produk"], $ip["id_satuan"], "harga_satuan");

    if (surat_pemesanan_detail_harga_satuan($id_surat_pemesanan, $ip["id_produk"], $ip["id_satuan"], "diskon") == 1) {
      if (surat_pemesanan_detail_diskon(surat_pemesanan_detail_harga_satuan($id_surat_pemesanan, $ip["id_produk"], $ip["id_satuan"], "id_surat_pemesanan_detail"), "tipe_diskon") == 1) {
        $diskon_produk = surat_pemesanan_detail_diskon(surat_pemesanan_detail_harga_satuan($id_surat_pemesanan, $ip["id_produk"], $ip["id_satuan"], "id_surat_pemesanan_detail"), "value");
      } else {
        $diskon_produk = surat_pemesanan_detail_diskon(surat_pemesanan_detail_harga_satuan($id_surat_pemesanan, $ip["id_produk"], $ip["id_satuan"], "id_surat_pemesanan_detail"), "value") * ($ip["qty_diterima"] * $har_sat) / 100;
      }
    } else {
      $diskon_produk = 0;
    }
    // $brutto = $ip["qty_diterima"] * $har_sat - $diskon_produk;
    $brutto = $ip["qty_diterima"] * $har_sat - $diskon_produk;
    @$tot = @$tot + $brutto;
  }
  return @$tot;
}



function invoice_pi_diskon($id_surat_pemesanan, $id_gr)
{
  if (surat_pemesanan($id_surat_pemesanan, "diskon") == 1) {
    if (surat_pemesanan_diskon($id_surat_pemesanan, "tipe_diskon") == 1) {
      $diskon_akhir = surat_pemesanan_diskon($id_surat_pemesanan, "value_diskon");
    } elseif (surat_pemesanan_diskon($id_surat_pemesanan, "tipe_diskon") == 2) {
      $diskon_akhir = invoice_pi_brutto($id_gr, $id_surat_pemesanan) * surat_pemesanan_diskon($id_surat_pemesanan, "value_diskon") / 100;
    }
  } elseif (surat_pemesanan($id_surat_pemesanan, "diskon") == 0) {
    echo $diskon_akhir = null;
  }
  return $diskon_akhir;
}

function invoice_pi_dpp($id_gr, $id_surat_pemesanan)
{
  return invoice_pi_brutto($id_gr, $id_surat_pemesanan) - invoice_pi_diskon($id_surat_pemesanan, $id_gr);
}

function invoice_pi_tax($id_surat_pemesanan, $id_gr)
{
  if (surat_pemesanan($id_surat_pemesanan, "pajak") == 1) {
    $pajak = (invoice_pi_dpp($id_gr, $id_surat_pemesanan)) * surat_pemesanan_pajak($id_surat_pemesanan, "persen") / 100;
  } else {
    $pajak = 0;
  }
  return $pajak;
}

function invoice_pi_ongkir($id)
{
  // foreach (surat_pemesanan_detail($id) as $ss) :
  //   @$tt += $ss["weight_kg"] * $ss["qty"];
  // endforeach;
  // $tt = surat_pemesanan_expedisi($id, "kg") * $tt;
  // return $tt;
}

function invoice_po($id)
{
  if (invoice_header($id, "id_report") == 1) {
    $no_po = invoice_header($id, "kode");
  } elseif (invoice_header($id, "id_report") == 9) {
    $no_po = gr_satu(invoice_header($id, "kode"), "no_po");
  }
  return $no_po;
}

function invoice_header($id, $ok)
{
  $a = query_satu("SELECT * FROM invoice_header WHERE
  no_invoice = '$id'");
  return @$a[$ok];
}

function invoice_satu($id, $o)
{
  $a = query_satu("SELECT * FROM invoice WHERE no_invoice = '$id'");
  return $a[$o];
}

function invoice($id_report)
{
  return query("SELECT * FROM invoice WHERE id_report = '$id_report'");
}

function invoice_jumlah($no_invoice)
{
  return jumlah("SELECT * FROM invoice WHERE no_invoice = '$no_invoice'");
}

function stok_produk_satu($id, $ok, $y)
{
  $a = query_satu("SELECT * FROM stok_produk
  WHERE
  id_produk = '$id' AND
  id_satuan = '$ok'");
  return $a[$y];
}

function stok_produk_ulang_satu()
{
  $i = [];
  $a = query("SELECT distinct id_produk, id_satuan FROM stok_produk ORDER BY id_produk ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function stok_produk_total($id, $ok)
{
  $a = query_satu("SELECT SUM(value_stok) AS total_value FROM stok_produk
  WHERE
  id_produk = '$id' AND
  id_satuan = '$ok'");
  return $a["total_value"];
}

function stok_produk_control_satu($a, $b, $c)
{
  $d = query_satu("SELECT * FROM stok_produk_control WHERE
  id_produk = '$a' AND
  bsk = '$b'");
  return $d[$c];
}

function produk_satuan_nilai_jum($id)
{
  return jumlah("SELECT * FROM produk_satuan_nilai WHERE id_produk = '$id'");
}

function produk_satuan_nilai_satu($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_satuan_nilai
  WHERE
  id_produk = '$id' AND
  tampil = 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_satuan_nilai_nol($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_satuan_nilai
  WHERE
  id_produk = '$id' AND
  tampil = 0");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_satuan_nilai_jumlah($id, $ok)
{
  return jumlah("SELECT * FROM produk_satuan_nilai WHERE
  satuan1 = '$id' AND
  id_produk = '$ok'");
}

function produk_satuan_nilai_jumlah_sama($id, $ok, $yes)
{
  return jumlah("SELECT * FROM produk_satuan_nilai WHERE
  satuan1 = '$id' AND
  satuan2 = '$ok' AND
  id_produk = '$yes'");
}

function produk_satuan_nilai($id, $y, $z, $x)
{
  $a = query_satu("SELECT * FROM produk_satuan_nilai
  WHERE
  id_produk = '$id' AND
  satuan1 = '$y' AND
  satuan2 = '$z'");
  return @$a[$x];
}

function produk_satuan_nilai_all($id)
{
  return query("SELECT * FROM produk_satuan_nilai WHERE
  id_produk = '$id'");
}

function produk_satuan_b_jum($id)
{
  return jumlah("SELECT * FROM produk_isi_satuan,
  satuan,
  jenis_qty
  WHERE
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 1 or
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 2");
}

function produk_satuan_b($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_isi_satuan,
  satuan,
  jenis_qty
  WHERE
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 1 or
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 2");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_satuan_b_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM produk_isi_satuan,
  satuan,
  jenis_qty
  WHERE
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 1 or
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 2");
  return $a[$ok];
}

function produk_satuan_s_jum($id)
{
  return jumlah("SELECT * FROM produk_isi_satuan,
  satuan,
  jenis_qty
  WHERE
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 3 or
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 4");
}

function produk_satuan_s_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM produk_isi_satuan,
  satuan,
  jenis_qty
  WHERE
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 3 or
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 4");
  return $a[$ok];
}

function produk_satuan_k_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM produk_isi_satuan,
  satuan,
  jenis_qty
  WHERE
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 5 or
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 6");
  return $a[$ok];
}

function produk_satuan_s($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_isi_satuan,
  satuan,
  jenis_qty
  WHERE
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 3 or
  produk_isi_satuan.id_produk = '$id' AND
  satuan.id_satuan = produk_isi_satuan.id_satuan AND
  jenis_qty.id_jenis_qty = satuan.id_jenis_qty AND
  jenis_qty.id_jenis_qty = 4");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function jenis_qty_satu($id, $y)
{
  $a = query_satu("SELECT * FROM jenis_qty WHERE id_jenis_qty = '$id'");
  return $a[$y];
}

function gudang()
{
  $i = [];
  $a = query("SELECT * FROM gudang ORDER BY edit DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function gudang_satu($id, $y)
{
  $a = query_satu("SELECT * FROM gudang WHERE id_gudang = '$id'");
  return $a[$y];
}

function gudang_kecuali($id)
{
  return query("SELECT * FROM gudang WHERE id_gudang != '$id'");
}

function gudang_produk_jum($id_produk, $id_gudang, $id_satuan, $id_wo_jenis)
{
  return jumlah("SELECT * FROM gudang_produk WHERE
      id_produk = '$id_produk' AND
      id_gudang = '$id_gudang' AND
      id_satuan = '$id_satuan' AND
      id_wo_jenis = '$id_wo_jenis'");
}

function gudang_produk_satu($id_produk, $id_gudang, $id_satuan, $id_wo_jenis, $isi)
{
  $a = query_satu("SELECT * FROM gudang_produk WHERE
      id_produk = '$id_produk' AND
      id_gudang = '$id_gudang' AND
      id_satuan = '$id_satuan' AND
      id_wo_jenis = '$id_wo_jenis'");
  return $a[$isi];
}

function jenis_satuan()
{
  $i = [];
  $a = query("SELECT * FROM jenis_qty");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function mata_uang_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM mata_uang WHERE id_mata_uang <> '$id' AND
  id_mata_uang = 0");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function mata_uang(){
  return query("SELECT * FROM mata_uang");
}

function mata_uang_satu($id_mata_uang,$isi)
{
  $a = query_satu("SELECT * FROM mata_uang WHERE id_mata_uang = '$id_mata_uang'");
  return $a[$isi];
}

function warna_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM warna WHERE id_warna <> '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function ukuran()
{
  $i = [];
  $a = query("SELECT * FROM ukuran");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function ukuran_satu($id, $x)
{
  $a = query_satu("SELECT * FROM ukuran WHERE id_ukuran = '$id'");
  return $a[$x];
}

function produk_ukuran_isi_satu($id, $y, $u)
{
  $a = query_satu("SELECT * FROM produk_ukuran_isi WHERE
  id_ukuran = '$id' AND
  id_produk = '$y'");
  return $a[$u];
}

function produk_ukuran_isi_jum($id)
{
  return jumlah("SELECT * FROM produk_ukuran_isi
  WHERE
  id_produk = '$id'");
}

function produk_ukuran_isi_total($id)
{
  $pu_yeah = query_satu("SELECT ROUND(EXP(SUM(LOG(nilai))),0) as total FROM produk_ukuran_isi WHERE id_produk = '$id'");
  return $pu_yeah["total"];
}

function produk_ukuran_isi($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_ukuran_isi WHERE id_produk = '$id' ORDER BY id_ukuran ASC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function harga_produk_terbesar_jum($id)
{
  return jumlah("SELECT * FROM harga_produk_terbesar WHERE
  id_produk = '$id'");
}

function harga_produk_terbesar_pilih($id, $ok)
{
  $i = [];
  $a = query("SELECT * FROM harga_produk_terbesar
  WHERE
  id_seller = '$id' AND
  id_produk = '$ok'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function harga_produk_terbesar($id)
{
  $i = [];
  $a = query("SELECT * FROM harga_produk_terbesar
  WHERE
  id_produk = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function harga_produk_terbesar_all()
{
  return query("SELECT * FROM harga_produk_terbesar");
}

function harga_produk_terbesar_hanya_produk()
{
  return query("SELECT distinct id_produk FROM harga_produk_terbesar");
}

function harga_produk_terbesar_satu($id, $ok, $y)
{
  $a = query_satu("SELECT * FROM harga_produk_terbesar WHERE
  id_seller = '$id' AND
  id_produk = '$ok'");
  return @$a[$y];
}

function produk_harga_jual_jum($id)
{
  return jumlah("SELECT * FROM produk_harga_jual WHERE
  id_harga_produk_terbesar = '$id'");
}

function produk_harga_jual($id, $ok)
{
  $a = query_satu("SELECT * FROM produk_harga_jual WHERE
  id_harga_produk_terbesar = '$id'");
  return $a[$ok];
}

function produk_harga_header_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM produk_harga_header WHERE
  id_produk_harga_header = '$id'");
  return $a[$ok];
}

function produk_harga_header()
{
  $i = [];
  $a = query("SELECT * FROM produk_harga_header
  WHERE
  id_produk_harga_header <> 1");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_harga_header_kecuali($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_harga_header
  WHERE
  id_produk_harga_header NOT IN(SELECT id_produk_harga_header FROM produk_harga_jual WHERE
  id_harga_produk_terbesar = '$id')");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_harga_jual_ada($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_harga_jual
  WHERE
  id_harga_produk_terbesar = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function produk_expired_jum($id)
{
  return jumlah("SELECT * FROM produk_expired WHERE
  id_produk = '$id'");
}

function produk_expired($id)
{
  $i = [];
  $a = query("SELECT * FROM produk_expired WHERE id_produk = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function expired_all()
{
  $i = [];
  $a = query("SELECT * FROM expired");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function expired_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM expired WHERE
  id_expired = '$id'");
  return $a[$ok];
}

function bom()
{
  $i = [];
  $a = query("SELECT * FROM bom");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function bom_detail($id)
{
  return query("SELECT * FROM bom_detail WHERE
  id_bom = '$id'");
}

function bom_detail_jum($id)
{
  return jumlah("SELECT * FROM bom_detail WHERE id_bom = '$id'");
}

function bom_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM bom WHERE
  id_bom = '$id'");
  return @$a[$ok];
}

function bom_satuan($id)
{
  return query("SELECT * FROM bom_satuan WHERE id_bom = '$id'");
}

function bom_satuan_jum($id)
{
  return jumlah("SELECT * FROM bom_satuan WHERE id_bom = '$id'");
}

function bom_satuan_satu($id_bom, $id_produk, $y)
{
  $a = query_satu("SELECT * FROM bom_satuan WHERE
  id_bom = '$id_bom' AND
  id_produk = '$id_produk'");
  return $a[$y];
}

function bom_reciep_satuan_jum($id)
{
  return jumlah("SELECT * FROM bom_reciep_satuan WHERE id_bom = '$id'");
}

function bom_reciep_satuan_satu($id, $o)
{
  $a = query_satu("SELECT * FROM bom_reciep_satuan WHERE id_bom = '$id'");
  return @$a[$o];
}

function ppic_favorit($id)
{
  $i = [];
  $a = query("SELECT * FROM ppic
  WHERE
  fav = 1 AND
  id_user = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function ppic_not_fav_jum($id)
{
  $user = user("id_user");
  return jumlah("SELECT * FROM ppic WHERE id_bom = '$id' AND
  id_user = '$user' AND
  fav = 0");
}

function ppic_one($id, $ok, $y)
{
  $user = user("id_user");
  $a = query_satu("SELECT * FROM ppic WHERE
  id_bom = '$id' AND
  id_user = '$user' AND
  fav = '$ok'");
  return $a[$y];
}

function ppic($id)
{
  $i = [];
  $a = query("SELECT * FROM ppic
  WHERE
  fav = 0 AND
  id_user = '$id'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function ppic_tot($id)
{
  $user = user("id_user");
  $c = query("SELECT distinct id_produk FROM bom_detail WHERE
          id_bom IN(SELECT id_bom FROM ppic WHERE fav = 1)");
  while ($d = query_banyak($c)) {
    if ($id == 1) {
      foreach (ppic_favorit($user) as $pf) :
        if (@produk_isi_satuan_awal($d["id_produk"], "id_satuan")) {
          if (@$resep_persen = @bom_detail_satu($pf["id_bom"], $d["id_produk"], "resep_persen")) {
            if ($pf["b"] != 0) {
              @$tot = ($resep_persen) * ($pf["b"] * produk_satuan_nilai($d["id_produk"], @produk_isi_satuan_awal($d["id_produk"], "id_satuan"), @produk_isi_satuan_akhir($d["id_produk"], "id_satuan"), "nilai")) / 100;
              $cek = jumlah("SELECT * FROM ppic_tot WHERE
              id_produk = '$d[id_produk]' AND
              id_user = '$user'");
              if ($cek == 0) {
                if (!empty($tot)) {
                  query("INSERT INTO ppic_tot (id_produk,tot,id_user) VALUES('$d[id_produk]','$tot','$user')");
                }
              } else {
                $lih = query_satu("SELECT * FROM ppic_tot WHERE
                id_produk = '$d[id_produk]' AND
                id_user = '$user'");
                $hehe = $lih["tot"] + $tot;
                if (!empty($hehe)) {
                  query("UPDATE ppic_tot SET
                        tot = '$hehe'
                        WHERE
                        id_produk = '$d[id_produk]' AND
                        id_user = '$user'");
                }
              }
            } else {

              @$tot = @$pf["k"] * bom_detail_satu($pf["id_bom"], $d["id_produk"], "resep_persen") / 100;
              $cek = jumlah("SELECT * FROM ppic_tot WHERE
              id_produk = '$d[id_produk]' AND
              id_user = '$user'");
              if ($cek == 0) {
                if (!empty($tot)) {
                  query("INSERT INTO (id_produk,tot,id_user) ppic_tot VALUES('$d[id_produk]','$tot','$user')");
                }
              } else {
                $lih = query_satu("SELECT * FROM ppic_tot WHERE
                id_produk = '$d[id_produk]' AND
                id_user = '$user'");
                $hehe = $lih["tot"] + $tot;
                if (!empty($hehe)) {
                  query("UPDATE ppic_tot SET
                        tot = '$hehe'
                        WHERE
                        id_produk = '$d[id_produk]' AND
                        id_user = '$user'");
                }
              }

              //numb_nol($pf["k"]/produk_satuan_nilai($d["id_produk"], @produk_isi_satuan_awal($d["id_produk"], "id_satuan"), @produk_isi_satuan_akhir($d["id_produk"], "id_satuan"), "nilai"));
            }
          } else {
            $xx = 0;
            //echo "Resep nya kosong<br>";
          }
        } else {
          $xx = 0;
          //echo '0<br>';
        }
      endforeach;
    } elseif ($id == 2) {
      foreach (ppic($user) as $p) :

        if (@produk_isi_satuan_awal($d["id_produk"], "id_satuan")) {
          if (@$resep_persen = @bom_detail_satu($p["id_bom"], $d["id_produk"], "resep_persen")) {
            if ($p["b"] != 0) {
              @$tot = ($resep_persen) * ($p["b"] * produk_satuan_nilai($d["id_produk"], @produk_isi_satuan_awal($d["id_produk"], "id_satuan"), @produk_isi_satuan_akhir($d["id_produk"], "id_satuan"), "nilai")) / 100;
              $cek = jumlah("SELECT * FROM ppic_tot WHERE
                          id_produk = '$d[id_produk]' AND
                          id_user = '$user'");
              if ($cek == 0) {
                if (!empty($tot)) {
                  query("INSERT INTO ppic_tot (id_produk,tot,id_user) VALUES('$d[id_produk]','$tot','$user')");
                }
              } else {
                $lih = query_satu("SELECT * FROM ppic_tot WHERE
                            id_produk = '$d[id_produk]' AND
                            id_user = '$user'");
                $hehe = $lih["tot"] + $tot;
                if (!empty($hehe)) {
                  query("UPDATE ppic_tot SET
                                    tot = '$hehe'
                                    WHERE
                                    id_produk = '$d[id_produk]' AND
                                    id_user = '$user'");
                }
              }
            } else {
              @$tot = @$p["k"] * bom_detail_satu($p["id_bom"], $d["id_produk"], "resep_persen") / 100;
              $cek = jumlah("SELECT * FROM ppic_tot WHERE
                          id_produk = '$d[id_produk]' AND
                          id_user = '$user'");
              if ($cek == 0) {
                if (!empty($tot)) {
                  query("INSERT INTO ppic_tot (id_produk,tot,id_user) VALUES('$d[id_produk]','$tot','$user')");
                }
              } else {
                $lih = query_satu("SELECT * FROM ppic_tot WHERE
                            id_produk = '$d[id_produk]' AND
                            id_user = '$user'");
                $hehe = $lih["tot"] + $tot;
                if (!empty($hehe)) {
                  query("UPDATE ppic_tot SET
                                    tot = '$hehe'
                                    WHERE
                                    id_produk = '$d[id_produk]' AND
                                    id_user = '$user'");
                }
              }
              // numb_nol($p["k"]/produk_satuan_nilai($d["id_produk"], @produk_isi_satuan_awal($d["id_produk"], "id_satuan"), @produk_isi_satuan_akhir($d["id_produk"], "id_satuan"), "nilai"));
            }
          } else {
            $xx = 0;
            //echo "Resep nya kosong<br>";
          }
        } else {
          $xx = 0;
          //echo '0<br>';
        }

      endforeach;
    }
  }
}

function ppic_tot_remove()
{
  $user = user("id_user");
  return query("DELETE FROM ppic_tot WHERE id_user = '$user'");
}

function ppic_tot_see()
{
  $user = user("id_user");
  $i = [];
  $a = query("SELECT * FROM ppic_tot
  WHERE
  id_user = '$user'");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function ppic_tot_see_minus()
{
  $user = user("id_user");
  return query("SELECT * FROM ppic_tot
  WHERE
  persen < 0 AND
  id_user = '$user'");
}

function ppic_tot_see_nol()
{
  $user = user("id_user");
  return query("SELECT * FROM ppic_tot
  WHERE
  persen = 0 AND
  id_user = '$user'");
}

function ppic_tot_see_20()
{
  $user = user("id_user");
  return query("SELECT * FROM ppic_tot
  WHERE
  persen > 0 AND
  persen <= 20 AND
  id_user = '$user'");
}

function ppic_tot_see_40()
{
  $user = user("id_user");
  return query("SELECT * FROM ppic_tot
  WHERE
  persen > 20 AND
  persen <= 40 AND
  id_user = '$user'");
}

function ppic_tot_see_60()
{
  $user = user("id_user");
  return query("SELECT * FROM ppic_tot
  WHERE
  persen > 40 AND
  persen <= 60 AND
  id_user = '$user'");
}

function ppic_tot_see_100()
{
  $user = user("id_user");
  return query("SELECT * FROM ppic_tot
  WHERE
  persen > 60 AND
  id_user = '$user'");
}

function ppic_persen($id, $haha)
{
  // $min_stok = @stok_produk_control_satu($id,3,"min");
  // $sisa_stok = produk_satu($id,"stok_produk");
  // if ($min_stok != 0){
  //   if ($sisa_stok < $min_stok) {
  //     $haha = '-'.($min_stok-$sisa_stok)/$min_stok*100;
  //   }elseif ($sisa_stok > $min_stok) {
  //     $haha = ($sisa_stok-$min_stok)/$min_stok*100;
  //   }elseif ($sisa_stok == $min_stok) {
  //     $haha = 0;
  //   }
  // }else {
  //     $haha = 0;
  //   }
  $user = user("id_user");
  return query("UPDATE ppic_tot SET persen = '$haha' WHERE id_produk = '$id' AND
  id_user = '$user'");
}

function id($id)
{
  $konek = konek();
  $id = mysqli_real_escape_string($konek, g($id));
  return $id;
}

function bom_detail_satu($id, $ok, $y)
{
  $a = query_satu("SELECT * FROM bom_detail WHERE
  id_bom = '$id' AND
  id_produk = '$ok'");
  return $a[$y];
}

function bom_detail_id_satu($id, $y)
{
  $a = query_satu("SELECT * FROM bom_detail WHERE
  id_bom_detail = '$id'");
  return $a[$y];
}

function pr_nol_satu($id, $ok)
{
  $user = user("id_user");
  $a = query_satu("SELECT * FROM pr WHERE
  id_produk = '$id' AND
  id_user = '$user' AND
  status_pr = '0'");
  return $a[$ok];
}

function pr_nol_jum($id)
{
  $user = user("id_user");
  return jumlah("SELECT * FROM pr WHERE
  id_produk = '$id' AND
  id_user = '$user' AND
  status_pr = '0'");
}

function pr_pilih_jum($id)
{
  $user = user("id_user");
  return jumlah("SELECT * FROM pr_pilih WHERE
  id_produk = '$id' AND
  id_user = '$user'");
}

function pr_pilih()
{
  $user = user("id_user");
  return query("SELECT * FROM pr_pilih WHERE
  id_user = '$user'");
}

function pr_header_all()
{
  return query("SELECT * FROM pr_header WHERE hidden = 0");
}

function pr_header_all_semua()
{
  return query("SELECT * FROM pr_header");
}

function pr_header_hidden()
{
  foreach (pr_header_all_semua() as $id) :
    if (pr_detail_jum($id["kode_pr"]) == surat_pemesanan_detail_pr_jum_kodepr($id["kode_pr"])) {
      return query("UPDATE pr_header SET hidden = 1 WHERE kode_pr = '$id[kode_pr]'");
    } else {
      return query("UPDATE pr_header SET hidden = 0 WHERE kode_pr = '$id[kode_pr]'");
    }
  endforeach;
}

function pr_header_this_month()
{
  $bulan = date("m");
  $tahun = date("Y");
  return query("SELECT * FROM pr_header WHERE
  month(tgl_pr) = '$bulan' AND
  year(tgl_pr) = '$tahun'");
}

function pr_header_today()
{
  $bulan = date("m");
  $tahun = date("Y");
  $tanggal = date("d");
  return query("SELECT * FROM pr_header WHERE
  month(tgl_pr) = '$bulan' AND
  year(tgl_pr) = '$tahun' AND
  day(tgl_pr) = '$tanggal'");
}

function pr_header_choose_date($id)
{
  return query("SELECT * FROM pr_header WHERE
  date(tgl_pr) = '$id'");
}

function pr_header_choose_month($bulan, $tahun)
{
  return query("SELECT * FROM pr_header WHERE
  month(tgl_pr) = '$bulan' AND
  year(tgl_pr) = '$tahun'");
}

function pr_header_choose_year($tahun)
{
  return query("SELECT * FROM pr_header WHERE
  year(tgl_pr) = '$tahun'");
}

function pr_header_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM pr_header WHERE
  kode_pr = '$id'");
  return $a[$ok];
}

function pr_header_tahun()
{
  return query("SELECT DISTINCT year(tgl_pr) AS tahun FROM pr_header");
}

function pr_detail_jum($id)
{
  return jumlah("SELECT * FROM pr_detail WHERE
  kode_pr = '$id'");
}

function pr_detail($id)
{
  return query("SELECT * FROM pr_detail WHERE
  kode_pr = '$id' AND
  id_produk NOT IN(SELECT id_produk FROM surat_pemesanan_detail_pr
  WHERE
  kode_pr = '$id')");
}

function pr_detail_all($id)
{
  return query("SELECT * FROM pr_detail WHERE
  kode_pr = '$id'");
}

function pr_detail_satu($id, $ok, $y)
{
  $a = query_satu("SELECT * FROM pr_detail WHERE
  kode_pr = '$id' AND
  id_produk = '$ok'");
  return $a[$y];
}

function surat_pemesanan_detail_pr_satu($id, $ok, $y)
{
  $a = query_satu("SELECT * FROM surat_pemesanan_detail_pr
  WHERE
  id_surat_pemesanan_detail = '$id' AND
  id_produk = '$ok'");
  return $a[$y];
}


function surat_pemesanan_detail_pr_jum_kodepr($id)
{
  return jumlah("SELECT * FROM surat_pemesanan_detail_pr
  WHERE
  kode_pr = '$id'");
}

function surat_pemesanan_detail_pr_jum_kodepr_produk($id, $y)
{
  return jumlah("SELECT * FROM surat_pemesanan_detail_pr
  WHERE
  kode_pr = '$id' AND
  id_produk = '$y'");
}

function surat_penawaran_satu($id, $ok)
{
  $a = query_satu("SELECT * FROM surat_penawaran WHERE id_surat_penawaran = '$id'");
  return $a[$ok];
}

function ql_tot_see($id)
{
  $a = query_satu("SELECT * FROM ql_tot WHERE id_surat_penawaran = '$id'");
  return $a["tot"];
}

function ql_tot($id, $o)
{
  $cek = jumlah("SELECT * FROM ql_tot WHERE
  id_surat_penawaran = '$id'");
  if ($cek > 0) {
    $t = query("UPDATE ql_tot SET tot = '$o'
    WHERE
    id_surat_penawaran = '$id'");
  } else {
    $t = query("INSERT INTO ql_tot VALUES('$id','$o')");
  }
  return $t;
}

function surat_penawaran_detail_jum($id)
{
  return jumlah("SELECT * FROM surat_penawaran_detail WHERE id_surat_penawaran = '$id'");
}

function surat_penawaran_detail($id)
{
  return query("SELECT * FROM surat_penawaran_detail WHERE id_surat_penawaran = '$id'");
}

function surat_penawaran_detail_diskon($id, $o)
{
  $a = query_satu("SELECT * FROM surat_penawaran_detail_diskon WHERE id_surat_penawaran = '$id'");
  return @$a[$o];
}

function surat_penawaran_detail_diskon_lihat($id,$y, $o)
{
  $a = query_satu("SELECT * FROM surat_penawaran_detail_diskon WHERE id_surat_penawaran = '$id' AND
  id_produk = '$y'");
  return @$a[$o];
}

function surat_penawaran_brutto($id)
{
  foreach (surat_penawaran_detail($id) as $spd) :
    $harga = $spd["harga"] * $spd["qty"];
    if ($spd["diskon_jenis_nama"] == 0) {
      $diskon = 0;
    } else {
      if ($spd["diskon_jenis_nama"] == 1) {
        $diskon = surat_penawaran_detail_diskon($id, "value");
      } elseif ($spd["diskon_jenis_nama"] == 2) {
        $diskon = surat_penawaran_detail_diskon($id, "value") * $harga / 100;
      }
    }
    $tot = $harga - $diskon;
    @$tot_all = $tot;
  endforeach;
  return @$tot_all;
}

function surat_penawaran_tot_berat($id)
{
  foreach (surat_penawaran_detail($id) as $spd) :
    $tot = $spd["berat_gram"];
    @$tot_all += $tot;
  endforeach;
  return @$tot_all;
}

function surat_penawaran_ongkir_total($id)
{
  return surat_penawaran_ongkir_satu($id, "kg") * (surat_penawaran_tot_berat($id) / 1000);
}

function surat_penawaran_ongkir_netto($id)
{
  return surat_penawaran_brutto($id) + @surat_penawaran_ongkir_total($id);
}

function surat_penawaran_ongkir_jum($id)
{
  return jumlah("SELECT * FROM surat_penawaran_ongkir WHERE id_surat_penawaran = '$id'");
}

function surat_penawaran_ongkir_satu($id, $o)
{
  $a = query_satu("SELECT * FROM surat_penawaran_ongkir WHERE id_surat_penawaran = '$id'");
  return $a[$o];
}

function surat_penawaran_ongkir($id_surat_penawaran)
{
  return query("SELECT * FROM surat_penawaran_ongkir WHERE id_surat_penawaran = '$id_surat_penawaran'");
}

function surat_penawaran_masa_berlaku()
{
  return query("SELECT * FROM surat_penawaran_masa_berlaku");
}

function surat_penawaran_masa_berlaku_satu($id, $y)
{
  $a = query_satu("SELECT * FROM surat_penawaran_masa_berlaku WHERE
  id = '$id' ");
  return $a[$y];
}

function surat_penawaran_masa_berlaku_hari_satu($id, $o, $y)
{
  $a = query_satu("SELECT * FROM surat_penawaran_masa_berlaku_hari WHERE
  id_surat_penawaran = '$id' AND
  id = '$o'");
  return $a[$y];
}

function surat_penawaran_masa_berlaku_hari_jum($id)
{
  return jumlah("SELECT * FROM surat_penawaran_masa_berlaku_hari WHERE
  id_surat_penawaran = '$id'");
}

function surat_penawaran_this_month()
{
  $bulan = date("m");
  $tahun = date("Y");
  return query("SELECT * FROM surat_penawaran WHERE 
  status != 0 AND
  month(tgl_surat_penawaran) = '$bulan' AND
  year(tgl_surat_penawaran) = '$tahun'");
}

function surat_penawaran_this_day()
{
  $date = date("Y-m-d");
  return query("SELECT * FROM surat_penawaran WHERE 
  status != 0 AND
  tgl_surat_penawaran = '$date'");
}

function surat_penawaran_not_in_so()
{
  return query("SELECT * FROM surat_penawaran WHERE
  id_surat_penawaran NOT IN(SELECT id_surat_penawaran FROM so WHERE no_so != '') AND
  no_ql != '' AND
  status = 1");
}

function surat_penawaran_not_in_so_jum()
{
  return jumlah("SELECT * FROM surat_penawaran WHERE
  id_surat_penawaran NOT IN(SELECT id_surat_penawaran FROM so WHERE no_so != '') AND
  no_ql != '' AND
  status = 1");
}

function surat_penawaran_jenis_satu($id, $o)
{
  $a = query_satu("SELECT * FROM surat_penawaran_jenis WHERE id = '$id'");
  return $a[$o];
}

function adj()
{
  $i = [];
  $a = query("SELECT * FROM adjusment ORDER BY id DESC");
  while ($b = query_banyak($a)) {
    $i[] = $b;
  }
  return $i;
}

function adj_gudang()
{
  return query("SELECT id_gudang FROM adjusment_gudang");
}

// fun

function so_satu_ql($id, $o)
{
  $a = query_satu("SELECT * FROM so WHERE id_surat_penawaran = '$id'");
  return $a[$o];
}

function so_tot_see($id)
{
  $a = query_satu("SELECT * FROM so_tot WHERE id_so = '$id'");
  return $a["tot"];
}

function so_tot($id, $o)
{
  $cek = jumlah("SELECT * FROM so_tot WHERE
  id_so = '$id'");
  if ($cek > 0) {
    $t = query("UPDATE so_tot SET tot = '$o'
    WHERE
    id_so = '$id'");
  } else {
    $t = query("INSERT INTO so_tot VALUES('$id','$o')");
  }
  return $t;
}

function so_satu($id, $o)
{
  $a = query_satu("SELECT * FROM so WHERE id_so = '$id' OR no_so = '$id'");
  return @$a[$o];
}

function so_no_so($id, $o)
{
  $a = query_satu("SELECT * FROM so WHERE id_so = '$id' OR no_so = '$id'");
  return $a[$o];
}

function so_ongkir($id, $o)
{
  $a = query_satu("SELECT * FROM so_ongkir WHERE id_so = '$id'");
  return $a[$o];
}

function so_ongkir_total($id, $o)
{
  return so_ongkir($id, "kg") * (surat_penawaran_tot_berat($o) / 1000);
}

function so_ongkir_total_detail($id)
{
  return so_ongkir($id, "kg") * (so_detail_berat_gram($id) / 1000);
}

function so_ongkir_jum($id)
{
  return jumlah("SELECT * FROM so_ongkir WHERE id_so = '$id'");
}



function so_kredit_satu($id, $o)
{
  $a = query_satu("SELECT * FROM so_kredit WHERE id_so = '$id'");
  return $a[$o];
}

function so_pajak_persen($id, $o)
{
  $a = query_satu("SELECT * FROM so_pajak_persen WHERE id_so = '$id'");
  return @$a[$o];
}

function so_diskon($id, $o)
{
  $a = query_satu("SELECT * FROM so_diskon WHERE id_so = '$id'");
  return $a[$o];
}

function so_diskon_tot($id)
{
  $brutto = surat_penawaran_brutto(so_satu($id, "id_surat_penawaran"));
  if (so_satu($id, "diskon_jenis_nama") == 0) {
    $diskon = 0;
  } else {
    if (so_satu($id, "diskon_jenis_nama") == 1) {
      $diskon = so_diskon($id, "val");
    } elseif (so_satu($id, "diskon_jenis_nama") == 2) {
      $diskon = $brutto * so_diskon($id, "val") / 100;
    }
  }
  return $diskon;
}

function so_diskon_satu($id_so,$isi)
{
  $a = query_satu("SELECT * FROM so_diskon WHERE
  id_so = '$id_so'");
  return $a[$isi];
}

function so_diskon_tot_detail($id)
{
  $brutto = so_detail_brutto($id);
  if (so_satu($id, "diskon_jenis_nama") == 0) {
    $diskon = 0;
  } else {
    if (so_satu($id, "diskon_jenis_nama") == 1) {
      $diskon = so_diskon($id, "val");
    } elseif (so_satu($id, "diskon_jenis_nama") == 2) {
      $diskon = $brutto * so_diskon($id, "val") / 100;
    }
  }
  return $diskon;
}

function so_tax($id)
{
  $brutto = surat_penawaran_brutto(so_satu($id, "id_surat_penawaran"));
  if (so_satu($id, "tax") == 1) {
    $tax = $brutto * so_pajak_persen($id, "value") / 100;
  } else {
    $tax = 0;
  }
  return $tax;
}

function so_tax_detail($id)
{
  $brutto = so_detail_brutto($id);
  if (so_satu($id, "tax") == 1) {
    $tax = $brutto * so_pajak_persen($id, "value") / 100;
  } else {
    $tax = 0;
  }
  return $tax;
}

function so_netto($id)
{
  $brutto = surat_penawaran_brutto(so_satu($id, "id_surat_penawaran"));
  if (so_ongkir_jum($id) > 0) {
    $ongkir = so_ongkir_total($id, so_satu($id, "id_surat_penawaran"));
  } else {
    $ongkir = 0;
  }
  $tax = so_tax($id);
  $diskon = so_diskon_tot($id);
  return ($brutto + $ongkir + $tax) - $diskon;
}

function so_netto_detail($id)
{
  $brutto = so_detail_brutto($id);
  if (so_ongkir_jum($id) > 0) {
    $ongkir = so_ongkir_total_detail($id);
  } else {
    $ongkir = 0;
  }
  $tax = so_tax_detail($id);
  $diskon = so_diskon_tot_detail($id);
  return $brutto + $ongkir + $tax - $diskon;

  // $brutto = so_detail_brutto($id);
  // if (so_ongkir_jum($id)>0) {
  //   $ongkir = so_ongkir_total($id,so_satu($id,"id_surat_penawaran"));
  // }else {
  //   $ongkir = 0;
  // }
  // $tax = so_tax_detail($id);
  // $diskon = so_diskon_tot_detail($id);
  // return ($brutto+$ongkir+$tax)-$diskon;
}

function so_all_this_month()
{
  // $bulan = date("m");
  // $tahun = date("Y");
  // return query("SELECT * FROM so WHERE
  // status != 0 AND
  // month(buat) = '$bulan' AND
  // year(buat) = '$tahun'");
  return query("SELECT * FROM so WHERE status != 0");
}

function so_all_this_day()
{
  $tgl = date("Y-m-d");
  // return query("SELECT * FROM so WHERE
  // status != 0 AND
  // month(buat) = '$bulan' AND
  // year(buat) = '$tahun'");
  return query("SELECT * FROM so WHERE status != 0 AND
  date(buat) = '$tgl'");
}

function so_detail_jum($id)
{
  return jumlah("SELECT * FROM so_detail WHERE id_so = '$id'");
}

function so_detail($ono)
{
  return query("SELECT * FROM so_detail WHERE id_so = '$ono'");
}

function so_detail_diskon($id, $y, $o)
{
  $a = query_satu("SELECT * FROM so_detail_diskon WHERE
  id_so = '$id' AND
  id_produk = '$y'");
  return $a[$o];
}

function so_detail_brutto($id)
{
  foreach (so_detail($id) as $sd) :

    $harga = $sd["harga"];

    if ($sd["diskon_jenis_nama"] == 0) {
      $diskon = 0;
    } else {
      if (so_satu($id, "id_surat_penawaran") == 0) {
        if ($sd["diskon_jenis_nama"] == 1) {
          $diskon = so_detail_diskon($id, $sd["id_produk"], "value");
        } elseif ($sd["diskon_jenis_nama"] == 2) {
          $diskon = so_detail_diskon($id, $sd["id_produk"], "value") * ($harga * $sd["qty"]) / 100;
        }
      } else {
        if ($sd["diskon_jenis_nama"] == 1) {
          $diskon = surat_penawaran_detail_diskon(si_satu($id, "id_surat_penawaran"), "value");
        } elseif ($sd["diskon_jenis_nama"] == 2) {
          $diskon = surat_penawaran_detail_diskon(si_satu($id, "id_surat_penawaran"), "value") * $harga / 100;
        }
      }
    }

    $tot = $harga * $sd["qty"] - ($diskon);
    @$all_tot += @$tot;
  endforeach;
  return @$all_tot;
  // foreach(so_detail($id) as $sd) :
  //   if ($sd["diskon_jenis_nama"] == 1) {
  //     $diskon = so_detail_diskon($id,$sd["id_produk"],"value");
  //   }elseif ($sd["diskon_jenis_nama"] == 2) {
  //     $diskon = so_detail_diskon($id,$sd["id_produk"],"value")*($sd["harga"]*$sd["qty"])/100;
  //   }else {
  //     $diskon = 0;
  //   }
  //   $tot = $sd["harga"]*$sd["qty"]-$diskon;
  //   @$all_tot += @$tot;
  // endforeach;
  // return @$all_tot;
}

function so_detail_berat_gram($id)
{
  foreach (so_detail($id) as $sd) :
    $gram = $sd["berat_gram"];
    @$all_tot += @$gram;
  endforeach;
  return @$all_tot;
}

function so_detail_satu($id_so,$id_produk,$isi)
{
  $a = query_satu("SELECT * FROM so_detail WHERE
  id_so = '$id_so' AND
  id_produk = '$id_produk'");
  return $a[$isi];
}

function so_confirm()
{
  return query("SELECT * FROM so WHERE
  status = 16 AND
  id_so NOT IN(SELECT id_so FROM si_so)");
}

function so_sales_jum($id)
{
  return jumlah("SELECT * FROM so_sales WHERE id_so = '$id'");
}

function so_sales($id,$b)
{
  $a = query_satu("SELECT * FROM so_sales WHERE
  id_so = '$id'");
  return $a[$b];
}

function diskon_jenis_nama_satu($id, $o)
{
  $a = query_satu("SELECT * FROM diskon_jenis_nama WHERE id = '$id'");
  return $a[$o];
}

function diskon_jenis_nama_all()
{
  return query("SELECT * FROM diskon_jenis_nama");
}

function diskon_jenis_nama_kecuali($id)
{
  return query("SELECT * FROM diskon_jenis_nama WHERE id != '$id'");
}

function po_penjualan_satu($id, $o)
{
  $a = query_satu("SELECT * FROM po_penjualan WHERE id_po_penjualan = '$id'");
  return $a[$o];
}

function po_penjualan_kredit_satu($id, $o)
{
  $a = query_satu("SELECT * FROM po_penjualan_kredit WHERE id_po_penjualan = '$id'");
  return $a[$o];
}

function si_satu($id, $o)
{
  $a = query_satu("SELECT * FROM si WHERE id_si = '$id' OR no_si = '$id'");
  return @$a[$o];
}

function si_complete()
{
  return query("SELECT * FROM si WHERE id_status = 1");
}

function si_so($id)
{
  $a = query_satu("SELECT id_so FROM si_so WHERE id_si = '$id'");
  return $a["id_so"];
}

function si_so_jum($id_si)
{
  return jumlah("SELECT * FROM si_so WHERE id_si = '$id_si'");
}

function si_so_netto($id)
{
  $brutto = so_detail_brutto($id);
  if (@si_ongkir($id, "kg")) {
    $ongkir = so_detail_berat_gram($id) / 1000 * (@si_ongkir($id, "kg"));
  } else {
    $ongkir = 0;
  }
  $tax = @so_tax_detail($id);
  $diskon = @so_diskon_tot_detail($id);
  $tot = $brutto + $ongkir + $tax - $diskon;
  return $tot;
}

function si_ongkir($id, $o)
{
  $a = query_satu("SELECT * FROM si_ongkir WHERE id_si = '$id'");
  return @$a[$o];
}

function si_ongkir_potongan_jum($id)
{
  return jumlah("SELECT * FROM si_ongkir_potongan WHERE id_si = '$id'");
}

function si_ongkir_potongan_satu($id, $o)
{
  $a = query_satu("SELECT * FROM si_ongkir_potongan WHERE id_si = '$id'");
  return $a[$o];
}

function si_ongkir_total($id)
{
  if (si_satu($id, "input_dari") == 1) {
    $ongkir = so_ongkir_total_detail($id);
  } elseif (si_satu($id, "input_dari") == 2) {
    $ongkir = si_ongkir($id, "kg") * (si_stok_berat($id) / 1000);
  } else {
    $ongkir = 0;
  }
  return $ongkir;
}

function si_ongkir_jum($id)
{
  return jumlah("SELECT * FROM si_ongkir WHERE id_si = '$id'");
}

function si_stok($id, $o)
{
  $a = query_satu("SELECT * FROM si_stok WHERE id_si = '$id'");
  return @$a[$o];
}

function si_stok_kredit($id, $o)
{
  $a = query_satu("SELECT * FROM si_stok_kredit WHERE id_si = '$id'");
  return $a[$o];
}

function si_stok_kredit_jum($id)
{
  return jumlah("SELECT * FROM si_stok_kredit WHERE id_si = '$id'");
}

function si_stok_jum($id)
{
  return jumlah("SELECT * FROM si_stok WHERE id_si = '$id'");
}

function si_stok_satu($id, $o)
{
  $a = query_satu("SELECT * FROM si_stok WHERE id_si = '$id'");
  return @$a[$o];
}

function si_stok_pajak($id, $o)
{
  $a = query_satu("SELECT * FROM si_stok_pajak WHERE id_si = '$id'");
  return $a[$o];
}

function si_stok_pajak_jumlah($id_si)
{
  return jumlah("SELECT * FROM si_stok_pajak WHERE id_si = '$id_si'");
}

function so_stok_pajak_jumlah($id_so)
{
  return jumlah("SELECT * FROM so_pajak_persen WHERE id_so = '$id_so' ");
}

function si_stok_pajak_jum($id)
{
  if (si_stok_satu($id, "tax") == 1) {
    $tax = si_stok_pajak($id, "persen") * si_stok_brutto($id) / 100;
  } elseif (si_stok_satu($id, "tax") == 0) {
    $tax = 0;
  }
  return $tax;
}

function si_save_today()
{
  $tgl = date("Y-m-d");
  return query("SELECT * FROM si WHERE id_status != 0 AND
  tgl_si = '$tgl'");
}



function si_report()
{
  return query("SELECT * FROM si WHERE id_status != 0 ");
}

function si_tot($id, $o)
{
  $cek = jumlah("SELECT * FROM si_tot WHERE
  id_si = '$id'");
  if ($cek > 0) {
    $t = query("UPDATE si_tot SET tot = '$o'
    WHERE
    id_si = '$id'");
  } else {
    $t = query("INSERT INTO si_tot VALUES('$id','$o')");
  }
  return $t;
}

function si_tot_see($id)
{
  $a = query_satu("SELECT * FROM si_tot WHERE id_si = '$id'");
  return $a["tot"];
}

function si_stok_detail($id)
{
  return query("SELECT * FROM si_stok_detail WHERE id_si = '$id'");
}

function si_stok_detail_satu($id_si,$id_produk,$isi)
{
  $a = query_satu("SELECT * FROM si_stok_detail WHERE
  id_si = '$id_si' AND
  id_produk = '$id_produk'");
  return @$a[$isi];
}

function si_stok_detaillimitnya($id)
{
  return query("SELECT * FROM si_stok_detail WHERE id_si = '$id' LIMIT 5");
}

function si_stok_detail_jum($id)
{
  return jumlah("SELECT * FROM si_stok_detail WHERE id_si = '$id'");
}

function si_stok_detail_diskon_satu($id, $o, $u)
{
  $a = query_satu("SELECT * FROM si_stok_detail_diskon WHERE
  id_si = '$id' AND
  id_produk = '$o'");
  return $a[$u];
}

function si_stok_diskon($id)
{
  $a = query_satu("SELECT * FROM si_stok_diskon WHERE id_si = '$id'");
  return $a["value"];
}

function si_stok_diskon_jum($id)
{
  return jumlah("SELECT * FROM si_stok_diskon WHERE id_si = '$id'");
}

function si_stok_diskon_total($id)
{
  if (@si_stok_satu($id, "diskon_jenis_nama") == 1) {
    @$diskon = @si_stok_diskon($id);
  } elseif (si_stok_satu($id, "diskon_jenis_nama") == 2) {
    @$diskon = @si_stok_diskon($id) * @si_stok_brutto($id) / 100;
  }
  return @$diskon;
}

function si_stok_brutto($id)
{
  foreach (si_stok_detail($id) as $ssd) :
    $qty = $ssd["qty"];
    $harga = $ssd["harga"];
    if ($ssd["diskon_jenis_nama"] == 0) {
      $diskon = 0;
    } elseif ($ssd["diskon_jenis_nama"] == 1) {
      $diskon = si_stok_detail_diskon_satu($id, $ssd["id_produk"], "value");
    } elseif ($ssd["diskon_jenis_nama"] == 2) {
      $diskon = si_stok_detail_diskon_satu($id, $ssd["id_produk"], "value") * ($ssd["qty"] * $ssd["harga"]) / 100;
    }
    $tot = ($qty * $harga  - $diskon );
    @$tot_all += $tot;
  endforeach;
  return @$tot_all;
}

function si_stok_berat($id)
{
  foreach (si_stok_detail($id) as $ssd) :
    $tot = $ssd["berat_gram"];
    @$tot_all += $tot;
  endforeach;
  return @$tot_all;
}

function si_stok_netto($id)
{
  $brutto = si_stok_brutto($id);
  $ongkir = si_ongkir_total($id);
  $ongkos_angkut = si_stok_satu($id, "ongkos_angkut");
  $tax = si_stok_pajak_jum($id);
  $diskon = si_stok_diskon_total($id);
  $uang_muka = si_stok_satu($id, "uang_muka");
  return ($brutto + $ongkir + $ongkos_angkut + $tax) - $diskon - $uang_muka;
}

function si_sales_jum($id)
{
  return jumlah("SELECT * FROM si_sales WHERE id_si = '$id'");
}

function si_sales($id)
{
  $a = query_satu("SELECT * FROM si_sales WHERE id_si = '$id'");
  return $a["id_sales"];
}

function diantar_satu($id, $o)
{
  $a = query_satu("SELECT * FROM diantar WHERE id_diantar = '$id'");
  return @$a[$o];
}

function diantar_kecuali($id)
{
  return query("SELECT * FROM diantar WHERE id_diantar != '$id'");
}

function do_satu($id, $o)
{
  $a = query_satu("SELECT * FROM do WHERE no_do = '$id'");
  return $a[$o];
}

function do_all()
{
  return query("SELECT * FROM do");
}

function do_ongkir($id, $o)
{
  $a = query_satu("SELECT * FROM so_ongkir WHERE id_do = '$id'");
  return $a[$o];
}

function csv()
{
  return query("SELECT * FROM csv ORDER BY urutan ASC");
}

function expedisi_jenis()
{
  return query("SELECT * FROM expedisi_jenis ORDER BY edit DESC");
}

function expedisi_jenis_satu($id, $o)
{
  $a = query_satu("SELECT * FROM expedisi_jenis WHERE id = '$id'");
  return $a[$o];
}

function expedisi_jenis_kecuali($id)
{
  return query("SELECT * FROM expedisi_jenis WHERE id != '$id'");
}

function expedisi_tipe()
{
  return query("SELECT * FROM expedisi_tipe ORDER BY edit DESC");
}

function expedisi_tipe_satu($id, $o)
{
  $a = query_satu("SELECT * FROM expedisi_tipe WHERE id_expedisi_tipe = '$id'");
  return $a[$o];
}

function pages($id, $start_start)
{
  $awal = 5;
  $jum = jumlah("SELECT * FROM $id");
  $pages = $jum / 5;
  $cek_akhir = floor($pages);
  $start = $start_start;
  if (($cek_akhir * $awal) == $jum) {
    $akhir = $cek_akhir;
  } else {
    $akhir = $cek_akhir + 1;
  }
  $html = '
  <nav aria-label="...">
  <ul class="pagination pagination-sm m-0 float-right">';
  if ($start == 1) {
    $html .= '<li class="page-item disabled">
  <span class="page-link">Previous</span>
</li>
<li class="page-item active"><button class="page-link">1</button></li>';
  } else {
    $html .= '<li class="page-item">
  <span class="page-link pilih-pages" pages="' . $start - 1 . '">Previous</span>
</li>
<li class="page-item"><button class="page-link pilih-pages" pages="1">1...</button></li>';
  }

  if ($start > 2 and $start < $akhir) {
    $html .= '<li class="page-item" aria-current="page">
  <span class="page-link pilih-pages" pages="' . $start - 1 . '">' . $start - 1 . '</span>
</li>';
  }

  if ($start != 1 and $start < $akhir) {
    $html .= '<li class="page-item active" aria-current="page">
  <span class="page-link">' . $start . '</span>
</li>';
  }

  if (($start + 1) != $akhir and $start < $akhir) {
    $html .= '<li class="page-item" aria-current="page">
  <span class="page-link pilih-pages" pages="' . $start + 1 . '">' . $start + 1 . '</span>
</li>';
  }
  if (($start) != $akhir) {
    $html .= '<li class="page-item" aria-current="page">
  <span class="page-link pilih-pages" pages="' . $akhir . '">...' . $akhir . '</span>
</li>';
  } else {
    $html .= '
  <li class="page-item" aria-current="page">
  <span class="page-link pilih-pages" pages="' . $akhir - 1 . '">' . $akhir - 1 . '</span>
</li>
  <li class="page-item active" aria-current="page">
  <span class="page-link">' . $akhir . '</span>
</li>';
  }
  if ($start != $akhir and $start < $akhir) {
    $html .= '<li class="page-item">
  <span class="page-link pilih-pages" pages="' . $start + 1 . '">Next</span>
  </li>';
  } else {
    $html .= ' <li class="page-item disabled">
    <span class="page-link">Next</span>
  </li>';
  }
  $html .= ' </ul>
  </nav>
  ';
  echo $html;
}

function pages_kil($id, $start_start, $awal)
{
  $awal = $awal;
  $jum = jumlah("SELECT * FROM kil WHERE
  id_kil_header = '$id' AND
  status != 0");
  $pages = $jum / $awal;
  $cek_akhir = floor($pages);
  $start = $start_start;
  if (($cek_akhir * $awal) == $jum) {
    $akhir = $cek_akhir;
  } else {
    $akhir = $cek_akhir + 1;
  }
  $html = '
  <nav aria-label="...">
  <ul class="pagination pagination-sm m-0 float-right">';
  if ($start == 1) {
    $html .= '<li class="page-item disabled">
  <span class="page-link">Previous</span>
</li>
<li class="page-item active"><button class="page-link">1</button></li>';
  } else {
    $html .= '<li class="page-item">
  <span class="page-link pilih-pages" pages="' . $start - 1 . '">Previous</span>
</li>
<li class="page-item"><button class="page-link pilih-pages" pages="1">1...</button></li>';
  }

  if ($start > 2 and $start < $akhir) {
    $html .= '<li class="page-item" aria-current="page">
  <span class="page-link pilih-pages" pages="' . $start - 1 . '">' . $start - 1 . '</span>
</li>';
  }

  if ($start != 1 and $start < $akhir) {
    $html .= '<li class="page-item active" aria-current="page">
  <span class="page-link">' . $start . '</span>
</li>';
  }

  if (($start + 1) != $akhir and $start < $akhir) {
    $html .= '<li class="page-item" aria-current="page">
  <span class="page-link pilih-pages" pages="' . $start + 1 . '">' . $start + 1 . '</span>
</li>';
  }
  if (($start) != $akhir) {
    $html .= '<li class="page-item" aria-current="page">
  <span class="page-link pilih-pages" pages="' . $akhir . '">...' . $akhir . '</span>
</li>';
  } else {
    $html .= '
  <li class="page-item" aria-current="page">
  <span class="page-link pilih-pages" pages="' . $akhir - 1 . '">' . $akhir - 1 . '</span>
</li>
  <li class="page-item active" aria-current="page">
  <span class="page-link">' . $akhir . '</span>
</li>';
  }
  if ($start != $akhir and $start < $akhir) {
    $html .= '<li class="page-item">
  <span class="page-link pilih-pages" pages="' . $start + 1 . '">Next</span>
  </li>';
  } else {
    $html .= ' <li class="page-item disabled">
    <span class="page-link">Next</span>
  </li>';
  }
  $html .= ' </ul>
  </nav>
  ';
  echo $html;
}

function kil_jenis($id)
{
  return query("SELECT * FROM kil_jenis WHERE id_kil_jenis_nama = '$id'");
}

function kil_jenis_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil_jenis WHERE id_kil_jenis_nama = '$id'");
  return $a[$o];
}

function kil_jenis_satu_id($id, $o)
{
  $a = query_satu("SELECT * FROM kil_jenis WHERE id_kil_jenis = '$id'");
  return $a[$o];
}

function kil($id)
{
  return query("SELECT * FROM kil WHERE id_kil_header = '$id' AND status = 1");
}

function kil_customer_pilih($id)
{
  return query("SELECT * FROM kil WHERE id_kil_header = '$id' AND status = 1 AND
  id NOT IN(SELECT id_kil FROM kil_customer)");
}

function kil_id($id)
{
  $konek = konek();
  $user = user("id_user");
  $ri = riwayat();
  $cek = kil_jum_id($id);
  if ($cek > 0) {
    $a = query_satu("SELECT * FROM kil WHERE id_kil_header = '$id' AND
    id_user = '$user' AND
    status = '0'");
    $id_kil = $a["id"];
  } else {
    $a = mysqli_query($konek, "INSERT INTO kil (id_kil_header,edit,id_user) VALUES('$id','$ri','$user')");
    $id_kil = mysqli_insert_id($konek);
  }
  return $id_kil;
}

function kil_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil WHERE id = '$id'");
  return @$a[$o];
}

function kil_jum($id)
{
  return jumlah("SELECT * FROM kil WHERE id_kil_header = '$id' AND
  status = 1");
}

function kil_jum_id($id)
{
  $user = user("id_user");
  return jumlah("SELECT * FROM kil WHERE id_kil_header = '$id' AND
  id_user = '$user' AND
  status = 0");
}

function kil_identitas_jum($id, $o)
{
  return jumlah("SELECT * FROM kil_identitas WHERE
  id_kil = '$id' AND
  id_kil_identitas_jenis = '$o'");
}

function kil_identitas_satu($id, $o, $y)
{
  $a = query_satu("SELECT * FROM kil_identitas WHERE
  id_kil = '$id' AND
  id_kil_identitas_jenis = '$o'");
  return $a[$y];
}

function kil_identitas_id($id_kil, $id_kil_jenis)
{
  $konek = konek();
  $cek = kil_identitas_jum($id_kil, $id_kil_jenis);
  if ($cek > 0) {
    $id_kil_identitas = kil_identitas_satu($id_kil, $id_kil_jenis, "id");
  } else {
    @mysqli_query($konek, "INSERT INTO kil_identitas (id_kil,id_kil_identitas_jenis) VALUES('$id_kil','$id_kil_jenis')");
    $id_kil_identitas = mysqli_insert_id($konek);
  }
  return $id_kil_identitas;
}

function kil_identitas_alamat($id)
{
  return query("SELECT * FROM kil_identitas WHERE
  id_kil = '$id' AND
  ket IN(SELECT kelurahan FROM kil_alamat)");
}

function kil_identitas_alamat_jum($id)
{
  return jumlah("SELECT * FROM kil_identitas WHERE
  id_kil = '$id' AND
  ket IN(SELECT kelurahan FROM kil_alamat)");
}

function kil_telp_satu($id)
{
  $a = query_satu("SELECT * FROM kil_telp WHERE
  id_kil_identitas = '$id'");
  return $a["telp"];
}

function kil_telp($id)
{
  return query("SELECT * FROM kil_telp WHERE id_kil_identitas = '$id'");
}

function kil_email_satu($id)
{
  $a = query_satu("SELECT * FROM kil_email WHERE
  id_kil_identitas = '$id'");
  return $a["email"];
}

function kil_email($id)
{
  return query("SELECT * FROM kil_email WHERE
  id_kil_identitas = '$id'");
}

function kil_alamat_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil_alamat WHERE
  id_kil_identitas = '$id'");
  return @$a[$o];
}

function kil_alamat_jum($id)
{
  return jumlah("SELECT * FROM kil_alamat WHERE id_kil_identitas = '$id'");
}

// function kil_alamat_sesuaikan()
// {
//   $a = query("SELECT * FROM kil_alamat");
//   foreach($a as $b) :
//     $id_kil_identitas = $b["id_kil_identitas"];
//     $kel = $b["kelurahan"];
//     $kec = kel_lihat($kel,"district_id");
//     $kab = kec_lihat(kel_lihat($kel,"district_id"),"regency_id");
//     $prov = kab_lihat(kec_lihat(kel_lihat($kel,"district_id"),"regency_id"),"province_id");
//     query("UPDATE kil_alamat SET
//     province = '$prov',
//     kabupaten = '$kab',
//     kecamatan = '$kec'
//     WHERE
//     id_kil_identitas = '$id_kil_identitas' AND
//     kelurahan = '$kel'");
//   endforeach;
// }

function kil_nomor_satu($id, $o, $y)
{
  $a = query_satu("SELECT * FROM kil_nomor WHERE
  id_kil = '$id' AND
  id_nomor_jenis = '$o'");
  return $a[$y];
}

function kil_contact_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil_contact WHERE
  id_kil_identitas = '$id'");
  return @$a[$o];
}



function kil_status($id)
{
  return query("SELECT * FROM kil_status WHERE id_kil = '$id'");
}

function kil_bank($id)
{
  return query("SELECT * FROM kil_bank WHERE id_kil = '$id'");
}

function kil_bank_jum($id, $o, $y)
{
  return jumlah("SELECT * FROM kil_bank WHERE
  id_kil = '$id' AND
  id_bank = '$o' AND
  norek = '$y'");
}

function kil_armada($id)
{
  return query("SELECT * FROM kil_armada WHERE
  id_kil = '$id'");
}

function kil_karyawan($id)
{
  return query("SELECT * FROM kil_karyawan WHERE id_kil = '$id'");
}

function kil_karyawan_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil_karyawan WHERE
  id_kil = '$id'");
  return @$a[$o];
}

function kil_karyawan_telp($id, $o, $nama)
{
  return query("SELECT * FROM kil_karyawan_telp WHERE
  id_kil = '$id' AND
  id_karyawan_jenis = '$o' AND
  nama = '$nama'");
}

function kil_karyawan_telp_satu($id, $o, $nama, $y)
{
  $a = query_satu("SELECT * FROM kil_karyawan_telp WHERE
  id_kil = '$id' AND
  id_karyawan_jenis = '$o' AND
  nama = '$nama'");
  return @$a[$y];
}

function kil_area($id)
{
  return query("SELECT * FROM kil_area WHERE id_kil = '$id'");
}

function kil_area_jum($id)
{
  return jumlah("SELECT * FROM kil_area WHERE id_kil = '$id'");
}

function kil_plafond_satu($id, $y, $o)
{
  $a = query_satu("SELECT * FROM kil_pafond WHERE
  id_kil = '$id' AND
  id_kil_plafond_jenis = '$y'");
  return $a[$o];
}

function kil_produk_jum($id, $o)
{
  return jumlah("SELECT * FROM kil_produk WHERE
  id_kil = '$id' AND
  agent = '$o'");
}

function kil_produk($id, $o)
{
  return query("SELECT * FROM kil_produk WHERE
  id_kil = '$id' AND
  agent = '$o'");
}

function kil_identitas_nama_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil_identitas_nama WHERE
  id_kil_identitas = '$id'");
  return $a[$o];
}

function kil_identitas_contact($id)
{
  return query("SELECT * FROM kil_identitas WHERE id_kil = '$id' AND
  id IN(SELECT id_kil_identitas FROM kil_contact)");
}

function kil_identitas_contact_jum($id)
{
  return jumlah("SELECT * FROM kil_identitas WHERE id_kil = '$id' AND
  id IN(SELECT id_kil_identitas FROM kil_contact)");
}

function kil_distributor_stockis_jum($id)
{
  return jumlah("SELECT * FROM kil_distributor_stockis WHERE
  id_kil = '$id'");
}

function kil_distributor_stockis($id)
{
  return query("SELECT * FROM kil_distributor_stockis WHERE
  id_kil = '$id'");
}

function do_armada_satu($id, $o)
{
  $a = query_satu("SELECT * FROM do_armada WHERE no_do = '$id'");
  return $a[$o];
}

function do_armada($id)
{
  return query("SELECT * FROM do_armada WHERE nama_supir = '$id'");
}

function kil_objek_jum($id)
{
  return jumlah("SELECT * FROM kil_objek WHERE id_kil = '$id'");
}

function kil_objek_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil_objek WHERE id_kil = '$id'");
  return @$a[$o];
}

function kil_prangko_gudang_jum($id)
{
  return jumlah("SELECT * FROM kil_prangko_gudang WHERE id_kil = '$id'");
}

function kil_prangko_gudang_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil_prangko_gudang WHERE id_kil = '$id'");
  return @$a[$o];
}

function kil_prangko_gudang_produk_jum($id, $o)
{
  return jumlah("SELECT * FROM kil_prangko_gudang_produk WHERE id_kil_prangko_gudang = '$id' AND
  nama_produk = '$o'");
}

function kil_prangko_gudang_produk_jum_all($id)
{
  $kil_prangko_gudang = kil_prangko_gudang_satu($id, "id");
  return jumlah("SELECT * FROM kil_prangko_gudang_produk WHERE id_kil_prangko_gudang = '$kil_prangko_gudang'");
}

function kil_prangko_gudang_produk($id)
{
  $kil_prangko_gudang = kil_prangko_gudang_satu($id, "id");
  return query("SELECT * FROM kil_prangko_gudang_produk WHERE
  id_kil_prangko_gudang = '$kil_prangko_gudang'");
}

function kil_type_toko($id)
{
  return query("SELECT * FROM kil_type_toko WHERE id_kil = '$id'");
}

function kil_kategori_toko($id)
{
  return query("SELECT * FROM kil_kategori_toko WHERE id_kil = '$id'");
}

function kil_jenis_pembayaran($id)
{
  return query("SELECT * FROM kil_jenis_pembayaran WHERE id_kil = '$id'");
}

function kil_fax_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil_fax WHERE
  id_kil_identitas = '$id'");
  return @$a[$o];
}

function kil_web_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil_web WHERE
  id_kil = '$id'");
  return @$a[$o];
}

function kil_contact($id)
{
  return query("SELECT * FROM kil_contact WHERE
  id_kil_identitas = '$id'");
}

function kil_depo_cabang($id)
{
  return query("SELECT * FROM kil_depo_cabang WHERE id_kil = '$id'");
}

function kil_area_distribusi($id)
{
  return query("SELECT * FROM kil_area_distribusi WHERE id_kil = '$id'");
}

function kil_karyawan_jumlah($id)
{
  return query("SELECT * FROM kil_karyawan_jumlah WHERE id_kil = '$id'");
}

function kil_karyawan_jumlah_jum($id)
{
  return jumlah("SELECT * FROM kil_karyawan_jumlah WHERE id_kil = '$id'");
}

function kil_pelanggan($id)
{
  return query("SELECT * FROM kil_pelanggan WHERE id_kil = '$id'");
}

function kil_pelanggan_jum($id)
{
  return jumlah("SELECT * FROM kil_pelanggan WHERE id_kil = '$id'");
}

function kil_principals($id)
{
  return query("SELECT * FROM kil_principals WHERE id_kil = '$id'");
}

function kil_principals_jum($id)
{
  return jumlah("SELECT * FROM kil_principals WHERE id_kil = '$id'");
}

function kil_area_distribusi_produk_satu($id, $o)
{
  $a = query_satu("SELECT * FROM kil_area_distribusi_produk WHERE
  id_kil = '$id'");
  return $a[$o];
}

function kil_area_distribusi_produk_jum($id)
{
  return jumlah("SELECT * FROM kil_area_distribusi_produk WHERE id_kil = '$id'");
}

function kil_customer($id, $o)
{
  $a = query_satu("SELECT * FROM kil_customer WHERE id_customer = '$id' or id_kil = '$id'");
  return @$a[$o];
}

function kil_customer_jum_kil($id)
{
  return jumlah("SELECT * FROM kil_customer WHERE id_kil = '$id'");
}

function kil_customer_jum_customer($id)
{
  return jumlah("SELECT * FROM kil_customer WHERE id_customer = '$id'");
}

function wo_produksi()
{
  $sekarang = date("Y-m-d");
  return query("SELECT * FROM wo WHERE
  id NOT IN(SELECT id_wo FROM produksi) AND
  tgl_akhir_berlaku >= '$sekarang' AND
  id IN(SELECT id_wo FROM wo_jadwal_produksi)");
}

function wo_produksi_jum($id)
{
  return jumlah("SELECT * FROM produksi WHERE id_wo = '$id'");
}

function wo_jenis($id)
{
  return query("SELECT * FROM wo_jenis WHERE id_wo_jenis_nama = '$id'");
}

function wo_jenis_satu($id, $o)
{
  $a = query_satu("SELECT * FROM wo_jenis WHERE
  id = '$id'");
  return @$a[$o];
}

function wo_satu($id, $o)
{
  $a = query_satu("SELECT * FROM wo WHERE id = '$id'");
  return @$a[$o];
}

function wo()
{
  return query("SELECT * FROM wo");
}

function wo_check($id)
{
  if (jumlah("SELECT * FROM wo WHERE id = '$id'") < 1) {
    echo "<script>location='?halaman=working-order'</script>";
  }
}

function wo_today()
{
  $today = date("Y-m-d");
  return query("SELECT * FROM wo WHERE
  date(buat) = '$today'");
}

function wo_allin()
{
  return query("SELECT * FROM wo ");
}

function wo_date_search($id)
{
  return query("SELECT * FROM wo WHERE
  date(buat) = '$id'");
}

function wo_month_search($bulan, $tahun)
{
  return query("SELECT * FROM wo WHERE
  month(buat) = '$bulan' AND
  year(buat) = '$tahun'");
}

function wo_year_search($id)
{
  return query("SELECT * FROM wo WHERE
  year(buat) = '$id'");
}

function wo_section1_id($id)
{
  $konek = konek();
  $jum = jumlah("SELECT * FROM wo_section1 WHERE
  id_wo = '$id'");
  if ($jum > 0) {
    $cek = query_satu("SELECT id FROM wo_section1 WHERE
    id_wo = '$id'");
    $id = $cek["id"];
  } else {
    mysqli_query($konek, "INSERT INTO wo_section1 VALUES(null,'$id','')");
    $id = mysqli_insert_id($konek);
  }
  return $id;
}

function wo_section1($id)
{
  $a = query_satu("SELECT * FROM wo_section1 WHERE
  id = '$id' OR
  id_wo = '$id'");
  return @$a["jumlah_berat_hasil_produk"];
}

function wo_section1_satu($id_wo, $o)
{
  $a = query_satu("SELECT * FROM wo_section1 WHERE
  id_wo = '$id_wo'");
  return $a[$o];
}

function wo_section1_detail_jum($id, $o, $y)
{
  return jumlah("SELECT * FROM wo_section1_detail WHERE
  id_wo_section1 = '$id' AND
  id_bom_detail = '$o' AND
  id_wo_jenis = '$y'");
}

function wo_section1_detail_satu($id, $o, $y, $u)
{
  $a = query_satu("SELECT * FROM wo_section1_detail WHERE
  id_wo_section1 = '$id' AND
  id_bom_detail = '$o' AND
  id_wo_jenis = '$y'");
  return @$a[$u];
}

function wo_section1_satuan_satu($id, $o, $e, $y)
{
  $id_wo_section1 = wo_section1_id($id);
  $a = query_satu("SELECT * FROM wo_section1_satuan WHERE
  id_wo_section1 = '$id_wo_section1' AND
  id_produk = '$o' AND
  id_wo_jenis = '$e'");
  return @$a[$y];
}

function wo_section1_satuan_jum($id)
{
  return jumlah("SELECT * FROM wo_section1_satuan WHERE id_wo_section1 = '$id'");
}

function wo_section1_satuan($id)
{
  return query("SELECT * FROM wo_section1_satuan WHERE id_wo_section1 = '$id'");
}

function wo_reciep_satuan_satu($id, $o, $y)
{
  $a = query_satu("SELECT * FROM wo_reciep_satuan WHERE
  id_wo_section1 = '$id' AND
  id_produk = '$o'");
  return @$a[$y];
}

function wo_reciep_satuan($id)
{
  return query("SELECT * FROM wo_reciep_satuan WHERE
  id_wo_section1 = '$id'");
}

function wo_reciep_satuan_jum($id)
{
  return jumlah("SELECT * FROM wo_reciep_satuan WHERE
  id_wo_section1 = '$id'");
}

function wo_reciep_satuan_detail_satu($id, $o, $y)
{
  $a = query_satu("SELECT * FROM wo_reciep_satuan_detail WHERE
  id_wo_reciep_satuan = '$id' AND
  id_wo_jenis = '$o'");
  return @$a[$y];
}

function wo_section2_jum($id)
{
  return jumlah("SELECT * FROM wo_section2 WHERE id_wo = '$id'");
}

function wo_section2_satu($id, $o)
{
  $a = query_satu("SELECT * FROM wo_section2 WHERE id_wo = '$id' or id = '$id'");
  return @$a[$o];
}

function wo_section2_header_jum($id)
{
  return jumlah("SELECT * FROM wo_section2_header WHERE
  id_wo_section2 = '$id'");
}

function wo_section2_header($id)
{
  return query("SELECT * FROM wo_section2_header WHERE
  id_wo_section2 = '$id'");
}

function wo_section2_header_satu($id, $o)
{
  $a = query_satu("SELECT * FROM wo_section2_header WHERE id_wo_section2 = '$id'");
  return @$a[$o];
}

function wo_section2_header_tot_qty_plastik($id)
{
  foreach (wo_section2_header($id) as $ws2h) :
    $qty_plastik = $ws2h["qty_plastik"];
    @$tot_qty_plastik += $qty_plastik;
  endforeach;
  return $tot_qty_plastik;
}

function wo_section2_detail_satu($id, $o, $y)
{
  $a = query_satu("SELECT * FROM wo_section2_detail WHERE
  id_wo_section2_header = '$id' AND
  wo_jenis_section2 = '$o'");
  return @$a[$y];
}

function wo_section2_detail_total($oke)
{
  $id_wo_section2 = wo_section2_satu($oke, "id");
  foreach (wo_section2_header($id_wo_section2) as $ws2h) :
    $id = $ws2h["id"];
    $qty = wo_section2_detail_satu($id, 11, "qty");
    @$tot_qty += $qty;
  endforeach;
  if (wo_section2_link_bsj_jum($id_wo_section2) > 0) {
    $satuan_bsj_link = wo_section2_link_bsj_satu($id_wo_section2, "id_satuan");
    $qty_bsj_link = wo_section2_link_bsj_satu($id_wo_section2, "qty");
    $satuan_sec2 = wo_section2_satu($oke, "id_satuan");
    $id_produk = bom_satu(wo_satu($oke, "id_bom"), "id_produk");
    $nilai = produk_satuan_nilai($id_produk, $satuan_sec2, $satuan_bsj_link, "nilai");
    $total = ($qty_bsj_link / $nilai) + $tot_qty;
  } else {
    $total = $tot_qty;
  }
  return $total;
}

function wo_section2_detail_total_bs_plastik($id_wo)
{
  $id_wo_section2 = wo_section2_satu($id_wo, "id");
  foreach (wo_section2_header($id_wo_section2) as $ws2h) :
    $qty_plastik_bs_sec2 = wo_section2_detail_satu($ws2h["id"], 12, "qty");
    @$tot_qty_plastik_bs_sec2 += $qty_plastik_bs_sec2;
  endforeach;
  return @$tot_qty_plastik_bs_sec2;
  //echo "Sedang dalam pengembangan";
}

function wo_section2_detail_total_bs_bb($id_wo)
{
  $id_wo_section2 = wo_section2_satu($id_wo, "id");
  foreach (wo_section2_header($id_wo_section2) as $ws2h) :
    $qty_bb_sec2 = wo_section2_detail_satu($ws2h["id"], 13, "qty");
    @$tot_bb_sec2 += $qty_bb_sec2;
  endforeach;
  return @$tot_bb_sec2;
  //echo "Sedang dalam pengembangan";
}

function wo_section2_link_bsj_jum($id)
{
  return jumlah("SELECT * FROM wo_section2_link_bsj WHERE
  id_wo_section2 = '$id'");
}

function wo_section2_link_bsj_satu($id, $o)
{
  $a = query_satu("SELECT * FROM wo_section2_link_bsj WHERE
  id_wo_section2 = '$id'");
  return $a[$o];
}

function wo_section2_link_bsj_total($oke)
{
  $id_wo_section2 = wo_section2_satu($oke, "id");
  if (wo_section2_link_bsj_jum($id_wo_section2) > 0) {
    $satuan_bsj_link = wo_section2_link_bsj_satu($id_wo_section2, "id_satuan");
    $satuan_sec2 = wo_section2_satu($oke, "id_satuan");
    $id_produk = bom_satu(wo_satu($oke, "id_bom"), "id_produk");
    $nilai = produk_satuan_nilai($id_produk, $satuan_sec2, $satuan_bsj_link, "nilai");
  } else {
    $nilai = 0;
  }
  return $nilai;
}

function wo_section3_satu($id, $o)
{
  $a = query_satu("SELECT * FROM wo_section3 WHERE
  id_wo = '$id'");
  return $a[$o];
}

function wo_section3_detail_jum($id)
{
  return jumlah("SELECT * FROM wo_section3_detail WHERE id_wo_section3 = '$id'");
}

function wo_section3_detail_satu($id, $o)
{
  $a = query_satu("SELECT * FROM wo_section3_detail WHERE
  id_wo_section3 = '$id'");
  return @$a[$o];
}

function wo_section3_detail($id)
{
  return query("SELECT * FROM wo_section3_detail WHERE
  id_wo_section3 = '$id'");
}

function wo_section3_detail_total_qty($id)
{
  foreach (wo_section3_detail(wo_section3_satu($id, "id")) as $ws3d) :
    $qty = $ws3d["qty"];
    @$tot_qty += $qty;
  endforeach;
  return @$tot_qty;
}

function wo_section3_header_jum($id)
{
  return jumlah("SELECT * FROM wo_section3_header WHERE
  id_wo_section3 = '$id'");
}

function wo_section3_header_satu($id, $o)
{
  $a = query_satu("SELECT * FROM wo_section3_header WHERE
  id_wo_section3 = '$id'");
  return @$a[$o];
}

function wo_section3_header_wo_jenis_satu($id, $y, $o)
{
  $a = query_satu("SELECT * FROM wo_section3_header WHERE
  id_wo_section3 = '$id' AND
  id_wo_jenis = '$y'");
  return @$a[$o];
}

function wo_tambah_sisa_jum($id, $o)
{
  return jumlah("SELECT * FROM wo_tambah_sisa WHERE
  id_wo = '$id' AND
  id_wo_jenis = '$o'");
}

function wo_tambah_sisa_satu($id, $o, $y)
{
  $a = query_satu("SELECT * FROM wo_tambah_sisa WHERE
  id_wo = '$id' AND
  id_wo_jenis = '$o'");
  return $a[$y];
}

function wo_losspacking($id)
{
  return query("SELECT * FROM wo_losspacking WHERE id_wo_section1 = '$id'");
}

function wo_losspacking_satu($id, $a, $o)
{
  $b = query_satu("SELECT * FROM wo_losspacking
  WHERE
  id_wo_section1 = '$id' AND
  id_wo_jenis = '$a'");
  return $b[$o];
}

function wo_losspacking_jum($id)
{
  return jumlah("SELECT * FROM wo_losspacking WHERE
  id_wo_section1 = '$id'");
}

function wo_metode_lhp_satu($id_wo, $id_wo_section, $id_wo_jenis_bs, $o)
{
  $a = query_satu("SELECT * FROM wo_metode_lhp WHERE
  id_wo = '$id_wo' AND
  id_wo_section = '$id_wo_section' AND
  id_wo_jenis_bs = '$id_wo_jenis_bs'
  ");
  return @$a[$o];
}

function wo_metode_lhp_jum($id_wo, $id_wo_section, $id_wo_jenis_bs)
{
  return jumlah("SELECT * FROM wo_metode_lhp WHERE
  id_wo = '$id_wo' AND
  id_wo_section = '$id_wo_section' AND
  id_wo_jenis_bs = '$id_wo_jenis_bs'");
}

function wo_status($id)
{
  $a = query_satu("SELECT id_wo_jenis FROM wo_status WHERE id_wo = '$id'");
  return $a["id_wo_jenis"];
}

function wo_riwayat($id)
{
  return query("SELECT * FROM wo_riwayat WHERE id_wo = '$id'");
}

function wo_bom_today()
{
  $date = date("Y-m-d");
  return query("SELECT * FROM wo_bom WHERE
  date(buat) = '$date'");
}

function wo_bom_satu($id, $a)
{
  $b = query_satu("SELECT * FROM wo_bom WHERE id_wo = '$id'");
  return $b[$a];
}

function wo_bom_jumlah($id)
{
  return jumlah("SELECT * FROM wo_bom WHERE id = '$id'");
}

function wo_bom_check($id)
{
  if (wo_bom_jumlah($id) < 1) {
    echo "<script>
    location='?halaman=bill-of-materials';
    </script>";
  }
}

function wo_bom_header_jum($id)
{
  return jumlah("SELECT * FROM wo_bom_header WHERE id_wo_bom = '$id'");
}

function wo_bom_header_satu($id, $o, $y)
{
  $a = query_satu("SELECT * FROM wo_bom_header WHERE
  id_wo_bom = '$id' AND
  id_produk = '$o'");
  return @$a[$y];
}

function wo_bom_header_detail_satu($id, $y, $o)
{
  $a = query_satu("SELECT * FROM wo_bom_header_detail WHERE
  id_wo_bom_header = '$id' AND
  id_wo_jenis = '$y'");
  return @$a[$o];
}

function wo_bom_header_detail_jum($id_wo_jenis, $id_wo_bom)
{
  return jumlah("SELECT * FROM wo_bom_header_detail WHERE
  id_wo_jenis = '$id_wo_jenis' AND
  id_wo_bom = '$id_wo_bom'");
}

function wo_bom_header($id)
{
  return query("SELECT * FROM wo_bom_header WHERE id_wo_bom = '$id'");
}

function wo_jadwal_produksi_jum($id)
{
  return jumlah("SELECT * FROM wo_jadwal_produksi WHERE id_wo = '$id'");
}

function wo_jadwal_produksi_satu($id, $o)
{
  $a = query_satu("SELECT * FROM wo_jadwal_produksi WHERE id_wo = '$id'");
  return $a[$o];
}

// function wo_update_satuan()
// {
//   $a = query("SELECT * FROM bom_reciep_satuan");
//   foreach($a as $b) :
//     query("UPDATE wo SET id_satuan = '$b[id_satuan]'
//     WHERE
//     id_bom = '$b[id_bom]'");
//   endforeach;
// }

function produksi_today()
{
  $hari_ini = date("Y-m-d");
  return query("SELECT * FROM produksi WHERE
  date(buat) = '$hari_ini'");
}

function produksi_all()
{
  return query("SELECT * FROM produksi");
}

function produksi_satu($id, $o)
{
  $a = query_satu("SELECT * FROM produksi WHERE
  id_wo = '$id'");
  return $a[$o];
}

function tindakan_riwayat_satu($id, $o)
{
  $a = query_satu("SELECT * FROM tindakan_riwayat WHERE
id_tindakan_riwayat = '$id'");
  return $a[$o];
}

function produk_stok_riwayat_satu($id, $o)
{
  $a = query_satu("SELECT * FROM produk_stok_riwayat WHERE id_user = '$id'");
  return $a[$o];
}

function produk_stok_riwayat($id_produk)
{
  return query("SELECT * FROM produk_stok_riwayat WHERE id_produk = '$id_produk' ORDER BY tgl DESC");
}

function bulan_nama($id)
{
  $a = query_satu("SELECT nama FROM bulan WHERE id = '$id'");
  return $a["nama"];
}

function bulan_all()
{
 
  return query("SELECT * FROM bulan");
}

function pp_year()
{
  $tahun = date("Y");
  return query("SELECT * FROM pp WHERE
  tahun = '$tahun'");
}

function pp_year_pilih($tahun)
{
  return query("SELECT * FROM pp WHERE tahun = '$tahun'");
}

function pp_satu($id, $o)
{
  $a = query_satu("SELECT * FROM pp WHERE id = '$id'");
  return $a[$o];
}

function pp_jenis($id)
{
  return query("SELECT * FROM pp_jenis WHERE id_pp_jenis_header = '$id'");
}

function pp_jenis_satu($id, $o)
{
  $a = query_satu("SELECT * FROM pp_jenis WHERE id = '$id'");
  return $a[$o];
}

function pp_detail_check($id)
{
  $cek = jumlah("SELECT * FROM pp WHERE id = '$id'");
  if ($cek < 1) {
    echo "<script>
    location='?halaman=planning';
    </script>";
  }
}

function pp_week($id)
{
  return query("SELECT * FROM pp_week WHERE id_pp = '$id'
  ORDER BY id_pp_jenis ASC");
}

function pp_week_jenis($id, $jenis, $isi)
{
  $a = query_satu("SELECT * FROM pp_week WHERE
  id_pp = '$id' AND
  id_pp_jenis = '$jenis'");
  return $a[$isi];
}

function pp_week_jum($id)
{
  return jumlah("SELECT * FROM pp_week WHERE id_pp = '$id'");
}

function pp_week_satu($id_pp, $id_pp_jenis, $isi)
{
  $a = query_satu("SELECT * FROM pp_week WHERE
  id_pp = '$id_pp' AND
  id_pp_jenis = '$id_pp_jenis'");
  return $a[$isi];
}

function pp_produk_header($id)
{
  return query("SELECT * FROM pp_produk_header WHERE id_pp = '$id'");
}

function pp_produk_header_satu($id_pp, $id_produk, $isi)
{
  $a = query_satu("SELECT * FROM pp_produk_header WHERE
  id_pp = '$id_pp' AND
  id_produk = '$id_produk'");
  return $a[$isi];
}

function pp_sdm_satu($id_pp, $date, $isi)
{
  $a = query_satu("SELECT * FROM pp_sdm WHERE
  id_pp = '$id_pp' AND
  date = '$date'");
  return @$a[$isi];
}

function pp_qty_satu($id_pp, $id_produk, $date, $isi)
{
  $a = query_satu("SELECT * FROM pp_qty WHERE
  id_pp = '$id_pp' AND
  id_produk = '$id_produk' AND
  date = '$date'");
  return @$a[$isi];
}

function pp_qty_total($id_pp, $id_produk, $id_pp_jenis_week)
{
  $a = query("SELECT * FROM pp_qty WHERE id_pp = '$id_pp' AND id_produk = '$id_produk' AND
  id_pp_jenis_week = '$id_pp_jenis_week'");
  foreach ($a as $b) :
    @$total += $b["value"];
  endforeach;
  return @$total;
}

function pp_qty_total_kesamping($id_pp, $id_produk)
{
  $a = query("SELECT * FROM pp_qty WHERE id_pp = '$id_pp' AND id_produk = '$id_produk'");
  foreach ($a as $b) :
    @$total += $b["value"];
  endforeach;
  return @$total;
}

function pp_tahun()
{
  return query("SELECT distinct tahun FROM pp ORDER BY tahun ASC");
}

# onlineshop
function get_carts($id)
{
  if (!empty($id)) {
    return query("SELECT * FROM cart WHERE id_user = '$id'");
  };
}

function get_username_os($id)
{
  if (!empty($id)) {
    $u = @query_satu("SELECT * FROM user_onlineshop WHERE id_user = '$id'");
    if (!empty($u)) {
      return $u["username"];
    }
  }
}

function status_pesanan_os($id) {
  return @query_satu("SELECT * FROM status_pesanan_os WHERE id_status = '$id'")["nama_status"];
}

function class_pesanan_os($id) {
  return @query_satu("SELECT * FROM status_pesanan_os WHERE id_status = '$id'")["class"];
}

function get_product_os_name($id)
{
  if (!empty($id)) {
    $p = @query_satu("SELECT * FROM produk_online WHERE id_produk = '$id'");
    if (!empty($p)) {
      return $p["judul_online"];
    }
  }
}

function pp_total($id_pp)
{
  query("DELETE FROM pp_total_per_satuan WHERE id_pp = '$id_pp'");
  $cek_satuan_produk_header = query("SELECT distinct id_satuan FROM pp_produk_header WHERE
  id_pp = '$id_pp'");
  foreach ($cek_satuan_produk_header as $csph) {
    $kk = query("SELECT * FROM pp_produk_header,
    pp_qty
    WHERE
    pp_qty.id_pp = '$id_pp' AND
    pp_qty.id_produk = pp_produk_header.id_produk AND
    pp_produk_header.id_satuan = '$csph[id_satuan]' AND
    pp_produk_header.id_pp = '$id_pp'");
    foreach ($kk as $k) {
      $cek = jumlah("SELECT * FROM pp_total_per_satuan WHERE
      id_pp = '$id_pp' AND
      id_satuan = '$csph[id_satuan]'");
      if ($cek > 0) {
        $totot = pp_total_per_satuan($id_pp, $csph["id_satuan"]) + $k["value"];
        query("UPDATE pp_total_per_satuan SET total = '$totot'
        WHERE
        id_pp = '$id_pp' AND
        id_satuan = '$csph[id_satuan]'");
      } else {
        query("INSERT INTO pp_total_per_satuan VALUES('$id_pp','$csph[id_satuan]','$k[value]')");
      }
    }
  }
}

function pp_total_per_satuan($id_pp, $satuan)
{
  $a = query_satu("SELECT * FROM pp_total_per_satuan WHERE
  id_pp = '$id_pp' AND
  id_satuan = '$satuan'");
  return @$a["total"];
}

function pp_total_per_satuan_all($id_pp)
{
  return query("SELECT * FROM pp_total_per_satuan WHERE id_pp = '$id_pp'");
}

function get_all_order_os()
{
  return @query("SELECT * FROM pesanan_os");
}

function get_data_order_os_byid($id)
{
  return @query_satu("SELECT * FROM pesanan_os WHERE id = '$id'");
}

function retur_cust_satu($id_retur,$isi)
{
  $a = query_satu("SELECT * FROM retur_cust WHERE id_retur = '$id_retur'");
  return $a[$isi];
}

function retur_cust_jum($id_retur)
{
  return jumlah("SELECT * FROM retur_cust WHERE id_retur = '$id_retur'");
}

function retur_kode_satu($id_retur,$isi)
{
  $a = query_satu("SELECT * FROM retur_kode WHERE
  id_retur = '$id_retur'");
  return @$a[$isi];
}

function retur_kode_jum($id_retur)
{
  return jumlah("SELECT * FROM retur_kode WHERE id_retur = '$id_retur'");
}

function retur_detail_jum($id_retur)
{
  return jumlah("SELECT * FROM retur_detail WHERE id_retur = '$id_retur'");
}

function retur_detail($id_retur)
{
  return query("SELECT * FROM retur_detail WHERE id_retur = '$id_retur'");
}



function retur_detail_satu($id_retur,$id_produk,$isi)
{
  $a = query_satu("SELECT * FROM retur_detail WHERE
  id_retur = '$id_retur' AND
  id_produk = '$id_produk'");
  return $a[$isi];
}

function retur_detail_diskon_satu($id_retur,$id_produk,$isi)
{
  $a = query_satu("SELECT * FROM retur_detail_diskon WHERE
  id_retur = '$id_retur' AND
  id_produk = '$id_produk'");
  return $a[$isi];
}

function retur_total($id_retur)
{
  foreach(retur_detail($id_retur) as $rd) :
    if ($rd["id_diskon_jenis_nama"] == 0) {
      $diskon = 0;
    }elseif ($rd["id_diskon_jenis_nama"] == 1) {
      $diskon = retur_detail_diskon_satu($id_retur,$rd["id_produk"],"nilai");
    }elseif ($rd["id_diskon_jenis_nama"] == 2) {
      $diskon = retur_detail_diskon_satu($id_retur,$rd["id_produk"],"nilai")*$rd["harga"]/100;
    }
    $tot = ($rd["harga"]-$diskon)*$rd["qty"];
    @$tot_tot += $tot;
  endforeach;
  if (retur_diskon_jum($id_retur)>0) {
    if (retur_diskon_satu($id_retur,"id_diskon_jenis_nama") == 1) {
      $diskon_retur = retur_diskon_satu($id_retur,"nilai");
    }elseif (retur_diskon_satu($id_retur,"id_diskon_jenis_nama") == 2) {
      $diskon_retur = retur_diskon_satu($id_retur,"nilai")*@$tot_tot/100;
    }
  }else {
    $diskon_retur = 0;
  }
  @$all_tot = @$tot_tot - $diskon_retur;
  return @$all_tot;
}

function retur_jenis()
{
  return query("SELECT * FROM retur_jenis");
}

function retur_jenis_satu($id_retur_jenis)
{
  $a = query_satu("SELECT * FROM retur_jenis WHERE
  id = '$id_retur_jenis'");
  return @$a["nama"];
}

function retur_satu($id,$isi)
{
  $a = query_satu("SELECT * FROM retur WHERE id = '$id'");
  return $a[$isi];
}

function retur_today()
{
  $hari = date("Y-m-d");
  return query("SELECT * FROM retur WHERE
  date(edit) = '$hari' AND
  id_status != 44");
}

function retur_report_today($id_report)
{
  $hari = date("Y-m-d");
  return query("SELECT * FROM retur WHERE
  date(edit) = '$hari' AND
  id_report = '$id_report' AND
  id_status != 44");
}

function retur_diskon_jum($id_retur)
{
  return jumlah("SELECT * FROM retur_diskon WHERE id_retur = '$id_retur'");
}

function retur_diskon_satu($id_retur,$isi){
  $a = query_satu("SELECT * FROM retur_diskon WHERE
  id_retur = '$id_retur'");
  return $a[$isi];
}

function retur_suplier($id_retur,$isi)
{
  $a = query_satu("SELECT * FROM retur_suplier WHERE
  id_retur = '$id_retur'");
  return $a[$isi];
}

function retur_alasan_satu($id_retur,$isi)
{
  $a = query_satu("SELECT * FROM retur_alasan WHERE
  id_retur = '$id_retur'");
  return @$a[$isi];
}

function si_bruto_total($id_si)
{
  if (si_stok_pajak_jumlah($id_si)>0) {
    foreach(si_stok_detail($id_si) as $nb) :
    $k = "1.".si_stok_pajak($id_si,"persen");
    $harga = ($nb["harga"]/$k);
    if ($nb["diskon_jenis_nama"] == 0) {
      $diskon = 0;
    }elseif ($nb["diskon_jenis_nama"] == 1) {
      $diskon = si_stok_detail_diskon_satu($nb["id_si"],$nb["id_produk"],"value");
    }elseif ($nb["diskon_jenis_nama"] == 2) {
      $diskon = si_stok_detail_diskon_satu($nb["id_si"],$nb["id_produk"],"value")*$harga/100;
    }
    $harga_dong = ($harga-$diskon)*$nb["qty"];
    @$tot += ($harga_dong);
    endforeach;
  }else {
    foreach(si_stok_detail($id_si) as $nb) :
      if ($nb["diskon_jenis_nama"] == 0) {
        $diskon = 0;
      }elseif ($nb["diskon_jenis_nama"] == 1) {
        $diskon = si_stok_detail_diskon_satu($nb["id_si"],$nb["id_produk"],"value");
      }elseif ($nb["diskon_jenis_nama"] == 2) {
        $diskon = si_stok_detail_diskon_satu($nb["id_si"],$nb["id_produk"],"value")*$nb["harga"]/100;
      }

      $harga = ($nb["harga"]-$diskon) * $nb["qty"];
      @$tot += $harga;
    endforeach;
  }
  return @$tot;
}

function si_netto($id_si)
{
  $tot = si_bruto_total($id_si);
  return $tot;
}


function ewallet()
{
  return query("SELECT * FROM e_wallet ORDER BY nama ASC");
}

function ewallet_satu($id,$isi)
{
  $a = query_satu("SELECT * FROM e_wallet WHERE id = '$id'");
  return $a[$isi];
}

function ewallet_kecuali($id_ewallet)
{
  return query("SELECT * FROM e_wallet WHERE
  id != '$id_ewallet'");
}

function ewallet_data()
{
  return query("SELECT * FROM e_wallet_data ORDER BY id_ewallet ASC");
}

function e_wallet_data_satu($id,$isi)
{
  $a = query_satu("SELECT * FROM e_wallet_data WHERE
  id = '$id'");
  return $a[$isi];
}

function tampil_si_piutang (){
  $i = [];
  $a = query("SELECT * FROM si, so, si_so, so_detail,
  so_tot, si_stok, si_stok detail 
  WHERE si.id_si = si_so.id_si");
 
}

function hutang_sisa($id_suplier)
{
  if (jumlah("SELECT * FROM gr WHERE id_suplier = '$id_suplier' AND
  no_gr IN(SELECT kode FROM invoice_header)")>0) {
    $q = query("SELECT * FROM gr, invoice_header WHERE
    invoice_header.kode = gr.no_gr AND
    gr.id_suplier = '$id_suplier'");
    foreach($q as $qs) :
if (invoice_jumlah($qs["no_invoice"])>0) {
    $jum =+ invoice_satu($qs["no_invoice"],"value");
  }
  endforeach;
  return $jum;
  }
}

function hutang_cek_jum($id_suplier)
{
  $cek = jumlah("SELECT * FROM hutang WHERE
  id_suplier = '$id_suplier' AND
  id_status = 49");
  return $cek;
}

function hutang_not_save($id_suplier,$isi)
{
  $a = query_satu("SELECT * FROM hutang WHERE
  id_suplier = '$id_suplier' AND
  id_status = 49");
  return $a[$isi];
}

function hutang_satu($id,$isi)
{
  $a = query_satu("SELECT * FROM hutang WHERE
  id = '$id'");
  return $a[$isi];
}

function hutang_faktur($id_hutang)
{
  $a = query("SELECT * FROM hutang_faktur WHERE
  id_hutang = '$id_hutang'");
  return $a;
}

function hutang_faktur_invoice_jum($id_hutang,$no_invoice)
{
  return jumlah("SELECT * FROM hutang_faktur WHERE
  id_hutang = '$id_hutang' AND
  no_invoice = '$no_invoice'");
}

function hutang_faktur_invoice_satu($id_hutang,$no_invoice,$isi)
{
  $a = query_satu("SELECT * FROM hutang_faktur WHERE
  id_hutang = '$id_hutang' AND
  no_invoice = '$no_invoice'");
  return $a[$isi];
}

function hutang_faktur_total_bayar($id_hutang)
{
  $query = hutang_faktur($id_hutang);
  foreach($query as $q) :
    $jum_bayar = $q["jum_bayar"];
    @$tot_bayar += $jum_bayar;
  endforeach;
  return @$tot_bayar;
}

function hutang_bayar_jum($id_hutang,$id_hutang_bayar_jenis)
{
  return jumlah("SELECT * FROM hutang_bayar WHERE
  id_hutang = '$id_hutang' AND
  id_hutang_bayar_jenis = '$id_hutang_bayar_jenis'");
}

function hutang_bayar_satu($id_hutang,$id_hutang_bayar_jenis,$isi)
{
  $a = query_satu("SELECT * FROM hutang_bayar WHERE
  id_hutang = '$id_hutang' AND
  id_hutang_bayar_jenis = '$id_hutang_bayar_jenis'");
  return $a[$isi];
}

function hutang_bayar_total($id_hutang)
{
  $a = query("SELECT * FROM hutang_bayar WHERE
  id_hutang = '$id_hutang'");
  foreach($a as $b) :
    $nilai = $b["nilai"];
    @$total += $nilai;
  endforeach;
  return $total;
}

function hutang_bayar_kode_jum($id_hutang,$id_hutang_bayar_jenis)
{
  return jumlah("SELECT * FROM hutang_bayar_kode WHERE
  id_hutang = '$id_hutang' AND
  id_hutang_bayar_jenis = '$id_hutang_bayar_jenis'");
}

function hutang_bayar_kode_satu($id_hutang,$id_hutang_bayar_jenis,$isi)
{
  $a = query_satu("SELECT * FROM hutang_bayar_kode WHERE
  id_hutang = '$id_hutang' AND
  id_hutang_bayar_jenis = '$id_hutang_bayar_jenis'");
  return $a[$isi];
}

function hutang_giro($id_hutang)
{
  return query("SELECT * FROM hutang_giro WHERE id_hutang = '$id_hutang'");
}

function hutang_giro_satu($id,$isi)
{
  $a = query_satu("SELECT * FROM hutang_giro WHERE id = '$id'");
  return $a[$isi];
}

function hutang_giro_total($id_hutang)
{
  foreach(hutang_giro($id_hutang) as $hg) :
    @$nilai_faktur += $hg["nilai_faktur"];   
  endforeach;
    return @$nilai_faktur;
}

function hutang_panjar_giro($id_hutang)
{
  return query("SELECT * FROM hutang_panjar_giro WHERE id_hutang = '$id_hutang'");
}

function sisa_hari($tanggal_awal,$tanggal_akhir)
{
  $tgl1 = strtotime($tanggal_awal);
  $tgl2 = strtotime($tanggal_akhir); 

  $jarak = $tgl2 - $tgl1;

  $hari = $jarak / 60 / 60 / 24;
  return $hari;
}