<?php
/**
 * Admin new order
 *
 * */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
global $fbbttm_blogname,$orderdatafull,$fbbttm_helperobj,$fbbttm_settingvalarray;





$username = $firstname = $lastname = $fbbttm_user_country = $fbbttm_user_state = $fbbttm_street_1 = $fbbttm_street_2 = $fbbttm_city = $fbbttm_pincode = $fbbttm_phone =  $oderid = $paymentmethod = $fbbttm_sub_total= $fbbttm_tax = $fbbttm_discount= $fbbttm_grand_total = $fbbttm_created_date = $user_email = ''  ;



if(!empty($orderdatafull)){

    $oderinfo = $orderdatafull['orderinfo'];

    foreach ($oderinfo as $orderinfodata) {
        // code...
            $oderid  = $orderinfodata->fbbttm_fdbid;
            $paymentmethod  = $orderinfodata->fbbttm_payment_method;
            $fbbttm_sub_total  = FBBTTM_CURRENCY_SYMBOL.''.$orderinfodata->fbbttm_sub_total;
            $fbbttm_tax  = FBBTTM_CURRENCY_SYMBOL.''.$orderinfodata->fbbttm_tax;
            $fbbttm_discount  = FBBTTM_CURRENCY_SYMBOL.''.$orderinfodata->fbbttm_discount;
            $fbbttm_grand_total  = FBBTTM_CURRENCY_SYMBOL.''.$orderinfodata->fbbttm_grand_total;
            $fbbttm_created_date = $orderinfodata->fbbttm_created_date;

            $user_email  = $orderinfodata->user_email;
            // phpcs:disable WordPress.DateTime.RestrictedFunctions.date_date 
            $fbbttm_created_date = date('M d, Y', strtotime($fbbttm_created_date));

            $username = $orderinfodata->display_name;
            $firstname = $orderinfodata->fbbttm_first_name;
            $lastname = $orderinfodata->fbbttm_last_name;
            $countryid = $orderinfodata->fbbttm_user_country; 
            
            $stateid = $orderinfodata->fbbttm_user_state;      


            $countryid = $orderinfodata->fbbttm_user_country; 
            $countryname ='';
            if(!empty($countryid)){
                $countrydata = $fbbttm_helperobj->fbbttm_comman_single_tableinfo(FBBTTM_COUNTRIES,'id',$countryid);

                foreach($countrydata as $cdata){
                    $countryname = $cdata->name;
                }
            }

            $stateid = $orderinfodata->fbbttm_user_state;  
             $statename ='';  
            if(!empty($stateid)) {  
                $statedata = $fbbttm_helperobj->fbbttm_comman_single_tableinfo(FBBTTM_STATES,'id',$stateid);

                foreach($statedata as $sdata){
                    $statename = $sdata->name;
                }
            }
  



            $fbbttm_street_1 = $orderinfodata->fbbttm_street_1;                         
            $fbbttm_street_2 = $orderinfodata->fbbttm_street_2;                         
            $fbbttm_city = $orderinfodata->fbbttm_city;                         
            $fbbttm_pincode = $orderinfodata->fbbttm_pincode;                         
            $fbbttm_phone = $orderinfodata->fbbttm_phone;   

    }

}
    

defined( 'ABSPATH' ) || exit;

do_action( 'fbbttm_email_header' );

?>

<div>
    <?php /* translators: %s: order number */ ?>
<h3><?php printf( esc_html__( 'New Order: #%s,', 'foodboxbooker' ), esc_html( $oderid ) ); ?></h3>
<?php /* translators: %s: User name */ ?>
<p><?php printf( esc_html__( 'You’ve received the following order from %s,', 'foodboxbooker' ), esc_html( $firstname.''.$lastname ) ); ?></p>

<p><?php printf( '[Order %s] (%s)',  esc_html($oderid) , esc_html($fbbttm_created_date) ) ;?></p>
</div>

