Page 1 of 1

Invoice sistem: PRINT button with different invoice design.

Posted: 2021-12-03 12:40
by fciprian
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!

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

Posted: 2021-12-03 15:45
by pbottcher
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;
}

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

Posted: 2021-12-04 01:20
by fciprian
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!!!

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

Posted: 2021-12-04 08:57
by pbottcher
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.

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

Posted: 2021-12-07 08:42
by fciprian
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

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

Posted: 2021-12-08 05:09
by jsetzer
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';