Merge branch '16.0' of git@github.com:Dolibarr/dolibarr.git into develop
This commit is contained in:
commit
d7209f1818
@ -1507,12 +1507,13 @@ class Propal extends CommonObject
|
||||
/**
|
||||
* Load a proposal from database. Get also lines.
|
||||
*
|
||||
* @param int $rowid id of object to load
|
||||
* @param string $ref Ref of proposal
|
||||
* @param string $ref_ext Ref ext of proposal
|
||||
* @return int >0 if OK, <0 if KO
|
||||
* @param int $rowid Id of object to load
|
||||
* @param string $ref Ref of proposal
|
||||
* @param string $ref_ext Ref ext of proposal
|
||||
* @param int $forceentity Entity id to force when searching on ref or ref_ext
|
||||
* @return int >0 if OK, <0 if KO
|
||||
*/
|
||||
public function fetch($rowid, $ref = '', $ref_ext = '')
|
||||
public function fetch($rowid, $ref = '', $ref_ext = '', $forceentity = 0)
|
||||
{
|
||||
$sql = "SELECT p.rowid, p.ref, p.entity, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc";
|
||||
$sql .= ", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
|
||||
@ -1551,10 +1552,15 @@ class Propal extends CommonObject
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON p.fk_input_reason = dr.rowid';
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON p.fk_incoterms = i.rowid';
|
||||
|
||||
if ($ref) {
|
||||
$sql .= " WHERE p.entity IN (".getEntity('propal').")"; // Dont't use entity if you use rowid
|
||||
if (!empty($ref)) {
|
||||
if (!empty($forceentity)) {
|
||||
$sql .= " WHERE p.entity = ".(int) $forceentity; // Check only the current entity because we may have the same reference in several entities
|
||||
} else {
|
||||
$sql .= " WHERE p.entity IN (".getEntity('propal').")";
|
||||
}
|
||||
$sql .= " AND p.ref='".$this->db->escape($ref)."'";
|
||||
} else {
|
||||
// Dont't use entity if you use rowid
|
||||
$sql .= " WHERE p.rowid = ".((int) $rowid);
|
||||
}
|
||||
|
||||
@ -3812,7 +3818,7 @@ class Propal extends CommonObject
|
||||
* @param int $hidedetails Hide details of lines
|
||||
* @param int $hidedesc Hide description
|
||||
* @param int $hideref Hide ref
|
||||
* @param null|array $moreparams Array to provide more information
|
||||
* @param null|array $moreparams Array to provide more information
|
||||
* @return int 0 if KO, 1 if OK
|
||||
*/
|
||||
public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
|
||||
|
||||
@ -53,6 +53,7 @@ if (is_numeric($entity)) {
|
||||
define("DOLENTITY", $entity);
|
||||
}
|
||||
include '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
|
||||
@ -123,33 +124,64 @@ if ($action == "importSignature") {
|
||||
|
||||
if (!$error) {
|
||||
// Defined modele of doc
|
||||
$directdownloadlink = $object->getLastMainDocLink('proposal');
|
||||
$last_main_doc_file = $object->last_main_doc;
|
||||
$directdownloadlink = $object->getLastMainDocLink('proposal'); // url to download the $object->last_main_doc
|
||||
|
||||
if (preg_match('/\.pdf/i', $directdownloadlink)) {
|
||||
if (preg_match('/\.pdf/i', $last_main_doc_file)) {
|
||||
// TODO Use the $last_main_doc_file to defined the $newpdffilename and $sourcefile
|
||||
$newpdffilename = $upload_dir.$ref."_signed-".$date.".pdf";
|
||||
$sourcefile = $upload_dir.$ref.".pdf";
|
||||
|
||||
if (dol_is_file($sourcefile)) {
|
||||
// We build the new PDF
|
||||
$pdf = pdf_getInstance();
|
||||
$pdf->Open();
|
||||
$pdf->AddPage();
|
||||
$pagecount = $pdf->setSourceFile($sourcefile); // original PDF
|
||||
if (class_exists('TCPDF')) {
|
||||
$pdf->setPrintHeader(false);
|
||||
$pdf->setPrintFooter(false);
|
||||
}
|
||||
$pdf->SetFont(pdf_getPDFFont($langs));
|
||||
|
||||
for ($i=1; $i<($pagecount+1); $i++) {
|
||||
if ($i>1) $pdf->AddPage();
|
||||
$tppl=$pdf->importPage($i);
|
||||
$pdf->useTemplate($tppl);
|
||||
if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
|
||||
$pdf->SetCompression(false);
|
||||
}
|
||||
|
||||
$pdf->Image($upload_dir.$filename, 129, 239.6, 60, 15); // FIXME Position will be wrong with non A4 format. Use a value from width and height of page minus relative offset.
|
||||
$pdf->Close();
|
||||
|
||||
//$pdf->Open();
|
||||
$pagecount = $pdf->setSourceFile($sourcefile); // original PDF
|
||||
|
||||
$s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
|
||||
for ($i=1; $i<($pagecount+1); $i++) {
|
||||
try {
|
||||
$tppl = $pdf->importPage($i);
|
||||
$s = $pdf->getTemplatesize($tppl);
|
||||
$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
|
||||
$pdf->useTemplate($tppl);
|
||||
} catch (Exception $e) {
|
||||
dol_syslog("Error when manipulating some PDF by onlineSign: ".$e->getMessage(), LOG_ERR);
|
||||
$response = $e->getMessage();
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
// A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
|
||||
// TODO Get position of box from PDF template
|
||||
$xforimgstart = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
|
||||
$yforimgstart = (empty($s['h']) ? 240 : $s['h'] - 60);
|
||||
$wforimg = $s['w'] - 20 - $xforimgstart;
|
||||
|
||||
$pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
|
||||
//$pdf->Close();
|
||||
$pdf->Output($newpdffilename, "F");
|
||||
|
||||
// Index the new file and update the last_main_doc property of object.
|
||||
$object->indexFile($newpdffilename, 1);
|
||||
}
|
||||
} elseif (preg_match('/\.odt/i', $last_main_doc_file)) {
|
||||
// Adding signature on .ODT not yet supported
|
||||
// TODO
|
||||
} else {
|
||||
// Adding signature on doc not yet supported
|
||||
// Document format not supported to insert online signature.
|
||||
// We should just create an image file with the signature.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1043,7 +1043,8 @@ abstract class CommonObject
|
||||
// Add entry into index
|
||||
if ($initsharekey) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
|
||||
// TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first
|
||||
|
||||
// TODO We can't, we dont' have full path of file, only last_main_doc and ->element, so we must first rebuild full path $destfull
|
||||
/*
|
||||
$ecmfile->filepath = $rel_dir;
|
||||
$ecmfile->filename = $filename;
|
||||
|
||||
@ -39,7 +39,7 @@ if (!defined('NOBROWSERNOTIF')) {
|
||||
|
||||
// For MultiCompany module.
|
||||
// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
|
||||
// TODO This should be useless. Because entity must be retrieve from object ref and not from url.
|
||||
// Because 2 entities can have the same ref.
|
||||
$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
|
||||
if (is_numeric($entity)) {
|
||||
define("DOLENTITY", $entity);
|
||||
@ -51,7 +51,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
|
||||
|
||||
// Load translation files
|
||||
$langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "members", "paybox", "propal", "commercial"));
|
||||
@ -125,8 +124,9 @@ $creditor = $mysoc->name;
|
||||
|
||||
$type = $source;
|
||||
if ($source == 'proposal') {
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
|
||||
$object = new Propal($db);
|
||||
$object->fetch(0, $ref);
|
||||
$result= $object->fetch(0, $ref, '', $entity);
|
||||
} else {
|
||||
accessforbidden('Bad value for source');
|
||||
exit;
|
||||
@ -290,16 +290,7 @@ if ($source == 'proposal') {
|
||||
$found = true;
|
||||
$langs->load("proposal");
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
|
||||
|
||||
$proposal = new Propal($db);
|
||||
$result = $proposal->fetch('', $ref);
|
||||
if ($result <= 0) {
|
||||
$mesg = $proposal->error;
|
||||
$error++;
|
||||
} else {
|
||||
$result = $proposal->fetch_thirdparty($proposal->socid);
|
||||
}
|
||||
$result = $object->fetch_thirdparty($object->socid);
|
||||
|
||||
// Creditor
|
||||
|
||||
@ -315,39 +306,47 @@ if ($source == 'proposal') {
|
||||
print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
|
||||
print '</td><td class="CTableRow2">';
|
||||
print img_picto('', 'company', 'class="pictofixedwidth"');
|
||||
print '<b>'.$proposal->thirdparty->name.'</b>';
|
||||
print '<b>'.$object->thirdparty->name.'</b>';
|
||||
print '</td></tr>'."\n";
|
||||
|
||||
// Amount
|
||||
|
||||
print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
|
||||
print '</td><td class="CTableRow2">';
|
||||
print '<b>'.price($proposal->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).'</b>';
|
||||
print '<b>'.price($object->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).'</b>';
|
||||
print '</td></tr>'."\n";
|
||||
|
||||
// Object
|
||||
|
||||
$text = '<b>'.$langs->trans("SignatureProposalRef", $proposal->ref).'</b>';
|
||||
$text = '<b>'.$langs->trans("SignatureProposalRef", $object->ref).'</b>';
|
||||
print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
|
||||
print '</td><td class="CTableRow2">'.$text;
|
||||
if ($proposal->status == $proposal::STATUS_VALIDATED) {
|
||||
$directdownloadlink = $proposal->getLastMainDocLink('proposal');
|
||||
|
||||
$last_main_doc_file = $object->last_main_doc;
|
||||
|
||||
if ($object->status == $object::STATUS_VALIDATED) {
|
||||
if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
|
||||
// It seems document has never been generated, or was generated and then deleted.
|
||||
// So we try to regenerate it with its default template.
|
||||
$defaulttemplate = ''; // We force the use an empty string instead of $object->model_pdf to be sure to use a "main" default template and not the last one used.
|
||||
$object->generateDocument($defaulttemplate, $langs);
|
||||
}
|
||||
|
||||
$directdownloadlink = $object->getLastMainDocLink('proposal');
|
||||
if ($directdownloadlink) {
|
||||
print '<br><a href="'.$directdownloadlink.'">';
|
||||
print img_mime($proposal->last_main_doc, '');
|
||||
print img_mime($object->last_main_doc, '');
|
||||
print $langs->trans("DownloadDocument").'</a>';
|
||||
}
|
||||
} else {
|
||||
$last_main_doc_file = $proposal->last_main_doc;
|
||||
|
||||
if ($proposal->status == $proposal::STATUS_NOTSIGNED) {
|
||||
$directdownloadlink = $proposal->getLastMainDocLink('proposal');
|
||||
if ($object->status == $object::STATUS_NOTSIGNED) {
|
||||
$directdownloadlink = $object->getLastMainDocLink('proposal');
|
||||
if ($directdownloadlink) {
|
||||
print '<br><a href="'.$directdownloadlink.'">';
|
||||
print img_mime($proposal->last_main_doc, '');
|
||||
print img_mime($last_main_doc_file, '');
|
||||
print $langs->trans("DownloadDocument").'</a>';
|
||||
}
|
||||
} elseif ($proposal->status == $proposal::STATUS_SIGNED || $proposal->status == $proposal::STATUS_BILLED) {
|
||||
} elseif ($object->status == $object::STATUS_SIGNED || $object->status == $object::STATUS_BILLED) {
|
||||
if (preg_match('/_signed-(\d+)/', $last_main_doc_file)) { // If the last main doc has been signed
|
||||
$last_main_doc_file_not_signed = preg_replace('/_signed-(\d+)/', '', $last_main_doc_file);
|
||||
|
||||
@ -355,10 +354,10 @@ if ($source == 'proposal') {
|
||||
$datefilenotsigned = dol_filemtime($last_main_doc_file_not_signed);
|
||||
|
||||
if (empty($datefilenotsigned) || $datefilesigned > $datefilenotsigned) {
|
||||
$directdownloadlink = $proposal->getLastMainDocLink('proposal');
|
||||
$directdownloadlink = $object->getLastMainDocLink('proposal');
|
||||
if ($directdownloadlink) {
|
||||
print '<br><a href="'.$directdownloadlink.'">';
|
||||
print img_mime($proposal->last_main_doc, '');
|
||||
print img_mime($object->last_main_doc, '');
|
||||
print $langs->trans("DownloadDocument").'</a>';
|
||||
}
|
||||
}
|
||||
@ -367,10 +366,8 @@ if ($source == 'proposal') {
|
||||
}
|
||||
|
||||
print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
|
||||
print '<input type="hidden" name="ref" value="'.$proposal->ref.'">';
|
||||
print '<input type="hidden" name="ref" value="'.$object->ref.'">';
|
||||
print '</td></tr>'."\n";
|
||||
|
||||
// TODO Add link to download PDF (similar code than for invoice)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user