<!DOCTYPE html>
<html>
<?php
$crm_login_company_id = Yii::app()->user->master_user_company_id;
$privillage_modal = new MasCompanySettings();
$privillage_condition = 'crm_company_id=' . $crm_login_company_id;
$privillage_count = $privillage_modal->count(array('condition' => $privillage_condition));
$privillage_settings_module = $privillage_modal->find(array('condition' => $privillage_condition));
$master_permission = $privillage_settings_module->permissions;
$master_permission_array = json_decode($master_permission, true);
// $bonus_quantity = $privillage_settings_module->bonus_quantity;
?>

<head>
    <title>DELIVERY LIST</title>
</head>

<body>
    <div class="border-red">
        <?php
        $model_Delivery = DeliveryNote::model()->findByPk($id);

        ?>

        <!------===header section-->
        <div class="">
            <?php $this->renderPartial('//common/header'); ?>
            <div class="col-4">
                <div class="input-block">
                    <b><?php echo $id; ?></b>
                    <br>

                </div>
                <b><?php echo $model_Delivery->customer->customer_name; ?></b>
                <br> <?php if ($model_Delivery->billing_address != '') { ?>
                    <small><?php echo strtoupper(nl2br($model_Delivery->billing_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; text-align: center;">
                    <?php echo "DELIVERY NOTE"; ?>
                </div>
            </div>
            <div class="col-4" style="color:#101010;float:right;">
                <table class="table" style="width:100%">
                    <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 #</td>
                        <td>
                            <?php echo $model_Delivery->order_id; ?>
                        </td>
                    </tr>

                    <tr>
                        <td>Shipped By</td>
                        <td>
                            <?php echo $model_Delivery->shippedby->via; ?>
                        </td>
                    </tr>
                    <tr>
                        <td>Delivery Date</td>
                        <td>
                            <?php echo date('d/m/Y', STRTOTIME($model_Delivery->delivery_date)); ?>
                        </td>
                    </tr>
                    <tr>
                        <td>LPO</td>
                        <td>
                            <?php echo $model_Delivery->lpo; ?>
                        </td>
                    </tr>
                    <tr>
                        <td>Inco Terms</td>
                        <td>
                            <?php echo $model_Delivery->incoterm->inco_name; ?>
                        </td>
                    </tr>


                    <!-- <tr>
                    <td>Tracking No</td>
                    <td>
                          <?php //echo $model_Delivery->tracking_no; ?>
                    </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 class="input-block">

                    <barcode code="<?php echo $id; ?>" type="C39" height="0.66" size="1.2" />
                </div>
            </div>

        </div>

        <!------===header section-->

        <br>
        <div class="col-md-12">
            <table id="" class="table">
                <thead>
                    <tr>
                        <th class="text-left">No</th>
                        <th class="text-left">Part No</th>
                        <th class="text-left">Description</th>
                        <th class="text-center">Ord. Qty</th>
                        <?php if ($bonus_quantity == "Y") { ?>
                            <th class="text-center">Ord. Bonus Qty</th>
                        <?php } ?>
                        <th class="text-center">Unit</th>
                        <th class="text-center">Del. Qty</th>
                        <?php if ($bonus_quantity == "Y") { ?>
                            <th class="text-center">Del. Bonus Qty</th>
                        <?php } ?>

                    </tr>
                </thead>
                <tbody>

                    <?php
                    $m = 1;
                    $condition .= '1=1';
                    $condition .= ' AND t.delivery_note_id ="' . $id . '"';
                    $total = 0;
                    $j = 1;
                    $model_DeliveryItems = DeliveryNoteItem::model()->findAll(array('condition' => $condition, 'order' => 'id ASC'));
                    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 echo $j; ?>
                                </td>
                                <td>
                                    <?php echo $each_DeliveryItem->product->part_number; ?>
                                </td>
                                <td>
                                    <?php echo nl2br($each_DeliveryItem->description); ?>
                                    <?php if ($each_DeliveryItem->product->have_expiry_date == 'Y') {
                                        $batch_no = StockLedger::getBatchNo($id, $each_DeliveryItem->product_id, 'DELIVERY_NOTE');
                                        ?>
                                        <hr style="width:105%;">
                                        <br />
                                        Batch No:<?php echo $batch_no; ?>
                                    <?php } ?>
                                    <?php if ($each_DeliveryItem->product->have_serial_no == 'Y') {
                                        $sl_no = StockLedger::getSerialNo($id, $each_DeliveryItem->product_id, 'DELIVERY_NOTE');
                                        ?>
                                        <hr style="width:105%;">
                                        <br />
                                        Serial No:<?php echo $sl_no; ?>
                                    <?php } ?>
                                </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 Yii::app()->numberFormatter->formatCurrency($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++;
                        }

                        //} 
                    }
                    ?>


                </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 != '') {
            ?>
            <div class="box" style="width: 100%;">
                <h5>Terms and Conditions</h5>
                <div class="h5sub-details">
                    <?php echo nl2br($model_Delivery->terms_and_conditions); ?>
                </div>
            </div>
            <?php
        }
        ?>

        <div class="box" style="width: 100%; margin-bottom: 21rem;">
            <div class="col-12">
                <div class="row" style="margin-top: 1rem; margin-left: 2px;">
                    <h5>Acknowledge Receipt: Goods Received in Good Condition</h5>
                </div>
            </div><br><br>


            <div style="position:relative">

                <div style="float:left; width: 40%;text-align: center;">
                    ___________________________________________ <br>
                    <span style="text-align: center;"><small>Received By / Signature</small></span>
                </div>
                <div style="width: 20%;"></div>
                <div style="width: 40%;float: right;text-align: center;">
                    ___________________________________________ <br>
                    <span style="text-align: center;"><small>Prepared By / Signature</small></span>
                </div>
            </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)); ?>

    </div>
</body>

</html>