<?php

require_once('helpers/querys.php');

if (isset($_GET['id'])) {
    $data = cdp_getChargePrint($_GET['id']);
}

if (!isset($_GET['id']) or $data['rowCount'] != 1) {
    cdp_redirect_to("courier_list.php");
}

$row = $data['data'];
$db->cdp_query("SELECT concat(cdb_users.fname,' ',cdb_users.lname) as ReceiverName FROM cdb_add_order inner join cdb_users on (cdb_users.id=cdb_add_order.receiver_id)  WHERE order_id='" . $row->order_id . "'");
$receiver_data = $db->cdp_registro();

$db->cdp_query("SELECT cdb_users.phone as ReceiverPhn FROM cdb_add_order inner join cdb_users on (cdb_users.id=cdb_add_order.receiver_id)  WHERE order_id='" . $row->order_id . "'");
$receiver_phn = $db->cdp_registro();

$db->cdp_query("SELECT * FROM cdb_add_order WHERE order_id='" . $row->order_id . "'");
$row_order = $db->cdp_registro();

$db->cdp_query("SELECT origin_off FROM cdb_add_order WHERE order_id='" . $row->order_id . "'");
$or_off = $db->cdp_registro();

$db->cdp_query("SELECT * FROM cdb_add_order WHERE order_id='" . $row->order_id . "'");
$order_stat = $db->cdp_registro();

$db->cdp_query("SELECT * FROM cdb_charges_order WHERE order_id='" . $row->id_charge . "'");
$row_order = $db->cdp_registro();

$db->cdp_query("SELECT * FROM cdb_charges_order WHERE order_id='" . $row->id_charge . "'");
$pay_order = $db->cdp_registro();

$db->cdp_query("SELECT * FROM cdb_users where id= '".$row->user_id."'"); 
$sender_data2= $db->cdp_registro();

$db->cdp_query("SELECT concat(cdb_users.fname,' ',cdb_users.lname) as SenderName FROM cdb_add_order inner join cdb_users on (cdb_users.id=cdb_add_order.sender_id) WHERE order_id='" . $row->order_id . "'"); 
$sender_data= $db->cdp_registro();

$db->cdp_query("SELECT cdb_users.phone as SenderPhn FROM cdb_add_order inner join cdb_users on (cdb_users.id=cdb_add_order.sender_id) WHERE order_id='" . $row->order_id . "'"); 
$sender_phn= $db->cdp_registro();

$db->cdp_query("SELECT * FROM cdb_address_shipments where order_track='" . $row->order_prefix . $row->order_no . "'");
$address_order = $db->cdp_registro();

$db->cdp_query("SELECT order_prefix, order_no FROM cdb_add_order where order_id='" . $row->order_id . "'");
$address_order1 = $db->cdp_registro();

$db->cdp_query("SELECT order_item_description, order_item_weight FROM cdb_add_order_item where order_id='" . $row->order_id . "'");
$desc_order = $db->cdp_registro();

