if ($facture_id) { $factures[$facture_id] = $facture->load($facture_id); } elseif (count($factures_id)) { $where = array(); $where["facture_id"] = CSQLDataSource::prepareIn(array_keys($factures_id)); $factures = $facture->loadList($where); } else { $where = array(); $where["praticien_id"] = " = '{$prat_id}'"; $where["cloture"] = "BETWEEN '{$date_min}' AND '{$date_max}'"; $factures = $facture->loadList($where, "facture_id DESC", null, "facture_id"); } $facture_pdf = new CEditPdf(); $facture_pdf->factures = $factures; if ($type_pdf == "bvr") { $facture_pdf->editFactureBVR(); } if ($type_pdf == "bvr_TS") { $facture_pdf->editFactureBVR("TS"); } if ($type_pdf == "justificatif") { $facture_pdf->editJustificatif(); } if ($type_pdf == "bvr_justif") { $facture_pdf->editFactureBVRJustif(); } if ($type_pdf == "impression") { $facture_pdf->printBill($tiers_soldant); $journal_pdf = new CEditJournal(); $journal_pdf->type_pdf = "debiteur"; $journal_pdf->factures = $factures;
if (count($factures)) { $printer_justif = new CPrinter(); $printer_justif->function_id = $user->function_id; $printer_justif->label = "justif"; $printer_justif->loadMatchingObject(); if (!$printer_justif->_id) { CAppUI::setMsg("Les imprimantes ne sont pas paramétrées", UI_MSG_ERROR); echo CAppUI::getMsg(); return false; } $file = new CFile(); foreach ($factures as $facture) { $facture_pdf = new CEditPdf(); $facture_pdf->factures = array($facture); $pdf = ""; $pdf = $facture_pdf->editFactureBVR(false, "S"); $file_path = tempnam("tmp", "facture"); $file->_file_path = $file_path; file_put_contents($file_path, $pdf); $printer_bvr->loadRefSource()->sendDocument($file); unlink($file_path); $pdf = ""; $pdf = $facture_pdf->editJustificatif(false, "S"); $file_path = tempnam("tmp", "facture"); $file->_file_path = $file_path; file_put_contents($file_path, $pdf); $printer_justif->loadRefSource()->sendDocument($file); unlink($file_path); } } }
/** * Impression des factures * * @param bool $ts tiers soldant * * @return void */ function printBill($ts = false) { if (count($this->factures)) { $user = CMediusers::get(); $printer_bvr = new CPrinter(); $printer_bvr->function_id = $user->function_id; $printer_bvr->label = "bvr"; $printer_bvr->loadMatchingObject(); $printer_justif = new CPrinter(); $printer_justif->function_id = $user->function_id; $printer_justif->label = "justif"; $printer_justif->loadMatchingObject(); if (!$printer_bvr->_id || !$printer_justif->_id) { CAppUI::setMsg("Les imprimantes ne sont pas paramétrées", UI_MSG_ERROR); echo CAppUI::getMsg(); return false; } $file = new CFile(); foreach ($this->factures as $facture) { $facture_pdf = new CEditPdf(); $facture_pdf->factures = array($facture); $pdf = ""; $pdf = $facture_pdf->editFactureBVR($ts, "S"); $file_path = tempnam("tmp", "facture"); $file->_file_path = $file_path; file_put_contents($file_path, $pdf); $printer_bvr->loadRefSource()->sendDocument($file); unlink($file_path); $pdf = ""; $pdf = $facture_pdf->editJustificatif($ts, "S"); $file_path = tempnam("tmp", "facture"); $file->_file_path = $file_path; file_put_contents($file_path, $pdf); $printer_justif->loadRefSource()->sendDocument($file); unlink($file_path); } } }