<?php

/* * *********************************************************** */
/*
  This Class is made to be generic and to be used in the system.
  All HTML elements must bedefined here
  
  */
/* * *********************************************************** */

class Forms extends CommonFunctions
{

    // end text function!    
    //btn function, that return a button
    //arguments:
    //1st:id of the button
    //2nd:arguments, for the type of the btn(for ex: cancel,custom(you give the class you want))
    //3rd:class of the button
    //4th:value the button will show
    public static function btn($id = null, $args = null, $class = null, $val = null)
    {
        switch ($args) {
            case '':
                return '<hr><div class="row"><button id="' . $id . '" class="btn btn-primary btn-cons pull-right"><i class="fa fa-check"> Submit</i></button></div>';
                break;
            case 'cancel':
                return '<button id="' . $id . '" class="btn btn-default btn-cons"><i class="fa fa-close"> Cancel</i></button>';
                break;
            case 'custom':
                return '<button id="' . $id . '" type="submit" class="btn btn-' . $class . ' btn-cons">' . $val . '</button>';
                break;
            case 'group':
                return '<div class="btn-group">
                        <button id="' . $id . '" type="button" class="btn btn-default">
                            <span class="p-t-5 p-b-5"><i class="fa fa-star fs-15"></i></span>
                        <br>
                        <span class="fs-11 font-montserrat text-uppercase">Favourites</span>
                        </button>
                    </div>';
                break;
        }
    }

    public static function select2($options, $id = null)
    {
        $return = '';
        $attrarr = '';
        if (is_callable($options)) {
            $options = $options();
        }
        foreach ($options as $x) {
            $return .= '<option id="' . $id . '" value="' . $x . '">' . $x . '</option>';
        }
        return ' <select ' . $attrarr . ' class="full-width" data-init-plugin="select2" placeholder: "Select an option">
                        <option value="" selected="selected"></option>
                        ' . $return . '
                    </select>';
    }

    public static function AlertDiv($Alertid)
    {
        return '<div class="col-md-12"><div class="alert hidden" id="' . $Alertid . '"></div></div>';
    }

    //function that return currency dropdown
    //if $id is not null it will return only default currencies
    //if $id is null it will return all currencies
    public static function CurrencyDropDown($id = null, $color, $is_default = null)
    {

        $DefaultCurID = CurrencyFactory::getDefaultCurrencyById(1);
        $CurList = CurrencyFactory::GetLIListCurrency($id);
        return ' <div Default-Currency="' . (!is_null($is_default) ? '' : $DefaultCurID) . '" class="input-group-btn DropDownForForms Closable ' . (is_null($id) ? 'open' : '') . ' " id="CurrencyDropDown">
                                    <button type="button" class="btn btn-' . $color . ' btn-block dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                        <span><strong>Select Currency</strong></span>
                                        <input type="hidden" name="Currency_ID" value="' . (!is_null($is_default) ? '' : $DefaultCurID) . '" class="form-control ignore" onkeyup="return false" onkeydown="return false"/>
                                    </button>
                                    <ul class="dropdown-menu">
                                        ' . $CurList . '
                                        <li class="divider"></li>
                                        <li><a class="LoadMore">More..</a></li>
                                    </ul>
                                </div>';
    }

    public static function FloatingAddButton($color, $target, $title, $class = null)
    {
        //$color          = parent::thisColor();
        return '<style>
                    .actionButton {
                        background-color: #' . $color . '!important;
                    }
                </style>
                <div class="floatingContainer ' . (!is_null($class) ? $class : '') . ' pull-right">
                    <a herf="#" data-toggle="modal" data-target="' . $target . '"><div class="actionButton" >
                        <p class="floatingText"><span class="floatingTextBG">' . $title . '</span></p>
                    </div></a>
                </div>';
    }

    public static function UploadImage($options)
    {

        return ' <div class="col-md-4 b-r b-dashed b-grey">
                            <div class="col-md-4 profile-col">
                                <div class="profile-pic">
                                    <div class="profile-border">
                                        <img ' . (isset($options['ImageID']) ? 'id="' . $options['ImageID'] . '"' : '') .
            '" class="NewUploadPhoto" ' . (isset($options['src']) ? 'src="' . $options['src'] . '"' : '') . ' alt="">
                                    </div>
                                </div>
                                <button class="btn btn-default" ' . (isset($options['ButtonID']) ? 'id="' . $options['ButtonID'] . '"' : '') . '>Upload<input type="file" data-target="#' . (isset($options['ImageID']) ? $options['ImageID'] : '') . '" ' . (isset($options['OnChange']) ? 'onchange="' . $options['OnChange'] . '"' : '') . ' name="image_file" value="Upload"></button>
                            </div>
                        </div>';
    }

    public static function formGroup1($options)
    {

        return '<div ' . (isset($options['id']) ? 'id="' . $options['id'] . 'Container"' : '')
            . ' class="' . (isset($options['width']) ? 'col-md-' . $options['width'] : '') . '"'
            . (isset($options['hidden']) ? $options['hidden'] : '') . '>
                        <div class="form-group form-material floating">'
            . (isset($options['example']) ? '<span class="help">' . $options['example'] . '</span>' : '') .
            '<input ' . (isset($options['type']) ? 'type="' . $options['type'] . '"' : '') . ' 
                            class="form-control ' . (isset($options['classes']) ? $options['classes'] : '') . '" ' . (isset($options['id']) ? 'id="' . $options['id'] . '"' : '') . ' '
            . (isset($options['name']) ? 'name="' . $options['name'] . '"' : '')
            . (isset($options['value']) ? 'value="' . $options['value'] . '"' : '') . '
                            ' . (isset($options['required']) ? 'required' : '') . '  ' . (($options['type'] == 'date') ? 'data-plugin="datepicker"' : '') . ' />
                            ' . (isset($options['label']) ? '<label class="floating-label" for="' . (isset($options['id']) ? 'id="' . $options['id'] . '"' : '') . '">' . $options['label'] . '</label>' : '') . '
                        </div>
                    </div>';
    }

    // end of form group form1!

    public static function select1($options)
    {
        $return = '';
        $attrarr = '';
        //check if the value recieved is function or not
        //        if(isset($options['valueID'])&&isset($options['valueName']))
        //            $return.='<option  value="'.$options['valueID'].'">'.$options['valueName'].'</option>';
        if (isset($options['SelectOptions'])) {
            if ($options['SelectOptions'] == null) {
                unset($options['SelectOptions']);
            } else {
                if (is_callable($options['SelectOptions'])) {
                    $options['SelectOptions'] = $options();
                }
                if (isset($options['firstOption']))
                    $return .= '<option value="0"> ' . $options['firstOption'] . ' </option>';
                foreach ($options['SelectOptions'] as $x) {
                    $return .= '<option  value="' . $x[$options['optionName'] . '_ID'] . '" ' . (isset($options['valueID']) ? ($x[$options['optionName'] . '_ID'] == $options['valueID'] ? 'selected' : '') : '') . '>' . $x[$options['optionName'] . '_' . $options['optionValue']] . '</option>';
                }
            }
        }


        if (isset($options['Attributes'])) {
            if (is_array($options['Attributes'])) {

                foreach ($options['Attributes'] as $h) {
                    $attrarr .= $h;
                }
            } else {
                $attrarr = $options['Attributes'];
            }
        }

        return '
        <div class="col-md-' . (isset($options['width']) ? $options['width'] : '') . ' ' . (isset($options['classes']) ? $options['classes'] : '') . '" id="col_' . (isset($options['SelectID']) ? $options['SelectID'] : '') . '">
            <div class="form-group form-material">
                <div><label class="control-label" ' . (isset($options['SelectID']) ? 'for="' . $options['SelectID'] . '"' : '') . '>' . (isset($options['label']) ? $options['label'] : '') . '</label></div>
                    <select ' . $attrarr . ' ' . (isset($options['SelectID']) ? 'id="' . $options['SelectID'] . '"' : '') . '' . (isset($options['SelectID']) ? 'name="' . $options['SelectID'] . '"' : '') . ' class=" form-control full-width ' . (isset($options['Class']) ? $options['Class'] : '') . '" >

                        ' . $return . '
                    </select>
            </div>
        </div>';
    }

    public static function viewImage($options)
    {

        return ' <div class="col-md-4 profile-col  ">
                    <div class="view-profile-pic" style=" margin: 40px;">
                        <div class="profile-border" >
                            <img id="ImagePreview" src="' . $options['filename'] . '" data-src="' . $options['filename'] . '" alt="" >
                        </div>
                    </div>
                </div>';
    }

    public static function viewInfoDetails($options)
    {
        //        echo"<pre>";
        //        print_r($options);

        $body = '';
        $count = 0;
        $keys = array();
        $vals = array();
        $classes = array();
        $j = 1;
        foreach ($options as $index => $val) {

            if (is_array($val)) {
                $i = 1;
                $body .= $val['title'];
                foreach ($val as $key => $val2) {
                    if ($key != 'ID' and $key != 'title') {
                        $key = str_replace('_', ' ', $key);
                        if ($i % 2 == 1)
                            $body .= '<div class="row">
                                        <div class="form-group">';

                        $body .= '<label class="col-sm-3 control-label">' . $key . '</label>
                                            <div class="col-sm-3 ' . $index . ' ">' . $val2 . ' </div>';
                        if ((($i % 2 != 1 || $i == count($val) - 1) && $j != 1) || (($i % 2 != 1 || $i == count($val) - 2) && $j == 1))
                            $body .= '</div></div>';
                        $i++;
                    }
                }
            }
            $j++;
        }
        return $body;
    }

    public static function viewProfiles($options)
    {
        //       require_once(dirname(__FILE__).'../../Includes/language.php');
        //        die();
        //        msg('en','Price');
        //        CommonLanguage::message('en','Price');
        //        $CommonLanguage = new CommonLanguage;
        $result = '';
        $i = 1;
        foreach ($options[0] as $index => $val) {
            if ($i % 2 != 0) {
                //                echo"---odd---";
                $result .= '<div class="row"><div class="form-group">';
            }
            $result .= '<label class="col-sm-2 control-label">' . CommonLanguage::getMessage($index) . '</label><div class="col-sm-4 ">' . $val . '</div>';
            if ($i % 2 == 0) {
                //                echo"---even---";
                $result .= '</div></div>';
            }
            $i++;
            //            echo $result;
        }
        return $result;
    }

