Пример #1
0
 public function xuatkhoAction()
 {
     $aParam = $this->getParam();
     $kho = FacilityConsignmentAssocs::findFirst("facilityid='" . NHAKHO . "' AND consignmentid='" . $aParam['consignmentid'] . "'");
     if ($kho == true) {
         $aParam["updated_at"] = (new DateTime())->format('Y-m-d H:i:s');
         if ($aParam['quantity'] <= $kho->quantity) {
             $kho->quantity = $kho->quantity - $aParam['quantity'];
             $result = $kho->update();
             $cuahang = FacilityConsignmentAssocs::findFirst("facilityid='" . $aParam['facilityid'] . "' AND consignmentid='" . $aParam['consignmentid'] . "'");
             if ($cuahang == true) {
                 $cuahang->quantity = $cuahang->quantity + $aParam['quantity'];
                 $result_ = $cuahang->update();
             } else {
                 $aParam["created_at"] = (new DateTime())->format('Y-m-d H:i:s');
                 $new = new FacilityConsignmentAssocs();
                 $result_ = $new->save($aParam);
             }
             if ($result == true && $result_ == true) {
                 return $this->showErrorJson(1);
             } else {
                 return $this->showErrorJson(0, "Consignment", $aParam);
             }
         } else {
             return $this->showErrorJson(22, "Consignment", $aParam);
         }
     } else {
         return $this->showErrorJson(2, "Consignment", $aParam);
     }
 }
Пример #2
0
 public function addAction()
 {
     $aParam = $this->getParam();
     $check = Consignment::findFirst("consignmentname_vi='" . $aParam['consignmentname_vi'] . "' OR consignmentname_en='" . $aParam['consignmentname_en'] . "'");
     if ($check == false) {
         $aParam["consignmentid"] = $this->randomToken(10);
         $aParam["created_at"] = (new DateTime())->format('Y-m-d H:i:s');
         $aParam["updated_at"] = (new DateTime())->format('Y-m-d H:i:s');
         $new = new Consignment();
         $result = $new->save($aParam);
         $aParam['facilityid'] = NHAKHO;
         $aParam['consignmentid'] = $new->consignmentid;
         $new_ = new FacilityConsignmentAssocs();
         $result_ = $new_->save($aParam);
         if ($result == true && $result_ == true) {
             return $this->showErrorJson(1);
         } else {
             return $this->showErrorJson(0, "Consignment", $aParam);
         }
     } else {
         return $this->showErrorJson(2, "Consignment", $aParam);
     }
 }