<?php
session_start();

require_once "../config.php";

require_once "../ajax/send_email.php";
$databaseFile = '../../uploads/geolite/ip.mmdb';
require_once "../../translation.php";
require_once "../../translation_ee.php";
require_once "../../translation_lt.php";

require_once "../../translation_en.php";
require_once "../../translation_fi.php";



require_once '../database1.php';
require_once "../check_admin.php";

class edit_orders extends database
{
    public function index($data,$dataItem,$id)
    {
		$where['cl_id']= $id;
        $this->dbh = $this->connectPDO1();
        $this->dbh->beginTransaction();
        try
        {

		  $res = $this->update1('tb_checkout',$data, $where);
          if(!$res)
          {
           
            return 0;
            exit;
          }
        

          $res = $this->update1('tb_checkout_item',$dataItem, ['cl_checkout_id' => $id]);
          if(!$res)
          {
            return 0;
            exit;
          }

            $this->dbh->commit();
            return 1;
            exit;
        }
        catch (PDOException $e) {
            // roll back transaction
            $this->dbh->rollback();
            return 0;
        }  
    }
    
    public function Getdata($id)
    {
        $where['cl_id'] = $id;
        return $this->fetchRow('tb_checkout', $where);
    }

  public function getOrderItemsGeneral($checkoutItemID)
  {
    
    $where[] = $checkoutItemID;
    $sql = ' SELECT ci.*, p.cl_name, p.cl_supplier, p.cl_product_id, p.cl_profit_percentage, p.cl_supplier_price, p.cl_shipping_price, p.cl_digital FROM tb_checkout_item ci INNER JOIN tb_product p ON ci.cl_product_id=p.cl_id WHERE ci.cl_deleted_at IS NULL AND p.cl_type="General" AND ci.cl_checkout_id=? ';
    return $this->callQuery($sql, $where);
  }


  public function getOrderItemsVariable($checkoutItemID)
  {
    
    $where[] = $checkoutItemID;
    $sql = ' SELECT ci.*, p.cl_name, p.cl_supplier, p.cl_product_id, p.cl_profit_percentage, p.cl_supplier_price, p.cl_shipping_price, p.cl_digital, vpf.cl_filter, vpfv.cl_name AS value, GROUP_CONCAT(CONCAT(vpf.cl_filter, "-", vpfv.cl_name)) AS spec FROM tb_checkout_item ci INNER JOIN tb_product p ON ci.cl_product_id=p.cl_id INNER JOIN tb_variable_product vp ON ci.cl_variable_product_id=vp.cl_id INNER JOIN tb_variable_product_attributes vpa ON vp.cl_id=vpa.cl_variable_product_id INNER JOIN tb_variable_product_filter vpf ON vpf.cl_id=vpa.cl_filter_id INNER JOIN tb_variable_product_filter_values vpfv ON vpfv.cl_id=vpa.cl_value_id WHERE ci.cl_deleted_at IS NULL AND p.cl_type="Variable" AND ci.cl_checkout_id=? GROUP BY ci.cl_product_id ';
    return $this->callQuery($sql, $where);
  }

  public function getPickUpPoint($id)
  {
      $sql = ' SELECT * FROM tb_pickup_points WHERE cl_id=? ';
      return $this->callQueryRow($sql, [$id]);
    //return $this->fetchRow('tb_pickup_points', ['cl_id' => $id]);
  }

  

  public function getAllItems($id)
  {
    $where[] = $id;
    $sql = ' SELECT p.cl_name,ci.cl_quantity, ci.cl_amount,p.cl_image, p.cl_image_location FROM  tb_checkout_item ci INNER JOIN tb_product p ON ci.cl_product_id=p.cl_id WHERE ci.cl_checkout_id=? AND ci.cl_deleted_at IS NULL ';
    return $this->callQuery($sql, $where);
  }

}

$dev = new edit_orders();	
$msg="";
if(!isset($_GET['id']))
{
	  header('Location:list.php');
      exit;
}
$id=$_GET['id'];
$res1 = $dev->Getdata($id);
if(!$res1)
{
  exit;
}


$currentStatus = $res1['cl_status'];

