<?php
//ini_set('display_errors', 1);
//error_reporting(E_ALL);
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Weekly_report extends REF_Controller {
    public function __construct() {
        parent::__construct();
		$this->load->helper(array('form', 'url'));
        $this->load->library('upload');
        $this->load->model('reports/weekly_model', '', TRUE);
        $this->uri_key_index = 0;
    }
    
    public function index() {
        $data = array();
       
        if (!empty($this->session->flashdata('success'))) 
            $data['success'] = $this->session->flashdata('success');
        else 
            $data['error'] = $this->session->flashdata('error');
        
        if((!empty($this->input->post('submit'))) && ($this->input->post('submit') == 'Get Summary Data' || $this->input->post('submit') == 'Section Wise Report' || $this->input->post('submit') == 'Pdf Summary Data' || $this->input->post('submit') == 'Excel Summary Data' || $this->input->post('submit') == 'Get Details Data' || $this->input->post('submit') == 'Print Details Data' || $this->input->post('submit') == 'Pdf Details Data' || $this->input->post('submit') == 'Excel Details Data' || $this->input->post('submit') == 'Chart Summary Data' || $this->input->post('submit') == 'Chart Details Data')) {  //  || $this->input->post('submit') == 'Print Summary Data'
            $start_date = $this->input->post('start_date');
            $end_date = $this->input->post('end_date');
            $data_type = $this->input->post('submit');
            $abishegam = $this->weekly_model->get_abishegam_data($start_date,$end_date,$data_type);
			$homam = $this->weekly_model->get_homam_data($start_date,$end_date,$data_type);
            $festival = $this->weekly_model->get_festival_data($start_date,$end_date,$data_type);
            $ubayam = $this->weekly_model->get_ubayam_data($start_date,$end_date,$data_type);
            $mega = $this->weekly_model->get_mega_data($start_date,$end_date,$data_type);
            $other = $this->weekly_model->get_other_service_data($start_date,$end_date,$data_type);
            $gold_silver = $this->weekly_model->get_gold_silver_data($start_date,$end_date,$data_type);
            $temple = $this->weekly_model->get_temple_activity_data($start_date,$end_date,$data_type);
            $member_subscripe = $this->weekly_model->get_member_subscribe_data($start_date,$end_date,$data_type);
            $building_fund  = $this->weekly_model->get_building_fund_data($start_date,$end_date,$data_type);
            $outdoor = $this->weekly_model->get_outdoor_data($start_date,$end_date,$data_type);
            $prasadam = $this->weekly_model->get_prasadam_data($start_date,$end_date,$data_type);
            $madappalli = $this->weekly_model->get_madappalli_data($start_date,$end_date,$data_type);
            $donation = $this->weekly_model->get_donation_data($start_date,$end_date,$data_type);
            $hall_booking = $this->weekly_model->get_hall_booking_data($start_date,$end_date,$data_type);
            $wedding_hall = $this->weekly_model->get_wed_hall_booking_data($start_date,$end_date,$data_type);
            $archanai = $this->weekly_model->get_archanai_data($start_date,$end_date,$data_type);
            $kattalai = $this->weekly_model->get_kattalai_data($start_date,$end_date,$data_type);
            $membership = $this->weekly_model->get_membership_data($start_date,$end_date,$data_type);
            $card_topup = $this->weekly_model->get_membership_card_topup_data($start_date,$end_date,$data_type);
            $temple_shop = $this->weekly_model->get_temple_shop_data($start_date,$end_date,$data_type);
        } elseif($this->input->post('submit') == 'Print Summary Data') {
			$start_date = $this->input->post('start_date');
			$end_date = $this->input->post('end_date');
			$data_type = $this->input->post('submit');
			$abishegam = $this->weekly_model->get_abishegam_data($start_date,$end_date,$data_type);
			$homam = $this->weekly_model->get_homam_data($start_date,$end_date,$data_type);
			$festival = $this->weekly_model->get_festival_data($start_date,$end_date,$data_type);
			$ubayam = $this->weekly_model->get_ubayam_data($start_date,$end_date,$data_type);
			$mega = $this->weekly_model->get_mega_data($start_date,$end_date,$data_type);
			$other = $this->weekly_model->get_other_service_data($start_date,$end_date,$data_type);
			$gold_silver = $this->weekly_model->get_gold_silver_data($start_date,$end_date,$data_type);
			$temple = $this->weekly_model->get_temple_activity_data($start_date,$end_date,$data_type);
			$member_subscripe = $this->weekly_model->get_member_subscribe_data($start_date,$end_date,$data_type);
			$building_fund  = $this->weekly_model->get_building_fund_data($start_date,$end_date,$data_type);
			$outdoor = $this->weekly_model->get_outdoor_data($start_date,$end_date,$data_type);
			$prasadam = $this->weekly_model->get_prasadam_data($start_date,$end_date,$data_type);
			$madappalli = $this->weekly_model->get_madappalli_data($start_date,$end_date,$data_type);
			$donation = $this->weekly_model->get_donation_data($start_date,$end_date,$data_type);
			$hall_booking = $this->weekly_model->get_hall_booking_data($start_date,$end_date,$data_type);
			$wedding_hall = $this->weekly_model->get_wed_hall_booking_data($start_date,$end_date,$data_type);
			$archanai = $this->weekly_model->get_archanai_data($start_date,$end_date,$data_type);
			$kattalai = $this->weekly_model->get_kattalai_data($start_date,$end_date,$data_type);
			$membership = $this->weekly_model->get_membership_data($start_date,$end_date,$data_type);
			$card_topup = $this->weekly_model->get_membership_card_topup_data($start_date,$end_date,$data_type);
			$temple_shop = $this->weekly_model->get_temple_shop_data($start_date,$end_date,$data_type);

			$results = array_merge($abishegam,$archanai,$building_fund,$donation,$festival,$gold_silver,$hall_booking,$homam,$kattalai,$madappalli,$mega,$member_subscripe,$membership,$card_topup,$outdoor,$other,$prasadam,$temple,$temple_shop,$ubayam,$wedding_hall);
		   
			$general = $this->general_settings_model->get_by_id();
			
			$body = array();
			$total_amt  = 0;
			$jj			= 0;
			foreach($results as $key=>$value) {
			   #$total_amt += $value['amount'];
				$jo = ++$jj;
			   //Refund Amount
				$Refund = $this->weekly_model->get_refund_amt_by_ids($value['type_id'],$value['service_id'],$value['id'],$date);
			  
				if(!empty($Refund)) {
					$recentAmt = $value['amount'] - $Refund;
				}
				else {
				   $recentAmt = $value['amount'];
				}
				
				$total_amt += $recentAmt;
				if(!empty($value['gst'])) {
					$AmtwithGst = $recentAmt * ($value['gst'] / 100);
				} else {
					$AmtwithGst = 0;
				}
											
			   $gst = (!empty($value['amount'])) ? number_format($recentAmt - $AmtwithGst,2,'.','') : '0.00';
			   $gst_amt = (!empty($value['gst'])) ? number_format($AmtwithGst,2,'.','') : '0.00';
				if($general->gst > 0) {
					$body[] = array($jo, $value['rec_no'], $value['name'], $value['qty'], $value['price'], '<span style="float: right;">' . $gst . '</span>', '<span style="float: right;">' . $gst_amt . '</span>','<span style="float: right;">' . number_format($recentAmt,2,'.','') . '</span>');
				} else {
					$body[] = array($jo, $value['rec_no'], $value['name'], $value['qty'], $value['price'], '<span style="float: right;">' . number_format($recentAmt,2,'.','') . '</span>');  
				}
			   
			}
						
			$sub_body 	= $this->get_sub_body( $start_date, $end_date );
			$sub_body[] = array('Total S$',  number_format(($total_amt),2,'.','')); 
			
			$footer_cnt	= '<div style="width: 100%; float: right;">
							<div style="float: left; clear: both; width:33.3%;">
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div><b style="font-size: 15px;">Verified By</b></div>
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div>-----------------------------------------</div>
						   </div>
						   <div style="float: left; width:33.3%;">
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div><b style="font-size: 15px;">Approved By</b></div>
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div>-----------------------------------------</div>
						   </div>
						   <div style="float: left; width:33.3%;">
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div><b style="font-size: 15px;">Confirmed By</b></div>
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div>&nbsp;</div>
								<div>-----------------------------------------</div>
						   </div>
					   </div>';
			
			$args = array(
				'type'      => '10', // Default = 1 // Normal (Double print), '2' => Kattalai Archanai,   '3' = Hall Booking | Wedding Hall, '4' => 'Madapalli', '5' => Archanai, '6' => Common
				'rec_no'    => '',
				'title'     => 'Weekly Summary Report',		
				'start_date' => $start_date,
				'end_date' => $end_date,
				'amount'    => array(''),
				'copy'      => FALSE,
				'footer_txt'=> $footer_cnt,
				
				'data'      => array(
					'tables' => array(				
						'head'  => array('S.No', 'Receipt No', 'Name', 'Qty', 'U.Price',(($general->gst > 0) ? 'Before GST' : ''), (($general->gst > 0) ? 'GST' : ''), 'Total ('.(($general->gst > 0) ? 'Incl. of GST' : '').')'),
						'body'  => $body,
					),
			   
					'sub_tables' => array(
						'head'  => array(''),
						'body'  => $sub_body,
					),
				),
			);	

			//echo "<pre>"; print_r($args); exit;
			print_rec($args);
			redirect('weekly_report','refresh');
		}else  {
            $start_date = '';
            $end_date = '';
            $data_type = 'Get Summary Data';
            $abishegam = $this->weekly_model->get_abishegam_data($start_date = '',$end_date = '',$data_type);
			$homam = $this->weekly_model->get_homam_data($start_date = '',$end_date = '',$data_type);
            $festival = $this->weekly_model->get_festival_data($start_date = '',$end_date = '',$data_type);
            $ubayam = $this->weekly_model->get_ubayam_data($start_date = '',$end_date = '',$data_type);
            $mega = $this->weekly_model->get_mega_data($start_date = '',$end_date = '',$data_type);
            $other = $this->weekly_model->get_other_service_data($start_date = '',$end_date = '',$data_type);
            $gold_silver = $this->weekly_model->get_gold_silver_data($start_date = '',$end_date = '',$data_type);
            $temple = $this->weekly_model->get_temple_activity_data($start_date = '',$end_date = '',$data_type);
            $member_subscripe = $this->weekly_model->get_member_subscribe_data($start_date = '',$end_date = '',$data_type);
            $building_fund  = $this->weekly_model->get_building_fund_data($start_date = '',$end_date = '',$data_type);
            $outdoor = $this->weekly_model->get_outdoor_data($start_date = '',$end_date = '',$data_type);
            $prasadam = $this->weekly_model->get_prasadam_data($start_date = '',$end_date = '',$data_type);
            $madappalli = $this->weekly_model->get_madappalli_data($start_date = '',$end_date = '',$data_type);
            $donation = $this->weekly_model->get_donation_data($start_date = '',$end_date = '',$data_type);
            $hall_booking = $this->weekly_model->get_hall_booking_data($start_date = '',$end_date = '',$data_type);
            $wedding_hall = $this->weekly_model->get_wed_hall_booking_data($start_date = '',$end_date = '',$data_type);
            $archanai = $this->weekly_model->get_archanai_data($start_date = '',$end_date = '',$data_type);
            $kattalai = $this->weekly_model->get_kattalai_data($start_date = '' ,$end_date = '',$data_type);
            $membership = $this->weekly_model->get_membership_data($start_date = '',$end_date = '',$data_type);
            $card_topup = $this->weekly_model->get_membership_card_topup_data($start_date = '',$end_date = '',$data_type);
            $temple_shop = $this->weekly_model->get_temple_shop_data($start_date = '',$end_date = '',$data_type);
        }
        #echo '<pre>';print_r($abishegam);die;
        $data['results'] = array_merge($abishegam,$archanai,$building_fund,$donation,$festival,$gold_silver,$hall_booking,$homam,$kattalai,$madappalli,$mega,$member_subscripe,$membership,$card_topup,$outdoor,$other,$prasadam,$temple,$temple_shop,$ubayam,$wedding_hall);
        #echo '<pre>';print_r($data['results']);exit;
        $data['start_date'] = $start_date;
        $data['end_date'] = $end_date;
        $data['type'] = $data_type;
        $data['mode'] = $this->weekly_model->payment_type_list();
        $actions = $this->actions();
        $data['form_action'] = 'weekly_report';
        $data['title'] = 'Weekly Summary Report';
		
		$data['pdftype'] 	= '';
		$data['exceltype']	= '';
		$data['charttype'] 	= '';
		
		if($this->input->post('submit') == 'Get Summary Data'  || $this->input->post('submit') == 'Print Summary Data'){
			$data['pdftype'] 	= 'Pdf Summary Data';
			$data['exceltype'] 	= 'Excel Summary Data';
			$data['charttype'] 	= 'Chart Summary Data';
		}
		elseif($this->input->post('submit') == 'Get Details Data' || $this->input->post('submit') == 'Print Details Data'){
			$data['pdftype'] 	= 'Pdf Details Data';	
			$data['exceltype'] 	= 'Excel Details Data';
			$data['charttype'] 	= 'Chart Details Data';
		}else{
			$data['pdftype'] 	= 'Pdf Summary Data';
			$data['exceltype'] 	= 'Excel Summary Data';
			$data['charttype'] 	= 'Chart Summary Data';
		}
        
        $filters = array();
        if(!empty($this->input->post('filter_columns'))) {
            foreach($this->input->post('filter_columns') as $key=>$value) {
                array_push($filters,$this->input->post($value));
            } 
        }
        $data['filters'] = array_filter($filters);
        
        if($this->input->post('submit') == 'Chart Summary Data' || $this->input->post('submit') == 'Chart Details Data' ){		
            $data['dataType'] = $this->input->post('submit');
			$q 							= $this->db->get_where(TBL_SETTINGS_BASIC);
			$data['settings'] 			= $q->row_array();
			$q_des						= $this->db->get_where(TBL_SETTINGS_DESIGN);
            $data['settings'] 			= array_merge($data['settings'], $q_des->row_array());
			$user_data 					= get_session_userdata();
			$_SESSION['pdf_chart']		= "success";
            $_SESSION['pdf_chart_file']	= "weekly_chart_report.pdf";
			
			include($_SERVER['DOCUMENT_ROOT'].'/smmt/application/views/reports/weekly/chartpdf.php');
        }else if ($this->input->post('submit') == 'Section Wise Report') {
			
            $data['dataType'] 			= $this->input->post('submit');			
			$q 							= $this->db->get_where(TBL_SETTINGS_BASIC);
			$data['settings'] 			= $q->row_array();
			$q_des						= $this->db->get_where(TBL_SETTINGS_DESIGN);
            $data['settings'] 			= array_merge($data['settings'], $q_des->row_array());
			
			$data['abishegam'] 			= $abishegam;
			$data['archanai'] 			= $archanai;
			$data['building_fund'] 		= $building_fund;
			$data['donation'] 			= $donation;
			$data['festival'] 			= $festival;
			$data['gold_silver'] 		= $gold_silver;
			$data['hall_booking'] 		= $hall_booking;
			$data['homam'] 				= $homam;
			$data['kattalai'] 			= $kattalai;
			$data['madappalli'] 		= $madappalli;
			$data['mega'] 				= $mega;
			$data['member_subscripe']	= $member_subscripe;
			$data['membership']			= $membership;
			$data['card_topup']			= $card_topup;
			$data['outdoor']			= $outdoor;
			$data['other']				= $other;
			$data['prasadam']			= $prasadam;
			$data['temple']				= $temple;
			$data['temple_shop']		= $temple_shop;
			$data['ubayam']				= $ubayam;
			$data['wedding_hall']		= $wedding_hall;
			
			$user_data 					= get_session_userdata();
			$_SESSION['pdf_section']		= "success";
            $_SESSION['pdf_section_file']	= "weekly_section_report.pdf";	
			
			include($_SERVER['DOCUMENT_ROOT'].'/smmt/application/views/reports/weekly/separate_pdf.php');			
        }else if($this->input->post('submit') == 'Print Details Data' ){
           $data['dataType'] = $this->input->post('submit');			
			if( IS_KSK ) :
                $html = $this->load->view('reports/weekly/pdfnew', $data, TRUE);
				print_rec($html);
				redirect('weekly_report','refresh');
            else :
                $this->render($data, 'reports/weekly/pdf');
            endif;
        } else if ($this->input->post('submit') == 'Pdf Summary Data' || $this->input->post('submit') == 'Pdf Details Data') {
            $data['dataType'] = $this->input->post('submit');
			$user_data 			= get_session_userdata();
			
            if (IS_KSK) :
                $html = $this->load->view('reports/weekly/pdf', $data, TRUE);
                $args = array();
                if (!is_array($args)) :
                    $is_html = TRUE;
                    $args = array('raw_html' => $args, 'copy' => FALSE);
                endif;
                $type = !empty($args['type']) ? $args['type'] : '1';
                define('IS_SHORT', ($type == '5' || $args['short'] ? TRUE : FALSE));
                define('WIDTH', IS_SHORT ? '287' : '1000'); //'562');
                // $args['is_copy'] = ($type == '1' && !isset($args['copy'])) || $args['copy'] ? TRUE : FALSE;
                $args['is_copy'] = (( $type == '12' || $type == '13' || $type == '14' || $type == '15' || $type == '16' || $type == '17') && !isset($args['copy'])) || $args['copy'] ? TRUE : FALSE;
                $args['sepr'] = '&nbsp;/&nbsp;';
                $q = $this->db->get_where(TBL_SETTINGS_BASIC);
                $args['settings'] = $q->row_array();
                $settings=$args['settings'];
                $q = $this->db->get_where(TBL_SETTINGS_DESIGN);
                $args['settings'] = array_merge($args['settings'], $q->row_array());
//                print_r($args);
               // $header = $this->load->view('templates/print/pdfheader', $args, TRUE);
                $logo_url = !empty($args['settings']['logo']) && file_exists(DIR_COMPANY_LOGO. $args['settings']['logo']) ? DIR_COMPANY_LOGO . $args['settings']['logo'] : 'assets/images/logo.png';
              // $htmlall ='<div class="clear" style="clear:both;height:9em"></div>';
				$search_date=$date;               
                $htmlall ='<table width="100%" style="font-family:Verdana, Geneva, sans-serif">';
                $htmlall .='<tr>';
                $htmlall .=' <td width="5%"><div style="min-width: 115px;">';
                $htmlall .='<img src="'.$logo_url.'" style="width:100px" />';
                $htmlall .='</div></td>';
                $htmlall .=' <td width="80%" align="center">';
                $htmlall .=' <table border="0" width="100%">';
                $htmlall .=' <tr>';
                $htmlall .=' <td align="center" style="font-size:14px;">';
                $htmlall .=$settings['temple_name'];
                $htmlall .='</tr>';
                $htmlall .='</table>';
                $htmlall .='</td>';
                $htmlall .='<tr><td colspan="3"><hr></td></tr>';
                $htmlall .='</table>';
                $htmlall .='<table width="100%" border="0" width="100%" cellpadding="5" style="font-family:Verdana, Geneva, sans-serif">';
                $htmlall .='<tr>';
                $htmlall .='<td width="25%">&nbsp;</td>';
                $htmlall .='<td align="center" width="50%" style="font-weight:bold; font-size:14px;">';
                $htmlall .='Weekly Summary Report';
                $htmlall .='<td width="25%" style="font-size:13px;">';               
				$htmlall .='Printed On:';
                $htmlall .=$user_data['name']."-".date("Y-m-d H:i:s");
                $htmlall .='</td>';
                $htmlall .=' </tr>';
                $htmlall .=' </table>';      
           
              
                $html = $this->load->view('reports/weekly/pdf', $data, TRUE);
                /*
				 if (count($data['nets_results']) > 0 || count($data['cheque_results']) > 0) {
                     $html .=$this->load->view('reports/daily_summary/pdf_nets', $data, TRUE);
                 }
               */
               $htmlall .= $html;
        
                $filename = "weekly_summary_report_" . date("Y-m-d");
                $pdfFilePath = date('d-m-Y').".pdf";
                $this->load->library('m_pdf');
                $pdf = $this->m_pdf->load();
                $pdf->SetAutoFont(AUTOFONT_ALL);
				//                $pdf->AddPage("L");
				 $pdf->AddPage('L', // L - landscape, P - portrait
				'', '', '', '',
				5, // margin_left
				5, // margin right
				5, // margin top
				5, // margin bottom
				3, // margin header
				3);
            	unlink(FCPATH.'uploads/weekly_pdf/');
                $pdf->setFooter('{PAGENO}');
              	$pdf->WriteHTML($htmlall);
               	$pdf->Output(FCPATH.'uploads/weekly_pdf/'.$pdfFilePath, "F");
               	$_SESSION['pdf_weekly']="success";
               	$_SESSION['pdf_weekly_file']=$pdfFilePath;
                redirect("weekly_report","refresh");
                
               //exit(0);
            else :
                $this->render($data, 'reports/weekly/pdf');
            endif;
        } elseif(((!empty($this->input->post('submit'))) && ($this->input->post('submit') == 'Excel Summary Data' || $this->input->post('submit') == 'Excel Details Data'))) {
		    $this->load->view('reports/weekly/excel', $data);
        } else {
            $this->render($data, 'reports/weekly/list');
        }
    }
	
	function uploadchartpdf(){
		unlink(FCPATH.'uploads/weekly_pdf/weekly_chart_report.pdf');
		$filename					= 'pdf';
		$config						= array();
		$config['upload_path'] 		= FCPATH.'uploads/weekly_pdf/';
		$config['allowed_types'] 	= '*';
		$config['max_size']    		= '15000000';
		$config['file_name']        = "weekly_chart_report.pdf";
		$this->load->library('upload');
	
		$this->upload->initialize($config);
	
		if(!is_dir($path)){
			@mkdir($path, 0777, true);
		}
	
		if ( ! $this->upload->do_upload($filename)) {
			echo $this->upload->display_errors();
			exit;
		} else {
			return "success";
		}
	}
	
	function generate_chart_report(){
		unlink(FCPATH.'uploads/weekly_pdf/weekly_chart_report.pdf');
		$html			= $_POST['variable'];
		$pdfFilePath 	= "weekly_chart_report.pdf";
		$this->load->library('m_pdf');
		$pdf = $this->m_pdf->load();
		$pdf->SetAutoFont(AUTOFONT_ALL);
		//                $pdf->AddPage("L");
		 $pdf->AddPage('P', // L - landscape, P - portrait
		'', '', '', '',
		5, // margin_left
		5, // margin right
		5, // margin top
		5, // margin bottom
		3, // margin header
		3);
		unlink(FCPATH.'uploads/weekly_pdf/');
		$pdf->setFooter('{PAGENO}');
		$pdf->WriteHTML($html);
		$pdf->Output(FCPATH.'uploads/weekly_pdf/'.$pdfFilePath, "F");
	}
	
	function generate_section_report(){
		unlink(FCPATH.'uploads/weekly_pdf/weekly_section_report.pdf');
		$html			= $_POST['variable'];
		$pdfFilePath 	= "weekly_section_report.pdf";
		$this->load->library('m_pdf');
		$pdf = $this->m_pdf->load();
		$pdf->SetAutoFont(AUTOFONT_ALL);
		//                $pdf->AddPage("L");
		 $pdf->AddPage('P', // L - landscape, P - portrait
		'', '', '', '',
		5, // margin_left
		5, // margin right
		5, // margin top
		5, // margin bottom
		3, // margin header
		3);
		unlink(FCPATH.'uploads/weekly_pdf/');
		$pdf->setFooter('{PAGENO}');
		$pdf->WriteHTML($html);
		$pdf->Output(FCPATH.'uploads/weekly_pdf/'.$pdfFilePath, "F");
	}
	
	function get_sub_body( $date1, $date2 ) {        
		$sub_body 		= array();
		$mode 			= $this->weekly_model->payment_type_list();	
		$refundAmount 	= $this->weekly_model->get_refund_amount($date1, $date2);
		foreach($mode as $key=>$value) {
			$paidAmount = $this->weekly_model->get_total_paid_amt_by_type($value->id, $date1, $date2);
			if($value->payment_mode == 'cash') { 
				$refundAmt = $this->weekly_model->get_refund_amount($date);
			} else { 
				$refundAmt = '0.00';
			}

			$Amount = (!empty($paidAmount->amount)) ? (($value->payment_mode == 'cash') ? number_format($paidAmount->amount - $refundAmt,2,'.','') :  $paidAmount->amount ) : '0.00';

			$sub_body[] = array(ucfirst($value->name).' S$', $Amount);
		}
		
		return $sub_body;
	}
   
} 
?>