Skip to content
Snippets Groups Projects
bon-prelevement.class.php 39.1 KiB
Newer Older
     *
     *
     */
    function DeleteNotificationById($rowid)
    {
        $result = 0;

        $sql = "DELETE FROM ".MAIN_DB_PREFIX."prelevement_notifications ";
        $sql .= " WHERE rowid = '".$rowid."';";

        if ($this->db->query($sql))
        {
            return 0;
        }
        else
        {
            return -1;
        }
    }

    /**
     *
     *
     */
    function DeleteNotification($user, $action)
    {
        $result = 0;

        $sql = "DELETE FROM ".MAIN_DB_PREFIX."prelevement_notifications ";
        $sql .= " WHERE fk_user = '".$user."' AND action = '".$action."';";

        if ($this->db->query($sql))
        {
            return 0;
        }
        else
        {
            return -1;
        }
    }
     *
     *
     */
    function AddNotification($user, $action)
    {
        $result = 0;

        if ($this->DeleteNotification($user, $action) == 0)
        {

            $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_notifications ";
            $sql .= " (fk_user, action )";
            $sql .= " VALUES ('".$user."','".$action."');";

            if ($this->db->query($sql))
            {
                $result = 0;
            }
            else
            {
                $result = -1;
                dolibarr_syslog("BonPrelevement::AddNotification Erreur $result");
            }
        }

        return $result;
    }

    /**
     * Gnration d'un bon de prlvement
     *
     */
    function Generate()
    {
        $result = -1;

        $this->file = fopen ($this->filename,"w");


        /*
         * En-tete Emetteur
         */
        $this->EnregEmetteur();

        /*
         * Lignes
         */
        $this->total = 0;

        $sql = "SELECT rowid, client_nom, code_banque, code_guichet, number, amount";
        $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes";
        $sql .= " WHERE fk_prelevement_bons = ".$this->id;

        $i = 0;

        if ($this->db->query($sql))
        {
            $num = $this->db->num_rows();

            while ($i < $num)
            {
                $row = $this->db->fetch_row();

                $this->EnregDestinataire($row[0],
                $row[1],
                $row[2],
                $row[3],
                $row[4],
                $row[5]);

                $this->total = $this->total + $row[5];

                $i++;
            }
        }
        else
        {
            $result = -2;
        }
        /*
        $nbfactures = sizeof($this->factures);
        for ($i = 0 ; $i < $nbfactures ; $i++)
        {
        $fac = new Facture($this->db);
        $fac->fetch($this->factures[$i]);
        $fac->fetch_client();
        $fac->client->rib();
        if ($fac->client->bank_account->verif()) {
        $this->total = $this->total + $fac->total_ttc;
        $this->EnregDestinataire($fac);
        }else{
        print $fac->client->bank_account->error_message;
        print $fac->client->nom; }
        }
        */

        /*
        * Pied de page total
        */

        $this->EnregTotal($this->total);

        fclose($this->file);

        return $result;
    }


    /**
     * Enregistrements destinataires
     *
     *
    function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount)
    {
        fputs ($this->file, "06");
        fputs ($this->file, "08"); // Prlvement ordinaire
        fputs ($this->file, "        "); // Zone Rserve B2
        fputs ($this->file, $this->numero_national_emetteur); // Numro National d'emmetteur B3
        fputs ($this->file, "       ");
        fputs ($this->file, strftime("%d%m", $this->date_echeance));
        fputs ($this->file, substr(strftime("%y", $this->date_echeance),1));
        // Raison Sociale Destinataire C2
        fputs ($this->file, substr($client->nom. "                           ",0,24));
        fputs ($this->file, substr("                                    ",0,24));
        fputs ($this->file, substr("                             ",0,8));
        fputs ($this->file, $rib_guichet);
        fputs ($this->file, substr("000000000000000".$rib_number, -11));
        $montant = (round($amount,2) * 100);
        fputs ($this->file, substr("000000000000000".$montant, -16));
        fputs ($this->file, substr("*".$this->ref.$rowid."                                   ",0,13));
        fputs ($this->file, substr("                                        ",0,18));
        fputs ($this->file, $rib_banque);
        fputs ($this->file, substr("                                        ",0,5));
    /**
     * Enregistrements destinataires
     *
     *
     */
    function EnregDestinataireVersion1($fac)
    {
        fputs ($this->file, "06");
        fputs ($this->file, "08"); // Prlvement ordinaire
        fputs ($this->file, "        "); // Zone Rserve B2
        fputs ($this->file, $this->numero_national_emetteur); // Numro National d'emmetteur B3
        fputs ($this->file, "       ");
        fputs ($this->file, strftime("%d%m", $this->date_echeance));
        fputs ($this->file, substr(strftime("%y", $this->date_echeance),1));
        // Raison Sociale Destinataire C2
        fputs ($this->file, substr($fac->client->nom. "                           ",0,24));
        // Reference de la remise crancier D1
        fputs ($this->file, substr("                                    ",0,24));
        fputs ($this->file, substr("                             ",0,8));
        fputs ($this->file, $fac->client->bank_account->code_guichet);
        fputs ($this->file, substr("000000000000000".$fac->client->bank_account->number, -11));
        $montant = (round($fac->total_ttc,2) * 100);
        fputs ($this->file, substr("000000000000000".$montant, -16));
        fputs ($this->file, substr("*".$fac->ref."                                   ",0,13));
        fputs ($this->file, substr("                                        ",0,18));
        fputs ($this->file, $fac->client->bank_account->code_banque);
        fputs ($this->file, substr("                                        ",0,5));
    /**
     *
     *
     */
    function EnregEmetteur()
    {
        fputs ($this->file, "03");
        fputs ($this->file, "08"); // Prlvement ordinaire
        fputs ($this->file, "        "); // Zone Rserve B2
        fputs ($this->file, $this->numero_national_emetteur); // Numro National d'emmetteur B3
        fputs ($this->file, "       ");
        fputs ($this->file, strftime("%d%m", $this->date_echeance));
        fputs ($this->file, substr(strftime("%y", $this->date_echeance),1));
        fputs ($this->file, substr($this->raison_sociale. "                           ",0,24));
        // Reference de la remise crancier D1 sur 7 caractres
        fputs ($this->file, substr($this->reference_remise. "                           ",0,7));
        fputs ($this->file, substr("                                    ",0,17));
        fputs ($this->file, substr("                             ",0,2));
        fputs ($this->file, "E");
        fputs ($this->file, substr("                             ",0,5));
        fputs ($this->file, $this->emetteur_code_guichet);
        fputs ($this->file, substr("000000000000000".$this->emetteur_numero_compte, -11));
        fputs ($this->file, substr("                                        ",0,16));
        fputs ($this->file, substr("                                        ",0,31));
        fputs ($this->file, $this->emetteur_code_etablissement);
        fputs ($this->file, substr("                                        ",0,5));
    /**
     * Pied de page
     *
     */
    function EnregTotal($total)
    {
        fputs ($this->file, "08");
        fputs ($this->file, "08"); // Prlvement ordinaire
        fputs ($this->file, "        "); // Zone Rserve B2
        fputs ($this->file, $this->numero_national_emetteur); // Numro National d'emmetteur B3
        fputs ($this->file, substr("                           ",0,12));
        fputs ($this->file, substr("                           ",0,24));
        fputs ($this->file, substr("                                    ",0,24));
        fputs ($this->file, substr("                             ",0,8));
        fputs ($this->file, substr("                             ",0,5));

        // Numero de compte D4

        fputs ($this->file, substr("                             ",0,11));

        // Zone E Montant

        $montant = ($total * 100);

        fputs ($this->file, substr("000000000000000".$montant, -16));

        // Zone Rserve F

        fputs ($this->file, substr("                                        ",0,31));

        // Code tablissement

        fputs ($this->file, substr("                                        ",0,5));

        // Zone Rserve F

        fputs ($this->file, substr("                                        ",0,5));

        fputs ($this->file, "\n");
    }
Rodolphe Quiedeville's avatar
Rodolphe Quiedeville committed
?>