var ajax_url = "index.php?module=EcmSales&action=javahelper&to_pdf=1"; var itemsTable = 'itemsTable'; var items = new Array(); var displayArray = new Array(); var searchedProducts = new Array(); var validation = new Object(); var shipping_addresses = new Array(); //add mz //oo vat stuff var account_vat_payer = false; var oo_active = false; function createDoc(id){ switch($('#doc_type').val()) { case 'EcmInvoiceOuts': window.open('index.php?module=EcmInvoiceOuts&action=EditView&isSALE=true&record='+id); break; case 'EcmReceipts': window.open('index.php?module=EcmReceipts&action=EditView&isSALE=true&record='+id); break; case 'EcmPrepaymentInvoices': window.open('index.php?module=EcmPrepaymentInvoices&action=EditView&ecmsale_id='+id); break; case 'EcmStockDocOuts': window.open('index.php?module=EcmStockDocOuts&parent_doc_type=1&action=EditView&parent_doc_id='+id); break; } } function calculateDate(date){ var params = { job : 'calculateDate', date : date, }; $.ajax({ type : "POST", url : ajax_url, dataType : "json", success : function(data) { $('#send_date').val(data['date']); }, data : params }); } function calculateRow(index) { if (index == -1) return; // liczone według najlepszych zasad księgowości var price_start = UnformatNumber($('#price_start_' + index).val()); var discount = UnformatNumber($('#discount_' + index).val()); var vat_value = $('#ecmvat_value_' + index).val(); var quantity = UnformatNumber($('#quantity_' + index).val()); var res = UnformatNumber($('#quantity_res_' + index).val()); var precision = UnformatNumber($('#product_precision_' + index).val()); var price_netto = 0; if (discount > 0) price_netto = price_start - (price_start * (discount / 100)); else price_netto = price_start; var total_netto = price_netto * quantity; if (res > quantity) res = quantity; $('#quantity_res_' + index).val(FormatNumber(res,0)); // put data $('#price_netto_' + index).val(FormatNumber(price_netto)); $('#total_netto_' + index).val(FormatNumber(total_netto)); // put data to items array items[index].price_start = toFixed(price_start, 2); items[index].price_netto = toFixed(price_netto, 2); items[index].total_netto = toFixed(total_netto, 2); items[index].quantity = toFixed(quantity, precision); items[index].discount = toFixed(discount, 2); items[index].ecmvat_id = $('#ecmvat_id_' + index).val(); items[index].ecmvat_name = $('#ecmvat_name_' + index).val(); items[index].ecmvat_value = vat_value; // put other data items[index].recipient_code = $('#recipient_code_' + index).val(); // change name or language? items[index].name = $('#name_' + index).val(); items[index].unit_name = $('#unit_name_' + index).val(); // calculate total calculateTotal(); } function calculateTotal() { var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row var vats = new Array(); var all_subtotal = 0; var all_total = 0; var sum_vats = 0; var sum_discounts = 0; var sum_oo = 0; if (account_vat_payer==true && $('#pdf_type').val() == 'K') { oo_active = true; manageOO(); } else { oo_active = false; manageOO(); } for (var index = 0; index != count; index++) { subtotal = UnformatNumber($('#total_netto_' + index).val()); all_subtotal += subtotal; if ($('#product_is_oo_'+index).val() == '1') sum_oo += subtotal; if (!$("#no_tax").is(":checked")) { // font color to black $("#ecmvat_name_" + index).css("color", "black"); if (!($('#ecmvat_id_' + index).val() in vats)) { vats[$('#ecmvat_id_' + index).val()] = new Object(); vats[$('#ecmvat_id_' + index).val()].value_name = $( '#ecmvat_name_' + index).val(); // ex. 23 vats[$('#ecmvat_id_' + index).val()].value = subtotal * ($('#ecmvat_value_' + index).val() / 100); } else vats[$('#ecmvat_id_' + index).val()].value += subtotal * ($('#ecmvat_value_' + index).val() / 100); sum_vats += subtotal * ($('#ecmvat_value_' + index).val() / 100); } else { // set color to red $("#ecmvat_name_" + index).css("color", "red"); } if (UnformatNumber($('#discount_' + index).val()) > 0) sum_discounts += (UnformatNumber($('#price_start_' + index).val()) * UnformatNumber($( '#quantity_' + index).val())) * (UnformatNumber($('#discount_' + index).val()) / 100); } all_total = all_subtotal + sum_vats; var html = ''; var vats_summary = ''; for ( var x in vats) { if(vats[x].value_name!=''){ html += '
| ' + column.label + ' | '; }); html += '
| '; html += ' '; html += ' | '; html += '';
html += ' '; html += ' | ';
html += ''; html += ' |
');
var params = {
job : 'getPricesInfo',
product_id : $("#product_id_" + index).val(),
pricebook_id : $("#pricebook_id :selected").val(),
account_id : $("#parent_id").val(),
};
$
.ajax({
type : "POST",
url : ajax_url,
dataType : "json",
async : false,
success : function(data) {
html = '
|
|
| ';
var show_purchase_prices = false;
if (show_purchase_prices) {
html += '
| ';
}
html += '