Esempio n. 1
0
 public function validateRequest(Qurbani $qurbani)
 {
     $errors = [];
     if ($qurbani->getSheep() < 0) {
         $errors[] = "Invalid Number of Sheep";
     }
     if ($qurbani->getCows() < 0) {
         $errors[] = "Invalid Number of Cows";
     }
     if ($qurbani->getCamels() < 0) {
         $errors[] = "Invalid Number of Camels";
     }
     if ($qurbani->getSheep() + $qurbani->getCows() + $qurbani->getCamels() <= 0) {
         $errors[] = "At least one animal is required";
     }
     if (($qurbani->getDonationid() != null || $qurbani->getQurbanikey() == null) && !$qurbani->getIsvoid()) {
         $sheep = $qurbani->getSheep();
         $cows = $qurbani->getCows();
         $camels = $qurbani->getCamels();
         if ($qurbani->getQurbanikey() != null) {
             $current = $this->qurbaniRepo->fetch($qurbani->getQurbanikey());
             if ($current == null) {
                 $errors[] = "Could not find Qurbani Donation";
             } else {
                 if ($current->getQurbanimonth() != $this->details->qurbanimonth) {
                     $errors[] = "Invalid Qurbani Month";
                 }
                 if ($current->getDonationid() != null && !$current->getIsvoid()) {
                     $sheep -= $current->getSheep();
                     $cows -= $current->getCows();
                     $camels -= $current->getCamels();
                 }
             }
         }
         $sheepLeft = $this->details->totalsheep - $this->getPurchasedSheep();
         $cowsLeft = $this->details->totalcows - $this->getPurchasedCows();
         $camelsLeft = $this->details->totalcamels - $this->getPurchasedCamels();
         if ($sheep > $sheepLeft) {
             $errors[] = "Only {$sheepLeft} Sheep left";
         }
         if ($cows > $cowsLeft) {
             $errors[] = "Only {$cowsLeft} Cows left";
         }
         if ($camels > $camelsLeft) {
             $errors[] = "Only {$camelsLeft} Camels left";
         }
     }
     return $errors;
 }
Esempio n. 2
0
 public function __construct(Qurbani $qurbani = null)
 {
     if ($qurbani != null) {
         $this->qurbanikey = $qurbani->getQurbanikey();
         $this->qurbanimonth = $qurbani->getQurbanimonth();
         $this->sheep = $qurbani->getSheep();
         $this->cows = $qurbani->getCows();
         $this->camels = $qurbani->getCamels();
         $this->total = $qurbani->getTotal();
         $this->fullname = $qurbani->getFullname();
         $this->email = $qurbani->getEmail();
         $this->mobile = $qurbani->getMobile();
         $this->instructions = $qurbani->getInstructions();
         $this->donationid = $qurbani->getDonationid();
         $this->isvoid = $qurbani->getIsvoid();
         $this->iscomplete = $qurbani->getIscomplete();
         $this->createddate = $qurbani->getCreateddate();
     }
 }