Skip to content

Instantly share code, notes, and snippets.

@bobtfish
Created February 22, 2011 22:44
Show Gist options
  • Select an option

  • Save bobtfish/839595 to your computer and use it in GitHub Desktop.

Select an option

Save bobtfish/839595 to your computer and use it in GitHub Desktop.
[%
MACRO my_fmoney(amount,currency)
BLOCK;
IF currency == 'GBP';
fprefix = "£";
ELSIF currency == 'USD';
fprefix = "\$";
ELSIF currency == 'EUR';
fprefix = "€";
ELSE;
prefix = "";
postfix = " " _ currency;
END;
amount = amount | format('%.2f');
pieces = amount.split('\.');
IF pieces.size == 2;
penny_amount = pieces.1;
pennies = penny_amount | format('%02d');
pounds = pieces.0.chunk(-3).join(',');
fprefix _ pounds _ "." _ pennies _ postfix;
ELSE;
fprefix _ "0.00" _ postfix;
END;
END;
%]
[% INCLUDE "inc/header" title => 'Catalogue Reports - Invoice Content' subsection => 'monthly report' %]
[% USE DBI('dbi:mysql:myco_reports:dbhost.example.com', 'reports', 'elided') %]
[%
client_id = p('client_id');
invoice_id = p('id');
UNLESS client_id;
source = uri_params.0;
FOREACH result IN DBI.query("select id from clients where identifier = ?",source);
client_id = result.id;
END;
END;
%]
[% THROW "client id not provided" UNLESS client_id %]
[% THROW "invoice id not provided" UNLESS invoice_id %]
[%
results = DBI.query("SELECT * FROM invoices WHERE id = ?",invoice_id);
FOREACH invoice = results; END;
THROW "invoice with given id not found" UNLESS invoice;
THROW "The invoice requested does not belong to spemycofied client." IF client_id != invoice.client_id;
invoiceextras = DBI.query("SELECT * FROM invoices_extras WHERE invoice_id = ?",invoice_id);
invoice.setup_fees = [];
invoice.extra_fees = [];
invoice.discounts = [];
invoice.standard = [];
FOREACH itemextra = invoiceextras;
IF itemextra.type =="setup";
invoice.setup_fees.push(itemextra);
invoice.extras_subtotal = invoice.extras_subtotal + itemextra.amount;
END;
IF itemextra.type =="extra";
invoice.extra_fees.push(itemextra);
invoice.extras_subtotal = invoice.extras_subtotal + itemextra.amount;
END;
IF itemextra.type =="discount";
invoice.discounts.push(itemextra);
invoice.extras_subtotal = invoice.extras_subtotal - itemextra.amount;
END;
IF itemextra.type =="standard";
invoice.standard.push(itemextra);
invoice.extras_subtotal = invoice.extras_subtotal + itemextra.amount;
END;
END;
invoice.IMESubtotal = invoice.amount_importing + invoice.amount_importing_overage + invoice.amount_management + invoice.amount_management_overage + invoice.amount_exporting + invoice.amount_exporting_overage + invoice.amount_exporting_data + invoice.amount_exporting_overage_data + invoice.amount_video_importing + invoice.amount_video_management + invoice.amount_video_exporting;
invoice.TotalBeforeTax = invoice.extras_subtotal + invoice.IMESubtotal;
invoice.vat_amount = invoice.TotalBeforeTax * (invoice.vat_percent / 100.0);
invoice.vat_amount = invoice.vat_amount | format('%.2f');
invoice.TotalAfterTax = invoice.TotalBeforeTax + invoice.vat_amount;
%]
<style>
td { border-top: 1px solid #cd9966; border-bottom: 1px solid #cd9966 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment