<?php
/* $Id: index.php 6941 2014-10-26 23:18:08Z daintree $*/
error_reporting(E_ALL & ~E_NOTICE);
$PageSecurity=0;
include('includes/DefineSuppTransClass.php');
include('includes/session.inc');

$Title=_('ERP Home');
include('includes/newheader.php');

?>

		
  					
	<script src="angular/angular.min.js"></script>  
        
 
     
     
		

   
  
 									
									<?php
//this is where you paste. Below paste it:

if (!isset($_SESSION['SuppTrans'])){
	prnMsg(_('To enter a supplier invoice or credit note the supplier must first be selected from the supplier selection screen') . ', ' . _('then the link to enter a supplier invoice or supplier credit note must be clicked on'),'info');
	echo '<br /><a href="' . $RootPath . '/SelectSupplier.php">' . _('Select A Supplier') . '</a>';
	include('includes/footer.inc');
	exit;
	/*It all stops here if there aint no supplier selected and transaction initiated ie $_SESSION['SuppTrans'] started off*/
}

/*If the user hit the Add to transaction button then process this first before showing  all GL codes on the transaction otherwise it wouldnt show the latest addition*/

if (isset($_POST['AddGLCodeToTrans'])
	AND $_POST['AddGLCodeToTrans'] == _('Enter GL Line')){
 //echo $_POST['VatRate'];
	//$_POST['VatRate'] = 0.15;
	$InputError = False;
	if ($_POST['GLCode'] == ''){
		$_POST['GLCode'] = $_POST['AcctSelection'];
	}

	if ($_POST['GLCode'] == ''){
		prnMsg( _('You must select a general ledger code from the list below') ,'warn');
		$InputError = True;
		
	}
	


	
	$SQL = "SELECT oldglcode,
			name
		FROM oldglcode
		WHERE oldglcode ='" . $_POST['GLCode'] . "'";
	$Result = DB_query($SQL);
	$MyRow = DB_fetch_row($Result);
		$GLActName = $MyRow[1];
//echo $_POST['VatRate'];
	//if ($InputError == False){

		$_SESSION['SuppTrans']->Add_GLCodes_To_Trans($_POST['GLCode'],
													$GLActName,
													filter_number_format($_POST['Amount']),
													$_POST['Narrative'],
													$_POST['Tag'],
													$_POST['Department'],
													$_POST['VatRate']
													);
	
		
		unset($_POST['GLCode']);
		unset($_POST['AcctSelection']);
		unset($_POST['Amount']);
	    unset($_POST['Narrative']);
		unset($_POST['Tag']);
		unset($_POST['Department']);
		unset($_POST['VatRate']);
	//}
}

if (isset($_GET['Delete'])){
	$_SESSION['SuppTrans']->Remove_GLCodes_From_Trans($_GET['Delete']);
}

if (isset($_GET['Edit'])){
	$_POST['GLCode'] = $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->GLCode;
	$_POST['AcctSelection']= $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->GLCode;
	$_POST['Amount'] = $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->Amount;
    $_POST['Narrative'] = $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->Narrative;
	$_POST['Tag'] = $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->Tag;
	$_POST['Department'] = $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->Department;
	$_POST['VatRate'] = $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->VatRate;
	
	$_SESSION['SuppTrans']->Remove_GLCodes_From_Trans($_GET['Edit']);
}

/*Show all the selected GLCodes so far from the SESSION['SuppInv']->GLCodes array */
if ($_SESSION['SuppTrans']->InvoiceOrCredit == 'Invoice'){
	echo '<p class="page_title_text">
			<img src="'.$RootPath.'/css/'.$Theme.'/images/transactions.png" title="' . _('General Ledger') . '" alt="" />' . ' ' . _('General Ledger Analysis of Invoice From') . ' ' . $_SESSION['SuppTrans']->SupplierName;
} else {
	echo '<p class="page_title_text">
			<img src="'.$RootPath.'/css/'.$Theme.'/images/transactions.png" title="' . _('General Ledger') . '" alt="" />' . ' ' . _('General Ledger Analysis of Credit Note From') . ' ' . $_SESSION['SuppTrans']->SupplierName;
}
echo '</p>
	<div class = "table-responsive"><table class="table"  style="text-align: center">';

$TableHeader = '<tr >
					<th class="ascending">' . _('Account') . '</th>
				     
					<th class="ascending">' . _('Amount(VEP)') . '</th>
									
					<th>' . _('Narrative') . '</th>
					<th class="ascending">' . _('Tag') . '</th>
					<th class="ascending">' . _('Department') . '</th>
					<th class="ascending">' . _('Tax Rate') . '</th>
					
				</tr>';