if(isset($_POST['data']))
{
	$data=$_POST['data'];
    if(isset($data['sms_send_checkbox']))
    {
        $sms_send_checkbox = $data['sms_send_checkbox'];
        unset($data['sms_send_checkbox']);
    }
	if(trim($data['cl_fname']) == '')
	{
		//$msg.= "Firstname is required<br/>";
	}
      
	if($msg=="")
	{
        $dataItem = array();
        if(trim($data['cl_delivery_date']) != '')
        {
             $dataItem['cl_delivery_date'] = $data['cl_delivery_date'] = date("Y-m-d", strtotime($data['cl_delivery_date']));
            if($res1['cl_checkout_type'] == 'ind')
            {
                $data['cl_warraty_period'] = 730;
                $dataItem['cl_warraty_period'] = 730;
            }
            else
            {
                $data['cl_warraty_period'] = 365;
                $dataItem['cl_warraty_period'] = 365;
            }
        }
        else
        {
            $data['cl_delivery_date'] = null;
            $data['cl_warraty_period'] = 0;

            $dataItem['cl_delivery_date'] = null;
            $dataItem['cl_warraty_period'] = 0;
        }

        if(trim($data['cl_expected_delivery_date']) != '')
        {
            $data['cl_expected_delivery_date'] = date("Y-m-d", strtotime($data['cl_expected_delivery_date']));
        }
        else
        {
            $data['cl_expected_delivery_date'] = null;
        }

		$res = $dev->index($data,$dataItem, $id);
        if($res)
        {
            $currentImage = '';
            $res1 = $dev->Getdata($id);
            //$currentStatus = $res1['cl_status'];

            $items = $dev->getAllItems($id);
            
            
            if($data['cl_status'] == 'Shipped')
            {
                
              
                
                
                $htmlEmailNew = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office" lang="en">
   <head>
      <meta charset="UTF-8">
      <meta content="width=device-width, initial-scale=1" name="viewport">
      <meta name="x-apple-disable-message-reformatting">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta content="telephone=no" name="format-detection">
      <title>shipping</title>
      <!--[if (mso 16)]>
      <style type="text/css"> a {text-decoration: none;}  </style>
      <![endif]--><!--[if gte mso 9]>
      <style>sup { font-size: 100% !important; }</style>
      <![endif]--><!--[if gte mso 9]>
      <noscript>
         <xml>
            <o:OfficeDocumentSettings>
               <o:AllowPNG></o:AllowPNG>
               <o:PixelsPerInch>96</o:PixelsPerInch>
            </o:OfficeDocumentSettings>
         </xml>
      </noscript>
      <![endif]--><!--[if mso]>
      <xml>
         <w:WordDocument xmlns:w="urn:schemas-microsoft-com:office:word">
            <w:DontUseAdvancedTypographyReadingMail/>
         </w:WordDocument>
      </xml>
      <![endif]-->
      <style type="text/css">.rollover:hover .rollover-first { max-height:0px!important; display:none!important;}.rollover:hover .rollover-second { max-height:none!important; display:block!important;}.rollover span { font-size:0px;}u + .body img ~ div div { display:none;}#outlook a { padding:0;}span.MsoHyperlink,span.MsoHyperlinkFollowed { color:inherit; mso-style-priority:99;}a.es-button { mso-style-priority:100!important; text-decoration:none!important;}a[x-apple-data-detectors],#MessageViewBody a { color:inherit!important; text-decoration:none!important; font-size:inherit!important; font-family:inherit!important; font-weight:inherit!important; line-height:inherit!important;}.es-desk-hidden { display:none; float:left; overflow:hidden; width:0; max-height:0; line-height:0; mso-hide:all;}@media only screen and (max-width:600px) {.es-m-p0r { padding-right:0px!important } .es-m-p0l { padding-left:0px!important } .es-p-default { }
         *[class="gmail-fix"] { display:none!important } p, a { line-height:150%!important } h1, h1 a { line-height:120%!important } h2, h2 a { line-height:120%!important } h3, h3 a { line-height:120%!important } h4, h4 a { line-height:120%!important } h5, h5 a { line-height:120%!important } h6, h6 a { line-height:120%!important } .es-header-body p { } .es-content-body p { } .es-footer-body p { } .es-infoblock p { } h1 { font-size:36px!important; text-align:left } h2 { font-size:26px!important; text-align:left } h3 { font-size:20px!important; text-align:left } h4 { font-size:24px!important; text-align:left } h5 { font-size:20px!important; text-align:left } h6 { font-size:16px!important; text-align:left } .es-header-body h1 a, .es-content-body h1 a, .es-footer-body h1 a { font-size:36px!important } .es-header-body h2 a, .es-content-body h2 a, .es-footer-body h2 a { font-size:26px!important }
         .es-header-body h3 a, .es-content-body h3 a, .es-footer-body h3 a { font-size:20px!important } .es-header-body h4 a, .es-content-body h4 a, .es-footer-body h4 a { font-size:24px!important } .es-header-body h5 a, .es-content-body h5 a, .es-footer-body h5 a { font-size:20px!important } .es-header-body h6 a, .es-content-body h6 a, .es-footer-body h6 a { font-size:16px!important } .es-menu td a { font-size:12px!important } .es-header-body p, .es-header-body a { font-size:14px!important } .es-content-body p, .es-content-body a { font-size:14px!important } .es-footer-body p, .es-footer-body a { font-size:14px!important } .es-infoblock p, .es-infoblock a { font-size:12px!important } .es-m-txt-c, .es-m-txt-c h1, .es-m-txt-c h2, .es-m-txt-c h3, .es-m-txt-c h4, .es-m-txt-c h5, .es-m-txt-c h6 { text-align:center!important }
         .es-m-txt-r, .es-m-txt-r h1, .es-m-txt-r h2, .es-m-txt-r h3, .es-m-txt-r h4, .es-m-txt-r h5, .es-m-txt-r h6 { text-align:right!important } .es-m-txt-j, .es-m-txt-j h1, .es-m-txt-j h2, .es-m-txt-j h3, .es-m-txt-j h4, .es-m-txt-j h5, .es-m-txt-j h6 { text-align:justify!important } .es-m-txt-l, .es-m-txt-l h1, .es-m-txt-l h2, .es-m-txt-l h3, .es-m-txt-l h4, .es-m-txt-l h5, .es-m-txt-l h6 { text-align:left!important } .es-m-txt-r img, .es-m-txt-c img, .es-m-txt-l img { display:inline!important } .es-m-txt-r .rollover:hover .rollover-second, .es-m-txt-c .rollover:hover .rollover-second, .es-m-txt-l .rollover:hover .rollover-second { display:inline!important } .es-m-txt-r .rollover span, .es-m-txt-c .rollover span, .es-m-txt-l .rollover span { line-height:0!important; font-size:0!important; display:block } .es-spacer { display:inline-table }
         a.es-button, button.es-button { font-size:20px!important; padding:10px 20px 10px 20px!important; line-height:120%!important } a.es-button, button.es-button, .es-button-border { display:inline-block!important } .es-m-fw, .es-m-fw.es-fw, .es-m-fw .es-button { display:block!important } .es-m-il, .es-m-il .es-button, .es-social, .es-social td, .es-menu { display:inline-block!important } .es-adaptive table, .es-left, .es-right { width:100%!important } .es-content table, .es-header table, .es-footer table, .es-content, .es-footer, .es-header { width:100%!important; max-width:600px!important } .adapt-img { width:100%!important; height:auto!important } .es-mobile-hidden, .es-hidden { display:none!important } .es-desk-hidden { width:auto!important; overflow:visible!important; float:none!important; max-height:inherit!important; line-height:inherit!important } tr.es-desk-hidden { display:table-row!important }
         table.es-desk-hidden { display:table!important } td.es-desk-menu-hidden { display:table-cell!important } .es-menu td { width:1%!important } table.es-table-not-adapt, .esd-block-html table { width:auto!important } .h-auto { height:auto!important } .es-text-7416 .es-text-mobile-size-28, .es-text-7416 .es-text-mobile-size-28 * { font-size:28px!important; line-height:150%!important } .es-text-3577 .es-text-mobile-size-18, .es-text-3577 .es-text-mobile-size-18 * { font-size:18px!important; line-height:150%!important } .es-text-4524 .es-text-mobile-size-16, .es-text-4524 .es-text-mobile-size-16 * { font-size:16px!important; line-height:150%!important } .es-text-3707 .es-text-mobile-size-18, .es-text-3707 .es-text-mobile-size-18 * { font-size:18px!important; line-height:150%!important } }@media screen and (max-width:384px) {.mail-message-content { width:414px!important } }
      </style>
   </head>
   <body class="body" style="width:100%;height:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;padding:0;Margin:0">
      <div dir="ltr" class="es-wrapper-color" lang="en" style="background-color:#FAFAFA">
         <!--[if gte mso 9]>
         <v:background xmlns:v="urn:schemas-microsoft-com:vml" fill="t">
            <v:fill type="tile" color="#fafafa"></v:fill>
         </v:background>
         <![endif]-->
         <table width="100%" cellspacing="0" cellpadding="0" class="es-wrapper" role="none" style="border-collapse:collapse;border-spacing:0px;padding:0;Margin:0;width:100%;height:100%;background-repeat:repeat;background-position:center top;background-color:#FAFAFA">
            <tr>
               <td valign="top" style="padding:0;Margin:0">
                  <table cellpadding="0" cellspacing="0" align="center" class="es-header" role="none" style="border-collapse:collapse;border-spacing:0px;width:100%;table-layout:fixed !important;background-color:transparent;background-repeat:repeat;background-position:center top">
                     <tr>
                        <td align="center" style="padding:0;Margin:0">
                           <table bgcolor="#cc0000" align="center" cellpadding="0" cellspacing="0" class="es-header-body" style="border-collapse:collapse;border-spacing:0px;background-color:#cc0000;width:600px" role="none">
                              <tr>
                                 <td align="left" style="padding:0;Margin:0">
                                    <table cellpadding="0" cellspacing="0" width="100%" role="none" style="border-collapse:collapse;border-spacing:0px">
                                       <tr>
                                          <td valign="top" align="center" class="es-m-p0r" style="padding:0;Margin:0;width:600px">
                                             <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                <tr>
                                                    <td></td>
                                                    <td align="center" style="padding:0;Margin:0;padding-top:7px;padding-bottom:7px;font-size:0px;width:70px"><img src="' . MAIN_DOMAIN . '/images/emails/logo.png" alt="Logo" width="40" title="Logo" class="adapt-img" style="display:block;font-size:12px;border:0;outline:none;text-decoration:none;width:60px"></td>
                                                        <td></td>
                                                    </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                           </table>
                        </td>
                     </tr>
                  </table>
                  <table cellpadding="0" cellspacing="0" align="center" class="es-content" role="none" style="border-collapse:collapse;border-spacing:0px;width:100%;table-layout:fixed !important">
                     <tr>
                        <td align="center" style="padding:0;Margin:0">
                           <table bgcolor="#ffffff" align="center" cellpadding="0" cellspacing="0" class="es-content-body" role="none" style="border-collapse:collapse;border-spacing:0px;background-color:#FFFFFF;width:600px">
                              <tr>
                                 <td align="left" style="padding:0;Margin:0;padding-top:15px;padding-right:20px;padding-left:20px">
                                    <table cellpadding="0" cellspacing="0" width="100%" role="none" style="border-collapse:collapse;border-spacing:0px">
                                       <tr>
                                          <td align="center" valign="top" style="padding:0;Margin:0;width:560px">
                                             <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                <tr>
                                                   <td align="center" class="es-text-7416" style="padding:0;Margin:0;padding-top:15px;padding-bottom:15px">
                                                      <h1 class="es-m-txt-c es-text-mobile-size-28" style="Margin:0;letter-spacing:0;font-size:28px;font-style:normal;font-weight:bold;line-height:28px;color:#333333">Your items have been shipped!</h1>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                           </table>
                        </td>
                     </tr>
                  </table>
                  <table cellpadding="0" cellspacing="0" align="center" class="es-content" role="none" style="border-collapse:collapse;border-spacing:0px;width:100%;table-layout:fixed !important">
                     <tr>
                        <td align="center" style="padding:0;Margin:0">
                           <table bgcolor="#ffffff" align="center" cellpadding="0" cellspacing="0" class="es-content-body" role="none" style="border-collapse:collapse;border-spacing:0px;background-color:#FFFFFF;width:600px">
                              <tr>
                                 <td align="left" style="padding:0;Margin:0">
                                    <table cellpadding="0" cellspacing="0" width="100%" role="none" style="border-collapse:collapse;border-spacing:0px">
                                       <tr>
                                          <td align="center" valign="top" style="padding:0;Margin:0;width:600px">
                                             <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                <tr>
                                                   <td align="center" style="padding:0;Margin:0;font-size:0"><img src="' . MAIN_DOMAIN . '/images/emails/banner-shipped.jpg" alt="" width="600" class="adapt-img" style="display:block;font-size:14px;border:0;outline:none;text-decoration:none"></td>
                                                </tr>
                                                <tr>
                                                   <td align="center" class="es-m-p0r es-m-p0l es-text-3577" style="Margin:0;padding-top:15px;padding-right:40px;padding-bottom:25px;padding-left:40px">
                                                      <p class="es-text-mobile-size-18" style="Margin:0;line-height:27px;letter-spacing:0;color:#333333;font-size:18px">We have handed your order to the courier, and it should arrive at your delivery address soon.&nbsp;</p>
                                                   </td>
                                                </tr>
                                                <tr>
                                                   <td align="center" style="padding:0;Margin:0"><a href="' . MAIN_DOMAIN . '/veikals/account/orders" target="_blank" class="es-button" style="text-decoration:none;color:#ffffff;font-size:20px;padding:10px 50px;display:inline-block;background:#ca0000;border-radius:50px;font-weight:normal;font-style:normal;line-height:24px;width:auto;text-align:center;letter-spacing:0;">Track status</a></td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                              <tr>
                                 <td align="left" class="esdev-adapt-off" style="Margin:0;padding-top:15px;padding-right:20px;padding-left:20px;padding-bottom:15px">
                                    <table cellpadding="0" cellspacing="0" class="esdev-mso-table" role="none" style="border-collapse:collapse;border-spacing:0px;width:560px">
                                       <tr>
                                          <td valign="top" class="esdev-mso-td" style="padding:0;Margin:0">
                                             <table cellpadding="0" cellspacing="0" align="right" class="es-right" role="none" style="border-collapse:collapse;border-spacing:0px;float:right">
                                                <tr>
                                                   <td align="center" style="padding:0;Margin:0;width:560px">
                                                      <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                         <tr>
                                                            <td align="left" class="es-text-3707" style="padding:0;Margin:0;padding-top:25px">
                                                               <p class="es-text-mobile-size-18" style="Margin:0;line-height:27px;letter-spacing:0;color:#333333;font-size:18px">Shipping details:</p>
                                                            </td>
                                                         </tr>
                                                      </table>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                              <tr>
                                 <td align="left" class="esdev-adapt-off" style="Margin:0;padding-top:15px;padding-right:20px;padding-left:20px;padding-bottom:40px">
                                    <table cellpadding="0" cellspacing="0" class="esdev-mso-table" role="none" style="border-collapse:collapse;border-spacing:0px;width:560px">
                                       <tr>
                                          <td valign="top" class="esdev-mso-td" style="padding:0;Margin:0">
                                             <table cellspacing="0" align="right" cellpadding="0" class="es-right" role="none" style="border-collapse:collapse;border-spacing:0px;float:right">
                                                <tr>
                                                   <td align="center" style="padding:0;Margin:0;width:560px">
                                                      <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                         <tr>
                                                            <td align="left" style="padding:0;Margin:0;padding-top:5px">
                                                               <p style="Margin:0;line-height:21px;letter-spacing:0;color:#333333;font-size:14px"><strong> Delivery to: </strong>' . htmlspecialchars($res1['cl_address']) . '<strong> <br></strong></p>
                                                            </td>
                                                         </tr>
                                                         <tr>
                                                            <td align="left" style="padding:0;Margin:0">
                                                               <p style="line-height:21px;letter-spacing:0;color:#333333;font-size:14px"><strong>Tracking number</strong>: <span style="color:#ca0000">' . htmlspecialchars($res1['cl_tracking_number']) . '</span></p>
                                                               
                                                               <p style="line-height:21px;letter-spacing:0;color:#333333;font-size:14px;"><strong>Courier</strong>: <span style="color:#ca0000">' . htmlspecialchars($res1['cl_courier_provider']) . '</span></p>
                                                            </td>
                                                         </tr>
                                                      </table>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                              <tr>
                                 <td align="left" bgcolor="#333333" class="esdev-adapt-off" style="padding:0;Margin:0;background-color:#333333">
                                    <table cellpadding="0" cellspacing="0" class="esdev-mso-table" role="none" style="border-collapse:collapse;border-spacing:0px;width:600px">
                                       <tr>
                                          <td valign="top" class="esdev-mso-td" style="padding:0;Margin:0">
                                             <table cellpadding="0" cellspacing="0" align="left" class="es-left" role="none" style="border-collapse:collapse;border-spacing:0px;float:left">
                                                <tr>
                                                   <td align="center" class="es-m-p0r" style="padding:0;Margin:0;width:600px">
                                                      <table role="presentation" cellpadding="0" cellspacing="0" width="100%" bgcolor="#333" style="border-collapse:collapse;border-spacing:0px;background-color:#333">
                                                         <tr>
                                                            <td align="center" style="padding:0;Margin:0;font-size:0">
                                                               <table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0" class="es-spacer" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                                  <tr>
                                                                     <td style="padding:0;Margin:0;background:none;height:0px;width:100%;margin:0px;border-bottom:1px solid #cccccc"></td>
                                                                  </tr>
                                                               </table>
                                                            </td>
                                                         </tr>
                                                      </table>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                           </table>
                        </td>
                     </tr>
                  </table>
                  <table cellpadding="0" cellspacing="0" align="center" background class="es-footer" role="none" style="border-collapse:collapse;border-spacing:0px;width:100%;table-layout:fixed !important;background-color:transparent;background-repeat:repeat;background-position:center top"></table>
                  <table cellpadding="0" cellspacing="0" align="center" class="es-footer" role="none" style="border-collapse:collapse;border-spacing:0px;width:100%;table-layout:fixed !important;background-color:transparent;background-repeat:repeat;background-position:center top">
                     <tr>
                        <td align="center" style="padding:0;Margin:0">
                           <table align="center" cellpadding="0" cellspacing="0" class="es-footer-body" style="border-collapse:collapse;border-spacing:0px;background-color:transparent;width:600px" role="none">
                              <tr>
                                 <td align="left" bgcolor="#ffffff" style="padding:0;Margin:0;padding-top:10px;padding-bottom:10px;background-color:#ffffff">
                                    <table width="100%" cellpadding="0" cellspacing="0" role="none" style="border-collapse:collapse;border-spacing:0px">
                                       <tr>
                                          <td align="left" style="padding:0;Margin:0;width:600px">
                                             <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                <tr>
                                                   <td align="center" class="es-text-4524" style="padding:0;Margin:0;padding-top:15px;padding-bottom:25px">
                                                      <p class="es-text-mobile-size-16" style="Margin:0;line-height:24px;letter-spacing:0;color:#ca0000;font-size:16px">Posty.lt</p>
                                                      <p style="Margin:0;line-height:18px;letter-spacing:0;color:#333333;font-size:12px">© 2025 Posty Logistics</p>
                                                   </td>
                                                </tr>
                                                <tr>
                                                   <td style="padding:0;Margin:0">
                                                      <table cellspacing="0" width="100%" cellpadding="0" class="es-menu" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                         <tr class="links">
                                                            <td align="center" valign="top" width="25.00%" style="Margin:0;border:0;padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px">
                                                               <div style="vertical-align:middle;display:block"><a target="_blank" href="" style="text-decoration:none;display:block;color:#999999;font-size:12px">Help</a></div>
                                                            </td>
                                                            <td align="center" valign="top" width="25.00%" style="Margin:0;border:0;padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;border-left:1px solid #cccccc">
                                                               <div style="vertical-align:middle;display:block"><a target="_blank" href="" style="text-decoration:none;display:block;color:#999999;font-size:12px">Contact</a></div>
                                                            </td>
                                                            <td width="25.00%" align="center" valign="top" style="Margin:0;border:0;padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;border-left:1px solid #cccccc">
                                                               <div style="vertical-align:middle;display:block"><a target="_blank" href="" style="text-decoration:none;display:block;color:#999999;font-size:12px">Terms of Use</a></div>
                                                            </td>
                                                            <td width="25.00%" align="center" valign="top" style="Margin:0;border:0;padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;border-left:1px solid #cccccc">
                                                               <div style="vertical-align:middle;display:block"><a href="" target="_blank" style="text-decoration:none;display:block;color:#999999;font-size:12px">Privacy Policy</a></div>
                                                            </td>
                                                         </tr>
                                                      </table>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                           </table>
                        </td>
                     </tr>
                  </table>
               </td>
            </tr>
         </table>
      </div>
   </body>
</html>';
              
                        send_email($res1['cl_email'], 'Posty', 'Posty - ' . lang('Products Shipped', $language) . ' 67371-' . $res1['cl_id'], $htmlEmailNew, null, 1, 1);

            }

         else if($data['cl_status'] == 'Delivered')
            {
                $htmlEmail = '<table style="width:100%;max-width:800px;margin:0 auto;font-family:arial;color:#595151">
                            
                            <tr>
                             <td></td>
                                <td style="padding-bottom:25px;text-align:center">
                                    <img style="" src="https://posty.lt/uploads/logo/logo.png?version=1019" style="width:60px" />
                                </div>
                                </td>
                                 <td></td>
                            </tr>
                            <tr>
                                <th colspan="3" style="font-size: 35px;padding-bottom:35px;color:black;text-align:center">
                                     #67371-' . $res1['cl_id'] . '  - ' . lang('Please Leave Review', $language) . '
                                </th>
                            </tr>
                            <tr>
                                <th colspan="3" style="text-align:left;font-size: 18px;padding-bottom:15px;color:black;font-weight:bold">
                                    ' . lang('Hello', $language) . ', ' . $res1['cl_fname'] . '!
                                </th>
                            </tr>
                            
                            <tr>
                                <td colspan="3" style="ext-align:left;font-size: 18px;padding-bottom:15px;color:black;font-weight:bold">
                                    ' . lang('Thank you for purchasing', $language) . ' www.posty.lt
                                </div>
                            </tr>

                            <tr>
                                <td colspan="3" style="ext-align:left;font-size: 18px;padding-bottom:15px;color:black">
                                    ' . lang('You will help other buyers a lot of sharing their experience and evaluating the purchased goods. It will take no more than a minute of your time', $language) . '.
                                </div>
                            </tr>
                            
                            <tr>
                                <td colspan="3" style="padding-bottom:25px;text-align:center">
                                    <a href="' . MAIN_DOMAIN . '/veikals/account/orders" style="background-color:black;color:white;padding:25px;display:block;text-decoration:none">' . lang('EVALUATE THE GOODS PURCHASED', $language) . '.</a>
                                </td>
                            </tr>

                            <tr>
                                <td colspan="3" style="ext-align:left;font-size: 18px;padding-bottom:15px;color:black">
                                    ' . lang('If you are satisfied with your work of www.posty.lt, we will be happy if you leave your positive feedback on www.posty.lt', $language) . '.
                                </div>
                            </tr>
                             <tr>
                                <th colspan="3" style="text-align: center;padding-top: 81px;font-size: 18px">
                                  ' . lang('Paldies, ka izvēlējāties Elect.lv', $language) . '!
                                </th>
                              </tr>
                             
                            ';
                            

                            $htmlEmail.= '</table>';
                            
                         

                        //send_email($res1['cl_email'], 'Posty', 'Posty - ' . lang('Products Delivered', $language) . ' 67371-' . $res1['cl_id'], $htmlEmail, null, 1, 1);

            }
            
            
           


            if($currentStatus != $data['cl_status'])
            {
                $country = $data['cl_country'];
    
                if($country == 'Latvija')
                {
                    $number = '371';
                }
                else if($country == 'Austria')
                {
                    $number = '43';
                }
                else if($country == 'Italu')
                {
                    $number = '39';
                }
                else if($country == 'Belgium')
                {
                    $number = '32';
                }
                else if($country == 'Bulgaria')
                {
                    $number = '359';
                }
                else if($country == 'Lithuania')
                {
                    $number = '370';
                }
                else if($country == 'Croati')
                {
                    $number = '385';
                }
                else if($country == 'Luxembourg')
                {
                    $number = '352';
                }
                else if($country == 'Cyprus')
                {
                    $number = '357';
                }
                else if($country == 'Malta')
                {
                    $number = '356';
                }
                else if($country == 'Czechia')
                {
                    $number = '420';
                }
                else if($country == 'Netherlands')
                {
                    $number = '31';
                }
                else if($country == 'Denmark')
                {
                    $number = '45';
                }
                else if($country == 'Poland')
                {
                    $number = '48';
                }
                else if($country == 'Estonia')
                {
                    $number = '372';
                }
                else if($country == 'Portugal')
                {
                    $number = '351';
                }
                else if($country == 'Finland')
                {
                    $number = '358';
                }
                else if($country == 'Romania')
                {
                    $number = '40';
                }
                else if($country == 'France')
                {
                    $number = '33';
                }
                else if($country == 'Slovakia')
                {
                    $number = '421';
                }
                else if($country == 'Germany')
                {
                    $number = '49';
                }
                else if($country == 'Slovenia')
                {
                    $number = '386';
                }
                else if($country == 'Greece')
                {
                    $number = '30';
                }
                else if($country == 'Spain')
                {
                    $number = '34';
                }
                else if($country == 'Hungary')
                {
                    $number = '36';
                }
                else if($country == 'Sweden')
                {
                    $number = '46';
                }else if($country == 'Ireland')
                {
                    $number = '353';
                }else if($country == 'United Kingdom')
                {
                    $number = '44';
                }
                else if($country == 'India')
                {
                    $number = '91';
                }

                $message = '';
                $number.= $data['cl_mobile'];

               
                if(isset($sms_send_checkbox) && $sms_send_checkbox == 1)
                {
                    if($data['cl_status'] == 'Delivered')
                    {
                        $message = 'Paldies kad izvēlējies POSTY.LT    Ja esi apmierināts ar mūsu apkalpošanu,mēs būtu ļoti pateicīgi par atsauksmi salīdzini.lv vai facebook lapā.';
                        //    'https://www.salidzini.lv/veikals/elect.lv    https://www.facebook.com/Eretaillv/    Jauku dienu vēlot tavs viedveikals elect.LV';
                    }
                    else if($data['cl_status'] == 'Shipped')
                    {
                         $message = lang('shipped_sms', $language, $id, $data['cl_tracking_number']);
                       // $message = 'Sveiki!    Jūsu Pasūtījums 67371-' . $id . ' ir nodots kurjeram.    Jūsu nosekošanas nr: ' . $data['cl_tracking_number'] . '    Kurjers: ' . $data['cl_courier_provider'] . '    Paldies kad izvēlējies posty.LT';
                       
                    }
                    else if($data['cl_status'] == 'Payment Received')
                    {
                        $message = lang('payment_received_sms', $language, $id);
                      //  $message = 'Paldies! Jūsu rēķina 67371-' . $id . ' veiktais maksājums ir saņemts.    Sākam sagatavot jūsu pasūtījumu izsūtīšanai.';
                    }
                    else if($data['cl_status'] == 'Money refunded')
                    {
                        $message = lang('money_refunded_sms', $language, $id);
                       // $message = 'Sveiki! Esam veikuši naudas atmaksu par pasūtījumu 67371-' . $id . '    Jūsu prece vai nu bija brāķis, vai arī tika konstatēti citi tehniski iesmesli.    Vairak informācijas par naudas atmaksas iemeslu Jūs variet uzzināt zvanot mums uz    tālruni: +371 61112470    Jauku dienu vēlot tavs viedveikals.';
                    }
                    else if($data['cl_status'] == 'Items ordered')
                    {
                        $message = 'Sveiki!    Esam pasūtījuši Jūsu 67371-' . $id . ' pasūtījuma preces, un viņas ir ceļā uz mūsu    Latvijas noliktavu.';
                    }
                    else if($data['cl_status'] == 'Items received')
                    {
                        $message = 'Sveiki!    Jūsu pasūtījuma 67371-' . $id . ' preces ir mūsu Latvijas noliktavā.    Jauku dienu vēlot tavs viedveikals     POSTY.LT';
                    }
                    else if($data['cl_status'] == 'Processing')
                    {
                        $message = 'Sākam sagatavot Jūsu pasūtījumu 67371-' . $id . ' nodošanai uz piegādi.    Jauku dienu vēlot POSTY.LT!';
                    }
                    else if($data['cl_status'] == 'Processed')
                    {
                        $message = 'Jūsu pasūtījums 67371-' . $id . ' ir apstrādāts.Un informācija nosūtīta kurjeram.    Tuvākajā laikā Jūsu pasūtījums tiks nodots uz piegādi!    Jauku dienu vēlot tavs viedveikals    POSTY.LT';
                    }
                }

                if(trim($message) != '')
                {
                    file_get_contents('https://api.text2reach.com/sms/send?api_key=15C279E8CF27FCAD9D14BE6C9C7094F5&phone=' . $number . '&from=POSTY.LT&message=' . $message);
                }
                
                
                if($data['cl_status'] == 'Payment Received')
                {
                    
                  
                            
                    
                    $htmlEmailPaymentReceived = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office" lang="en">
   <head>
      <meta charset="UTF-8">
      <meta content="width=device-width, initial-scale=1" name="viewport">
      <meta name="x-apple-disable-message-reformatting">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta content="telephone=no" name="format-detection">
      <title>New Message</title>
      <!--[if (mso 16)]>
      <style type="text/css"> a {text-decoration: none;}  </style>
      <![endif]--><!--[if gte mso 9]>
      <style>sup { font-size: 100% !important; }</style>
      <![endif]--><!--[if gte mso 9]>
      <noscript>
         <xml>
            <o:OfficeDocumentSettings>
               <o:AllowPNG></o:AllowPNG>
               <o:PixelsPerInch>96</o:PixelsPerInch>
            </o:OfficeDocumentSettings>
         </xml>
      </noscript>
      <![endif]--><!--[if mso]>
      <xml>
         <w:WordDocument xmlns:w="urn:schemas-microsoft-com:office:word">
            <w:DontUseAdvancedTypographyReadingMail/>
         </w:WordDocument>
      </xml>
      <![endif]-->
      <style type="text/css">.rollover:hover .rollover-first { max-height:0px!important; display:none!important;}.rollover:hover .rollover-second { max-height:none!important; display:block!important;}.rollover span { font-size:0px;}u + .body img ~ div div { display:none;}#outlook a { padding:0;}span.MsoHyperlink,span.MsoHyperlinkFollowed { color:inherit; mso-style-priority:99;}a.es-button { mso-style-priority:100!important; text-decoration:none!important;}a[x-apple-data-detectors],#MessageViewBody a { color:inherit!important; text-decoration:none!important; font-size:inherit!important; font-family:inherit!important; font-weight:inherit!important; line-height:inherit!important;}.es-desk-hidden { display:none; float:left; overflow:hidden; width:0; max-height:0; line-height:0; mso-hide:all;}@media only screen and (max-width:600px) {.es-m-p0r { padding-right:0px!important } .es-m-p0l { padding-left:0px!important } .es-p-default { }
         *[class="gmail-fix"] { display:none!important } p, a { line-height:150%!important } h1, h1 a { line-height:120%!important } h2, h2 a { line-height:120%!important } h3, h3 a { line-height:120%!important } h4, h4 a { line-height:120%!important } h5, h5 a { line-height:120%!important } h6, h6 a { line-height:120%!important } .es-header-body p { } .es-content-body p { } .es-footer-body p { } .es-infoblock p { } h1 { font-size:36px!important; text-align:left } h2 { font-size:26px!important; text-align:left } h3 { font-size:20px!important; text-align:left } h4 { font-size:24px!important; text-align:left } h5 { font-size:20px!important; text-align:left } h6 { font-size:16px!important; text-align:left } .es-header-body h1 a, .es-content-body h1 a, .es-footer-body h1 a { font-size:36px!important } .es-header-body h2 a, .es-content-body h2 a, .es-footer-body h2 a { font-size:26px!important }
         .es-header-body h3 a, .es-content-body h3 a, .es-footer-body h3 a { font-size:20px!important } .es-header-body h4 a, .es-content-body h4 a, .es-footer-body h4 a { font-size:24px!important } .es-header-body h5 a, .es-content-body h5 a, .es-footer-body h5 a { font-size:20px!important } .es-header-body h6 a, .es-content-body h6 a, .es-footer-body h6 a { font-size:16px!important } .es-menu td a { font-size:12px!important } .es-header-body p, .es-header-body a { font-size:14px!important } .es-content-body p, .es-content-body a { font-size:14px!important } .es-footer-body p, .es-footer-body a { font-size:14px!important } .es-infoblock p, .es-infoblock a { font-size:12px!important } .es-m-txt-c, .es-m-txt-c h1, .es-m-txt-c h2, .es-m-txt-c h3, .es-m-txt-c h4, .es-m-txt-c h5, .es-m-txt-c h6 { text-align:center!important }
         .es-m-txt-r, .es-m-txt-r h1, .es-m-txt-r h2, .es-m-txt-r h3, .es-m-txt-r h4, .es-m-txt-r h5, .es-m-txt-r h6 { text-align:right!important } .es-m-txt-j, .es-m-txt-j h1, .es-m-txt-j h2, .es-m-txt-j h3, .es-m-txt-j h4, .es-m-txt-j h5, .es-m-txt-j h6 { text-align:justify!important } .es-m-txt-l, .es-m-txt-l h1, .es-m-txt-l h2, .es-m-txt-l h3, .es-m-txt-l h4, .es-m-txt-l h5, .es-m-txt-l h6 { text-align:left!important } .es-m-txt-r img, .es-m-txt-c img, .es-m-txt-l img { display:inline!important } .es-m-txt-r .rollover:hover .rollover-second, .es-m-txt-c .rollover:hover .rollover-second, .es-m-txt-l .rollover:hover .rollover-second { display:inline!important } .es-m-txt-r .rollover span, .es-m-txt-c .rollover span, .es-m-txt-l .rollover span { line-height:0!important; font-size:0!important; display:block } .es-spacer { display:inline-table }
         a.es-button, button.es-button { font-size:20px!important; padding:10px 20px 10px 20px!important; line-height:120%!important } a.es-button, button.es-button, .es-button-border { display:inline-block!important } .es-m-fw, .es-m-fw.es-fw, .es-m-fw .es-button { display:block!important } .es-m-il, .es-m-il .es-button, .es-social, .es-social td, .es-menu { display:inline-block!important } .es-adaptive table, .es-left, .es-right { width:100%!important } .es-content table, .es-header table, .es-footer table, .es-content, .es-footer, .es-header { width:100%!important; max-width:600px!important } .adapt-img { width:100%!important; height:auto!important } .es-mobile-hidden, .es-hidden { display:none!important } .es-desk-hidden { width:auto!important; overflow:visible!important; float:none!important; max-height:inherit!important; line-height:inherit!important } tr.es-desk-hidden { display:table-row!important }
         table.es-desk-hidden { display:table!important } td.es-desk-menu-hidden { display:table-cell!important } .es-menu td { width:1%!important } table.es-table-not-adapt, .esd-block-html table { width:auto!important } .h-auto { height:auto!important } .es-text-7416 .es-text-mobile-size-28, .es-text-7416 .es-text-mobile-size-28 * { font-size:28px!important; line-height:150%!important } .es-text-3577 .es-text-mobile-size-18, .es-text-3577 .es-text-mobile-size-18 * { font-size:18px!important; line-height:150%!important } .es-text-4524 .es-text-mobile-size-16, .es-text-4524 .es-text-mobile-size-16 * { font-size:16px!important; line-height:150%!important } .es-text-3707 .es-text-mobile-size-18, .es-text-3707 .es-text-mobile-size-18 * { font-size:18px!important; line-height:150%!important } }@media screen and (max-width:384px) {.mail-message-content { width:414px!important } }
      </style>
   </head>
   <body class="body" style="width:100%;height:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;padding:0;Margin:0">
      <div dir="ltr" class="es-wrapper-color" lang="en" style="background-color:#FAFAFA">
         <!--[if gte mso 9]>
         <v:background xmlns:v="urn:schemas-microsoft-com:vml" fill="t">
            <v:fill type="tile" color="#fafafa"></v:fill>
         </v:background>
         <![endif]-->
         <table width="100%" cellspacing="0" cellpadding="0" class="es-wrapper" role="none" style="border-collapse:collapse;border-spacing:0px;padding:0;Margin:0;width:100%;height:100%;background-repeat:repeat;background-position:center top;background-color:#FAFAFA">
            <tr>
               <td valign="top" style="padding:0;Margin:0">
                  <table cellpadding="0" cellspacing="0" align="center" class="es-header" role="none" style="border-collapse:collapse;border-spacing:0px;width:100%;table-layout:fixed !important;background-color:transparent;background-repeat:repeat;background-position:center top">
                     <tr>
                        <td align="center" style="padding:0;Margin:0">
                           <table bgcolor="#cc0000" align="center" cellpadding="0" cellspacing="0" class="es-header-body" style="border-collapse:collapse;border-spacing:0px;background-color:#cc0000;width:600px" role="none">
                              <tr>
                                 <td align="left" style="padding:0;Margin:0">
                                    <table cellpadding="0" cellspacing="0" width="100%" role="none" style="border-collapse:collapse;border-spacing:0px">
                                       <tr>
                                          <td valign="top" align="center" class="es-m-p0r" style="padding:0;Margin:0;width:600px">
                                             <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                <tr>
                                                    <td></td>
                                                    <td align="center" style="padding:0;Margin:0;padding-top:7px;padding-bottom:7px;font-size:0px;width:60px"><img src="' . MAIN_DOMAIN . '/images/emails/logo.png" alt="Logo"  title="Logo" class="adapt-img" style="display:block;font-size:12px;border:0;outline:none;text-decoration:none;width:60px" width="60"></td>
                                                       <td></td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                           </table>
                        </td>
                     </tr>
                  </table>
                  <table cellpadding="0" cellspacing="0" align="center" class="es-content" role="none" style="border-collapse:collapse;border-spacing:0px;width:100%;table-layout:fixed !important">
                     <tr>
                        <td align="center" style="padding:0;Margin:0">
                           <table bgcolor="#ffffff" align="center" cellpadding="0" cellspacing="0" class="es-content-body" role="none" style="border-collapse:collapse;border-spacing:0px;background-color:#FFFFFF;width:600px">
                              <tr>
                                 <td align="left" style="padding:0;Margin:0;padding-top:15px;padding-right:20px;padding-left:20px">
                                    <table cellpadding="0" cellspacing="0" width="100%" role="none" style="border-collapse:collapse;border-spacing:0px">
                                       <tr>
                                          <td align="center" valign="top" style="padding:0;Margin:0;width:560px">
                                             <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                <tr>
                                                   <td align="center" class="es-text-7416" style="padding:0;Margin:0;padding-top:15px;padding-bottom:15px">
                                                      <h1 class="es-m-txt-c es-text-mobile-size-28" style="Margin:0;letter-spacing:0;font-size:28px;font-style:normal;font-weight:bold;line-height:28px;color:#333333">Thanks for you order!</h1>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                           </table>
                        </td>
                     </tr>
                  </table>
                  <table cellpadding="0" cellspacing="0" align="center" class="es-content" role="none" style="border-collapse:collapse;border-spacing:0px;width:100%;table-layout:fixed !important">
                     <tr>
                        <td align="center" style="padding:0;Margin:0">
                           <table bgcolor="#ffffff" align="center" cellpadding="0" cellspacing="0" class="es-content-body" role="none" style="border-collapse:collapse;border-spacing:0px;background-color:#FFFFFF;width:600px">
                              <tr>
                                 <td align="left" style="padding:0;Margin:0">
                                    <table cellpadding="0" cellspacing="0" width="100%" role="none" style="border-collapse:collapse;border-spacing:0px">
                                       <tr>
                                          <td align="center" valign="top" style="padding:0;Margin:0;width:600px">
                                             <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                <tr>
                                                   <td align="center" style="padding:0;Margin:0;font-size:0"><img src="' . MAIN_DOMAIN . '/images/emails/banner-confirmed.jpg" alt="" width="600" class="adapt-img" style="display:block;font-size:14px;border:0;outline:none;text-decoration:none"></td>
                                                </tr>
                                                <tr>
                                                   <td align="center" class="es-m-p0r es-m-p0l es-text-3577" style="Margin:0;padding-top:15px;padding-right:40px;padding-bottom:25px;padding-left:40px">
                                                      <p class="es-text-mobile-size-18" style="Margin:0;line-height:27px;letter-spacing:0;color:#333333;font-size:18px">We have received your payment, and your order is currently being processed.</p>
                                                   </td>
                                                </tr>
                                                <tr>
                                                   <td align="center" style="padding:0;Margin:0"><span class="es-button-border" style="border-style:solid;border-color:#5c68e2;background:#ca0000;border-width:0;display:inline-block;border-radius:50px;width:auto"><a href="' . MAIN_DOMAIN . '/veikals/account/orders" target="_blank" class="es-button" style="mso-style-priority:100 !important;text-decoration:none !important;color:#FFFFFF;font-size:20px;padding:10px 50px;display:inline-block;background:#ca0000;border-radius:50px;font-weight:normal;font-style:normal;line-height:24px;width:auto;text-align:center;letter-spacing:0;">Visit order details</a></span></td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                              <tr>
                                 <td align="left" class="esdev-adapt-off" style="Margin:0;padding-top:15px;padding-right:20px;padding-left:20px;padding-bottom:15px">
                                    <table cellpadding="0" cellspacing="0" class="esdev-mso-table" role="none" style="border-collapse:collapse;border-spacing:0px;width:560px">
                                       <tr>
                                          <td valign="top" class="esdev-mso-td" style="padding:0;Margin:0">
                                             <table cellpadding="0" cellspacing="0" align="right" class="es-right" role="none" style="border-collapse:collapse;border-spacing:0px;float:right">
                                                <tr>
                                                   <td align="center" style="padding:0;Margin:0;width:560px">
                                                      <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                         <tr>
                                                            <td align="left" class="es-text-3707" style="padding:0;Margin:0;padding-top:25px">
                                                               <p class="es-text-mobile-size-18" style="Margin:0;line-height:27px;letter-spacing:0;color:#333333;font-size:18px">Order summary:</p>
                                                            </td>
                                                         </tr>
                                                      </table>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>';
                    
                              $vatAmount = $res1['cl_vat_amount'];
                              $priceAfterPromoCode = $res1['cl_priceAfterPromoCode'];
                              $vatPercentage = ($vatAmount / $priceAfterPromoCode) * 100;
                              $vatPercentage = round($vatPercentage, 2);

                    
                            foreach($items AS $item)
                            { 
                                if($item['cl_image'] != '')
                                {
                                    if($item['cl_image_location'] == 'Server')
                                    { 
                                        $currentImage = MAIN_DOMAIN . '/uploads/products/' . htmlspecialchars($item['cl_image']);

                                    }
                                    else if($item['cl_image_location'] == 'CDN')
                                    {
                                        $currentImage = 'https://cdn.action.pl/File.aspx?CID=73833&UID=efix2881&PID=ec4549b100d92e60dd4c768ae1e61033&P=' . htmlspecialchars($item['cl_image']); 
                                    }
                                    else
                                    {
                                        $currentImage = $item['cl_image'];
                                    }
                                }
                                
                                
                                
                                /*$finalPrice = $this->helper->getFinalPrice($supplierPrice, $request->profitPercentageArray);
                                $salePrice = $finalPrice;
                                $itemSalePriceWithVAT = $salePrice + ($salePrice * ($request->profitPercentageArray['taxPercentage'] / 100));
                                */
                                
                                $htmlEmailPaymentReceived.= '<tr>
                                 <td align="left" class="esdev-adapt-off" style="Margin:0;padding-top:15px;padding-right:20px;padding-left:20px;padding-bottom:40px">
                                    <table cellpadding="0" cellspacing="0" class="esdev-mso-table" role="none" style="border-collapse:collapse;border-spacing:0px;width:560px">
                                       <tr>
                                          <td valign="top" class="esdev-mso-td" style="padding:0;Margin:0">
                                             <table cellpadding="0" cellspacing="0" align="left" class="es-left" role="none" style="border-collapse:collapse;border-spacing:0px;float:left">
                                                <tr>
                                                   <td align="center" class="es-m-p0r" style="padding:0;Margin:0;width:127px">
                                                      <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                         <tr>
                                                            <td align="center" style="padding:0;Margin:0;font-size:0px"><img src="' . $currentImage . '" alt="" width="69" class="adapt-img" style="display:block;font-size:14px;border:0;outline:none;text-decoration:none"></td>
                                                         </tr>
                                                      </table>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                          <td class="es-m-w0" style="padding:0;Margin:0;width:20px"></td>
                                          <td valign="top" class="esdev-mso-td" style="padding:0;Margin:0">
                                             <table cellpadding="0" cellspacing="0" align="right" class="es-right" role="none" style="border-collapse:collapse;border-spacing:0px;float:right">
                                                <tr>
                                                   <td align="center" style="padding:0;Margin:0;width:413px">
                                                      <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                         <tr>
                                                            <td align="left" style="padding:0;Margin:0;padding-top:5px">
                                                               <p style="Margin:0;line-height:21px;letter-spacing:0;color:#333333;font-size:14px"><strong> ' . $item['cl_name'] . '<br> </strong></p>
                                                            </td>
                                                         </tr>
                                                         <tr>
                                                            <td align="left" style="padding:0;Margin:0;padding-top:25px">
                                                               <p style="Margin:0;line-height:21px;letter-spacing:0;color:#333333;font-size:14px"><strong>' . lang('Cena', $language) . ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;' . lang('Daudzums', $language) . '</strong></p>
                                                               <p style="Margin:0;line-height:21px;letter-spacing:0;color:#333333;font-size:14px">€ ' . round($item['cl_amount'] + ($item['cl_amount'] * ($vatPercentage / 100)), 2) . ' &nbsp; &nbsp; &nbsp; &nbsp; ' . $item['cl_quantity'] . '</p>
                                                            </td>
                                                         </tr>
                                                      </table>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>';
                              
                            }
$htmlEmailPaymentReceived.= '<tr>
                                 <td align="left" bgcolor="#333333" class="esdev-adapt-off" style="padding:0;Margin:0;background-color:#333333">
                                    <table cellpadding="0" cellspacing="0" class="esdev-mso-table" role="none" style="border-collapse:collapse;border-spacing:0px;width:600px">
                                       <tr>
                                          <td valign="top" class="esdev-mso-td" style="padding:0;Margin:0">
                                             <table cellpadding="0" cellspacing="0" align="left" class="es-left" role="none" style="border-collapse:collapse;border-spacing:0px;float:left">
                                                <tr>
                                                   <td align="center" class="es-m-p0r" style="padding:0;Margin:0;width:600px">
                                                      <table cellpadding="0" cellspacing="0" width="100%" role="presentation" bgcolor="#333" style="border-collapse:collapse;border-spacing:0px;background-color:#333">
                                                         <tr>
                                                            <td align="center" style="padding:0;Margin:0;font-size:0">
                                                               <table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0" class="es-spacer" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                                  <tr>
                                                                     <td style="padding:0;Margin:0;border-bottom:1px solid #cccccc;background:none;height:0px;width:100%;margin:0px"></td>
                                                                  </tr>
                                                               </table>
                                                            </td>
                                                         </tr>
                                                      </table>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                           </table>
                        </td>
                     </tr>
                  </table>
                  <table cellpadding="0" cellspacing="0" align="center" background class="es-footer" role="none" style="border-collapse:collapse;border-spacing:0px;width:100%;table-layout:fixed !important;background-color:transparent;background-repeat:repeat;background-position:center top"></table>
                  <table cellpadding="0" cellspacing="0" align="center" class="es-footer" role="none" style="border-collapse:collapse;border-spacing:0px;width:100%;table-layout:fixed !important;background-color:transparent;background-repeat:repeat;background-position:center top">
                     <tr>
                        <td align="center" style="padding:0;Margin:0">
                           <table align="center" cellpadding="0" cellspacing="0" class="es-footer-body" style="border-collapse:collapse;border-spacing:0px;background-color:transparent;width:600px" role="none">
                              <tr>
                                 <td align="left" bgcolor="#ffffff" style="padding:0;Margin:0;padding-top:10px;padding-bottom:10px;background-color:#ffffff">
                                    <table cellpadding="0" cellspacing="0" width="100%" role="none" style="border-collapse:collapse;border-spacing:0px">
                                       <tr>
                                          <td align="left" style="padding:0;Margin:0;width:600px">
                                             <table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                <tr>
                                                   <td align="center" class="es-text-4524" style="padding:0;Margin:0;padding-top:15px;padding-bottom:25px">
                                                      <p class="es-text-mobile-size-16" style="Margin:0;line-height:24px;letter-spacing:0;color:#ca0000;font-size:16px">Posty.lt</p>
                                                      <p style="Margin:0;line-height:18px;letter-spacing:0;color:#333333;font-size:12px">© 2025 Posty Logistics</p>
                                                   </td>
                                                </tr>
                                                <tr>
                                                   <td style="padding:0;Margin:0">
                                                      <table cellpadding="0" cellspacing="0" width="100%" class="es-menu" role="presentation" style="border-collapse:collapse;border-spacing:0px">
                                                         <tr class="links">
                                                            <td align="center" valign="top" width="25.00%" style="Margin:0;border:0;padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px">
                                                               <div style="vertical-align:middle;display:block"><a target="_blank" href="https://posty.lt/lt/Kontakti" style="text-decoration:none;display:block;color:#999999;font-size:12px">Help</a></div>
                                                            </td>
                                                            <td align="center" valign="top" width="25.00%" style="Margin:0;border:0;padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;border-left:1px solid #cccccc">
                                                               <div style="vertical-align:middle;display:block"><a target="_blank" href="https://posty.lt/lt/Kontakti" style="text-decoration:none;display:block;color:#999999;font-size:12px">Contact</a></div>
                                                            </td>
                                                            <td align="center" valign="top" width="25.00%" style="Margin:0;border:0;padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;border-left:1px solid #cccccc">
                                                               <div style="vertical-align:middle;display:block"><a target="_blank" href="https://posty.lt/lt/Kontakti" style="text-decoration:none;display:block;color:#999999;font-size:12px">Terms of Use</a></div>
                                                            </td>
                                                            <td align="center" valign="top" width="25.00%" style="Margin:0;border:0;padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;border-left:1px solid #cccccc">
                                                               <div style="vertical-align:middle;display:block"><a target="_blank" href="https://posty.lt/lt/Kontakti" style="text-decoration:none;display:block;color:#999999;font-size:12px">Privacy Policy</a></div>
                                                            </td>
                                                         </tr>
                                                      </table>
                                                   </td>
                                                </tr>
                                             </table>
                                          </td>
                                       </tr>
                                    </table>
                                 </td>
                              </tr>
                           </table>
                        </td>
                     </tr>
                  </table>
               </td>
            </tr>
         </table>
      </div>
   </body>
</html>';
                         

                        send_email($res1['cl_email'], 'Posty', 'Posty - ' . lang('Payment Confirmed', $language) . ' 67371-' . $res1['cl_id'], $htmlEmailPaymentReceived, null, 1, 1);
                }
            }

            if(!isset($_POST['reload']))
            {
                header('Location:list.php?message=Updated Successfully');
                exit;
            }

            $msg = 'User Order Updated Successfully';
            
        }
        else {
            $msg = 'Something Went Wrong';
        }
	}
}