<div>
    <h3><?php echo esc_html__('Order details','foodboxbooker');?></h3>
    <table class="" width="100%" style="text-align:left; border-spacing: 0; border: 1px solid #000;">
        <tbody style="border-bottom: 1px solid #000; width: 100%; background-color: #246dd678; display: flex;">
        <tr style="font-size:16px; line-height:26px; width: 100%; padding: 5px 10px;display: table;">
            <th><?php echo esc_html__('Product Name','foodboxbooker');?></th>
            <th><?php echo esc_html__('Package Details','foodboxbooker');?></th>
            <th><?php echo esc_html__('Subtotal','foodboxbooker');?></th>
        </tr>
        </tbody>

        <tbody style="display: flex; width: 100%; border-bottom: 1px solid #000;">
           
                <?php foreach($orderdatafull['orderiteminfo'] as $orderitem){

                    $title = get_the_title($orderitem->fbbttm_fd_id);
                    $packname = $orderitem->fbbttm_pack_name;
                    $packprice = $fbbttm_helperobj->fbbttm_get_price_with_currency($orderitem->fbbttm_package_price);
                    $fooditemprice = $fbbttm_helperobj->fbbttm_get_price_with_currency($orderitem->fbbttm_fitem_price);
                    $packspecialprice = $fbbttm_helperobj->fbbttm_get_price_with_currency($orderitem->fbbttm_special_price);
                    $packday = $orderitem->fbbttm_package_day;
                    $packstartdate = $orderitem->fbbttm_food_startdate;
                    $packenddate = $orderitem->fbbttm_food_enddate;
                    $packdescription = $orderitem->fbbttm_package_description;
                    $foodtime = $orderitem->fbbttm_food_time;
                    $deliverydays = $orderitem->fbbttm_booking_deliveryday;

                    

                    $post_meta = get_post_meta($orderitem->fbbttm_fd_id); 
                    $itemdetails =  (!empty($post_meta['fbbttmdetails'][0]))? $post_meta['fbbttmdetails'][0] : '';

                    ?>
                <tr style="display: table; font-size:15px;line-height:35px; width: 100%; padding: 0 10px; vertical-align: top;">
                <td><?php echo esc_html($title);?></td>
                <td style="width: 42%;">

                       <div><?php echo esc_html__('Package Name','foodboxbooker'); echo esc_html(' : '.$packname);?></div>

                        <div><?php echo esc_html__('Package Startdate','foodboxbooker'); echo esc_html(' : '.$packstartdate);?></div>
                        <div><?php echo esc_html__('Package enddate','foodboxbooker'); echo esc_html(' : '.$packenddate);?></div>

                        <div><?php echo esc_html__('Delivery Day','foodboxbooker'); echo esc_html(' : '.$deliverydays);?></div>

                        <div><?php echo esc_html__('Delivery Time','foodboxbooker'); echo esc_html(' : '.$foodtime );?></div>

                        <div><?php echo esc_html__('Package info','foodboxbooker'); echo esc_html(' : '.$packdescription);?></div>

                        <div><?php echo esc_html__('Item info','foodboxbooker'); echo esc_html(' : '.$itemdetails);?></div>



                </td>
                <td>

                    <?php echo esc_html($packprice);?>
                </td>
                    </tr>
            <?php }?>
        
        </tbody>
        <tfoot style="display: table; font-size:15px; width: 100%;padding: 10px;">
            <tr>
                <td colspan="2" style="padding-right: 5px; width: 35%;">
                    <?php echo esc_html__('Subtotal','foodboxbooker');?>
                </td>
                <td>
                <?php echo esc_html($fbbttm_sub_total);?>
             </td>
            </tr>

            <tr>
                <td colspan="2" style="padding-right: 5px; width: 35%;">
                    <?php echo esc_html__('Tax','foodboxbooker');?>
                </td>
                <td>
                <?php echo esc_html($fbbttm_tax);?>
             </td>
            </tr>


            <tr style="padding-right: 20px;">
                <td colspan="2" style="padding-right: 5px; width: 35%;">
                    <?php echo esc_html__('Total','foodboxbooker');?>
                </td>
                <td>
                <?php echo esc_html($fbbttm_grand_total);?>
             </td>
            </tr>

        </tfoot>
    </table>
</div>

<div style="margin-top: 30px;">
     <h3><?php echo esc_html__('Billing address','foodboxbooker');?></h3>

     <div style="border: 1px solid;padding: 10px;font-size: 15px;line-height: 25px;">
            <p style="width: 48%;margin: 5px 0;"><?php printf(  '%s %s',  esc_html($firstname) , esc_html($lastname)); ?></p>
            <p style="display: inline-block;margin: 5px 0; padding-right: 8px;"><?php printf(  '%s', esc_html( $fbbttm_street_1) ); ?></p> , 
            <p style="display: inline-block;margin: 5px 0;"><?php printf( '%s', esc_html($fbbttm_city) ); ?></p><br>
            <p style="display: inline-block;margin: 5px 0; padding-right: 5px;"><?php printf(  '%s', esc_html($statename) ); ?></p> , 
            <p style="display: inline-block;margin: 5px 0; padding: 0 5px;"><?php printf(  '%s',  esc_html($countryname) ); ?></p>
            <p style="display: inline-block;margin: 5px 0;"><?php printf(  '%s', esc_html($fbbttm_pincode )); ?></p>
            <p style="width: 48%;margin: 5px 0;"><?php printf(  '%s',  esc_html($fbbttm_phone) ); ?></p>
            <p style="width: 48%;margin: 5px 0;"><a href="mail-to:<?php echo esc_html($user_email);?>"><?php printf(  '%s',  esc_html($user_email) ); ?></a></p>

     </div>

</div>

<div style="margin-top: 20px;">
    <div> <?php echo esc_html__('Congratulations on the sale.','foodboxbooker');?></div>
</div>

<?php
do_action( 'fbbttm_email_footer' );
?>