    public static function FloatingButtonWithOptions($listArray)
    {
        $value = '<style>.actionButton { background-color: #4c0870!important }</style>
		<div class="floatingContainer horizontal"><div class="actionButton"></div><div class="subactionContent">';
        foreach ($listArray as $list) :
            $value .= '<div class="subActionButton" style=background-color:' . $list['color'] . '>
						<a ' . (array_key_exists('id', $list) ? 'id=' . $list['id'] : '') . '  ' . (array_key_exists('data-id', $list) ? 'data-id=' . $list['data-id'] : '') . '  ' . (array_key_exists('target', $list) ? 'data-toggle="modal" data-target="' . $list['target'] . '"' : '') . '>
						  <i class="' . $list['icon'] . '"></i>
							<p class="floatingText"><span class="floatingTextBG">' . $list['text'] . '</span></p>
						 </a>
						 </div>';
        endforeach;
        $value .= '</div></div>';
        return $value;
    }

    //join details of two common entries
    public static function JoinSimilarItemsInArray(&$what, $needle)
    {
        $cnt = count($what);
        for ($x = 0; $x < $cnt; $x++) {
            $CurItem1 = $what[$x];
            for ($y = $x; $y < $cnt; $y++) {
                $CurItem2 = $what[$y];
                if (isset($CurItem2[$needle]) && isset($CurItem1[$needle]) && $x != $y && $CurItem1[$needle] == $CurItem2[$needle]) {
                    $arrayKeys = array_keys($CurItem1);
                    $arrayValues = array_values($CurItem1);
                    for ($z = 0; $z < count($arrayValues); $z++) {
                        if ($CurItem1[$arrayKeys[$z]] != $CurItem2[$arrayKeys[$z]]) {
                            $what[$x][$arrayKeys[$z]] .= ', ' . $CurItem2[$arrayKeys[$z]];
                        }
                    }
                    $what[$y] = [];
                }
            }
        }

        function RemoveEmpty($v)
        {
            return count($v) > 0;
        }

        $what = array_values(array_filter($what, "RemoveEmpty"));
    }

    public static function addRowButton()
    {
        return '<span class="fa fa-plus-circle" style="color: #4c0870;margin-left: 10px;cursor: pointer;font-size: 16px;"></span>';
    }

    //$options['TableHeaders']: array that contain headers of datatable
    //$options['ArrayContent'] : array of values of the body
    //$options['ArrayContent'][$i][0] must be the id
    //$options['Actions'] is an array:
    //$options['Action']['isDropDown'] can be true(Dropdown) or false(button)
    //$options['Action']['ActionOption] array of options of li or btn (href,class,title,icon,data-target)
    public static function CreateDatatable($options)
    {
        //        echo"<pre>";
        //        print_r($options);
        //        if(array_key_exists("Status",$options))
        //            die("okokkk");  
        $TableHeader = '';
        $TableBody = '';
        //Draw header of datatable
        for ($i = 0; $i < count($options['TableHeaders']); $i++) {
            $TableHeader .= '<th style="background-color:#' . $options['Color_Value'] . ';color:#fff;border:1px solid #e5e5e5;" class="text-center">' . $options['TableHeaders'][$i] . '</th>';
        }
        if (isset($options['Action'])) {
            $TableHeader .= '<th style="background-color:#' . $options['Color_Value'] . ';color:#fff;border:1px solid #e5e5e5;" class="text-center">' . CommonLanguage::getMessage('Action') . '</th>';
        }
        for ($j = 0; $j < count($options['ArrayContent']); $j++) {
            $TableBody .= '<tr data-id="' . $options['ArrayContent'][$j][0] . '" ' . (array_key_exists("Status", $options) ? 'data-status="' . $options["ArrayContent"][$j]["Status_ID"] . '"' : '') . '>';
            //            $newCount = (array_key_exists("Status",$options)? (count($options['ArrayContent'][$j])) : (count($options['ArrayContent'][$j])));
            for ($k = 1; $k < count($options['ArrayContent'][$j]); $k++) {
                if (array_key_exists('breakDown', $options)) {
                    $k == $options['breakDown'] ? $TableBody .= '<td class="v-align-middle breakDownTd " style="border:1px solid #e5e5e5;"><div class="Arrow"><b>' . $options['ArrayContent'][$j][$k] . '</b></div></td>' : $TableBody .= '<td>' . $options['ArrayContent'][$j][$k] . '</td>';
                } else
                if (array_key_exists('status_td', $options)) {
                    //                        echo"helloo";
                    $k == $options['status_td'] ? $TableBody .= '<td class="v-align-middle text-center Status" style="border:1px solid #e5e5e5;"><span class="label"></span></td>' : $TableBody .= '<td class="text-center" style="border:1px solid #e5e5e5;">' . $options['ArrayContent'][$j][$k] . '</td>';
                } else {

                    $TableBody .= '<td class="text-center" style="border:1px solid #e5e5e5;">' . $options['ArrayContent'][$j][$k] . '</td>';
                }
            }
            if (isset($options['Action'])) { //if we want the last th to be a dropdown or btn
                if ($options['Action']['isDropDown']) {
                    $TableBody .= '<td class="text-center" style="border:1px solid #e5e5e5;"><div class="btn-group m-b-sm Action">
                        <button type="button" class="btn bg-success-darker dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                            ' . CommonLanguage::getMessage('Action') . '<span class="caret"></span>
                        </button>                            
                        <ul class="dropdown-menu" role="menu">';
                    for ($h = 0; $h < count($options['Action']['ActionOption']); $h++) {
                        $TableBody .= '<li> <a title="' . $options['Action']['ActionOption'][$h]['title'] . '" class="' . $options['Action']['ActionOption'][$h]['class'] . '" 
                                                ' . (isset($options['Action']['ActionOption'][$h]['href']) ? 'href="' . SITE_LINK . '' . $options['Action']['ActionOption'][$h]['href'] . '' . $options['ArrayContent'][$j][0] . '"' : '') . ' 
                                                data-toggle="modal" data-target="' . (isset($options['Action']['ActionOption'][$h]['data-target']) ? $options['Action']['ActionOption'][$h]['data-target'] : '') . '"> 
                                            <i class="fa ' . $options['Action']['ActionOption'][$h]['icon'] . '" type="button" class="btn btn-default"> ' . $options['Action']['ActionOption'][$h]['title'] . ' </i> 
                                            </a></li>';
                    }
                    $TableBody .= '</ul></div></td>';
                } else {
                    $TableBody .= '<td class="text-center" style="border:1px solid #e5e5e5;"><a ' . (isset($options['Action']['ActionOption'][0]['href']) ? 'href="' . SITE_LINK . '' . $options['Action']['ActionOption'][0]['href'] . '' . $options['ArrayContent'][$j][0] . '"' : '') . '><button  class="btn ' . $options['Action']['ActionOption'][0]['class'] . '" 
                                                data-toggle="modal" data-target="' . (isset($options['Action']['ActionOption'][0]['data-target']) ? $options['Action']['ActionOption'][0]['data-target'] : '') . '">
                                                ' . (isset($options['Action']['ActionOption'][0]['icon']) ? '<i class="fa ' . $options['Action']['ActionOption'][0]['icon'] . '"></i>' : '') . ' ' . $options['Action']['ActionOption'][0]['title'] . ' </button></a></td>';
                }
            }
            $TableBody .= '</tr>';
        }





        return '<div >
                    <table class="table table-striped" style="    border-collapse: collapse;width:100%" id="tableWithSearch" >
                        <thead>
                            <tr>
                              ' . $TableHeader . '  
                            </tr>
                        </thead>
                        <tbody id="body_element">
                           ' . $TableBody . '

                        </tbody>
                    </table>
                    </div>';
    }

    public static function ModalLoader($modalID)
    {
        return '<div id="' . $modalID . '" style="position:absolute;left:0;right:0;top:0px;height:100%;background:rgba(255,255,255,0.9);z-index:999" class="hidden"><img class="image-responsive-height demo-mw-50" src="img/demo/progress.svg" alt="Progress" style="position: absolute;left: 50%;top: 50%;margin: -25px 0 0 -25px;" /></div>';
    }

