<?php defined('BASEPATH') OR exit('No direct script access allowed');
$addressView = !empty($addressView) ? $addressView : 'export/address/salinv';
$this->view('export/css');
?>
<div class="trans">
		<a name="<?php echo $tNo; ?>"></a>
		<table  style="font-size: 14px !important;" border="0" cellspacing="0" cellpadding="0" width="100%" class="noborder nopadding vat">
			<tbody>
				<tr>
					<td style="font-size: 13px !important;" width="70%" ><span><?php echo $tNo_text; ?>
										&nbsp;: <b><?php echo $tNo; ?></span></b></td>
										<td width="30%" style="font-size: 13px !important;" class="label ar"><span><?php echo $tDate_text; ?>
										&nbsp;: <b><?php echo  $tDate;?></span></b></td>
						<!--	<table class="noborder invMeta" style="width:100%" cellspacing="0" cellpadding= "0">
								<tbody>
									<tr>
										<td colspan="2" >
										<b>&nbsp;<b>
										</td>
									</tr>
									<tr>
										<td style="font-size: 13px !important;" colspan="2" >
										<b ></b>
										</td>
									</tr>
									<tr>
										
									</tr>
								</tbody>
							</table>
					</td>-->
				</tr>
			</tbody>
		</table>
</div>
<?php 
		$totqty_consume = 0;
		$totqty_produce = 0;
		$tot_consume = 0;
		$tot_produce = 0;
		$consume_qty = 0;
		$produce_qty = 0;
		$byproduct_qty = 0;
		$consume_amt = 0;
		$produce_amt = 0;
		$byproduct_amt = 0;
		$expense_amt = 0;
			foreach($consumptions as $key => $value) {
				if (!is_array($value)) continue;
				$consume_qty += isset($value['qty']) ? (float)$value['qty'] : 0;
				$consume_amt += isset($value['amount']) ? (float)$value['amount'] : 0;
			}
			foreach($production as $key => $value) {
				if (!is_array($value)) continue;
				$produce_qty += isset($value['qty']) ? (float)$value['qty'] : 0;
				$produce_amt += isset($value['amount']) ? (float)$value['amount'] : 0;
			}
			foreach($expenses as $key => $value) {
				if (!is_array($value)) continue;
				$expense_amt += isset($value['amount']) ? (float)$value['amount'] : 0;
			}
			foreach($byproduct as $key => $value) {
				if (!is_array($value)) continue;
				$byproduct_qty += isset($value['qty']) ? (float)$value['qty'] : 0;
				$byproduct_amt += isset($value['amount']) ? (float)$value['amount'] : 0;
			}
		$tot_consume  = 	(!empty($consume_amt) ? abs($consume_amt) : '0') + (!empty($expense_amt) ? abs($expense_amt) : '0');
		$tot_produce  = 	(!empty($produce_amt) ? abs($produce_amt) : '0') + (!empty($byproduct_amt) ? abs($byproduct_amt) : '0') ;
		$totqty_consume = (!empty($consume_qty) ? abs($consume_qty) : '0');
			$totqty_produce =(!empty($produce_qty) ? abs($produce_qty) : '0') + (!empty($byproduct_qty) ? abs($byproduct_qty) : '0') ;
		
