<?php
require_once("../include/config.php");	
require_once("../include/startup.php");

$obj  = new Client();
$obj1  = new Company();

if($G_memberid > 0)
{
	$memberid = $G_memberid;
$companyid = $_GET['companyid'];
	
			
		$memberinvoicesid = intval($_GET['memberinvoicesid']);
	
$obj_invoice	= new Invoice_frproforma();

$query="select c.head_Email,c.panno,a.billed_membername,a.duedate,a.billing_membercompanyid,a.status,a.invoiceno,a.InvoiceTotalAmount,a.invoicedate
					,a.duedate,a.discount_amount,a.inv_Add1,a.inv_Pin,a.inv_CityName,a.inv_Add2,a.inv_StateName,a.invoiceno,a.InvoiceTotalAmount,a.InvoiceBaseAmount,d.gstno,a.inv_GST_no,
					a.InvoiceBaseAmountBeforeDiscount,a.cgst_amount,a.sgst_amount,a.igst_amount,b.* from mstmember x
				  	inner join trninvoicetomember_frproforma a on x.memberid = a.memberid 
				  	inner join trninvoicetomemberdetails_frproforma b on a.memberinvoicesid = b.memberinvoicesid
					inner join mstclients c on b.billed_membercompanyid = c.clientcompanyid
              	inner join user_company d on a.billing_membercompanyid=d.membercompanyid
             	where x.memberid = $G_memberid and quotes_proforma_invoice = 0 and a.memberinvoicesid = $memberinvoicesid";
		$querylist = $obj_invoice ->getInvoice('',$query);
	if(is_array($querylist))
	{
		$rowcount = count($querylist);
	}
	
for($i=0;$i<$rowcount;$i++){
			
				 $counter++;
			$memberid										= $G_memberid;
			$memberinvoicesid								= 	$memberinvoicesid;	
			$billed_membercompanyid						=	$querylist[$i]['billed_membercompanyid'];
			$billing_membercompanyid					= $billing_membercompanyid_proforma;
			$billed_membername 							= $querylist[$i]['billed_membername'];
			$InvoiceBaseAmountBeforeDiscount       = $querylist[$i]['InvoiceBaseAmountBeforeDiscount'];
			$inv_Add1										= $querylist[$i]['inv_Add1'];
			$inv_Add2										= $querylist[$i]['inv_Add2'];
			$inv_Add3										= $querylist[$i]['inv_Add3'];
			$inv_Add4										= $querylist[$i]['inv_Add4'];
			$address                        			= $querylist[$i]['inv_Add1'].'</br>'.$querylist[$i]['inv_Add2'].'</br>'.$querylist[$i]['inv_CityName'].' '.$querylist[$i]['inv_Pin'];
			$panno											= $querylist[$i]['panno'];
			$gstno											= $querylist[$i]['gstno'];
			$quotes_proforma_invoice					=	0;
			$inv_CityName 									= $querylist[$i]['inv_CityName'];
			$inv_Pin 										= $querylist[$i]['inv_Pin'];
			$inv_StateName 								= $querylist[$i]['inv_StateName'];
			$inv_head_Stateid								= $querylist[$i]['inv_head_Stateid'];
			$invoiceno 										= $querylist[$i]['invoiceno'];
			$invoicedate									= date('d-m-Y',strtotime($querylist[$i]['invoicedate']));
			$duedate											= $querylist[$i]['duedate'];
			$statusdata 											= $querylist[$i]['status'];
		
			$igst_percentage								= $querylist[$i]['igst_percentage'];
			$igst_amount									= $querylist[$i]['igst_amount'];
			$cgst_percentage								= $querylist[$i]['cgst_percentage'];
			$cgst_amount									= $querylist[$i]['cgst_amount'];
			$sgst_percentage								= $querylist[$i]['sgst_percentage'];
			$sgst_amount									= $querylist[$i]['sgst_amount'];
			$ugst_percentage								= $querylist[$i]['ugst_percentage'];
			$ugst_amount									= $querylist[$i]['ugst_amount'];
			$discount_percentage							= $querylist[$i]['discount_percentage'];
			$discount_amount								= number_format($querylist[$i]['discount_amount']);
			$InvoiceBaseAmountBeforeDiscount			= $querylist[$i]['InvoiceBaseAmountBeforeDiscount'];
			$InvoiceBaseAmount							= number_format($querylist[$i]['InvoiceBaseAmount']);
			$InvoiceTotalAmount							= number_format($querylist[$i]['InvoiceTotalAmount']);
			$InvoiceTotalAmount1							= $querylist[$i]['InvoiceTotalAmount'];
			$quantity										= $querylist[$i]['quantity'];
		  $itemno 						=	$querylist[$i]['itemno'];
  $igst_amount_product						=	$querylist[$i]['igst_amount_product'];
  $cgst_amount_product						=	$querylist[$i]['cgst_amount_product'];
  $sgst_amount_product						=	$querylist[$i]['sgst_amount_product'];
	
			$discount_amount								= $querylist[$i]['discount_amount'];
		//	$price											= $querylist[$i]['InvoiceTotalAmount'];
			$ProductBaseAmount							= number_format($querylist[$i]['ProductBaseAmount']);
			$ProductTotalAmount							= number_format($querylist[$i]['ProductTotalAmount']);
			$productname									= $querylist[$i]['productname'];
			//$product_description								= str_replace(' ', "\n", $querylist[$i]['product_description']);
			$product_description								= $querylist[$i]['product_description'];
			$product_unit									= $querylist[$i]['product_unit'];
			$inv_GST_no										= $querylist[$i]['inv_GST_no'];
			$approved							=$sqllist[$i]['approved'];
         		$balance 							= $InvoiceTotalAmount - $TotalAmount;
         		$todays = (date("d-m-Y")) ;
         if($statusdata == '0')
         		{
							$status = 'Draft';         		         		
         		}
         		elseif($statusdata == '1')
         		{
							$status = 'Approved';         		
         		}    		
         		elseif($statusdata == '2')
         		{
         				$status = 'Rejected';         		
         		}
         		
         			$j = $i+1;
				
					$trndetails .='<tr id="txtdisplay_1">
									<td width="1%"><input type="checkbox" class="case"></td>
									
									<td style="text-align: center;"><span id="snum" >'.($j).'</span></td>
									
									<td><input type="text"  name="txtitemno_display1[]" value="'.$itemno.'" data-type="itemno" id="txtitemno_display_1" class="form-control autocomplete_txt data_display" autocomplete="off"></td>
									
									<td><input type="text" name="txtitemname_display1[]" value="'.$productname.'" data-type="productname" id="txtitemname_display_1" class="form-control autocomplete_txt" autocomplete="off"></td>
									
									<td><input type="text" name="txthsncode_display1[]" value="'.$hsn_code.'" id="txthsncode_display_1" class="form-control" autocomplete="off"></td>
									
									<td><input type="text" name="txtitemprice_display1[]" value="'.$ProductBaseAmount.'" id="txtitemprice_display_1" class="form-control autooriginalprice_display " autocomplete="off"></td>
									
									<td><input type="text" name="txtcgst_display1[]" value="'.$cgst_amount_product.'" id="txtcgst_display_1" class="form-control" autocomplete="off"><input type="hidden"  id="txtcgst_hidden_display_1" class="form-control autocgst_display" ></td>
									
									<td><input type="text" name="txtsgst_display1[]" value="'.$sgst_amount_product.'" id="txtsgst_display_1" class="form-control" autocomplete="off"><input type="hidden"  id="txtsgst_hidden_display_1" class="form-control autosgst_display"></td>
									
									<td><input type="text" name="txtigst_display1[]" value="'.$igst_amount_product.'" id="txtigst_display_1" class="form-control " autocomplete="off"><input type="hidden" id="txtigst_hidden_display_1" class="form-control autoigst_display"></td>
									
								 	<td><input type="text" name="txtitemquantity_display1[]" value="'.$quantity.'" data-type="itemno" id="txtitemquantity_display_1" class="form-control  autocomplete_quantity"  autocomplete="off"></td>
									<td><input type="text" name="txtitemsubtotal_display1[]" value="'.$ProductTotalAmount.'" id="txtitemsubtotal_display_1" class="form-control  autototal_display" autocomplete="off" style="text-align: right;"></td>
									</tr>';

		
		}
		


		
	require_once("header1.html");
	require_once("leftnav.html");
	require_once("Proforma-details1.html");
	require_once("footer1.html");


}
else if (!headers_sent($filename, $linenum)) 
{
				$redirect_url = DOC_ROOT."login.php";
				header("Location: $redirect_url");
    			exit;
					// You would most likely trigger an error here.
}
else 
{
				echo "Headers already sent in $filename on line $linenum\n" .
          			"Cannot redirect, for now please click this <a ";
    			exit;
}   
	
?>
