<!DOCTYPE html>
<html>
<head>
    <title>Invoice</title>
	<style type="text/css">
    .table td {
        border: 1px solid #1f67b2;
    }
	.table {
	border-collapse: collapse !important;
	font-size: 12px;
	color: #101010;
	width: 100%;
}
.table thead th{
	background: #e4e3e3;
	color: #000;
}
.table th,
.table td {
	border: 1px solid #000 !important;
	text-align: left;
	padding: 3px 6px; 
        background-color: white;
}
.table th.text-left,
.table td.text-left{
	text-align: left;
	text-align: left !important;
}
.table th.text-right,
.table td.text-right{
	text-align: right;
	text-align: right !important;
}
.table th.text-center,
.table td.text-center{
	text-align: center;
	text-align: center !important;
}
.table tbody tr:nth-child(even){
	background: #e4e3e3;
}
.table th.Table-Title,
.table td.Table-Title{
    padding:7px 6px !important;
    font-size:1.15rem;
    color:green;
    font-weight:500;
    text-transform:uppercase;
}
.table th.total,
.table td.total{
	background: #e4e3e3;
	color: #fff;
	font-size: 11px;
}
.border_top{
    border:2px solid #000;
}
</style>
</head>
<body style="font-family:open-sans">
    <?php
        $outbound = OutboundInvoice::model()->findByPk($id);
        $transport= array('1' => 'AIR', '2' => 'SEA', '3' => 'COURIER', '4' => 'LAND');
        $delivery = array(  '1' => array( 'name' => 'FOB', 'insurance' => 'COLLECT', 'freight' => 'COLLECT'),
                            '2' => array( 'name' => 'EX-WORKS', 'insurance' => 'COLLECT', 'freight' => 'COLLECT'),
                            '3' => array( 'name' => 'CIF', 'insurance' => 'PREPAID', 'freight' => 'PREPAID'),
                            '4' => array( 'name' => 'CFR', 'insurance' => 'COLLECT', 'freight' => 'PREPAID'),
                            '5' => array( 'name' => 'CPT', 'insurance' => 'COLLECT', 'freight' => 'PREPAID'),
                            '6' => array( 'name' => 'FCA', 'insurance' => 'COLLECT', 'freight' => 'COLLECT'),
                        );
    ?>
     <htmlpageheader name="myHeader">
