<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

include_once( dirname(dirname(__FILE__)) . '/classes/check.class.php');
include_once( dirname(dirname(__FILE__)) . '/admin/classes/functions.php');
protect("*");
$techGuys = getUsersByLevel( 4 );
$currentUser = getUserDetailsById($_SESSION['jigowatt']['user_id']);
$clients = getClients();
/*
if ( !empty($_GET['flush']) ) {
    if ( 'go_ahead' == base64_decode( $_GET['flush'] ) ) {
        flashInvoiceSession();
    }
}

$newInvoice = false;

if ( !empty($_GET['new']) && $_GET['new'] == 'true' ) {
    $newInvoice = true;
}

if ( !empty($_GET['invoice_id'])) {
    $_SESSION['invoice'] = $_GET['invoice_id'];
    $newInvoice = true;
}

if ( empty($_SESSION['invoice'] ) ) {
    $_SESSION['invoice'] = createInvoiceDraft();
    header('Location: /admin/main.php?new=true');
    exit();
}*/

$id = !empty($_GET['invoice_id']) ? $_GET['invoice_id'] : 0;
$newInvoice = true;
if ( !$id ) {
    $newInvoice = true;
    $id = createInvoiceDraft();
    header('Location: /admin/main.php?invoice_id=' . $id);
    exit();
}
$_SESSION['invoice'] = $invId = $id;
$invoice = getInvoice( $id );

$invoicePhotos = getInvoicePhotos( $invId );
$parts = getIvoiceParts($invId);

$damageListForm = array(
    1 => 'CAPOT',
    2 => 'PAVILLON',
    3 => 'DESSUS HAYON',
    4 => 'VLISE HAYON',
    5 => 'PAN. LATERAL G',
    6 => 'PORTE ARR. G',
    7 => 'PORTE AV. G',
    8 => 'LONGERON G',
    9 => 'AILE G',
    10 => 'AILE D',
    11 => 'PORTE Av. D',
    12 => 'PORTE ARR. D',
    13 => 'PAN LATERAL D',
    14 => 'LONGERON D',
    15 => 'AUTRE',
    'stripping' => 'Dégarnissage',
    'other_fees' => 'Autres frais',
    'glazier' => 'Vitrier',
    'work_force' => 'Main d\'oeuvre',
    'parts' => 'Pièces'
);

include_once 'header.php';
echo '<script> var clients = '. ( json_encode($clients) ) .'; </script>';
echo '<script> var javascriptObject = '. ( empty($invoice['javascript_object']) ? '{}' : $invoice['javascript_object'] ) .'; </script>';
echo '<script> var javascriptObject2 = '. ( empty($invoice['javascript_object2']) ? '{}' : $invoice['javascript_object2'] ) .'; </script>';
echo '<script> var savedRequest = '. ( empty($invoice['latest_request']) ? '{}' : $invoice['latest_request'] ) .'; </script>';
?>
<div id="page-name" data-page-name="invoice" data-status="draft" data-invoice-id="<?php echo $invId; ?>"></div>
<div class="container">
    <div class="row">

        <?php if ( empty($invoice) ): ?>
            <div id="invoice_alert" class="col-md-12">
                <div class="panel panel-danger">
                    <div class="panel-heading">
                        <div class="text-center"><strong>Aucune facture disponible pour ce ID</strong></div>
                    </div>
                </div>
            </div>
            <?php include_once('footer.php'); exit; ?>
        <?php endif; ?>

        <div class="col-md-6">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <a class="btn btn-info text-right" href="/admin/client.php/"><i class="glyphicon glyphicon-plus"></i> Créer un client</a>
                </div>
                <div class="panel-body">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="clients">Choisir un client</label>
                            <select name="client" class="form-control" id="clients">
                                <option value=""> --Choisir-- </option>
                                <?php foreach ( $clients as $client ): ?>
                                    <option value="<?php echo $client['clientid'] ?>" <?php echo ($client['clientid'] == $invoice['client_id']) ? 'selected' : '';  ?> ><?php echo $client['cie']; ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="date">Date:</label>
                                <input type="text" class="form-control" id="date" value="<?php echo date('Y/m/d'); ?>">
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="tech">Tech:</label>
                                <select class="form-control" id="tech">
                                    <?php foreach ( $techGuys as $techGuy ): ?>
                                        <option value="<?php echo $techGuy['user_id']; ?>" <?php echo $currentUser['user_id'] == $techGuy['user_id'] ? 'selected' : '' ?> ><?php echo $techGuy['name']; ?></option>
                                    <?php endforeach; ?>
                                </select>
