<?php 

function invoice_cb() {
	$invoice = new pm_invoice();
	$invoice->get_invoice_by_id($_GET['id']);
	$user_meta = get_user_meta($invoice->invoice->user_id);
  add_page_javascript('app/assets/js/page-scripts/js-functions.js');
  add_page_stylesheet('contents/plugins/payment_module/css/invoice.css', 'pmInvoiceCss');
  $media = isset($_GET['media']) ? $_GET['media'] : "view";
	?>
	<section class="invoice" style="max-width: 800px;margin: auto;">
      <?php echo $invoice->invoice_template($user_meta); ?>
      <!-- this row will not appear when printing -->
      <div class="row no-print">
        <div class="col-xs-12 col-sm-7">
            <?php if ($media !== 'print'):

              if(current_user_can("pm_add_payment") && $invoice->status() == "unpaid"):
              ?>
                  <a href="pm-add-payment?ref=<?php echo $invoice->invoice->invoice_number; ?>" class="btn mb-2  btn-default popmeup" data-width=700 data-height=500>Add Payment</a>
                  <a href="pm-add-discount?ref=<?php echo $invoice->invoice->invoice_number; ?>" class="btn mb-2  btn-default popmeup" data-width=700 data-height=500>Add Discount</a>
                <?php
              endif;
              ?>
              <a href="invoice?id=<?php echo $invoice->invoice->id; ?>&media=print" target="_blank" class="btn mb-2 btn-default"><i class="fa fa-print"></i> Print</a>
              <a href="?id=<?php echo $invoice->invoice->id; ?>&action=<?php echo base64_encode('pm_download_invoice') ?>" class="btn mb-2 btn-default"><i class="fa fa-download"></i> Download PDF</a>
              <?php if ($invoice->status() === 'paid'): ?>
                <a href="?id=<?php echo $invoice->invoice->id; ?>&action=<?php echo base64_encode('pm_download_invoice_receipt') ?>" class="btn mb-2 btn-default"><i class="fa fa-download"></i> Download Receipt</a>
              <?php endif; 
              do_action("pm_invoice_btns", ["invoice_obj" => $invoice]);
            endif; ?>
          
          
          <!-- <button type="button" class="btn btn-success pull-right"><i class="fa fa-credit-card"></i> Submit Payment
          </button>
          <button type="button" class="btn btn-primary pull-right" style="margin-right: 5px;">
            <i class="fa fa-download"></i> Generate PDF
          </button> -->
        </div>
        <div class="col-xs-12 col-sm-5">
          <?php if ($media !== 'print'):
            if($invoice->status() !== "paid") :
              $args = [
                'token' => new_token(),
                'amount' => $invoice->total(true),
                'in_ref' => $invoice->invoice->invoice_number,
                'user_id' => $invoice->user_id,
                'btn_text' => "Submit and Pay ".toMoney((int) $invoice->total(true)),
                'btn_class' => "btn btn-success btn-sm pull-right"
              ];
              do_action('_pm_make_payment_button', $args);
            endif;
          endif ?>
        </div>
      </div>
    </section>
	<?php
}