Skip to content

Instantly share code, notes, and snippets.

@tiagomatos
Last active February 6, 2018 18:18
Show Gist options
  • Save tiagomatos/c57e3440a73164506403eca4e2fe5b2f to your computer and use it in GitHub Desktop.
Save tiagomatos/c57e3440a73164506403eca4e2fe5b2f to your computer and use it in GitHub Desktop.
Validate Factura / Boleta presence for Jumpseller Checkout (for Invoicing Systems integration in Chile).
<script type="text/javascript">
// On the Admin Panel Configuration: https://www.evernote.com/l/APbc8GhuD4VCBam1eRbZb_M0Jr-wKdQqTVQ add the Custom Fields:
// Select List (Boleta o Factura) with the options: "Boleta Electrónica" and "Factura Electrónica"
// Input Fields: "Razón Social" and "Giro"
// Store Theme Checkout Form: https://www.evernote.com/l/APYKFPLISu9GpJihPufTIFUiLT7bhyUgWBU
// use this on the Template: "Payment/Checkout" with {% include 'factura_boleta_validator' %}
$(document).ready(function(){
//Chile Tax ID Verifier
$("#order_shipping_address_taxid").attr("pattern", "[0-9]{7,8}-[0-9Kk]{1}"); // with . and . [0-9]{1,2}.[0-9]{3}.[0-9]{3}-[0-9Kk]{1}
$("#order_shipping_address_taxid").attr("placeholder", "ej. 12345678-5");
$("#order_shipping_address_taxid").attr("title", "ej. 12345678-5");
$("#checkout").on("submit", function(){
var option = $("#order_other_boleta_o_factura option:selected").val();
if(option == 'Factura Electrónica'){
if(!$('#order_other_razon_social').val() || !$('#order_other_giro').val()){
alert('Razón Social o Giro no presente.');
return false;
}
}
})
$('#other_razon_social').hide(); // by default hidden
$('#other_giro').hide(); // by default hidden
$('#order_other_boleta_o_factura option[value=""]').remove(); // remove default value.
$('#shipping_address_taxid').hide();
$('#order_other_boleta_o_factura').on('change', function() {
var option = $("#order_other_boleta_o_factura option:selected").val();
if(option == 'Factura Electrónica'){
$('#other_razon_social').show();
$('#other_giro').show();
if($("#shipping_same_as_billing").is(":checked")){
$('#order_shipping_address_taxid').attr("required","required");
$('#shipping_address_taxid').show();
$('#shipping_address_taxid').appendTo("#other");
} else {
$('#order_billing_address_taxid').attr("required","required");
$('#billing_address_taxid').show();
$('#billing_address_taxid').appendTo("#other");
}
}else{
$('#other_razon_social').hide();
$('#other_giro').hide();
$('#order_shipping_address_taxid').removeAttr('required');
$('#shipping_address_taxid').hide();
$('#order_billing_address_taxid').removeAttr('required');
$('#billing_address_taxid').hide();
}
})
});
</script>
@tiagomatos
Copy link
Author

The Chilean RUT validation can be further restricted by using this validation on checkout:

https://gist.github.com/tiagomatos/73b4166069d59e44906255edef498392

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment