| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 
 |     header('Content-Type: text/csv; charset=utf-8');  
    header('Content-Disposition: attachment; filename="' . $filename . '"');  
    header('Expires: 0');
    header("Pragma: no-cache");
 
    $output = fopen("php://output", "w"); 
 
    fputcsv($output, array('id', 'code_journal', 'date', 'num_facture', 'compte_comptable', 'compte_auxiliaire', 'libelle', 'debit', 'credit'), ";");  
    $sql_export = "SELECT * from " . $_SESSION["table"] . " ORDER BY date, num_facture DESC";  
    $result_export = mysqli_query($mysqli, $sql_export);  
    if(!mysqli_query($mysqli, $sql_export))
    {
        echo "alerte : Erreur EXPORT MySQL sur la table " .$_SESSION["table"] ."";    
    } else
    {
        $i=0;
        while($row = mysqli_fetch_array($result_export))  
        {
            $i++;
            if ($_SESSION["fis_ref"] == "REP")
            {
                if ($row['moyen_de_paiement'] === "carte bancaire")
                {
                    $id = $i;
                    $cj = "RCB";
                    $date = date("d/m/Y", strtotime($row['date']));
                    $fact = $row['num_facture'];
                    $lib = $row['client_fournisseur'];
                    $montant = str_replace('.', ',', $row['montant']);	
                    $dc = $row['debit_credit'];
 
                    // Règlements
                    if (substr($row['note'], 0, 6) == "Stripe") {
                        $cc = 58050000;
                    } else {
                        $cc = 58030000;
                    }
 
                    $cptea = $row['compte_auxiliaire'];
 
                    if ($dc == "credit") {
                        $debit = $montant;
                        $credit = "";
                    } else if ($dc == "debit") {
                        $debit = "";
                        $credit = $montant;
                    }
 
                    $ligne1 = array($id, $cj, $date, $fact, $lib, $cc, $cptea, $debit, $credit);
 
                    // Contrepartie règlements
                    $cptec = $row['compte_tiers'];
                    $cptea = $row['compte_auxiliaire'];
                    if (substr($cptec,0,3) == "411") {
                        $cc = $cptea;
                    } else {
                        $cc = $cptec;
                    }
 
                    if ($dc == "credit") {
                        $debit = "";
                        $credit = $montant;
                    } else if ($dc == "debit") {
                        $debit = $montant;
                        $credit = "";
                    }
 
                    $ligne2 = array($id, $cj, $date, $fact, $lib, $cc, $cptea, $debit, $credit);
                }
                $exp = array($ligne1, $ligne2);
                foreach ($exp as $export)
                {
                    fputcsv($output, $export, ";");
                }
            } | 
Partager