$db->cdp_query("SELECT cdb_delivery_time.delitime as Deli FROM cdb_delivery_time
                INNER JOIN cdb_add_order on (cdb_delivery_time.id = cdb_add_order.order_deli_time) 
                WHERE order_id='" . $row->order_id . "'");
$deli = $db->cdp_registro();

$db->cdp_query("SELECT recipient_country, recipient_city, recipient_address FROM cdb_address_shipments where order_id='" . $row->order_id . "'");
$address_order2 = $db->cdp_registro();

$db->cdp_query("SELECT currency FROM cdb_add_order WHERE order_id='" . $row->order_id . "'");
$row_curr = $db->cdp_registro();

$db->cdp_query("SELECT cdb_met_payment.name_pay as PayType FROM cdb_met_payment 
                INNER JOIN cdb_charges_order on (cdb_met_payment.id = cdb_charges_order.payment_type) 
                WHERE order_id='" . $row->order_id . "'");
$pay_name = $db->cdp_registro();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="theme-color" content="#ffffff">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="icon" type="image/png" sizes="16x16" href="assets/<?php echo $core->favicon ?>">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Favicon icon -->
    <title>Charge - #<?php echo $row->id_charge; ?></title>

    <link type='text/css' href='assets/custom_dependencies/print.css' rel='stylesheet' />

</head>

<body>
    <div id="page-wrap">
        <table width="90%">
            <tr>
                <td style="border: 0;  text-align: left" width="18%">
                    <div id="logo">

                        <?php echo ($core->logo) ? '<img src="assets/uploads/shiine.png"/>' : $core->site_name; ?>
                </td>
                <td style="border: 0;  text-align: center" width="56%">
                   <strong><?php echo $core->site_name; ?></strong></br>
                   <strong> NBO - Eastleigh:</strong> +254-798886456<br>
                   <strong> MGQ - :</strong> +252-619442255<br>
                </td>
                <td style="border: 0;  text-align: center" width="48%">
                    </br><img src='https://barcode.tec-it.com/barcode.ashx?data=<?php echo $address_order1->order_prefix . $address_order1->order_no; ?>&code=Code128&multiplebarcodes=false&translate-esc=false&unit=Fit&dpi=72&imagetype=Gif&rotation=0&color=%23000000&bgcolor=%23ffffff&qunit=Mm&quiet=0&modulewidth=50' alt='' />
                </td>
    </div>
    </tr>
    </table>
    <hr>
    </br>
    <div id="customer">

        <table id="meta">
            <tr>
                <td rowspan="5" style="border: 1px solid black;   text-align: left" width="62%">
                    <?php
                    if ($or_off->origin_off == 88){
                        $new_add = 'Eastleigh Al Fajri 2nd Fl Rm S18 Opposite Tokyo Shopping Center. Contact Number 0798886456';
                    } else {
                        $new_add = '';
                    }
                    ?>
                    <?php if ($or_off->origin_off == 88): ?>
                        <strong style="color: #2596be; font-size: 14px;">RECEIVING OFFICE: <?php echo $new_add; ?> </strong>
                    <?php endif; ?>
                    </br> </br>
                    <strong>DATE:</strong> 
                    <?php echo $row->charge_date; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <?php
                    if ($order_stat->status_invoice == 1) {

							$text_status = $lang['invoice_paid'];

						} else if ($order_stat->status_invoice == 2) {

							$text_status = $lang['invoice_pending'];

						} else if ($order_stat->status_invoice == 3) {
							$text_status = $lang['verify_payment'];

						}
						?>
                    <strong>PAYMENT STATUS:</strong>
                    <?php echo $text_status ?>
                    </br> </br>

                    <strong>RECEIVER:</strong>
                    <?php print_r( $receiver_data->ReceiverName);?>&nbsp;&nbsp;<?php print_r( $receiver_phn->ReceiverPhn);?>&nbsp;&nbsp; <strong>DESTINATION: </strong> <?php echo $address_order2->recipient_city; ?>
                    </br> </br>

                    <strong>SENDER:</strong>
                    <?php print_r( $sender_data->SenderName);?>&nbsp;&nbsp;<?php print_r( $sender_phn->SenderPhn);?>&nbsp;&nbsp;<strong>PAYMENT MODE: </strong><?php print_r($pay_name->PayType); ?>
                    </br> </br>

                    <strong>THE SUM OF:</strong>
                    <?php print_r($row_curr->currency); ?><?php echo number_format($row->total); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <strong>BALANCE: </strong><?php print_r($row_curr->currency); ?><?php print_r($order_stat->tax_discount); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <!--<strong>BALANCE: </strong><?php print_r($row_curr->currency); ?><?php print_r($row->total-$pay_order->total); ?>-->
                    </br> </br>
                    
                    <strong>IN CONCEPT OF:</strong> Payment for Shipping <b><?php echo $address_order1->order_prefix . $address_order1->order_no; ?></b>
                    </br> </br>
                    
                    <strong>SHIPMENT DETAILS:</strong> Description: <b><?php echo $desc_order->order_item_description; ?></b>&nbsp;&nbsp;&nbsp;Weight(kgs): <b><?php echo $desc_order->order_item_weight; ?></b>&nbsp;&nbsp;&nbsp;Delivery: <b><?php echo $deli->Deli; ?></b>

                    <?php if ($row->note != null) { ?>


                        <br>
                        <br>
                        <br>


                        <strong>Note:</strong>
                        <?php echo $row->note; ?></br>

                    <?php } ?>
                </td>
            </tr>
        </table>
    </div>


    <!--    end related transactions -->

    <div id="terms">
        <table style="width: 100%;border: 1px solid black; border-radius: 30px">
            <tr>
                <td>
                    <p align="justify">This voucher is valid without amendments or erasures and must have the signature and stamp of the authorized person.</p>
                </td>
            </tr>

        </table>
        </br>
        <table id="signing">
            <tr class="noBorder">
                <td align="center">
                    <h4><?php echo $sender_data2->fname.' '. $sender_data2->lname; ?></h4>
                </td>
                <td align="center">
                    <h4><?php echo $row->charge_date; ?></h4>
                </td>
                <td align="center">
                    <h4></h4>
                </td>
            </tr>
            <tr class="noBorder">
                <td align="center">Made by</td>
                <td align="center">Received Date</td>
                <td align="center">Authorized</td>
            </tr>


        </table>
    </div>
    </br>
    </br>
    <hr/>
    </br>
    <hr style="border: 1px dashed black;" />
    </br>
    <hr/>
    </br>
    </br>
    <table width="90%">
            <tr>
                <td style="border: 0;  text-align: left" width="18%">
                    <div id="logo">

                        <?php echo ($core->logo) ? '<img src="assets/uploads/shiine.png"/>' : $core->site_name; ?>
                </td>
                <td style="border: 0;  text-align: center" width="56%">
                   <strong><?php echo $core->site_name; ?></strong></br>
                   <strong> NBO - Eastleigh:</strong> +254-798886456<br>
                   <strong> MGQ - KM4 H.Afrik:</strong> +252-619442255<br>
                </td>
                <td style="border: 0;  text-align: center" width="48%">
                    </br><img src='https://barcode.tec-it.com/barcode.ashx?data=<?php echo $address_order1->order_prefix . $address_order1->order_no; ?>&code=Code128&multiplebarcodes=false&translate-esc=false&unit=Fit&dpi=72&imagetype=Gif&rotation=0&color=%23000000&bgcolor=%23ffffff&qunit=Mm&quiet=0&modulewidth=50' alt='' />
                </td>
    </div>
    </tr>
    </table>
    <hr>
    </br>
    <div id="customer1">

        <table id="meta">
            <tr>
                <td rowspan="5" style="border: 1px solid black;   text-align: left" width="62%">
                    <?php
                    if ($or_off->origin_off == 88){
                        $new_add = 'Eastleigh Al Fajri 2nd Fl Rm S18 Opposite Tokyo Shopping Center. Contact Number 0758622442';
                    } else {
                        $new_add = '';
                    }
                    ?>
                    <?php if ($or_off->origin_off == 88): ?>
                        <strong style="color: #2596be;font-size: 14px;">RECEIVING OFFICE: <?php echo $new_add; ?> </strong>
                    <?php endif; ?>
                    </br> </br>
                    <strong>DATE:</strong> 
                    <?php echo $row->charge_date; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <?php
                    if ($order_stat->status_invoice == 1) {

							$text_status = $lang['invoice_paid'];

						} else if ($order_stat->status_invoice == 2) {

							$text_status = $lang['invoice_pending'];

						} else if ($order_stat->status_invoice == 3) {
							$text_status = $lang['verify_payment'];

						}
						?>
                    <strong>PAYMENT STATUS:</strong>
                    <?php echo $text_status ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </br> </br>
                    
                    <strong>RECEIVER:</strong>
                    
                    <?php print_r( $receiver_data->ReceiverName);?>&nbsp;&nbsp;<?php print_r( $receiver_phn->ReceiverPhn);?>&nbsp;&nbsp; <strong>DESTINATION: </strong> <?php echo $address_order2->recipient_city; ?>
                    </br> </br>

                    <strong>SENDER:</strong>
                    <?php print_r( $sender_data->SenderName);?>&nbsp;&nbsp;<?php print_r( $sender_phn->SenderPhn);?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>PAYMENT MODE: </strong><?php print_r($pay_name->PayType); ?>
                    </br> </br>
                    
                    <strong>THE SUM OF:</strong>
                    <?php print_r($row_curr->currency); ?><?php echo number_format($row->total); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <strong>DISCOUNT: </strong><?php print_r($row_curr->currency); ?><?php print_r($order_stat->tax_discount); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <!--<strong>BALANCE: </strong><?php print_r($row_curr->currency); ?><?php print_r($order_stat->tax_discount); ?>-->
                    </br> </br>
                    
                    <strong>IN CONCEPT OF:</strong> Payment for Shipping <b><?php echo $address_order1->order_prefix . $address_order1->order_no; ?></b>
                    </br> </br>
                    <?php
                    if ($deli_order->delitime == 1) {

							$text_status = $lang['invoice_paid'];

						} else if ($order_stat->status_invoice == 2) {

							$text_status = $lang['invoice_pending'];

						} else if ($order_stat->status_invoice == 3) {
							$text_status = $lang['verify_payment'];

						}
						?>
                    <strong>SHIPMENT DETAILS:</strong> Description: <b><?php echo $desc_order->order_item_description; ?></b>&nbsp;&nbsp;&nbsp;Weight(kgs): <b><?php echo $desc_order->order_item_weight; ?></b></b>&nbsp;&nbsp;&nbsp;Delivery: <b><?php echo $deli->Deli; ?></b>


                    <?php if ($row->note != null) { ?>


                        <br>
                        <br>
                        <br>


                        <strong>Note:</strong>
                        <?php echo $row->note; ?></br>

                    <?php } ?>
                </td>
            </tr>
        </table>
    </div>


    <!--    end related transactions -->

    <div id="terms">
        <table style="width: 100%;border: 1px solid black; border-radius: 30px">
            <tr>
                <td>
                    <p align="justify">This voucher is valid without amendments or erasures and must have the signature and stamp of the authorized person.</p>
                </td>
            </tr>

        </table>
        </br>
        <table id="signing">
            <tr class="noBorder">
                <td align="center">
                    <h4><?php echo $sender_data2->fname.' '. $sender_data2->lname; ?></h4>
                </td>
                <td align="center">
                    <h4><?php echo $row->charge_date; ?></h4>
                </td>
                <td align="center">
                    <h4></h4>
                </td>
            </tr>
            <tr class="noBorder">
                <td align="center">Made by</td>
                <td align="center">Received Date</td>
                <td align="center">Authorized</td>
            </tr>


        </table>
    </div>
    
    <button class='button -dark center no-print' onClick="window.print();" style="font-size:16px">Print receipt of payment &nbsp;&nbsp; <i class="fa fa-print"></i></button>
    </div>

</body>

</html>