<?php
// *************************************************************************
// *                                                                       *
// * DEPRIXA BASIC -  Freight Forwarding & Shipping Software Solutions     *
// * Copyright (c) JAOMWEB. All Rights Reserved                            *
// *                                                                       *
// *************************************************************************
// *                                                                       *
// * Email: support@jaom.info                                              *
// * Website: https://deprixa.link/documentation/                          *
// *                                                                       *
// *************************************************************************
// *                                                                       *
// * This software is furnished under a license and may be used and copied *
// * only  in  accordance  with  the  terms  of such  license and with the *
// * inclusion of the above copyright notice.                              *
// * If you Purchased from Codecanyon, Please read the full License from   *
// * here- http://codecanyon.net/licenses/standard                         *
// *                                                                       *
// *************************************************************************



if (!$user->cdp_is_Admin())
    cdp_redirect_to("login.php");


$userData = $user->cdp_getUserData();
$statusrow = $core->cdp_getStatus();
$paymethodrow = $core->cdp_getPaymentMethod();

$db = new Conexion;

$month = date('m');
$year = date('Y');

$sql = "SELECT * FROM cdb_add_order where status_courier!=21 and is_consolidate!=1 and order_payment_method >1  and month(order_date)='$month' AND year(order_date)='$year'  order by order_id desc";



$db->cdp_query($sql);
$data = $db->cdp_registros();




$count = 0;
$sumador_pendiente = 0;
$sumador_total = 0;
$sumador_pagado = 0;

foreach ($data as $row) {



    $db->cdp_query('SELECT  IFNULL(sum(total), 0)  as total  FROM cdb_charges_order WHERE order_id=:order_id');

    $db->bind(':order_id', $row->order_id);

    $db->cdp_execute();

    $sum_payment = $db->cdp_registro();

    $pendiente = $row->total_order - $sum_payment->total;

    $sumador_pendiente += $pendiente;
    $sumador_total += $row->total_order;
    $sumador_pagado += $sum_payment->total;


    $count++;
}



?>
<!DOCTYPE html>
<html dir="ltr" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="keywords" content="Courier DEPRIXA-Integral Web System" />
    <meta name="author" content="Jaomweb">

    <title><?php echo $lang['leftorder142'] ?> | <?php echo $core->site_name ?></title>
    <link rel="stylesheet" type="text/css" href="assets/libs/select2/dist/css/select2.min.css">
    <?php include 'views/inc/head_scripts.php'; ?>

    <link rel="stylesheet" href="assets/daterangepicker.css">

</head>