<!--                                <input type="text" class="form-control" value="--><?php //echo $currentUser['name']; ?><!--" id="tech">-->
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="reclamation"># Facture:</label>
                                <input class="form-control" id="reclamation" value="<?php echo !empty($invoice['reclamation']) ? $invoice['reclamation'] : $id; ?>">
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12" style="border: 1px solid #e4e4e4; padding-top: 10px;">
                        <input type="hidden" name="clientid" id="clientid" value="">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="client_fname">Prénom:</label>
                                <input readonly="readonly" type="text" class="form-control" id="client_fname">
                            </div>
                            <div class="form-group">
                                <label for="client_lname">Nom:</label>
                                <input readonly="readonly" type="text" class="form-control" id="client_lname">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="client_tel1">Téléphone:</label>
                                <input readonly="readonly" type="text" class="form-control" id="client_tel1">
                            </div>
                            <div class="form-group">
                                <label for="client_email">Courriel:</label>
                                <input readonly="readonly" type="email" class="form-control" id="client_email">
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label for="client_cie">Compagnie:</label>
                                <input readonly="readonly" type="text" class="form-control" id="client_cie">
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
<!--                                <label for="insurer">Assureur:</label>-->
                                <!--<select name="insurer" class="form-control" id="insurer">
                                    <option value="Promutuel">Promutuel</option>
<!--                                    <option value="SSQ">SSQ</option>-->
<!--                                    <option value="La Capital">La Capital</option>-->
<!--                                    <option value="Intact">Intact</option>-->
<!--                                    <option value="l\'unique"> L'unique</option>
                                </select>-->
<!--                                <input type="text" id="insurer" name="insurer" class="form-control" value="--><?php //echo $invoice['insurer']; ?><!--">-->
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12" id="vinArea" style="border: 1px solid #e4e4e4; padding-top: 10px;">
                        <div id="vinAreaOverlay" style="display: none;"><p><img src="/admin/assets/img/ajax-loader.gif"></p></div>

                        <div class="input-group">
                            <input type="text" placeholder="Type VIN" class="form-control col-md-9" id="vin">
                            <span class="input-group-btn">
                               <button class="btn btn-primary" id="scanVIN" type="button">Scan VIN</button>
                            </span>
                        </div>

                        <div class="form-group">
                            <div id="vinResults">
                                <div class="list-group">
<!--                                    <a class="list-group-item selectClient" href="javascript:void(0);">Item 1</a>-->
                                </div>
                            </div>
                            <div id="vinOutput">

                                <?php foreach ( array(
                                    'brand' => 'Marque',
                                    'model' => 'Modèle',
                                    'year' => 'Année',
                                    'inventory' => '#Inventaire',
                                    'sn' => '#NS',
                                    'color' => 'Couleur',
                                    'pa' => 'P.A',
                                    'bt' => 'B.T',
                                    'millage' => 'Millage',
                                                ) as $k => $v ): ?>
                                    <div class="col-md-6 <?php echo $k == 'sn' ? 'hidden' : ''; ?>">
                                        <div class="form-group">
                                            <label for="<?php echo $k; ?>"><?php echo $v; ?>:</label>
                                            <input type="text" required="required" class="form-control" id="<?php echo $k; ?>" value="">
                                        </div>
                                    </div>
                                <?php endforeach; ?>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12" style="border: 1px solid #e4e4e4; padding-top: 10px; min-height: 100px; padding-bottom: 15px; margin-bottom: 5px;">
                        <h4>Photos: </h4>
                        <form action="/admin/ajax/ajax_file_upload.php" id="dropzone" class="dropzone">
                            <div class="fallback">
                                <input name="file" type="file" multiple />
                            </div>
                        </form>

<!--                        --><?php //if ( $newInvoice == false ): ?>
                            <div id="photo_view">
                                <?php foreach ( $invoicePhotos as $photo ): ?>
                                    <a href="/<?php echo $photo['photo_url']; ?>" data-lightbox="image-<?php echo $photo['id']; ?>">
                                        <img class="img img-thumbnail" data-lightbox="image-<?php echo $photo['id']; ?>" src="/<?php echo $photo['photo_url']; ?>" width="100px">
                                    </a>
                                <?php endforeach; ?>
                            </div>
