Money format

Discuss here how to configure hoteldruid and better use its features.

Moderator: marco

Post Reply
viknet
Posts: 27
Joined: Sat Jan 24, 2009 3:08 pm

Re: Money format

Post by viknet »

I have the answer, if your probleme is when creating a document....

the solution is named javascript I can send a sample document If you need it.
I made a very complexe bill It's a shame it's not built in with php residence.....

marco, I can give you my doc if you need it.....

A+ (also french by the way)
viknet
Posts: 27
Joined: Sat Jan 24, 2009 3:08 pm

Re: Money format

Post by viknet »

try to past this in your document.
marco, you might want to add this as a standard bill, out of the box....
feel free to do it of you want to.

Best regards

Viknet
---------------------------------------------
<body>

<style type="text/css">


table.bar_like_result {
margin-left: 0.2cm;
border-width: 1px;
border-spacing: 2px;
border-style: solid solid solid solid;
border-color: black black black black;
border-collapse: collapse;
empty-cells: show;
table-layout: automatic;
text-align:left;
}

</style>
<script type="text/javascript">
var TSTPT=22;
var TVA=0.1;
var nb_apartements=0;
[r]nb_apartements++;
[/r]
var people_num_tot=0;
[r]var str="[people_num_tot]"; if (!str.match("__")) people_num_tot=people_num_tot+"[people_num_tot]"*1;
[/r]

var extra_beds_num=0;
[r]var str="[extra_beds_num]"; if (!str.match("__")) extra_beds_num=extra_beds_num+"[extra_beds_num]"*1;
[/r]




</script>

<table>
<TR><TD width=350>
<IMG src="includes/icone/entete.gif" width="300" height="355">
</TD>
<TD width=250 valign=bottom>
<BR><BR><BR>

<script type="text/javascript">

var str="[sex]"; if (str.match("f")) document.write("<B>Mme "); else document.write("<B>Mr ");
var str="[surname]"; if (!str.match("__")) document.write("[surname] ");
var str="[name]"; if (!str.match("__")) document.write("[name]");

document.write("</B><BR>");
var str="[street_number]"; if (!str.match("__")) document.write("[street_number] ");
var str="[street]"; if (!str.match("__")) document.write("[street]");
document.write("<BR>");
var str="[postal_code]"; if (!str.match("__")) document.write("[postal_code] ");
var str="[city]"; if (!str.match("__")) document.write("[city]");
var str="[nation]"; if (!str.match("__")) document.write("[nation]");
</script>
<BR><BR><BR><BR><BR><BR>
</TD></TR></TABLE>
<BR><BR>

<B>Facture n° : [document_progressive_number]</B>
<BR>

