Fix showing duplicata

This commit is contained in:
Laurent Destailleur 2026-06-06 19:33:41 +02:00
parent ebe0a857bf
commit 0c72f820a9
6 changed files with 34 additions and 29 deletions

View file

@ -75,18 +75,9 @@ if ($element === 'facture') { // Test on permission done in top of page
if ($facture->fetch($id) > 0) {
//print 'Object '.$element.' logged with action code = '.$action." pos_print_counter is currently ".$facture->pos_print_counter;
/* Increase of counter is now managed inside the document.php file
if ($facture->status > Facture::STATUS_DRAFT) {
// Increase counter by 1
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET pos_print_counter = pos_print_counter + 1";
$sql .= " WHERE rowid = ".((int) $facture->id);
$db->query($sql);
$facture->pos_print_counter += 1;
// $facture->update($user, 1); // disabled update, we did a direct sql update before. We disable trigger here because we already call the trigger $action = DOC_PREVIEW or DOC_DOWNLOAD just after.
}
*/
// Increase of counter is managed by the file that generate the ticket, so "receipt.php"
// Call trigger to log the $action 'DOC_PREVIEW' or 'DOC_DOWNLOAD'
$facture->call_trigger($action, $user);
}

View file

@ -376,7 +376,7 @@ class Facture extends CommonInvoice
'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'visible' => -1, 'position' => 310),
'module_source' => array('type' => 'varchar(32)', 'label' => 'POSModule', 'langfile' => 'cashdesk', 'enabled' => "(isModEnabled('cashdesk') || isModEnabled('takepos') || getDolGlobalInt('INVOICE_SHOW_POS'))", 'visible' => -1, 'position' => 315),
'pos_source' => array('type' => 'varchar(32)', 'label' => 'POSTerminal', 'langfile' => 'cashdesk', 'enabled' => "(isModEnabled('cashdesk') || isModEnabled('takepos') || getDolGlobalInt('INVOICE_SHOW_POS'))", 'visible' => -1, 'position' => 320),
'pos_print_counter' => array('type' => 'varchar(32)', 'label' => 'PrintCount', 'langfile' => 'cashdesk', 'enabled' => "(isModEnabled('cashdesk') || isModEnabled('takepos') || getDolGlobalInt('INVOICE_SHOW_POS'))", 'visible' => 0, 'position' => 325),
'pos_print_counter' => array('type' => 'integer', 'label' => 'PrintCount', 'langfile' => 'cashdesk', 'enabled' => "(isModEnabled('cashdesk') || isModEnabled('takepos') || getDolGlobalInt('INVOICE_SHOW_POS'))", 'visible' => 0, 'position' => 325),
'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 500),
'tms' => array('type' => 'timestamp', 'label' => 'DateModificationShort', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 502),
'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -1, 'position' => 506),
@ -2374,7 +2374,7 @@ class Facture extends CommonInvoice
$this->module_source = $obj->module_source;
$this->pos_source = $obj->pos_source;
$this->pos_print_counter = $obj->pos_print_counter;
$this->pos_print_counter = (int) $obj->pos_print_counter;
$this->email_sent_counter = $obj->email_sent_counter;
// Multicurrency

View file

@ -23,6 +23,8 @@
* \ingroup core
* \brief Code for actions print_file to print file (with calling trigger) when using the Direct Print feature.
* The relative filename to print must be provided into GETPOST('file', 'alpha') parameter
*
* This file is no more used for certified version, direct print feature has been disabled.
*/
@ -85,7 +87,7 @@ if ($action == 'print_file' && $user->hasRight('printing', 'read')) {
$db->query($sql);
//$tmpinvoice->pos_print_counter += 1;
//$tmpinvoice->update($user, 1); // We disable trigger here because we already call the trigger $action = DOC_PREVIEW or DOC_DOWNLOAD just after
//$tmpinvoice->update($user, 1); // We disable trigger here because we already call the trigger $action = DOC_PREVIEW or DOC_DOWNLOAD just after
}
}

View file