echo $TableHeader;
$TotalGLValue=0;
$TotalGLValueVIP=0;
$TotalGLVat=0;

foreach ( $_SESSION['SuppTrans']->GLCodes AS $EnteredGLCode){
	
	$vep = round($EnteredGLCode->Amount,2);
	$vat = ($EnteredGLCode->Amount * $EnteredGLCode->VatRate);
	$vat = round($vat,2);
	$vip = $vep + $vat;

	echo '<tr >
			<td style="text-align: center">' . $EnteredGLCode->GLCode . '</td>
		   
			<td class="number"  style="text-align: center">' . locale_number_format($EnteredGLCode->Amount,$_SESSION['SuppTrans']->CurrDecimalPlaces) . '</td>
			
			<td style="text-align: center">' . $EnteredGLCode->Narrative . '</td>
			<td style="text-align: center">' . $EnteredGLCode->Tag  . ' - ' . $EnteredGLCode->TagName . '</td>
			<td  style="text-align: center">' . $EnteredGLCode->Department  . ' - ' . $EnteredGLCode->DepartmentName . '</td>
			 <td class="number"  style="text-align: center">' . locale_number_format($EnteredGLCode->VatRate,$_SESSION['SuppTrans']->CurrDecimalPlaces) . '</td>
			<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?Edit=' . $EnteredGLCode->Counter . '">' . _('Edit') . '</a></td>
			<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?Delete=' . $EnteredGLCode->Counter . '">' . _('Delete') . '</a></td>
		</tr>';

	$TotalGLValue += $EnteredGLCode->Amount;
	$TotalGLValueVIP += $vip;
$TotalGLVat+= $vat;

	$i++;
	if ($i>15){
		$i = 0;
		echo $TableHeader;
	}
}

echo '<tr>
		<td colspan="2" class="number" >' . _('Total(VEP)') . ':</td>
		<td class="number"  style="text-align: center">' . locale_number_format($TotalGLValue,$_SESSION['SuppTrans']->CurrDecimalPlaces) . '</td>
	</tr>
	
	<tr>
		<td colspan="2" class="number">' . _('Vat') . ':</td>
		<td class="number"  style="text-align: center">' . locale_number_format($TotalGLVat,$_SESSION['SuppTrans']->CurrDecimalPlaces) . '</td>
	</tr>
	<tr>
		<td colspan="2" class="number">' . _('Total(VIP)') . ':</td>
		<td class="number"  style="text-align: center">' . locale_number_format($TotalGLValueVIP,$_SESSION['SuppTrans']->CurrDecimalPlaces) . '</td>
	</tr>
	</table></div>';

if ($_SESSION['SuppTrans']->InvoiceOrCredit == 'Invoice'){
	echo '<br />
		<div class="centre">
			<a href="' . $RootPath . '/SupplierInvoiceGL.php">' . _('Back to Invoice Entry') . '</a>
		</div>';
} else {
	echo '<br />
		<div class="centre">
			<a href="' . $RootPath . '/SupplierCredit.php">' . _('Back to Credit Note Entry') . '</a>
		</div>';
}

/*Set up a form to allow input of new GL entries */
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';

echo '<br />
	<table class="selection">';
if (!isset($_POST['GLCode'])) {
	$_POST['GLCode']='';
}

echo 	'<tr>
		<td>' . _('Select department') . ':</td>
		<td><select name="Department">';

$SQL = "SELECT departmentid,
			departmentname
		FROM department
		ORDER BY departmentid";

$result=DB_query($SQL);

while ($myrow=DB_fetch_array($result)){
	if (isset($_POST['Department']) AND $_POST['Department']==$myrow['departmentid']){
		echo '<option selected="selected" value="' . $myrow['departmentid'] . '">' . $myrow['departmentid'].' - ' .$myrow['departmentname'] . '</option>';
	} else {
		echo '<option value="' . $myrow['departmentid'] . '">' . $myrow['departmentid'].' - ' .$myrow['departmentname'] . '</option>';
	}
}
echo '</select></td>
	</tr>';

echo 	'<tr>
		<td>' . _('Select Cost Center/Tag') . ':</td>
		<td><select name="Tag">';

$SQL = "SELECT tagref,
			tagdescription
		FROM tags
		ORDER BY tagref";

