<script>
	function get_dpt() {
		show_loading();
		jQuery.ajax({
			url: app_url + 'dpt_report/get_dpt',
			type: 'POST',
			dataType: 'JSON',
			data: jQuery('#form_dpt').serialize(),
			success: function(response) {
				hide_loading();
				jQuery('#table_dpt_report tbody').html('');
				jQuery('#table_dpt_pickup tbody').html('');
				jQuery(response.data).each(function(adata, bdata) {
					var tr_style = '';
					if (bdata.grand_discount > 0) {
						tr_style = "style='background:#e6e4e4;'";
					}
					var table = "";
					table += "<tr "+tr_style+">";
					table += "	<td align='center'>";
					table += (adata + 1);
					table += "	</td>";
					table += "	<td>";
					table += bdata.nobill;
					table += "	</td>";
					table += "	<td>";
					table += bdata.date;
					table += "	</td>";
					table += "	<td>";
					table += bdata.customer;
					table += "	</td>";
					table += "	<td align='right'>";
					if (bdata.grand_discount > 0) {
						table += thousand_separator(parseInt(bdata.before_discount)) + ', AD ';
					}
					table += thousand_separator(parseInt(bdata.grand_total_final));
					table += "	</td>";
					table += "	<td align='right'>";
					table += thousand_separator(parseInt(bdata.total_pay));
					table += "	</td>";
					table += "	<td>";
					table += bdata.cashier;
					table += "	</td>";
					table += "	<td>";
					table += bdata.status;
					table += "	</td>";
					table += "	<td>";
					table += bdata.payment_status;
					table += "	</td>";
					table += "<tr>";

					jQuery('#table_dpt_report tbody').append(table);
				});

				jQuery(response.data_pickup).each(function(adata, bdata) {
					var table = "";
					table += "<tr>";
					table += "	<td>";
					table += (adata + 1);
					table += "	</td>";
					table += "	<td>";
					table += bdata.nobill;
					table += "	</td>";
					table += "	<td>";
					table += bdata.date;
					table += "	</td>";
					table += "	<td>";
					table += bdata.customer;
					table += "	</td>";
					table += "	<td align='right'>";
					table += thousand_separator(parseInt(bdata.grand_total_final));
					table += "	</td>";
					table += "	<td align='right'>";
					table += thousand_separator(parseInt(bdata.total_pay));
					table += "	</td>";
					table += "	<td>";
					table += bdata.cashier;
					table += "	</td>";
					table += "	<td>";
					table += bdata.status;
					table += "	</td>";
					table += "	<td>";
					table += bdata.payment_status;
					table += "	</td>";
					table += "<tr>";

					jQuery('#table_dpt_pickup tbody').append(table);
				});

				jQuery('.txt-total').text(thousand_separator(parseInt(response.total)));
				jQuery('.txt-total-pickup').text(thousand_separator(parseInt(response.total_pickup)));
				jQuery('.txt-total-all').text(thousand_separator(parseInt(response.total_all)));

				jQuery('#table_dpt_outlay tbody').html(response.outlay);
				jQuery('#table_dpt_payment tbody').html(response.payment);
				jQuery('#table_dpt_analysis tbody').html(response.analysis);
			},
			error: function(response) {
			}
		});
	}

	get_dpt();

	jQuery("#btn_filter").on('click', function() {
		get_dpt();
	});