<?php
$modelCredit = Creditnote::model()->findByPk($id);
?>
<!DOCTYPE html>
<html>

    <head>
        <title>CREDIT NOTE</title>
        <style>
            body{padding:0px!important;font-size:12px;}
            table{
                border-collapse: collapse;}
            .item_table {
                border-collapse: collapse;
                font-size:12px!important;
                margin:0px;
            }
            table.item_table,.item_table th,.item_table td {
                border: 1px solid black; 
                font-family:'Times New Roman', Times, serif;
                padding:1px;
            } 

            .second-colom{

                height:100px;

                border-bottom:1px solid;

                text-align:center;

                width:100%;

            }


            .nobdr_table, .nobdr_table td{ border:none!important;padding:0px!important}

        </style>
    </head>

    <body>

        <div class="">
            <?php if (Yii::app()->user->master_company_code == 'ARK') { ?>
                <div class="header" style="width:100%;float: left;padding-bottom:10px;">
                    <img src="images/arkheader.png"/>
                </div>
                <?php
            } else {
                ?>
                <div class="header" style="width:100%;float: left;border-bottom: 6px solid #850EA6;padding-bottom:10px;">

                    <div style="text-align:left; float:left; width:37%; font-family:'Times New Roman', Times, serif;"> 



                        <p style="margin:0px;padding:0px;font-size: 18px;"><span style="color:#b61f70;">ACE</span><span style="color:#0080e2;"> CENTRO </span><span style="color:#782a88;" > ENTERPRISES</span></p>

                        <div style="float:left;font-size:12px;line-height:16px;">

                            <p style="padding: 0px;margin:0px;float: left;">P. O. Box 95325, Abu Dhabi - U.A.E.</p>

                            <p style="padding: 0px;margin:0px;float: left;">TRN	:	100226227500003</p>

                            <p style="padding: 0px;margin:0px;float: left;">T	&nbsp;	&nbsp; &nbsp;: +971 2 6737900 </p>

                            <p style="padding: 0px;margin:0px;float: left;">F	&nbsp;	&nbsp; &nbsp;:	+971 2 6737800</p>

                            <p style="padding: 0px;margin:0px;float: left;">E	&nbsp;	&nbsp; &nbsp;:	info@acecentro.com</p>

                            <p style="padding: 0px;margin:0px;float: left;">W&nbsp;	&nbsp; &nbsp;:	www.acecentro.com </p>

                        </div>

                    </div>

                    <div style="text-align:center; float:left; width:30%;"> 

                        <img src="images/logo.png" style="margin-top:10px;height:110px;"/>

                    </div>

                    <div style="float:right; width:30%;"> 

                        <p style="text-align:right;margin:0px;padding:0px;font-size: 20px;"><span style="color:#b61f70;float:right;text-align:right;font-family:tahoma;">ايـــس</span><span style="color:#0080e2;float:right;text-align:right;font-family:tahoma;"> سينـتـرو </span><span style="color:#782a88;float:right;text-align:right;font-family:tahoma;" > للــمشـاريع</span></p>
                        <div style="float:left;font-size:12px;text-align:right;">
                            <p style="margin:0px;float: right;font-family:tahoma;">صندوق بريد 95325 ، أبو ظبي - الإمارات العربية المتحدةم.</p>
                            <p style="margin:0px;float: right;font-family:tahoma;">رقم التسجيل الضريبي : 100226227500003</p>
                            <p style="margin:0px;float: right;font-family:tahoma;">+971 2 6737900	:ت </p>

                            <p style="margin:0px;float: right;font-family:tahoma;">+971 2 6737800 : ف </p>

                            <p style="margin:0px;float: right;font-family:tahoma;">info@acecentro.com : لإ </p>

                            <p style="margin:0px;float: right;font-family:tahoma;">www.acecentro.com : إ    </p>

                        </div>

                    </div>

                </div>
                <?php
            }
            ?>
            <div  style="width:100%;float: left;margin-top: 10px;font-size:11px;font-family:'Times New Roman', Times, serif;"> 
                <div style="text-align:left; float:left; width:50%;" >
                    <htmlpageheader name="firstpage" style="display:none">
                    </htmlpageheader>

                    <htmlpageheader name="otherpages" style="display:none">
                        <div style="text-align:center; float:left; width:100%;font-family:'Times New Roman', Times, serif;font-style:italic;margin-bottom:10c.m;"> 

                            <img src="images/logo.png" style="height:90px;"/><br />
                            ---- Page {PAGENO} ----
                        </div>
                    </htmlpageheader>

                    <sethtmlpageheader name="firstpage" value="off" show-this-page="1" />
                    <sethtmlpageheader name="otherpages" value="on" />
                    <div style="float:left;">



                        <span style="font-weight:bold;padding-bottom: 6px;float: left;"><?php echo strtoupper($modelCredit->customer->customer_name); ?></span><br />

                        <span style="padding-bottom: 6px;float: left;"><?php
                            echo strtoupper(nl2br($modelCredit->invoice->billing_address));
                            ?> </span>
                        <table class="" style="width:100%">
                            <tr>
                                <td style="width: 120px">Tel</td>
                                <td style="width: 2px">:</td>
                                <td style="float: left;">
                                    <?php echo strtoupper($modelCredit->customer->customer_phone_no); ?>
                                </td>
                            </tr>
                            <tr>
                                <td>Fax</td>
                                <td>:</td>
                                <td>
                                    <?php echo strtoupper($modelCredit->customer->customer_fax); ?>
                                </td>
                            </tr>
                            <tr>
                                <td>TRN</td>
                                <td>:</td>
                                <td>
                                    <?php echo strtoupper($modelCredit->customer->customer_trn_no); ?>
                                </td>
                            </tr>
                            <!--tr>
                                <td>Kind Attn.</td>
                                    <td>:</td>
                                <td>
                            <?php //echo  strtoupper($modelCredit->customercontact->person_name);  ?>
                                </td>
                            </tr-->
                            <tr>
                                <td ><b>CREDIT NOTE #</b></td>
                                <td>:</td>
                                <td style="text-align:left;">
                                    <b><?php echo $modelCredit->id; ?></b>
                                </td>
                            </tr>
                        </table>  


                    </div>

                </div>

                <div style="text-align:right; float:right;padding-left: 60px; width:40%;" >

                    <table class="table" style="width:100%">
                        <tr>

                            <td class="bc-tl">File ID</td>
                            <td>
                                <?php echo $modelCredit->file_id; ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Customer ID</td>
                            <td>
                                <?php echo $modelCredit->customer_id; ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Credited Date</td>
                            <td>
                                <?php echo date('d/m/Y', STRTOTIME($modelCredit->credited_date)); ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Invoice No</td>
                            <td>
                                <?php echo $modelCredit->invoice_id; ?>
                            </td>
                        </tr>

                        <tr>
                            <td>Currency</td>
                            <td>
                                <?php
                                $modelCurrency = new MasCurrency();
                                $modelCurrency = $modelCurrency->getCurrencyDetails($modelCredit->currency);
                                echo $modelCurrency->currency_code;
                                if ($modelCurrency->currency_code != "AED") {
                                    echo "/" . $modelCredit->exchange_rate;
                                }
                                ?>
                            </td>
                        </tr>

                    </table>




                </div>

                <div style="float:right;margin-right: 30%; width:60%;padding: 5px 10px; border: 1px solid #7D26CD;border-radius: 4px;font-size:15px;margin-top:20px;margin-bottom:20px;width:270px;" align="center">
                    <b>TAX CREDIT NOTE</b>
                </div> 

            </div>

            <div class="col-md-12">
                <table id="" class="table">
                    <thead>
                        <tr>
                            <th class="text-center bc-tl" style="width:5%">No</th>
                            <th class="text-center" style="width:55%">Description</th>
                            <th class="text-center" style="width:10%">U,Price</th>
                            <th class="text-center" style="width:10%">Tax(%)</th>
                            <th class="text-center" style="width:10%">Tax Amount</th>   
                            <th class="text-center" style="width:10%">T.Price</th>   
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $modelCreditItems = CreditnoteItem::model()->findAll(array('condition' => 'creditnote_id = ' . $id . ' AND returned_quantity>0'));
                        $total = $total_vat = 0;
                        foreach ($modelCreditItems as $i => $modelCreditItems) {
                            ?>
                            <tr>
                                <td><?php echo $i + 1; ?></td>
                                <td><?php echo $modelCreditItems->description; ?></td>
                                <td class="text-right">
                                    <?php echo Yii::app()->numberFormatter->formatCurrency($modelCreditItems->rate, " "); ?>
                                </td> 
                                <td class="text-right">
                                    <?php echo (int) $modelCreditItems->tax_vat_percentage; ?>
                                </td>
                                <td class="text-right">
                                    <?php echo Yii::app()->numberFormatter->formatCurrency($modelCreditItems->tax_vat_amount, " "); ?>
                                </td>
                                <td class="text-right"><?php echo Yii::app()->numberFormatter->formatCurrency($modelCreditItems->net_amount + $modelCreditItems->tax_vat_amount, " "); ?>
                                </td>                 
                            </tr>
                            <?php
                            $total += $modelCreditItems->net_amount + $modelCreditItems->tax_vat_amount;
                        }
                        ?>                
                        <tr>
                            <td class="text-center"  colspan="1"><b>G.Total</b></td>
                            <td colspan="4"><b>
                                    <?php
                                    if ($total > 0) {
                                        echo MasCurrency::number_to_currency(number_format(($total), 2, '.', ''), $modelCredit->currency);
                                    }
                                    ?>

                                </b></td>
                            <td class="text-right" ><b><?php echo Yii::app()->numberFormatter->formatCurrency($total, " "); ?></b></td>
                        </tr>

                    </tbody>
                </table>


            </div>
            <?php
            if ($modelCredit->reason != '') {
                ?>
                <div class="box" style="width: 100%">
                    <h5>Reason</h5>
                    <div class="h5sub-details">
                        <?php echo nl2br($modelCredit->reason); ?>
                    </div>
                </div>
                <?php
            }
            ?>
            <?php
            if ($modelCredit->terms_and_conditions != '') {
                ?>
                <div style='page-break-after:always'></div>
                <div class="box" style="width:100%">
                    <h5>Terms & Conditions</h5>
                    <div class="h5sub-details">
                        <?php echo nl2br($modelCredit->terms_and_conditions); ?>
                    </div>
                </div>
                <?php
            }
            ?>
            <br>
            <br>
            <div style="width:100%;float:left;font-size:12px;margin-top:5px; font-family:'Times New Roman', Times, serif">
                <div style="width:50%;float:left;">
                    <span>For and on behalf of,</span><br />
                    <span><b>ACE CENTRO ENTERPRISES</b></span>
                </div>
                <div style="width:50%;float:left;margin-left:105px;margin-top:5px; font-family:'Times New Roman', Times, serif">
                    <span>Terms and conditions accepted by:</span><br />
                    <span><b><?php echo strtoupper($modelCredit->customer->customer_name); ?></b></span>
                </div>
            </div>
            <div style="width:100%;float:left; text-align:center;font-size:12px;">
                <p style="padding:0px;margin:0px;">Sign</p> 
                <p style="padding:0px;margin:0px;">Date</p> 
                <p style="padding:0px;margin:0px;">Stamp</p> 
            </div>
            <div style="width:100%;float:left;font-size:12px;">
                <div style="width:50%;float:left; font-family:'Times New Roman', Times, serif">
                    <div style="border-bottom:1px solid #000;width:150px; "></div>
                    <span><b>Name:</b></span><br />
                    <em>Finance Department</em><br />
                    <span>Cell : +971 55 504 0033</span><br />
                </div>
                <div style="width:50%;float:left;font-size:12px;margin-left:105px; font-family:'Times New Roman', Times, serif">
                    <div style="border-bottom:1px solid #000;width:150px;"></div>
                    <span><b><?php echo strtoupper($modelCredit->contact->person_name); ?></b></span><br />
                    <em><?php
                        if (!empty($modelCredit->contact->designation)) {
                            echo $modelCredit->contact->designation;
                        } else {
                            ?>Authorized Signatory<?php } ?></em><br />
                    <span>Cell : <?php echo strtoupper($modelCredit->contact->contact_mobile_no); ?></span><br />
                </div>
            </div>



            <htmlpagefooter name="firstfooter">
                <div style="text-align:right;width:100%;"><i>Contd...</i></div> 
                <div style="text-align:center;width:100%;"><img src="<?php echo 'images/' . Yii::app()->user->company_footer_logo; ?>" /></div> 
            </htmlpagefooter>
            <sethtmlpagefooter name="firstfooter" page="all" value="on" />

            <htmlpagefooter name="lastfooter">
                <div style="text-align:right;width:100%;">Contd...</div> 

                <div style="text-align:center;width:100%;"><img src="<?php echo 'images/' . Yii::app()->user->company_footer_logo; ?>" /></div> 
            </htmlpagefooter>
            <sethtmlpagefooter name="lastfooter" value="off" />

            <htmlpagefooter name="myfooter">

                <div style="text-align:center;width:100%;"><img src="<?php echo 'images/' . Yii::app()->user->company_footer_logo; ?>" /></div> 
            </htmlpagefooter>
            <sethtmlpagefooter name="myfooter" page="all" value="on" />
    </body>

</html>
