<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
<?php
set_time_limit(3000);
ini_set('memory_limit', '-1');
include_once 'app/Mage.php';
umask(0);
Mage::app();
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
Mage::init();
include "conn.php";
$orderid = $_GET['order'];
$name = $_GET['name'];
$street = $_GET['street'];
$city = $_GET['city'];
$code = $_GET['code'];
$country  = $_GET['country'];
$phone = $_GET['phone'];

$subtotal = 0;
$total = 0;
$TVA = 0;
//arrays
$o=0;
$order = Mage::getModel('sales/order')->load($orderid, 'increment_id');
$storeid = Mage::getModel('core/store')->load($order->getStoreId())->getWebsiteId();
$store = Mage::app()->getStore($storeid);
$storename = $store->getName();
//modificari1
	
	
	
	
	//-modificari1

$items = $order->getAllVisibleItems();

$incrementuri = array_fill(1, 20, '');
$names = array_fill(1, 20, '');
$bucs = array_fill(1, 20, '');
$cantitati = array_fill(1, 20, '');
$preturi = array_fill(1, 20, '');
$subtotaluri = array_fill(1, 20, '');
$TVAuri = array_fill(1, 20, '');
$pretfan1 = number_format((float)$order->getShippingInclTax(), 2, '.', '');
$tvafan = number_format((float)$pretfan1/119 *19, 2, '.', '');
$pretfan = $pretfan1 - $tvafan;
foreach($items as $i):
	$o=$o+1;
	$incrementuri[$o] = $o."<br>";
	$names[$o] = $i->getName()."<br>";
	$bucs[$o] = 'BUC'."<br>";
	$cantitati[$o] = number_format((float)$i->getData('qty_ordered'), 0, '.', '')."<br>";
	$preturi1[$o] = number_format((float)$i->getPrice(), 2, '.', '')."<br>";
	$preturi[$o] = "".$preturi1[$o];
	$subtotaluri1[$o] = number_format((float)$i->getPrice()*$i->getData('qty_ordered'), 2, '.', '')."<br>";
		$subtotal = $subtotal + $subtotaluri1[$o];
	$subtotaluri[$o] = "".$subtotaluri1[$o];
	$TVAuri1[$o] = number_format((float)($i->getPrice()*$i->getData('qty_ordered'))/100*$i->getTaxPercent(), 2, '.', '')."<br>";
	$TVAuri[$o] = "".$TVAuri1[$o];
	$TVA = $TVA + $TVAuri1[$o];
endforeach;
$o = $o+1;



$discount = $order->getDiscountAmount()+0;
$iban = $order->getBillingAddress()->getIban();
$nrregcom = $order->getBillingAddress()->getNrregcom();
$cui = $order->getBillingAddress()->getCui();
$bank = $order->getBillingAddress()->getBank();
$azi = date('d-m-Y');

$queryaa = mysqli_query($conn, "SELECT * FROM sales_flat_order WHERE increment_id = '$orderid'");
			while($row1 = mysqli_fetch_array($queryaa, MYSQLI_ASSOC))
			{
				$onestepcheckout_giftwrap_amount = $row1['onestepcheckout_giftwrap_amount'];
			}
if(!$onestepcheckout_giftwrap_amount){
    $asigurare_name = "";
    $asigurare1 = "";
    $asigurare2 = "";
	$oo = "";
  }else{ 
    $asigurare_name = "Asigurare transport";
    $asigurare1 = "8.4 Lei";
    $asigurare2 = "1.6 Lei";
    $asigurare_total = $asigurare1 + $asigurare2;
	$oo = $o+1;
  }
