Posts

Using 'Group By' to Select the Row with the 'max(date)' and Updating it

update item_rate set rate_of_tax = 18 where id in (select id from (select id from item_rate where date_effective in (select max(date_effective) from item_rate group by item_name)) as t1) Explained : First get the maximum date_effective for each item_name.  Get the item_rate row id for that date  Place it into a temporary table t1  Select the ids from the temporary table  Update the item_rate table, set the rates of tax for the selected row ids from the temporary table.  Note : The temporary table is required because the table to be updated cannot be the same as the table being queried. item_rate Table ------------------------------------------------- | id | date_effective | rate_of_tax | item_name | ------------------------------------------------- | 1  | 01.Jan.2017    |   12.0      |  item1    | | 2  | 15.Jan.2017    |   12.0  ...

How to change the displayed name for a payment module in Prestashop

Often payment modules need to be renamed to something more appropriate for customers to understand them. It is important to display information that a customer would understand, especially when money and payments are involved. Prestashop Version 1.6.0.6 Go to the modules folder on your Prestashop host. Open your module folder, for example : bankwire Go to the translations folder. Edit the .php file which relates to the language, en.php is for English. Changing the rows highlighted below in the en.php file will help change what is displayed to the customer. bankwire_05adcee99142c1a60fb38bb1330bbbc1'] = 'Bank Transfer / NEFT / RTGS / IMPS - You will be provided bank details'; $_MODULE['<{bankwire}prestashop>bankwire_a246a8e9907530c4c36b8b4c37bbc823'] = 'Accept payments for your products via bank wire transfer.'; $_MODULE['<{bankwire}prestashop>bankwire_cbe0a99684b145e77f3e14174ac212e3'] = 'Are you sure about removing these ...

Tabbing In and Out of an Editable JComboBox

Tabbing in and out of an editable JComboBox seems to be really quirky. First we need to disable the default focus traversal keys for the JComboBox editor. editor.setFocusTraversalKeysEnabled(false); Then we add a KeyListener as below : editor.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_TAB: int n = e.getModifiers(); if (n > 0) { comboBox.transferFocusBackward(); } else { comboBox.getEditor().getEditorComponent().transferFocus(); } e.consume(); break; } } }); Notice that to tab forward, we are using the editor component and to tab backward we are using the combobox directly. Any...

How to Convert an ImageIcon to a Base64 encoded String in Java

To convert an ImageIcon to a Base64 encoded string, we first need to convert the ImageIcon to a BufferedImage. The BufferedImage then needs to be converted to a ByteArray using a ByteArrayOutputStream. Then using a Base64 encoder, we can convert the ByteArray to a Base64 String. Particularly useful when trying to save an image loaded into a JLabel  to the database. To get the image from the JLabel, we need to get the ImageIcon from the JLabel using getIcon(); import com.itextpdf.text.pdf.codec.Base64; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import javax.imageio.ImageIO; import java.awt.Graphics; private String ConvertImageIconToBase64String(ImageIcon ii) { // Create a buffered image of the size of the original image icon BufferedImage image = new BufferedImage(ii.getIconWidth(), ii.getIconHeight(), BufferedImage.TYPE_INT_RGB); // Create a graphics object to draw the image Graphics g = image.createGraphics(); // Paint the icon on ...