<commit_before><?php
namespace Scat\Controller;

use \Psr\Container\ContainerInterface;
use \Slim\Http\ServerRequest as Request;
use \Slim\Http\Response as Response;
use \Slim\Views\Twig as View;
use \Respect\Validation\Validator as v;

class Transactions {
  private $view, $txn, $data, $tax;

  public function __construct(View $view, \Scat\Service\Txn $txn,
                              \Scat\Service\Data $data,
                              \Scat\Service\Tax $tax)
  {
    $this->view= $view;
    $this->txn= $txn;
    $this->data= $data;
    $this->tax= $tax;
  }

  private function getAmazonClient(\Scat\Service\Config $config) {
    $config= [
      'merchant_id' => $config->get('amazon.merchant_id'),
      'access_key' => $config->get('amazon.access_key'),
      'secret_key' => $config->get('amazon.secret_key'),
      'client_id' => $config->get('amazon.client_id'),
      'region' => $config->get('amazon.region'),
      'currency_code' => $config->get('amazon.currency_code'),
      'sandbox' => (bool)$GLOBALS['DEBUG']
    ];

    $client= new \AmazonPay\Client($config);
    return $client;
  }

  public function search(Request $request, Response $response, $type) {
    $q= trim($request->getParam('q'));

    if (preg_match('/^((%V|@)INV-)?(\d+)/', $q, $m)) {
      $txn= $this->txn->fetchById($m[3]);
      if ($txn) {
        return $response->withRedirect(
          ($type == 'customer' ? '/sale/' : '/purchase/') . $txn->id
        );
      }
    }

    $page= (int)$request->getParam('page');
    $limit= 25;

    $txns= $this->txn->find($type, $page, $limit, $q);
    if (($status= $request->getParam('status'))) {
      $txns= $txns->where('status', $status);
    }

    $accept= $request->getHeaderLine('Accept');
    if (strpos($accept, 'application/json') !== false) {
      return $response->withJson($txns->find_many());
    }

    return $this->view->render($response, 'txn/index.html', [
      'type' => $type,
      'txns' => $txns->find_many(),
      'page' => $page,
      'limit' => $limit,
      'status' => $status,
      'q' => $q,
    ]);
  }

  public function sales(Request $request, Response $response) {
    return $this->search($request, $response, 'customer');
  }

  public function newSale(Response $response) {
    ob_start();
    include "../old-index.php";
    $content= ob_get_clean();
    return $this->view->render($response, 'sale/old-new.html', [
      'title' => $GLOBALS['title'],
      'content' => $content,
    ]);
  }

  public function sale(Request $request, Response $response, $id) {
    $txn= $this->txn->fetchById($id);
    if (!$txn)
      throw new \Slim\Exception\HttpNotFoundException($request);

    $accept= $request->getHeaderLine('Accept');
    if (strpos($accept, 'application/json') !== false) {
      return $response->withJson($txn);
    }

    if (!$GLOBALS['DEBUG']) {
      return $response->withRedirect("/?id=$id");
    }

    if (($block= $request->getParam('block'))) {
      $html= $this->view->fetchBlock('sale/txn.html', $block, [
        'txn' => $txn,
      ]);

      $response->getBody()->write($html);
      return $response;
    }

    return $this->view->render($response, 'sale/txn.html', [
      'txn' => $txn,
    ]);<commit_msg>Force access to new txn UI<commit_after><?php
namespace Scat\Controller;

use \Psr\Container\ContainerInterface;
use \Slim\Http\ServerRequest as Request;
use \Slim\Http\Response as Response;
use \Slim\Views\Twig as View;
use \Respect\Validation\Validator as v;

class Transactions {
  private $view, $txn, $data, $tax;

  public function __construct(View $view, \Scat\Service\Txn $txn,
                              \Scat\Service\Data $data,
                              \Scat\Service\Tax $tax)
  {
    $this->view= $view;
    $this->txn= $txn;
    $this->data= $data;
    $this->tax= $tax;
  }

  private function getAmazonClient(\Scat\Service\Config $config) {
    $config= [
      'merchant_id' => $config->get('amazon.merchant_id'),
      'access_key' => $config->get('amazon.access_key'),
      'secret_key' => $config->get('amazon.secret_key'),
      'client_id' => $config->get('amazon.client_id'),
      'region' => $config->get('amazon.region'),
      'currency_code' => $config->get('amazon.currency_code'),
      'sandbox' => (bool)$GLOBALS['DEBUG']
    ];

    $client= new \AmazonPay\Client($config);
    return $client;
  }

  public function search(Request $request, Response $response, $type) {
    $q= trim($request->getParam('q'));

    if (preg_match('/^((%V|@)INV-)?(\d+)/', $q, $m)) {
      $txn= $this->txn->fetchById($m[3]);
      if ($txn) {
        return $response->withRedirect(
          ($type == 'customer' ? '/sale/' : '/purchase/') . $txn->id
        );
      }
    }

    $page= (int)$request->getParam('page');
    $limit= 25;

    $txns= $this->txn->find($type, $page, $limit, $q);
    if (($status= $request->getParam('status'))) {
      $txns= $txns->where('status', $status);
    }

    $accept= $request->getHeaderLine('Accept');
    if (strpos($accept, 'application/json') !== false) {
      return $response->withJson($txns->find_many());
    }

    return $this->view->render($response, 'txn/index.html', [
      'type' => $type,
      'txns' => $txns->find_many(),
      'page' => $page,
      'limit' => $limit,
      'status' => $status,
      'q' => $q,
    ]);
  }

  public function sales(Request $request, Response $response) {
    return $this->search($request, $response, 'customer');
  }

  public function newSale(Response $response) {
    ob_start();
    include "../old-index.php";
    $content= ob_get_clean();
    return $this->view->render($response, 'sale/old-new.html', [
      'title' => $GLOBALS['title'],
      'content' => $content,
    ]);
  }

  public function sale(Request $request, Response $response, $id) {
    $txn= $this->txn->fetchById($id);
    if (!$txn)
      throw new \Slim\Exception\HttpNotFoundException($request);

    $accept= $request->getHeaderLine('Accept');
    if (strpos($accept, 'application/json') !== false) {
      return $response->withJson($txn);
    }

    if (!$GLOBALS['DEBUG'] && !$request->getParam('force')) {
      return $response->withRedirect("/?id=$id");
    }

    if (($block= $request->getParam('block'))) {
      $html= $this->view->fetchBlock('sale/txn.html', $block, [
        'txn' => $txn,
      ]);

      $response->getBody()->write($html);
      return $response;
    }

    return $this->view->render($response, 'sale/txn.html', [
      'txn' => $txn,
    ]);
{'fraction_non_alphanumeric': 0.2073414222085701, 'fraction_numerical': 0.0009215174320380894, 'mean_word_length': 2.9299939649969824, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 120, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '112063', 'n_tokens_mistral': 2259, 'n_tokens_neox': 2218, 'n_words': 406}