<commit_before><commit_msg>creado evento para reservar item<commit_after><?php namespace PCI\Listeners\Note;

use PCI\Events\Note\NewNoteCreation;
use PCI\Mamarrachismo\Converter\interfaces\StockTypeConverterInterface;

/**
 * Class ReserveItemStock
 *
 * @package PCI\Listeners\Note
 * @author  <NAME> <<EMAIL>>
 * @link    https://github.com/slayerfat/sistemaPCI Repositorio en linea.
 */
class ReserveItemStock
{

    /**
     * @var \PCI\Mamarrachismo\Converter\StockTypeConverter
     */
    private $converter;

    /**
     * @param StockTypeConverterInterface $converter
     */
    public function __construct(StockTypeConverterInterface $converter)
    {
        $this->converter = $converter;
    }

    /**
     * Handle the event.
     *
     * @param \PCI\Events\Note\NewNoteCreation $event
     */
    public function handle(NewNoteCreation $event)
    {
        foreach ($event->items as $item) {
            $this->converter->setItem($item);
            $amount = $this->converter->convert(
                $item->pivot->stock_type_id,
                $item->pivot->quantity
            );

            // chequear el stock de cada item
            if ($item->stock() < $amount || $amount == 0) {
                // TODO: ignorar item
                continue;
            }

            $item->reserved += $amount;
            $item->save();
        }
    }
}
{'fraction_non_alphanumeric': 0.1270878721859114, 'fraction_numerical': 0.0007262164124909223, 'mean_word_length': 2.1036036036036037, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 19, 'https://': 1, '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': '3859928', 'n_tokens_mistral': 416, 'n_tokens_neox': 398, 'n_words': 75}