$templateType = 'edit';
$res1 = $dev->Getdata($id);
$items = $dev->getOrderItemsGeneral($id);
$itemsVariable = $dev->getOrderItemsVariable($id);

$pickUpPointID = $res1['cl_pickup_point'];
if($pickUpPointID != 0)
{
    $pickuPoint = $dev->getPickUpPoint($pickUpPointID);
   
}


include '../header.php';
?>
<link rel="stylesheet" href="../jquery_file_upload/css/style.css">
<link rel="stylesheet" href="../jquery_file_upload/css/jquery.fileupload.css">
            <!-- MAIN CONTENT-->
            <div class="main-content">
                <div class="section__content section__content--p30">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="overview-wrap">
                                    <h2 class="title-1">
                                        Edit Order
                                        <button type="button" class="btn btn-danger" id="order_email_again">Send Order Email Again</button>
                                         <button type="button" class="btn btn-success" id="invoice_create">Create Invoice Only</button>
                                         <a class="btn btn-primary" href="#amount_quantity_edit">Edit Amount and Quantity</a>

                                         <?php
                                         if($res1['cl_courier_provider'] == 'DPD' && trim($res1['cl_tracking_number']) == '')
                                            { ?>
                                         <button type="button" class="btn btn-info" id="label_create">Create Shipping Label</button>
                                         <?php
                                     }
                                     else if($res1['cl_courier_provider'] == 'DPD')
                                     {
                                        ?>
                                         <div class="alert alert-warning">Shipping Label created already. If you want to create new, clear existing tracking id, and save.</div>
                                         <?php
                                     }
                                     ?>


                                        <div class="order_email_error"></div>
                                    </h2>
                                    
                                </div>
								<?php if($msg !=''){echo '<span class="col-md-6 alert alert-danger pull-left">'.$msg.'</span>';}?>
                            </div>
                        </div>
                        
                        <div class="row m-t-25 m-row">
					
                            <div class="col-md-6 col-xs-12">
                                <div class="card">
                                    
                                    <div class="card-body card-block">
									<form method="post" accept-charset="UTF-8">
                                        <div class="form-group">
                                           
                                            <label for="Firstname" class=" form-control-label">Firstname</label>
                                            <input type="text" name="data[cl_fname]" id="Firstname" placeholder="Firstname" class="form-control" value="<?php echo htmlspecialchars($res1['cl_fname']);?>"/>
                                        </div>
                                        <div class="form-group">
                                            <label for="Surname" class=" form-control-label">Surname</label>
                                            <input type="text" name="data[cl_surname]" id="Surname" placeholder="Surname" class="form-control" value="<?php echo htmlspecialchars($res1['cl_surname']);?>"/>
                                        </div>
                                        <div class="form-group">
                                            <label for="Mobile" class=" form-control-label">Mobile</label>
                                            <input type="text" name="data[cl_mobile]" id="Mobile" placeholder="Mobile" class="form-control" value="<?php echo htmlspecialchars($res1['cl_mobile']);?>"/>
                                        </div>
                                         <div class="form-group">
                                               <label for="email" class=" form-control-label">Email</label>
                                             <input type="text" class="form-control" name="data[cl_email]" id="email" placeholder="E-mail" value="<?php echo htmlspecialchars($res1['cl_email']);?>">
                                        </div>
                                        <div class="form-group">
                                               <label for="address" class=" form-control-label">Address</label>
                                             <input type="text" class="form-control" name="data[cl_address]" id="address" placeholder="Address" value="<?php echo htmlspecialchars($res1['cl_address']);?>">
                                        </div>
                                         <div class="form-group">
                                               <label for="city" class=" form-control-label">City</label>
                                             <input type="text" class="form-control" name="data[cl_city]" id="city" placeholder="City" value="<?php echo htmlspecialchars($res1['cl_city']);?>">
                                        </div>
                                         <div class="form-group">
                                               <label for="country" class=" form-control-label">County</label>
                                             <input type="text" class="form-control" name="data[cl_country]" id="country" placeholder="Country" value="<?php echo htmlspecialchars($res1['cl_country']);?>">
                                        </div>
                                        <div class="form-group">
                                               <label for="pasta_indeks" class=" form-control-label">Pasta Indeks</label>
                                             <input type="text" class="form-control" name="data[cl_pasta_indeks]" id="pasta_indeks" placeholder="pasta_indeks" value="<?php echo htmlspecialchars($res1['cl_pasta_indeks']);?>">
                                        </div>
                                         <div class="form-group">
                                               <label for="status" class=" form-control-label">Order Status</label>
                                             <select type="text" class="form-control" name="data[cl_status]" id="status">
                                                 <option value="Processing" <?php if($res1['cl_status'] == 'Processing'){echo 'selected';} ?>>Processing</option>
                                                 <option value="Processing2" <?php if($res1['cl_status'] == 'Processing2'){echo 'selected';} ?>>Processing2</option>
                                                 <option value="Processing3" <?php if($res1['cl_status'] == 'Processing3'){echo 'selected';} ?>>Processing3</option>
                                                 <option value="Processing4" <?php if($res1['cl_status'] == 'Processing4'){echo 'selected';} ?>>Processing4</option>
                                                 <option value="Processed" <?php if($res1['cl_status'] == 'Processed'){echo 'selected';} ?>>Processed</option>
                                                 <option value="Processed2" <?php if($res1['cl_status'] == 'Processed2'){echo 'selected';} ?>>Processed2</option>
                                                 <option value="Processed3" <?php if($res1['cl_status'] == 'Processed3'){echo 'selected';} ?>>Processed3</option>
                                                 <option value="Processed7" <?php if($res1['cl_status'] == 'Processed7'){echo 'selected';} ?>>Processed7</option>
                                                 <option value="Processed8" <?php if($res1['cl_status'] == 'Processed8'){echo 'selected';} ?>>Processed8</option>
                                                 <option value="Waiting on payment" <?php if($res1['cl_status'] == 'Waiting on payment'){echo 'selected';} ?>>Waiting on payment</option>
                                                 <option value="Payment Received" <?php if($res1['cl_status'] == 'Payment Received'){echo 'selected';} ?>>Payment Received</option>
                                                 <option value="Being prepared for shipping" <?php if($res1['cl_status'] == 'Being prepared for shipping'){echo 'selected';} ?>>Being prepared for shipping</option>
                                                  <option value="Being prepared for shipping2" <?php if($res1['cl_status'] == 'Being prepared for shipping2'){echo 'selected';} ?>>Being prepared for shipping2</option>
                                                   <option value="Being prepared for shipping3" <?php if($res1['cl_status'] == 'Being prepared for shipping3'){echo 'selected';} ?>>Being prepared for shipping3</option>
                                                 <option value="Shipped" <?php if($res1['cl_status'] == 'Shipped'){echo 'selected';} ?>>Shipped</option>
                                                 <option value="Delivered" <?php if($res1['cl_status'] == 'Delivered'){echo 'selected';} ?>>Delivered</option>
                                                  <option value="Cancelled"<?php if($res1['cl_status'] == 'Cancelled'){echo 'selected';} ?>>Cancelled</option>
                                                  <option value="Items ordered" <?php if($res1['cl_status'] == 'Items ordered'){echo 'selected';} ?>>Items ordered</option>
                                                  <option value="Items received"<?php if($res1['cl_status'] == 'Items received'){echo 'selected';} ?>>Items received</option>
                                                  <option value="Money refunded" <?php if($res1['cl_status'] == 'Money refunded'){echo 'selected';} ?>>Money refunded</option>
                                                  <option value="Money requested" <?php if($res1['cl_status'] == 'Money requested'){echo 'selected';} ?>>Money requested</option>
                                             </select> 
                                        </div>

                                        <div class="form-group">
                                            <input type="checkbox" checked="checked" name="data[sms_send_checkbox]" value="1" /> Send sms if status changed 
                                        </div>
                                        <div class="form-group">
                                               <label for="company_name" class=" form-control-label">Expected Delivery Date</label>
                                             <input type="text" class="form-control datepicker" name="data[cl_expected_delivery_date]" id="expected_delivery_date" placeholder="Expected Delivery Date" value="<?php if(trim($res1['cl_expected_delivery_date']) != ''){echo htmlspecialchars(date("d M Y", strtotime($res1['cl_expected_delivery_date'])));}?>">
                                        </div>
                                        <div class="form-group">
                                               <label for="company_name" class=" form-control-label">Delivery Date</label>
                                             <input type="text" class="form-control datepicker" name="data[cl_delivery_date]" id="delivery_date" placeholder="Delivery Date" value="<?php if(trim($res1['cl_delivery_date']) != ''){echo htmlspecialchars(date("d M Y", strtotime($res1['cl_delivery_date'])));}?>">
                                        </div>
                                         <div class="form-group">
                                               <label for="courier_provider" class=" form-control-label">Courier Provider</label>
                                             <input type="text" class="form-control" name="data[cl_courier_provider]" id="courier_provider" placeholder="courier provider" value="<?php echo htmlspecialchars($res1['cl_courier_provider']);?>">
                                        </div>
                                         <div class="form-group">
                                               <label for="tracking_number" class=" form-control-label">Tracking Number</label>
                                             <input type="text" class="form-control" name="data[cl_tracking_number]" id="tracking_number" placeholder="tracking number" value="<?php echo htmlspecialchars($res1['cl_tracking_number']);?>">
                                        </div>
                                        <div class="form-group">
                                               <label for="checkout_type" class=" form-control-label">Checkout Type</label>
                                             <select type="text" class="form-control" name="data[cl_checkout_type]" id="checkout_type">
                                                 <option value="ind" <?php if($res1['cl_checkout_type'] == 'ind'){echo 'selected';} ?>>Individual</option>
                                                 <option value="com"<?php if($res1['cl_checkout_type'] == 'com'){echo 'selected';} ?>>Company</option>
                                                
                                             </select> 
                                        </div>
                                        
                                        <div class="form-group">
                                               <label for="company_name" class=" form-control-label">Company Name</label>
                                             <input type="text" class="form-control" name="data[cl_company_name]" id="company_name" placeholder="company name" value="<?php echo htmlspecialchars($res1['cl_company_name']);?>">
                                        </div>
                                        <div class="form-group">
                                               <label for="registration_number" class=" form-control-label">Registration Number</label>
                                             <input type="text" class="form-control" name="data[cl_registration_number]" id="registration_number" placeholder="registration number" value="<?php echo htmlspecialchars($res1['cl_registration_number']);?>">
                                        </div>
                                        <div class="form-group">
                                               <label for="vat_number" class=" form-control-label">VAT Number</label>
                                             <input type="text" class="form-control" name="data[cl_vat_number]" id="vat_number" placeholder="vat number" value="<?php echo htmlspecialchars($res1['cl_vat_number']);?>">
                                        </div>
                                        <div class="form-group">
                                               <label for="vat_number" class=" form-control-label">Amount Calculation</label>
                                             <select class="form-control" name="data[cl_price_calculation]" id="price_calculation" placeholder="Price Calculation" value="<?php echo htmlspecialchars($res1['cl_vat_number']);?>">
                                                 <option value="Automatic" <?php if($res1['cl_price_calculation'] == 'Automatic'){echo 'selected';} ?>>Automatic</option>
                                                 <option value="Manual" <?php if($res1['cl_price_calculation'] == 'Manual'){echo 'selected';} ?>>Manual</option>
                                             </select>
                                        </div>
                                         <div class="form-group">
                                               <label for="notes" class=" form-control-label">Notes</label>
                                             <textarea class="form-control" name="data[cl_notes]" id="notes" placeholder="Notes" style="height:250px"> <?php echo htmlspecialchars($res1['cl_notes']);?></textarea>
                                        </div>
                                        <div class="form-group input-container">
                                            <label for="file" class=" form-control-label">Invoice</label>
                                                <input type="hidden" class="image" name="data[cl_invoice_doc]" value="<?php if(isset($res1['cl_invoice_doc'])){echo $res1['cl_invoice_doc'];}?>"/>
                                                <input type="hidden" class="name"   />
                                                    <!-- The container for the uploaded files -->
                                                    <span class="btn btn-success fileinput-button">
                                                    <i class="glyphicon glyphicon-plus"></i>
                                                    <span>Select file</span>
                                                    <!-- The file input field used as target for the file upload widget -->
                                                    <input class="fileupload" type="file" name="file" >
                                                    </span>
                                                    <br>
                                                <br>
                                                <!-- The global progress bar -->
                                                <div class="progress">
                                                    <div class="progress-bar progress-bar-success"></div>
                                                </div>
                                                <!-- The container for the uploaded files -->
                                              <?php
                                                  if($templateType == 'edit')
                                    {
                                        $current='<div class="col-xs-12 col-sm-12"><span class="files_area">Current Invoice (Manual): <a target="_blank" class="" href="../uploads/invoice/' . $res1['cl_invoice_doc'].'">Download</a></span></div>';

                                        $current.= '<div class="col-xs-12 col-sm-12"><span class="files_area">Current Invoice (Automatic): <a target="_blank" class="" href="' . MAIN_DOMAIN . '/uploads/invoice/' . $res1['cl_auto_invoice_doc'].'">Download</a></span></div>';
                                    }
                                    else
                                    {
                                        $current='';
                                    }
                                    ?>
                                            <?php echo $current;?>
                                                <div class="file_name">
                                                        
                                                    </div>
                                                 <div class="error_area"></div>

                                            <div class="error-input"></div>
                                        </div>

                                         <div class="form-group input-container">
                                            <label for="file" class=" form-control-label">Warranty Card</label>
                                                <input type="hidden" class="image" name="data[cl_warranty_card]" value="<?php if(isset($res1['cl_warranty_card'])){echo $res1['cl_warranty_card'];}?>"/>
                                                <input type="hidden" class="name"   />
                                                    <!-- The container for the uploaded files -->
                                                    <span class="btn btn-success fileinput-button">
                                                    <i class="glyphicon glyphicon-plus"></i>
                                                    <span>Select file</span>
                                                    <!-- The file input field used as target for the file upload widget -->
                                                    <input class="fileuploadWarrantyCard" type="file" name="file" >
                                                    </span>
                                                    <br>
                                                <br>
                                                <!-- The global progress bar -->
                                                <div class="progress">
                                                    <div class="progress-bar progress-bar-success"></div>
                                                </div>
                                                <!-- The container for the uploaded files -->
                                              <?php
                                                  if($templateType == 'edit')
                                    {
                                        $current='<span class="files_area">Current Warranty Card : <a target="_blank" class="" href="../uploads/warranty_card/' . $res1['cl_warranty_card'].'">Download</a></span>';
                                    }
                                    else
                                    {
                                        $current='';
                                    }
                                    ?>
                                            <?php echo $current;?>
                                                <div class="file_name">
                                                        
                                                    </div>
                                                 <div class="error_area"></div>

                                            <div class="error-input"></div>
                                        </div>
                                        
										<div class="form-group">
                      <div class="btn-container col-xs-12 col-sm-12 pull-left">
                         <button type="submit" class="track-btn pull-right">Submit</button>
                          <button type="submit" class="track-btn pull-right" name="reload">Submit And Reload Page</button>
                      </div>

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




                             

                             <div class="col-md-6 col-xs-12">
                                        <div class="card">
                                            <div class="card-body card-block">
                                                <div class="col-sm-12 col-xs-12 pull-left">
                                                    <h5 class="small-heading py-4">Pasūtītāja dati</h5>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>Type</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_checkout_type']);?> </p>
                                                        </div>
                                                    </div>
                                                    <?php
                                                    if($res1['cl_checkout_type'] == 'ind')
                                                        { ?>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>Vārds</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_fname']);?> </p>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>Uzvārds</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_surname']);?> </p>
                                                        </div>
                                                    </div>
                                                    <?php
                                                }
                                                else
                                                {
                                                ?>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>Company Name</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_company_name']);?> </p>
                                                        </div>
                                                    </div>

                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>Registration Number</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_registration_number']);?> </p>
                                                        </div>
                                                    </div>

                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>VAT Number</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_vat_number']);?> </p>
                                                        </div>
                                                    </div>

                                                <?php
                                            }
                                            ?>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>Kontakttālrunis</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_mobile']);?></p>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>E-pasts</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_email']);?></p>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="col-md-12 pull-left">
                                                    <h5 class="small-heading py-4">Piegādes adrese</h5>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>Pilsēta</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_city']);?> </p>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>Novads</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_country']);?></p>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>Adrese</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_address']);?><br/>
                                                            <?php echo htmlspecialchars($res1['cl_pin']);?>
                                                            </p>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>Pasta indeks</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_pasta_indeks']);?> </p>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <p><strong>IP</strong></p>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <p><?php echo htmlspecialchars($res1['cl_ip']);?> </p>
                                                        </div>
                                                    </div>
                                                </div>  

                                                <div class="col-md-12 col-xs-12 pull-left no-padding">
                                                    
                                                    <div class="col-sm-12 pull-left">
                                                        <div class="row">
                                                        <div class="col-md-4">
                                                                <p><strong>Delivery Type</strong></p>
                                                            </div>
                                                            <div class="col-md-8">
                                                                <p><?php echo htmlspecialchars($res1['cl_delivery_type']);?> </p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12 pull-left">
                                                        <div class="row">
                                                        <div class="col-md-4">
                                                                <p><strong>Payment Type</strong></p>
                                                            </div>
                                                            <div class="col-md-8">
                                                                <p><?php echo htmlspecialchars($res1['cl_payment_type']);?> </p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12 pull-left">
                                                        <div class="row">
                                                        <div class="col-md-4">
                                                                <p><strong>Payment Reference</strong></p>
                                                            </div>
                                                            <div class="col-md-8">
                                                                <p><?php echo htmlspecialchars($res1['cl_payment_reference']);?> </p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12 pull-left">
                                                        <div class="row">
                                                        <div class="col-md-4">
                                                                <p><strong>Courier Provider</strong></p>
                                                            </div>
                                                            <div class="col-md-8">
                                                                <p><?php echo htmlspecialchars($res1['cl_courier_provider']);?> </p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12 pull-left">
                                                        <div class="row">
                                                        <div class="col-md-4">
                                                                <p><strong>Tracking Number</strong></p>
                                                            </div>
                                                            <div class="col-md-8">
                                                                <p><?php echo htmlspecialchars($res1['cl_tracking_number']);?> </p>
                                                            </div>
                                                        </div>
                                                    </div>

                                                    <div class="col-sm-12 pull-left">
                                                        <div class="row">
                                                        <div class="col-md-4">
                                                                <p><strong>Shipping Method</strong></p>
                                                            </div>
                                                            <div class="col-md-8">
                                                                <p><?php echo htmlspecialchars($res1['cl_shipping_method']);?> </p>
                                                            </div>
                                                        </div>
                                                    </div>

                                                    <?php
                                                    if(isset($pickuPoint))
                                                    {

                                                        ?>
                                                    <div class="col-sm-12 pull-left">
                                                        <div class="row">
                                                        <div class="col-md-4">
                                                                <p><strong>Pickup Point</strong></p>
                                                            </div>
                                                            <div class="col-md-8">
                                                                <p><?php echo htmlspecialchars($pickuPoint['cl_name']);?><br/>
                                                                    <?php echo htmlspecialchars($pickuPoint['cl_address1']);?><br/>
                                                                    <?php echo htmlspecialchars($pickuPoint['cl_address2']);?><br/>
                                                                    <?php echo htmlspecialchars($pickuPoint['cl_city']);?><br/>
                                                                    ZIP : <?php echo htmlspecialchars($pickuPoint['cl_postcode']);?><br/>
                                                                    Country : <?php echo htmlspecialchars($pickuPoint['cl_country']);?><br/>
                                                                    Courier Provider : <?php echo htmlspecialchars($pickuPoint['cl_courier_provider']);?><br/>

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

                                                    <?php 
                                                }
                                                ?>


                                                    

                                                    <div class="col-sm-12 pull-left">
                                                        <div class="row">
                                                        <div class="col-md-4">
                                                                <p><strong>Status</strong></p>
                                                            </div>
                                                            <div class="col-md-8">
                                                                <p><?php echo htmlspecialchars($res1['cl_status']);?> </p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                   
                                                   

                                                    <div class="col-sm-12 pull-left">
                                                        <div class="row">
                                                            <div class="col-md-4">
                                                                <p><strong>Created On</strong></p>
                                                            </div>
                                                            <div class="col-md-8">
                                                                <p><?php echo date("d M Y H:i:s", strtotime($res1['cl_created_at']));?> </p>
                                                            </div>
                                                        </div>
                                                    </div>  
                                                
                                                   
                                     
                                            </div>

                                            <?php 
                                if($res1['cl_payment_type'] == 'Loan')
                                { ?>
                                <div class="well-white col-sm-12 col-xs-12 no-padding">
                                    <h5 class="small-heading col-sm-12 py-4">Līzings</h5>
                                    
                                    <div class="col-md-12 pull-left">
                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Down Payment</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_down_payment']);?> </p>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Number of Payment Terms</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_payment_terms']);?> </p>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Vārds</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_fname']);?> </p>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Uzvārds</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_surname']);?> </p>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Persons kods</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_kods']);?> </p>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Pases numurs</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_id_card']);?> </p>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Loan Expiration Date</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars(date("d M Y", strtotime($res1['cl_loan_expiration_date'])));?> </p>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>City / Parish / State</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_city_state']);?> </p>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Street / Village</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_street_village']);?> </p>
                                            </div>
                                        </div>

                                    </div>
                                    <div class="col-md-12 pull-left">

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Apartment Number</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_apartment_number']);?> </p>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Pasta Index</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_pasta_index']);?> </p>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Phone</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_phone']);?> </p>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Additional Phone</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_additional_phone']);?> </p>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Workplace</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_workplace']);?> </p>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Periods Worked</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_periods_worked']);?> </p>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Amats</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_amats']);?> </p>
                                            </div>
                                        </div>
                                        
                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Alga</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_alga']);?> </p>
                                            </div>
                                        </div>
                                        
                                        <div class="row">
                                            <div class="col-md-4">
                                                <p><strong>Existing Loan</strong></p>
                                            </div>
                                            <div class="col-md-8">
                                                <p><?php echo htmlspecialchars($res1['cl_loan_existing_loan']);?> </p>
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="row mt-4">
                                            <div class="col-md-8">
                                                <p><strong>Aizņēmējs: Vai Jūs esat politiski nozīmīga persona, politiski nozīmīgas personas ģimenes loceklis vai ar politiski nozīmīgu personu cieši saistīta persona?</strong></p>
                                            </div>
                                            <div class="col-md-4">
                                                <p>
                                                <?php
                                                if($res1['cl_loan_1_checkbox'] == 1)
                                                {
                                                    echo 'Yes';
                                                }
                                                else
                                                {
                                                    echo 'No';
                                                }
                                                ?>
                                                </p>
                                            </div>
                                        </div>
                                        
                                        <div class="row mt-4">
                                            <div class="col-md-8">
                                                <p><strong>Vai Jūs esat patiesais labuma guvējs plānotā darījuma?</strong></p>
                                            </div>
                                            <div class="col-md-4">
                                                <p>
                                                <?php
                                                if($res1['cl_loan_2_checkbox'] == 1)
                                                {
                                                    echo 'Yes';
                                                }
                                                else
                                                {
                                                    echo 'No';
                                                }
                                                ?>
                                                </p>
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="row mt-4">
                                            <div class="col-md-8">
                                                <p><strong>AS "LATEKO LĪZINGS", reģistrācijas nr. 40003366651, Katlakalna ielā 1, Rīgā, LV-1073 kā pārzinis saņem un apstrādā manus personas datus kredītspējas izvērtēšanai pirms līguma noslēgšanas. Pārzinis kredītspējas izvērtēšanai saņem informāciju par mani no trešām personām (AS "CREFO Birojs", AS Kredītinformācijas Birojs, Iedzīvotāju reģistrs, Valsts ieņēmumu dienests un no citām bāzēm un reģistriem, ar kuriem uz šī pieteikuma iesniegšanas brīdi AS „LATEKO LĪZINGS” tiek noslēgts līgums).<br/>
