<?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    class PaymentVoucherReport extends MX_Controller
    {
        
        public function __construct()
        {
            parent::__construct();
            $this->load->helper('url');
            $this->load->library('form_validation');
            $this->utils->allow();
            $this->load->model('Paymentvoucherreport_model');
        }
        
        public function index()
        {
			$data['dataTable']  = ""; $data['totalAmount'] = 0; $data['cashAmount'] = 0; $data['bankAmount']=0;
			$data['totalTaxAmount'] = 0;  $data['finalTotal'] = 0; $debitName = ''; $creditName =''; $data['totalWithTax']=0;
			if(isset($_POST['searchByDate'])) { 
			    $fromDate = $this->input->POST('fromDate');
				$toDate   = $this->input->POST('toDate');
				$receiptVoucherDetails  = $this->Paymentvoucherreport_model->searchPAndLReportByDate($fromDate,$toDate);
				$totalAmmountForCash    = $this->Paymentvoucherreport_model->totalCashAmount($fromDate,$toDate);
				foreach($totalAmmountForCash as $cahAccount):
					$data['cashAmount']  = $cahAccount['total'];
				endforeach;
				$totalAmmountForBank    = $this->Paymentvoucherreport_model->totalBankAmount($fromDate,$toDate);
				foreach($totalAmmountForBank as $bankAccount):
						$data['bankAmount']  = $bankAccount['total'];
				endforeach;
				foreach($receiptVoucherDetails as $receiptDetails):
					$debitAccountId   = $receiptDetails['debitAccountRegisterId'];
					$debitAccoutName  = $this->Paymentvoucherreport_model->accountName($debitAccountId);
					foreach($debitAccoutName as $debitAccount):
						$debitName    = $debitAccount['accountName'];
					endforeach;
					$creditAccountId  = $receiptDetails['creditAccountRegisterId'];
					$creditAccoutName = $this->Paymentvoucherreport_model->accountName($creditAccountId);
					foreach($creditAccoutName as $creditAccount):
						$creditName   = $creditAccount['accountName'];
					endforeach;
					$totalWithTax	 = $receiptDetails['amount']+$receiptDetails['taxAmount'];
					$data['dataTable'] 	.='<tr>
													<td><center> '.$receiptDetails['journalDate'].'</center> </td>
													<td><center> '.$receiptDetails['voucherNumber'].'</center> </td>
													<td>'.$debitName.'</td>
													<td>'.$creditName.'</td>
													<td>'.$receiptDetails['remarks'].'</td>
													<td style="text-align:right"> '.number_format($receiptDetails['amount'],2,'.','').'</td>
													<td style="text-align:right"> '.number_format($receiptDetails['taxAmount'],2,'.','').'</td>
													<td style="text-align:right"> '.number_format($receiptDetails['amount']+$receiptDetails['taxAmount'],2,'.','').'</td>


													<!--<td><center></center></td>-->
											
													
													
												</tr>';
					
					$data['totalTaxAmount'] = $data['totalTaxAmount']+$receiptDetails['taxAmount'];
					$data['finalTotal']     = $data['finalTotal']+$receiptDetails['amount'];
					$data['totalWithTax']     =$data['totalWithTax']+$receiptDetails['amount']+$receiptDetails['taxAmount'];		
					
			   endforeach;
			 }
            $data['view']  = 'PaymentVoucherReport/paymentVoucherReportView';
            $this->load->view('master', $data);
        }
		
	}