<div class="">
    <div class="">
    <br>
        <div class="col-12" style="color:#101010;">
            <div class="text-left">
                <img src="<?php echo 'images/pdf/' . Yii::app()->user->pdf_company_logo; ?>" class="logo" style="height:28px;">
            </div>
        </div>
		<div class="col-4">
		    <div class="text-left">
                <h5><?php echo Yii::app()->user->company_name; ?></h5>
				<h6 style="font-weight:300;margin-top:-5px;margin-bottom:3px;"><?php echo Yii::app()->user->billing_address; ?></h6>
			</div>
		</div>
        <div class="col-4 text-center">
			   <h2>Invoice</h2>
			</div>
		<div class="col-4" style="margin-right:-30px;margin-top:20px;">
		    <div class="text-right">
			    <table class="table" style="width:100%">
				    <tr>

							<td class="bc-tl">Date</td>
							<td>
								<?php echo date('d/m/Y', strtotime($outbound->invoice_date)) ?>
							</td>
					</tr>
					<tr>

							<td class="bc-tl">Invoice No<br>&nbsp;</td>
							<td>
								<?php echo $outbound->invoice_no ?><br>&nbsp;
							</td>
					</tr>
					<!-- <tr>

							<td class="bc-tl">Container<br>&nbsp;</td>
							<td>
                                <?php //echo $outbound->containers(); ?><br>&nbsp;
							</td>
					</tr>
					<tr>

							<td class="bc-tl">Size</td>
							<td>
								&nbsp;
							</td>
					</tr> -->
                </table>
			</div>
		</div>
    </div> 
	<div class="col-md-12" style="margin-top:10px;">
	   <div class="col-4" style="float:left;">
	       <table class="table" border="1" style="text-align:left;width:100%; border-collapse: collapse;">
            <tbody>
                <tr>
                    <td class="text-left" style="font-size:11.5px;background-color:none;"><b>Buyer / Applicant</b></td>
                </tr>
				<tr>
                    <td height="20" class="text-left" style="font-size:11.5px;background-color:none;"><?php echo $outbound->customer->name ?></td>
                </tr>
				<tr>
                    <td height="70" class="text-left" style="font-size:11.5px;"><?php echo nl2br($outbound->customer->billing_adds); ?></td>
                </tr>
			</tbody>
		   </table>
	   </div>
	   <div class="col-4" style="float:right;">
	        <table class="table" border="1" style="text-align:left;width:100%; border-collapse: collapse;">
            <tbody>
                <tr>
                    <td class="text-left" style="font-size:11.5px;background-color:none;"><b>Consignee</td>
                </tr>
				<tr>
                    <td height="20" class="text-left" style="font-size:11.5px;background-color:none;"><?php echo $outbound->consignee_name ?></td>
                </tr>
				<tr>
                    <td height="70" class="text-left" style="font-size:11.5px;"><?php echo $outbound->consignee_address ?></td>
                </tr>
			</tbody>
		   </table>
	   </div>
    </div>
	</div>
    <div class="col-md-12" style="margin-top:10px;">
        <table border="1" style="border-collapse: collapse; text-align:center;width:100%;">
            <thead>
                <tr>
                    <th class="text-center" style="width:10%;font-size:10px;background-color:none;">From Port</th>
                    <th class="text-center" style="font-size:10px;background-color:none;">To Port</th>
                    <th class="text-center" style="width:13%;font-size:10px;background-color:none;">Shipment Mode</th>
                    <th class="text-center" style="width:10%;font-size:10px;background-color:none;">Agent / Line</th>
                    <th class="text-center" style="width:15%;font-size:10px;background-color:none;">Mode of Payment</th>
                    <th class="text-center" style="width:14%;font-size:10px;background-color:none;">Delivery Terms</th>
                    <th class="text-center" style="width:10%;font-size:10px;background-color:none;">Insurance</th>
                    <th class="text-center" style="width:10%;font-size:10px;background-color:none;">Freight</th>
                </tr>
            </thead>
            <tbody style="font-size: 10%;">
                <tr>
                    <td style="font-size:9px;"><?php echo $outbound->from_port; ?></td>
                    <td style="font-size:9px;"><?php echo $outbound->destination; ?></td>
                    <td style="font-size:9px;"><?php echo $transport[$outbound->mode_of_transport]; ?></td>
                    <td style="font-size:9px;"><?php if(!($outbound->agent == 'None')){ echo $outbound->agent; } ?></td>
                    <td style="font-size:9px;"><?php echo $outbound->payment_terms; ?></td>
                    <td style="font-size:9px;"><?php echo $delivery[$outbound->inco_terms]['name']; ?></td>
                    <td style="font-size:9px;"><?php echo $delivery[$outbound->inco_terms]['insurance']; ?></td>
                    <td style="text-align:center;font-size:9px;"><?php echo $delivery[$outbound->inco_terms]['freight']; ?></td>
                </tr>
            </tbody>
        </table>
    </div>
	<br>
    </htmlpageheader>
