$sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOST("page", 'int'); if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (!$sortorder) { $sortorder = "ASC"; } if (!$sortfield) { $sortfield = "name"; } $object = new Local($db); $object->fetch($id); $upload_dir = $conf->immobilier->dir_output . '/local/' . dol_sanitizeFileName($object->id); $modulepart = 'immobilier'; /* * Actions */ if (GETPOST("sendit") && !empty($conf->global->MAIN_UPLOAD_DOC)) { dol_add_file_process($upload_dir, 0, 1, 'userfile'); } if ($action == 'delete') { $file = $upload_dir . '/' . GETPOST("urlfile"); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). $ret = dol_delete_file($file); if ($ret) { setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); } else {
dol_include_once("/immobilier/class/local.class.php"); dol_include_once('/immobilier/lib/immobilier.lib.php'); // Class require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; // Langs $langs->load("immobilier@immobilier"); $langs->load("other"); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); // Security check $mesg = ''; $object = new Local($db); if ($id > 0 || !empty($ref)) { $result = $object->fetch($id, $ref); $dir = $conf->immobilier->dir_output . '/photo/' . dol_sanitizeFileName($object->id); } /* * Actions */ if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && GETPOST('sendit') && !empty($conf->global->MAIN_UPLOAD_DOC)) { if ($object->id) { $result = $object->add_photo($dir, $_FILES['userfile']); } } if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer)) { $object->delete_photo($dir . "/" . $_GET["file"]); } if ($action == 'addthumb' && $_GET["file"]) { $object->add_thumb($dir . "/" . $_GET["file"]);
} // Class dol_include_once("/immobilier/class/local.class.php"); dol_include_once('/immobilier/lib/immobilier.lib.php'); // Langs $langs->load("immobilier@immobilier"); $id = GETPOST('id', 'int'); $mesg = ''; $limit = $conf->liste_limit; /* * loyer et paiement par local * */ llxheader('', $langs->trans("bilanlocal"), ''); $local = new Local($db); $result = $local->fetch($id); $head = contrat_prepare_head($local); dol_fiche_head($head, 'info', $langs->trans("Imoinfo"), 0, 'propertie'); $sql = "(SELECT l.periode_du as date , l.montant_tot as debit, 0 as credit , l.nom as des"; $sql .= " FROM " . MAIN_DB_PREFIX . "immo_loyer as l"; $sql .= " WHERE l.local_id =" . $id; $sql .= ")"; $sql .= "UNION (SELECT p.date_paiement as date, 0 as debit , p.montant as credit, p.commentaire as des"; $sql .= " FROM " . MAIN_DB_PREFIX . "immo_paie as p"; $sql .= " WHERE p.local_id =" . $id; $sql .= ")"; $sql .= "ORDER BY date"; $result = $db->query($sql); if ($result) { $num_lignes = $db->num_rows($result); $i = 0;
/** * \brief Fonction generant le document sur le disque * \param agf Objet document a generer (ou id si ancienne methode) * outputlangs Lang object for output language * file Name of file to generate * \return int 1=ok, 0=ko */ function write_file($loyer, $outputlangs, $file, $socid, $courrier) { global $user, $langs, $conf, $mysoc; $default_font_size = pdf_getPDFFontSize($outputlangs); if (!is_object($outputlangs)) { $outputlangs = $langs; } if (!is_object($loyer)) { $id = $loyer; $loyer = new Loyer($this->db); $ret = $loyer->fetch($id); } // dol_syslog ( "pdf_quittance::debug loyer=" . var_export ( $loyer, true ) ); // Definition of $dir and $file $dir = $conf->immobilier->dir_output; $file = $dir . '/' . $file; if (!file_exists($dir)) { if (create_exdir($dir) < 0) { $this->error = $langs->trans("ErrorCanNotCreateDir", $dir); return 0; } } if (file_exists($dir)) { $pdf = pdf_getInstance($this->format, $this->unit, $this->orientation); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->Open(); $pagenb = 0; $pdf->SetTitle($outputlangs->convToOutputCharset($loyer->nom)); $pdf->SetSubject($outputlangs->transnoentities("Quitance")); $pdf->SetCreator("Dolibarr " . DOL_VERSION . ' (Immobilier module)'); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->fullname)); $pdf->SetKeyWords($outputlangs->convToOutputCharset($loyer->nom) . " " . $outputlangs->transnoentities("Document")); if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) { $pdf->SetCompression(false); } $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right $pdf->SetAutoPageBreak(1, 0); // On recupere les infos societe $locataire = new Locataire($this->db); $result = $locataire->fetch($loyer->locataire_id); $proprio = new Adherent($this->db); $result = $proprio->fetch($loyer->proprietaire_id); $local = new Local($this->db); $result = $local->fetch($loyer->local_id); $paiement = new Paie($this->db); $result = $paiement->fetch_by_loyer($loyer->id); if (!empty($loyer->id)) { // New page $pdf->AddPage(); $pagenb++; $this->_pagehead($pdf, $agf, 1, $outputlangs); $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 9); $pdf->MultiCell(0, 3, '', 0, 'J'); $pdf->SetTextColor(0, 0, 0); $posY = $this->marge_haute; $posX = $this->marge_gauche; // Bloc Owner $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 15); $pdf->SetXY($posX, $posY + 3); $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset('Bailleur'), 1, 'C'); $posY = $pdf->getY(); $pdf->SetXY($posX, $posY); $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 13); $this->str = $proprio->getFullName($outputlangs) . "\n"; $this->str .= $proprio->address . "\n"; $this->str .= $proprio->zip . ' ' . $proprio->town; $this->str .= ' - ' . $proprio->country . "\n\n"; if ($proprio->phone) { $this->str .= $outputlangs->transnoentities('Téléphone') . ' ' . $proprio->phone . "\n"; } if ($proprio->fax) { $this->str .= $outputlangs->transnoentities('Fax') . ' ' . $proprio->fax . "\n"; } if ($proprio->email) { $this->str .= $outputlangs->transnoentities('EMail') . ' ' . $proprio->email . "\n"; } if ($proprio->url) { $this->str .= $outputlangs->transnoentities('Url') . ' ' . $proprio->url . "\n"; } $pdf->MultiCell(100, 20, $outputlangs->convToOutputCharset($this->str), 1, 'L'); // Bloc Locataire $posX = $this->page_largeur - $this->marge_droite - 100; $posY = $pdf->getY() + 10; $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 15); $pdf->SetXY($posX, $posY); $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset('Locataire Destinataire'), 1, 'C'); $posY = $pdf->getY(); $pdf->SetXY($posX, $posY); $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 13); $this->str = $locataire->nom . "\n"; $this->str .= $local->nom . "\n"; if (!empty($locataire->adresse)) { $this->str .= $locataire->adresse . "\n"; } else { $this->str .= $local->adresse . "\n"; } $pdf->MultiCell(100, 20, $outputlangs->convToOutputCharset($this->str), 1, 'L'); // Bloc Quittance de loyer $posX = $this->marge_gauche; $posY = $pdf->getY() + 10; $widthbox = $this->page_largeur - $this->marge_gauche - $this->marge_droite; $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 15); $pdf->SetXY($posX, $posY); $pdf->MultiCell($widthbox, 3, $outputlangs->convToOutputCharset('Quittance de loyer'), 1, 'C'); $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 13); $posY = $pdf->getY(); $pdf->SetXY($posX, $posY); $period = 'Loyer ' . dol_print_date($loyer->periode_du, '%b %Y'); $pdf->MultiCell($widthbox, 3, $outputlangs->convToOutputCharset($period), 1, 'C'); $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 13); $posY = $pdf->getY(); $pdf->SetXY($posX, $posY); $numquitance = 'Quittance n°:' . 'ILQ' . $loyer->id; $pdf->MultiCell($widthbox, 3, $outputlangs->convToOutputCharset($numquitance), 1, 'R'); // Sous Bloc Quittance de loyer Gauche $posX = $this->marge_gauche; $posY = $pdf->getY(); $widthbox = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2; $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 12); $pdf->SetXY($posX, $posY); $text = ' Reçu de :' . $locataire->nom . "\n"; $text .= "\n"; $montantpay = 0; if (!empty($loyer->paiepartiel)) { $montantpay = $loyer->paiepartiel; } $text .= ' la somme de :' . $montantpay . '€' . "\n"; $text .= "\n"; $dtpaiement = $paiement->date_paiement; if (empty($dtpaiement)) { $dtpaiement = $loyer->echeance; } $text .= ' le :' . dol_print_date($dtpaiement, 'daytext') . "\n"; $text .= "\n"; $text .= ' pour loyer et accessoires des locaux sis à :' . "\n"; $text .= $local->adresse . "\n"; $text .= "\n"; $text .= 'en paiement du terme du ' . dol_print_date($loyer->periode_du, 'daytext') . "\n"; $text .= 'au ' . dol_print_date($loyer->periode_au, 'daytext') . "\n"; $text .= "\n"; $text .= 'Fait à ' . $proprio->town . "\n"; $text .= 'le ' . dol_print_date(dol_now(), 'daytext') . "\n"; $text .= "\n"; $pdf->MultiCell($widthbox, 0, $outputlangs->convToOutputCharset($text), 1, 'L'); $newpoy = $pdf->getY(); // Sous Bloc Quittance de loyer Droite $posX = $widthbox + $this->marge_gauche; $widthbox = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2; $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 12); $pdf->SetXY($posX, $posY); $text = '<table>'; $text .= '<tr>'; $text .= '<td colspan="2">'; $text .= 'Détail :' . "<BR>"; $text .= ' - Loyer nu :' . $loyer->loy . '€' . "<BR>"; $text .= ' - Charges / Provisions de Charges :' . $loyer->charges . '€' . "<BR>"; $text .= "<BR>"; $text .= 'Montant total du terme :' . $loyer->montant_tot . '€' . "<BR>"; $text .= '</td>'; $text .= '</tr>'; $sql = "SELECT p.rowid, p.loyer_id, date_paiement as dp, p.montant, p.commentaire as type, il.montant_tot as amount"; $sql .= " FROM " . MAIN_DB_PREFIX . "immo_paie as p"; $sql .= ", " . MAIN_DB_PREFIX . "immo_loyer as il "; $sql .= " WHERE p.loyer_id = " . $loyer->id; $sql .= " AND p.loyer_id = il.rowid"; $sql .= " ORDER BY dp DESC"; // print $sql; dol_syslog(get_class($this) . ':: Paiement sql=' . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; $total = 0; $text .= '<tr>'; $text .= '<td align="left">' . $langs->trans("Date") . '</td>'; $text .= '<td align="right">' . $langs->trans("Amount") . '</td>'; $text .= '</tr><br>'; $var = True; while ($i < $num) { $objp = $this->db->fetch_object($resql); $text .= '<tr>'; $text .= '<td>' . dol_print_date($this->db->jdate($objp->dp), 'day') . "</td>"; $text .= '<td align="right">' . price($objp->montant) . ' ' . $langs->trans("Currency" . $conf->currency) . "</td>"; $text .= "</tr>"; $totalpaye += $objp->montant; $i++; } if ($loyer->paye == 0) { $text .= "<br><tr><td align=\"left\">" . $langs->trans("AlreadyPaid") . " :</td><td align=\"right\">" . price($totalpaye) . " " . $langs->trans("Currency" . $conf->currency) . "</td></tr>"; $text .= "<tr><td align=\"left\">" . $langs->trans("AmountExpected") . " :</td><td align=\"right\">" . price($loyer->montant_tot) . " " . $langs->trans("Currency" . $conf->currency) . "</td></tr>"; $resteapayer = $loyer->montant_tot - $totalpaye; $text .= "<tr><td align=\"left\">" . $langs->trans("RemainderToPay") . " :</td>"; $text .= "<td align=\"right\">" . price($resteapayer, 2) . " " . $langs->trans("Currency" . $conf->currency) . "</td></tr>"; } $this->db->free($resql); } $text .= "</table>"; $pdf->writeHTMLCell($widthbox, $newpoy - $posY, $posX, $posY, dol_htmlentitiesbr($text), 1); // Tableau Loyer et solde $sql = "SELECT il.nom, il.solde"; $sql .= " FROM " . MAIN_DB_PREFIX . "immo_loyer as il "; $sql .= " WHERE il.solde<>0 AND paye=0 AND periode_du<'" . $this->db->idate($loyer->periode_du) . "'"; $sql .= " AND local_id=" . $loyer->local_id . " AND locataire_id=" . $loyer->locataire_id; $sql .= " ORDER BY echeance ASC"; dol_syslog(get_class($this) . ':: loyerAntierieur sql=' . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); if ($num > 0) { // Bloc Solde Anterieur $posX = $this->marge_gauche; $posY = $pdf->getY() + ($newpoy - $posY) + 5; $widthbox = $this->page_largeur - $this->marge_gauche - $this->marge_droite; $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 15); $pdf->SetXY($posX, $posY); $pdf->MultiCell($widthbox, 3, $outputlangs->convToOutputCharset('Solde Anterieur'), 1, 'C'); $text = '<table>'; // print $sql; dol_syslog(get_class($this) . ':: loyerAntierieur sql=' . $sql, LOG_DEBUG); $resql = $this->db->query($sql); $i = 0; $total = 0; $var = True; while ($i < $num) { $objp = $this->db->fetch_object($resql); $text .= '<tr>'; $text .= '<td>' . $objp->nom . "</td>"; $text .= "<td align=\"right\">" . $objp->solde . ' ' . $langs->trans("Currency" . $conf->currency) . "</td>"; $text .= "</tr>"; $i++; } $this->db->free($resql); $text .= "</table>"; $posY = $pdf->getY(); $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 13); $pdf->writeHTMLCell($widthbox, 0, $posX, $posY, dol_htmlentitiesbr($text), 1, 1); } } // Bloc total somme due // Tableau total somme due $sql = "SELECT SUM(il.solde) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "immo_loyer as il "; $sql .= " WHERE il.solde<>0 AND paye=0 AND periode_du<='" . $this->db->idate($loyer->periode_du) . "'"; $sql .= " AND local_id=" . $loyer->local_id . " AND locataire_id=" . $loyer->locataire_id; $sql .= " GROUP BY local_id,locataire_id"; // print $sql; dol_syslog(get_class($this) . ':: loyerAntierieur sql=' . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); if ($num > 0) { $objp = $this->db->fetch_object($resql); $posX = $this->marge_gauche; $posY = $pdf->getY() + 5; $widthbox = $this->page_largeur - $this->marge_gauche - $this->marge_droite; $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 15); $pdf->SetXY($posX, $posY); if ($objp->total > 0) { $title = 'Total somme due'; } else { $title = 'Total somme à rembouser'; } $pdf->MultiCell($widthbox, 3, $outputlangs->convToOutputCharset($title), 1, 'C'); $text = '<table>'; $i = 0; $total = 0; $text .= '<tr>'; $text .= "<td align=\"right\">" . $objp->total . ' ' . $langs->trans("Currency" . $conf->currency) . "</td></tr>"; $this->db->free($resql); $text .= "</table>"; $posY = $pdf->getY(); $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 13); $pdf->writeHTMLCell($widthbox, 0, $posX, $posY, dol_htmlentitiesbr($text), 1); } } } $pdf->Close(); $pdf->Output($file, 'F'); if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } return 1; // Pas d'erreur } else { $this->error = $langs->trans("ErrorConstantNotDefined", "AGF_OUTPUTDIR"); return 0; } $this->error = $langs->trans("ErrorUnknown"); return 0; // Erreur par defaut }