$grandtot = $order->getGrandTotal()+0;
$TVA = number_format($grandtot*19/119, 2, ',',' ');
$subtotal = $subtotal + $pretfan + $asigurare1;
include("mpdf/mpdf.php");
$Mpdf=new mPDF('utf-8', 'A4');
$Mpdf->WriteHTML("<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />

<style>
@media print {
tr.row1 {
   background-color:#f0f0f0; !important;
    -webkit-print-color-adjust: exact; 
}
table.table1{
	-webkit-print-size-adjust: exact;
}
table.table2{
	-webkit-print-size-adjust: exact;
}

}

div.div1{
	position:relative; margin-top:-100px; margin-left:340px;	
}
</style>
</head>
<body>
<table><tr>
<td style='padding-right: 20px;'>
	<font style='font-size:12px;' ><b>
	Furnizor<br>
	SOURCE MANAGEMENT EOOD RUSE<br>
	SUCURSALA BUCURESTI SARAFINESTI<br>
	J40/3397/2018<br>
	RO 39003568<br>
	STRADA SARAFINESTI NR 8<br>
	BUCURESTI, SECTOR 2<br>
	CONT IBAN RO61INGB0000999907802299<br>
	BANCA ING<br>
	Email garantiifix@gmail.com<br>
	Telefon 0751499759<br>
	</b></font>
</td>

<td style='padding-right: 20px;'>
	<font style='font-size:20px;'><b>Factura proforma</b><br>
	Numar $orderid</b></font><br><br>
	<div style='border-style: solid; padding-left: 10px; padding-right: 20px; border-width: 1px;'>
		
	</div>
	<div style='border-style: solid; padding-left: 10px; padding-right: 20px; border-width: 1px;'>
		Data: $azi
	</div>
</td>

<td style='padding-right: 20px;'>
	<font style='font-size:14px;'>
		 CUMPARATOR<br>
		 $name<br>
		 $street<br>
		 $city, $code<br>
		 T:$phone<br>
		 $cui<br>
		 $nrregcom<br>
		 $iban<br>
		 $bank
</td>
</tr>
</table>

<table border='1' style='border-collapse:collapse; border:1px solid black; margin-top:50px; position:absolute;' class='table1'>
	<tr class='row1' style='background-color:#f0f0f0;'><td width='20'><font style='font-size:7px;' color='#666666'><span style='font-size:10px;'>N</span>R. <span style='font-size:10px;'>C</span>RT.</font></td><td width='450'><font style='font-size:8px;' color='#666666' style='margin-left:15px;'>N<span style='font-size:7px;'>UME PRODUS</span></font></td><td width='20'><font style='font-size:10px;' color='#666666' style='margin-left:3px;'>U.M.</font></td><td width='70' style='text-align:center;'><font style='font-size:7px;' color='#666666'><span style='font-size:10px;'>C</span>ANTITATE</font></td><td width='90' style='text-align:center;'><font style='font-size:7px;' color='#666666'><span style='font-size:10px;'>P</span>RET UNITAR</font></td><td width='100' style='text-align:center;'><font style='font-size:7px;' color='#666666'><span style='font-size:10px;'>V</span>ALOARE</font></td><td width='70' style='text-align:center;'><font style='font-size:10px;' color='#666666'>TVA</font></td></tr>
			<tr >
			//Nr Crt
			<td valign='top' align='center'  style='height:600px;'><font style='font-size:12px; '>
				$incrementuri[1]
				$incrementuri[2]
				$incrementuri[3]
				$incrementuri[4]
				$incrementuri[5]
				$incrementuri[6]
				$incrementuri[7]
				$incrementuri[8]
				$incrementuri[9]
				$incrementuri[10]
				$incrementuri[11]
				$incrementuri[12]
				$incrementuri[13]
				$incrementuri[14]
				$incrementuri[15]
				$incrementuri[16]
				$incrementuri[17]
				$incrementuri[18]
				$incrementuri[19]
				$incrementuri[20]
				$o<br>
				$oo
			</font></td>
			<td valign='top'><font style='font-size:12px;'>
				$names[1]
				$names[2]
				$names[3]
				$names[4]
				$names[5]
				$names[6]
				$names[7]
				$names[8]
				$names[9]
				$names[10]
				$names[11]
				$names[12]
				$names[13]
				$names[14]
				$names[15]
				$names[16]
				$names[17]
				$names[18]
				$names[19]
				$names[20]
				Coletarie<br>
				$asigurare_name
			</font></td>
			<td valign='top'><font style='font-size:12px;'>
				$bucs[1]
				$bucs[2]
				$bucs[3]
				$bucs[4]
				$bucs[5]
				$bucs[6]
				$bucs[7]
				$bucs[8]
				$bucs[9]
				$bucs[10]
				$bucs[11]
				$bucs[12]
				$bucs[13]
				$bucs[14]
				$bucs[15]
				$bucs[16]
				$bucs[17]
				$bucs[18]
				$bucs[19]
				$bucs[20]
			</font></td>
			<td valign='top' align='center'><font style='font-size:12px;'>
				$cantitati[1]
				$cantitati[2]
				$cantitati[3]
				$cantitati[4]
				$cantitati[5]
				$cantitati[6]
				$cantitati[7]
				$cantitati[8]
				$cantitati[9]
				$cantitati[10]
				$cantitati[11]
				$cantitati[12]
				$cantitati[13]
				$cantitati[14]
				$cantitati[15]
				$cantitati[16]
				$cantitati[17]
				$cantitati[18]
				$cantitati[19]
				$cantitati[20]
			</font></td>
			<td valign='top' align='right'><font style='font-size:12px;'>
				$preturi[1]
				$preturi[2]
				$preturi[3]
				$preturi[4]
				$preturi[5]
				$preturi[6]
				$preturi[7]
				$preturi[8]
				$preturi[9]
				$preturi[10]
				$preturi[11]
				$preturi[12]
				$preturi[13]
				$preturi[14]
				$preturi[15]
				$preturi[16]
				$preturi[17]
				$preturi[18]
				$preturi[19]
				$preturi[20]
			</font></td>
			<td valign='top' align='right'><font style='font-size:12px;'>
				$subtotaluri[1]
				$subtotaluri[2]
				$subtotaluri[3]
				$subtotaluri[4]
				$subtotaluri[5]
				$subtotaluri[6]
				$subtotaluri[7]
				$subtotaluri[8]
				$subtotaluri[9]
				$subtotaluri[10]
				$subtotaluri[11]
				$subtotaluri[12]
				$subtotaluri[13]
				$subtotaluri[14]
				$subtotaluri[15]
				$subtotaluri[16]
				$subtotaluri[17]
				$subtotaluri[18]
				$subtotaluri[19]
				$subtotaluri[20]
				$pretfan Lei<br>
				$asigurare1
			</font></td>
			<td valign='top' align='right'><font style='font-size:12px;'>
				$TVAuri[1]
				$TVAuri[2]
				$TVAuri[3]
				$TVAuri[4]
				$TVAuri[5]
				$TVAuri[6]
				$TVAuri[7]
				$TVAuri[8]
				$TVAuri[9]
				$TVAuri[10]
				$TVAuri[11]
				$TVAuri[12]
				$TVAuri[13]
				$TVAuri[14]
				$TVAuri[15]
				$TVAuri[16]
				$TVAuri[17]
				$TVAuri[18]
				$TVAuri[19]
				$TVAuri[20]
				$tvafan Lei<br>
				$asigurare2
			</font></td>
			</tr>
</table>

<table border='1' style='border-collapse:collapse; border:1px solid black; margin-top:15px; position:absolute;'>
	<tr height='125px;'>
		<td valign='top' style='padding-right:20px;'><font style='font-size:12px;'>Semnatura si<br>
			stampila<br>
			furnizor<br>
		</font></td>
		<td valign='top'><font style='font-size:12px;'>
		Date privind expeditia<br>
		Nume si prenume..............................................................<br>
		B.I./C.I.seria........., nr....................., eliberat..............................<br>
		Expedierea s-a facut in prezenta noastra<br>
		la data de....................................ora......................<br>
		Data: $azi<br>
		Semnatura ...........................................................<br>
		</font></td>
		<td valign='top' style='padding-right:40px;'><font style='font-size:12px;'>Semnatura<br>
			de<br>
			primire<br>
		</font></td>
		<td valign='top' style='width:200px;'><font style='font-size:12px;'><b>
			SUBTOTAL: $subtotal LEI<br>
			TVA: $TVA LEI<br>			
			DISCOUNT: $discount LEI<br>			
			TOTAL: $grandtot LEI<br>
		</b></font></td>
	</tr>
</table>

");

$Mpdf->Output();

exit;
?>
