Invoice sistem: PRINT button with different invoice design.

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
fciprian
Veteran Member
Posts: 52
Joined: 2020-04-20 10:51

Invoice sistem: PRINT button with different invoice design.

Post by fciprian » 2021-12-03 12:40

Hello. I need some help that could solve many "problems".
I have table Invoice. On /hooks i have added this script so i can add the PRINT INVOICE button.
But i need a customization. When a field "Design" is 1 (from the same Invoice table) to go generate with file PrintInvoice.php and where is "2" on filed "Design" to generate with PrintInvoice2.php
So i need to have ONLY 1 button with the different file generation depending on filed "Design"
Here is the script that i have and works but i need the customization:

<script>
$j(function(){
<?php if($selectedID){ ?>
$j('#Invoice_dv_action_buttons .btn-toolbar').append(
'<div class="btn-group-vertical btn-group-lg" style="width: 100%;">' +
'<button type="button" class="btn btn-default btn-lg" onclick="print_invoice()">' +
'<i class="glyphicon glyphicon-print"></i> PRINT INVOICE</button>' +
'</div>'
);
<?php } ?>
});

function print_invoice(){
var selectedID = '<?php echo urlencode($selectedID); ?>';
window.location = 'PrintInvoice.php?InvoiceID=' + selectedID;
}
</script>

Thank you verry much! I apriciate your work!

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Invoice sistem: PRINT button with different invoice design.

Post by pbottcher » 2021-12-03 15:45

Hi,

you can try to amend your function to something like

Code: Select all

function print_invoice(){
var url=$j('#Design').val() == 2 ?  'PrintInvoice.php2' :  'PrintInvoice.php?InvoiceID=';
var selectedID = '<?php echo urlencode($selectedID); ?>';
window.location =url+ selectedID;
}
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

fciprian
Veteran Member
Posts: 52
Joined: 2020-04-20 10:51

Re: Invoice sistem: PRINT button with different invoice design.

Post by fciprian » 2021-12-04 01:20

Hello. And thank you verry much for your time.
I have made the changes BUT when i leave exactly like you said i have this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from and Invoice.id=5' at line 1
Interogare:
select from and Invoice.id=5

When i edit window.location =url+ selectedID; to window.location = 'PrintInvoice.php?InvoiceID=' + selectedID; it works BUT the var function is not used.
Any ideas?

Thank you!!!

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Invoice sistem: PRINT button with different invoice design.

Post by pbottcher » 2021-12-04 08:57

Hi,

so if you use the function as I proposed, it seems that your php page get called. As I do not know what you are doing in your PrintInvoice.php or PrintInvoice2.php, it is impossible to tell what happens.
What is the value of $j('#Design').val() at the time? Is it possible that the error is within the PrintInvoice2.php?

In order to see what happens you can add a call to the alert to have a look at the string.

Code: Select all

function print_invoice(){
var url=$j('#Design').val() == 2 ?  'PrintInvoice.php2' :  'PrintInvoice.php?InvoiceID=';
var selectedID = '<?php echo urlencode($selectedID); ?>';
alert(url+ selectedID);
window.location =url+ selectedID;
}
So call the page with $j('#Design').val() a value of 1 and $j('#Design').val() with a value of 2 and see if the result is like
PrintInvoice.php?InvoiceID=SELECTEDID or PrintInvoice.php2?InvoiceID=SELECTEDID

if this is the case, you need to look into your PHP files.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

fciprian
Veteran Member
Posts: 52
Joined: 2020-04-20 10:51

Re: Invoice sistem: PRINT button with different invoice design.

Post by fciprian » 2021-12-07 08:42

Worked like a charm.
THANK YOU FOR YOUR TIME!!!

One another little question. If i have 4 designs (with 4 different php files) ?
It can be customized as :
var url=$j('#Design').val() == 1 ? 'PrintInvoice.php1';
var url=$j('#Design').val() == 2 ? 'PrintInvoice.php2';
var url=$j('#Design').val() == 3 ? 'PrintInvoice.php3';
var url=$j('#Design').val() == 4 ? 'PrintInvoice.php4';

Thank you again for your time!!!! I apriciate all helpers around here that makes our life easear :x

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Invoice sistem: PRINT button with different invoice design.

Post by jsetzer » 2021-12-08 05:09

Please dont' get me wrong, from my experience you should avoid changing the extension from .php to .php1 ... .php4. Usually your webserver will be configured for executing .php-files only. Sometimes webservers are configured for handling .php differently from .php5, for example. In these cases, the extension is related to a PHP-version. But you should not use the extension for passing parameters from my experience.

(1) I recommend something like PrintInvoice.php?design=1 and get the parameter using $_REQUEST['design']. Advantage: There is only one file and your webserver is already configured correctly for handling the .php extension.

(2) Or if you want to split up your code into different files:

PrintInvoice-1.php, ..., PrintInvoice-4.php

Javascript code for (1)

Code: Select all

var url = 'PrintInvoice.php?design=' + $j('#Design').val() + '.php';
PHP code for (1)

Code: Select all

<?php
$design_default = 1;
$design = isset($_REQUEST['design']) ? $_REQUEST['design'] : $design_default;
// ...

Javascript code for (2)

Code: Select all

var url = 'PrintInvoice_' + $j('#Design').val() + '.php';
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply