<!DOCTYPE html>
<html>
    <head>
        <title>Delivery List</title>
        <style>
            /*@page {
                            margin-top: 5.6cm;
                            margin-bottom: 3.5cm;
                            margin-left: 1cm;
                            margin-right: 1cm;
                            header: html_myHeader;
                            header: html_otherpages;
                            font-family:'Times New Roman';
                        }
            @page :first {
                            margin-top: 5.6cm;
                            margin-bottom: 3.5cm;
                            margin-left: 1cm;
                            margin-right: 1cm;
                            header: html_firstpage;
                            footer: html_firstfooter;
                        }*/
            @page {
                margin-top: 7.3cm;
                margin-bottom: 1cm;
                margin-left: 1cm;
                margin-right: 1cm;
                header: html_myHeader;
                header: html_otherpages;
                footer: html_firstfooter;
                font-family:'Times New Roman';
            }
            @page :first {
                margin-top: 0.5cm;
                margin-bottom: 2cm;
                header: html_firstpage;
                footer: html_firstfooter;
            }
            @page :last {
                footer: html_lastfooter;
            }
        </style>    
    </head>
    <?php
    if (isset(Yii::app()->user->pdf_company_logo)) {
        $logo_name = Yii::app()->user->pdf_company_logo;
    } else {
        $logo_name = "pdf_logo.png";
    }
    $model_Delivery = DeliveryNote::model()->findByPk($id);
    ?>
    <body style="font-family: 'Times New Roman' Times serif">
          <div class="main" >
            <?php $this->renderPartial("//common/header");?>
                </div> 
                <div class="col-4">
                    <div class="input-block">
                        <b>Voucher NO:<?php echo $id; ?></b>
                    </div>
                    <b><?php echo $model_Delivery->customer->customer_name; ?></b>
                    <br>  <?php if ($model_Delivery->customer->customer_address != '') { ?>       
                        <small><?php echo strtoupper(nl2br($model_Delivery->customer->customer_address)); ?></small>
<?php } ?>
                    <br><?php if ($model_Delivery->customer->customer_phone_no != '') { ?>        
                        <small>Phone : <?php echo strtoupper($model_Delivery->customer->customer_phone_no); ?></small><br>
<?php } ?>   
                </div>
                <div class="col-4">
                    <div class="h3" style="margin-top: 0;margin-bottom: 0;color: #000000;font-size: 14px;text-align:center;">
                    <?php echo "DELIVERY NOTE"; ?>
                    </div> 
                    <div style="width:100%;font-family:'Times New Roman', Times, serif;font-style:italic; margin-bottom:2cm;text-align:center;"> ---- Page 1 ----</div> 
                </div>
                <div class="col-4" style="color:#101010;">
                    <table class="table" style="width:50%" style="font-size:13px;margin-top: 15px;">
                        <tr>
<?php
$model_lead = Lead::model()->find(array('condition' => 'file_id="' . $model_Delivery->file_id . '"'));
?>
                               <!-- <td class="bc-tl">File ID</td>
                                <td>
                            <?php //echo $model_Delivery->file_id;?>
                                </td>-->
                        </tr>
                        <tr>
                            <td>Order No (if any)</td>
                            <td>
                        <?php echo $model_order->id; ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Invoice NO</td>
                            <td>
                            <?php echo $model_in->invoice_id; ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Delivery Date</td>
                            <td>
                                <?php echo date("d/m/Y", strtotime($model_Delivery->delivery_date)); ?>
                            </td>
                        </tr>
                        <?php
                                if (isset($model_lead->leadowner->first_name) && $model_lead->leadowner->first_name != "") {
                                    ?>
                            <tr>
                                <td colspan="2">
                            <?php echo $model_lead->leadowner->first_name . ' ' . $model_lead->leadowner->last_name . ' , ' . $model_lead->leadowner->phno; ?>
                                </td>
                            </tr>
                        <?php }
                        ?>
                    </table>
                </div>
            </div>
        </div>

        <div class="col-md-12">
            <table id="" class="table" style="font-size:13px;margin-bottom: 5px;">
                <thead>
                    <tr>
                        <th class="text-left" style="width:5%">No</th>
                        <th class="text-center" style="width:25%">Part No</th>
                        <!--<th class="text-center" style="width:25%">Description</th>-->
                        <th class="text-center" style="width:5%">Ord. Qty</th>
<?php if ($bonus_quantity == "Y") { ?>
                            <th class="text-center" style="width:4%">Ord. Bonus Qty</th>                     
<?php } ?>
                        <th class="text-center" style="width:5%">Unit</th>
                        <th class="text-center" style="width:15%">Delivery Qty</th>
<?php if ($bonus_quantity == "Y") { ?>
                            <th class="text-center" style="width:4%">Del. Bonus Qty</th>                     
                        <?php } ?>

                    </tr>
                </thead>
                <tbody>

                        <?php
                        $m = 1;
                        $condition .= '1=1';
                        $condition .= ' AND t.delivery_note_id ="' . $id . '"';
                        $total = 0;

                        $total_cbm = 0;
                        $total_weight = 0;
                        $j = 1;
                        $count_alternate_ids = DeliveryNoteItem::model()->count(array('condition' => 'alternate_id!="" AND t.delivery_note_id ="' . $id . '"'));
                        if ($count_alternate_ids > 0) {
                            $order_by = 'alternate_id ASC';
                        } else {
                            $order_by = 'id ASC';
                        }
                        $model_DeliveryItems = DeliveryNoteItem::model()->findAll(array('condition' => $condition, 'order' => $order_by));
                        foreach ($model_DeliveryItems as $i => $each_DeliveryItem) {
                            ?>

                        <?php
                        if ($each_DeliveryItem->picked_qty > 0 || $each_DeliveryItem->picked_bonus_qty > 0) {
                            $sl_no = '';
                            $batch_no = '';
                            ?>
                            <tr <?php echo ( $each_DeliveryItem->product->inventory_item_type == '2' ) ? 'style="color:red;"' : ''; ?>>
                                <td>
                            <?php
                            if ($count_alternate_ids > 0) {
                                echo $each_DeliveryItem->alternate_id;
                            } else {
                                echo $j;
                            }
                            ?>
                                </td>
                                <td>
                                    <?php echo $each_DeliveryItem->product->part_number; ?>
                                </td>
                                <!--<td>
                                    <?php //echo nl2br($each_DeliveryItem->description);?>
                                </td>-->

                                <td class="text-right">
                                    <?php echo Yii::app()->numberFormatter->formatCurrency($each_DeliveryItem->quantity, " "); ?>
                                </td>
                                    <?php if ($bonus_quantity == "Y") { ?>
                                    <td class="text-right">
            <?php echo Yii::app()->numberFormatter->formatCurrency($each_DeliveryItem->bonus_qty, " "); ?>
                                    </td>
                                <?php } ?>
                                <td class="text-center">
        <?php echo $each_DeliveryItem->unitdetails->name; //.'(1x'.$each_DeliveryItem->unitdetails->factor.')'; ?>
                                </td>
                                <td class="text-right">
                                <?php echo $each_DeliveryItem->picked_qty; ?>
                                </td>
                                    <?php if ($bonus_quantity == "Y") { ?>
                                    <td class="text-right">
                                    <?php //echo Yii::app()->numberFormatter->formatCurrency($each_DeliveryItem->picked_bonus_qty," "); ?>
                                    </td>
                                    <?php } ?>
                            </tr>

                                    <?php
                                    $j++;
                                    if ($each_DeliveryItem->unitdetails->name == 'CTN') {

                                        $item_cbm = $each_DeliveryItem->product->cubic_meter;
                                        $item_weight = $each_DeliveryItem->product->weight;
                                        $total_cbm += ($each_DeliveryItem->picked_qty * $item_cbm);
                                        $total_weight += ($each_DeliveryItem->picked_qty * $item_weight);
                                        $total_qty = $each_DeliveryItem->picked_qty;
                                        $tot_cartoons += $total_qty;
                                    }
                                }

                                //} 
                            }
                            ?>
                       <!--  <tr>
                            <td></td>
                            <td style="text-align:right !important;" colspan="4"><b>Total</b></td>
                            
                        </tr>  -->      

                </tbody>
            </table>

        </div>

      <!--  <div style="width: 100%;">
            <div style="width: 48%; height: 80px; float: left; border: 1px solid #1f67b2; padding: 5px;"> 
                <h5>Please ensure that all items are quoted in Carton</h5>
                <div class="h5sub-details" style="font-size: 13px;">Total CBM : <b><?php //echo $total_cbm; ?> </b>CBM</div>
                <div class="h5sub-details" style="font-size: 13px;">Total Weight : <b><?php //echo $total_weight; ?> </b>KG</div> 
                <div class="h5sub-details" style="font-size: 13px;">No. of Cartoons : <b><?php //echo $tot_cartoons; ?> </b></div> 
            </div>
            <div style="width: 48%; height: 80px; float: right; padding: 5px; border: 1px solid #1f67b2;"> 
                <h5></h5>
                <div  style="font-size: 13px;">Mark : <b>______________ </b></div><br>
                <div  style="font-size: 13px;">Delivery Area :<b>______________ </b></div>
            </div>
        </div>-->

<?php
if ($model_Delivery->terms_and_conditions != '') {
    ?>
            <h5>Terms and Conditions</h5>
            <div class="h5sub-details">
    <?php echo nl2br($model_Delivery->terms_and_conditions); ?>
            </div>
    <?php
}
?>

        <div style="width: 100%; height: 80px; border: 1px solid #1f67b2; margin-top: 5px;padding: 1px;"> 
            <div style="float:left; width: 40%;text-align: center;"> 
                <br>
                <br>
                ___________________________________________ <br>
                <span style="text-align: center;"><small>Received by/Contact Number</small></span>
            </div>
            <div style="width: 20%;"></div>
            <div style="width: 40%;float: right;text-align: center;"> 
                <br>
                _________________________________________ <br>
                <span style="text-align: center;"><small>Prepared By</small></span>
                <br>
                <br>
                _________________________________________ <br>
                <span style="text-align: center;"><small>Delivered By</small></span>
            </div>
        </div>

<?php
$model_Delivery = DeliveryNote::model()->findByPk($id);
$created_datetime = $model_Delivery->created_datetime;
?>
<?php $this->renderPartial("//common/footer",array('company_id'=>$company_id));?>
</body>

</html>