Beispiel #1
0
 public static function pair_with_transaction(array $item)
 {
     $trans = self::transaction_to_assoc($item);
     if (empty($trans['ident']) || empty($trans['symvar'])) {
         //~ throw new \System\Error('No ident or symvar');
         // Ignored - not an interesting payment
         return;
     }
     $match = self::get_first(array('ident' => $trans['ident'], 'symvar' => $trans['symvar']))->fetch();
     if ($match) {
         $item = $match;
     } else {
         $item = new self($trans);
     }
     if ($item->id && $item->check) {
         if ($item->check->is_paid) {
             // Ignored - transaction already paired with check and check is paid
             return;
         }
         $check = $item->check;
     } else {
         $check = \Workshop\Check::get_first()->where(array("symvar" => $item->symvar))->fetch();
     }
     if ($check) {
         $item->check = $check;
     } else {
         // Ignored - transaction without check
         //~ return;
         // No. Save payment with no checks.
     }
     $item->save();
     if ($check && !$check->is_paid) {
         $item->check->update_ballance();
     }
 }
Beispiel #2
0
 public function run_form()
 {
     $end = \DateTime::createFromFormat('Y-m-d H:i:s', static::EDITABLE_UNTIL);
     $this->req('symvar');
     $check = \Workshop\Check::get_first(array("symvar" => $this->symvar))->fetch();
     if (!$check) {
         throw new \System\Error\NotFound();
     }
     $signup = $check->signup;
     if (!$signup) {
         throw new \System\Error\NotFound();
     }
     $picked = $signup->food->fetch();
     $food = \Food\Item::get_all(array("edible" => true))->sort_by('blank desc')->fetch();
     $days = array();
     $data = array('soup_2016-05-14' => 1, 'main_2016-05-14' => 11, 'soup_2016-05-15' => 5, 'main_2016-05-15' => 12);
     foreach ($picked as $item) {
         $date = $item->date->format('Y-m-d');
         $type = $item->type == 1 ? 'soup' : 'main';
         $name = $type . '_' . $date;
         $data[$name] = $item->id;
     }
     foreach ($food as $item) {
         $date = $item->date->format('Y-m-d');
         $type = $item->type == 1 ? 'soup' : 'main';
         if (!array_key_exists($date, $days)) {
             $days[$date] = array("date" => $item->date, "soup" => array(), "main" => array());
         }
         $days[$date][$type][] = array("name" => $item->name, "value" => $item->id);
     }
     $f = $this->response->form(array("desc" => 'Předvol si obědy na Improtřesk 2016. Tato možnost končí ' . $end->format('j. n. v H:i') . '. Můžeš si zvolit "překvapte mě" a my jídlo vybereme za tebe.', "id" => 'food-picker', "default" => $data));
     foreach ($days as $date => $day) {
         $f->input(array("type" => 'radio', "label" => 'Polévka ' . $day['date']->format('j.n.'), "name" => 'soup_' . $date, "options" => $day['soup'], "required" => true));
         $f->input(array("type" => 'radio', "label" => 'Hlavní chod ' . $day['date']->format('j.n.'), "name" => 'main_' . $date, "options" => $day['main'], "required" => true));
     }
     $f->submit('Uložit');
     $f->out($this);
     if ($f->submited()) {
         if ($f->passed()) {
             $data = $f->get_data();
             $use = array();
             foreach ($data as $key => $val) {
                 if ($val != 666 && (strpos($key, 'soup') === 0 || strpos($key, 'main') === 0)) {
                     $use[] = $val;
                 }
             }
             $signup->food = $use;
             $signup->save();
             $this->partial('forms/message', array("msg" => 'Uloženo'));
         } else {
             $this->partial('forms/message', array("msg" => 'Neplatný vstup, zkus to prosím znova'));
         }
     }
 }
Beispiel #3
0
 public function run()
 {
     $account_pay = \Workshop\Check::get_all()->reset_cols()->add_cols(array('SUM(amount) as `total`'))->where(array("is_paid" => false))->assoc_with(null)->fetch_one();
     $account_sum = \Workshop\Payment::get_all()->reset_cols()->add_cols(array('SUM(amount) as `total`'))->assoc_with(null)->fetch_one();
     $stats = array("total" => \Workshop\SignUp::get_all()->count(), "unpaid" => \Workshop\SignUp::get_all()->where(array('paid' => false, 'solved' => false))->count(), "paid" => \Workshop\SignUp::get_all()->where(array('paid' => true))->count(), "waiting" => \Workshop\SignUp::get_all()->where(array('paid' => true, 'solved' => false, 'canceled' => false))->count(), "solved" => \Workshop\SignUp::get_all()->where(array('solved' => true, 'canceled' => false))->count(), "meals" => \Workshop\SignUp::get_all()->where(array('solved' => true, 'lunch' => true, 'canceled' => false))->count(), "hotel" => \Workshop\SignUp::get_all()->where(array('solved' => true, 'hotel' => true, 'canceled' => false))->count(), "expected_cnt" => \Workshop\Check::get_all()->where(array("is_paid" => false))->count(), "expected_sum" => $account_pay['total'], "received_cnt" => \Workshop\Payment::get_all()->count(), "received_sum" => $account_sum['total']);
     $ws = \Workshop::get_all()->fetch();
     foreach ($ws as $w) {
         $w->sig_total = $w->signups->count();
         $w->ass_total = $w->assignees->count();
     }
     $this->partial('stats/signups', array("stats" => $stats, "workshops" => $ws));
 }
Beispiel #4
0
 public function getSignup()
 {
     $this->req('symvar');
     $check = \Workshop\Check::get_first(array("symvar" => $this->symvar))->fetch();
     if (!$check) {
         throw new \System\Error\NotFound();
     }
     $signup = $check->signup;
     if (!$signup || !$signup->hotel) {
         throw new \System\Error\NotFound();
     }
     return $signup;
 }