<sethtmlpageheader name="myHeader" page="ALL" value="1" show-this-page="1" />
	<div class="col-md-12">
        <table id="" class="table" style="border:1px solid #000; table-collapse:collapse !important;border-bottom:1px solid #000text-align:center;">
            <thead>
                <tr>
                    <th class="text-center" style="width:5%;background-color:none;color:#000;height:30px; padding-top:10px;">S.No</th>
                    <th class="text-center" style="width:10%;background-color:none;color:#000;height:30px;">GMC</th>
                    <th class="text-center" style="width:18%;background-color:none;color:#000;height:30px">Item No.</th>
                    <th class="text-center" style="font-size:12px;width:25%;background-color:none;color:#000;height:30px">Description</th>
                    <th class="text-center" style="width:12%;background-color:none;color:#000;height:30px">HS Code</th>
                    <th class="text-center" style="width:11%;background-color:none;color:#000;height:30px">COO</th>
                    <th class="text-center" style="width:7%;background-color:none;color:#000;height:30px;">Qty</th>
                    <th class="text-center" style="width:10%;background-color:none;color:#000;height:30p">Unit Price (<?php echo $outbound->currency ?>)</th>
					 <th class="text-center" style="width:14%;background-color:none;color:#000;height:30px;">Total (<?php echo $outbound->currency ?>)</th>
                </tr>
            </thead>
            <tbody>
                <?php 
                    $totalQty = 0;
                    $totalValue = 0;

                    $condition = 'OI.outb_quantity > 0 AND OI.invoice_id='. (int) $outbound->id;
                    if( trim($container) != '' ){
                        $condition .= ' AND OI.outb_container_no="'.$container.'"';
                    }

                    $query = 'SELECT *, ( net_value / outb_quantity ) AS rate FROM ( SELECT 
                                    OI.outb_part_number,
                                    IM.description,
                                    C.category_name,
                                    OI.outb_hs_code,
                                    CO.coo_name,
                                    SUM(OI.outb_quantity) AS outb_quantity,
                                    SUM( OI.outb_unit_price * OI.outb_quantity ) AS net_value
                                FROM 
                                    {{outbound_invoice_items}} OI 
                                LEFT JOIN {{item_master}} IM ON IM.part_number = OI.outb_part_number
                                LEFT JOIN {{mas_category}} C ON C.id = IM.category_id
                                LEFT JOIN {{coo_master}} CO ON CO.coo_code = OI.outb_contry_of_origin_code
                                WHERE '. $condition . 
                                ' GROUP BY OI.outb_part_number, OI.outb_contry_of_origin_code ) AS A ';

                    $items = Yii::app()->db->createCommand( $query )->queryAll();

                    if( $container != '' ){
                    ?>
                    <tr>
                        <td style="padding-top:10px;padding-bottom:10px;border:none;text-align:center;border-right:1px solid #000;" colspan="9" class="text-center">Container No : <?php echo $container; ?></td>
                    </tr>
                <?php } ?>
                <?php foreach( $items as  $i => $each ) :  
                            $netValue = $each['rate'] * $each['outb_quantity'];
                    ?>
                 <tr>
                    <td style="font-size:10px;padding-top:10px;padding-bottom:10px;border:none;border-bottom:1px solid grey;border-right:1px solid #000;border-left:1px solid #000;text-align:center;"><?php echo $i+1; ?></td>
                    <td style="font-size:10px;padding-top:10px;padding-bottom:10px;border:none;border-bottom:1px solid grey;text-align:center;border-right:1px solid #000"><?php echo $each['outb_part_number']; ?></td>
                    <td style="font-size:10px;padding-top:10px;padding-bottom:10px;border:none;border-bottom:1px solid grey;text-align:center;border-right:1px solid #000"><?php echo $each['description']; ?></td>
                    <td style="font-size:10px;padding-top:10px;padding-bottom:10px;border:none;border-bottom:1px solid grey;text-align:center;border-right:1px solid #000"><?php echo $each['category_name']; ?></td>
                    <td style="font-size:10px;padding-top:10px;padding-bottom:10px;border:none;border-bottom:1px solid grey;text-align:center;border-right:1px solid #000"><?php echo $each['outb_hs_code']; ?></td>
                    <td style="font-size:10px;padding-top:10px;padding-bottom:10px;border:none;border-bottom:1px solid grey;text-align:center;border-right:1px solid #000"><?php echo $each['coo_name']; ?></td>
                    <td style="font-size:10px;padding-top:10px;padding-bottom:10px;border:none;border-bottom:1px solid grey;text-align:center;border-right:1px solid #000" class="text-right"><?php echo  (float) $each['outb_quantity']; ?></td>
                    <td style="font-size:10px;padding-top:10px;padding-bottom:10px;border:none;border-bottom:1px solid grey;text-align:right;border-right:1px solid #000" class="text-right"><?php echo number_format($each['rate'], 2); ?></td>
					<td style="font-size:10px;padding-top:10px;padding-bottom:10px;border:none;border-bottom:1px solid grey;text-align:right;border-right:1px solid #000;" class="text-right"><?php echo number_format($netValue, 2); ?></td>
                </tr> 
                <?php 
                        $totalQty += $each['outb_quantity'];
                        $totalValue += $netValue;
                        endforeach; ?>

                 <tr>
                    <td  colspan="6" class="text-right" style="font-size:11px;"><b>Total</b></td>
					<td class="text-right" style="text-align:center;font-size:11px;"><b><?php echo $totalQty; ?></b></td>
                    <!--<td class="text-right"></td>-->
                    <td class="text-right" style="font-size:11px;" colspan="2"><b><?php echo $outbound->currency ?>&nbsp;<?php echo number_format($totalValue, 2);  //number_format($totalValue, 2); ?></b></td>
                 </tr>
                 <?php  $totalBotom = 0; ?>
                 <?php if( $show_freight=='true' &&  $outbound->freight_charge > 0 ) : 
                            $totalBotom += $outbound->freight_charge;
                    ?>
                    <tr>
                        <td colspan="6" class="text-right" style="font-size:11px;"><b>Freight</b></td>
                        <td class="text-right" colspan="3" style="font-size:11px;"><b><?php echo $outbound->currency ?>&nbsp;<?php echo number_format($outbound->freight_charge,2) //number_format($outbound->freight_charge, 3, '.', ''); ?></b></td>
                    </tr>
                <?php endif; ?>
                <?php if( $show_interest=='true' && $outbound->interest_charge > 0 ) : 
                            $totalBotom += $outbound->interest_charge;
                    ?>
                    <tr>
                        <td colspan="6" class="text-right" style="font-size:11px;"><b>Interest</b></td>
                        <td class="text-right" colspan="3" style="font-size:11px;"><b><?php echo $outbound->currency ?>&nbsp;<?php echo number_format($outbound->interest_charge,2) //number_format($outbound->interest_charge, 2, '.', ''); ?></b></td>
                    </tr>
                <?php endif; ?>
                <?php if( $totalBotom > 0 ) :  ?>
                    <tr>
                        <td colspan="6" class="text-right" style="font-size:11px;"><b>Grand Total</b></td>
                        <td class="text-right" colspan="3" style="font-size:11px;"><b><?php echo $outbound->currency ?>&nbsp;<?php echo number_format($totalValue + $totalBotom,2) //number_format(($totalValue + $totalBotom ), 2, '.', ''); ?></b></td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>

    </div>