    public static function gettrialBalance($trialList, $act = null, $is_job = 0)
    {
        //        die('okk');
        //            echo"<pre>";
        //        die(print_r($trialList));
        //        die(self::DecimalNumber(-1256478.2563));
        $resultToreturn = ' 
            <style>
            .parent-class td{font-size: 1.2em !important;background-color:#e5e5e5 !important;font-weight:bold !important;}
            </style>
            <table class="table table-print-tr-class" id="TrialBalanceTable">
                <thead>
                    <tr>';
        if ($is_job != 3)
            $resultToreturn .= '<th class="v-align-middle text-left " style="width:2% !important;">A/C No.</th>';
        $resultToreturn .= '<th class="v-align-middle text-left bold" style="width:20% !important;">' . CommonLanguage::getMessage('Name') . '</th>';
        $resultToreturn .= empty($is_job) ? '<th class="v-align-middle text-left bold" style="width:20% !important;">' . CommonLanguage::getMessage('Currency') . '</th>' : '';
        $resultToreturn .= '<th class="v-align-middle text-center" style="width:10% !important;">' . CommonLanguage::getMessage('opening') . '</th>

                        <th class="v-align-middle text-center" style="width:10% !important;">' . CommonLanguage::getMessage('previous') . '</th>
                        <th class="v-align-middle text-center" style="width:10% !important;">' . CommonLanguage::getMessage('debit') . '</th>
                        <th class="v-align-middle text-center" style="width:10% !important;">' . CommonLanguage::getMessage('credit') . '</th>
                        <th class="v-align-middle text-center" style="width:10% !important;">' . CommonLanguage::getMessage('current') . '</th>';
        if (smc_session()['default_setting']['activate_second_currency'] == 1) {
            $resultToreturn .= '<th class="v-align-middle text-center " style="width:10% !important;">' . CommonLanguage::getMessage('debit') . smc_session()['local_currency_symbol'] . '</th>
                <th class="v-align-middle text-center " style="width:10% !important;">' . CommonLanguage::getMessage('credit') . smc_session()['local_currency_symbol'] . '</th>
                <th class="v-align-middle text-center " style="width:10% !important;">' . CommonLanguage::getMessage('current') . smc_session()['local_currency_symbol'] . '</th>
                        <th class="v-align-middle text-center " style="width:10% !important;">' . CommonLanguage::getMessage('debit') . smc_session()['second_currency']['symbol'] . '</th>
                        <th class="v-align-middle text-center " style="width:10% !important;">' . CommonLanguage::getMessage('credit') . smc_session()['second_currency']['symbol'] . '</th>
                        <th class="v-align-middle text-center " style="width:10% !important;">' . CommonLanguage::getMessage('current') . smc_session()['second_currency']['symbol'] . '</th>';
        }
        $resultToreturn .= '<th class="v-align-middle text-center" style="width:10% !important;">' . CommonLanguage::getMessage('closing') . '</th>
                        <th class="v-align-middle text-center" style="width:10% !important;">' . CommonLanguage::getMessage('Balance') . '</th>
                    </tr>
                </thead>
                <tbody>';
        $open_balance = $prev_balance = $Debits = $Credits = $Balance = $local_debits = $local_credits = $second_debits = $second_credits = $second_balance = $overall_balance = $local_balance = $close_balance = 0;
        foreach ($trialList as $data) {
            $link = $is_job == 0 ? (is_null($act) ? 'ledger/' : 'ledger/act/') . $data["Code"] : ($is_job == 1 ? (is_null($act) ? 'statament_of_job/' : 'statament_of_job/act/') . $data["job_id"] : ($is_job == 2 ? ((is_null($act) ? 'statament_of_project/' : 'statament_of_project/act/') . $data["project_id"]) : ($is_job == 4 ? ((is_null($act) ? 'statement_activity/' : 'statement_activity/act/') . $data["activity_id"]) : (is_null($act) ? 'statement_pos_customer/' : 'statement_pos_customer/act/') . $data["pos_customer_id"])));
            $resultToreturn .= '<tr class="' . ($data['is_parent'] ? 'parent-class' : '') . '">';
            if ($is_job != 3)
                $resultToreturn .= '<td><a style="color:black;" href="' . SITE_LINK . 'ACC/' . $link . '"><span >' . $data["Code"] . '</span></a></td>';
            $resultToreturn .= '<td class="text-left " ><span class="Name">' . $data["Name"] . '</span></td>';
            $resultToreturn .= empty($is_job) ? '<td class="text-left " ><span class="Name">' . $data["currency"] . '</span></td>' : '';
            $resultToreturn .= '<td class="text-center" > <span >' . (Forms::DecimalNumber($data["open_balance"])) . '</span></td>
                        <td class="text-center" > <span >' . (Forms::DecimalNumber($data["prev_balance"])) . '</span></td>
                        <td class="text-center" > <span >' . (Forms::DecimalNumber($data["Debits"])) . '</span></td>
                        <td class="text-center" > <span >' . (Forms::DecimalNumber($data["Credits"])) . '</span></td>
                        <td class="text-center" > <span >' . (Forms::DecimalNumber($data["Balance"])) . '</span></td>';
            if (smc_session()['default_setting']['activate_second_currency'] == 1) {

                $resultToreturn .= '<td class="text-center " > <span >' . (Forms::DecimalNumber($data["local_debits"])) . '</span></td>
                            <td class="text-center " > <span >' . (Forms::DecimalNumber($data["local_credits"])) . '</span></td>
                            <td class="text-center " > <span >' . (Forms::DecimalNumber($data["local_balance"])) . '</span></td>
                        <td class="text-center " > <span >' . (Forms::DecimalNumber($data["second_debits"])) . '</span></td>
                        <td class="text-center " > <span >' . (Forms::DecimalNumber($data["second_credits"])) . '</span></td>
                        <td class="text-center " > <span >' . (Forms::DecimalNumber($data["second_balance"])) . '</span></td>';
            }
            $resultToreturn .= '<td class="text-center" > <span >' . (Forms::DecimalNumber($data["close_balance"])) . '</span></td>
                        <td class="text-center" > <span >' . (Forms::DecimalNumber($data["overall_balance"])) . '</span></td>
                    </tr>';

            if (!$data['is_parent']) {
                $open_balance += $data["open_balance"];
                $prev_balance += $data["prev_balance"];
                $Debits += $data["Debits"];
                $Credits += $data["Credits"];
                $Balance += $data["Balance"];
                $local_debits += $data["local_debits"];
                $local_credits += $data["local_credits"];
                $local_balance += $data["local_balance"];
                $second_debits += $data["second_debits"];
                $second_credits += $data["second_credits"];
                $second_balance += $data["second_balance"];
                $close_balance += $data["close_balance"];
                $overall_balance += $data["overall_balance"];
            }
        }


        $resultToreturn .= '
            <tfoot>
                <tr style="color: #4c0870;">';
        if ($is_job != 3)
            $resultToreturn .= '<td></td>';
        $resultToreturn .= '<td class="text-left bold" style="font-size: 1.2em;"><span >Total</span></td>';
        $resultToreturn .= empty($is_job) ? '<td></td>' : '';
        $resultToreturn .= '<td class="text-center bold" style="font-size: 1.2em;"> <span >' . (Forms::DecimalNumber($open_balance)) . '</span></td>
                    <td class="text-center bold" style="font-size: 1.25em;" > <span >' . (Forms::DecimalNumber($prev_balance)) . '</span></td>
                    <td class="text-center bold" style="font-size: 1.2em;" > <span >' . (Forms::DecimalNumber($Debits)) . '</span></td>
                    <td class="text-center bold" style="font-size: 1.2em;" > <span >' . (Forms::DecimalNumber($Credits)) . '</span></td>
                    <td class="text-center bold" style="font-size: 1.2em;" > <span >' . (Forms::DecimalNumber($Balance)) . '</span></td>';
        if (smc_session()['default_setting']['activate_second_currency'] == 1) {
            $resultToreturn .= '<td class="text-center bold " style="font-size: 1.2em;" > <span >' . (Forms::DecimalNumber($local_debits)) . '</span></td>
                <td class="text-center bold " style="font-size: 1.2em;" > <span >' . (Forms::DecimalNumber($local_credits)) . '</span></td>
                <td class="text-center bold " style="font-size: 1.2em;" > <span >' . (Forms::DecimalNumber($local_balance)) . '</span></td>
                    <td class="text-center bold " style="font-size: 1.2em;" > <span >' . (Forms::DecimalNumber($second_debits)) . '</span></td>
                    <td class="text-center bold " style="font-size: 1.2em;" > <span >' . (Forms::DecimalNumber($second_credits)) . '</span></td>
                    <td class="text-center bold " style="font-size: 1.2em;" > <span >' . (Forms::DecimalNumber($second_balance)) . '</span></td>';
        }
        $resultToreturn .= '<td class="text-center bold" style="font-size: 1.2em;"> <span >' . (Forms::DecimalNumber($close_balance)) . '</span></td>
                    <td class="text-center bold" style="font-size: 1.2em;" > <span >' . (Forms::DecimalNumber($overall_balance)) . '</span></td>
                </tr></tfoot>';
        $resultToreturn .= '</table>';
        return $resultToreturn;
        //            die('ok');
    }

    public static function DecimalNumber($num)
    {  
        $num = self::public_round_number($num);
        $flag = false;
        if (substr($num, 0, 1) === '-') {
            $flag = true;
        }
        $num = number_format($num, smc_session()['default_setting']['round_digits'], ".", ",");
        $num2 = str_replace('-', '', $num);
        return ($flag ? '(' . $num2 . ')' : $num2);
        //        return $num2;
    }

    //href=>Inventory/ViewProduct/{$d}
    public static function action_snippet($options)
    {
        $permissions = new Permissions(Session::getUserID());

        $html = '';
        if ($options['isDropDown']) {
            $html .= '<div class="btn-group m-b-sm Action" ' . (isset($options['data_id']) ? 'data-id="' . $options['data_id'] . '"' : '') . ' ' . (isset($options['attr']) ? $options['attr'] : '') . '>
                        <button type="button" class="btn bg-' . $options['color'] . ' dropdown-toggle" data-toggle="dropdown" aria-expanded="false" ' . (isset($options['btn-attr']) ? $options['btn-attr'] : '') . '>
                            ' . CommonLanguage::getMessage('Action') . '<span class="caret"></span>
                        </button>                            
                        <ul class="dropdown-menu" role="menu">';
            for ($h = 0; $h < count($options['ActionOption']); $h++) {
                if (isset($options['ActionOption'][$h]['permission'])) {
                    $html .= (($permissions->hasPermission($options['ActionOption'][$h]['permission'])) ? '<li> <a title="' . $options['ActionOption'][$h]['title'] . '" class="' . $options['ActionOption'][$h]['class'] . '" 
                                                ' . (isset($options['ActionOption'][$h]['href']) ? 'href="' . SITE_LINK . '' . $options['ActionOption'][$h]['href'] . '' . ' "' : '') . ' 
                                                ' . (isset($options['ActionOption'][$h]['attr']) ? $options['ActionOption'][$h]['attr'] : '') . ' 
                                                 ' . (isset($options['ActionOption'][$h]['data-target']) ? 'data-target=' . $options['ActionOption'][$h]['data-target'] . ' data-toggle="modal"' : '') . '> 
                                            <i class="fa ' . $options['ActionOption'][$h]['icon'] . '" type="button" class="btn btn-default"></i> ' . $options['ActionOption'][$h]['title'] . '
                                            </a></li>' : '');
                } else {
                    $html .= '<li> <a title="' . $options['ActionOption'][$h]['title'] . '" class="' . $options['ActionOption'][$h]['class'] . '" 
                                                ' . (isset($options['ActionOption'][$h]['href']) ? 'href="' . SITE_LINK . '' . $options['ActionOption'][$h]['href'] . '' . ' "' : '') . ' 
                                                     ' . (isset($options['ActionOption'][$h]['attr']) ? $options['ActionOption'][$h]['attr'] : '') . ' 
                                                 ' . (isset($options['ActionOption'][$h]['data-target']) ? 'data-target=' . $options['ActionOption'][$h]['data-target'] . ' data-toggle="modal"' : '') . '> 
                                            <i class="fa ' . $options['ActionOption'][$h]['icon'] . '" type="button" class="btn btn-default"></i> ' . $options['ActionOption'][$h]['title'] . '
                                            </a></li>';
                }
            }
            $html .= '</ul></div>';
        } else {
            if (isset($options['ActionOption'][0]['permission'])) {
                if ($permissions->hasPermission($options['ActionOption'][0]['permission'])) {
                    $html .= '<a ' . (isset($options['ActionOption'][0]['href']) ? 'href="' . SITE_LINK . '' . $options['ActionOption'][0]['href'] . '"' : '') . ' ' . (isset($options['ActionOption'][0]['attr']) ? $options['ActionOption'][0]['attr'] : '') . ' ><button  ' . (isset($options['ActionOption'][0]['attr']) ? $options['ActionOption'][0]['attr'] : '') . ' class="btn ' . $options['ActionOption'][0]['class'] . '" ' . (isset($options['data_id']) ? 'data-id="' . $options['data_id'] . '"' : '') . '
                                                data-toggle="modal" data-target="' . (isset($options['ActionOption'][0]['data-target']) ? $options['ActionOption'][0]['data-target'] : '') . '">
                                                ' . (isset($options['ActionOption'][0]['icon']) ? '<i class="fa ' . $options['ActionOption'][0]['icon'] . '"></i>' : '') . ' ' . $options['ActionOption'][0]['title'] . ' </button></a>';
                } else {
                    $html .= '<span>' . CommonLanguage::getMessage('noauthactions') . '</span>';
                }
            } else {
                $html .= '<a ' . (isset($options['ActionOption'][0]['href']) ? 'href="' . SITE_LINK . '' . $options['ActionOption'][0]['href'] . '"' : '') . '  ' . (isset($options['ActionOption'][0]['attr']) ? $options['ActionOption'][0]['attr'] : '') . ' ><button  ' . (isset($options['ActionOption'][0]['attr']) ? $options['ActionOption'][0]['attr'] : '') . ' class="btn ' . $options['ActionOption'][0]['class'] . '" ' . (isset($options['data_id']) ? 'data-id="' . $options['data_id'] . '"' : '') . '
                                                data-toggle="modal" data-target="' . (isset($options['ActionOption'][0]['data-target']) ? $options['ActionOption'][0]['data-target'] : '') . '">
                                                ' . (isset($options['ActionOption'][0]['icon']) ? '<i class="fa ' . $options['ActionOption'][0]['icon'] . '"></i>' : '') . ' ' . $options['ActionOption'][0]['title'] . ' </button></a>';
            }
        }


        return $html;
    }

    public static function snippet_datepicker()
    {
        $html = '<div  class="form-group form-group-default input-group">';
        $html .= '<label>' . CommonLanguage::getMessage('Date') . '</label>';
        $html .= '<input id="Date" name="Date" class="form-control" value="' . Date::getToday() . '" />';
        $html .= '<span class="input-group-addon bg-complete-darker"><i class="fa fa-calendar"></i></span></div>';
        return $html;
    }

    public static function snippet_rangepicker()
    {
        $html = '<div class=" input-daterange " id="datepicker-range">';
        //        $html.='<h5>'.CommonLanguage::getMessage('range_date').'</h5>';
        $html .= '<input id="From_To_Date" type="text" class="form-control" name="From_To_Date" ></div>';
        return $html;
    }

    public static function datatable_chekcbox($d)
    {
        $html = '<input type="checkbox" ' . ($d == 1 ? "checked" : "") . ' data-value="' . $d . '" class="check" />';

        return $html;
    }

    public static function yesno($param)
    {
        return $param == 1 ? CommonLanguage::getMessage('yes') : CommonLanguage::getMessage('no');
    }

    public static function incomeStatementForm($list, $options)
    {
        $result = '';
        foreach ($list as $key => $val) {
            if (is_array($val['value'])) {

                $result .= '<tr><td> <strong>' . CommonLanguage::getMessage($val['title']) . '</strong> </td><td></td></tr>';

                foreach ($val['value'] as $mykey => $value) {
                    $result .= '<tr>
                                    <td ' . (!empty($value['tooltip']) ? 'title="' . CommonLanguage::getMessage($value['tooltip']) . '"' : '') . '>' . CommonLanguage::getMessage($value['title']) . '</td>
                                    <td>' . Forms::DecimalNumber($value['value']) . '</td></tr>';
                }
            } else {
                $result .= '<tr>
                                <td ' . (!empty($val['tooltip']) ? 'title="' . CommonLanguage::getMessage($val['tooltip']) . '"' : '') . '><span ' . (!empty($val['link']) ? 'class="openFrame fa fa-info-circle cursor"' : '') . ' ' . (!empty($val['link']) ? 'data-src="ACC/trialBalance?is_pop=1&currency_id=' . $options['currency'] . '&account=' . $val['account'] . '&from_date=' . $options['from_date'] . '&to_date=' . $options['to_date'] . '"' : '') . '>&nbsp;</span><strong>' . CommonLanguage::getMessage($val['title']) . '</strong> </td>
                                <td>' . Forms::DecimalNumber($val['value']) . '</td>
                            </tr>';
            }
        }
        return $result;
    }

    public static function financialPosition($list, $options)
    {
        $html = '<tr><td colspan="2" class="text-center bg-complete white title">Assets</td></tr>' .
            Forms::incomeStatementForm($list['assets'], $options) .
            '<tr><td colspan="2"  class="text-center bg-complete white title">Liabilities</td></tr>' . Forms::incomeStatementForm($list['liabilities'], $options);

        return $html;
    }

    public static function build_key_products($keys)
    {

        $html = '<tbody>';
        $count = 1;
        for ($i = 1; $i <= 6; $i++) {
            $html .= '<tr>';
            for ($j = 1; $j <= 9; $j++) {
                $html .= '<td data-id="' . $count . '" data-plu="' . (array_key_exists(($count), $keys) ? $keys[$count]['Product_PLU'] : '') . '" data-pid="' . (array_key_exists(($count), $keys) ? $keys[$count]['Product_ID'] : '') . '" data-product="' . (array_key_exists(($count), $keys) ? $keys[$count]['Product_Name'] : '') . '"><div class="key-cell" ' . (array_key_exists($count, $keys) ? 'style="    color: #4c0870;"' : '') . '>' . $count . '<br>' . (array_key_exists(($count), $keys) ? $keys[$count]['Product_Name'] : '') . '</div></td>';
                $count++;
            }
            $html .= '</tr>';
        }
        $html .= '</tbody>';
        return $html;
    }

    public static function build_skip_key_products($array)
    {
        $row = smc_session()['default_setting']['default_pos_row'];
        $column = smc_session()['default_setting']['default_pos_column'];
        $html = '<tbody>';
        $count = 1;
        for ($i = 1; $i <= $row; $i++) {
            $html .= '<tr>';
            for ($j = 1; $j <= $column; $j++) {
                $is_exist = isset($array[$i][$j]);
                $background_color = $is_exist ? ($array[$i][$j]['product_color'] ? $array[$i][$j]['product_color'] : '#4c0870') : '#fff';
                $text_color = $is_exist ? '#fff' : '#eb9220';
                $html .= '<td  style="background-color:' . $background_color . '" data-id="' . $count . '" data-row="' . $i . '" data-column="' . $j . '"  data-product-color="' . ($is_exist ? $array[$i][$j]['product_color'] : '') . '" data-pid="' . ($is_exist ? $array[$i][$j]['Product_ID'] : '') . '" data-product="' . ($is_exist ? $array[$i][$j]['Product_Name'] : '') . '"><div class="key-cell" style="    color: ' . $text_color . ';">' . $count . '<br>' . ($is_exist ? $array[$i][$j]['Product_Name'] : '') . '</div></td>';
                $count++;
            }
            $html .= '</tr>';
        }
        $html .= '</tbody>';
        return $html;
    }

    public static function CommonSearch($term = null, $page, $limit, $col_name, $col_id, $table, $cond = '')
    {
        $db = DBConnectorFactory::loadDriver();
        $data = array();
        $data['is_more'] = false;
        $data['data'] = array();
        $data_filter = array();
        if (!is_null($term)) {
            $cond .= ' and ' . $col_name . ' LIKE ? ';
            $data_filter[] = "%" . $term . "%";
        }
        $query = $db->prepare_Stmt('select  ' . $col_id . ' as id, ' . $col_name . ' as text
                                from  ' . $table . ' where 1=1 ' . $cond . '
                                limit ' . ($page * $limit) . ',' . ($limit + 1), $data_filter);
        while ($row = $db->assoc($query)) {
            $data['data'][] = $row;
        }
        if (count($data['data']) > $limit) {
            array_pop($data['data']);
            $data['is_more'] = true;
        }
        return $data;
    }

    public static function common_search($term = null, $page, $limit, $type)
    {
        $db = DBConnectorFactory::loadDriver();
        $data = array();
        $cond = '';
        $data['is_more'] = false;
        $data['data'] = array();
        $data_filter = array();
        $type_arr = ['ticketing_station' => ['col_id' => 'ticketing_station_id', 'col_name' => 'ticketing_station_name', 'table' => 'tbl_ticketing_station']];
        $col_id = $type_arr[$type]['col_id'];
        $col_name = $type_arr[$type]['col_name'];
        $table = $type_arr[$type]['table'];
        if (!is_null($term)) {
            $cond .= ' and ' . $col_name . ' LIKE ? ';
            $data_filter[] = "%" . $term . "%";
        }
        $query = $db->prepare_Stmt('select  ' . $col_id . ' as id, ' . $col_name . ' as text
                                from  ' . $table . ' where 1=1 ' . $cond . '
                                limit ' . ($page * $limit) . ',' . ($limit + 1), $data_filter);
        while ($row = $db->assoc($query)) {
            $data['data'][] = $row;
        }
        if (count($data['data']) > $limit) {
            array_pop($data['data']);
            $data['is_more'] = true;
        }
        return $data;
    }
 
    public static function build_print_template($keys, $main_arr = array(), $detail_arr = array(), $is_allow_dtl_arr = false)
    {
        //$keys can take a normal one key string or array of keys so we check if first key exist take it else go search to next key
        $cond = "";
        $cond2 = "";
        $permissions = Session::getPermissionsObject();
        $template_not_exist = false;
        $tmplt_id = null;
        if (!empty($keys['id'])) {
            $cond .= " and template_id = '{$keys['id']}' ";
            $tmplt_id = $keys['id'];
            unset($keys['id']);
        }

        if($permissions->hasPermission('Branches')){
            $cond2 .= ' and branch_id ="' . (smc_session()['user_accounts']['branch_id']) . '"'  ;
        }else{
            $cond2 .= ' and branch_id ="' . (smc_session()['user_accounts']['branch_id']) . '"'  ;
        }
        


        $keys = "'" . (is_array($keys) ? implode("', '", $keys) : $keys) . "'";
        //    
        $db = DBConnectorFactory::loadDriver();
        $query = $db->prepare_Stmt("select * from tbl_print_template where template_key in ({$keys}) and status = 1 {$cond} {$cond2} order by FIELD(template_key, {$keys}) asc limit 1");
        $tmplt_row = $db->assoc($query);
        if (empty($tmplt_row)){
            $template_not_exist = true;        
        }
        if($template_not_exist){
            $db = DBConnectorFactory::loadDriver();
            $query = $db->prepare_Stmt("select * from tbl_print_template where template_key in ({$keys}) and status = 1   {$cond} order by FIELD(template_key, {$keys}) asc limit 1");
            $tmplt_row = $db->assoc($query);
            if (empty($tmplt_row))
                return array('html' => "No Template {$keys} Exist!" . (empty($tmplt_id) ? "" : " With Template ID: " . $tmplt_id));
        }

        $html = $tmplt_row['template_text'];
        //get organization data
        $org_obj = new Organization;
        $tmp_org = $org_obj->getOrganizationDetails();
        foreach ($tmp_org[0] as $org_indx => $org_val){
            $main_arr['org__' . $org_indx] = $org_val;
            $main_arr[''.$org_indx]= $org_val;
        }
        $cond3  = '';
        $cond3 .= ' and temp.branch_id ="' . (smc_session()['user_accounts']['branch_id']) . '"'  ;
        $query = $db->prepare_Stmt("SELECT * FROM `tbl_template_attribute` as attr , tbl_print_template as temp WHERE attr.`template_id` = temp.template_id and  template_key in ({$keys})  " .  $cond3 . "   ");
        
        

        while ($row = $db->assoc($query))
            $main_arr[$row['attribute_key']] = $row['attribute_value'];


        if(strlen($main_arr['org__Organization_Commercial_Registry']) <= 0)
            $main_arr['hidden_org__Organization_Commercial_Registry'] = 'hidden';

        if(strlen($main_arr['Organization_vat_num']) <= 0)
            $main_arr['hidden_Organization_vat_num'] = 'hidden';

        if(strlen($main_arr['org__Organization_Phone']) <= 0)
            $main_arr['hidden_org__Organization_Phone'] = 'hidden';

        if(strlen($main_arr['organiaztion_name_en']) <= 0)
            $main_arr['hidden_organiaztion_name_en'] = 'hidden';
        
        if(strlen($main_arr['org_cr_en']) <= 0)
            $main_arr['hidden_org_cr_en'] = 'hidden';

        if(strlen($main_arr['org_vat_en']) <= 0)
            $main_arr['hidden_org_vat_en'] = 'hidden';

        if(strlen($main_arr['org_phone_en']) <= 0)
            $main_arr['hidden_org_phone_en'] = 'hidden';

        if(strlen($main_arr['organiaztion_name_en']) <= 0)
            $main_arr['hidden_organiaztion_name_en'] = 'hidden';

        if(strlen($main_arr['org_des_ar']) <= 0)
            $main_arr['hidden_org_des_ar'] = 'hidden';

        if(strlen($main_arr['org_des_en']) <= 0)
            $main_arr['hidden_org_des_en'] = 'hidden';

        
        $main_arr['print_date'] = date('Y-m-d H:i:s');
        if(smc_session()['default_setting']['enable_sales_invoice_qr_code'] != 1){
        $main_arr['hide_qr'] = "hidden";
        }
        //get common data
        $main_arr['smc__print_time'] = date('Y-m-d H:i:s');
        $main_arr['smc__print_username'] = empty(smc_session()['user_logged_username']) ? '' : smc_session()['user_logged_username'];
        $main_arr['smc__print_userfullname'] = empty(smc_session()['user_logged_full_name']) ? '' : smc_session()['user_logged_full_name'];
        $main_arr['smc__theme_path'] = THEME_PATH;
        $main_arr['smc__upload_path'] = str_replace(dirBase, '', upload_path);
        $main_arr['smc__upload_url'] = upload_url;
        $main_arr['smc__site_link'] = SITE_LINK;
        $main_arr['smc__logo_url'] = SITE_LINK . 'img/logo_white.png';
        $main_arr['smc__system_vat_percent'] = smc_session()['vat_percent'];
        $main_arr['smc__local_currency_symbol'] = smc_session()['local_currency_symbol'];
        //
        if (!empty($detail_arr)) {
            foreach ($detail_arr as $dtl_indx => $dtl_rows) {
                $html = self::build_print_template_details($html, $dtl_indx, $dtl_rows, $is_allow_dtl_arr);
            }
        }
        //better to keep it here so if there is in detail same variable 
        foreach ($main_arr as $indx => $val) {
            if (!is_array($val))
                $html = str_replace("[[{$indx}]]", $val, $html);
            elseif (!is_numeric($indx) && $is_allow_dtl_arr)    //in case if this val is array and index is string we treat it as details
                $html = self::build_print_template_details($html, $indx, $val, $is_allow_dtl_arr);
        }
        unset($tmplt_row['template_text']);
        $tmplt_row['html'] = $html;
        return $tmplt_row;
    }

    public static function build_print_template_details($html, $dtl_indx, $dtl_rows, $is_allow_dtl_arr)
    {
        $dtl_strt_txt = "[[smc__start_{$dtl_indx}]]";
        $dtl_end_txt = "[[smc__end_{$dtl_indx}]]";
        $dtl_strt_len = mb_strlen($dtl_strt_txt);
        $dtl_end_len = mb_strlen($dtl_end_txt);
        $dtl_strt_pos = mb_strpos($html, $dtl_strt_txt);
        $dtl_end_pos = mb_strpos($html, $dtl_end_txt);
        if ($dtl_strt_pos !== false && $dtl_end_pos !== false && $dtl_strt_pos < $dtl_end_pos) {
            $dtl_html_tmplt = mb_substr($html, ($dtl_strt_pos + $dtl_strt_len), ($dtl_end_pos - $dtl_strt_pos - $dtl_strt_len));
            if (!empty($dtl_html_tmplt)) {
                $dtl_html = "";
                if (!empty($dtl_rows)) {
                    foreach ($dtl_rows as $dtl_row) {
                        $crnt_dtl_html = $dtl_html_tmplt;
                        foreach ($dtl_row as $dtl_row_indx => $dtl_row_val) {
                            if (!is_array($dtl_row_val))
                                $crnt_dtl_html = str_replace("[[{$dtl_row_indx}]]", $dtl_row_val, $crnt_dtl_html);
                            elseif (!is_numeric($dtl_row_indx) && $is_allow_dtl_arr)    //in case if this val is array and index is string we treat it as details
                                $crnt_dtl_html = self::build_print_template_details($crnt_dtl_html, $dtl_row_indx, $dtl_row_val, $is_allow_dtl_arr);
                        }
                        $dtl_html .= $crnt_dtl_html;
                    }
                }
                $html = mb_substr($html, 0, $dtl_strt_pos) . $dtl_html . mb_substr($html, $dtl_end_pos + $dtl_end_len);
            }
        }
        return $html;
    }

    //    public static function print_html_template($html, $type, $optns = array()) {
    //        //types: barcode,invoice,pos_invoice
    //        if ($type == 'barcode')
    //            $is_sumatra = smc_session()['default_setting']['barcode_sumatra_print'];
    //        else
    //            $is_sumatra = smc_session()['default_setting']['sumatra_print'];
    //        if ($type == 'invoice')
    //            $is_sumatra = false;
    //        //
    //        if ($is_sumatra)
    //            echo $html;
    //        else {
    ////            if ($type == 'barcode')
    ////                $pdf = new TCPDF('L', "mm", PDF_PAGE_FORMAT, true, 'UTF-8', false);
    ////            else
    ////                $pdf = new TCPDF('P', 'cm', array(8, 22));
    ////            $pdf->SetCreator(PDF_CREATOR);
    ////            $pdf->SetTitle('trusto');
    ////            $pdf->setPrintHeader(false);
    ////            $pdf->setPrintFooter(false);
    ////            $pdf->SetMargins(0, 0, 0);
    ////            $pdf->SetHeaderMargin(0);
    ////            $pdf->SetFooterMargin(0);
    ////            //keep add page below..
    ////            if ($type == 'barcode')
    ////                $pdf->AddPage('L', array(58, 30));
    ////            else
    ////                $pdf->AddPage('', array(8, 22));
    ////            //$pdf->SetFont('aealarabiya', '', 14);
    //////            $pdf->SetFont('dejavusans', 'B', 14);
    ////            $pdf->SetAutoPageBreak(false, 0);
    ////            $pdf->writeHTML($html, true, false, true, false, '');
    ////            $pdf_file_name = tmp_dir_path . "pdf__" . uniqid() . ".pdf";
    ////            $pdf->Output($pdf_file_name, 'F');
    ////            
    ////            self::real_print($pdf_file_name, null, $optns);
    //            self::real_print(tmp_dir_path . "test.html", null, $optns);
    //        }
    //    }

    public static function html2pdf($html, $options, $pdf_path = null)
    {
        if (empty($pdf_path)) {
            $pdf_dir = tmp_dir_path . date('Y_m_d') . '/';
            if (!is_dir($pdf_dir))
                mkdir($pdf_dir);
            $pdf_path = $pdf_dir . 'html2pdf_' . uniqid() . '__' . date('Y_m_d_H_i_s') . '.pdf';
        }
        $wkhtml2pdf_path = dirname(dirname(dirname(__DIR__))) . "\wkhtmltopdf\wkhtmltopdf.exe";
        if (file_exists($wkhtml2pdf_path)) {
            /**
             * wkhtml2pdf
             */
            //$tmp_html_file = tempnam(sys_get_temp_dir(), 'pdf_wkhtml') . '.html';
            //we stop above 'tempnam' since in some places it take time and return nothing
            $tmp_html_file = sys_get_temp_dir() . '/pdf_wkhtml_' . microtime(true) . '_' . uniqid() . '.html';
            file_put_contents($tmp_html_file, $html);
            // -R 10mm : -R margin right, -L, -T, -B, for right left default 10mm for top bottom default 0
            //to print background: --background or --no-background  --zoom 1.3
            //if we don't add  --encoding utf-8 then we must put in template meta charset utf8
            $wkhtml2pdf_optns = " -T 0mm -B 0mm -R 0mm -L 0mm --disable-smart-shrinking --dpi 96 --encoding utf-8 ";
            $wkhtml2pdf_optns .= (empty($options['width']) ? "" : " --page-width {$options['width']}cm ");
            $wkhtml2pdf_optns .= (empty($options['height']) ? "" : " --page-height {$options['height']}cm ");
            $wkhtml2pdf_optns .= ((!empty($options['orientation']) && strtoupper($options['orientation']) == 'L') ? " --orientation Landscape " : "");
            exec("\"{$wkhtml2pdf_path}\" {$wkhtml2pdf_optns} \"{$tmp_html_file}\" \"{$pdf_path}\" ");
            unlink($tmp_html_file);
        } else {
            /**
             * Dompdf
             */
            require_once __DIR__ . '/html2pdf.php';
            generate_pdf($html, $options, $pdf_path);
        }
        /**
         * tcpdf :: html to pdf
         */
        //        $pdf = new tcpdf($options['orientation'], 'cm', array($options['width'], $options['height']), true, 'UTF-8');
        //        $pdf->SetCreator(PDF_CREATOR);
        //        $pdf->SetTitle('PDF');
        //        $pdf->setPrintHeader(false);
        //        $pdf->setPrintFooter(false);
        //        //$pdf->SetMargins(0.3, 0.3, 0.3);
        //        //$pdf->SetFont('aealarabiya', '', 14);
        //        $pdf->AddPage('', array($options['width'], $options['height']));
        //        $pdf->writeHTML($html, true, false, true, false, '');
        //        $pdf->Output($pdf_path, 'F');
        //
        return $pdf_path;
    }

    public static function get_print_width_height($key = null)
    {
        $w = $h = 0;
        if (empty($key) || $key == 'pos') {
            $w = empty(smc_session()['default_setting']['sumatra_print_pos_width']) ?  8.0 : smc_session()['default_setting']['sumatra_print_pos_width'];
            $h = empty(smc_session()['default_setting']['sumatra_print_pos_height']) ? 327.6 : smc_session()['default_setting']['sumatra_print_pos_height'];
        }
        return array('width' => $w, 'height' => $h);
    }

    public static function real_print($printer, $file_path, $optns = null)
    {
        if (empty($printer))
            $printer = self::getDefaultprinterName();
        //
        if (empty($optns))
            $optns = array();
        $paper_size = ' ';
        if (!empty($optns['repeat'])) {
            $repeat = $optns['repeat'];
            $repeat = preg_replace('/[^0-9]/', '', $repeat);    //remove any characters except numbers like ',2x'
        }
        if (!is_numeric($repeat) || $repeat < 1)
            $repeat = 1;
        if (!empty($optns['paper_size']))   //ex: "58x30mm"
            $paper_size .= " -paper \"{$optns['paper_size']}\" ";
        if (empty($optns['cmd']))
            $optns['cmd'] = '';
        //
        if (!empty($optns['is_cmd'])) {
            $printer_path = SYSTEM_PATH . "cmd\pdfprint.exe";
            $cmd = "\"{$printer_path}\"  " . (empty($printer) ? "" : " -printer \"{$printer}\" ") . " " . ((isset($optns['orientation']) && !empty($optns['orientation'])) ? (strtoupper($optns['orientation']) == 'L' ? ' -orient 2 ' : ' -orient 1 ') : "") . " {$paper_size} -copies {$repeat} \"{$file_path}\"";
        } else {
            $printer_path = dirname(dirname(dirname(__DIR__))) . "\SumatraPDF\SumatraPDF.exe";
            $cmd = "\"{$printer_path}\" -silent " . (empty($printer) ? " -print-to-default " : " -print-to \"{$printer}\" ") . " -print-settings \"noscale" . ((isset($optns['orientation']) && !empty($optns['orientation'])) ? (strtoupper($optns['orientation']) == 'L' ? ',landscape' : ',portrait') : "") . ",{$repeat}x\" -view \"continuous single page\" \"{$file_path}\" ";
        }
        //echo "<br>".$cmd."<br>";
        if (smc_session()['default_setting']['is_production'] == 1) {
            exec($cmd);
            unlink($file_path);
            //            if (strtoupper(substr(PHP_OS/* php_uname('s') */, 0, 3)) === 'WIN') {
            //                pclose(popen('start /B "' . escapeshellarg($cmd) . '"', 'r'));
            //            } else {
            //                exec($cmd);
            //                unlink($file_path);
            //            }
        }
    }

    public static function getDefaultprinterName()
    {
        static $def_printer = null;
        if (is_null($def_printer)) {
            $db = DBConnectorFactory::loadDriver();
            $depot_id = !empty(smc_session()['user_accounts']['depot_id']) ? smc_session()['user_accounts']['depot_id'] : smc_session()['default_setting']['default_depot_id'];
            $branch_id = CommonBusiness::getBranchByDepot($depot_id);
            $remote_ip = empty($_SERVER['REMOTE_ADDR']) ? "" : $_SERVER['REMOTE_ADDR'];
            $query = $db->query("SELECT printer_name FROM tbl_printers WHERE is_default = '1' 
                    and (branch_id = '' or concat_ws('',',',branch_id,',') LIKE  ?)
                    and (remote_ip = '' or remote_ip = ?)
                order by remote_ip = ? desc
                ", array("%,{$branch_id},%", $remote_ip, $remote_ip));
            $printer_row = $db->assoc($query);
            if (empty($printer_row))
                $def_printer = '';
            else
                $def_printer = str_replace("[user_ip]", $_SERVER['REMOTE_ADDR'], $printer_row['printer_name']);
        }
        return $def_printer;
    }

    public static function getKeyPrinterName($key)
    {
        static $printer_arr = array();
        if (!isset($printer_arr[$key])) {
            $depot_id = !empty(smc_session()['user_accounts']['depot_id']) ? smc_session()['user_accounts']['depot_id'] : smc_session()['default_setting']['default_depot_id'];
            $branch_id = CommonBusiness::getBranchByDepot($depot_id);
            $db = DBConnectorFactory::loadDriver();
            $query = $db->prepare_Stmt('SELECT printer_name FROM tbl_printers WHERE printer_key = ? and (branch_id = "" or concat_ws("",",",branch_id,",") LIKE  "%,' . $branch_id . ',%") ', array(&$key));
            $printer_row = $db->assoc($query);
            $printer_arr[$key] = '';
            if (!empty($printer_row))
                $printer_arr[$key] = str_replace("[user_ip]", $_SERVER['REMOTE_ADDR'], $printer_row['printer_name']);
        }
        return $printer_arr[$key];
    }

    public static function generate_barcode($code, $is_html = true)
    {
        if ($is_html) {
            require_once 'BarcodeGenerator.php';
            $barcode_obj = new BarcodeGeneratorHTML();
            $barcode_html = $barcode_obj->getBarcode($code, BarcodeGenerator::TYPE_CODE_128, 1.3, 33);
            return $barcode_html;
        }
        require_once 'barcode_128.php';
        $barcode = Code128Barcode::generate($code);
        header("Content-type: image/jpeg");
        imagejpeg($barcode);
    }

    public static function generate_type_barcode($code, $is_html = true, $type = null)
    {
        //$type = BarcodeGenerator::TYPE_CODE_128;  //check types in BarcodeGenerator file
        require_once 'BarcodeGenerator.php';
        if (empty($type))
            $type = BarcodeGenerator::TYPE_CODE_128;
        if ($is_html) {
            $barcode_obj = new BarcodeGeneratorHTML();
            $barcode_html = $barcode_obj->getBarcode($code, $type, null/* 1.3 */, 33);
            return $barcode_html;
        }
        $barcode_obj = new BarcodeGeneratorJPG();
        $barcode_html = $barcode_obj->getBarcode($code, $type, null/* 1.4 */, 50);
        header("Content-type: image/jpeg");
        echo $barcode_html;
        exit;
    }

    public static function generate_qrcode($code, $file_path = null)
    {
        require_once 'phpqrcode.php';
        //here if there is file path then will save to that file, else if false it will create png image with header and output to the browser
        QRcode::png($code, (empty($file_path) ? false : $file_path), $pixelPerPoint = QR_ECLEVEL_H, $outerFrame = 20);
    }

    public static function build_barcode_text($length = null, $code = null)
    {
        if (empty($length))
            $length = smc_session()['default_setting']['default_barcode_length'];
        //for EAN-13, start code: 200 - 299 is local codes for internal company usage
        if ($length == 13) {
            if (empty($code))
                $code = rand(200, 299);
            $remain_char = 12 - mb_strlen($code);
            if ($remain_char < 0)
                return $code;
            $tmp_code = '';
            for ($i = 0; $i < $remain_char; $i++)
                $tmp_code .= rand(0, 9);
            $code .= str_shuffle($tmp_code);
            //for check digit
            //        $sum = 0;
            //        for ($i = (mb_strlen($code) - 1); $i >= 0; $i--)
            //            $sum += (($i % 2) * 2 + 1 ) * $code[$i];
            //        $check_digit = (10 - ($sum % 10));
            //first change digits to a string so that we can access individual numbers
            $code = (string) $code;
            //Add the values of the digits in the even-numbered positions: 2, 4, 6, etc.
            $even_sum = $code{
                1} + $code{
                3} + $code{
                5} + $code{
                7} + $code{
                9} + $code{
                11};
            //Multiply this result by 3.
            $even_sum_three = $even_sum * 3;
            //Add the values of the digits in the odd-numbered positions: 1, 3, 5, etc.
            $odd_sum = $code{
                0} + $code{
                2} + $code{
                4} + $code{
                6} + $code{
                8} + $code{
                10};
            //Sum the results of steps 2 and 3.
            $total_sum = $even_sum_three + $odd_sum;
            //The check character is the smallest number which, when added to the result in step 4,  produces a multiple of 10.
            $next_ten = (ceil($total_sum / 10)) * 10;
            $check_digit = $next_ten - $total_sum;
            return $code . $check_digit;
        }
        //for any code length generate
        $remain_char = $length - mb_strlen($code);
        if ($remain_char < 0)
            return $code;
        $tmp_code = '';
        for ($i = 0; $i < $remain_char; $i++)
            $tmp_code .= rand(0, 9);
        $code .= str_shuffle($tmp_code);
        return $code;
    }

    public static function build_table_html($data)
    {
        //                echo"<pre>";
        //                die(print_r($data));
        $html = ' ';
        foreach ($data as $row) {
            $html .= ' <tr>';
            $class = '';
            if (!empty($row['class'])) {
                $class = $row['class'];
                unset($row['class']);
            }
            //            echo"<pre>";print_r($row);
            foreach ($row as $col) {
                $html .= '<td class=" ' . ($class) . '" >' . $col . '</td>';
            }
            $html .= ' </tr>';
        }
        return $html;
    }

    public static function build_payroll_table($data)
    {
        //        echo"<pre>";
        //        die(print_r($data));
        $html = ' ';
        foreach ($data['details'] as $title => $pay) {
            if (($title == 'Lunch' && $pay == 0) || ($title == 'Phone' && $pay == 0) || ($title == 'other_charges' && $pay == 0) || ($title == 'emp_charge1' && $pay == 0) || ($title == 'emp_charge2' && $pay == 0) || ($title == 'emp_charge3' && $pay == 0) || ($title == 'emp_charge4' && $pay == 0))
                continue;
            $html .= '<tr>
                        <td class="bold">' . CommonLanguage::getMessage($title) . '</td>
                        <td class="text-center" id="' . $title . '" data-value="' . $pay . '">' . (is_numeric($pay) ? self::public_round_number($pay) : $pay) . '</td>
                    </tr>';
        }
        $html .= '<tr>
                <td class="bold f-18">' . CommonLanguage::getMessage('net_pay') . '</td>
                <td class="bold text-center f-18">' . self::public_round_number($data['main']['Net_Pay']) . ' ' . smc_session()['local_currency_symbol'] . '</td>
            </tr>';

        return $html;
    }

    //This function display list of inforamtion used in pages ACC , Inventory
    public static function draw_menu_blocks($menu_arr, $panel_head_class)
    {
        $menu_html = "";
        $permissions = Session::getPermissionsObject();
        $num = 1; //for show and hide
        if(smc_session()['default_setting']['disable_animation'] == 0){
        $arr = array( "flip-left", "flip-right",  "zoom-in","zoom-in-up","zoom-in-down");
        }else{
        $arr = array( "", "", "","","");
        }
        shuffle($arr);

        foreach ($menu_arr as $main_row) {

            $menu_prnt = $menu_sub = "";
            if (!empty($main_row['prmsn']) && !$permissions->hasPermission($main_row['prmsn']))
                continue;
                
            $menu_prnt .= "
                <div class='col-md-3' data-aos='".$arr[0]."' data-aos-duration='1000'>
                <div href='#a1-a0{$num}' data-toggle='collapse' data-parent='.accordion-{$num}' class='panel-heading clearfix {$panel_head_class}' style='color:#ffffff!important;border-radius: 30px;background-color: #e19421 !important;'>
                            <h4 class='panel-title'><i class='{$main_row['icon']}'></i> " . CommonLanguage::getMessage($main_row['msg']) . "</h4>
                        </div>
                    <div id='a1-a0{$num}' class='panel-collapse collapse' class='panel panel-white' style='background-color: #4c0870;border-radius: 20px;'>
                        
                        <div class='panel-body'>

              ";
            if (!empty($main_row['detail'])) {
                foreach ($main_row['detail'] as $sub_row) {
                    if (!$permissions->hasPermission($sub_row['prmsn']))
                        continue;
                    $menu_sub .= "
                            <div class='MainPanelItem' ><a style='color:#ffffff !important;' href='" . (empty($sub_row['lnk']) ? '' : $sub_row['lnk']) . "' " . (empty($sub_row['mdl']) ? "" : " data-toggle='modal' data-target='{$sub_row['mdl']}' ") . " class='mainPageLinks' ><i class='{$sub_row['icon']}'></i> " . CommonLanguage::getMessage($sub_row['msg']) . "" . (isset($sub_row['badge']) ? '<span class="badge badge-success bg-primary pull-right" style="min-width:20px;width:auto;padding:0 2px;">' . $sub_row['badge'] . '</span>' : '') . "</a></div>";
                }
            }
            $menu_prnt .= $menu_sub . "
                        </div>
                    </div>
                </div>";
            if (!empty($menu_sub))   //if no sub for parent or no permission for sub then return empty
                $menu_html .= $menu_prnt;

            $num += 1;
        }
        return $menu_html;
    }

    public static function num_to_word($number, $currency_id, $lang)
    {
        $currency_arr = [
            'en' => [
                '84' => ['Lebanese Pound', 'qeresh'],
                '144' => ['US Dollar', 'cent'],
                '47' => ['Euro', 'cent'],
                '53' => ['Cede', 'Cede'],
                '120' => ['Saudi riyal', 'Halalah'],
                '2' => ['Dirham', 'fils']
            ],
            'ar' => [
                '84' => ['ليرة لبنانية', 'قرش'],
                '144' => ['دولار أمريكي', 'سنت'],
                '47' => ['يورو', 'سنت'],
                '53' => ['Cede', 'Cede'],
                '120' => ['ريال', 'هللة'],
                '2' => ['درهم إماراتي', 'فلس']
            ]
        ];
        $number = round(str_replace(array(',', ' '), '', trim($number)), 2);
        $words = NumToWords::convert($lang, floatval($number), $currency_arr[$lang][$currency_id][0], $currency_arr[$lang][$currency_id][1]);
        return $words;
    }

    public static function build_att_template_html($data)
    {
        $columns = json_decode($data, true);
        $indx_arr = array();
        foreach (range('A', 'Z') as $letter) {
            $indx_arr[] = $letter;
        }
        $html = '<div style="">';
        $i = 1;
        foreach ($columns as $col => $value) {
            $html .= '<strong>' . $indx_arr[$col] . ' : </strong><span attr="' . $value . '">' . CommonLanguage::getMessage($value) . '</span><br>';

            if ($i % 9 == 0) {
                $html .= '</div><div style="padding-left:2%;">';
            }
            $i++;
        }
        $html .= '</div>';
        return $html;
    }

    public static function build_setting_row($setting_name, $setting_type, $setting_value, $setting_value_name)
    {
        $row = '';
        $type = $setting_type;
        if ($type == 'bool') {
            $row = '<input type="checkbox" data-type="' . $type . '" class="setting-bool" name="' . $setting_name . '"  ' . ($setting_value == 1 ? 'checked' : '') . '/>';
        } elseif ($type == 'number') {
            $row = '<input type="number" data-type="' . $type . '" class="form-control" name="' . $setting_name . '" value="' . $setting_value . '" />';
        } elseif ($type == 'percent') {
            $row = '<input type="number" data-type="' . $type . '" class="form-control" min="0" name="' . $setting_name . '" value="' . $setting_value . '" max="100"/>';
        } elseif ($type == 'time') {
            $row = '<input type="text" data-type="' . $type . '" data-content="timepicker" class="form-control "    name="' . $setting_name . '" value="' . $setting_value . '"/>';
        } elseif (strpos($type, "##") !== false) {
            $type_array = explode("##", $type);
            if ($type_array[0] == 'table') {
                $multiple_select_array = '';
                if (!empty($setting_value) && $type_array[1] == 'm')
                    $multiple_select_array = json_encode($setting_value_name);
                $row = "<input type='hidden' data-type='" . $type_array[0] . "' data-select-type='" . $type_array[1] . "' data-content='" . $type_array[2] . "' class='full-width setting-select' value='" . ((!empty($setting_value) && $type_array[1] == "s") ? $setting_value : "") . "' 
                             data-select-name='" . ((!empty($setting_value) && $type_array[1] == "s") ? $setting_value_name : "") . "' name='" . $setting_name . "' data-content-multiple='" . $multiple_select_array . "' />";
            }
            if ($type_array[0] == 'option') {
                $options = json_decode($type_array[2], true);
                //                echo"<pre>";print_r($options);
                $select_type = $type_array[1];
                $row = '<select name="' . $setting_name . '" data-select-type="' . $select_type . '" data-type="' . $type_array[0] . '" class="full-width setting-select "  data-init-plugin="select2" ' . ($select_type == 'm' ? 'multiple' : '') . ' >';
                $selected_options_array = $setting_value != '' ? explode(",", $setting_value) : [];
                foreach ($options as $key => $value) {
                    $row .= '<option value="' . $key . '" ' . (in_array($key, $selected_options_array) ? 'selected' : '') . '>' . CommonLanguage::getmessage($value) . '</option>';
                }
                $row .= '</select>';
            }
        } else //if ($type == 'text')   //default type is 'text'
            $row = '<input type="text" data-type="' . $type . '"  class="form-control "    name="' . $setting_name . '" value="' . $setting_value . '"/>';
        //
        return $row;
    }

    public static function build_postponed_report($data)
    {
        $html = '';
        foreach ($data as $category_data) {
            $html .= '<div class="row">
                <div class="col-md-12">
                    <h3 class="bold title-color">' . $category_data['category_name'] . '</h3>
                </div>
                <div class="col-md-12">
                    <table class="table table-bordered mytable">
                        <thead>
                        <th>#</th>
                        <th>' . CommonLanguage::getMessage('customer_name') . '</th>
                        <th>' . CommonLanguage::getMessage('posponted_date') . '</th>
                        <th>' . CommonLanguage::getMessage('note') . '</th>
                        <th>' . CommonLanguage::getMessage('product_name') . '</th>
                        <th>' . CommonLanguage::getMessage('Quantity') . '</th>
                        <th>' . CommonLanguage::getMessage('tags') . '</th>
                        </thead>';
            foreach ($category_data['details'] as $row) {
                $html .= '<tr>
                    <td>' . $row['invoice_nb'] . '</td>
                    <td>' . $row['customer_name'] . '</td>
                    <td>' . $row['postponed_date_time'] . '</td>
                    <td>' . $row['postponed_note'] . '</td>
                    <td>' . $row['product_name'] . '</td>
                    <td>' . $row['quantity'] . '</td>
                    <td>' . (empty($row['tag']) ? '' : ($row['tag'] . (!empty($row['criteria_note']) ? ' (' . $row['criteria_note'] . ') ' : ''))) . '</td>
                    </tr>';
            }
            $html .= '</table><div></div>';
        }
        return $html;
    }

    public static function buildJobOrderBlock($job_order_block_options, $index)
    {
        $html = '';
        foreach ($job_order_block_options as $blocks) {
            $html .= '<div class="main_div_row">';
            $html .= '<h5 class="bold">' . $blocks['block_name'] . ' <span class="fa fa-minus delete_main_block" style="color:#ed9421;margin-top:15px;"></span></h5>';
            $html .= '<div class="col-md-12 AddRow m-b-10" data-block-id = "' . $blocks['block_id'] . '" data-index-id ="' . $index . '" >';
            foreach ($blocks['options'] as $job_order_option) {
                if ($job_order_option['is_published'] == 0) {
                    $html .= '<div class="main_option_row ' . ($job_order_option['is_title_hidden'] == 1 ? 'm-t-5' : '') . '  " >';
                    $html .= '<h5 class="semi-bold ' . ($job_order_option['is_content_hidden'] == 1 ? 'option_clickable' : '') . ' ' . ($job_order_option['is_title_hidden'] == 1 ? 'hidden' : '') . '"> ' . $job_order_option['option_title'] . ' :</h5>';
                    $html .= '<div class="main_div_options ' . ($job_order_option['is_content_hidden'] == 1 ? 'hidden' : '') . '">';
                    $html .= '<div class="row">';
                    $i = 1;
                    foreach ($job_order_option['options'] as $option) {
                        $html .= '<div class="col-md-4  option_row_values " data-option-detail-id="' . $option['option_detail_id'] . '" data-is-required="' . $option['is_required'] . '" data-type="' . $option['type_id'] . '" data-id="' . $option['option_detail_id'] . '" data-is-published="' . $job_order_option['is_published'] . '">';
                        $html .= '<div class="col-md-4">';
                        $html .= '<label class="sub_type_label">' . $option['option_detail_name'] . '&nbsp;&nbsp;';
                        if ($option['is_required'] == 1) {
                            $html .= '<span class="red-star">*</span>';
                        }
                        $html .= '</label> </div>';
                        $html .= '<div class="col-md-8">';
                        if ($option['type_id'] == 1 || $option['type_id'] == 5 || $option['type_id'] == 6) {
                            $html .= '<input type="' . ($option['type_id'] == 6 ? 'number' : 'text') . '" class="option_detail_name form-control ' . ($option['type_id'] == 5 ? 'autocomplete' : '') . '" style="width:200px;" />';
                        } else if ($option['type_id'] == 3) {
                            foreach ($option['detail_value_title'] as $detail_value) {
                                $html .= '<input type="checkbox" class="option_detail_name_checkbox"  name="option_detail_name_checkbox" value="' . $detail_value . '"  />';
                                $html .= '<label>' . $detail_value . '</label>';
                            }
                        } else if ($option['type_id'] == 4) {
                            $html .= '<input type="file" class="option_detail_name_image  form-control" name="option_detail_name_file_' . $blocks['block_id'] . '_' . $index . '_' . $option['option_detail_id'] . '[]" multiple data-old-image="" deleted-image-data=""  onchange="ValidateForNewImage(this)"/>';
                        } else if ($option['type_id'] == 2) {
                            $html .= '&nbsp;<span class="fa fa-close"></span>&nbsp;';
                            foreach ($option['detail_value_title'] as $detail_value) {
                                $html .= '<input type="radio" class="option_detail_name_radio" data-attribute-name="' . $detail_value . '" name="option_detail_name_radio_' . $blocks['block_id'] . '_' . $index . '_' . $option['option_detail_id'] . '"   />';
                                $html .= '<label>' . $detail_value . '</label>';
                            }
                        } else {

                            $html .= '<select name="option_detail_select" class="option_detail_select full-width" data-init-plugin="select2">';
                            $html .= '<option value="" >' . CommonLanguage::getMessage('select') . '</option>';
                            foreach ($option['detail_value_title'] as $detail_value) {
                                $html .= '<option value="' . $detail_value . '">' . $detail_value . '</option>';
                            }
                            $html .= '</select>';
                        }
                        $html .= '</div></div>';
                        if ($i % 3 == 0) {
                            $html .= '</div>';
                            $html .= '<div class="row">';
                        }
                        $i++;
                    }
                    $html .= '</div></div></div>';
                }
            }
            $html .= '</div></div>';
        }
        return $html;
    }

    public static function customer_sold_item_report_header($header_arr)
    {
        $html = '';
        $html .= '<tr>';
        foreach ($header_arr as $header) {
            $html .= '<th class="text-center" colspan=' . $header['colspan'] . ' >' . $header['name'] . '</th>';
        }
        $html .= '</tr>';
        $html .= '<tr>';

        $i = 0;
        foreach ($header_arr as $indx => $header) {
            if ($i == 0) {

                $html .= ' <th></th>';
            } elseif ($indx == 'others' || $indx == 'totals') {
                $html .= ' <th class="text-center"  >' . CommonLanguage::getMessage('Price') . ' (' . smc_session()['local_currency_symbol'] . ')' . '</th>';
            } else {
                $html .= '<th class="text-center"  >' . CommonLanguage::getMessage('qty') . (!empty($header['uom']) ? ' (' . $header['uom'] . ')' : '') . '</th>';
                $html .= '<th class="text-center"  >' . CommonLanguage::getMessage('Price') . ' (' . smc_session()['local_currency_symbol'] . ')' . '</th>';
            }
            $i++;
        }
        $html .= ' </tr>';
        return $html;
    }

    public static function build_ticketing_reply($data)
    {
        $html = '';
        foreach ($data as $row) {
            $html .= '<div class="alert alert-success " >';
            $html .= '<div class="row">';
            $html .= '<div class="col-md-12">';
            $html .= '<div class="col-md-6 text-created "><h4>' . $row['User_Full_Name'] . '</h4></div>';
            $html .= '<div class="col-md-6 pull-right"><h4 class="pull-right bold">' . $row['date_created'] . '</h4></div>';
            $html .= '</div>';
            $html .= '</div>' . $row['ticketing_reply_description'];
            $html .= '<div class="display-flex" id="main_image_div">';
            if (is_dir(dirBase . "uploads/ticketing/" . $row['ticketing_id'] . "/" . $row['ticketing_reply_id'])) {
                //                echo 'hello';
                $dir = scandir(dirBase . "uploads/ticketing/" . $row['ticketing_id'] . "/" . $row['ticketing_reply_id']);
                foreach ($dir as $file_name) {
                    if (substr($file_name, 0, 1) != '..' && substr($file_name, 0, 1) != '.' && $file_name) {
                        $path_info = dirBase . "uploads/ticketing/" . $row['ticketing_id'] . "/" . $row['ticketing_reply_id'] . "/" . $file_name;
                        $extension = pathinfo($path_info)['extension'];
                        $html .= '<div class=" main_image_row display-flex m-r-10"  data-image-name="' . $file_name . '">';
                        if (in_array($extension, ['png', 'gif', 'jpeg', 'png', 'jpg'])) {
                            $html .= '<img class="image_popup" popup-src="' . SITE_LINK . 'uploads/ticketing/' . $row['ticketing_id'] . '/' . $row['ticketing_reply_id'] . '/' . $file_name . '" src="' . SITE_LINK . 'uploads/ticketing/' . $row['ticketing_id'] . '/' . $row['ticketing_reply_id'] . '/' . $file_name . '" style="max-width:50px;max-height:50px;cursor:pointer;">';
                        } else {
                            $html .= '<a target="_blank" href="' . SITE_LINK . 'uploads/ticketing/' . $row['ticketing_id'] . '/' . $row['ticketing_reply_id'] . '/' . $file_name . '">' . $extension . '</a>';
                        }
                        $html .= '</div>';
                    }
                }
            }
            $html .= '</div>';
            $html .= '</div>';
        }
        return $html;
    }

    public static function get_attachments_div($path, $delete_attachment = true)
    {
        $html = '';
        if (is_dir(dirBase . $path)) {
            $dir = scandir(dirBase . $path);
            foreach ($dir as $file_name) {
                if (substr($file_name, 0, 1) != '..' && substr($file_name, 0, 1) != '.' && $file_name) {
                    $path_info = dirBase . $path . "/" . $file_name;
                    $extension = pathinfo($path_info)['extension'];
                    $html .= '<div class=" main_attachment_row display-flex m-r-10"  data-attachment-name="' . $file_name . '">';
                    if (in_array($extension, ['png', 'gif', 'jpeg', 'png', 'jpg'])) {
                        $html .= '<img class="image_popup" popup-src="' . SITE_LINK . $path . '/' . $file_name . '" src="' . SITE_LINK . $path . '/' . $file_name . '" style="max-width:50px;max-height:50px;cursor:pointer;">';
                    } else {
                        $html .= '<a target="_blank" href="' . SITE_LINK . $path . '/' . $file_name . '">' . $extension . '</a>';
                    }
                    if ($delete_attachment)
                        $html .= ' <i class="fa fa-trash delete_attachment red-star" style="cursor:pointer;"></i>';
                    $html .= '</div>';
                }
            }
        }
        return $html;
    }
}
