public function newAction(Request $request, $shopid) { $trades = null; $shop = $this->getRepository('BookkeepEntityBundle:Shop')->find($shopid); if (!($rp = $this->get('session')->get('refundProduct'))) { $rp = new RefundProduct(); $item = new RefundItem(); $rp->getRefundItems()->add($item); $this->get('session')->set('refundProduct', $rp); } $shopTrades = $this->getRepository('BookkeepEntityBundle:ShopTrade')->findBy(array('shop' => $shop)); foreach ($shopTrades as $shopTrade) { if ($shopTrade->getQuantity() == 0) { $this->remove($shopTrade); } $trades[] = $shopTrade->getTrade(); } $rpForm = $this->createForm(new RefundProductType($shop), $rp); if ($request->isMethod('GET')) { return $this->render('BookkeepAdminBundle:Refund:new.html.twig', array('rpForm' => $rpForm->createView(), 'shop' => $shop)); } $rpForm->handleRequest($request); if ($rpForm->isValid()) { $earnedSum = 0; $rp->setManager($this->getUser()); $rp->setShop($shop); $shop = $this->getRepository('BookkeepEntityBundle:Shop')->find($shopid); foreach ($rp->getRefundItems() as $item) { $item->setRefundProduct($rp); $shopTrade = $this->getRepository('BookkeepEntityBundle:ShopTrade')->findOneBy(array('shop' => $shop, 'trade' => $item->getTrade())); if ($item->getRestore()) { if ($shopTrade) { $shopTrade->setQuantity($shopTrade->getQuantity() + $item->getQuantity()); } else { $shopTrade = new ShopTrade(); $shopTrade->setShop($shop); $shopTrade->setTrade($item->getTrade()); $shopTrade->setQuantity($item->getQuantity()); } } $earnedSum = $earnedSum + $item->getPrice() * $item->getQuantity(); } $shop->setCash($shop->getCash() + $earnedSum); $shopTrades = $this->getRepository('BookkeepEntityBundle:ShopTrade')->findBy(array('shop' => $shop)); foreach ($shopTrades as $shopTrade) { if ($shopTrade->getQuantity() == 0) { $this->remove($shopTrade); } } $cashOperation = new CashOperation(); $cashOperation->setShop($shop); $cashOperation->setQuantity($earnedSum)->setType("UP")->setComment("Возвращено {$earnedSum} сом в магазине #{$shop->getId()} при возврате товаров"); $this->save($shop, $cashOperation, $rp); $this->getFlashBag()->add('success', 'Возврат товаров оформлен!'); $this->get('session')->set('refundProduct', null); return $this->render('BookkeepAdminBundle:Refund:new.html.twig', array('rpForm' => $rpForm->createView(), 'shop' => $shop)); } }
public function newAction(Request $request) { $organization = $this->getRepository('BookkeepEntityBundle:Organization')->findOneBy(array("title" => $this->container->get('session')->get('organization'))); if (!($pr = $this->get('session')->get('prRegistration'))) { $pr = new ProductRegistration(); $item = new ProductRegistrationTradeItem(); $pr->getTradeItems()->add($item); $this->get('session')->set('prRegistration', $pr); } $prForm = $this->createForm(new PrType($this->getUser(), $organization), $pr); if ($request->isMethod('GET')) { return $this->render('BookkeepAdminBundle:ProductRegistration:new.html.twig', array('prForm' => $prForm->createView())); } $prForm->handleRequest($request); if ($prForm->isValid()) { $amountSpent = 0; $pr->setManager($this->getUser()); $shop = $pr->getShop(); foreach ($pr->getTradeItems() as $item) { $item->setProductRegistration($pr); $amountSpent += $item->getQuantity() * $item->getPrice(); $shopTrade = $this->getRepository('BookkeepEntityBundle:ShopTrade')->findOneBy(array('shop' => $shop, 'trade' => $item->getTrade())); if ($shopTrade) { $shopTrade->setQuantity($shopTrade->getQuantity() + $item->getQuantity()); $this->save($shopTrade); } else { $shopTrade = new ShopTrade(); $shopTrade->setShop($shop); $shopTrade->setTrade($item->getTrade()); $shopTrade->setQuantity($item->getQuantity()); $this->save($shopTrade); } } $pr->setCost($amountSpent); $shop->setCash($shop->getCash() - $amountSpent); $cashOperation = new CashOperation(); $cashOperation->setShop($shop); $cashOperation->setQuantity($amountSpent)->setType("DOWN")->setComment("Списано {$amountSpent} сом при оформлении прихода в магазине #{$shop->getId()}"); $this->save($shop, $cashOperation, $pr); $this->getFlashBag()->add('success', 'Приход товаров оформлен!'); $this->get('session')->set('prRegistration', null); return $this->render('BookkeepAdminBundle:ProductRegistration:new.html.twig', array('prForm' => $prForm->createView())); } }
public function incrementCashAction(Request $request, $shopId) { $shop = $this->getRepository('BookkeepEntityBundle:Shop')->find($shopId); if (!$shop) { $this->getFlashBag()->add('error', 'Ошибка при пополнении кассы'); return $this->redirectToRoute('admin_shop_list'); } $cashQuantity = $request->request->get('form')['quantity']; $currentCash = $shop->getCash(); $shop->setCash($currentCash + $cashQuantity); $this->save($shop); $cashOperation = new CashOperation(); $cashOperation->setShop($shop); $cashOperation->setQuantity($cashQuantity); $cashOperation->setType("UP"); $comment = $request->request->get('form')['comment']; if ($comment) { $cashOperation->setComment($comment); } else { $cashOperation->setComment("Пополнена касса магазина #{$shop->getId()} на сумму {$cashQuantity} сом"); } $this->save($cashOperation); $this->getFlashBag()->add('success', 'Касса успешно пополнена'); return $this->redirectToRoute('admin_shop_show', array('id' => $shopId, 'org' => $this->container->get('session')->get('organization'))); }
public function newAction(Request $request, $shopid) { $trades = null; $shop = $this->getRepository('BookkeepEntityBundle:Shop')->find($shopid); $organization = $this->getRepository('BookkeepEntityBundle:Organization')->findOneBy(array("title" => $this->container->get('session')->get('organization'))); if (!($sr = $this->get('session')->get('srRegistration'))) { $sr = new SalesRegistration(); $item = new SalesRegistrationTradeItem(); $sr->getTradeItems()->add($item); $this->get('session')->set('srRegistration', $sr); } $shopTrades = $this->getRepository('BookkeepEntityBundle:ShopTrade')->findBy(array('shop' => $shop)); foreach ($shopTrades as $shopTrade) { if ($shopTrade->getQuantity() == 0) { $this->remove($shopTrade); } $trades[] = $shopTrade->getTrade(); } $srForm = $this->createForm(new SalesRegistrationType($this->getUser(), $organization, $shop, $trades), $sr); if ($request->isMethod('GET')) { return $this->render('BookkeepAdminBundle:SalesRegistration:new.html.twig', array('srForm' => $srForm->createView(), 'shop' => $shop)); } $srForm->handleRequest($request); if ($srForm->isValid()) { $earnedSum = 0; $sr->setManager($this->getUser()); $sr->setShop($shop); $shop = $this->getRepository('BookkeepEntityBundle:Shop')->find($shopid); foreach ($sr->getTradeItems() as $item) { $item->setSalesRegistration($sr); $earnedSum += $item->getQuantity() * $item->getPrice(); $shopTrade = $this->getRepository('BookkeepEntityBundle:ShopTrade')->findOneBy(array('shop' => $shop, 'trade' => $item->getTrade())); if ($shopTrade) { if ($shopTrade->getQuantity() == 0) { $this->remove($shopTrade); } else { if ($shopTrade->getQuantity() >= $item->getQuantity()) { $shopTrade->setQuantity($shopTrade->getQuantity() - $item->getQuantity()); $this->save($shopTrade); } } } } $shopTrades = $this->getRepository('BookkeepEntityBundle:ShopTrade')->findBy(array('shop' => $shop)); foreach ($shopTrades as $shopTrade) { if ($shopTrade->getQuantity() == 0) { $this->remove($shopTrade); } } $sr->setCost($earnedSum); $shop->setCash($shop->getCash() + $earnedSum); $cashOperation = new CashOperation(); $cashOperation->setShop($shop); $cashOperation->setQuantity($earnedSum)->setType("UP")->setComment("Заработано {$earnedSum} сом в магазине #{$shop->getId()}"); $this->save($shop, $cashOperation, $sr); $this->getFlashBag()->add('success', 'Продажа товаров оформлена!'); $this->get('session')->set('srRegistration', null); return $this->render('BookkeepAdminBundle:SalesRegistration:new.html.twig', array('srForm' => $srForm->createView(), 'shop' => $shop)); } }