<!--                        --><?php //endif; ?>

                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="panel panel-primary">
                <div class="panel-body">
                    <ul class="nav nav-tabs" id="vehicles" role="tablist">
                        <li role="presentation" class="active"><a role="tab" data-toggle="tab" href="#car">Auto</a></li>
                        <li role="presentation"><a role="tab" data-toggle="tab" href="#truck">Camion</a></li>
                        <li role="presentation"><a role="tab" data-toggle="tab" href="#suv">VUS</a></li>
                    </ul>
                    <div class="tab-content">
                        <div role="tabpanel" class="tab-pane active" id="car">
                            <div id="graphics_car">
                                <div data-dot-number="1" data-dot-type="car" class="dot dot-1">1</div>
                                <div data-dot-number="2" data-dot-type="car" class="dot dot-2">2</div>
                                <div data-dot-number="3" data-dot-type="car" class="dot dot-3">3</div>
                                <div data-dot-number="4" data-dot-type="car" class="dot dot-4">4</div>
                                <div data-dot-number="5" data-dot-type="car" class="dot dot-5">5</div>
                                <div data-dot-number="6" data-dot-type="car" class="dot dot-6">6</div>
                                <div data-dot-number="7" data-dot-type="car" class="dot dot-7">7</div>
                                <div data-dot-number="8" data-dot-type="car" class="dot dot-8">8</div>
                                <div data-dot-number="9" data-dot-type="car" class="dot dot-9">9</div>
                                <div data-dot-number="10" data-dot-type="car" class="dot dot-10">10</div>
                                <div data-dot-number="11" data-dot-type="car" class="dot dot-11">11</div>
                                <div data-dot-number="12" data-dot-type="car" class="dot dot-12">12</div>
                                <div data-dot-number="13" data-dot-type="car" class="dot dot-13">13</div>
                                <div data-dot-number="14" data-dot-type="car" class="dot dot-14">14</div>
                                <div data-dot-number="15" data-dot-type="car" class="dot dot-15">15</div>
                            </div>
                        </div>
                        <div role="tabpanel" class="tab-pane" id="truck">
                            <div id="graphics_truck">
                                <div data-dot-number="1" data-dot-type="truck" class="dot dot-1">1</div>
                                <div data-dot-number="2" data-dot-type="truck" class="dot dot-2">2</div>
                                <div data-dot-number="3" data-dot-type="truck" class="dot dot-3">3</div>
                                <div data-dot-number="4" data-dot-type="truck" class="dot dot-4">4</div>
                                <div data-dot-number="5" data-dot-type="truck" class="dot dot-5">5</div>
                                <div data-dot-number="6" data-dot-type="truck" class="dot dot-6">6</div>
                                <div data-dot-number="7" data-dot-type="truck" class="dot dot-7">7</div>
                                <div data-dot-number="8" data-dot-type="truck" class="dot dot-8">8</div>
                                <div data-dot-number="9" data-dot-type="truck" class="dot dot-9">9</div>
                                <div data-dot-number="10" data-dot-type="truck" class="dot dot-10">10</div>
                                <div data-dot-number="11" data-dot-type="truck" class="dot dot-11">11</div>
                                <div data-dot-number="12" data-dot-type="truck" class="dot dot-12">12</div>
                                <div data-dot-number="13" data-dot-type="truck" class="dot dot-13">13</div>
                                <div data-dot-number="14" data-dot-type="truck" class="dot dot-14">14</div>
                                <div data-dot-number="15" data-dot-type="truck" class="dot dot-15">15</div>
                            </div>
                        </div>
                        <div role="tabpanel" class="tab-pane" id="suv">
                            <div id="graphics_suv">
                                <div data-dot-number="1" data-dot-type="suv" class="dot dot-1">1</div>
                                <div data-dot-number="2" data-dot-type="suv" class="dot dot-2">2</div>
                                <div data-dot-number="3" data-dot-type="suv" class="dot dot-3">3</div>
                                <div data-dot-number="4" data-dot-type="suv" class="dot dot-4">4</div>
                                <div data-dot-number="5" data-dot-type="suv" class="dot dot-5">5</div>
                                <div data-dot-number="6" data-dot-type="suv" class="dot dot-6">6</div>
                                <div data-dot-number="7" data-dot-type="suv" class="dot dot-7">7</div>
                                <div data-dot-number="8" data-dot-type="suv" class="dot dot-8">8</div>
                                <div data-dot-number="9" data-dot-type="suv" class="dot dot-9">9</div>
                                <div data-dot-number="10" data-dot-type="suv" class="dot dot-10">10</div>
                                <div data-dot-number="11" data-dot-type="suv" class="dot dot-11">11</div>
                                <div data-dot-number="12" data-dot-type="suv" class="dot dot-12">12</div>
                                <div data-dot-number="13" data-dot-type="suv" class="dot dot-13">13</div>
                                <div data-dot-number="14" data-dot-type="suv" class="dot dot-14">14</div>
                                <div data-dot-number="15" data-dot-type="suv" class="dot dot-15">15</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                <div class="panel panel-primary">
                    <div class="panel-heading" role="tab" id="strippingHead">
                        <h4 class="panel-title">
                            <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                Dégarnissage
                            </a>
                        </h4>
                    </div>
                    <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
                        <div class="panel-body">
                            <div class="form-inline">
                                <div class="checkbox" style="border-bottom: 1px solid #e4e4e4; padding-bottom: 10px;">
                                    <label><input id="stripping_partial" data-price="150" class="stripping" value="Partial stripping" type="checkbox"> Dégarnissage partiel</label>
                                    <label><input id="stripping_compact" class="stripping" data-price="250" value="Compact" type="checkbox"> Compact</label>
                                    <label><input id="stripping_standard" class="stripping" data-price="325" value="Standard" type="checkbox"> Standard</label>
                                    <label><input id="stripping_suv" class="stripping" data-price="400" value="SUV" type="checkbox"> VUS</label>
                                    <label><input id="stripping_sky_roof" class="stripping" data-price="75" value="Sky roof" type="checkbox"> Toit ouvrant</label>
                                    <label><input id="stripping_dvd_video_acc" class="stripping" data-price="75" value="DVD Video Acc." type="checkbox"> DVD Vidéo Acc.</label>
                                    <label><input id="stripping_root_support" class="stripping" data-price="75" value="Roof support" type="checkbox"> Support à toit</label>
                                    <label><input id="stripping_back_glass" class="back_glass" data-price="" value="Back glass" type="checkbox"> Vitre arrière</label>
                                </div>
                            </div>
                            <div class="input-details" style="padding-top: 10px;">
                                <div class="form-group">
                                    <label for="stripping_price">Prix</label>
                                    <input type="number" class="form-control" id="stripping_price">
                                </div>
                                <div class="form-group">
                                    <label for="stripping_tech">Tech</label>
                                    <select class="form-control" name="stripping_tech" id="stripping_tech">
                                        <?php foreach ( $techGuys as $techGuy ): ?>
                                            <option value="<?php echo $techGuy['user_id']; ?>" <?php echo $currentUser['user_id'] == $techGuy['user_id'] ? 'selected' : '' ?>><?php echo $techGuy['name']; ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="stripping_note">Note.</label>
                                    <textarea name="stripping_note" class="form-control" id="stripping_note"
                                              style="width: 100%;"></textarea>
                                </div>
                                <div class="form-group">
                                    <button id="stripping_add" class="btn btn-primary btn-md">Ajouter</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel panel-primary">
                    <div class="panel-heading" role="tab" id="otherFeesHead">
                        <h4 class="panel-title">
                            <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
                                Autres frais
                            </a>
                        </h4>
                    </div>
                    <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
                        <div class="panel-body">
                            <div class="form-group">
                                <label for="oversize_dent">Bosse surdimensionnée (plus de 30mm) Prix:</label>
                                <input type="number" min="0" id="oversize_dent" value="0" class="form-control">
                            </div>
                            <div class="form-group">
                                <label for="other_fees_description">Description: </label>
                                <textarea id="other_fees_description" class="form-control"></textarea>
                            </div>
                            <div class="form-group hidden">
                                <label for="other_fees_price">Prix:</label>
                                <input type="number" min="0" id="other_fees_price" value="0" class="form-control">
                            </div>
                            <div class="form-group">
                                <label for="other_fees_total_price">Prix Total: </label>
                                <input type="number" id="other_fees_total_price" class="form-control" value="0">
                            </div>
                            <div class="form-group">
                                <button id="other_fees_add_button" class="btn btn-primary btn-md">Ajouter</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel panel-primary">
                    <div class="panel-heading" role="tab" id="glazierHead">
                        <h4 class="panel-title">
                            <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                                Vitrier
                            </a>
                        </h4>
                    </div>
                    <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
                        <div class="panel-body">
                            <div class="form-group">
                                <label for="glazier_tech">Tech: </label>
                                <input type="text" class="form-control" id="glazier_tech">
                            </div>
                            <div class="form-group">
                                <label for="glazier_price">Prix: </label>
                                <input type="number" class="form-control" id="glazier_price" value="0" min="0">
                            </div>
                            <div class="form-group">
                                <label for="glazier_note">Note: </label>
                                <input type="text" class="form-control" id="glazier_note">
                            </div>
                            <div class="form-group">
                                <button id="glazier_add" class="btn btn-primary btn-md">Ajouter</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel panel-primary">
                    <div class="panel-heading" role="tab" id="workForceHead">
                        <h4 class="panel-title">
                            <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseFour" aria-expanded="false" aria-controls="collapseFour">
                                Main d'oeuvre
                            </a>
                        </h4>
                    </div>
                    <div id="collapseFour" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingFour">
                        <div class="panel-body">
                            <div class="form-group">
                                <label for="glazier_note">Note/Heure: </label>
                                <input type="text" class="form-control" id="work_force_note">
                            </div>
                            <div class="form-group">
                                <label for="glazier_price">Prix: </label>
                                <input type="number" class="form-control" id="work_force_price" value="0" min="0">
                            </div>
                            <div class="form-group">
                                <button id="work_force_add" class="btn btn-primary btn-md">Ajouter</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel panel-primary">
                    <div class="panel-heading" role="tab" id="partsHead">
                        <h4 class="panel-title">
                            <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseFive" aria-expanded="false" aria-controls="collapseFive">
                                Pièces
                            </a>
                        </h4>
                    </div>
                    <div id="collapseFive" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingFive">
                        <div class="panel-body">
                            <?php for ( $part = 1; $part <=10; $part += 1 ): ?>
                                <div class="form-group">
                                    <label for="part_<?php echo $part; ?>">Pièce <?php echo $part; ?>: </label>
                                    <input type="text" class="form-control" id="part_<?php echo $part; ?>" value="<?php echo !empty($parts[$part-1]['name']) ? $parts[$part-1]['name'] : '' ?>">
                                </div>
                                <div class="form-group">
                                    <label for="part_<?php echo $part; ?>">Commandé: <input type="checkbox" value="ordered" name="part_order_status_<?php echo $part; ?>" id="part_order_<?php echo $part; ?>" <?php echo !empty($parts[$part-1]['ordered']) ? 'checked' : '' ?> ></label>
                                    <label for="part_<?php echo $part; ?>">Reçu: <input type="checkbox" value="received" name="part_received_status_<?php echo $part; ?>" id="part_received_<?php echo $part; ?>" <?php echo !empty($parts[$part-1]['received']) ? 'checked' : '' ?> ></label>
                                </div>
                                <div class="form-group">
                                    <label for="part_price_<?php echo $part; ?>">Price: </label>
                                    <input type="text" class="form-control part-price" id="part_price_<?php echo $part; ?>" value="<?php echo !empty($parts[$part-1]['price']) ? $parts[$part-1]['price'] : '' ?>">
                                    <input type="hidden" id="total_parts">
                                </div>
                                <hr>
                            <?php endfor; ?>
                            <div class="form-group">
                                <label for="part_price">Prix: </label>
                                <input type="text" class="form-control" <?php echo isset($invoice['']) ?> id="part_price">
                            </div>
                            <div class="form-group">
                                <button id="parts_add" class="btn btn-primary btn-md">Ajouter</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
        <div class="col-md-12">
            <div class="panel panel-info">
                <div class="panel-heading">
                    <div class="text-center text-uppercase"><strong>Facture</strong></div>
                </div>
                <div class="panel-body">
                    <form id="invoice" action="" class="form-horizontal" method="post">
                        <div class="form-group">
                            <label class="control-label col-sm-2" for="invoice_location">Contrat de location:</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" name="invoice[location]" id="invoice_location" placeholder="Contrat de location">
                            </div>

                            <label class="control-label col-sm-2" for="invoice_location">Jours:</label>
                            <div class="col-sm-2">
                                <input type="number" id="number_of_days" class="form-control" placeholder="Nombre de jours">
                            </div>

                            <div class="col-sm-2">
                                <div class="checkbox">
                                    <label><input name="invoice[rental_car]" id="rental_car" value="1" type="checkbox"> Véhicule de location:</label>
                                </div>
                            </div>
                        </div>

                        <table class="table table-responsive">
                            <tr>
                                <th>#</th>
                                <th>Tech</th>
                                <th>Description / Note</th>
                                <th>Prix</th>
                            </tr>
                            <?php foreach ( $damageListForm as $key => $damageListItem ): ?>
                                <?php if ( is_numeric($key) ): ?>
                                    <tr>
                                        <td><?php echo $key; ?> - <?php echo $damageListItem; ?></td>
                                        <td>
                                            <select class="form-control" id="inv_<?php echo $key; ?>_tech" name="invoice[damage<?php echo $key; ?>][tech]">
                                                <?php foreach ( $techGuys as $techGuy ): ?>
                                                    <option value="<?php echo $techGuy['user_id']; ?>" <?php echo $currentUser['user_id'] == $techGuy['user_id'] ? 'selected' : '' ?>><?php echo $techGuy['name']; ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </td>
                                        <td>
                                            <input type="text" id="inv_<?php echo $key; ?>_note" class="form-control" name="invoice[damage<?php echo $key; ?>][description]">
                                        </td>
                                        <td>
                                            <input type="number" min="0" id="inv_<?php echo $key; ?>_price" class="form-control invoice_price" name="invoice[damage<?php echo $key; ?>][price]">
                                        </td>
                                    </tr>
                                <?php endif; ?>
                            <?php endforeach; ?>
                            <?php foreach ( $damageListForm as $key => $damageListItem ): ?>
                                <?php if ( !is_numeric($key) ): ?>
                                    <tr>
                                        <td><?php echo $damageListItem; ?></td>
                                        <td>
                                            <?php if ( $key == 'glazier' ): ?>
                                                <input type="text" class="form-control" id="inv_<?php echo $key; ?>_tech" name="invoice[damage<?php echo $key; ?>][tech]">
                                            <?php else: ?>
                                                <select class="form-control <?php echo ( in_array($key, ['other_fees','work_force','parts']) ) ? 'hidden' : ''; ?>" id="inv_<?php echo $key; ?>_tech" name="invoice[damage<?php echo $key; ?>][tech]">
                                                    <?php foreach ( $techGuys as $techGuy ): ?>
                                                        <option value="<?php echo $techGuy['user_id']; ?>" <?php echo $currentUser['user_id'] == $techGuy['user_id'] ? 'selected' : '' ?>><?php echo $techGuy['name']; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" id="inv_<?php echo $key; ?>_note" name="invoice[damage<?php echo $key; ?>][description]">
                                        </td>
                                        <td>
                                            <input type="number" min="0" class="form-control invoice_price" id="inv_<?php echo $key; ?>_price" name="invoice[damage<?php echo $key; ?>][price]">
                                        </td>
                                    </tr>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </table>
                        <div class="col-md-12">
                            <div class="col-md-9 clearfix">
                                <div>
                                    <p>Je soussigné(e), déclare avoir pris connaissance des réparations de débosselage sans peinture exécuter sur mon véhicule par Carrossier Express, et je m’en déclare entièrement satisfait(e).</p>
                                </div>

                                <div id="signature">
                                    <?php if ( $invoice['signature_img'] ): ?>
                                        <img src="<?php echo $invoice['signature_img']; ?>" alt="Signature Image">
                                    <?php endif; ?>
                                </div>

                                <div id="signature-pad" class="clearfix">
                                    <canvas class="pad"></canvas>
                                    <br>
                                    <a href="#" class="btn btn-xs btn-danger" id="signature-clear">Effacer la signature</a>
                                </div>

                                <br>

                                <div id="payment_type">
                                    <label for="p_check"> <input id="p_check" <?php echo $invoice['payment_method'] == 'check' ? ' checked ' : ''; ?> name="payment_method" type="radio" value="check"> Chèque</label> &nbsp;
                                    <label for="p_interac"> <input id="p_interac" <?php echo $invoice['payment_method'] == 'interac' ? ' checked ' : ''; ?> name="payment_method" type="radio" value="interac"> Interac</label> &nbsp;
                                    <label for="p_cash"> <input id="p_cash" <?php echo $invoice['payment_method'] == 'cash' ? ' checked ' : ''; ?> name="payment_method" type="radio" value="cash"> Contant</label>
                                </div>

                            </div>
                            <div class="col-md-3">
                                <table>
                                    <tr>
                                        <td>Sous Total: </td>
                                        <td><input type="number" id="sub_total" class="form-control invoice_price_calculate" name="invoice[subtotal]"></td>
                                    </tr>
                                    <tr>
                                        <td>TPS (5%): </td>
                                        <td><input type="number" id="tps" class="form-control invoice_price_calculate" name="invoice[tps]"></td>
                                    </tr>
                                    <tr>
                                        <td>TVQ (9.975%): </td>
                                        <td><input type="number" id="tvq" class="form-control invoice_price_calculate" name="invoice[tvq]"></td>
                                    </tr>
                                    <tr>
                                        <td>Franchise: </td>
                                        <td><input type="number" id="franchise" min="0" step="1" class="form-control invoice_price_calculate" name="invoice[franchise]"></td>
                                    </tr>
                                    <tr>
                                        <td>Total: </td>
                                        <td><input type="number" id="total" class="form-control invoice_price_calculate" name="invoice[total]"></td>
                                    </tr>
                                    <tr>
                                        <td>Dépôt:  </td>
                                        <td><input type="number" id="deposit" class="form-control invoice_price_calculate" name="invoice[deposit]"></td>
                                    </tr>
                                    <tr>
                                        <td>Balance:  </td>
                                        <td><input type="number" id="balance" class="form-control invoice_price_calculate" name="invoice[balance]"></td>
                                    </tr>
                                </table>
                            </div>
                            <div class="col-md-12 clearfix">

                                <div class="form-group" style="padding-top: 10px;">
                                    <input type="hidden" name="payment_status" id="payment_status" value="0"/>
                                    <?php if( !empty($invoice['payment_status'])){ ?>
                                    <button type="button" style="margin-right: 16px;" id="payment-button" data-value="PAID" class="btn btn-success pull-right">PAYÉ</button>
                                    <?php } else { ?>
                                        <button type="button" style="margin-right: 16px;" id="payment-button" data-value="Payment Pending" class="btn btn-danger pull-right">NON PAYÉ</button>
                                    <?php } ?>
                                </div>

                                <div class="form-group">
                                    <label class="control-label">Notes: </label>
                                    <textarea name="invoice[damages_notes]" id="damages" class="form-control"></textarea>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="panel-footer clearfix">
                    <button class="btn btn-primary btn-lg pull-right" id="saveInvoice" type="button">Sauvegarder</button>
                    <a class="btn btn-warning" target="_blank" href="/admin/invoice/index.php?invoice_id=<?php echo $id; ?>&print=y">Imprimer</a>
                    | <a class="btn btn-success" target="_blank" href="/admin/invoice/index-email.php?invoice_id=<?php echo $id; ?>&email=y&token=creedDefaultToken">Send by email</a>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="chooseClientModal" class="modal fade" role="dialog">
    <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Choisir Client</h4>
            </div>
            <div class="modal-body">

                <div class="form-group">
                    <input type="text" style="width: 100%;" autocomplete="off" id="client_search_token" class="form-control" placeholder="Type Client Info">
                </div>

                <div id="client-lists">
                    <div class="list-group">

                    </div>
                </div>

            </div>
