<?php
	$this->mypdf_class->tcpdf();

	global $cm_data_pdf;
	global $ct_data_pdf;
	global $yy;
	global $inc;

	$cm_data_pdf = $cm_data;
	$ct_data_pdf = $ct_data;
	$inc = 1;

	class MYPDF extends TCPDF 
	{
		public function Header()
		{
			global $cm_data_pdf;
			$tbl_header 	= "";
			$customer		= $cm_data_pdf[0]['customer'] == '' ? '-' : strtoupper($cm_data_pdf[0]['customer']);
			$customer_gst	= $cm_data_pdf[0]['customer_gst'] == '' ? '' : '('.strtoupper($cm_data_pdf[0]['customer_gst']).')';
			$customer_mobile= $cm_data_pdf[0]['customer_mobile'] == '' ? '' : '-'.strtoupper($cm_data_pdf[0]['customer_mobile']);
			$broker			= $cm_data_pdf[0]['broker'] == '' ? '-' : strtoupper($cm_data_pdf[0]['broker']);			
			$broker_pan		= $cm_data_pdf[0]['broker_pan'] == '' ? '' : '('.strtoupper($cm_data_pdf[0]['broker_pan']).')';			
			$broker_mobile	= $cm_data_pdf[0]['broker_mobile'] == '' ? '' : '-'.strtoupper($cm_data_pdf[0]['broker_mobile']);			
			$through		= strtoupper($cm_data_pdf[0]['cm_through']);			

			$entry_no		= $cm_data_pdf[0]['cm_entry_no'];
			$entry_date		= date('d-m-Y', strtotime($cm_data_pdf[0]['cm_entry_date']));
			$entry_time		= date('h:i a');
			$image      	= assets('img/kavan.png');
			$logo      		= assets('img/logo.jpg');
			

			$this->SetFont('Times', '', 8);
			$tbl_header .= <<<EOD
				<table style="border-bottom:1px dashed black;">
					<tr>
						<td align="left" width="30%">
							<table border="0" cellpadding="8">
								<tr>
									<td>
										<u><b>REG. OFFICE ADD:- </b></u>
										<br>313, RUSHABH APARTMENTS 
										<br>PRARTHANA SAMAJ, MUMBAI - 400 004
										<br><b>TEL</b>   : 42952258 / 26755090.
										<br><b>QBC</b>   : 3125/ 7271,
										<br><b>Mob</b>   : 9819920081/ 9819920084,
										<br><b>Email</b> : ruchir@live.in										
									</td>												
								</tr>					
							</table>
						</td>
						<td align="center" width="40%">
							<table border="0" cellpadding="1">
								<tr>
									<td>
										<img src="$logo" style="width:500%;height:400%;" />
									</td>												
								</tr>					
								<tr>
									<td>
										<table border="0" cellpadding="1">
											<tr>
												<td width="50%">
													<img src="$image" style="width:600%;height:600%;" />		
												</td>
												<td width="50%">
													<b style="font-size:20px;">KAVAN EXPORTS</b>
												</td>
											</tr>
										</table>
									</td>
								</tr>
								<tr>
									<td>
										<u style="font-size:12px;">DELIVERY CHALLAN</u>
									</td>
								</tr>
							</table>
						</td>	
						<td align="right" width="30%">
							<table border="0" cellpadding="8">
								<tr>
									<td align="left" style="font-size:10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<u ><b>CORRESPONDENCE ADD:- </b></u>
										<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JW-7030, 7TH FLOOR,
										<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BHARAT DIAMOND BOURSE,
										<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BANDRA KURLA COMPLEX,
										<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BANDRA - EAST,
										<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MUMBAI - 400 051
										<b>
										<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GST NO  
										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- 27AANHR3053F1Z1							
										<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSN CODE &nbsp;- 71023910							
										</b>
									</td>												
								</tr>			
							</table>
						</td>							
					</tr>					
				</table>

EOD;
			$tbl_header .= <<<EOD
				<table border="0" cellpadding="0" cellspacing="2" style="font-size:11px;">
					<tr>
						<td width="80%" align="left">
							&nbsp;&nbsp;<b>Party,</b>&nbsp;&nbsp;&nbsp;<u>$customer $customer_mobile $customer_gst</u>
						</td>												
						<td width="20%" align="left">
							<b>J.No:-</b>&nbsp;&nbsp;&nbsp;<u>$entry_no</u>
						</td>												
					</tr>					
					<tr>
						<td width="80%" align="left">
							&nbsp;&nbsp;<b>Broker</b>&nbsp;&nbsp;&nbsp;<u>$broker $broker_mobile $broker_pan</u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;							
							&nbsp;&nbsp;<b>Through</b>&nbsp;&nbsp;&nbsp;<u>$through</u>
						</td>												
						<td width="20%" align="left">
							<b>Date:-</b>&nbsp;&nbsp;&nbsp;<u>$entry_date</u>
						</td>												
					</tr>					
					<tr>
						<td width="80%" align="left">
							&nbsp;&nbsp;Dear Sir,
						</td>												
						<td width="20%" align="left">
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<u>$entry_time</u>
						</td>												
					</tr>					
					<tr>
						<td width="80%" align="left">
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							Please receive the following cut & Polished Diamonds on approval for Import sales & Import assortment.
						</td>												
						<td width="20%" align="left">						
						</td>												
					</tr>					
				</table>	

				<table border="1">
					<tr>
						<td width="5%" align="center"><br>SR No</td>
						<td width="9%" align="center"><br>Stock ID</td>
						<td width="6%" align="center"><br>Shape</td>
						<td width="6%" align="center"><br>Weight</td>						
						<td width="6%" align="center"><br>Color</td>						
						<td width="6%" align="center"><br>Clarity</td>						
						<td width="6%" align="center"><br>Cut</td>						
						<td width="6%" align="center"><br>Pol</td>						
						<td width="6%" align="center"><br>Sym</td>						
						<td width="6%" align="center"><br>Flor</td>						
						<td width="6%" align="center"><br>Lab</td>						
						<td width="7%" align="center"><br>Discount</td>						
						<td width="9%" align="center"><br>Rapaport ($)</td>						
						<td width="16%" align="center"><br>Remarks</td>						
					</tr>				
				</table>							
EOD;
			$this->writeHTMLCell(199, 139, 4, 4, $tbl_header, 1, 0, 0, true, 'L', true);
			// $this->SetTopMargin(3);	
			$yy = $this->GetY();
			$yy = $yy + 55;
			$this->line(14,$yy,14,101);
			$this->line(31.9,$yy,31.9,101);
			$this->line(43.8,$yy,43.8,101);
			$this->line(55.7,$yy,55.7,101);
			$this->line(67.6,$yy,67.6,101);
			$this->line(79.6,$yy,79.6,101);
			$this->line(91.5,$yy,91.5,101);
			$this->line(103.5,$yy,103.5,101);
			$this->line(115.5,$yy,115.5,101);
			$this->line(127.4,$yy,127.4,101);
			$this->line(139.3,$yy,139.3,101);
			$this->line(153.2,$yy,153.2,101);			
			$this->line(171.1,$yy,171.1,101);			
			
			
			$this->SetTopMargin($yy + 4);
		}

		public function Footer() 
    	{
    		global $cm_data_pdf;
    		global $ct_data_pdf;
    		global $inc;
    		$cnt = count($ct_data_pdf)/10+1;
    		$cnt = explode('.', $cnt);
    		// echo "<pre>"; print_r($cnt);exit();
    		$cnt = $cnt[0];
    		$cnt1 = $cnt + $cnt;
    		$tbl_footer = "";   	
    		$total_qty 	= $cm_data_pdf[0]['cm_total_qty'];
    		$total_amt 	= round($cm_data_pdf[0]['cm_total_amt']);
    		$words		= number_to_word($total_amt);
    		$total_weight = 0;
    		if($inc == $cnt || $inc == $cnt1)
    		{
    			foreach ($ct_data_pdf as $key => $value) 
				{
					$total_weight = $total_weight + $value['dm_wt'];
					$total_weight1 = number_format($total_weight, 2);
				}
				$tbl_footer .= <<<EOD
    			<table style="border-top:1px solid black;" cellpadding="3">
    				<tr>
    				<td style="border:1px solid black;"> 
    					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b style="font-size:9px;">$total_weight1  </b>
					</td>
    				</tr>
					<tr>					
						<td width="80%">
							<b style="font-size:8px;">
							ACKNOWLEDGEMENT OF ENTRUSTMENT
							</b>
							
							<br>
							<small>
								We hereby entrust to you the following goods for manufacturing/ inspection on approval basis with the following conditions
								<br>
								&nbsp;
								1. The goods remain our property
								<br>
								&nbsp;
								2. You will not sale or pledge or mortgage the said goods or otherwise deal with them in any manner which is prejudicial to our rights.
								<br>
								&nbsp;
								3. The goods will be returned to us forthwith on demand
								<br>
								&nbsp;
								4. The goods will be held while in your custody at your risk in all aspects
								<br>
								&nbsp;
								5. You will be responsible for the said goods in the same condition in which it was given to you or polished if it was given for manufacturing as per particular description
								<br>
								&nbsp;
								6. Subject to MUMBAI JURISDICTION.
							</small>
						</td>
						<td width="20%">
							<br>
							<br>
							<br>
							<br>
							<b>For Kavan Exports</b>
						</td>
					</tr>	
					<tr>
						<td></td>
					</tr>
					<tr>
						<td width="40%" align="center">
							------------------------------------
							<br>
							<b style="font-size:8px;">Reciever Signature</b>
						</td>
						<td width="40%" align="left">
							------------------------------------
							<br>
							<b style="font-size:8px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Through Sign</b>
						</td>
						<td width="20%"></td>
					</tr>												
				</table>										
EOD;
    		}
    		else
    		{
    			$tbl_footer .= <<<EOD
    			<table style="border-top:1px solid black;" cellpadding="3">
    				<tr>
    				<td style="border:1px solid black;">   </td>
    				</tr>
					<tr>					
						<td width="80%">
							<b style="font-size:8px;">
							ACKNOWLEDGEMENT OF ENTRUSTMENT
							</b>
							
							<br>
							<small>
								We hereby entrust to you the following goods for manufacturing/ inspection on approval basis with the following conditions
								<br>
								&nbsp;
								1. The goods remain our property
								<br>
								&nbsp;
								2. You will not sale or pledge or mortgage the said goods or otherwise deal with them in any manner which is prejudicial to our rights.
								<br>
								&nbsp;
								3. The goods will be returned to us forthwith on demand
								<br>
								&nbsp;
								4. The goods will be held while in your custody at your risk in all aspects
								<br>
								&nbsp;
								5. You will be responsible for the said goods in the same condition in which it was given to you or polished if it was given for manufacturing as per particular description
								<br>
								&nbsp;
								6. Subject to MUMBAI JURISDICTION.
							</small>
						</td>
						<td width="20%">
							<br>
							<br>
							<br>
							<br>
							<b>For Kavan Exports</b>
						</td>
					</tr>	
					<tr>
						<td></td>
					</tr>
					<tr>
						<td width="40%" align="center">
							------------------------------------
							<br>
							<b style="font-size:8px;">Reciever Signature</b>
						</td>
						<td width="40%" align="left">
							------------------------------------
							<br>
							<b style="font-size:8px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Through Sign</b>
						</td>
						<td width="20%"></td>
					</tr>												
				</table>										
EOD;
    		}
    		
    		
		  	$this->writeHTMLCell(199, 139, 4, 101, $tbl_footer, 0, 0, 0, true, 'L', true);
        	// Set font
        	$this->SetFont('helvetica', 'I', 6);
        	// $this->startPageGroup();
        	// Page number
        	$this->Cell(1, 60, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
        	$inc++;
    	}
	}

	// create new PDF document
	$pdf = new MYPDF('L', PDF_UNIT, array(148, 210), true, 'UTF-8', false);
	// set document information
	$pdf->SetCreator(PDF_CREATOR);
	$pdf->SetAuthor('Imran Khan');
	$pdf->SetTitle('JANGAD ISSUE Pdf');
	$pdf->SetSubject('JANGAD ISSUE Pdf');

	// set default header data
	$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

	// set header and footer fonts
	$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
	$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

	// set default monospaced font
	$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

	// set margins
	$pdf->SetMargins(8, 50, 5);
	$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
	$pdf->SetFooterMargin(50);

	// set auto page breaks
	$pdf->SetAutoPageBreak(TRUE, 45);

	// set image scale factor
	$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

	// set some language-dependent strings (optional)
	if (@file_exists(dirname(__FILE__).'/lang/eng.php')) 
	{
	    require_once(dirname(__FILE__).'/lang/eng.php');
	    $pdf->setLanguageArray($l);
	}


	$pdf->SetFont('Helvetica', '', 7.5);
	$tbl = "";
	
	$pdf->AddPage('L');

	$tbl .= <<<EOD
			<table cellpadding="1">
EOD;
			$total_weight = 0;
			foreach ($ct_data_pdf as $key => $value) 
			{
				$sr_no 		= $key + 1;
				$code 		= strtoupper($value['dm_code']);
				$sh 		= strtoupper($value['dm_sh']);
				$wt 		= strtoupper($value['dm_wt']);
				$col 		= strtoupper($value['dm_col']);
				$cla 		= strtoupper($value['dm_cla']);
				$cut 		= strtoupper($value['dm_cut']);
				$pol 		= strtoupper($value['dm_pol']);
				$sym 		= strtoupper($value['dm_sym']);
				$fl 		= strtoupper($value['dm_fl']);
				$lab 		= strtoupper($value['dm_lab']);
				$disc 		= strtoupper($value['dm_disc']);
				$rap 		= strtoupper($value['dm_rap']);
				$total_weight = $total_weight + $value['dm_wt'];
				
				$tbl .= <<<EOD
					<tr>
						<td width="5%" align="left" >$sr_no</td>
						<td width="9%" align="left">$code</td>
						<td width="6%" align="left">$sh</td>
						<td width="6%" align="left">$wt</td>						
						<td width="6%" align="left">$col</td>						
						<td width="6%" align="left">$cla</td>						
						<td width="6%" align="left">$cut</td>						
						<td width="6%" align="left">$pol</td>						
						<td width="6%" align="left">$sym</td>						
						<td width="6%" align="left">$fl</td>						
						<td width="6%" align="left">$lab</td>						
						<td width="7%" align="left">$disc</td>						
						<td width="6%" align="right">$rap</td>						
						<td width="16%" align="left"></td>						
					</tr>					
EOD;
			}

	$tbl .= <<<EOD
				</table>
EOD;
	$pdf->writeHTML($tbl, true, false, false, false, '');

$tbl = "";
	
	$pdf->AddPage('L');
	
	$tbl .= <<<EOD
			<table>
EOD;
			$total_weight = 0;
			foreach ($ct_data_pdf as $key => $value) 
			{
				$sr_no 		= $key + 1;
				$code 		= strtoupper($value['dm_code']);
				$sh 		= strtoupper($value['dm_sh']);
				$wt 		= strtoupper($value['dm_wt']);
				$col 		= strtoupper($value['dm_col']);
				$cla 		= strtoupper($value['dm_cla']);
				$cut 		= strtoupper($value['dm_cut']);
				$pol 		= strtoupper($value['dm_pol']);
				$sym 		= strtoupper($value['dm_sym']);
				$fl 		= strtoupper($value['dm_fl']);
				$lab 		= strtoupper($value['dm_lab']);
				$disc 		= strtoupper($value['dm_disc']);
				$rap 		= strtoupper($value['dm_rap']);

				$total_weight = $total_weight + $value['dm_wt'];
				
				$tbl .= <<<EOD
					<tr>
						<td width="5%" align="left" >$sr_no</td>
						<td width="9%" align="left">$code</td>
						<td width="6%" align="left">$sh</td>
						<td width="6%" align="left">$wt</td>						
						<td width="6%" align="left">$col</td>						
						<td width="6%" align="left">$cla</td>						
						<td width="6%" align="left">$cut</td>						
						<td width="6%" align="left">$pol</td>						
						<td width="6%" align="left">$sym</td>						
						<td width="6%" align="left">$fl</td>						
						<td width="6%" align="left">$lab</td>						
						<td width="7%" align="left">$disc</td>						
						<td width="6%" align="right">$rap</td>						
						<td width="16%" align="left"></td>						
					</tr>					
EOD;
			}

	$tbl .= <<<EOD
				</table>
EOD;
	$pdf->writeHTML($tbl, true, false, false, false, '');	
	
	// $pdf->writeHTMLCell(188, 150, 6, 134, $tbl, 0, 0, 0, true, 'P', true);
	$pdf->IncludeJS("print();");
	// ---------------------------------------------------------

	//Close and output PDF document
	ob_end_clean();
	$pdf->Output('JANGAD ISSUE.pdf', 'I');
	//============================================================+
	// END OF FILE
	//============================================================+
