<?php

defined('BASEPATH') or exit('No direct script access allowed');

$dimensions = $pdf->getPageDimensions();

$info_right_column = '';
$info_left_column  = '';



$info_right_column ='<table cellpadding="1">
            <tr>
                <td width="170" style="padding-bottom:50px;font-size:18px" cellpadding="2">   Proforma</td>
                <td width="400" style="border-color: #fff; color: #fff";>  </td>
            </tr>
         
                
                
                    <tr>
                        <td bgcolor="#e6eff5" style="width: 40%">   N° Proforma </td>
                        <td bgcolor="#e6eff5" style="width: 10%"> : </td>
                        <td bgcolor="#e6eff5" >' . $estimate_number . '</td>
                    </tr>
                    <tr>
                        <td bgcolor="#e6eff5" style="width: 40%">   Date du devis  </td>
                        <td bgcolor="#e6eff5" style="width: 10%"> : </td>
                        <td bgcolor="#e6eff5" >' . _d($estimate->date) . '</td>
                    </tr>
                    <tr>
                        <td bgcolor="#e6eff5" style="width: 40%">   Date d\'expiration </td>
                        <td bgcolor="#e6eff5" style="width: 10%"> : </td>
                        <td bgcolor="#e6eff5" >' . _d($estimate->expirydate) . '</td>
                    </tr>
                    
                
               
           
            <tr>
                
            </tr>
        </table>

        <style type="text/css">
        
        table.first {
        color: #003300;
        font-family: Arial;
        font-size: 8pt;
        border-left: 3px solid red;
        border-right: 3px solid #FF00FF;
        border-top: 3px solid green;
        border-bottom: 3px solid blue;
        background-color: #ccffcc;
    }
    td {
        border: 1px solid #eee;
        border-radius: 5px;
        
        text-align: left;
        padding:20px;
        
    }
    
    </style>';




//$info_right_column .= '<span style="font-weight:bold;font-size:27px;">' . _l('estimate_pdf_heading') . '</span><br />';
//$info_right_column .= '<b style="color:#4e4e4e;"># ' . $estimate_number . '</b>';

if (get_option('show_status_on_pdf_ei') == 1) {
    //$info_right_column .= '<br /><span style="color:rgb(' . estimate_status_color_pdf($status) . ');text-transform:uppercase;">' . format_estimate_status($status, '', false) . '</span>';
}

// Add logo
$info_left_column .= pdf_logo_url();
// Write top left logo and right column info/text
pdf_multi_row($info_left_column, $info_right_column, $pdf, ($dimensions['wk'] / 2) - $dimensions['lm']);

$pdf->ln(4);

$organization_info = '<div style="color:#424242;">';
    $organization_info .= format_organization_info();
$organization_info .= '</div><br><br><br><br><br><br>';

// Estimate to
$estimate_info = '<b>' . _l('estimate_to') . '</b>';
$estimate_info .= '<div style="color:#424242;">';
$estimate_info .= format_customer_info($estimate, 'estimate', 'billing');
$estimate_info .= '</div>';

// ship to to
if ($estimate->include_shipping == 1 && $estimate->show_shipping_on_estimate == 1) {
    $estimate_info .= '<br /><b>' . _l('ship_to') . '</b>';
    $estimate_info .= '<div style="color:#424242;">';
    $estimate_info .= format_customer_info($estimate, 'estimate', 'shipping');
    $estimate_info .= '</div>';
}

$estimate_info .= '<br />' . _l('estimate_data_date') . ': ' . _d($estimate->date) . '<br />';

if (!empty($estimate->expirydate)) {
    $estimate_info .= _l('estimate_data_expiry_date') . ': ' . _d($estimate->expirydate) . '<br />';
}

if (!empty($estimate->reference_no)) {
    $estimate_info .= _l('reference_no') . ': ' . $estimate->reference_no . '<br />';
}

if ($estimate->sale_agent != 0 && get_option('show_sale_agent_on_estimates') == 1) {
    $estimate_info .= _l('sale_agent_string') . ': ' . get_staff_full_name($estimate->sale_agent) . '<br />';
}

if ($estimate->project_id != 0 && get_option('show_project_on_estimate') == 1) {
    $estimate_info .= _l('project') . ': ' . get_project_name_by_id($estimate->project_id) . '<br />';
}

foreach ($pdf_custom_fields as $field) {
    $value = get_custom_field_value($estimate->id, $field['id'], 'estimate');
    if ($value == '') {
        continue;
    }
    $estimate_info .= $field['name'] . ': ' . $value . '<br />';
}


$estimate_info = '
 

<table cellpadding="3"  >
            <tr>
                <td width="170" style="padding:10px; font-size: 18px; ">   Client</td>
                <td width="200" bgcolor="#ffffff" style="border-color: #ffffff; color: #fff";> vide </td>
            </tr>
            
                
                
                    <tr bgcolor="#e6eff5">
                        <td  bgcolor="#e6eff5" style="width: 40%;">   Nom / RS </td>
                        <td bgcolor="#e6eff5" style="width: 10%"> : </td>
                        <td bgcolor="#e6eff5" >' . $estimate->client->company . '</td>
                    </tr>

                    <tr>
                        <td bgcolor="#e6eff5" style="vertical-align:middle;">   Adresse </td>
                        <td bgcolor="#e6eff5" > : </td>
                        <td bgcolor="#e6eff5">' . $estimate->client->address . ' <br/> ' . $estimate->client->city . '<br/> ' . $estimate->client->state . '</td>
                    </tr>
                    <tr>
                        <td bgcolor="#e6eff5">   Téléphone </td>
                        <td bgcolor="#e6eff5"> : </td>
                        <td bgcolor="#e6eff5"> ' . $estimate->client->phonenumber . '</td>
                    </tr>
                    <tr>
                        <td bgcolor="#e6eff5">   Email </td>
                        <td bgcolor="#e6eff5"> : </td>
                        <td bgcolor="#e6eff5">  </td>
                    </tr>
            
            <tr>
                
            </tr>
        </table>
        <style type="text/css">
        
        table.first {
        color: #003300;
        font-family: Arial;
        font-size: 8pt;
        border-left: 3px solid red;
        border-right: 3px solid #FF00FF;
        border-top: 3px solid green;
        border-bottom: 3px solid blue;
        background-color: #ccffcc;
    }
    td {
        border: 1px solid #e6eff5;
        border-radius: 5px;
       
        text-align: left;
        padding:20px;
        
    }
    </style>';

        


$left_info  = $swap == '1' ? $estimate_info : $organization_info;
$right_info = $swap == '1' ? $organization_info : $estimate_info;

pdf_multi_row($left_info, $right_info, $pdf, ($dimensions['wk'] / 2) - $dimensions['lm']);

// The Table
$pdf->Ln(hooks()->apply_filters('pdf_info_and_table_separator', 6));

// The items table
$items = get_items_table_data($estimate, 'estimate', 'pdf');

$tblhtml = $items->table();

$pdf->writeHTML($tblhtml, true, false, false, false, '');

$pdf->Ln(18);
$tbltotal = '';
$tbltotal .= '<br><br><br><table cellpadding="6" style="font-size:' . ($font_size + 4) . 'px">';
$tbltotal .= '
<tr>
    <td align="right" width="85%"><strong>' . _l('estimate_subtotal') . '</strong></td>
    <td align="right" width="15%">' . app_format_money($estimate->subtotal, $estimate->currency_name) . '</td>
</tr>';

if (is_sale_discount_applied($estimate)) {
    $tbltotal .= '
    <tr>
        <td align="right" width="85%"><strong>' . _l('estimate_discount');
    if (is_sale_discount($estimate, 'percent')) {
        $tbltotal .= '(' . app_format_number($estimate->discount_percent, true) . '%)';
    }
    $tbltotal .= '</strong>';
    $tbltotal .= '</td>';
    $tbltotal .= '<td align="right" width="15%">-' . app_format_money($estimate->discount_total, $estimate->currency_name) . '</td>
    </tr>';
}

foreach ($items->taxes() as $tax) {
    $tbltotal .= '<tr>
    <td align="right" width="85%"><strong>' . $tax['taxname'] . ' (' . app_format_number($tax['taxrate']) . '%)' . '</strong></td>
    <td align="right" width="15%">' . app_format_money($tax['total_tax'], $estimate->currency_name) . '</td>
</tr>';
}

if ((int)$estimate->adjustment != 0) {
    $tbltotal .= '<tr>
    <td align="right" width="85%"><strong>' . _l('estimate_adjustment') . '</strong></td>
    <td align="right" width="15%">' . app_format_money($estimate->adjustment, $estimate->currency_name) . '</td>
</tr>';
}

$tbltotal .= '
<tr style="background-color:#f0f0ff;">
    <td align="right" width="85%"><strong>' . _l('estimate_total') . '</strong></td>
    <td align="right" width="15%">' . app_format_money($estimate->total, $estimate->currency_name) . '</td>
</tr>';

$tbltotal .= '</table>';



