diff --git a/hesabixCore/src/Controller/BusinessController.php b/hesabixCore/src/Controller/BusinessController.php index 9de5b59..ca39c25 100644 --- a/hesabixCore/src/Controller/BusinessController.php +++ b/hesabixCore/src/Controller/BusinessController.php @@ -251,7 +251,9 @@ class BusinessController extends AbstractController 'bid' => $business, 'head' => true ]); - + if(!$year){ + $year = new Year; + } $startYearArray = explode('-', $params['year']['startShamsi']); if(count($startYearArray) == 1) $startYearArray = explode('/', $params['year']['startShamsi']); diff --git a/hesabixCore/src/Controller/CommodityController.php b/hesabixCore/src/Controller/CommodityController.php index b70bc25..e53b374 100644 --- a/hesabixCore/src/Controller/CommodityController.php +++ b/hesabixCore/src/Controller/CommodityController.php @@ -94,7 +94,6 @@ class CommodityController extends AbstractController } $temp['count'] = $count; } - $res[] = $temp; } return $this->json($res); @@ -160,6 +159,29 @@ class CommodityController extends AbstractController $temp['count'] = $count; } + //calculate other prices + $pricesAll = $entityManager->getRepository(PriceList::class)->findBy([ + 'bid' => $acc['bid'] + ]); + foreach ($pricesAll as $list) { + $priceDetails = $entityManager->getRepository(PriceListDetail::class)->findOneBy([ + 'list' => $list, + 'commodity' => $item + ]); + if ($priceDetails) { + $temp['prices'][] = Explore::ExploreCommodityPriceListDetail($priceDetails); + } else { + $spd = new PriceListDetail; + $spd->setList($list); + $spd->setMoney($acc['bid']->getMoney()); + $spd->setCommodity($item); + $spd->setPriceBuy(0); + $spd->setPriceSell(0); + $entityManager->persist($spd); + $entityManager->flush(); + $temp['prices'][] = Explore::ExploreCommodityPriceListDetail($spd); + } + } $res[] = $temp; } return $this->json($res); diff --git a/hesabixCore/src/Controller/YearController.php b/hesabixCore/src/Controller/YearController.php index 239f20c..3d11270 100644 --- a/hesabixCore/src/Controller/YearController.php +++ b/hesabixCore/src/Controller/YearController.php @@ -21,6 +21,18 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class YearController extends AbstractController { + public function createDefaultYear(Business $bid,EntityManagerInterface $entityManagerInterface) : Year{ + $year = new Year(); + $year->setBid($bid); + $year->setHead(true); + $year->setLabel('سال مالی اول'); + $year->setStart(time()); + $year->setEnd(time() + 31563000); + $entityManagerInterface->persist($year); + $entityManagerInterface->flush(); + return $year; + + } #[Route('/api/year/list', name: 'app_year_list')] public function app_year_list(Request $request, EntityManagerInterface $entityManager): JsonResponse { @@ -30,6 +42,10 @@ class YearController extends AbstractController $years = $entityManager->getRepository(Year::class)->findBy([ 'bid' => $business ]); + if (count($years) == 0) { + //no year created create first year + $years = [$this->createDefaultYear($business,$entityManager)]; + } return $this->json($years); } diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index 169cdf8..e104eb4 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -337,9 +337,16 @@ class Explore 'name' => $money->getName(), ]; } - public static function ExploreYear(Year $year) + public static function ExploreYear(Year | null $year) { $jdate = new Jdate(); + if(!$year){ + $year = new Year(); + $year->setHead(true); + $year->setLabel('سال مالی اول'); + $year->setStart(time()); + $year->setEnd(time() + 31536000); + } return [ 'id' => $year->getId(), 'label' => $year->getLabel(), @@ -347,8 +354,8 @@ class Explore 'start' => $year->getStart(), 'end' => $year->getEnd(), 'now' => time(), - 'startShamsi' => $jdate->jdate('Y-n-d', $year->getStart()), - 'endShamsi' => $jdate->jdate('Y-n-d', $year->getEnd()), + 'startShamsi' => $jdate->jdate('Y/n/d', $year->getStart()), + 'endShamsi' => $jdate->jdate('Y/n/d', $year->getEnd()), ]; }