$result=DB_query($SQL);
echo '<option value="0"></option>';
while ($myrow=DB_fetch_array($result)){
	if (isset($_POST['Tag']) AND $_POST['Tag']==$myrow['tagref']){
		echo '<option selected="selected" value="' . $myrow['tagref'] . '">' . $myrow['tagdescription'].' - ' .$myrow['tagdescription'] . '</option>';
	} else {
		echo '<option value="' . $myrow['tagref'] . '">' . $myrow['tagdescription'].' - ' .$myrow['tagref'] . '</option>';
	}
}
echo '</select></td>
	</tr>';


echo '<tr>
	<td>' . _('Account Selection') . ':
		<br />(' . _('If you know the code enter it above') . '
		<br />' . _('otherwise select the account from the list') . ')</td>
	<td><select name="AcctSelection">';

$sql = "SELECT * FROM oldglcode ORDER BY oldglcode";

$result = DB_query($sql);
echo '<option value=""></option>';
while ($myrow = DB_fetch_array($result)) {
	if ($myrow['oldglcode'] == $_POST['AcctSelection']) {
		echo '<option selected="selected" value="';
	} else {
		echo '<option value="';
	}
	echo $myrow['oldglcode'] . '">' .$myrow['oldglcode']  . ' - ' . htmlspecialchars($myrow['name'], ENT_QUOTES, 'UTF-8', false). '</option>';
}

echo '</select>
	</td> 
	</tr>';
if (!isset($_POST['Amount'])) {
	$_POST['Amount']=0;
}
echo '<tr>
		<td>' . _('Amount(VEP)') . ':</td>
		<td><input type="text" class="number" required="required" pattern="(?!^[-]?0[.,]0*$).{1,11}" title="'._('The amount must be numeric and cannot be zero').'" name="Amount" size="12" placeholder="'._('No zero numeric').'" maxlength="11" value="' .  locale_number_format($_POST['Amount'],$_SESSION['SuppTrans']->CurrDecimalPlaces) . '" /></td>
	</tr>';
if (!isset($_POST['VatRate'])) {
	$_POST['VatRate']=0;
}

echo '<tr>
	<td>' . _('Vat Rate') . ':
		
	<td><select name="VatRate" id="VatRate" required="required">';

$sql = "SELECT * FROM taxrates order by taxid desc";

$result = DB_query($sql);
echo '<option value=""></option>';
while ($myrow = DB_fetch_array($result)) {
	if (isset($_POST['VatRate']) AND $_POST['VatRate']==$myrow['rate']){
		echo '<option selected="selected" value="' . $myrow['rate'] . '">' . $myrow['name'].' - ' .$myrow['rate'] . '</option>';
	} else {
		echo '<option value="' . $myrow['rate'] . '">' . $myrow['name'].' - ' .$myrow['rate'] . '</option>';
	}
}
echo '</select>
	</td> 
	</tr>';
if (!isset($_POST['Narrative'])) {
	$_POST['Narrative']='';
}
echo '<tr>
		<td>' . _('Narrative') . ':</td>
		<td><textarea name="Narrative" cols="40" rows="2">' .  $_POST['Narrative'] . '</textarea></td>
	</tr>
	</table>
	<br />';

echo '<div class="centre">
		<input type="submit" name="AddGLCodeToTrans" value="' . _('Enter GL Line') . '" />
	</div>';

echo '</div>
      </form>';





			  
 	echo '</div >';
	?>
						

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

						<!--end:: Widgets/Stats-->

						<!--Begin::Section-->
						

		<!-- end::Quick Sidebar -->

		<!-- begin::Scroll Top -->
		<div id="m_scroll_top" class="m-scroll-top">
			<i class="la la-arrow-up"></i>
		</div>

		<!-- end::Scroll Top -->

		<!-- begin::Quick Nav -->
		

		<!-- begin::Quick Nav -->
<script src="includes/vendors/owl.carousel/dist/owl.carousel.js" type="text/javascript"></script>

		<!--end::Page Scripts -->
	</body>

	<!-- end::Body -->
</html>
 
      
<?php



/*The module link codes are hard coded in a switch statement below to determine the options to show for each tab */
include('includes/MainMenuLinksArray.php');