<br>
	<div class="col-md-12" style="margin-bottom:5px;">
	    <table class="table">
		   <tr>
            <td style="height:18px;"></td>
		   </tr>
		</table> 
	</div>
	<div class="col-md-12">
	    <table class="table">
            <?php if( $outbound->invoice_note != '' ){  ?>
                <tr >
                    <td style="width:24%; height:26px; font-size:9px;"><b><u>DESCRIPTION OF GOODS :</u> </b></td>
                    <td style="text-transform: uppercase;font-size:9px;"><?php echo $outbound->invoice_note; ?></td>
                </tr>
            <?php } ?>
		   <tr>
		       <td style="width:24%;height:26px; font-size:9px;"><b><u>COUNTRY OF ORIGIN: </u> </b></td>
			   <td style="text-transform: uppercase;font-size:9px;"><?php echo $container == "" ? $outbound->country_origins_labels() : $outbound->country_origins_labels_container( $container ); ?></td>
		   </tr>
		</table>
	</div>
    <?php if( $outbound->customer->need_manufacure == 'Y' ){  ?>
        <div class="col-md-12" style="margin-bottom:0px;">
            <table class="table">
            <tr>
                <td><b><u>MANUFACTURERS FULL NAME & ADDRESS:</u><br>&nbsp;</b></td>
            </tr>
            <?php 
                $condition = $container != "" ?  'outb_container_no ="'.$container.'" AND invoice_id='.(int) $outbound->id  : 'invoice_id='.(int) $outbound->id;
                foreach( OutboundInvoiceItems::model()->findAll( array( 'select' => 'DISTINCT outb_contry_of_origin', 'condition' => $condition )) as $each ) : 
                        if( $each->outb_contry_of_origin != '') :

                            if( $each->outb_contry_of_origin == 'CN' && $outbound->currency == 'EUR' )
                                $each->outb_contry_of_origin = 'CNN';
                    ?>
                        <tr>
                            <td><?php echo strtoupper($each->coo->address); ?> </td>
                        </tr>
                        <?php endif; ?>
            <?php endforeach; ?>
            </table>
        </div>
    <?php } ?>
    <?php if( $outbound->remarks !='' ) : ?>
        <div class="col-md-12" style="margin-bottom:5px;">
            <table class="table">
            <tr>
                <td><b><u>REMARKS:</u><br>&nbsp;</b></td>
            </tr>
            <tr>
                    <td><?php echo $outbound->remarks; ?> </td>
                </tr>
            </table>
        </div>
    <?php endif;?><br>                        
    <div style="width:90%;text-align:right;position:absolute;bottom:70;">
       <h4>_____________________________</h4>           
       <h4>YAMAHA MUSIC GULF FZE</h4></div><htmlpagefooter name="myfooter">

                <div style="border-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px;">
                    <div style="text-align:center;width:100%">
                    </div>
                    <div style="text-align:center;width:100%">Page {PAGENO} of {nb} </div>
                </div>
            </htmlpagefooter>
        <sethtmlpagefooter name="myfooter" page="all" value="on" />
</body>
</html>