if (get_option('total_to_words_enabled') == 1) {

    $tbltotal .= '<br><br><div><span>Arrêtée la présente proforma à la somme de</span><br/><strong><i>'.$CI->numberword->convert($estimate->total, $estimate->currency_name).'</i></strong> </div>';
    // Set the font bold
   /* $pdf->SetFont($font_name, 'B', $font_size);

    $arreter='Arrêtée la présente proforma à la somme de';
    $pdf->Cell(0, 0, $arreter . ': ' . $CI->numberword->convert($estimate->total, $estimate->currency_name), 0, 1, 'C', 0, '', 0);
    // Set the font again to normal like the rest of the pdf
    $pdf->SetFont($font_name, '', $font_size);
    $pdf->Ln(4);*/
}

$pdf->writeHTML($tbltotal, true, false, false, false, '');



if (!empty($estimate->clientnote)) {
    $pdf->Ln(4);
    $pdf->SetFont($font_name, 'B', $font_size);
    $pdf->Cell(0, 0, _l('estimate_note'), 0, 1, 'L', 0, '', 0);
    $pdf->SetFont($font_name, '', $font_size);
    $pdf->Ln(2);
    $pdf->writeHTMLCell('', '', '', '', $estimate->clientnote, 0, 1, false, true, 'L', true);
}

if (!empty($estimate->terms)) {
    $pdf->Ln(4);
    $pdf->SetFont($font_name, 'B', $font_size);
    $pdf->Cell(0, 0, _l('terms_and_conditions'), 0, 1, 'L', 0, '', 0);
    $pdf->SetFont($font_name, '', $font_size);
    $pdf->Ln(2);
    $pdf->writeHTMLCell('', '', '', '', $estimate->terms, 0, 1, false, true, 'L', true);
}

// Pied de page Technologie House
$pdf->Ln(18);
$tblpied='<div style="position: absolute; bottom: 0px;width: 100%; margin: 0 auto;">

                <div style="width: 90%;  font-size: 9px; padding-left: 50px;padding-bottom: 5px;">
                <strong>SAV</strong>  : Jusqu\'à 3ans selon la nature du produit<br>
                <strong>Garantie</strong>
                 : La durée de garantie des produits varie de 6 mois à 3 ans selon la nature du produit
                <br>
                <strong>NB</strong>
                : La société décline toute responsabilité en cas de dommages causés par des surchages électriques ou par une mauvaise utilisation des produits(plus de détails dans les conditions de vente).  

                <br>
                <span style="font-size: 10px; font-weight: bold; font-style: italic;">Compte bancaire: BOA : ML045 01010 25176220 201-56</span>
                    
                </div>


                <div style="background-color: rgba(0,49,82,1); width: 100%; margin:0 auto; font-family: Ubuntu; padding-left: 25px;padding-right: 25px; padding-top: 5px; padding-bottom: 5px; z-index: 1;display: flex;flex-direction: row;">
    
<div style="display: inline-block;  width: 40%;color: #eee;  float: left;margin-left: 20px">
        <div style="margin-bottom: 10px">
        <img src=""  alt="" style="width: 12px; height: auto;">
        <img src=""  alt="" style="width: 12px; height: auto;">

          <span style="font-size: 12px;">Mali</span>
        </div>
        <div style="font-size: 10px; line-height: 12px;">
            Avenue Cheick Zayed près de la SOTELMA de lafiabougou ACI 2000 Bamako Rép. du Mali. <br> RCCM: MA.BKO.2015.A4483 - NIF: 084124049Y<br>
            Tél: +223 20 22 29 89 / Cell: +223 62 08 34 52<br>
            Email: contact@thnet.net Website: www.thnet.net
        </div>
    </div>

    <div style="display: inline-block;  width: 40%;color: #eee; float: right;margin-right: 20px">
        <div style="margin-bottom: 10px">
        <img src=""  alt="" style="width: 12px; height: auto;">
        <img src="" alt="" style="width: 12px; height: auto; margin: auto 5px;">
          <span style="font-size: 13px;">Guinée</span>
        </div>
        <div style="font-size: 10px; line-height: 12px;">
            Boulevard Pita, Av de la Rép. en face de la BCI de Kaloum Conakry Rép. de Guinée<br>
            Tél: +224 628 36 36 35 <br>
            Email: guinee_conakry@thnet.net  Website: www.thnet.net
        </div>
    </div>

    
</div>

</div>';

$footer_image_file = 'uploads/company/piedfact.png';
$footer_logo_html = '<div style="width:1000px !important;height:100px;"><img width:"1000px;" src="' . $footer_image_file . '" /></div>';

//$pdf->writeHTMLCell(210, '', 0, 250, $footer_logo_html, 0, 1, false, true, 'L', false);
//$pdf->writeHTML($tblpied, true, false, false, false, '');