Пример #1
0
 public function chargeCustomerAction($cid, $charge)
 {
     $success = true;
     $errors = array();
     $log = $this->get('log_interface');
     $em = $this->get('doctrine')->getManager();
     $repo = $em->getRepository('TuxCoffeeCornerCoreBundle:Customer');
     $customer = $repo->findOneBy(array('id_customer' => $cid));
     $repo = $this->get('doctrine')->getRepository('TuxCoffeeCornerCoreBundle:Product');
     $product = $repo->findOneBy(array('barcode' => 1));
     /* barcode 1 => einzahlung */
     if ($customer) {
         if (is_numeric($charge)) {
             if ($product) {
                 $trx = new TccTrx();
                 $trx->setAmount($charge);
                 $trx->setStatus(2);
                 $trx->setCustomer($customer);
                 $trx->setProduct($product);
                 $em->persist($trx);
             } else {
                 $success = false;
                 $errors[] = "Product 'Einzahlung' not found: it should have barcode '1'";
             }
             $vault = new Vault();
             if ($charge >= 0) {
                 $vault->setInput($charge);
             } else {
                 $vault->setOuttake(abs($charge));
             }
             $login_session = $this->getRequest()->getSession();
             $username = $login_session->get('username');
             $vault->setCashier($username);
             // if (isset($_SERVER['REMOTE_USER']))
             // 	$vault->setCashier($_SERVER['REMOTE_USER']);
             // elseif (isset($_SERVER['REDIRECT_REMOTE_USER']))
             // 	$vault->setCashier($_SERVER['REDIRECT_REMOTE_USER']);
             $vault->setComment("Einzahlung " . $customer->getName());
             $em->persist($vault);
             $customer->charge($charge);
             $em->persist($customer);
             $em->flush();
             $repo = $em->getRepository('TuxCoffeeCornerCoreBundle:Mail');
             $mail = $repo->findOneBy(array('identifier' => "receipt"));
             if ($mail) {
                 $charge = sprintf("%01.2f", $charge);
                 $this->get('mail_interface')->sendMail($mail, $customer, "[CHARGE]={$charge}");
             } else {
                 $success = false;
                 $errors[] = "No 'receipt' mail found";
                 $log->writeLog($this->logname, "Error while sending reminder: No 'receipt' mail found", 1);
             }
         } else {
             $success = false;
             $errors[] = "Invalid value for charge: '{$charge}' must be numeric";
         }
     } else {
         $success = false;
         $errors[] = "Customer '{$cid}' not found";
         $log->writeLog($this->logname, "Error while charging customer '{$cid}': customer not found", 1);
     }
     $message = $this->render("TuxCoffeeCornerCoreBundle:adminPages/snippets:" . ($success ? "successMsg" : "errorMsg") . ".html.php", array('errors' => $errors))->getContent();
     return new Response(json_encode(array('success' => $success, 'message' => $message)), 200, array('content-type' => 'application/json'));
 }
Пример #2
0
 public function editAction($vid)
 {
     $success = true;
     $errors = array();
     $em = $this->get('doctrine')->getManager();
     $repo = $em->getRepository('TuxCoffeeCornerCoreBundle:Vault');
     $entry = $repo->findOneBy(array('id_vault' => $vid));
     if (!$entry) {
         $entry = new Vault();
     }
     $entry->setTimestamp($_POST['timestamp']);
     $entry->setInput($_POST['input']);
     $entry->setOuttake($_POST['outtake']);
     $entry->setComment($_POST['comment']);
     $entry->setCashier($_POST['cashier']);
     $postErrors = $this->get('validator')->validate($entry);
     if (count($postErrors) > 0) {
         $success = false;
         foreach ($postErrors as $error) {
             $errors[] = $error->getMessage();
         }
     } else {
         $em = $this->get('Doctrine')->getManager();
         $em->persist($entry);
         try {
             $em->flush();
         } catch (\Exception $e) {
             $success = false;
             $errors[] = '<b>Uuuh! Some nasty database exception caught:</b> ' . $e->getMessage() . "\n";
         }
     }
     $message = $this->render("TuxCoffeeCornerCoreBundle:adminPages/snippets:" . ($success ? "successMsg" : "errorMsg") . ".html.php", array('errors' => $errors))->getContent();
     return new Response(json_encode(array('success' => $success, 'message' => $message)), 200, array('content-type' => 'application/json'));
 }