<?php
  require_once('modules/EcmPrepaymentInvoices/EcmPrepaymentInvoice.php');
  $focus = new EcmPrepaymentInvoice();
  if(isset($_REQUEST['generate']) && $_REQUEST['generate'] == '1') {
    try {
	  if(isset($_REQUEST['record']) && $_REQUEST['record'] != '') $focus->retrieve($_REQUEST['record']);
      $focus->template_id = $_REQUEST['template_id'];
      $focus->setTemplate();
      $arr = array();
      $arr['number'] = (isset($focus->id) && $focus->id != '') ? $focus->number : $focus->generateNumber("ecmprepaymentinvoices","number"); 
      $arr['document_no'] = $focus->formatNumber();
    }
    catch (Exception $e) { echo ''; return; }
    $json = getJSONobj();
    echo '['.$json->encode($arr).']';
    return;
  }
?>