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 buyAction($bar)
 {
     $log = $this->get('log_interface');
     $session = $this->getRequest()->getSession();
     $cid = $session->get('id');
     $repo = $this->get('doctrine')->getRepository('TuxCoffeeCornerCoreBundle:Product');
     $product = $repo->findOneBy(array('barcode' => $bar));
     $repo = $this->get('doctrine')->getRepository('TuxCoffeeCornerCoreBundle:Customer');
     $customer = $repo->findOneBy(array('id_customer' => $cid));
     $customer->charge(-$product->getPrice());
     $customer->setFavorite($product);
     $trx = new TccTrx();
     $trx->setAmount($product->getPrice());
     $trx->setStatus(1);
     $trx->setCustomer($customer);
     $trx->setProduct($product);
     $em = $this->get('Doctrine')->getManager();
     $em->persist($trx);
     $em->persist($customer);
     $em->flush();
     $log->writeLog($this->logname, "Customer '{$cid}' bought '{$bar}'", 3);
     return new Response("Done", 200, array('content-type' => 'text/plain'));
 }