<!--            <div class="modal-footer">
                <button type="button" id="client_submit" class="btn btn-primary" disabled="disabled"><i class="glyphicon glyphicon-check"></i> Submit</button>
            </div>-->
        </div>

    </div>
</div>

<div id="dotPreviewModal" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="dot_name"></h4>
            </div>
            <div class="modal-body">

                <div id="dot_section_2">
                    <div class="row">
                        <div class="col-md-12" style="border: 1px solid #e4e4e4; padding: 10px;">
                            <div class="col-md-3">
                                <h5>TRÈS LÉGER 1-5X</h5>
                                <div class="btn-group" data-toggle="buttons">
                                    <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="1" data-mm-max="5" value="10" autocomplete="off"> <10mm </label>
                                    <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="1" data-mm-max="5" value="20" autocomplete="off"> <20mm </label>
                                    <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="1" data-mm-max="5" value="30" autocomplete="off"> <30mm </label>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <h5>LÉGER 6-15X</h5>
                                <div class="btn-group" data-toggle="buttons">
                                    <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="6" data-mm-max="15" value="10" autocomplete="off"> <10mm </label>
                                    <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="6" data-mm-max="15" value="20" autocomplete="off"> <20mm </label>
                                    <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="6" data-mm-max="15" value="30" autocomplete="off"> <30mm </label>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <h5>MODÉRER 16-30X</h5>
                                <div class="btn-group" data-toggle="buttons">
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="16" data-mm-max="30" value="10" autocomplete="off"> <10mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="16" data-mm-max="30" value="20" autocomplete="off"> <20mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="16" data-mm-max="30" value="30" autocomplete="off"> <30mm </label>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <h5>MÉDIUM 31-50X</h5>
                                <div class="btn-group" data-toggle="buttons">
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="31" data-mm-max="50" value="10" autocomplete="off"> <10mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="31" data-mm-max="50" value="20" autocomplete="off"> <20mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="31" data-mm-max="50" value="30" autocomplete="off"> <30mm </label>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12" id="for_1_2_4" style="border: 1px solid #e4e4e4; padding: 10px;">
                            <div class="col-md-3">
                                <h5>LOURD 51-75X</h5>
                                <div class="btn-group" data-toggle="buttons">
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="51" data-mm-max="75" value="10" autocomplete="off"> <10mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="51" data-mm-max="75" value="20" autocomplete="off"> <20mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="51" data-mm-max="75" value="30" autocomplete="off"> <30mm </label>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <h5>SÉVÈRE 76-100X</h5>
                                <div class="btn-group" data-toggle="buttons">
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="76" data-mm-max="100" value="10" autocomplete="off"> <10mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="76" data-mm-max="100" value="20" autocomplete="off"> <20mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="76" data-mm-max="100" value="30" autocomplete="off"> <30mm </label>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <h5>EXTRÊME 101-150X</h5>
                                <div class="btn-group" data-toggle="buttons">
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="101" data-mm-max="150" value="10" autocomplete="off"> <10mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="101" data-mm-max="150" value="20" autocomplete="off"> <20mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="101" data-mm-max="150" value="30" autocomplete="off"> <30mm </label>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <h5>LIMITE 151-200X</h5>
                                <div class="btn-group" data-toggle="buttons">
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="151" data-mm-max="200" value="10" autocomplete="off"> <10mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="151" data-mm-max="200" value="20" autocomplete="off"> <20mm </label>
                                <label class="btn btn-success btn-xs dot-label"> <input type="radio" name="dot[type]" data-mm-min="151" data-mm-max="200" value="30" autocomplete="off"> <30mm </label>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12" style="margin-top: 20px; padding: 10px;">
                            <div class="col-md-12">
                                <div class="btn-group" data-toggle="buttons">
                                <label class="btn btn-success btn-xs dot-label-cb"><input type="checkbox" data-formula="addToDesc" value="DA" name="dot[extra]" autocomplete="off"> DA</label>
                                <label class="btn btn-success btn-xs dot-label-cb"><input type="checkbox" data-formula="addToDesc" value="PTP" name="dot[extra]" autocomplete="off"> PTP</label>
                                <label class="btn btn-success btn-xs dot-label-cb"><input type="checkbox" data-formula="addPricing" id="ptp" data-price="50" value="SD" name="dot[extra]" autocomplete="off"> SD</label>
                                <label class="btn btn-success btn-xs dot-label-cb"><input type="checkbox" data-formula="addToDesc" value="RC" name="dot[extra]" autocomplete="off"> RC</label>
                                <label class="btn btn-success btn-xs dot-label-cb"><input type="checkbox" data-formula="addPricingPercentage" data-price="25" id="al" value="AL" name="dot[extra]" autocomplete="off"> AL</label>
                                </div>
                            </div>
                            <div class="hidden">
                                <div class="form-group">
                                    <input type="text" placeholder="Pricing" readonly="readonly" class="form-control" required="required" name="dot[pricing]" value="0" id="dot_pricing">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <hr>

                <div id="dot_section_1">
                    <input type="hidden" id="dot_number" value="">
                    <div class="form-group">
                        <label for="dot_tech">Tech: </label>
                        <select name="dot[tech]" class="form-control" id="dot_tech">
                            <?php foreach ( $techGuys as $techGuy ): ?>
                                <option value="<?php echo $techGuy['user_id']; ?>" <?php echo $currentUser['user_id'] == $techGuy['user_id'] ? 'selected' : '' ?>><?php echo $techGuy['name']; ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="dot_desc">Note: </label>
                        <input type="text" class="form-control" id="dot_desc" value="">
                    </div>
                    <div class="form-group">
                        <label for="dot_price">Prix: </label>
                        <input type="number"  class="form-control" id="dot_price" value="">
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" id="addDotInfo" type="button">Ajouter</button>
                <button class="btn btn-warning" data-dismiss="modal" data-target="#dotPreviewModal">Fermer</button>
            </div>
        </div>

    </div>
</div>

<?php include_once('footer.php'); ?>
