|
|
|
@ -1,6 +1,4 @@ |
|
|
|
<!-- Content Wrapper. Contains page content --> |
|
|
|
<div class="content-wrapper"> |
|
|
|
<!-- Content Header (Page header) --> |
|
|
|
<section class="content-header"> |
|
|
|
<h1> |
|
|
|
Gérer les |
|
|
|
@ -12,9 +10,7 @@ |
|
|
|
</ol> |
|
|
|
</section> |
|
|
|
|
|
|
|
<!-- Main content --> |
|
|
|
<section class="content"> |
|
|
|
<!-- Small boxes (Stat box) --> |
|
|
|
<div class="row"> |
|
|
|
<div class="col-md-12 col-xs-12"> |
|
|
|
|
|
|
|
@ -53,37 +49,12 @@ |
|
|
|
</div> |
|
|
|
<?php endif; ?> |
|
|
|
|
|
|
|
<?php |
|
|
|
// ✅ VÉRIFIER SI LA COMMANDE EST MODIFIABLE |
|
|
|
// Seuls les statuts 1 (Validé) et 3 (Validé et Livré) sont NON modifiables |
|
|
|
$is_editable = isset($is_editable) ? $is_editable : true; |
|
|
|
$paid_status = $order_data['order']['paid_status'] ?? 2; |
|
|
|
?> |
|
|
|
|
|
|
|
<?php if (!$is_editable): ?> |
|
|
|
<!-- ✅ ALERTE SI NON MODIFIABLE --> |
|
|
|
<div class="alert alert-warning alert-dismissible" role="alert"> |
|
|
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> |
|
|
|
<span aria-hidden="true">×</span> |
|
|
|
</button> |
|
|
|
<strong><i class="fa fa-lock"></i> Cette commande ne peut plus être modifiée</strong><br> |
|
|
|
Elle a été <?php echo ($paid_status == 1) ? 'validée' : 'validée et livrée'; ?>. |
|
|
|
Vous pouvez uniquement consulter les informations. |
|
|
|
</div> |
|
|
|
<?php endif; ?> |
|
|
|
|
|
|
|
<div class="box"> |
|
|
|
<div class="box-header"> |
|
|
|
<h3 class="box-title"> |
|
|
|
<?php echo $is_editable ? 'Mise à jour de commande' : 'Consultation de commande'; ?> |
|
|
|
</h3> |
|
|
|
</div> |
|
|
|
<!-- /.box-header --> |
|
|
|
<form role="form" |
|
|
|
action="<?php base_url('orders/create') ?>" |
|
|
|
method="post" |
|
|
|
class="form-horizontal" |
|
|
|
<?php echo !$is_editable ? 'onsubmit="return false;"' : ''; ?>> |
|
|
|
<h3 class="box-title">Mise à jour de commande</h3> |
|
|
|
</div> |
|
|
|
|
|
|
|
<form role="form" action="<?php base_url('orders/create') ?>" method="post" class="form-horizontal"> |
|
|
|
<div class="box-body"> |
|
|
|
|
|
|
|
<div class="form-group"> |
|
|
|
@ -98,7 +69,7 @@ |
|
|
|
<div class="form-group"> |
|
|
|
<label for="types" class="col-sm-5 control-label" style="text-align:left;">Types</label> |
|
|
|
<div class="col-sm-7"> |
|
|
|
<select name="" id="typesCommande" class="form-control" <?php echo !$is_editable ? 'disabled' : ''; ?>> |
|
|
|
<select name="" id="typesCommande" class="form-control"> |
|
|
|
<option value="1">Facture</option> |
|
|
|
<option value="2">Bon de Livraison & Facture</option> |
|
|
|
<option value="3">Bon de Livraison</option> |
|
|
|
@ -109,56 +80,28 @@ |
|
|
|
<div class="form-group"> |
|
|
|
<label for="customer_name" class="col-sm-5 control-label" style="text-align:left;">Nom du client</label> |
|
|
|
<div class="col-sm-7"> |
|
|
|
<input type="text" |
|
|
|
class="form-control" |
|
|
|
id="customer_name" |
|
|
|
name="customer_name" |
|
|
|
placeholder="Enter Customer Name" |
|
|
|
value="<?php echo $order_data['order']['customer_name'] ?>" |
|
|
|
autocomplete="off" |
|
|
|
<?php echo !$is_editable ? 'disabled readonly' : ''; ?> /> |
|
|
|
<input type="text" class="form-control" id="customer_name" name="customer_name" placeholder="Enter Customer Name" value="<?php echo $order_data['order']['customer_name'] ?>" autocomplete="off" /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="form-group"> |
|
|
|
<label for="gross_amount" class="col-sm-5 control-label" style="text-align:left;">Adresse du client</label> |
|
|
|
<div class="col-sm-7"> |
|
|
|
<input type="text" |
|
|
|
class="form-control" |
|
|
|
id="customer_address" |
|
|
|
name="customer_address" |
|
|
|
placeholder="Enter Customer Address" |
|
|
|
value="<?php echo $order_data['order']['customer_address'] ?>" |
|
|
|
autocomplete="off" |
|
|
|
<?php echo !$is_editable ? 'disabled readonly' : ''; ?>> |
|
|
|
<input type="text" class="form-control" id="customer_address" name="customer_address" placeholder="Enter Customer Address" value="<?php echo $order_data['order']['customer_address'] ?>" autocomplete="off"> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="form-group"> |
|
|
|
<label for="gross_amount" class="col-sm-5 control-label" style="text-align:left;">Téléphone du client</label> |
|
|
|
<div class="col-sm-7"> |
|
|
|
<input type="text" |
|
|
|
class="form-control" |
|
|
|
id="customer_phone" |
|
|
|
name="customer_phone" |
|
|
|
placeholder="Enter Customer Phone" |
|
|
|
value="<?php echo $order_data['order']['customer_phone'] ?>" |
|
|
|
autocomplete="off" |
|
|
|
<?php echo !$is_editable ? 'disabled readonly' : ''; ?>> |
|
|
|
<input type="text" class="form-control" id="customer_phone" name="customer_phone" placeholder="Enter Customer Phone" value="<?php echo $order_data['order']['customer_phone'] ?>" autocomplete="off"> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="form-group"> |
|
|
|
<label for="gross_amount" class="col-sm-5 control-label" style="text-align:left;">CIN du client</label> |
|
|
|
<div class="col-sm-7"> |
|
|
|
<input type="text" |
|
|
|
class="form-control" |
|
|
|
id="customer_cin" |
|
|
|
name="customer_cin" |
|
|
|
placeholder="Enter Customer CIN" |
|
|
|
value="<?php echo $order_data['order']['customer_cin'] ?>" |
|
|
|
autocomplete="off" |
|
|
|
<?php echo !$is_editable ? 'disabled readonly' : ''; ?>> |
|
|
|
<input type="text" class="form-control" id="customer_cin" name="customer_cin" placeholder="Enter Customer CIN" value="<?php echo $order_data['order']['customer_cin'] ?>" autocomplete="off"> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
@ -168,14 +111,10 @@ |
|
|
|
<thead> |
|
|
|
<tr> |
|
|
|
<th style="width:50%">Produit</th> |
|
|
|
<th style="width:10%">Quantité</th> |
|
|
|
<th style="width:15%">Puissance (CC)</th> |
|
|
|
<th style="width:10%">Prix unitaire</th> |
|
|
|
<th style="width:20%">Montant</th> |
|
|
|
<th style="width:10%"> |
|
|
|
<?php if ($is_editable): ?> |
|
|
|
<button type="button" id="add_row" class="btn btn-default"><i class="fa fa-plus"></i></button> |
|
|
|
<?php endif; ?> |
|
|
|
</th> |
|
|
|
<th style="width:10%"><button type="button" id="add_row" class="btn btn-default"><i class="fa fa-plus"></i></button></th> |
|
|
|
</tr> |
|
|
|
</thead> |
|
|
|
|
|
|
|
@ -185,71 +124,59 @@ |
|
|
|
<?php foreach ($order_data['order_item'] as $key => $val): ?> |
|
|
|
<tr id="row_<?php echo $x; ?>"> |
|
|
|
<td> |
|
|
|
<select class="form-control select_group product" |
|
|
|
data-row-id="row_<?php echo $x; ?>" |
|
|
|
id="product_<?php echo $x; ?>" |
|
|
|
name="product[]" |
|
|
|
style="width:100%;" |
|
|
|
onchange="getProductData(<?php echo $x; ?>)" |
|
|
|
<?php echo !$is_editable ? 'disabled' : 'required'; ?>> |
|
|
|
<select class="form-control select_group product" data-row-id="row_<?php echo $x; ?>" |
|
|
|
id="product_<?php echo $x; ?>" name="product[]" style="width:100%;" |
|
|
|
onchange="getProductData(<?php echo $x; ?>)" required> |
|
|
|
<option value=""></option> |
|
|
|
<?php foreach ($products as $k => $v): ?> |
|
|
|
<option value="<?php echo $v['id'] ?>" <?php if ($val['product_id'] == $v['id']) { echo "selected='selected'"; } ?>><?php echo $v['name'] ?></option> |
|
|
|
<option value="<?php echo $v['id'] ?>" |
|
|
|
<?php if ($val['product_id'] == $v['id']) { echo "selected='selected'"; } ?>> |
|
|
|
<?php |
|
|
|
echo $v['sku'] . ' | ' . $v['name']; |
|
|
|
if (!empty($v['numero_de_moteur'])) { |
|
|
|
echo ' | ' . $v['numero_de_moteur']; |
|
|
|
} |
|
|
|
?> |
|
|
|
</option> |
|
|
|
<?php endforeach ?> |
|
|
|
</select> |
|
|
|
</td> |
|
|
|
|
|
|
|
<!-- ✅ COLONNE PUISSANCE VISIBLE --> |
|
|
|
<td> |
|
|
|
<input type="number" |
|
|
|
name="qty[]" |
|
|
|
id="qty_<?php echo $x; ?>" |
|
|
|
class="form-control" |
|
|
|
onkeyup="getTotal(<?php echo $x; ?>)" |
|
|
|
value="<?php echo $val['qty'] ?>" |
|
|
|
autocomplete="off" |
|
|
|
<?php echo !$is_editable ? 'disabled readonly' : 'required'; ?>> |
|
|
|
<input type="number" name="puissance[]" id="puissance_<?php echo $x; ?>" |
|
|
|
class="form-control" placeholder="Puissance" |
|
|
|
value="<?php echo esc($val['puissance'] ?? '1') ?>" |
|
|
|
autocomplete="off" min="1"> |
|
|
|
</td> |
|
|
|
|
|
|
|
<td> |
|
|
|
<input type="text" |
|
|
|
name="rate[]" |
|
|
|
id="rate_<?php echo $x; ?>" |
|
|
|
class="form-control" |
|
|
|
disabled |
|
|
|
value="<?php echo $val['rate'] ?>" |
|
|
|
autocomplete="off"> |
|
|
|
<input type="hidden" |
|
|
|
name="rate_value[]" |
|
|
|
id="rate_value_<?php echo $x; ?>" |
|
|
|
class="form-control" |
|
|
|
value="<?php echo $val['rate'] ?>" |
|
|
|
autocomplete="off"> |
|
|
|
<input type="text" name="rate[]" id="rate_<?php echo $x; ?>" |
|
|
|
class="form-control" disabled |
|
|
|
value="<?php echo esc($val['rate']) ?>" autocomplete="off"> |
|
|
|
<input type="hidden" name="rate_value[]" id="rate_value_<?php echo $x; ?>" |
|
|
|
class="form-control" value="<?php echo esc($val['rate']) ?>" autocomplete="off"> |
|
|
|
</td> |
|
|
|
|
|
|
|
<td> |
|
|
|
<input type="text" |
|
|
|
name="amount[]" |
|
|
|
id="amount_<?php echo $x; ?>" |
|
|
|
class="form-control" |
|
|
|
disabled |
|
|
|
value="<?php echo $val['amount'] ?>" |
|
|
|
autocomplete="off"> |
|
|
|
<input type="hidden" |
|
|
|
name="amount_value[]" |
|
|
|
id="amount_value_<?php echo $x; ?>" |
|
|
|
class="form-control" |
|
|
|
value="<?php echo $val['amount'] ?>" |
|
|
|
autocomplete="off"> |
|
|
|
<input type="text" name="amount[]" id="amount_<?php echo $x; ?>" |
|
|
|
class="form-control" disabled |
|
|
|
value="<?php echo esc($val['amount']) ?>" autocomplete="off"> |
|
|
|
<input type="hidden" name="amount_value[]" id="amount_value_<?php echo $x; ?>" |
|
|
|
class="form-control" value="<?php echo esc($val['amount']) ?>" autocomplete="off"> |
|
|
|
</td> |
|
|
|
|
|
|
|
<td> |
|
|
|
<?php if ($is_editable): ?> |
|
|
|
<button type="button" class="btn btn-default" onclick="removeRow('<?php echo $x; ?>')"> |
|
|
|
<button type="button" class="btn btn-default" |
|
|
|
onclick="removeRow('<?php echo $x; ?>')"> |
|
|
|
<i class="fa fa-close"></i> |
|
|
|
</button> |
|
|
|
<?php endif; ?> |
|
|
|
</td> |
|
|
|
</tr> |
|
|
|
<?php $x++; ?> |
|
|
|
<?php endforeach; ?> |
|
|
|
<?php endif; ?> |
|
|
|
</tbody> |
|
|
|
</tbody> |
|
|
|
</table> |
|
|
|
|
|
|
|
<br /> <br /> |
|
|
|
@ -259,29 +186,8 @@ |
|
|
|
<div class="form-group"> |
|
|
|
<label for="gross_amount" class="col-sm-5 control-label">Prix affiché</label> |
|
|
|
<div class="col-sm-7"> |
|
|
|
<input type="text" |
|
|
|
class="form-control" |
|
|
|
id="gross_amount" |
|
|
|
name="gross_amount" |
|
|
|
disabled |
|
|
|
value="<?php echo $order_data['order']['gross_amount'] ?>" |
|
|
|
autocomplete="off"> |
|
|
|
<input type="hidden" |
|
|
|
class="form-control" |
|
|
|
id="gross_amount_value" |
|
|
|
name="gross_amount_value" |
|
|
|
value="<?php echo $order_data['order']['gross_amount'] ?>" |
|
|
|
autocomplete="off"> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<!-- ✅ ALERTE VISUELLE INTÉGRÉE --> |
|
|
|
<div id="price_alert" style="display: none; margin-bottom: 15px;"> |
|
|
|
<div class="col-sm-offset-5 col-sm-7"> |
|
|
|
<div style="background-color: #f8d7da; border: 1px solid #f5c6cb; color: #721c24; padding: 10px 15px; border-radius: 4px; animation: slideDown 0.3s ease-out;"> |
|
|
|
<i class="fa fa-exclamation-triangle" style="margin-right: 8px;"></i> |
|
|
|
<strong>Attention !</strong> <span id="price_alert_message"></span> |
|
|
|
</div> |
|
|
|
<input type="text" class="form-control" id="gross_amount" name="gross_amount" disabled value="<?php echo $order_data['order']['gross_amount'] ?>" autocomplete="off"> |
|
|
|
<input type="hidden" class="form-control" id="gross_amount_value" name="gross_amount_value" value="<?php echo $order_data['order']['gross_amount'] ?>" autocomplete="off"> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
@ -290,44 +196,19 @@ |
|
|
|
<div class="col-sm-7"> |
|
|
|
<?php |
|
|
|
$users = session()->get('user'); |
|
|
|
if($users && $users['group_name'] == 'COMMERCIALE' && $is_editable): |
|
|
|
if($users && $users['group_name'] == 'COMMERCIALE'): |
|
|
|
?> |
|
|
|
<input type="text" |
|
|
|
class="form-control" |
|
|
|
id="discount" |
|
|
|
name="discount" |
|
|
|
placeholder="Discount" |
|
|
|
onkeyup="subAmount()" |
|
|
|
value="<?php echo $order_data['order']['discount'] ?>" |
|
|
|
autocomplete="off"> |
|
|
|
<input type="text" class="form-control" id="discount" name="discount" placeholder="Discount" onkeyup="subAmount()" value="<?php echo $order_data['order']['discount'] ?>" autocomplete="off"> |
|
|
|
<?php else: ?> |
|
|
|
<input type="text" |
|
|
|
class="form-control" |
|
|
|
id="discount" |
|
|
|
name="discount" |
|
|
|
readonly |
|
|
|
value="<?php echo $order_data['order']['discount'] ?>" |
|
|
|
autocomplete="off"> |
|
|
|
<input type="text" class="form-control" id="discount" name="discount" readonly value="<?php echo $order_data['order']['discount'] ?>" autocomplete="off"> |
|
|
|
<?php endif; ?> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="form-group"> |
|
|
|
<label for="net_amount" class="col-sm-5 control-label">Remise</label> |
|
|
|
<div class="col-sm-7"> |
|
|
|
<input type="text" |
|
|
|
class="form-control" |
|
|
|
id="net_amount" |
|
|
|
name="net_amount" |
|
|
|
disabled |
|
|
|
value="<?php echo $order_data['order']['net_amount'] ?>" |
|
|
|
autocomplete="off"> |
|
|
|
<input type="hidden" |
|
|
|
class="form-control" |
|
|
|
id="net_amount_value" |
|
|
|
name="net_amount_value" |
|
|
|
value="<?php echo $order_data['order']['net_amount'] ?>" |
|
|
|
autocomplete="off"> |
|
|
|
<input type="text" class="form-control" id="net_amount" name="net_amount" disabled value="<?php echo $order_data['order']['net_amount'] ?>" autocomplete="off"> |
|
|
|
<input type="hidden" class="form-control" id="net_amount_value" name="net_amount_value" value="<?php echo $order_data['order']['net_amount'] ?>" autocomplete="off"> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
@ -339,10 +220,7 @@ |
|
|
|
<div class="form-group"> |
|
|
|
<label for="paid_status" class="col-sm-5 control-label">Tranche de paiement</label> |
|
|
|
<div class="col-sm-7"> |
|
|
|
<select class="form-control" |
|
|
|
id="payment_mode" |
|
|
|
name="payment_mode" |
|
|
|
<?php echo !$is_editable ? 'disabled' : ''; ?>> |
|
|
|
<select class="form-control" id="payment_mode" name="payment_mode"> |
|
|
|
<option value="1" selected>une tranche</option> |
|
|
|
<option value="2">deux tranches</option> |
|
|
|
</select> |
|
|
|
@ -362,57 +240,44 @@ |
|
|
|
<div class="form-group" id="paid_status_1" style="display: none"> |
|
|
|
<label for="paid_status_1" class="col-sm-5 control-label">Tranche 1</label> |
|
|
|
<div class="col-sm-3"> |
|
|
|
<select class="form-control" |
|
|
|
id="payment_mode_1" |
|
|
|
name="order_payment_mode_1" |
|
|
|
<?php echo !$is_editable ? 'disabled' : ''; ?>> |
|
|
|
<select class="form-control" id="payment_mode_1" name="order_payment_mode_1"> |
|
|
|
<option value="MVOLA">MVOLA</option> |
|
|
|
<option value="Virement Bancaire">Virement Bancaire</option> |
|
|
|
<option value="En espèce">En espèce</option> |
|
|
|
</select> |
|
|
|
</div> |
|
|
|
<div class="col-sm-4"> |
|
|
|
<input type="number" |
|
|
|
class="form-control" |
|
|
|
id="payment_amount_1" |
|
|
|
name="tranche_1" |
|
|
|
placeholder="Montant" |
|
|
|
onkeyup="calculerTranche2()" |
|
|
|
<?php echo !$is_editable ? 'disabled readonly' : ''; ?>> |
|
|
|
<input type="number" class="form-control" id="payment_amount_1" |
|
|
|
name="tranche_1" placeholder="Montant" onkeyup="calculerTranche2()"> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="form-group" id="paid_status_2" style="display: none"> |
|
|
|
<label for="paid_status_2" class="col-sm-5 control-label">Tranche 2 (Reste)</label> |
|
|
|
<div class="col-sm-3"> |
|
|
|
<select class="form-control" |
|
|
|
id="payment_mode_2" |
|
|
|
name="order_payment_mode_2" |
|
|
|
<?php echo !$is_editable ? 'disabled' : ''; ?>> |
|
|
|
<select class="form-control" id="payment_mode_2" name="order_payment_mode_2"> |
|
|
|
<option value="MVOLA">MVOLA</option> |
|
|
|
<option value="Virement Bancaire">Virement Bancaire</option> |
|
|
|
<option value="En espèce">En espèce</option> |
|
|
|
</select> |
|
|
|
</div> |
|
|
|
<div class="col-sm-4"> |
|
|
|
<input type="number" |
|
|
|
class="form-control" |
|
|
|
id="payment_amount_2" |
|
|
|
name="tranche_2" |
|
|
|
placeholder="Montant" |
|
|
|
readonly> |
|
|
|
<input type="number" class="form-control" id="payment_amount_2" |
|
|
|
name="tranche_2" placeholder="Montant" readonly> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<?php endif; ?> |
|
|
|
|
|
|
|
<?php |
|
|
|
$users = session()->get('user'); |
|
|
|
if ($users && $users['group_name'] !== 'COMMERCIALE'): |
|
|
|
?> |
|
|
|
|
|
|
|
<div class="form-group"> |
|
|
|
<label for="paid_status" class="col-sm-5 control-label">Statut payant</label> |
|
|
|
<div class="col-sm-7"> |
|
|
|
<select type="text" |
|
|
|
class="form-control" |
|
|
|
id="paid_status" |
|
|
|
name="paid_status" |
|
|
|
<?php echo !$is_editable ? 'disabled' : ''; ?>> |
|
|
|
<select type="text" class="form-control" id="paid_status" name="paid_status"> |
|
|
|
<option value="1">Validé</option> |
|
|
|
<option value="2">Refusé</option> |
|
|
|
</select> |
|
|
|
@ -422,64 +287,24 @@ |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<!-- /.box-body --> |
|
|
|
|
|
|
|
<div class="box-footer"> |
|
|
|
<input type="hidden" name="service_charge_rate" value="<?php echo $company_data['service_charge_value'] ?>" autocomplete="off"> |
|
|
|
<input type="hidden" name="vat_charge_rate" value="<?php echo $company_data['vat_charge_value'] ?>" autocomplete="off"> |
|
|
|
|
|
|
|
<a target="__blank" id="Imprimente" href="<?php echo base_url() . 'orders/printDiv/' . $order_data['order']['id'] ?>" class="btn btn-default">Imprimer</a> |
|
|
|
|
|
|
|
<?php if ($is_editable): ?> |
|
|
|
<button type="submit" class="btn btn-primary">Enregistrer</button> |
|
|
|
<?php endif; ?> |
|
|
|
|
|
|
|
<a href="<?php echo base_url('orders/') ?>" class="btn btn-warning">Retour</a> |
|
|
|
</div> |
|
|
|
</form> |
|
|
|
<!-- /.box-body --> |
|
|
|
</div> |
|
|
|
<!-- /.box --> |
|
|
|
</div> |
|
|
|
<!-- col-md-12 --> |
|
|
|
</div> |
|
|
|
<!-- /.row --> |
|
|
|
</section> |
|
|
|
<!-- /.content --> |
|
|
|
</div> |
|
|
|
<!-- /.content-wrapper --> |
|
|
|
|
|
|
|
<style> |
|
|
|
/* ✅ Animation pour l'alerte */ |
|
|
|
@keyframes slideDown { |
|
|
|
from { |
|
|
|
opacity: 0; |
|
|
|
transform: translateY(-10px); |
|
|
|
} |
|
|
|
to { |
|
|
|
opacity: 1; |
|
|
|
transform: translateY(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* ✅ Style pour l'input en erreur */ |
|
|
|
.input-error { |
|
|
|
border: 2px solid #dc3545 !important; |
|
|
|
box-shadow: 0 0 8px rgba(220, 53, 69, 0.5) !important; |
|
|
|
animation: pulse 0.5s ease-in-out; |
|
|
|
} |
|
|
|
|
|
|
|
@keyframes pulse { |
|
|
|
0%, 100% { box-shadow: 0 0 8px rgba(220, 53, 69, 0.5); } |
|
|
|
50% { box-shadow: 0 0 15px rgba(220, 53, 69, 0.8); } |
|
|
|
} |
|
|
|
</style> |
|
|
|
|
|
|
|
<script type="text/javascript"> |
|
|
|
var base_url = "<?php echo base_url(); ?>"; |
|
|
|
var idData = "<?php echo $order_data['order']['id']; ?>"; |
|
|
|
var is_editable = <?php echo $is_editable ? 'true' : 'false'; ?>; |
|
|
|
|
|
|
|
let Imprimente = document.getElementById('Imprimente'); |
|
|
|
let typesCommande = document.getElementById('typesCommande'); |
|
|
|
|
|
|
|
@ -496,77 +321,12 @@ |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// ============================================ |
|
|
|
// 🔹 FONCTION D'ALERTE VISUELLE |
|
|
|
// ============================================ |
|
|
|
function showPriceAlert(message) { |
|
|
|
const alertBox = $('#price_alert'); |
|
|
|
const discountInput = $('#discount'); |
|
|
|
|
|
|
|
$('#price_alert_message').text(message); |
|
|
|
alertBox.slideDown(300); |
|
|
|
discountInput.addClass('input-error'); |
|
|
|
|
|
|
|
setTimeout(function() { |
|
|
|
alertBox.slideUp(300); |
|
|
|
discountInput.removeClass('input-error'); |
|
|
|
}, 3500); |
|
|
|
} |
|
|
|
|
|
|
|
function hidePriceAlert() { |
|
|
|
$('#price_alert').slideUp(300); |
|
|
|
$('#discount').removeClass('input-error'); |
|
|
|
} |
|
|
|
|
|
|
|
// ============================================ |
|
|
|
// 🔹 VALIDATION DU PRIX DEMANDÉ |
|
|
|
// ============================================ |
|
|
|
function validateDiscount() { |
|
|
|
if (!is_editable) return true; // ✅ Pas de validation si non éditable |
|
|
|
|
|
|
|
var discount = parseFloat($('#discount').val()); |
|
|
|
var grossAmount = parseFloat($('#gross_amount_value').val()) || 0; |
|
|
|
|
|
|
|
if (discount < 0) { |
|
|
|
showPriceAlert("Le prix demandé ne peut pas être négatif !"); |
|
|
|
$('#discount').val(''); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (discount > grossAmount) { |
|
|
|
showPriceAlert("Le prix demandé ne peut pas dépasser le prix affiché (" + grossAmount.toFixed(2) + ") !"); |
|
|
|
$('#discount').val(grossAmount.toFixed(2)); |
|
|
|
subAmount(); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
hidePriceAlert(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
$(document).ready(function() { |
|
|
|
$(".select_group").select2(); |
|
|
|
|
|
|
|
$("#mainOrdersNav").addClass('active'); |
|
|
|
$("#manageOrdersNav").addClass('active'); |
|
|
|
|
|
|
|
// ✅ Désactiver toutes les interactions si non éditable |
|
|
|
if (!is_editable) { |
|
|
|
$('input, select, textarea').prop('disabled', true); |
|
|
|
$('#add_row').hide(); |
|
|
|
$('.btn-default[onclick^="removeRow"]').hide(); |
|
|
|
} |
|
|
|
|
|
|
|
// ✅ Validation en temps réel du prix demandé |
|
|
|
if (is_editable) { |
|
|
|
$('#discount').on('keyup change', function() { |
|
|
|
validateDiscount(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// ============================================ |
|
|
|
// 🔹 GESTION DES TRANCHES DE PAIEMENT |
|
|
|
// ============================================ |
|
|
|
var paymentTranche = 1; |
|
|
|
var netAmount = parseFloat($('#net_amount_value').val()) || 0; |
|
|
|
$('#payment_amount_1').val(netAmount); |
|
|
|
@ -587,26 +347,18 @@ |
|
|
|
} |
|
|
|
|
|
|
|
$("#payment_mode").on("change", function() { |
|
|
|
if (is_editable) { |
|
|
|
addPaymentTranche($(this).val()); |
|
|
|
updateMontantTranches(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
$('#payment_amount_1').on("input", function() { |
|
|
|
if (is_editable) { |
|
|
|
var amount1 = parseFloat($(this).val()) || 0; |
|
|
|
var amount2 = netAmount - amount1; |
|
|
|
$('#payment_amount_2').val(amount2); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
addPaymentTranche(paymentTranche); |
|
|
|
|
|
|
|
// ============================================ |
|
|
|
// 🔹 TABLEAU DE PRODUITS |
|
|
|
// ============================================ |
|
|
|
if (is_editable) { |
|
|
|
$("#add_row").unbind('click').bind('click', function() { |
|
|
|
var table = $("#product_info_table"); |
|
|
|
var count_table_tbody_tr = $("#product_info_table tbody tr").length; |
|
|
|
@ -621,15 +373,22 @@ |
|
|
|
'<td>' + |
|
|
|
'<select class="form-control select_group product" data-row-id="' + row_id + '" id="product_' + row_id + '" name="product[]" style="width:100%;" onchange="getProductData(' + row_id + ')">' + |
|
|
|
'<option value=""></option>'; |
|
|
|
|
|
|
|
$.each(response, function(index, value) { |
|
|
|
html += '<option value="' + value.id + '">' + value.name + '</option>'; |
|
|
|
var displayText = value.sku + ' | ' + value.name; |
|
|
|
if (value.numero_de_moteur) { |
|
|
|
displayText += ' | ' + value.numero_de_moteur; |
|
|
|
} |
|
|
|
// ✅ Ne plus afficher la puissance |
|
|
|
html += '<option value="' + value.id + '">' + displayText + '</option>'; |
|
|
|
}); |
|
|
|
|
|
|
|
html += '</select>' + |
|
|
|
'</td>' + |
|
|
|
'<td><input type="number" name="qty[]" id="qty_' + row_id + '" class="form-control" onkeyup="getTotal(' + row_id + ')"></td>' + |
|
|
|
'<td><input type="text" name="rate[]" id="rate_' + row_id + '" class="form-control" disabled><input type="hidden" name="rate_value[]" id="rate_value_' + row_id + '" class="form-control"></td>' + |
|
|
|
'<td><input type="text" name="amount[]" id="amount_' + row_id + '" class="form-control" disabled><input type="hidden" name="amount_value[]" id="amount_value_' + row_id + '" class="form-control"></td>' + |
|
|
|
// ✅ Colonne puissance visible et modifiable |
|
|
|
'<td><input type="text" name="puissance[]" id="puissance_' + row_id + '" class="form-control" placeholder="Puissance" autocomplete="off" value="1"></td>' + |
|
|
|
'<td><input type="text" name="rate[]" id="rate_' + row_id + '" class="form-control numeric-input" disabled min="0"><input type="hidden" name="rate_value[]" id="rate_value_' + row_id + '" class="form-control"><input type="hidden" id="min_price_' + row_id + '" name="min_price[]" value=""></td>' + |
|
|
|
'<td><input type="text" name="amount[]" id="amount_' + row_id + '" class="form-control numeric-input" disabled min="0"><input type="hidden" name="amount_value[]" id="amount_value_' + row_id + '" class="form-control"></td>' + |
|
|
|
'<td><button type="button" class="btn btn-default" onclick="removeRow(\'' + row_id + '\')"><i class="fa fa-close"></i></button></td>' + |
|
|
|
'</tr>'; |
|
|
|
|
|
|
|
@ -644,18 +403,11 @@ |
|
|
|
}); |
|
|
|
|
|
|
|
return false; |
|
|
|
}); |
|
|
|
} |
|
|
|
}); // /document.ready |
|
|
|
}); |
|
|
|
|
|
|
|
// ============================================ |
|
|
|
// 🔹 CALCUL DU TOTAL |
|
|
|
// ============================================ |
|
|
|
function getTotal(row = null) { |
|
|
|
if (!is_editable) return; // ✅ Bloquer si non éditable |
|
|
|
|
|
|
|
if (row) { |
|
|
|
var total = Number($("#rate_value_" + row).val()) * Number($("#qty_" + row).val()); |
|
|
|
var total = Number($("#rate_value_" + row).val()); |
|
|
|
total = total.toFixed(2); |
|
|
|
$("#amount_" + row).val(total); |
|
|
|
$("#amount_value_" + row).val(total); |
|
|
|
@ -665,15 +417,14 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 🔹 OBTENIR LES DONNÉES PRODUIT |
|
|
|
function getProductData(row_id) { |
|
|
|
if (!is_editable) return; // ✅ Bloquer si non éditable |
|
|
|
|
|
|
|
var product_id = $("#product_" + row_id).val(); |
|
|
|
|
|
|
|
if (product_id == "") { |
|
|
|
$("#rate_" + row_id).val(""); |
|
|
|
$("#rate_value_" + row_id).val(""); |
|
|
|
$("#qty_" + row_id).val(""); |
|
|
|
$("#min_price_" + row_id).val(""); |
|
|
|
$("#puissance_" + row_id).val("1"); // ✅ Réinitialiser à 1 |
|
|
|
$("#amount_" + row_id).val(""); |
|
|
|
$("#amount_value_" + row_id).val(""); |
|
|
|
} else { |
|
|
|
@ -683,26 +434,39 @@ |
|
|
|
data: { product_id: product_id }, |
|
|
|
dataType: 'json', |
|
|
|
success: function(response) { |
|
|
|
$("#rate_" + row_id).val(response.price); |
|
|
|
$("#rate_value_" + row_id).val(response.price); |
|
|
|
$("#qty_" + row_id).val(1); |
|
|
|
$("#qty_value_" + row_id).val(1); |
|
|
|
var total = Number(response.price) * 1; |
|
|
|
console.log('✅ Response:', response); // Debug |
|
|
|
|
|
|
|
var prixVente = parseFloat(response.prix_vente) || 0; |
|
|
|
var prixMinimal = parseFloat(response.prix_minimal) || 0; |
|
|
|
|
|
|
|
if (prixVente < 0) prixVente = 0; |
|
|
|
if (prixMinimal < 0) prixMinimal = 0; |
|
|
|
|
|
|
|
$("#rate_" + row_id).val(prixVente); |
|
|
|
$("#rate_value_" + row_id).val(prixVente); |
|
|
|
$("#min_price_" + row_id).val(prixMinimal); |
|
|
|
|
|
|
|
// ✅ CORRECTION : Remplir la puissance |
|
|
|
var puissanceValue = response.puissance || '1'; |
|
|
|
console.log('✅ Puissance extraite:', puissanceValue); // Debug |
|
|
|
$("#puissance_" + row_id).val(puissanceValue); |
|
|
|
|
|
|
|
// ✅ Calculer le montant (prix * puissance) |
|
|
|
var total = prixVente * 1; // Pour l'instant on garde qty=1 |
|
|
|
total = total.toFixed(2); |
|
|
|
$("#amount_" + row_id).val(total); |
|
|
|
$("#amount_value_" + row_id).val(total); |
|
|
|
|
|
|
|
subAmount(); |
|
|
|
}, |
|
|
|
error: function(xhr, status, error) { |
|
|
|
console.error('❌ Erreur AJAX:', error); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ============================================ |
|
|
|
// 🔹 CALCUL DU MONTANT TOTAL (AVEC TVA, REMISE, ETC.) |
|
|
|
// ============================================ |
|
|
|
function subAmount() { |
|
|
|
if (!is_editable) return; // ✅ Bloquer si non éditable |
|
|
|
|
|
|
|
var service_charge = <?php echo ($company_data['service_charge_value'] > 0) ? $company_data['service_charge_value'] : 0; ?>; |
|
|
|
var vat_charge = <?php echo ($company_data['vat_charge_value'] > 0) ? $company_data['vat_charge_value'] : 0; ?>; |
|
|
|
|
|
|
|
@ -734,12 +498,10 @@ |
|
|
|
|
|
|
|
var discount = $("#discount").val(); |
|
|
|
if (discount) { |
|
|
|
if (validateDiscount()) { |
|
|
|
var grandTotal = Number(totalAmount) - Number(discount); |
|
|
|
grandTotal = grandTotal.toFixed(2); |
|
|
|
$("#net_amount").val(grandTotal); |
|
|
|
$("#net_amount_value").val(grandTotal); |
|
|
|
} |
|
|
|
} else { |
|
|
|
$("#net_amount").val(totalAmount); |
|
|
|
$("#net_amount_value").val(totalAmount); |
|
|
|
@ -756,12 +518,7 @@ |
|
|
|
updateMontantTranches(); |
|
|
|
} |
|
|
|
|
|
|
|
// ============================================ |
|
|
|
// 🔹 AUTRES FONCTIONS |
|
|
|
// ============================================ |
|
|
|
function paidAmount() { |
|
|
|
if (!is_editable) return; |
|
|
|
|
|
|
|
var grandTotal = $("#net_amount_value").val(); |
|
|
|
if (grandTotal) { |
|
|
|
var dueAmount = Number($("#net_amount_value").val()) - Number($("#paid_amount").val()); |
|
|
|
@ -772,15 +529,10 @@ |
|
|
|
} |
|
|
|
|
|
|
|
function removeRow(tr_id) { |
|
|
|
if (!is_editable) return; // ✅ Bloquer si non éditable |
|
|
|
|
|
|
|
$("#product_info_table tbody tr#row_" + tr_id).remove(); |
|
|
|
subAmount(); |
|
|
|
} |
|
|
|
|
|
|
|
// ============================================ |
|
|
|
// 🔹 GESTION MONTANT DE TRANCHES |
|
|
|
// ============================================ |
|
|
|
function getMontantPourTranches() { |
|
|
|
var discount = parseFloat($("#discount").val()) || 0; |
|
|
|
var grossAmount = parseFloat($("#gross_amount_value").val()) || 0; |
|
|
|
@ -788,8 +540,6 @@ |
|
|
|
} |
|
|
|
|
|
|
|
function updateMontantTranches() { |
|
|
|
if (!is_editable) return; |
|
|
|
|
|
|
|
var montant = getMontantPourTranches(); |
|
|
|
var discount = parseFloat($("#discount").val()) || 0; |
|
|
|
|
|
|
|
@ -808,8 +558,6 @@ |
|
|
|
} |
|
|
|
|
|
|
|
function calculerTranche2() { |
|
|
|
if (!is_editable) return; |
|
|
|
|
|
|
|
var montantTotal = getMontantPourTranches(); |
|
|
|
var tranche1 = parseFloat($("#payment_amount_1").val()) || 0; |
|
|
|
var tranche2 = montantTotal - tranche1; |
|
|
|
@ -817,16 +565,12 @@ |
|
|
|
$("#payment_amount_2").val(tranche2.toFixed(2)); |
|
|
|
} |
|
|
|
|
|
|
|
if (is_editable) { |
|
|
|
$("#discount").on('keyup', function() { |
|
|
|
updateMontantTranches(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
const net_amount_value = document.getElementById('net_amount_value'); |
|
|
|
const net_amount = document.getElementById('net_amount'); |
|
|
|
const payment_amount_1 = document.getElementById('payment_amount_1'); |
|
|
|
if (payment_amount_1 && net_amount) { |
|
|
|
payment_amount_1.value = net_amount.value; |
|
|
|
} |
|
|
|
</script> |