Closed GoogleCodeExporter closed 8 years ago
It could use some improvement, but this is what I put together:
<script>
var fileCounter = 0;
function printDivToFile(id, outputFile, ext) {
if (document.jzebra != null) {
document.jzebra.findPrinter(); // Needed due to a bug w/ NullPrintService
document.jzebra.append(document.getElementById(id).textContent);
document.jzebra.printToFile(outputFile + pad(fileCounter++, 3, 0) + "." + ext);
} else {
alert("Error! jzebra is null.");
}
}
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
</script>
<input type="button" onClick="printDivToFile('test-div',
'C:\\Users\\YOUR_USERNAME\\Desktop\\test-div', 'txt');" value="Print to
Desktop, etc"><br />
<div id="test-div">~PUERTO[1]
~DOCUMENTOFISCAL[]
~DOCUMENTOREFERENCIA[%ORDER_ID%]
~TIPODOCUMENTO[0]
~CAJA[001]
~SUCURSAL[100]
~RAZONSOCIAL[B&R]
~NCF[123456789%ORDER_ID%]
~RNC[%comprobante_fiscal%]
~PROPINA[SI]
~COPIAS[0]
<SHOP_BODY>~DETALLE[%SHOP_ORDER_ITEM_NAME%,%SHOP_ORDER_ITEM_COUNT%,%SHOP_ORDER_I
TEM_AMOUNT%,18,0,0]</SHOP_BODY>
~PAGOEFECTIVO[%TOTAL%]
~COMENTARIOS[Codigo cliente:%Codigo_del_cliente%, Nombre:%first_name%,
Dirección:%address1%, Sector: %sector%, Tel:%night_phone_b%]
~CIERREDOCUMENTO[Gracias por su compra lo atendio %LOGGED_USER%]
~@~</div>
Original comment by tres.fin...@gmail.com
on 19 Sep 2013 at 7:58
Hi,
You are a genius!! thanks so much. I was able to implement the code and it is
working quite well.
2 issues:
1- when I do the checkout in the online POS it goes to the confirmation page,
as should, and this is where the raw "txt" content is placed (test-div) When I
"print" it produces the file test-div000.txt as expected, but if the cashier
hits the print button again, that will create file test-div001.txt and if you
click "print" again we get test-div003.txt etc.
Now if we go back to the POS and create another sale and repeat the process we
will overwrite ticket test-div000.txt
In other words the auto numbering is happening on re-printing (which we prefer
not to) and not for each new transaction.
Can you further assist?
2-The file produced is encoded incorrectly, so instead of seeing:
~PUERTO[1]
~DOCUMENTOFISCAL[]
~DOCUMENTOREFERENCIA[%ORDER_ID%]
~TIPODOCUMENTO[0]
~CAJA[001]
~SUCURSAL[100]
etc....
With windows Notepad we see:
~PUERTO[1]box~DOCUMENTOFISCAL[]box~DOCUMENTOREFERENCIA[2147483662]box~TIPODOCUME
NTO[0]box~CAJA[001]box~SUCURSAL[100] etc...
box= is little square zero 0
The program we use to send the stored file to the fiscal printer is very fussy,
no extra spaces, etc. With a spooler software we tried first we had to set
utf-8 and TXT in its settings.
I know this part is not a script defect but I am at a lost as to how to force
the file to be created per the requirements.
Obviously I lack the necessary skills to be messing with all this!!! so I will
be very grateful if you can help here as well.
Thanks again
Original comment by normi...@gmail.com
on 21 Sep 2013 at 8:24
> ... the auto numbering is happening on re-printing (which we prefer not to)
and not for each new transaction.
Its up to you how best to handle it. I can put a feature in to auto-number
automatically, but I want to first know exactly how you expect the files to get
generated. Take into consideration that I have no background information on
what a "new transaction" is, so you might need to pass in a parameter that
helps this happen.
> With windows Notepad we see: ~PUERTO[1]box~DOCUMENTOFISCAL[]
This is because the web browser uses "\n" instead of "\r\n". A quick replace
with JavaScript will fix the newline issue using ".replace(/\n/g, "\r\n")"
document.jzebra.append(document.getElementById(id).textContent.replace(/\n/g, "\r\n"));
> box= is little square zero 0
Perhaps you can explain a little bit more on this. If it's not a standard
ASCII character, you can use UNICODE format instead, which a quick Google
search should find.
> set utf-8 and TXT in its settings
I think jzebra will export to UTF8 file if you force that as a charset. I
haven't tested this though.
document.jzebra.setEncoding("UTF-8");
I'm a bit curious how this is all sending to the printer, and what type of
printer you are using. Perhaps you can shed some light on that as well, as you
are the first to request files in a specific format be written to the
filesystem. I'm intrigued.
-Tres
Original comment by tres.fin...@gmail.com
on 21 Sep 2013 at 8:53
Hi,
I am providing you with a demo site where the process is happening. You can
process orders on the online POS to see from A to Z there are no real
transactions, its a demo site. You will see comments addresed to you on the
final print page.
http://www.maxxebiz.com/fbshops/Templates/Template002b/pos_t2_blue.php
We would like the print file created 1 per POS order, hitting the print button
again should not create a new file (reprinting it is another issue, in case of
paper jam, out of paper, ink, etc)
The program we use to talk to the printer was created by a system integrator in
the Dominican Republic to interface with the fiscal printers in use here that
capture all retail sales transactions in the printers memory as well as print
the tickets. This is for protection against tax evasion. It is in use in
several countries around the world.
Now what this system integrator has achieved is to be certified by the DR tax
dept, where he provides a certification to the merchant who complies with his
process. He gave us a spec for us to use in the print file that incorporates
the fields and values to be passed using his interface software, he takes care
of printer drivers (black box process)
We tested the process recently and our file structure complies. Now we are
trying using JZebra to automate our end and make it easy for the cashier.
His software monitors the folder and sends the the created sequenced file
invoices to the printer.
I hope that explains the process better.
By the way your tip of ".replace(/\n/g, "\r\n")" was all that was required, the
files are looking ok now.
Hopefully we can sort out the files sequencing as 1 per order, then we are good.
Once we have 1 system certified we can enter this local market and offer small
businesses a simple POS system.
I certainly appreciate your help, I could have NEVER figured these things out.
Normand
Original comment by normi...@gmail.com
on 22 Sep 2013 at 6:46
Normand,
The only issue I see is determining what an "order" is. How will I know when
to repeat numbering again? Should the file never be overwritten? Do the files
get deleted after they're processed and sent to the printer?
If you can illustrate how to handle this numbering in a fashion that we can
easily control, I can have this feature added this week.
Just tell me what scenarios can happen and how you want the numbering to
respond. Keep in mind, you could handle this logic server-side and pass the
numbering to the applet as well.
-Tres
Original comment by tres.fin...@gmail.com
on 22 Sep 2013 at 7:41
[deleted comment]
Also, can it skip numbers? If your "order number" increments and would work in
the file name, we can just use that, right? i.e. <?php echo $order_number; ?>
Something like this?
document.jzebra.printToFile(outputFile + <?php echo $order_number; ?> + "." + ext);
-Tres
Original comment by tres.fin...@gmail.com
on 22 Sep 2013 at 7:45
Yes our order number would be fine, be great to do any auditing
Original comment by normi...@gmail.com
on 22 Sep 2013 at 8:10
@Normand,
Try this and see if it does what you are looking for... Note, it would try to
overwrite the file if you print it a second time. I can add a feature to never
overwrite if you determine that's needed.
<div id="test-div" style="display:none;">~PUERTO[1]
~DOCUMENTOFISCAL[]
~DOCUMENTOREFERENCIA[%ORDER_ID%]
~TIPODOCUMENTO[0]
~CAJA[001]
~SUCURSAL[100]
~RAZONSOCIAL[B&R]
~NCF[123456789%ORDER_ID%]
~RNC[%comprobante_fiscal%]
~PROPINA[SI]
~COPIAS[0]
<SHOP_BODY>~DETALLE[%SHOP_ORDER_ITEM_NAME%,%SHOP_ORDER_ITEM_COUNT%,%SHOP_ORDER_I
TEM_AMOUNT%,18,0,0]</SHOP_BODY>
~PAGOEFECTIVO[%TOTAL%]
~COMENTARIOS[Codigo cliente:%Codigo_del_cliente%, Nombre:%first_name%,
Dirección:%address1%, Sector: %sector%, Tel:%night_phone_b%]
~CIERREDOCUMENTO[Gracias por su compra lo atendio %LOGGED_USER%]
~@~</div>
<input type="button" value="Print Div" onClick="printDivToFile('test-div',
'C:\\Users\\USERNAME\\Desktop\\', 'DSP');">
<script type="text/javascript">
function printDivToFile(id, outputFile, ext) {
var applet = document.jzebra;
if (applet) {
// Needed due to a bug w/ NullPrintService
applet.findPrinter();
// Replace newlines with newline carriage returns
applet.append(document.getElementById(id).textContent.replace(/\n/g, "\r\n"));
// Extract the order number from text using regex and split.
// Note: It should always be the second array element
var orderNumber = document.getElementById(id).textContent.split(/~NCF\[(.*?)\]/)[1];
// Write a file with the order number as it's name.
applet.printToFile(outputFile + orderNumber + "." + ext);
} else {
alert("Error! Applet is null.");
}
}
</script>
Original comment by tres.fin...@gmail.com
on 23 Sep 2013 at 1:31
Good morning!
I have made the changes you suggested above, but have not succeeded in
obtaining a file output. I might have introduced some errors.
Maybe it would be easier to use: ~DOCUMENTOREFERENCIA[%ORDER_ID%] and not have
to extract the %ORDER_ID% from ~NCF string
I change the print directory to "mitienda" as I had "test-div" as the folder
and that happens to be what we are printing, but that did not change anything
I see you have taken care of the visibility of the test-div, nice touch.
I hopee its just some minor thing.
Thanks for giving so much assistance.
Regards,
Normand
Original comment by normi...@gmail.com
on 23 Sep 2013 at 2:17
It says "document.getElementById(id).textContent" is null. Is there a reason
why you surrounded the text lines with <p><span
style="font-size:13px;color:#000000;">...</span></p> ?
-Tres
Original comment by tres.fin...@gmail.com
on 23 Sep 2013 at 2:33
Sorry I fixed the div. Instead of creating an code based html div, I used the
web program to create a div and it added all that unnecessary code.
However I still see no file created.
Probably more blunders on my part?
Original comment by normi...@gmail.com
on 23 Sep 2013 at 3:10
@Normand,
You should get in the habit of using a debugger in the web browser. :)
Chrome's "inspect element" and "FireBug" are two good places to start.... :)
You have a rogue <script type="text/javascript"> tag on line 70 and I think
that's breaking quite a bit.
-Tres
Original comment by tres.fin...@gmail.com
on 23 Sep 2013 at 3:42
Hi,
As usual you were right, I had that line there by mistake.
EVERYTHING WORKS PERFECTLY - GREAT
I am not a programmer and do not have all the required discipline and
experience. I am a website designer with "some" ability (usually to get myself
in trouble!!!)
I will try too learn these tools to hopefully avoid these mishaps.
But the things you have done here in the last few days are amazing. I wont be
getting to these capabilities anytime soon.
I am hoping to firm up an order shortly for our first POS with fiscal printer.
After that I will have to add the "open cashier drawer" command (I saw that as
part of the functionality of JZebra) I guess I will need more info about the
actual hardware in use)
I will keep you informed of our progress.
I'm not sure what your line of business is, but let me know if you have any
interest in the POS system. I can share our system, you could commercialize it
in your area maybe. Kindly advise.
Many thanks
Sincerely,
Normand
Original comment by normi...@gmail.com
on 23 Sep 2013 at 5:57
@Normand,
Thank you for the kind words. We have a supported version of jzebra as well.
When you get closer to deployment, please email me, tres@qzindustries.com. The
cost of the software is listed here: http://qzindustries.com.
Closing bug and marking as invalid since we were able to achieve what we needed
without any code changes. If you feel this bug was closed in error, feel free
to reopen it!
-Tres
Original comment by tres.fin...@gmail.com
on 23 Sep 2013 at 6:34
Original issue reported on code.google.com by
normi...@gmail.com
on 19 Sep 2013 at 6:43