?>
<div style="width: 100%;">
  <div  style="width: 50%;float: left;">
      <table  border="0"  cellspacing="0" cellpadding="2" style="width:100%;table-layout:fixed;padding-top:15px;padding-bottom:15px;padding-right:5px;" class="middlecol">
			<col style="width:8%">
			<col style="width:auto">
			<col style="width:15%">
			<col style="width:15%">
			<col style="width:15%">
		</colgroup>
   		 <thead>
			<tr><th colspan="5">Consumption</th></tr>
			<tr>
				<th>Sno</th>
				<th>Item</th>
				<th class="ar">Quantity</th>
				<th  class="ar">Rate</th>
				<th  class="ar">Amount</th>
			</tr>
		</thead>
		<tbody>
				<?php foreach($consumptions as $key => $value) {
				echo '<tr>';
				echo '<td>'.($key + 1).'</td>';
				echo '<td>'.$value['itemName'];
				if(!empty($value['attrs'])){
					echo '<p class="desc nm pretxt"><small>'.$value['attrs'].'</small></p>';
				}
				echo '</td>';
				echo '<td  class="ar">'.((float)abs($value['qty'])).'&nbsp;' . $value['unit']. '&nbsp;</td>';
				//echo '&nbsp;<small>' . $value['unit']. '</small>&nbsp;';
				echo '<td  class="ar">'.number_format(abs($value['rate']),2).'</td>';
				echo '<td class="ar">'.number_format(abs($value['amount']),2).'</td>';
				echo '</tr>';
				 }?>
				 <?php if(!empty($consume_amt)){?>
				<tr>
					<td colspan="2"><b>Total</b></td>
					<td class="ar"><?php echo (float)(abs($consume_qty)).'&nbsp;' . $consumptions[0]['unit']?></td>
					<td></td>
					<td  class="ar"><?php echo number_format(abs($consume_amt),2);?></td>
				</tr>
				<?php }?>
		</tbody>
    </table>
  </div>

  <div style="width: 50%;float: right;">
   <table  border="0"  cellspacing="0" cellpadding="2" style="width:100%;table-layout:fixed;padding-top:15px;padding-bottom:15px;" class="middlecol">
			<col style="width:8%">
			<col style="width:auto">
			<col style="width:15%">
			<col style="width:15%">
			<col style="width:15%">
      		<thead>
			<tr><th colspan="5">Production</th></tr>
			<tr>
				<th>Sno</th>
				<th>Item</th>
				<th class="ar">Quantity</th>
				<th  class="ar">Rate</th>
				<th  class="ar">Amount</th>
			</tr>
		</thead>
		<tbody>
			<?php if(!empty($production)){ 
			 foreach($production as $key => $value) {
				echo '<tr>';
				echo '<td>'.($key + 1).'</td>';
				echo '<td>'.$value['itemName'];
				if(!empty($value['attrs'])){
					echo '<p class="desc nm pretxt"><small>'.$value['attrs'].'</small></p>';
				}
				echo '</td>';
				echo '<td  class="ar">'. ((float)abs($value['qty'])).'&nbsp;' . $value['unit']. '&nbsp;</td>';
				echo '<td class="ar">'.number_format($value['rate'],2).'</td>';
				echo '<td  class="ar">'.number_format($value['amount'],2).'</td>';
				echo '</tr>';
				 }?>
				 <?php if (!empty($produce_amt)){?>
				<tr>
					<td colspan="2"><b>Total</b></td>
					<td class="ar"><?php echo (float)($produce_qty).'&nbsp;' . $production[0]['unit'];?></td>
					<td></td>
					<td  class="ar"><?php echo number_format($produce_amt,2);?></td>
				</tr>
				<?php }
				
			}?>
		</tbody>
    </table>
   </div>
</div>

