Debug Receipt printer module and reduce duplicate translation key

This commit is contained in:
Laurent Destailleur 2020-06-20 15:19:19 +02:00
parent b54c18730b
commit ccc55dcb1e
4 changed files with 152 additions and 141 deletions

View File

@ -260,7 +260,8 @@ if ($mode == 'config' && $user->admin) {
print '<input type="hidden" name="action" value="updateprinter">';
}
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
print $langs->trans("ReceiptPrinterDesc")."<br><br>\n";
@ -346,11 +347,11 @@ if ($mode == 'config' && $user->admin) {
}
print '</form>';
print '<div><p></div>';
print '<br>';
dol_fiche_head();
print $langs->trans("ReceiptPrinterTypeDesc")."<br><br>\n";
print load_fiche_titre($langs->trans("ReceiptPrinterTypeDesc"), '', '')."\n";
print '<table class="noborder centpercent">'."\n";
print '<tr class="oddeven"><td>'.$langs->trans("CONNECTOR_DUMMY").':</td><td>'.$langs->trans("CONNECTOR_DUMMY_HELP").'</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans("CONNECTOR_NETWORK_PRINT").':</td><td>'.$langs->trans("CONNECTOR_NETWORK_PRINT_HELP").'</td></tr>';
@ -358,12 +359,12 @@ if ($mode == 'config' && $user->admin) {
print '<tr class="oddeven"><td>'.$langs->trans("CONNECTOR_WINDOWS_PRINT").':</td><td>'.$langs->trans("CONNECTOR_WINDOWS_PRINT_HELP").'</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans("CONNECTOR_CUPS_PRINT").':</td><td>'.$langs->trans("CONNECTOR_CUPS_PRINT_HELP").'</td></tr>';
print '</table>';
dol_fiche_end();
print '<div><p></div>';
print '<br>';
print load_fiche_titre($langs->trans("ReceiptPrinterProfileDesc"), '', '')."\n";
dol_fiche_head();
print $langs->trans("ReceiptPrinterProfileDesc")."<br><br>\n";
print '<table class="noborder centpercent">'."\n";
print '<tr class="oddeven"><td>'.$langs->trans("PROFILE_DEFAULT").':</td><td>'.$langs->trans("PROFILE_DEFAULT_HELP").'</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans("PROFILE_SIMPLE").':</td><td>'.$langs->trans("PROFILE_SIMPLE_HELP").'</td></tr>';
@ -371,7 +372,6 @@ if ($mode == 'config' && $user->admin) {
print '<tr class="oddeven"><td>'.$langs->trans("PROFILE_P822D").':</td><td>'.$langs->trans("PROFILE_P822D_HELP").'</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans("PROFILE_STAR").':</td><td>'.$langs->trans("PROFILE_STAR_HELP").'</td></tr>';
print '</table>';
dol_fiche_end();
}
if ($mode == 'template' && $user->admin) {
@ -383,9 +383,9 @@ if ($mode == 'template' && $user->admin) {
print '<input type="hidden" name="action" value="updatetemplate">';
}
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
print $langs->trans("ReceiptPrinterTemplateDesc")."<br><br>\n";
print load_fiche_titre($langs->trans("ReceiptPrinterTemplateDesc"), '', '')."<br><br>\n";
print '<table class="noborder centpercent">'."\n";
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Name").'</th>';
@ -412,15 +412,15 @@ if ($mode == 'template' && $user->admin) {
print '<td>'.$printer->listprinterstemplates[$line]['name'].'</td>';
print '<td>'.nl2br(htmlentities($printer->listprinterstemplates[$line]['template'])).'</td>';
// edit icon
print '<td><a href="'.$_SERVER['PHP_SELF'].'?mode=template&amp;action=edittemplate&amp;templateid='.$printer->listprinterstemplates[$line]['rowid'].'">';
print '<td><a class="editfielda paddingleftonly paddingrightonly" href="'.$_SERVER['PHP_SELF'].'?mode=template&amp;action=edittemplate&amp;templateid='.$printer->listprinterstemplates[$line]['rowid'].'">';
print img_picto($langs->trans("Edit"), 'edit');
print '</a>';
// delete icon
print '<a href="'.$_SERVER['PHP_SELF'].'?mode=template&amp;action=deletetemplate&amp;templateid='.$printer->listprinterstemplates[$line]['rowid'].'&amp;templatename='.$printer->listprinterstemplates[$line]['name'].'">';
print '<a class="paddingleftonly paddingrightonly" href="'.$_SERVER['PHP_SELF'].'?mode=template&amp;action=deletetemplate&amp;templateid='.$printer->listprinterstemplates[$line]['rowid'].'&amp;templatename='.$printer->listprinterstemplates[$line]['name'].'">';
print img_picto($langs->trans("Delete"), 'delete');
print '</a>';
// test icon
print '<a href="'.$_SERVER['PHP_SELF'].'?mode=template&amp;action=testtemplate&amp;templateid='.$printer->listprinterstemplates[$line]['rowid'].'&amp;templatename='.$printer->listprinterstemplates[$line]['name'].'">';
print '<a class="paddingleftonly paddingrightonly" href="'.$_SERVER['PHP_SELF'].'?mode=template&amp;action=testtemplate&amp;templateid='.$printer->listprinterstemplates[$line]['rowid'].'&amp;templatename='.$printer->listprinterstemplates[$line]['name'].'">';
print img_picto($langs->trans("TestPrinterTemplate"), 'printer');
print '</a></td>';
}
@ -441,21 +441,22 @@ if ($mode == 'template' && $user->admin) {
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'"></div>';
}
print '</form>';
print '<div><p></div>';
print '<br>';
print '<table class="noborder centpercent">'."\n";
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Tag").'</th>';
print '<th>'.$langs->trans("Description").'</th>';
print "</tr>\n";
$max = count($printer->tags);
for ($tag = 0; $tag < $max; $tag++) {
$langs->loadLangs(array("bills", "companies"));
foreach ($printer->tags as $key => $val) {
print '<tr class="oddeven">';
print '<td>&lt;'.$printer->tags[$tag].'&gt;</td><td>'.$langs->trans(strtoupper($printer->tags[$tag])).'</td>';
print '<td>&lt;'.$key.'&gt;</td><td>'.$langs->trans($val).'</td>';
print '</tr>';
}
print '</table>';
dol_fiche_end();
}
// End of page

View File

@ -158,79 +158,72 @@ class dolReceiptPrinter extends Printer
{
$this->db = $db;
$this->tags = array(
'dol_line_feed',
'dol_line_feed_reverse',
'dol_align_left',
'dol_align_center',
'dol_align_right',
'dol_use_font_a',
'dol_use_font_b',
'dol_use_font_c',
'dol_bold',
'dol_bold_disabled',
'dol_double_height',
'dol_double_width',
'dol_default_height_width',
'dol_underline',
'dol_underline_disabled',
'dol_cut_paper_full',
'dol_cut_paper_partial',
'dol_open_drawer',
'dol_beep',
'dol_print_text',
'dol_print_barcode',
'dol_value_date',
'dol_value_date_time',
'dol_value_year',
'dol_value_month_letters',
'dol_value_month',
'dol_value_day',
'dol_value_day_letters',
'dol_line_feed' => 'DOL_LINE_FEED',
'dol_line_feed_reverse' => 'DOL_LINE_FEED_REVERSE',
'dol_align_left' => 'DOL_ALIGN_LEFT',
'dol_align_center' => 'DOL_ALIGN_CENTER',
'dol_align_right' => 'DOL_ALIGN_RIGHT',
'dol_use_font_a' => 'DOL_USE_FONT_A',
'dol_use_font_b' => 'DOL_USE_FONT_B',
'dol_use_font_c' => 'DOL_USE_FONT_C',
'dol_bold' => 'DOL_BOLD',
'dol_bold_disabled' => 'DOL_BOLD_DISABLED',
'dol_double_height' => 'DOL_DOUBLE_HEIGHT',
'dol_double_width' => 'DOL_DOUBLE_WIDTH',
'dol_default_height_width' => 'DOL_DEFAULT_HEIGHT_WIDTH',
'dol_underline' => 'DOL_UNDERLINE',
'dol_underline_disabled' => 'DOL_UNDERLINE_DISABLED',
'dol_cut_paper_full' => 'DOL_CUT_PAPER_FULL',
'dol_cut_paper_partial' => 'DOL_CUT_PAPER_PARTIAL',
'dol_open_drawer' => 'DOL_OPEN_DRAWER',
'dol_beep' => 'DOL_BEEP',
'dol_print_text' => 'DOL_PRINT_TEXT',
'dol_print_barcode' => 'DOL_PRINT_BARCODE',
'dol_value_date' => 'DateInvoice',
'dol_value_date_time' => 'DateInvoiceWithTime',
'dol_value_year' => 'YearInvoice',
'dol_value_month_letters' => 'DOL_VALUE_MONTH_LETTERS',
'dol_value_month' => 'DOL_VALUE_MONTH',
'dol_value_day' => 'DOL_VALUE_DAY',
'dol_value_day_letters' => 'DOL_VALUE_DAY',
//'dol_print_payment',
'dol_print_logo',
'dol_print_logo_old',
'dol_value_object_id',
'dol_value_object_ref',
'dol_print_object_lines',
'dol_print_object_tax',
'dol_print_object_local_tax',
'dol_print_object_total',
'dol_print_object_number',
'dol_print_order_lines',
'dol_value_customer_firstname',
'dol_value_customer_lastname',
'dol_value_customer_mail',
'dol_value_customer_phone',
'dol_value_customer_mobile',
'dol_value_customer_skype',
'dol_value_customer_tax_number',
'dol_value_customer_account_balance',
'dol_value_mysoc_name',
'dol_value_mysoc_address',
'dol_value_mysoc_zip',
'dol_value_mysoc_town',
'dol_value_mysoc_country',
'dol_value_mysoc_idprof1',
'dol_value_mysoc_idprof2',
'dol_value_mysoc_idprof3',
'dol_value_mysoc_idprof4',
'dol_value_mysoc_idprof5',
'dol_value_mysoc_idprof6',
'dol_value_mysoc_tva_intra',
'dol_value_mysoc_capital',
'dol_value_vendor_lastname',
'dol_value_vendor_firstname',
'dol_value_vendor_mail',
'dol_value_customer_points',
'dol_value_object_points',
//'dol_print_if_customer',
//'dol_print_if_vendor',
//'dol_print_if_happy_hour',
//'dol_print_if_num_object_unique',
//'dol_print_if_customer_points',
//'dol_print_if_object_points',
//'dol_print_if_customer_tax_number',
//'dol_print_if_customer_account_balance_positive',
'dol_print_logo' => 'DOL_PRINT_LOGO',
'dol_print_logo_old' => 'DOL_PRINT_LOGO_OLD',
'dol_value_object_id' => 'InvoiceID',
'dol_value_object_ref' => 'InvoiceRef',
'dol_print_object_lines' => 'DOL_PRINT_OBJECT_LINES',
'dol_print_object_tax' => 'TotalVAT',
'dol_print_object_local_tax1' => 'TotalLT1',
'dol_print_object_local_tax2' => 'TotalLT2',
'dol_print_object_total' => 'Total',
'dol_print_object_number' => 'DOL_PRINT_OBJECT_NUMBER',
'dol_value_object_points' => 'DOL_VALUE_OBJECT_POINTS',
'dol_print_order_lines' => 'DOL_PRINT_ORDER_LINES',
'dol_value_customer_firstname' => 'DOL_VALUE_CUSTOMER_FIRSTNAME',
'dol_value_customer_lastname' => 'DOL_VALUE_CUSTOMER_LASTNAME',
'dol_value_customer_mail' => 'DOL_VALUE_CUSTOMER_MAIL',
'dol_value_customer_phone' => 'DOL_VALUE_CUSTOMER_PHONE',
'dol_value_customer_mobile' => 'DOL_VALUE_CUSTOMER_MOBILE',
'dol_value_customer_skype' => 'DOL_VALUE_CUSTOMER_SKYPE',
'dol_value_customer_tax_number' => 'DOL_VALUE_CUSTOMER_TAX_NUMBER',
'dol_value_customer_account_balance' => 'DOL_VALUE_CUSTOMER_ACCOUNT_BALANCE',
'dol_value_customer_points' => 'DOL_VALUE_CUSTOMER_POINTS',
'dol_value_mysoc_name' => 'DOL_VALUE_MYSOC_NAME',
'dol_value_mysoc_address' => 'Address',
'dol_value_mysoc_zip' => 'Zip',
'dol_value_mysoc_town' => 'Town',
'dol_value_mysoc_country' => 'Country',
'dol_value_mysoc_idprof1' => 'ProfId1',
'dol_value_mysoc_idprof2' => 'ProfId2',
'dol_value_mysoc_idprof3' => 'ProfId3',
'dol_value_mysoc_idprof4' => 'ProfId4',
'dol_value_mysoc_idprof5' => 'ProfId5',
'dol_value_mysoc_idprof6' => 'ProfId6',
'dol_value_mysoc_tva_intra' => 'VATIntra',
'dol_value_mysoc_capital' => 'Capital',
'dol_value_vendor_lastname' => 'VendorLastname',
'dol_value_vendor_firstname' => 'VendorFirstname',
'dol_value_vendor_mail' => 'VendorEmail',
);
}
@ -545,14 +538,14 @@ class dolReceiptPrinter extends Printer
/**
* Function to Print Receipt Ticket
*
* @param object $object order or invoice object
* @param int $templateid Template id
* @param int $printerid Printer id
* @return int 0 if OK; >0 if KO
* @param Facture|Commande $object Order or invoice object
* @param int $templateid Template id
* @param int $printerid Printer id
* @return int 0 if OK; >0 if KO
*/
public function sendToPrinter($object, $templateid, $printerid)
{
global $conf, $mysoc, $langs;
global $conf, $mysoc, $langs, $user;
$error = 0;
$ret = $this->loadTemplate($templateid);
@ -560,15 +553,23 @@ class dolReceiptPrinter extends Printer
$this->template = str_replace('<dol_value_object_id>', $object->id, $this->template);
$this->template = str_replace('<dol_value_object_ref>', $object->ref, $this->template);
$this->template = str_replace('<dol_value_object_points>', $object->points, $this->template);
$this->template = str_replace('<dol_value_customer_firstname>', $object->customer_firstname, $this->template);
$this->template = str_replace('<dol_value_customer_lastname>', $object->customer_lastname, $this->template);
$this->template = str_replace('<dol_value_customer_mail>', $object->customer_mail, $this->template);
$this->template = str_replace('<dol_value_customer_phone>', $object->customer_phone, $this->template);
$this->template = str_replace('<dol_value_customer_mobile>', $object->customer_mobile, $this->template);
$this->template = str_replace('<dol_value_customer_skype>', $object->customer_skype, $this->template);
$this->template = str_replace('<dol_value_customer_tax_number>', $object->customer_tax_number, $this->template);
$this->template = str_replace('<dol_value_date>', dol_print_date($object->date, 'day'), $this->template);
$this->template = str_replace('<dol_value_date_time>', dol_print_date($object->date, 'dayhour'), $this->template);
$this->template = str_replace('<dol_value_year>', dol_print_date($object->date, '%Y'), $this->template);
$this->template = str_replace('<dol_value_month_letters>', $langs->trans("Month".dol_print_date($object->date, '%m')), $this->template);
$this->template = str_replace('<dol_value_month>', dol_print_date($object->date, '%m'), $this->template);
$this->template = str_replace('<dol_value_day>', dol_print_date($object->date, '%d'), $this->template);
$this->template = str_replace('<dol_value_day_letters>', $langs->trans("Day".dol_print_date($object->date, '%m')[1]), $this->template);
$this->template = str_replace('<dol_value_customer_firstname>', $object->thirdparty->firstname, $this->template);
$this->template = str_replace('<dol_value_customer_lastname>', $object->thirdparty->lastname, $this->template);
$this->template = str_replace('<dol_value_customer_mail>', $object->thirdparty->mail, $this->template);
$this->template = str_replace('<dol_value_customer_phone>', $object->thirdparty->phone, $this->template);
$this->template = str_replace('<dol_value_customer_mobile>', $object->thirdparty->mobile, $this->template);
$this->template = str_replace('<dol_value_customer_tax_number>', $object->thirdparty->vatintra, $this->template);
$this->template = str_replace('<dol_value_customer_account_balance>', $object->customer_account_balance, $this->template);
$this->template = str_replace('<dol_value_customer_points>', $object->customer_points, $this->template);
$this->template = str_replace('<dol_value_mysoc_name>', $mysoc->name, $this->template);
$this->template = str_replace('<dol_value_mysoc_address>', $mysoc->address, $this->template);
$this->template = str_replace('<dol_value_mysoc_zip>', $mysoc->zip, $this->template);
@ -582,16 +583,10 @@ class dolReceiptPrinter extends Printer
$this->template = str_replace('<dol_value_mysoc_idprof6>', $mysoc->idprof6, $this->template);
$this->template = str_replace('<dol_value_mysoc_tva_intra>', $mysoc->tva_intra, $this->template);
$this->template = str_replace('<dol_value_mysoc_capital>', $mysoc->capital, $this->template);
$this->template = str_replace('<dol_value_vendor_firstname>', $object->vendor_firstname, $this->template);
$this->template = str_replace('<dol_value_vendor_lastname>', $object->vendor_lastname, $this->template);
$this->template = str_replace('<dol_value_vendor_mail>', $object->vendor_mail, $this->template);
$this->template = str_replace('<dol_value_date>', dol_print_date($object->date, 'day'), $this->template);
$this->template = str_replace('<dol_value_date_time>', dol_print_date($object->date, 'dayhour'), $this->template);
$this->template = str_replace('<dol_value_year>', dol_print_date($object->date, '%Y'), $this->template);
$this->template = str_replace('<dol_value_month_letters>', $langs->trans("Month".dol_print_date($object->date, '%m')), $this->template);
$this->template = str_replace('<dol_value_month>', dol_print_date($object->date, '%m'), $this->template);
$this->template = str_replace('<dol_value_day>', dol_print_date($object->date, '%d'), $this->template);
$this->template = str_replace('<dol_value_day_letters>', $langs->trans("Day".dol_print_date($object->date, '%m')[1]), $this->template);
$this->template = str_replace('<dol_value_vendor_firstname>', $user->firstname, $this->template);
$this->template = str_replace('<dol_value_vendor_lastname>', $user->lastname, $this->template);
$this->template = str_replace('<dol_value_vendor_mail>', $user->email, $this->template);
// parse template
$p = xml_parser_create();
@ -634,6 +629,26 @@ class dolReceiptPrinter extends Printer
$this->printer->text($spaces.$vatkey.'% '.str_pad(price($vatvalue), 10, ' ', STR_PAD_LEFT)."\n");
}
break;
case 'DOL_PRINT_OBJECT_TAX1':
//var_dump($object);
$total_localtax1 = 0;
foreach ($object->lines as $line) {
$total_localtax1 += $line->total_localtax1;
}
foreach ($vatarray as $vatkey => $vatvalue) {
$this->printer->text(str_pad(price($total_localtax1), 10, ' ', STR_PAD_LEFT)."\n");
}
break;
case 'DOL_PRINT_OBJECT_TAX2':
//var_dump($object);
$total_localtax2 = 0;
foreach ($object->lines as $line) {
$total_localtax2 += $line->total_localtax2;
}
foreach ($vatarray as $vatkey => $vatvalue) {
$this->printer->text(str_pad(price($total_localtax2), 10, ' ', STR_PAD_LEFT)."\n");
}
break;
case 'DOL_PRINT_OBJECT_TOTAL':
$title = $langs->trans('TotalHT');
$spacestoadd = $nbcharactbyline - strlen($title) - 10;

View File

@ -56,16 +56,15 @@ DOL_UNDERLINE=Enable underline
DOL_UNDERLINE_DISABLED=Disable underline
DOL_BEEP=Beed sound
DOL_PRINT_TEXT=Print text
DOL_VALUE_DATE=Invoice date
DOL_VALUE_DATE_TIME=Invoice date and time
DOL_VALUE_YEAR=Invoice year
DateInvoiceWithTime=Invoice date and time
YearInvoice=Invoice year
DOL_VALUE_MONTH_LETTERS=Invoice month in letters
DOL_VALUE_MONTH=Invoice month
DOL_VALUE_DAY=Invoice day
DOL_VALUE_DAY_LETTERS=Inovice day in letters
DOL_LINE_FEED_REVERSE=Line feed reverse
DOL_VALUE_OBJECT_ID=Invoice ID
DOL_VALUE_OBJECT_REF=Invoice ref
InvoiceID=Invoice ID
InvoiceRef=Invoice ref
DOL_PRINT_OBJECT_LINES=Invoice lines
DOL_VALUE_CUSTOMER_FIRSTNAME=Customer first name
DOL_VALUE_CUSTOMER_LASTNAME=Customer last name
@ -76,20 +75,8 @@ DOL_VALUE_CUSTOMER_SKYPE=Customer Skype
DOL_VALUE_CUSTOMER_TAX_NUMBER=Customer tax number
DOL_VALUE_CUSTOMER_ACCOUNT_BALANCE=Customer account balance
DOL_VALUE_MYSOC_NAME=Your company name
DOL_VALUE_MYSOC_ADDRESS=Your company address
DOL_VALUE_MYSOC_ZIP=Your zip code
DOL_VALUE_MYSOC_TOWN=Your town
DOL_VALUE_MYSOC_COUNTRY=Your country
DOL_VALUE_MYSOC_IDPROF1=Your IDPROF1
DOL_VALUE_MYSOC_IDPROF2=Your IDPROF2
DOL_VALUE_MYSOC_IDPROF3=Your IDPROF3
DOL_VALUE_MYSOC_IDPROF4=Your IDPROF4
DOL_VALUE_MYSOC_IDPROF5=Your IDPROF5
DOL_VALUE_MYSOC_IDPROF6=Your IDPROF6
DOL_VALUE_MYSOC_TVA_INTRA=Intra-Community VAT ID
DOL_VALUE_MYSOC_CAPITAL=Capital
DOL_VALUE_VENDOR_LASTNAME=Vendor last name
DOL_VALUE_VENDOR_FIRSTNAME=Vendor first name
DOL_VALUE_VENDOR_MAIL=Vendor mail
VendorLastname=Vendor last name
VendorFirstname=Vendor first name
VendorEmail=Vendor email
DOL_VALUE_CUSTOMER_POINTS=Customer points
DOL_VALUE_OBJECT_POINTS=Object points

View File

@ -117,14 +117,22 @@ if ($conf->receiptprinter->enabled) {
print $langs->trans('DolibarrReceiptPrinter');
print '<td>';
print $langs->trans('ReceiptPrinterMethodDescription');
print '<br>';
print '<a href="'.DOL_URL_ROOT.'/admin/receiptprinter.php">'.$langs->trans("Setup").'</a>';
print '</td><td class="center">';
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter")
{
print img_picto($langs->trans("Activated"), 'switch_on');
}
else
{
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmethod&value=receiptprinter">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
if ($conf->receiptprinter->enabled) {
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter")
{
print img_picto($langs->trans("Activated"), 'switch_on');
}
else
{
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmethod&value=receiptprinter">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
}
} else {
print '<span class="opacitymedium">';
print $langs->trans("ModuleReceiptPrinterMustBeEnabled");
print '</span>';
}
print "</td></tr>\n";
}