Ar informāciju par personas datu apstrādes politiku, kuru īsteno AS „LATEKO LĪZINGS”, var iepazīties <a href="https://latekolizings.lv/lv/privatuma-atruna" target="_blank">https://latekolizings.lv/lv/privatuma-atruna</a></strong></p>
                                            </div>
                                            <div class="col-md-4">
                                                <p>
                                                <?php
                                                if($res1['cl_loan_3_checkbox'] == 1)
                                                {
                                                    echo 'Yes';
                                                }
                                                else
                                                {
                                                    echo 'No';
                                                }
                                                ?>
                                                </p>
                                            </div>
                                        </div>

                                        
                                    </div>
                                  
                                    
                                </div>
                                <?php
                                }
                                ?>

                                
                                        </div>

                                         <div class="card top-margin">
                                            <div class="card-body card-block">
                                                <div class="table-responsive table--no-card m-b-30 top-margin pull-left">
                                    
                                                    <table class="table table-borderless table-data3 ACP_table" style="width:100%">
                                                        <thead>
                                                            <tr>
                                                                <th colspan="6" style="text-align: left;">
                                                                    General
                                                                </th>
                                                            </tr>
                                                            <tr>
                                                                <th>Product Name</th>
                                                               
                                                                <th>Supplier</th>
                                                                <th>Product ID</th>

                                                                <th>Sale Price</th>
                                                                <th>Quantity</th>
                                                                <th>Total</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                           <?php
                                                           $total = 0;

                                                            foreach($items AS $orders)
                                                            {
                                                                
                                                                //$product = $obj->getProduct($orders['cl_product_id']);
                                                            
                                                                //$product = $product[0];
                                                                //if($product)
                                                                //{
                                                            ?>
                                                                <tr class="action-container">
                                                                    <td><?php echo htmlspecialchars($orders['cl_name']);?></td>
                                                                    <td><?php echo htmlspecialchars($orders['cl_supplier']);?></td>
                                                                    <td><?php echo htmlspecialchars($orders['cl_product_id']);?></td>
                                                                    
                                                                    
                                                                    <td>$<?php echo htmlspecialchars($orders['cl_amount']) / htmlspecialchars($orders['cl_quantity']);?></td>
                                                                    <td> <?php echo htmlspecialchars($orders['cl_quantity']);?></td>
                                                                    <td>$<?php echo htmlspecialchars($orders['cl_amount']);?></td>
                                                                    <?php $total+= $orders['cl_amount'] ?>
                                                                    
                                                                </tr>
                                                            <?php
                                                        //}
                                                            }
                                                            ?>
                                                           
                                                        </tbody>
                                                        <tfoot>
                                                            
                                                            <tr>
                                                                <td colspan="6" style="text-align: right">
                                                                    Final Total : $<?php echo $res1['cl_total'] ?>
                                                                </td>
                                                            </tr>
                                                        </tfoot>
                                                    </table>

                                                    <table class="table table-borderless table-data3 ACP_table" style="width:100%">
                                                        <thead>
                                                            <tr>
                                                                <th colspan="7" style="text-align: left;">
                                                                    Varaible
                                                                </th>
                                                            </tr>
                                                            <tr>
                                                                <th>Product Name</th>
                                                                <th>Specifications</th>
                                                                <th>Supplier</th>
                                                                <th>Product ID</th>

                                                                <th>Sale Price</th>
                                                                <th>Quantity</th>
                                                                <th>Total</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                           <?php
                                                           $total = 0;

                                                            foreach($itemsVariable AS $orders)
                                                            {
                                                                
                                                                //$product = $obj->getProduct($orders['cl_product_id']);
                                                            
                                                                //$product = $product[0];
                                                                //if($product)
                                                                //{
                                                            ?>
                                                                <tr class="action-container">
                                                                    <td><?php echo htmlspecialchars($orders['cl_name']);?></td>
                                                                    <td><?php echo htmlspecialchars($orders['spec']);?> </td>
                                                                    <td><?php echo htmlspecialchars($orders['cl_supplier']);?></td>
                                                                    <td><?php echo htmlspecialchars($orders['cl_product_id']);?></td>
                                                                    
                                                                    
                                                                    <td>$<?php echo htmlspecialchars($orders['cl_amount']) / htmlspecialchars($orders['cl_quantity']);?></td>
                                                                    <td> <?php echo htmlspecialchars($orders['cl_quantity']);?></td>
                                                                    <td>$<?php echo htmlspecialchars($orders['cl_amount']);?></td>
                                                                    <?php $total+= $orders['cl_amount'] ?>
                                                                    
                                                                </tr>
                                                            <?php
                                                        //}
                                                            }
                                                            ?>
                                                           
                                                        </tbody>
                                                        <tfoot>
                                                            
                                                            <tr>
                                                                <td colspan="6" style="text-align: right">
                                                                    Final Total : $<?php echo $res1['cl_total'] ?>
                                                                </td>
                                                            </tr>
                                                        </tfoot>
                                                    </table>

                                                    
                                                    
                                                </div>
                                            </div>

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



                        <?php
                        if($groupArray['short'] == 'ADM')
                        { ?>
<div class="col-xs-12 col-sm-12" id="amount_quantity_edit">
                        <div class="card">
                                    
                                    <div class="card-body card-block">               

<div class="col-xs-12 col-sm-12 pull-left">
  <table class="table table-bordered ACP_table" style="width:100%">

    <thead>
      <tr>
        <th colspan="6"> 
          Existing Items
        </th>
      </tr>
      <tr>
        <th>
          Item
        </th>
        <th>
          Quantity
        </th>
        <th>
          Amount
        </th>
       <th>
        Digital
       </th>
       <th>
        Code
       </th>
        <th>

        </th>
      </tr>
    </thead>
    <tbody>
      <?php
       $pvn = 0;
       $total = 0;
        if(!empty($items))
        {
          foreach($items AS $item)
          {

             if($item['cl_supplier_price'] < 20)
                {
                    $profitPercentage = $profitPercentage0_20;
                }
                else if($item['cl_supplier_price'] >= 20 && $item['cl_supplier_price'] <= 50)
                {
                    $profitPercentage = $profitPercentage20_50;
                }
                else if($item['cl_supplier_price'] >= 50 && $item['cl_supplier_price'] <= 100)
                {
                    $profitPercentage = $profitPercentage50_100;
                }
                else if($item['cl_supplier_price'] >= 100 && $item['cl_supplier_price'] <= 200)
                {
                    $profitPercentage = $profitPercentage100_200;
                }
             else if($item['cl_supplier_price'] >= 200 && $item['cl_supplier_price'] <= 800)
              {
                $profitPercentage = $profitPercentage200_800;
              }
              else
              {
                $profitPercentage = $profitPercentageMoreThan800;
              }

               $salePrice = $item['cl_supplier_price'] + ($item['cl_supplier_price'] * $profitPercentage / 100);
            ?>
            <tr cluster-id="<?php echo $item['cl_id'] ?>">
              <td>
                <?php echo htmlspecialchars($item['cl_name']) ?>
              </td>
              <td>
               <input type="text" class="form-control item_quantity item_field" name="quantity" value="<?php echo htmlspecialchars($item['cl_quantity']) ?>" <?php if($res1['cl_price_calculation'] == 'Automatic'){echo 'disabled';} ?> />
                <div class="error_input"></div>
              </td>
              <td>
                <input type="text" class="form-control item_amount item_field" name="amount" value="<?php echo htmlspecialchars($item['cl_amount']) ?>" <?php if($res1['cl_price_calculation'] == 'Automatic'){echo 'disabled';} ?> />
                 <div class="error_input"></div>
              </td>

              <td>
                <?php
                if($item['cl_digital'] == 1)
                {
                    echo 'Yes';
                }
                else
                {
                    echo 'No';
                }
                ?>
              </td>

              <td>
                <input type="text" class="form-control item_code" name="code" value="<?php echo htmlspecialchars($item['cl_code']) ?>"  />
                 <div class="error_input"></div>
              </td>
            
              <td>
               
                <button type="button" class="btn btn-xs btn-danger btn-delete-existing" cluster-id="<?php echo htmlspecialchars($item['cl_id']) ?>"><i class="fa fa-trash"></i></button>
                <div class="delete_error"></div>
              </td>
            </tr>
            <?php

            $total+= $item['cl_amount'];

            if($pvn < $item['cl_shipping_price'])
             {
                $pvn = $item['cl_shipping_price'];
             }
          }
        }

        $pvn = $pvn + ($pvn * $taxPercentage / 100);
                                      //  $pvn = 4.12;
        $grandtotal = $total + $pvn;
      ?>
    </tbody>
  </table>

   

  <table class="table table-bordered top-margin" style="width:100%;margin-top: 15px" id="new_order_items">

    <thead>
      <tr>
        <th colspan="4"> 
          New Items
          <button type="button" class="btn btn-danger pull-right" id="add_order_item">Add</button>
        </th>
      </tr>
      <tr>
        <th>
          Item
        </th>
        <th>
          Quantity
        </th>
        <th>
          Amount
        </th>
        
        <th>

        </th>
      </tr>
    </thead>
    <tbody>

    </tbody>
    <tfoot>
        <tr>
            <th colspan="3">
                Total
            </th>
            <th>
                <input type="number" class="form-control input_amount" name="price_total" value="<?php if($res1['cl_price_calculation'] == 'Automatic'){echo $total;}else{echo $res1['cl_price_total'];} ?>" <?php if($res1['cl_price_calculation'] == 'Automatic'){echo 'disabled';} ?> />
                <div class="error_input"></div>
            </th>
        </tr>
        <tr>    
            <th colspan="3">
                PVN
            </th>
            <th>
                <input type="number" class="form-control input_amount" name="pvn" value="<?php if($res1['cl_price_calculation'] == 'Automatic'){echo $pvn;}else{echo $res1['cl_pvn'];} ?>" <?php if($res1['cl_price_calculation'] == 'Automatic'){echo 'disabled';} ?> />
                <div class="error_input"></div>
            </th>
       
        </tr>
        <tr>
            <th colspan="3">
                Grand Total
            </th>
            <th>
                <input type="number" class="form-control input_amount" name="grand_total" value="<?php if($res1['cl_price_calculation'] == 'Automatic'){echo $grandtotal;}else{echo $res1['cl_grand_total'];} ?>" <?php if($res1['cl_price_calculation'] == 'Automatic'){echo 'disabled';} ?> />
                <div class="error_input"></div>
            </th>
        
         </tr>
        <tr>
            <th colspan="3">
                Amount after Promocode
            </th>
            <th>
                <input type="number" class="form-control input_amount" name="priceAfterPromoCode" value="<?php echo $res1['cl_priceAfterPromoCode'] ?>" <?php if($res1['cl_price_calculation'] == 'Automatic'){echo 'disabled';} ?> />
                <div class="error_input"></div>
            </th>
        </tr>
        <tr>
            <th colspan="3">
                VAT Percentage
            </th>
            <th>
                 <?php 

                 if($res1['cl_price_calculation'] == 'Automatic'){
                    $vatPercentage = $grandtotal * $taxPercentage/100;
                }
                else
                {
                    $vatPercentage = $res1['cl_vat_amount'];
                }

                     ?>
                
                <input type="number" class="form-control input_amount" name="vat_amount" value="<?php echo $vatPercentage ?>" <?php if($res1['cl_price_calculation'] == 'Automatic'){echo 'disabled';} ?> />
                <div class="error_input"></div>
            </th>
        </tr>
        <tr>
            <th colspan="3">
                Final Total
            </th>
            <th>
                   <?php    
                   if($res1['cl_price_calculation'] == 'Automatic'){
                        $finalTotal = $grandtotal + $vatPercentage;
                    }
                    else{
                        $finalTotal = $res1['cl_total'];
                    } ?>
                <input type="number" class="form-control input_amount" name="total" value="<?php echo $finalTotal ?>" <?php if($res1['cl_price_calculation'] == 'Automatic'){echo 'disabled';} ?> />
                <div class="error_input"></div>
            </th>
        </tr>
    </tfoot>

  </table>
</div>

                                             <div class="btn-container col-xs-12 col-sm-12 pull-left" style="margin-top:15px">
                         
                                <?php
                                        if($res1['cl_invoice'] == 0)
                                        {
                                    ?>
                                        <button type="button" cluster-url="../ajax/convert_to_invoice_without_email?id=<?php echo $id;?>" class="btn btn-success pull-right btn-link-new" cluster-redirect="view?id=<?php echo $id;?>" cluster-message="Converting order to Invoice">Convert to Invoice (Without email)</button>
                                       <button type="button" cluster-url="../ajax/convert_to_invoice?id=<?php echo $id;?>" class="btn btn-primary pull-right btn-link-new" cluster-redirect="view?id=<?php echo $id;?>" cluster-message="Converting order to Invoice" style="margin-right:5px">Convert to Invoice (With Email)</button>
                                       <div class="error-area col-sm-12 pull-left"></div>
                                       <?php
                                        }
                                        else 
                                        {
                                       ?>
                                       <button class="btn btn-primary pull-right btn-link-new" cluster-url="../ajax/send_invoice_again?id=<?php echo $id;?>" cluster-message="Sending Email"> Sent Inoice again to customer</button>
                                        <button class="btn btn-success pull-right "  disabled="disabled" style="margin-right : 5px"><i class="fa fa-check"></i>  Conveted to Invoice</button>

                                        <div class="error-area col-sm-12 pull-left"></div>
                                         <?php
                                        }
                                        ?>
                                    </div>
                                        
                                        
                                        </div>
                                        
                                       
                                    </div>

</div>

<?php
}
?>

                        <script src="../jquery_file_upload/js/vendor/jquery.ui.widget.js"></script>
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="../jquery_file_upload/js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="../jquery_file_upload/js/jquery.fileupload.js"></script>  
                    <script>
							$(document).ready(function(){
								$('.active').removeClass('active');
								$('#device-menu').addClass('active');

                                $('.input_amount').change(function(){
                                    var name = $(this).attr('name');
                                    var value = $(this).val();
                                    var parent = $(this).parents('tr').first();
                                    $(parent).find('.error_input').html('<div class="alert alert-warning">Changing Total</div>');
                                    $.post("../ajax/user_orders/update_total?id=<?php echo $id ?>", {name:name, value:value}, function(res){
                                        $(parent).find('.error_input').html('<div class="alert alert-success">' + res.message + '</div>');
                                    }, 'json').fail(function(xhr) {
                                        
                                          var html = '';
                                          var res = xhr.responseJSON;
                                          console.log(xhr);
                                          if (typeof res === 'undefined') {
                                            $(parent).find('.error_input').html('<div class="alert alert-danger">Something went wrong</div>').show();
                                          }
                                          if (typeof res.error_description === 'undefined') {
                                            if(typeof res.error_text === 'undefined')
                                            {
                                                $(parent).find('.error_input').html('<div class="alert alert-danger">Something went wrong</div>').show();
                                               
                                                return;
                                            }
                                            else
                                            {
                                                $(parent).find('.error_input').html('<div class="alert alert-danger">' + res.error_text + '</div>').show();
                                              
                                                return;
                                            }
                                          }
                                        
                                       
                                    });
                                });
							}); 

                            jQuery(document).on('change', '.item_field', function(){
                                 var name = $(this).attr('name');
                                  var value = $(this).val();
                                 var parent = $(this).parents('tr').first();
                                 var parentTD = $(this).parents('td').first();
                                    var id = $(parent).attr('cluster-id');
                                 $(parentTD).find('.error_input').html('<div class="alert alert-warning">Changing Total</div>');
                                    $.post("../ajax/user_orders/update_item_total?id=" + id, {name:name, value:value}, function(res){
                                        $(parentTD).find('.error_input').html('<div class="alert alert-success">' + res.message + '</div>');
                                    }, 'json').fail(function(xhr) {
                                        
                                          var html = '';
                                          var res = xhr.responseJSON;
                                          console.log(xhr);
                                          if (typeof res === 'undefined') {
                                            $(parentTD).find('.error_input').html('<div class="alert alert-danger">Something went wrong</div>').show();
                                          }
                                          if (typeof res.error_description === 'undefined') {
                                            if(typeof res.error_text === 'undefined')
                                            {
                                                $(parentTD).find('.error_input').html('<div class="alert alert-danger">Something went wrong</div>').show();
                                               
                                                return;
                                            }
                                            else
                                            {
                                                $(parentTD).find('.error_input').html('<div class="alert alert-danger">' + res.error_text + '</div>').show();
                                              
                                                return;
                                            }
                                          }
                                        
                                       
                                    });
                            });



                            jQuery(document).on('change', '.item_code', function(){
                                var code = jQuery(this).val();
                                 var parent = $(this).parents('tr').first();
                                 var parentTD = $(this).parents('td').first();
                                    var id = $(parent).attr('cluster-id');
                                     $(parentTD).find('.error_input').html('<div class="alert alert-warning">Updating Code</div>');
                                $.post("../ajax/user_orders/update_code?id=" + id, {code:code}, function(res){
                                        $(parentTD).find('.error_input').html('<div class="alert alert-success">' + res.message + '</div>');
                                    }, 'json').fail(function(xhr) {
                                        
                                          var html = '';
                                          var res = xhr.responseJSON;
                                          console.log(xhr);
                                          if (typeof res === 'undefined') {
                                            $(parentTD).find('.error_input').html('<div class="alert alert-danger">Something went wrong</div>').show();
                                          }
                                          if (typeof res.error_description === 'undefined') {
                                            if(typeof res.error_text === 'undefined')
                                            {
                                                $(parentTD).find('.error_input').html('<div class="alert alert-danger">Something went wrong</div>').show();
                                               
                                                return;
                                            }
                                            else
                                            {
                                                $(parentTD).find('.error_input').html('<div class="alert alert-danger">' + res.error_text + '</div>').show();
                                              
                                                return;
                                            }
                                          }
                                        
                                       
                                    });
                            });
						</script>      
                        <script>
                        $(function () {
                                'use strict';
   
                            var url = '../ajax/upload_invoice';
                            $('.fileupload').fileupload({
                                url: url,
                                dataType: 'json',
                                submit: function(e,data){
                                  var parent = $(this).parents('.input-container').first();
                                  $(parent).find('.files_area').html('');
                                  $(parent).find('.error_area').html('<div class="alert alert-warning">Upload in progress</div>');
                                  $(parent).find('.progress .progress-bar').removeAttr('style');


                                },
                                done: function (e, data) {
                                    /*$.each(data.result.files, function (index, file) {
                                        console.log(file);
                                    });*/
                                   
                                    var parent = $(this).parents('.input-container').first();
                                    $(parent).find('.files_area').html('<a target="_blank" class="" href="../uploads/invoice/' + data.result.file + '">Download</a>');
                                    $(parent).find('.file_name').text(data.result.actualName);
                                    $(parent).find('.error_area').html('');
                                    $(parent).find('.image').val(data.result.file);
                                    $(parent).find('.name').val(data.result.actualName);
                                },
                                fail: function (e, data) {
                                  var parent = $(this).parents('.input-container').first();
                                  $(parent).find('.error_area').html('<div class="alert alert-danger">' + data.jqXHR.responseJSON.error_text + '</div>');
                                  $(parent).find('.progress .progress-bar').css(
                                        'background-color',
                                        'salmon'
                                    );
                                },
                                progressall: function (e, data) {
                                  var parent = $(this).parents('.input-container').first();
                                    var progress = parseInt(data.loaded / data.total * 100, 10);
                                     $(parent).find('.progress .progress-bar').css(
                                        'width',
                                        progress + '%'
                                    );
                                }
                            }).prop('disabled', !$.support.fileInput)
                                .parent().addClass($.support.fileInput ? undefined : 'disabled');


                          
                            $('.fileuploadWarrantyCard').fileupload({
                                url: '../ajax/upload_warranty_card',
                                dataType: 'json',
                                submit: function(e,data){
                                  var parent = $(this).parents('.input-container').first();
                                  $(parent).find('.files_area').html('');
                                  $(parent).find('.error_area').html('<div class="alert alert-warning">Upload in progress</div>');
                                  $(parent).find('.progress .progress-bar').removeAttr('style');


                                },
                                done: function (e, data) {
                                    /*$.each(data.result.files, function (index, file) {
                                        console.log(file);
                                    });*/
                                   
                                    var parent = $(this).parents('.input-container').first();
                                    $(parent).find('.files_area').html('<a target="_blank" class="" href="../uploads/warranty_card/' + data.result.file + '">Download</a>');
                                    $(parent).find('.file_name').text(data.result.actualName);
                                    $(parent).find('.error_area').html('');
                                    $(parent).find('.image').val(data.result.file);
                                    $(parent).find('.name').val(data.result.actualName);
                                },
                                fail: function (e, data) {
                                  var parent = $(this).parents('.input-container').first();
                                  $(parent).find('.error_area').html('<div class="alert alert-danger">' + data.jqXHR.responseJSON.error_text + '</div>');
                                  $(parent).find('.progress .progress-bar').css(
                                        'background-color',
                                        'salmon'
                                    );
                                },
                                progressall: function (e, data) {
                                  var parent = $(this).parents('.input-container').first();
                                    var progress = parseInt(data.loaded / data.total * 100, 10);
                                     $(parent).find('.progress .progress-bar').css(
                                        'width',
                                        progress + '%'
                                    );
                                }
                            }).prop('disabled', !$.support.fileInput)
                                .parent().addClass($.support.fileInput ? undefined : 'disabled');
                        });


  $(document).on('click', '#add_order_item', function(){
    var html = '<tr><td><input type="text" class="form-control product_name" /><input type="hidden" class="form-control product_id" /></td> <td><input type="number" class="form-control quantity" /></td><td class="amount"></td><td><button type="button" class="btn btn-xs btn-primary btn-add"><i class="fa fa-plus"></i></button><button type="button" class="btn btn-xs btn-danger delete-client"><i class="fa fa-trash"></i></button></td></tr>';
    $('#new_order_items tbody').append(html);
  });




  var options = {source: function(request,response) {
        $.ajax ({
            url: "../ajax/products/get_products",
            data: {name: request.term},
            dataType: "json",
            type:'POST',
            success: function( data ) {
            response( $.map( data, function( item ) {
                return {
                    label: item.cl_name,
                    value: item.cl_name,
                    data:item
                }
            }));
        } 
        })
    },
    minLength: 1,
    select: function( event, ui ) {
        
        var parent = $(this).parents('tr').first();
        $(parent).find('.product_id').val(ui.item.data.cl_id);
        $(parent).find('.quantity').val(1);
        

        var supplierPrice = ui.item.data.cl_supplier_price;
         if(supplierPrice < 20)
        {
            profitPercentage = <?php echo $profitPercentage0_20 ?>;
        }
        else if(supplierPrice >= 20 && supplierPrice <= 50)
        {
            profitPercentage = <?php echo $profitPercentage20_50 ?>;
        }
        else if(supplierPrice >= 50 && supplierPrice <= 100)
        {
            profitPercentage = <?php echo $profitPercentage50_100 ?>;
        }
        else if(supplierPrice >= 100 && supplierPrice <= 200)
        {
            profitPercentage = <?php echo $profitPercentage100_200 ?>;
        }
        else if(supplierPrice >= 200 && supplierPrice <= 800)
        {
          profitPercentage = <?php echo $profitPercentage200_800 ?>;
        }
        else
        {
          profitPercentage = <?php echo $profitPercentageMoreThan800 ?>;
        }


        var amount = Number(supplierPrice) + Number(supplierPrice * profitPercentage / 100);
        $(parent).find('.amount').text(amount);
        $(parent).find('.quantity').attr('cluster-price', amount);

    }
  };


  $(document).on('keydown.autocomplete','.product_name',function(){
      $(this).autocomplete(options);
  });


  $(document).on('change', '.quantity', function(){
    var parent = $(this).parents('tr').first();
    if($.isNumeric($(this).val()))
    {
      var price = $(this).attr('cluster-price');
      var finalPrice = price * $(this).val();
      $(parent).find('.amount').text(finalPrice);
    }
    else
    {
      $(parent).find('.amount').text(0);
    }
  });


  $(document).on('click', '.delete-client', function(){
    var conf = confirm("Are you sure you want to delete this?");
    if(!conf)
    {
      return;
    }
    var parent = $(this).parents('tr').first();
    $(parent).remove();
  });

  $(document).on('click', '.btn-add', function(){
    var parent = $(this).parents('tr').first();
    $(parent).find('button').attr('disabled', 'disabled');
    var data = new Object();
     data['product_id'] = $(parent).find('.product_id').val();
     data['quantity'] = $(parent).find('.quantity').val();
    $.post('../ajax/user_orders/add_item?id=<?php echo $id ?>', {data:data}, function(){
        location.reload();
    },'json').fail(function(xhr) {
               $(parent).find('button').removeAttr('disabled');
            });
  });
      
                        </script>   


