<?php
/**
 * [BEGIN_COT_EXT]
 * Hooks=marketorders.ajax.admin_arbitrage_result
 * Order=99
 * [END_COT_EXT]
 */

defined('COT_CODE') or die('Wrong URL.');

if($ord_upd['order_status'] == 'done' && $ord['order_userid'] > 0) {
  $orderdoneforbuyersumm = explode('|', $cfg['payments']['orderdoneforbuyersumm']);

  if((int)$orderdoneforbuyersumm[0] > 0 && (float)$orderdoneforbuyersumm[1] > 0)
  {
    $cntbuyerordersdone = $db->query("SELECT COUNT(*) FROM $db_market_orders WHERE order_userid=".$ord['order_userid']." AND order_status='done'")->fetchColumn();
    if(!$cntbuyerordersdone) $cntbuyerordersdone = 0;
    $cntbuyerordersdone++; //хук перед update текущего заказа

    if($cntbuyerordersdone >= (int)$orderdoneforbuyersumm[1] && ((int)$orderdoneforbuyersumm[1] == 1 || ($cntbuyerordersdone % (int)$orderdoneforbuyersumm[1]) == 0))
  	{
      require_once cot_incfile('payments', 'module');

      cot_payments_updateuserbalance_hand($ord['order_userid'], (float)$orderdoneforbuyersumm[1], $L['payments_orderdoneforbuyersumm_pay_desc'], true);

  		/* === Hook === */
  	  foreach (cot_getextplugins('payments.orderdoneforbuyer.done') as $pl)
  	  {
  		  include $pl;
  	  }
  	  /* ===== */
  	}
  }
}