@ -405,15 +405,19 @@ if ($modulepart == 'facture') {
dol_syslog("Print for action=".$action.". Current counter of this non draft invoice is already ".$invoice->id.", so file was already printed, so we regenerate the PDF to add mention DUPLICATA", LOG_DEBUG);
// Increase counter by 1
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET pos_print_counter = pos_print_counter + 1";
$sql .= " WHERE rowid = ".((int) $invoice->id);
$db->query($sql);
// $object->pos_print_counter is current value. We increase it here.
if ($object->status == $object::STATUS_CLOSED) {
// Increase counter by 1
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET pos_print_counter = pos_print_counter + 1";
$sql .= " WHERE rowid = ".((int) $invoice->id);
$db->query($sql);
$invoice->pos_print_counter += 1;
//$invoice->update($user, 1); // disabled update, we already did a direct sql update before. We disable trigger here because we already call the trigger $action = DOC_PREVIEW or DOC_DOWNLOAD just after.
$invoice->pos_print_counter += 1;
//$invoice->update($user, 1); // disabled update, we already did a direct sql update before. We disable trigger here because we already call the trigger $action = DOC_PREVIEW or DOC_DOWNLOAD just after.
}
// When we reach the second print, we must regenerate the document to have the mention duplicate on PDF
// When we reach the second print, we must regenerate the document to have the mention duplicata on PDF)
// No need if we are at print 3, 4 or more. The PDF was regenerated when counter was 2,
if ($invoice->pos_print_counter == 2) {
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang(GETPOST('lang'));

View file

@ -1358,7 +1358,12 @@ if (empty($reshook)) {
if (($action == "valid" || $action == "history" || $action == 'creditnote' || ($action == 'addline' && $invoice->status == $invoice::STATUS_CLOSED)) && $user->hasRight('takepos', 'run')) {
$sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n";
$sectionwithinvoicelink .= '<span style="font-size:120%;" class="center inline-block marginbottomonly">';
$sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." - ";
if ($invoice->status == $invoice::STATUS_DRAFT) {
$sectionwithinvoicelink .= $invoice->ref;
} else {
$sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice');
}
$sectionwithinvoicelink .= " - ";
$remaintopay = $invoice->getRemainToPay();
if ($remaintopay > 0) {
$sectionwithinvoicelink .= $langs->trans('RemainToPay').': <span class="amountremaintopay" style="font-size: unset">'.price($remaintopay, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
@ -1870,7 +1875,8 @@ if ($usediv) {
}
$buttontocreatecreditnote = '';
if (($action == "valid" || $action == "history" || ($action == "addline" && $invoice->status == $invoice::STATUS_CLOSED)) && $invoice->type != Facture::TYPE_CREDIT_NOTE && !getDolGlobalString('TAKEPOS_NO_CREDITNOTE')) {
if (($action == "valid" || $action == "history" || $action == "addline")
&& $invoice->type != Facture::TYPE_CREDIT_NOTE && !getDolGlobalString('TAKEPOS_NO_CREDITNOTE') && $invoice->status == $invoice::STATUS_CLOSED) {
$buttontocreatecreditnote .= ' &nbsp; <!-- Show button to create a credit note -->'."\n";
$buttontocreatecreditnote .= '<button id="buttonprint" type="button" onclick="ModalBox(\'ModalCreditNote\')">'.$langs->trans('CreateCreditNote').'</button>';
if (getDolGlobalInt('TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT')) {

View file

@ -289,13 +289,14 @@ if (isALNERunningVersion() && isModEnabled('blockedlog')) {
}
// $object->pos_print_counter is current value. We increase it here.
if ($object->status == $object::STATUS_CLOSED) {
// If no more a temporary receipt, we increase counter by 1
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET pos_print_counter = pos_print_counter + 1";
$sql .= " WHERE rowid = ".((int) $object->id);
$db->query($sql);
// Increase counter by 1
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET pos_print_counter = pos_print_counter + 1";
$sql .= " WHERE rowid = ".((int) $object->id);
$db->query($sql);
$object->pos_print_counter += 1;
$object->pos_print_counter += 1;
}
// Show if it is a duplicata
$isADuplicata = ($object->pos_print_counter >= 2);
@ -590,6 +591,7 @@ if (!GETPOST('forcenoautoopen') && !GETPOST('specimen') && empty($nojs)) {
<script type="text/javascript">
<?php
if ($facid) {
print 'console.log("ref = '.$object->ref.' - pos_print_counter = '.$object->pos_print_counter.'");';
print 'window.print();';
} //Avoid print when is specimen
?>