<script>
    jQuery(document).ready(function(){
        jQuery('#order_email_again').click(function(){
            jQuery('#order_email_again').attr('disabled', 'disabled');
            jQuery('.order_email_error').html('<div class="alert alert-warning">Sending Email</div>');
            jQuery.post('../ajax/user_orders/send_order_email?id=<?php echo $id ?>', function(){
                jQuery('#order_email_again').removeAttr('disabled');
                jQuery('.order_email_error').html('<div class="alert alert-success">Email Sent Successfully</div>');
            },'json')
            .fail(function(xhr) {
                jQuery('#order_email_again').removeAttr('disabled');
                jQuery('.order_email_error').html('<div class="alert alert-danger">Something Went Wrong</div>');
            });
        });

        jQuery('#invoice_create').click(function(){
            jQuery('#invoice_create').attr('disabled', 'disabled');
            jQuery('.order_email_error').html('<div class="alert alert-warning">Creating Invoice</div>');
            jQuery.post('../ajax/user_orders/send_order_email?id=<?php echo $id ?>&email=no', function(){
                jQuery('#invoice_create').removeAttr('disabled');
                jQuery('.order_email_error').html('<div class="alert alert-success">Invoice created Successfully</div>');
            },'json')
            .fail(function(xhr) {
                jQuery('#order_email_again').removeAttr('disabled');
                jQuery('.order_email_error').html('<div class="alert alert-danger">Something Went Wrong</div>');
            });
        });
    });


    jQuery(document).on('click', '.btn-delete-existing', function(){
        var parent = $(this).parents('tr').first();
        $(parent).find('button').attr('disabled', 'disabled');
        var id = $(this).attr('cluster-id');
        $.get('../ajax/user_orders/delete_item', {id:id}, function(){
            location.reload();
        },'json').fail(function(xhr) {
            $(parent).find('button').removeAttr('disabled');
            var res = xhr.responseJSON;
             if (typeof res === 'undefined') {
                $(parent).find('.delete_error').html('<div class="alert alert-danger">Something went wrong</div>').show();
              }
              if (typeof res.error_description === 'undefined') {
                if(typeof res.error_text === 'undefined')
                {
                    $(parent).find('.delete_error').html('<div class="alert alert-danger">Something went wrong</div>').show();
                    window.location.href = '#body_part';
                    return;
                }
                else
                {
                    $(parent).find('.delete_error').html('<div class="alert alert-danger">' + res.error_text + '</div>').show();
                    window.location.href = '#body_part';
                    return;
                }
              }
            
        });
    });

    jQuery(document).on('change', '#status', function(){
        if(jQuery(this).val() == 'Delivered')
        {
             var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];;
            var d = new Date();
            var dateValue = d.getDate() + ' ' + months[d.getMonth()] + ' ' + d.getFullYear();
            if(jQuery('#delivery_date').val() == '')
            {
                jQuery('#delivery_date').val(dateValue);
            }
        }
    });

    jQuery(document).ready(function(){
        jQuery('#label_create').click(function(){
            jQuery(this).attr('disabled', 'disabled');
            var current = jQuery(this);
            jQuery('.order_email_error').html('<div class="alert alert-warning">Creating Shipment.....</div>');
            $.get('../ajax/user_orders/create_shipment', {id:<?php echo $id ?>}, function(res){
                jQuery(current).removeAttr('disabled');
                 jQuery('.order_email_error').html('<div class="alert alert-success">' + res.message + '</div>');
                 jQuery('#tracking_number').val(res.tracking_number);
                location.reload();
            },'json').fail(function(xhr) {
                 jQuery(current).removeAttr('disabled');
                $(parent).find('button').removeAttr('disabled');
                var res = xhr.responseJSON;
                 if (typeof res === 'undefined') {
                    $('.order_email_error').html('<div class="alert alert-danger">Something went wrong</div>').show();
                  }
                  if (typeof res.error_description === 'undefined') {
                    if(typeof res.error_text === 'undefined')
                    {
                        $('.order_email_error').html('<div class="alert alert-danger">Something went wrong</div>').show();
                        window.location.href = '#body_part';
                        return;
                    }
                    else
                    {
                        $('.order_email_error').html('<div class="alert alert-danger">' + res.error_text + '</div>').show();
                        window.location.href = '#body_part';
                        return;
                    }
                  }
                
            });
        });
    });
</script>

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