<div style="width: 100%;display: flex;">
<?php if(!empty($expenses)){?>
  <div style="width: 50%;float: left;">
      <table  border="0"  cellspacing="0" cellpadding="2" style="width:100%;table-layout:fixed;padding-top:15px;padding-bottom:15px;padding-right:5px;" class="middlecol">
		<col style="width:8%">
		<col style="width:auto">
			<col style="width:15%">
		<thead>
			<tr><th colspan="3">Additional Cost</th></tr>
			<tr>
				<th>Sno</th>
				<th>Description</th>
				<th>Amount</th>
			</tr>
		</thead>
		<tbody>
			
			<?php  if(!empty($expenses)){ 
			foreach($expenses as $key => $value) {
				echo '<tr>';
				echo '<td>'.($key + 1).'</td>';
				echo '<td>'.$value['itemName'].'</td>';
				echo '<td  class="ar">'.number_format($value['amount'],2).'</td>';
				echo '</tr>';
				
				
			}
			 }?>
			<?php  if(!empty($expense_amt)){?> 
				<tr>
					<td colspan="2"><b>Total</b></td>
					<td class="ar"><?php echo number_format($expense_amt,2);?></td>
					
				</tr>
			<?php } ?>
		</tbody> 
      		
    </table>
  </div>
<?php } ?>
<?php if(!empty($byproduct)){?>
  <div style="width: 50%;float: right;">
   <table  border="0"  cellspacing="0" cellpadding="2" style="width:100%;table-layout:fixed;padding-top:15px;padding-bottom:15px;" class="middlecol">
		<col style="width:8%">
		<col style="width:auto">
			<col style="width:15%">
			<col style="width:15%">
			<col style="width:15%">
   		<thead>
			<tr><th colspan="5">By products</th></tr>
			<tr>
				<th>Sno</th>
				<th>Item</th>
				<th class="ar">Quantity</th>
				<th  class="ar">Rate</th>
				<th  class="ar">Amount</th>
			</tr>
		</thead>
		<tbody>
					<?php  
					$byproductSno = 1;
					if(!empty($byproduct)){
						foreach($byproduct as $key => $value) {
						if (!is_array($value)) continue;
						echo '<tr>';
						echo '<td>'.($byproductSno++).'</td>';
						echo '<td>'.(!empty($value['itemName']) ? $value['itemName'] : '');
						if(!empty($value['attrs'])){
							echo '<p class="desc nm pretxt"><small>'.$value['attrs'].'</small></p>';
						}
						echo '</td>';
						echo '<td  class="ar">'.((float)abs(isset($value['qty']) ? $value['qty'] : 0)).'&nbsp;' . (!empty($value['unit']) ? $value['unit'] : '') . '&nbsp;</td>';
						echo '<td  class="ar">'.number_format((float)(isset($value['rate']) ? $value['rate'] : 0),2).'</td>';
						echo '<td  class="ar">'.number_format((float)(isset($value['amount']) ? $value['amount'] : 0),2).'</td>';
						echo '</tr>';
						}
					 }?>
				 <?php  
				if(!empty($byproduct_amt)){?>
				<tr>
					<td colspan="2"><b>Total</b></td>
					<td class="ar"><?php echo (float)($byproduct_qty).'&nbsp;' . $byproduct[0]['unit'];?></td>
					<td></td>
					<td  class="ar"><?php echo number_format($byproduct_amt,2);?></td>
				</tr>
				<?php }?>
		</tbody>
    </table>
   </div>
<?php } ?>
</div>


<div style="width: 100%;display: flex;">
  <div  style="width: 50%;float: left;">
      <table  border="0"  cellspacing="0" cellpadding="2" style="width:100%;table-layout:fixed;padding-top:15px;padding-bottom:15px;padding-right:5px;" class="middlecol">
				<col style="width:auto">
			<col style="width:15%">
			<col style="width:15%">
			<col style="width:15%">
					<tbody>
							<tr>
								<td style="border-top: 0.1px solid black;"><b>Total</b></td>
									<td style="border-top: 0.1px solid black;" class="ar"><?php echo (float) ($totqty_consume) .'&nbsp;' .(( !empty($consumptions) && ($consumptions[0]) && $consumptions[0]['unit']) ? $consumptions[0]['unit'] : '') ;?></td>
								<td  colspan="2" style="border-top: 0.1px solid black;" class="ar"><?php echo number_format($tot_consume,2);?></td>
								
							</tr>
					</tbody> 
    </table>
  </div>

  <div style="width: 50%;float: right;">
   <table  border="0"  cellspacing="0" cellpadding="2" style="width:100%;table-layout:fixed;padding-top:15px;padding-bottom:15px;" class="middlecol">
			<col style="width:auto">
			<col style="width:15%">
			<col style="width:15%">
			<col style="width:15%">
		<tbody>
							<tr>
								<td style="border-top: 0.1px solid black;"><b>Total</b></td>
									<td style="border-top: 0.1px solid black;" class="ar"><?php echo (float)($totqty_produce) .'&nbsp;' .(( !empty($production) && ($production[0]) && $production[0]['unit']) ? $production[0]['unit'] : '');?></td>
								<td colspan="2" style="border-top: 0.1px solid black;" class="ar"><?php echo number_format($tot_produce,2);?></td>
								
							</tr>
					</tbody> 
    </table>
   </div>