Réservation numéro :
<script type="text/javascript">
var str="[reservation_code]"; document.write(str.toUpperCase());
</script>
<BR>
Séjour du : [selection_starting_date] au [selection_ending_date] ([periods_num]
<script type="text/javascript">
document.write("jour");
if ([periods_num]>1) document.write("s");
document.write(")<BR>");
if (people_num_tot!=0) document.write("Nombre de personnes : " + people_num_tot);
if (extra_beds_num!=0) document.write(" dont " + extra_beds_num + " lit(s) supplémentaire(s)");
</script>
<BR><BR><BR>


<div align=center>
<table id="facture" class="bar_like_result" border="1" width=800 >
</TABLE>
</div>

<script type="text/javascript">
var TSTPT=22;
var TVA=0.1;
var taxe_tstpt=0;
var nb_apartements=0;
var price_tot_ht = 0;
var price_tot=0;
var price_tot1=0;
var TVA_facture=0;
var paid=0;
var rest_to_pay=0;

function format_cost(cost)
{
cost_h=(Math.round(cost*100)/100);
cost_integer=Math.floor(cost_h);
cost_tenth=Math.floor(cost_h*10-cost_integer*10);
cost_hundreth=Math.floor((cost_h*10-Math.floor(cost_h*10))*10);
formated_string=cost_integer+"."+cost_tenth+cost_hundreth;
return(formated_string);
}

function format_cost_euro(cost)
{
return(format_cost(cost)+"&"+"nbsp;€");
}

function format_cost_Dhs(cost)
{
return(Math.round(cost)+"&"+"nbsp;Dhs.");
}




var facture = document.getElementById('facture');


var x=facture.insertRow(facture.rows.length);
var y=x.insertCell(0); var z=x.insertCell(1); var t=x.insertCell(2); var u=x.insertCell(3); var v=x.insertCell(4);
y.innerHTML="<B>Désignation</B>";
z.innerHTML="<B>Chambres</B>";
t.innerHTML="<B>Quantité</B>";
u.innerHTML="<B>Prix U.</B>";
v.innerHTML="<B>Total</B>";

y.align="center";
z.align="center";
t.align="center";
u.align="center";
v.align="center";

y.width="400px";
z.width="100px";
t.width="100px";
u.width="100px";
v.width="100px";

y.style.borderBottom="thin solid black";
z.style.borderBottom="thin solid black";
t.style.borderBottom="thin solid black";
u.style.borderBottom="thin solid black";
v.style.borderBottom="thin solid black";

[r]
nb_apartements++;

price_tot_ht = price_tot_ht + ([price_tot]-(TSTPT*[people_num_tot]*[periods_num]))/(1+TVA);
price_tot = price_tot + [price_tot];
TVA_facture = TVA_facture + ([price_tot]-TSTPT*[people_num_tot]*[periods_num])/(1+TVA)*TVA+TSTPT*[people_num_tot]*[periods_num];
var str="[paid]"; if (!str.match("__")) paid = paid + ("[paid]"*1);
var str="[rest_to_pay]"; if (!str.match("__")) rest_to_pay = rest_to_pay + ("[rest_to_pay]"*1);




var str="[rate_price]"; if (!str.match("__")) {
price_tot1=price_tot1+"[rate_price]"*1;
var x=facture.insertRow(facture.rows.length);
var y=x.insertCell(0); var z=x.insertCell(1); var t=x.insertCell(2); var u=x.insertCell(3); var v=x.insertCell(4);
y.innerHTML="[rate_name]";
z.innerHTML="[apartment]";
t.innerHTML="[periods_num]";

u.innerHTML=format_cost_euro("[rate_price]"/("[periods_num]"*1));
v.innerHTML=format_cost_euro("[rate_price]"*1);
z.align="center";
t.align="right";
u.align="right";
v.align="right";
}

[r3]

var str="[extra_cost_name]";

if (str.match("TS")) {
taxe_tstpt = taxe_tstpt + ("[extra_cost_value]"*1);
}
else {
price_tot1=price_tot1+"[extra_cost_value]"*1;
var x=facture.insertRow(facture.rows.length);
var y=x.insertCell(0); var z=x.insertCell(1); var t=x.insertCell(2); var u=x.insertCell(3); var v=x.insertCell(4);
y.innerHTML="[extra_cost_name]";
z.innerHTML="[apartment]";
if (str.match("Lit"))
{
t.innerHTML="[periods_num]";
u.innerHTML=format_cost_euro("[extra_cost_value]"/("[periods_num]"*1));
}
v.innerHTML=format_cost_euro("[extra_cost_value]"*1);
z.align="center";
t.align="right";
u.align="right";
v.align="right";
}
[/r3]



var str="[discount]"; if (!str.match("__")) {
price_tot1=price_tot1-"[discount]"*1;
var x=facture.insertRow(facture.rows.length);
var y=x.insertCell(0); var z=x.insertCell(1); var t=x.insertCell(2); var u=x.insertCell(3); var v=x.insertCell(4);
y.innerHTML="Remise exceptionnelle";
z.innerHTML="[apartment]";
v.innerHTML=format_cost_euro("-[discount]"*1);
t.align="right";
u.align="right";
v.align="right";
z.align="center";
}
[/r]


var x=facture.insertRow(facture.rows.length);
var y=x.insertCell(0); var z=x.insertCell(1); var t=x.insertCell(2); var u=x.insertCell(3); var v=x.insertCell(4);
y.innerHTML="Taxes de séjour : (TS et TPT)";
t.innerHTML=taxe_tstpt/TSTPT;
u.innerHTML=format_cost_euro(TSTPT);
v.innerHTML=format_cost_euro(taxe_tstpt);
t.align="right";
u.align="right";
v.align="right";
z.align="center";

y.style.borderBottom="thin solid black";
z.style.borderBottom="thin solid black";
t.style.borderBottom="thin solid black";
u.style.borderBottom="thin solid black";
v.style.borderBottom="thin solid black";

price_tot1=price_tot1+taxe_tstpt;

price_tot=price_tot1;
price_tot_ht =(price_tot-taxe_tstpt)/(1+TVA);
TVA_facture=price_tot_ht*TVA+taxe_tstpt;
rest_to_pay=price_tot-paid;


var x=facture.insertRow(facture.rows.length);
var y=x.insertCell(0); var z=x.insertCell(1); var t=x.insertCell(2); var u=x.insertCell(3); var v=x.insertCell(4);
y.innerHTML="<B>Total ( HT: "+format_cost_euro(price_tot_ht)+")</B>";
v.innerHTML="<B>"+format_cost_euro(price_tot)+"</B>";
t.align="right";
u.align="right";
v.align="right";
z.align="center";



var x=facture.insertRow(facture.rows.length);
var y=x.insertCell(0); var z=x.insertCell(1); var t=x.insertCell(2); var u=x.insertCell(3); var v=x.insertCell(4);
y.innerHTML="Dont TVA 10% et Taxe de séjour";
v.innerHTML=format_cost_euro(TVA_facture);
t.align="right";
u.align="right";
v.align="right";
z.align="center";



var x=facture.insertRow(facture.rows.length);
var y=x.insertCell(0); var z=x.insertCell(1); var t=x.insertCell(2); var u=x.insertCell(3); var v=x.insertCell(4);
y.innerHTML="Acompte";
v.innerHTML=format_cost_euro(paid);
t.align="right";
u.align="right";
v.align="right";
z.align="center";

var x=facture.insertRow(facture.rows.length);
var y=x.insertCell(0); var z=x.insertCell(1); var t=x.insertCell(2); var u=x.insertCell(3); var v=x.insertCell(4);
y.innerHTML="<B>Reste à payer</B>";
v.innerHTML="<B>"+format_cost_euro(rest_to_pay)+"</B>";
t.align="right";
u.align="right";
v.align="right";
z.align="center";



</script>

<BR>
<BR>
<HR>
</body>
mhlspn
Posts: 3
Joined: Mon May 11, 2009 9:10 am

Re: Money format

Post by mhlspn »

Viknet,

Thank you very much for this excellent solution and for sharing your work.
It works fine for me with the room and the local french city tax.

Even if I don't understand the variable assignment TSTPT=22.
Why 22 € unit price ?

Mysterie ?

However thanks again

Michael
viknet
Posts: 27
Joined: Sat Jan 24, 2009 3:08 pm

Re: Money format

Post by viknet »

why 22 ???

Because it has to be this way in morroco but you have to change it in france, let me explain:

TSTPT="Taxe de sejour" it is a daily taxe per person on top of the VAT.

It exist at least in france and morroco. In morroco the price is 22 Dirham per day per person

This tax is automaticly calculated by php residence (daily obligatory extra cost multiplied by number of people)

I should not need to have it appear in my bill except that I wanted to show the price excluding taxes and this price excluding taxes is (PHPresidence price-"taxe de sejour/daily tax")/(1+VAT) this is the reason why I needed to have this TSTPT=22 in my bill, just adjust TSTPT and VAT to the local rates.

Best regards

Vincent
marco
Posts: 1332
Joined: Tue Jul 05, 2005 6:00 pm
Location: Roma, Italia

Re: Money format

Post by marco »

Hello Michael and Vincent,
The [today] bug has been solved in 1.2. If you have a variable called for example [custom_price] with a value of 50 and want to show 50,00 you can create another variable called [custom_price_p] and assign to it the value of [custom_price] + 0 (on the third line in actions when you add a condition in version 1.2). If you don't want the underscores create a [custom_variable] and equate it with the original [variable] (first line in actions). Now php-residence includes a default invoice in rtf format, but javascript is also a good option.

Regards,
Marco
Problems installing, configuring, upgrading?
Try the easiest way to use HotelDruid:
https://www.digitaldruid.net/hosted/index.php
Post Reply