protected function updateAuctionProfitStatusAndPaidCompleteAt(AuctionPayment $payment, $isCreate = false)
 {
     /**
      * @var \Woojin\StoreBundle\Entity\Auction
      */
     $auction = $payment->getAuction();
     /**
      * 客戶尚未結清的餘額
      *
      * @var integer
      */
     $owe = $auction->getOwe() - (true === $isCreate ? $payment->getAmount() : 0);
     /**
      * Auction 的毛利狀態
      *
      * @var integer
      */
     $profitStatus = 0 === $owe ? Auction::PROFIT_STATUS_PAY_COMPLETE : Auction::PROFIT_STATUS_NOT_PAID_YET;
     $auction->setProfitStatus($profitStatus);
     if (Auction::PROFIT_STATUS_NOT_PAID_YET === $auction->getProfitStatus()) {
         $auction->setPaidCompleteAt(NULL);
     } else {
         $orgPayment = $this->em->getRepository('WoojinStoreBundle:Auction')->fetchLatestPaymentByAuction($auction);
         $paidCompleteAt = $orgPayment->getPaidAt() >= $payment->getPaidAt() ? $orgPayment->getPaidAt() : $payment->getPaidAt();
         $auction->setPaidCompleteAt($paidCompleteAt);
     }
     $this->em->persist($auction);
     $this->em->flush();
 }
 public function create(array $options)
 {
     $this->configureCreateOptions();
     $options = $this->getResolver()->resolve($options);
     $payment = new AuctionPayment();
     $payment->setAuction($options['auction'])->setPayType($options['payType'])->setCreater($options['creater'])->setAmount($options['amount'])->setPaidAt($options['paidAt'])->setOrgAmount($options['orgAmount']);
     return $payment;
 }
 protected function configureDropOptions(AuctionPayment $payment)
 {
     $this->setResolver(new OptionsResolver());
     $this->getResolver()->setRequired('canceller')->setAllowedTypes('canceller', 'Woojin\\UserBundle\\Entity\\User')->setAllowedValues('canceller', function (User $canceller) use($payment) {
         if (Auction::PROFIT_STATUS_ASSIGN_COMPLETE === $payment->getAuction()->getProfitStatus()) {
             throw new \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException('This auction deny all payment operations because profit has been assigned!');
         }
         return $canceller->getStore()->getId() === $payment->getAuction()->getBsoStore()->getId();
     });
 }
Example #4
0
 protected function getPaymentAmountWithoutTax(AuctionPayment $payment)
 {
     return (int) $payment->getAmount();
 }
 /**
  * @Route("/{id}", name="auction_payment_drop", options={"expose"=true})
  * @ParamConverter("payment", class="WoojinStoreBundle:AuctionPayment")
  * @Method("DELETE")
  */
 public function dropAction(AuctionPayment $payment)
 {
     /**
      * DoctrineManager
      *
      * @var \Doctrine\ORM\EntityManager;
      */
     $em = $this->getDoctrine()->getManager();
     /**
      * 目前登入的使用者實體
      *
      * @var \Woojin\UserBundle\Entity\User
      */
     $user = $this->get('security.token_storage')->getToken()->getUser();
     /**
      * Session
      *
      * @var \Symfony\Component\HttpFoundation\Session\Session
      */
     $session = $this->get('session');
     /**
      * @var \Woojin\Service\Store\AuctionPaymentService
      */
     $service = $this->get('auction.payment.service');
     if (!$payment->getAuction()->isAllowedEditPayment($user) || true === $payment->getIsCancel()) {
         throw $this->createAccessDeniedException('Not allowed to edit this auction!');
     }
     try {
         $payment = $service->drop($payment, array('canceller' => $user));
         $em->persist($payment);
         $em->flush();
         $session->getFlashBag()->add('success', '競拍付款取消完成!');
     } catch (\Exception $e) {
         $session->getFlashBag()->add('error', $e->getMessage());
     }
     return $this->redirect($this->generateUrl('goods_edit_v2', array('id' => $payment->getAuction()->getProduct()->getId())) . '/#_soldop');
 }