</div>

<div class="trans">
<table   border="0" cellspacing="0" cellpadding="0" width="100%" class="noborder nopadding vat">
	<!--<col style="width:50%;">
	<col style="width:50%;">-->
	<tbody>
	<?php 	
		
		$isSign = isset($isSign) ? $isSign : 1;
		if ((!$is_email || !empty($company['invsign'] || !empty($is_pdf))) && !empty(trim(lang("For"))))
		{
			$clr = ($headColor == 'transparent') ? 'black' : $headColor;
		if(!empty($isSign)) { ?><tr>
			<td class="ar bgColor" colspan="2" style="color:<?php echo $clr; ?>;font-size: 12px !important;" ><span><?php echo lang("For"); ?> <?php echo  $company['name'] ?></span></td>
		</tr><?php } 
		}
		?><tr><?php
			$hgt = '';
			if(empty($isSign)) {
				$hgt = '100px';
			}
			echo '<td width="50%" valign="bottom" class="vab nbr custsign bgColor" style="height: '.$hgt.'" >';
			if(!empty($notes)){
			echo '<span><b>Notes </b><br>'.nl2br($notes).'</span>';
			}
			if ((!$is_email  ||!empty($is_pdf)) && !empty($isCustSign))
			{
				$clr = ($headColor == 'transparent') ? 'black' : $headColor;
				echo '<span class="" style="margin-top:40px;color:'.$clr.'" >' . ($tType == DELCHALLAN ? lang("Received") : lang("Customer Signature")) . '</span>';
			}
			echo '</td>';
			
			echo '<td  width="50%" valign="bottom" class="vab ar authsign bgColor" style="color:'.$headColor.'" >';
			//echo $eOe;
			if ($tType != PURINV && !empty(trim(lang("For")))) {
				if (!empty($company['invsign']) && (!empty($signOnPrint)))// $isPrint
				{
					$clr = ($headColor == 'transparent') ? 'black' : $headColor;
					echo '<span class="sign"><img src="' . $company['invsign'] . '" width="" height="" /style="margin-top:0px;color:'.$clr.'" /></span><br>';
					if(!empty($isSign)) {
						echo '<span style="color:'.$clr.';">'.lang("Authorized Signature").'</span>';
					}
				}
				else if (!empty($isSign) && (!$is_email || !empty($company['invsign'] || !empty($is_pdf))))
				{
					$clr = ($headColor == 'transparent') ? 'black' : $headColor;
					echo '<br><br><br><span class="" style="margin-top:40px;float:right;color:'.$clr.'">'.lang("Authorized Signature").'</span>';
				}
			}
			echo '</td>';
		?></tr>
		
	</tbody>
</table>
</div>
<style>
table{
	border-left: none;
	border-bottom: none;
}
th {
	white-space: nowrap;
	font-size:12px;
}
span{
	font-size:13px;
}
td {
display: table-cell;
font-size:12px;
}
td { 
  overflow: hidden !important;
}
.al{
	text-align: left !important;
}
.ar{
	text-align: right !important;
}
.middlecol{
		color:#000;
		width: 100%;
		
	}

.middlecol th{
		border-right: 0.1px solid #000000;
		border-left: 0.1px solid #000000;
		border-top: none;
		border-bottom : 0.1px solid #000000;
		border-top:0.1px solid #000000;
		background: none !important;	
	}
.middlecol td{
		padding-right:10px;
		border-left: 0.1px solid #000000;
		border-top: none;
		border-bottom : 0.1px solid #000000;
		border-right:0.1px solid #000000;
		padding: 3px !important;
		font-size: 12px !important;
	}

</style>
		
		