if (isset($SupplierLogin) AND $SupplierLogin==1){
	echo '<table class="table_index">
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=1">' . _('View or Amend outstanding offers') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=2">' . _('Create a new offer') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=3">' . _('View any open tenders without an offer') . '</a></p>
			</td>
			</tr>
		</table>';
	include('includes/footer.inc');
	exit;
} elseif (isset($CustomerLogin) AND $CustomerLogin==1){
	echo '<table class="table_index">
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/CustomerInquiry.php?CustomerID=' . $_SESSION['CustomerID'] . '">' . _('Account Status') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SelectOrderItems.php?NewOrder=Yes">' . _('Place An Order') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SelectCompletedOrder.php?SelectedCustomer=' . $_SESSION['CustomerID'] . '">' . _('Order Status') . '</a></p>
			</td>
			</tr>
		</table>';

	include('includes/footer.inc');
	exit;
}

if (isset($_GET['Application'])){ /*This is sent by this page (to itself) when the user clicks on a tab */
	$_SESSION['Module'] = $_GET['Application'];
}








//include('includes/footer.inc');

function GetRptLinks($GroupID) {
/*
This function retrieves the reports given a certain group id as defined in /reports/admin/defaults.php
in the acssociative array $ReportGroups[]. It will fetch the reports belonging solely to the group
specified to create a list of links for insertion into a table to choose a report. Two table sections will
be generated, one for standard reports and the other for custom reports.
*/
	global $db, $RootPath, $ReportList;
	require_once('reportwriter/languages/en_US/reports.php');
	require_once('reportwriter/admin/defaults.php');
	$GroupID=$ReportList[$GroupID];
	$Title= array(_('Custom Reports'), _('Standard Reports and Forms'));

	$sql= "SELECT id,
				reporttype,
				defaultreport,
				groupname,
				reportname
			FROM reports
			ORDER BY groupname,
					reportname";
	$Result=DB_query($sql,'','',false,true);
	$ReportList = '';
	while ($Temp = DB_fetch_array($Result)) $ReportList[] = $Temp;

	$RptLinks = '';
	for ($Def=1; $Def>=0; $Def--) {
        $RptLinks .= '<li class="menu_group_headers">';
        $RptLinks .= '<b>' .  $Title[$Def] . '</b>';
        $RptLinks .= '</li>';
		$NoEntries = true;
		if ($ReportList) { // then there are reports to show, show by grouping
			foreach ($ReportList as $Report) {
				if ($Report['groupname']==$GroupID AND $Report['defaultreport']==$Def) {
                    $RptLinks .= '<li class="menu_group_item">';
					$RptLinks .= '<p>&bull; <a href="' . $RootPath . '/reportwriter/ReportMaker.php?action=go&amp;reportid=' . $Report['id'] . '">' . _($Report['reportname']) . '</a></p>';
					$RptLinks .= '</li>';
					$NoEntries = false;
				}
			}
			// now fetch the form groups that are a part of this group (List after reports)
			$NoForms = true;
			foreach ($ReportList as $Report) {
				$Group=explode(':',$Report['groupname']); // break into main group and form group array
				if ($NoForms AND $Group[0]==$GroupID AND $Report['reporttype']=='frm' AND $Report['defaultreport']==$Def) {
                    $RptLinks .= '<li class="menu_group_item">';
					$RptLinks .= '<img src="' . $RootPath . '/css/' . $_SESSION['Theme'] . '/images/folders.gif" width="16" height="13" alt="" />&nbsp;';
					$RptLinks .= '<p>&bull; <a href="' . $RootPath . '/reportwriter/FormMaker.php?id=' . $Report['groupname'] . '"></p>';
					$RptLinks .= $FormGroups[$Report['groupname']] . '</a>';
					$RptLinks .= '</li>';
					$NoForms = false;
					$NoEntries = false;
				}
			}
		}
		if ($NoEntries) $RptLinks .= '<li class="menu_group_item">' . _('There are no reports to show!') . '</li>';
	}
	return $RptLinks;
}
	
?>
<!-- Modal HTML embedded directly into document -->
<div id="ex1" class="modal">
  <p>Thanks for clicking. That felt good.</p>
  <a href="#" rel="modal:close">Close</a>
</div>


<!-- Modal -->
 <div class="modal fade" id="getCodeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog modal-lg">
      <div class="modal-content">
       <div class="modal-header">
         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
         <h4 class="modal-title" id="myModalLabel"> API CODE </h4>
       </div>
       <div class="modal-body" id="getCode" style="overflow-x: scroll;">
       
          
          
       </div>
    </div>
   </div>
 </div>
<script>
jQuery(document).ready(function($){


	
	  
	

	
	
	
   }); 
	
	

	
	
		
		

	
	
</script>


<script type="text/javascript">
jQuery(document).on("ready xcrudafterrequest",function(){
    
});
</script>