Example #1
0
 public function log(Orders $order, User $user, PayType $paytype, $amount = null, $act = null)
 {
     $ope = new Ope();
     $ope->setOrder($order)->setUser($user)->setPayType($paytype)->setAmount($amount)->setAct($act)->setDatetime(new \DateTime());
     $this->setOpe($ope);
     return $this;
 }
Example #2
0
 public function create(array $options = array())
 {
     $act;
     foreach ($options['orders'] as $order) {
         switch ($order->getKind()->getId()) {
             case Avenue::OK_IN:
                 $act = '成立進貨訂單';
                 break;
             case Avenue::OK_CONSIGN_IN:
                 $act = '成立寄賣訂單';
                 break;
             case Avenue::OK_FEEDBACK:
                 $act = '成立寄賣回扣訂單';
                 break;
             default:
                 break;
         }
         $ope = new Ope();
         $ope->setUser($options['user'])->setOrder($order)->setAct($act)->setDatetime(new \DateTime())->setAmount($options['cost'])->setPayType($options['paytype']);
         $this->addStorage($ope);
     }
     return $this;
 }
Example #3
0
 /**
  * 調出貨請求確認
  * 
  * @Route("/backOrder/{id}/confirm", name="order_backOrder_confirm", options={"expose"=true})
  * @ParamConverter("move", class="WoojinGoodsBundle:Move")
  * @Method("GET")
  */
 public function backOrderConfirmAction(Request $request, Move $move)
 {
     if (!$move->isModifyble()) {
         return new \Exception("請求已經為終止狀態,不可更改!");
     }
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $session = $this->get('session');
     $em = $this->getDoctrine()->getManager();
     $qb = $em->createQueryBuilder();
     $em->getConnection()->beginTransaction();
     try {
         $oGoodsStatus = $em->find('WoojinGoodsBundle:GoodsStatus', Avenue::GS_OTHERSTORE);
         $oGoodsStatusIn = $em->find('WoojinGoodsBundle:GoodsStatus', Avenue::GS_ONSALE);
         // 從調貨請求出抓出被調出的商品
         $product = $move->getOrgGoods();
         // 將商品狀態設定為他店
         $product->setStatus($oGoodsStatus);
         // 尋找是否已經存在屬於該店的護照(產編字首和商品指紋)
         $qb->select('gd')->from('WoojinGoodsBundle:GoodsPassport', 'gd')->where($qb->expr()->andX($qb->expr()->eq('SUBSTRING(gd.sn, 1, 1)', $qb->expr()->literal($user->getStore()->getSn())), $qb->expr()->eq('gd.parent', $product->getParent()->getId())));
         // Query 結果為調進貨的商品,若不存在該商品則反為 NULL
         $newProducts = $qb->getQuery()->getResult();
         // 如果為空則建立新護照, 直接將原本護照的內容copy到新護照上
         if (empty($newProducts)) {
             $productFactory = $this->get('factory.product');
             // 複製調出商品實體
             $productFactory->_clone($product);
             // 從工廠提取複製品
             $newProduct = $productFactory->getProduct();
             // 改變複製品的產編和狀態(上架)
             $newProduct->setSn($newProduct->genSn($user->getStore()->getSn()))->setStatus($oGoodsStatusIn);
             $em->persist($newProduct);
             $em->flush();
         } else {
             // 若不為空則直接使用取得的舊護照
             /* 
              * 商品回國將狀態改為國內( 上架 ), 
              * 寄賣金額改為0 表示不用做二段通知 
              */
             // 取得護照
             $newProduct = $newProducts[0];
             // 將商品狀態改為上架
             $newProduct->setStatus($oGoodsStatusIn);
             $em->persist($newProduct);
             // 取得該護照的所有訂單記錄
             $newOrders = $newProduct->getOrders();
             // 依照訂單記錄進行迭代
             foreach ($newOrders as $key => $order) {
                 if (Avenue::OK_FEEDBACK === $order->getId()) {
                     // 將寄賣金額從 -1 改為 0
                     $order->setPaid(0);
                     $em->persist($order);
                     break;
                 }
             }
         }
         $move->setStatus($em->find('WoojinGoodsBundle:MoveStatus', Avenue::MV_COMPLETE))->setNewGoods($newProduct)->setCatcher($user);
         $em->persist($move);
         $complete = $em->find('WoojinOrderBundle:OrdersStatus', Avenue::OS_COMPLETE);
         $cashType = $em->find('WoojinOrderBundle:PayType', Avenue::PT_CASH);
         $ordersMoveOut = new Orders();
         $ordersMoveOut->setStatus($complete)->setPaid($product->getCost())->setRequired($product->getCost())->setPayType($cashType)->setKind($em->find('WoojinOrderBundle:OrdersKind', Avenue::OK_MOVE_OUT))->setGoodsPassport($product);
         $ordersMoveIn = new Orders();
         $ordersMoveIn->setStatus($complete)->setPaid($product->getCost())->setRequired($product->getCost())->setPayType($cashType)->setKind($em->find('WoojinOrderBundle:OrdersKind', Avenue::OK_MOVE_IN))->setGoodsPassport($newProduct);
         $ordersMoveIn->addRelate($ordersMoveOut);
         $ordersMoveOut->setParent($ordersMoveIn);
         $em->persist($ordersMoveIn);
         $em->persist($ordersMoveOut);
         // 記錄調貨進操作記錄
         $opeIn = new Ope();
         $opeOut = new Ope();
         $opeIn->setUser($move->getCatcher())->setDatetime(new \DateTime(date('Y-m-d H:i:s')))->setOrders($ordersMoveIn)->setAct('成立調進貨訂單');
         $opeOut->setUser($move->getThrower())->setDatetime(new \DateTime(date('Y-m-d H:i:s')))->setOrders($ordersMoveOut)->setAct('成立調出貨訂單');
         $newProduct->setSn($newProduct->genSn($user->getStore()->getSn()));
         $em->persist($opeIn);
         $em->persist($opeOut);
         $em->persist($newProduct);
         $em->flush();
         $em->getConnection()->commit();
         $session->getFlashBag()->add('success', $product->getSn() . ' -> ' . $newProduct->getSn());
     } catch (Exception $e) {
         $em->getConnection()->rollback();
         throw $e;
     }
     // 若已經上傳至yahoo,
     if ($newProduct->getYahooId()) {
         $apiClient = $this->get('yahoo.api.client');
         $apiClient->updateMain($apiClient->getProvider()->genR($newProduct)->getR());
         $session->getFlashBag()->add('success', 'Yahoo商城同步更新完成');
         $product->setYahooId(NULL);
         $em->persist($product);
         $em->flush();
     } else {
         $session->getFlashBag()->add('error', 'Yahoo商城同步未進行');
     }
     return $this->redirect($this->generateUrl('move'));
 }