<body>
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->
    <?php $agencyrow = $core->cdp_getBranchoffices(); ?>


    <?php include 'views/inc/preloader.php'; ?>
    <!-- ============================================================== -->
    <!-- Main wrapper - style you can find in pages.scss -->
    <!-- ============================================================== -->
    <div id="main-wrapper">
        <!-- ============================================================== -->
        <!-- Topbar header - style you can find in pages.scss -->
        <!-- ============================================================== -->

        <!-- ============================================================== -->
        <!-- Preloader - style you can find in spinners.css -->
        <!-- ============================================================== -->

        <?php include 'views/inc/topbar.php'; ?>

        <!-- End Topbar header -->


        <!-- Left Sidebar - style you can find in sidebar.scss  -->

        <?php include 'views/inc/left_sidebar.php'; ?>


        <!-- End Left Sidebar - style you can find in sidebar.scss  -->

        <!-- Page wrapper  -->
        <!-- ============================================================== -->
        <div class="page-wrapper">

            <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-5 align-self-center">
                        <h4 class="page-title"> <?php echo $lang['leftorder142'] ?></h4>

                    </div>
                </div>
            </div>

            <!-- Action part -->
            <!-- Button group part -->
            <div class="bg-light p-15">
                <div class="row justify-content-center">
                    <div class="col-md-12">
                        <div class="row">
                            <div class="col-12">
                                <!-- <div id="loader" style="display:none"></div> -->
                                <div id="resultados_ajax"></div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Action part -->


            <div class="container-fluid">

                <!-- -------------------------------------------------------------- -->
                <!-- Overview, Visits, Sales, Order -->
                <!-- -------------------------------------------------------------- -->
                <?php if ($userData->userlevel == 9) { ?>
                    <div class="row">
                        <!-- column -->
                        <div class="col-sm-12 col-lg-6 d-flex align-items-stretch">
                            <!-- ---------------------
                            start Last Month Summary
                        ---------------- -->
                            <div class="card w-100">
                                <div class="card-body">
                                    <div class="d-flex align-items-center mb-4">
                                        <div>
                                            <h4 class="card-title"><?php echo $lang['leftorder108'] ?></h4>
                                            <h5 class="card-subtitle"><?php echo $lang['leftorder123'] ?></h5>
                                        </div>

                                    </div>

                                    <div class="row">
                                        <!-- column -->
                                        <div class="col-sm-12 col-md-12 col-lg-12">
                                            <ul class="list-style-none">

                                                <li class="m-t-30">
                                                    <div class="d-flex align-items-center">
                                                        <div>
                                                            <span class="text-muted"><?php echo $lang['dashnew14'] ?></span>
                                                            <h4 class="m-b-0">
                                                                <span class="font-16">
                                                                    <?php echo $core->currency; ?> <?php

                                                                                                    echo number_format($sumador_total, 2, '.', '.');
                                                                                                    ?>
                                                                </span>
                                                            </h4>
                                                        </div>
                                                    </div>

                                                    <div class="progress" style="height: 7px;">
                                                        <div class="progress-bar progress-bar-striped bg-info progress-bar-animated" role="progressbar" aria-valuenow="47" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo number_format($sumador_total, 2, '.', '.') / 100; ?>%"></div>
                                                    </div>
                                                </li>

                                                <div><br></div>

                                                <li class="m-t-30">
                                                    <div class="d-flex align-items-center">
                                                        <div>
                                                            <span class="text-muted"><?php echo $lang['leftorder143'] ?></span>
                                                            <h4 class="m-b-0">
                                                                <span class="font-16">

                                                                    <?php echo $core->currency; ?> <?php
                                                                                                    echo number_format($sumador_pagado, 2, '.', '.');
                                                                                                    ?>
                                                                </span>
                                                            </h4>
                                                        </div>
                                                    </div>
                                                    <div class="progress" style="height: 7px;">
                                                        <div class="progress-bar progress-bar-striped bg-success progress-bar-animated" role="progressbar" aria-valuenow="47" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo number_format($sumador_pagado, 2, '.', '.') / 100; ?>%"></div>
                                                    </div>
                                                </li>

                                                <div><br></div>

                                                <li class="m-t-30 m-b-40">
                                                    <div class="d-flex align-items-center">
                                                        <div>
                                                            <span class="text-muted"><?php echo $lang['leftorder144'] ?></span>
                                                            <h4 class="m-b-0">
                                                                <span class="font-16">

                                                                    <?php echo $core->currency; ?> <?php
                                                                                                    echo number_format($sumador_pendiente, 2, '.', '.');

                                                                                                    ?>
                                                                </span>
                                                            </h4>
                                                        </div>
                                                    </div>

                                                    <div class="progress" style="height: 7px;">
                                                        <div class="progress-bar progress-bar-striped bg-orange progress-bar-animated" role="progressbar" aria-valuenow="47" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo number_format($sumador_pendiente, 2, '.', '.') / 100; ?>%"></div>
                                                    </div>
                                                </li>


                                            </ul>
                                        </div>
                                    </div>

                                </div>

                            </div>
                            <!-- ---------------------
                            end Last Month Summary
                        ---------------- -->
                        </div>

                        <!-- column -->
                        <div class="col-sm-12 col-lg-6 ">

                            <!-- Bsic Line Chart -->
                            <div class="col-lg-12">
                                <!-- ---------------------
                                    start Bsic Line Chart
                                ---------------- -->
                                <div class="card">
                                    <div class="border-bottom title-part-padding">
                                        <h4 class="card-title mb-0"><?php echo $lang['count11'] ?></h4>
                                    </div>
                                    <div class="card-body analytics-info">
                                        <div id="basic-line" style="height:250px;"></div>
                                    </div>
                                </div>
                                <!-- ---------------------
                                    end Bsic Line Chart
                                ---------------- -->
                            </div>

                        </div>
                    </div>



                    <div class="row">
                        <!-- Column -->

                        <div class="col-lg-12 col-xl-12 col-md-12">
                            <div class="card">
                                <div class="card-body">
                                    <div class="row mb-5">
                                        <div class="col-md-3 col-sm-12">
                                            <!-- <div class="form-group"> -->
                                            <div class="btn-group mt-2 hide" id="div-actions-checked">
                                                <span class="mt-2 mr-4"><strong id="countChecked"> Selected: 0</strong></span>
                                                <button class="btn btn-info dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                    <?php echo $lang['leftorder127'] ?>
                                                </button>
                                                <div class="dropdown-menu">
                                                    <a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#modalCheckboxStatus"><i style="color:#20c997" class="ti-reload"></i>&nbsp;<?php echo $lang['filter35'] ?></a>

                                                    <a class="dropdown-item" onclick="cdp_printMultipleLabel();" target="_blank"> <i style="color:#343a40" class="ti-printer"></i>&nbsp;<?php echo $lang['toollabel'] ?> </a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- <span id="countChecked">0</span> -->

                                    <div class="row mb-3 ml-2">

                                        <div class="col-md-3">
                                            <div class="input-group">
                                                <span class="input-group-text">
                                                    <span class="ri-calendar-2-line" style="color:#6610f2"></span>
                                                </span>
                                                <input type="text" name="daterange" id="daterange" class="form-control float-right">
                                            </div>
                                        </div>

                                        <div class=" col-sm-12 col-md-3">
                                            <div class="input-group">
                                                <input type="text" name="search" id="search" class="form-control input-sm float-right" placeholder="search tracking" onkeyup="cdp_load(1);">
                                                <div class="input-group-append input-sm">
                                                    <button type="submit" class="btn btn-info"><i class="fa fa-search"></i></button>
                                                </div>
                                            </div>
                                        </div><!-- /.col -->

                                        <div class="col-md-3">
                                            <select class="select2 form-select" style="width: 100%; height:36px;" id="customer_id" name="customer_id" onchange="cdp_load(1);">
                                            </select>
                                        </div>

                                        <div class="col-sm-12 col-md-3">
                                            <div class="input-group">
                                                <select onchange="cdp_load(1);" class="form-select" id="agency_courier" name="agency_courier">

                                                    <option value="0">--<?php echo $lang['left202'] ?>--</option>
                                                    <?php foreach ($agencyrow as $row) : ?>
                                                        <option value="<?php echo $row->id; ?>"><?php echo $row->name_branch; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="outer_div"></div>


                                </div>
                            </div>
                        </div>
                        <!-- Column -->
                    </div>

                <?php } else if ($userData->userlevel == 2) { ?>

                    <div class="row">
                        <!-- column -->
                        <div class="col-sm-12 col-lg-6 d-flex align-items-stretch">
                            <!-- ---------------------
                            start Last Month Summary
                        ---------------- -->
                            <div class="card w-100">
                                <div class="card-body">
                                    <div class="d-flex align-items-center mb-4">
                                        <div>
                                            <h4 class="card-title"><?php echo $lang['leftorder108'] ?></h4>
                                            <h5 class="card-subtitle"><?php echo $lang['leftorder123'] ?></h5>
                                        </div>

                                    </div>

                                    <div class="row">
                                        <!-- column -->
                                        <div class="col-sm-12 col-md-12 col-lg-12">
                                            <ul class="list-style-none">

                                                <li class="m-t-30">
                                                    <div class="d-flex align-items-center">
                                                        <div>
                                                            <span class="text-muted"><?php echo $lang['dashnew14'] ?></span>
                                                            <h4 class="m-b-0">
                                                                <span class="font-16">
                                                                    <?php echo $core->currency; ?> <?php

                                                                                                    echo number_format($sumador_total, 2, '.', '.');
                                                                                                    ?>
                                                                </span>
                                                            </h4>
                                                        </div>
                                                    </div>

                                                    <div class="progress" style="height: 7px;">
                                                        <div class="progress-bar progress-bar-striped bg-info progress-bar-animated" role="progressbar" aria-valuenow="47" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo number_format($sumador_total, 2, '.', '.') / 100; ?>%"></div>
                                                    </div>
                                                </li>

                                                <div><br></div>

                                                <li class="m-t-30">
                                                    <div class="d-flex align-items-center">
                                                        <div>
                                                            <span class="text-muted">Total accounts paid</span>
                                                            <h4 class="m-b-0">
                                                                <span class="font-16">

                                                                    <?php echo $core->currency; ?> <?php
                                                                                                    echo number_format($sumador_pagado, 2, '.', '.');
                                                                                                    ?>
                                                                </span>
                                                            </h4>
                                                        </div>
                                                    </div>
                                                    <div class="progress" style="height: 7px;">
                                                        <div class="progress-bar progress-bar-striped bg-success progress-bar-animated" role="progressbar" aria-valuenow="47" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo number_format($sumador_pagado, 2, '.', '.') / 100; ?>%"></div>
                                                    </div>
                                                </li>

                                                <div><br></div>

                                                <li class="m-t-30 m-b-40">
                                                    <div class="d-flex align-items-center">
                                                        <div>
                                                            <span class="text-muted"><?php echo $lang['leftorder143'] ?></span>
                                                            <h4 class="m-b-0">
                                                                <span class="font-16">

                                                                    <?php echo $core->currency; ?> <?php

                                                                                                    echo number_format($sumador_pendiente, 2, '.', '.');

                                                                                                    ?>
                                                                </span>
                                                            </h4>
                                                        </div>
                                                    </div>

                                                    <div class="progress" style="height: 7px;">
                                                        <div class="progress-bar progress-bar-striped bg-orange progress-bar-animated" role="progressbar" aria-valuenow="47" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo number_format($sumador_pendiente, 2, '.', '.') / 100; ?>%"></div>
                                                    </div>
                                                </li>


                                            </ul>
                                        </div>
                                    </div>

                                </div>

                            </div>
                            <!-- ---------------------
                            end Last Month Summary
                        ---------------- -->
                        </div>

                        <!-- column -->
                        <div class="col-sm-12 col-lg-6 ">

                            <!-- Bsic Line Chart -->
                            <div class="col-lg-12">
                                <!-- ---------------------
                                    start Bsic Line Chart
                                ---------------- -->
                                <div class="card">
                                    <div class="border-bottom title-part-padding">
                                        <h4 class="card-title mb-0"><?php echo $lang['count11'] ?></h4>
                                    </div>
                                    <div class="card-body analytics-info">
                                        <div id="basic-line" style="height:250px;"></div>
                                    </div>
                                </div>
                                <!-- ---------------------
                                    end Bsic Line Chart
                                ---------------- -->
                            </div>

                        </div>
                    </div>



                    <div class="row">
                        <!-- Column -->

                        <div class="col-lg-12 col-xl-12 col-md-12">
                            <div class="card">
                                <div class="card-body">
                                    <div class="row mb-5">
                                        <div class="col-md-3 col-sm-12">
                                            <!-- <div class="form-group"> -->
                                            <div class="btn-group mt-2 hide" id="div-actions-checked">
                                                <span class="mt-2 mr-4"><strong id="countChecked"> Selected: 0</strong></span>
                                                <button class="btn btn-info dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                    <?php echo $lang['leftorder127'] ?>
                                                </button>
                                                <div class="dropdown-menu">
                                                    <a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#modalCheckboxStatus"><i style="color:#20c997" class="ti-reload"></i>&nbsp;<?php echo $lang['filter35'] ?></a>

                                                    <a class="dropdown-item" onclick="cdp_printMultipleLabel();" target="_blank"> <i style="color:#343a40" class="ti-printer"></i>&nbsp;<?php echo $lang['toollabel'] ?> </a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- <span id="countChecked">0</span> -->

                                    <div class="row mb-3 ml-2">

                                        <div class="col-md-3">
                                            <div class="input-group">
                                                <span class="input-group-text">
                                                    <span class="ri-calendar-2-line" style="color:#6610f2"></span>
                                                </span>
                                                <input type="text" name="daterange" id="daterange" class="form-control float-right">
                                            </div>
                                        </div>

                                        <div class=" col-sm-12 col-md-3">
                                            <div class="input-group">
                                                <input type="text" name="search" id="search" class="form-control input-sm float-right" placeholder="search tracking" onkeyup="cdp_load(1);">
                                                <div class="input-group-append input-sm">
                                                    <button type="submit" class="btn btn-info"><i class="fa fa-search"></i></button>
                                                </div>
                                            </div>
                                        </div><!-- /.col -->

                                        <div class="col-md-3">
                                            <select class="select2 form-select" style="width: 100%; height:36px;" id="customer_id" name="customer_id" onchange="cdp_load(1);">
                                            </select>
                                        </div>

                                        <div class="col-sm-12 col-md-3">
                                            <div class="input-group">
                                                <select onchange="cdp_load(1);" class="form-select" id="agency_courier" name="agency_courier">

                                                    <option value="0">--<?php echo $lang['left202'] ?>--</option>
                                                    <?php foreach ($agencyrow as $row) : ?>
                                                        <option value="<?php echo $row->id; ?>"><?php echo $row->name_branch; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="outer_div"></div>


                                </div>
                            </div>
                        </div>
                        <!-- Column -->
                    </div>
                <?php } ?>
            </div>

            <?php
            include('views/modals/modal_update_status_checked.php');
            ?>
            <?php include('views/modals/modal_charges_list.php'); ?>
            <?php include('views/modals/modal_charges_add.php'); ?>
            <?php include('views/modals/modal_charges_edit.php'); ?>

        </div>

        <?php include 'views/inc/footer.php'; ?>

    </div>
    <!-- ============================================================== -->
    <!-- End Page wrapper  -->
    <!-- ============================================================== -->
    <script src="assets/moment.min.js"></script>
    <script src="assets/daterangepicker.js"></script>
    <script src="assets/libs/select2/dist/js/select2.full.min.js"></script>
    <script src="assets/libs/select2/dist/js/select2.min.js"></script>
    <script src="assets/libs/echarts/dist/echarts-en.min.js"></script>

    <script src="dataJs/dashboard_account.js"> </script>
    <script src="dataJs/accounts_receivable.js"></script>
    <script src="dataJs/soloNumeros.js"></script>



</body>

</html>