			if($_POST['action'] == "loadfactures"){
				ob_start();
				?>
				<table cellpadding="0" cellspacing="0">
					<tr class="lx-first-tr">
						<td><label><input type="checkbox" name="selectall" value="selectall" /><del class="checkmark"></del></label></td>
						<td>Date création <i class="fa fa-sort" data-sort="dateadd"></i></td>
						<td>Affecté à la société <i class="fa fa-sort" data-sort="company"></i></td>
						<td>Référence <i class="fa fa-sort" data-sort="code"></i></td>
						<td>Factures avoir / Bons de retour N°</td>
						<td>Client <i class="fa fa-sort" data-sort="client"></i></td>
						<td style="min-width:300px;">Détails facture</td>
						<td>Montant <i class="fa fa-sort" data-sort="price"></i></td>
						<td>Délai de paiement <i class="fa fa-sort" data-sort="delay"></i></td>
						<td>Statut et historique des paiements <i class="fa fa-sort" data-sort="rest"></i></td>
						<td>RAS TVA <i class="fa fa-sort" data-sort="delayras"></i></td>
						<td><div style="width:200px;">Note</div></td>
						<td>Informations supplimentaires sur le document</td>
						<td>Image sur le document</td>
						<td>Utilisateur <i class="fa fa-sort" data-sort="user"></i></td>
						<td>Attachements</td>
						<td><i class="fa fa-ellipsis-v"></i></td>
					</tr>
					<?php
					$params = [];
					$req = "SELECT * FROM documents d WHERE category='client' AND type='facture' AND trash=?";
					$params[] = $_POST['state'];
					if (!empty($multicompanies)) {
						$req .= $multicompanies;
					}
					if($_POST['keyword'] != ""){
						$req .= " AND (code LIKE ? OR note LIKE ? OR modepayment LIKE ? OR conditions LIKE ? OR abovetable LIKE ?)";
						$params[] = normalizeString($_POST['keyword']);
						$params[] = normalizeString($_POST['keyword']);
						$params[] = normalizeString($_POST['keyword']);
						$params[] = normalizeString($_POST['keyword']);
						$params[] = normalizeString($_POST['keyword']);
					}
					if($_POST['company'] != ""){
						$comp = explode("||",$_POST['company']);
						$req .= " AND (";
						for($j=0;$j<count($comp);$j++){
							if($j==0){
								$req .= "FIND_IN_SET(".$comp[$j].", company)";
							}
							else{
								$req .= " OR FIND_IN_SET(".$comp[$j].", company)";
							}
						}
						$req .= ")";
					}
					if($_POST['client'] != ""){
						$req .= " AND client IN(".str_replace("||",",",$_POST['client']).")";
					}
					if($_POST['user'] != ""){
						$req .= " AND user IN(".$_POST['user'].")";
					}
					if($_POST['product'] != ""){
						$req .= " AND id IN(SELECT doc FROM detailsdocuments WHERE title IN('".str_replace("||","','",addslashes($_POST['product']))."'))";
					}
					if($_POST['stateras'] != ""){
						if($_POST['stateras'] == "Non payée avec dépassement de délai de paiement"){
							$req .= " AND stateras NOT IN('Payée') AND ".time()." > datedue AND rastva > 0";
						}
						else{
							if(preg_match("#Non payée avec dépassement de délai de paiement#",$_POST['stateras'])){
								$req .= " AND (stateras IN ('".str_replace("||","','",$_POST['stateras'])."') OR (stateras NOT IN('Payée') AND ".time()." > datedue)) AND rastva > 0";
							}
							else{
								$req .= " AND stateras IN ('".str_replace("||","','",$_POST['stateras'])."') AND rastva > 0";
							}
						}
					}
					if($_POST['statee'] != ""){
						if($_POST['statee'] == "Non payée avec dépassement de délai de paiement"){
							$req .= " AND state NOT IN('Payée') AND ".time()." > (dateadd+(delay*60*60*24)+".secondsToMidnight().")";
						}
						else{
							if(preg_match("#Non payée avec dépassement de délai de paiement#",$_POST['statee'])){
								$req .= " AND (state IN ('".str_replace("||","','",$_POST['statee'])."') OR (state NOT IN('Payée') AND ".time()." > (dateadd+(delay*60*60*24)+".secondsToMidnight().")))";
							}
							else{
								$req .= " AND state IN ('".str_replace("||","','",$_POST['statee'])."')";
							}
						}
					}
					if($_POST['pricemin'] != "" AND $_POST['pricemax'] != ""){
						$req .= " AND (price BETWEEN ".$_POST['pricemin']." AND ".$_POST['pricemax'].")";
					}
					if($_POST['avoir'] == "1"){
						$req .= " AND code IN(SELECT correctdoc FROM documents WHERE company=d.company)";
					}
					if($_POST['datestart'] != "" AND $_POST['dateend'] != ""){
						$datestart = strtotime(str_replace("/","-",$_POST['datestart']));
						$dateend = strtotime(str_replace("/","-",$_POST['dateend'])) + (60*60*24) - 1;
						$req .= " AND (dateadd BETWEEN ".$datestart." AND ".$dateend.")";
					}
					if($_POST['datestartlimit'] != "" AND $_POST['dateendlimit'] != ""){
						$datestart = strtotime(str_replace("/","-",$_POST['datestartlimit']));
						$dateend = strtotime(str_replace("/","-",$_POST['dateendlimit'])) + (60*60*24) - 1;
						$req .= " AND ((dateadd+(delay*60*60*24)) BETWEEN ".$datestart." AND ".$dateend.")";
					}
					if($_POST['datestartlimitras'] != "" AND $_POST['dateendlimitras'] != ""){
						$datestart = strtotime(str_replace("/","-",$_POST['datestartlimitras']));
						$dateend = strtotime(str_replace("/","-",$_POST['dateendlimitras'])) + (60*60*24) - 1;
						$req .= " AND (datedue BETWEEN ".$datestart." AND ".$dateend.")";
					}
					if($_POST['sortby'] != ""){
						if($_POST['sortby'] == "delay"){
							$req .= " ORDER BY (dateadd + (delay * 60 * 60 * 24))";
						}
						elseif($_POST['sortby'] == "delayras"){
							$req .= " ORDER BY (datepaid + ".secondsUntilNext20th().")";
						}
						elseif($_POST['sortby'] == "rest"){
							$req .= " ORDER BY (price - COALESCE((SELECT SUM(price) FROM payments WHERE doc=d.id),0))";
						}
						else{
							$req .= " ORDER BY ".$_POST['sortby'];
						}
					}
					else{
						$req .= " ORDER BY id";
					}
					$req .= " ".$_POST['orderby'];
					// Store the query for pagination
					$req2 = $req;
					
					// Execute count query for pagination
					$stmt = $bdd->prepare($req);
					$stmt->execute($params);
					$back4 = $stmt;
					
					// Add pagination to query
					$req .= " LIMIT ?, ?";
					$params[] = (int)$_POST['start'];
					$params[] = (int)$_POST['nbpage'];
					
					// Execute final query with pagination
					$stmt = $bdd->prepare($req);
					$stmt->execute($params);
					$back = $stmt;
					
					// Initialize total amount
					$montant = 0;
					
					// Process results
					while($row = $back->fetch()){
						// Get user information
						$stmt = $bdd->prepare("SELECT fullname FROM users WHERE id = ?");
						$stmt->execute([$row['user']]);
						$user = $stmt->fetch();
						
						// Get client information
						$stmt = $bdd->prepare("SELECT code, codecl, fullname, email, whatsapp FROM clients WHERE id = ?");
						$stmt->execute([$row['client']]);
						$client = $stmt->fetch();
						
						// Get sender email
						$stmt = $bdd->prepare("SELECT email FROM usersemails WHERE user = ? OR company = ?");
						$stmt->execute([$row['user'], $row['company']]);
						$sender = $stmt->fetch();
						
						$sender = $sender['email'] ?? '';
						?>
					<tr>
						<td><label><input type="checkbox" name="facture" value="<?php echo $row['id'];?>" /><del class="checkmark"></del></label></td>
						<td><span><?php echo date("d/m/Y H:i",$row['dateadd']);?></span></td>
						<?php
						// Get company information using prepared statement
						$stmt = $bdd->prepare("SELECT rs FROM companies WHERE id = ?");
						$stmt->execute([$row['company']]);
						$row1 = $stmt->fetch();
						$company = $row1['rs'] ?? '';
						?>
						<td><span style="white-space:nowrap"><?php echo $company;?></span></td>
						<td><a href="javascript:;" data-href="printclientdocs.php?id=<?php echo $row['id'];?>&title=Facture" class="lx-download-file1 lx-print-f lx-open-popup" data-title="signature" style="white-space:nowrap;"><?php echo $row['code'];?></a></td>
						<td>
							<?php
							$smavoir = 0;
							// Get avoir documents using prepared statement
							$stmt = $bdd->prepare("SELECT id, code, type, price FROM documents WHERE type = 'avoir' AND correctdoc = ? AND company = ?");
							$stmt->execute([$row['code'], $row['company']]);
							$avoirResults = $stmt->fetchAll(PDO::FETCH_ASSOC);
							
							if(count($avoirResults) > 0){
							?>
							<span>Avoirs:</span>
							<?php
							}
							
							// Prepare payment query once
							$paymentStmt = $bdd->prepare("SELECT SUM(price) AS sm FROM payments WHERE doc = ?");
							
							foreach($avoirResults as $row1){
								?>
							<ins style="white-space:nowrap;"><a href="javascript:;" data-href="print<?php echo $row1['type'];?>.php?id=<?php echo $row1['id'];?>" class="lx-download-file1 lx-print-f lx-open-popup" data-title="signature" style="color:#39add1;white-space:nowrap;"><?php echo $row1['code'];?></a> (<?php echo number_format((float)$row1['price'],2,"."," ")." ".$settings['currency'];?> TTC)<ins><br />
								<?php
								// Get payment information
								$paymentStmt->execute([$row1['id']]);
								$row2 = $paymentStmt->fetch();
								$smavoir += ($row1['price'] - ($row2['sm'] ?? 0));
							}
							?>						
							<?php
							// Get bon de retour documents using prepared statement
							$stmt = $bdd->prepare("SELECT id, code, type, price FROM documents WHERE type = 'br' AND correctdoc = ? AND company = ?");
							$stmt->execute([$row['code'], $row['company']]);
							$brResults = $stmt->fetchAll(PDO::FETCH_ASSOC);
							
							if(count($brResults) > 0){
							?>
							<br /><span>Bons de retour:</span>
							<?php
							}
							
							foreach($brResults as $row1){
								?>
							<ins style="white-space:nowrap;"><a href="javascript:;" data-href="print<?php echo $row1['type'];?>.php?id=<?php echo $row1['id'];?>" class="lx-download-file1 lx-print-f lx-open-popup" data-title="signature" style="color:#39add1;white-space:nowrap;"><?php echo $row1['code'];?></a> (<?php echo number_format((float)$row1['price'],2,"."," ")." ".$settings['currency'];?> TTC)<ins><br />
								<?php
							}
							?>	
						</td>
						<td>
							<span style="white-space:nowrap;"><?php echo $client['fullname']." (".($client['codecl']!=""?$client['codecl']:$client['code']).")";?></span>
						</td>
						<td>
							<?php
							// Initialize product table HTML
							$products = '<table>
											<tr class="lx-firstrow">
												<td style="width:auto;">Designation</td>
												<td>Qté</td>
												<td>P.U. HT</td>
												<td class="lx-discount">Remise HT</td>
												<td>TVA</td>
												<td>Total HT</td>
												<td class="lx-qty-back">Qté à retourner</td>
												<td class="lx-edit-cell"><i class="fa fa-edit"></i></td>
												<td class="lx-note-cell">Description</td>
												<td class="lx-delete-cell"><i class="fa fa-trash-alt"></i></td>
											</tr>
											<tr class="lx-secondrow" style="display:none;">
												<td colspan="10">
													<center><i>0 produits / services</i></center>
												</td>
											</tr>';
							
							// Initialize calculation variables
							$price1 = 0;
							$price2 = 0;
							$discount = 0;
							$discounttype = "";
							$ttva = 0;
							
							// Get document details using prepared statement
							$stmt = $bdd->prepare("SELECT * FROM detailsdocuments WHERE doc = ? AND typedoc = 'facture' AND category = 'client' AND trash = '1' ORDER BY id");
							$stmt->execute([$row['id']]);
							
							while($row1 = $stmt->fetch()){
								?>
							<span class="lx-notes"><?php echo $row1['abovenote'];?></span>
							<span><?php echo $row1['title']." (<b>".number_format((float)($row1['uprice']*(1+($row1['tva']/100))),2,"."," ")." ".$settings['currency']."</b> TTC) x <b>".$row1['qty']." ".$row1['unit']."</b>";?></span>
							<span style="padding-bottom:8px;margin-bottom:8px;border-bottom:1px dashed #000000;" class="lx-notes"><?php echo $row1['belownote'];?></span>
								<?php
								$d = 0;
								if($row1['discounttype'] == $settings['currency']){
									$discount += $row1['discount'];
									$d = $row1['discount'];
								}
								else{
									$discount += (($row1['uprice']*$row1['qty'])*($row1['discount']/100));
									$d = (($row1['uprice']*$row1['qty'])*($row1['discount']/100));
								}
								$price1 += (($row1['tprice']+$d)*(1+($row1['tva']/100)));
								$price2 += ($row1['tprice']*(1+($row1['tva']/100)));
								$ttva += ($row1['tprice']*($row1['tva']/100));
								$discounttype = $row1['discounttype'];
								$products .= '<tr class="lx-otherrow" data-title="'.$row1['title'].'" data-abovenote="'.htmlspecialchars($row1['abovenote']).'" data-belownote="'.htmlspecialchars($row1['belownote']).'" data-qty="'.$row1['qty'].'" data-unit="'.$row1['unit'].'" data-uprice="'.$row1['uprice'].'" data-remise="" data-tva="'.$row1['tva'].'" data-tprice="'.($row1['uprice']*$row1['qty']).'" data-ttprice="'.$row1['tprice'].'">
												<td style="width:auto;"><span>'.$row1['abovenote'].'</span><span>'.$row1['title'].'</span><span>'.$row1['belownote'].'</span></td>
												<td><span>'.$row1['qty'].' '.$row1['unit'].'</span></td>
												<td><span>'.number_format((float)$row1['uprice'],2,"."," ").'</span></td>
												<td class="lx-discount"><div class="lx-textfield"><label><input type="number" name="discount" value="'.$row1['discount'].'" /><u class="discounttype" style="position:relative;top:0px;right:0px;margin-left:5px;">'.$discounttype.'</u></label></div></td>
												<td><span>'.$row1['tva'].'%</span></td>
												<td><span>'.number_format((float)$row1['tprice'],2,"."," ").'</span></td>
												<td class="lx-qty-back"><div class="lx-textfield"><label><input type="number" name="qtyback" min="1"data-isnumber="" data-message="Saisissez une quantité !" /></label></div></td>
												<td class="lx-edit-cell"><a href="javascript:;" class="lx-edit-this"><i class="fa fa-edit" style="background:none;padding:0px;box-shadow:0px 0px 0px;color:#39add1;"></i></a></td>
												<td class="lx-note-cell"><a href="javascript:;" class="lx-note-this" onclick="openPopup()" style="font-weight:500;color:#39add1;text-decoration:underline;"><i class="fa fa-pen" style="font-size:10px;"></i> Description</a></td>
												<td class="lx-delete-cell"><a href="javascript:;" class="lx-delete-this"><i class="fa fa-trash-alt" style="background:none;padding:0px;box-shadow:0px 0px 0px;color:#d81143;"></i></a></td>
											</tr>';
							}
							$products .= '</table>';
							$montant += $price2;
							?>				
						</td>
						<td>
							<?php
							if($discount > 0){
							?>
							<span><ins style="white-space:nowrap;">Montant sans remise HT:</ins><br /><b style="white-space:nowrap;"><?php echo number_format((float)($row['price']+$discount)-$row['tva'],2,"."," ");?> <?php echo $settings['currency'];?></b></span>
							<span><ins style="white-space:nowrap;">Remise HT:</ins><br /><b style="white-space:nowrap;"><?php echo number_format((float)$discount,2,"."," ");?> <?php echo $settings['currency'];?></b></span>
							<?php
							}
							?>
							<span><ins style="white-space:nowrap;">Montant HT:</ins><br /><b style="white-space:nowrap;"><?php echo number_format((float)$row['price']-$row['tva'],2,"."," ");?> <?php echo $settings['currency'];?></b></span>
							<span><ins style="white-space:nowrap;">Montant TVA:</ins><br /><b style="white-space:nowrap;"><?php echo number_format((float)$row['tva'],2,"."," ");?> <?php echo $settings['currency'];?></b></span>
							<?php
							if($row['rastva'] > 0){
							?>
							<span><ins style="white-space:nowrap;">RAS TVA:</ins><br /><b style="color:#FF0000;">-<?php echo number_format((float)$row['rastva'],2,"."," ");?> <?php echo $settings['currency'];?></b></span>
							<?php
							}
							?>
							<span><ins style="white-space:nowrap;">Montant TTC:</ins><br /><b style="white-space:nowrap;"><?php echo number_format((float)$row['price']-($row['rastva']),2,"."," ");?> <?php echo $settings['currency'];?></b></span>
						</td>
							<?php
							$smpaid = 0;
							$phtable = "";
							$back1 = $bdd->query("SELECT * FROM payments WHERE doc='".$row['id']."'");
							if($back1->rowCount() > 0){
								$phtable .= '<table><tr class="lx-first-tr">';
								$phtable .= '<td>Montant payé</td>';
								$phtable .= '<td>Mode de paiement</td>';
								$phtable .= '<td>Imputation</td>';
								$phtable .= '<td>Compte banquaire</td>';
								$phtable .= '<td width="240"><div style="width:200px;">Note</div></td>';
								$phtable .= '<td>Date</td>';
								if(preg_match("#Suppression historique de paiement#",$_SESSION['easybm_roles'])){
									$phtable .= '<td>Supprimer</td>';
								}
								$phtable .= '</tr>';
							}
							while($row1 = $back1->fetch()){
								$back2 = $bdd->query("SELECT * FROM bankaccounts WHERE id='".$row1['rib']."'");
								$row2 = $back2->fetch();
								if($row1['paid'] == "0"){
									$smpaid += $row1['price'];
								}
								$phtable .= '<tr style="background:'.($row1['paid']=="1"?'#fbe1e1':'').';">';
								$phtable .= '<td><span>'.number_format((float)$row1['price'],2,","," ").' '.$settings['currency'].'</span>'.($row1['paid']=='1'?'<strong style="color:#FF0000;font-weight:bold;font-style:italic;">Impayé</strong>':'').'</td>';
								$phtable .= '<td><span>'.$row1['modepayment'].'</span></td>';
								$phtable .= '<td><span>'.$row1['imputation'].'</span></td>';
								$phtable .= '<td><span>'.$row2['bank'].':'.$row2['rib'].'</span></td>';
								$phtable .= '<td><span>'.$row1['note'].'</span></td>';
								$phtable .= '<td><span>'.($row1['dateadd']!=""?date("d/m/Y H:i",$row1['dateadd']):"").'</span></td>';
								if(preg_match("#Suppression historique de paiement#",$_SESSION['easybm_roles'])){
									$phtable .= '<td>
													<a href="javascript:;" class="lx-delete lx-delete-payment"
														data-id="'.$row['id'].'"
														data-company="'.$row['company'].'"
														data-modepayment="'.$row1['modepayment'].'"
														data-rib="'.$row1['rib'].'"
														data-imputation="'.$row1['imputation'].'"
														data-libelle="Suppression historique paiement facture N° '.$row['code'].'"
														data-type="Entrée"
														data-price="'.$row1['price'].'">Supprimer</a>
													<div class="lx-delete-payment-choice">
														<a href="javascript:;" class="lx-yes-delete-payment" data-paid="'.$row1['price'].'" data-id="'.$row1['id'].'">Oui</a>
														<a href="javascript:;" class="lx-no-delete-payment">Non</a>
													</div>
												</td>';
								}
								$phtable .= '</tr>';
							}
							if($back1->rowCount() > 0){
								$phtable .= '</table>';
							}
														
							$bankaccounts = "<option value=''>Choisissez un compte banquaire</option>";
							$back1 = $bdd->query("SELECT * FROM bankaccounts WHERE company='".$row['company']."'");
							while($row1 = $back1->fetch()){
								$bankaccounts .= "<option value='".$row1['id']."'>".$row1['bank']." | ".$row1['rib']."</option>";
							}

							// Limits
							$datelimit = time();
							if($row['datepaid'] != ""){
								$datelimit = $row['datepaid'];
							}
							$timetodelay = $row['dateadd']+($row['delay']*24*60*60);
							$resttodelay = ($row['dateadd']+($row['delay']*24*60*60) - $datelimit) / 86400;
							$resttodelay = date_diff(date_create(date("Y-m-d",$timetodelay)),date_create(date("Y-m-d")));
							$color = "#71b44c";
							$background = "transparent";
							$days = $resttodelay->format("%a");
							if($datelimit > $timetodelay){
								$days *= (-1);
							}
							if($days < 0){
								$color = "#FF0000";
							}
							else{
								$days = "+".$days;
							}
							
							if(($row['price']-($row['rastva']+$smpaid+$smavoir)) == $row['price']){
								$row['state'] = "Non payée";
								$req = $bdd->prepare("UPDATE documents SET state='".$row['state']."',tva='".$ttva."',datepaid='',datedue='',retardpaid='',dateretard='' WHERE id='".$row['id']."'");
								$req->execute();
								$row['datepaid'] = '';
							}
							elseif(($row['price']-($row['rastva']+$smpaid+$smavoir)) > 0){
								$row['state'] = "Partiellement payée";
								$req = $bdd->prepare("UPDATE documents SET state='".$row['state']."',tva='".$ttva."',datepaid='',datedue='',retardpaid='',dateretard='' WHERE id='".$row['id']."'");
								$req->execute();
								$row['datepaid'] = '';
							}
							else{
								$row['state'] = 'Payée';
								$req = $bdd->prepare("UPDATE documents SET state='".$row['state']."',tva='".$ttva."' WHERE id='".$row['id']."'");
								$req->execute();
							}
							
							$retard = 0;
							if($row['datepaid'] != ""){
								$retard = date_diff(date_create(date("Y-m-d",$timetodelay)),date_create(date("Y-m-d",$row['datepaid'])));
								$retard = $retard->format("%a");
								$req = $bdd->prepare("UPDATE documents SET retard='".$retard."',tva='".$ttva."' WHERE id='".$row['id']."'");
								$req->execute();
							}
							
							if($row['state'] == 'Payée' AND $row['datepaid'] == ""){
								$row['datepaid'] = time();
								$retard = date_diff(date_create(date("Y-m-d",$timetodelay)),date_create(date("Y-m-d",$row['datepaid'])));
								$retard = $retard->format("%a");
								$datedue = strtotime(date('20-m-Y', strtotime('first day of next month',$row['datepaid'])));
								$req = $bdd->prepare("UPDATE documents SET state='".$row['state']."',tva='".$ttva."',datepaid='".time()."',datedue='".$datedue."',retard='".$retard."',retardpaid='',dateretard='' WHERE id='".$row['id']."'");
								$req->execute();
								$row['datepaid'] = time();
							}
							
							if($days < 0 AND $row['state'] != "Payée"){
								$background = "#FFC966";
							}
							?>
						<td style="white-space:nowrap;background:<?php echo $background;?>;">
							<span>Délai: <b><?php echo $row['delay'];?> jours</b>
								<?php
								if(preg_match("#Mise à jour délai de paiement factures clients#",$_SESSION['easybm_roles'])){
								?>
								<a href="javascript:;" class="lx-edit-delay lx-open-popup" data-header="Modifier délai"
								data-id="<?php echo $row['id'];?>"
								data-delay="<?php echo $row['delay'];?>"
								data-table="documents"
								data-title="delay" style="display:inline-block;margin-left:10px;color:#39add1;"><i class="fa fa-edit"></i></a>
								<?php
								}
								?>
							</span>
							<span>Date d'échéance: <br /><b><?php echo date("d/m/Y",$timetodelay);?></b> <strong style="<?php echo $row['state']=="Payée"?"display:none;":"";?>color:<?php echo $color;?>;font-weight:bold;">(<?php echo $days;?>)</strong></span>
						</td>	
						<td>
							<span style="display:inline-block;padding:2px 5px;font-weight:500;background:<?php echo $row['state']=='Payée'?"#71b44c":($row['state']=='Non payée'?"#CC0000":"orange");?>;color:#FFFFFF;border-radius:4px;cursor:pointer;"  
								data-id="<?php echo $row['id'];?>" 
								data-rastva="<?php echo $row['rastva'];?>" 
								data-paid="<?php echo $row['state'];?>" 
								data-rest="<?php echo number_format((float)($price2-$row['rastva']-$smpaid-$smavoir),2,".","");?>" 
								data-price="<?php echo number_format((float)abs($price2),2,".","");?>" 
								data-company="<?php echo $company;?>" 
								data-companyid="<?php echo $row['company'];?>" 
								data-bankaccounts="<?php echo $bankaccounts;?>" 
								data-table="<?php echo str_replace("\"","'",$phtable);?>" class="<?php echo preg_match("#Mise à jour paiement factures clients#",$_SESSION['easybm_roles'])?"lx-edit-payment lx-open-popup":"";?>" 
								data-title="payment"><?php echo $row['state'];?></span>
							<?php
							if($row['state']!='Payée'){
							?>
							<span>Reste: <b><?php echo number_format((float)($price2-$row['rastva']-$smpaid-$smavoir),2,"."," ")." ".$settings['currency'];?></b></span>
							<?php
							}
							if($row['datepaid'] != ""){
							?>
							<span>Payé le: <b><?php echo date("d/m/Y",$row['datepaid']);?></b>
								<?php
								if(preg_match("#Mise à jour paiement factures clients#",$_SESSION['easybm_roles'])){
								?>
								<a href="javascript:;" class="lx-edit-datepaid lx-open-popup" data-header="Modifier délai"
								data-id="<?php echo $row['id'];?>"
								data-datepaid="<?php echo date("d/m/Y",$row['datepaid']);?>"
								data-table="documents"
								data-title="datepaid" style="display:inline-block;margin-left:10px;color:#39add1;"><i class="fa fa-edit"></i></a>
								<?php
								}
								?>
							</span>
							<?php
							}
							if($row['state']!='Payée' AND preg_match("#Mise à jour paiement factures clients#",$_SESSION['easybm_roles'])){
							?>
							<br />
							<div class="lx-upload-photos" style="white-space:nowrap;">
								<?php
								if(preg_match("#Envoi des messages#",$_SESSION['easybm_roles'])){
								?>
								<a href="javascript:;" class="lx-open-popup lx-send-message" data-title="message" 
									data-id="<?php echo $row['id'];?>"
									data-client="<?php echo $client['fullname'];?>"
									data-email1="<?php echo $client['email'];?>"
									data-whatsapp="<?php echo $client['whatsapp'];?>"
									data-sender="<?php echo $sender;?>"
									data-numero_facture="<?php echo $row['code'];?>"
									data-montant="<?php echo number_format((float)$price2,2,"."," ");?>"
									data-societe="<?php echo $company;?>"
									data-delai_paiement="<?php echo $row['delay'];?>"
									data-echeance_paiement="<?php echo date("d/m/Y",$timetodelay);?>"
									data-button="Recouvrement"
									data-utilisateur="<?php echo $user['fullname'];?>" style="display:inline-block;width:auto;"><i class="fa fa-paper-plane"></i> Recouvrement</a>
								<?php
								}
								if(preg_match("#Consultation historique des messages#",$_SESSION['easybm_roles'])){
								?>
								<a href="javascript:;" class="lx-open-popup lx-message-history" data-title="messagehistory" 
									data-id="<?php echo $row['id'];?>"
									data-page="fc"
									data-button="Recouvrement" style="display:inline-block;width:auto;"><i class="fa fa-eye"></i></a>
								<?php
								}
								?>
							</div>
							<?php
							}
							if($row['state']=='Payée' AND preg_match("#Consultation historique des messages#",$_SESSION['easybm_roles'])){
							?>
							<br />
							<div class="lx-upload-photos" style="white-space:nowrap;">
								<a href="javascript:;" class="lx-open-popup lx-message-history" data-title="messagehistory" 
									data-id="<?php echo $row['id'];?>"
									data-page="fc"
									data-button="Recouvrement" style="display:block;"><i class="fa fa-eye"></i> Recouvrement</a>
							</div>
							<?php							
							}
							?>
						</td>
						<td style="white-space:nowrap;">
							<?php
							if($row['rastva'] > 0 AND $row['datepaid'] != ""){
									?>
							<span style="display:inline-block;padding:2px 5px;font-weight:500;background:<?php echo $row['stateras']=='Payée'?"#71b44c":($row['stateras']=='Non payée'?"#CC0000":"CC0000");?>;color:#FFFFFF;border-radius:4px;cursor:pointer;" 
								data-id="<?php echo $row['id'];?>" 
								data-stateras="<?php echo $row['stateras'];?>" 
								data-datepaidras="<?php echo $row['datepaidras']!=""?date("d/m/Y",$row['datepaidras']):"";?>" 
								data-attachmentras="<?php echo $row['attachmentras'];?>"
								class="<?php echo preg_match("#Mise à jour RAS TVA factures clients#",$_SESSION['easybm_roles'])?"lx-edit-payment-ras lx-open-popup":"";?>" 
								data-title="rastva"><?php echo $row['stateras'];?></span>
								<?php
								if($row['stateras'] == "Non payée"){
								?>
							<span>RAS TAV: <b style="color:#FF0000;"><?php echo $row['rastva'];?> <?php echo $settings['currency'];?></b></span>
								<?php
								}
								?>
							<span>Date d'écheance: <b><?php echo date('20/m/Y', strtotime('first day of next month',$row['datepaid']));?></b></span>
								<?php
								if($row['datepaidras'] != ""){
									$date1 = strtotime(date('20-m-Y', strtotime('first day of next month',$row['datepaid'])));
									$date2 = $row['datepaidras'];
									$resttodelay = date_diff(date_create(date("Y-m-d",$date1)),date_create(date("Y-m-d",$date2)));
									$days = $resttodelay->format("%a");
									?>
							<span>Payé le: <b><?php echo date("d/m/Y",$row['datepaidras']);?></b><a href="javascript:;" 
								data-id="<?php echo $row['id'];?>" 
								data-stateras="<?php echo $row['stateras'];?>" 
								data-datepaidras="<?php echo $row['datepaidras']!=""?date("d/m/Y",$row['datepaidras']):"";?>" 
								data-attachmentras="<?php echo $row['attachmentras'];?>"
								class="<?php echo preg_match("#Mise à jour RAS TVA factures clients#",$_SESSION['easybm_roles'])?"lx-edit-payment-ras lx-open-popup":"";?>" 
								data-title="rastva" style="display:inline-block;margin-left:10px;color:#39add1;"><i class="fa fa-edit"></i></a></span>
									<?php
									if($date2 > $date1){
										$req = $bdd->prepare("UPDATE documents SET retardras='".$days."' WHERE id='".$row['id']."'");
										$req->execute();
										?>
							<span style="color:#FF0000;font-weight:bold;">Avec <?php echo $days;?> jours de retard</span>
										<?php
									}
									if($row['attachmentras'] != ""){
										?>
							<span><b><a href="uploads/<?php echo $row['attachmentras'];?>" target="_blank" style="color:#39add1;"><i class="fa fa-download"></i> Téléchager</a></b></span>
										<?php
									}
								}
								if($row['stateras']!='Payée' AND preg_match("#Mise à jour RAS TVA factures clients#",$_SESSION['easybm_roles'])){
								?>
								<br />
								<div class="lx-upload-photos" style="white-space:nowrap;">
									<?php
									if(preg_match("#Envoi des messages#",$_SESSION['easybm_roles'])){
									?>
									<a href="javascript:;" class="lx-open-popup lx-send-message" data-title="message" 
										data-id="<?php echo $row['id'];?>"
										data-client="<?php echo $client['fullname'];?>"
										data-email1="<?php echo $client['email'];?>"
										data-whatsapp="<?php echo $client['whatsapp'];?>"
										data-sender="<?php echo $sender;?>"
										data-numero_facture="<?php echo $row['code'];?>"
										data-montant="<?php echo number_format((float)$price2,2,"."," ");?>"
										data-societe="<?php echo $company;?>"
										data-delai_paiement="<?php echo $row['delay'];?>"
										data-echeance_paiement="<?php echo date("d/m/Y",$timetodelay);?>"
										data-button="Rappel paiement RAS"
										data-utilisateur="<?php echo $user['fullname'];?>" style="display:inline-block;width:auto;"><i class="fa fa-paper-plane"></i> Rappel paiement RAS</a>
									<?php
									}
									if(preg_match("#Consultation historique des messages#",$_SESSION['easybm_roles'])){
									?>
									<a href="javascript:;" class="lx-open-popup lx-message-history" data-title="messagehistory" 
										data-id="<?php echo $row['id'];?>"
										data-page="fc"
										data-button="Rappel paiement RAS" style="display:inline-block;width:auto;"><i class="fa fa-eye"></i></a>
									<?php
									}
									?>
								</div>
								<?php
								}
								if($row['stateras']=='Payée' AND preg_match("#Consultation historique des messages#",$_SESSION['easybm_roles'])){
								?>
								<br />
								<div class="lx-upload-photos" style="white-space:nowrap;">
									<a href="javascript:;" class="lx-open-popup lx-message-history" data-title="messagehistory" 
										data-id="<?php echo $row['id'];?>"
										data-page="fc"
										data-button="Rappel paiement RAS" style="display:block;"><i class="fa fa-eye"></i> Rappel paiement RAS</a>
								</div>
								<?php									
								}
							}
							?>
						</td>						
						<td><span><?php echo $row['note'];?></span></td>
						<td>
							<?php
							if($row['abovetable'] != ""){
							?>
							<span style="white-space:nowrap;width:300px;"><strong>Note (au-dessus de tableau) :</strong></span>
							<span style="margin-bottom:10px;"><?php echo str_replace("<p>&nbsp;</p>","",$row['abovetable']);?></span>
							<?php
							}
							if($row['modepayment'] != ""){
							?>
							<span><strong>Mode de paiement (au-dessous de tableau) :</strong></span>
							<span style="margin-bottom:10px;"><?php echo str_replace("<p>&nbsp;</p>","",$row['modepayment']);?></span>
							<?php
							}
							if($row['conditions'] != ""){
							?>
							<span><strong>Conditions (au-dessous de tableau) :</strong></span>
							<span style="margin-bottom:10px;"><?php echo str_replace("<p>&nbsp;</p>","",$row['conditions']);?></span>
							<?php
							}
							?>
						</td>
						<td>
							<?php
							if($row['picture'] != ""){
								?>
							<div class="lx-photos-preview">
								<?php
								if($_SESSION['easybm_type'] == "moderator"){
								?>
								<a href="javascript:;" class="lx-delete-images"><i class="material-icons"><img src="images/close.svg" style="width:22px;padding:3px;background:#EEEEEE;border-radius:6px;" /></i></a>
								<div class="lx-delete-image-choice">
									<a href="javascript:;" class="lx-yes-delete-image" data-allpics="<?php echo $row['picture'];?>" data-pic="<?php echo $row['picture'];?>" data-table="documents" data-column="picture" data-id="<?php echo $row['id'];?>">Oui</a>
									<a href="javascript:;" class="lx-no-delete-image">Non</a>
								</div>		
								<?php
								}
								?>
								<img src="uploads/<?php echo $row['picture'];?>" class="lx-open-popup lx-open-zoombox" data-title="zoombox" />
							</div>
								<?php
							}
							?>
							<div class="lx-upload-photos">
								<input type="file" name="uploadphotos[]" id="uploadphotos<?php echo $row['id'];?>" data-table="documents" data-column="picture" data-id="<?php echo $row['id'];?>" accept="image/x-png,image/jpeg" />
								<a href="javascript:;" class="">Ajouter photo</a>
							</div>
						</td>
						<td><span style="white-space:nowrap"><?php echo $user['fullname'];?></span></td>
						<td>
							<?php
							if($row['attachments'] != ""){
								$attachments = explode(",",$row['attachments']);
								for($i=1;$i<count($attachments);$i++){
									?>
							<span style="position:relative;white-space:nowrap;margin-bottom:5px;">
								<a href="javascript:;" class="lx-delete-file"><i class="fa fa-times"></i></a>
								<div class="lx-delete-file-choice">
									<a href="javascript:;" class="lx-yes-delete-file" data-table="documents" data-id="<?php echo $row['id'];?>" data-file="<?php echo $attachments[$i];?>" data-files="<?php echo $row['attachments'];?>">Oui</a>
									<a href="javascript:;" class="lx-no-delete-file">Non</a>
								</div>
								<a href="uploads/<?php echo $attachments[$i];?>" target="_blank" style="white-space:nowrap;"><?php echo $attachments[$i];?></a>
							</span>
									<?php
								}
							}
							?>
							<div class="lx-upload-files">
								<input type="file" name="uploadfiles[]" id="uploadfiles<?php echo $row['id'];?>" data-table="documents" data-id="<?php echo $row['id'];?>" multiple="multiple" accept="image/*,.pdf,.doc,.docx,.xls,.xlsx,.txt" />
								<a href="javascript:;" class=""><i class="fa fa-plus"></i> fichier</a>
							</div>
						</td>
						<td style="position:relative;">
							<?php
							if($_POST['state'] == 1){
								?>
							<a href="javascript:;" class="lx-open-edit-menu"><i class="fa fa-ellipsis-v"></i></a>
							<div class="lx-edit-menu">
								<a href="javascript:;" data-href="printclientdocs.php?id=<?php echo $row['id'];?>&title=Facture" class="lx-download-file1 lx-print-f lx-open-popup" data-title="signature">Imprimer</a>
								<?php
								if(preg_match("#Modifier Factures clients#",$_SESSION['easybm_roles'])){
									?>
								<a href="javascript:;" class="lx-edit lx-edit-command lx-open-popup" data-table="commands" data-header="Modifier" 
									data-id="<?php echo $row['id'];?>"
									data-code="<?php echo substr($row['code'],7);?>"
									data-dateadd="<?php echo date("d/m/Y",$row['dateadd']);?>"
									data-company="<?php echo $row['company'];?>"
									data-exist="1"
									data-client="<?php echo $row['client'];?>"
									data-products="<?php echo str_replace("\"","'",$products);?>"
									data-discounttype="<?php echo $discounttype;?>"
									data-correctdoc="<?php echo $row['correctdoc'];?>"
									data-note="<?php echo str_replace("\"","'",sanitize_vars($row['note']));?>" data-title="command">Modifier</a>
									<?php
								}
								if(preg_match("#Transformation / Dupplication documents#",$_SESSION['easybm_roles'])){
									?>
								<a href="javascript:;" class="lx-edit lx-edit-command lx-open-popup" data-table="commands" data-header="Transformer / Dupliquer" 
									data-id="0"
									data-code="<?php echo substr($row['code'],7);?>"
									data-dateadd="<?php echo date("d/m/Y",$row['dateadd']);?>"
									data-company="<?php echo $row['company'];?>"
									data-exist="1"
									data-client="<?php echo $row['client'];?>"
									data-products="<?php echo str_replace("\"","'",$products);?>"
									data-discounttype="<?php echo $discounttype;?>"
									data-correctdoc="<?php echo $row['correctdoc'];?>"
									data-note="<?php echo str_replace("\"","'",sanitize_vars($row['note']));?>"
									data-modepayment="<?php echo str_replace("\"","'",sanitize_vars($row['modepayment']));?>"
									data-conditions="<?php echo str_replace("\"","'",sanitize_vars($row['conditions']));?>"
									data-abovetable="<?php echo str_replace("\"","'",sanitize_vars($row['abovetable']));?>" data-title="command">Transformer / Duppliquer</a>
									<?php
								}
								if(preg_match("#Ajouter Factures avoir#",$_SESSION['easybm_roles'])){
									?>
								<a href="javascript:;" class="lx-edit lx-edit-command lx-open-popup" style="color:#FFA500;" data-table="commands" data-header="Avoir / bon de retour" 
									data-id="-1"
									data-code="<?php echo substr($row['code'],7);?>"
									data-dateadd="<?php echo date("d/m/Y",$row['dateadd']);?>"
									data-company="<?php echo $row['company'];?>"
									data-exist="1"
									data-client="<?php echo $row['client'];?>"
									data-products="<?php echo str_replace("\"","'",$products);?>"
									data-discounttype="<?php echo $discounttype;?>"
									data-correctdoc="<?php echo $row['code'];?>"
									data-note="<?php echo str_replace("\"","'",sanitize_vars($row['note']));?>" data-title="command">Avoir / bon de retour</a>
									<?php
								}
								?>
								<a href="javascript:;" class="lx-edit lx-edit-extrainfo lx-open-popup" data-table="extrainfo" data-header="Informations supplimentaires sur le document" 
									data-id="<?php echo $row['id'];?>"
									data-modepayment="<?php echo str_replace("\"","'",sanitize_vars($row['modepayment']));?>"
									data-conditions="<?php echo str_replace("\"","'",sanitize_vars($row['conditions']));?>"
									data-abovetable="<?php echo str_replace("\"","'",sanitize_vars($row['abovetable']));?>" data-title="extrainfo">Informations supplimentaires sur le document</a>
								<?php
								if(preg_match("#Supprimer Factures clients#",$_SESSION['easybm_roles'])){
								?>
								<a href="javascript:;" class="lx-delete lx-delete-command lx-open-popup" data-title="deleterecord" data-id="<?php echo $row['id'];?>">Supprimer</a>
								<?php
								}
								?>
							</div>
								<?php
							}
							?>
						</td>
					</tr>
						<?php
					}
					?>
					<tr class="lx-first-tr">
						<td><label><input type="checkbox" name="selectall" value="selectall" /><del class="checkmark"></del></label></td>
						<td>Date création <i class="fa fa-sort" data-sort="dateadd"></i></td>
						<td>Affecté à la société <i class="fa fa-sort" data-sort="company"></i></td>
						<td>Référence <i class="fa fa-sort" data-sort="code"></i></td>
						<td>Factures avoir / Bons de retour N°</td>
						<td>Client <i class="fa fa-sort" data-sort="client"></i></td>
						<td style="min-width:300px;">Détails facture</td>
						<td>Montant <i class="fa fa-sort" data-sort="price"></i></td>
						<td>Délai de paiement <i class="fa fa-sort" data-sort="delay"></i></td>
						<td>Statut et historique des paiements <i class="fa fa-sort" data-sort="rest"></i></td>
						<td>RAS TVA <i class="fa fa-sort" data-sort="delayras"></i></td>
						<td><div style="width:200px;">Note</div></td>
						<td>Informations supplimentaires sur le document</td>
						<td>Image sur le document</td>
						<td>Utilisateur <i class="fa fa-sort" data-sort="user"></i></td>
						<td>Attachements</td>
						<td><i class="fa fa-ellipsis-v"></i></td>
					</tr>
				</table>
				<?php
				$req1 = "SELECT COUNT(id) AS nb FROM documents c WHERE trash='1' AND type='facture'".$multicompanies;
				$req = "";
				if($_POST['keyword'] != ""){
					$req .= " AND (code LIKE '".normalizeString($_POST['keyword'])."' 
									OR note LIKE '".normalizeString($_POST['keyword'])."' 
									OR modepayment LIKE '".normalizeString($_POST['keyword'])."'
									OR conditions LIKE '".normalizeString($_POST['keyword'])."'
									OR abovetable LIKE '".normalizeString($_POST['keyword'])."')";
				}
				if($_POST['company'] != ""){
					$comp = explode("||",$_POST['company']);
					$req .= " AND (";
					for($j=0;$j<count($comp);$j++){
						if($j==0){
							$req .= "FIND_IN_SET(".$comp[$j].", company)";
						}
						else{
							$req .= " OR FIND_IN_SET(".$comp[$j].", company)";
						}
					}
					$req .= ")";
				}
				if($_POST['client'] != ""){
					$req .= " AND client IN(".str_replace("||",",",$_POST['client']).")";
				}
				if($_POST['user'] != ""){
					$req .= " AND user IN(".$_POST['user'].")";
				}
				if($_POST['product'] != ""){
					$req .= " AND id IN(SELECT doc FROM detailsdocuments WHERE title IN('".str_replace("||","','",addslashes($_POST['product']))."'))";
				}
				if($_POST['stateras'] != ""){
					if($_POST['stateras'] == "Non payée avec dépassement de délai de paiement"){
						$req .= " AND stateras NOT IN('Payée') AND ".time()." > datedue AND rastva > 0";
					}
					else{
						if(preg_match("#Non payée avec dépassement de délai de paiement#",$_POST['stateras'])){
							$req .= " AND (stateras IN ('".str_replace("||","','",$_POST['stateras'])."') OR (stateras NOT IN('Payée') AND ".time()." > datedue)) AND rastva > 0";
						}
						else{
							$req .= " AND stateras IN ('".str_replace("||","','",$_POST['stateras'])."') AND rastva > 0";
						}
					}
				}
				if($_POST['statee'] != ""){
					if($_POST['statee'] == "Non payée avec dépassement de délai de paiement"){
						$req .= " AND state NOT IN('Payée') AND ".time()." > (dateadd+(delay*60*60*24))";
					}
					else{
						if(preg_match("#Non payée avec dépassement de délai de paiement#",$_POST['statee'])){
							$req .= " AND (state IN ('".str_replace("||","','",$_POST['statee'])."') OR (state NOT IN('Payée') AND ".time()." > (dateadd+(delay*60*60*24))))";
						}
						else{
							$req .= " AND state IN ('".str_replace("||","','",$_POST['statee'])."')";
						}
					}
				}
				if($_POST['pricemin'] != "" AND $_POST['pricemax'] != ""){
					$req .= " AND (price BETWEEN ".$_POST['pricemin']." AND ".$_POST['pricemax'].")";
				}
				if($_POST['datestart'] != "" AND $_POST['dateend'] != ""){
					$datestart = strtotime(str_replace("/","-",$_POST['datestart']));
					$dateend = strtotime(str_replace("/","-",$_POST['dateend'])) + (60*60*24) - 1;
					$req .= " AND (dateadd BETWEEN ".$datestart." AND ".$dateend.")";
				}
				if($_POST['datestartlimit'] != "" AND $_POST['dateendlimit'] != ""){
					$datestart = strtotime(str_replace("/","-",$_POST['datestartlimit']));
					$dateend = strtotime(str_replace("/","-",$_POST['dateendlimit'])) + (60*60*24) - 1;
					$req .= " AND ((dateadd+(delay*60*60*24)) BETWEEN ".$datestart." AND ".$dateend.")";
				}
				if($_POST['datestartlimitras'] != "" AND $_POST['dateendlimitras'] != ""){
					$datestart = strtotime(str_replace("/","-",$_POST['datestartlimitras']));
					$dateend = strtotime(str_replace("/","-",$_POST['dateendlimitras'])) + (60*60*24) - 1;
					$req .= " AND (datedue BETWEEN ".$datestart." AND ".$dateend.")";
				}
				$back = $bdd->query($req1.$req);
				$row = $back->fetch();
				$nbcmds = 0.1;
				if($row['nb'] != 0){
					$nbcmds = $row['nb'];
				}
				
				$ids = "0";
				$ca = 0;
				$ca1 = 0;				
				$req1 = "SELECT id,price,rastva FROM documents c WHERE type='facture'".$multicompanies;
				$back = $bdd->query($req1.$req);
				while($row = $back->fetch()){
					$ids .= ",".$row['id'];
					$ca += $row['price']-$row['rastva'];
					$ca1 += $row['price']-$row['rastva'];
				}
				
				if($ca1 == 0){
					$ca1 = 1;
				}
				$req1 = "SELECT SUM(price) AS paid FROM payments WHERE paid='0' AND typedoc='facture' AND doc IN(".$ids.")".$multicompanies;
				$back = $bdd->query($req1);
				$row = $back->fetch();
				$paid = $row['paid'];
				
				$rest = $ca - $paid;
				?>
				<div class="lx-caisse-total lx-caisse-total1">
					<h3 style="background:#d9534f;">En cours</h3>
					<p><?php echo number_format((float)(isset($rest)?$rest:0),2,"."," ")." ".$settings['currency'];?> TTC</p>
					<ins><?php echo number_format((float)$rest*100/$ca1,2,"."," ")?>%</ins>
					<h4 class="lx-progress-container">
						<ins class="lx-progress-bar" style="width:<?php echo $rest*100/$ca1?>%;background:#d9534f;"></ins>
					</h4>
				</div>
				<div class="lx-caisse-total lx-caisse-total2">
					<h3 style="background:#5cb85c;">Payé</h3>
					<p><?php echo number_format((float)(isset($paid)?$paid:0),2,"."," ")." ".$settings['currency'];?> TTC</p>
					<ins><?php echo number_format((float)$paid*100/$ca1,2,"."," ")?>%</ins>
					<h4 class="lx-progress-container">
						<ins class="lx-progress-bar" style="width:<?php echo $paid*100/$ca1?>%;background:#5cb85c;"></ins>
					</h4>
				</div>
				<div class="lx-caisse-total lx-caisse-total3">
					<h3 style="background:#337ab7;">Chiffre d'affaires</h3>
					<p><?php echo number_format((float)(isset($ca)?$ca:0),2,"."," ")." ".$settings['currency'];?> TTC</p>
					<ins><?php echo number_format((float)$ca*100/$ca1,2,"."," ")?>%</ins>
					<h4 class="lx-progress-container">
						<ins class="lx-progress-bar" style="width:<?php echo $ca*100/$ca1?>%;background:#337ab7;"></ins>
					</h4>
				</div>
				<input type="hidden" id="posts" value="<?php echo $back4->rowCount();?>" /><input type="hidden" id="req" value="<?php echo $req2;?>" />
				<?php
				if($back4->rowCount() > ($_POST['start'] + $_POST['nbpage'])){
				?>
				<p><?php echo ($_POST['start'] + $_POST['nbpage']);?> facture(s) de <?php echo $back4->rowCount();?></p>
				<?php
				}
				else{
				?>
				<p><?php echo $back4->rowCount();?> facture(s) de <?php echo $back4->rowCount();?></p>
				<?php			
				}
				$req1 = "SELECT SUM(price) AS price,SUM(tva) AS tva,SUM(rastva) AS rastva FROM documents c WHERE type='facture' AND trash='1'".$multicompanies;
				$back = $bdd->query($req1.$req);
				$row = $back->fetch();
				?>
				<div class="lx-caisse-total4">
					<div style="float:left;margin-right:60px;">
						<p>* Total Montant HT: <b><?php echo number_format((float)$row['price']-$row['tva'],2,"."," ");?> <?php echo $settings['currency'];?></b></p>
						<p>* Total TVA: <b><?php echo number_format((float)$row['tva'],2,"."," ");?> <?php echo $settings['currency'];?></b></p>
						<p>* Total RAS TVA: <b style="color:#FF0000;"><?php echo number_format((float)$row['rastva'],2,"."," ");?> <?php echo $settings['currency'];?></b></p>
						<p>* Total Montant TTC: <b><?php echo number_format((float)$row['price']-($row['rastva']),2,"."," ");?> <?php echo $settings['currency'];?></b></p>
					</div>
				</div>
				<?php
			}