Example #4
0
 protected function batchAddEachProcess($rData)
 {
     $em = $this->em;
     $oOrders = new Orders();
     $oOpe = new Ope();
     $oGoodsPassport = new GoodsPassport();
     $oGoodsPassport->setBrand($this->brand)->setModel($rData['model'])->setColor($this->color)->setPattern($this->pattern)->setColorSn(array_key_exists('colorSn', $rData) ? $rData['colorSn'] : '')->setLevel($this->oGoodsLevel)->setGoodsStatus($this->oGoodsStatus)->setName($rData['sGoodsName'])->setCost($rData['nGoodsCost'])->setPrice($rData['nGoodsPrice'])->setOrgSn(array_key_exists('sGoodsOrgSn', $rData) ? $rData['sGoodsOrgSn'] : '')->setMemo(array_key_exists('sGoodsMemo', $rData) ? $rData['sGoodsMemo'] : '');
     $em->persist($oGoodsPassport);
     $em->flush();
     $sym = $this->get('base_method')->getSymbol();
     $theRate = $sym == 'NT' ? self::SN_RATE : 10;
     $nGoodsId = $oGoodsPassport->getId();
     $sGoodsSn = $oGoodsPassport->genSn($rData['sStoreSn']);
     $oGoodsPassport->setSn($sGoodsSn)->setParent($em->find('WoojinGoodsBundle:GoodsPassport', $nGoodsId));
     $em->persist($oGoodsPassport);
     $em->flush();
     $oOrders->setGoodsPassport($oGoodsPassport)->setPayType($this->oPayType)->setOrdersKind($this->oOrdersKind)->setOrdersStatus($this->oOrdersStatus)->setRequired($rData['nGoodsCost'])->setPaid($rData['nGoodsCost']);
     $em->persist($oOrders);
     $em->flush();
     $nOrdersId = $oOrders->getId();
     //Ope實體新增
     $oOpe->setOrders($oOrders)->setUser($this->oUser)->setAct('批次成立進貨訂單')->setDatetime(new \DateTime($rData['time']));
     $em->persist($oOpe);
     $em->flush();
 }
Example #5
0
 protected function pick($product)
 {
     // 更新商品狀態
     $product->setStatus($this->saleStatus);
     $per = (100 - $this->invoice->getInvoiceSurcharge()) / 100;
     $order = new Orders();
     $order->setPaid(0)->setRequired(round($product->getPromotionPrice(true) * $per))->setOrgPaid(0)->setOrgRequired($product->getPromotionPrice(true))->setPayType($this->paytype)->setKind($this->kind)->setStatus($this->completeStatus)->setGoodsPassport($product)->setInvoice($this->invoice)->setCustom($this->custom);
     $ope = new Ope();
     $ope->setOrders($order)->setUser($this->user)->setAct('官網售出')->setDatetime(new \DateTime());
     $this->em->persist($product);
     $this->em->persist($order);
     $this->em->persist($ope);
 }