<?php 

function pm_add_discount_cb() {
	$invoice = new pm_invoice();
	$invoice->get_invoice_by_number($_GET['ref']);
	?>
    <div class="row">
		<div class="col-md-6">
			<div class="card">
			    <div class="card-body">
			      	<form id="new-discount-form" method="post" enctype="multipart/form-data" action="contents/plugins/payment_module/ajax.php" data-clearform=1>
			      		<input type="hidden" name="in_ref" id="in_ref" value="<?php echo $invoice->invoice->invoice_number ?>">
			      		<input type="hidden" name="user_id" id="user_id" value="<?php echo $invoice->invoice->user_id ?>">
			      		<?php 
			      			select(['label' => 'Method', 'id' => 'mode', 'required' => 'required'], ['Flat Discount' => 'flat', 'Percentage Discount' => 'percentage'], "Flat");
			      			input(['label' => 'Discount', 'id' => 'discount', 'class' => 'form-control numbers-only', 'required' => 'required', 'min' => '0', 'max' => $invoice->total(true)]);
			      			input(['label' => 'Narration', 'id' => 'narration', 'required' => 'required']);
			      			input(['label' => 'Discount/Promo Code', 'id' => 'ref', 'hint' => 'Leave empty if there is no discount/promo code']);
			      			submit_btn("add_discount", "Submit"); 
			      		?>
			      	</form>
			    </div>
			</div>
		</div>
	</div>
	<?php
	add_page_javascript('contents/plugins/payment_module/js/discount.js');
	add_page_javascript('app/assets/js/page-scripts/js-functions.js');
	add_page_javascript('app/assets/js/page-scripts/submit.js');
	add_page_javascript('app/assets/js/page-scripts/koweb.js');
}